aboutsummaryrefslogtreecommitdiff
path: root/lld
AgeCommit message (Collapse)AuthorFilesLines
2022-04-25[ELF] --emit-relocs: fix missing STT_SECTION when the first input section is ↵Fangrui Song2-17/+78
synthetic addSectionSymbols suppresses the STT_SECTION symbol if the first input section is non-SHF_MERGE synthetic. This is incorrect when the first input section is synthetic while a non-synthetic input section exists: * `.bss : { *(COMMON) *(.bss) }` (abc388ed3cf0ef7e617ebe243d3b0b32d29e69a5 regressed the case because COMMON symbols precede .bss in the absence of a linker script) * Place a synthetic section in another section: `.data : { *(.got) *(.data) }` For `%t/a1` in the new test emit-relocs-synthetic.s, ld.lld produces incorrect relocations with symbol index 0. ``` 0000000000000000 <_start>: 0: 8b 05 33 00 00 00 movl 51(%rip), %eax # 0x39 <bss> 0000000000000002: R_X86_64_PC32 *ABS*+0xd 6: 8b 05 1c 00 00 00 movl 28(%rip), %eax # 0x28 <common> 0000000000000008: R_X86_64_PC32 common-0x4 c: 8b 05 06 00 00 00 movl 6(%rip), %eax # 0x18 000000000000000e: R_X86_64_GOTPCRELX *ABS*+0x4 ``` Fix the issue by checking every input section. Reviewed By: ikudrin Differential Revision: https://reviews.llvm.org/D122463 (cherry picked from commit 7370a489b1005e424b23bd0009af2365aef4db53)
2022-04-18Force GHashCell to be 8-byte-aligned.Eli Friedman1-1/+5
Otherwise, with recent versions of libstdc++, clang can't tell that the atomic operations are properly aligned, and generates calls to libatomic. (Actually, because of the use of reinterpret_cast, it wasn't guaranteed to be aligned, but I think it ended up being aligned in practice.) Fixes https://github.com/llvm/llvm-project/issues/54790 , the part where LLVM failed to build. Differential Revision: https://reviews.llvm.org/D123872 (cherry picked from commit 13fc1781735a327699d9522e8e44899acf92a61a)
2022-04-14[LLD][COFF] Fix TypeServerSource matcher with more than one collisionTobias Hieta3-13/+15
Follow-up from 98bc304e9faded44f1d8988ffa4c5d8b50c759ec - while that commit fixed when you had two PDBs colliding on the same Guid it didn't fix the case where you had more than two PDBs using the same Guid. This commit fixes that and also tests much more carefully that all the types are correct no matter the order. Reviewed By: aganea, saudi Differential Revision: https://reviews.llvm.org/D123185 (cherry picked from commit 0dfa8a019d9a64d7706eb82bdb083fd9b815e088)
2022-04-14[lld][COFF] Fix TypeServerSource lookup on GUID collisionsTobias Hieta7-2/+2426
Microsoft shipped a bunch of PDB files with broken/invalid GUIDs which lead lld to use 0xFF as the key for these files in an internal cache. When multiple files have this key it will lead to collisions and confused symbol lookup. Several approaches to fix this was considered. Including making the key the path to the PDB file, but this requires some filesystem operations in order to normalize the file path. Since this only happens with malformatted PDB files and we haven't seen this before they malformatted files where shipped with visual studio we probably shouldn't optimize for this use-case. Instead we now just don't insert files with Guid == 0xFF into the cache map and warn if we get collisions so similar problems can be found in the future instead of being silent. Discussion about the root issue and the approach to this fix can be found on Github: https://github.com/llvm/llvm-project/issues/54487 Reviewed By: aganea Differential Revision: https://reviews.llvm.org/D122372 (cherry picked from commit 98bc304e9faded44f1d8988ffa4c5d8b50c759ec)
2022-04-05[ELF] Fix llvm_unreachable failure when COMMON is placed in SHT_PROGBITS ↵Fangrui Song2-42/+37
output section Fix a regression in aa27bab5a1a17e9c4168a741a6298ecaa92c1ecb: COMMON in an SHT_PROGBITS output section caused llvm_unreachable failure. (cherry picked from commit 1db59dc8e28819b1960dae8e7fe6d79ad4b03340)
2022-03-07[LLD] [COFF] Order .debug_* sections at the end, to avoid leaving gaps if ↵Martin Storsjö2-1/+13
stripped So far, we sort all discardable sections at the end, with only some extra logic to make sure that the .reloc section is at the start of that group of sections. But if there are other discardable sections, other than .reloc, they must also be ordered before .debug_* sections, to avoid leaving gaps if the executable is stripped. (Stripping executables doesn't remove all discardable sections, only the ones named .debug_*). Rust binaries seem to include a .rmeta section, which is marked discardable. This fixes stripping such binaries if built with dwarf debug info included. This fixes issues observed in MSYS2 in https://github.com/msys2/MINGW-packages/pull/10555. Differential Revision: https://reviews.llvm.org/D120805 (cherry picked from commit 4c3b74b7f5d6192d1731c88f1aeb396bc51d4949)
2022-03-07[MC][WebAssembly] Fix crash when relocation addend underlows U32Sam Clegg4-4/+55
For the object file writer we need to allow the underflow (ar write zero), but for the final linker output we should probably generate an error (I've left that as a TODO for now). Fixes: https://github.com/llvm/llvm-project/issues/54012 Differential Revision: https://reviews.llvm.org/D120522 (cherry picked from commit 4c75521ce0b1ac55fba1a91ef5156fc811f5dfcb)
2022-02-26[ELF][X86] Don't create IBT .plt if there is no PLT entryJoao Moreira4-3/+17
https://github.com/ClangBuiltLinux/linux/issues/1606 When GNU_PROPERTY_X86_FEATURE_1_IBT is enabled, ld.lld will create .plt output section even if there is no PLT entry. Fix this by implementing IBTPltSection::isNeeded instead of using the default code path (which always returns true). Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D120600 (cherry picked from commit 9d7001eba9c4cb311e03cd8cdc231f9e579f2d0f)
2022-02-25[ELF] Support some absolute/PC-relative relocation types for REL formatFangrui Song4-0/+55
ctfconvert seems to use REL-format `.rel.SUNW_dof` for 32-bit architectures. ``` Binary file usr/ports/lang/perl5.32/work/perl-5.32.1/dtrace_mini.o matches [alfredo.junior@dell-a ~/tmp/llvm-bug]$ readelf -r dtrace_mini.o Relocation section (.rel.SUNW_dof): r_offset r_info r_type st_value st_name 00000184 0000281a R_PPC_REL32 00000000 $dtrace1772974259.Perl_dtrace_probe_load ``` Support R_PPC_REL32 to fix `ld.lld: error: drti.c:(.SUNW_dof+0x4E4): internal linker error: cannot read addend for relocation R_PPC_REL32`. While here, add some common relocation types for AArch64, PPC, and PPC64. We perform minimum tests. Reviewed By: adalava, arichardson Differential Revision: https://reviews.llvm.org/D120535 (cherry picked from commit 767e64fc11d7734843ec5bb0bd3f7330541bb1a6)
2022-02-18[ELF] Fix .strtab corruption when a symbol name is emptyorigin/release/14.xFangrui Song1-0/+1
This is a simplified c12d49c4e286fa108d4d69f1c6d2b8d691993ffd in main which just fixes the bug but does not affect the -O2 deduplication.
2022-02-16[lld] One more formatting fix for the release notesJez Ng1-1/+1
2022-02-16[lld] Fix RST formatting in release notesJez Ng1-10/+10
2022-02-15[ELF][PPC64] Fix assertion failure for branches to hidden undefined weak for ↵Fangrui Song5-53/+55
-no-pie Reported by Stefan Pintilie in D119773. For a branch to a hidden undefined weak symbol, there is an `assert(sym->getVA());` failure in PPC64LongBranchTargetSection::writeTo for a -no-pie link. The root cause is that we unnecessarily create the thunk for the -no-pie link. Fix this by changing the condition to just `s.isUndefined()`. See the inline comment. Rename ppc64-weak-undef-call.s to ppc64-undefined-weak.s to be consistent with other architectures. Reviewed By: sfertile, stefanp Differential Revision: https://reviews.llvm.org/D119787 (cherry picked from commit 53b59fdc52bf6c8bf15ce7c146d2cebe338f34a7)
2022-02-15[lld-macho] Fill out release notes for 14.xJez Ng1-4/+79
Differential Revision: https://reviews.llvm.org/D119811
2022-02-14ReleaseNotes: add lld/ELF notesFangrui Song1-5/+53
For the release/14.x branch. Differential Revision: https://reviews.llvm.org/D119318
2022-02-09[ELF] Warn about to-be-removed -d, -dc, -dp, and --[no-]define-commonFangrui Song2-5/+10
See https://github.com/llvm/llvm-project/issues/53660
2022-02-09[docs] Add release notes for things that I've been involved inMartin Storsjö1-2/+7
2022-02-08[ELF] --warn-backrefs: suppress warnings for backward references within the ↵Fangrui Song2-13/+21
archive (cherry picked from commit 99580e29d821beeaf75345deb3e4cc2c6808bfc0)
2022-02-08[lld][clang][cmake] Clean up a few thingsJohn Ericson1-6/+12
- If not using `llvm-config`, `LLVM_MAIN_SRC_DIR` now has a sane default - `LLVM_CONFIG_PATH` will continue to work for LLD for back compat. - More quoting of paths in an abundance of caution. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D118792 (cherry picked from commit e0eeae9a447004cc346d9bf36c0d02f45e276a7c)
2022-02-07Fix lld standalone buildMariusz Ceier1-1/+1
lld/ELF/OutputSections.cpp includes llvm/Config/config.h for LLVM_ENABLE_ZLIB definition, but llvm/Config/config.h doesn't exist in standalone build. To fix this, this patch moves LLVM_ENABLE_ZLIB from config.h to llvm-config.h and updates OutputSections.cpp to include llvm-config.h instead of config.h Reviewed By: MaskRay, mgorny Differential Revision: https://reviews.llvm.org/D119058 (cherry picked from commit e8bff9ae54a55b4dbfeb6ba55f723abbd81bf494)
2022-02-05[ELF] Fix crash when an input is incompatible with a lazy object fileFangrui Song2-6/+8
The diagnostic is concise. It is ok because the case is rare. (cherry picked from commit bad1b7fbb0fec532f097ac59805562020f895962)
2022-02-04[ELF] Support R_PPC_NONE/R_PPC64_NONE in getImplicitAddendFangrui Song3-0/+32
Similar to f457863ae345d2635026501f5383e0e625869639 (cherry picked from commit 53fc5d9b9a0110f097c6e9f7aa3bff3621eaf268)
2022-02-04[ELF][test] Test getImplicitAddend for ↵Fangrui Song4-89/+26
R_ARM_NONE/R_RISCV_NONE/R_386_NONE/R_X86_64_NONE Similar to f457863ae345d2635026501f5383e0e625869639 (cherry picked from commit 3fd30958b79293f64545c7328c58982f959feb51)
2022-02-04[ELF] Support REL-format R_AARCH64_NONE relocationFangrui Song3-26/+71
-fprofile-use=/-fprofile-sample-use= compiles may produce REL-format .rel.llvm.call-graph-profile even if the prevailing format is RELA on AArch64. Add R_AARCH64_NONE to getImplicitAddend to fix this linker error: ``` ld.lld: error: internal linker error: cannot read addend for relocation R_AARCH64_NONE PLEASE submit a bug report to https://crbug.com and run tools/clang/scripts/process_crashreports.py (only works inside Google) which will upload a report and include the crash backtrace. ``` (cherry picked from commit f457863ae345d2635026501f5383e0e625869639)
2022-02-01[docs] Remove hard-coded version numbers from sphinx configsTom Stellard2-17/+10
This updates all the non-runtime project release notes to use the version number from CMake instead of the hard-coded version numbers in conf.py. It also hides warnings about pre-releases when the git suffix is dropped from the LLVM version in CMake. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D112181
2022-02-02[lld][ELF] Add support for ADRP+ADD optimization for AArch64Alexander Shaposhnikov7-6/+188
This diff adds support for ADRP+ADD optimization for AArch64 described in https://github.com/ARM-software/abi-aa/commit/d2ca58c54b8e955cfef25c71822f837ae0439d73 i.e. under appropriate constraints ADRP x0, symbol ADD x0, x0, :lo12: symbol can be turned into NOP ADR x0, symbol Test plan: make check-all Differential revision: https://reviews.llvm.org/D117614
2022-02-01[lld-macho][nfc] Comments and style fixesJez Ng6-18/+29
Added some comments (particularly around finalize() and finalizeContents()) as well as doing some rephrasing / grammar fixes for existing comments. Also did some minor style fixups, such as by putting methods together in a class definition and having fields of similar types next to each other. Reviewed By: #lld-macho, oontvoo Differential Revision: https://reviews.llvm.org/D118714
2022-02-01[ELF] Update flag propagation rule to ignore discarded output sectionsFangrui Song2-6/+8
See the updated insert-before.test for the effects: many synthetic sections are SHF_ALLOC|SHF_WRITE. If they are discarded, we don't want to propagate their flags to subsequent output section descriptions. `getFirstInputSection(sec) == nullptr` can technically be merged into `isDiscardable` but I'd like to postpone that as not sharing code may give more refactoring opportunity. Depends on D118529. Reviewed By: peter.smith, bluca Differential Revision: https://reviews.llvm.org/D118530
2022-02-01[ELF] Rename adjustSectionsBeforeSorting to adjustOutputSections and make it ↵Fangrui Song5-20/+18
affect INSERT commands adjustSectionsBeforeSorting updates some output section attributes (alignment/flags) and removes discardable empty sections. When it is called, INSERT commands have not been processed. Therefore the flags propagation rule may not affect output sections defined in an INSERT command properly. Fix this by moving processInsertCommands before adjustSectionsBeforeSorting. adjustSectionsBeforeSorting is somewhat misnamed. The order between it and sortInputSections does not matter. With the pass shuffle, the name of adjustSectionsBeforeSorting becomes wrong. Therefore rename it. The new name is not set into stone. The function mixes several tasks and the code may be refactored in a way that we may give them more meaningful names. With this patch, I think the behavior of attribute propagation becomes more reasonable. In particular, in the absence of non-INSERT SECTIONS, inserting a section after a SHF_ALLOC one will give us a SHF_ALLOC section, not a non-SHF_ALLOC one (see linkerscript/insert-after.test). Reviewed By: peter.smith, bluca Differential Revision: https://reviews.llvm.org/D118529
2022-02-01[ELF] Deduplicate names of local symbols only with -O2Fangrui Song3-2/+41
The deduplication requires a DenseMap of the same size of the local part of .strtab . I optimized it in e20544543478b259eb09fa0a253d4fb1a5525d9e but it is still quite slow. For Release build of clang, deduplication makes .strtab 1.1% smaller and makes the link 3% slower. For chrome, deduplication makes .strtab 0.1% smaller and makes the link 6% slower. I suggest that we only perform the optimization with -O2 (default is -O1). Not deduplicating local symbol names will simplify parallel symbol table write. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D118577
2022-02-01[ELF] Simplify code with invokeELFT. NFCFangrui Song2-34/+3
2022-02-01[ELF] De-template LinkerDriver::link. NFCFangrui Song3-27/+33
Replace `f<ELFT>(x)` with `InvokeELFT(f, x)`. The size reduction comes from turning `link` from 4 specializations into 1. My x86-64 lld executable is 26KiB smaller. Reviewed By: ikudrin Differential Revision: https://reviews.llvm.org/D118551
2022-02-01[lld][MachO] Fix typo in rename.sAlexander Shaposhnikov1-1/+1
2022-02-01[lld][ELF] Add missing RUN in aarch64-adrp-ldr-got.sAlexander Shaposhnikov1-1/+1
2022-02-01[ELF] Change vector<Symbol *> to SmallVector. NFCFangrui Song1-1/+1
2022-02-01[ELF] Change vector<InputSection *> to SmallVector. NFCFangrui Song4-6/+6
My x86-64 lld executable is 8KiB smaller.
2022-02-01[ELF] Switch split-stack to use SmallVector. NFCFangrui Song1-2/+3
My x86-64 lld executable is 1.1KiB smaller.
2022-01-31[lld-macho][test] Add test for UUID formatJez Ng1-0/+9
Reviewed By: keith Differential Revision: https://reviews.llvm.org/D118646
2022-01-31[BitcodeWriter] Fix cases of some functionsFangrui Song1-1/+1
`WriteIndexToFile` is used by external projects so I do not touch it.
2022-01-30[ELF] splitStrings: replace entSize==1 special case with manual loop ↵Fangrui Song2-20/+20
unswitch. NFC My x86-64 lld executable is actually smaller.
2022-01-30[ELF] Simplify SectionBase::partition handling and make it live by default. NFCFangrui Song5-12/+8
Previously an InputSectionBase is dead (`partition==0`) by default. SyntheticSection calls markLive and BssSection overrides that with markDead. It is more natural to make InputSectionBase live by default and let --gc-sections mark InputSectionBase dead. When linking a Release build of clang: * --no-gc-sections:, the removed `inputSections` loop decreases markLive time from 4ms to 1ms. * --gc-sections: the extra `inputSections` loop increases markLive time from 0.181296s to 0.188526s. This is as of we lose the removing one `inputSections` loop optimization (4374824ccf6e7ae68264d996a9ae5bb5e3be7fc5). I believe the loss can be mitigated if we refactor markLive.
2022-01-30[ELF] Change splitSections to objectFiles based parallelForEach. NFCFangrui Song1-7/+13
The work is more balanced.
2022-01-30[lld-macho] Add support for -add_empty_sectionKeith Smiley3-0/+28
This is a ld64 option equivalent to `-sectcreate seg sect /dev/null` that's useful for creating sections like the RESTRICT section. Differential Revision: https://reviews.llvm.org/D117749
2022-01-30[test][lld-macho] Improve LC_FUNCTION_STARTS test coverageKeith Smiley1-0/+27
Previously functions that aren't included in the symtab were also excluded from the function starts. Symbols missing from function starts degrades the debugger experience in the case you don't have debug info for them. Differential Revision: https://reviews.llvm.org/D114275
2022-01-30[ELF] copyShtGroup: replace unordered_set<uint32_t> with DenseSet<uint32_t>. NFCFangrui Song2-4/+2
We don't need to support the empty/tombstone key section index.
2022-01-30[ELF] crtbegin/crtend test: replace std::regex with hand-written matcher. NFCFangrui Song1-15/+11
My x86-64 lld executable is 18KiB smaller.
2022-01-30[ELF][test] Test {crtbegin,crtend}{S,T}.oFangrui Song1-1/+5
2022-01-30[ELF] Simplify maybeCompress with lld::split. NFCFangrui Song1-6/+3
2022-01-30[ELF] Optimize MergeInputSection::splitNonStrings with resize_for_overwrite. NFCFangrui Song2-1/+2
2022-01-29[ELF] Add some Mips*Section to InStruct and change make<Mips*Section> to ↵Fangrui Song3-15/+21
std::make_unique Similar to D116143. My x86-64 lld executable is 20+KiB smaller.