summaryrefslogtreecommitdiffstats
path: root/lld/test/ELF/linkerscript
Commit message (Collapse)AuthorAgeFilesLines
...
* Handle a section being more aligned than a page size.Rafael Espindola2017-07-221-0/+10
| | | | llvm-svn: 308812
* Don't crash on an empty section with an ALIGN.Rafael Espindola2017-07-221-0/+6
| | | | llvm-svn: 308809
* [ELF] Align the value if needed when computing the expressionPetr Hosek2017-07-202-0/+27
| | | | | | | | | Also add the test cases for the addition and subtraction both for the relative and absolute case. Differential Revision: https://reviews.llvm.org/D35346 llvm-svn: 308692
* Fix REQUIRES line.Rafael Espindola2017-07-181-1/+1
| | | | llvm-svn: 308385
* Fix a crash.Rafael Espindola2017-07-181-0/+7
| | | | | | | | | This is PR33821. What we really want to check in here is if the output section was created, not if the command was empty. llvm-svn: 308382
* [LLD] Mark a number of x86 only tests to require x86Jon Chesterfield2017-07-181-0/+1
| | | | | | | | | | | Noticed while testing for an out of tree target. There are probably more tests that should be so marked. I'm not sure who owns these tests so I've added a few names I recognise from the recent history. With advice from probinson, ruiu, rafael and dramatically improved by davidb. Thank you all! Differential Revision: https://reviews.llvm.org/D34685 llvm-svn: 308335
* [ELF] Fix writing the content of the .got section in a wrong place.Igor Kudrin2017-07-141-0/+23
| | | | | | | | | | In filling the .got sections, InputSection::OutSecOff was added twice when finding the position to apply a relocation: first time in InputSection::writeTo() and then in SectionBase::getOffset(). Differential revision: https://reviews.llvm.org/D34232 llvm-svn: 308003
* [ELF] - Allow moving location counter backward in some cases.George Rimar2017-07-122-4/+15
| | | | | | | | | | | | Patch removes restriction about moving location counter backwards outside of output sections declarations. That may be useful for some apps relying on such scripts, known example is linux kernel. Differential revision: https://reviews.llvm.org/D34977 llvm-svn: 307794
* [ELF] Remove unused synthetic sections from script commandsPetr Hosek2017-07-031-0/+18
| | | | | | | | | | | | | | Script commands are processed before unused synthetic sections are removed. Therefore, if a linker script matches one of these sections it'll get emitted as an empty output section because the logic for removing unused synthetic sections ignores script commands which could have already matched and captured one of these sections. This patch fixes that by also removing the unused synthetic sections from the script commands. Differential Revision: https://reviews.llvm.org/D34800 llvm-svn: 307037
* [LLD][LinkerScript] Allow non-alloc sections to be assigned to segments.Andrew Ng2017-07-031-0/+44
| | | | | | | | | | | | | | | | | | | | This patch makes changes to allow sections without the SHF_ALLOC bit to be assigned to segments in a linker script. The assignment of output sections to segments is performed in LinkerScript::createPhdrs. Previously, this function would bail as soon as it encountered an output section which did not have the SHF_ALLOC bit set, thus preventing any output section without SHF_ALLOC from being assigned to a segment. This restriction has now been removed from LinkerScript::createPhdrs and instead a check for SHF_ALLOC has been added to LinkerScript::adjustSectionsAfterSorting to not propagate program headers to sections without SHF_ALLOC which matches the behaviour of bfd linker scripts. Differential Revision: https://reviews.llvm.org/D34204 llvm-svn: 307013
* Check the produced file instead of stderr.Rafael Espindola2017-06-281-2/+3
| | | | | | | | | | It is somewhat pointless to check that a specific error is not produced. That is already checked by the ld.lld exit value. Instead make the test a bit stronger by checking that the output file has the expected symbol and section. llvm-svn: 306496
* Prefer -Ttext over linker script values.Rafael Espindola2017-06-201-0/+11
| | | | | | | | | | | | | | | | | | | | I found this while trying to build u-boot. It uses -Ttext in combination with linker scripts. My first reaction was to change the linker scripts to have the correct value, but I found that it is actually quite convenient to have -Ttext take precedence. By having just .text : { *(.text) } In the script, they can define the text address in a single Makefile and pass it to ld with -Ttext and for the C code with -DFoo=value. Doing the same with linker scripts would require them to be generated during the build. llvm-svn: 305766
* [LLD][LinkerScript] Add support for segment NONE.Andrew Ng2017-06-191-0/+39
| | | | | | | | | | | | | This patch adds support for segment NONE in linker scripts which enables the specification that a section should not be assigned to any segment. Note that GNU ld does not disallow the definition of a segment named NONE, which if defined, effectively overrides the behaviour described above. This feature has been copied. Differential Revision: https://reviews.llvm.org/D34203 llvm-svn: 305700
* Error when discarding .dynstr.Rafael Espindola2017-06-161-0/+5
| | | | | | We would crash before. llvm-svn: 305615
* Error when discarding .dynsym.Rafael Espindola2017-06-161-0/+5
| | | | | | We would crash instead before. llvm-svn: 305614
* Error on trying to discard .dynamic.Rafael Espindola2017-06-162-6/+13
| | | | | | We would crash instead before. llvm-svn: 305613
* [ELF] Mark symbols referenced from linker script as livePetr Hosek2017-06-151-0/+16
| | | | | | | | | This is necessary to ensure that sections containing symbols referenced from linker scripts (e.g. in data commands) don't get GC'd. Differential Revision: https://reviews.llvm.org/D34195 llvm-svn: 305452
* Set non alloc section address to 0 earlier.Rafael Espindola2017-06-132-2/+2
| | | | | | | | | | | | | | | Currently we do layout as if non alloc sections had an actual address and then set it to zero. This produces a few odd results where a symbol has an address that is inconsistent with the section address. The simplest way to fix it is probably to just set the address earlier. The behavior of bfd seems to be similar, but it only sets the non alloc section address is missing from the linker script or if the script has an explicit " : 0" setting the address of the output section (which the default script does). llvm-svn: 305323
* Also check section address in test.Rafael Espindola2017-06-121-0/+3
| | | | | | | This shows an oddity of this output. While the section address is 0, the the symbol address is computed as if the section was allocatable. llvm-svn: 305250
* Fix a bug in output section directive.Rui Ueyama2017-06-081-1/+1
| | | | | | | | | | Previously, it couldn't parse SECTIONS .text (0x1000) : { *(.text) } because "(" was interpreted as the begining of the "(NOLOAD)" directive. llvm-svn: 305006
* [ELF] - Linkerscript: implement NOLOAD section type.George Rimar2017-06-071-0/+46
| | | | | | | | | | | | | | | This is PR32351 Each output section may have a type. The type is a keyword in parentheses. (https://sourceware.org/binutils/docs/ld/Output-Section-Type.html#Output-Section-Type) This patch support only one type, it is NOLOAD. If output section has such type, we force it to be SHT_NOBITS. More details are available on a review page. Differential revision: https://reviews.llvm.org/D33647 llvm-svn: 304925
* [ELF] - Do not merge relocation sections by name when using --emit-relocs.George Rimar2017-06-071-0/+20
| | | | | | | | | | | | Previously we would merge relocation sections by name. That did not work in some cases, like testcase shows. Patch implements logic to merge relocation sections if their target sections were merged into the same output section. Differential revision: https://reviews.llvm.org/D33824 llvm-svn: 304886
* [ELF] - Linkerscript: improved error reporting.George Rimar2017-06-072-2/+2
| | | | | | | | | | | | | | | | When linking linux kernel LLD currently reports next errors: ld: error: unable to evaluate expression: input section .head.text has no output section assigned ld: error: At least one side of the expression must be absolute ld: error: At least one side of the expression must be absolute That does not provide file/line information and overall looks unclear. Patch adds location information to ExprValue and that allows to provide more clear error messages. Differential revision: https://reviews.llvm.org/D33943 llvm-svn: 304881
* [ELF] - Do not crash when linkerscript applies fill to .bss.George Rimar2017-05-301-0/+7
| | | | | | | | | | | | | | I found that during visual inspection of code while wrote different patch. Script in testcase probably have nothing common with real life, but we segfault currently using it. If output section is known NOBITS, there is no need to create writers threads for doing nothing or proccess any filler logic that is useless here. We can just early return, that is what this patch do. DIfferential revision: https://reviews.llvm.org/D33646 llvm-svn: 304192
* [ELF] Filter out non InputSection members from InputSectionsPetr Hosek2017-05-301-0/+10
| | | | | | | | | InputSections may contain MergeInputSection members which trigger a segmentation fault when trying to cast them to InputSection. Differential Revision: https://reviews.llvm.org/D33628 llvm-svn: 304189
* [ELF] Use late evaluation for ALIGN in expressionPetr Hosek2017-05-302-1/+7
| | | | | | | | | | | | | | | | | | While the following expression is handled fine: PROVIDE_HIDDEN(newsym = oldsym + address); The following expression triggers an error because the expression is evaluated as absolute: PROVIDE_HIDDEN(newsym = ALIGN(oldsym, CONSTANT(MAXPAGESIZE)) + address); To avoid this error, we use late evaluation for ALIGN by making the alignment an attribute of the expression itself. Differential Revision: https://reviews.llvm.org/D33629 llvm-svn: 304185
* Order writable executable sections before writable ones.Rafael Espindola2017-05-261-1/+1
| | | | | | | | | | | | | | On SPARC, .plt is both writeable and executable. The current way sections are sorted means that lld puts it after .data/.bss. but it really needs to be close to .test to make sure branches into .plt don't overflow. I'd argue that because .bss is supposed to come last on all architectures, we should change the default sort order such that writable and executable sections come before sections that are just writeable. read-only executable sections should still come after sections that are just read-only of course. This diff makes this change. llvm-svn: 304008
* Do not track section types of previous sections, always use PROGBITS for ↵Dmitry Mikulin2017-05-241-0/+9
| | | | | | | | dummy sections. Fix for PR33029. llvm-svn: 303770
* Optimize orphan placement in a general way.Rafael Espindola2017-05-122-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | We used to place orphans by just using compareSectionsNonScript. Then we noticed that since linker scripts can use another order, we should first try match the section to a given PT_LOAD. But there is nothing special about PT_LOAD. The same issue can show up for PT_GNU_RELRO for example. In general, we have to search for the most similar section and put the orphan next to it. Most similar being defined as how long they follow the same code path in compareSecitonsNonScript. That is what this patch does. We now compute a rank for each output section, with a bit for each branch in what was compareSectionsNonScript. With this findOrphanPos is now fully general and orphan placement can be optimized by placing every section with the same rank at once. The included testcase is a variation of many-sections.s that uses allocatable sections to avoid the fast path in the existing code. Without threads it goes form 46 seconds to 0.9 seconds. llvm-svn: 302903
* [ELF] - Make text section location explicit in early-assign-symbol.s test.George Rimar2017-05-111-2/+2
| | | | | | | | Testcase itself depends on .text section location, which was orphan earlier. Suggested by Rafael Espíndola llvm-svn: 302792
* [ELF] Define __ehdr_start unconditionally even when using linker scriptPetr Hosek2017-05-101-3/+11
| | | | | | | | | | This behavior differs from the semantics implemented by GNU linkers which only define this symbol iff ELF headers are in the memory mapped segment. Differential Revision: https://reviews.llvm.org/D33019 llvm-svn: 302687
* [ELF] - Don't segfault when assigning non-calculatable absolute symbol value.George Rimar2017-05-101-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | This is PR32664. Issue was revealed by linux kernel script which was: SECTIONS { . = (0xffffffff80000000 + ALIGN(0x1000000, 0x200000)); phys_startup_64 = ABSOLUTE(startup_64 - 0xffffffff80000000); .text : AT(ADDR(.text) - 0xffffffff80000000) { ..... *(.head.text) Where startup_64 is in .head.text. At the place of assignment to phys_startup_64 we can not calculate absolute value for startup_64 because .text section has no VA assigned. Two patches were prepared earlier to address this: D32173 and D32174. And in comments for D32173 was suggested not try to support this case, but error out. Differential revision: https://reviews.llvm.org/D32793 llvm-svn: 302668
* Add memory ORIGIN and LENGTH expression supportRui Ueyama2017-05-091-0/+33
| | | | | | | | | | | | | | | Adds support for the ORIGIN and LENGTH linker script built in functions. ORIGIN(memory) Return the origin of the memory region LENGTH(memory) Return the length of the memory region Redo of D29775 for refactored linker script parsing. Patch by Robert Clarke Differential Revision: https://reviews.llvm.org/D32934 llvm-svn: 302564
* [ELF] - Linkerscript: support combination of linkerscript and ↵George Rimar2017-05-082-0/+39
| | | | | | | | | | | | --compress-debug-sections. Previously it was impossible to use linkerscript with --compress-debug-sections because of assert failture: Assertion failed: isFinalized(), file C:\llvm\lib\MC\StringTableBuilder.cpp, line 64 Patch fixes the issue llvm-svn: 302413
* Fix pr32816.Rafael Espindola2017-05-011-0/+33
| | | | | | | | When using linkerscripts we were trying to sort SHF_LINK_ORDER sections too early. Instead of always doing two runs of assignAddresses, record the section order in processCommands. llvm-svn: 301830
* Create an OutputSection for each non-empty OutputSectionCommand.Rafael Espindola2017-04-261-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We were already pretty close, the one exception was when a name was reused in another SECTIONS directive: SECTIONS { .text : { *(.text) } .data : { *(.data) } } SECTIONS { .data : { *(other) } } In this case we would create a single .data and magically output "other" while looking at the first OutputSectionCommand. We now create two .data sections. This matches what gold does. If we really want to create a single one, we should change the parser so that the above is parsed as if the user had written SECTIONS { .text : { *(.text) } .data : { *(.data) *(other)} } That is, there should be only one OutputSectionCommand for .data and it would have two InputSectionDescriptions. By itself this patch makes the code a bit more complicated, but is an important step in allowing assignAddresses to operate just on the linker script. llvm-svn: 301484
* Use CHECK-NEXT in a test.Rafael Espindola2017-04-261-7/+7
| | | | | | This will simplify a future patch. llvm-svn: 301415
* [ELF] - Linkerscript: make section with no content to be SHT_PROGBITS by ↵George Rimar2017-04-142-2/+4
| | | | | | | | | | | | | | | | | | default. Imagine next script: SECTIONS { BYTE(0x11); } Section content written to disk will be 0x11. Previous LLD behavior was to make this section SHT_NOBITS. What is not correct because section has content. ld.bfd makes such sections SHT_PROGBITS, this patch do the same. This fixes PR32537 Differential revision: https://reviews.llvm.org/D32016 llvm-svn: 300317
* [ELF] - Cleanup of align.s testcase. NFC.George Rimar2017-04-141-62/+26
| | | | llvm-svn: 300316
* [ELF] LinkerScript: Don't assign zero to all regular symbolsGeorge Rimar2017-04-141-1/+34
| | | | | | | | | | | | This fixes an assertion `Align != 0u && "Align can't be 0."' in llvm::alignTo() when a linker script references a globally defined variable in an ALIGN() context. Patch by Alexander Richardson ! Differential revision: https://reviews.llvm.org/D31984 llvm-svn: 300315
* Fix FILL linker script command.Rui Ueyama2017-04-131-1/+1
| | | | | | | FILL command doesn't need a semicolon. Fixes https://bugs.llvm.org/show_bug.cgi?id=32657 llvm-svn: 300280
* Allow expressions in MEMORY command.Rui Ueyama2017-04-121-1/+1
| | | | | | | | | | Previously, we allowed only integers in this context. Now you can write expressions there. LLD is now able to handle the following linker, for example. MEMORY { rom (rx) : ORIGIN = (1024 * 1024) } llvm-svn: 300131
* Make intentional typos look more obvious.Rui Ueyama2017-04-121-2/+2
| | | | | | | | We do not check for similarities when handling unknown tokens in linker scripts, so "ORIGI" and "LENTH" are not good tokens as a test for unknown tokens, as I was tempted to "fix" them. llvm-svn: 300130
* Remove redundant spaces.Rui Ueyama2017-04-121-7/+7
| | | | llvm-svn: 300129
* Remove useless 0x prefixes.Rui Ueyama2017-04-121-5/+5
| | | | llvm-svn: 300128
* Make a few tests shorter. NFC.Rui Ueyama2017-04-127-95/+29
| | | | llvm-svn: 300120
* [ELF] Recommit r299635 to pad x86 executable sections with 0xccJames Henderson2017-04-074-7/+51
| | | | | | This follows r299748 which fixed a latent bug the original commit exposed. llvm-svn: 299755
* Revert r299635 because it exposed a latent bug.James Henderson2017-04-064-51/+7
| | | | llvm-svn: 299655
* [ELF] Pad x86 executable sections with 0xcc int3 instructionsJames Henderson2017-04-064-7/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Executable sections should not be padded with zero by default. On some architectures, 0x00 is the start of a valid instruction sequence, so can confuse disassembly between InputSections (and indeed the start of the next InputSection in some situations). Further, in the case of misjumps into padding, padding may start to be executed silently. On x86, the "0xcc" byte represents the int3 trap instruction. It is a single byte long so can serve well as padding. This change switches x86 (and x86_64) to use this value for padding in executable sections, if no linker script directive overrides it. It also puts the behaviour into place making it easy to change the behaviour of other targets when desired. I do not know the relevant instruction sequences for trap instructions on other targets however, so somebody should add this separately. Because the old behaviour simply wrote padding in the whole section before overwriting most of it, this change also modifies the padding algorithm to write padding only where needed. This in turn has caused a small behaviour change with regards to what values are written via Fill commands in linker scripts, bringing it into line with ld.bfd. The fill value is now written starting from the end of the previous block, which means that it always starts from the first byte of the fill, whereas the old behaviour meant that the padding sometimes started mid-way through the fill value. See the test changes for more details. Reviewed by: ruiu Differential Revision: https://reviews.llvm.org/D30886 Bugzilla: http://bugs.llvm.org/show_bug.cgi?id=32227 llvm-svn: 299635
* Use uint64_t to keep file size even on 32-bit machines.Rui Ueyama2017-04-051-0/+8
| | | | | | If an output file is too large for 32-bit, we should report an error. llvm-svn: 299592
OpenPOWER on IntegriCloud