Commit Graph

15541 Commits

Author SHA1 Message Date
Nico Weber 330abe8d43 fix comment typo to cycle bots 2022-08-15 18:49:02 -04:00
Kazu Hirata f5a68feab3 Use llvm::none_of (NFC) 2022-08-14 16:25:39 -07:00
Nico Weber b696500b9a [lld/mac] Stop accepting arbitrary suffixes on --(no-)warn-dylib-install-name
The flag accidentally used Joined<> instead of Flag<>.

Previously, `--warn-dylib-install-namefoobarbaz` would be accepted and
had the same effect as `-warn-dylib-install-name`. Now the flag only
works if no suffix is attached to it, as originally intended.

Also fix a typo in the flag's help text.

Differential Revision: https://reviews.llvm.org/D131781
2022-08-12 15:27:02 -04:00
Leonard Grey 6c62795058 [lld-macho] Ensure cached objects are affected by `-object_path_lto`
This refactors LTO compile to look more like COFF, where cache hits and misses are all funneled through the same code path.

Previously, cache hits were *not* being saved to -object_path_lto, which led to them sometimes falling out of the cache before dsymutil could process them. As a side effect of the refactor, cached objects are now saved with -save-temps as well, which seems desirable.

(Deleted lld/test/MachO/lto-cache-dsymutil.ll and rolled it into lld/test/MachO/lto-object-path.ll, since the cache-only, non object path approach is unreliable anyway).

Differential Revision: https://reviews.llvm.org/D131624
2022-08-12 10:56:58 -04:00
Nico Weber 39a093471a [lld/mac] Add missing `_eq` suffix on two (internal) option names
No behavior change.
2022-08-12 08:18:52 -04:00
Martin Storsjö e6db064394 [doc] Remove release notes from the main branch for changes that were backported to 15.x 2022-08-12 11:21:51 +03:00
Martin Storsjö 5d513ef6cf [LLD] [COFF] Add support for a new, mingw specific embedded directive -exclude-symbols:
This is an entirely new embedded directive - extending the GNU ld
command line option --exclude-symbols to be usable in embedded
directives too.

(GNU ld.bfd also got support for the same new directive, currently in
the latest git version, after the 2.39 branch.)

This works as an inverse to the regular embedded dllexport directives,
for cases when autoexport of all eligible symbols is performed.

Differential Revision: https://reviews.llvm.org/D130120
2022-08-11 11:59:48 +03:00
Martin Storsjö d1da6469f9 [LLD] [MinGW] Implement the --exclude-symbols option
This adds support for the existing GNU ld command line option, which
allows excluding individual symbols from autoexport (when linking a
DLL and no symbols are marked explicitly as dllexported).

Differential Revision: https://reviews.llvm.org/D130118
2022-08-11 11:59:47 +03:00
Keith Smiley 3c24fae398
[lld-macho] Add support for objc_msgSend stubs
Apple Clang in Xcode 14 introduced a new feature for reducing the
overhead of objc_msgSend calls by deduplicating the setup calls for each
individual selector. This works by clang adding undefined symbols for
each selector called in a translation unit, such as `_objc_msgSend$foo`
for calling the `foo` method on any `NSObject`. There are 2
different modes for this behavior, the default directly does the setup
for `_objc_msgSend` and calls it, and the smaller option does the
selector setup, and then calls the standard `_objc_msgSend` stub
function.

The general overview of how this works is:

- Undefined symbols with the given prefix are collected
- The suffix of each matching undefined symbol is added as a string to
  `__objc_methname`
- A pointer is added for every method name in the `__objc_selrefs`
  section
- A `got` entry is emitted for `_objc_msgSend`
- Stubs are emitting pointing to the synthesized locations

Notes:

- Both `__objc_methname` and `__objc_selrefs` can also exist from object
  files, so their contents are merged with our synthesized contents
- The compiler emits method names for defined methods, but not for
  undefined symbols you call, but stubs are used for both
- This only implements the default "fast" mode currently just to reduce
  the diff, I also doubt many folks will care to swap modes
