summaryrefslogtreecommitdiffstats
path: root/lld/ELF/InputSection.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] Pass a pointer to InputFile to the getRelocTargetVA to escape ↵Simon Atanasyan2018-06-111-11/+10
| | | | | | dereferencing of nullptr. NFC llvm-svn: 334392
* [ELF][MIPS] Multi-GOT implementationSimon Atanasyan2018-06-111-14/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [PPC64] Add support for local-exec TLS modelZaara Syeda2018-06-081-1/+16
| | | | | | | | | | | | | | | | | | | 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 llvm-svn: 334304
* [PPC64] Support R_PPC64_GOT_TLSLD16 relocations.Sean Fertile2018-05-311-0/+2
| | | | | | | | | 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 llvm-svn: 333681
* Rename R_TLSGD/R_TLSLD to add _GOT_FROM_END. NFC.Sean Fertile2018-05-311-3/+3
| | | | | | | | | 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 llvm-svn: 333674
* [PPC64] Support General-Dynamic tls.Sean Fertile2018-05-291-0/+2
| | | | | | | | | Adds handling of all the relocation types for general-dynamic thread local storage. Differential Revision: https://reviews.llvm.org/D47325 llvm-svn: 333420
* ELF: Do not ICF two sections with different output sections.Peter Collingbourne2018-05-231-1/+1
| | | | | | | | | | 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 llvm-svn: 333052
* [ELF][MIPS] Fix calculation of GP relative relocations in case of ↵Simon Atanasyan2018-05-081-9/+24
| | | | | | | | | | | | | | | | | | | 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 llvm-svn: 331772
* [PPC64] Emit plt call stubs to the text section rather then the plt section.Sean Fertile2018-05-061-5/+7
| | | | | | | | | | | | | | | | | | 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 llvm-svn: 331607
* [PPC64] Remove support for ELF V1 ABI in LLDZaara Syeda2018-05-041-12/+3
| | | | | | | | | | | 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 llvm-svn: 331529
* Fix warning: result of 32-bit shift implicitly converted to 64 bits - NFCZaara Syeda2018-04-301-1/+1
| | | | | | | | Fix warning caused by rL331046. Differential Revision: https://reviews.llvm.org/D45729 llvm-svn: 331181
* Split .eh_frame sections in parellel.Rafael Espindola2018-04-271-4/+0
| | | | | | We can now split them in the same spot we split merge sections. llvm-svn: 331064
* Split merge sections early.Rafael Espindola2018-04-271-4/+0
| | | | | | | | | | | | | | | 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. llvm-svn: 331058
* [PPC64] Add offset to local entry point when calling functions without pltZaara Syeda2018-04-271-1/+12
| | | | | | | | | | | | | | 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 llvm-svn: 331046
* Remove duplicate "error:" from an error message.Rui Ueyama2018-04-231-6/+6
| | | | | | | This patch also simplifies the code a bit which wasn't committed in https://reviews.llvm.org/r330600. llvm-svn: 330644
* [PPC64] Fix toc restore nops offset for V2 ABIZaara Syeda2018-04-231-2/+6
| | | | | | | | | | 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 llvm-svn: 330600
* Define InputSection::getOffset inline.Rafael Espindola2018-04-191-2/+2
| | | | | | | This is much simpler than the other section types and there are many places where the section type is statically know. llvm-svn: 330350
* Simplify Repl handling.Rafael Espindola2018-04-191-4/+3
| | | | | | | | | | 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. llvm-svn: 330346
* Simplify getOffset for synthetic sections.Rafael Espindola2018-04-191-5/+1
| | | | | | | | | | 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. llvm-svn: 330340
* Rename MergeInputSection::getOffset.Rafael Espindola2018-04-191-3/+4
| | | | | | | Unlike the getOffset in the base class, this one computes the offset in the parent synthetic section, not the final output section. llvm-svn: 330339
* Simplify. NFC.Rafael Espindola2018-04-191-1/+3
| | | | | | | | 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. llvm-svn: 330307
* Don't call getOffset twice. NFC.Rafael Espindola2018-04-191-2/+3
| | | | | | Just a bit faster. llvm-svn: 330306
* Don't ignore addend when a SHF_MERGE section is dead.Rafael Espindola2018-04-061-3/+0
| | | | | | | | 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. llvm-svn: 329367
* Initialize OffsetMap earlier.Rafael Espindola2018-04-051-0/+4
| | | | | | | Now that getSectionPiece uses OffsetMap, it is advantageous to initialize it earlier. llvm-svn: 329242
* Don't ignore addend in getOffset.Rafael Espindola2018-04-041-3/+0
| | | | | | | | 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. llvm-svn: 329219
* Inline initOffsetMap.Rafael Espindola2018-04-031-6/+0
| | | | | | | | | | | | | | | 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. llvm-svn: 329117
* Use OffsetMap in getSectionPiece.Rafael Espindola2018-04-031-5/+17
| | | | | | | | | | 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. llvm-svn: 329044
* Initialize OffsetMap in a known location.Rafael Espindola2018-03-281-7/+6
| | | | | | This is a small optimization and avoids the need to use call_once. llvm-svn: 328686
* Define a trivial method inline.Rafael Espindola2018-03-281-7/+2
| | | | llvm-svn: 328685
* Store live offsets as uint32_t.Rafael Espindola2018-03-281-1/+1
| | | | | | | We don't support input merge sections larger than 4gb, so these can be uint32_t. llvm-svn: 328684
* Reduce code duplication a bit. NFCRafael Espindola2018-03-261-1/+2
| | | | llvm-svn: 328569
* Add a SectionBase::getVA helper. NFC.Rafael Espindola2018-03-241-4/+8
| | | | | | There were a few too many places duplicating this. llvm-svn: 328402
* Move a Repl access.Rafael Espindola2018-03-231-2/+2
| | | | | | | | Since SectionBase::getOutputSection handles ICF replaces and SectionBase::getOffset was handling it in some cases, it is more consistent to have getOffset always handle it. llvm-svn: 328391
* Add a minimal fix for PR36878.Rafael Espindola2018-03-231-3/+3
| | | | | | | | | | | | | | | When looking for the output section and the output offset the expectation was that the caller had looked at Repl. That works fine for InputSections, but in the case of MergeInputSections the caller doesn't have the section that is actually replaced. The original testcase was failing because getOutputSection was returning null. The slightly extended testcase also checks that getOffset also checks Repl. I will send a refactoring separetelly. llvm-svn: 328332
* [ELF] - Fix crash relative to SHF_LINK_ORDER sections.George Rimar2018-03-081-9/+3
| | | | | | | | | | | | | | | | | Our code assumes all input sections in an output SHF_LINK_ORDER section has SHF_LINK_ORDER flag. We do not check that and that can cause a crash. That happens because we call std::stable_sort(Sections.begin(), Sections.end(), compareByFilePosition);, where compareByFilePosition predicate does not expect to see null when calls getLinkOrderDep. The same might happen when sections refer to non-regular sections. Test cases demonstrate the issues, patch fixes them. Differential revision: https://reviews.llvm.org/D44193 llvm-svn: 327006
* [ELF] - Revert r325877 "[ELF] - Do not crash with --emit-relocs and ↵George Rimar2018-02-231-2/+0
| | | | | | | | --icf=all together." Not latest version of patch was committed by mistake. llvm-svn: 325878
* [ELF] - Do not crash with --emit-relocs and --icf=all together.George Rimar2018-02-231-0/+2
| | | | | | | | | | Previously we would crash because did not mark .rel[a] sections as dead and they tried to access parent which was not live after ICF and therefore was null. Differential revision: https://reviews.llvm.org/D43241 llvm-svn: 325877
* Ensure that Elf_Rel addends are always written for dynamic relocationsAlexander Richardson2018-02-161-0/+2
| | | | | | | | | | | | Summary: This follows up on r321889 where writing of Elf_Rel addends was partially moved to RelocationBaseSection. This patch ensures that the addends are always written to the output section when a input section uses RELA but the output is REL. Differential Revision: https://reviews.llvm.org/D42843 llvm-svn: 325328
* [ELF] Fix use after free in case of using --whole-archive.Igor Kudrin2018-02-161-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D34554 llvm-svn: 325313
* Relax relocation type checking in a non-ALLOC section.Rui Ueyama2018-02-161-9/+27
| | | | | | | | | | | | | | | | | | Even though it doesn't make sense, there seems to be multiple programs in the wild that create PC-relative relocations in non-ALLOC sections. I believe this is caused by the negligence of GNU linkers to not report any errors for such relocations. Currently, lld emits warnings against such relocations and exits. So, you cannot link any program that contains wrong relocations until you fix an issue in a program that generates wrong ELF files. It's often impractical to fix a program because it's not always easy. This patch relaxes the error checking and emit a warning instead. Differential Revision: https://reviews.llvm.org/D43351 llvm-svn: 325307
* Do not use Decompressor::isCompressedELFSection. NFC.Rui Ueyama2018-02-121-1/+3
| | | | | | | | | In order to identify a compressed section, we check if a section name starts with ".zdebug" or the section has SHF_COMPRESSED flag. We already use the knowledge in this function. So hiding that check in isCompressedELFSection doesn't make sense. llvm-svn: 324951
* Remove 'z' in .zdebug when decompressing a section.Rui Ueyama2018-02-121-1/+10
| | | | | | | | | | | When decompressing a compressed debug section, we drop SHF_COMPRESSED flag but we didn't drop "z" in ".zdebug" section name. This patch does that for consistency. This change also fixes the issue that .zdebug_gnu_pubnames are not dropped when we are creating a .gdb_index section. llvm-svn: 324949
* s/uncompress/decompress/g.Rui Ueyama2018-02-121-6/+6
| | | | | | | In lld, we use both "uncompress" and "decompress" which is confusing. Since LLVM uses "decompress", we should use the same term. llvm-svn: 324944
* [ELF][MIPS] Change format of output relocations to Elf_RelSimon Atanasyan2018-02-021-2/+2
| | | | | | | | | | | Initially LLD generates Elf_Rel relocations for O32 ABI and Elf_Rela relocations for N32 / N64 ABIs. In other words, format of input and output relocations was always the same. Now LLD generates all output relocations using Elf_Rel format only. It conforms to ABIs requirement. The patch suggested by Alexander Richardson. llvm-svn: 324064
* Move function to the file where it is used.Rafael Espindola2018-01-301-26/+0
| | | | llvm-svn: 323780
* Simplify handling of size relocations.Rafael Espindola2018-01-051-1/+1
| | | | | | This is possible now that getSize is not a template. llvm-svn: 321900
* Detemplate reportDuplicate.Rafael Espindola2017-12-231-34/+1
| | | | | | | | | | We normally avoid "switch (Config->EKind)", but in this case I think it is worth it. It is only executed when there is an error and it allows detemplating a lot of code. llvm-svn: 321404
* Pass an InputFile to the InputSection constructor.Rafael Espindola2017-12-211-4/+5
| | | | | | | This simplifies toRegularSection and reduces the noise in a followup patch. llvm-svn: 321240
* Convert a few more InputFiles to references.Rafael Espindola2017-12-211-38/+38
| | | | | | | We use null files in sections to represent linker created sections, so ObjFile<ELFT> is never null. llvm-svn: 321238
* Detemplate createCommentSection.Rafael Espindola2017-12-211-7/+13
| | | | | | | It was only templated so it could create a dummy section header that was immediately parsed back. llvm-svn: 321235
OpenPOWER on IntegriCloud