summaryrefslogtreecommitdiffstats
path: root/lld/ELF/SymbolTable.h
Commit message (Collapse)AuthorAgeFilesLines
* [ELF] Replace SymbolTable::forEachSymbol with iterator_range symbols()Fangrui Song2019-11-261-6/+10
| | | | | | | | | | | | | | D62381 introduced forEachSymbol(). It seems that many call sites cannot be parallelized because the body shared some states. Replace forEachSymbol with iterator_range<filter_iterator<...>> symbols() to simplify code and improve debuggability (std::function calls take some frames). It also allows us to use early return to simplify code added in D69650. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D70505
* [ELF] Rename odd variable names "New" after r365730. NFCFangrui Song2019-08-131-1/+1
| | | | | | | | | | New -> newSym or newFlags Reviewed By: atanasyan Differential Revision: https://reviews.llvm.org/D66127 llvm-svn: 368651
* [ELF] Handle non-glob patterns before glob patterns in version scripts & fix ↵Fangrui Song2019-07-111-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | a corner case of --dynamic-list This fixes PR38549, which is silently accepted by ld.bfd. This seems correct because it makes sense to let non-glob patterns take precedence over glob patterns. lld issues an error because `assignWildcardVersion(ver, VER_NDX_LOCAL);` is processed before `assignExactVersion(ver, v.id, v.name);`. Move all assignWildcardVersion() calls after assignExactVersion() calls to fix this. Also, move handleDynamicList() to the bottom. computeBinding() called by includeInDynsym() has this cryptic rule: if (versionId == VER_NDX_LOCAL && isDefined() && !isPreemptible) return STB_LOCAL; Before the change: * foo's version is set to VER_NDX_LOCAL due to `local: *` * handleDynamicList() is called - foo.computeBinding() is STB_LOCAL - foo.includeInDynsym() is false - foo.isPreemptible is not set (wrong) * foo's version is set to V1 After the change: * foo's version is set to VER_NDX_LOCAL due to `local: *` * foo's version is set to V1 * handleDynamicList() is called - foo.computeBinding() is STB_GLOBAL - foo.includeInDynsym() is true - foo.isPreemptible is set (correct) Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D64550 llvm-svn: 365760
* [Coding style change] Rename variables so that they start with a lowercase ↵Rui Ueyama2019-07-101-18/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | letter This patch is mechanically generated by clang-llvm-rename tool that I wrote using Clang Refactoring Engine just for creating this patch. You can see the source code of the tool at https://reviews.llvm.org/D64123. There's no manual post-processing; you can generate the same patch by re-running the tool against lld's code base. Here is the main discussion thread to change the LLVM coding style: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html In the discussion thread, I proposed we use lld as a testbed for variable naming scheme change, and this patch does that. I chose to rename variables so that they are in camelCase, just because that is a minimal change to make variables to start with a lowercase letter. Note to downstream patch maintainers: if you are maintaining a downstream lld repo, just rebasing ahead of this commit would cause massive merge conflicts because this patch essentially changes every line in the lld subdirectory. But there's a remedy. clang-llvm-rename tool is a batch tool, so you can rename variables in your downstream repo with the tool. Given that, here is how to rebase your repo to a commit after the mass renaming: 1. rebase to the commit just before the mass variable renaming, 2. apply the tool to your downstream repo to mass-rename variables locally, and 3. rebase again to the head. Most changes made by the tool should be identical for a downstream repo and for the head, so at the step 3, almost all changes should be merged and disappear. I'd expect that there would be some lines that you need to merge by hand, but that shouldn't be too many. Differential Revision: https://reviews.llvm.org/D64121 llvm-svn: 365595
* Use SymbolTable::insert() to implement --trace.Rui Ueyama2019-05-281-3/+7
| | | | | | Differential Revision: https://reviews.llvm.org/D62381 llvm-svn: 361791
* [ELF] Deleted unused forward declarations. NFCFangrui Song2019-05-241-8/+0
| | | | llvm-svn: 361614
* Move code for symbol resolution from SymbolTable.cpp to Symbols.cpp.Rui Ueyama2019-05-231-5/+0
| | | | | | | | | | | | | | | | My recent commits separated symbol resolution from the symbol table, so the functions to resolve symbols are now in a somewhat wrong file. This patch moves it to Symbols.cpp. The functions are now member functions of the symbol. This is code move change. I modified function names so that they are appropriate as member functions, though. No functionality change intended. Differential Revision: https://reviews.llvm.org/D62290 llvm-svn: 361474
* Move SymbolTable::addCombinedLTOObject() to LinkerDriver.Rui Ueyama2019-05-231-5/+0
| | | | | | | | | | | | Also renames it LinkerDriver::compileBitcodeFiles. The function doesn't logically belong to SymbolTable. We added this function to the symbol table because symbol table used to be a container of input files. This is no longer the case. Differential Revision: https://reviews.llvm.org/D62291 llvm-svn: 361469
* [ELF] Improve error message for relocations to symbols defined in discarded ↵Fangrui Song2019-05-221-0/+5
| | | | | | | | | | | | | | | | | | | | | sections Rather than report "undefined symbol: ", give more informative message about the object file that defines the discarded section. In particular, PR41133, if the section is a discarded COMDAT, print the section group signature and the object file with the prevailing definition. This is useful to track down some ODR issues. We need to * add `uint32_t DiscardedSecIdx` to Undefined for this feature. * make ComdatGroups public and change its type to DenseMap<CachedHashStringRef, const InputFile *> Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D59649 llvm-svn: 361359
* [ELF] Deleted unused ComdatGroups member variable left by D61854Fangrui Song2019-05-211-5/+0
| | | | llvm-svn: 361266
* Move symbol resolution code out of SymbolTable class.Rui Ueyama2019-05-171-10/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is the last patch of the series of patches to make it possible to resolve symbols without asking SymbolTable to do so. The main point of this patch is the introduction of `elf::resolveSymbol(Symbol *Old, Symbol *New)`. That function resolves or merges given symbols by examining symbol types and call replaceSymbol (which memcpy's New to Old) if necessary. With the new function, we have now separated symbol resolution from symbol lookup. If you already have a Symbol pointer, you can directly resolve the symbol without asking SymbolTable to do that. Now that the nice abstraction become available, I can start working on performance improvement of the linker. As a starter, I'm thinking of making --{start,end}-lib faster. --{start,end}-lib is currently unnecessarily slow because it looks up the symbol table twice for each symbol. - The first hash table lookup/insertion occurs when we instantiate a LazyObject file to insert LazyObject symbols. - The second hash table lookup/insertion occurs when we create an ObjFile from LazyObject file. That overwrites LazyObject symbols with Defined symbols. I think it is not too hard to see how we can now eliminate the second hash table lookup. We can keep LazyObject symbols in Step 1, and then call elf::resolveSymbol() to do Step 2. Differential Revision: https://reviews.llvm.org/D61898 llvm-svn: 360975
* Pemove SymbolTable::addBitcode as it is redundant.Rui Ueyama2019-05-161-1/+0
| | | | | | Differential Revision: https://reviews.llvm.org/D61897 llvm-svn: 360846
* Consistently return `Symbol *` from SymbolTable's add-family functions.Rui Ueyama2019-05-161-4/+4
| | | | llvm-svn: 360845
* De-template parseFile() and SymbolTable's add-family functions.Rui Ueyama2019-05-161-9/+5
| | | | | | Differential Revision: https://reviews.llvm.org/D61896 llvm-svn: 360844
* Introduce CommonSymbol.Rui Ueyama2019-05-161-3/+5
| | | | | | | | | | | | | | | | | Previously, we handled common symbols as a kind of Defined symbol, but what we were doing for common symbols is pretty different from regular defined symbols. Common symbol and defined symbol are probably as different as shared symbol and defined symbols are different. This patch introduces CommonSymbol to represent common symbols. After symbols are resolved, they are converted to Defined symbols residing in a .bss section. Differential Revision: https://reviews.llvm.org/D61895 llvm-svn: 360841
* Simplify SymbolTable::add{Defined,Undefined,...} functions.Rui Ueyama2019-05-161-23/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | SymbolTable's add-family functions have lots of parameters because when they have to create a new symbol, they forward given arguments to Symbol's constructors. Therefore, the functions take at least as many arguments as their corresponding constructors. This patch simplifies the add-family functions. Now, the functions take a symbol instead of arguments to construct a symbol. If there's no existing symbol, a given symbol is memcpy'ed to the symbol table. Otherwise, the functions attempt to merge the existing and a given new symbol. I also eliminated `CanOmitFromDynSym` parameter, so that the functions take really one argument. Symbol classes are trivially constructible, so looks like constructing them to pass to add-family functions is as cheap as passing a lot of arguments to the functions. A quick benchmark showed that this patch seems performance-neutral. This is a preparation for http://lists.llvm.org/pipermail/llvm-dev/2019-April/131902.html Differential Revision: https://reviews.llvm.org/D61855 llvm-svn: 360838
* Move SymbolTable::addFile to InputFiles.cpp.Rui Ueyama2019-05-141-1/+0
| | | | | | | | | | | | | | | | | The symbol table used to be a container of vectors of input files, but that's no longer the case because the vectors are moved out of SymbolTable and are now global variables. Therefore, addFile doesn't have to belong to any class. This patch moves the function out of the class. This patch is a preparation for my RFC [1]. [1] http://lists.llvm.org/pipermail/llvm-dev/2019-April/131902.html Differential Revision: https://reviews.llvm.org/D61854 llvm-svn: 360666
* De-template SymbolTable::addShared.Rui Ueyama2019-04-091-3/+3
| | | | | | | Because of r357925, this member function doesn't have to be a template of ELFT. llvm-svn: 357982
* ELF: De-template SharedFile. NFCI.Peter Collingbourne2019-04-081-4/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D60305 llvm-svn: 357925
* [ELF] Support --{,no-}allow-shlib-undefinedFangrui Song2019-02-011-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In ld.bfd/gold, --no-allow-shlib-undefined is the default when linking an executable. This patch implements a check to error on undefined symbols in a shared object, if all of its DT_NEEDED entries are seen. Our approach resembles the one used in gold, achieves a good balance to be useful but not too smart (ld.bfd traces all DSOs and emulates the behavior of a dynamic linker to catch more cases). The error is issued based on the symbol table, different from undefined reference errors issued for relocations. It is most effective when there are DSOs that were not linked with -z defs (e.g. when static sanitizers runtime is used). gold has a comment that some system libraries on GNU/Linux may have spurious undefined references and thus system libraries should be excluded (https://sourceware.org/bugzilla/show_bug.cgi?id=6811). The story may have changed now but we make --allow-shlib-undefined the default for now. Its interaction with -shared can be discussed in the future. Reviewers: ruiu, grimar, pcc, espindola Reviewed By: ruiu Subscribers: joerg, emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D57385 llvm-svn: 352826
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [ELF] A shared object is needed if any of its occurrences is neededFangrui Song2018-12-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Summary: If a DSO appears more than once with and without --as-needed, ld.bfd and gold consider --no-as-needed to takes precedence over --as-needed. lld didn't and this patch makes it do so. This makes it a bit away from the position-dependent behavior (how different occurrences of the same DSO interact) and protects us from some mysterious runtime errors: if some interceptor libraries add their own --no-as-needed dependencies (e.g. librt.so), and the user application specifies -Wl,--as-needed -lrt , the absence of the DT_NEEDED entry would make dlsym(RTLD_NEXT, "clock_gettime") return NULL and would break at runtime. Reviewers: ruiu, espindola Reviewed By: ruiu Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D56089 llvm-svn: 350105
* [ELF] - Make SymbolTable::addDefined return Defined.George Rimar2018-11-221-3/+3
| | | | | | | | | Now it returns Symbol. This should be NFC that avoids doing cast at the caller's sides. Differential revision: https://reviews.llvm.org/D54627 llvm-svn: 347455
* Remove `Type` parameter from SymbolTable::insert(). NFC.Rui Ueyama2018-10-121-3/+2
| | | | | | | | | `Type` parameter was used only to check for TLS attribute mismatch, but we can do that when we actually replace symbols, so we don't need to type as an argument. This change should simplify the interface of the symbol table a bit. llvm-svn: 344394
* Remove SymbolTable::addAbsolute().Rui Ueyama2018-10-111-2/+0
| | | | | | addAbsolute() could be implemented as a non-member function. llvm-svn: 344305
* Rename SymbolTable::addRegular -> SymbolTable::addDefined.Rui Ueyama2018-10-111-1/+1
| | | | | | | We have addAbsolute, addBitcode, addCommon, etc. addRegular looked a bit inconsistent. llvm-svn: 344294
* Remove unused default arguments.Rui Ueyama2018-10-111-3/+1
| | | | llvm-svn: 344292
* Remove SymbolTable::addUndefined<ELF32LE>(StringRef).Rui Ueyama2018-10-111-1/+1
| | | | | | Because we can implement the function as a non-member function. llvm-svn: 344290
* Make a member function private and rename it to avoid function overloading.Rui Ueyama2018-10-101-1/+2
| | | | llvm-svn: 344196
* Change how we handle -wrap.Rui Ueyama2018-08-221-11/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 340387
* Revert r336609: Fix direct calls to __wrap_sym when it is relocated.Rui Ueyama2018-07-181-1/+0
| | | | | | | This reverts commit r336609 as it doesn't seem to work with AArch64 thunk creation when used with ASan. llvm-svn: 337413
* Fix direct calls to __wrap_sym when it is relocated.Rui Ueyama2018-07-091-0/+1
| | | | | | | | | | | | 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 llvm-svn: 336609
* Make fetchIfLazy only fetch an object file. NFC.Rui Ueyama2018-04-031-1/+1
| | | | | | | Previously, fetchIfLazy did more than the name says. Now, setting to UsedInRegularObj is moved to another function. llvm-svn: 329092
* [ELF] - Eliminate Lazy class.George Rimar2018-04-031-1/+2
| | | | | | | | | Patch removes Lazy class which is just an excessive layer. Differential revision: https://reviews.llvm.org/D45083 llvm-svn: 329086
* Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.Rui Ueyama2018-02-281-1/+1
| | | | | | | | | 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 llvm-svn: 326339
* Put undefined symbols from shared libraries in the symbol table.Rafael Espindola2018-02-271-1/+0
| | | | | | | With the recent fixes these symbols have more in common than not with regular undefined symbols. llvm-svn: 326242
* ELF: Stop collecting a list of symbols in ArchiveFile.Peter Collingbourne2018-02-161-2/+2
| | | | | | | | | | | | 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 llvm-svn: 325380
* [ELF] - Remove dead declaration. NFC.George Rimar2018-01-301-1/+0
| | | | llvm-svn: 323747
* Detemplate reportDuplicate.Rafael Espindola2017-12-231-2/+0
| | | | | | | | | | 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. llvm-svn: 321404
* Use a reference in addLazyArchive. NFC.Rafael Espindola2017-12-201-1/+1
| | | | llvm-svn: 321194
* Use a reference for the shared symbol file.Rafael Espindola2017-12-201-1/+1
| | | | | | Every shared symbol has a file, so we can use a reference. llvm-svn: 321187
* Use a reference for a value that is never null. NFC.Rafael Espindola2017-12-201-1/+1
| | | | llvm-svn: 321186
* Use a reference for a value that is never null. NFC.Rafael Espindola2017-12-201-1/+1
| | | | llvm-svn: 321185
* Compact symbols from 96 to 88 bytes.Rafael Espindola2017-12-121-1/+1
| | | | | | | | | | | | 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. llvm-svn: 320449
* Remove some includes from InputFiles.h.Rafael Espindola2017-12-091-0/+2
| | | | | | | They were not used in InputFiles.h and it was getting too easy to add circular includes. llvm-svn: 320256
* Rename `Symtab` private memory to avoid confusion with global `Symtab`Sam Clegg2017-11-271-1/+1
| | | | | | | | | | | 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 llvm-svn: 319113
* Remove IsLocal.Rafael Espindola2017-11-171-3/+2
| | | | | | | Since we always have Binding in the current symbol design IsLocal is redundant. llvm-svn: 318497
* Simplify. NFC.Rafael Espindola2017-11-111-2/+0
| | | | | | copyFrom doesn't copy the Binding, so this was a nop. llvm-svn: 317965
* ELF: Remove SymbolTable::SymIndex class.Peter Collingbourne2017-11-061-7/+1
| | | | | | | | | 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 llvm-svn: 317450
* ELF: Merge DefinedRegular and Defined.Peter Collingbourne2017-11-061-3/+3
| | | | | | | | | Now that DefinedRegular is the only remaining derived class of Defined, we can merge the two classes. Differential Revision: https://reviews.llvm.org/D39667 llvm-svn: 317448
OpenPOWER on IntegriCloud