aboutsummaryrefslogtreecommitdiff
path: root/lld
AgeCommit message (Collapse)AuthorFilesLines
2024-03-12[ELF] Add --compress-section to compress matched non-SHF_ALLOC sectionsFangrui Song11-19/+259
--compress-sections <section-glib>=[none|zlib|zstd] is similar to --compress-debug-sections but applies to broader sections without the SHF_ALLOC flag. lld will report an error if a SHF_ALLOC section is matched. An interesting use case is to compress `.strtab`/`.symtab`, which consume a significant portion of the file size (15.1% for a release build of Clang). An older revision is available at https://reviews.llvm.org/D154641 . This patch focuses on non-allocated sections for safety. Moving `maybeCompress` as D154641 does not handle STT_SECTION symbols for `-r --compress-debug-sections=zlib` (see `relocatable-section-symbol.s` from #66804). Since different output sections may use different compression algorithms, we need CompressedData::type to generalize config->compressDebugSections. GNU ld feature request: https://sourceware.org/bugzilla/show_bug.cgi?id=27452 Link: https://discourse.llvm.org/t/rfc-compress-arbitrary-sections-with-ld-lld-compress-sections/71674 Pull Request: https://github.com/llvm/llvm-project/pull/84855
2024-03-11[lld][RISCV] Avoid second map lookup in mergeArch. NFC (#84687)Craig Topper1-4/+4
Instead of using find and then inserting into the map, we can use insert and fix up the version using the iterator if the insert fails.
2024-03-12[LLD] [COFF] Set the right alignment for DelayDirectoryChunk (#84697)Martin Storsjö2-7/+20
This makes a difference when linking executables with delay loaded libraries for arm32; the delay loader implementation can load data from the registry with instructions that assume alignment. This issue does not show up when linking in MinGW mode, because a PseudoRelocTableChunk gets injected, which also sets alignment, even if the chunk itself is empty.
2024-03-10[ELF] Move getSymbol/getRelocTargetSym from ObjFile<ELFT> to InputFile. NFCFangrui Song8-30/+29
This removes lots of unneeded `template getFile<ELFT>()`.
2024-03-11[LLD][COFF] Add support for IMPORT_NAME_EXPORTAS import library names. (#83211)Jacek Caban2-6/+30
This allows handling importlibs produced by llvm-dlltool in #78772. ARM64EC import libraries use it by default, but it's supported by MSVC link.exe on other platforms too. This also avoids assuming null-terminated input, like in #78769.
2024-03-10[lld-macho][NFC] Refactor ObjCSelRefsSection out of ObjCStubsSection (#83878)alx323-49/+83
Currently ObjCStubsSection is handling both the logic for the "__objc_stubs" section, as well as the logic for the "__objc_selrefs" section. While this is OK for now, it will be an issue for other features that want to interact with the "__objc_selrefs" section, such as upcoming relative method lists feature - which will also want to create / reference entries in the "__objc_selrefs" section. In this PR we split the logic relating to handling the "__objc_selrefs" section into a new SyntheticSection (ObjCSelRefsSection). Non-functional change - neither the behavior nor implementation changes, the interface is just made more friendly to not have "__objc_selrefs" so bound to "__objc_stubs". --------- Co-authored-by: Alex B <alexborcan@meta.com>
2024-03-08[ELF] Simplify GdbIndexSection. NFCFangrui Song1-17/+10
2024-03-08[ELF] Sort sections in order. NFCFangrui Song1-1/+1
2024-03-06[MC] Move CompressDebugSections/RelaxELFRelocations from ↵Fangrui Song1-1/+1
TargetOptions/MCAsmInfo to MCTargetOptions The convention is for such MC-specific options to reside in MCTargetOptions. However, CompressDebugSections/RelaxELFRelocations do not follow the convention: `CompressDebugSections` is defined in both TargetOptions and MCAsmInfo and there is forwarding complexity. Move the option to MCTargetOptions and hereby simplify the code. Rename the misleading RelaxELFRelocations to X86RelaxRelocations. llvm-mc -relax-relocations and llc -x86-relax-relocations can now be unified.
2024-03-06[ELF,test] Remove unneeded -relax-relocations from llvm-mcFangrui Song10-14/+13
This is option is x86-64 specific and should not be used by AMDGPU/SystemZ. On x86-64, the option defaults to true and is unnecessary.
2024-03-06[ELF] Reject error-prone meta characters in input section descriptionFangrui Song2-10/+36
The lexer is overly permissive. When parsing file patterns in an input section description and there is a missing `)`, we would accept many non-sensible tokens (e.g. `}`) as patterns, leading to confusion, e.g. `*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.text*)) } PROVIDE_HIDDEN(__code_end = .)` (#81804). Ideally, the lexer should be stateful to report more errors like GNU ld and get rid of hacks like `ScriptLexer::maybeSplitExpr`, but that would require a large rewrite of the lexer. For now, just reject certain non-wildcard meta characters to detect common mistakes. Pull Request: https://github.com/llvm/llvm-project/pull/84130
2024-03-06[AMDGPU] Rename COV module flag to amdhsa_code_object_version (#79905)Emma Pilkington1-1/+1
The previous name 'amdgpu_code_object_version', was misleading since this is really a property of the HSA OS. The new spelling also matches the asm directive I added in bc82cfb.
2024-03-05[ELF] Improve wildcard testFangrui Song1-10/+10
2024-03-05[ELF] Improve wildcard tests for input section descriptionsFangrui Song1-12/+42
2024-03-05Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (#83702)Mehdi Amini1-1/+1
The base class llvm::ThreadPoolInterface will be renamed llvm::ThreadPool in a subsequent commit. This is a breaking change: clients who use to create a ThreadPool must now create a DefaultThreadPool instead.
2024-03-05[lld][LoongArch] Fix handleUleb128Weining Lu1-2/+3
2024-03-05[lld][test] Fix sanitizer buildbot failureWeining Lu1-1/+1
Buildbot failure: https://lab.llvm.org/buildbot/#/builders/5/builds/41530/steps/9/logs/stdio
2024-03-05[lld][LoongArch] Support the R_LARCH_{ADD,SUB}_ULEB128 relocation types (#81133)Jinyang He2-0/+121
For a label difference like `.uleb128 A-B`, MC generates a pair of R_LARCH_{ADD,SUB}_ULEB128 if A-B cannot be folded as a constant. GNU assembler generates a pair of relocations in more cases (when A or B is in a code section with linker relaxation). It is similar to RISCV. R_LARCH_{ADD,SUB}_ULEB128 relocations are created by Clang and GCC in `.gcc_except_table` and other debug sections with linker relaxation enabled. On LoongArch, first read the buf and count the available space. Then add or sub the value. Finally truncate the expected value and fill it into the available space.
2024-03-02[lld] Fixes for unitests in standalone builds (#83670)Michał Górny2-3/+4
1. Replace the obsolete `llvm_add_unittests()` CMake function with an explicit check for `TARGET llvm_gtest`. This is more consistent with the rest of the code, and it makes it possible to avoid checking out `third-party` tree. 2. Add `LLDUnitTests` test dependency to standalone builds. It is defined unconditionally, and actually necessary to ensure that unit tests will be built.
2024-03-01[lld][macho][NFC] Add specific namespace scope for objc symbol names (#83618)alx323-6/+8
Move symbol names from directly under `objc` scope to `objc::symbol_names`. Ex: `objc::klass` -> `objc::symbol_names::klass` Co-authored-by: Alex B <alexborcan@meta.com>
2024-03-01[ELF] Internalize enumFangrui Song3-1/+6
g++ -flto has a diagnostic `-Wodr` about mismatched redeclarations, which even apply to `enum`. Fix #83529 Reviewers: thesamesam Reviewed By: thesamesam Pull Request: https://github.com/llvm/llvm-project/pull/83604
2024-02-27[lld] Adds support for xros. (#83031)rohit-rao4-8/+22
2024-02-27Improve readability of "undefined reference" message (#82671)DeanSturtevant14-12/+13
The current message implies a command line flag caused an undefined reference. This of course is wrong and causes confusion. The message now more accurately reflects the true state of affairs.
2024-02-26[lld/ELF] Add documentation on large sections (#82560)Arthur Eubanks5-0/+53
Fixes #82438
2024-02-25[lld][WebAssembly] Add `--no-growable-memory` (#82890)SingleAccretion6-12/+46
We recently added `--initial-heap` - an option that allows one to up the initial memory size without the burden of having to know exactly how much is needed. However, in the process of implementing support for this in Emscripten (https://github.com/emscripten-core/emscripten/pull/21071), we have realized that `--initial-heap` cannot support the use-case of non-growable memories by itself, since with it we don't know what to set `--max-memory` to. We have thus agreed to move the above work forward by introducing another option to the linker (see https://github.com/emscripten-core/emscripten/pull/21071#discussion_r1491755616), one that would allow users to explicitly specify they want a non-growable memory. This change does this by introducing `--no-growable-memory`: an option that is mutally exclusive with `--max-memory` (for simplicity - we can also decide that it should override or be overridable by `--max-memory`. In Emscripten a similar mix of options results in `--no-growable-memory` taking precedence). The option specifies that the maximum memory size should be set to the initial memory size, effectively disallowing memory growth. Closes #81932.
2024-02-24[Mips] Fix unable to handle inline assembly ends with compat-branch o… ↵yingopq1-8/+10
(#77291) …n MIPS Modify: Add a global variable 'CurForbiddenSlotAttr' to save current instruction's forbidden slot and whether set reorder. This is the judgment condition for whether to add nop. We would add a couple of '.set noreorder' and '.set reorder' to wrap the current instruction and the next instruction. Then we can get previous instruction`s forbidden slot attribute and whether set reorder by 'CurForbiddenSlotAttr'. If previous instruction has forbidden slot and .set reorder is active and current instruction is CTI. Then emit a NOP after it. Fix https://github.com/llvm/llvm-project/issues/61045. Because https://reviews.llvm.org/D158589 was 'Needs Review' state, not ending, so we commit pull request again.
2024-02-20[ELF] Support placing .lbss/.lrodata/.ldata after .bssFangrui Song6-22/+77
https://reviews.llvm.org/D150510 places .lrodata before .rodata to minimize the number of permission transitions in the memory image. However, this layout is less ideal for -fno-pic code (which is still important). Small code model -fno-pic code has R_X86_64_32S relocations with a range of `[0,2**31)` (if we ignore the negative area). Placing `.lrodata` earlier exerts relocation pressure on such code. Non-x86 64-bit architectures generally have a similar `[0,2**31)` limitation if they don't use PC-relative relocations. If we place .lrodata later, we will need one extra PT_LOAD. Two layouts are appealing: * .bss/.lbss/.lrodata/.ldata (GNU ld) * .bss/.ldata/.lbss/.lrodata The GNU ld layout has the nice property that there is only one BSS (except .tbss/.relro_padding). Add -z lrodata-after-bss to support this layout. Since a read-only PT_LOAD segment (for large data sections) may appear after RW PT_LOAD segments. The placement of `_etext` has to be adjusted. Pull Request: https://github.com/llvm/llvm-project/pull/81224
2024-02-20[ELF] .eh_frame: use errorOrWarn for "PC offset is too large"Fangrui Song2-3/+7
errorOrWarn is more conventional for recoverable errors. This error message does not have to use `fatal`, and we try to remove such uses in parallel code paths.
2024-02-21[WebAssembly] Add segment RETAIN flag to support private retained data (#81539)Yuta Saito3-8/+94
In WebAssembly, we have `WASM_SYMBOL_NO_STRIP` symbol flag to mark the referenced content as retained. However, the flag is not enough to express retained data that is not referenced by any symbol. This patch adds a new segment flag`WASM_SEG_FLAG_RETAIN` to support "private" linkage data that is retained by llvm.used. This kind of data that is not referenced but must be retained is usually used with encapsulation symbols (__start/__stop). Swift runtime uses this technique and depends on the fact "all metadata sections in live objects are retained", which was not guaranteed with `--gc-sections` before this patch. This is a revised version of https://reviews.llvm.org/D126950 (has been reverted) based on @MaskRay's comments
2024-02-16Revert "[lld] enable fixup chains by default (#79894)"Hans Wennborg7-54/+44
This caused links to fail with: lld/MachO/Symbols.cpp:97: virtual uint64_t lld::macho::Defined::getVA() const: Assertion `target->usesThunks()' failed. or crash when asserts are disabled. See comment on https://github.com/llvm/llvm-project/pull/79894 > Enable chained fixups in lld when all platform and version criteria are > met. This is an attempt at simplifying the logic used in ld 907: > > https://github.com/apple-oss-distributions/ld64/blob/93d74eafc37c0558b4ffb88a8bc15c17bed44a20/src/ld/Options.cpp#L5458-L5549 > > Some changes were made to simplify the logic: > - only enable chained fixups for macOS from 13.0 to avoid the arch check > - only enable chained fixups for iphonesimulator from 16.0 to avoid the > arch check > - don't enable chained fixups for not specifically listed platforms > - don't enable chained fixups for arm64_32 This reverts commit 775c2856fb32868f357a3ce3f2b4139541e12578.
2024-02-16[lld/MachO] Fix assert on unsorted data-in-code entries (#81758)Nico Weber2-9/+24
When the data-in-code entries are in separate sections, they are not guaranteed to be sorted. In particular, 68b1cc36f3df marked some libc++ string functions as noinline, which leads to global ctors involving strings now producing data-in-code sections in __TEXT,__StaticInit, which is why this now happens in practice. Since data-in-code entries are relatively rare and small, just sort them. No observed performance impact. See also crbug.com/41487860
2024-02-14[lld/ELF] Avoid unnecessary TPOFF relocations in GOT for -pie (#81739)Ulrich Weigand2-1/+35
With the new SystemZ port we noticed that -pie executables generated from files containing R_390_TLS_IEENT relocations will have unnecessary relocations in their GOT: 9e8d8: R_390_TLS_TPOFF *ABS*+0x18 This is caused by the config->isPic conditon in addTpOffsetGotEntry: static void addTpOffsetGotEntry(Symbol &sym) { in.got->addEntry(sym); uint64_t off = sym.getGotOffset(); if (!sym.isPreemptible && !config->isPic) { in.got->addConstant({R_TPREL, target->symbolicRel, off, 0, &sym}); return; } It is correct that we need to retain a TPOFF relocation if the target symbol is preemptible or if we're building a shared library. But when building a -pie executable, those values are fixed at link time and there's no need for any remaining dynamic relocation. Note that the equivalent MIPS-specific code in MipsGotSection::build checks for config->shared instead of config->isPic; we should use the same check here. (Note also that on many other platforms we're not even using addTpOffsetGotEntry in this case as an IE->LE relaxation is applied before; we don't have this type of relaxation on SystemZ.)
2024-02-13[lld/ELF] fix typos to cycle botsNico Weber4-8/+8
2024-02-13[Object][COFF][NFC] Make writeImportLibrary NativeExports argument optional. ↵Jacek Caban1-6/+6
(#81600) It's not interesting for majority of downstream users.
2024-02-13[lld] Add target support for SystemZ (s390x) (#75643)Ulrich Weigand36-10/+1959
This patch adds full support for linking SystemZ (ELF s390x) object files. Support should be generally complete: - All relocation types are supported. - Full shared library support (DYNAMIC, GOT, PLT, ifunc). - Relaxation of TLS and GOT relocations where appropriate. - Platform-specific test cases. In addition to new platform code and the obvious changes, there were a few additional changes to common code: - Add three new RelExpr members (R_GOTPLT_OFF, R_GOTPLT_PC, and R_PLT_GOTREL) needed to support certain s390x relocations. I chose not to use a platform-specific name since nothing in the definition of these relocs is actually platform-specific; it is well possible that other platforms will need the same. - A couple of tweaks to TLS relocation handling, as the particular semantics of the s390x versions differ slightly. See comments in the code. This was tested by building and testing >1500 Fedora packages, with only a handful of failures; as these also have issues when building with LLD on other architectures, they seem unrelated. Co-authored-by: Tulio Magno Quites Machado Filho <tuliom@redhat.com>
2024-02-13[LLD] [MinGW] Implement the --lto-emit-asm and -plugin-opt=emit-llvm options ↵Martin Storsjö3-0/+16
(#81475) These were implemented in the COFF linker in 3923e61b96cf90123762f0e0381504efaba2d77a and d12b99a4313816cf99e97cb5f579e2d51ba72b0b. This matches the corresponding options in the ELF linker.
2024-02-12[ELF] Place _edata before .bss in the presence of .ldataFangrui Song2-5/+8
This minor issue is identified while working on #81224.
2024-02-12[ELF] Properly reject unsupported e_machineFangrui Song2-1/+13
Fix an incorrect llvm_unreachable.
2024-02-13[llvm-lib] Add support for -defArm64Native argument. (#81426)Jacek Caban1-6/+6
This can be used to create import libraries that contain both ARM64EC and native exports. The implementation follows observed MSVC lib.exe behaviour. It's ignored on targets other than ARM64EC.
2024-02-12[LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463)Martin Storsjö1-10/+19
If llvm-readobj is built with a 32 bit time_t, it can't print such timestamps correctly.
2024-02-10[LLD] [COFF] Pick timestamps from the SOURCE_DATE_EPOCH variable (#81326)Martin Storsjö2-1/+27
The SOURCE_DATE_EPOCH environment variable can be set in order to get reproducible build. When linking PE/COFF modules with LLD, the timestamp field is set to the current time, unless either the /timestamp: or /Brepro option is set. If neither of them is set, check the SOURCE_DATE_EPOCH variable, before resorting to using the actual current date and time. See https://reproducible-builds.org/docs/source-date-epoch/ for reference on the use of this variable.
2024-02-09[lld] Fix test failures when running as root user (#81339)Tom Stellard7-7/+7
This makes it easier to run the tests in a containerized environment.
2024-02-09[ELF] Apply forgotten change to #81223Fangrui Song1-5/+5
2024-02-09[ELF] Improve _etext/_edata testsFangrui Song2-34/+45
2024-02-09[ELF] --no-rosegment: don't mark read-only PT_LOAD segments executable (#81223)Fangrui Song2-13/+17
Once we move `.lrodata` after .bss (#78521), or if we use `SECTIONS` commands, certain read-only sections may be in their own PT_LOAD, not in the traditional "text segment". Current --no-rosegment code may unnecessarily mark read-only PT_LOAD executable. Fix it.
2024-02-08[ELF] Improve --ro-rosegment testsFangrui Song1-6/+24
2024-02-08[ELF] Improve --ro-rosegment/--omagic/--nmagic testsFangrui Song1-141/+59
Notably, test that --ro-rosegment with a linker script may unnecessarily make a read-only PT_LOAD executable.
2024-02-07[LLD][ELF] Silence warning when building with latest MSVCAlexandre Ganea1-2/+2
This fixes: ``` [193/3517] Building CXX object tools\lld\ELF\CMakeFiles\lldELF.dir\Arch\LoongArch.cpp.obj C:\git\llvm-project\lld\ELF\Arch\LoongArch.cpp(683): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended? ```
2024-02-07[Object][Wasm] Use file offset for section addresses in linked wasm files ↵Derek Schuff3-19/+19
(#80529) Wasm has no unified virtual memory space as other object formats and architectures do, so previously WasmObjectFile reported 0 for all section addresses, and until 428cf71ff used section offsets for function symbols. Now we use file offsets for function symbols, and this change switches section addresses to do the same (in linked files). The main result of this is that objdump now reports VMAs in section listings, and also uses file offets rather than section offsets when disassembling linked binaries (matching the behavior of other disassemblers and stack traces produced by browwsers). To make this work, this PR also updates objdump's generation of synthetics fallback symbols to match lib/Object and also correctly plumbs symbol types for regular and dummy symbols through to the backend to avoid needing special knowledge of address 0. This also paves the way for generating symbols from name sections rather than symbol tables or imports (see #76107) by allowing the disassembler's synthetic fallback symbols match the name-section generated symbols (in a followup PR).
2024-02-06[llvm-readobj][Object][COFF] Print COFF import library symbol export name. ↵Jacek Caban3-0/+18
(#78769) getExportName implementation is based on lld-link. In its current form, it's mostly about convenience, but it will be more useful for EXPORTAS support, for which export name is not possible to deduce from other printed properties.