- This only implements this for arm64 and x86_64, we don't need to
  implement this for 32 bit iOS archs, but we should implement it for
  watchOS archs in a later diff

Differential Revision: https://reviews.llvm.org/D128108
2022-08-10 17:17:17 -07:00
Nico Weber 87248ba5b1 [lld/elf] Use C++17 nested namespace syntax in most places
Like D131405, but for ELF.

No behavior change.

Differential Revision: https://reviews.llvm.org/D131612
2022-08-10 16:47:30 -04:00
Fangrui Song e3fcf2e06f [ELF] Simplify llvm::enumerate with structured binding. NFC 2022-08-09 21:52:08 -07:00
Fangrui Song 596f490ab9 [ELF] De-template BitcodeFile::parse. NFC 2022-08-09 21:46:28 -07:00
Fangrui Song dc55ab3840 [ELF] De-template createBitcodeSymbol. NFC 2022-08-09 21:43:36 -07:00
Fangrui Song dfe2a3f3eb [COFF] Change a llvm::StringSet<> to llvm::DenseSet<StringRef>. NFC
The former stores strings and is therefore more expensive.
2022-08-09 17:50:42 -07:00
Pengxuan Zheng c951edb7b2 [LLD][COFF] Identify /GL object files which are inside libraries
With D26647, we can already identify input object files compiled by cl.exe with
/GL. It seems to be helpful to do the same and print an error message for those
object files compiled with /GL but are inside libraries/archives too.

Reviewed By: rnk, thieta

Differential Revision: https://reviews.llvm.org/D131458
2022-08-09 12:32:35 -07:00
Keith Smiley ee27bca2e2
[lld-macho][test] Rename dtrace test (NFC)
This matches the convention used elsewhere

Differential Revision: https://reviews.llvm.org/D131456
2022-08-09 08:40:08 -07:00
Alex Brachet dbd04b853b [ELF] Support --package-metadata
This was recently introduced in GNU linkers and it makes sense for
ld.lld to have the same support. This implementation omits checking if
the input string is valid json to reduce size bloat.

Differential Revision: https://reviews.llvm.org/D131439
2022-08-08 21:31:58 +00:00
Nico Weber 09db7f5331 [lld/mac] Remove unusual "Fallthrough" comments
Normally we'd use LLVM_FALLTHROUGH, or now, [[fallthrough]].
But for case labels followed directly by other case labels, we
use neither.

No behavior change.
2022-08-08 14:18:44 -04:00
Nico Weber aa1abd7684 [lld/win] Use C++17 structured bindings
No behavior change.

Differential Revision: https://reviews.llvm.org/D131403
2022-08-08 11:51:38 -04:00
Nico Weber 7c26641d9d [lld/win] Use C++17 nested namespace syntax in most places
Like D131354, but for COFF.

No behavior change.

Differential Revision: https://reviews.llvm.org/D131405
2022-08-08 11:48:12 -04:00
Nico Weber 2f3256a02e [lld/mac] Use C++17 structured bindings in two more places
No behavior change.
2022-08-08 11:09:44 -04:00
Tobias Hieta 576375a2d6
[LLD][COFF] Ignore DEBUG_S_XFGHASH_TYPE/VIRTUAL
These are new debug types that ships with the latest
Windows SDK and would warn and finally fail lld-link.

The symbols seems to be related to Microsoft's XFG
which is their version of CFG. We can't handle any of
this yet, so for now we can just ignore these types
so that lld doesn't fail with a new version of Windows
SDK.

Fixes: #56285

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D129378
2022-08-08 15:53:52 +02:00
Nico Weber b99da9d255 [lld/mac] Use C++17 structured bindings
No behavior change.

Differential Revision: https://reviews.llvm.org/D131355
2022-08-08 07:21:28 -04:00
Nico Weber bf20d43f82 [lld/mac] Use C++17 nested namespace syntax in most places
Some header files used

    namespace lld {
    namespace macho {
    // ...
    } // namespace macho
    std::string toString(const Type &t);
    } // namespace lld

