71 Commits

Author SHA1 Message Date
Cameron McInally
a42bb8b57a
[Driver] Move CommonArgs to a location visible by the Frontend Drivers (#142800)
This patch moves the CommonArgs utilities into a location visible by the
Frontend Drivers, so that the Frontend Drivers may share option parsing
code with the Compiler Driver. This is useful when the Frontend Drivers
would like to verify that their incoming options are well-formed and
also not reinvent the option parsing wheel.

We already see code in the Clang/Flang Drivers that is parsing and
verifying its incoming options. E.g. OPT_ffp_contract. This option is
parsed in the Compiler Driver, Clang Driver, and Flang Driver, all with
slightly different parsing code. It would be nice if the Frontend
Drivers were not required to duplicate this Compiler Driver code. That
way there is no/low maintenance burden on keeping all these parsing
functions in sync.

Along those lines, the Frontend Drivers will now have a useful mechanism
to verify their incoming options are well-formed. Currently, the
Frontend Drivers trust that the Compiler Driver is not passing back junk
in some cases. The Language Drivers may even accept junk with no error
at all. E.g.:

  `clang -cc1 -mprefer-vector-width=junk test.c'

With this patch, we'll now be able to tighten up incomming options to
the Frontend drivers in a lightweight way.

---------

Co-authored-by: Cameron McInally <cmcinally@nvidia.com>
Co-authored-by: Shafik Yaghmour <shafik.yaghmour@intel.com>
2025-06-06 17:59:24 -04:00
Daniel Chen
2080334574
[flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX and LoP (#131041)
This PR is to improve the driver code to build `flang-rt` path by
re-using the logic and code of `compiler-rt`.

1. Moved `addFortranRuntimeLibraryPath` and `addFortranRuntimeLibs` to
`ToolChain.h` and made them virtual so that they can be overridden if
customization is needed. The current implementation of those two
procedures is moved to `ToolChain.cpp` as the base implementation to
default to.

2. Both AIX and PPCLinux now override `addFortranRuntimeLibs`. 
The overriding function of `addFortranRuntimeLibs` for both AIX and
PPCLinux calls `getCompilerRTArgString` => `getCompilerRT` =>
`buildCompilerRTBasename` to get the path to `flang-rt`. This code
handles `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR` setting. As shown in
`PPCLinux.cpp`, `FT_static` is the default. If not found, it will search
and build for `FT_shared`. To differentiate `flang-rt` from `clang-rt`,
a boolean flag `IsFortran` is passed to the chain of functions in order
to reach `buildCompilerRTBasename`.
2025-04-03 11:21:19 -04:00
Brad Smith
5912de9ede
[Driver][NetBSD] Remove support for NetBSD 8.x (#122513) 2025-01-10 14:46:43 -05:00
Nico Weber
50046221b8 Revert "[Driver] Cache SanitizerArgs (NFC) (#119442)"
This reverts commit bae383ba6b53b0d8257c83f99ceecdd751d0a378.
Prerequisite to reverting #119071.
2024-12-15 14:04:55 -05:00
Aaron Puchert
bae383ba6b
[Driver] Cache SanitizerArgs (NFC) (#119442)
The name getSanitizerArgs seems to mislead callers that this is a cheap
function, but it extracts the SanitizerArgs each time it is called.

So we try to reuse it a bit more.
2024-12-12 15:38:37 +01:00
Tarun Prabhu
1c0958bd95
[flang][Driver] Support -nostdlib and -nodefaultlibs (#108868)
This partially addresses some requests in #89888
2024-09-17 13:59:14 -06:00
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
Brad Smith
81617f8500
[Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (#83216)
…D, Fuchsia and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
2024-03-04 19:44:15 -05:00
Brad Smith
d5f77e112e
[Driver] Remove duplicate -r flag usage when linking (#82715)
Bug #82010
2024-03-02 21:33:59 -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
Brad Smith
f0ad2e9fda
[Driver] Make use of AddFilePathLibArgs() on NetBSD. (#71371)
This will help using lld or mold as a linker.
2023-11-15 13:36:16 -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
Brad Smith
760658c118
[Driver] Silence stdlib warning when linking C on *BSD / Solaris / Haiku (#70434)
Same as 12b87f6ef720080fab1e2d48ca2d8c5ba478ee5d and the addition to Gnu.
2023-11-01 04:28:55 -04:00
Brad Smith
a8e0acf660 [Driver][NFC] Fix a typo in the function name 2023-10-27 22:10:05 -04:00
Brad Smith
c149ff3d37
[Driver] Link Flang runtime on FreeBSD, NetBSD, OpenBSD, DragonFly and Haiku (#69817) 2023-10-27 04:43:19 -04:00
Brad Smith
15254eb740
[Driver] Clean up unused architecture related bits for *BSD's (#69809)
- FreeBSD removed big-endian arm with 12.0.
- OpenBSD never had big-endian arm support. I added it just in case, but it has
  never been used.
- Remove sparcel bits. It was sprinkled in a few places but it will never be a
  thing.
- Remove 32-bit sparc bits for FreeBSD. FreeBSD has never had 32-bit sparc
  support.
- Remove sparc64 IAS test as support was enabled across the board awhile ago.
2023-10-26 14:44:12 -04:00
Brad Smith
09b02f5d56 [Driver][NetBSD][NFC] Some cleaning up 2023-10-21 04:45:41 -04:00
Fangrui Song
993e839480
[Driver] Don't pass -Z to ld for ELF platforms (#69120)
-Z is an Apple ld64 option. ELF linkers don't recognize -Z, except
OpenBSD which patched GNU ld to add -Z for zmagic (seems unused)

> -Z Produce 'Standard' executables, disables Writable XOR Executable
features in resulting binaries.

Some `ToolChain`s have -Z due to copy-and-paste mistakes.
2023-10-15 19:12:35 -07:00
Brad Smith
894927b491
[Driver] Group together linker options using addAllArgs (#68349) 2023-10-12 00:34:19 -04:00
Brad Smith
8a4b9e9965
[Driver] Move assertion check before checking Output.isFilename (#67210) 2023-09-25 20:19:25 -04:00
Brad Smith
62ffbe0dcc
[Driver] Hook up NetBSD/riscv support (#67256) 2023-09-24 16:29:46 -04:00
Brad Smith
a009fa79a4
[Driver] Some improvements for path handling on NetBSD (#66863)
- Make use of concat macro with various paths
- Replace usage of = with SysRoot
2023-09-20 12:50:37 -04:00
Brad Smith
18b6e2139f
[Driver] Replace usage of -Bshareable linker flag with -shared (#65842)
The two flags mean the same thing for the bfd / lld linkers so just use
the same flag consistently everywhere.
2023-09-10 04:35:58 -04:00
Rainer Orth
779353e576 [Driver] Improve legibility of ld -z options on Solaris
Following the lead of the Linux code, this patch passes the `ld -z` options
as two separate args on Solaris, improving legibility.  For lack of a
variadic `std::push_back`, `getAsNeededOption` had to be changed to
`addAsNeededOption`, matching other `add*Options` functions, changing
callers accordingly.  The additional args are also used in a WIP revision
of the Solaris GNU ld patch D85309 <https://reviews.llvm.org/D85309>, which
will allow runtime selection of the linker to use.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D158955
2023-08-28 09:25:47 +02: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
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
Brad Smith
9a9827dc11 [Driver][NetBSD] Simplify NetBSD version handling
NetBSD 6.x and older is ancient. Remove now unnecessary version check.

Reviewed By: mgorny

Differential Revision: https://reviews.llvm.org/D146891
2023-03-27 00:01:42 -04:00
Brad Smith
e449e1dff9 [Driver] move NetBSD header search path management to the driver
This matches OpenBSD and FreeBSD. https://reviews.llvm.org/D138183

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D140817
2023-01-05 06:13:40 -05:00
Brad Smith
abc8f2b724 [Driver] Don't passs --dynamic-linker in -r mode
No behavior change as GNU ld/gold/ld.lld ignore --dynamic-linker in -r mode.
This change makes the intention clearer as we already suppress --dynamic-linker
for -shared, -static, and -static-pie.

Reviewed by: MaskRay, phosek

Differential Revision: https://reviews.llvm.org/D129714
2022-07-16 20:13:24 -04:00
Brad Smith
d241ce0f97 [Driver][NetBSD] -r: imply -nostdlib like GCC
Similar to D116843 for Gnu.cpp

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D119655
2022-02-14 23:29:13 -05:00
James Farrell
219672b8dd Revert "Revert "Use VersionTuple for parsing versions in Triple, fixing issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible.""
This reverts commit 63a6348cad6caccf285c1661bc60d8ba5a40c972.

Differential Revision: https://reviews.llvm.org/D115254
2021-12-07 23:15:21 +00:00
James Farrell
63a6348cad Revert "Use VersionTuple for parsing versions in Triple, fixing issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible."
This reverts commit 50324670342d9391f62671685f4d6b4880a4ea9a.
2021-12-06 17:35:26 +00:00
James Farrell
5032467034 Use VersionTuple for parsing versions in Triple, fixing issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible.
This reverts commit 40d5eeac6cd89a2360c3ba997cbaa816abca828c.

Differential Revision: https://reviews.llvm.org/D114885
2021-12-06 14:57:47 +00:00
Nikita Popov
40d5eeac6c Revert "Use VersionTuple for parsing versions in Triple. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible."
This reverts commit 1e8286467036d8ef1a972de723f805a4981b2692.

llvm/test/Transforms/LoopStrengthReduce/X86/2009-11-10-LSRCrash.ll fails
with assertion failure:

llc: /home/nikic/llvm-project/llvm/include/llvm/ADT/Optional.h:196: T& llvm::optional_detail::OptionalStorage<T, true>::getValue() & [with T = unsigned int]: Assertion `hasVal' failed.
...
 #8 0x00005633843af5cb llvm::MCStreamer::emitVersionForTarget(llvm::Triple const&, llvm::VersionTuple const&)
 #9 0x0000563383b47f14 llvm::AsmPrinter::doInitialization(llvm::Module&)
2021-11-30 18:36:32 +01:00
James Farrell
1e82864670 Use VersionTuple for parsing versions in Triple. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible.
See also https://github.com/android/ndk/issues/1455.

Differential Revision: https://reviews.llvm.org/D114163
2021-11-30 15:44:23 +00:00
Yaxun (Sam) Liu
0309e50f33 [Driver] Fix ToolChain::getSanitizerArgs
The driver uses class SanitizerArgs to store parsed sanitizer arguments. It keeps a cached
SanitizerArgs object in ToolChain and uses it for different jobs. This does not work if
the sanitizer options are different for different jobs, which could happen when an
offloading toolchain translates the options for different jobs.

To fix this, SanitizerArgs should be created by using the actual arguments passed
to jobs instead of the original arguments passed to the driver, since the toolchain
may change the original arguments. And the sanitizer arguments should be diagnose
once.

This patch also fixes HIP toolchain for handling -fgpu-sanitize: a warning is emitted
for GPU's not supporting sanitizer and skipped. This is for backward compatibility
with existing -fsanitize options. -fgpu-sanitize is also turned on by default.

Reviewed by: Artem Belevich, Evgenii Stepanov

Differential Revision: https://reviews.llvm.org/D111443
2021-11-11 17:17:08 -05:00
Frederic Cambus
ecef035953
[Driver][NetBSD] Use Triple reference instead of ToolChain.getTriple().
Differential Revision: https://reviews.llvm.org/D111805
2021-10-15 16:36:19 +02:00
Frederic Cambus
1f90b365bd
[Driver][NetBSD] Use ToolChain reference instead of getToolChain().
Differential Revision: https://reviews.llvm.org/D111340
2021-10-08 11:13:22 +02:00
Nico Weber
973519826e [clang-cl] Emit nicer warning on unknown /arch: arguments
Now prints the list of known archs. This requires plumbing a Driver
arg through a few functions.

Also add two more convenience insert() overlods to StringMap.

Differential Revision: https://reviews.llvm.org/D109105
2021-09-02 10:37:32 -04:00
Kazu Hirata
b8debabb77 [clang] Remove redundant calls to c_str() (NFC)
Identified with readability-redundant-string-cstr.
2021-08-31 08:53:51 -07:00
Fangrui Song
74933efeb6 [Driver] Detect Debian hack g++-multiarch-incdir.diff to simplify addLibStdCXXIncludePaths call sites 2021-03-21 17:33:31 -07:00
Serge Pavlov
70bf35070a [Driver] Add output file to properties of Command
Object of class `Command` contains various properties of a command to
execute, but output file was missed from them. This change adds this
property. It is required for reporting consumed time and memory implemented
in D78903 and may be used in other cases too.

Differential Revision: https://reviews.llvm.org/D78902
2020-10-08 18:23:39 +07:00
James Y Knight
4772b99dff Clang Driver: refactor support for writing response files to be
specified at Command creation, rather than as part of the Tool.

This resolves the hack I just added to allow Darwin toolchain to vary
its level of support based on `-mlinker-version=`.

The change preserves the _current_ settings for response-file support.
Some tools look likely to be declaring that they don't support
response files in error, however I kept them as-is in order for this
change to be a simple refactoring.

Differential Revision: https://reviews.llvm.org/D82782
2020-06-29 18:27:02 -04:00
Fangrui Song
b2b5cac3ec Default to -fuse-init-array
Very few ELF platforms still use .ctors/.dtors now.  Linux (glibc: 1999-07),
DragonFlyBSD, FreeBSD (2012-03) and Solaris have supported .init_array
for many years. Some architectures like AArch64/RISC-V default to
.init_array . GNU ld and gold can even convert .ctors to .init_array .

It makes more sense to flip the CC1 default, and only uses
-fno-use-init-array on platforms that don't support .init_array .
For example, OpenBSD did not support DT_INIT_ARRAY before Aug 2016
(86fa57a279)

I may miss some ELF platforms that still use .ctors, but their
maintainers can easily diagnose such problems.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D71393
2019-12-12 10:32:56 -08:00
Joerg Sonnenberger
cb92413c52 Fix -fuse-init-array decision logic on NetBSD
For NetBSD 9 and later, it is the default. On older versions, only ARM
and AArch64 use it by default.

llvm-svn: 375468
2019-10-21 23:35:33 +00:00
Pirama Arumuga Nainar
d60ff75b56 [Driver] Add -static-openmp driver option
Summary:
For Gnu, FreeBSD and NetBSD, this option forces linking with the static
OpenMP host runtime (similar to -static-libgcc and -static-libstdcxx).

Android's NDK will start the shared OpenMP runtime in addition to the static
libomp.  In this scenario, the linker will prefer to use the shared library by
default.  Add this option to enable linking with the static libomp.

Reviewers: Hahnfeld, danalbert, srhines, joerg, jdoerfert

Subscribers: guansong, cfe-commits

Tags: #clang

Fixes https://github.com/android-ndk/ndk/issues/1028

Differential Revision: https://reviews.llvm.org/D67200

llvm-svn: 371437
2019-09-09 18:31:41 +00:00
Jonas Devlieghere
2b3d49b610 [Clang] Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

Differential revision: https://reviews.llvm.org/D66259

llvm-svn: 368942
2019-08-14 23:04:18 +00:00
Pierre Gousseau
1e39fc1faa [asan] Add gcc 8's driver option -fsanitize=pointer-compare and -fsanitize=pointer-substract.
Disabled by default as this is still an experimental feature.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D59221

llvm-svn: 358285
2019-04-12 14:14:58 +00:00
Nico Weber
885b790f89 Remove esan.
It hasn't seen active development in years, and it hasn't reached a
state where it was useful.

Remove the code until someone is interested in working on it again.

Differential Revision: https://reviews.llvm.org/D59133

llvm-svn: 355862
2019-03-11 20:23:40 +00:00