summaryrefslogtreecommitdiff
path: root/lld/ELF/SymbolTable.h
AgeCommit message (Collapse)Author
2018-08-22Change how we handle -wrap.Rui Ueyama
We have an issue with -wrap that the option doesn't work well when renamed symbols get PLT entries. I'll explain what is the issue and how this patch solves it. For one -wrap option, we have three symbols: foo, wrap_foo and real_foo. Currently, we use memcpy to overwrite wrapped symbols so that they get the same contents. This works in most cases but doesn't when the relocation processor sets some flags in the symbol. memcpy'ed symbols are just aliases, so they always have to have the same contents, but the relocation processor breaks that assumption. r336609 is an attempt to fix the issue by memcpy'ing again after processing relocations, so that symbols that are out of sync get the same contents again. That works in most cases as well, but it breaks ASan build in a mysterious way. We could probably fix the issue by choosing symbol attributes that need to be copied after they are updated. But it feels too complicated to me. So, in this patch, I fixed it once and for all. With this patch, we no longer memcpy symbols. All references to renamed symbols point to new symbols after wrapSymbols() is done. Differential Revision: https://reviews.llvm.org/D50569
2018-07-18Revert r336609: Fix direct calls to __wrap_sym when it is relocated.Rui Ueyama
This reverts commit r336609 as it doesn't seem to work with AArch64 thunk creation when used with ASan.
2018-07-09Fix direct calls to __wrap_sym when it is relocated.Rui Ueyama
Patch by Matthew Koontz! Before, direct calls to __wrap_sym would not map to valid PLT entries, so they would crash at runtime. This change maps such calls to the same PLT entry as calls to sym that are then wrapped. Differential Revision: https://reviews.llvm.org/D48502
2018-04-03Make fetchIfLazy only fetch an object file. NFC.Rui Ueyama
Previously, fetchIfLazy did more than the name says. Now, setting to UsedInRegularObj is moved to another function.
2018-04-03[ELF] - Eliminate Lazy class.George Rimar
Patch removes Lazy class which is just an excessive layer. Differential revision: https://reviews.llvm.org/D45083
2018-02-28Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.Rui Ueyama
This should resolve the issue that lld build fails in some hosts that uses case-insensitive file system. Differential Revision: https://reviews.llvm.org/D43788
2018-02-27Put undefined symbols from shared libraries in the symbol table.Rafael Espindola
With the recent fixes these symbols have more in common than not with regular undefined symbols.
2018-02-16ELF: Stop collecting a list of symbols in ArchiveFile.Peter Collingbourne
There seems to be no reason to collect this list of symbols. Also fix a bug where --exclude-libs would apply to all symbols that appear in an archive's symbol table, even if the relevant archive member was not added to the link. Differential Revision: https://reviews.llvm.org/D43369
2018-01-30[ELF] - Remove dead declaration. NFC.George Rimar
2017-12-23Detemplate reportDuplicate.Rafael Espindola
We normally avoid "switch (Config->EKind)", but in this case I think it is worth it. It is only executed when there is an error and it allows detemplating a lot of code.
2017-12-20Use a reference in addLazyArchive. NFC.Rafael Espindola
2017-12-20Use a reference for the shared symbol file.Rafael Espindola
Every shared symbol has a file, so we can use a reference.
2017-12-20Use a reference for a value that is never null. NFC.Rafael Espindola
2017-12-20Use a reference for a value that is never null. NFC.Rafael Espindola
2017-12-12Compact symbols from 96 to 88 bytes.Rafael Espindola
By using an index instead of a pointer for verdef we can put the index next to the alignment field. This uses the otherwise wasted area and reduces the shared symbol size. By itself the performance change of this is in the noise, but I have a followup patch to remove another 8 bytes that improves performance when combined with this.
2017-12-09Remove some includes from InputFiles.h.Rafael Espindola
They were not used in InputFiles.h and it was getting too easy to add circular includes.
2017-11-27Rename `Symtab` private memory to avoid confusion with global `Symtab`Sam Clegg
This is also consistent with SymVector that exists in COFF port and soon to be added to the wasm port. Split off as part of https://reviews.llvm.org/D40371 Differential Revision: https://reviews.llvm.org/D40525
2017-11-17Remove IsLocal.Rafael Espindola
Since we always have Binding in the current symbol design IsLocal is redundant.
2017-11-11Simplify. NFC.Rafael Espindola
copyFrom doesn't copy the Binding, so this was a nop.
2017-11-06ELF: Remove SymbolTable::SymIndex class.Peter Collingbourne
The Traced flag is unnecessary because we only need to set the index to -1 to mark a symbol for tracing. Differential Revision: https://reviews.llvm.org/D39672
2017-11-06ELF: Merge DefinedRegular and Defined.Peter Collingbourne
Now that DefinedRegular is the only remaining derived class of Defined, we can merge the two classes. Differential Revision: https://reviews.llvm.org/D39667
2017-11-04Rewrite addSymbolWrap and applySymbolWrap. NFCI.Rui Ueyama
r317396 changed the way how we handle the -defsym option. The option is now handled using the infrastructure for the linker script. We used to handle both -defsym and -wrap using the same set of functions in the symbol table. Now, we don't need to do that. This patch rewrites the functions so that they become more straightforward. The new functions directly handle -wrap rather than abstract it.
2017-11-04Remove dead code and update comment.Rui Ueyama
2017-11-03Rename SymbolBody -> SymbolRui Ueyama
Now that we have only SymbolBody as the symbol class. So, "SymbolBody" is a bit strange name now. This is a mechanical change generated by perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF) nd clang-format-diff. Differential Revision: https://reviews.llvm.org/D39459
2017-10-31Merge SymbolBody and Symbol into one class, SymbolBody.Rui Ueyama
SymbolBody and Symbol were separated classes due to a historical reason. Symbol used to be a pointer to a SymbolBody, and the relationship between Symbol and SymbolBody was n:1. r2681780 changed that. Since that patch, SymbolBody and Symbol are allocated next to each other to improve memory locality, and they have 1:1 relationship now. So, the separation of Symbol and SymbolBody no longer makes sense. This patch merges them into one class. In order to avoid updating too many places, I chose SymbolBody as a unified name. I'll rename it Symbol in a follow-up patch. Differential Revision: https://reviews.llvm.org/D39406
2017-10-28Pass symbol attributes instead of ElfSym to Shared symbol ctor.Rui Ueyama
This change allows us to use less templates for Shared symbol and the functions that deals with shared symbols.
2017-10-16Revert r315877: Simplify.Konstantin Zhuravlyov
It causes MSVC 2015 to emit "C4307: '-': integral constant overflow" warning Differential Revision: https://reviews.llvm.org/D38955
2017-10-15Simplify.Rui Ueyama
2017-10-07Inline small function. NFC.Rafael Espindola
2017-10-06Refine our --wrap implementation.Rafael Espindola
Before this patch we would copy foo into real_foo and wrap_foo into foo. The net result is that __wrap_foo shows up twice in the symbol table. With this patch we: * save a copy of __real_foo before copying foo. * drop one of the __wrap_foo from the symbol table. * if __real_foo was not undefined, add a *new* symbol with that content to the symbol table. The net result is that Anything using foo now uses __wrap_foo Anything using __real_foo now uses foo. Anything using __wrap_foo still does. And the symbol table has foo, __wrap_foo and __real_foo (if defined). Which I think is the desired behavior.
2017-10-03Inline a small function.Rui Ueyama
2017-10-03[ELF] Avoid promoting an undefined weak entry symbol to global.Igor Kudrin
Without this patch, lld emits "error: undefined symbol: _start" if it encountered only weak references to that symbol.
2017-09-30Make parameter lists of SymbolTable::add* functions more consistent. NFC.Rui Ueyama
2017-09-25Move Config->SymbolRenaming to SymbolTable.Rui Ueyama
In order to keep track of symbol renaming, we used to have Config->SymbolRenaming, and whether a symbol is in the map or not affects its symbol attribute (i.e. "LinkeRedefined" bit). This patch adds "CanInline" bit to Symbol to aggreagate symbol information in one place and removed the member from Config since no one except SymbolTable now uses the table.
2017-09-08If --dynamic-list is given, only those symbols are preemptible.Rafael Espindola
This allows combining --dynamic-list and version scripts too. The version script controls which symbols are visible, and --dynamic-list controls which of those are preemptible. Unlike previous versions, undefined symbols are still considered preemptible, which was the issue breaking the cfi tests. This fixes pr34053.
2017-09-08Revert "Revert "Revert r311468: If --dynamic-list is given, only those ↵Rafael Espindola
symbols are preemptible"" This reverts commit r312757. Evgenii Stepanov reports that it broke some tests.
2017-09-07Revert "Revert r311468: If --dynamic-list is given, only those symbols are ↵Rafael Espindola
preemptible" If --dynamic-list is given, only those symbols are preemptible. This allows combining --dynamic-list and version scripts too. The version script controls which symbols are visible, and --dynamic-list controls which of those are preemptible. This fixes pr34053.
2017-08-22Revert r311468: If --dynamic-list is given, only those symbols are preemptibleRui Ueyama
This reverts commit r311468 because it broke some CFI bots.
2017-08-22If --dynamic-list is given, only those symbols are preemptibleRui Ueyama
Patch by Rafael Espíndola. This is PR34053. The implementation is a bit of a hack, given the precise location where IsPreemtible is set, it cannot be used from SymbolTable::handleAnonymousVersion. I could add another method to SymbolTable if you think that would be better. Differential Revision: https://reviews.llvm.org/D36499
2017-08-15Remove SymbolTable::findInCurrentDSO.Rui Ueyama
This function doesn't seem to add value to the symbol table as it is easy to write code without it.
2017-07-26Rename ObjectFile -> ObjFile.Rui Ueyama
Rename it because it was too easy to conflict with llvm::object::ObjectFile which broke buildbots several times.
2017-07-26Detemplate SymbolTable.Rafael Espindola
NFC, just makes it easier to access from non templated code.
2017-06-30Remove unused declarationsSam Clegg
Differential Revision: https://reviews.llvm.org/D34852
2017-06-21Implement the --exclude-libs option.Rui Ueyama
The --exclude-libs option is not a popular option, but at least some programs in Android depend on it, so it's worth to support it. Differential Revision: https://reviews.llvm.org/D34422
2017-06-05Symbols re-defined with -wrap and -defsym need to be excluded from inter-Dmitry Mikulin
procedural optimizations to prevent dropping symbols and allow the linker to process re-directs. PR33145: --wrap doesn't work with lto. Differential Revision: https://reviews.llvm.org/D33621
2017-05-25Revert "Simplify a variable type by using StringRef instead of ↵Rafael Espindola
CachedHashStringRef." This reverts commit r303787. It caused a slowdown in fast links. That is, links with no debug info or optimizations.
2017-05-24Simplify a variable type by using StringRef instead of CachedHashStringRef.Rui Ueyama
A variable `ComdatGroup` is not supposed to contain a large number of items. Even when linking clang, it ends up having only 300K strings. It doesn't make sense to use CachedHashStringRef for this hash table. This patch has neutral or slightly positive impact on performance while reducing code complexity.
2017-04-26[ELF] - Implemented --defsym option.George Rimar
gnu ld description of option is: --defsym=symbol=expression Create a global symbol in the output file, containing the absolute address given by expression. You may use this option as many times as necessary to define multiple symbols in the command line. A limited form of arithmetic is supported for the expression in this context: you may give a hexadecimal constant or the name of an existing symbol, or use "+" and "-" to add or subtract hexadecimal constants or symbols. If you need more elaborate expressions, consider using the linker command language from a script. Note: there should be no white space between symbol, the equals sign ("="), and expression. In compare with D32082, this patch does not support math expressions and absolute symbols. It implemented via code similar to --wrap. That covers 1 of 3 possible --defsym cases. Differential revision: https://reviews.llvm.org/D32171
2017-03-08Remove DefinedSynthetic.Rafael Espindola
With this we have a single section hierarchy. It is a bit less code, but the main advantage will be in a future patch being able to handle foo = symbol_in_obj; in a linker script. Currently that fails since we try to find the output section of symbol_in_obj. With this we should be able to just return an InputSection from the expression.
2017-03-08Use uint32_t for alignment in more places, NFC.Rafael Espindola