In those files, I didn't use a nested namespace since it's not a big win there.

No behavior change.

Differential Revision: https://reviews.llvm.org/D131354
2022-08-08 07:11:17 -04:00
Fangrui Song ec04e45c03 [lld] LLVM_FALLTHROUGH => [[fallthrough]]. NFC
With C++17 there is no Clang pedantic warning or MSVC C5051.
2022-08-07 00:02:35 +00:00
Fangrui Song bccdf9197b Revert "[lld-macho] Work around odr-use of const non-inline static data member to fix -O0 build after D128298"
This reverts commit 20b2d3260d.
The workaround is no longer needed for C++17.
2022-08-06 16:44:14 -07:00
Tom Stellard 91f3f0bf31 lld/cmake: Drop use of llvm-config for LLVM install discovery
This has been deprecated since D116492 earlier in 2022.

That seems recent, but with the recent cut of LLVM 15 that is still two releases (14 and 15). Meanwhile Clang has deprecated `llvm-config` for a lot longer, and since it is likely that LLD users are also Clang users, this serves as an extra "heads up" that `llvm-config` is on its way out.

Remove it in favor of using CMake's find_package() function.

Reviewed By: MaskRay, mgorny

Differential Revision: https://reviews.llvm.org/D131144
2022-08-06 16:24:04 -04:00
Fangrui Song e45a5696bb [ELF] toString(const InputFile *): synchronize toStringCache
The function may be called currently for diagnostics.
2022-08-06 01:00:06 -07:00
Tobias Hieta b1356504e6
[LLVM] Update C++ standard to 17
Also make the soft toolchain requirements hard. This allows
us to use C++17 features in LLVM now.

If we find patterns with C++17 that improve readability
it should be recommended in the coding standards.

Reviewed By: jhenderson, cor3ntin, MaskRay

Differential Revision: https://reviews.llvm.org/D130689
2022-08-06 09:42:10 +02:00
Fangrui Song d7cbfcf36a [ELF][AArch64] Fix potentially corrupted section content for PAC
D74537 introduced a bug: if `(config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_PAC) != 0`
with -z pac-plt unspecified, we incorrectly use AArch64BtiPac, whose writePlt will make
out-of-bounds write after the .plt section. This is often benign because the
output section after .plt will usually overwrite the content.

This is very difficult to test without D131247 (Parallelize writes of different OutputSections).
2022-08-05 18:24:54 -07:00
Fangrui Song e89d6d2ac5 [ELF] Keep only getTarget() call. NFC
The place from D61712 seems unneeded now. We can just use the place added by
D62609 (support AArch64 BTI/PAC).
2022-08-05 18:20:23 -07:00
Fangrui Song abd9807590 [ELF] mergeCmp: work around irreflexivity bug
Some tests (e.g. aarch64-feature-pac.s) segfault in libstdc++ _GLIBCXX_DEBUG
builds (enabled by LLVM_ENABLE_EXPENSIVE_CHECKS).

dyn_cast<ThunkSection> is incorrectly true for any SyntheticSection. std::merge
transitively calls mergeCmp(x, x) (due to __glibcxx_requires_irreflexive_pred)
and will segfault in `ta->getTargetInputSection()`. The dyn_cast<ThunkSection>
issue should be eventually fixed properly, bug `a != b` is robust enough for now.
2022-08-05 17:08:37 -07:00
Fangrui Song 28d05d6723 [ELF][PPC64] Fix potentially corrupted section content with empty .got
D91426 makes .got possibly empty while needed. If .got and .data have the same
address, and .got's content is written after .data, the first word of .data will
be corrupted.

The bug is not testable without D131247.
2022-08-05 15:22:57 -07:00
Fangrui Song 2515cb80cd [ELF] Parallelize input section initialization
This implements the last step of
https://discourse.llvm.org/t/parallel-input-file-parsing/60164 for the ELF port.

