summaryrefslogtreecommitdiffstats
path: root/lld/ELF/InputFiles.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF2] - Basic implementation of -r/--relocatableGeorge Rimar2016-02-251-1/+4
| | | | | | | | | | | | | -r, -relocatable - Generate relocatable output Currently does not have support for files containing relocation sections with entries that refer to local symbols (like rel[a].eh_frame which refer to sections and not to symbols) Differential revision: http://reviews.llvm.org/D14382 llvm-svn: 261838
* ELF: Do not instantiate InputSectionBase::Discarded.Rui Ueyama2016-02-241-6/+6
| | | | | | | | | | | | | "Discarded" section is a marker for discarded sections, and we do not use the instance except for checking its identity. In that sense, it is just another type of a "null" pointer for InputSectionBase. So, it doesn't have to be a real instance of InputSectionBase class. In this patch, we no longer instantiate Discarded section but instead use -1 as a pointer value. This eliminates a global variable which needed initialization at startup. llvm-svn: 261761
* Handle bitcode files in archive files with --whole-archive.Rui Ueyama2016-02-231-1/+6
| | | | | | | | | | This patch moves BitcodeFile instantiation into createObjectFile. Previously, we handle bitcode files outside that function and did not handle for --whole-archive. http://reviews.llvm.org/D17527 llvm-svn: 261663
* Handle undef symbols in LTO.Rafael Espindola2016-02-191-1/+5
| | | | | | This also handles bc files is archives. llvm-svn: 261374
* Add support for merging strings with alignment larger than one char.Rafael Espindola2016-02-191-7/+7
| | | | | | | | | | | This reduces the .rodata of scyladb from 4501932 to 4334639 bytes (1.038 times smaller). I don't think it is critical to support tail merging, just exact duplicates, but given the code organization it was actually a bit easier to support both. llvm-svn: 261327
* Trying to fix the MSVC build.Rafael Espindola2016-02-121-4/+4
| | | | llvm-svn: 260743
* Try to fix the build in some bots.Rafael Espindola2016-02-121-12/+15
| | | | llvm-svn: 260736
* Add initial LTO support.Rafael Espindola2016-02-121-0/+25
| | | | llvm-svn: 260726
* Sort includes. NFC.Rafael Espindola2016-02-111-1/+1
| | | | llvm-svn: 260528
* Don't push relocation sections onto InputSection<ELFT>::Discarded.RelocSectionsSean Silva2016-02-041-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: LLVM3.3 (and earlier) would fail to include a relocation section in the group that the section it was relocating is in. Object files affected by this issue have been encountered in the wild when using LLD. This would result in a siutation like: Section { Index: 5 Name: .text._Z3fooIiEvv (6) Type: SHT_PROGBITS (0x1) Flags [ (0x206) SHF_ALLOC (0x2) SHF_EXECINSTR (0x4) SHF_GROUP (0x200) ] Address: 0x0 Offset: 0x48 Size: 5 Link: 0 Info: 0 AddressAlignment: 1 EntrySize: 0 } Section { Index: 6 Name: .rela.text._Z3fooIiEvv (1) Type: SHT_RELA (0x4) Flags [ (0x0) ] Address: 0x0 Offset: 0x3F0 Size: 24 Link: 8 Info: 5 AddressAlignment: 8 EntrySize: 24 } In LLD, during symbol resolution, we discard the section containing the weak symbol, but this amounts to replacing it with InputSection<ELFT>::Discarded. When we later saw the corresponding relocation section, we would then end up pusing onto InputSection<ELFT>::Discarded.RelocSections, which is bogus. Reviewers: ruiu, rafael Subscribers: llvm-commits, Bigcheese Differential Revision: http://reviews.llvm.org/D16898 llvm-svn: 259831
* ELF: Include archive names in error messages.Rui Ueyama2016-02-021-2/+5
| | | | | | | | If object files are drawn from archive files, the error message should be something like "conflict symbols in foo.a(bar.o) and baz.o" instead of "conflict symbols in bar.o and baz.o". This patch implements that. llvm-svn: 259475
* ELF: Rename error -> fatal and redefine error as a non-noreturn function.Rui Ueyama2016-01-281-30/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In many situations, we don't want to exit at the first error even in the process model. For example, it is better to report all undefined symbols rather than reporting the first one that the linker picked up randomly. In order to handle such errors, we don't need to wrap everything with ErrorOr (thanks for David Blaikie for pointing this out!) Instead, we can set a flag to record the fact that we found an error and keep it going until it reaches a reasonable checkpoint. This idea should be applicable to other places. For example, we can ignore broken relocations and check for errors after visiting all relocs. In this patch, I rename error to fatal, and introduce another version of error which doesn't call exit. That function instead sets HasError to true. Once HasError becomes true, it stays true, so that we know that there was an error if it is true. I think introducing a non-noreturn error reporting function is by itself a good idea, and it looks to me that this also provides a gradual path towards lld-as-a-library (or at least embed-lld-to-your-program) without sacrificing code readability with lots of ErrorOr's. http://reviews.llvm.org/D16641 llvm-svn: 259069
* Simplify function signature. NFC.Rui Ueyama2016-01-211-4/+3
| | | | | | StringTable is a member variable, so we don't need to pass it around. llvm-svn: 258382
* Fix indentation.Rui Ueyama2016-01-211-1/+1
| | | | llvm-svn: 258374
* Simplify MipsReginfoInputSection.Rui Ueyama2016-01-061-1/+3
| | | | | | | MipsReginfoInputSection is basically just a container of Elf_Mips_Reginfo struct. This patch makes that struct directly accessible from others. llvm-svn: 256984
* Rename GroupEntryType -> uint32_X.Rui Ueyama2016-01-061-6/+5
| | | | | | | GroupEntryType was a 32-bit integral type but that was not obvious from its name. llvm-svn: 256971
* Rename Comdats -> ComdatGroups.Rui Ueyama2016-01-061-4/+4
| | | | | | | I usually prefer short names, but in this case the new descriptive name should improve readability a bit. llvm-svn: 256899
* Rename SharedFile::parse -> SharedFile::parseRest.Rui Ueyama2016-01-061-1/+4
| | | | | | | | | | | | Unlike ObjectFile or ArchiveFile, SharedFile had two parse functions, parseSoName() and parse(). parse must have been called after parseSoName, but that requirement was not obvious from their names. (So it looked like you could call parse() on a shared object file right away.) This patch rename parseRest. It is now obvious that there's no single parse function for the shared object file. llvm-svn: 256898
* Remove redundant this->.Rui Ueyama2016-01-061-16/+15
| | | | llvm-svn: 256894
* Simplify --whole-archive handling.Rui Ueyama2016-01-061-24/+3
| | | | | | | | | | | | | | | | | Previously, we handle archive files with --whole-archive this way: create instances of ArchiveFile, call getMembers to obtain memory buffers of archive members, and create ObjectFiles for the members. We didn't call anything except getMembers if --whole-archive was specified. I noticed that we didn't actually have to create ArchiveFile instaces at all for that case. All we need is to get a list of memory buffers for members, which can be done by a non-member function. This patch removes getMembers member function from ArchiveFile. Also removed unnecessary code for memory management. llvm-svn: 256893
* Do not use templates to instantiate {Object,Shared}Files.Rui Ueyama2016-01-061-7/+9
| | | | | | | createELFFile looked complex because of its use of template, so I want to keep it private within this file. llvm-svn: 256880
* Simplify. NFC.Rui Ueyama2016-01-061-17/+14
| | | | llvm-svn: 256879
* [ELF][MIPS] Implement R_MIPS_GPREL16/R_MIPS_GPREL32 relocationsSimon Atanasyan2015-12-251-2/+8
| | | | | | | | | | | | | | | | | | | | The R_MIPS_GPREL16 / R_MIPS_GPREL32 relocations use the following expressions for calculations: ``` local symbol: S + A + GP0 - GP global symbol: S + A - GP GP - Represents the final gp value, i.e. _gp symbol GP0 - Represents the gp value used to create the relocatable object ``` The GP0 value is taken from the .reginfo data section defined by an object file. To implement that I keep a reference to `MipsReginfoInputSection` in the `ObjectFile` class. This reference is used by the `ObjectFile::getMipsGp0` method to return the GP0 value. Differential Revision: http://reviews.llvm.org/D15760 llvm-svn: 256416
* Make it possible to create common symbols from bitcode.Rafael Espindola2015-12-241-1/+3
| | | | | | | Since the only missing bit was the size, I just replaced the Elf_Sym with the size. llvm-svn: 256384
* Delete DefinedAbsolute.Rafael Espindola2015-12-241-4/+2
| | | | | | | | | | | | | | | | | | | | There are 3 symbol types that a .bc can provide during lto: defined, undefined, common. Defined and undefined symbols have already been refactored. I was working on common and noticed that absolute symbols would become an oddity: They would be the only symbol type present in a .o but not in a.bc. Looking a bit more, other than the special section number they were only used for special rules for computing values. In that way they are similar to TLS, and we don't have a DefinedTLS. This patch deletes it. With it we have a reasonable rule of the thumb for having a symbol kind: It exists if it has special resolution semantics. llvm-svn: 256383
* Split functions and add comments. NFC.Rui Ueyama2015-12-241-17/+29
| | | | llvm-svn: 256369
* Return early and remove a redundant error check. NFC.Rui Ueyama2015-12-241-9/+6
| | | | llvm-svn: 256367
* Add machine type check for MIPS-specific code path.Rui Ueyama2015-12-241-1/+1
| | | | llvm-svn: 256355
* Simplify memory management.Rafael Espindola2015-12-231-2/+0
| | | | | | We no longer need an explicit delete or a polymorphic destructor. llvm-svn: 256333
* Fix the last leak asan found in test/ELF.Rafael Espindola2015-12-231-2/+4
| | | | llvm-svn: 256316
* Fix another asan detected leak.Rafael Espindola2015-12-231-1/+1
| | | | llvm-svn: 256311
* Fix two asan found bugs:Rafael Espindola2015-12-231-0/+2
| | | | | | | We were leaking InputFile subclasses data. UndefinedElf was missing a classof. llvm-svn: 256309
* Split Undefined and UndefinedElf.Rafael Espindola2015-12-221-2/+2
| | | | | | | | | | | | | | | | | | | | | | I am working on adding LTO support to the new ELF lld. In order to do that, it will be necessary to represent defined and undefined symbols that are not from ELF files. One way to do it is to change the symbol hierarchy to look like Defined : SymbolBody Undefined : SymbolBody DefinedElf<ELFT> : Defined UndefinedElf<ELFT> : Undefined Another option would be to use bogus Elf_Sym, but I think that is getting a bit too hackish. This patch does the Undefined/UndefinedElf. Split. The next one will do the Defined/DefinedElf split. llvm-svn: 256289
* [ELF][MIPS] MIPS .reginfo sections handlingSimon Atanasyan2015-12-201-0/+3
| | | | | | | | | | | | | | | | | | | | | MIPS .reginfo section provides information on the registers used by the code in the object file. Linker should collect this information and write .reginfo section in the output file. This section contains a union of used registers masks taken from input .reginfo sections and final value of the `_gp` symbol. For details see the "Register Information" section in Chapter 4 in the following document: ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf The patch implements .reginfo sections handling with a couple missed features: a) it does not put output .reginfo section into the separate REGINFO segment; b) it does not merge `ri_cprmask` masks from input section. These features will be implemented later. Differential Revision: http://reviews.llvm.org/D15669 llvm-svn: 256119
* ELF: Avoid string concatenation if there's no error.Rui Ueyama2015-12-171-6/+8
| | | | llvm-svn: 255870
* Revert "ELF: Make .note.GNU-stack more compatible with traditional linkers."Rui Ueyama2015-11-241-9/+4
| | | | | | | This reverts commit r253797 because it was based on a misunderstanding that lld wouldn't work on NetBSD without this change. llvm-svn: 254003
* ELF: Make .note.GNU-stack more compatible with traditional linkers.Rui Ueyama2015-11-211-6/+11
| | | | | | | | | | | | | With this patch, lld creates PT_GNU_STACK segments only when all input files have .note.GNU-stack sections. This is in line with other linkers with a minor difference (we don't care about .note.GNU-stack rwx bits as you can always remove .note.GNU-stack sections instead of setting x bit.) At least, NetBSD loader does not understand PT_GNU_STACK segments and reject any executables that have the section. This patch makes lld compatible with such operating systems. llvm-svn: 253797
* Remove redundant namespace specifiers.Rui Ueyama2015-11-201-27/+25
| | | | llvm-svn: 253635
* Make a function out-of-line.Rui Ueyama2015-11-201-0/+8
| | | | | | There's no need to write it in a .h file. llvm-svn: 253633
* Remove redundant "using namespace".Rui Ueyama2015-11-201-2/+0
| | | | llvm-svn: 253632
* [ELF2] - Implemented PT_GNU_STACK support, -z execstack option.George Rimar2015-11-141-1/+3
| | | | | | | | | | PT_GNU_STACK is a entry in the elf file format which contains the access rights (read, write, execute) of the stack, it is always generated now. By default stack is not executable in this implementation. -z execstack can be used to make executable. Differential revision: http://reviews.llvm.org/D14571 llvm-svn: 253145
* Add support for processing .eh_frame.Rafael Espindola2015-11-111-4/+14
| | | | | | | | | | | | | This adds support for: * Uniquing CIEs * Dropping FDEs that point to dropped sections It drops 657 488 bytes from the .eh_frame of a Release+Asserts clang. The link time impact is smallish. Linking clang with a Release+Asserts lld goes from 0.488064805 seconds to 0.504763060 seconds (1.034 X slower). llvm-svn: 252790
* [ELF2] - Fixed crash for case when section sh_entsize is set to zero for ↵George Rimar2015-11-091-1/+1
| | | | | | | | SHF_MERGE type of sections. Differential revision: http://reviews.llvm.org/D14451 llvm-svn: 252454
* These are the matching changes needed to the lld project for the changes to llvmKevin Enderby2015-11-051-1/+4
| | | | | | | in r252192 that changed the Archive and Child interfaces in libObject. These include Rafael Espindola’s many suggested updates. llvm-svn: 252193
* Avoid implicit Archive::child_iterator construction.Rafael Espindola2015-11-051-5/+5
| | | | llvm-svn: 252167
* Two small fixes to copy relocation processing.Rafael Espindola2015-11-031-11/+43
| | | | | | | * We can determine the alignment requirement. * We have to update the bss alignment with it. llvm-svn: 251914
* Add support for merging string from SHF_STRINGS sections.Rafael Espindola2015-10-241-8/+30
| | | | llvm-svn: 251212
* ELF2: Implement --gc-sections.Rui Ueyama2015-10-221-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | Section garbage collection is a feature to remove unused sections from outputs. Unused sections are sections that cannot be reachable from known GC-root symbols or sections. Naturally the feature is implemented as a mark-sweep garbage collector. In this patch, I added Live bit to InputSectionBase. If and only if Live bit is on, the section will be written to the output. Starting from GC-root symbols or sections, a new function, markLive(), visits all reachable sections and sets their Live bits. Writer then ignores sections whose Live bit is off, so that such sections are excluded from the output. This change has small negative impact on performance if you use the feature because making sections means more work. The time to link Clang changes from 0.356s to 0.386s, or +8%. It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes. That is 4.3% reduction. http://reviews.llvm.org/D13950 llvm-svn: 251043
* Add support for merging the contents of SHF_MERGE sections.Rafael Espindola2015-10-191-6/+18
| | | | | | For now SHF_STRINGS are not supported. llvm-svn: 250737
* Add a ObjectFile<ELFT>::getSection helper and simplify. NFC.Rafael Espindola2015-10-161-10/+17
| | | | llvm-svn: 250519
OpenPOWER on IntegriCloud