summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Writer.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Move OutputSectionFactory to LinkerScript.cpp. NFC.Rui Ueyama2017-11-041-3/+1
| | | | | | | | That class is used only by LinkerScript.cpp, so we should move it to that file. Also, it no longer has to be a "factory" class. It can just be a non-member function. llvm-svn: 317427
* Rename SymbolBody -> SymbolRui Ueyama2017-11-031-11/+11
| | | | | | | | | | | | | 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] - Removed unused variable. NFC.George Rimar2017-11-031-4/+1
| | | | llvm-svn: 317316
* [ELF] Remove unnecessary function call. NFC.James Henderson2017-10-311-1/+1
| | | | | | | | | | | StringTableSection does not implement postThunkContents, so calling it on these sections is pointless (it calls an empty virtual function), and we can remove it. Reviewers: ruiu Differential Revision: https://reviews.llvm.org/D39460 llvm-svn: 317014
* Merge SymbolBody and Symbol into one class, SymbolBody.Rui Ueyama2017-10-311-18/+16
| | | | | | | | | | | | | | | | | | | SymbolBody and Symbol were separated classes due to a historical reason. Symbol used to be a pointer to a SymbolBody, and the relationship between Symbol and SymbolBody was n:1. r2681780 changed that. Since that patch, SymbolBody and Symbol are allocated next to each other to improve memory locality, and they have 1:1 relationship now. So, the separation of Symbol and SymbolBody no longer makes sense. This patch merges them into one class. In order to avoid updating too many places, I chose SymbolBody as a unified name. I'll rename it Symbol in a follow-up patch. Differential Revision: https://reviews.llvm.org/D39406 llvm-svn: 317006
* [ELF] - Simplify output section creation.George Rimar2017-10-311-30/+7
| | | | | | | | | | | | | When there is no SECTION commands given, all sections are technically orphans, but now we handle script orphans sections and regular "orphans" sections for non-scripted case differently, though we can handle them at one place. Patch do that change. Differential revision: https://reviews.llvm.org/D39045 llvm-svn: 316984
* [ELF] - Stop sorting input sections in createSections().George Rimar2017-10-301-32/+32
| | | | | | | | | | It does not seem that createSections() is a good place for applying sorting. Patch changes code to do that inside sortSections(), which looks more appropriate place. Differential revision: https://reviews.llvm.org/D39371 llvm-svn: 316893
* ELF: Correctly set edata if there are no .bss sections.Peter Collingbourne2017-10-291-20/+17
| | | | | | | | | | | edata needs to be set to the end of the last mapped initialized section. We were previously mishandling the case where there were no non-mapped sections by setting it to the end of the last section in the output file. Differential Revision: https://reviews.llvm.org/D39399 llvm-svn: 316877
* Pass symbol attributes instead of ElfSym to Shared symbol ctor.Rui Ueyama2017-10-281-1/+1
| | | | | | | This change allows us to use less templates for Shared symbol and the functions that deals with shared symbols. llvm-svn: 316841
* Rename isInCurrentDSO -> isInCurrentOutput.Rui Ueyama2017-10-271-2/+2
| | | | | | | | | | | | DSO is short for dynamic shared object, so the function name was a little confusing because it sounded like it didn't work when we were a creating statically-linked executable or something. What we mean by "DSO" here is the current output file that we are creating. Thus the new name. Alternatively, we could call it the current ELF module, but "module" is a overloaded word, so I avoided that. llvm-svn: 316809
* ELF: Add support for emitting dynamic relocations in the Android relocation ↵Peter Collingbourne2017-10-271-10/+25
| | | | | | | | | | | | | | | | | | | | | | | packing format. The Android relocation packing format is a more compact format for dynamic relocations in executables and DSOs that is based on delta encoding and SLEBs. An overview of the format can be found in the Android source code: https://android.googlesource.com/platform/bionic/+/refs/heads/master/tools/relocation_packer/src/delta_encoder.h This patch implements relocation packing using that format. This implementation uses a more intelligent algorithm for compressing relative relocations than Android's own relocation packer. As a result it can generally create smaller relocation sections than that packer. If I link Chromium for Android targeting ARM32 I get a .rel.dyn of size 174693 bytes, as compared to 371832 bytes with gold and the Android packer. Differential Revision: https://reviews.llvm.org/D39152 llvm-svn: 316775
* [ELF] - Stop naming relocation sections with first input section name.George Rimar2017-10-271-0/+8
| | | | | | | | | | | | | | | | It was reported (https://reviews.llvm.org/D38724#902841) that when we use -ffunction-sections --emit-relocs build, REL[A] output section receives the name of first input section, like .rela.text.first_function_in_text rather than .rela.text. It is probably not really an issue as sh_info still points to correct target section, but it does not look clean in output and allows internal section name to leak there, what at least looks confusing and is not consistent with ld.bfd. Patch changes this behavior so that target output section name is used as a base. Differential revision: https://reviews.llvm.org/D39242 llvm-svn: 316760
* [ELF] - Simplify reporting of garbage collected sections.George Rimar2017-10-271-1/+1
| | | | | | | | | This moves reporting of garbage collected sections right after we do GC. That simplifies things. Differential revision: https://reviews.llvm.org/D39058 llvm-svn: 316759
* [ELF] Add support for multiple passes to createThunks()Peter Smith2017-10-271-3/+1
| | | | | | | | | | | | | This change allows Thunks to be added on multiple passes. To do this we must merge only the thunks added in each pass, and deal with thunks that have drifted out of range of their callers. A thunk may end out of range of its caller if enough thunks are added in between the caller and the thunk. To handle this we create another thunk. Differential Revision: https://reviews.llvm.org/D34692 llvm-svn: 316754
* [ELF] Introduce range extension thunks for ARMPeter Smith2017-10-271-6/+1
| | | | | | | | | | | | | | This change adds initial support for range extension thunks. All thunks must be created within the first pass so some corner cases are not supported. A follow up patch will add support for multiple passes. With this change the existing tests arm-branch-error.s and arm-thumb-branch-error.s now no longer fail with an out of range branch. These have been renamed and tests added for the range extension thunk. Differential Revision: https://reviews.llvm.org/D34691 llvm-svn: 316752
* Simplify logic to find the last executable segment. NFC.Rui Ueyama2017-10-271-12/+7
| | | | llvm-svn: 316742
* Fix typo.Rui Ueyama2017-10-271-1/+1
| | | | llvm-svn: 316741
* De-template EhFrameHdr. NFC.Rui Ueyama2017-10-271-22/+17
| | | | llvm-svn: 316734
* De-template EhFrameSection. NFC.Rui Ueyama2017-10-271-7/+7
| | | | llvm-svn: 316731
* [lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman2017-10-251-6/+6
| | | | | | | | | | | | | | | | | | | 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
* Improve comment.Rui Ueyama2017-10-241-6/+8
| | | | llvm-svn: 316489
* LLD/ELF: Allow targets to set e_flagsKonstantin Zhuravlyov2017-10-241-8/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D39139 llvm-svn: 316460
* [ELF] When placing orphans, handle case when last section is deadPetr Hosek2017-10-231-6/+8
| | | | | | | | | | | | | | | r315292 introduced a change that's supposed to consistently ignore "dead" output sections when placing orphans. Unfortunately, that change doesn't handle the special case when the orphan section is second to last section and the last section is dead (e.g. because it's being discarded) introducing a regression in some cases. This change handles this case by using the same predicate when checking the last section. Differential Revision: https://reviews.llvm.org/D39172 llvm-svn: 316307
* Remove unused argument.Rafael Espindola2017-10-201-2/+2
| | | | llvm-svn: 316248
* [ELF] - Simplify. NFC.George Rimar2017-10-191-3/+1
| | | | llvm-svn: 316163
* [ELF] - Remove excessive helper. NFC.George Rimar2017-10-181-14/+7
| | | | | | | | Removes addRegular() helper that looks excessive from Writer.cpp. Differential revision: https://reviews.llvm.org/D39006 llvm-svn: 316068
* [ELF] - Simplify. NFC.George Rimar2017-10-171-5/+4
| | | | llvm-svn: 316002
* [lld] Move Threads to CommonBob Haarman2017-10-131-1/+1
| | | | | | | | | | | | | | | | Summary: This will allow using the functionality from other linkers. It is also a prerequisite for sharing the error logging code. Reviewers: ruiu Reviewed By: ruiu Subscribers: emaste, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D38822 llvm-svn: 315725
* Hide SymbolBody::IsLocal.Rui Ueyama2017-10-131-1/+1
| | | | | | | IsLocal member is initialized by the constructor and will never change. So we don't want to make it directly accessible. llvm-svn: 315667
* Rename processCommands -> processSectionCommands.Rui Ueyama2017-10-111-2/+2
| | | | llvm-svn: 315415
* Rename Commands -> SectionCommands.Rui Ueyama2017-10-111-18/+20
| | | | | | | | | | "Commands" was ambiguous because in the linker script, everything is a command. We used to handle only SECTIONS commands, and at the time, it might make sense to call them the commands, but it is no longer the case. We handle not only SECTIONS but also MEMORY, PHDRS, VERSION, etc., and they are all commands. llvm-svn: 315409
* Rename HasSections -> HasSectionsComand.Rui Ueyama2017-10-111-6/+6
| | | | | | | | HasSections is true if there is at least one SECTIONS linker script command, and it is not directly related to whether we have section objects or not. So I think the new name is better. llvm-svn: 315405
* Remove ScriptConfiguration class and move the members to LinkerScript class.Rui Ueyama2017-10-111-19/+18
| | | | | | | | | | | | | | | | ScriptConfiguration was a class to contain parsed results of linker scripts. LinkerScript is a class to interpret it. That ditinction was needed because we haven't instantiated LinkerScript early (because, IIRC, LinkerScript class was a ELFT template function). So, when we parse linker scripts, we couldn't directly store the result to a LinkerScript instance. Now, that limitation is gone. We instantiate LinkerScript at the very beginning of our main function. We can directly store parse results to a LinkerScript instance. llvm-svn: 315403
* Don't create a dummy __tls_get_addr.Rafael Espindola2017-10-101-9/+0
| | | | | | | | | | | | | | | We just don't need one with the current setup. We only error on undefined references that are used by some relocation. If we managed to relax all uses of __tls_get_addr, no relocation uses it and we don't produce an error. This is less code and fixes the case were we fail to relax. Before we would produce a broken output, but now we produce an error. llvm-svn: 315334
* [LLD] Fix findOrphanPos to consistently ignore "dead" OutputSection'sAndrew Ng2017-10-101-3/+5
| | | | | | | | | | | | | | When findOrphanPos does the reverse search to find the OutputSection preceding the orphan's insertion point, look for a live OutputSection and ignore "dead" OutputSection's. This matches the behaviour of the forward search performed earlier in this function. Added test which without the above fix fails as a result of an orphan executable section being incorrectly placed in a non-executable segment. Differential Review: https://reviews.llvm.org/D38690 llvm-svn: 315292
* Rename ignoreInterpSection -> needsInterpSection.Rui Ueyama2017-10-081-1/+1
| | | | | | This should improve consistency. Also added comment. llvm-svn: 315169
* Inline small function. NFC.Rafael Espindola2017-10-071-1/+3
| | | | llvm-svn: 315141
* Remove OutputSection::updateAlignment.Rui Ueyama2017-10-071-1/+1
| | | | | | I feel it is easier to understand without this function. llvm-svn: 315140
* Do not mutate Script->Opt.Commands from a leaf helper function.Rui Ueyama2017-10-061-5/+7
| | | | | | | | Factory::addInputSec added an output section to Script->Opt.Commands, but that is too subtle. This patch makes it explicit so that it is easy to see when a new element is added to Script->Opt.Commands. llvm-svn: 315129
* Split addSection into two small functions. NFCI.Rui Ueyama2017-10-061-1/+1
| | | | | | | | | addSection function was hard to read because it behaves differently depending on its arguments but what exactly it does is not clear. Now it should be better. Still, it is not clear (not what but) why it does what it does, but I'll take a look at it later. llvm-svn: 315124
* Revert r314616: Run writeTo() concurrently.Rui Ueyama2017-10-061-4/+2
| | | | | | | This reverts commit r314616 because nested parallel-for loops can hang. Our ThreadPoolExecutor is not necessarily able to handle nested calls. llvm-svn: 315098
* Call exitLld() from elf::link.Rui Ueyama2017-10-041-6/+0
| | | | | | | | | We used to call exitLld() from a leaf function, Writer::run(), because we had objects on the stack whose dtors are expensive. Now we no longer have such objects on the stack, so there's no reason to exist from the leaf function. llvm-svn: 314869
* Remove BssSection::reserveSpace().Rui Ueyama2017-10-041-2/+2
| | | | | | | We no longer call reserveSpace more than once, so it can be merged with its constructor. llvm-svn: 314867
* Rewrite a comment.Rui Ueyama2017-10-021-4/+12
| | | | llvm-svn: 314707
* [MIPS] Fix PLT entries generation in case of linking regular and microMIPS codeSimon Atanasyan2017-10-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently LLD calls the `isMicroMips` routine to determine type of PLT entries needs to be generated: regular or microMIPS. This routine checks ELF header flags in the `FirstObj` to retrieve type of linked object files. So if the first file does not contain microMIPS code, LLD will generate PLT entries with regular (non-microMIPS) code only. Ideally, if a PLT entry is referenced by microMIPS code only this entry should contain microMIPS code, if a PLT entry is referenced by regular code this entry should contain regular code. In a "mixed" case the PLT entry can be either microMIPS or regular, but each "cross-mode-call" has additional cost. It's rather difficult to implement this ideal solution. But we can assume that if there is an input object file with microMIPS code, the most part of the code is microMIPS too. So we need to deduce type of PLT entries based on finally calculated ELF header flags and do not check only the first input object file. This change implements this. - The `getMipsEFlags` renamed to the `calcMipsEFlags`. The function called from the `LinkerDriver::link`. Result is stored in the Configuration::MipsEFlags field. - The `isMicroMips` and `isMipsR6` routines access the `MipsEFlags` field to get and check calculated ELF flags. - New types of PLT records created when necessary. Differential revision: https://reviews.llvm.org/D37747 llvm-svn: 314675
* [ELF] - Stop removing sections in removeUnusedSyntheticSections().George Rimar2017-10-021-4/+3
| | | | | | | | | | That makes code a bit more consistent. Instead of removing sections there we can just mark them as dead. So that removeEmptyCommands() will handle the rest. Differential revision: https://reviews.llvm.org/D38393 llvm-svn: 314654
* Run writeTo() concurrently.Rui Ueyama2017-10-011-2/+4
| | | | | | | | I don't know why we didn't use parallelForEach to call writeTo, but there should be no reason to not do that, as most writeTo functions are safe to run concurrently. llvm-svn: 314616
* [ELF] Simpler scheme for handling common symbolsBen Dunbobbin2017-09-291-7/+0
| | | | | | | | | Convert all common symbols to regular symbols after scan. This means that the downstream code does not to handle common symbols as a special case. Differential Revision: https://reviews.llvm.org/D38137 llvm-svn: 314495
* [ELF] - Detemplate of HashTableSection<ELFT>George Rimar2017-09-271-3/+3
| | | | | | | | Detemplation of one more synthetic section. Differential revision: https://reviews.llvm.org/D38241 llvm-svn: 314283
* [ELF] - Simplify removeUnusedSyntheticSections a bit.George Rimar2017-09-251-2/+0
| | | | | | | | | | | | | | | Previously`InX::Got` and InX::MipsGot synthetic sections were not removed if ElfSym::GlobalOffsetTable was defined. ElfSym::GlobalOffsetTable is a symbol for _GLOBAL_OFFSET_TABLE_. Patch moves ElfSym::GlobalOffsetTable check out from removeUnusedSyntheticSections. Also note that there was no point to check ElfSym::GlobalOffsetTable for MIPS case because InX::MipsGot::empty() always returns false for non-relocatable case, and in case of relocatable output we do not create special symbols anyways. Differential revision: https://reviews.llvm.org/D37623 llvm-svn: 314099
OpenPOWER on IntegriCloud