aboutsummaryrefslogtreecommitdiff
path: root/lld
AgeCommit message (Collapse)AuthorFilesLines
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.
2022-01-29[ELF] Remove make<std::unique_ptr<MemoryBuffer>>. NFCFangrui Song1-2/+2
2022-01-29[ELF] De-template getErrorPlace. NFCFangrui Song1-16/+1
2022-01-29[ELF] De-template getAndFeatures. NFCFangrui Song2-6/+5
2022-01-29[ELF] Make errorOrWarn opaque to decrease code size. NFCFangrui Song2-6/+8
In my x86-64 lld, .text is -3.08Ki smaller.
2022-01-29[ELF] Optimize obj.getSectionIndex. NFCFangrui Song1-3/+10
2022-01-29[ELF] Simplify eSyms. NFCFangrui Song1-4/+2
2022-01-29[ELF] createInputSection: remove unneeded argument. NFCFangrui Song2-7/+7
2022-01-29[ELF] Avoid repeated getObj construction in getSectionIndex. NFCFangrui Song2-20/+25
2022-01-29[ELF] Reorder InputSectionBase::parent. NFCFangrui Song1-6/+6
Move it before others.
2022-01-29[ELF] Reorder InputFile members. NFCFangrui Song1-13/+12
`symbols` is used frequently. Moving it before others can decrease offsets.
2022-01-29[ELF] --gdb-index: switch to SmallVector. NFCFangrui Song2-12/+12
2022-01-29[ELF] Refactor -z combrelocFangrui Song4-94/+101
* `RelocationBaseSection::addReloc` increases `numRelativeRelocs`, which duplicates the work done by RelocationSection<ELFT>::writeTo. * --pack-dyn-relocs=android has inappropropriate DT_RELACOUNT. AndroidPackedRelocationSection does not necessarily place relative relocations in the front and DT_RELACOUNT might cause semantics error (though our implementation doesn't and Android bionic doesn't use DT_RELACOUNT anyway.) Move `llvm::partition` to a new function `partitionRels` and compute `numRelativeRelocs` there. Now `RelocationBaseSection::addReloc` is trivial and can be moved to the header to enable inlining. The rest of DynamicReloc and `-z combreloc` handling is moved to the non-template `RelocationBaseSection::computeRels` to decrease code size. My x86-64 lld executable is 44+KiB smaller. While here, rename `sort` to `combreloc`.
2022-01-30[LLD][MinGW] Add --heap argument supportMateusz Mikuła3-0/+8
Noticed in https://github.com/msys2/MINGW-packages/pull/10567. Differential Revision: https://reviews.llvm.org/D118405
2022-01-28[ELF][test] Improve INSERT [AFTER|BEFORE] and adjustSectionsBeforeSorting testsFangrui Song3-45/+48
2022-01-28[ELF] Change the search order for dependent librariesPetr Hosek2-14/+15
When processing dependent libraries, if there's a directory of the same name as the library being searched for, either in the current directory or earlier in the search order, LLD will try to open it and report an error. This is because LLD uses file existence check. To address this issue we reverse the order, searching the library by basename first and only considering search paths later, and current directory last. Differential Revision: https://reviews.llvm.org/D118498
2022-01-28[lld] Add module name to LTO inline asm diagnosticFangrui Song3-0/+48
Close #52781: for LTO, the inline asm diagnostic uses `<inline asm>` as the file name (lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp) and it is unclear which module has the issue. With this patch, we will see the module name (say `asm.o`) before `<inline asm>` with ThinLTO. ``` % clang -flto=thin -c asm.c && myld.lld asm.o -e f ld.lld: error: asm.o <inline asm>:1:2: invalid instruction mnemonic 'invalid' invalid ^~~~~~~ ``` For regular LTO, unfortunately the original module name is lost and we only get ld-temp.o. Reviewed By: #lld-macho, ychen, Jez Ng Differential Revision: https://reviews.llvm.org/D118434
2022-01-28[lld][Macho] Include dead-stripped symbols in mapfileRoger Kim2-20/+73
ld64 outputs dead stripped symbols when using the -dead-strip flag. This change mimics that behavior for lld. ld64's -dead_strip flag outputs: ``` $ ld -map map basics.o -o out -dead_strip -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lSystem $ cat map # Path: out # Arch: x86_64 # Object files: [ 0] linker synthesized [ 1] basics.o # Sections: # Address Size Segment Section 0x100003F97 0x00000021 __TEXT __text 0x100003FB8 0x00000048 __TEXT __unwind_info 0x100004000 0x00000008 __DATA_CONST __got 0x100008000 0x00000010 __DATA __ref_section 0x100008010 0x00000001 __DATA __common # Symbols: # Address Size File Name 0x100003F97 0x00000006 [ 1] _ref_local 0x100003F9D 0x00000001 [ 1] _ref_private_extern 0x100003F9E 0x0000000C [ 1] _main 0x100003FAA 0x00000006 [ 1] _no_dead_strip_globl 0x100003FB0 0x00000001 [ 1] _ref_from_no_dead_strip_globl 0x100003FB1 0x00000006 [ 1] _no_dead_strip_local 0x100003FB7 0x00000001 [ 1] _ref_from_no_dead_strip_local 0x100003FB8 0x00000048 [ 0] compact unwind info 0x100004000 0x00000008 [ 0] non-lazy-pointer-to-local: _ref_com 0x100008000 0x00000008 [ 1] _ref_data 0x100008008 0x00000008 [ 1] l_ref_data 0x100008010 0x00000001 [ 1] _ref_com # Dead Stripped Symbols: # Size File Name <<dead>> 0x00000006 [ 1] _unref_extern <<dead>> 0x00000001 [ 1] _unref_local <<dead>> 0x00000007 [ 1] _unref_private_extern <<dead>> 0x00000001 [ 1] _ref_private_extern_u <<dead>> 0x00000008 [ 1] _unref_data <<dead>> 0x00000008 [ 1] l_unref_data <<dead>> 0x00000001 [ 1] _unref_com ``` Reviewed By: int3, #lld-macho, thevinster Differential Revision: https://reviews.llvm.org/D114737