summaryrefslogtreecommitdiffstats
path: root/lld/ELF/InputSection.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Simplify ICF alignment handling.Rui Ueyama2016-12-051-1/+1
| | | | llvm-svn: 288630
* Ignone SHF_INFO_LINK.Rafael Espindola2016-12-031-3/+4
| | | | | | | | | Some elf producers (dtrace) put this flag in relocation sections and some (MC) don't. If we don't ignore the flag we end up with multiple relocation sections poiting to the same section, which we don't support. llvm-svn: 288585
* [ELF] - Disable emiting multiple output sections when merging is disabled.George Rimar2016-11-291-0/+6
| | | | | | | | | | When -O0 is specified, we do not do section merging. Though before this patch several sections were generated instead of single, what is useless. Differential revision: https://reviews.llvm.org/D27041 llvm-svn: 288151
* [ELF][MIPS] Do not change MipsGotSection state in the getPageEntryOffset methodSimon Atanasyan2016-11-291-1/+1
| | | | | | | | | | | | | | The MipsGotSection::getPageEntryOffset calculates index of GOT entry with a "page" address. Previously this method changes the state of MipsGotSection because it modifies PageIndexMap field. That leads to the unpredictable results if getPageEntryOffset called from multiple threads. The patch makes getPageEntryOffset constant. To do so it calculates GOT entry index but does not update PageIndexMap field. Later in the MipsGotSection::writeTo method linker calculates "page" addresses and writes them to the output. llvm-svn: 288129
* Change return types of split{Non,}Strings.Rui Ueyama2016-11-261-13/+8
| | | | | | | | They return new vectors, but at the same time they mutate other vectors, so returning values doesn't make much sense. We should just mutate two vectors. llvm-svn: 287979
* Fix typo.Rui Ueyama2016-11-251-4/+4
| | | | llvm-svn: 287951
* Parallelize uncompress() and splitIntoPieces().Rui Ueyama2016-11-251-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Uncompressing section contents and spliting mergeable section contents into smaller chunks are heavy tasks. They scan entire section contents and do CPU-intensive tasks such as uncompressing zlib-compressed data or computing a hash value for each section piece. Luckily, these tasks are independent to each other, so we can do that in parallel_for_each. The number of input sections is large (as opposed to the number of output sections), so there's a large parallelism here. Actually the current design to call uncompress() and splitIntoPieces() in batch was chosen with doing this in mind. Basically what we need to do here is to replace `for` with `parallel_for_each`. It seems this patch improves latency significantly if linked programs contain debug info (which in turn contain lots of mergeable strings.) For example, the latency to link Clang (debug build) improved by 20% on my machine as shown below. Note that ld.gold took 19.2 seconds to do the same thing. Before: 30801.782712 task-clock (msec) # 3.652 CPUs utilized ( +- 2.59% ) 104,084 context-switches # 0.003 M/sec ( +- 1.02% ) 5,063 cpu-migrations # 0.164 K/sec ( +- 13.66% ) 2,528,130 page-faults # 0.082 M/sec ( +- 0.47% ) 85,317,809,130 cycles # 2.770 GHz ( +- 2.62% ) 67,352,463,373 stalled-cycles-frontend # 78.94% frontend cycles idle ( +- 3.06% ) <not supported> stalled-cycles-backend 44,295,945,493 instructions # 0.52 insns per cycle # 1.52 stalled cycles per insn ( +- 0.44% ) 8,572,384,877 branches # 278.308 M/sec ( +- 0.66% ) 141,806,726 branch-misses # 1.65% of all branches ( +- 0.13% ) 8.433424003 seconds time elapsed ( +- 1.20% ) After: 35523.764575 task-clock (msec) # 5.265 CPUs utilized ( +- 2.67% ) 159,107 context-switches # 0.004 M/sec ( +- 0.48% ) 8,123 cpu-migrations # 0.229 K/sec ( +- 23.34% ) 2,372,483 page-faults # 0.067 M/sec ( +- 0.36% ) 98,395,342,152 cycles # 2.770 GHz ( +- 2.62% ) 79,294,670,125 stalled-cycles-frontend # 80.59% frontend cycles idle ( +- 3.03% ) <not supported> stalled-cycles-backend 46,274,151,813 instructions # 0.47 insns per cycle # 1.71 stalled cycles per insn ( +- 0.47% ) 8,987,621,670 branches # 253.003 M/sec ( +- 0.60% ) 148,900,624 branch-misses # 1.66% of all branches ( +- 0.27% ) 6.747548004 seconds time elapsed ( +- 0.40% ) llvm-svn: 287946
* Move getLocation from Relocations.cpp to InputSection.cpp.Rui Ueyama2016-11-251-1/+26
| | | | | | | | The function was used only within Relocations.cpp, but now we are using it in many places, so this patch moves it to a file that fits to the functionality. llvm-svn: 287943
* [ELF] Add explicit template instantiations for toStringEugene Leviant2016-11-251-0/+5
| | | | llvm-svn: 287938
* [ELF][MIPS] Fix handling of _gp/_gp_disp/__gnu_local_gp symbolsSimon Atanasyan2016-11-231-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | Offset between beginning of a .got section and _gp symbols used in MIPS GOT relocations calculations. Usually the expression looks like VA + Offset - GP, where VA is the .got section address, Offset - offset of the GOT entry, GP - offset between .got and _gp. Also there two "magic" symbols _gp_disp and __gnu_local_gp which hold the offset mentioned above. These symbols might be referenced by MIPS relocations. Now the linker always defines _gp symbol and uses hardcoded value for its initialization. So offset between .got and _gp is 0x7ff0. The _gp_disp and __gnu_local_gp defined if required and initialized by 0x7ff0. In fact that is not correct because _gp symbol might be defined by a linker script and holds arbitrary value. In that case we need to use this value in relocation calculation and initialize _gp_disp and __gnu_local_gp properly. The patch fixes the problem and completes fixing the bug #30311. https://llvm.org/bugs/show_bug.cgi?id=30311 Differential revision: https://reviews.llvm.org/D27036 llvm-svn: 287832
* Define toString() as a generic function to get a string for error message.Rui Ueyama2016-11-231-10/+16
| | | | | | | | | | | | | | | We have different functions to stringize objects to construct error messages. For InputFile, we have getFilename, and for InputSection, we have getName. You had to memorize them. I think this is the case where the function overloading comes in handy. This patch defines toString() functions that are overloaded for all these types, so that you just call it in error(). Differential Revision: https://reviews.llvm.org/D27030 llvm-svn: 287787
* [ELF] Refactor several error messagesEugene Leviant2016-11-231-2/+3
| | | | | | Differential revision: https://reviews.llvm.org/D26970 llvm-svn: 287753
* [ELF] Fixup buffer pointer when writing synthetic sectionsEugene Leviant2016-11-231-1/+1
| | | | | | Differential revision: https://reviews.llvm.org/D26980 llvm-svn: 287751
* [ELF] Print error location in .eh_frame parserEugene Leviant2016-11-231-3/+2
| | | | | | Differential revision: https://reviews.llvm.org/D26914 llvm-svn: 287750
* Simplify MergeOutputSection.Rui Ueyama2016-11-181-28/+15
| | | | | | | | | | | | | | | | | MergeOutputSection class was a bit hard to use because it provdes a series of finalize functions that have to be called in a right way at a right time. It also intereacted with MergeInputSection, and the logic was somewhat entangled between the two classes. This patch simplifies it by providing only one finalize function. Now, all you have to do is to call MergeOutputSection::finalize when you have added all sections to the output section. Then, it internally merges strings and initliazes StringPiece objects. I think this is much easier to understand. This patch also adds comments. llvm-svn: 287314
* [ELF][MIPS] Remove 'mips' word from MipsGotSection fields and methods names. NFCSimon Atanasyan2016-11-171-4/+4
| | | | | | Also add new comments with MIPS GOT description. llvm-svn: 287264
* [ELF][MIPS] Add MipsGotSection to handle MIPS GOTSimon Atanasyan2016-11-161-6/+8
| | | | | | | | | | | | | MIPS GOT handling is very different from other targets so it is better to keep the code in the separatre section class MipsGotSection. This patch introduces the new section and moves all MIPS specific code from GotSection to the new class. I did not rename fields and methods in the MipsGotSection class to reduce the diff and plan to do that by the separate commit. Differential revision: https://reviews.llvm.org/D26733 llvm-svn: 287150
* [ELF] Convert RelocationSection to input sectionEugene Leviant2016-11-161-6/+10
| | | | | | Differential revision: https://reviews.llvm.org/D26669 llvm-svn: 287092
* [ELF] - format. NFC.George Rimar2016-11-141-4/+2
| | | | llvm-svn: 286805
* [ELF] Convert .got section to input sectionEugene Leviant2016-11-111-17/+19
| | | | | | Differential revision: https://reviews.llvm.org/D26498 llvm-svn: 286580
* Remove a member from InputSectionData and use the pool instead.Rui Ueyama2016-11-111-4/+4
| | | | llvm-svn: 286557
* Parse relocations only once.Rafael Espindola2016-11-101-11/+11
| | | | | | | | | | | | | | | | Relocations are the last thing that we wore storing a raw section pointer to and parsing on demand. With this patch we parse it only once and store a pointer to the actual data. The patch also changes where we store it. It is now in InputSectionBase. Not all sections have relocations, but most do and this simplifies the logic. It also means that we now only support one relocation section per section. Given that that constraint is maintained even with -r with gold bfd and lld, I think it is OK. llvm-svn: 286459
* [ELF] Convert .got.plt section to input sectionEugene Leviant2016-11-101-3/+14
| | | | | | Differential revision: https://reviews.llvm.org/D26349 llvm-svn: 286443
* [ELF][MIPS] Convert .MIPS.abiflags section to synthetic input sectionSimon Atanasyan2016-11-091-33/+0
| | | | | | | | | | | | | | Previously, we have both input and output section for .MIPS.abiflags. Now we have only one class for .MIPS.abiflags, which is MipsAbiFlagsSection. This class is a synthetic input section. .MIPS.abiflags sections are handled as regular sections until the control reaches Writer. Writer then aggregates all sections whose type is SHT_MIPS_ABIFLAGS to create a single synthesized input section. The synthesized section is then processed normally as if it came from an input file. llvm-svn: 286398
* [ELF][MIPS] Convert .reginfo and .MIPS.options sections to synthetic input ↵Simon Atanasyan2016-11-091-66/+1
| | | | | | | | | | | | | | | | | | | sections Previously, we have both input and output sections for .reginfo and .MIPS.options. Now for each such sections we have one synthetic input sections: MipsReginfoSection and MipsOptionsSection respectively. Both sections are handled as regular sections until the control reaches Writer. Writer then aggregates all sections whose type is SHT_MIPS_REGINFO or SHT_MIPS_OPTIONS to create a single synthesized input section. In that moment Writer also save GP0 value to the MipsGp0 field of the corresponding ObjectFile. This value required for R_MIPS_GPREL16 and R_MIPS_GPREL32 relocations calculation. Differential revision: https://reviews.llvm.org/D26444 llvm-svn: 286397
* Make Discarded a InputSection.Rafael Espindola2016-11-091-0/+3
| | | | | | | It was quite confusing that it had SectionKind of Regular, but was not actually a InputSection. llvm-svn: 286379
* Add a convenience getObj method. NFC.Rafael Espindola2016-11-091-3/+3
| | | | llvm-svn: 286370
* [ELF] ARM and AArch64 undefined weak reference valuesPeter Smith2016-11-091-0/+46
| | | | | | | | | | | | | The ARM 32 and 64-bit ABI does not use 0 for undefined weak references that are used in PC relative relocations. In particular: - A branch relocation to an undefined weak resolves to the next instruction. Effectively making the branch a no-op - In all other cases the symbol resolves to the place so that S + A - P resolves to A. Differential Revision: https://reviews.llvm.org/D26240 llvm-svn: 286353
* Split Header into individual fields.Rafael Espindola2016-11-091-14/+12
| | | | | | | | | This is similar to what was done for InputSection. With this the various fields are stored in host order and only converted to target order when writing. llvm-svn: 286327
* Revert "[ELF] Make InputSection<ELFT>::writeTo virtual"Rafael Espindola2016-11-081-5/+7
| | | | | | | | This reverts commit r286100. This saves 8 bytes of every InputSection. llvm-svn: 286235
* [ELF] Make InputSection<ELFT>::writeTo virtualEugene Leviant2016-11-071-7/+5
| | | | | | Differential revision: https://reviews.llvm.org/D26281 llvm-svn: 286100
* Rewrite CommonInputSection as a synthetic input section.Rui Ueyama2016-11-051-25/+0
| | | | | | | | | | | | A CommonInputSection is a section containing all common symbols. That was an input section but was abstracted in a different way than the synthetic input sections because it was written before the synthetic input section was invented. This patch rewrites CommonInputSection as a synthetic input section so that it behaves better with other sections. llvm-svn: 286053
* Now that the ELFFile constructor does nothing, create it when needed.Rafael Espindola2016-11-031-1/+1
| | | | | | This avoids duplicating the buffer in InputFile. llvm-svn: 285965
* Update for llvm change.Rafael Espindola2016-11-031-4/+4
| | | | llvm-svn: 285956
* Create SyntheticSections.cpp.Rui Ueyama2016-11-011-91/+0
| | | | | | | | We are going to have many more classes for linker-synthesized input sections, so it's worth to be added to a separate file than to the file for regular input sections. llvm-svn: 285740
* [ELF/GC] Fix pending references to garbage collected sections.Davide Italiano2016-11-011-2/+4
| | | | | | | | | | | | | | | | | | | The example reported in PR30793 shows a case where gc reclaims a SHF_TLS section, but it doesn't reclaim the section containing the debug info for it. This is expected, as we do not reclaim non-alloc sections during the garbage collection phase (and this is not going to change anytime soon, at least this is what I gathered last I talked with Rafael about it). So, we end up with a pending reference, thinking that the input was invalid (which is not true, as it's GC that removed the SHT_TLS section, and therefore didn't create the PT_TLS *segment* for it). In cases like this, just assign a VA of zero at relocation time instead of error'ing out (this is what gold does as well, FWIW). Differential Revision: https://reviews.llvm.org/D26201 llvm-svn: 285735
* Don't store an OutputLoc in every InputSection.Rafael Espindola2016-11-011-13/+15
| | | | | | It was only used by build-id and that can easily compute it. llvm-svn: 285691
* Convert BuildIdSection to input sectionEugene Leviant2016-11-011-0/+89
| | | | | | Differential revision: https://reviews.llvm.org/D25627 llvm-svn: 285682
* Allow fetching source line, when multiple "AX" sections presentEugene Leviant2016-11-011-1/+3
| | | | | | Differential revision: https://reviews.llvm.org/D26070 llvm-svn: 285680
* Don't create a dummy ELF to process a binary file.Rafael Espindola2016-10-271-3/+4
| | | | | | | Now that it is easy to create input section and symbols, this is simple. llvm-svn: 285322
* Pass a InputSectionData to classoff.Rafael Espindola2016-10-261-6/+6
| | | | | | This allows a non template class to hold input sections. llvm-svn: 285221
* Delete trivial getters. NFC.Rafael Espindola2016-10-261-14/+14
| | | | llvm-svn: 285190
* Read section headers upfront.Rafael Espindola2016-10-261-30/+43
| | | | | | | | | | | | | | | | | | Instead of storing a pointer, store the members we need. The reason for doing this is that it makes it far easier to create synthetic sections. It also avoids reading data from files multiple times., which might help with cross endian linking and host architectures with slow unaligned access. There are obvious compacting opportunities, but this already has mixed results even on native x86_64 linking. There is also the possibility of better refactoring the code for handling common symbols, but this already shows that a custom class is not necessary. llvm-svn: 285148
* Be a bit more consistent about using getters. NFC.Rafael Espindola2016-10-251-10/+10
| | | | llvm-svn: 285082
* Delete getSectionHdr.Rafael Espindola2016-10-251-6/+5
| | | | | | | | | | | We were fairly inconsistent as to what information should be accessed with getSectionHdr and what information (like alignment) was stored elsewhere. Now all section info has a dedicated getter. The code is also a bit more compact. llvm-svn: 285079
* [ELF][MIPS] Put local GOT entries accessed via a 16-bit index firstSimon Atanasyan2016-10-211-0/+1
| | | | | | | | | | | | | | | | | | | | | | Some MIPS relocations used to access GOT entries are able to manipulate 16-bit index. The other ones like R_MIPS_CALL_HI16/LO16 can handle 32-bit indexes. 16-bit relocations are generated by default. The 32-bit relocations are generated by -mxgot flag passed to compiler. Usually these relocation are not mixed in the same code but files like crt*.o contain 16-bit relocations so even if all "user's" code compiled with -mxgot flag a few 16-bit relocations might come to the linking phase. Now LLD does not differentiate local GOT entries accessed via a 16-bit and 32-bit indexes. That might lead to relocation's overflow if 16-bit entries are allocated to far from the beginning of the GOT. The patch introduces new "part" of MIPS GOT dedicated to the local GOT entries accessed by 32-bit relocations. That allows to put local GOT entries accessed via a 16-bit index first and escape relocation's overflow. Differential revision: https://reviews.llvm.org/D25833 llvm-svn: 284809
* Compact SectionPiece.Rafael Espindola2016-10-201-11/+22
| | | | | | | We allocate a lot of these when linking debug info. This speeds up the link of debug programs by 1% to 2%. llvm-svn: 284716
* [ELF] Allow relative exceptions relocations in shared librariesPeter Smith2016-10-201-0/+1
| | | | | | | | | | | | | The R_ARM_PREL31 and R_ARM_NONE relocations should not be faulted in shared libraries. In the case of R_ARM_NONE, we have moved the TLS relaxation hint instruction to R_TLSDESC_CALL so that R_HINT can be used without side-effects. In the case of R_ARM_PREL31 we permit it to be used against PLT entries as the personality routines are imported when used in shared libraries. Differential Revision: https://reviews.llvm.org/D25721 llvm-svn: 284710
* [ELF] - Applied clang format. NFC.George Rimar2016-10-201-9/+6
| | | | llvm-svn: 284705
* Don't call markLiveAt for non alloc sections.Rafael Espindola2016-10-191-1/+2
| | | | | | We don't gc them anyway, so just use an early return in Enqueue. llvm-svn: 284663
OpenPOWER on IntegriCloud