summaryrefslogtreecommitdiffstats
path: root/lld/ELF/OutputSections.h
Commit message (Collapse)AuthorAgeFilesLines
* [ELF] Make MergeInputSection merging aware of output sectionsFangrui Song2019-09-241-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes PR38748 mergeSections() calls getOutputSectionName() to get output section names. Two MergeInputSections may be merged even if they are made different by SECTIONS commands. This patch moves mergeSections() after processSectionCommands() and addOrphanSections() to fix the issue. The new pass is renamed to OutputSection::finalizeInputSections(). processSectionCommands() and addorphanSections() are changed to add sections to InputSectionDescription::sectionBases. finalizeInputSections() merges MergeInputSections and migrates `sectionBases` to `sections`. For the -r case, we drop an optimization that tries keeping sh_entsize non-zero. This is for the simplicity of addOrphanSections(). The updated merge-entsize2.s reflects the change. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D67504 llvm-svn: 372734
* [Coding style change] Rename variables so that they start with a lowercase ↵Rui Ueyama2019-07-101-49/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | letter This patch is mechanically generated by clang-llvm-rename tool that I wrote using Clang Refactoring Engine just for creating this patch. You can see the source code of the tool at https://reviews.llvm.org/D64123. There's no manual post-processing; you can generate the same patch by re-running the tool against lld's code base. Here is the main discussion thread to change the LLVM coding style: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html In the discussion thread, I proposed we use lld as a testbed for variable naming scheme change, and this patch does that. I chose to rename variables so that they are in camelCase, just because that is a minimal change to make variables to start with a lowercase letter. Note to downstream patch maintainers: if you are maintaining a downstream lld repo, just rebasing ahead of this commit would cause massive merge conflicts because this patch essentially changes every line in the lld subdirectory. But there's a remedy. clang-llvm-rename tool is a batch tool, so you can rename variables in your downstream repo with the tool. Given that, here is how to rebase your repo to a commit after the mass renaming: 1. rebase to the commit just before the mass variable renaming, 2. apply the tool to your downstream repo to mass-rename variables locally, and 3. rebase again to the head. Most changes made by the tool should be identical for a downstream repo and for the head, so at the step 3, almost all changes should be merged and disappear. I'd expect that there would be some lines that you need to merge by hand, but that shouldn't be too many. Differential Revision: https://reviews.llvm.org/D64121 llvm-svn: 365595
* ELF: Introduce a separate bit for tracking whether an output section has ↵Peter Collingbourne2019-06-031-0/+5
| | | | | | | | | | | | | | | | | | ever had an input section added to it. NFCI. We currently (ab)use the Live bit on output sections to track whether the section has ever had an input section added to it, and then later use it during orphan placement. This will conflict with one of my upcoming partition-related changes that will assign all output sections to a partition (thus marking them as live) so that they can be added to the correct segment by the code that creates program headers. Instead of using the Live bit for this purpose, create a new flag and start using it to track the property explicitly. Differential Revision: https://reviews.llvm.org/D62348 llvm-svn: 362444
* [LLD][ELF] - Do not remove empty sections referenced in LOADADDR/ADDR commands.George Rimar2019-04-261-0/+1
| | | | | | | | | | | | | | | This is https://bugs.llvm.org//show_bug.cgi?id=38750. If script references empty sections in LOADADDR/ADDR commands .empty : { *(.empty ) } .text : AT(LOADADDR (.empty) + SIZEOF (.empty)) { *(.text) } then an empty section will be removed and LOADADDR/ADDR will evaluate to null. It is not that user may expect from using of the generic script, what is a common case. Differential revision: https://reviews.llvm.org/D54621 llvm-svn: 359279
* [ELF] Delete unused forward declarations and unused ↵Fangrui Song2019-03-151-9/+0
| | | | | | DynamicReloc::getInputSec(). NFC llvm-svn: 356239
* ELF: De-template OutputSection::finalize() and MipsGotSection::build(). NFCI.Peter Collingbourne2019-03-061-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D58810 llvm-svn: 355479
* ELF: Write .eh_frame_hdr explicitly after writing .eh_frame.Peter Collingbourne2019-02-281-3/+1
| | | | | | | | | | | This lets us remove the special case from Writer::writeSections(), and also fixes a bug where .eh_frame_hdr isn't necessarily written in the correct order if a linker script moves .eh_frame and .eh_frame_hdr into the same output section. Differential Revision: https://reviews.llvm.org/D58795 llvm-svn: 355153
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [ELF] Make TrapInstr and Filler byte arrays. NFC.Simon Atanasyan2018-11-141-2/+3
| | | | | | | | | | | | The uint32_t type does not clearly convey that these fields are interpreted in the target endianness. Converting them to byte arrays should make this more obvious and less error-prone. Patch by James Clarke Differential Revision: http://reviews.llvm.org/D54207 llvm-svn: 346893
* Remove a global variable that we can live without.Rui Ueyama2018-10-231-1/+0
| | | | | | | | | | Out::DebugInfo was used only by GdbIndex class to determine if we need to create a .gdb_index section, but we can do the same check without it. Added a test that this patch doesn't change the existing behavior. llvm-svn: 345058
* [ELF] - Implement linker script OVERLAYs.George Rimar2018-06-271-0/+1
| | | | | | | | | | | | | | | | | | This is PR36768. Linker script OVERLAYs are described in 4.6.9. Overlay Description of the spec: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/sections.html They are used to allow output sections which have different LMAs but the same VAs and used for embedded programming. Currently, LLD restricts overlapping of sections and that seems to be the most desired behaviour for defaults. My thoughts about possible approaches for PR36768 are on the bug page, this patch implements OVERLAY keyword and allows VAs overlapping for sections that within the overlay. Differential revision: https://reviews.llvm.org/D44780 llvm-svn: 335714
* [ELF] Pass callables by function_refBenjamin Kramer2018-06-161-1/+1
| | | | | | | No need to create a heavyweight std::function if it's not stored. No functionality change intended. llvm-svn: 334885
* [PPC64] Remove support for ELF V1 ABI in LLDZaara Syeda2018-05-041-2/+0
| | | | | | | | | | | The current support for V1 ABI in LLD is incomplete. This patch removes V1 ABI support and changes the default behavior to V2 ABI, issuing an error when using the V1 ABI. It also updates the testcases to V2 and removes any V1 specific tests. Differential Revision: https://reviews.llvm.org/D46316 llvm-svn: 331529
* Use exact uint32_t for uint32_t ELF field. NFC.Rui Ueyama2018-03-071-1/+1
| | | | llvm-svn: 326934
* Initialize a member in C++11 style. NFC.Rui Ueyama2018-03-071-1/+1
| | | | llvm-svn: 326933
* [ELF] - Do not remove empty sections that use symbols in expressions.George Rimar2018-03-011-0/+1
| | | | | | | | | | | | | | | This is PR36515. Currenly if we have a script like .debug_info 0 : { *(.debug_info) }, we would not remove this section and keep it in the output. That does not work, because it is common case for debug sections to have a zero address expression. Patch changes behavior so that we remove only sections that do not use symbols in its expressions. Differential revision: https://reviews.llvm.org/D43863 llvm-svn: 326430
* Simplify removing empty output sections.Rafael Espindola2018-03-011-2/+0
| | | | | | | With this the meaning of the Live bit in output sections is clear: we have at some point added a input section into it. llvm-svn: 326401
* Keep flags from phantom synthetic sections.Rafael Espindola2018-02-261-0/+2
| | | | | | | | | | | | | | | | | | | | | This fixes pr36475. I think this code can be simplified a bit, but I would like to check in the more direct fix if we are in agreement on the direction and then refactor. This is not something that bfd does. The issue is not noticed in bfd because it keeps fewer sections from the linkerscript in the output. The reasons why it seems reasonable to do this: - As George noticed, we would still keep the flags if the output section had both an empty synthetic section and a regular section - We need an heuristic to find the flags of output sections. Using the flags of a synthetic section that would have been there seems a reasonable heuristic. llvm-svn: 326137
* [ELF] - Introduce getInputSections() helper.George Rimar2018-02-221-0/+2
| | | | | | | | | | | We sometimes need to iterate over input sections for a given output section. It is not very convinent because we have to iterate over section descriptions. Patch introduces getInputSections helper, it simplifies things. Differential revision: https://reviews.llvm.org/D43574 llvm-svn: 325763
* Consistent (non) use of empty lines in include blocksSam Clegg2018-02-201-1/+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] - Support COPY, INFO, OVERLAY output sections attributes.George Rimar2018-02-161-0/+1
| | | | | | | | | | | | | | This is PR36298. (COPY), (INFO), (OVERLAY) all have the same effect: section should be marked as non-allocatable. (https://www.eecs.umich.edu/courses/eecs373/readings/Linker.pdf, 3.6.8.1 Output Section Type) Differential revision: https://reviews.llvm.org/D43071 llvm-svn: 325331
* Sort orphan section if --symbol-ordering-file is given.Rafael Espindola2018-01-301-2/+0
| | | | | | Before this patch orphan sections were not sorted. llvm-svn: 323779
* Move LMAOffset from the OutputSection to the PhdrEntry. NFC.Rafael Espindola2018-01-251-2/+1
| | | | | | | | | | | | | | | | | | | | | | If two sections are in the same PT_LOAD, their relatives offsets, virtual address and physical addresses are all the same. I initially wanted to have a single global LMAOffset, on the assumption that every ELF file was in practiced loaded contiguously in both physical and virtual memory. Unfortunately that is not the case. The linux kernel has: LOAD 0x200000 0xffffffff81000000 0x0000000001000000 0xced000 0xced000 R E 0x200000 LOAD 0x1000000 0xffffffff81e00000 0x0000000001e00000 0x15f000 0x15f000 RW 0x200000 LOAD 0x1200000 0x0000000000000000 0x0000000001f5f000 0x01b198 0x01b198 RW 0x200000 LOAD 0x137b000 0xffffffff81f7b000 0x0000000001f7b000 0x116000 0x1ec000 RWE 0x200000 The delta for all but the third PT_LOAD is the same: 0xffffffff80000000. I think the 3rd one is a hack for implementing per cpu data, but we can't break that. llvm-svn: 323456
* Only lookup LMARegion once. NFC.Rafael Espindola2018-01-251-0/+1
| | | | | | This is similar to how we handle MemRegion. llvm-svn: 323396
* [ELF] - Fix for ld.lld does not accept "AT" syntax for declaring LMA regionGeorge Rimar2018-01-121-0/+1
| | | | | | | | | | | AT> lma_region expression allows to specify the memory region for section load address. Should fix PR35684. Differential revision: https://reviews.llvm.org/D41397 llvm-svn: 322359
* Fix line endings. NFC.Rafael Espindola2017-12-121-6/+6
| | | | llvm-svn: 320502
* [ELF] Reset OutputSection size prior to processing linker script commandsJames Henderson2017-12-121-7/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The size of an OutputSection is calculated early, to aid handling of compressed debug sections. However, subsequent to this point, unused synthetic sections are removed. In the event that an OutputSection, from which such an InputSection is removed, is still required (e.g. because it has a symbol assignment), and no longer has any InputSections, dot assignments, or BYTE()-family directives, the size member is never updated when processing the commands. If the removed InputSection had a non-zero size (such as a .got.plt section), the section ends up with the wrong size in the output. The fix is to reset the OutputSection size prior to processing the linker script commands relating to that OutputSection. This ensures that the size is correct even in the above situation. Additionally, to reduce the risk of developers misusing OutputSection Size and InputSection OutSecOff, they are set to simply the number of InputSections in an OutputSection, and the corresponding index respectively. We cannot completely stop using them, due to SHF_LINK_ORDER sections requiring them. Compressed debug sections also require the full size. This is now calculated in maybeCompress for these kinds of sections. Reviewers: ruiu, rafael Differential Revision: https://reviews.llvm.org/D38361 llvm-svn: 320472
* Delete dead code. NFC.Rafael Espindola2017-11-291-14/+0
| | | | llvm-svn: 319274
* ELF: Merge DefinedRegular and Defined.Peter Collingbourne2017-11-061-1/+1
| | | | | | | | | Now that DefinedRegular is the only remaining derived class of Defined, we can merge the two classes. Differential Revision: https://reviews.llvm.org/D39667 llvm-svn: 317448
* [ELF] - Stop using SectionKey for creating output sections.George Rimar2017-11-041-16/+1
| | | | | | | | | | | | | | | | | | | | | | Stop using SectionKey for creating output sections. Initially SectionKey was designed because we merged section with use of Flags and Alignment fields. Currently LLD merges them by name only, except the case when -relocatable output is produced. In that case we still merge sections only with the same flags and alignment. There is probably no issue at all to stop using Flags and Alignment for -r and just disable the merging in that case. After doing that change we can get rid of using SectionKey. That is not only simplifies the code, but also gives some perfomance boost. I tried to link chrome and mozilla, results are next: * chrome link time goes from 1,666750355s to 1,551585364s, that is about 7%. * mozilla time changes from 3,210261947 to 3,153782940, or about 2%. Differential revision: https://reviews.llvm.org/D39594 llvm-svn: 317406
* Rename SymbolBody -> SymbolRui Ueyama2017-11-031-1/+1
| | | | | | | | | | | | | 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] - Simplify reporting of garbage collected sections.George Rimar2017-10-271-1/+0
| | | | | | | | | 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
* Rename processCommands -> processSectionCommands.Rui Ueyama2017-10-111-0/+1
| | | | llvm-svn: 315415
* Rename Commands -> SectionCommands.Rui Ueyama2017-10-111-1/+1
| | | | | | | | | | "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
* Remove OutputSection::updateAlignment.Rui Ueyama2017-10-071-5/+0
| | | | | | I feel it is easier to understand without this function. llvm-svn: 315140
* Merge addInputSec with OutputSection::addSection.Rui Ueyama2017-10-071-2/+1
| | | | | | | | | | Previously, when we added an input section to an output section, we called `OutputSectionFactory::addInputSec`. This isn't a good design because, a factory class is intended to create a new object and return it, but in this use case, it will never create a new object. This patch fixes the design flaw. llvm-svn: 315138
* Remove unused parameters.Rui Ueyama2017-10-071-3/+1
| | | | llvm-svn: 315133
* Do not mutate Script->Opt.Commands from a leaf helper function.Rui Ueyama2017-10-061-0/+2
| | | | | | | | 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
* Make a few member varaibles/functions private.Rui Ueyama2017-10-061-6/+9
| | | | llvm-svn: 315115
* Move new lld's code to Common subdirectory.Rui Ueyama2017-10-021-1/+1
| | | | | | | | | | 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] - Remove one of OutputSectionFactory::addInputSec().George Rimar2017-09-151-2/+1
| | | | | | | | | | Patch removes one of OutputSectionFactory::addInputSec methods. That allows to simplify reporting of discarded sections and should help to D37561. Differential revision: https://reviews.llvm.org/D37735 llvm-svn: 313361
* [ELF] - Store pointer to PT_LOAD instead of pointer to first section in ↵George Rimar2017-09-071-7/+8
| | | | | | | | | | | OutputSection It is a bit more convinent and helps to simplify logic of program headers allocation a little. Differential revision: https://reviews.llvm.org/D34956 llvm-svn: 312711
* [ELF] - Fix "--symbol-ordering-file doesn't work with linker scripts"George Rimar2017-08-041-0/+2
| | | | | | | | | | | | | | | This is PR33889, Patch adds support of combination of linkerscript and -symbol-ordering-file option. If no sorting commands are present in script inside section declaration and no --sort-section option specified, code uses sorting from ordering file if any exist. Differential revision: https://reviews.llvm.org/D35843 llvm-svn: 310045
* Merge OutputSectionCommand and OutputSection.Rafael Espindola2017-07-271-3/+28
| | | | | | | | | | | | | This is a bit of a hack, but it is *so* convenient. Now that we create synthetic linker scripts when none is provided, we always have to handle paired OutputSection and OutputsectionCommand and keep a mapping from one to the other. This patch simplifies things by merging them and creating what used to be OutputSectionCommands really early. llvm-svn: 309311
* Rename ObjectFile -> ObjFile.Rui Ueyama2017-07-261-1/+1
| | | | | | | Rename it because it was too easy to conflict with llvm::object::ObjectFile which broke buildbots several times. llvm-svn: 309199
* [ELF] - Apply clang-format. NFC.George Rimar2017-07-181-4/+3
| | | | llvm-svn: 308297
* Remove redundant argument. NFC.Rafael Espindola2017-07-061-2/+1
| | | | llvm-svn: 307279
* Move fabricateDefaultCommands earlier.Rafael Espindola2017-07-051-3/+0
| | | | | | | It is now just after the OutputSections are created, which is as early as it can possibly go. llvm-svn: 307225
* Use Entry::SecSize in a couple of cases.Rafael Espindola2017-07-051-1/+0
| | | | | | | This avoids having to compute relocation section sizes early, removing the last use of assignOffsets. llvm-svn: 307219
OpenPOWER on IntegriCloud