Commit Graph

14855 Commits

Author SHA1 Message Date
John Ericson a1da5f3c2d [lld] Deprecate using llvm-config to detect llvm installation
This is continuing in the path of D51714, which did this for Clang.

I have rearranged the source code Clang so one can diff the top-level
CMakeLists.txt of Clang and LLD, ensuring we use the same strategy for
both.

Besides diffing the two files, `git diff --color-moved` on LLD also helps review.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D116492
2022-01-07 20:51:14 +00:00
John Ericson 44e3365775 [CMake] Factor out config prefix finding logic
See the docs in the new function for details.

 I think I found every instance of this copy pasted code. Polly could
 also use it, but currently does something different, so I will save the
 behavior change for a future revision.

We get the shared, non-installed CMake modules following the pattern
established in D116472.

It might be good to have LLD and Flang also use this, but that would be
a functional change and so I leave it as future work.

Reviewed By: beanz, lebedev.ri

Differential Revision: https://reviews.llvm.org/D116521
2022-01-07 20:16:18 +00:00
Brian Cain ddf1fb1f13 [Hexagon] Save results from partial compound
Previously compounding was all-or-nothing.  Now, the
compounding attempts will iterate and yield the most
compounds that still result in a valid packet.
2022-01-06 14:08:33 -08:00
Vincent Lee a963bc490d [lld-macho] Increase slops to prevent thunk out of range
One of our internal arm64 apps hit a thunk out of range error when building
with LLD. Per the comment, I'm arbitrarily increasing slop size to 256.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D116705
2022-01-06 12:29:12 -08:00
Vy Nguyen fb9bfb2c59 [lld][macho][nfc] Make tests less britle by not expecting ordering in symbol table dump.
(parial)fixes PR/53026

Differential Revision: https://reviews.llvm.org/D116718
2022-01-06 09:45:44 -05:00
Fangrui Song 6e4bbbfcc8 [ELF] Enforce double-dash form for --color-diagnostics/--rsp-quoting/--symbol-ordering-file
They are LLD-specific and by convention we enforce the double-dash form to avoid
collision with short options (e.g. weird `-c olor-diagnostics` interpretation in
GNU ld). They are rarely used and to the best of my investigation the undesired
single-dash forms are not used in the wild.
2022-01-06 01:02:14 -08:00
Fangrui Song bfc2f4b122 [ELF] Update help messages to prefer canonical name for some long options
And improve the help message for --pop-state.
2022-01-06 00:43:46 -08:00
Nico Weber d5b2921faf [lld/tests] Stop setting the "asserts" and "debug" features
The last use of `REQUIRES: debug` was removed in 2013 in 72c5d3d7c in favor of
`REQUIRES: asserts`.

The last use of `REQUIRES: asserts` was removed in 2015 in 251b0e268 when the
old COFF linker was removed.

lld's test suite currently has no behavior difference with respect to
assertions or debug builds (and hasn't had it for 6 years). Let's keep it that
way :)

Differential Revision: https://reviews.llvm.org/D115941
2022-01-05 13:39:17 -05:00
Fangrui Song 954aaf7c14 [ELF] Demote all lazy symbols. NFC
This complements D111365.

D111365 did not demote isUsedInRegularObj lazy symbols just to work around
a --symbol-ordering-file diagnostic quirk.

The quirk was dropped by 00dd2d15a4,
so we can demote all lazy symbols now, not just the isUsedInRegularObj ones.
2022-01-05 10:24:29 -08:00
Nico Weber 085f078307 Revert "Revert D109159 "[amdgpu] Enable selection of `s_cselect_b64`.""
This reverts commit 859ebca744.
The change contained many unrelated changes and e.g. restored
unit test failes for the old lld port.
2022-01-05 13:10:25 -05:00
David Salinas 859ebca744 Revert D109159 "[amdgpu] Enable selection of `s_cselect_b64`."
This reverts commit 640beb38e7.

That commit caused performance degradtion in Quicksilver test QS:sGPU and a functional test failure in (rocPRIM rocprim.device_segmented_radix_sort).
Reverting until we have a better solution to s_cselect_b64 codegen cleanup

Change-Id: Ibf8e397df94001f248fba609f072088a46abae08

Reviewed By: kzhuravl

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

Change-Id: Id169459ce4dfffa857d5645a0af50b0063ce1105
2022-01-05 17:57:32 +00:00
Nico Weber 5730d11c2b [lld-link] Consistently print all /verbose output to stderr
lld-link used to consistently print all /verbose output to stdout, and that was
an intentional decision: https://reviews.llvm.org/rG4bce7bcc88f3

