summaryrefslogtreecommitdiffstats
path: root/lld/ELF/InputFiles.h
Commit message (Collapse)AuthorAgeFilesLines
...
* Add --warn-backrefs to maintain compatibility with other linkersRui Ueyama2018-04-091-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm proposing a new command line flag, --warn-backrefs in this patch. The flag and the feature proposed below don't exist in GNU linkers nor the current lld. --warn-backrefs is an option to detect reverse or cyclic dependencies between static archives, and it can be used to keep your program compatible with GNU linkers after you switch to lld. I'll explain the feature and why you may find it useful below. lld's symbol resolution semantics is more relaxed than traditional Unix linkers. Therefore, ld.lld foo.a bar.o succeeds even if bar.o contains an undefined symbol that have to be resolved by some object file in foo.a. Traditional Unix linkers don't allow this kind of backward reference, as they visit each file only once from left to right in the command line while resolving all undefined symbol at the moment of visiting. In the above case, since there's no undefined symbol when a linker visits foo.a, no files are pulled out from foo.a, and because the linker forgets about foo.a after visiting, it can't resolve undefined symbols that could have been resolved otherwise. That lld accepts more relaxed form means (besides it makes more sense) that you can accidentally write a command line or a build file that works only with lld, even if you have a plan to distribute it to wider users who may be using GNU linkers. With --check-library-dependency, you can detect a library order that doesn't work with other Unix linkers. The option is also useful to detect cyclic dependencies between static archives. Again, lld accepts ld.lld foo.a bar.a even if foo.a and bar.a depend on each other. With --warn-backrefs it is handled as an error. Here is how the option works. We assign a group ID to each file. A file with a smaller group ID can pull out object files from an archive file with an equal or greater group ID. Otherwise, it is a reverse dependency and an error. A file outside --{start,end}-group gets a fresh ID when instantiated. All files within the same --{start,end}-group get the same group ID. E.g. ld.lld A B --start-group C D --end-group E A and B form group 0, C, D and their member object files form group 1, and E forms group 2. I think that you can see how this group assignment rule simulates the traditional linker's semantics. Differential Revision: https://reviews.llvm.org/D45195 llvm-svn: 329636
* [ELF] - Eliminate Lazy class.George Rimar2018-04-031-1/+0
| | | | | | | | | Patch removes Lazy class which is just an excessive layer. Differential revision: https://reviews.llvm.org/D45083 llvm-svn: 329086
* Merge LazyArchive::fetch() and ArchiveFile::getMember(). NFC.Rui Ueyama2018-04-031-5/+5
| | | | | | | | They are to pull out an object file for a symbol, but for a historical reason the code is written in two separate functions. This patch merges them. llvm-svn: 329039
* Re-implement --just-symbols as a regular object file.Rui Ueyama2018-03-301-3/+4
| | | | | | | | | | | | I tried a few different designs to find a way to implement it without too much hassle and settled down with this. Unlike before, object files given as arguments for --just-symbols are handled as object files, with an exception that their section tables are handled as if they were all null. Differential Revision: https://reviews.llvm.org/D42025 llvm-svn: 328852
* Rename NonLocal -> Global.Rui Ueyama2018-03-281-1/+1
| | | | | | | | NonLocal is technically more accurate, but we already use the term "Global" to specify the non-local part of the symbol table, and Local <-> Global is easier to digest. llvm-svn: 328740
* Strip @VER suffices from the LTO output.Rafael Espindola2018-03-281-0/+1
| | | | | | | | | | | | | | | This fixes pr36623. The problem is that we have to parse versions out of names before LTO so that LTO can use that information. When we get the LTO produced .o files, we replace the previous symbols with the LTO produced ones, but they still have @ in their names. We could just trim the name directly, but calling parseSymbolVersion to do it is simpler. llvm-svn: 328738
* Refactor SharedFile::parseRest. NFC.Rui Ueyama2018-03-261-1/+3
| | | | | | | | | SharedFile::parseRest function grew organically and got a bit hard to understand. This patch refactor it. This patch also adds comments. Differential Revision: https://reviews.llvm.org/D44860 llvm-svn: 328579
* Fix PR36793.Rafael Espindola2018-03-231-1/+4
| | | | | | | With this patch lld will iterate over compile units to find the line tables instead of assuming there is only one at offset 0. llvm-svn: 328284
* Replace a std::pair with a struct.Rafael Espindola2018-03-211-1/+5
| | | | | | This is more readable and should reduce the noise in a followup patch. llvm-svn: 328164
* Simplify LazyobjFile and readElfSymbols.Rui Ueyama2018-03-081-3/+1
| | | | | | | | | | addElfSymbols and readJustSymbolsFile still has duplicate code, but I didn't come up with a good idea to eliminate them. Since this patch is an improvement, I'm sending this for review. Differential Revision: https://reviews.llvm.org/D44187 llvm-svn: 326972
* Implement --just-symbols.Rui Ueyama2018-03-061-0/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D39348 llvm-svn: 326835
* Put undefined symbols from shared libraries in the symbol table.Rafael Espindola2018-02-271-8/+0
| | | | | | | With the recent fixes these symbols have more in common than not with regular undefined symbols. llvm-svn: 326242
* [ELF] Create and export symbols provided by a linker script if they ↵Igor Kudrin2018-02-271-3/+8
| | | | | | | | | | | referenced by DSOs. It should be possible to resolve undefined symbols in dynamic libraries using symbols defined in a linker script. Differential Revision: https://reviews.llvm.org/D43011 llvm-svn: 326176
* Consistent (non) use of empty lines in include blocksSam Clegg2018-02-201-2/+0
| | | | | | | | | The profailing style in lld seem to be to not include such empty lines. Clang-tidy/clang-format seem to handle this just fine. Differential Revision: https://reviews.llvm.org/D43528 llvm-svn: 325629
* ELF: Stop collecting a list of symbols in ArchiveFile.Peter Collingbourne2018-02-161-1/+1
| | | | | | | | | | | | 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] Fix use after free in case of using --whole-archive.Igor Kudrin2018-02-161-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D34554 llvm-svn: 325313
* [ELF] - Report valid binary filename when reporting error.George Rimar2018-02-051-2/+2
| | | | | | | | | | We did not report valid filename for duplicate symbol error when symbol came from binary input file. Patch fixes it. Differential revision: https://reviews.llvm.org/D42635 llvm-svn: 324217
* Detemplate reportDuplicate.Rafael Espindola2017-12-231-1/+4
| | | | | | | | | | 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
* Detemplate isCompatible(). NFC.Rafael Espindola2017-12-231-4/+6
| | | | llvm-svn: 321393
* Inline a small function.Rui Ueyama2017-12-131-1/+0
| | | | | | Differential Revision: https://reviews.llvm.org/D41204 llvm-svn: 320652
* Make a method private. NFC.Rafael Espindola2017-12-131-2/+1
| | | | llvm-svn: 320542
* Compact symbols from 96 to 88 bytes.Rafael Espindola2017-12-121-0/+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-2/+1
| | | | | | | They were not used in InputFiles.h and it was getting too easy to add circular includes. llvm-svn: 320256
* Consistent use of <internal> when displaying internal symbol namesSam Clegg2017-11-271-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40510 llvm-svn: 319108
* Simplify as-needed handling.Rafael Espindola2017-11-221-3/+1
| | | | | | This is a reduction of a patch by Rui Ueyama. llvm-svn: 318852
* Rename SymbolBody -> SymbolRui Ueyama2017-11-031-9/+8
| | | | | | | | | | | | | 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 llvm-svn: 317370
* [ELF] - Teach LLD to report line numbers for data symbols.George Rimar2017-11-011-1/+3
| | | | | | | | | | | | | | | | | | | This is PR34826. Currently LLD is unable to report line number when reporting duplicate declaration of some variable. That happens because for extracting line information we always use .debug_line section content which describes mapping from machine instructions to source file locations, what does not help for variables as does not describe them. In this patch I am taking the approproate information about variables locations from the .debug_info section. Differential revision: https://reviews.llvm.org/D38721 llvm-svn: 317080
* Pass symbol attributes instead of ElfSym to Shared symbol ctor.Rui Ueyama2017-10-281-2/+1
| | | | | | | This change allows us to use less templates for Shared symbol and the functions that deals with shared symbols. llvm-svn: 316841
* [lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman2017-10-251-1/+1
| | | | | | | | | | | | | | | | | | | Summary: The COFF linker and the ELF linker have long had similar but separate Error.h and Error.cpp files to implement error handling. This change introduces new error handling code in Common/ErrorHandler.h, changes the COFF and ELF linkers to use it, and removes the old, separate implementations. Reviewers: ruiu Reviewed By: ruiu Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits Differential Revision: https://reviews.llvm.org/D39259 llvm-svn: 316624
* Update for llvm change.Rafael Espindola2017-10-101-1/+1
| | | | llvm-svn: 315377
* Move new lld's code to Common subdirectory.Rui Ueyama2017-10-021-2/+2
| | | | | | | | | | New lld's files are spread under lib subdirectory, and it isn't easy to find which files are actually maintained. This patch moves maintained files to Common subdirectory. Differential Revision: https://reviews.llvm.org/D37645 llvm-svn: 314719
* [ELF] - Introduce std::vector<InputFile *> global arrays.George Rimar2017-09-191-11/+5
| | | | | | | | | | | | This patch removes lot of static Instances arrays from different input file classes and introduces global arrays for access instead. Similar to arrays we have for InputSections/OutputSectionCommands. It allows to iterate over input files in a non-templated code. Differential revision: https://reviews.llvm.org/D35987 llvm-svn: 313619
* Rename {Lazy,}ObjectKind -> {Lazy,}ObjKind.Rui Ueyama2017-08-191-12/+8
| | | | | | | I renamed corresponding classes in r309199 but forgot to rename enums at the moment. Rename them now to make them consistent. llvm-svn: 311214
* [ELF] - Move getSymbols() methods to InputFile.George Rimar2017-08-041-12/+11
| | | | | | | | It can help to detemplate code. Differential revision: https://reviews.llvm.org/D35936 llvm-svn: 310049
* Use more consistent namesRafael Espindola2017-08-021-8/+8
| | | | | | | | | | | | | | | | | | | | Reviewing another change I noticed that we use "getSymbols" to mean different things in different files. Depending on the file it can return ArrayRef<StringRef> ArrayRef<SymbolBody*> ArrayRef<Symbol*> ArrayRef<Elf_Sym> With this change it always returns an ArrayRef<SymbolBody*>. The other functions are renamed getELFsyms() and getSymbolNames(). Note that we cannot return ArrayRef<Symbol*> instead of ArreyRef<SymbolBody*> because local symbols have a SymbolBody but not a Symbol. llvm-svn: 309840
* Rename ObjectFile -> ObjFile.Rui Ueyama2017-07-261-10/+9
| | | | | | | Rename it because it was too easy to conflict with llvm::object::ObjectFile which broke buildbots several times. llvm-svn: 309199
* Detemplate SymbolTable.Rafael Espindola2017-07-261-0/+12
| | | | | | NFC, just makes it easier to access from non templated code. llvm-svn: 309152
* [ELF] Avoid data race in ObjectFile<ELFT>::getDILineInfo().Igor Kudrin2017-07-211-0/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D35537 llvm-svn: 308728
* Speed up gdb index creation.Rafael Espindola2017-07-191-0/+1
| | | | | | | | | | | With that in place we can use lld's own infrastructure for the low level detail of dwarf parsing. With this we don't decompress sections twice, we don't scan all realocations and even with this simplistic implementation linking clang with gdb index goes from 34.09 seconds to 20.80 seconds. llvm-svn: 308544
* [ELF] - Apply clang-format. NFC.George Rimar2017-07-181-2/+2
| | | | llvm-svn: 308297
* Implement the --exclude-libs option.Rui Ueyama2017-06-211-0/+2
| | | | | | | | | 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 llvm-svn: 305920
* Allow the GNU gold-style nonstandard SHT_GROUP section.Rui Ueyama2017-06-121-2/+5
| | | | | | | | | | | | | | | | | | | | | The ELF standard defines that the SHT_GROUP section as follows: - its sh_link has the symbol index, and - the symbol name is used to uniquify section groups. Object files created by GNU gold does not seem to comply with the standard. They have this additional rule: - if the symbol has no name and a STT_SECTION symbol, a section name is used instead of a symbol name. If we don't do anything for this, the linker fails with a mysterious error message if input files are generated by gas. It is unfortunate but I think we need to support it. Differential Revision: https://reviews.llvm.org/D34064 llvm-svn: 305218
* Revert "Simplify a variable type by using StringRef instead of ↵Rafael Espindola2017-05-251-3/+6
| | | | | | | | | | | CachedHashStringRef." This reverts commit r303787. It caused a slowdown in fast links. That is, links with no debug info or optimizations. llvm-svn: 303925
* Simplify a variable type by using StringRef instead of CachedHashStringRef.Rui Ueyama2017-05-241-6/+3
| | | | | | | | | | 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. llvm-svn: 303787
* Remove redundant `explicit`.Rui Ueyama2017-05-051-2/+2
| | | | llvm-svn: 302273
* Remember OffsetInArchive in LazyObjectFile.Rafael Espindola2017-05-051-2/+4
| | | | | | | LazyObjectFile might turn out to be a BitcodeFile, so we need OffsetInArchive. llvm-svn: 302242
* Remember archive name when creating LazyObjectFile.Rafael Espindola2017-05-051-1/+4
| | | | | | | | It is needed for creating an unique identifier for ThinLTO. This fixes pr32931. llvm-svn: 302235
* Reduce code duplication. NFC.Rafael Espindola2017-05-041-0/+1
| | | | llvm-svn: 302155
* Accept archive files with no symbol table instad of warning on them.Rui Ueyama2017-05-031-1/+1
| | | | | | | | | | | | | It seems virtually everyone who tries to do LTO build with Clang and LLD was hit by a mistake to forget using llvm-ar command to create archive files. I wasn't an exception. Since this is an annoying common issue, it is probably better to handle that gracefully rather than reporting an error and tell the user to redo build with different configuration. Differential Revision: https://reviews.llvm.org/D32721 llvm-svn: 302083
* Removes createELFFile which takes a template class as a template parameter.Rui Ueyama2017-04-261-1/+1
| | | | | | | | | This patch is to reduce amount of template uses. The new code is less exciting and boring than before, but I think it is easier to read. Differential Revision: https://reviews.llvm.org/D32467 llvm-svn: 301488
OpenPOWER on IntegriCloud