aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/ToolChain.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-03-11[clang][ARM] Refactor ComputeLLVMTriple code for ARMDavid Spickett1-122/+2
This moves code that sets the architecture name and Float ABI into two new functions in ToolChains/Arch/ARM.cpp. Greatly simplifying ComputeLLVMTriple. Some light refactoring in setArchNameInTriple to move local variables closer to their first use. Reviewed By: ostannard Differential Revision: https://reviews.llvm.org/D98253
2021-03-02[clang+lld] Pass -platform_version args to ld64.lldJez Ng1-3/+3
Fix regression where we aren't passing `-platform_version` to new ld64.lld after {D95204}. Most of the changes were originally in D95204, but I backed them out due to test failures on builds which have `CLANG_DEFAULT_LINKER=lld`. The tests are properly updated in this diff. Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D97741
2021-03-01[lld-macho] Partial revert of D95204Jez Ng1-3/+3
Trying to unbreak https://lab.llvm.org/buildbot/#/builders/57/builds/4753 I'm not able to repro the failures locally so... here's hoping
2021-03-01[lld-macho] Switch default to new Darwin backendJez Ng1-3/+3
The new Darwin backend for LLD is now able to link reasonably large real-world programs on x86_64. For instance, we have achieved self-hosting for the X86_64 target, where all LLD tests pass when building lld with itself on macOS. As such, we would like to make it the default back-end. The new port is now named `ld64.lld`, and the old port remains accessible as `ld64.lld.darwinold` This [annoucement email][1] has some context. (But note that, unlike what the email says, we are no longer doing this as part of the LLVM 12 branch cut -- instead we will go into LLVM 13.) Numerous mechanical test changes were required to make this change; in the interest of creating something that's reviewable on Phabricator, I've split out the boring changes into a separate diff (D95905). I plan to merge its contents with those in this diff before landing. (@gkm made the original draft of this diff, and he has agreed to let me take over.) [1]: https://lists.llvm.org/pipermail/llvm-dev/2021-January/147665.html Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D95204
2021-02-25[Android] Use -l:libunwind.a with --rtlib=compiler-rtRyan Prichard1-3/+6
On Android, the unwinder isn't part of the C++ STL and isn't (in older versions) exported from libc.so. Instead, the driver links the static unwinder archive implicitly. Currently, the Android NDK implicitly links libgcc.a to provide both builtins and the unwinder. To support switching to compiler-rt builtins and libunwind, make --rtlib=compiler-rt behave the same way on Android, and implicitly pass -l:libunwind.a to the linker. Adjust the -ldl logic. For the Android NDK, the unwinder (whether libgcc.a or libunwind.a) is linked statically and calls a function in the dynamic loader for finding unwind tables (e.g. dl_iterate_phdr). On Android, this function is in libc.a for static executables and libdl.so otherwise, so -ldl is needed. (glibc doesn't need -ldl because its libc.so exports dl_iterate_phdr.) Differential Revision: https://reviews.llvm.org/D96403
2021-02-24Reland "[Driver][Windows] Support per-target runtimes dir layout for profile ↵Markus Böck1-6/+15
instr generate" This relands commit rG7f9d5d6e444c which was reverted in rGab5b00ada9e7 Differential Revision: https://reviews.llvm.org/D96638
2021-02-23Revert "[Driver][Windows] Support per-target runtimes dir layout for profile ↵Nico Weber1-19/+9
instr generate" This reverts commit 7f9d5d6e444c91ce6f2e377b312ac573dfc6779a. Breaks check-clang everywhere, see https://reviews.llvm.org/D96638#2583608
2021-02-23[Driver][Windows] Support per-target runtimes dir layout for profile instr ↵zero91781-9/+19
generate When targeting a MSVC triple, --dependant-libs with the name of the clang runtime library for profiling is added to the command line args. In it's current implementations clang_rt.profile-<ARCH> is chosen as the name. When building a distribution using LLVM_ENABLE_PER_TARGET_RUNTIME_DIR this fails, due to the runtime file names not having an architecture suffix in the filename. This patch refactors getCompilerRT and getCompilerRTBasename to always consider per-target runtime directories. getCompilerRTBasename now simply returns the filename component of the path found by getCompilerRT Differential Revision: https://reviews.llvm.org/D96638
2021-02-18[HIP] Support device sanitizerYaxun (Sam) Liu1-0/+5
Add option -fgpu-sanitize to enable sanitizer for AMDGPU target. Since it is experimental, it is off by default. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D96835
2021-02-10Revert "Revert "[clang][driver] Only warn once about invalid library values""Tom Weaver1-21/+41
This reverts commit a743702a1f4880e4492196b1ce9a9a63e0b4c075. Test was fixed in c6a1b16db7dc7a0af8951b39f29ddbe639a98a3b
2021-02-10Revert "[clang][driver] Only warn once about invalid library values"Tom Weaver1-41/+21
This reverts commit a6439b52088b1d58d8e7aa9891c9011648710593. Caused buildbot failure http://lab.llvm.org:8014/#/builders/125/builds/125
2021-02-10[clang][driver] Only warn once about invalid library valuesTimm Bäder1-21/+41
Since ToolChain::GetCXXStdlibType() is a simple getter that might emit the "invalid library name in argument" warning, it can conceivably be called several times while initializing the build pipeline. Before this patch, a simple 'clang++ -stdlib=foo ./test.cpp' would print the warning twice, -rt=lib=foo would print 6 times. Change this and always only print the warning once. Keep the rest of the semantics of the functions. Differential Revision: https://reviews.llvm.org/D95915
2021-02-04[clang][Arm] Fix handling of -Wa,-march=David Spickett1-2/+13
This fixes Bugzilla #48894 for Arm, where it was reported that -Wa,-march was not being handled by the integrated assembler. This was previously fixed for -Wa,-mthumb by parsing the argument in ToolChain::ComputeLLVMTriple instead of CollectArgsForIntegratedAssembler. It has to be done in the former because the Triple is read only by the time we get to the latter. Previously only mcpu would work via -Wa but only because "-target-cpu" is it's own option to cc1, which we were able to modify. Target architecture is part of "-target-triple". This change applies the same workaround to -march and cleans up handling of -Wa,-mcpu at the same time. There were some places where we were not using the last instance of an argument. The existing -Wa,-mthumb code was doing this correctly, so I've just added tests to confirm that. Now the same rules will apply to -Wa,-march/-mcpu as would if you just passed them to the compiler: * -Wa/-Xassembler options only apply to assembly files. * Architecture derived from mcpu beats any march options. * When there are multiple mcpu or multiple march, the last one wins. * If there is a compiler option and an assembler option of the same type, we prefer the one that fits the input type. * If there is an applicable mcpu option but it is overruled by an march, the cpu value is still used for the "-target-cpu" cc1 option. Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D95872
2021-01-02[PowerPC] Support powerpcle target in Clang [3/5]Brandon Bergren1-0/+2
Add powerpcle support to clang. For FreeBSD, assume a freestanding environment for now, as we only need it in the first place to build loader, which runs in the OpenFirmware environment instead of the FreeBSD environment. For Linux, recognize glibc and musl environments to match current usage in Void Linux PPC. Adjust driver to match current binutils behavior regarding machine naming. Adjust and expand tests. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D93919
2020-12-03[Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.Ahmed Bougacha1-1/+7
This also teaches MachO writers/readers about the MachO cpu subtype, beyond the minimal subtype reader support present at the moment. This also defines a preprocessor macro to allow users to distinguish __arm64__ from __arm64e__. arm64e defaults to an "apple-a12" CPU, which supports v8.3a, allowing pointer-authentication codegen. It also currently defaults to ios14 and macos11. Differential Revision: https://reviews.llvm.org/D87095
2020-12-03arm64: count Triple::aarch64_32 as an aarch64 target and enable leaf frame ↵Tim Northover1-2/+2
pointers
2020-11-24clang: Pass -platform-version to new MachO LLDNico Weber1-2/+7
New MachO LLD doesn't implement the old -macos_version_min (etc) flags, but it understands the modern platform_version flag. So make the clang driver pass that when using new MachO LLD. Also, while here, don't pass -lto_library to LLD, since it links in LTO libraries statically (which it can because it's versioned alongside clang). Differential Revision: https://reviews.llvm.org/D92037
2020-11-24clang+lld: Improve clang+ld.darwinnew.lld interaction, pass -demangleNico Weber1-2/+9
This patch: - adds an ld64.lld.darwinnew symlink for lld, to go with f2710d4b576, so that `clang -fuse-ld=lld.darwinnew` can be used to test new Mach-O lld while it's in bring-up. (The expectation is that we'll remove this again once new Mach-O lld is the defauld and only Mach-O lld.) - lets the clang driver know if the linker is lld (currently only triggered if `-fuse-ld=lld` or `-fuse-ld=lld.darwinnew` is passed). Currently only used for the next point, but could be used to implement other features that need close coordination between compiler and linker, e.g. having a diag for calling `clang++` instead of `clang` when link errors are caused by a missing C++ stdlib. - lets the clang driver pass `-demangle` to Mach-O lld (both old and new), in addition to ld64 - implements -demangle for new Mach-O lld - changes demangleItanium() to accept _Z, __Z, ___Z, ____Z prefixes (and updates one test added in D68014). Mach-O has an extra underscore for symbols, and the three (or, on Mach-O, four) underscores are used for block names. Differential Revision: https://reviews.llvm.org/D91884
2020-10-30[clang][driver] Rename DriverOption as NoXarchOption (NFC)Andrzej Warzynski1-5/+8
As discussed in [1], ClangFlags::DriverOption is currently only used to mark options that should not be forwarded to other tools via `-Xarch` options. This patch renames this flag accordingly and updates the corresponding driver diagnostic. A comment in ToolChain::TranslateXarchArgs is also updated to reflect the change. The original comment referred to isDriverOption(), which is no longer available. [1] http://lists.llvm.org/pipermail/cfe-dev/2020-October/066953.html Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D89799
2020-10-21[Driver] Incorporate -mfloat-abi in the computed triple on ARMJohn Brawn1-0/+31
LLVM assumes that when it creates a call to a C library function it can use the C calling convention. On ARM the effective calling convention is determined from the target triple, however using -mfloat-abi=hard on ARM means that calls to (and definitions of) C library functions use the arm_aapcs_vfpcc calling convention which can result in a mismatch. Fix this by incorporating -mfloat-abi into the target triple, similar to how -mbig-endian and -march/-mcpu are. This only works for EABI targets and not Android or iOS, but there the float abi is fixed so instead give an error. Fixes PR45524 Differential Revision: https://reviews.llvm.org/D89573
2020-10-03Revert "[Driver] Move detectLibcxxIncludePath to ToolChain"Nico Weber1-23/+0
This reverts commit e25bf2592060e7751f8b14522c97081ce2047175. Breaks tests on Windows, see comments on https://reviews.llvm.org/D88452
2020-10-02[Driver] Move detectLibcxxIncludePath to ToolChainPetr Hosek1-0/+23
This helper method is useful even outside of Gnu toolchains, so move it to ToolChain so it can be reused in other toolchains such as Fuchsia. Differential Revision: https://reviews.llvm.org/D88452
2020-10-02Revert "[Driver] Move detectLibcxxIncludePath to ToolChain"Petr Hosek1-23/+0
This reverts commit a594fd28e373cb7cd348cf01f6a90e055bf6cf6d which is failign on some bots.
2020-10-02[Driver] Move detectLibcxxIncludePath to ToolChainPetr Hosek1-0/+23
This helper method is useful even outside of Gnu toolchains, so move it to ToolChain so it can be reused in other toolchains such as Fuchsia. Differential Revision: https://reviews.llvm.org/D88452
2020-09-28[clang][driver][AIX] Set compiler-rt as default rtlibDavid Tenty1-0/+2
Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D88182
2020-09-19[Driver] Add disabled-by-default -Wuse-ld-path for the deprecation warning ↵Fangrui Song1-1/+1
for -fuse-ld=/abs/path The warning is currently not under a -W option, so it cannot be suppressed. This is annoying for the widespread build system Bazel when specifying the path to gold https://github.com/bazelbuild/bazel/commit/cdd0c3cdba270115940e8ca5ec8104cbcd694671 I have notified them about using --ld-path= forwards https://github.com/bazelbuild/bazel/pull/8580#issuecomment-694321543 but we have to give some transitional period. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D87837
2020-09-17[RISCV] Support Shadow Call StackZhaoshi Zheng1-1/+2
Currenlty assume x18 is used as pointer to shadow call stack. User shall pass flags: "-fsanitize=shadow-call-stack -ffixed-x18" Runtime supported is needed to setup x18. If SCS is desired, all parts of the program should be built with -ffixed-x18 to maintain inter-operatability. There's no particuluar reason that we must use x18 as SCS pointer. Any register may be used, as long as it does not have designated purpose already, like RA or passing call arguments. Differential Revision: https://reviews.llvm.org/D84414
2020-08-27Add an unsigned shift base sanitizerJF Bastien1-8/+8
It's not undefined behavior for an unsigned left shift to overflow (i.e. to shift bits out), but it has been the source of bugs and exploits in certain codebases in the past. As we do in other parts of UBSan, this patch adds a dynamic checker which acts beyond UBSan and checks other sources of errors. The option is enabled as part of -fsanitize=integer. The flag is named: -fsanitize=unsigned-shift-base This matches shift-base and shift-exponent flags. <rdar://problem/46129047> Differential Revision: https://reviews.llvm.org/D86000
2020-08-13[clang][Driver] Default to /usr/bin/ld on SolarisRainer Orth1-2/+7
`clang` currently requires the native linker on Solaris: - It passes `-C` to `ld` which GNU `ld` doesn't understand. - To use `gld`, one needs to pass the correct `-m EMU` option to select the right emulation. Solaris `ld` cannot handle that option. So far I've worked around this by passing `-DCLANG_DEFAULT_LINKER=/usr/bin/ld` to `cmake`. However, if someone forgets this, it depends on the user's `PATH` whether or not `clang` finds the correct linker, which doesn't make for a good user experience. While it would be nice to detect the linker flavor at runtime, this is more involved. Instead, this patch defaults to `/usr/bin/ld` on Solaris. This doesn't work on its own, however: a link fails with clang-12: error: unable to execute command: Executable "x86_64-pc-solaris2.11-/usr/bin/ld" doesn't exist! I avoid this by leaving absolute paths alone in `ToolChain::GetLinkerPath`. Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and `x86_64-pc-linux-gnu`. Differential Revision: https://reviews.llvm.org/D84029
2020-07-20[Driver] Add --ld-path= and deprecate -fuse-ld=/abs/path and -fuse-ld=rel/pathFangrui Song1-4/+28
Supersedes D80225. Add --ld-path= to avoid strange target specific prefixes and make -fuse-ld= focus on its intended job: "linker flavor". (-f* affects generated code or language features. --ld-path does not affect codegen, so it is not named -f*) The way --ld-path= works is similar to "Command Search and Execution" in POSIX.1-2017 2.9.1 Simple Commands. If --ld-path= specifies * an absolute path, the value specifies the linker. * a relative path without a path component separator (/), the value is searched using the -B, COMPILER_PATH, then PATH. * a relative path with a path component separator, the linker is found relative to the current working directory. -fuse-ld= and --ld-path= can be composed, e.g. `-fuse-ld=lld --ld-path=/usr/bin/ld.lld` The driver can base its linker option decision on the flavor -fuse-ld=, but it should not do fragile flavor checking with --ld-path=. Reviewed By: whitequark, keith Differential Revision: https://reviews.llvm.org/D83015
2020-07-16[WebAssembly] Triple::wasm64 related cleanupWouter van Oortmerssen1-6/+3
Differential Revision: https://reviews.llvm.org/D83713
2020-06-22Add Statically Linked LibrariesAaron En Ye Shi1-0/+18
Add GNU Static Lib Tool, which supports the --emit-static-lib flag. For HIP, a static library archive will be created and consist of HIP Fat Binary host object with the device images embedded. Using llvm-ar to create the static archive. Also, delete existing output file to ensure a new archive is created each time. Reviewers: yaxunl, tra, rjmccall, echristo Subscribers: echristo, JonChesterfield, scchan, msearles Differential Revision: https://reviews.llvm.org/D78759
2020-06-17[Driver] Search computed sysroot for libc++ header pathsRyan Prichard1-0/+4
Summary: The Android NDK's clang driver is used with an Android -target setting, and the driver automatically finds the Android sysroot at a path relative to the driver. The sysroot has the libc++ headers in it. Remove Hurd::computeSysRoot as it is equivalent to the new ToolChain::computeSysRoot method. Fixes PR46213. Reviewers: srhines, danalbert, #libc, kristina Reviewed By: srhines, danalbert Subscribers: ldionne, sthibaul, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D81622
2020-06-06recommit "[HIP] Add default header and include path"Yaxun (Sam) Liu1-0/+3
recommit 11d06b9511bd25aabbfad10dff548b0ce29135a5 with fix for lit tests.
2020-06-05Revert "recommit "[HIP] Add default header and include path""Nico Weber1-3/+0
This reverts commit 1fa43e0b34d9736f62c6c1b6c371a5e39cd1624d. Still breaks tests on several bots, see https://reviews.llvm.org/D81176
2020-06-05recommit "[HIP] Add default header and include path"Yaxun (Sam) Liu1-0/+3
recommit 11d06b9511bd25aabbfad10dff548b0ce29135a5 with fix for lit tests.
2020-06-05Revert "[HIP] Add default header and include path"Yaxun (Sam) Liu1-3/+0
This reverts commit 11d06b9511bd25aabbfad10dff548b0ce29135a5.
2020-06-05[HIP] Add default header and include pathYaxun (Sam) Liu1-0/+3
To support std::complex and some other standard C/C++ functions in HIP device code, they need to be forced to be __host__ __device__ functions by pragmas. This is done by some clang standard C++ wrapper headers which are shared between cuda-clang and hip-Clang. For these standard C++ wapper headers to work properly, specific include path order has to be enforced: clang C++ wrapper include path standard C++ include path clang include path Also, these C++ wrapper headers require device version of some standard C/C++ functions must be declared before including them. This needs to be done by including a default header which declares or defines these device functions. The default header is always included before any other headers are included by users. This patch adds the the default header and include path for HIP. Differential Revision: https://reviews.llvm.org/D81176
2020-05-29[clang] [Darwin] Add reverse mappings for aarch64/aarch64_32 to darwin arch ↵Martin Storsjö1-2/+5
names These are mapped in MachO::getMachOArchName already, but were missing in ToolChain::getDefaultUniversalArchName. Having these reverse mapped here fixes weird inconsistencies like -dumpmachine showing a target triple like "aarch64-apple-darwin", while "clang -target aarch64-apple-darwin" didn't use to work (ended up mapped as unknown-apple-ios). Differential Revision: https://reviews.llvm.org/D79117
2020-05-27[Driver] Support -fsanitize=shadow-call-stack and cfi-icall on aarch64_beFangrui Song1-6/+3
D80647 did not fix https://bugs.llvm.org/show_bug.cgi?id=46076 This is the fix.
2020-05-08[Driver] Don't pass -u__llvm_profile_runtime for clang -fprofile-arcs a.oFangrui Song1-13/+10
clang --coverage a.o # InstrProfilingRuntime.cpp.o not linked in clang --fprofile-arcs a.o # InstrProfilingRuntime.cpp.o unexpectedly linked in Fix --fprofile-arcs.
2020-05-08[Driver] Don't warn -Wunused-command-line-argument for --coverage ↵Fangrui Song1-3/+3
-ftest-coverage -fprofile-arcs
2020-04-28[Windows] Autolink with basenames and add libdir to libpathReid Kleckner1-7/+22
Prior to this change, for a few compiler-rt libraries such as ubsan and the profile library, Clang would embed "-defaultlib:path/to/rt-arch.lib" into the .drective section of every object compiled with -finstr-profile-generate or -fsanitize=ubsan as appropriate. These paths assume that the link step will run from the same working directory as the compile step. There is also evidence that sometimes the paths become absolute, such as when clang is run from a different drive letter from the current working directory. This is fragile, and I'd like to get away from having paths embedded in the object if possible. Long ago it was suggested that we use this for ASan, and apparently I felt the same way back then: https://reviews.llvm.org/D4428#56536 This is also consistent with how all other autolinking usage works for PS4, Mac, and Windows: they all use basenames, not paths. To keep things working for people using the standard GCC driver workflow, the driver now adds the resource directory to the linker library search path when it calls the linker. This is enough to make check-ubsan pass, and seems like a generally good thing. Users that invoke the linker directly (most clang-cl users) will have to add clang's resource library directory to their linker search path in their build system. I'm not sure where I can document this. Ideally I'd also do it in the MSBuild files, but I can't figure out where they go. I'd like to start with this for now. Reviewed By: hans Differential Revision: https://reviews.llvm.org/D65543
2020-03-24[CUDA][HIP] Add -Xarch_device and -Xarch_host optionsYaxun (Sam) Liu1-5/+58
The argument after -Xarch_device will be added to the arguments for CUDA/HIP device compilation and will be removed for host compilation. The argument after -Xarch_host will be added to the arguments for CUDA/HIP host compilation and will be removed for device compilation. Differential Revision: https://reviews.llvm.org/D76520
2020-03-22[NFC] Refactor handling of Xarch optionYaxun (Sam) Liu1-0/+30
Extract common code to a function. To prepare for adding an option for CUDA/HIP host and device only option. Differential Revision: https://reviews.llvm.org/D76455
2020-02-12clang: Guess at some platform FTZ/DAZ default settingsMatt Arsenault1-10/+17
This is to avoid performance regressions when the default attribute behavior is fixed to assume ieee. I tested the default on x86_64 ubuntu, which seems to default to FTZ/DAZ, but am guessing for x86 and PS4.
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-12/+14
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-15Revert "[OPENMP]Do not use RTTI by default for NVPTX devices."Alexey Bataev1-2/+1
This reverts commit 23058f9dd4d7e18239fd63b6da52549514b45fda. It breaks builds of cuda code somehow in some cases.
2020-01-14[OPENMP]Do not use RTTI by default for NVPTX devices.Alexey Bataev1-1/+2
NVPTX does not support RTTI, so disable it by default.
2019-12-17[Driver] Avoid copies in range-based for loopsMark de Wever1-1/+1
This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall. Differential Revision: https://reviews.llvm.org/D71527