https://reviews.llvm.org/rGe6e206d4b4814 added message() and log(),
and back then `log()` morally was just `if (verbose) message(...)`
and message() wrote to stdout.

So that change moved most /verbose-induced writes to outs() to
log(). Except for the one in printDiscardedMessage(), since
the check for `verbose` for that one is in the caller, in
Writer::createSections():

    if (config->verbose)
      sc->printDiscardedMessage();

Later, https://reviews.llvm.org/D41033 changed log() to write to
stderr. That moved lld-link from writing all its /verbose output
to stdout to writing almost all of its /verbose output to stderr --
except for printDiscardedMessage() output.

This change moves printDiscardedMessage() to call log() as well,
so that all /verbose output once again consistently goes to the same
stream.

Differential Revision: https://reviews.llvm.org/D116667
2022-01-05 11:52:04 -05:00
Benjamin Kramer afc14a0d17 Retire llvm::make_reverse_iterator in favor of std::make_reverse_iterator
std::make_reverse_iterator is a C++14 feature, gcc has it since GCC 5.1.
2022-01-05 14:07:08 +01:00
Fangrui Song ddea3bf7d1 [ELF] Remove redundant cast. NFC 2022-01-05 02:07:15 -08:00
Fangrui Song 0940cd18f2 [ELF] --symbol-ordering-file: use getLocalSymbols. NFC 2022-01-05 02:06:31 -08:00
Fangrui Song 00dd2d15a4 [ELF] --symbol-ordering-file: remove weird !lazy condition for "no such symbol" diagnostic
The diagnostic is emitted for an unextracted lazy symbol but suppressed for an
undefined symbol. Suppressing the diagnostic for unextracted lazy symbol
probably makes more sense because (a) an unextracted lazy symbol is quite
similar to an undefined symbol and (b) an unextracted lazy symbol is different
from "no such symbol".
2022-01-05 02:04:36 -08:00
Fangrui Song 935229f66b [ELF] Symbol::getVA: assert not called on a lazy symbol
The code path is dead after D111365.
2022-01-05 00:46:48 -08:00
Xu Mingjie b5149f4e66 [LTO] Fix assertion failed when flushing bitcode incrementally for LTO output.
In https://reviews.llvm.org/D86905, we introduce an optimization, when lld emits LLVM bitcode,
we allow bitcode writer flush data to disk early when buffered data size is above some threshold.

But when `--plugin-opt=emit-llvm` and `-o /dev/null` are used,
lld will trigger assertion `BytesRead >= 0 && static_cast<size_t>(BytesRead) == BytesFromDisk`.
When we write output to /dev/null, BytesRead is zero, but at this program point BytesFromDisk is always non-zero.

Reviewed By: stephan.yichao.zhao, MaskRay

Differential Revision: https://reviews.llvm.org/D112297
2022-01-04 21:40:23 -08:00
Fangrui Song 292395329c [lld-link] Remove unneeded lto::InputFile::create after D116434 2022-01-04 19:38:32 -08:00
Luís Ferreira 10e40a4ea3 [lld] Add support for other demanglers other than Itanium
LLVM core library supports demangling other mangled symbols other than itanium,
such as D and Rust. LLD should use those demanglers in order to output pretty
demangled symbols on error messages.

Reviewed By: MaskRay, #lld-macho

Differential Revision: https://reviews.llvm.org/D116279
2022-01-05 03:25:41 +00:00
Fangrui Song d496abbe2a [lld-link] Replace LazyObjFile with lazy ObjFile/BitcodeFile
Similar to ELF 3a5fb57393.

* previously when a LazyObjFile was extracted, a new ObjFile/BitcodeFile was created; now the file is reused, just with `lazy` cleared
* avoid the confusing transfer of `symbols` from LazyObjFile to the new file
* simpler code, smaller executable (5200+ bytes smaller on x86-64)
* make eager parsing feasible (for parallel section/symbol table initialization)

Reviewed By: aganea, rnk

Differential Revision: https://reviews.llvm.org/D116434
2022-01-04 15:11:44 -08:00
Markus Böck c40049d6d7 [lld][MinGW] Remove `--no-as-needed` from ignored flags
In the post commit discussion of https://reviews.llvm.org/D116484 it was concluded that `--no-as-needed` should not be ignored. `--as-needed` stays ignored as it is already the default behaviour on COFF, which cannot be changed.
2022-01-03 23:01:02 +01:00
Kazu Hirata 5e1177302b [wasm] Use nullptr instead of NULL (NFC)
Identified with modernize-use-nullptr.
2022-01-02 10:20:21 -08:00
Markus Böck 1b708b67f6 [lld][MinGW] Ignore `--[no-]as-neeed` flags in MinGW driver
These flags are specific to ELF, but are still accepted by GNU ld, even if it does not do anything. This patch adds them as ignored option for the sake of compatibility.

Part of https://github.com/llvm/llvm-project/issues/52947

Differential Revision: https://reviews.llvm.org/D116484
2022-01-02 12:03:21 +01:00
John Ericson b3af9fbcc9 Set the path to the shared cmake modules based on the llvm directory
It’s still possible to build parts of the main llvm build (lld, clang etc) by symlinking them into llvm/tools.

Reviewed By: Ericson2314

Differential Revision: https://reviews.llvm.org/D116472
2022-01-01 17:59:08 +00:00
John Ericson 896537048d [lld][CMake] Use `GNUInstallDirs` to support custom installation dirs
Extracted from D99484. My new plan is to start from the outside and work
inward.

Reviewed By: stephenneuendorffer

Differential Revision: https://reviews.llvm.org/D115568
2021-12-31 18:57:57 +00:00
Fangrui Song ed67d5a03a [ELF] Switch cNamedSections to SmallVector. NFC
Make it smaller
2021-12-30 16:08:26 -08:00
Fangrui Song 441de75f69 [lld][docs] Update _templates/indexsidebar.html after Bugzilla->GitHub issue migration 2021-12-30 13:34:45 -08:00
Fangrui Song dabac5feec [ELF][LTO] Cache symbol table of lazy BitcodeFile
Similar to D62188: a BitcodeFile's symbol table may be iterated twice, once in
--start-lib (lazy) state, and once in the non-lazy state. This patch
makes `parseLazy` save `symbols[i]` so that the non-lazy state does not need to
re-insert to the global symbol table. Avoiding a redundant `saver.save` may save
memory.

`Maximum resident set size (kbytes)` for a large --thinlto-index-only link:

* without the patch: 10164000
* with the patch: 10095716 (0.6% decrease)

Note: we can remove `saver.save` if `BitcodeCompiler::add` does not transfer the ownership
of `f.obj` in `checkError(ltoObj->add(std::move(f.obj), resols));`.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D116390
2021-12-30 12:03:29 -08:00
Fangrui Song a96fe1bf3b [ELF][LTO] Call madvise(MADV_DONTNEED) on MemoryBuffer instances
@tejohnson noticed that freeing MemoryBuffer instances right before
`lto->compile` can save RSS, likely because the memory can be reused by
LTO indexing (e.g. ThinLTO import/export lists).).

For ELFFileBase instances, symbol and section names are backed by MemoryBuffer,
so destroying MemoryBuffer would make some infrequent passes (parseSymbolVersion,
reportBackrefs) crash and make debugging difficult.
For a BitcodeFile, its content is completely unused, but destroying its
MemoryBuffer makes the buffer identifier inaccessible and may introduce
constraints for future changes.
This patch leverages madvise(MADV_DONTNEED) which achieves the major gain
without the latent issues.

`Maximum resident set size (kbytes): ` for a large --thinlto-index-only link:

* current behavior: 10146104KiB
* destroy MemoryBuffer instances: 8555240KiB
* madvise(MADV_DONTNEED) just bitcodeFiles  and lazyBitcodeFiles: 8737372KiB
* madvise(MADV_DONTNEED) all MemoryBuffers: 8739796KiB  (16% decrease)

Depends on D116366

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D116367
2021-12-30 11:36:58 -08:00
Luís Ferreira 8792cd75d0 Revert "[lld] Add support for other demanglers other than Itanium"
This reverts commit e60d6dfd5a.

clang-ppc64le-rhel buildbot failed (https://lab.llvm.org/buildbot#builders/57/builds/13424):

    tools/lld/MachO/CMakeFiles/lldMachO.dir/Symbols.cpp.o: In function `lld::demangle(llvm::StringRef, bool)':
    Symbols.cpp:(.text._ZN3lld8demangleEN4llvm9StringRefEb[_ZN3lld8demangleEN4llvm9StringRefEb]+0x90): undefined reference to `llvm::demangle(std::string const&)'
2021-12-30 18:04:21 +00:00
Luís Ferreira e60d6dfd5a [lld] Add support for other demanglers other than Itanium
LLVM core library supports demangling other mangled symbols other than itanium,
such as D and Rust. LLD should use those demanglers in order to output pretty
demangled symbols on error messages.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D116279
2021-12-30 17:52:38 +00:00
Fangrui Song de92a13fec [ELF] --gc-sections: Work around SHT_PROGBITS .init_array.N for Rust
See https://github.com/rust-lang/rust/issues/92181
2021-12-28 16:40:51 -08:00
Mike Hommey 319181f767 [lld-macho] Fix alignment of TLV data sections
References from thread-local variable sections are treated as offsets
relative to the start of the thread-local data memory area, which is
initialized via copying all the TLV data sections (which are all
contiguous). If later data sections require a greater alignment than
earlier ones, the offsets of data within those sections won't be
guaranteed to aligned unless we normalize alignments. We therefore use
the largest alignment for all TLV data sections.

Reviewed By: #lld-macho, int3

Differential Revision: https://reviews.llvm.org/D116263
2021-12-28 19:03:13 -05:00
Fangrui Song 49f646a9ed [ELF] Change EhInputSection::pieces to SmallVector
The decreased size does not matter that much as one file contributes at most one EhInputSection.
2021-12-27 21:34:38 -08:00
Fangrui Song cb203f3f92 [ELF] Change InStruct/Partition pointers to unique_ptr
and remove associated make<XXX> calls.
gnuHash and sysvHash are unchanged, otherwise LinkerScript::discard would
destroy the objects which may be referenced by input section descriptions.

My x86-64 lld executable is 121+KiB smaller.
2021-12-27 18:15:23 -08:00
Fangrui Song 049cd480a0 [ELF] Use const reference. NFC 2021-12-27 17:05:48 -08:00
Fangrui Song 3c94d5d9d2 [ELF] addOrphanSections: avoid std::function 2021-12-27 15:57:38 -08:00
Fangrui Song b8a4780032 [ELF] Simplify and optimize SymbolTableSection<ELFT>::writeTo 2021-12-27 15:16:14 -08:00
Fangrui Song 80c14dcc0e [ELF] Delete stale declaration. NFC 2021-12-27 12:56:38 -08:00
Fangrui Song e590c9bc73 [ELF] -r: move zero OutputSection::addr code into finalizeAddressDependentContent
Ensure addresses are unchanged after finalizeAddressDependentContent.
2021-12-27 12:10:23 -08:00
Fangrui Song abc388ed3c [ELF] Move excludeLibs/redirectSymbols/replaceCommonSymbols adjacent
Make post-thinlto-index symbol resolution passes closer.
2021-12-27 00:31:55 -08:00
Fangrui Song 66c550f8de [ELF] Delete unused LazyObjKind 2021-12-27 00:03:53 -08:00
Fangrui Song b07292f77a [ELF] Serialize deleteFallThruJmpInsn to fix concurrency issue
New deleteFallThruJmpInsn calls `make<JumpInstrMod>` which cannot be called
concurrently. Losing parallelism is unfortunate but we can think of a better
approach if parallelism here justifies itself.
2021-12-26 23:26:13 -08:00
Fangrui Song 315554e873 [ELF] Unify sizeof(InputSection) limits for _WIN32 and others
Windows sizeof(InputSection) seems to match non-Windows now.
2021-12-26 23:02:24 -08:00
Fangrui Song e90c8c0422 [ELF] Optimize basic block section bytesDropped/jumpInstrMods
and make them more space efficient. This decreases sizeof(InputSection) from 176
to 160, and decreases peak memory usage by 0.3% when linking Chrome.
2021-12-26 22:17:30 -08:00
Fangrui Song 64038ef8c3 [ELF] ScriptParser: change std::vector to SmallVector 2021-12-26 20:12:55 -08:00
Fangrui Song e9262edf0d [ELF] SymbolTable:🔣 don't filter out PlaceholderKind
Placeholders (-y and redirectSymbols removed versioned symbols) are very rare and
the check just makes symbol table iteration slower. Most iterations filter out
placeholders anyway, so this change just drops the filter behavior.

For "Add symbols to symtabs", we need to ensure that redirectSymbols sets
isUsedInRegularObj to false when making a symbol placeholder, to avoid an
assertion failure in SymbolTableSection<ELFT>::writeTo.

My .text is 2KiB smaller. The speed-up linking chrome is 0.x%.
2021-12-26 18:11:45 -08:00
Fangrui Song 7924b3814f [ELF] Add Symbol::hasVersionSuffix
"Process symbol versions" may take 2+% time.
"Redirect symbols" may take 0.6% time.
This change speeds up the two passes and makes `*sym.getVersionSuffix()
== '@'` in the `undefined reference` diagnostic cleaner.

Linking chrome (no debug info) and another large program is 1.5% faster.

For empty-ver2.s: the behavior now matches GNU ld, though I'd consider the input
invalid and the exact behavior does not matter.
2021-12-26 17:25:54 -08:00
Fangrui Song 469144ffa3 [ELF] De-template InputSectionBase::getEnclosingFunction 2021-12-26 15:21:22 -08:00