268 Commits

Author SHA1 Message Date
Joseph Huber
f2a87b07e7
[OpenMP] Use loaded offloading toolchains to add libraries (#87108)
Summary:
We want to pass these GPU libraries by default if a certain offloading
toolchain is loaded for OpenMP. Previously I parsed this from the
arguments because it's only available in the compilation. This doesn't
really work for `native` and it's extra effort, so this patch just
passes in the `Compilation` as an extr argument and uses that. Tests
should be unaffected.
2024-04-01 17:26:20 -05:00
Fangrui Song
938ddbf349 [Driver,Darwin] Simplify libc++ include path after #80527. NFC
My #80527 mentioned that `InstalledDir` was weird in the
-canonical-prefixes mode. #70817 was a workaround to find the libc++
include path for a symlinked clang. After #80527, `InstalledDir` was
identical to `Dir` and was subsequently removed, the code change #70817
can be reverted.
2024-03-03 18:30:17 -08:00
Fangrui Song
2b5cd8be3a [Driver] Remove InstallDir and getInstalledDir. NFC
Follow-up to #80527.
2024-03-03 18:10:46 -08:00
Brad Smith
d5f77e112e
[Driver] Remove duplicate -r flag usage when linking (#82715)
Bug #82010
2024-03-02 21:33:59 -05:00
Cyndy Ishida
1245f5f4da
[clang][Driver] Add support for XROS_DEPLOYMENT_TARGET env var (#81011) 2024-02-09 08:52:06 -08:00
Juergen Ributzka
4ad4c8e90e
[clang] Use LazyDetector for all toolchains. (#79073)
Use the LazyDetector also for the remaining toolchains to avoid unnecessarily checking for the Cuda and Rocm installations.

This fixes rdar://121397534.
2024-01-23 13:14:17 -08:00
Jonas Devlieghere
a4fe6a1838
[clang] Upstream XROS support in Clang (#78392)
Upstream XROS support in the clang frontend and driver.
2024-01-17 21:09:15 -08:00
Zixu Wang
c3f96acb41
Revert "[Fix] Disable fdefine-target-os-macros for now" (#78353)
https://github.com/llvm/llvm-test-suite/pull/65 fixed the
llvm-test-suite errors. Reapply the change to enable
`fdefine-target-os-macros` by default for Darwin targets.

This reverts commit 63be986f612c175559efffed9daebcb944fa5cea.
2024-01-16 16:48:20 -08:00
Arthur Eubanks
d34901f30b Revert "[clang][Darwin] Remove legacy framework search path logic in the frontend (#75841)"
This reverts commit 61999b18c407b9f5c07577e63057d41c65240e61.

See comments on https://github.com/llvm/llvm-project/pull/75841. This
was intended to be NFC but actually isn't.
2024-01-02 18:09:16 +00:00
Louis Dionne
61999b18c4
[clang][Darwin] Remove legacy framework search path logic in the frontend (#75841)
This removes a long standing piece of technical debt. Most other
platforms have moved all their header search path logic to the driver,
but Darwin still had some logic for setting framework search paths
present in the frontend. This patch moves that logic to the driver
alongside existing logic that already handles part of these search
paths.

This is intended to be a pure refactor without any functional change
visible to users, since the search paths before and after should be the
same, and in the same order. The change in the tests is necessary
because we would previously add the DriverKit framework search path in
the frontend regardless of whether we actually need to, which we now
handle correctly because the driver checks for ld64-605.1+.

Fixes #75638
2023-12-31 05:15:49 -05:00
Kazu Hirata
f3dcc2351c
[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 08:54:13 -08:00
Kazu Hirata
cc4ecfd68b
[ADT] Rename SmallString::{starts,ends}with to {starts,ends}_with (#74916)
This patch renames {starts,ends}with to {starts,ends}_with for
consistency with std::{string,string_view}::{starts,ends}_with in
C++20.  Since there are only a handful of occurrences, this patch
skips the deprecation phase and simply renames them.
2023-12-09 14:28:45 -08:00
Zixu Wang
c9b4bb9ff9
[Fix] Disable fdefine-target-os-macros for now (#74886)
https://github.com/llvm/llvm-project/pull/74676 landed the work to
implement `-fdefine-target-os-macros` and enabled the extension for the
Darwin driver. However it is breaking some test builds. Leave the
extension disabled for now until we can fix/workaround the build
failures.
2023-12-08 13:07:29 -08:00
Zixu Wang
6e1f19168b
[clang][PP] Add extension to predefine target OS macros (#74676)
Add an extension feature `define-target-os-macros` that enables clang to
provide definitions of common TARGET_OS_* conditional macros. The
extension is enabled in the Darwin toolchain driver.
2023-12-07 17:40:58 -08:00
Louis Dionne
e4f951e4ee [clang][NFC] Fix typo in comment about Mac Catalyst 2023-11-30 11:05:41 -05:00
Michael Klemm
17feb330aa
[flang][Driver] Let the linker fail on multiple definitions of main() (#73124)
The flang driver was silently ignoring the `main()` function in
`Fortran_main.a` for entry into the Fortran program unit if an external
`main()` as supplied (e.g., via cross-language linkage with Fortran and
C/C++). This PR fixes this by making sure that the linker always pulls
in the `main()` definition from `Fortran_main.a` and consequently fails
due to multiple definitions of the same symbol if another object file
also has a definition of `main()`.
2023-11-28 14:20:30 -06:00
David Truby
0bc7cd4d51
[flang] Add runtimes using --dependent-lib on MSVC targets (#72519)
This patch uses the added --dependent-lib support to add the relevant
runtimes on MSVC targets as `/DEFAULTLIB:` sections in the object file
rather than on the link line. This should help CMake support for flang
on Windows.

Fixes #63741 
Fixes #68017
2023-11-23 14:19:57 +00:00
Liviu Ionescu
a32a2b2ceb
[clang][driver] Add <executable>/../include/c++/v1 to include path on Darwin (#70817)
On macOS, when clang is invoked via a symlink, since the InstalledDir is
where the link is located, the C++ headers are not identified and the
default system headers from the SDK are used.

This can be undesirable if a toolchain is created by symlinking clang
into a directory and placing libc++ headers in that directory with the
intent of those headers overriding the SDK headers. This change solves
that problem by also looking for libc++ headers in the toolchain-relative
location of the executable symlink, if any.
2023-11-20 11:14:36 -05:00
David Truby
cf1e3420b0
[flang][windows] Add option to link against specific MSVC CRT (#70833)
Currently flang's runtime libraries are only built for the specific CRT
that LLVM itself was built against. This patch adds the cmake logic for
building a separate runtime for each CRT configuration and adds a flag
for selecting a CRT configuration to link against.
2023-11-10 16:13:49 +00:00
Alan Phipps
f95b2f1acf Reland "[InstrProf][compiler-rt] Enable MC/DC Support in LLVM Source-based Code Coverage (1/3)"
Part 1 of 3. This includes the LLVM back-end processing and profile
reading/writing components. compiler-rt changes are included.

Differential Revision: https://reviews.llvm.org/D138846
2023-10-30 11:15:02 -05:00
Fangrui Song
4eecfda50a [Driver] Rename AddAllArgs (initialization list overload) to addAllArgs
Most ArgList member functions use the modern functionName style while some like
AddAllArgs use the legacy FunctionName style. These uses are mostly linker
options which have been modified recently to fix duplicate -e issues, so just
update these call sites.
2023-10-10 21:31:18 -07:00
Ian Anderson
0ea3d88bdb [Modules] Add a flag to control builtin headers being in system modules
Including select builtin headers in system modules is a workaround for module cycles, primarily in Apple's Darwin module that includes all of its C standard library headers. The workaround is problematic because it doesn't include all of the builtin headers (inttypes.h is notably absent), and it also doesn't include C++ headers. The straightforward for for this is to make top level modules for all of the C standard library headers and unwind.h in C++, clang, and the OS.

However, doing so in clang before the OS modules are ready re-introduces the module cycles. Add a -fbuiltin-headers-in-system-modules option to control if the special builtin headers belong to system modules or builtin modules. Pass the option by default for Apple.

Reviewed By: ChuanqiXu, Bigcheese, benlangmuir

Differential Revision: https://reviews.llvm.org/D159483
2023-09-28 11:30:09 -07:00
Fangrui Song
8d7a523923 [Driver] Remove remnant PowerPC Darwin code
Continue the work started at https://reviews.llvm.org/D50989
2023-09-10 12:37:06 -07:00
Aaron Ballman
a02f9a7756 Revert "[clang] Enable sized deallocation by default in C++14 onwards"
This reverts commit 2916b125f686115deab2ba573dcaff3847566ab9.

Reverting due to failures on:
https://lab.llvm.org/buildbot/#/builders/216/builds/26407
https://lab.llvm.org/staging/#/builders/247/builds/5659
http://45.33.8.238/win/83485/step_7.txt
2023-08-29 09:36:59 -04:00
wangpc
2916b125f6 [clang] Enable sized deallocation by default in C++14 onwards
Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

Reviewed By: rnk, aaron.ballman, #libc, ldionne, Mordante, MaskRay

Differential Revision: https://reviews.llvm.org/D112921
2023-08-29 15:42:50 +08:00
Alex Lorenz
3197357b7e
Revert "[clang] Match -isysroot behaviour with system compiler on Darwin"
This reverts commit f24aa691aa4f25291db8f7c61c6e9007288859e7.

This change caused these two test failures on Darwin CI:
Clang.Tooling.clang-check-mac-libcxx-abspath.cpp
Clang.Tooling.clang-check-mac-libcxx-relpath.cpp

https://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/37169/

More info in https://reviews.llvm.org/D157283
2023-08-23 14:50:02 -07:00
Dmitry Polukhin
f24aa691aa [clang] Match -isysroot behaviour with system compiler on Darwin
See discussion in https://reviews.llvm.org/D89001

I updated test to match actual behavior of
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
after that modified upstream to match the test.

Differential Revision: https://reviews.llvm.org/D157283
2023-08-23 18:10:18 +01:00
Fangrui Song
1c66d08b01 Rename warn_drv_overriding_flag_option (-Woverriding-t-option) to warn_drv_overriding_flag_option (-Woverriding-option)
warn_drv_overriding_flag_option was added for clang-cl `/T*` options (D1290) and its group name was planned to be renamed to overriding-option.
The name -Woverriding-t-option does not make sense for other uses,
mostly related to -ffp-model= related diagnostics.

Reviewed By: hans, skan, dexonsmith

Differential Revision: https://reviews.llvm.org/D158137
2023-08-18 09:15:37 -07:00
Jon Roelofs
1a135bceb6
[MachineOutliner][LTO] Enable outlining of linkonceodr functions on all targets.
... that have the outliner enabled.

Differential revision: https://reviews.llvm.org/D157925
2023-08-14 16:22:48 -07:00
Blue Gaston
11b7ce26f2 [ASanStableABI][Driver] Stop linking to asan dylib when stable abi is enabled
This patch enables linking of the static archive when fsanitize-stable-abi is set and stops linking to the asan dylib.

To link to the Address Sanitizer stable abi static library use "-fsanitize=address -fsanitize-stable-abi"

Updates a test with these flags.

rdar://112480890

Differential Revision: https://reviews.llvm.org/D156718
2023-08-02 11:30:29 -07:00
Cassie Jones
45ff63ba61 [Driver] Also warn about -mwatchos-version-min and -mtvos-version-min
Sometimes users pass this option when targeting embedded architectures like armv7m on non-darwin platforms.
This applies to watchOS and tvOS as well as iOS.

Depends on D155407

Reviewed By: MaskRay, ahatanak

Differential Revision: https://reviews.llvm.org/D155408
2023-07-17 13:26:52 -07:00
Cassie Jones
f7ad7d147b [Driver] Warn about all instances -mios-version-min not just the last
Follow-up to D155123, uniformly handle cases where there are duplicate
-mios-verion-min arguments.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D155407
2023-07-16 16:45:49 -07:00
Akira Hatanaka
509d051606 [Driver] Warn about -mios-version-min instead of erroring out when
targeting MachO embedded architectures

Sometimes users pass this option when targeting embedded architectures
like armv7m on non-darwin platforms.

Emit a warning instead of erroring out, which restores the behavior
prior to 34d7acd444b88342fc93fca202608c1e16fa5946.
2023-07-13 06:44:54 -07:00
Fangrui Song
62281227bf [Driver] Remove duplicate -e
-e has the LinkerInput flag (commit fcf8ada18f9cfb1261262e4b0399ae9ab40451f8)
and is rendered by AddLinkerInputs. We should remove duplicate rendering (e.g.,
`Args.AddAllArgs(CmdArgs, options::OPT_e)`).
2023-07-07 23:42:16 -07:00
Keith Smiley
2129cc1b3a
[clang][Darwin] Error out when missing requested libarclite library
Starting with the SDKs provided with Xcode 14.3, this library no longer
exists. Before this change this results in an opaque linker error in the
case that your deployment target is low enough that this library is
added. This produces a more useful error message in that case.

Differential Revision: https://reviews.llvm.org/D150988
2023-06-01 09:32:59 -07:00
Ellis Hoag
85af42df5d [lld] add context-sensitive PGO options for MachO
Enable support for CSPGO for lld MachO targets.

Since lld MachO does not support `-plugin-opt=`, we need to create the `--cs-profile-generate` and `--cs-profile-path=` options and propagate them in `Darwin.cpp`. These flags are not supported by ld64.

Also outline code into `getLastCSProfileGenerateArg()` to share between `CommonArgs.cpp` and `Darwin.cpp`.

CSPGO is already implemented for ELF (https://reviews.llvm.org/D56675) and COFF (https://reviews.llvm.org/D98763).

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D151589
2023-05-31 17:53:46 -07:00
Tim Northover
211055c744 AArch64: emit synchronous unwind for Darwin arm64_32 platforms too.
Since we're checking the triple directly, arm64_32 shows up differently and was
still getting an attempt at asynchronous unwind that added lots more
`__eh_frame` entries instead of the compact format.
2023-05-23 13:15:32 +01:00
Fangrui Song
67cbe1b859 Allow -fsanitize=function on all targets
Functions instrumented with -fsanitize=function have two words before
the function label: a signature and a RTTI proxy.
Instrumented call sites check the signature first to skip checks
for uninstrumented callees.

The code is generic and works for all targets supporting C++ RTTI.
Change clangDriver to allow all targets. Add tests for Armv8.5
Branch Target Identification and `-fpatchable-function-entry=`.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D148573
2023-05-19 07:59:37 -07:00
Julian Lettner
c3f0153ec2 [MachO] Disable atexit()-based lowering when LTO'ing kernel/kext code
The kernel and kext environments do not provide the `__cxa_atexit()`
function, so we can't use it for lowering global module destructors.

Unfortunately, just querying for "compiling for kernel/kext?" in the LTO
pipeline isn't possible (kernel/kext identifier isn't part of the triple
yet) so we need to pass down a CodeGen flag.

rdar://93536111

Differential Revision: https://reviews.llvm.org/D148967
2023-04-25 12:13:40 -07:00
David Tenty
2fe49ea0d0 [clang][PowerPC] Remove remaining Darwin support
POWER Darwin support in the backend has been removed for some time: https://discourse.llvm.org/t/rfc-remove-darwin-support-from-power-backends
but Clang still has the TargetInfo and other remnants lying around.

This patch does some cleanup and removes those and other related frontend support still remaining. We adjust any tests using the triple to either remove
the test if unneeded or switch to another Power triple.

Reviewed By: MaskRay, nemanjai

Differential Revision: https://reviews.llvm.org/D146459
2023-03-28 17:12:49 -04:00
usama hameed
665e32ee0f
[Sanitizers] Error out for -static-libsan on darwin
Differential Revision: https://reviews.llvm.org/D144672
2023-03-06 16:08:26 +05:00
usama hameed
6420daab19
Revert "[Sanitizers] Error out for -static-libsan on darwin"
This reverts commit 4e7d40e0928cfe448ba947d2a67895fccaa3535f.
2023-03-02 19:48:38 +05:00
usama hameed
4e7d40e092
[Sanitizers] Error out for -static-libsan on darwin
since it is not supported

Differential Revision: https://reviews.llvm.org/D144672
2023-03-02 00:07:03 +05:00
Archibald Elliott
8e3d7cf5de [NFC][TargetParser] Remove llvm/Support/TargetParser.h 2023-02-07 11:08:21 +00:00
usama hameed
57690a8ece [Sanitizers] fix -fno-sanitize-link-runtime for darwin
rdar://99200922

Differential Revision: https://reviews.llvm.org/D142421
2023-02-01 11:06:19 -08:00
Gregory Alfonso
9f5d881206 [NFC] Correct argument comment typo
For Darwin, the boolean being passed is called IsSimulator, not "IsImulator"

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D139547
2023-01-30 16:06:45 -08:00
Nico Weber
a5f446bc4b Revert "[clang][Darwin] Try to guess the SDK root with xcrun when unspecified"
This reverts commit ecade80d93960ad01d8665db02c23841e055a80f.
Breaks tests on macOS and tries to run xcrun on non-mac platforms,
see comments on https://reviews.llvm.org/D136315
2023-01-19 20:05:11 -05:00
Caleb Zulawski
ecade80d93 [clang][Darwin] Try to guess the SDK root with xcrun when unspecified
Picking up from https://reviews.llvm.org/D109460

Reviewed By: ldionne

Differential Revision: https://reviews.llvm.org/D136315
2023-01-18 18:20:59 +00:00
usama hameed
a44477b1f4 [CompilerRT] Remove ubsan static runtime on Apple
This patch removes the static ubsan runtime on Apple devices. The motivation
is to reduce the toolchain size.

rdar://102061519

Differential Revision: https://reviews.llvm.org/D141550
2023-01-17 14:33:31 -08:00
serge-sans-paille
a3c248db87
Move from llvm::makeArrayRef to ArrayRef deduction guides - clang/ part
This is a follow-up to https://reviews.llvm.org/D140896, split into
several parts as it touches a lot of files.

Differential Revision: https://reviews.llvm.org/D141139
2023-01-09 12:15:24 +01:00