Commit Graph

14834 Commits

Author SHA1 Message Date
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
Fangrui Song 213896bc5a [ELF] Remove unused InputSection::getOffsetInFile 2021-12-26 15:18:56 -08:00
Fangrui Song a1c2ee0147 [ELF] LinkerScript/OutputSection: change other std::vector members to SmallVector
11+KiB smaller .text with both libc++ and libstdc++ builds.
2021-12-26 13:53:47 -08:00
Fangrui Song 10316a6f94 [ELF] Change InputSectionDescription members from vector to SmallVector
This decreases sizeof(lld:🧝:InputSectionDescription) from 264 to 232.
2021-12-26 13:06:54 -08:00
Fangrui Song bf7f3dd74e [ELF] Move outSecOff addition from InputSection::writeTo to the caller
Simplify the code a bit and improve consistency with SyntheticSection::writeTo.
2021-12-26 12:11:41 -08:00
Fangrui Song aabe901d57 [ELF] Remove one redundant computeBinding
This does resolve the redundancy in includeInDynsym().
2021-12-25 23:59:27 -08:00
Fangrui Song 20b4704da3 [ELF] reportRangeError: mention symbol name for non-STT_SECTION local symbols like non-global symbols 2021-12-25 23:46:47 -08:00
Fangrui Song 2c8ebab32e [ELF] sortSymTabSymbols: change vector to SmallVector
This function may take ~1% time. SmallVector<SymbolTableEntry, 0> is smaller (16 bytes
instead of 24) and more efficient.
2021-12-25 23:16:27 -08:00
Fangrui Song d5e310b154 [ELF][test] Make some TLS tests less sensitive to addresses 2021-12-25 22:05:20 -08:00
Fangrui Song a00f480fe8 [ELF] scanReloc: remove unused start parameter. NFC
This was once used as a workaround for detecting missing PPC64 TLSGD/TLSLD
relocations produced by ancient IBM XL C/C++.
2021-12-25 14:34:06 -08:00
Fangrui Song dd4f5d4ae5 [ELF] De-template handleTlsRelocation. NFC 2021-12-25 14:23:13 -08:00
Fangrui Song 70912420bb [ELF] Move TLS dynamic relocations to postScanRelocations
This temporarily increases sizeof(SymbolUnion), but allows us to mov GOT/PLT/etc
index members outside Symbol in the future.

Then, we can make TLSDESC and TLSGD use different indexes and support mixed
TLSDESC and TLSGD (tested by x86-64-tlsdesc-gd-mixed.s).

Note: needsTlsGd and needsTlsGdToIe may optionally be combined.

Test updates are due to reordered GOT entries.
2021-12-24 22:36:49 -08:00
Fangrui Song cde37a7e5a [ELF][test] Add tests for mixed GD-to-IE and IE, mixed TLSDESC and GD
Note: mixed TLSDESC and GD currently does not work.
2021-12-24 22:24:15 -08:00
Kazu Hirata 62e48ed10f Use isa instead of dyn_cast (NFC) 2021-12-24 21:22:27 -08:00
Kazu Hirata 9c0a4227a9 Use Optional::getValueOr (NFC) 2021-12-24 20:57:40 -08:00
Fangrui Song 40fae4d8fc [ELF] Optimize replaceCommonSymbols
This decreases the 0.2% time (no debug info) to nearly no.
2021-12-24 19:01:51 -08:00
Fangrui Song 745420d3f4 [ELF] Cache global variable `target` in relocate*
This avoid repeated load of the unique_ptr in hot paths.
2021-12-24 17:54:12 -08:00
Fangrui Song b5a0f0f397 [ELF] Add ELFFileBase::{elfShdrs,numELFShdrs} to avoid duplicate llvm::object::ELFFile::sections()
This mainly avoid `relsOrRelas` cost in `InputSectionBase::relocate`.
`llvm::object::ELFFile::sections()` has redundant and expensive checks.
2021-12-24 17:10:38 -08:00
Fangrui Song 5e3403bd22 [ELF] parseLazy: skip local symbols 2021-12-24 13:16:34 -08:00
Fangrui Song e694180033 [ELF] Optimize --wrap to only check non-local symbols 2021-12-24 12:28:59 -08:00
Fangrui Song e1b6b5be46 [ELF] Avoid referencing SectionBase::repl after ICF
It is fairly easy to forget SectionBase::repl after ICF.
Let ICF rewrite a Defined symbol's `section` field to avoid references to
SectionBase::repl in subsequent passes. This slightly improves the --icf=none
performance due to less indirection (maybe for --icf={safe,all} as well if most
symbols are Defined).

With this change, there is only one reference to `repl` (--gdb-index D89751).
We can undo f4fb5fd752 (`Move Repl to SectionBase.`)
but move `repl` to `InputSection` instead.

Reviewed By: ikudrin

Differential Revision: https://reviews.llvm.org/D116093
2021-12-24 12:09:48 -08:00
Fangrui Song 0d749e13f7 [ELF] Optimize symbol initialization and resolution
Avoid repeated load of global pointer (symtab) / members (sections.size(), firstGlobal) in the hot paths.

And remove some unneeded this->
2021-12-23 21:54:32 -08:00