summaryrefslogtreecommitdiffstats
path: root/lld/test/ELF/linkerscript
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] - Report LMA region overflows.George Rimar2018-03-071-0/+17
| | | | | | | | | 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/+23
| | | | | | | | | 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-0/+37
| | | | | | | | | | | | | | | | 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 location for div/mod by zero.George Rimar2018-03-051-1/+7
| | | | | | | | | | | "division by zero" or "modulo by zero" are not very informative errors and even probably confusing as does not let to know that error is coming from linker script. Patch adds location reporting. Differential revision: https://reviews.llvm.org/D43934 llvm-svn: 326686
* [ELF] - Report error when memory region is overflowed by data commands.George Rimar2018-03-021-0/+22
| | | | | | | | | | | | | | | | | | 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-0/+11
| | | | | | | | | | | | 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] - Don't crash on broken MEMORY declaration.George Rimar2018-03-011-0/+13
| | | | | | | | | | | LLD crashes with broken scripts shown in testcase, because fails to read memory regon name and accesses MemoryRegions's element which is nullptr. Patch fixes it. Differential revision: https://reviews.llvm.org/D43866 llvm-svn: 326431
* [ELF] - Do not remove empty sections that use symbols in expressions.George Rimar2018-03-011-0/+18
| | | | | | | | | | | | | | | 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
* [ELF] - Fix eh-frame-reloc-out-of-range.test.George Rimar2018-03-011-1/+1
| | | | | | Was broken after recent testcases changes. llvm-svn: 326427
* Convert more tests as linker scripts instead of assembly.Rui Ueyama2018-03-0136-491/+445
| | | | llvm-svn: 326415
* Convert more .s files to linker script files.Rui Ueyama2018-03-0136-468/+506
| | | | | | | | | | | | | | Summary: This change removes large "echo" commands from the test by writing tests themselves as linker scripts. Reviewers: rafael Subscribers: emaste, javed.absar, llvm-commits, arichardson Differential Revision: https://reviews.llvm.org/D43900 llvm-svn: 326403
* Write some tests as linker scripts instead of assembly files.Rui Ueyama2018-02-286-83/+79
| | | | | | | | | | Some linker script test cases contain only a few lines of assembly and a long linker script. Such tests are easier to maintain if we write the main test file as a linkier script instead of assembly. Differential Revision: https://reviews.llvm.org/D43887 llvm-svn: 326363
* Add "%" operator to the linker script.Rui Ueyama2018-02-281-0/+2
| | | | | | | | This patch improves compatibility with GNU linkers. Differential Revision: https://reviews.llvm.org/D43883 llvm-svn: 326348
* [ELF] Process linker scripts deeper when declaring symbols.Igor Kudrin2018-02-282-1/+6
| | | | | | | | 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
* [ELF] Create and export symbols provided by a linker script if they ↵Igor Kudrin2018-02-272-0/+16
| | | | | | | | | | | 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-7/+15
| | | | | | | | | | | | | | | | | | | | | 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] - Do not remove empty output sections that are explicitly assigned to ↵George Rimar2018-02-232-1/+2
| | | | | | | | | | | | | 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/+15
| | | | | | | | | | | | | | 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 testcase documenting flags assigned when empty synthetic section ↵George Rimar2018-02-231-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | is removed. This responds to PR36475, r325763 led to unexprected layout change, though new behavior seems to be more correct. Previously we could have following script: .foo : { *(.foo) } .bar : { *(.synthetic_empty) BYTE(0x11) }} where synthetic_empty is a synthetic section which is empty and hence removed by linker. Before r325763 .bar would receive section flags from .synthetic_empty, but after this revision it receives flags the same as .foo section has. It is the same as if there would not be any synthetic_empty section in a script, so looks reasonable and consistent behavior: .foo : { *(.foo) } .bar : { BYTE(0x11) }} Patch adds testcase to document it. Differential revision: https://reviews.llvm.org/D43632 llvm-svn: 325873
* [ELF] - Simplify testcase. NFC.George Rimar2018-02-212-13/+10
| | | | | | | | This removes script input file and inlines script into testcase body. That is consistent with othet LS tests and makes testcase easier to read. llvm-svn: 325673
* Use toString to print out garbage-collected sections.Rui Ueyama2018-02-171-2/+2
| | | | | | | | | | Currently, archive file name is missing in this message. In general, we should avoid constructing strings in an ad-hoc manner and instead use toString() to get consistent output strings. Differential Revision: https://reviews.llvm.org/D43420 llvm-svn: 325416
* [ELF] - Support COPY, INFO, OVERLAY output sections attributes.George Rimar2018-02-161-0/+33
| | | | | | | | | | | | | | 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] Simplify handling of AT section attribute.Igor Kudrin2018-02-151-0/+36
| | | | | | | | This also makes the behavior close to GNU ld's. Differential Revision: https://reviews.llvm.org/D43284 llvm-svn: 325213
* [ELF] - Fix BB after r324463.George Rimar2018-02-071-1/+1
| | | | | | Test requires arm, but specified x86. llvm-svn: 324464
* [ELF] - Remove unused synthetic sections correctly.George Rimar2018-02-072-1/+10
| | | | | | | | | | | | | | | | This is PR35740 which now crashes because we remove unused synthetic sections incorrectly. We can keep input section description and corresponding output section live even if it must be empty and dead. This results in a crash because SHF_LINK_ORDER handling code tries to access first section which is nullptr in this case. Patch fixes the issue. Differential revision: https://reviews.llvm.org/D42681 llvm-svn: 324463
* Make sure that --no-check-sections doesn't print out warning messages.Rui Ueyama2018-02-071-2/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D42988 llvm-svn: 324434
* Add -{no,}-check-sections flags to enable/disable section overlcheckingRui Ueyama2018-02-021-1/+3
| | | | | | | | GNU linkers have this option. Differential Revision: https://reviews.llvm.org/D42858 llvm-svn: 324150
* Sort each InputSectionDescription individually.Rafael Espindola2018-02-011-0/+6
| | | | | | | | | This fixes pr36190. Thanks to James Henderson for the testcase and for pointing out how to fix this. llvm-svn: 323993
* [ELF] Make overlapping output sections an errorAlexander Richardson2018-01-311-0/+169
| | | | | | | | | | | | | | | | | | | | | | | Summary: While trying to make a linker script behave the same way with lld as it did with bfd, I discovered that lld currently doesn't diagnose overlapping output sections. I was getting very strange runtime failures which I tracked down to overlapping sections in the resulting binary. When linking with ld.bfd overlapping output sections are an error unless --noinhibit-exec is passed and I believe lld should behave the same way here to avoid surprising crashes at runtime. The patch also uncovered an errors in the tests: arm-thumb-interwork-thunk was creating a binary where .got.plt was placed at an address overlapping with .got. Reviewers: ruiu, grimar, rafael Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D41046 llvm-svn: 323856
* Run dos2unix on another file. NFC.Rafael Espindola2018-01-301-18/+18
| | | | llvm-svn: 323796
* Run dos2unix in a few files. NFC.Rafael Espindola2018-01-301-13/+13
| | | | llvm-svn: 323793
* Sort orphan section if --symbol-ordering-file is given.Rafael Espindola2018-01-301-0/+4
| | | | | | Before this patch orphan sections were not sorted. llvm-svn: 323779
* [ELF] - Define linkerscript symbols early.George Rimar2018-01-302-13/+65
| | | | | | | | | | | | | | | | 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
* Put the header in the first PT_LOAD even if that PT_LOAD has a LMAExpr.Rafael Espindola2018-01-291-0/+21
| | | | | | | | | | | | | This should fix PR36017. The root problem is that we were creating a PT_LOAD just for the header. That was technically valid, but inconvenient: we should not be making the ELF discontinuous. The solution is to allow a section with LMAExpr to be added to a PT_LOAD if that PT_LOAD doesn't already have a LMAExpr. llvm-svn: 323625
* Improve LMARegion handling.Rafael Espindola2018-01-251-0/+38
| | | | | | | | | | | | 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
* [ELF] Keep tests from wrinting to the test directory.Benjamin Kramer2018-01-192-14/+14
| | | | llvm-svn: 322943
* Handle parsing AT(ADDR(.foo-bar)).Rafael Espindola2018-01-181-0/+10
| | | | | | | | The problem we had with it is that anything inside an AT is an expression, so we failed to parse the section name because of the - in it. llvm-svn: 322801
* [ELF] - Stop mixing order of -defsym/-script commands.George Rimar2018-01-171-0/+19
| | | | | | | | | | | | | | | | | | | | | Previously we always handled -defsym after other commands in command line. That made impossible to overload values set by -defsym from linker script: test.script: foo = 0x22; -defsym=foo=0x11 -script t.script would always set foo to 0x11. That is inconstent with common logic which allows to override command line options. it is inconsistent with bfd behavior and seems breaks assumption that -defsym is the same as linker script assignment, as -defsyms always handled out of command line order. Patch fixes the handling order. Differential revision: https://reviews.llvm.org/D42054 llvm-svn: 322625
* Fix incorrect physical address on self-referencing AT command.Rafael Espindola2018-01-121-0/+63
| | | | | | | | | | | | When a section placement (AT) command references the section itself, the physical address of the section in the ELF header was calculated incorrectly due to alignment happening right after the location pointer's value was captured. The problem was diagnosed and the first version of the patch written by Erick Reyes. llvm-svn: 322421
* [ELF] - Fix for ld.lld does not accept "AT" syntax for declaring LMA regionGeorge Rimar2018-01-121-0/+81
| | | | | | | | | | | 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
* [ELF] Compress debug sections after assignAddresses and support custom layoutJames Henderson2018-01-081-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, in r320472, I moved the calculation of section offsets and sizes for compressed debug sections into maybeCompress, which happens before assignAddresses, so that the compression had the required information. However, I failed to take account of relocations that patch such sections. This had two effects: 1. A race condition existed when a debug section referred to a different debug section (see PR35788). 2. References to symbols in non-debug sections would be patched incorrectly. This is because the addresses of such symbols are not calculated until after assignAddresses (this was a partial regression caused by r320472, but they could still have been broken before, in the event that a custom layout was used in a linker script). assignAddresses does not need to know about the output section size of non-allocatable sections, because they do not affect the value of Dot. This means that there is no longer a reason not to support custom layout of compressed debug sections, as far as I'm aware. These two points allow for delaying when maybeCompress can be called, removing the need for the loop I previously added to calculate the section size, and therefore the race condition. Furthermore, by delaying, we fix the issues of relocations getting incorrect symbol values, because they have now all been finalized. llvm-svn: 321986
* Align SHT_NOBITS sections is they are the first on a PT_LOAD.Rafael Espindola2018-01-021-0/+18
| | | | | | | | | | | | | | | | | | | We normally want to ignore SHT_NOBITS sections when computing offsets. The sh_offset of section itself seems to be irrelevant and - If the section is in the middle of a PT_LOAD, it will make no difference on the computed offset of the followup section. - If it is in the end of a PT_LOAD, we want to avoid its alignment changing the offset of the followup sections. The issue is if it is at the start of the PT_LOAD. In that case we do have to align it so that the following sections have congruent address and offset module the page size. We were not handling this case. This should fix freebsd kernel link. llvm-svn: 321657
* Fix output section offset and contents when linker script uses memory region ↵Rafael Espindola2017-12-241-0/+36
| | | | | | | | | | | | | | | | | and data commands. Advance the memory region offset when handling a linker script data command such as BYTE or LONG. Failure to advance the offset results in corrupted output with overlapping sections. Update tests to check for this combination of both a) memory regions and b) data commands. Fixes https://bugs.llvm.org/show_bug.cgi?id=35565 Patch by Owen Shaw! llvm-svn: 321418
* Result of subtracting two symbols should be absolute.Rafael Espindola2017-12-221-0/+6
| | | | | | | | | | When two linker script symbols are subtracted, the result should be absolute. This is the behavior of binutils' ld. Patch by Erick Reyes! llvm-svn: 321390
* [ELF] Fix an assignment command at the end of an .ARM.exidx section.Igor Kudrin2017-12-201-0/+17
| | | | | | | | The value of the symbol in the assignment should include the sentinel entry. Differential Revision: https://reviews.llvm.org/D41234 llvm-svn: 321154
* Use # instead of // for comments in a test.Rafael Espindola2017-12-191-4/+4
| | | | | | The test was using both // and # before. llvm-svn: 321049
* [ELF] Remove Duplicate .ARM.exidx sectionsPeter Smith2017-12-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | The ARM.exidx section contains a table of 8-byte entries with the first word of each entry an offset to the function it describes and the second word instructions for unwinding if an exception is thrown from that function. The SHF_LINK_ORDER processing will order the table in ascending order of the functions described by the exception table entries. As the address range of an exception table entry is terminated by the next table entry, it is possible to merge consecutive table entries that have identical unwind instructions. For this implementation we define a table entry to be identical if: - Both entries are the special EXIDX_CANTUNWIND. - Both entries have the same inline unwind instructions. We do not attempt to establish if table entries that are references to .ARM.extab sections are identical. This implementation works at a granularity of a single .ARM.exidx InputSection. If all entries in the InputSection are identical to the previous table entry we can remove the InputSection. A more sophisticated but more complex implementation would rewrite InputSection contents so that duplicates within a .ARM.exidx InputSection can be merged. Differential Revision: https://reviews.llvm.org/D40967 llvm-svn: 320803
* [ELF] Prevent crash in writing an .ARM.exidx sentinel entry.Igor Kudrin2017-12-141-0/+24
| | | | | | | | | | | | We might crash in 'ARMExidxSentinelSection::writeTo()' because it expected the sentinel entry to be put in the same 'InputSectionDescription' as the last real entry. This assumption fails if the last output section command for .ARM.exidx is anything but an input section description, because in this case 'OutputSection::addSection()' creates a new 'InputSectionDescription'. Differential Revision: https://reviews.llvm.org/D41105 llvm-svn: 320668
* Remove trailing whitespace.Rui Ueyama2017-12-125-7/+7
| | | | llvm-svn: 320520
* [ELF] Reset OutputSection size prior to processing linker script commandsJames Henderson2017-12-121-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud