summaryrefslogtreecommitdiffstats
path: root/lld/ELF/OutputSections.h
Commit message (Collapse)AuthorAgeFilesLines
...
* ELF: Do not use -1 to mark pieces of merge sections as being tail merged.Peter Collingbourne2016-05-051-2/+1
| | | | | | | | | | | | | | | | | We were previously using an output offset of -1 for both GC'd and tail merged pieces. We need to distinguish these two cases in order to filter GC'd symbols from the symbol table -- we were previously asserting when we asked for the VA of a symbol pointing into a dead piece, which would end up asking the tail merging string table for an offset even though we hadn't initialized it properly. This patch fixes the bug by using an offset of -1 to exclusively mean GC'd pieces, using 0 for tail merges, and distinguishing the tail merge case from an offset of 0 by asking the output section whether it is tail merge. Differential Revision: http://reviews.llvm.org/D19953 llvm-svn: 268604
* [ELF][MIPS] Read/write .MIPS.options sectionSimon Atanasyan2016-05-041-0/+14
| | | | | | | | | MIPS N64 ABI introduces .MIPS.options section which specifies miscellaneous options to be applied to an object/shared/executable file. LLVM as well as modern versions of GNU tools read and write the only type of the options - ODK_REGINFO. It is exact copy of .reginfo section used by O32 ABI. llvm-svn: 268485
* Pass all buffers to BuildId hash function at once. NFC.Rui Ueyama2016-05-021-18/+4
| | | | | | | | | This change simplifies the BuildId classes by removing a few member functions and variables from them. It should also make it easy to parallelize hash computation in future because now each BuildId object see all inputs rather than one at a time. llvm-svn: 268333
* ELF: Create .gnu.version and .gnu.version_r sections when linking against ↵Peter Collingbourne2016-04-271-0/+49
| | | | | | | | versioned DSOs. Differential Revision: http://reviews.llvm.org/D19464 llvm-svn: 267775
* Revert "[ELF] - Avoid using memset for zero-initialization of struct member. ↵Sean Silva2016-04-201-1/+1
| | | | | | | | | | | | | | | | | | NFC." This reverts commit r266618. It breaks basically everything. I think VS2013 doesn't interpret this code in the same way. The size field (at least) is left uninitialized, causing all sorts of havok (e.g. creating a 34GB file for a trivial hello world program). The offending compiler reports itself as follows: c:\release-vs2013>cl /? Microsoft (R) C/C++ Optimizing Compiler Version 18.00.40629 for x64 Copyright (C) Microsoft Corporation. All rights reserved. llvm-svn: 266857
* Simplify mips got handling.Rafael Espindola2016-04-191-2/+2
| | | | | | | This avoids computing the address of a position in the got just to then subtract got->getva(). llvm-svn: 266831
* [ELF] - Avoid using memset for zero-initialization of struct member. NFC.George Rimar2016-04-181-1/+1
| | | | llvm-svn: 266618
* [ELF] Remove redundant empty line. NFCSimon Atanasyan2016-04-151-1/+0
| | | | llvm-svn: 266421
* Change how we apply relocations.Rafael Espindola2016-04-131-2/+1
| | | | | | | | | | | | | | | | | | | | | | | With this patch we use the first scan over the relocations to remember the information we found about them: will them be relaxed, will a plt be used, etc. With that the actual relocation application becomes much simpler. That is particularly true for the interfaces in Target.h. This unfortunately means that we now do two passes over relocations for non SHF_ALLOC sections. I think this can be solved by factoring out the code that scans a single relocation. It can then be used both as a scan that record info and for a dedicated direct relocation of non SHF_ALLOC sections. I also think it is possible to reduce the number of enum values by representing a target with just an OutputSection and an offset (which can be from the start or end). This should unblock adding features like relocation optimizations. llvm-svn: 266158
* Mark OffsetSec const. NFC.Rafael Espindola2016-04-111-2/+2
| | | | llvm-svn: 265940
* Remove initializer that are always set by the constructor.Rafael Espindola2016-04-111-5/+5
| | | | llvm-svn: 265939
* Mark a few methods const.Rafael Espindola2016-04-111-4/+4
| | | | llvm-svn: 265938
* Make getSymbolBinding a local static. NFC.Rafael Espindola2016-04-081-1/+0
| | | | llvm-svn: 265791
* ELF: Add --build-id=sha1 option.Rui Ueyama2016-04-071-0/+11
| | | | llvm-svn: 265748
* ELF: Implement --build-id=md5.Rui Ueyama2016-04-071-7/+28
| | | | | | | | | Previously, we supported only one hash function, FNV-1, so BuildIdSection directly handled hash computation. In this patch, I made BuildIdSection an abstract class and defined two subclasses, BuildIdFnv1 and BuildIdMd5. llvm-svn: 265737
* Simplify dynamic relocation creation.Rafael Espindola2016-04-071-20/+4
| | | | | | | The position of a relocation can always be expressed as an offset in an output section. llvm-svn: 265682
* Delete Off_Bss.Rafael Espindola2016-04-071-1/+0
| | | | | | It is now just a special case of Off_Sec. llvm-svn: 265676
* Don't create dynamic relocs for discarded .eh_frame entries.Rafael Espindola2016-04-071-7/+12
| | | | | | | | This requires knowing input section offsets in output sections before scanRelocs. This is generally a good thing and should allow further simplifications in the creation of dynamic relocations. llvm-svn: 265673
* Update for llvm change.Rafael Espindola2016-04-051-2/+1
| | | | llvm-svn: 265404
* [ELF] Implement infrastructure for thunk code creationSimon Atanasyan2016-03-311-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some targets might require creation of thunks. For example, MIPS targets require stubs to call PIC code from non-PIC one. The patch implements infrastructure for thunk code creation and provides support for MIPS LA25 stubs. Any MIPS PIC code function is invoked with its address in register $t9. So if we have a branch instruction from non-PIC code to the PIC one we cannot make the jump directly and need to create a small stub to save the target function address. See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf - In relocation scanning phase we ask target about thunk creation necessity by calling `TagetInfo::needsThunk` method. The `InputSection` class maintains list of Symbols requires thunk creation. - Reassigning offsets performed for each input sections after relocation scanning complete because position of each section might change due thunk creation. - The patch introduces new dedicated value for DefinedSynthetic symbols DefinedSynthetic::SectionEnd. Synthetic symbol with that value always points to the end of the corresponding output section. That allows to escape updating synthetic symbols if output sections sizes changes after relocation scanning due thunk creation. - In the `InputSection::writeTo` method we write thunks after corresponding input section. Each thunk is written by calling `TargetInfo::writeThunk` method. - The patch supports the only type of thunk code for each target. For now, it is enough. Differential Revision: http://reviews.llvm.org/D17934 llvm-svn: 265059
* Split Writer::assignAddresses. NFC.Rui Ueyama2016-03-301-0/+4
| | | | llvm-svn: 264905
* [ELF][MIPS] Reduce number of redundant entries in the local part of MIPS GOTSimon Atanasyan2016-03-291-0/+3
| | | | | | | | | | | | | | | | Local symbol which requires GOT entry initialized by "page" address. This address is high 16 bits of sum of the symbol value and the relocation addend. In the relocation scanning phase final values of symbols are unknown so to reduce number of allocated GOT entries do the following trick. Save all output sections referenced by GOT relocations during the relocation scanning phase. Then later in the `GotSection::finalize` method calculate number of "pages" required to cover all saved output sections and allocate appropriate number of GOT entries. We assume the worst case - each 64kb page of the output section has at least one GOT relocation against it. Differential Revision: http://reviews.llvm.org/D18349 llvm-svn: 264730
* [ELF][MIPS] Delete GotSection::addMipsLocalEntry methodSimon Atanasyan2016-03-221-1/+0
| | | | | | | | | | Now local symbols have SymbolBody so we can handle all kind of symbols in the GotSection::addEntry method. The patch moves the code from addMipsLocalEntry to addEntry. NFC. Differential Revision: http://reviews.llvm.org/D18302 llvm-svn: 264032
* Use ELFT instead of ELFFile<ELFT>.Rui Ueyama2016-03-141-43/+41
| | | | llvm-svn: 263510
* Remove unused #include.Rui Ueyama2016-03-131-5/+2
| | | | llvm-svn: 263390
* ELF: Add `Rela` member variable to Config.Rui Ueyama2016-03-131-3/+1
| | | | | | | The member is true if we want to create relocatin sections with RELA instead of REL. llvm-svn: 263387
* ELF: Redefine canBeDefined as a member function of SymbolBody.Rui Ueyama2016-03-131-2/+0
| | | | | | | | | We want to make SymbolBody the central place to query symbol information. This patch also renames canBePreempted to isPreemptible because I feel that the latter is slightly better (the former is three words and the latter is two words.) llvm-svn: 263386
* Use RelTy instead of Elf_Rel_Impl<ELFT, isRela> for readability.Rui Ueyama2016-03-131-5/+3
| | | | llvm-svn: 263368
* ELF: Implement --build-id.Rui Ueyama2016-03-111-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements --build-id. After the linker creates an output file in the memory buffer, it computes the FNV1 hash of the resulting file and set the hash to the .note section as a build-id. GNU ld and gold have the same feature, but their default choice of the hash function is different. Their default is SHA1. We made a deliberate choice to not use a secure hash function for the sake of performance. Computing a secure hash is slow -- for example, MD5 throughput is usually 400 MB/s or so. SHA1 is slower than that. As a result, if you pass --build-id to gold, then the linker becomes about 10% slower than that without the option. We observed a similar degradation in an experimental implementation of build-id for LLD. On the other hand, we observed only 1-2% performance degradation with the FNV hash. Since build-id is not for digital certificate or anything, we think that a very small probability of collision is acceptable. We considered using other signals such as using input file timestamps as inputs to a secure hash function. But such signals would have an issue with build reproducibility (if you build a binary from the same source tree using the same toolchain, the build id should become the same.) GNU linkers accepts --build-id=<style> option where style is one of "MD5", "SHA1", or an arbitrary hex string. That option is out of scope of this patch. http://reviews.llvm.org/D18091 llvm-svn: 263292
* Remember the input section of locals.Rafael Espindola2016-03-111-9/+0
| | | | | | This is already a simplification, but will allow much more. llvm-svn: 263224
* Create a SymbolBody for locals.Rafael Espindola2016-03-111-8/+5
| | | | | | pr26878 shows a case where locals have to be in the got. llvm-svn: 263222
* Move getLocalRelTarget to the file where it is used.Rafael Espindola2016-03-101-6/+0
| | | | llvm-svn: 263152
* Remove an unnecessary hack.Rafael Espindola2016-03-081-1/+1
| | | | | | | It doesn't look like anything is depending on using local dynamic tls relocations with preemptable symbols. llvm-svn: 262957
* Delete isTlsDynRel.Rafael Espindola2016-03-081-1/+1
| | | | | | | | | | | | It was a badly specified hack for when a tls relocation should be propagated to the dynamic relocation table. This replaces it with a not as bad hack of saying that a local dynamic tls relocation is never preempted. I will try to remove even that second hack in the next patch. llvm-svn: 262955
* [ELF] - add support for relocations against local symbols when producing ↵George Rimar2016-03-031-0/+3
| | | | | | | | | | | | | relocatable output. There was a known limitation for -r option: relocations against local symbols were not supported. For example rel[a].eh_frame sections contained relocations against sections and that was not supported for -r before. Patch fixes that. Differential review: http://reviews.llvm.org/D17813 llvm-svn: 262590
* Rename elf2 to elf.Rafael Espindola2016-02-281-2/+2
| | | | llvm-svn: 262159
* Fix some confusion about what can be preempted.Rafael Espindola2016-02-261-1/+1
| | | | | | | | | | | For shared libraries we allow any weak undefined symbol to eventually be resolved, even if we never see a definition in another .so. This matches the behavior when handling other undefined symbols in a shared library. For executables, we require seeing a definition in a .so or resolve it to zero. This is also similar to how non weak symbols are handled. llvm-svn: 262017
* [ELF] - Referencing __start or __stop should keep the section from GC.George Rimar2016-02-251-0/+2
| | | | | | | | | | | | This fixes the https://llvm.org/bugs/show_bug.cgi?id=22906 bug. In GNU Binutils, a reference to start or stop is sufficient to prevent the section from being garbage collected. Patch implements the same behavior for lld. Differential revision: http://reviews.llvm.org/D17502 llvm-svn: 261840
* [ELF2] - Basic implementation of -r/--relocatableGeorge Rimar2016-02-251-0/+1
| | | | | | | | | | | | | -r, -relocatable - Generate relocatable output Currently does not have support for files containing relocation sections with entries that refer to local symbols (like rel[a].eh_frame which refer to sections and not to symbols) Differential revision: http://reviews.llvm.org/D14382 llvm-svn: 261838
* Fix the aarch64 logic for dynamic relocations.Rafael Espindola2016-02-231-14/+0
| | | | | | | | | | | | | There is nothing aarch64 specific in here. If a symbol can be preempted, we need to copy the full relocation to the dynamic linker. If a symbol cannot be preempted, we can make the dynamic linker life easier and produce a relative relocation. This is directly equivalent to R_X86_64_64 to R_x86_64_RELATIVE conversion. llvm-svn: 261678
* [lld] [ELF/AArch64] Fix R_AARCH64_ABS64 in Shared modeAdhemerval Zanella2016-02-231-0/+14
| | | | | | | | | | | | | | This patch fixes the R_AARCH64_ABS64 relocation when used in shared mode, where it requires a dynamic R_AARCH64_RELATIVE relocation. To correct set the addend on the dynamic relocation (since it will be used by the dynamic linker), a new TargetInfo specific hook was created (getDynRelativeAddend) to get the correct addend based on relocation type. The patch fixes the issues when creating shared library code against {init,fini}_array, where it issues R_AARCH64_ABS64 relocation against local symbols. llvm-svn: 261651
* Add support for merging strings with alignment larger than one char.Rafael Espindola2016-02-191-2/+3
| | | | | | | | | | | This reduces the .rodata of scyladb from 4501932 to 4334639 bytes (1.038 times smaller). I don't think it is critical to support tail merging, just exact duplicates, but given the code organization it was actually a bit easier to support both. llvm-svn: 261327
* Renamed sh_type -> Type, sh_flags -> Flags in arguments. NFC.George Rimar2016-02-181-4/+4
| | | | llvm-svn: 261213
* Make getOffset a member function of DynamicReloc<ELFT>.Rui Ueyama2016-02-171-0/+2
| | | | | | | Logically it belongs to DynamicReloc, and it is more readable to be a member of the class. llvm-svn: 261069
* Use shorter names for the .gnu.hash class.Rui Ueyama2016-02-171-2/+2
| | | | llvm-svn: 261067
* Use stable_partition instead of erasing all elements and fill it again.Rui Ueyama2016-02-171-1/+1
| | | | llvm-svn: 261066
* Use an accurate type instead of unsigned.Rui Ueyama2016-02-171-4/+6
| | | | | | | These values are offsets in the string table (which must fit in host computer's memory space), so size_t is better than unsigned. llvm-svn: 261065
* Split SymbolTableSection::writeGlobalSymbols.Rui Ueyama2016-02-171-0/+1
| | | | | | | | Previously, we added garbage-collected symbols to the symbol table and filter them out when we were writing symbols to the file. In this patch, garbage-collected symbols are filtered out from beginning. llvm-svn: 261064
* ELF: Implement the correct semantics of .[cd]tors.Rui Ueyama2016-02-111-1/+3
| | | | | | | | | As I noted in the comment, the sorting order of .[cd]tors are different from .{init,fini}_array's. http://reviews.llvm.org/D17120 llvm-svn: 260620
* ELF: Implement __attribute__((init_priority(N)) support.Rui Ueyama2016-02-101-0/+1
| | | | llvm-svn: 260460
OpenPOWER on IntegriCloud