summaryrefslogtreecommitdiff
path: root/lld/ELF/InputSection.cpp
AgeCommit message (Collapse)Author
2018-09-26[ELF] llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song
Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: ruiu, espindola Subscribers: emaste, arichardson, mgrang, llvm-commits Differential Revision: https://reviews.llvm.org/D52569
2018-09-25Reset input section pointers to null on each linker invocation.Rui Ueyama
Previously, if you invoke lld's `main` more than once in the same process, the second invocation could fail or produce a wrong result due to a stale pointer values of the previous run. Differential Revision: https://reviews.llvm.org/D52506
2018-09-21[ELF] Use the Repl point to avoid the segfault when using ICFPetr Hosek
This addresses PR38918. Differential Revision: https://reviews.llvm.org/D52202
2018-09-20[PPC64] Helper for offset from a function's global entry to local entry. [NFC]Sean Fertile
The PPC64 elf V2 abi defines 2 entry points for a function. There are a few places we need to calculate the offset from the global entry to the local entry and how this is done is not straight forward. This patch adds a helper function mostly for documentation purposes, explaining how the 2 entry points differ and why we choose one over the other, as well as documenting how the offsets are encoded into a functions st_other field. Differential Revision: https://reviews.llvm.org/D52231
2018-09-04When a relocation to an undefined symbol is an R_X86_64_PC32, an inputSterling Augustine
section will not have an input file. Don't crash under those circumstances. Neither clang nor llvm-mc generates R_X86_64_PC32 relocations due to https://reviews.llvm.org/D43383, which makes it hard to write a test case. However, gcc does generate such relocations. I want to get a fix in now, but will figure out a way to actually exercise this code path as soon as I can.
2018-08-31[LLD] Check too large offsets into merge sections earlierBen Dunbobbin
This patch moves the checking for too large offsets into merge sections earlier. Without this change the large offset generated in the added test-case will cause an assert (as it happens to be a value reserved as a "tombstone" in the DenseMap implementation) when OffsetMap is queried in getSectionPiece(). To simplify the code and avoid future mistakes I have refactored so that there is only one function that looks up offsets in the OffsetMap. Differential Revision: https://reviews.llvm.org/D51180
2018-08-13Support shared objects for split stack.Sterling Augustine
2018-08-09Support RISC-VRui Ueyama
Patch by PkmX. This patch makes lld recognize RISC-V target and implements basic relocation for RV32/RV64 (and RVC). This should be necessary for static linking ELF applications. The ABI documentation for RISC-V can be found at: https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md. Note that the documentation is far from complete so we had to figure out some details from bfd. The patch should be pretty straightforward. Some highlights: - A new relocation Expr R_RISCV_PC_INDIRECT is added. This is needed as the low part of a PC-relative relocation is linked to the corresponding high part (auipc), see: https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#pc-relative-symbol-addresses - LLVM's MC support for RISC-V is very incomplete (we are working on this), so tests are given in objectyaml format with the original assembly included in the comments. Once we have complete support for RISC-V in MC, we can switch to llvm-as/llvm-objdump. - We don't support linker relaxation for now as it requires greater changes to lld that is beyond the scope of this patch. Once this is accepted we can start to work on adding relaxation to lld. Differential Revision: https://reviews.llvm.org/D39322
2018-08-02[LLD] Update split stack support to handle more generic prologues. Improve ↵Jordan Rupprecht
error handling. Add test file for better code-coverage. Update tests to be more complete. Submitting patch on behalf of saugustine. Differential Revision: https://reviews.llvm.org/D49926
2018-08-02[LLD][ELF] - Remove dead check from adjustSplitStackFunctionPrologues().George Rimar
In according to the comment, undefined symbol should never reach there. So, should be able to remove the check. I am assuming this is NFC.
2018-08-02[LLD][ELF] - An attemp to fix BB after rL338718.George Rimar
BB is unhappy :`-( http://lab.llvm.org:8011/builders/lld-perf-testsuite/builds/5632
2018-08-02[LLD][ELF] - Remove excessive cases from getRelocTargetVA(). NFC.George Rimar
There is no point to explicitly proccess the expressions this patch removes. We already have a llvm_unreachable for the default case.
2018-08-02[LLD][ELF] - Remove dead code. NFC.George Rimar
It does not seem that this code is alive. I seems was needed previously but we fixed it. If it is still needed, it needs new tests, but for now I do not know how to trigger it, and so I removed it.
2018-08-01[LLD][ELF] - Apply clang-format to InputSections.cpp. NFC.George Rimar
2018-08-01[LLD][ELF] - Removed excessive llvm:: prefix. NFC.George Rimar
2018-07-31Simplify. NFC.Rui Ueyama
2018-07-17Implement framework for linking split-stack object files, and x86_64 support.Sterling Augustine
2018-07-16[ELF] - Eliminate ObjFile<ELFT>::getLineInfo. NFC.George Rimar
Flow is the same, but a bit shorter after this change.
2018-07-11[ELF] Update addends in non-allocatable sections for REL targets when ↵Igor Kudrin
creating a relocatable output. This fixes PR37735. Differential Revision: https://reviews.llvm.org/D48929
2018-07-09[PPC64] Add TLS local dynamic to local exec relaxationZaara Syeda
This patch adds the target call back relaxTlsLdToLe to support TLS relaxation from local dynamic to local exec model. Differential Revision: https://reviews.llvm.org/D48293
2018-06-27[PPC64] Add support for R_PPC64_GOT_DTPREL16* relocationsZaara Syeda
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
2018-06-26[PPC64] Thread-local storage general-dynamic to initial-exec relaxation.Sean Fertile
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
2018-06-11[ELF] Pass a pointer to InputFile to the getRelocTargetVA to escape ↵Simon Atanasyan
dereferencing of nullptr. NFC
2018-06-11[ELF][MIPS] Multi-GOT implementationSimon Atanasyan
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
2018-06-08[PPC64] Add support for local-exec TLS modelZaara Syeda
This patch adds the relocations needed support the local-exec TLS model: R_PPC64_TPREL16 R_PPC64_TPREL16_HA R_PPC64_TPREL16_LO R_PPC64_TPREL16_HI R_PPC64_TPREL16_DS R_PPC64_TPREL16_LO_DS R_PPC64_TPREL16_HIGHER R_PPC64_TPREL16_HIGHERA R_PPC64_TPREL16_HIGHEST R_PPC64_TPREL16_HIGHESTA Differential Revision: https://reviews.llvm.org/D47598
2018-05-31[PPC64] Support R_PPC64_GOT_TLSLD16 relocations.Sean Fertile
Add support for the R_PPC64_GOT_TLSLD16 relocations used to build the address of the tls_index struct used in local-dynamic tls. Differential Revision: https://reviews.llvm.org/D47538
2018-05-31Rename R_TLSGD/R_TLSLD to add _GOT_FROM_END. NFC.Sean Fertile
getRelocTargetVA for R_TLSGD and R_TLSLD RelExprs calculate an offset from the end of the got, so adjust the names to reflect this. Differential Revision: https://reviews.llvm.org/D47379
2018-05-29[PPC64] Support General-Dynamic tls.Sean Fertile
Adds handling of all the relocation types for general-dynamic thread local storage. Differential Revision: https://reviews.llvm.org/D47325
2018-05-23ELF: Do not ICF two sections with different output sections.Peter Collingbourne
Note that this doesn't do the right thing in the case where there is a linker script. We probably need to move output section assignment before ICF to get the correct behaviour here. Differential Revision: https://reviews.llvm.org/D47241
2018-05-08[ELF][MIPS] Fix calculation of GP relative relocations in case of ↵Simon Atanasyan
relocatable output Some MIPS relocations depend on "gp" value. By default, this value has 0x7ff0 offset from a .got section. But relocatable files produced by a compiler or a linker might redefine this default value and we have to use it for a calculation of the relocation result. When we generate EXE or DSO it's trivial. Generating a relocatable output is more difficult case because the linker does calculate relocations in this case and cannot store individual "gp" values used by each input object file. As a workaround we add the "gp" value to the relocation addend. This fixes https://llvm.org/pr31149 Differential revision: https://reviews.llvm.org/D45972
2018-05-06[PPC64] Emit plt call stubs to the text section rather then the plt section.Sean Fertile
On PowerPC calls to functions through the plt must be done through a call stub that is responsible for: 1) Saving the toc pointer to the stack. 2) Loading the target functions address from the plt into both r12 and the count register. 3) Indirectly branching to the target function. Previously we have been emitting these call stubs to the .plt section, however the .plt section should be reserved for the lazy symbol resolution stubs. This patch moves the call stubs to the text section by moving the implementation from writePlt to the thunk framework. Differential Revision: https://reviews.llvm.org/D46204
2018-05-04[PPC64] Remove support for ELF V1 ABI in LLDZaara Syeda
The current support for V1 ABI in LLD is incomplete. This patch removes V1 ABI support and changes the default behavior to V2 ABI, issuing an error when using the V1 ABI. It also updates the testcases to V2 and removes any V1 specific tests. Differential Revision: https://reviews.llvm.org/D46316
2018-04-30Fix warning: result of 32-bit shift implicitly converted to 64 bits - NFCZaara Syeda
Fix warning caused by rL331046. Differential Revision: https://reviews.llvm.org/D45729
2018-04-27Split .eh_frame sections in parellel.Rafael Espindola
We can now split them in the same spot we split merge sections.
2018-04-27Split merge sections early.Rafael Espindola
Now that getSectionPiece is fast (uses a hash) it is probably OK to split merge sections early. The reason I want to do this is to split eh_frame sections in the same place. This does mean that we have to decompress early. Given that the only compressed sections are debug info, I don't think we are missing much. It is a small improvement: 0.5% on the geometric mean.
2018-04-27[PPC64] Add offset to local entry point when calling functions without pltZaara Syeda
PPC64 V2 ABI describes two entry points to a function. The global entry point sets up the TOC base pointer. When calling a local function, the call should branch to the local entry point rather than the global entry point. Section 3.4.1 describes using the 3 most significant bits of the st_other field to find out how many instructions there are between the local and global entry point. This patch adds the correct offset required to branch to the local entry point of a function. Differential Revision: https://reviews.llvm.org/D45729
2018-04-23Remove duplicate "error:" from an error message.Rui Ueyama
This patch also simplifies the code a bit which wasn't committed in https://reviews.llvm.org/r330600.
2018-04-23[PPC64] Fix toc restore nops offset for V2 ABIZaara Syeda
The PPC64 V2 ABI restores the toc base by loading from an offset of 24 from r1. This patch fixes the offset and updates the testcases from V1 to V2. It also issues an error when a nop is missing after a call to an external function. Differential Revision: https://reviews.llvm.org/D45892
2018-04-19Define InputSection::getOffset inline.Rafael Espindola
This is much simpler than the other section types and there are many places where the section type is statically know.
2018-04-19Simplify Repl handling.Rafael Espindola
Now that we don't ICF synthetic sections, we can go back to the old logic on whose responsibility it is to check Repl. The idea is that Sec->something() will not check Repl. It is the responsibility of the caller to find the correct Sec.
2018-04-19Simplify getOffset for synthetic sections.Rafael Espindola
We had a single symbol using -1 with a synthetic section. It is simpler to just update its value. This is not a big will by itself, but will allow having a simple getOffset for InputSeciton.
2018-04-19Rename MergeInputSection::getOffset.Rafael Espindola
Unlike the getOffset in the base class, this one computes the offset in the parent synthetic section, not the final output section.
2018-04-19Simplify. NFC.Rafael Espindola
Using getOffset is here was a bit of an overkill. This is being written and has relocations. This implies it is a .eh_frame or regular section.
2018-04-19Don't call getOffset twice. NFC.Rafael Espindola
Just a bit faster.
2018-04-06Don't ignore addend when a SHF_MERGE section is dead.Rafael Espindola
This is similar to r329219, but for the entire section. Like r329219 I don't expect this to have any real impact, it is just more consistent and simpler.
2018-04-05Initialize OffsetMap earlier.Rafael Espindola
Now that getSectionPiece uses OffsetMap, it is advantageous to initialize it earlier.
2018-04-04Don't ignore addend in getOffset.Rafael Espindola
We were ignoring the addend if the piece was dead. I don't expect this to make a difference in any real world situations, but it is simpler anyway.
2018-04-03Inline initOffsetMap.Rafael Espindola
In the lld perf builder r328686 had a negative impact in stalled-cycles-frontend. Somehow that stat is not showing on my machine, but the attached patch shows an improvement on cache-misses, which is probably a reasonable proxy. My working theory is that given a large input the pieces vector is out of cache by the time initOffsetMap runs. Both finalizeContents implementation have a convenient location for initializing the OffsetMap, so this seems the best solution.
2018-04-03Use OffsetMap in getSectionPiece.Rafael Espindola
OffsetMap maps to a SectionPiece index, but we were not taking advantage of that in getSectionPiece. With this patch both getOffset and getSectionPiece use OffsetMap and the binary search is moved to findSectionPiece.
2018-03-28Initialize OffsetMap in a known location.Rafael Espindola
This is a small optimization and avoids the need to use call_once.