summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Symbols.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] - Do not crash if symbol type set to TLS when there is no tls sections.George Rimar2016-10-041-1/+5
| | | | | | | | | | | | id_000021,sig_11,src_000002,op_flip1,pos_92 from PR30540 does not have TLS sections, but type of one of the symbol is broken and set to STT_TLS, what resulted in a crash. Patch fixes crash. DIfferential revision: https://reviews.llvm.org/D25083 llvm-svn: 283198
* [ELF][MIPS] Setup STO_MIPS_PIC flag for PIC symbols when generate a ↵Simon Atanasyan2016-09-291-0/+12
| | | | | | | | | | relocatable object In case of linking PIC and non-PIC code together and generation of a relocatable object, all PIC symbols should have STO_MIPS_PIC flag in the symbol table of the ouput file. llvm-svn: 282714
* [ELF] Do not adjust TLS symbol value when produce relocatable objectSimon Atanasyan2016-09-141-1/+1
| | | | | | | When the linker generates a relocatable object there is no TLS program header and we should not adjust TLS symbols value. llvm-svn: 281494
* Simplify InputFile ownership management.Rui Ueyama2016-09-141-5/+5
| | | | | | | | | | | | | | | | | | | | Previously, all input files were owned by the symbol table. Files were created at various places, such as the Driver, the lazy symbols, or the bitcode compiler, and the ownership of new files was transferred to the symbol table using std::unique_ptr. All input files were then free'd when the symbol table is freed which is on program exit. I think we don't have to transfer ownership just to free all instance at once on exit. In this patch, all instances are automatically collected to a vector and freed on exit. In this way, we no longer have to use std::unique_ptr. Differential Revision: https://reviews.llvm.org/D24493 llvm-svn: 281425
* Delete unnecessary template.Rafael Espindola2016-08-311-11/+4
| | | | llvm-svn: 280237
* Delete DefinedBitcode.Rafael Espindola2016-08-311-12/+0
| | | | | | | Given that we almost always want to handle it as DefinedRegular, just use DefinedRegular. llvm-svn: 280226
* [ELF] Symbol assignment within output section descriptionEugene Leviant2016-08-111-1/+1
| | | | llvm-svn: 278322
* Remove DefinedCommon::Section.Rui Ueyama2016-08-021-4/+4
| | | | | | | Since CommonInputSection is a singleton class, we don't need to store pointers to all DefinedCommon symbols. llvm-svn: 277410
* [ELF] Allows setting section for common symbols in linker scriptEugene Leviant2016-07-281-5/+14
| | | | llvm-svn: 277023
* Simplify symbol version handling.Rui Ueyama2016-07-211-5/+0
| | | | | | | | | r275711 for "speedng up symbol version handling" was committed by misunderstanding; the benchmark number was measured with a debug build. The number with a release build didn't actually change. This patch removes false optimizations added in that patch. llvm-svn: 276267
* Remove SymbolBody::PlaceholderKind.Rui Ueyama2016-07-181-1/+0
| | | | | | | | | | | | | In the last patch for --trace-symbol, I introduced a new symbol type PlaceholderKind and store it to SymVector storage. It made all code that iterates over SymVector to recognize and skip PlaceholderKind symbols. I found that that's annoying. In this patch, I removed PlaceholderKind and stop storing them to SymVector. Now the information whether a symbol is being watched by --trace-symbol is stored to the Symtab hash table. llvm-svn: 275747
* Implement almost-zero-cost --trace-symbol.Rui Ueyama2016-07-171-0/+16
| | | | | | | | | | | | | | | | | | | | --trace-symbol is a command line option to watch a symbol. Previosly, we looked up a hash table for a new symbol if the option is given. Any code that looks up a hash table for each symbol is expensive because the linker handles a lot of symbols. In our design, we look up a hash table strictly only once for a symbol, so --trace-symbol was an exception. This patch improves efficiency of the option by merging the hash table into the symbol table. Instead of looking up a separate hash table with a string, this patch sets `Traced` flag to symbols specified by --trace-symbol. So, if you insert a symbol and get a symbol with `Traced` flag on, you know that you need to print out a log message for the symbol. This is nearly zero cost. llvm-svn: 275716
* Print out file names for common symbols for --trace-symbol.Rui Ueyama2016-07-171-2/+4
| | | | | | | Previously, there was no way to get a file name for a DefinedCommon symbol. This patch adds it. llvm-svn: 275712
* Handle versioned symbols efficiently.Rui Ueyama2016-07-171-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Versions can be assigned to symbols in two different ways. One is the usual version scripts, and the other is special symbol suffix '@'. If a symbol contains '@', the string after that is considered to specify a version name. Previously, we look for '@' for all symbols. Anything that works on every symbol can be expensive because the linker has to handle a lot of symbols. The search for '@' was not an exception. In this patch, I made two optimizations. The first optimization is to handle '@' only when at least one version is defined. If no versions are defined, no versions can be assigned to any symbols, so it's waste of time to search for '@'. The second optimization is to scan only suffixes of symbol names instead of entire symbol names. Symbol names can be very long, but symbol versions are usually short, so scanning entire symbol names is waste of time, too. There are some error cases which we no longer be able to detect with this patch. I don't think it's a major drawback because they are minor errors. Speed is more important. This change improves LLD with debug info self-link time from 6.6993 seconds to 6.3426 seconds (or -5.3%). Differential Revision: https://reviews.llvm.org/D22433 llvm-svn: 275711
* Add a pointer to a source file to SymbolBody.Rui Ueyama2016-07-171-30/+32
| | | | | | | | | | | | Previously, each subclass of SymbolBody had a pointer to a source file from which it was created. So, there was no single way to get a source file for a symbol. We had getSourceFile<ELFT>(), but the function was a bit inconvenient as it's a template. This patch makes SymbolBody have a pointer to a source file. If a symbol is not created from a file, the pointer has a nullptr. llvm-svn: 275701
* Add GotEntrySize/GotPltEntrySize to ELF target.Rui Ueyama2016-07-131-2/+2
| | | | | | | | | | | | | Patch by H.J Lu. For x86-64 psABI, the entry size of .got and .got.plt sections is 8 bytes for both LP64 and ILP32. Add GotEntrySize and GotPltEntrySize to ELF target instead of using size of ELFT::uint. Now we can generate a simple working x32 executable. Differential Revision: http://reviews.llvm.org/D22288 llvm-svn: 275301
* Recommit R274836 Add Thunk support framework for ARM and MipsPeter Smith2016-07-081-9/+22
| | | | | | | | | | | The TinyPtrVector of const Thunk<ELFT>* in InputSections.h can cause build failures on certain compiler/library combinations when Thunk<ELFT> is not a complete type or is an abstract class. Fixed by making Thunk<ELFT> non Abstract. type or is an abstract class llvm-svn: 274863
* Revert R274836 Add Thunk support framework for ARM and MipsPeter Smith2016-07-081-22/+9
| | | | | | | This seems to be causing a buildbot failure on lld-x86_64-freebsd. Will reproduce locally and fix. llvm-svn: 274841
* Add Thunk support framework for ARM and MipsPeter Smith2016-07-081-9/+22
| | | | | | | | | | | | | | | | | | | | | | | Generalise the Mips LA25 Thunk code and implement ARM and Thumb interworking Thunks. - Introduce a new module Thunks.cpp to store the Target Specific Thunk implementations. - DefinedRegular and Shared have a ThunkData field to record Thunk. - A Target can have more than one type of Thunk. - Support PC-relative calls to Thunks. - Support Thunks to PLT entries. - Existing Mips LA25 Thunk code integrated. - Support for ARMv7A interworking Thunks. Limitations: - Only one Thunk per SymbolBody, this is sufficient for all currently implemented Thunks. - ARM thunks assume presence of V6T2 MOVT and MOVW instructions. Differential revision: http://reviews.llvm.org/D21891 llvm-svn: 274836
* Move demangle() from Symbols.cpp to Strings.cpp.Rui Ueyama2016-07-071-31/+0
| | | | | | | | | | | | Symbols.cpp contains functions to handle ELF symbols. demangle() function is essentially a function to work on a string rather than on an ELF symbol. So Strings.cpp is a better place to put that function. This change also make demangle to demangle symbols unconditionally. Previously, it demangled symbols only when Config->Demangle is true. llvm-svn: 274804
* -Bsymbolic should not make symbols more preemptable.Rafael Espindola2016-07-071-3/+6
| | | | | | But it was doing that for protected undefined symbols. llvm-svn: 274803
* [ELF] - Implemented support of default/non-default symbols versionsGeorge Rimar2016-06-281-0/+8
| | | | | | | | | | | | | | | | | | | | t is possible to create new version of symbol instead of depricated one using combination of version script and asm commands. For example: __asm__(".symver b_1,b@LIBSAMPLE_1.0"); int b_1() { return 10; } __asm__(".symver b_2,b@@LIBSAMPLE_2.0"); int b_2() { return 20; } This code makes b_2() to be default implementation for b(). b_1() is used for compatibility with binaries compiled against library of older version LIBSAMPLE_1.0. This patch implements support for above functionality in lld. Differential revision: http://reviews.llvm.org/D21681 llvm-svn: 274002
* [ELF] - Recommit r273143("[ELF] - Basic versioned symbols support implemented.")George Rimar2016-06-201-1/+1
| | | | | | | | | | | | | | | | | | 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
* Revert r273143 "[ELF] - Basic versioned symbols support implemented."George Rimar2016-06-201-1/+1
| | | | | | | 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-1/+1
| | | | | | | | | | | | | 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
* [ELF][MIPS] Support GOT entries for non-preemptible symbols with different ↵Simon Atanasyan2016-06-191-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | 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 PltZero -> PltHeader.Rui Ueyama2016-06-161-1/+1
| | | | | | | | | | | | 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
* Don't include --start-lib/--end-lib files twice.Rafael Espindola2016-06-141-0/+3
| | | | | | | | | This should never happen with correct programs, but it is trivial write a testcase where lld would crash or report duplicated symbols. We now behave like when an archive is used and include the file only once. llvm-svn: 272724
* Use a reference instead of a pointer. NFC.Rafael Espindola2016-06-141-2/+2
| | | | llvm-svn: 272719
* Inline SymbolBody::init. NFC.Rui Ueyama2016-05-241-12/+4
| | | | | | I think this function was too short to be an independent function. llvm-svn: 270534
* Fix copy relocations in pie.Rafael Espindola2016-05-051-2/+4
| | | | | | | | We were creating the copy relocations just fine, but then thinking that the .bss position could be preempted and creating a dynamic relocation to it, which would crash at runtime since that memory is read only. llvm-svn: 268668
* ELF: Forbid all relative relocations to absolute symbols in PIC, except for ↵Peter Collingbourne2016-05-031-3/+6
| | | | | | | | | | | | | | | | | | weak undefined. Weak undefined symbols resolve to the image base. This is a little strange, but it allows us to link function calls to such symbols. Normally such a call will be guarded with a comparison, which will load a zero from the GOT. There's one example of such a function call in crti.o in Linux's CRT. As part of this change, I also needed to make the synthetic start and end symbols image base relative in the case where their sections were empty, so that PC-relative references to those symbols would continue to work. Differential Revision: http://reviews.llvm.org/D19844 llvm-svn: 268350
* Teach Undefined symbols from which file they are created from.Rui Ueyama2016-05-021-0/+17
| | | | | | | | | This patch increases the size of Undefined by the size of a pointer, but it wouldn't actually increase the size of memory that LLD uses because we are not allocating the exact size but the size of the largest SymbolBody. llvm-svn: 268310
* ELF: New symbol table design.Peter Collingbourne2016-05-011-66/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove Size from Undefined symbol.Rui Ueyama2016-04-281-9/+4
| | | | | | | | | | | There seems to be no reason to keep st_size of undefined symbols. This patch removes the member for it. This patch will change outputs in cases that undefined symbols are copied to output, but I think this is unimportant. Differential Revision: http://reviews.llvm.org/D19574 llvm-svn: 267826
* ELF: Merge UndefinedBitcode and UndefinedElf. NFC.Peter Collingbourne2016-04-271-28/+13
| | | | | | Differential Revision: http://reviews.llvm.org/D19566 llvm-svn: 267640
* ELF: Re-implement -u directly and remove CanKeepUndefined flag.Peter Collingbourne2016-04-271-6/+2
| | | | | | | | | | | | | | | | The semantics of the -u flag are to load the lazy symbol named by the flag. We were previously relying on this behavior falling out of symbol resolution against a synthetic undefined symbol, but that didn't quite give us the correct behavior, so we needed a flag to mark symbols created with -u so we could treat them specially in the writer. However, it's simpler and less error prone to implement the required behavior directly and remove the flag. This fixes an issue where symbols loaded with -u would receive hidden visibility even when the definition in an object file had wider visibility. Differential Revision: http://reviews.llvm.org/D19560 llvm-svn: 267639
* ELF: Simplify preemption logic. Do not include weak undefined symbols in ↵Peter Collingbourne2016-04-241-7/+8
| | | | | | | | non-DSOs. Add a test for -Bsymbolic + undefined symbols. llvm-svn: 267323
* ELF: Always include undefined DSO symbols in the symbol table.Peter Collingbourne2016-04-241-7/+4
| | | | | | | | | Fixes check-llvm when bootstrapping. Also remove mostly dead and most likely incorrect logic regarding preemption of weak undefined symbols. llvm-svn: 267314
* ELF: Implement basic support for --version-script.Peter Collingbourne2016-04-221-18/+13
| | | | | | | | | | | | | | | | | | | | This patch only implements support for version scripts of the form: { [ global: symbol1; symbol2; [...]; symbolN; ] local: *; }; No wildcards are supported, other than for the local entry. Symbol versioning is also not supported. It works by introducing a new Symbol flag which tracks whether a symbol appears in the global section of a version script. This patch also simplifies the logic in SymbolBody::isPreemptible(), and teaches it to handle the case where symbols with default visibility in DSOs do not appear in the dynamic symbol table because of a version script. Fixes PR27482. Differential Revision: http://reviews.llvm.org/D19430 llvm-svn: 267208
* Inline SymbolTable::compareCommons and add comments. NFC.Rui Ueyama2016-04-221-14/+18
| | | | llvm-svn: 267195
* ELF: Move Visibility, IsUsedInRegularObj and MustBeInDynSym flags to Symbol.Peter Collingbourne2016-04-221-48/+6
| | | | | | | | | | | | | | 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
* Internalize linkonce_odr more often.Rafael Espindola2016-04-211-1/+7
| | | | | | | | | | | | | | Since there is a copy in every translation unit that uses them, they can be omitted from the symbol table if the address is not significant. This still doesn't catch as many cases as the gold plugin. The difference is that we check canBeOmittedFromSymbolTable in each file and use lazy loading which limits what it can do. Gold checks it in the merged file. I think the correct way of getting the same results as gold is just to cache in the IR the result of canBeOmittedFromSymbolTable. llvm-svn: 267063
* Start adding support for internalizing shared libraries.Rafael Espindola2016-04-211-0/+9
| | | | llvm-svn: 267045
* Two small related fixes.Rafael Espindola2016-04-151-2/+3
| | | | | | | * A hidden undefined is not preemptable. * It is always zero, so we don't need a dynamic reloc for it. llvm-svn: 266424
* Don't set MustBeInDynSym for hidden symbols.Rafael Espindola2016-04-131-2/+3
| | | | llvm-svn: 266230
* ELF: Use hidden visibility for all DefinedSynthetic symbols.Peter Collingbourne2016-04-131-3/+2
| | | | | | | | | | | | | This simplifies the code by allowing us to remove the visibility argument to functions that create synthetic symbols. The only functional change is that the visibility of the MIPS "_gp" symbol is now hidden. Because this symbol is defined in every executable or DSO, it would be difficult to observe a visibility change here. Differential Revision: http://reviews.llvm.org/D19033 llvm-svn: 266208
* Cleanup the handling of MustBeInDynSym and IsUsedInRegularObj.Rafael Espindola2016-04-081-9/+12
| | | | | | | | | | | | | | | | | | Now MustBeInDynSym is only true if the symbol really must be in the dynamic symbol table. IsUsedInRegularObj is only true if the symbol is used in a .o or -u. Not a .so or a .bc. A benefit is that this is now done almost entirilly during symbol resolution. The only exception is copy relocations because of aliases. This includes a small fix in that protected symbols in .so don't force executable symbols to be exported. This also opens the way for implementing internalize for -shared. llvm-svn: 265826
* Don't lower the visibility because of shared symbols.Rafael Espindola2016-04-081-3/+5
| | | | | | | If a shared library has a protected symbol 'foo', that doesn't imply that the symbol 'foo' in the output should be protected or not. llvm-svn: 265794
* ELF: Implement --start-lib and --end-libRui Ueyama2016-04-071-2/+13
| | | | | | | | | | | | | | | | start-lib and end-lib are options to link object files in the same semantics as archive files. If an object is in start-lib and end-lib, the object is linked only when the file is needed to resolve undefined symbols. That means, if an object is in start-lib and end-lib, it behaves as if it were in an archive file. In this patch, I introduced a new notion, LazyObjectFile. That is analogous to Archive file type, but that works for a single object file instead of for an archive file. http://reviews.llvm.org/D18814 llvm-svn: 265710
OpenPOWER on IntegriCloud