summaryrefslogtreecommitdiffstats
path: root/lld/ELF/OutputSections.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Move function to the file where it is used.Rafael Espindola2015-12-231-17/+0
| | | | llvm-svn: 256348
* Split Undefined and UndefinedElf.Rafael Espindola2015-12-221-6/+17
| | | | | | | | | | | | | | | | | | | | | | I am working on adding LTO support to the new ELF lld. In order to do that, it will be necessary to represent defined and undefined symbols that are not from ELF files. One way to do it is to change the symbol hierarchy to look like Defined : SymbolBody Undefined : SymbolBody DefinedElf<ELFT> : Defined UndefinedElf<ELFT> : Undefined Another option would be to use bogus Elf_Sym, but I think that is getting a bit too hackish. This patch does the Undefined/UndefinedElf. Split. The next one will do the Defined/DefinedElf split. llvm-svn: 256289
* Simplify types. NFC.Rafael Espindola2015-12-211-2/+2
| | | | llvm-svn: 256197
* Remove unnecessary cast.Rafael Espindola2015-12-211-1/+1
| | | | llvm-svn: 256189
* [ELF] - fixed not properly handled @GOTTPOFF relocation against local symbolsGeorge Rimar2015-12-211-22/+14
| | | | | | | | | | | | | | This patch changes sequence of applying relocations, moving tls optimized relocation handling code before code for other locals. Without that change relocation @GOTTPOFF against local symbol caused runtime error ("unrecognized reloc ..."). That change also should fix other tls optimized relocations, but I did not check them, that's a field for another patch. R_X86_64_GOTTPOFF relocations against locals can be found when linking against libc.a(malloc.o): 000000000036 000600000016 R_X86_64_GOTTPOFF 0000000000000000 libc_tsd_MALLOC - 4 000000000131 000600000016 R_X86_64_GOTTPOFF 0000000000000000 libc_tsd_MALLOC - 4 Differential revision: http://reviews.llvm.org/D15581 llvm-svn: 256145
* [ELF] - Implemented R_*_IRELATIVE relocations for x86, x64 targets.George Rimar2015-12-211-2/+5
| | | | | | | | | | | This relocation is similar to R_*_RELATIVE except that the value used in this relocation is the program address returned by the function, which takes no arguments, at the address of the result of the corresponding R_*_RELATIVE relocation as specified in the processor-specific ABI. The purpose of this relocation to avoid name lookup for locally defined STT_GNU_IFUNC symbols at load-time. More info can be found in ifunc.txt from https://sites.google.com/site/x32abi/documents. Differential revision: http://reviews.llvm.org/D15235 llvm-svn: 256144
* [ELF] - R_386_GOTOFF relocation implemented.George Rimar2015-12-211-0/+2
| | | | | | | | | | | R_386_GOTOFF is calculated as S + A - GOT, where: S - Represents the value of the symbol whose index resides in the relocation entry. A - Represents the addend used to compute the value of the relocatable field. GOT - Represents the address of the global offset table. Differential revision: http://reviews.llvm.org/D15383 llvm-svn: 256143
* [ELF] - Fixed padding for CIE/FDE entries of .eh_frame sectionGeorge Rimar2015-12-211-5/+6
| | | | | | | | | | | | Spec says both CIE/FDE has "Padding Extra bytes to align the CIE structure to an addressing unit size boundary." https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA/ehframechpt.html Patch aligns CIE/FDE entries to the size of platform pointer. Differential revision: http://reviews.llvm.org/D15637 llvm-svn: 256141
* [ELF][MIPS] MIPS .reginfo sections handlingSimon Atanasyan2015-12-201-0/+26
| | | | | | | | | | | | | | | | | | | | | MIPS .reginfo section provides information on the registers used by the code in the object file. Linker should collect this information and write .reginfo section in the output file. This section contains a union of used registers masks taken from input .reginfo sections and final value of the `_gp` symbol. For details see the "Register Information" section in Chapter 4 in the following document: ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf The patch implements .reginfo sections handling with a couple missed features: a) it does not put output .reginfo section into the separate REGINFO segment; b) it does not merge `ri_cprmask` masks from input section. These features will be implemented later. Differential Revision: http://reviews.llvm.org/D15669 llvm-svn: 256119
* [ELF] - implemented @indntpoff (x86) relocation and its optimization.George Rimar2015-12-171-2/+3
| | | | | | | | | | @indntpoff is similar to @gotntpoff, but for use in position dependent code. While @gotntpoff resolves to GOT slot address relative to the start of the GOT in the movl or addl instructions, @indntpoff resolves to the absolute GOT slot address. ("ELF Handling For Thread-Local Storage", Ulrich Drepper). Differential revision: http://reviews.llvm.org/D15494 llvm-svn: 255884
* [ELF] - implement support of extended length field for CIE/FDE records of ↵George Rimar2015-12-171-7/+27
| | | | | | | | | | | | eh_frame. Ian Lance Taylor writes: "Read 4 bytes. If they are not 0xffffffff, they are the length of the CIE or FDE record. Otherwise the next 64 bits holds the length, and this is a 64-bit DWARF format. This is like .debug_frame." (http://www.airs.com/blog/archives/460), that also consistent with spec (https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA/ehframechpt.html). Patch implements support of described extended length field and also adds few more checks for safety. Differential revision: http://reviews.llvm.org/D15532 llvm-svn: 255883
* ELF: Rename relocNeedsCopy -> needsCopyRelRui Ueyama2015-12-171-1/+1
| | | | | | Just "copy" was a bit too ambiguous to say about copy relocations. llvm-svn: 255866
* ELF: Separate NeedsCopy and OffsetInBSS.Rui Ueyama2015-12-171-2/+2
| | | | | | | | | | Previously, OffsetInBSS is -1 if it has no information about copy relocation, 0 if it needs a copy relocation, and >0 if its offset in BSS has been assigned. These flags were too subtle. This patch adds a new flag, NeedsCopy, to carry information about whether a shared symbol needs a copy relocation or not. llvm-svn: 255865
* ELF: Remove accessors that don't hide anything.Rui Ueyama2015-12-171-8/+8
| | | | llvm-svn: 255857
* ELF: Rename isTLS -> isTls for consistency.Rui Ueyama2015-12-171-1/+1
| | | | llvm-svn: 255855
* Fixed mistype in comment. NFC.George Rimar2015-12-151-1/+1
| | | | llvm-svn: 255646
* Reapply fixed r255626 that broke buildbot:George Rimar2015-12-151-15/+13
| | | | | | | | | | | | | [ELF] - refactor of code in RelocationSection<ELFT>::writeTo() Just a little reformat of 'if' conditions, NFC. Differential revision: http://reviews.llvm.org/D15453 Fix was: * Renamed unsigned Rel; to unsigned Reloc; llvm-svn: 255631
* Revert of r255626 "[ELF] - refactor of code in ↵George Rimar2015-12-151-13/+15
| | | | | | | | | | | | | | | RelocationSection<ELFT>::writeTo()" as it broke buildbot: http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/17836/steps/build_Lld/logs/stdio /Users/buildslave/as-bldslv9/lld-x86_64-darwin13/llvm.src/tools/lld/ELF/OutputSections.cpp:268:14: error: redefinition of 'Rel' unsigned Rel; ^ /Users/buildslave/as-bldslv9/lld-x86_64-darwin13/llvm.src/tools/lld/ELF/OutputSections.cpp:241:34: note: previous definition is here for (const DynamicReloc<ELFT> &Rel : Relocs) { That compiles fine on my MSVS 2015 thought. llvm-svn: 255628
* [ELF] - refactor of code in RelocationSection<ELFT>::writeTo()George Rimar2015-12-151-15/+13
| | | | | | | | Just a little reformat of 'if' conditions, NFC. Differential revision: http://reviews.llvm.org/D15453 llvm-svn: 255626
* Treat unnamed symbols as locals.Rafael Espindola2015-12-111-1/+1
| | | | | | | There is work under way in llvm to avoid creating unnecessary names for symbols. This makes lld capable of handling that. llvm-svn: 255357
* Discard local symbols from SHF_MERGE sections.Rafael Espindola2015-12-111-3/+14
| | | | | | This matches the behavior of both gold and bfd ld. llvm-svn: 255355
* Renamed addLocalModelTlsIndex() -> addCurrentModuleTlsIndex(), NFC.George Rimar2015-12-071-1/+1
| | | | | | (per discussion with Michael Spencer) llvm-svn: 254896
* [ELF] - Implemented @tlsgd optimization (GD->IE case, x64).George Rimar2015-12-041-7/+14
| | | | | | | | | "Ulrich Drepper, ELF Handling For Thread-Local Storage" (5.5 x86-x64 linker optimizations, http://www.akkadia.org/drepper/tls.pdf) shows how GD can be optimized to IE. This patch implements the optimization. Differential revision: http://reviews.llvm.org/D15000 llvm-svn: 254713
* [ELF] - Fixed bug leading to miss of tls relocation when @tlsgd and ↵George Rimar2015-12-011-4/+13
| | | | | | | | | | | | | | | | | @gottpoff relocations were used at the same time. Combination of @tlsgd and @gottpoff at the same time leads to miss of R_X86_64_TPOFF64 dynamic relocation. Patch fixes that. @tlsgd(%rip) - Allocate two contiguous entries in the GOT to hold a tls index structure (for passing to tls get addr). @gottpoff(%rip) - Allocate one GOT entry to hold a variable offset in initial TLS block (relative to TLS block end, %fs:0). The same situation can be observed for x86 (probably others too, not sure) with corresponding for that target relocations: @tlsgd, @gotntpoff. Differential revision: http://reviews.llvm.org/D15105 llvm-svn: 254443
* Reapply r254428.George Rimar2015-12-011-4/+6
| | | | | | | | | | | | | | | | | | | Fix was: uint32_t getLocalTlsIndexVA() { return getVA() + LocalTlsIndexOff; } => uint32_t getLocalTlsIndexVA() { return Base::getVA() + LocalTlsIndexOff; } Both works for my MSVS. Original commit message: [ELF] - Refactor of tls_index implementation for tls local dynamic model. Patch contains the next 2 changes: 1) static variable Out<ELFT>::LocalModuleTlsIndexOffset moved to Out<ELFT>::Got. At fact there is no meaning for it to be separated from GOT class because at each place of using it anyways needs to call GOT`s getVA(). Also it is impossible to have that offset and not have GOT. 2) addLocalModuleTlsIndex -> addLocalModelTlsIndex (word "Module" changed to "Model"). Not sure was it a mistype or not but I think that update is closer to Urlich terminology. Differential revision: http://reviews.llvm.org/D15113 llvm-svn: 254433
* revert r254428 [ELF] - Refactor of tls_index implementation for tls local ↵George Rimar2015-12-011-6/+4
| | | | | | | | | | | | | | dynamic model. It failed buildbot: http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/3782/steps/build/logs/stdio Target.cpp In file included from /home/buildbot/Buildbot/Slave/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/lld/ELF/Target.cpp:20: /home/buildbot/Buildbot/Slave/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/lld/ELF/OutputSections.h:136:42: error: use of undeclared identifier 'getVA' uint32_t getLocalTlsIndexVA() { return getVA() + LocalTlsIndexOff; } llvm-svn: 254432
* [ELF] - Refactor of tls_index implementation for tls local dynamic model.George Rimar2015-12-011-4/+6
| | | | | | | | | | Patch contains the next 2 changes: 1) static variable Out<ELFT>::LocalModuleTlsIndexOffset moved to Out<ELFT>::Got. At fact there is no meaning for it to be separated from GOT class because at each place of using it anyways needs to call GOT`s getVA(). Also it is impossible to have that offset and not have GOT. 2) addLocalModuleTlsIndex -> addLocalModelTlsIndex (word "Module" changed to "Model"). Not sure was it a mistype or not but I think that update is closer to Urlich terminology. Differential revision: http://reviews.llvm.org/D15113 llvm-svn: 254428
* [ELF] - Split RelocationSection<ELFT>::writeTo function.George Rimar2015-11-301-19/+26
| | | | | | | | Splitted writeTo to separate tls relocs handling stuff which is too long for one method now. NFC. Differential revision: http://reviews.llvm.org/D15012 llvm-svn: 254309
* Fixed potential crash on non-ELF64LE targets.George Rimar2015-11-291-1/+1
| | | | | | Incorrect template specialization was used (generic ELFT type was expected but platform specific was used). llvm-svn: 254253
* Replaced stuff with auto. NFC.George Rimar2015-11-261-1/+1
| | | | llvm-svn: 254175
* Reapply r254098.George Rimar2015-11-251-5/+17
| | | | | | | | | Fix is (OutputSections.cpp): for (std::pair<const SymbolBody *, size_t> &I : Entries) { => for (std::pair<const SymbolBody *, unsigned> &I : Entries) { llvm-svn: 254105
* Revert r254098 as it seems broke build bot.George Rimar2015-11-251-17/+5
| | | | | | http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/3555 llvm-svn: 254103
* [ELF] - Lazy relocations support for x86 target.George Rimar2015-11-251-5/+17
| | | | | | | | | | | Patch implements lazy relocations for x86. One of features of x86 is that executable files and shared object files have separate procedure linkage tables. So patch implements both cases. Detailed information about instructions used can be found in http://docs.oracle.com/cd/E19620-01/805-3050/chapter6-1235/index.html (search: x86: Procedure Linkage Table). Differential revision: http://reviews.llvm.org/D14955 llvm-svn: 254098
* [ELF/x86] Implemented R_386_TLS_LE_32, R_386_TLS_LE relocations.George Rimar2015-11-251-1/+2
| | | | | | | | | | | | | | | | | | | | | This patch implements next relocations: R_386_TLS_LE - Negative offset relative to static TLS (GNU version). R_386_TLS_LE_32 - Offset relative to static TLS block. These ones are created when using next code sequences: * @tpoff - The operator must be used to compute an immediate value. The linker will report an error if the referenced variable is not defined or it is not code for the executable itself. No GOT entry is created in this case. * @ntpoff Calculate the negative offset of the variable it is added to relative to the static TLS block. The operator must be used to compute an immediate value. The linker will report an error if the referenced variable is not defined or it is not code for the executable itself. No GOT entry is created in this case. Information was found in Ulrich Drepper, ELF Handling For Thread-Local Storage, http://www.akkadia.org/drepper/tls.pdf, (6.2, p76) Differential revision: http://reviews.llvm.org/D14930 llvm-svn: 254090
* Fix Elf_Rel processing for .eh_frame.Rafael Espindola2015-11-231-1/+1
| | | | | | Thanks to Simon for the bug report. llvm-svn: 253869
* Fix formatting.Rui Ueyama2015-11-191-9/+8
| | | | llvm-svn: 253620
* [ELF2] Remove target specific code from GotPltSection.Igor Kudrin2015-11-161-9/+7
| | | | | | | | | | | The content of reserved entries of the .got.plt section is target specific. In particular, on x86_64 the zero entry holds the address of the .dynamic section, but on AArch64 the same info is stored in the zero entry of the .got section. Differential revision: http://reviews.llvm.org/D14703 llvm-svn: 253239
* [ELF2] - Implemented R_X86_64_GOTTPOFF relocationGeorge Rimar2015-11-131-4/+9
| | | | | | | | Generates single GOT entry, R_X86_64_TPOFF64 is added to RelaDyn. Differential revision: http://reviews.llvm.org/D14621 llvm-svn: 253049
* [ELF2] - fix of eh-frame-merge.s and eh-frame-merge.s tests fails for win32 ↵George Rimar2015-11-131-1/+1
| | | | | | configuration. llvm-svn: 253043
* [elf2] get{Local,Global}DynamicReloc -> is{LocalGlobal}DynamicReloc.Michael J. Spencer2015-11-131-2/+2
| | | | llvm-svn: 252982
* [elf2] Implement global dynamic tls.Michael J. Spencer2015-11-131-2/+21
| | | | llvm-svn: 252979
* [ELF2] Add mandatory .dynamic section entries on MIPS.Igor Kudrin2015-11-121-2/+56
| | | | | | | | | | | | | | | | | | | | | The MIPS target requires specific dynamic section entries to be defined. * DT_MIPS_RLD_VERSION and DT_MIPS_FLAGS store predefined values. * DT_MIPS_BASE_ADDRESS holds base VA. * DT_MIPS_LOCAL_GOTNO holds the number of local GOT entries. * DT_MIPS_SYMTABNO holds the number of .dynsym entries. * DT_MIPS_GOTSYM holds the index of the .dynsym entry which corresponds to the first entry of the global part of GOT. * DT_MIPS_RLD_MAP holds the address of the reserved space in the data segment. * DT_MIPS_PLTGOT points to the .got.plt section if it exists. * DT_PLTGOT holds the address of the GOT section. See "Dynamic Section" in Chapter 5 in the following document for detailed description: ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf Differential revision: http://reviews.llvm.org/D14450 llvm-svn: 252857
* [ELF2] Sort dynamic symbols according to the MIPS requirements.Igor Kudrin2015-11-121-0/+13
| | | | | | | | | | | | | The MIPS ABI has requirements to sort the entries in the .dyn.sym section. Symbols which are not in the GOT have to precede the symbols which are added to the GOT. The latter must have the same order as the corresponding GOT entries. Since these sorting requirements contradict those of the GNU hash section, they cannot be used together. Differential revision: http://reviews.llvm.org/D14281 llvm-svn: 252854
* Add support for processing .eh_frame.Rafael Espindola2015-11-111-2/+151
| | | | | | | | | | | | | This adds support for: * Uniquing CIEs * Dropping FDEs that point to dropped sections It drops 657 488 bytes from the .eh_frame of a Release+Asserts clang. The link time impact is smallish. Linking clang with a Release+Asserts lld goes from 0.488064805 seconds to 0.504763060 seconds (1.034 X slower). llvm-svn: 252790
* [elf2] Add support for local TLS symbols.Michael J. Spencer2015-11-111-1/+6
| | | | llvm-svn: 252686
* [elf2] Add support for R_X86_64_TLSLD.Michael J. Spencer2015-11-111-0/+17
| | | | | | | | | | | | | | | 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
* Start treating .eh_frame specially.Rafael Espindola2015-11-091-1/+1
| | | | | | | For now, just don't follow edges leaving from it to mark other sections live. llvm-svn: 252493
* Round up the memsize of PT_TLS.Rafael Espindola2015-11-061-1/+1
| | | | | | | | 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-2/+16
| | | | | | | | | | | | | | | 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] 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
OpenPOWER on IntegriCloud