summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [LLD] Do not overwrite LMAOffset of PT_LOAD headerGeorge Rimar2018-08-021-8/+16
| | | | | | | | | | | | Patch by Konstantin Schwarz! If more than a single output section is added to a PT_LOAD header, only the first section should set the LMAOffset of the segment. Otherwise, we get a load-address overlap error Differential revision: https://reviews.llvm.org/D50133 llvm-svn: 338697
* [LLD] Only increase LMARegion if different from MemRegionGeorge Rimar2018-08-021-1/+2
| | | | | | | | | | | | Patch by Konstantin Schwarz! If both the MemRegion and LMARegion are set for an output section in a linker script, we should only increase the LMARegion if it is different from the MemRegion. Otherwise, we reserve the memory twice. Differential revision: https://reviews.llvm.org/D50065 llvm-svn: 338684
* lld: add experimental support for SHT_RELR sections.Rui Ueyama2018-07-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Patch by Rahul Chaudhry! This change adds experimental support for SHT_RELR sections, proposed here: https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg Pass '--pack-dyn-relocs=relr' to enable generation of SHT_RELR section and DT_RELR, DT_RELRSZ, and DT_RELRENT dynamic tags. Definitions for the new ELF section type and dynamic array tags, as well as the encoding used in the new section are all under discussion and are subject to change. Use with caution! Pass '--use-android-relr-tags' with '--pack-dyn-relocs=relr' to use SHT_ANDROID_RELR section type instead of SHT_RELR, as well as DT_ANDROID_RELR* dynamic tags instead of DT_RELR*. The generated section contents are identical. '--pack-dyn-relocs=android+relr --use-android-relr-tags' enables both '--pack-dyn-relocs=android' and '--pack-dyn-relocs=relr': lld will encode the relative relocations in a SHT_ANDROID_RELR section, and pack the rest of the dynamic relocations in a SHT_ANDROID_REL(A) section. Differential Revision: https://reviews.llvm.org/D48247 llvm-svn: 336594
* [ELF] - Eliminate dead "if". NFC.George Rimar2018-07-051-2/+0
| | | | | | | | | | | | We call switchTo() from assignAddresses() for switching to Aether, and from assignOffsets(). First calls assignOffsets() one by one for each output section. (https://github.com/llvm-mirror/lld/blob/master/ELF/LinkerScript.cpp#L1045) That I believe means the condition removed in this patch is dead. llvm-svn: 336356
* [ELF] - Convert excessive dyn_cast -> cast. NFC.George Rimar2018-07-051-3/+2
| | | | | | | | | Currently, there are only OutputSection and SymbolAssignment commands possible at the first level under SECTIONS tag. Hence, dyn_cast was excessive. llvm-svn: 336354
* [ELF] - Advance position in a memory region when change the Dot.George Rimar2018-07-051-0/+3
| | | | | | | | | | | | This is https://bugs.llvm.org//show_bug.cgi?id=37836 Previously LLD could assign to Dot or set the address for the section with address expression but did not advance the position in a memory region. Patch fixes the issue. llvm-svn: 336335
* [ELF] Don't create empty output section for unreferenced PROVIDEsJames Henderson2018-07-031-1/+8
| | | | | | | | | | | | | | | | | | | | LLD removes empty output sections otherwise specified in the linker script. Prior to this change however, if section descriptions included ANY kind of symbol assignment, then the consequent output section would not be removed, even if the assignment was marked with PROVIDE and not actually triggered (i.e. the symbol was never referenced). This change modifies the isDiscarable function to ignore such directives when determining whether a section should be discarded, in keeping with bfd's behaviour. Symbol assignments that do result in a symbol definition will continue to result in a kept section (this is not actually the same as bfd's behaviour, but it is simpler, and probably makes more sense). Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D48771 llvm-svn: 336184
* Make ALIGN work with -r in linker scriptsRui Ueyama2018-05-171-4/+5
| | | | | | | | | | | | Patch by Mark Kettenis. Make ALIGN work in linker scripts used with the -r option. This works in GNU ld (ld.bfd) and is used to generate the "random gap" object for linking the OpenBSD kernel. Differential Revision: https://reviews.llvm.org/D46839 llvm-svn: 332656
* Delete unused variable.Rafael Espindola2018-04-261-1/+1
| | | | llvm-svn: 330978
* Replace SharedSymbols with Defined when creating copy relocations.Rafael Espindola2018-04-261-2/+2
| | | | | | | | | | | | | This is slightly simpler to read IMHO. Now if a symbol has a position in the file, it is Defined. The main motivation is that with this a SharedSymbol doesn't need a section, which reduces the size of SymbolUnion. With this the peak allocation when linking chromium goes from 568.1 to 564.2 MB. llvm-svn: 330966
* [ELF] - Eliminate the AssertCommand.George Rimar2018-04-251-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently, LLD supports ASSERT as a separate command. We support two forms now. Assign expression-form: . = ASSERT(0x100) (old GNU ld required it and some scripts in the wild are still using something like . = ASSERT((_end - _text <= (512 * 1024 * 1024)), "kernel image bigger than KERNEL_IMAGE_SIZE"); Nowadays above is not a mandatory form and command-like form is commonly used: ASSERT(<expr>, "text); The return value of the ASSERT is Dot. That was implemented in D30171. It looks like (2) is just a short version of (1) then. GNU ld does *not* list ASSERT as a SECTIONS command: https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS Given above we probably can change ASSERT to be an assignment to Dot. That makes the rest of the code much simpler. Patch do that. Differential revision: https://reviews.llvm.org/D45434 llvm-svn: 330814
* [ELF] - Stop setting OutSecOff too early.George Rimar2018-04-091-3/+2
| | | | | | | | | | | | | | | | | | | | | | | Currently LLD sets OutSecOff in addSection for input sections. That is a fake offset (just a rude approximation to remember the order), used for sorting SHF_LINK_ORDER sections (see resolveShfLinkOrder, compareByFilePosition). There are 2 problems with such approach: 1. We currently change and reuse Size field as a value assigned. Changing size is not good because leads to bugs. Currently, SIZEOF(.bss) for empty .bss returns 2 because we add two empty synthetic sections and increase size twice by 1. (See PR37011: https://bugs.llvm.org/show_bug.cgi?id=37011) 2. Such approach simply does not work when --symbol-ordering-file is involved, because processing of the ordering file might break the initial section order. This fixes PR37011. Differential revision: https://reviews.llvm.org/D45368 llvm-svn: 329560
* [ELF] - Reveal more information in -Map file about assignments.George Rimar2018-04-051-0/+2
| | | | | | | | | | | | | | | | | Currently, LLD print symbol assignment commands to the map file, but it does not do that for assignments that are outside of the section descriptions. Such assignments can affect the layout though. The patch implements the following: * Teaches LLD to print symbol assignments outside of section declaration. * Teaches LLD to print PROVIDE/HIDDEN/PROVIDE hidden commands. In case when symbol is not provided, nothing will be printed. Differential revision: https://reviews.llvm.org/D44894 llvm-svn: 329272
* [ELF] - Cleanup. NFCI.George Rimar2018-04-041-2/+2
| | | | | | | | | Rename field, added comments. This is splitted from the D44894. Requested to be committed as independent cleanup. llvm-svn: 329162
* Reduce code duplication a bit.Rafael Espindola2018-03-261-3/+3
| | | | | | Thanks to George Rimar for pointing it out. llvm-svn: 328571
* Reduce code duplication a bit. NFCRafael Espindola2018-03-261-3/+2
| | | | llvm-svn: 328569
* This is PR36799.George Rimar2018-03-261-3/+9
| | | | | | | | | | | | | | | | Currently, we might have a bug with scripts like below: .foo : ALIGN(8) { *(.foo) } > ram because do not expand the memory region when doing ALIGN. This might result in file range overlaps. The patch fixes the issue. Differential revision: https://reviews.llvm.org/D44730 llvm-svn: 328479
* [ELF] - Do not ignore discarding of .rela.plt/.rela.dyn, allow doing custom ↵George Rimar2018-03-241-2/+5
| | | | | | | | | | | | | | | | | | | | | | layout for them. Currently when we build input sections list in linker script we ignore all rel[a] sections. That was done to support scripts like .rela.dyn : { *(.rela.data) } for emit relocs. Though as a result following scripts were also silently ignored: /DISCARD/ : { *(.rela.plt) /DISCARD/ : { *(.rela.dyn) and we produced output with this sections. That is not ideal. The solution this patch suggests is simple: do not ignore synthetic rel[a] sections. That way we can enable common discarding logic for them and report a proper error. Differential revision: https://reviews.llvm.org/D41640 llvm-svn: 328419
* [ELF] - Another fix for "LLD crashes with --emit-relocs when trying to ↵George Rimar2018-03-231-4/+17
| | | | | | | | | | | | | | | proccess .eh_frame" This fixes PR36367 which is about segfault when --emit-relocs is used together with .eh_frame sections which happens because of reordering of regular and .rel[a] sections. Path changes loop that iterates over input sections to create relocation target sections first. Differential revision: https://reviews.llvm.org/D44679 llvm-svn: 328299
* [ELF] - Show data and assignment commands in the map file.George Rimar2018-03-151-0/+2
| | | | | | | | | Patch teaches LLD to print BYTE/SHORT/LONG/QUAD and location move commands to the map file. Differential revision: https://reviews.llvm.org/D44004 llvm-svn: 327612
* [ELF] - Implement INSERT BEFORE.George Rimar2018-03-131-9/+17
| | | | | | | | | | | This finishes PR35877. INSERT BEFORE used similar to INSERT AFTER, it inserts sections before the given target section. Differential revision: https://reviews.llvm.org/D44380 llvm-svn: 327378
* [ELF] - Drop special flags for empty output sections.George Rimar2018-03-131-7/+11
| | | | | | | | | | | | | | | | This fixes PR36598. LLD currently crashes when we have empty output section with SHF_LINK_ORDER flag. This might happen if we place an empty synthetic section in the linker script, but keep output section alive with the use of additional symbol, for example. The patch fixes the issue by dropping all special flags for empty sections. Differential revision: https://reviews.llvm.org/D44376 llvm-svn: 327374
* [ELF] - Support "INSERT AFTER" statement.George Rimar2018-03-081-0/+20
| | | | | | | | | | | | | | | | | | | | This implements INSERT AFTER in a following way: During reading scripts it collects all insert statements. After we done and read all files it inserts statements into script commands list. With that: * Rest of code does know nothing about INSERT. * Approach is straightforward and have no visible limitations. * It is also easy to support INSERT BEFORE (was seen in clang code once). * Should work for PR35877 and similar cases. Cons: * It assumes we have "main" scripts that describes sections. Differential revision: https://reviews.llvm.org/D43468 llvm-svn: 327003
* Use exact uint32_t for uint32_t ELF field. NFC.Rui Ueyama2018-03-071-1/+1
| | | | llvm-svn: 326934
* [ELF] - Recommit r326892,r326893 "[ELF] - Report LMA region overflows."George Rimar2018-03-071-2/+2
| | | | | | | | | | | | With fix: add missing "RUN:" prefix to test case. Original commit message: We do not report LMA region overflows currently. Both GNU linkers do that. The patch implements it. Differential revision: https://reviews.llvm.org/D44094 llvm-svn: 326895
* [ELF] - Revert r326892, r326893.George Rimar2018-03-071-2/+2
| | | | | | | Bots are still unhappy: http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/26259 llvm-svn: 326894
* [ELF] - Report LMA region overflows.George Rimar2018-03-071-2/+2
| | | | | | | | | We do not report LMA region overflows currently. Both GNU linkers do that. The patch implements it. Differential revision: https://reviews.llvm.org/D44094 llvm-svn: 326892
* [ELF] - Allow discarding .hash and .gnu.hash from linker script.George Rimar2018-03-071-0/+8
| | | | | | | | | Currently, LLD segfaults when linker script attempts to discard one of the hash sections. This patch fixes that. Differential revision: https://reviews.llvm.org/D44012 llvm-svn: 326891
* [ELF] - Support moving location counter when MEMORY is used.George Rimar2018-03-051-29/+24
| | | | | | | | | | | | | | | | We do not expand memory region correctly for following scripts: .foo.1 : { *(.foo.1) . += 0x1000; } > ram Patch generalizes expanding of output sections and memory regions in one place and fixes the issue. Differential revision: https://reviews.llvm.org/D43999 llvm-svn: 326688
* [ELF] - Report error when memory region is overflowed by data commands.George Rimar2018-03-021-12/+15
| | | | | | | | | | | | | | | | | | LLD can not catch a memory area overflow when using a data command. If we have the script below: .foo : { *(.foo) BYTE(0x1) } > ram where BYTE overflows the ram region, we do not report it currently. Patch fixes that. Differential revision: https://reviews.llvm.org/D43948 llvm-svn: 326545
* Don't allocate a header bellow address 0.Rafael Espindola2018-03-011-4/+18
| | | | | | | | | | | | With the current code if the script has a PHDRS we always obey and try to allocate a header. This can cause Min - HeaderSize to underflow. It looks like bfd actually prints an error for this case. With this patch we do the same. Found while looking at pr36515. llvm-svn: 326441
* [ELF] - Do not remove empty sections that use symbols in expressions.George Rimar2018-03-011-5/+4
| | | | | | | | | | | | | | | 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-6/+30
| | | | | | | 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
* Simplify. NFC.Rafael Espindola2018-02-281-3/+3
| | | | llvm-svn: 326344
* Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.Rui Ueyama2018-02-281-1/+1
| | | | | | | | | This should resolve the issue that lld build fails in some hosts that uses case-insensitive file system. Differential Revision: https://reviews.llvm.org/D43788 llvm-svn: 326339
* [ELF] Process linker scripts deeper when declaring symbols.Igor Kudrin2018-02-281-14/+33
| | | | | | | | We should process symbols inside output section declarations the same way as top-level ones. Differential Revision: https://reviews.llvm.org/D43008 llvm-svn: 326305
* Put undefined symbols from shared libraries in the symbol table.Rafael Espindola2018-02-271-4/+0
| | | | | | | With the recent fixes these symbols have more in common than not with regular undefined symbols. llvm-svn: 326242
* [ELF] Create and export symbols provided by a linker script if they ↵Igor Kudrin2018-02-271-3/+7
| | | | | | | | | | | referenced by DSOs. It should be possible to resolve undefined symbols in dynamic libraries using symbols defined in a linker script. Differential Revision: https://reviews.llvm.org/D43011 llvm-svn: 326176
* Keep flags from phantom synthetic sections.Rafael Espindola2018-02-261-20/+1
| | | | | | | | | | | | | | | | | | | | | 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] Fix IsPreemptible comment and typo. NFCFangrui Song2018-02-231-1/+1
| | | | llvm-svn: 325963
* [ELF] - Do not remove empty output sections that are explicitly assigned to ↵George Rimar2018-02-231-21/+17
| | | | | | | | | | | | | phdr in script. This continues direction started in D43069. We can keep sections that are explicitly assigned to segment in script. It helps to simplify code. Differential revision: https://reviews.llvm.org/D43571 llvm-svn: 325887
* [ELF] - Report error if removed empty output section declaration used ↵George Rimar2018-02-231-0/+7
| | | | | | | | | | | | | | undefined symbols. This is for fixing PR36297. Issue itself is that if we have SECTIONS { .bar (a+b) : { *(.stub) } }; script and no section .stub, when LLD will remove .bar, but produce output with undefined symbols a and b. Differential revision: https://reviews.llvm.org/D43069 llvm-svn: 325875
* [ELF] Add comment for preemptible and fix typo. NFCFangrui Song2018-02-231-1/+1
| | | | | | | | Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D43642 llvm-svn: 325855
* [ELF] - Support COPY, INFO, OVERLAY output sections attributes.George Rimar2018-02-161-0/+2
| | | | | | | | | | | | | | 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
* [ELF] - Make defsym to work correctly with reserved symbols.George Rimar2018-02-071-1/+1
| | | | | | | | | | | | Previously --defsym=foo2=etext+2 would produce incorrect value for foo2 because expressions did not work correctly with reserved symbols, section offset was calculated wrong for them. Fixes PR35744. Differential revision: https://reviews.llvm.org/D42911 llvm-svn: 324461
* Sort orphan section if --symbol-ordering-file is given.Rafael Espindola2018-01-301-22/+8
| | | | | | Before this patch orphan sections were not sorted. llvm-svn: 323779
* [ELF] - Define linkerscript symbols early.George Rimar2018-01-301-7/+43
| | | | | | | | | | | | | | | | Currently symbols assigned or created by linkerscript are not processed early enough. As a result it is not possible to version them or assign any other flags/properties. Patch creates Defined symbols for -defsym and linkerscript symbols early, so that issue from above can be addressed. It is based on Rafael Espindola's version of D38239 patch. Fixes PR34121. Differential revision: https://reviews.llvm.org/D41987 llvm-svn: 323729
* Move LMAOffset from the OutputSection to the PhdrEntry. NFC.Rafael Espindola2018-01-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | 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
* Improve LMARegion handling.Rafael Espindola2018-01-251-1/+8
| | | | | | | | | | | | This fixes the crash reported at PR36083. The issue is that we were trying to put all the sections in the same PT_LOAD and crashing trying to write past the end of the file. This also adds accounting for used space in LMARegion, without it all 3 PT_LOADs would have the same physical address. llvm-svn: 323449
* Simplify. NFC.Rafael Espindola2018-01-251-9/+5
| | | | llvm-svn: 323440
OpenPOWER on IntegriCloud