summaryrefslogtreecommitdiffstats
path: root/lld/ELF
Commit message (Collapse)AuthorAgeFilesLines
...
* Improve error message for bad SHF_MERGE sectionsRui Ueyama2019-10-102-6/+9
| | | | | | | | This patch adds a section name to error messages. Differential Revision: https://reviews.llvm.org/D68758 llvm-svn: 374290
* [lld][Hexagon] Support PLT relocation R_HEX_B15_PCREL_X/R_HEX_B9_PCREL_XSid Manning2019-10-081-2/+2
| | | | | | | | These are sometimes generated by tail call optimizations. Differential Revision: https://reviews.llvm.org/D66542 llvm-svn: 374052
* Report error if -export-dynamic is used with -rRui Ueyama2019-10-081-0/+2
| | | | | | | | | | | | | The combination of the two flags doesn't make sense. And other linkers seem to just ignore --export-dynamic if --relocatable is given, but we probably should report it as an error to let users know that is an invalid combination. Fixes https://bugs.llvm.org/show_bug.cgi?id=43552 Differential Revision: https://reviews.llvm.org/D68441 llvm-svn: 374022
* [ELF][MIPS] De-template writeValue. NFCFangrui Song2019-10-071-23/+20
| | | | | | Depends on D68561. llvm-svn: 373886
* [ELF] Wrap things in `namespace lld { namespace elf {`, NFCFangrui Song2019-10-0737-341/+439
| | | | | | | | | | | This makes it clear `ELF/**/*.cpp` files define things in the `lld::elf` namespace and simplifies `elf::foo` to `foo`. Reviewed By: atanasyan, grimar, ruiu Differential Revision: https://reviews.llvm.org/D68323 llvm-svn: 373885
* [ELF][MIPS] Use lld::elf::{read,write}* instead of ↵Fangrui Song2019-10-071-70/+68
| | | | | | | | | | | | | | llvm::support::endian::{read,write}* This allows us to delete `using namespace llvm::support::endian` and simplify D68323. This change adds runtime config->endianness check but the overhead should be negligible. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D68561 llvm-svn: 373884
* [ELF] Use union-find set and doubly linked list in Call-Chain Clustering ↵Fangrui Song2019-10-041-52/+62
| | | | | | | | | | | | | | | | | (C³) heuristic Before, SecToClusters[*] was used to track the belonged cluster. During a merge (From -> Into), every element of From has to be updated. Use a union-find set to speed up this use case. Also, replace `std::vector<int> Sections;` with a doubly-linked pointers: int Next, Prev; Reviewed By: Bigcheese Differential Revision: https://reviews.llvm.org/D46228 llvm-svn: 373708
* ELF: Add .interp synthetic sections first in createSyntheticSections().Peter Collingbourne2019-10-012-9/+15
| | | | | | | | | | | | | | | | | | | | | | Our .interp section is not a SyntheticSection. As a result, it terminates the loop in removeUnusedSyntheticSections(). This has at least two consequences: - The synthetic .bss and .bss.rel.ro sections are always present in dynamically linked executables, even when they are not needed. - The synthetic .ARM.exidx (and possibly other) sections are always present in partitions other than the last one, even when not needed. .ARM.exidx in particular is problematic because it assumes that its list of code sections is non-empty in getLinkOrderDep(), which can lead to a crash if the partition does not have any code sections. Fix these problems by moving the creation of the .interp sections to the top of createSyntheticSections(). While here, make the code a little less error-prone by changing the add() lambdas to take a SyntheticSection instead of an InputSectionBase. Differential Revision: https://reviews.llvm.org/D68256 llvm-svn: 373347
* ELF: Don't merge SHF_LINK_ORDER sections for different output sections in ↵Peter Collingbourne2019-09-301-18/+42
| | | | | | | | | | | | | | | | | | | | | relocatable links. Merging SHF_LINK_ORDER sections can affect semantics if the sh_link fields point to different sections. Specifically, for SHF_LINK_ORDER sections, the sh_link field acts as a reverse dependency from the linked section, causing the SHF_LINK_ORDER section to be included if the linked section is included. Merging sections with different sh_link fields will cause the entire contents of the SHF_LINK_ORDER section to be associated with a single (arbitrarily chosen) output section, whereas the correct semantics are for the individual pieces of the SHF_LINK_ORDER section to be associated with their linked output sections. As a result we can end up incorrectly dropping SHF_LINK_ORDER section contents or including the wrong section contents, depending on which linked sections were chosen. Differential Revision: https://reviews.llvm.org/D68094 llvm-svn: 373255
* [LLD] Simplify the demangleItanium function. NFC.Martin Storsjo2019-09-272-6/+2
| | | | | | | | | Instead of returning an optional, just return the input string if demangling fails, as that's what all callers use anyway. Differential Revision: https://reviews.llvm.org/D68015 llvm-svn: 373077
* [ELF] Set SectionBase::partition in processSectionCommandsFangrui Song2019-09-261-0/+5
| | | | | | | | | | | | | | | | | Fixes PR43461 (regression caused by D67504) The partition field of a SECTIONS-specified section is not set after D67504. The 0 value affects findSection() which checks if the partition field is 1. So `Out::initArray = findSection(".init_array")` is null, and DT_INIT_ARRAYSZ is not set. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D68087 llvm-svn: 372996
* [mips] Relax jalr/jr instructions using R_MIPS_JALR relocationSimon Atanasyan2019-09-261-1/+21
| | | | | | | | | | | The R_MIPS_JALR relocation denotes jalr/jr instructions in position independent code. Both these instructions take a target's address from the $25 register. If offset to the target symbol fits into the 18-bits, it's more efficient to replace jalr/jr by bal/b instructions. Differential Revision: https://reviews.llvm.org/D68057 llvm-svn: 372951
* [ELF] Add -z separate-loadable-segments to complement separate-code and ↵Fangrui Song2019-09-253-13/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | noseparate-code D64906 allows PT_LOAD to have overlapping p_offset ranges. In the default R RX RW RW layout + -z noseparate-code case, we do not tail pad segments when transiting to another segment. This can save at most 3*maxPageSize bytes. a) Before D64906, we tail pad R, RX and the first RW. b) With -z separate-code, we tail pad R and RX, but not the first RW (RELRO). In some cases, b) saves one file page. In some cases, b) wastes one virtual memory page. The waste is a concern on Fuchsia. Because it uses compressed binaries, it doesn't benefit from the saved file page. This patch adds -z separate-loadable-segments to restore the behavior before D64906. It can affect section addresses and can thus be used as a debugging mechanism (see PR43214 and ld.so partition bug in crbug.com/998712). Reviewed By: jakehehrlich, ruiu Differential Revision: https://reviews.llvm.org/D67481 llvm-svn: 372807
* [ELF] accept thinlto options without --plugin-opt= prefixBob Haarman2019-09-252-16/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When support for ThinLTO was first added to lld, the options that control it were prefixed with --plugin-opt= for compatibility with an existing implementation as a linker plugin. This change enables shorter versions of the options to be used, as follows: New Existing -thinlto-emit-imports-files --plugin-opt=thinlto-emit-imports-files -thinlto-index-only --plugin-opt=thinlto-index-only -thinlto-index-only= --plugin-opt=thinlto-index-only= -thinlto-object-suffix-replace= --plugin-opt=thinlto-object-suffix-replace= -thinlto-prefix-replace= --plugin-opt=thinlto-prefix-replace= -lto-obj-path= --plugin-opt=obj-path= The options with the --plugin-opt= prefix have been retained as aliases for the shorter variants so that they continue to be accepted. Reviewers: tejohnson, ruiu, espindola Reviewed By: ruiu Subscribers: emaste, arichardson, MaskRay, steven_wu, dexonsmith, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67782 llvm-svn: 372798
* [ELF][ARM] Fix crash when discarding InputSections that have .ARM.exidxPeter Smith2019-09-242-10/+19
| | | | | | | | | | | | When /DISCARD/ is used on an input section, that input section may have a .ARM.exidx metadata section that depends on it. As the discard handling comes after the .ARM.exidx synthetic section is created we need to make sure that we account for the case where the .ARM.exidx output section should be removed because there are no more live input sections. Differential Revision: https://reviews.llvm.org/D67848 llvm-svn: 372781
* [LLD][ELF][MIPS] - Inline the short helper function. NFC.George Rimar2019-09-241-10/+8
| | | | | | It was requested in a post-commit comment for r372570. llvm-svn: 372747
* [ELF] Delete SectionBase::assignedFangrui Song2019-09-242-22/+9
| | | | | | | | | | | | | D67504 removed uses of `assigned` from OutputSection::addSection, which makes `assigned` purely used in processSectionCommands() and its callees. By replacing its references with `parent`, we can remove `assigned`. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D67531 llvm-svn: 372735
* [ELF] Make MergeInputSection merging aware of output sectionsFangrui Song2019-09-249-138/+168
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes PR38748 mergeSections() calls getOutputSectionName() to get output section names. Two MergeInputSections may be merged even if they are made different by SECTIONS commands. This patch moves mergeSections() after processSectionCommands() and addOrphanSections() to fix the issue. The new pass is renamed to OutputSection::finalizeInputSections(). processSectionCommands() and addorphanSections() are changed to add sections to InputSectionDescription::sectionBases. finalizeInputSections() merges MergeInputSections and migrates `sectionBases` to `sections`. For the -r case, we drop an optimization that tries keeping sh_entsize non-zero. This is for the simplicity of addOrphanSections(). The updated merge-entsize2.s reflects the change. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D67504 llvm-svn: 372734
* [mips] Support elf32btsmipn32_fbsd / elf32ltsmipn32_fbsd emulationsSimon Atanasyan2019-09-231-1/+2
| | | | | | Patch by Kyle Evans. llvm-svn: 372651
* [LLD][ELF] - Simplify getFlagsFromEmulation(). NFCI.George Rimar2019-09-231-12/+2
| | | | | | A straightforward simplification. llvm-svn: 372570
* [mips] Deduce MIPS specific ELF header flags from `emulation`Simon Atanasyan2019-09-221-1/+19
| | | | | | | | | In case of linking binary blobs which do not have any ELF headers, we can deduce MIPS ABI ELF header flags from an `emulation` option. Patch by Kyle Evans. llvm-svn: 372513
* [ELF] Error if the linked-to section of a SHF_LINK_ORDER section is discardedFangrui Song2019-09-201-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: If st_link(A)=B, and A has the SHF_LINK_ORDER flag, we may dereference a null pointer if B is garbage collected (PR43147): 1. In Wrter.cpp:compareByFilePosition, `aOut->sectionIndex` or `bOut->sectionIndex` 2. In OutputSections::finalize, `d->getParent()->sectionIndex` Simply error and bail out to avoid null pointer dereferences. ld.bfd has a similar error: sh_link of section `.bar' points to discarded section `.foo0' of `a.o' ld.bfd is more permissive in that it just checks whether the linked-to section of the first input section is discarded. This is likely because it sets sh_link of the output section according to the first input section. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D67761 llvm-svn: 372400
* [ELF][AARCH64] Refactor AArchErrataFix to match changes in ARMErrataFix NFC.Peter Smith2019-09-171-22/+19
| | | | | | | | | | | | | | | | | | D67284 introduced ARMErrataFix.cpp which was derived from AArch64ErrataFix.cpp. There were some useful refactoring changes made to ARMErrataFix.cpp made as part of the review. This change applies the relevant changes back to AArch64ErrataFix.cpp. Main changes are: - Old style variable names in comments like IS, are now new style isec. - Simplify init() collection of mappingSymbols to always start with a code mapping symbol. - Simplify logic in mergeCmp(). - Fix one 80 column overflow caused by IS -> isec transformation. Differential Revision: https://reviews.llvm.org/D67622 llvm-svn: 372094
* [ELF][Hexagon] Allow PT_LOAD to have overlapping p_offset ranges on EM_HEXAGONFangrui Song2019-09-171-6/+1
| | | | | | | | Port the D64906 technique to EM_HEXAGON. This concludes the patch series. Differential Revision: https://reviews.llvm.org/D67605 llvm-svn: 372059
* [lld] Update lld driver to use new LTO APIs to handle libcall symbolsSteven Wu2019-09-161-7/+2
| | | | | | | NFC. Remove duplicated code in ELF/COFF driver and libLTO legacy interfaces. llvm-svn: 372022
* [ELF][ARM] Fix -Werror buildbots NFC.Peter Smith2019-09-161-1/+1
| | | | | | | | | | Provide a missing initializer to get rid of warning provoking buildbot failures. error: missing field 'rel' initializer [-Werror,-Wmissing-field-initializers] llvm-svn: 371970
* [ELF][ARM] Implement --fix-cortex-a8 to fix erratum 657417Peter Smith2019-09-168-7/+599
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The --fix-cortex-a8 option implements a linker workaround for the coretex-a8 erratum 657417. A summary of the erratum conditions is: - A 32-bit Thumb-2 branch instruction B.w, Bcc.w, BL, BLX spans two 4KiB regions. - The destination of the branch is to the first 4KiB region. - The instruction before the branch is a 32-bit Thumb-2 non-branch instruction. The linker fix is to redirect the branch to a patch not in the first 4KiB region. The patch forwards the branch on to its target. The cortex-a8, is an old CPU, with the first implementation of this workaround in ld.bfd appearing in 2009. The cortex-a8 has been used in early Android Phones and there are some critical applications that still need to run on a cortex-a8 that have the erratum. The patch is applied roughly 10 times on LLD and 20 on Clang when they are built with --fix-cortex-a8 on an Arm system. The formal erratum description is avaliable in the ARM Core Cortex-A8 (AT400/AT401) Errata Notice document. This is available from Arm on request but it seems to be findable via a web search. Differential Revision: https://reviews.llvm.org/D67284 llvm-svn: 371965
* [ELF][X86] Allow PT_LOAD to have overlapping p_offset ranges on EM_X86_64Fangrui Song2019-09-161-2/+1
| | | | | | | | Port the D64906 technique to EM_X86_64. Differential Revision: https://reviews.llvm.org/D67482 llvm-svn: 371958
* [ELF] Map the ELF header at imageBaseFangrui Song2019-09-162-27/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If there is no readonly section, we map: * The ELF header at imageBase+maxPageSize * Program headers at imageBase+maxPageSize+sizeof(Ehdr) * The first section .text at imageBase+maxPageSize+sizeof(Ehdr)+sizeof(program headers) Due to the interaction between Writer<ELFT>::fixSectionAlignments and LinkerScript::allocateHeaders, `alignDown(p_vaddr(R PT_LOAD)) = alignDown(p_vaddr(RX PT_LOAD))`. The RX PT_LOAD will override the R PT_LOAD at runtime, which is not ideal: ``` // PHDR at 0x401034, should be 0x400034 PHDR 0x000034 0x00401034 0x00401034 0x000a0 0x000a0 R 0x4 // R PT_LOAD contains just Ehdr and program headers. // At 0x401000, should be 0x400000 LOAD 0x000000 0x00401000 0x00401000 0x000d4 0x000d4 R 0x1000 LOAD 0x0000d4 0x004010d4 0x004010d4 0x00001 0x00001 R E 0x1000 ``` * createPhdrs allocates the headers to the R PT_LOAD. * fixSectionAlignments assigns `imageBase+maxPageSize+sizeof(Ehdr)+sizeof(program headers)` (formula: `alignTo(dot, maxPageSize) + dot % config->maxPageSize`) to addrExpr of .text * allocateHeaders computes the minimum address among SHF_ALLOC sections, i.e. addr(.text) * allocateHeaders sets address of ELF header to `addr(.text)-sizeof(Ehdr)-sizeof(program headers) = imageBase+maxPageSize` The main observation is that when the SECTIONS command is not used, we don't have to call allocateHeaders. This requires an assumption that the presence of PT_PHDR and addresses of headers can be decided regardless of address information. This may seem natural because dot is not manipulated by a linker script. The other thing is that we have to drop the special rule for -T<section> in `getInitialDot`. If -Ttext is smaller than the image base, the headers will not be allocated with the old behavior (allocateHeaders is called) but always allocated with the new behavior. The behavior change is not a problem. Whether and where headers are allocated can vary among linkers, or ld.bfd across different versions (--enable-separate-code or not). It is thus advised to use a linker script with the PHDRS command to have a consistent behavior across linkers. If PT_PHDR is needed, an explicit --image-base can be a simpler alternative. Differential Revision: https://reviews.llvm.org/D67325 llvm-svn: 371957
* [ELF] Delete a redundant assignment to SectionBase::assigned. NFCFangrui Song2019-09-131-1/+0
| | | | | | | LinkerScript::discard marks a section dead. It is unnecessary to set the `assigned` bit. llvm-svn: 371804
* [ELF] ICF: change a dyn_cast<InputSection> to castFangrui Song2019-09-121-4/+5
| | | | | | | | ICF is performed after EhInputSections and MergeInputSections were eliminated from inputSections. Every element of inputSections is an InputSection. llvm-svn: 371744
* [ELF] Fix a common-page-size typoFangrui Song2019-09-121-1/+1
| | | | llvm-svn: 371716
* [ELF] Support -z undefsFangrui Song2019-09-121-1/+3
| | | | | | | | | | | -z undefs is the inverse of -z defs. It allows unresolved references from object files. This can be used to cancel --no-undefined or -z defs. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67479 llvm-svn: 371715
* [mips] Allow PT_LOAD to have overlapping p_offset ranges on EM_MIPSSimon Atanasyan2019-09-101-1/+0
| | | | | | | | Port the D64906 <https://reviews.llvm.org/D64906> technique to MIPS. Fix PR33131 llvm-svn: 371554
* [ELF] nmagic or omagic: don't allocate PT_PHDR or PF_R PT_LOAD for the ↵Fangrui Song2019-09-091-17/+22
| | | | | | | | | | | | | | | | | | | !hasPhdrsCommands case ``` part.phdrs = script->hasPhdrsCommands() ? script->createPhdrs() : createPhdrs(part); ``` createPhdrs() allocates a PT_PHDR and a PF_R PT_LOAD, which will be deleted later in LinkerScript::allocateHeaders, but leave a gap between the program headers and the first section. Don't allocate the segments to avoid the gap. PT_INTERP is likely not needed as well. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67324 llvm-svn: 371398
* [ELF][AArch64] Apply some NFC cleanups to AArch64ErrataFix.cppFangrui Song2019-09-091-10/+10
| | | | | | | | Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67310 llvm-svn: 371389
* [ELF] Replace error() with errorOrWarn() for the ASSERT commandFangrui Song2019-09-061-1/+1
| | | | | | | | | | | | | | | Summary: ld.bfd produces an output with --noinhibit-exec when an ASSERT fails. Use errorOrWarn() so that we can produce an output as well. An interesting case is that symbol assignments may execute multiple times, so we probably want to suppress errors for non-final runs. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D67285 llvm-svn: 371225
* Reland D66717 [ELF] Do not ICF two sections with different output sections ↵Fangrui Song2019-09-063-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (by SECTIONS commands) Recommit r370635 (reverted by r371202), with one change: move addOrphanSections() before ICF. Before, orphan sections in two different partitions may be folded and moved to the main partition. Now, InputSection->OutputSection assignment for orphans happens before ICF. ICF does not fold input sections with different output sections. With the PR43241 reproduce, `llvm-objcopy --extract-partition libvr.so libchrome__combined.so libvr.so` => no error Updated description: Fixes PR39418. Complements D47241 (the non-linker-script case). processSectionCommands() assigns input sections to output sections. ICF is called before it, so .text.foo and .text.bar may be folded even if their output sections are made different by SECTIONS commands. ``` markLive<ELFT>() doIcf<ELFT>() // During ICF, we don't know the output sections writeResult() combineEhSections<ELFT>() script->processSectionCommands() // InputSection -> OutputSection assignment ``` This patch splits processSectionCommands() into processSectionCommands() and processSymbolAssignments(), and moves processSectionCommands()/addOrphanSections() before ICF: ``` markLive<ELFT>() combineEhSections<ELFT>() script->processSectionCommands() script->addOrphanSections(); doIcf<ELFT>() // should remove folded input sections writeResult() script->processSymbolAssignments() ``` An alternative approach is to unfold a section `sec` in processSectionCommands() when we find `sec` and `sec->repl` belong to different output sections. I feel this patch is superior because this can fold more sections and the decouple of SectionCommand/SymbolAssignment gives flexibility: * An ExprValue can't be evaluated before its section is assigned to an output section -> we can delete getOutputSectionVA and simplify another place where we had to check if the output section is null. Moreover, a case in linkerscript/early-assign-symbol.s can be handled now. * processSectionCommands/processSymbolAssignments can be freely moved around. llvm-svn: 371216
* Revert "Revert r370635, it caused PR43241."Fangrui Song2019-09-066-71/+87
| | | | | | This reverts commit 50d2dca22b3b05d0ee4883b0cbf93d7d15f241fc. llvm-svn: 371215
* Revert r370635, it caused PR43241.Nico Weber2019-09-066-87/+71
| | | | llvm-svn: 371202
* [ELF] Initialize PhdrEntry::p_align to maxPageSize for PT_LOADFangrui Song2019-09-052-10/+8
| | | | | | | | | | | | | | | | | | | | | ``` Writer<ELFT>::run assignFileOffsets setFileOffset computeFileOffset os->ptLoad->p_align may be smaller than config->maxPageSize setPhdrs p_align = max(p_align, config->maxPageSize) ``` If we move the config->maxPageSize logic to the constructor of PhdrEntry, computeFileOffset can be simplified. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67211 llvm-svn: 371085
* Align output segments correctlyRui Ueyama2019-09-051-1/+2
| | | | | | | | | | | | | | | | Previously, segments were aligned according to their first section's alignment requirements. That was not correct, but segments are also aligned to a page boundary, and a page boundary is usually much larger than a section alignment requirement, so no one noticed this bug before. Now, lld has --nmagic option which sets maxPageSize to 1 to effectively disable page alignment, which reveals the issue. Fixes https://bugs.llvm.org/show_bug.cgi?id=43212 Differential Revision: https://reviews.llvm.org/D67152 llvm-svn: 371013
* [ELF] Don't shrink RelrSectionFangrui Song2019-09-041-0/+8
| | | | | | | | | | | | | | | | | | | | Fixes PR43214. The size of SHT_RELR may oscillate between 2 numbers (see D53003 for a similar --pack-dyn-relocs=android issue). This can happen if the shrink of SHT_RELR causes it to take more words to encode relocation offsets (this can happen with thunks or segments with overlapping p_offset ranges), and the expansion of SHT_RELR causes it to take fewer words to encode relocation offsets. To avoid the issue, add padding 1s to the end of the relocation section if its size would decrease. Trailing 1s do not decode to more relocations. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D67164 llvm-svn: 370923
* [ELF] Fix spell corrector: don't call elf::InputFile::getSymbols() on shared ↵Fangrui Song2019-09-041-1/+1
| | | | | | | | objects Exposed by pr34872.s llvm-svn: 370875
* [ELF] Add a spell corrector for "undefined symbol" diagnosticsFangrui Song2019-09-041-5/+80
| | | | | | | | | | | | | | | | | | | | | | | Non-undefined symbols with Levenshtein distance 1 or a transposition are suggestion candidates. This is probably good enough and it can suggest some missing/superfluous qualifiers: const, restrict, volatile, & and && ref-qualifier, e.g. error: undefined symbol: foo(int*) >>> referenced by b.o:(.text+0x1) +>>> did you mean: foo(int const*) +>>> defined in: a.o error: undefined symbol: foo(int*&) >>> referenced by b.o:(.text+0x1) +>>> did you mean: foo(int*) +>>> defined in: b.o Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67039 llvm-svn: 370853
* [ELF] Do not ICF two sections with different output sections (by SECTIONS ↵Fangrui Song2019-09-026-71/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | commands) Fixes PR39418. Complements D47241 (the non-linker-script case). processSectionCommands() assigns input sections to output sections. ICF is called before it, so .text.foo and .text.bar may be folded even if their output sections are made different by SECTIONS commands. ``` markLive<ELFT>() doIcf<ELFT>() // During ICF, we don't know the output sections writeResult() combineEhSections<ELFT>() script->processSectionCommands() // InputSection -> OutputSection assignment ``` This patch splits processSectionCommands() into processSectionCommands() and processSymbolAssignments(), and moves processSectionCommands() before ICF: ``` markLive<ELFT>() combineEhSections<ELFT>() script->processSectionCommands() doIcf<ELFT>() // should remove folded input sections writeResult() script->processSymbolAssignments() ``` An alternative approach is to unfold a section `sec` in processSectionCommands() when we find `sec` and `sec->repl` belong to different output sections. I feel this patch is superior because this can fold more sections and the decouple of SectionCommand/SymbolAssignment gives flexibility: * An ExprValue can't be evaluated before its section is assigned to an output section -> we can delete getOutputSectionVA and simplify another place where we had to check if the output section is null. Moreover, a case in linkerscript/early-assign-symbol.s can be handled now. * processSectionCommands/processSymbolAssignments can be freely moved around. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D66717 llvm-svn: 370635
* [ELF] Align SHT_LLVM_PART_EHDR to a maximum page size boundaryFangrui Song2019-09-021-2/+10
| | | | | | | | | | | | | | | | | | | | | Fixes https://bugs.chromium.org/p/chromium/issues/detail?id=998712 SHT_LLVM_PART_EHDR marks the start of a partition. The partition sections will be extracted to a separate file. Align to the next maximum page size boundary so that we can find the ELF header at the start. We cannot benefit from overlapping p_offset ranges with the previous segment anyway. It seems we lack some llvm-objcopy --extract-main-partition and --extract-partition sanity checks. It may place EHDR at the start even if p_offset if non zero. Anyway, the lld change is justified for the reasons above. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67032 llvm-svn: 370629
* [ELF] Set `referenced` bit of Undefined created by BitcodeFileFangrui Song2019-08-301-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | D64136 and D65584, while fixing STB_WEAK issues and improving our compatibility with ld.bfd, can cause another STB_WEAK problem related to LTO: If %tundef.o has an undefined reference on f, and %tweakundef.o has a weak undefined reference on f, %tdef.o has a definition of f ``` ld.lld %tundef.o %tweakundef.o --start-lib %tdef.o --end-lib ``` 1) `%tundef.o` doesn't set the `referenced` bit. 2) `%weakundef.o` changes the binding from STB_GLOBAL to STB_WEAK 3) `%tdef.o` is not fetched because the binding is weak. Step (1) is incorrect. This patch sets the `referenced` bit of Undefined created by bitcode files. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D66992 llvm-svn: 370437
* [ELF][RISCV] Allow PT_LOAD to have overlapping p_offset ranges on EM_RISCVFangrui Song2019-08-281-3/+3
| | | | | | | | Port the D64906 technique to RISC-V. It deletes 3 alignments at PT_LOAD boundaries for the default case: the size of a RISC-V binary decreases by at most 12kb. llvm-svn: 370192
* [ELF][AMDGPU][SPARC] Allow PT_LOAD to have overlapping p_offset ranges on ↵Fangrui Song2019-08-281-4/+3
| | | | | | EM_AMDGPU and EM_SPARCV9 llvm-svn: 370180
OpenPOWER on IntegriCloud