summaryrefslogtreecommitdiffstats
path: root/lld/ELF/OutputSections.h
Commit message (Collapse)AuthorAgeFilesLines
...
* [elf2] Add support for R_X86_64_TLSLD.Michael J. Spencer2015-11-111-0/+3
| | | | | | | | | | | | | | | leaq symbol@tlsld(%rip), %rdi call __tls_get_addr@plt symbol@tlsld (R_X86_64_TLSLD) instructs the linker to generate a tls_index entry (two GOT slots) in the GOT for the entire module (shared object or executable) with an offset of 0. The symbol for this GOT entry doesn't matter (as long as it's either local to the module or null), and gold doesn't put a symbol in the dynamic R_X86_64_DTPMOD64 relocation for the GOT entry. All other platforms defined in http://www.akkadia.org/drepper/tls.pdf except for Itanium use a similar model where global and local dynamic GOT entries take up 2 contiguous GOT slots, so we can handle this in a unified manner if we don't care about Itanium. While scanning relocations we need to identify local dynamic relocations and generate a single tls_index entry in the GOT for the module and store the address of it somewhere so we can later statically resolve the offset for R_X86_64_TLSLD relocations. We also need to generate a R_X86_64_DTPMOD64 relocation in the RelaDyn relocation section. This implementation is a bit hacky. It side steps the issue of GotSection and RelocationSection only handling SymbolBody entries by relying on a specific relocation type. The alternative to this seemed to be completely rewriting how GotSection and RelocationSection work, or using a different hacky signaling method. llvm-svn: 252682
* Round up the memsize of PT_TLS.Rafael Espindola2015-11-061-4/+3
| | | | | | | | This is cleaner than computing relocations as if we had done it. While at it, keep a single Phdr variable instead of multiple fields of it. llvm-svn: 252352
* [ELF2] Add GOT section for MIPS target.Igor Kudrin2015-11-061-3/+1
| | | | | | | | | | | | | | | This patch implements R_MIPS_GOT16 relocation for global symbols in order to generate some entries in GOT. Only reserved and global entries are supported for now. For the detailed description about GOT in MIPS, see "Global Offset Table" in Chapter 5 in the followin document: ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf In addition, the platform specific symbol "_gp" is added, see "Global Data Symbols" in Chapter 6 in the aforementioned document. Differential revision: http://reviews.llvm.org/D14211 llvm-svn: 252275
* [elf2] Fix R_X86_64_TPOFF32 handling.Michael J. Spencer2015-11-051-0/+2
| | | | | | | | For x86-64 the initial executable TLS block is placed directly before the thread specific data register so compilers can directly access it via R_X86_64_TPOFF32. Generate the correct (negative) offset for this case. llvm-svn: 252131
* Fix Clang-tidy modernize-use-override warnings, other minor fixes.Eugene Zelenko2015-11-041-4/+6
| | | | | | Differential revision: http://reviews.llvm.org/D14310 llvm-svn: 252034
* [elf2] Implement R_X86_64_TPOFF32.Michael J. Spencer2015-11-031-0/+3
| | | | | | This does not support TPOFF32 relocations to local symbols as the address calculations are separate. Support for this will be a separate patch. llvm-svn: 251998
* Remove redundant = nullptr.Rafael Espindola2015-11-031-1/+1
| | | | llvm-svn: 251987
* Create .bss only when needed.Rafael Espindola2015-11-031-1/+1
| | | | | | | This is a small complication, but produces nicer output and is a step to handling zero size sections uniformly. llvm-svn: 251980
* Two small fixes to copy relocation processing.Rafael Espindola2015-11-031-0/+4
| | | | | | | * We can determine the alignment requirement. * We have to update the bss alignment with it. llvm-svn: 251914
* Make a method static. NFC.Rafael Espindola2015-11-021-1/+0
| | | | llvm-svn: 251799
* [ELF2] Move sorting and data to the GNU hash table section.Igor Kudrin2015-10-281-13/+14
| | | | | | | | | It is the GNU hash table section that should be reaponsible for storing its own data and applying its requirements for the order to dynamic symbols. Differential Revision: http://reviews.llvm.org/D14084 llvm-svn: 251502
* Add support for merging string from SHF_STRINGS sections.Rafael Espindola2015-10-241-5/+5
| | | | llvm-svn: 251212
* ELF2: Remove setNameOffset and combine that with writeHeader. NFC.Rui Ueyama2015-10-241-1/+0
| | | | llvm-svn: 251193
* ELF2: Rename StringTableSection::getFileOff -> getOffset.Rui Ueyama2015-10-241-1/+1
| | | | | | | | getFileOff functions defined for other classes return an offset from beginning of the file. StringTableSection's getFileOff however returned an offset from beginning of the section. That was confusing. llvm-svn: 251192
* Update for llvm api change.Rafael Espindola2015-10-231-2/+2
| | | | llvm-svn: 251154
* [ELF2] Add support for GNU Hash sectionIgor Kudrin2015-10-221-2/+41
| | | | | | | | | | | | | | | | | | | This patch implements --hash-style command line switch. * By default, or with "sysv" or "both" parameters, the linker generates a standard ELF hash section. * With "gnu" or "both", it produces a GNU-style hash section. That section requires the symbols in the dynamic symbol table section, which are referenced in the GNU hash section, to be placed after not hashed ones and to be sorted to correspond the order of hash buckets in the GNU Hash section. The division function, as well as estimations for the section's parameters, are just the first rough attempt and the subjects for further adjustments. Differential Revision: http://reviews.llvm.org/D13815 llvm-svn: 251000
* ELF2: Simplify DT_FLAGS{,_1} handling. NFC.Rui Ueyama2015-10-211-0/+2
| | | | llvm-svn: 250914
* [ELF2] Determine the order of entries of symbol tables in the finalize() phase.Igor Kudrin2015-10-201-5/+5
| | | | | | | | | | | | | * Move the responsibility to call SymbolBody::setDynamicSymbolTableIndex() from the hash table to the dynamic symbol table. * Hash table is not longer responsible for filling the dynamic symbol table. * The final order of symbols of both symbol tables is set before writing phase starts. * Remove repeaded scan of the symbol table during writting SymbolTableSection. Differential Revision: http://reviews.llvm.org/D13911 llvm-svn: 250864
* [ELF2] Extract calculation of symbol binding as a separate function.Igor Kudrin2015-10-201-0/+2
| | | | | | Differential Revision: http://reviews.llvm.org/D13910 llvm-svn: 250855
* [ELF2] .shstrtab section implementedGeorge Rimar2015-10-201-1/+3
| | | | | | | | The section header table index of the entry that is associated with the section name string table. Differential Revision: http://reviews.llvm.org/D13904 llvm-svn: 250836
* [ELF2] - Lazy relocation support for x86_64.George Rimar2015-10-201-1/+21
| | | | | | | | Target has supportsLazyRelocations() method which can switch lazy relocations on/off (currently all targets are OFF except x64 which is ON). So no any other targets are affected now. Differential Revision: http://reviews.llvm.org/D13856?id=37726 llvm-svn: 250808
* Add support for merging the contents of SHF_MERGE sections.Rafael Espindola2015-10-191-0/+19
| | | | | | For now SHF_STRINGS are not supported. llvm-svn: 250737
* Change getLocalRelTarget to include the addend.Rafael Espindola2015-10-191-2/+14
| | | | | | | | | Given the name, it is natural for this function to compute the full target. This will simplify SHF_MERGE handling by allowing getLocalRelTarget to centralize the addend logic. llvm-svn: 250731
* [ELF2] In/out parameter of writeGlobalSymbols() is changed to in parameter.Igor Kudrin2015-10-191-1/+1
| | | | | | There is no outer code which requires the changed value. llvm-svn: 250688
* [ELF2] Remove unneeded new Type parameterHal Finkel2015-10-161-2/+1
| | | | | | | As pointed out by Rafael (with a further suggestion by Rui), the new Type parameter I added in r250555 is not needed. Remove it. llvm-svn: 250563
* [ELF2] getLocalRelTarget should handle R_PPC64_TOC directlyHal Finkel2015-10-161-1/+2
| | | | | | | | | | | | | | | | | | | R_PPC64_TOC does not have an associated symbol, but does have a non-zero VA that target-specific code must compute using some non-trivial rule. We handled this as a special case in PPC64TargetInfo::relocateOne, where we knew to write this special address, but that did not work when creating shared libraries. The special TOC address needs to be the subject of a R_PPC64_RELATIVE relocation, and so we also need to know how to encode this special address in the addend of that relocation. Thus, some target-specific logic is necessary when creating R_PPC64_RELATIVE as well. To solve this problem, we teach getLocalRelTarget to handle R_PPC64_TOC as a special case. This allows us to remove the special case in PPC64TargetInfo::relocateOne (simplifying code there), and naturally allows the existing logic to do the right thing when creating associated R_PPC64_RELATIVE relocations for shared libraries. llvm-svn: 250555
* ELF2: Use ELFT to template OutputSections.Rui Ueyama2015-10-151-45/+39
| | | | | | | | | | | | This patch is to use ELFT instead of Is64Bits to template OutputSection and its subclasses. This increases code size slightly because it creates two identical functions for some classes, but that's only 20 KB out of 33 MB, so it's negligible. This is as per discussion with Rafael. He's not fan of the idea but OK with this. We'll revisit later to this topic. llvm-svn: 250466
* ELF2: Move HashTableSection::hash out of the class.Rui Ueyama2015-10-151-11/+0
| | | | | | Because the function does not depend on the class. llvm-svn: 250462
* Remove a getter/setter that don't hide anything.Rui Ueyama2015-10-151-3/+1
| | | | llvm-svn: 250458
* Use OutputSectionBase in a few cases where we don't need a OutputSection.Rafael Espindola2015-10-151-5/+5
| | | | | | | NFC. This is just preparation for adding a new OutputSection dedicated to SHF_MERGE input sections. llvm-svn: 250419
* Handle dynamic relocs to weak undefined when possible.Rafael Espindola2015-10-141-1/+1
| | | | llvm-svn: 250311
* ELF2: Remove getAddrSize().Rui Ueyama2015-10-141-3/+1
| | | | llvm-svn: 250296
* Revert r250169: "This patch implements basic variant of lazy loading for ↵Rui Ueyama2015-10-131-22/+1
| | | | | | | | x86_x64 and for X86 targets." With this patch LLD is not able to self-host on x86-64 Linux. llvm-svn: 250182
* This patch implements basic variant of lazy loading for x86_x64 and for X86 ↵George Rimar2015-10-131-1/+22
| | | | | | | | | | | | | | | | | | | targets. What was done: 1) .got.plt section is created for functions that requires PLT. .got.plt has 3 predefined empty entries now that are required for dynamic linker. Also other new items created are configured to have correct jump to PLT[N]. 2) PLT section now has PLT[0] entry, also others ones are configured to support PLT->GOT(.got.plt) calls. 3) Implemented .rel[a].plt sections (based on patch http://reviews.llvm.org/D13569). 4) Fixed plt relocations types (based on patch http://reviews.llvm.org/D13589). NOTES: The .plt.got zero entry is still empty now. According to ELF specification it should hold the address of the dynamic structure, referenced with the symbol _DYNAMIC. The _DYNAMIC entry points to the .dynamic section which contains information used by the ELF interpreter to setup the binary. Differential Revision: http://reviews.llvm.org/D13651 llvm-svn: 250169
* [ELF2/PPC64] Resolve local-call relocations using the correct ↵Hal Finkel2015-10-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function-descriptor values Under PPC64 ELF v1 ABI, the symbols associated with each function name don't point directly to the code in the .text section (or similar), but rather to a function descriptor structure in a special data section named .opd. The elements in the .opd structure include a pointer to the actual code, and a the relevant TOC base value. Both of these are themselves set by relocations. When we have a local call, we need the relevant relocation to refer directly to the target code, not to the function-descriptor in the .opd section. Only when we have a .plt stub do we care about the address of the .opd function descriptor itself. So we make a few changes here: 1. Always write .opd first, so that its relocated data values are available for later use when writing the text sections. Record a pointer to the .opd structure, and its corresponding buffer. 2. When processing a relative branch relocation under ppc64, if the destination points into the .opd section, read the code pointer out of the function descriptor structure and use that instead. This this, I can link, and run, a dynamically-compiled "hello world" application on big-Endian PPC64/Linux (ELF v1 ABI) using lld. llvm-svn: 250122
* ELF2: Create a function to get VA from Elf_Rel.Rui Ueyama2015-10-121-2/+2
| | | | | | And remove git getLocalSymVA because there's no user of the function anymore. llvm-svn: 250095
* ELF2: Make SymbolTable a template class.Rui Ueyama2015-10-091-5/+5
| | | | | | | | | | | | | | | | | | | | | | | SymbolTable was not a template class. Instead we had switch-case-based type dispatch to call desired functions. We had to do that because SymbolTable was created before we know what ELF type objects had been passed. Every time I tried to add a new function to the symbol table, I had to define a dispatcher which consist of a single switch statement. It also brought an restriction what the driver can do. For example, we cannot add undefined symbols before any files are added to the symbol table. That's because no symbols can be added until the symbol table knows the ELF type, but when it knows about that, it's too late. In this patch, the driver makes a decision on what ELF type objects are being handled. Then the driver creates a SymbolTable object for an appropriate ELF type. http://reviews.llvm.org/D13544 llvm-svn: 249902
* ELF2: Reduce code repetition.Rui Ueyama2015-10-091-0/+12
| | | | llvm-svn: 249882
* Add support for comdats.Rafael Espindola2015-10-091-1/+2
| | | | | | The implementation is a direct translation to c++ of the rules in the ELF spec. llvm-svn: 249881
* Revert "[ELF2] - Implemented rel[a].plt sections"Rafael Espindola2015-10-091-2/+1
| | | | | | | | | | | | | | | | This reverts commit r249816. It broke building llvm with lld: $ ./bin/FileCheck ./bin/FileCheck: error while loading shared libraries: unexpected PLT reloc type 0x06 I think the only thing that is wrong with this patch is that it is too soon. The plt we create (and its relocs) don't support lazy loading, so they have to be relocated as ordinary dynamic relocations. llvm-svn: 249835
* [ELF2] - Implemented rel[a].plt sectionsGeorge Rimar2015-10-091-1/+2
| | | | | | | | .rela.plt contains list of elements in the PLT, which are liable to the relocation during the dynamic linking. Differential Revision: http://reviews.llvm.org/D13569 llvm-svn: 249816
* [ELF2] Make the .plt entry size target dependentHal Finkel2015-10-081-4/+1
| | | | | | | | | The size of a .plt entry is different on different targets (it is, specifically, much larger than 8 on all PPC ABIs). There is no functional change here (later patches to create .plt entries for PPC64 will depend on this change). llvm-svn: 249756
* ELF2: Stop using SymbolTableSection as a container for SymbolTable.Rui Ueyama2015-10-071-1/+0
| | | | | | `Symtab` is better than `Out<ELFT>::SymTab->getSymTable()`. llvm-svn: 249619
* ELF2: Make singleton output sections globally accessible.Rui Ueyama2015-10-071-32/+25
| | | | | | | | | | | | | | | Previously, output sections that are handled specially by the linker (e.g. PLT or GOT) were created by Writer and passed to other classes that need them. The problem was that because these special sections are required by so many classes, the plumbing work became too much burden. This patch is to simply make them accessible from anywhere in the linker to eliminate the plumbing work once and for all. http://reviews.llvm.org/D13486 llvm-svn: 249590
* ELF2: Move functions out of line.Rui Ueyama2015-10-071-46/+4
| | | | llvm-svn: 249566
* Don't create dynamic relocations when its known what the got points to.Rafael Espindola2015-10-061-3/+4
| | | | llvm-svn: 249485
* Handle strong undefined symbols fetching members after a weak undefined.Rafael Espindola2015-10-061-1/+1
| | | | | | | | | | This is a case that requires --start-group --end-group with regular ELF linkers. Fortunately it is still possible to handle it with lazy symbols without taking a second look at archives. Thanks to Michael Spencer for the bug report. llvm-svn: 249406
* Handle a common symbol needing a R_X86_64_RELATIVE.Rafael Espindola2015-10-051-1/+3
| | | | llvm-svn: 249357
* Include existing addend when computing R_X86_64_RELATIVE.Rafael Espindola2015-10-051-0/+1
| | | | llvm-svn: 249353
* Don't copy STT_SECTION from the inputs.Rafael Espindola2015-10-051-1/+4
| | | | | | This matches the behavior of gold and bfd ld. llvm-svn: 249326
OpenPOWER on IntegriCloud