summaryrefslogtreecommitdiffstats
path: root/lld/ELF
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] - Convert excessive dyn_cast -> cast. NFC.George Rimar2018-07-051-3/+2
| | | | | | | | | Currently, there are only OutputSection and SymbolAssignment commands possible at the first level under SECTIONS tag. Hence, dyn_cast was excessive. llvm-svn: 336354
* [ELF] - Remove dead code. NFC.George Rimar2018-07-051-3/+0
| | | | | | | | | | | | | I think code is dead, because the only way to see Path as empty seems would be if replaceThinLTOSuffix() replaced some prefix with empty prefix (making the result Path empty). But it is impossible to pass the empty prefix, we would file in driver: https://github.com/llvm-mirror/lld/blob/master/ELF/Driver.cpp#L669 llvm-svn: 336338
* [ELF] - Advance position in a memory region when change the Dot.George Rimar2018-07-051-0/+3
| | | | | | | | | | | | This is https://bugs.llvm.org//show_bug.cgi?id=37836 Previously LLD could assign to Dot or set the address for the section with address expression but did not advance the position in a memory region. Patch fixes the issue. llvm-svn: 336335
* [ELF] - Simplify. NFC.George Rimar2018-07-041-3/+1
| | | | | | | | | | | Currently, there are only OutputSection and SymbolAssignment commands possible at the first level under SECTIONS tag. So, shouldSkip() contained dead "return true". Patch simplifies the code. llvm-svn: 336282
* [ELF] - Add a comment. NFC.George Rimar2018-07-031-0/+1
| | | | | | | Minor follow up for r336197 "[ELF] - Add support for '||' and '&&' in linker scripts." llvm-svn: 336199
* [ELF] - Add support for '||' and '&&' in linker scripts.George Rimar2018-07-032-7/+13
| | | | | | | This is https://bugs.llvm.org//show_bug.cgi?id=37976, we had no support, but seems someone faced it. llvm-svn: 336197
* [ELF] Don't create empty output section for unreferenced PROVIDEsJames Henderson2018-07-031-1/+8
| | | | | | | | | | | | | | | | | | | | LLD removes empty output sections otherwise specified in the linker script. Prior to this change however, if section descriptions included ANY kind of symbol assignment, then the consequent output section would not be removed, even if the assignment was marked with PROVIDE and not actually triggered (i.e. the symbol was never referenced). This change modifies the isDiscarable function to ignore such directives when determining whether a section should be discarded, in keeping with bfd's behaviour. Symbol assignments that do result in a symbol definition will continue to result in a kept section (this is not actually the same as bfd's behaviour, but it is simpler, and probably makes more sense). Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D48771 llvm-svn: 336184
* [ELF] - Cleanup error reporting code and cover with the test. NFC.George Rimar2018-07-021-2/+2
| | | | | | | | | | | | | | | | We have the following code that is uncovered with the test: https://github.com/llvm-mirror/lld/blob/master/ELF/Target.cpp#L95 This patch: 1) Removes "!IS" check. Because at that point of execution (we are reolving the relocations during writing output) we should only have InputSection type of the sections in the vector. (because we already converted MergeInputSection in mergeSections() and combined EhInputSections in combineEhFrameSections()). 2) Covers the "!IS->getParent()" with the test. llvm-svn: 336106
* [ELF] - Remove dead code. NFC.George Rimar2018-07-021-1/+0
| | | | | | It duplicated the default implementation. llvm-svn: 336093
* [ELF] - Change dyn_cast to cast. NFC.George Rimar2018-07-021-1/+1
| | | | | | | | This is followup for r335958. Thanks to Rui for noticing. llvm-svn: 336082
* [ELF] - Eliminate dead code from shouldKeepInSymtab. NFC.George Rimar2018-06-291-3/+0
| | | | | | | | | | | | | | | | shouldKeepInSymtab is called from copyLocalSymbols: https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L574 The pre-condition is that symbol should be Defined: https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L572 And its section is Live: https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L548 InputSection::Discarded section can never be Live. And hence I believe check I removed in this patch is excessive. llvm-svn: 335973
* [ELF] - Remove dead code.George Rimar2018-06-291-3/+0
| | | | | | | | | | | | I do not think this code was ever alive, because the following code says we can have OutputSection and SymbolAssignment cases only. We already handle both of them. https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L502 FWIW, it is dead in the LLD code coverage reports I am running either. llvm-svn: 335958
* [ELF] Rename RF_PROGBITS_NOT_EXEC_OR_WRITE to RF_RODATAFangrui Song2018-06-271-7/+6
| | | | | | Post commit review at D48406 llvm-svn: 335743
* [PPC64] Add support for R_PPC64_GOT_DTPREL16* relocationsZaara Syeda2018-06-275-8/+39
| | | | | | | | | | | | | | The local dynamic TLS access on PPC64 ELF v2 ABI uses R_PPC64_GOT_DTPREL16* relocations when a TLS variables falls outside 2 GB of the thread storage block. This patch adds support for these relocations by adding a new RelExpr called R_TLSLD_GOT_OFF which emits a got entry for the TLS variable relative to the dynamic thread pointer using the relocation R_PPC64_DTPREL64. It then evaluates the R_PPC64_GOT_DTPREL16* relocations as the got offset for the R_PPC64_DTPREL64 got entries. Differential Revision: https://reviews.llvm.org/D48484 llvm-svn: 335732
* [PPC64] Add TLS global dynamic to local exec relaxationZaara Syeda2018-06-271-0/+37
| | | | | | | | | | | | | | | This patch adds the target call back relaxTlsGdToLe to support TLS relaxation from global dynamic to local exec model. The relaxation performs the following transformation: addis r3, r2, x@got@tlsgd@ha --> nop addi r3, r3, x@got@tlsgd@l --> addis r3, r13, x@tprel@ha bl __tls_get_addr(x@tlsgd) --> nop nop --> addi r3, r3, x@tprel@l Differential Revision: https://reviews.llvm.org/D48082 llvm-svn: 335730
* [ELF] - Implement linker script OVERLAYs.George Rimar2018-06-273-10/+81
| | | | | | | | | | | | | | | | | | This is PR36768. Linker script OVERLAYs are described in 4.6.9. Overlay Description of the spec: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/sections.html They are used to allow output sections which have different LMAs but the same VAs and used for embedded programming. Currently, LLD restricts overlapping of sections and that seems to be the most desired behaviour for defaults. My thoughts about possible approaches for PR36768 are on the bug page, this patch implements OVERLAY keyword and allows VAs overlapping for sections that within the overlay. Differential revision: https://reviews.llvm.org/D44780 llvm-svn: 335714
* Make -z option check more strict.Rui Ueyama2018-06-271-8/+8
| | | | llvm-svn: 335713
* Report an error for an unknown -z option.Rui Ueyama2018-06-271-0/+20
| | | | | | | | | This is a less clever version of https://reviews.llvm.org/D48433. This is a dumb version but I think I prefer this for its simplicity. Differential Revision: https://reviews.llvm.org/D48621 llvm-svn: 335712
* [ELF] Make non-writable non-executable PROGBITS sections closer to .textFangrui Song2018-06-261-14/+10
| | | | | | | | | | | | This generalizes the old heuristic placing SHT_DYNSYM SHT_DYNSTR first in the readonly SHF_ALLOC segment. Reviewers: espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D48406 llvm-svn: 335674
* [PPC64] Thread-local storage general-dynamic to initial-exec relaxation.Sean Fertile2018-06-263-0/+62
| | | | | | | | | | | | | | | | | | Patch adds support for relaxing the general-dynamic tls sequence to initial-exec. the relaxation performs the following transformation: addis r3, r2, x@got@tlsgd@ha --> addis r3, r2, x@got@tprel@ha addi r3, r3, x@got@tlsgd@l --> ld r3, x@got@tprel@l(r3) bl __tls_get_addr(x@tlsgd) --> nop nop --> add r3, r3, r13 and instead of emitting a DTPMOD64/DTPREL64 pair for x, we emit a single R_PPC64_TPREL64. Differential Revision: https://reviews.llvm.org/D48090 llvm-svn: 335651
* [ELF] Assign RF_EXEC rank even if --no-rosegment or SECTIONS command is usedFangrui Song2018-06-261-3/+2
| | | | | | | | | | | | | | | | | Summary: Currently when --no-rosegment is specified or a linker script with SECTIONS command is used, .rodata (A) .text (AX) are assigned the same rank and .rodata may be placed after .text . This increases the gap between .text and .bss and can cause pc-relative relocation overflow (e.g. gcc crtbegin.o crtbegin.S have R_X86_64_PC32 relocation from .text to .bss). This patch makes SingleRoRx affect only segment layout, not section layout. As a consequence, .rodata will be placed before .text regardless of SingleRoRx. Reviewers: espindola, ruiu, grimar, echristo, javed.absar Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D48405 llvm-svn: 335627
* [ELF] - Change the way of sorting local symbols.George Rimar2018-06-261-13/+13
| | | | | | | | | | | | | | | | | rLLD329787 added the stable sorting to SymbolTableBaseSection::postThunkContents. I profiled the Mozilla (response-O0.txt) from lld-speed-test package and found std::stable_sort is showing up in profile results and consuming the 3.1% of the total CPU time in the RelWithDebug build. Total time of postThunkContents is 3.54%, 238ms. This change reduces postTimeContents time to 50ms, making it to take 0.73% of Total CPU time. So, instead of sorting the local part I suggest to just rebuild it. That is what this patch does. Differential revision: https://reviews.llvm.org/D45519 llvm-svn: 335583
* Revert r335460 "[ELF] - ICF: Remove dead code. NFC."George Rimar2018-06-251-0/+3
| | | | | | My mistake, it was not NFC. llvm-svn: 335471
* [ELF] - ICF: Remove dead code. NFC.George Rimar2018-06-251-3/+0
| | | | | | | | | | | | Code is dead. We use only InputSections when building the list of sections elegible for the ICF: https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L439 And 'isEligible' filters out SyntheticSections as well for us. That way the only Kind we have in the Sections vector is SectionBase::Regular, so we do not need to check sections kind at all, it is always the same. llvm-svn: 335460
* [ELF] - Replace llvm::find_if with the loop. NFC.George Rimar2018-06-251-4/+3
| | | | | | Requested during post commit review. llvm-svn: 335447
* [ELF] - ICF: remove excessive check. NFC.George Rimar2018-06-221-3/+0
| | | | | | | | | | | | | | | | Change removes the excessive comparsion of the relocation arrays sizes. This code was dead, because at the higer level, equalsConstant function contains the following check: `A->NumRelocations != B->NumRelocations` where NumRelocations contains the size of the relocations array. So removed check did the same job twice. This was found with use of code coverage analysis. llvm-svn: 335346
* [ELF] - Change how we handle suplicate -wrap. [NFC]George Rimar2018-06-222-5/+9
| | | | | | | This avoids doing llvm::sort and std::unique for -wrap options. I think it is more clean way. llvm-svn: 335337
* [ELF][MIPS] Fill a primary-GOT as much as possibleSimon Atanasyan2018-06-201-8/+13
| | | | | | | | | While building a Global Offset Table try to fill the primary GOT as much as possible because the primary GOT can be accessed in the most effective way. If it is not possible, try to fill the last GOT in the multi-GOT list, and finally create a new GOT if both attempts failed. llvm-svn: 335140
* [ELF] Support -z initfirstFangrui Song2018-06-203-0/+4
| | | | | | | | | | | | | | | | Summary: glibc uses this option to link libpthread.so glibc/nptl/Makefile: LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst Reviewers: ruiu, echristo, espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D48329 llvm-svn: 335090
* [ELF] Uniquify --wrap list.Fangrui Song2018-06-181-2/+5
| | | | | | | | | | | | Summary: For --wrap foo --wrap foo, bfd/gold wrap the symbol only once but LLD would rotate it twice. Reviewers: ruiu, espindola Subscribers: emaste, arichardson, mgrang, llvm-commits Differential Revision: https://reviews.llvm.org/D48298 llvm-svn: 334991
* [ELF] Pass callables by function_refBenjamin Kramer2018-06-167-20/+20
| | | | | | | No need to create a heavyweight std::function if it's not stored. No functionality change intended. llvm-svn: 334885
* [ELF][MIPS] Fix stable_sort predicate to satisfy strict-ordering ↵Simon Atanasyan2018-06-151-4/+6
| | | | | | | | requirement. NFC Fix for PR37785. llvm-svn: 334851
* [ELF][MIPS] Replace calls to MapVector::find by MapVector::lookup. NFCSimon Atanasyan2018-06-141-5/+5
| | | | llvm-svn: 334705
* [ELF][X86_64] Use R_GOTREL_FROM_END instead of R_GOTREL for R_X86_64_GOTOFF64Fangrui Song2018-06-131-1/+1
| | | | | | | | | | | | | | | | | | Summary: R_X86_64_GOTOFF64: S + A - GOT R_X86_64_GOTPC{32,64}: GOT + A - P (R_GOTONLY_PC_FROM_END) R_X86_64_GOTOFF64 should use R_GOTREL_FROM_END so that in conjunction with R_X86_64_GOTPC{32,64}, the `GOT` term is neutralized. This also matches the handling of R_386_GOTOFF (S + A - GOT). Reviewers: ruiu, espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D48095 llvm-svn: 334672
* Remove needless bitwise-AND.Rui Ueyama2018-06-131-1/+1
| | | | | | Because applyMask ignores upper bits, we don't need to mask them. llvm-svn: 334647
* Make a function non-member because it doesn't depend on any class.Rui Ueyama2018-06-131-2/+1
| | | | llvm-svn: 334646
* Apply clang-format.Rui Ueyama2018-06-131-4/+2
| | | | llvm-svn: 334645
* Add Hexagon SupportSid Manning2018-06-134-0/+88
| | | | | | Differential Revision: https://reviews.llvm.org/D47791 llvm-svn: 334637
* Use shorter names for #lo, #hi, #ha, etc. NFC.Rui Ueyama2018-06-131-15/+15
| | | | | | | | Since these functions are file-local, the new names shouldn't be ambiguous. Differential Revision: https://reviews.llvm.org/D48093 llvm-svn: 334564
* Handle R_X86_64_GOTOFF64.Rui Ueyama2018-06-121-0/+3
| | | | | | | | | | | | | | | R_X86_64_GOTOFF64 is a relocation type to set to a distance betwween a symbol and the beginning of the .got section. Previously, we always created a dynamic relocation for the relocation type even though it can be resolved at link-time. Creating a dynamic relocation for R_X86_64_GOTOFF64 caused link failure for some programs that do have a relocation of the type in a .text section, as text relocations are prohibited in most configurations. Differential Revision: https://reviews.llvm.org/D48058 llvm-svn: 334534
* [ELF][PPC64] Support R_PPC64_DTPREL64 which may be emitted in .rela.debug_addrFangrui Song2018-06-121-0/+3
| | | | llvm-svn: 334533
* [ELF] Support R_X86_64_GOTPC{32,64}Fangrui Song2018-06-121-0/+5
| | | | | | | | | | Reviewers: ruiu, grimar, espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D47098 llvm-svn: 334532
* [ELF][MIPS] Fix TLS GOT entries for local symbols in shared librariesAlexander Richardson2018-06-121-2/+14
| | | | | | | | | | | | | Summary: Previously LLD would not add any dynamic relocations and write a module index of 1 which is not correct for the shared library case. This can happen when a thread-local global variable is marked as local with a version script. With this change I am now able to link all of the FreeBSD base system for MIPS64 with LLD. Differential Revision: https://reviews.llvm.org/D48002 llvm-svn: 334483
* [PPC64] Support R_PPC64_DTPREL relocations.Sean Fertile2018-06-121-7/+47
| | | | | | | | Patch adds support for most of the dynamic thread pointer based relocations for local-dynamic tls. The HIGH and HIGHA versions are missing becuase they are not supported by the llvm integrated assembler yet. llvm-svn: 334465
* AMDGPU/LLD: Handle R_AMDGPU_REL64 relocationKonstantin Zhuravlyov2018-06-111-0/+2
| | | | | | | | Requires r334443 from llvm Differential Revision: https://reviews.llvm.org/D47734 llvm-svn: 334444
* [ELF] Fix copy relocation when two symbols share the same Symbol instance.Fangrui Song2018-06-111-4/+5
| | | | | | | | | | In glibc libc.so.6, the multiple versions of sys_errlist share the same Symbol instance. When sys_errlist is copy relocated, we would replace SharedSymbol with Defined in the first iteration of the following loop: for (SharedSymbol *Sym : getSymbolsAt<ELFT>(SS)) Then in the second iteration, we think the symbol (which has been changed to Defined) is still SharedSymbol and screw up (the address ends up in the `Size` field). llvm-svn: 334432
* [ELF] Pass a pointer to InputFile to the getRelocTargetVA to escape ↵Simon Atanasyan2018-06-113-23/+22
| | | | | | dereferencing of nullptr. NFC llvm-svn: 334392
* [ELF][MIPS] Multi-GOT implementationSimon Atanasyan2018-06-1110-266/+511
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Almost all entries inside MIPS GOT are referenced by signed 16-bit index. Zero entry lies approximately in the middle of the GOT. So the total number of GOT entries cannot exceed ~16384 for 32-bit architecture and ~8192 for 64-bit architecture. This limitation makes impossible to link rather large application like for example LLVM+Clang. There are two workaround for this problem. The first one is using the -mxgot compiler's flag. It enables using a 32-bit index to access GOT entries. But each access requires two assembly instructions two load GOT entry index to a register. Another workaround is multi-GOT. This patch implements it. Here is a brief description of multi-GOT for detailed one see the following link https://dmz-portal.mips.com/wiki/MIPS_Multi_GOT. If the sum of local, global and tls entries is less than 64K only single got is enough. Otherwise, multi-got is created. Series of primary and multiple secondary GOTs have the following layout: ``` - Primary GOT Header Local entries Global entries Relocation only entries TLS entries - Secondary GOT Local entries Global entries TLS entries ... ``` All GOT entries required by relocations from a single input file entirely belong to either primary or one of secondary GOTs. To reference GOT entries each GOT has its own _gp value points to the "middle" of the GOT. In the code this value loaded to the register which is used for GOT access. MIPS 32 function's prologue: ``` lui v0,0x0 0: R_MIPS_HI16 _gp_disp addiu v0,v0,0 4: R_MIPS_LO16 _gp_disp ``` MIPS 64 function's prologue: ``` lui at,0x0 14: R_MIPS_GPREL16 main ``` Dynamic linker does not know anything about secondary GOTs and cannot use a regular MIPS mechanism for GOT entries initialization. So we have to use an approach accepted by other architectures and create dynamic relocations R_MIPS_REL32 to initialize global entries (and local in case of PIC code) in secondary GOTs. But ironically MIPS dynamic linker requires GOT entries and correspondingly ordered dynamic symbol table entries to deal with dynamic relocations. To handle this problem relocation-only section in the primary GOT contains entries for all symbols referenced in global parts of secondary GOTs. Although the sum of local and normal global entries of the primary got should be less than 64K, the size of the primary got (including relocation-only entries can be greater than 64K, because parts of the primary got that overflow the 64K limit are used only by the dynamic linker at dynamic link-time and not by 16-bit gp-relative addressing at run-time. The patch affects common LLD code in the following places: - Added new hidden -mips-got-size flag. This flag required to set low maximum size of a single GOT to be able to test the implementation using small test cases. - Added InputFile argument to the getRelocTargetVA function. The same symbol referenced by GOT relocation from different input file might be allocated in different GOT. So result of relocation depends on the file. - Added new ctor to the DynamicReloc class. This constructor records settings of dynamic relocation which used to adjust address of 64kb page lies inside a specific output section. With the patch LLD is able to link all LLVM+Clang+LLD applications and libraries for MIPS 32/64 targets. Differential revision: https://reviews.llvm.org/D31528 llvm-svn: 334390
* Fix build broken by r334341.Rui Ueyama2018-06-091-1/+1
| | | | llvm-svn: 334342
* Remove a dead variable.Rui Ueyama2018-06-092-2/+0
| | | | llvm-svn: 334341
OpenPOWER on IntegriCloud