For an ELF object file, we previously did: parse, (parallel) initializeLocalSymbols, (parallel) postParseObjectFile.
Now we do: parse, (parallel) initSectionsAndLocalSyms, (parallel) postParseObjectFile.

initSectionsAndLocalSyms does most of input section initialization.
The sequential `parse` does SHT_ARM_ATTRIBUTES/SHT_RISCV_ATTRIBUTES/SHT_GROUP initialization for now.

Performance linking some programs with --threads=8 (glibc 2.33 malloc and mimalloc):

* clang: 1.05x as fast with glibc malloc, 1.03x as fast with mimalloc
* chrome: 1.04x as fast with glibc malloc, 1.03x as fast with mimalloc
* internal search program: 1.08x as fast with glibc malloc, 1.05x as fast with mimalloc

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D130810
2022-08-04 11:47:52 -07:00
Fangrui Song f6bd0a8f2b [ELF] Add makeThreadLocal/makeThreadLocalN and remove InputFile::localSymStorage
makeThreadLocal/makeThreadLocalN are moved from D130810 ([ELF] Parallelize input
section initialization) here to make D130810 more focused on the refactor:

* COFF has some needs for multiple linker contexts. D108850 partially removed
  global states from lldCommon but left the global variable `lctx`.
* To the best of my knowledge, all multiple-linker-context feature requests to
  ELF are more from user convenience, with no very strong argument.
* In practice, ELF port is very difficult to remove global states without
  introducing significant performance regression/hurting code readability.
* Per-thread allocators from D122922/D123879 are too expensive and will not
  really benefit ELF.

This patch adds a simple thread_local based makeThreadLocal to
lld/Common/Memory.h. It will enable further optimization in ELF.
2022-08-04 11:09:40 -07:00
Fangrui Song 077b16aa6c [ELF] Remove unneeded make<InputSection>. NFC 2022-08-03 21:51:39 -07:00
Fangrui Song e2a932dd8a [ELF] Move updateARMVFPArgs/updateARMVFPArgs. NFC
To reduce diff for D130810.
2022-08-03 21:49:17 -07:00
Martin Storsjö 59c6f418fa [LLD] [MachO] Fix GCC build warnings
This fixes the following warnings produced by GCC 9:

    ../tools/lld/MachO/Arch/ARM64.cpp: In member function ‘void {anonymous}::OptimizationHintContext::applyAdrpLdr(const lld::macho::OptimizationHint&)’:
    ../tools/lld/MachO/Arch/ARM64.cpp:448:18: warning: comparison of integer expressions of different signedness: ‘int64_t’ {aka ‘long int’} and ‘uint64_t’ {aka ‘long unsigned int’} [-Wsign-compare]
      448 |   if (ldr.offset != (rel1->referentVA & 0xfff))
          |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../tools/lld/MachO/UnwindInfoSection.cpp: In function ‘bool canFoldEncoding(compact_unwind_encoding_t)’:
    ../tools/lld/MachO/UnwindInfoSection.cpp:404:44: warning: comparison between ‘enum<unnamed>’ and ‘enum<unnamed>’ [-Wenum-compare]
      404 |   static_assert(UNWIND_X86_64_MODE_MASK == UNWIND_X86_MODE_MASK, "");
          |                                            ^~~~~~~~~~~~~~~~~~~~
    ../tools/lld/MachO/UnwindInfoSection.cpp:405:49: warning: comparison between ‘enum<unnamed>’ and ‘enum<unnamed>’ [-Wenum-compare]
      405 |   static_assert(UNWIND_X86_64_MODE_STACK_IND == UNWIND_X86_MODE_STACK_IND, "");
          |                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~

Differential Revision: https://reviews.llvm.org/D130970
2022-08-03 00:14:39 +03:00
Gabriel Ravier 5dbd8faad5 [lld] Fixed a number of typos
I went over the output of the following mess of a command:

