summaryrefslogtreecommitdiffstats
path: root/lld/ELF/MarkLive.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Unpollute the global namespace. lld edition.Benjamin Kramer2016-08-061-0/+2
| | | | llvm-svn: 277926
* Fix PR28575.Rafael Espindola2016-07-211-9/+61
| | | | | | | | | | Not all relocations from a .eh_frame that point to an executable section should be ignored. In particular, the relocation finding the personality function should not. This is a reduction from trying to bootstrap a static lld on linux. llvm-svn: 276329
* Pass section by reference. NFC.Rafael Espindola2016-07-181-11/+11
| | | | llvm-svn: 275803
* Remove duplicate declaration.Rui Ueyama2016-07-021-0/+1
| | | | llvm-svn: 274429
* Rename EHInputSection -> EhInputSection.Rui Ueyama2016-05-241-2/+2
| | | | llvm-svn: 270532
* Do not split mergeable sections if they are gc'ed.Rui Ueyama2016-05-231-4/+7
| | | | | | | | | | | | | | | | | | | | | Previously, mergeable section's constructors did more than just setting member variables; it split section contents into small pieces. It is not always computationally cheap task because if the section is a mergeable string section, it needs to scan the entire section to split them by NUL characters. If a section would be thrown away by GC, that cost ended up being a waste of time. It is going to be larger problem if the section is compressed -- the whole time to uncompress it and split it up is going to be a waste. Luckily, we can defer section splitting after GC. We just have to remember which offsets are in use during GC and apply that later. This patch implements it. Differential Revision: http://reviews.llvm.org/D20516 llvm-svn: 270455
* Simplify SplitInputSection::getRangeAndSize.Rui Ueyama2016-05-221-3/+2
| | | | | | | | 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-3/+2
| | | | | | | | | | | | | 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
* Fix --gc-sections when .eh_frame has a lsda.Rafael Espindola2016-05-051-3/+5
| | | | | | We have to add sections to the work list, not just mark them live. llvm-svn: 268628
* ELF: Do not use -1 to mark pieces of merge sections as being tail merged.Peter Collingbourne2016-05-051-1/+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
* Do not pass Symtab to markLive/doICF since Symtab is globally accessible.Rui Ueyama2016-05-021-10/+11
| | | | llvm-svn: 268286
* [ELF] - keep alive all non-text sections referenced by .eh_frameGeorge Rimar2016-05-021-15/+36
| | | | | | | | | | | | | | | Patch implements one of suggestions from Rafael Ávila de Espíndola, to fix segfault after section that contains personality being garbage collected. Suggestion was just to keep alive all non executable sections referenced by .eh_frame. This fixes PR27529. Differential revision: http://reviews.llvm.org/D19656 llvm-svn: 268228
* ELF: New symbol table design.Peter Collingbourne2016-05-011-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements a new design for the symbol table that stores SymbolBodies within a memory region of the Symbol object. Symbols are mutated by constructing SymbolBodies in place over existing SymbolBodies, rather than by mutating pointers. As mentioned in the initial proposal [1], this memory layout helps reduce the cache miss rate by improving memory locality. Performance numbers: old(s) new(s) Without debug info: chrome 7.178 6.432 (-11.5%) LLVMgold.so 0.505 0.502 (-0.5%) clang 0.954 0.827 (-15.4%) llvm-as 0.052 0.045 (-15.5%) With debug info: scylla 5.695 5.613 (-1.5%) clang 14.396 14.143 (-1.8%) Performance counter results show that the fewer required indirections is indeed the cause of the improved performance. For example, when linking chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and instructions per cycle increases from 0.78 to 0.83. We are also executing many fewer instructions (15,516,401,933 down to 15,002,434,310), probably because we spend less time allocating SymbolBodies. The new mechanism by which symbols are added to the symbol table is by calling add* functions on the SymbolTable. In this patch, I handle local symbols by storing them inside "unparented" SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating these SymbolBodies, we can probably do that separately. I also removed a few members from the SymbolBody class that were only being used to pass information from the input file to the symbol table. This patch implements the new design for the ELF linker only. I intend to prepare a similar patch for the COFF linker. [1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html Differential Revision: http://reviews.llvm.org/D19752 llvm-svn: 268178
* ELF: Move code to where it is used, and related cleanups. NFC.Peter Collingbourne2016-04-261-24/+49
| | | | | | Differential Revision: http://reviews.llvm.org/D19490 llvm-svn: 267637
* Don't gc symbols that have to go in the dynamic symbol table.Rafael Espindola2016-04-261-4/+3
| | | | | | | | | We were only doing it for .so and --export-dynamic, but those are not the only ways a symbol ends up in the dynamic symbol table. Problem diagnostic and earlier patch version by Peter Collingbourne. llvm-svn: 267568
* Bring r267164 back with a fix.Rafael Espindola2016-04-221-10/+27
| | | | | | | | | | | | | | | | | 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-27/+10
| | | | | | | | | | | | This reverts commit r267164. Revert "Trying to fix the windows build." This reverts commit r267168. Debugging a bootstrap problem. llvm-svn: 267194
* ELF: Move Visibility, IsUsedInRegularObj and MustBeInDynSym flags to Symbol.Peter Collingbourne2016-04-221-7/+4
| | | | | | | | | | | | | | These are properties of a symbol name, rather than a particular instance of a symbol in an object file. We can simplify the code by collecting these properties in Symbol. The MustBeInDynSym flag has been renamed ExportDynamic, as its semantics have been changed to be the same as those of --dynamic-list and --export-dynamic-symbol, which do not cause hidden symbols to be exported. Differential Revision: http://reviews.llvm.org/D19400 llvm-svn: 267183
* GC entries of SHF_MERGE sections.Rafael Espindola2016-04-221-10/+27
| | | | | | | | | | | 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-4/+3
| | | | | | | | | | | | | | | | 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
* Try to fix Windows lld build.Nico Weber2016-04-221-1/+1
| | | | | | | | | | | | | | | | llvm\tools\lld\ELF\MarkLive.cpp(49): error C2872: 'ObjectFile': ambiguous symbol llvm\tools\lld\elf\InputFiles.h(100): note: could be 'lld::elf::ObjectFile' llvm\include\llvm/Object/IRObjectFile.h(26): note: or 'llvm::object::ObjectFile' llvm\tools\lld\ELF\MarkLive.cpp(133): note: see reference to function template instantiation 'void forEachSuccessor<ELFT>(lld::elf::InputSection<ELFT> *, std::function<void (lld::elf::InputSectionBase<ELFT> *)>)' being compiled with [ ELFT=llvm::object::ELF32LE ] llvm\tools\lld\ELF\MarkLive.cpp(136): note: see reference to function template instantiation 'void lld::elf::markLive<llvm::object::ELF32LE>(lld::elf::SymbolTable<llvm::object::ELF32LE> *) being compiled llvm-svn: 267161
* Move getRelocTarget to ObjectFile.Rafael Espindola2016-04-221-3/+4
| | | | | | It doesn't use anything from the InputSection. llvm-svn: 267154
* Simplify. NFC.Rafael Espindola2016-04-221-4/+2
| | | | llvm-svn: 267147
* Don't gc protected symbols.Rafael Espindola2016-04-211-1/+1
| | | | llvm-svn: 267081
* ELF: Template LinkerScript class.Rui Ueyama2016-04-201-1/+1
| | | | | | | | | | | | | | | | | | | | | Originally, linker scripts were basically an alternative way to specify options to the command line options. But as we add more features to hanlde symbols and sections, many member functions needed to be templated. Now most the members are templated. It is probably time to template the entire class. Previously, LinkerScript is an executor of the linker script as well as a storage of linker script configurations. This is not suitable to template the class because when we are reading linker script files, we don't know the ELF type yet, so we can't instantiate ELF-templated classes. In this patch, I defined a new class, ScriptConfiguration, to store linker script configurations. ScriptParser writes parse results to it, and LinkerScript uses them. Differential Revision: http://reviews.llvm.org/D19302 llvm-svn: 266908
* Store a Symbol for EntrySym.Rafael Espindola2016-04-151-2/+3
| | | | | | This makes it impossible to forget to call repl on the SymbolBody. llvm-svn: 266432
* Specialize the symbol table data structure a bit.Rafael Espindola2016-04-141-2/+2
| | | | | | | | | We never need to iterate over the K,V pairs, so we can avoid copying the key as MapVector does. This is a small speedup on most benchmarks. llvm-svn: 266364
* Hash symbol names only once per global SymbolBody.Rafael Espindola2016-04-141-1/+1
| | | | | | | | | | | The DenseMap doesn't store hash results. This means that when it is resized it has to recompute them. This patch is a small hack that wraps the StringRef in a struct that remembers the hash value. That way we can be sure it is only hashed once. llvm-svn: 266357
* Don't store an Elf_Sym for most symbols.Rafael Espindola2016-04-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Use ELFT instead of ELFFile<ELFT>.Rui Ueyama2016-03-141-3/+3
| | | | llvm-svn: 263510
* Create a SymbolBody for locals.Rafael Espindola2016-03-111-1/+1
| | | | | | pr26878 shows a case where locals have to be in the got. llvm-svn: 263222
* Rename elf2 to elf.Rafael Espindola2016-02-281-6/+6
| | | | llvm-svn: 262159
* [ELF] - Referencing __start or __stop should keep the section from GC.George Rimar2016-02-251-0/+6
| | | | | | | | | | | | 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
* ELF: Do not instantiate InputSectionBase::Discarded.Rui Ueyama2016-02-241-1/+1
| | | | | | | | | | | | | "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] - Linkerscript KEEP command.George Rimar2016-02-231-3/+6
| | | | | | | | | | | When link-time garbage collection is in use (-gc-sections), it is often useful to mark sections that should not be eliminated. This is accomplished by surrounding an input section's wildcard entry with KEEP(). Patch implements that command. Differential revision: http://reviews.llvm.org/D17242 llvm-svn: 261616
* Merge two consecutive if's. NFC.Rui Ueyama2016-01-121-3/+2
| | | | llvm-svn: 257527
* Remove unnecessary `lld::`.Rui Ueyama2016-01-061-5/+5
| | | | llvm-svn: 256970
* Update comments.Rui Ueyama2016-01-051-3/+3
| | | | llvm-svn: 256845
* Delete DefinedAbsolute.Rafael Espindola2015-12-241-1/+1
| | | | | | | | | | | | | | | | | | | | There are 3 symbol types that a .bc can provide during lto: defined, undefined, common. Defined and undefined symbols have already been refactored. I was working on common and noticed that absolute symbols would become an oddity: They would be the only symbol type present in a .o but not in a.bc. Looking a bit more, other than the special section number they were only used for special rules for computing values. In that way they are similar to TLS, and we don't have a DefinedTLS. This patch deletes it. With it we have a reasonable rule of the thumb for having a symbol kind: It exists if it has special resolution semantics. llvm-svn: 256383
* Remove `continue` to make the code a bit shorter. NFC.Rui Ueyama2015-12-241-8/+5
| | | | llvm-svn: 256379
* Mark .eh_frame sections as live by default. NFC.Rui Ueyama2015-12-241-4/+0
| | | | | | | This change eliminates a string comparison from the garbage collector. llvm-svn: 256378
* [ELF] Don't reclaim .ctors/.dtors sections.Davide Italiano2015-12-241-1/+2
| | | | | | | | | | | | | | | | | | In FreeBSD, rtld expects .ctors containing -1 (0xffffffff), and a .ctors section containing the correct bits is provided to the linker as input (/usr/lib/crtbegin.o). Contents of section .ctors: 0000 ffffffff ffffffff ........ This section is not stripped even if not referenced or empty, also in gold or ld.bfd. It would be nice to strip it when not needed but since existing object files rely on that we can't do better to keep it around. Differential Revision: http://reviews.llvm.org/D15767 llvm-svn: 256373
* Add a comment.Rui Ueyama2015-12-241-0/+3
| | | | llvm-svn: 256372
* Early continue. NFC.Rui Ueyama2015-11-121-8/+8
| | | | llvm-svn: 252935
* ELF2: Make type a bit stricter. NFC.Rui Ueyama2015-11-121-4/+4
| | | | llvm-svn: 252934
* Start treating .eh_frame specially.Rafael Espindola2015-11-091-4/+11
| | | | | | | For now, just don't follow edges leaving from it to mark other sections live. llvm-svn: 252493
* ELF2: Move some code from MarkLive.cpp to InputSection.cpp.Rui Ueyama2015-10-271-28/+13
| | | | | | This function is useful for ICF, so move that to a common place. llvm-svn: 251455
* ELF2: SymbolBody::repl() never returns a nullptr.Rui Ueyama2015-10-221-1/+1
| | | | | | So we can use dyn_cast instead of dyn_cast_or_null here. llvm-svn: 251076
* ELF2: Keep .eh_frame even if they are not live.Rui Ueyama2015-10-221-1/+2
| | | | | | | | | .eh_frame sections need to be preserved if they refer to live sections. So the liveness relation is reverse for eh_frame sections. For now, we simply preserve all .eh_frame sections. Thanks Rafael for pointing this out. .jcr are kept for the same reason. llvm-svn: 251068
* ELF2: Implement --gc-sections.Rui Ueyama2015-10-221-0/+141
Section garbage collection is a feature to remove unused sections from outputs. Unused sections are sections that cannot be reachable from known GC-root symbols or sections. Naturally the feature is implemented as a mark-sweep garbage collector. In this patch, I added Live bit to InputSectionBase. If and only if Live bit is on, the section will be written to the output. Starting from GC-root symbols or sections, a new function, markLive(), visits all reachable sections and sets their Live bits. Writer then ignores sections whose Live bit is off, so that such sections are excluded from the output. This change has small negative impact on performance if you use the feature because making sections means more work. The time to link Clang changes from 0.356s to 0.386s, or +8%. It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes. That is 4.3% reduction. http://reviews.llvm.org/D13950 llvm-svn: 251043
OpenPOWER on IntegriCloud