summaryrefslogtreecommitdiffstats
path: root/lld/ELF/InputSection.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] Generalize symbol type handling.Davide Italiano2016-03-041-1/+1
| | | | | | | | | | | | | | | SymbolBody constructor and friends take isFunc and isTLS boolean arguments. ELF symbols have already a type so than be easily passed as argument. If we want to support another type, this scheme is not good enough, that is, the current code logic would require passing another `bool isObject` around. Up to two argument, this stretching exercise was a little bit goofy but still acceptable, but with more types to support, is just too much, IMHO. Change the code so that the type is passed instead. Differential Revision: http://reviews.llvm.org/D17871 llvm-svn: 262684
* Rename 'fatal' to 'check' when it doesn't always fail.Rafael Espindola2016-03-031-2/+2
| | | | llvm-svn: 262666
* Simplify error handling.Rafael Espindola2016-03-031-7/+2
| | | | | | | This makes fatal return T when there is no error. This avoids the need for quite a few temporaries. llvm-svn: 262626
* [ELF] - add support for relocations against local symbols when producing ↵George Rimar2016-03-031-5/+9
| | | | | | | | | | | | | relocatable output. There was a known limitation for -r option: relocations against local symbols were not supported. For example rel[a].eh_frame sections contained relocations against sections and that was not supported for -r before. Patch fixes that. Differential review: http://reviews.llvm.org/D17813 llvm-svn: 262590
* Rename elf2 to elf.Rafael Espindola2016-02-281-25/+25
| | | | llvm-svn: 262159
* Refactor multiple calls to canBePreempted.Rafael Espindola2016-02-261-2/+3
| | | | llvm-svn: 262018
* Fix some confusion about what can be preempted.Rafael Espindola2016-02-261-2/+2
| | | | | | | | | | | For shared libraries we allow any weak undefined symbol to eventually be resolved, even if we never see a definition in another .so. This matches the behavior when handling other undefined symbols in a shared library. For executables, we require seeing a definition in a .so or resolve it to zero. This is also similar to how non weak symbols are handled. llvm-svn: 262017
* [ELF][MIPS] Calculate combined addend for R_MIPS_GOT16 against local symbolSimon Atanasyan2016-02-251-15/+38
| | | | | | | | | | | R_MIPS_GOT16 relocation against local symbol requires index of a local GOT entry which contains page address corresponds to sum of the symbol address and addend. The addend in that case is calculated using addends from the R_MIPS_GOT16 and paired R_MIPS_LO16 relocations. Differential Revision: http://reviews.llvm.org/D17610 llvm-svn: 261930
* ELF: Implement ICF.Rui Ueyama2016-02-251-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements the same algorithm as LLD/COFF's ICF. I'm not going to repeat the same description about how it works, so you want to read the comment in ICF.cpp in this patch if you want to know the details. This algorithm should be more powerful than the ICF algorithm implemented in GNU gold. It can even merge mutually-recursive functions (which is harder than one might think). ICF is a fairly effective size optimization. Here are some examples. LLD: 37.14 MB -> 35.80 MB (-3.6%) Clang: 59.41 MB -> 57.80 MB (-2.7%) The lacking feature is "safe" version of ICF. This merges all identical sections. That is not compatible with a C/C++ language requirement that two distinct functions must have distinct addresses. But as long as your program do not rely on the pointer equality (which is in many cases true), your program should work with the feature. LLD works fine for example. GNU gold implements so-called "safe ICF" that identifies functions that are safe to merge by heuristics -- for example, gold thinks that constructors are safe to merge because there is no way to take an address of a constructor in C++. We have a different idea which David Majnemer suggested that we add NOPs at beginning of merged functions so that two or more pointers can have distinct values. We can do whichever we want, but this patch does not include neither. http://reviews.llvm.org/D17529 llvm-svn: 261912
* [ELF2] - Basic implementation of -r/--relocatableGeorge Rimar2016-02-251-1/+50
| | | | | | | | | | | | | -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-5/+2
| | | | | | | | | | | | | "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
* Move target independent code out of x86_64 only path.Rafael Espindola2016-02-241-1/+1
| | | | | | | The logic for deciding if an undefined symbol should have the value of a got entry is not target specific. llvm-svn: 261760
* ELF: Remove InputSectionBase::getAlign and instead add Align member.Rui Ueyama2016-02-241-0/+5
| | | | | | | | | This is a preparation for ICF. If we merge two sections, we want to align the merged section at the largest alignment requirement. That means we want to update the alignment value, which was impossible before this patch because Header is a const value. llvm-svn: 261712
* ELF: Remove InputSectionBase::isLive and use Live member instead. NFC.Rui Ueyama2016-02-241-1/+7
| | | | | | This is also a preparation for ICF. llvm-svn: 261711
* ELF: Make some functions constant. NFC.Rui Ueyama2016-02-241-2/+2
| | | | | | This is a preparation for ICF. llvm-svn: 261710
* Simplify. NFC.Rafael Espindola2016-02-231-1/+1
| | | | llvm-svn: 261668
* Remove a trivial getter.Rafael Espindola2016-02-221-1/+1
| | | | llvm-svn: 261590
* Fixed comments formatting. NFC.George Rimar2016-02-181-1/+1
| | | | llvm-svn: 261214
* ELF: Make names for TLS module indices shorter.Rui Ueyama2016-02-051-1/+1
| | | | | | | | | | The previous names contained "Local" and "Current", but what we are handling is always local and current, so they were redundant. TlsIndex comes from "tls_index" struct that Ulrich Drepper is using in this document to describe this data structure in GOT. llvm-svn: 259852
* [ELF][MIPS] Add handling for __gnu_local_gp symbolSimon Atanasyan2016-02-041-0/+2
| | | | | | | This symbol is a "fake" symbol like "_gp_disp" and denotes the GOT + 0x7FF0 value. llvm-svn: 259781
* [ELF][MIPS] Replace needsMipsLocalGot function by canBePreemptedSimon Atanasyan2016-02-041-1/+1
| | | | | | | Symbol does not need an entry i the 'global' part of GOT if it cannot be preempted. So canBePreempted fully satisfies us at least for now. llvm-svn: 259779
* Define SymbolBody::getSize instead of getSymSize(SymbolBody&). NFC.Rui Ueyama2016-02-031-9/+1
| | | | llvm-svn: 259613
* ELF: Teach SymbolBody about how to get its addresses.Rui Ueyama2016-02-011-5/+5
| | | | | | | | | | | | | Previously, the methods to get symbol addresses were somewhat scattered in many places. You can use getEntryAddr returns the address of the symbol, but if you want to get the GOT address for the symbol, you needed to call Out<ELFT>::Got->getEntryAddr(Sym). This change adds new functions, getVA, getGotVA, getGotPltVA, and getPltVA to SymbolBody, so that you can use SymbolBody as the central place to ask about symbols. http://reviews.llvm.org/D16710 llvm-svn: 259404
* ELF: Make Target's member function names shorter.Rui Ueyama2016-01-291-9/+8
| | | | llvm-svn: 259147
* ELF: Remove accessors from Target.Rui Ueyama2016-01-291-1/+1
| | | | | | These accessors do not provide values. We can simply make the variables public. llvm-svn: 259141
* Rename isTlsOptimized -> canRelaxTls.Rui Ueyama2016-01-291-3/+3
| | | | | | | | This function is a predicate that a given relocation can be relaxed. The previous name implied that it returns true if a given relocation has already been optimized away. llvm-svn: 259128
* ELF: Rename error -> fatal and redefine error as a non-noreturn function.Rui Ueyama2016-01-281-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove unnecessary object:: prefix.Rafael Espindola2016-01-221-24/+24
| | | | llvm-svn: 258563
* [ELF] - fix possible UB when dereferencing nullGeorge Rimar2016-01-221-1/+1
| | | | | | | | | In InputSection.cpp it was possible to dereference null. Had to change signature of relocateTlsOptimize to accept pointer instead of reference. Differential revision: http://reviews.llvm.org/D16466 llvm-svn: 258508
* Style change. NFC.Rui Ueyama2016-01-211-28/+24
| | | | llvm-svn: 258427
* [ELF][MIPS] Initial support of MIPS local GOT entriesSimon Atanasyan2016-01-211-7/+19
| | | | | | | | | | | | | | | | | | | | | | | | Some MIPS relocation (for now R_MIPS_GOT16) requires creation of GOT entries for symbol not included in the dynamic symbol table. They are local symbols and non-local symbols with 'local' visibility. Local GOT entries occupy continuous block between GOT header and regular GOT entries. The patch adds initial support for handling local GOT entries. The main problem is allocating local GOT entries for local symbols. Such entries should be initialized by high 16-bit of the symbol value. In ideal world there should be no duplicated entries with the same values. But at the moment of the `Writer::scanRelocs` call we do not know a value of the symbol. In this patch we create new local GOT entry for each relocation against local symbol, though we can exhaust GOT quickly. That needs to be optimized later. When we calculate relocation we know a final symbol value and request local GOT entry index. To do that we maintain map between addresses and local GOT entry indexes. If we start to calculate relocations in parallel we will have to serialize access to this map. Differential Revision: http://reviews.llvm.org/D16324 llvm-svn: 258388
* ELF: Remove dead code.Rui Ueyama2016-01-081-1/+0
| | | | | | | | | | R_X86_64_PLT32 is handled in the same way as R_X86_64_PC32 by relocateOne(), so this function does not seems to be needed. Without this code, all tests still pass. http://reviews.llvm.org/D15971 llvm-svn: 257203
* ELF: Simplify Target::isSizeReloc and add comments.Rui Ueyama2016-01-081-2/+7
| | | | | | | | All non-trivial relocation decisions need explanations like this to help readers understand not only how relocations are handled but why they are handled these ways. This is a start. llvm-svn: 257119
* Simplify MipsReginfoInputSection.Rui Ueyama2016-01-061-14/+5
| | | | | | | MipsReginfoInputSection is basically just a container of Elf_Mips_Reginfo struct. This patch makes that struct directly accessible from others. llvm-svn: 256984
* Add llvm_unreachable to unreachable code.Rui Ueyama2016-01-061-1/+3
| | | | | | The original code was an infinite recursion when the control reaches there. llvm-svn: 256981
* [ELF][MIPS] Implement R_MIPS_GPREL16/R_MIPS_GPREL32 relocationsSimon Atanasyan2015-12-251-0/+13
| | | | | | | | | | | | | | | | | | | | 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
* [ELF] - Fixed handling relocations against zero sized .eh_frame section.George Rimar2015-12-251-0/+5
| | | | | | | | | | The file crtbeginT.o has relocations pointing to the start of an empty .eh_frame that is known to be the first in the link. It does that to identify the start of the output .eh_frame. Handle this special case. Differential revision: http://reviews.llvm.org/D15610 llvm-svn: 256414
* Delete DefinedAbsolute.Rafael Espindola2015-12-241-1/+1
| | | | | | | | | | | | | | | | | | | | 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
* Mark .eh_frame sections as live by default. NFC.Rui Ueyama2015-12-241-1/+6
| | | | | | | This change eliminates a string comparison from the garbage collector. llvm-svn: 256378
* Split Defined and DefinedElf.Rafael Espindola2015-12-241-1/+1
| | | | | | | This is similar to what was done for Undefined and opens the way for having a symbol defined in bitcode. llvm-svn: 256354
* [ELF] - fixed not properly handled @GOTTPOFF relocation against local symbolsGeorge Rimar2015-12-211-33/+39
| | | | | | | | | | | | | | This patch changes sequence of applying relocations, moving tls optimized relocation handling code before code for other locals. Without that change relocation @GOTTPOFF against local symbol caused runtime error ("unrecognized reloc ..."). That change also should fix other tls optimized relocations, but I did not check them, that's a field for another patch. R_X86_64_GOTTPOFF relocations against locals can be found when linking against libc.a(malloc.o): 000000000036 000600000016 R_X86_64_GOTTPOFF 0000000000000000 libc_tsd_MALLOC - 4 000000000131 000600000016 R_X86_64_GOTTPOFF 0000000000000000 libc_tsd_MALLOC - 4 Differential revision: http://reviews.llvm.org/D15581 llvm-svn: 256145
* [ELF][MIPS] MIPS .reginfo sections handlingSimon Atanasyan2015-12-201-0/+25
| | | | | | | | | | | | | | | | | | | | | 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] - implemented @indntpoff (x86) relocation and its optimization.George Rimar2015-12-171-2/+2
| | | | | | | | | | @indntpoff is similar to @gotntpoff, but for use in position dependent code. While @gotntpoff resolves to GOT slot address relative to the start of the GOT in the movl or addl instructions, @indntpoff resolves to the absolute GOT slot address. ("ELF Handling For Thread-Local Storage", Ulrich Drepper). Differential revision: http://reviews.llvm.org/D15494 llvm-svn: 255884
* ELF: Rename relocNeedsCopy -> needsCopyRelRui Ueyama2015-12-171-1/+1
| | | | | | Just "copy" was a bit too ambiguous to say about copy relocations. llvm-svn: 255866
* ELF: Rename isTLS -> isTls for consistency.Rui Ueyama2015-12-171-1/+1
| | | | llvm-svn: 255855
* [ELF][MIPS] Handle R_MIPS_HI16/LO16 relocations against _gp_disp symbolSimon Atanasyan2015-12-161-0/+5
| | | | | | | | | | | | The `_gp_disp` is a magic symbol designates offset between start of function and gp pointer into GOT. Only `R_MIPS_HI16` and `R_MIPS_LO16` relocations are permitted with `_gp_disp`. The patch adds the `_gp_disp` as an ignored symbol and adjusts symbol value before call the `relocateOne` for `R_MIPS_HI16/LO16` relocations. Differential Revision: http://reviews.llvm.org/D15480 llvm-svn: 255768
* [ELF][MIPS] Match paired relocation using relocation type and symbol indexSimon Atanasyan2015-12-131-3/+6
| | | | | | | If we have R_MIPS_HI16 relocation, the paired relocation is the next R_MIPS_LO16 relocation with the same symbol as a target. llvm-svn: 255452
* [ELF] - R_X86_64_SIZE64/R_X86_64_SIZE32 relocations implemented.George Rimar2015-12-111-4/+14
| | | | | | | | | | | | R_X86_64_SIZE64/R_X86_64_SIZE32 relocations were introduced in 0.98v of "System V Application Binary Interface x86-64" (http://www.x86-64.org/documentation/abi.pdf). Calculation for them is Z + A, where: Z - Represents the size of the symbol whose index resides in the relocation entry. A - Represents the addend used to compute the value of the relocatable field. Differential revision: http://reviews.llvm.org/D15335 llvm-svn: 255332
* [ELF] - Implemented @tlsgd optimization (GD->IE case, x64).George Rimar2015-12-041-2/+5
| | | | | | | | | "Ulrich Drepper, ELF Handling For Thread-Local Storage" (5.5 x86-x64 linker optimizations, http://www.akkadia.org/drepper/tls.pdf) shows how GD can be optimized to IE. This patch implements the optimization. Differential revision: http://reviews.llvm.org/D15000 llvm-svn: 254713
* [ELF] MIPS paired R_MIPS_HI16/LO16 relocations supportSimon Atanasyan2015-12-011-5/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Some MIPS relocations including `R_MIPS_HI16/R_MIPS_LO16` use combined addends. Such addend is calculated using addends of both paired relocations. Each `R_MIPS_HI16` relocation is paired with the next `R_MIPS_LO16` relocation. ABI requires to compute such combined addend in case of REL relocation record format only. For details see p. 4-17 at ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf This patch implements lookup of the next paired relocation suing new `InputSectionBase::findPairedRelocLocation` method. The primary disadvantage of this approach is that we put MIPS specific logic into the common code. The next disadvantage is that we lookup `R_MIPS_LO16` for each `R_MIPS_HI16` relocation, while in fact multiple `R_MIPS_HI16` might be paired with the single `R_MIPS_LO16`. From the other side this way allows us to keep `MipsTargetInfo` class stateless and implement later relocation handling in parallel. This patch does not support `R_MIPS_HI16/R_MIPS_LO16` relocations against `_gp_disp` symbol. In that case the relocations use a special formula for the calculation. That will be implemented later. Differential Revision: http://reviews.llvm.org/D15112 llvm-svn: 254461
OpenPOWER on IntegriCloud