summaryrefslogtreecommitdiffstats
path: root/lld/ELF/SymbolTable.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* ELF: Compute used bit for --as-needed during symbol resolution.Peter Collingbourne2016-06-091-4/+10
| | | | | | | | | | | | | | | | | | We can now use this to decide whether to emit a verneed during the final pass over the symbols. We were previously wrongly creating a verneed entry in the case where all references to a DSO's symbols were weak. In a future change we may also want to use the used bit to control whether shared symbols are preemptible and appear in the dynsym. This seems a little tricky to do at the moment because isNeeded() is templated. The only other functional change here is that we emit a DT_NEEDED for DSOs whose symbols are all preempted by objects that appear later in the link. But that doesn't seem too important to me. Differential Revision: http://reviews.llvm.org/D21171 llvm-svn: 272282
* Print member name in undefined symbol error.Rafael Espindola2016-05-091-9/+0
| | | | llvm-svn: 268976
* ELF: Fix regression in TLS attribute mismatch logic.Peter Collingbourne2016-05-031-3/+4
| | | | | | | | | Introduce a special symbol type to indicate that we have not yet seen a type for the symbol, so we should not report TLS mismatches for that symbol. Differential Revision: http://reviews.llvm.org/D19836 llvm-svn: 268411
* ELF: Remove the function SymbolTable<ELFT>::findFile.Peter Collingbourne2016-05-031-17/+0
| | | | | | We already have the function SymbolBody::getSourceFile which does the same thing. llvm-svn: 268353
* ELF: Forbid all relative relocations to absolute symbols in PIC, except for ↵Peter Collingbourne2016-05-031-1/+1
| | | | | | | | | | | | | | | | | | 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-18/+5
| | | | | | | | | 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-162/+308
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Fixed warning. NFC.George Rimar2016-04-291-1/+1
| | | | | | | | SymbolTable.cpp:298:36: warning: enumeral and non-enumeral type in conditional expression [-Wextra] Sym->Binding = New->isShared() ? STB_GLOBAL : New->Binding; ^ llvm-svn: 268040
* Remove Size from Undefined symbol.Rui Ueyama2016-04-281-3/+2
| | | | | | | | | | | 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
* Do not lookup the symbol table twice for each --wrap.Rui Ueyama2016-04-281-2/+3
| | | | llvm-svn: 267822
* ELF: Merge UndefinedBitcode and UndefinedElf. NFC.Peter Collingbourne2016-04-271-2/+3
| | | | | | Differential Revision: http://reviews.llvm.org/D19566 llvm-svn: 267640
* ELF: Re-implement -u directly and remove CanKeepUndefined flag.Peter Collingbourne2016-04-271-11/+11
| | | | | | | | | | | | | | | | 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
* Store the binding in the Symbol.Rafael Espindola2016-04-261-2/+6
| | | | | | | This remove a fixme, cleans up the weak undef interaction with archives and lets us keep weak undefs still weak if they resolve to shared. llvm-svn: 267555
* Add more comment.Rui Ueyama2016-04-231-0/+1
| | | | llvm-svn: 267260
* Add comments.Rui Ueyama2016-04-231-0/+7
| | | | llvm-svn: 267259
* ELF: Implement basic support for --version-script.Peter Collingbourne2016-04-221-1/+15
| | | | | | | | | | | | | | | | | | | | 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
* Update an out of date comment.Peter Collingbourne2016-04-221-4/+3
| | | | llvm-svn: 267200
* ELF: Move Visibility, IsUsedInRegularObj and MustBeInDynSym flags to Symbol.Peter Collingbourne2016-04-221-17/+36
| | | | | | | | | | | | | | 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
* [LTO] Implement parallel Codegen for LTO using splitCodeGen.Davide Italiano2016-04-151-15/+18
| | | | | | | | Parallelism level can be chosen using the new --lto-jobs=K option where K is the number of threads used for CodeGen. It currently defaults to 1. llvm-svn: 266484
* Specialize the symbol table data structure a bit.Rafael Espindola2016-04-141-3/+9
| | | | | | | | | 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
* ELF: Implement --dynamic-listAdhemerval Zanella2016-04-131-0/+8
| | | | | | | | | | | | | | | | | | | | | This patch implements the --dynamic-list option, which adds a list of global symbol that either should not be bounded by default definition when creating shared libraries, or add in dynamic symbol table in the case of creating executables. The patch modifies the ScriptParserBase class to use a list of Token instead of StringRef, which contains information if the token is a quoted or unquoted strings. It is used to use a faster search for exact match symbol name. The input file follow a similar format of linker script with some simplifications (it does not have scope or node names). It leads to a simplified parser define in DynamicList.{cpp,h}. Different from ld/gold neither glob pattern nor mangled names (extern 'C++') are currently supported. llvm-svn: 266227
* [ELF] - Change -t implementation to print which archive members are used.George Rimar2016-04-131-18/+21
| | | | | | | | | | | | | | | | | | | Previously each archive file was reported no matter were it's member used or not, like: lib/libLLVMSupport.a Now lld prints line for each used internal file, like: lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/StringSaver.cpp.o) lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/Host.cpp.o) lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/ConvertUTF.c.o) That should be consistent with what gold do. This fixes PR27243. Differential revision: http://reviews.llvm.org/D19011 llvm-svn: 266220
* ELF: Use hidden visibility for all DefinedSynthetic symbols.Peter Collingbourne2016-04-131-2/+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-2/+4
| | | | | | | | | | | | | | | | | | 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
* ELF: Implement --start-lib and --end-libRui Ueyama2016-04-071-3/+12
| | | | | | | | | | | | | | | | 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
* Change the type hierarchy for undefined symbols.Rafael Espindola2016-04-061-8/+11
| | | | | | | | | | We have to differentiate undefined symbols from bitcode and undefined symbols from other sources. Undefined symbols from bitcode should not inhibit the symbol being internalized. Undefined symbols from other sources should. llvm-svn: 265536
* Fix another case of propagating IsUsedRegularObj.Rafael Espindola2016-04-051-1/+4
| | | | | | | I have an idea on how to clean this up, but lets get the tests passing first. llvm-svn: 265374
* ELF: Make SymbolBody::compare a non-template function.Peter Collingbourne2016-04-051-1/+1
| | | | | | Differential Revision: http://reviews.llvm.org/D18781 llvm-svn: 265372
* ELF: Preserve MustBeInDynSym for bitcode symbols.Peter Collingbourne2016-04-051-0/+2
| | | | | | | | | | | Make sure to copy the MustBeInDynSym field when replacing shared symbols with bitcode symbols, and when replacing bitcode symbols with regular symbols in addCombinedLtoObject. Fixes interposition of DSO symbols with bitcode symbols in the main executable. Differential Revision: http://reviews.llvm.org/D18780 llvm-svn: 265371
* Don't store an Elf_Sym for most symbols.Rafael Espindola2016-04-041-9/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Prefer 'auto' over explicit type for consistency.Davide Italiano2016-04-021-1/+1
| | | | llvm-svn: 265250
* [LTO] Fix symbols which were internalized incorrectly.Davide Italiano2016-04-021-0/+1
| | | | | | | | | | | | | If a symbol is defined in an archive, when we replace its body the isUsedInRegularObj wasn't set correctly. Internalize makes its decision based on that bit so we ended up internalizing symbols that we shouldn't (because they're referenced). This should fix. Thanks to Peter and Rafael for discussion and help diagnosing the issue! Found during LTO of unittests. llvm-svn: 265208
* Make BitcodeCompiler::compile a non-template function. NFC.Rui Ueyama2016-03-291-2/+3
| | | | llvm-svn: 264770
* [LTO] Include in .symtab/.dynsym symbols introduced by optimizations.Davide Italiano2016-03-291-0/+1
| | | | | | | | | | | | Some optimizations, e.g. SimplifyLibCalls, can replace functions with others as part of the lowering, e.g. printf => puts. The new symbols don't have the isUsedInRegularObj flag set so they don't get included in the final symbol table (and dynamic symbol table), and the dynamic linker gets confused. Include them as a fix. Differential Revision: http://reviews.llvm.org/D18357 llvm-svn: 264688
* ELF: Create LTO.{cpp,h} and move LTO-related code to that file.Rui Ueyama2016-03-221-130/+9
| | | | | | | | | | | The code for LTO has been growing, so now is probably a good time to move it to its own file. SymbolTable.cpp is for symbol table, and because compiling bitcode files are semantically not a part of symbol table, this is I think a good thing to do. http://reviews.llvm.org/D18370 llvm-svn: 264091
* [lto] Provide a file name for the combined LTO object.Sean Silva2016-03-221-1/+2
| | | | | | | | | | Otherwise, we get diagnostics like: undefined symbol: foo in Which isn't particularly useful. llvm-svn: 264089
* [ELF] Refactor run of LTO passes into an helper. NFC.Davide Italiano2016-03-181-18/+22
| | | | | | Requested by: Rui Ueyama. llvm-svn: 263851
* [LTO] Call the optimizer before invoking codegen.Davide Italiano2016-03-171-10/+33
| | | | | | | | This is the required plumbing needed to run the LTO passes. Differential Revision: http://reviews.llvm.org/D18235 llvm-svn: 263761
* [ELF] - -pie/--pic-executable option implementedGeorge Rimar2016-03-171-1/+1
| | | | | | | | | | | | | | | | | -pie --pic-executable Create a position independent executable. This is currently only supported on ELF platforms. Position independent executables are similar to shared libraries in that they are relocated by the dynamic linker to the virtual address the OS chooses for them (which can vary between invocations). Like normal dynamically linked executables they can be executed and symbols defined in the executable cannot be overridden by shared libraries. Differential revision: http://reviews.llvm.org/D18183 llvm-svn: 263693
* Recommit of r263252, [ELF] - Change all messages to lowercase to be consistent.George Rimar2016-03-121-2/+2
| | | | | | | | | | | | | | | | | | | | | which was reverted because included unrelative changes by mistake. Original commit message: [ELF] - Change all messages to lowercase to be consistent. That is directly opposite to http://reviews.llvm.org/D18045, which was reverted. This patch changes all messages to start from lowercase letter if they were not before. That is done to be consistent with clang. Differential revision: http://reviews.llvm.org/D18085 llvm-svn: 263337
* Revert r263252: "[ELF] - Change all messages to lowercase to be consistent."Rui Ueyama2016-03-111-18/+24
| | | | | | This reverts commit r263252 because the change contained unrelated changes. llvm-svn: 263272
* [ELF] - Change all messages to lowercase to be consistent.George Rimar2016-03-111-24/+18
| | | | | | | | | | | | | | That is directly opposite to http://reviews.llvm.org/D18045, which was reverted. This patch changes all messages to start from lowercase letter if they were not before. That is done to be consistent with clang. Differential revision: http://reviews.llvm.org/D18085 llvm-svn: 263252
* More MSVC fixes.Rafael Espindola2016-03-111-1/+1
| | | | llvm-svn: 263251
* Avoid calling getNamedValue.Rafael Espindola2016-03-111-16/+22
| | | | | | | In lld we usually avoid hash lookups. In addition to that, IR names are not fully mangled, so it is best to avoid using them whenever possible. llvm-svn: 263248
* This reverts the r263125George Rimar2016-03-111-1/+1
| | | | | | | | | | | | | | | | | | | | It was discussed to make all messages be lowercase to be consistent with clang. (also reverts the r263128 which fixed build bot fail after r263125) Original commit message: [ELF] - Consistent spelling for error/warning messages Previously error and warnings were not consistent in lld. Some of them started from lowercase letter, others from uppercase. Also there was one or two which had a dot at the end. This patch changes all messages to start from uppercase letter if they were not before. Differential revision: http://reviews.llvm.org/D18045 llvm-svn: 263240
* Create a SymbolBody for locals.Rafael Espindola2016-03-111-3/+3
| | | | | | pr26878 shows a case where locals have to be in the got. llvm-svn: 263222
* [lto] Make sure that ctors are added to the combined module.Sean Silva2016-03-111-0/+5
| | | | | | | | | | | | | | Summary: More generally, appending linkage is a special case that we don't want to create a SymbolBody for. Reviewers: rafael, ruiu Subscribers: Bigcheese, llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D18012 llvm-svn: 263179
* [ELF] - Consistent spelling for error/warning messagesGeorge Rimar2016-03-101-1/+1
| | | | | | | | | | | | Previously error and warnings were not consistent in lld. Some of them started from lowercase letter, others from uppercase. Also there was one or two which had a dot at the end. This patch changes all messages to start from uppercase letter if they were not before. Differential revision: http://reviews.llvm.org/D18045 llvm-svn: 263125
* [lto] Add saving the LTO .o file to -save-temps.Sean Silva2016-03-091-0/+11
| | | | | | | | | | | | | | | | Summary: This implements another part of -save-temps. After this, the only remaining part is dumping the optimized bitcode. But currently LLD's LTO doesn't have a non-intrusive place to put this. Eventually we probably will and it will make sense to add it then. Reviewers: ruiu, rafael Subscribers: joker.eph, Bigcheese, llvm-commits Differential Revision: http://reviews.llvm.org/D18009 llvm-svn: 263070
* Update for Rui's comments on D18006Sean Silva2016-03-091-3/+5
| | | | | | Somehow I missed them. llvm-svn: 263057
OpenPOWER on IntegriCloud