summaryrefslogtreecommitdiffstats
path: root/lld/ELF/InputSection.h
Commit message (Collapse)AuthorAgeFilesLines
...
* Simplify SplitInputSection::getRangeAndSize.Rui Ueyama2016-05-221-2/+4
| | | | | | | | 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
* Define SectionPiece and use it instead of std::pair<uint_t, uint_t>.Rui Ueyama2016-05-221-18/+13
| | | | | | | | | | | | | 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
* Refactor R_RELAX_TLS_* value computation.Rafael Espindola2016-05-201-1/+0
| | | | | | | | | | | | This makes it explicit that each R_RELAX_TLS_* is equivalent to some other expression. With this I think we are at a sweet spot for how much is done in Target.cpp. I did experiment with moving *all* the value math out of it. It has the advantage that we know the final value in target independent code, but it gets quite verbose. llvm-svn: 270277
* [ELF][MIPS] Rename R_MIPS_GOT_xxx relocation expression kindsSimon Atanasyan2016-05-151-3/+3
| | | | | | | | | New names reflect purpose of corresponding GOT entries better. Both expression types related to entries allocated in the 'local' part of MIPS GOT. R_MIPS_GOT_LOCAL_PAGE is for entries contain 'page' addresses. R_MIPS_GOT_LOCAL is for entries contain 'full' address. llvm-svn: 269597
* Cache result when tail merging too.Rafael Espindola2016-05-051-5/+4
| | | | | | | This speeds up a link of chromium with -O2 (but no icf,gc) from 1.940664632 to 1.925578119. llvm-svn: 268639
* ELF: Do not use -1 to mark pieces of merge sections as being tail merged.Peter Collingbourne2016-05-051-1/+14
| | | | | | | | | | | | | | | | | 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
* Simplify handling of hint relocations.Rafael Espindola2016-05-041-0/+1
| | | | llvm-svn: 268501
* Sort entries. NFC.Rafael Espindola2016-05-041-1/+1
| | | | llvm-svn: 268499
* [ELF][MIPS] Read/write .MIPS.options sectionSimon Atanasyan2016-05-041-2/+13
| | | | | | | | | 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
* Don't create dynamic relocations to ro segments.Rafael Espindola2016-04-301-1/+2
| | | | | | | | | | | | | These would just crash at runtime. If we ever decide to support rw text segments this should make it easier to implement as there is now a single point where we notice the problem. I have tested this with a freebsd buildworld. It found a non pic assembly file being linked into a .so,. With that fixed, buildworld finished. llvm-svn: 268149
* Skip scanRelocs for non-alloc sections.Rui Ueyama2016-04-281-0/+3
| | | | | | | | | | | | | | | | | | | | | | | Relocations against sections with no SHF_ALLOC bit are R_ABS relocations. Currently we are creating Relocations vector for them, but that is wasteful. This patch is to skip vector construction and to directly apply relocations in place. This patch seems to be pretty effective for large executables with debug info. r266158 (Rafael's patch to change the way how we apply relocations) caused a temporary performance degradation for such executables, but this patch makes it even faster than before. Time to link clang with debug info (output size is 1070 MB): before r266158: 15.312 seconds (0%) r266158: 17.301 seconds (+13.0%) Head: 16.484 seconds (+7.7%) w/patch: 13.166 seconds (-14.0%) Differential Revision: http://reviews.llvm.org/D19645 llvm-svn: 267917
* ELF: Move code to where it is used, and related cleanups. NFC.Peter Collingbourne2016-04-261-6/+0
| | | | | | Differential Revision: http://reviews.llvm.org/D19490 llvm-svn: 267637
* Bring r267164 back with a fix.Rafael Espindola2016-04-221-2/+4
| | | | | | | | | | | | | | | | | The fix is to handle local symbols referring to SHF_MERGE sections. Original message: GC entries of SHF_MERGE sections. It is a fairly direct extension of the gc algorithm. For merge sections instead of remembering just a live bit, we remember which offsets were used. This reduces the .rodata sections in chromium from 9648861 to 9477472 bytes. llvm-svn: 267233
* Revert "GC entries of SHF_MERGE sections."Rafael Espindola2016-04-221-4/+2
| | | | | | | | | | | | This reverts commit r267164. Revert "Trying to fix the windows build." This reverts commit r267168. Debugging a bootstrap problem. llvm-svn: 267194
* GC entries of SHF_MERGE sections.Rafael Espindola2016-04-221-2/+4
| | | | | | | | | | | It is a fairly direct extension of the gc algorithm. For merge sections instead of remembering just a live bit, we remember which offsets were used. This reduces the .rodata sections in chromium from 9648861 to 9477472 bytes. llvm-svn: 267164
* This reverts commit r267154 and r267161.Rafael Espindola2016-04-221-0/+6
| | | | | | | | | | | | | | | | It turns out that this will read data from the section to properly handle Elf_Rel implicit addends. Sorry for the noise. Original messages: Try to fix Windows lld build. Move getRelocTarget to ObjectFile. It doesn't use anything from the InputSection. llvm-svn: 267163
* Move getRelocTarget to ObjectFile.Rafael Espindola2016-04-221-6/+0
| | | | | | It doesn't use anything from the InputSection. llvm-svn: 267154
* Delete refersToGotEntry.Rafael Espindola2016-04-201-0/+6
| | | | | | It can be computed from the expression. llvm-svn: 266890
* Simplify mips gp0 handling.Rafael Espindola2016-04-201-1/+0
| | | | | | In all currently supported cases this is a nop. llvm-svn: 266888
* Simplify mips got handling.Rafael Espindola2016-04-191-0/+1
| | | | | | | This avoids computing the address of a position in the got just to then subtract got->getva(). llvm-svn: 266831
* Have getRelExpr handle all cases on x86.Rafael Espindola2016-04-181-0/+5
| | | | | | | | This requires adding a few more expression types, but is already a small simplification. Having Writer.cpp know the exact expression will also allow further simplifications. llvm-svn: 266604
* Store a Symbol for EntrySym.Rafael Espindola2016-04-151-0/+2
| | | | | | This makes it impossible to forget to call repl on the SymbolBody. llvm-svn: 266432
* Change how we apply relocations.Rafael Espindola2016-04-131-7/+38
| | | | | | | | | | | | | | | | | | | | | | | 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
* Update for llvm change.Rafael Espindola2016-04-051-3/+2
| | | | llvm-svn: 265404
* Don't store an Elf_Sym for most symbols.Rafael Espindola2016-04-041-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Our symbol representation was redundant, and some times would get out of sync. It had an Elf_Sym, but some fields were copied to SymbolBody. Different parts of the code were checking the bits in SymbolBody and others were checking Elf_Sym. There are two general approaches to fix this: * Copy the required information and don't store and Elf_Sym. * Don't copy the information and always use the Elf_Smy. The second way sounds tempting, but has a big problem: we would have to template SymbolBody. I started doing it, but it requires templeting *everything* and creates a bit chicken and egg problem at the driver where we have to find ELFT before we can create an ArchiveFile for example. As much as possible I compared the test differences with what gold and bfd produce to make sure they are still valid. In most cases we are just adding hidden visibility to a local symbol, which is harmless. In most tests this is a small speedup. The only slowdown was scylla (1.006X). The largest speedup was clang with no --build-id, -O3 or --gc-sections (i.e.: focus on the relocations): 1.019X. llvm-svn: 265293
* [ELF] Implement infrastructure for thunk code creationSimon Atanasyan2016-03-311-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Simplify AHL handling.Rafael Espindola2016-03-291-2/+2
| | | | | | | | | | | | This simplifies a few things * Read the value as early as possible, instead of passing a pointer to the location. * Print the warning for missing pair close to where we find out it is missing. * Don't pass the value to relocateOne. llvm-svn: 264802
* Revert "bar"Rafael Espindola2016-03-181-8/+3
| | | | | | | This reverts commit r263799. It was a mistake. Sorry about that. llvm-svn: 263801
* barRafael Espindola2016-03-181-3/+8
| | | | llvm-svn: 263799
* Use ELFT instead of ELFFile<ELFT>.Rui Ueyama2016-03-141-18/+18
| | | | llvm-svn: 263510
* Use RelTy instead of Elf_Rel_Impl<ELFT, isRela> for readability.Rui Ueyama2016-03-131-17/+8
| | | | llvm-svn: 263368
* Simplify findMipsPairedReloc function signature. NFC.Rui Ueyama2016-03-131-2/+4
| | | | llvm-svn: 263356
* [ELF][MIPS] Put type of symbol (local/global) to the findMipsPairedReloc and ↵Simon Atanasyan2016-03-121-2/+2
| | | | | | call it from the single place. NFC. llvm-svn: 263339
* Rename elf2 to elf.Rafael Espindola2016-02-281-2/+2
| | | | llvm-svn: 262159
* Remove default values which are always overwritten.Rui Ueyama2016-02-251-2/+2
| | | | llvm-svn: 261913
* ELF: Implement ICF.Rui Ueyama2016-02-251-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements the same algorithm as LLD/COFF's ICF. I'm not going to repeat the same description about how it works, so you want to read the comment in ICF.cpp in this patch if you want to know the details. This algorithm should be more powerful than the ICF algorithm implemented in GNU gold. It can even merge mutually-recursive functions (which is harder than one might think). ICF is a fairly effective size optimization. Here are some examples. LLD: 37.14 MB -> 35.80 MB (-3.6%) Clang: 59.41 MB -> 57.80 MB (-2.7%) The lacking feature is "safe" version of ICF. This merges all identical sections. That is not compatible with a C/C++ language requirement that two distinct functions must have distinct addresses. But as long as your program do not rely on the pointer equality (which is in many cases true), your program should work with the feature. LLD works fine for example. GNU gold implements so-called "safe ICF" that identifies functions that are safe to merge by heuristics -- for example, gold thinks that constructors are safe to merge because there is no way to take an address of a constructor in C++. We have a different idea which David Majnemer suggested that we add NOPs at beginning of merged functions so that two or more pointers can have distinct values. We can do whichever we want, but this patch does not include neither. http://reviews.llvm.org/D17529 llvm-svn: 261912
* [ELF2] - Basic implementation of -r/--relocatableGeorge Rimar2016-02-251-0/+10
| | | | | | | | | | | | | -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
* ELF: Do not instantiate InputSectionBase::Discarded.Rui Ueyama2016-02-241-4/+3
| | | | | | | | | | | | | "Discarded" section is a marker for discarded sections, and we do not use the instance except for checking its identity. In that sense, it is just another type of a "null" pointer for InputSectionBase. So, it doesn't have to be a real instance of InputSectionBase class. In this patch, we no longer instantiate Discarded section but instead use -1 as a pointer value. This eliminates a global variable which needed initialization at startup. llvm-svn: 261761
* ELF: Remove InputSectionBase::getAlign and instead add Align member.Rui Ueyama2016-02-241-8/+1
| | | | | | | | | This is a preparation for ICF. If we merge two sections, we want to align the merged section at the largest alignment requirement. That means we want to update the alignment value, which was impossible before this patch because Header is a const value. llvm-svn: 261712
* ELF: Remove InputSectionBase::isLive and use Live member instead. NFC.Rui Ueyama2016-02-241-2/+0
| | | | | | This is also a preparation for ICF. llvm-svn: 261711
* ELF: Make some functions constant. NFC.Rui Ueyama2016-02-241-2/+2
| | | | | | This is a preparation for ICF. llvm-svn: 261710
* Use TinyPtrVector<Ty *> instead of SmallVector<Ty *, 1>.Rui Ueyama2016-02-231-1/+2
| | | | | | Thanks to Sean Silva for the suggestion. llvm-svn: 261606
* Simplify MipsReginfoInputSection.Rui Ueyama2016-01-061-6/+3
| | | | | | | MipsReginfoInputSection is basically just a container of Elf_Mips_Reginfo struct. This patch makes that struct directly accessible from others. llvm-svn: 256984
* Add comments.Rui Ueyama2016-01-061-0/+8
| | | | llvm-svn: 256905
* [ELF][MIPS] Implement R_MIPS_GPREL16/R_MIPS_GPREL32 relocationsSimon Atanasyan2015-12-251-0/+1
| | | | | | | | | | | | | | | | | | | | The R_MIPS_GPREL16 / R_MIPS_GPREL32 relocations use the following expressions for calculations: ``` local symbol: S + A + GP0 - GP global symbol: S + A - GP GP - Represents the final gp value, i.e. _gp symbol GP0 - Represents the gp value used to create the relocatable object ``` The GP0 value is taken from the .reginfo data section defined by an object file. To implement that I keep a reference to `MipsReginfoInputSection` in the `ObjectFile` class. This reference is used by the `ObjectFile::getMipsGp0` method to return the GP0 value. Differential Revision: http://reviews.llvm.org/D15760 llvm-svn: 256416
* [ELF][MIPS] MIPS .reginfo sections handlingSimon Atanasyan2015-12-201-1/+20
| | | | | | | | | | | | | | | | | | | | | 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][MIPS] Match paired relocation using relocation type and symbol indexSimon Atanasyan2015-12-131-1/+1
| | | | | | | If we have R_MIPS_HI16 relocation, the paired relocation is the next R_MIPS_LO16 relocation with the same symbol as a target. llvm-svn: 255452
* [ELF] MIPS paired R_MIPS_HI16/LO16 relocations supportSimon Atanasyan2015-12-011-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Some MIPS relocations including `R_MIPS_HI16/R_MIPS_LO16` use combined addends. Such addend is calculated using addends of both paired relocations. Each `R_MIPS_HI16` relocation is paired with the next `R_MIPS_LO16` relocation. ABI requires to compute such combined addend in case of REL relocation record format only. For details see p. 4-17 at ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf This patch implements lookup of the next paired relocation suing new `InputSectionBase::findPairedRelocLocation` method. The primary disadvantage of this approach is that we put MIPS specific logic into the common code. The next disadvantage is that we lookup `R_MIPS_LO16` for each `R_MIPS_HI16` relocation, while in fact multiple `R_MIPS_HI16` might be paired with the single `R_MIPS_LO16`. From the other side this way allows us to keep `MipsTargetInfo` class stateless and implement later relocation handling in parallel. This patch does not support `R_MIPS_HI16/R_MIPS_LO16` relocations against `_gp_disp` symbol. In that case the relocations use a special formula for the calculation. That will be implemented later. Differential Revision: http://reviews.llvm.org/D15112 llvm-svn: 254461
* Add support for processing .eh_frame.Rafael Espindola2015-11-111-6/+31
| | | | | | | | | | | | | 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
* Add a helper for getting the output offset of an input offset.Rafael Espindola2015-11-111-0/+5
| | | | | | This will get a non st_value use shortly. llvm-svn: 252753
OpenPOWER on IntegriCloud