summaryrefslogtreecommitdiffstats
path: root/lld/test/ELF/linkerscript
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] Change default output section type to SHT_NOBITSJake Ehrlich2017-12-115-8/+7
| | | | | | | | | | | | | | | | When an output section has no byte commands and has no input sections then it would be ideal if the type of the section is SHT_NOBITS so that the file can take up less space. This change sets the default type of of output sections to SHT_NOBITS instead of SHT_PROGBITS to allow this. This required some minor test changes (which double as tests for this new behavior) but extend-pt-load.s had be changed in a non-trivial way. Since it seems to me that the point of the test is to point out the consequences of how flags are assigned to output sections that don't have input sections I changed the test to work and still show how the memsize of the executable segment was changed. Differential Revision: https://reviews.llvm.org/D41082 llvm-svn: 320437
* [ELF] When a relocation is out of range print the value and the rangeAlexander Richardson2017-12-111-1/+1
| | | | | | | | | | | | Reviewers: ruiu, grimar Reviewed By: ruiu Subscribers: emaste, nemanjai, javed.absar, kbarton, llvm-commits Differential Revision: https://reviews.llvm.org/D40962 llvm-svn: 320416
* Create reserved symbols early so they can be versioned.Rafael Espindola2017-12-111-0/+28
| | | | | | | | | | | | | | | | | | | | | This fixes pr35570. We were creating these symbols after parsing version scripts, so they could not be versioned. We cannot move the version script parsing later because we need it for lto. One option is to move both addReservedSymbols and createSyntheticSections earlier. The disadvantage is that some sections created by createSyntheticSections replace other input sections. For example, gdb index replaces .debug_gnu_pubnames, so it wants to run after gc sections so that it can set S->Live to false. What this patch does instead is to move just the ElfHeader creation early. llvm-svn: 320390
* Fix a test that didn't actually test anything.Rui Ueyama2017-12-081-2/+2
| | | | llvm-svn: 320117
* [ELF] - Produce relocation section name consistent with output section name ↵George Rimar2017-12-012-1/+23
| | | | | | | | | | | | | | | | | when --emit-reloc used with linker script. This is for "Bug 35474 - --emit-relocs produces wrongly-named reloc sections". LLD currently for scripts like: .text.boot : { *(.text.boot) } emits relocation section with name .rela.text because does not take redefined name of output section into account and builds section name using rules for non-scripted case. Patch fixes this oddness. Differential revision: https://reviews.llvm.org/D40652 llvm-svn: 319526
* Add missing test. NFC.Rafael Espindola2017-11-302-0/+18
| | | | | | | | | | We had no tests for what PROVIDE should do if there is a shared symbol with the same name. In both bfd and our existing implementation PROVIDE wins. Add a test for that. llvm-svn: 319486
* Handle copy relocations in symbol assignments.Rafael Espindola2017-11-303-0/+44
| | | | | | | | | | | When a linker script has "foo = bar" and bar is the result of a copy relocation foo should point to the same location in .bss. This is part of a growing evidence that copy relocations should be implemented by using replaceSymbol to replace the SharedSymbol with a Defined. llvm-svn: 319449
* [ELF] Fall back to search dirs for linker scripts specified with -TAlexander Richardson2017-11-202-1/+20
| | | | | | | | | | | | | | | | | | | | Summary: This matches the behaviour of ld.bfd: https://sourceware.org/binutils/docs/ld/Options.html#Options If scriptfile does not exist in the current directory, ld looks for it in the directories specified by any preceding '-L' options. Multiple '-T' options accumulate. Reviewers: ruiu, grimar Reviewed By: ruiu, grimar Subscribers: emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D40129 llvm-svn: 318655
* [ELF][MIPS] Fix crash in LLD when linking code that needs PIC thunksAlexander Richardson2017-11-201-0/+40
| | | | | | | | | | | | | | | | | | | | | | | Summary: The bug triggers when the following conditions are met: - A thunk is created in a given input section S - A linker script is specified - There is at least one matcher in the linker script .text section output that does not match any of the sections in the input files, before the matcher that matches section S. The issue was found when linking the FreeBSD kernel for MIPS when built with -fPIC. Patch by Alfredo Mazzinghi. Reviewers: ruiu, psmith, atanasyan Reviewed By: ruiu Subscribers: peter.smith, emaste, sdardis, krytarowski, llvm-commits Differential Revision: https://reviews.llvm.org/D40174 llvm-svn: 318653
* Drop conflicting sh_entsize values.Rafael Espindola2017-11-151-1/+1
| | | | | | | | An output section can include elements from two input sections with different sh_entsize. When that happens the output section itself should not have a sh_entsize. llvm-svn: 318311
* Propagate sh_entsize out.Rafael Espindola2017-11-151-1/+1
| | | | | | | | | | No difference in practice other than having sh_entsize in the output. This should simplify the patch for handling SHF_MERGE in -r. Based on a patch by George Rimar. llvm-svn: 318306
* [ELF] - Linkerscript: fixed non-determinism when handling MEMORY.George Rimar2017-11-031-0/+23
| | | | | | | | | | | | | When findMemoryRegion do search to find a region for output section it iterates over MemoryRegions which is DenseMap and so does not guarantee iteration in insertion order. As a result selected region depends on its name and not on its definition position Testcase shows the issue, patch fixes it. Behavior after applying the patch seems consistent with bfd. Differential revision: https://reviews.llvm.org/D39544 llvm-svn: 317307
* [ELF] - Implement --orphan-handling option.George Rimar2017-10-251-24/+44
| | | | | | | | | | | | | | | | | | It is PR34946. Spec (http://man7.org/linux/man-pages/man1/ld.1.html) tells about --orphan-handling=MODE, option where MODE can be one of four: "place", "discard", "warn", "error". Currently we already report orphans when -verbose given, what becomes excessive with option implemented. Patch stops reporting orphans when -versbose is given, and support "place", "warn" and "error" modes. It is not yet clear that "discard" mode is useful so it is not supported. Differential revision: https://reviews.llvm.org/D39000 llvm-svn: 316583
* [ELF] - Linkerscript: fix issue with SUBALIGN.George Rimar2017-10-252-0/+25
| | | | | | | | | | | | | | | This is PR34886. SUBALIGN command currently triggers failture if result expression is zero. Patch fixes the issue, treating zero as 1, what is consistent with other places and ELF spec it seems. Patch also adds "is power of 2" check for this and other expressions returning alignment. Differential revision: https://reviews.llvm.org/D38846 llvm-svn: 316580
* [ELF] When placing orphans, handle case when last section is deadPetr Hosek2017-10-231-0/+25
| | | | | | | | | | | | | | | 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
* [ELF] - Linkerscript: Add `~` as separate math token.George Rimar2017-10-121-1/+1
| | | | | | | | | | | | | | | | | | Previously we did not support following: foo = ~0xFF; and had to add space before numeric value: foo = ~ 0xFF That was constistent with ld.bfd < 2.30, which shows: script.txt:3: undefined symbol `~2' referenced in expression, but inconsistent with gold. It was fixed for ld.bfd 2.30 as well: https://sourceware.org/bugzilla/show_bug.cgi?id=22267 Differential revision: https://reviews.llvm.org/D36508 llvm-svn: 315569
* [ELF] - Do not set output section flags except SHF_{ALLOC,WRITE,EXECINSTR}.George Rimar2017-10-112-0/+39
| | | | | | | | | | | | | | | | | | | | | | | This is PR34546. Currently LLD creates output sections even if it has no input sections, but its command contains an assignment. Committed code just assigns the same flag that was used in previous live section. That does not work sometimes. For example if we have following script: .ARM.exidx : { *(.ARM.exidx*) } .foo : { _foo = 0; } } Then first section has SHF_LINK_ORDER flag. But section foo should not. That was a reason of crash in OutputSection::finalize(). LLD tried to calculate Link value, calling front() on empty input sections list. We should only keep access flags and omit all others when creating such sections. Patch fixes the crash observed. Differential revision: https://reviews.llvm.org/D37736 llvm-svn: 315441
* [ELF] Set Dot initially to --image-base value when using linker scriptsJames Henderson2017-10-101-0/+18
| | | | | | | | | | | | | | | | | | | | | When parsing linker scripts, LLD previously started with a '.' value of 0, regardless of the internal default image base for the target, and regardless of switches such as --image-base. It seems reasonable to use a different image base value when using linker scripts and --image-base is specified, since otherwise the switch has no effect. This change does this, as well as removing unnecessary initialisation of Dot where it is not used. The default image base should not be used when processing linker scripts, because this will change the behaviour for existing linker script users, and potentially result in invalid output being produced, as a subsequent assignment to Dot could move the location counter backwards. Instead, we maintain the existing behaviour of starting from 0 if --image-base is not specified. Reviewers: ruiu Differential Revision: https://reviews.llvm.org/D38360 llvm-svn: 315293
* [LLD] Fix findOrphanPos to consistently ignore "dead" OutputSection'sAndrew Ng2017-10-101-0/+34
| | | | | | | | | | | | | | 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
* [ELF] - Do --hash-style=both by default.George Rimar2017-10-0613-18/+18
| | | | | | | | | | | | | | Its PR34712, GNU linkers recently changed default values to "both" of "sysv". Patch do the same for all targets except MIPS, where .gnu.hash section is not yet supported. Code suggested by Rui Ueyama. Differential revision: https://reviews.llvm.org/D38407 llvm-svn: 315051
* Fix header location with PHDR.Rafael Espindola2017-09-281-0/+13
| | | | | | | | | We were not subtracting its size, causing it to overlap with section data. Fixes PR34750. llvm-svn: 314440
* [ELF] - Report orphan sections if -verbose given.George Rimar2017-09-251-0/+34
| | | | | | | | | When -verbose is specified, patch outputs names of each input orphan section assigned to output. Differential revision: https://reviews.llvm.org/D37517 llvm-svn: 314098
* Consider ForceAbsolute again in moveAbsRight.Rafael Espindola2017-09-201-0/+17
| | | | | | | | | This patch goes back to considering ForceAbsolute in moveAbsRight, but only if the second argument is not already absolute. With this we can handle "foo + ABSOLUTE(foo)" and "ABSOLUTE(foo) + foo". llvm-svn: 313800
* Consider only A.Sec in moveAbsRight.Rafael Espindola2017-09-201-3/+4
| | | | | | | | | | | | | | The idea of this function is to simplify the implementation of binary operators like add. A value might be absolute because of an ABSOLUTE expression, but it still depends on the value of a section and we might not be able to evaluate it early. We should keep such values on the LHS, so that we can delay the evaluation. We can now handle both "1 + ABSOLUTE(foo)" and "ABSOLUTE(foo) + 1". llvm-svn: 313794
* Add a special case for trivial alignment.Rafael Espindola2017-09-201-4/+10
| | | | | | | | | | | Normally to find the offset of a value in a section, we have to compute the value since the alignment is defined on the final address. If the alignment is trivial, we can skip the value computation. This allows us to know the offset even in cases where we cannot yet know the value. llvm-svn: 313777
* Don't try to compute a value that is known to fail.Rafael Espindola2017-09-201-0/+4
| | | | | | | | | We try to evaluate expressions early when possible, but it is not possible to evaluate them early if they are based on a section. Before we would get this wrong on ABSOLUTE expressions. llvm-svn: 313764
* Tweak orphan section placement.Rafael Espindola2017-09-191-0/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | Given a linker script that ends in .some_sec { ...} ; __stack_start = .; . = . + 0x2000; __stack_end = .; lld would put orphan sections like .comment before __stack_end, corrupting the intended meaning. The reason we don't normally move orphans past assignments to . is to avoid breaking rx_sec : { *(rx_sec) } . = ALIGN(0x1000); /* The RW PT_LOAD starts here*/ but in this case, there is nothing after and it seems safer to put the orphan section last. This seems to match bfd's behavior and is convenient for writing linker scripts that care about the layout of SHF_ALLOC sections, but not of any non SHF_ALLOC sections. llvm-svn: 313646
* Align addresses, not offsets.Rafael Espindola2017-09-121-4/+12
| | | | | | | This fixes two more cases where we were aligning the offset in a section, instead of the final address. llvm-svn: 312983
* Correct ALIGN expression when inside a section.Rafael Espindola2017-09-111-0/+14
| | | | | | | | | | | | | | | When given foobar = ALIGN(., 0x100); my expectation from what the manual says is that the final address of foobar will be aligned. It seems that bfd aligns the offset in the section, which causes some odd results if the section is not 0x100 aligned. Gold aligns the address. This changes lld to align the final address. llvm-svn: 312979
* Update testcases for llvm-dwarfdump command line interface changeAdrian Prantl2017-09-111-2/+2
| | | | llvm-svn: 312976
* [ELF] Fix issue with test when build path contains '@'James Henderson2017-09-111-3/+3
| | | | | | | | | | | | | | | '@' is a valid character in file paths, but the linker script tokenizer treats it as a separate token. This was leading to an unexpected test failure, on our local builds. This patch changes the test to quote the path to prevent this happening. An alternative would have been to add '@' to the list of "unquoted tokens" in ScriptLexer.cpp, but ld.bfd has the same behaviour as the current LLD. Reviewers: ruiu Differential Revision: https://reviews.llvm.org/D37689 llvm-svn: 312922
* Currently lld creates a single section to collect all commons. There is no wayDmitry Mikulin2017-09-086-10/+198
| | | | | | | | | | | | | | | to separate commons based on file name patterns. The following linker script construct does not work because commons are allocated before section placement is done and the only synthesized BssSection that holds all commons has no file associated with it: SECTIONS { .common_0 : { *file0.o(COMMON) }} This patch changes the allocation of commons to create a section per common symbol and let the section logic do the layout. Differential revision: https://reviews.llvm.org/D37489 llvm-svn: 312796
* [ELF] - Simplify and improve symbols.s testcase.George Rimar2017-09-081-8/+5
| | | | | | | | | | | | There is no need to check anything excepr that symbol is not in output. Previously additional iformation like symbol values or flags were checked, that was not correct. For example if we would provide symbol with different value/visibility/type for case when should not provide symbol at all, testcase would not fail. llvm-svn: 312779
* [ELF] - Linkerscript: implement REGION_ALIAS.George Rimar2017-09-081-0/+54
| | | | | | | | | | | | REGION_ALIAS(alias, region) Alias names can be added to existing memory regions created with the MEMORY command. Each name corresponds to at most one memory region. Differential revision: https://reviews.llvm.org/D37477 llvm-svn: 312777
* Detect linker script INCLUDE cycles.Rui Ueyama2017-09-061-0/+15
| | | | | | Differential Revision: https://reviews.llvm.org/D37524 llvm-svn: 312656
* [ELF] - Linkerscript: set load address correctly if MEMORY command used.George Rimar2017-09-061-0/+46
| | | | | | | | | | | Previously LLD did not calculate LMAOffset correctly when AT and MEMORY were used together. Patch fixes PR34407. Differential revision: https://reviews.llvm.org/D37469 llvm-svn: 312625
* [ELF] Generate symbol assignments for predefined symbolsPetr Hosek2017-09-011-0/+6
| | | | | | | | | | | | | | | | | | | The problem with symbol assignments in implicit linker scripts is that they can refer synthetic symbols such as _end, _etext or _edata. The value of these symbols is currently fixed only after all linker script commands are processed, so these assignments will be using non-final and hence invalid value. Rather than fixing the symbol values after all command processing have finished, we instead change the logic to generate symbol assignment commands that set the value of these symbols while processing the commands, this ensures that the value is going to be correct by the time any reference to these symbol is processed and is equivalent to defining these symbols explicitly in linker script as BFD ld does. Differential Revision: https://reviews.llvm.org/D36986 llvm-svn: 312305
* Currently lld uses base names of files to match against file patterns inDmitry Mikulin2017-08-241-4/+43
| | | | | | | | | | linker script SECTION rules. This patch extends it to use a fully specified file name as it appears in --trace output to match agains, i.e, "<path>/<objname>.o" or "<path>/<libname>.a(<objname>.o)". Differential Revision: https://reviews.llvm.org/D37031 llvm-svn: 311713
* [ELF] Don't output headers into a segment if there's no space for themPetr Hosek2017-08-235-40/+37
| | | | | | | | | | | | | | | | | | | | | | Currently, LLD checks whether there's enough space for headers by checking if headers fit below the address of the first allocated section. However, that's always thue if the binary doesn't start at zero which means that LLD always emits a segment for headers, even if no other sections belong to that segment. This is a problem in cases when linker script is being used with a non-zero start address when we don't want to make the headers visible by not leaving enough space for them. This pattern is common in embedded programming but doesn't work in LLD. This patch changes the behavior of LLD in case when linker script is being to match the behavior of BFD ld and gold, which is to only place headers into a segment when they're covered by some output section. Differential Revision: https://reviews.llvm.org/D36256 llvm-svn: 311586
* [ELF] - Do not report multiple errors for single one in ScriptLexer::setError.George Rimar2017-08-232-8/+8
| | | | | | | | | | Previously up to 3 errors were reported at once, with patch we always will report only one, just like in other linker code. Differential revision: https://reviews.llvm.org/D37015 llvm-svn: 311537
* [ELF] - Do not segfault when doing logical and/or operations on symbols that ↵George Rimar2017-08-211-0/+3
| | | | | | | | | | | have no output sections. Previously we would crash on samples from testcase, because were trying to access zero pointer to output section. Differential revision: https://reviews.llvm.org/D36145 llvm-svn: 311311
* [ELF] - Don't segfault when accessing location counter inside MEMORY command.George Rimar2017-08-171-0/+6
| | | | | | | | | | | We would previously crash on next script: MEMORY { name : ORIGIN = .; } Patch fixes that. Differential revision: https://reviews.llvm.org/D36138 llvm-svn: 311073
* [ELF, LinkerScript] Support ! operator in linker script.Hafiz Abid Qadeer2017-08-101-0/+6
| | | | | | | | | | | | | | Summary: This small patch adds the support for ! operator in linker scripts. Reviewers: ruiu, rafael Reviewed By: ruiu Subscribers: meadori, grimar, emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D36451 llvm-svn: 310607
* [ELF] - Linkerscript: disallow discarding COMMON.George Rimar2017-08-101-0/+7
| | | | | | | | | | | | This patch restricts following construction: /DISCARD/ : { *(COMMON) } Previously LLD would crash. Differential revision: https://reviews.llvm.org/D36468 llvm-svn: 310554
* [ELF] - Fix "--symbol-ordering-file doesn't work with linker scripts"George Rimar2017-08-041-0/+23
| | | | | | | | | | | | | | | 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
* [ELF] - Do not segfault if linkerscript tries to access Target too early.George Rimar2017-08-031-0/+10
| | | | | | | | | | | | | | Following possible scripts triggered accessing to Target when it was not yet initialized (was nullptr). MEMORY { name : ORIGIN = DATA_SEGMENT_RELRO_END; } MEMORY { name : ORIGIN = CONSTANT(COMMONPAGESIZE); } Patch errors out instead. Differential revision: https://reviews.llvm.org/D36140 llvm-svn: 309953
* [ELF] - Do not crash when ALIGN/DATA_SEGMENT_ALIGN expression used with zero ↵George Rimar2017-07-282-0/+17
| | | | | | | | | | | | | value. Previously we would crash when tried to ALIGN(0). Patch uses value 1 instead in this case, that looks to be consistent with GNU linkers and reasonable and simple behavior itself. Differential revision: https://reviews.llvm.org/D35942 llvm-svn: 309372
* [ELF, LinkerScript] Memory region name parsing fixMeador Inge2017-07-261-2/+2
| | | | | | | | | | | | | | | | | This patch fixes a small issue with respect to how memory region names are parsed on output section descriptions. For example, consider: .text : { *(.text) } > rom That can also be written like: .text : { *(.text) } >rom The latter form is accepted by GNU LD and is fairly common. Differential Revision: https://reviews.llvm.org/D35920 llvm-svn: 309191
* [ELF] - Fix calculation of memory region offset.George Rimar2017-07-251-0/+14
| | | | | | | | | | | | | | This is PR33714. Previously for each input section offset of memory region was incremented on a size of output section. That resulted in a wrong error message saying about overflow. Patch fixes that. Differential revision: https://reviews.llvm.org/D35803 llvm-svn: 308955
* If user requested section alignment is greater than MaxPageSize, propagate ↵Dmitry Mikulin2017-07-241-1/+2
| | | | | | | | it to segment headers correctly. Differential Revision: https://reviews.llvm.org/D35813 llvm-svn: 308930
OpenPOWER on IntegriCloud