`(ulimit -m 2000000; ulimit -v 2000000; git ls-files -z | parallel --xargs -0 cat | aspell list --mode=none --ignore-case | grep -E '^[A-Za-z][a-z]*$' | sort | uniq -c | sort -n | grep -vE '.{25}' | aspell pipe -W3 | grep : | cut -d' ' -f2 | less)`

and proceeded to spend a few days looking at it to find probable typos
and fixed a few hundred of them in all of the llvm project (note, the
ones I found are not anywhere near all of them, but it seems like a
good start).

Differential Revision: https://reviews.llvm.org/D130982
2022-08-02 09:52:31 -04:00
Fangrui Song dde41c6c56 [ELF] --reproduce: strip directories for --print-archive-stats= and --why-extract=
Similar to -o and -Map.
2022-08-01 22:06:46 -07:00
Fangrui Song d0cf7b2015 [ELF] EhInputSection::getParentOffset: fix out-of-bounds access for symbols relative to a non-empty .eh_frame
This has unclear semantics and can be considered invalid. Return an arbitrary value.
2022-08-01 01:10:51 -07:00
Fangrui Song b2559f2f5c [ELF] .eh_frame: remove config->wordsize padding
Linux Standard Base Core Specification says that CIE/FDE is padded to an
addressing unit size boundary, but in practice GNU assembler/LLVM integrated
assembler pad FDE/CIE to 4 and the last FDE to 8 on 64-bit systems.

In addition, GNU ld doesn't pad to 8, so let's drop excess padding, too.
If the assembler provides aligned pieces, the output will be aligned.

Noticed .eh_frame size reduction for 3 executables: 0.3% (chrome), 4.7% (clang),
7.6% (an internal program).
2022-07-31 23:35:44 -07:00
Fangrui Song 81ed005c4c [ELF] Remove EhFrameSection::addSection. NFC 2022-07-31 19:55:05 -07:00
Fangrui Song b3452f8f13 [ELF] redirectSymbols: skip versioned symbol combine if config->versionDefinitions.size() == 2 2022-07-31 17:47:09 -07:00
Jez Ng 6c9f681252 [lld-macho] Support EH frame pointer encodings that use sdata4
Previously we only supporting using the system pointer size (aka the
`absptr` encoding) because `llvm-mc`'s CFI directives always generate EH
frames with that encoding. But libffi uses 4-byte-encoded, hand-rolled
EH frames, so this patch adds support for it.

Fixes #56576.

Reviewed By: #lld-macho, oontvoo

Differential Revision: https://reviews.llvm.org/D130804
2022-07-31 20:16:33 -04:00
Fangrui Song af1328ef45 [ELF] Simplify EhInputSection::split. NFC
* Inline getReloc
* Fold the UINT32_MAX length check into the section size check.
  This transformation is valid because we don't support .eh_frame input sections
  larger than 32-bit (unrealistic even for large code models).
2022-07-31 16:59:57 -07:00
Fangrui Song 3e9adff456 [ELF] Split EhInputSection::pieces into cies and fdes
This simplifies code, removes a read32 (for id==0 check), and makes it feasible
to combine some operations in EhInputSection::split and EhFrameSection::addRecords.

Mostly NFC, but fixes "Relocation not in any piece" assertion failure in an
erroneous case when a relocation offset precedes all CIE/FDE pices.
2022-07-31 16:16:10 -07:00
Fangrui Song 7c158b9ed1 [ELF][test] Merge .eh_frame tests 2022-07-31 14:52:20 -07:00
Fangrui Song a9c5d09c5e [ELF][test] Test identical CIE content with different personality
If we change
CieRecord *&rec = cieMap[{cie.data(), personality}];
to
CieRecord *&rec = cieMap[{cie.data(), nullptr}];

The new test can catch the failure.
2022-07-31 13:43:07 -07:00
Fangrui Song c09d323599 [ELF] Move EhInputSection out of inputSections. NFC
inputSections temporarily contains EhInputSection objects mainly for
combineEhSections. Place EhInputSection objects into a new vector
ehInputSections instead of inputSections.
2022-07-31 11:58:08 -07:00