summaryrefslogtreecommitdiffstats
path: root/lld/ELF/OutputSections.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* ELF: Rename error -> fatal and redefine error as a non-noreturn function.Rui Ueyama2016-01-281-21/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Do not use return with a function whose return type is void.Rui Ueyama2016-01-271-5/+7
| | | | | | | Although it is syntactically correct, it is a bit confusing, and not necessary here. llvm-svn: 258996
* Remove another case of almost duplicated code.Rafael Espindola2016-01-271-54/+8
| | | | | | | Were had very similar code for deciding to keep a local symbol and for actually writing it. llvm-svn: 258958
* Remove redundant variable.Rafael Espindola2016-01-271-2/+0
| | | | llvm-svn: 258940
* Simplify. NFC.Rui Ueyama2016-01-261-5/+5
| | | | llvm-svn: 258795
* Simplify. NFC.Rui Ueyama2016-01-261-15/+9
| | | | | | This new code should be logically equivalent to the previous code. llvm-svn: 258792
* Add missing template instantiations.Rui Ueyama2016-01-261-16/+24
| | | | llvm-svn: 258767
* Fix MSVC build.Rafael Espindola2016-01-261-2/+2
| | | | llvm-svn: 258766
* Move code to create RELATIVE reloc for TLS_IE to one place.Rui Ueyama2016-01-261-3/+10
| | | | llvm-svn: 258760
* ELF: Move code for GNU_IFUNC to one place. NFC.Rui Ueyama2016-01-261-3/+15
| | | | | | | | | This does not solve the problem that we call isGnuIFunc function both from RelocationSection and from the Writer::scanRelocs, but this at least should improve readability. I'm taking an incremental approach to reduce complexity. llvm-svn: 258753
* Define a helper function to make it visually shorter. NFC.Rui Ueyama2016-01-251-46/+41
| | | | llvm-svn: 258748
* Use Symtab.find() instead of Symtab.getSymbols().lookup().Rui Ueyama2016-01-251-4/+4
| | | | | | | This was the only place we directly called lookup on the internal table of the symbol table. llvm-svn: 258724
* Avoid almost duplication in .dynamic finalize and write.Rafael Espindola2016-01-251-152/+87
| | | | | | | | | | | | | There are a few cases where we have almost duplicated code. This patches fixes the simplest: the finalize and write of dynamic section. Right now they have to have exactly the same structure to decide if a DT_* entry is needed and then to actually write it. We cannot just write it to a std::vector in the first pass since addresses have not been computed yet. llvm-svn: 258723
* Fix: added assert condition to EhFrameHeader<ELFT>::assignEhFrame().George Rimar2016-01-251-2/+2
| | | | | | Thanks to David Blaikie who found that issue. llvm-svn: 258707
* Use of assert instead of llvm_unreachable in ↵George Rimar2016-01-251-1/+1
| | | | | | EhFrameHeader<ELFT>::assignEhFrame(). llvm-svn: 258670
* [ELF] Avoid unnecessary global variable.Sean Silva2016-01-231-2/+0
| | | | | | | | | | Summary: It looks like this snuck through in r256143/D15383. Reviewers: ruiu, grimar Differential Revision: http://reviews.llvm.org/D16500 llvm-svn: 258599
* Use of llvm_unreachable instead of warning in ↵George Rimar2016-01-221-5/+2
| | | | | | EhFrameHeader<ELFT>::assignEhFrame(). llvm-svn: 258499
* ELF: Move code to emit copyrel to one place. NFC.Rui Ueyama2016-01-211-9/+11
| | | | | | | | | In this code, we avoid calling needsCopyRel in writeTo because we called that function already in scanRelocs. Making the same decision twice is a waste and has a risk of a bug that we get inconsistent resuts. llvm-svn: 258430
* [ELF][MIPS] Initial support of MIPS local GOT entriesSimon Atanasyan2016-01-211-5/+39
| | | | | | | | | | | | | | | | | | | | | | | | 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] Do not keep STT_FILE symbols in the symbol tableSimon Atanasyan2016-01-201-1/+1
| | | | | | | STT_FILE symbols usually contain source file names. It is redundant to keep this information in the output file. llvm-svn: 258331
* Reapply r257753 with fix:George Rimar2016-01-151-1/+212
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Added check for terminator CIE/FDE which has zero data size. void EHOutputSection<ELFT>::addSectionAux( ... // If CIE/FDE data length is zero then Length is 4, this // shall be considered a terminator and processing shall end. if (Length == 4) break; ... After this "Bug 25923 - lld/ELF2 linked application crashes if exceptions were used." is fixed for me. Self link of clang also works. Initial commit message: [ELF] - implemented --eh-frame-hdr command line option. --eh-frame-hdr Request creation of ".eh_frame_hdr" section and ELF "PT_GNU_EH_FRAME" segment header. Both gold and the GNU linker support an option --eh-frame-hdr which tell them to construct a header for all the .eh_frame sections. This header is placed in a section named .eh_frame_hdr and also in a PT_GNU_EH_FRAME segment. At runtime the unwinder can find all the PT_GNU_EH_FRAME segments by calling dl_iterate_phdr. This section contains a lookup table for quick binary search of FDEs. Detailed info can be found here: http://www.airs.com/blog/archives/462 Differential revision: http://reviews.llvm.org/D15712 llvm-svn: 257889
* Update for LLVM function name change.Rui Ueyama2016-01-141-4/+4
| | | | llvm-svn: 257801
* Revert r257753: "[ELF] - implemented --eh-frame-hdr command line option."Rui Ueyama2016-01-141-208/+1
| | | | | | This reverts commit r257753 because we cannot link Clang with this patch. llvm-svn: 257797
* [ELF] - implemented --eh-frame-hdr command line option.George Rimar2016-01-141-1/+208
| | | | | | | | | | | | | | --eh-frame-hdr Request creation of ".eh_frame_hdr" section and ELF "PT_GNU_EH_FRAME" segment header. Both gold and the GNU linker support an option --eh-frame-hdr which tell them to construct a header for all the .eh_frame sections. This header is placed in a section named .eh_frame_hdr and also in a PT_GNU_EH_FRAME segment. At runtime the unwinder can find all the PT_GNU_EH_FRAME segments by calling dl_iterate_phdr. This section contains a lookup table for quick binary search of FDEs. Detailed info can be found here: http://www.airs.com/blog/archives/462 Differential revision: http://reviews.llvm.org/D15712 llvm-svn: 257753
* Fixed typo in comment. NFC.George Rimar2016-01-111-1/+1
| | | | llvm-svn: 257356
* Revert "Remove unnecessary type casts."Rui Ueyama2016-01-071-2/+3
| | | | | | | This reverts commit r257080 because it caused GCC to emit "enumeral and non-enumeral type in conditional expression" warning. llvm-svn: 257096
* Fix local variable name.Rui Ueyama2016-01-071-13/+13
| | | | | | | sh_type and sh_flags are valid names as members of ELF structs, but they are not as variables in LLVM. llvm-svn: 257082
* Remove useless local variable.Rui Ueyama2016-01-071-5/+2
| | | | llvm-svn: 257081
* Remove unnecessary type casts.Rui Ueyama2016-01-071-3/+2
| | | | llvm-svn: 257080
* Fix typo.Rui Ueyama2016-01-071-1/+1
| | | | | | They happened to be anagrams. llvm-svn: 257072
* [ELF] Add AMDGPU supportTom Stellard2016-01-071-1/+10
| | | | | | | | | | Summary: This will allow us to remove the AMDGPU support from old ELF. Reviewers: rafael, ruiu Differential Revision: http://reviews.llvm.org/D15895 llvm-svn: 257023
* ELF: Improve performance of string table construction.Rui Ueyama2016-01-071-14/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | String tables in unstripped executable files are fairly large in size. For example, lld's executable file is about 34.4 MB in my environment, and of which 3.5 MB is the string table. Efficiency of string table construction matters. Previously, the string table was built in an inefficient way. We used StringTableBuilder to build that and enabled string tail merging, although tail merging is not effective for the symbol table (you can only make the string table 0.3% smaller for lld.) Tail merging is computation intensive task and slow. This patch eliminates string tail merging. I changed the way of adding strings to the string table in this patch too. Previously, strings were added using add() and the same strings were then passed to getOffset() to get their offsets in the string table. In this way, getOffset() needs to look up a hash table to get offsets for given strings. This is a violation of "we look up the symbol table (or a hash table) only once for each symbol" dogma of the new LLD's design. Hash table lookup for long C++ mangled names is slow. I eliminated that lookup in this patch. In total, this patch improves link time of lld itself about 12% (3.50 seconds -> 3.08 seconds.) llvm-svn: 257017
* Define align() and use that instead of RoundUpToAlignment().Rui Ueyama2016-01-061-4/+4
| | | | | | The name "RoundUpToAlignment" is too long compared to what it does. llvm-svn: 256993
* Remove redundant `llvm::ELF::`.Rui Ueyama2016-01-061-25/+15
| | | | llvm-svn: 256986
* Simplify MipsReginfoInputSection.Rui Ueyama2016-01-061-2/+3
| | | | | | | MipsReginfoInputSection is basically just a container of Elf_Mips_Reginfo struct. This patch makes that struct directly accessible from others. llvm-svn: 256984
* Remove unnecessary `lld::`.Rui Ueyama2016-01-061-9/+8
| | | | llvm-svn: 256970
* Add debugger rendezvous DT_DEBUG .dynamic entryEd Maste2016-01-061-0/+5
| | | | | | | | | The runtime linker may store a pointer to a data structure used by debuggers. Differential Revision: http://reviews.llvm.org/D15775 llvm-svn: 256942
* Simplify. NFC.Rui Ueyama2016-01-061-3/+2
| | | | llvm-svn: 256903
* Simplify. NFC.Rui Ueyama2016-01-051-9/+8
| | | | llvm-svn: 256846
* Consistently use 'Bss' instead of 'BSS'.Rui Ueyama2016-01-051-3/+3
| | | | llvm-svn: 256844
* Revert or r256638. I`ve lost a little piece of code when resolved conflicts ↵George Rimar2016-01-021-12/+8
| | | | | | | | | | | | | | | | | | right before commit. Sorry about that. Test did not catch this either, so I`ll improve it and recommit later. Original commit message: [ELF] - Optimize .eh_frame section: remove CIE if all FDEs referencing it were removed. This patch performs little optimization for eh_frame section. If all FDE`s that referenced CIE are removed then CIE is also removed from output. That can happen for example when dropping FDEs that point to dropped sections. Testcase showing that is included. The same optimization was added to ld about 14 years ago: https://sourceware.org/ml/binutils/2001-12/msg00144.html, gold does not do that it seems. Differential revision: http://reviews.llvm.org/D15564 llvm-svn: 256693
* [ELF] - Optimize .eh_frame section: remove CIE if all FDEs referencing it ↵George Rimar2015-12-301-8/+12
| | | | | | | | | | | | | were removed. This patch performs little optimization for eh_frame section. If all FDE`s that referenced CIE are removed then CIE is also removed from output. That can happen for example when dropping FDEs that point to dropped sections. Testcase showing that is included. The same optimization was added to ld about 14 years ago: https://sourceware.org/ml/binutils/2001-12/msg00144.html, gold does not do that it seems. Differential revision: http://reviews.llvm.org/D15564 llvm-svn: 256638
* Reformat of conditions for calculating r_offset in ↵George Rimar2015-12-291-8/+6
| | | | | | RelocationSection<ELFT>::writeTo(). NFC. llvm-svn: 256563
* Use virtual function instead of hand-written type dispatch.Rui Ueyama2015-12-261-10/+13
| | | | | | | | OutputSectionBase already has virtual member functions. This patch makes addSection() a virtual function to remove code from Writer::createSections(). llvm-svn: 256436
* Move a function to a file where it is used.Rui Ueyama2015-12-251-10/+0
| | | | llvm-svn: 256410
* Simplify. NFC.Rafael Espindola2015-12-251-2/+1
| | | | llvm-svn: 256404
* Update the recorded CIE length when aligning.Rafael Espindola2015-12-241-7/+14
| | | | | | We cannot just pad with 0s as that would be a terminator mark. llvm-svn: 256392
* Make it possible to create common symbols from bitcode.Rafael Espindola2015-12-241-1/+4
| | | | | | | 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-12/+13
| | | | | | | | | | | | | | | | | | | | 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 Defined and DefinedElf.Rafael Espindola2015-12-241-2/+4
| | | | | | | This is similar to what was done for Undefined and opens the way for having a symbol defined in bitcode. llvm-svn: 256354
OpenPOWER on IntegriCloud