summaryrefslogtreecommitdiffstats
path: root/lld/ELF/OutputSections.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Move isValidCIdentifier to Strings.cpp.Rui Ueyama2016-06-291-12/+1
| | | | llvm-svn: 274112
* [ELF][MIPS] Support MIPS TLS relocationsSimon Atanasyan2016-06-231-1/+22
| | | | | | | | | | | | | | | | | | | | | | | The patch adds one more partition to the MIPS GOT. This time it is for TLS related GOT entries. Such entries are located after 'local' and 'global' ones. We cannot get a final offset for these entries at the time of creation because we do not know size of 'local' and 'global' partitions. So we have to adjust the offset later using `getMipsTlsOffset()` method. All MIPS TLS relocations which need GOT entries operates MIPS style GOT offset - 'offset from the GOT's beginning' - MipsGPOffset constant. That is why I add new types of relocation expressions. One more difference from othe ABIs is that the MIPS ABI does not support any TLS relocation relaxations. I decided to make a separate function `handleMipsTlsRelocation` and put MIPS TLS relocation handling code there. It is similar to `handleTlsRelocation` routine and duplicates its code. But it allows to make the code cleaner and prevent pollution of the `handleTlsRelocation` by MIPS 'if' statements. Differential Revision: http://reviews.llvm.org/D21606 llvm-svn: 273569
* Fix a bug that MIPS thunks can overwrite other section contents.Rui Ueyama2016-06-231-17/+33
| | | | | | | | | | | | | | | Peter Smith found while trying to support thunk creation for ARM that LLD sometimes creates broken thunks for MIPS. The cause of the bug is that we assign file offsets to input sections too early. We need to create all sections and then assign section offsets because appending thunks changes file offsets for all following sections. This patch separates the pass to assign file offsets from thunk creation pass. This effectively reverts r265673. Differential Revision: http://reviews.llvm.org/D21598 llvm-svn: 273532
* [ELF] - Implemented version script hierarchies.George Rimar2016-06-221-4/+25
| | | | | | | | | | | | | | | | | | | | Patch implements hierarchies for version scripts. This allows to handle script files with dependencies, like next one has: LIBSAMPLE_1.0{ global: a; }; LIBSAMPLE_2.0 { global: b; }LIBSAMPLE_1.0; Differential revision: http://reviews.llvm.org/D21556 llvm-svn: 273423
* [ELF] - Recommit r273143("[ELF] - Basic versioned symbols support implemented.")George Rimar2016-06-201-8/+88
| | | | | | | | | | | | | | | | | | With fix: -soname flag was not set in testcase. Hash calculated for base def was different on local and bot machines because filename fos used for calculating. Initial commit message: Patch implements basic support of versioned symbols. There is no wildcards patterns matching except local: *; There is no support for hierarchies. There is no support for symbols overrides (@ vs @@ not handled). This patch allows programs that using simple scripts to link and run. Differential revision: http://reviews.llvm.org/D21018 llvm-svn: 273152
* [ELF][MIPS] Fix predicate used for sorting MIPS dynamic symbol tablesSimon Atanasyan2016-06-201-2/+4
| | | | | | | Now it conforms requirement for std::stable_sort predicates. That resolves build-bot failures on Windows hosts. llvm-svn: 273151
* Revert r273143 "[ELF] - Basic versioned symbols support implemented."George Rimar2016-06-201-88/+8
| | | | | | | It broke buildbot: http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast llvm-svn: 273146
* [ELF] - Basic versioned symbols support implemented.George Rimar2016-06-201-8/+88
| | | | | | | | | | | | | Patch implements basic support of versioned symbols. There is no wildcards patterns matching except local: *; There is no support for hierarchies. There is no support for symbols overrides (@ vs @@ not handled). This patch allows programs that using simple scripts to link and run. Differential revision: http://reviews.llvm.org/D21018 llvm-svn: 273143
* Fixed compilation error under MSVS 2015 (looks like compiler bug). NFC.George Rimar2016-06-201-1/+2
| | | | llvm-svn: 273142
* [ELF][MIPS] Support GOT entries for non-preemptible symbols with different ↵Simon Atanasyan2016-06-191-93/+118
| | | | | | | | | | | | | | | | | | | | | | | | | | addends There are two motivations for this patch. The first one is a preparation for support MIPS TLS relocations. It might sound like a joke but for GOT entries related to TLS relocations MIPS ABI uses almost regular approach with creation of dynamic relocations for each GOT enty etc. But we need to separate these 'regular' TLS related entries from MIPS specific local and global parts of GOT. ABI declare simple solution - all TLS related entries allocated at the end of GOT after local/global parts. The second motivation it to support GOT relocations for non-preemptible symbols with addends. If we have more than one GOT relocations against symbol S with different addends we need to create GOT entries for each unique Symbol/Addend pairs. So we store all MIPS GOT entries in separate containers. For non-preemptible symbols we have to maintain two data structures. The first one is MipsLocal vector. Each entry corresponds to the GOT entry from the 'local' part of the GOT contains the symbol's address plus addend. The second one is MipsLocalMap. It is a map from Symbol/Addend pair to the GOT index. Differential Revision: http://reviews.llvm.org/D21297 llvm-svn: 273127
* Rename Align -> Alignment.Rui Ueyama2016-06-171-3/+3
| | | | | | | | I think it is me who named these variables, but I always find that they are slightly confusing because align is a verb. Adding four letters is worth it. llvm-svn: 272984
* Rename PltZero -> PltHeader.Rui Ueyama2016-06-161-3/+3
| | | | | | | | | | | | PltZero (or PLT[0]) was an appropriate name for the little code we have at beginning of the PLT section when we only supported x86 since the code for x86 just fits in the first PLT slot. It's not the case anymore. The code for ARM64 occupies first two slots, so PltZero spans PLT[0] and PLT[1], for example. This patch renames it to avoid confusion. llvm-svn: 272913
* Eliminate unnecessary call of SymbolBody::getPltVA.Rui Ueyama2016-06-161-1/+1
| | | | | | | | For ARM and MIPS, we don't need to call this function. This patch passes a symbol instead of a PLT entry address so that the target handler can call it if necessary. llvm-svn: 272910
* [ELF][MIPS] Move MIPS specific code under `if` block to accent its ↵Simon Atanasyan2016-06-101-14/+17
| | | | | | specificity. NFC llvm-svn: 272389
* Handle gd tls relocs pointing to local symbols.Rafael Espindola2016-06-081-1/+1
| | | | | | | | | If the symbol is local we don't need to create a R_X86_64_DTPOFF64, we can just write the correct value in the got. Should fix pr28018. llvm-svn: 272205
* [ELF] - Removed includeInGnuHashTable() function. NFC.George Rimar2016-06-081-6/+1
| | | | | | | It was one line global static function that looks nicer to inline, patch do that. llvm-svn: 272137
* [ELF] - Replaced one more hardcode with named constant. NFC.George Rimar2016-06-081-2/+1
| | | | llvm-svn: 272130
* [ELF] - Replaced hardcode with named constants. NFC.George Rimar2016-06-081-2/+1
| | | | llvm-svn: 272129
* [ELF] - Assign sh_link field of SHT_GNU_versym section to DynSymTab section ↵George Rimar2016-06-061-0/+3
| | | | | | | | | | | | | | | | | | | index. .gnu.version should have sh_link field initialized with index of DynSymTab section. GNU documentation looks misses that, but Sun docs mention it, according to https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter6-54676/index.html versym sh_link is indeed supposed to point to the .dynsym section. Binutils readelf tool also relies on that: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=binutils/readelf.c;h=b6454d353279dc57745cd5a2d68b5f3f69f8e17c;hb=5522f910cb539905d6adfdceab208ddfa5e84557#l9988 Both gold/bfd do the same + after this patch I am able to see this section in readelf output, was unable before in my case. Differential revision: http://reviews.llvm.org/D20956 llvm-svn: 271874
* Move GlobalDynIndex to SymbolBody.Rafael Espindola2016-06-051-4/+4
| | | | | | With that we can have local symbols with a tls gd index. llvm-svn: 271852
* Avoid doing binary search.Rui Ueyama2016-05-271-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MergedInputSection::getOffset is the busiest function in LLD if string merging is enabled and input files have lots of mergeable sections. It is usually the case when creating executable with debug info, so it is pretty common. The reason why it is slow is because it has to do faily complex computations. For non-mergeable sections, section contents are contiguous in output, so in order to compute an output offset, we only have to add the output section's base address to an input offset. But for mergeable strings, section contents are split for merging, so they are not contigous. We've got to do some lookups. We used to do binary search on the list of section pieces. It is slow because I think it's hostile to branch prediction. This patch replaces it with hash table lookup. Seems it's working pretty well. Below is "perf stat -r10" output when linking clang with debug info. In this case this patch speeds up about 4%. Before: 6584.153205 task-clock (msec) # 1.001 CPUs utilized ( +- 0.09% ) 238 context-switches # 0.036 K/sec ( +- 6.59% ) 0 cpu-migrations # 0.000 K/sec ( +- 50.92% ) 1,067,675 page-faults # 0.162 M/sec ( +- 0.15% ) 18,369,931,470 cycles # 2.790 GHz ( +- 0.09% ) 9,640,680,143 stalled-cycles-frontend # 52.48% frontend cycles idle ( +- 0.18% ) <not supported> stalled-cycles-backend 21,206,747,787 instructions # 1.15 insns per cycle # 0.45 stalled cycles per insn ( +- 0.04% ) 3,817,398,032 branches # 579.786 M/sec ( +- 0.04% ) 132,787,249 branch-misses # 3.48% of all branches ( +- 0.02% ) 6.579106511 seconds time elapsed ( +- 0.09% ) After: 6312.317533 task-clock (msec) # 1.001 CPUs utilized ( +- 0.19% ) 221 context-switches # 0.035 K/sec ( +- 4.11% ) 1 cpu-migrations # 0.000 K/sec ( +- 45.21% ) 1,280,775 page-faults # 0.203 M/sec ( +- 0.37% ) 17,611,539,150 cycles # 2.790 GHz ( +- 0.19% ) 10,285,148,569 stalled-cycles-frontend # 58.40% frontend cycles idle ( +- 0.30% ) <not supported> stalled-cycles-backend 18,794,779,900 instructions # 1.07 insns per cycle # 0.55 stalled cycles per insn ( +- 0.03% ) 3,287,450,865 branches # 520.799 M/sec ( +- 0.03% ) 72,259,605 branch-misses # 2.20% of all branches ( +- 0.01% ) 6.307411828 seconds time elapsed ( +- 0.19% ) Differential Revision: http://reviews.llvm.org/D20645 llvm-svn: 270999
* [ELF][MIPS] Handle section symbol points to the .MIPS.options / .reginfo sectionSimon Atanasyan2016-05-261-0/+2
| | | | | | | | | | | | | | MIPS .reginfo and .MIPS.options sections are consumed by the linker, and the linker produces a single output section. But it is possible that input files contain section symbol points to the corresponding input section. In case of generation a relocatable output we need to write such symbols to the output file. Fixes bug 27878. Differential Revision: http://reviews.llvm.org/D20688 llvm-svn: 270910
* Make SectionPiece 8 bytes smaller on LP64.Rui Ueyama2016-05-251-8/+8
| | | | | | | | | | | | This patch makes SectionPiece class 8 bytes smaller on platforms on which pointer size is 8 bytes. Sean suggested in a post commit review for r270340 that this could make a differentce, and it actually is. Time to link clang (with debug info) improved from 6.725 seconds to 6.589 seconds or by about 2%. Differential Revision: http://reviews.llvm.org/D20613 llvm-svn: 270717
* Use range loop.Rafael Espindola2016-05-241-3/+2
| | | | | | Thanks to Rui for the suggestion. llvm-svn: 270601
* Fix a wrong assumption.Rafael Espindola2016-05-241-18/+21
| | | | llvm-svn: 270573
* Do not start over relocation search from beginning.Rui Ueyama2016-05-241-9/+16
| | | | | | | | | | This patch addresses a post-commit review for r270325. r270325 introduced getReloc function that searches a relocation for a given range. It always started searching from beginning of relocation vector, so it was slower than before. Previously, we used to use the fact that the relocations are sorted. This patch restore it. llvm-svn: 270572
* Handle terminator .eh_frame when creating the index.Rafael Espindola2016-05-241-0/+4
| | | | llvm-svn: 270568
* Do not pass the symbol table. NFC.Rui Ueyama2016-05-241-9/+10
| | | | | | | Since the symbol table is a singleton class and globally accessible, we don't need to pass it around. llvm-svn: 270533
* Rename EHInputSection -> EhInputSection.Rui Ueyama2016-05-241-6/+6
| | | | llvm-svn: 270532
* Create a new file EhFrame.cpp and move code to read .eh_frame there.Rui Ueyama2016-05-241-99/+1
| | | | llvm-svn: 270526
* Use range-based for.Rui Ueyama2016-05-241-4/+1
| | | | llvm-svn: 270523
* Make getFdeEncoding a non-member function.Rui Ueyama2016-05-241-5/+3
| | | | | | This function does not depend on EhOutputSection class. llvm-svn: 270522
* Fix typos.Rui Ueyama2016-05-231-2/+2
| | | | llvm-svn: 270451
* Remove EhFrameHeader<ELFT>::reserveFde. NFC.Rui Ueyama2016-05-231-15/+7
| | | | llvm-svn: 270448
* Make .eh_frame a singleton output object.Rui Ueyama2016-05-231-18/+11
| | | | | | | | .eh_frame_hdr assumes that there is only one .eh_frame and ensures it by assertions. This patch makes .eh_frame a real singleton object to simplify. llvm-svn: 270445
* Do not propagate section name and attributes to .eh_frame.Rui Ueyama2016-05-231-3/+2
| | | | | | | | .eh_frame is always ".eh_frame" and its attribute is fixed. No need to copy from inputs to outputs. GNU gold also sets SHT_PROGBITS. llvm-svn: 270443
* Rename EHOutputSection -> EhOutputSection for consistency.Rui Ueyama2016-05-231-15/+15
| | | | llvm-svn: 270442
* Refactor EhFrameHdr.Rui Ueyama2016-05-231-60/+61
| | | | | | | | | | | | | Previously, EhFrameHdr section computed addresses to which FDEs are applied to. This is not an ideal design because EhFrameHdr does not know much about FDEs unless EhFrame passes the information to EhFrameHdr. It is what we did. This patch simplifies the code by making EhFrame to compute the values and pass the cooked information to EhFrameHdr. EhFrameHdr no longer have to know about the details of FDEs such as FDE encodings. llvm-svn: 270393
* Add comment.Rui Ueyama2016-05-231-0/+4
| | | | llvm-svn: 270390
* Simplify. NFC.Rui Ueyama2016-05-231-5/+5
| | | | llvm-svn: 270388
* Move splitInputSection from EHOutputSection to EHInputSection.Rui Ueyama2016-05-221-36/+1
| | | | llvm-svn: 270385
* Attempt to unbreak buildbots.Rui Ueyama2016-05-221-8/+8
| | | | | | | | My last commit made Clang to fail with an assertion failure. https://llvm.org/bugs/show_bug.cgi?id=27835 This is a patch to avoid that. llvm-svn: 270384
* Refactor EHOutputSection.Rui Ueyama2016-05-221-112/+130
| | | | | | | | | | | | | | This patch refactors EHOutputSection using SectionPiece struct. EHRegion class was removed since we can now directly use SectionPiece. An incomplete support of large CIE/FDE record (> 2^32 bytes) was removed because it silently created broken executable. There are several places in the existing code that "size" field is always 4 bytes and at offset 4 in the record, which is not true for 64-bit size records. We will have to support that in future, but it is better to error out instead of creating malformed eh_frame sections. llvm-svn: 270382
* Store section contents to SectionPiece. NFC.Rui Ueyama2016-05-221-6/+7
| | | | | | So that we don't need to cut a slice when we use a SectionPiece. llvm-svn: 270348
* Use StringPiece::Size instead of calculating it again. NFC.Rui Ueyama2016-05-221-28/+10
| | | | llvm-svn: 270347
* Simplify SplitInputSection::getRangeAndSize.Rui Ueyama2016-05-221-3/+3
| | | | | | | | This patch adds Size member to SectionPiece so that getRangeAndSize can just return a SectionPiece instead of a std::pair<SectionPiece *, uint_t>. Also renamed the function. llvm-svn: 270346
* Use slightly longer names. NFC.Rui Ueyama2016-05-221-50/+51
| | | | | | | We generally prefer short names, but this code went probably a bit too far. This patch renames single letter local/member varables. llvm-svn: 270342
* Use ArrayRef<uint8_t> for binary data instead of StringRef. NFC.Rui Ueyama2016-05-221-5/+5
| | | | llvm-svn: 270341
* Define SectionPiece and use it instead of std::pair<uint_t, uint_t>.Rui Ueyama2016-05-221-23/+20
| | | | | | | | | | | | | We were using std::pair to represents pieces of splittable section contents. It hurt readability because "first" and "second" are not meaningful. This patch give them names. One more thing is that piecewise liveness information is stored to the second element of the pair as a special value of output section offset. It was confusing, so I defiend a new bit, "Live", in the new struct. llvm-svn: 270340
* Use uintX_t instead of unsigned.Rui Ueyama2016-05-211-1/+1
| | | | | | | | This fixes a potential bug when cross linking very large executables on LLP64 machines such as Windows. On such platform, uintX_t is 64 bits while unsigned is 32 bits. llvm-svn: 270327
OpenPOWER on IntegriCloud