aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF/DriverUtils.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-12-11Rework the `Option` library to reduce dynamic relocations (#119198)Chandler Carruth1-6/+8
Apologies for the large change, I looked for ways to break this up and all of the ones I saw added real complexity. This change focuses on the option's prefixed names and the array of prefixes. These are present in every option and the dominant source of dynamic relocations for PIE or PIC users of LLVM and Clang tooling. In some cases, 100s or 1000s of them for the Clang driver which has a huge number of options. This PR addresses this by building a string table and a prefixes table that can be referenced with indices rather than pointers that require dynamic relocations. This removes almost 7k dynmaic relocations from the `clang` binary, roughly 8% of the remaining dynmaic relocations outside of vtables. For busy-boxing use cases where many different option tables are linked into the same binary, the savings add up a bit more. The string table is a straightforward mechanism, but the prefixes required some subtlety. They are encoded in a Pascal-string fashion with a size followed by a sequence of offsets. This works relatively well for the small realistic prefixes arrays in use. Lots of code has to change in order to land this though: both all the option library code has to be updated to use the string table and prefixes table, and all the users of the options library have to be updated to correctly instantiate the objects. Some follow-up patches in the works to provide an abstraction for this style of code, and to start using the same technique for some of the other strings here now that the infrastructure is in place.
2024-11-24[ELF] --reproduce: strip directories for --dependency-file=Fangrui Song1-0/+1
CMake may generate build.ninja with DEP_FILE specifying a non-existent directory in the reproduce tarball.
2024-11-16[ELF] Replace functions bAlloc/saver/uniqueSaver with member accessFangrui Song1-2/+2
2024-11-16[ELF] Make Ctx inherit from CommonLinkerContextFangrui Song1-3/+3
link calls `new CommonLinkerContext`. Now that `Ctx ctx` is a local variable, we can make it inherit from CommonLinkerContext.
2024-11-16[ELF] Remove unneeded Twine()Fangrui Song1-2/+1
2024-11-16[lld] Use context-aware outs() and errs()Fangrui Song1-6/+7
2024-11-16[ELF] Pass ctx &Fangrui Song1-2/+3
2024-11-16[ELF] Pass ctx to bAlloc/saver/uniqueSaverFangrui Song1-2/+2
2024-11-14[ELF] Migrate away from global ctxFangrui Song1-2/+2
2024-11-14[ELF] Migrate away from global ctxFangrui Song1-3/+4
2024-11-06[ELF] Replace error(...) with ErrAlways or ErrFangrui Song1-6/+7
Most are migrated to ErrAlways mechanically. In the future we should change most to Err.
2024-10-11[ELF] Pass Ctx &Fangrui Song1-4/+5
2024-10-06[ELF] Pass Ctx & to InputFilesFangrui Song1-7/+8
2024-09-25[ELF] Pass Ctx & to DriverFangrui Song1-1/+1
2024-09-21[ELF] Replace config-> with ctx.arg.Fangrui Song1-6/+6
2024-04-19[ELF] Add --default-script/-dTFangrui Song1-0/+1
GNU ld added --default-script (alias: -dT) in 2007. The option specifies a default script that is processed if --script/-T is not specified. -dT can be used to override GNU ld's internal linker script, but only when the application does not specify -T. In addition, dynamorio's CMakeLists.txt may use -dT. The implementation is simple and the feature can be useful to dabble with different section layouts. Pull Request: https://github.com/llvm/llvm-project/pull/89327
2024-01-22[lld] Use SmallString::operator std::string (NFC)Kazu Hirata1-1/+1
2023-08-04[llvm] Extract common `OptTable` bits into macrosJan Svoboda1-3/+1
All command-line tools using `llvm::opt` create an enum of option IDs and a table of `OptTable::Info` object. Most of the tools use the same ID (`OPT_##ID`), kind (`Option::KIND##Class`), group ID (`OPT_##GROUP`) and alias ID (`OPT_##ALIAS`). This patch extracts that common code into canonical macros. This results in fewer changes when tweaking the `OPTION` macros emitted by the TableGen backend. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D157028
2023-06-05[lld] StringRef::{starts,ends}with => {starts,ends}_with. NFCFangrui Song1-2/+2
The latter form is now preferred to be similar to C++20 starts_with. This replacement also removes one function call when startswith is not inlined.
2023-04-26[ELF] Add --remap-inputs= and --remap-inputs-file=Fangrui Song1-0/+1
--remap-inputs-file= can be specified multiple times, each naming a remap file that contains `from-glob=to-file` lines or `#`-led comments. ('=' is used a separator a la -fdebug-prefix-map=) --remap-inputs-file= can be used to: * replace an input file. E.g. `"*/libz.so=exp/libz.so"` can replace a resolved `-lz` without updating the input file list or (if used) a response file. When debugging an application where a bug is isolated to one single input file, this option gives a convenient way to test fixes. * remove an input file with `/dev/null` (changed to `NUL` on Windows), e.g. `"a.o=/dev/null"`. A build system may add unneeded dependencies. This option gives a convenient way to test the result removing some inputs. `--remap-inputs=a.o=aa.o` can be specified to provide one pattern without using an extra file. (bash/zsh process substitution is handy for specifying a pattern without using a remap file, e.g. `--remap-inputs-file=<(printf 'a.o=aa.o')`, but it may be unavailable in some systems. An extra file can be inconvenient for a build system.) Exact patterns are tested before wildcard patterns. In case of a tie, the first patterns wins. This is an implementation detail that users should not rely on. Co-authored-by: Marco Elver <elver@google.com> Link: https://discourse.llvm.org/t/rfc-support-exclude-inputs/70070 Reviewed By: melver, peter.smith Differential Revision: https://reviews.llvm.org/D148859
2023-02-10[NFC][TargetParser] Replace uses of llvm/Support/Host.hArchibald Elliott1-1/+1
The forwarding header is left in place because of its use in `polly/lib/External/isl/interface/extract_interface.cc`, but I have added a GCC warning about the fact it is deprecated, because it is used in `isl` from where it is included by Polly.
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott1-1/+1
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-01-12[OptTable] Precompute OptTable prefixes union table through tablegenserge-sans-paille1-1/+1
This avoid rediscovering this table when reading each options, providing a sensible 2% speedup when processing and empty file, and a measurable speedup on typical workloads, see: This is optional, the legacy, on-the-fly, approach can still be used through the GenericOptTable class, while the new one is used through PrecomputedOptTable. https://llvm-compile-time-tracker.com/compare.php?from=4da6cb3202817ee2897d6b690e4af950459caea4&to=19a492b704e8f5c1dea120b9c0d3859bd78796be&stat=instructions:u Differential Revision: https://reviews.llvm.org/D140800
2022-12-27[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-1/+4
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This a recommit of e953ae5bbc313fd0cc980ce021d487e5b5199ea4 and the subsequent fixes caa713559bd38f337d7d35de35686775e8fb5175 and 06b90e2e9c991e211fecc97948e533320a825470. The above patchset caused some version of GCC to take eons to compile clang/lib/Basic/Targets/AArch64.cpp, as spotted in aa171833ab0017d9732e82b8682c9848ab25ff9e. The fix is to make BuiltinInfo tables a compilation unit static variable, instead of a private static variable. Differential Revision: https://reviews.llvm.org/D139881
2022-12-25Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵Vitaly Buka1-4/+1
builtin and call information" Revert "Fix lldb option handling since e953ae5bbc313fd0cc980ce021d487e5b5199ea4 (part 2)" Revert "Fix lldb option handling since e953ae5bbc313fd0cc980ce021d487e5b5199ea4" GCC build hangs on this bot https://lab.llvm.org/buildbot/#/builders/37/builds/19104 compiling CMakeFiles/obj.clangBasic.dir/Targets/AArch64.cpp.d The bot uses GNU 11.3.0, but I can reproduce locally with gcc (Debian 12.2.0-3) 12.2.0. This reverts commit caa713559bd38f337d7d35de35686775e8fb5175. This reverts commit 06b90e2e9c991e211fecc97948e533320a825470. This reverts commit e953ae5bbc313fd0cc980ce021d487e5b5199ea4.
2022-12-24[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-1/+4
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This is a recommit of 719d98dfa841c522d8d452f0685e503538415a53 that into account a GGC issue (probably https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92181) when dealing with intiailizer_list and constant expressions. Workaround this by avoiding initializer list, at the expense of a temporary plain old array. Differential Revision: https://reviews.llvm.org/D139881
2022-12-23Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵serge-sans-paille1-3/+2
builtin and call information" There are still remaining issues with GCC 12, see for instance https://lab.llvm.org/buildbot/#/builders/93/builds/12669 This reverts commit 5ce4e92264102de21760c94db9166afe8f71fcf6.
2022-12-23[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-2/+3
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This is a recommit of 719d98dfa841c522d8d452f0685e503538415a53 with a change to llvm/utils/TableGen/OptParserEmitter.cpp to cope with GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108158 Differential Revision: https://reviews.llvm.org/D139881
2022-12-23Revert "[clang] Use a StringRef instead of a raw char pointer to store ↵serge-sans-paille1-3/+2
builtin and call information" Failing builds: https://lab.llvm.org/buildbot#builders/9/builds/19030 This is GCC specific and has been reported upstream: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108158 This reverts commit 719d98dfa841c522d8d452f0685e503538415a53.
2022-12-23[clang] Use a StringRef instead of a raw char pointer to store builtin and ↵serge-sans-paille1-2/+3
call information This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u Differential Revision: https://reviews.llvm.org/D139881
2022-12-08Store OptTable::Info::Name as a StringRefserge-sans-paille1-1/+1
This is a recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e, with a few cleanups. This avoids implicit conversion to StringRef at several points, which in turns avoid redundant calls to strlen. As a side effect, this greatly simplifies the implementation of StrCmpOptionNameIgnoreCase. It also eventually gives a consistent, humble speedup in compilation time (timing updated since original commit). https://llvm-compile-time-tracker.com/compare.php?from=de4b6a1bc64db33643f001ad45fae7b92b4a4688&to=c23a93d1292052b4be2fbe8c586fa31143d0c7ed&stat=instructions:u Differential Revision: https://reviews.llvm.org/D139274
2022-11-26[ELF] Change most llvm::Optional to std::optionalFangrui Song1-12/+13
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-10-01[ELF] Move driver into ctx and remove indirection. NFCFangrui Song1-1/+1
This removes one global variable and removes GOT and unique_ptr indirection.
2022-08-01[ELF] --reproduce: strip directories for --print-archive-stats= and ↵Fangrui Song1-2/+6
--why-extract= Similar to -o and -Map.
2022-07-29[ELF] Strip directories for -Map when emitting reproducer rspAlex Brachet1-3/+5
Similarly to -o output directories will not be created so -Map being copied verbatim will likely cause ld.lld @response.txt to fail. Differential Revision: https://reviews.llvm.org/D130681
2022-07-25[ELF] --reproduce: support --export-dynamic-symbol-listFangrui Song1-0/+1
2022-07-25[ELF] Simplify --build-id/--color-diagnostics with AliasArgs. NFCFangrui Song1-13/+6
2022-02-07[ELF] Clean up headers. NFCFangrui Song1-3/+1
2022-01-20Re-land [LLD] Remove global state in lldCommonAlexandre Ganea1-4/+3
Move all variables at file-scope or function-static-scope into a hosting structure (lld::CommonLinkerContext) that lives at lldMain()-scope. Drivers will inherit from this structure and add their own global state, in the same way as for the existing COFFLinkerContext. See discussion in https://lists.llvm.org/pipermail/llvm-dev/2021-June/151184.html The previous land f860fe362282ed69b9d4503a20e5d20b9a041189 caused issues in https://lab.llvm.org/buildbot/#/builders/123/builds/8383, fixed by 22ee510dac9440a74b2e5b3fe3ff13ccdbf55af3. Differential Revision: https://reviews.llvm.org/D108850
2022-01-16Revert [LLD] Remove global state in lldCommonAlexandre Ganea1-3/+4
It seems to be causing issues on https://lab.llvm.org/buildbot/#/builders/123/builds/8383
2022-01-16[LLD] Remove global state in lldCommonAlexandre Ganea1-4/+3
Move all variables at file-scope or function-static-scope into a hosting structure (lld::CommonLinkerContext) that lives at lldMain()-scope. Drivers will inherit from this structure and add their own global state, in the same way as for the existing COFFLinkerContext. See discussion in https://lists.llvm.org/pipermail/llvm-dev/2021-June/151184.html Differential Revision: https://reviews.llvm.org/D108850
2021-10-25[ELF] Update comments/diagnostics for some long options to use the canonical ↵Fangrui Song1-7/+6
two-dash form Rewrite some comments as appropriate.
2021-06-24[OptTable] Rename PrintHelp to printHelpFangrui Song1-1/+1
To be consistent with other member functions and match the coding standard.
2021-02-09[ELF] Rewriting the path of sample profile file for --reproduce response.txtHongtao Yu1-0/+3
Rewritting the path of the sample profile file in response.txt to be relative to the repro tar. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D96193
2020-12-01lld/ELF: Make three rarely-used flags work with --reproduceNico Weber1-0/+3
All three use readFile() for their argument so their argument file is already copied to the tar, but we weren't rewriting the argument to point to the path used in the tar file. No test because the change is trivial (several other flags in createResponseFile() also aren't tested, likely for the same reason.) Differential Revision: https://reviews.llvm.org/D92356
2020-11-30[lld/mac] Add --reproduce optionNico Weber1-1/+1
This adds support for ld.lld's --reproduce / lld-link's /reproduce: flag to the MachO port. This flag can be added to a link command to make the link write a tar file containing all inputs to the link and a response file containing the link command. This can be used to reproduce the link on another machine, which is useful for sharing bug report inputs or performance test loads. Since the linker is usually called through the clang driver and adding linker flags can be a bit cumbersome, setting the env var `LLD_REPRODUCE=foo.tar` triggers the feature as well. The file response.txt in the archive can be used with `ld64.lld.darwinnew $(cat response.txt)` as long as the contents are smaller than the command-line limit, or with `ld64.lld.darwinnew @response.txt` once D92149 is in. The support in this patch is sufficient to create a tar file for Chromium's base_unittests that can link after unpacking on a different machine. Differential Revision: https://reviews.llvm.org/D92274
2020-11-24[lld/mac] Implement basic typo correction for flagsNico Weber1-1/+1
Also use "unknown flag 'flag'" instead of "unknown flag: flag" for consistency with the other ports. Differential Revision: https://reviews.llvm.org/D91970
2020-11-10[lld][ELF] Add additional time trace categoriesJames Henderson1-0/+2
I noticed when running a large link with the --time-trace option that there were several areas which were missing any specific time trace categories (aside from the generic link/ExecuteLinker categories). This patch adds new categories to fill most of the "gaps", or to provide more detail than was previously provided. Reviewed by: MaskRay, grimar, russell.gallop Differential Revision: https://reviews.llvm.org/D90686
2020-05-15[ELF] Use namespace qualifiers (lld:: or elf::) instead of `namespace lld { ↵Fangrui Song1-12/+8
namespace elf {` Similar to D74882. This reverts much code from commit bd8cfe65f5fee4ad573adc2172359c9552e8cdc0 (D68323) and fixes some problems before D68323. Sorry for the churn but D68323 was a mistake. Namespace qualifiers avoid bugs where the definition does not match the declaration from the header. See https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions (D74515) Differential Revision: https://reviews.llvm.org/D79982
2020-03-11Remove unused Endian.h includes, NFCReid Kleckner1-0/+1
Mainly avoids including Host.h everywhere: $ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \ | grep '^[-+] ' | sort | uniq -c | sort -nr 3141 - /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/Host.h