aboutsummaryrefslogtreecommitdiff
path: root/lld
AgeCommit message (Collapse)AuthorFilesLines
2022-11-29[ELF] Handle GCC collect2 -plugin-opt= on WindowsBrett Werling2-3/+8
Follows up on commit cd5d5ce235081005173566c99c592550021de058 by additionally ignoring relative paths ending in "lto-wrapper.exe" as can be the case for GCC cross-compiled for Windows. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D138065 (cherry picked from commit cf4f35b78871aecc21e663067c57e60595bd7197)
2022-11-10Link liblldCOFF against libatomic when necessarySam James2-7/+3
Also simplify code for liblldCommon using the new LLVM_ATOMIC_LIB variable. Depends on D136280. Bug: https://bugs.gentoo.org/832675 Thanks-to: Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org> Tested-by: erhard_f@mailbox.org <erhard_f@mailbox.org> Differential Revision: https://reviews.llvm.org/D136281 (cherry picked from commit f0b451c77f14947e3e7d314f048679fa2f5c6298)
2022-10-28[lld-macho] Canonicalize personality pointers in EH framesJez Ng4-7/+75
We already do this for personality pointers referenced from compact unwind entries; this patch extends that behavior to personalities referenced via EH frames as well. This reduces the number of distinct personalities we need in the final binary, and helps us avoid hitting the "too many personalities" error. I renamed `UnwindInfoSection::prepareRelocations()` to simply `prepare` since we now do some non-reloc-specific stuff within. Fixes #58277. Reviewed By: #lld-macho, oontvoo Differential Revision: https://reviews.llvm.org/D135728 (cherry picked from commit 7b45dfc6811a52ff4e9a6054dc276d70d77fddaf)
2022-10-24[ELF] Suppress "duplicate symbol" when resolving STB_WEAK and STB_GNU_UNIQUE ↵Fangrui Song2-1/+43
in different COMDATs ``` template <typename T> struct A { A() {} int value = 0; }; template <typename Value> struct B { static A<int> a; }; template <typename Value> A<int> B<Value>::a; inline int foo() { return B<int>::a.value; } ``` ``` clang++ -c -fno-pic a.cc -o weak.o g++ -c -fno-pic a.cc -o unique.o # --enable-gnu-unique-object # Duplicate symbol error. In postParse, we do not check `sym.binding` ld.lld -e 0 weak.o unique.o ``` Mixing GCC and Clang object files in this case is not ideal. .bss._ZGVN1BIiE1aE has different COMDAT groups. It appears to work in practice because the guard variable prevents harm due to double initialization. For the linker, we just stick with the rule that a weak binding does not cause "duplicate symbol" errors. Close https://github.com/llvm/llvm-project/issues/58232 Differential Revision: https://reviews.llvm.org/D136381 (cherry picked from commit 0051b6bb78772b0658f28e5f31ddf91c1589aab5)
2022-09-28[ELF] Rewrite R_RISCV_ALIGN nops when r.addend%4 != 0Fangrui Song2-4/+18
For RVC, GNU assembler and LLVM integrated assembler add c.nop followed by a sequence of 4-byte nops. Even if remove % 4 == 0, we have to split one 4-byte nop and therefore need to write the code sequence, otherwise we create an incorrect c.unimp. (cherry picked from commit 78084d9e77b9a2017e2215491b71b37c2671c292)
2022-09-14[MachO] Don't fold compact unwind entries with LSDAShoaib Meenai2-12/+184
Folding them will cause the unwinder to compute the incorrect function start address for the folded entries, which in turn will cause the personality function to interpret the LSDA incorrectly and break exception handling. You can verify the end-to-end flow by creating a simple C++ file: ``` void h(); int main() { h(); } ``` and then linking this file against the liblsda.dylib produced by the test case added here. Before this change, running the resulting program would result in a program termination with an uncaught exception. Afterwards, it works correctly. Reviewed By: #lld-macho, thevinster Differential Revision: https://reviews.llvm.org/D132845 (cherry picked from commit 56bd3185cdd8d79731acd6c75bf41869284a12ed)
2022-09-14[MachO] Fix dead-stripping __eh_frameShoaib Meenai2-0/+55
This section is marked S_ATTR_LIVE_SUPPORT in input files, which meant that on arm64, we were unnecessarily preserving FDEs if we e.g. had multiple weak definitions for a function. Worse, we would actually produce an invalid `__eh_frame` section in that case, because the CIE associated with the unnecessary FDE would still get dead-stripped and we'd end up with a dangling FDE. We set up associations from functions to their FDEs, so dead-stripping will just work naturally, and we can clear S_ATTR_LIVE_SUPPORT from our input `__eh_frame` sections to fix dead-stripping. Reviewed By: #lld-macho, int3 Differential Revision: https://reviews.llvm.org/D132489 (cherry picked from commit a745e47900dde15c180d5caea7a1d292ca809eb1)
2022-09-12[LLD][COFF] Fix writing a map file when range extension thunks are insertedJan Ole Hüser4-4/+7
Bug: An assertion fails: Assertion failed: isa<To>(Val) && "cast<Ty>() argument of incompatible type!", file C:\Users\<user>\prog\llvm\llvm-git-lld-bug\llvm\include\llvm/Support/Casting.h, line 578 Bug is triggered, if - a map file is requested with /MAP, and - Architecture is ARMv7, Thumb, and - a relative jump (branch instruction) is greater than 16 MiB (2^24) The reason for the Bug is: - a Thunk is created for the jump - a Symbol for the Thunk is created - of type `DefinedSynthetic` - in file `Writer.cpp` - in function `getThunk` - the Symbol has no name - when creating the map file, the name of the Symbol is queried - the function `Symbol::computeName` of the base class `Symbol` casts the `this` pointer to type `DefinedCOFF` (a derived type), but the acutal type is `DefinedSynthetic` - The in the llvm::cast an assertion fails Changes: - Modify regression test to trigger this bug - Give the symbol pointing to the thunk a name, to fix the bug - Add assertion, that only DefinedCOFF symbols are allowed to have an empty name, when the constructor of the base class Symbol is executed Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D133201 (cherry picked from commit 4e5a59a3839f54d928d37d49d4c4ddbb3f339b76)
2022-09-04[DOCS] Minor fixes and removals of WIP warningsTobias Hieta1-7/+0
2022-08-29[lld] Fix typo in 15.x release notesShoaib Meenai1-1/+1
The flag is -femit-dwarf-unwind, not -femit-compact-unwind.
2022-08-28[ReleaseNotes]: Add PowerPC release notes for LLVM 15Amy Kwan1-0/+2
2022-08-25[LLD] [COFF] Fix export directives in object files from -includeoptionalMartin Storsjö2-8/+58
When an object file contains an export directive, we normally do some amount of deferred processing of them at the end of the linking process. The -includeoptional option was handled after this, and any object files (defining new exports) weren't handled. Move the handling of the -includeoptional into the same late loop which does the fixups for e.g. export directives. Ideally, this would also be done for object files that are pulled in by the wrap options, and for mingw autoimports, but those changes require more modifications, to make them safe for potentially being executed multiple times. This fixes https://github.com/llvm/llvm-project/issues/57243. Differential Revision: https://reviews.llvm.org/D132361 (cherry picked from commit af39e6f6fc905f3c067f022fb44136779d2f9c84)
2022-08-12[LLD] [COFF] Add support for a new, mingw specific embedded directive ↵Martin Storsjö7-4/+49
-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 (cherry picked from commit 5d513ef6cf4646e64bbb1d5f8610afd530964588)
2022-08-12[COFF] Change a llvm::StringSet<> to llvm::DenseSet<StringRef>. NFCFangrui Song1-1/+1
The former stores strings and is therefore more expensive. (cherry picked from commit dfe2a3f3eb92b6a94453a74f3f0a4552f6965fcc)
2022-08-12[LLD] [MinGW] Implement the --exclude-symbols optionMartin Storsjö9-0/+44
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 (cherry picked from commit d1da6469f9ea9b078276ee2e098241f0440468be)
2022-08-10[ELF] Support --package-metadataAlex Brachet8-0/+54
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 (cherry picked from commit dbd04b853b680b0a383e5f58edf3643364f67bdf)
2022-08-08[lld-macho] Support EH frame pointer encodings that use sdata4Jez Ng4-25/+117
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 (cherry picked from commit 6c9f6812523a706c11a12e6cb4119b0cf67bbb21)
2022-08-08[LLD][COFF] Ignore DEBUG_S_XFGHASH_TYPE/VIRTUALTobias Hieta3-2/+53
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 (cherry picked from commit 576375a2d670a7b1bd84b53b0187605a5f4ea0c8)
2022-08-08[ELF][AArch64] Fix potentially corrupted section content for PACFangrui Song1-2/+2
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). (cherry picked from commit d7cbfcf36ace575ec90434624279dd3ebce78c47)
2022-08-08[ELF] Keep only getTarget() call. NFCFangrui Song1-5/+0
The place from D61712 seems unneeded now. We can just use the place added by D62609 (support AArch64 BTI/PAC). (cherry picked from commit e89d6d2ac527f973c43563373dfdeb9e4c3bbcc5)
2022-08-08[ELF][PPC64] Fix potentially corrupted section content with empty .gotFangrui Song1-0/+3
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. (cherry picked from commit 28d05d672300e51f53c73fe9a4bd053e73844247)
2022-08-08[ELF] mergeCmp: work around irreflexivity bugFangrui Song1-1/+2
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. (cherry picked from commit abd9807590fc10eb92eb22aea7b50dbf08db7e9d)
2022-08-05[LLD] [MachO] Fix GCC build warningsMartin Storsjö2-3/+7
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 (cherry picked from commit 59c6f418fa3c5d6f5c8b75ebd817be8113de7931)
2022-08-03ReleaseNotes: add lld/ELF notesFangrui Song1-0/+23
For the release/15.x branch. Differential Revision: https://reviews.llvm.org/D130961
2022-08-03[LLD] [doc] Add release notes for MinGW changes for 15.xMartin Storsjö1-1/+2
2022-08-02[lld/mac] Add support for $ld$previous symbols with explicit symbol nameNico Weber5-76/+219
A symbol `$ld$previous$/Another$1.2.3$1$3.0$14.0$_xxx$` means "pretend symbol `_xxx` is in dylib `/Another` with version `1.2.3` if the deployment target is between `3.0` and `14.0` and we're targeting platform `1` (ie macOS)". This means dylibs can now inject synthetic dylibs into the link, so DylibFile needs to grow a 3rd constructor. The only other interesting thing is that such an injected dylib counts as a use of the original dylib. This patch gets this mostly right (if _only_ `$ld$previous` symbols are used from a dylib, we don't add a dep on the dylib itself, matching ld64), but one case where we don't match ld64 yet is that ld64 even omits the original dylib when linking it with `-needed-l`. Lld currently still adds a load command for the original dylib in that case. (That's for a future patch.) Fixes #56074. Differential Revision: https://reviews.llvm.org/D130725 (cherry picked from commit 241f0e8b76d544a4a07a7f775b8421632539be19)
2022-07-31[lld-macho] Release notes for 15.xJez Ng1-0/+111
From inspection of git log origin/release/14.x..origin/release/15.x -- lld/MachO Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D130850
2022-07-29[ELF][test] Fix compressed-debug-level.test with zlib-ngFangrui Song1-1/+1
The test is brittle but it seems unnecessary to remove size check now. Close #56222 (cherry picked from commit 876af563e73a3c1d6b49e13b4c1791a4208c8546)
2022-07-26[lld-macho] Fix -bitcode_process_mode arg typeKeith Smiley1-1/+1
This is still undocumented and unsupported, but if someone passed it before you would end up with a missing file error since this takes an argument that wouldn't be handled. Differential Revision: https://reviews.llvm.org/D130606
2022-07-26[ELF] addDependentLibrary: fix a use-after-free bug in archiveNameFangrui Song2-7/+13
2022-07-26[ELF] addLibrary: fix a use-after-free bug in archiveNameFangrui Song2-4/+4
It manifests as an incorrect name in --print-archive-stats=.
2022-07-26[ELF][test] Clean up print-archive-stats.sFangrui Song1-18/+20
2022-07-26[WPD] Use new llvm.public.type.test intrinsic for potentially publicly ↵Arthur Eubanks1-0/+27
visible classes Turning on opaque pointers has uncovered an issue with WPD where we currently pattern match away `assume(type.test)` in WPD so that a later LTT doesn't resolve the type test to undef and introduce an `assume(false)`. The pattern matching can fail in cases where we transform two `assume(type.test)`s into `assume(phi(type.test.1, type.test.2))`. Currently we create `assume(type.test)` for all virtual calls that might be devirtualized. This is to support `-Wl,--lto-whole-program-visibility`. To prevent this, all virtual calls that may not be in the same LTO module instead use a new `llvm.public.type.test` intrinsic in place of the `llvm.type.test`. Then when we know if `-Wl,--lto-whole-program-visibility` is passed or not, we can either replace all `llvm.public.type.test` with `llvm.type.test`, or replace all `llvm.public.type.test` with `true`. This prevents WPD from trying to pattern match away `assume(type.test)` for public virtual calls when failing the pattern matching will result in miscompiles. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D128955
2022-07-26[CMake] Fix add_subdirectory llvm buildsSebastian Neubauer1-1/+1
Fixes a regression from D117973, that used CMAKE_BINARY_DIR instead of LLVM_BINARY_DIR in some places. Differential Revision: https://reviews.llvm.org/D130555
2022-07-26[llvm-objdump,ARM] Add PrettyPrinters for Arm and AArch64.Simon Tatham51-968/+968
Most Arm disassemblers, including GNU objdump and Arm's own `fromelf`, emit an instruction's raw encoding as a 32-bit words or (for Thumb) one or two 16-bit halfwords, in logical order rather than according to their storage endianness. This is generally easier to read: it matches the encoding diagrams in the architecture spec, it matches the value you'd write in a `.inst` directive, and it means that fields within the instruction encoding that span more than one byte (such as branch offsets or `SVC` immediates) can be read directly in the encoding without having to mentally reverse the bytes. llvm-objdump already has a system of PrettyPrinter subclasses which makes it easy for a target to drop in its own preferred formatting. This patch adds pretty-printers for all the Arm targets, so that llvm-objdump will display Arm instruction encodings in their preferred layout instead of little-endian and bytewise. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D130358
2022-07-26[lld-macho] Implement -hidden-lDaniel Bertalan3-13/+23
Similarly to -load_hidden, this flag instructs the linker to not export symbols from the specified archive. While that flag takes a path, -hidden-l looks for the specified library name in the search path. The test changes are needed because -hidden-lfoo resolves to libfoo.a, not foo.a. Differential Revision: https://reviews.llvm.org/D130529
2022-07-25[cmake] Support custom package install pathsJohn Ericson1-6/+11
Firstly, we we make an additional GNUInstallDirs-style variable. With NixOS, for example, this is crucial as we want those to go in `${dev}/lib/cmake` not `${out}/lib/cmake` as that would a cmake subdir of the "regular" libdir, which is installed even when no one needs to do any development. Secondly, we make *Config.cmake robust to absolute package install paths. We for NixOS will in fact be passing them absolute paths to make the `${dev}` vs `${out}` distinction mentioned above, and the GNUInstallDirs-style variables are suposed to support absolute paths in general so it's good practice besides the NixOS use-case. Thirdly, we make `${project}_INSTALL_PACKAGE_DIR` CACHE PATHs like other install dirs are. Reviewed By: sebastian-ne Differential Revision: https://reviews.llvm.org/D117973
2022-07-25Reland "[lld-macho] Implement -load_hidden"Daniel Bertalan8-31/+160
This flag was introduced in ld64-609. It instructs the linker to link to a static library while treating its symbols as if they had hidden visibility. This is useful when building a dylib that links to static libraries but we don't want the symbols from those to be exported. Closes #51505 This reland adds bitcode file handling, so we won't get any compile errors due to BitcodeFile::forceHidden being unused. Differential Revision: https://reviews.llvm.org/D130473
2022-07-25Revert "[lld-macho] Implement -load_hidden"Daniel Bertalan7-131/+30
This reverts commit 4c79e1a3f4eb790f40239833ae237e828ce07386. Broke this bot: https://lab.llvm.org/buildbot/#builders/57/builds/20319
2022-07-25[lld-macho] Implement -load_hiddenDaniel Bertalan7-30/+131
This flag was introduced in ld64-609. It instructs the linker to link to a static library while treating its symbols as if they had hidden visibility. This is useful when building a dylib that links to static libraries but we don't want the symbols from those to be exported. Closes #51505 Differential Revision: https://reviews.llvm.org/D130473
2022-07-25[lld-macho] Demangle location name in undefined symbol diagnosticsDaniel Bertalan2-8/+14
If the `-demangle` flag is passed to lld, symbol names will now be demangled in the "referenced by:" message in addition to the referenced symbol's name, which was already demangled before this change. Differential Revision: https://reviews.llvm.org/D130490
2022-07-25[ELF] --reproduce: support --export-dynamic-symbol-listFangrui Song2-1/+5
2022-07-25[ELF] Simplify --build-id/--color-diagnostics with AliasArgs. NFCFangrui Song3-24/+14
2022-07-24Remove redundaunt override specifiers (NFC)Kazu Hirata1-4/+2
Identified with modernize-use-override.
2022-07-24[ELF] Optimize some non-constant alignTo with alignToPowerOf2. NFCFangrui Song6-32/+39
My x86-64 lld executable is 2KiB smaller. .eh_frame writing gets faster as there were lots of divisions.
2022-07-23Convert for_each to range-based for loops (NFC)Kazu Hirata2-10/+11
2022-07-23[lld-macho][nfc] Reduce nesting of code added in D130125Jez Ng1-11/+11
2022-07-23Use static_assert instead of assert (NFC)Kazu Hirata2-2/+3
Identified with misc-static-assert.
2022-07-23[lld-macho] Fold __objc_imageinfo sectionsJez Ng9-8/+296
Previously, we treated it as a regular ConcatInputSection. However, ld64 actually parses its contents and uses that to synthesize a single image info struct, generating one 8-byte section instead of `8 * number of object files with ObjC code`. I'm not entirely sure what impact this section has on the runtime, so I just tried to follow ld64's semantics as closely as possible in this diff. My main motivation though was to reduce binary size. No significant perf change on chromium_framework on my 16-core Mac Pro: base diff difference (95% CI) sys_time 1.764 ± 0.062 1.748 ± 0.032 [ -2.4% .. +0.5%] user_time 5.112 ± 0.104 5.106 ± 0.046 [ -0.9% .. +0.7%] wall_time 6.111 ± 0.184 6.085 ± 0.076 [ -1.6% .. +0.8%] samples 30 32 Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D130125
2022-07-23[lld-macho] Fix segfault when handling LTO + object file weak defsJez Ng3-2/+182
which occurs when there are EH frames present in the object file's weak def. Reviewed By: abrachet Differential Revision: https://reviews.llvm.org/D130409