summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Use linker script commands in writeMapFile.Rafael Espindola2017-05-181-3/+0
| | | | | | | | | | This converts the last (chronologically) user of OutputSections to use the linker script commands instead. The idea is to convert all uses after fabricateDefaultCommands, so that we have a single representation. llvm-svn: 303384
* Use a DenseMap in LinkerScript::getCmd.Rafael Espindola2017-05-101-6/+10
| | | | | | This improves many-sections.s with a linker script from 22s to 0.9s. llvm-svn: 302708
* Refactor OutputSection to OutputSectionCommand mapping.Rafael Espindola2017-05-101-31/+24
| | | | | | We now always use getCmd. I will optimize it in a followup commit. llvm-svn: 302706
* Remove one more use of section names.Rafael Espindola2017-05-101-1/+1
| | | | llvm-svn: 302672
* Remove another use of section names. NFC.Rafael Espindola2017-05-101-6/+5
| | | | llvm-svn: 302671
* [ELF] - Don't segfault when assigning non-calculatable absolute symbol value.George Rimar2017-05-101-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove another use of section names. NFC.Rafael Espindola2017-05-101-2/+2
| | | | llvm-svn: 302662
* Don't use section names in getFiller. NFC.Rafael Espindola2017-05-101-2/+2
| | | | | | This is just faster and avoids using names. llvm-svn: 302661
* [ELF] - Linkerscript: support combination of linkerscript and ↵George Rimar2017-05-081-8/+6
| | | | | | | | | | | | --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
* Delete LinkerScript::getSectionIndex.Rafael Espindola2017-05-051-19/+23
| | | | | | | | | We can set SectionIndex tentatively as we process the linker script instead of looking it repeatedly. In general we should try to have as few name lookups as possible. llvm-svn: 302299
* Simplify the header allocation.Rafael Espindola2017-05-041-4/+44
| | | | | | | | | | | | | | | | In the non linker script case we would try very early to find out if we could allocate the headers. Failing to do that would add extra alignment to the first ro section, since we would set PageAlign thinking it was the first section in the PT_LOAD. In the linker script case the header allocation must be done in the end, causing some duplication. We now tentatively add the headers to the first PT_LOAD and if it turns out they don't fit, remove them. With this we only need to allocate the headers in one place in the code. llvm-svn: 302186
* Fix accounting of tbss.Rafael Espindola2017-05-041-16/+14
| | | | | | | | | | | | | We were correctly computing the size contribution of a .tbss input section (it is none), but we were incorrectly considering the alignment of the output section: it was advancing Dot instead of ThreadBssOffset. As far as I can tell this was always wrong in our linkerscript implementation, but that became more visible now that the code is shared with the non linker script case. llvm-svn: 302107
* [ELF] Fix problems with fabricateDefaultCommands() and --section-startPeter Smith2017-05-031-11/+12
| | | | | | | | | | | | | | | | | | | | | | | | The --section-start <name>=<address> needs to be translated into equivalent linker script commands. There are a couple of problems with the existing implementation: - The --section-start with the lowest address is assumed to be at the start of the map. This assumption is incorrect, we have to iterate through the SectionStartMap to find the lowest address. - The addresses in --section-start were being over-aligned when the sections were marked as PageAlign. This is inconsistent with the use of SectionStartMap in fixHeaders(), and can cause problems when the PageAlign causes an "unable to move location counter backward" error when the --section-start with PageAlign is aligned to an address higher than the next --section-start. The ld.bfd and ld.gold seem to be more consistent with this approach but this is not a well specified area. This change fixes the problems above and also corrects a typo in which fabricateDefaultCommands() is called with the wrong parameter, it should be called with AllocateHeader not Config->MaxPageSize. Differential Revision: https://reviews.llvm.org/D32749 llvm-svn: 302007
* Fix pr32816.Rafael Espindola2017-05-011-1/+8
| | | | | | | | 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
* Bring back r301678.Rafael Espindola2017-04-291-30/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | This version uses a set to speed up the synchronize method. Original message: Remove LinkerScript::flush. This patch replaces flush with a last ditch attempt at synchronizing the section list with the linker script "AST". The synchronization is a bit of a hack and should in time be avoided by creating the AST earlier so that modifications can be made directly to it instead of modifying the section list and synchronizing it back. This is the main step for fixing https://bugs.llvm.org/show_bug.cgi?id=32816. With this in place I think the only missing thing would be to have processCommands assign section indexes as dummy offsets so that the sort in OutputSection::finalize works. With this LinkerScript::assignAddresses becomes much simpler, which should help with the thunk work. llvm-svn: 301745
* Revert r301678: Remove LinkerScript::flush.Rui Ueyama2017-04-281-64/+30
| | | | | | | | This reverts commit r301678 since that change significantly slowed down the linker. Before this patch, LLD could link clang in 8 seconds, but with this patch it took 40 seconds. llvm-svn: 301709
* Rename one of the variables to avoid confusion.Rafael Espindola2017-04-281-2/+2
| | | | llvm-svn: 301691
* Remove LinkerScript::flush.Rafael Espindola2017-04-281-30/+64
| | | | | | | | | | | | | | | | | | | | This patch replaces flush with a last ditch attempt at synchronizing the section list with the linker script "AST". The synchronization is a bit of a hack and should in time be avoided by creating the AST earlier so that modifications can be made directly to it instead of modifying the section list and synchronizing it back. This is the main step for fixing https://bugs.llvm.org/show_bug.cgi?id=32816. With this in place I think the only missing thing would be to have processCommands assign section indexes as dummy offsets so that the sort in OutputSection::finalize works. With this LinkerScript::assignAddresses becomes much simpler, which should help with the thunk work. llvm-svn: 301678
* Create an OutputSection for each non-empty OutputSectionCommand.Rafael Espindola2017-04-261-15/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [ELF] Always use Script::assignAddresses()Peter Smith2017-04-191-0/+50
| | | | | | | | | | | | | | | | | | | This change fabricates linker script commands for the case where there is no linker script SECTIONS to control address assignment. This permits us to have a single Script->assignAddresses() function. There is a small change in user-visible-behavior with respect to the handling of .tbss SHT_NOBITS, SHF_TLS as the Script->assignAddresses() requires setDot() to be called with monotically increasing addresses. The tls-offset.s test has been updated so that the script and non-script results match. This change should make the non-script behavior of lld closer to an equivalent linker script. Differential Revision: https://reviews.llvm.org/D31888 llvm-svn: 300687
* [ELF] - Linkerscript: make section with no content to be SHT_PROGBITS by ↵George Rimar2017-04-141-1/+1
| | | | | | | | | | | | | | | | | | 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] LinkerScript: Don't assign zero to all regular symbolsGeorge Rimar2017-04-141-1/+6
| | | | | | | | | | | | 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
* Simplify this further.Rafael Espindola2017-04-071-2/+1
| | | | | | Thanks to Rui for noticing it. llvm-svn: 299777
* [ELF] Recommit r299635 to pad x86 executable sections with 0xccJames Henderson2017-04-071-2/+2
| | | | | | This follows r299748 which fixed a latent bug the original commit exposed. llvm-svn: 299755
* Remove unnecessary cast.Rafael Espindola2017-04-071-1/+1
| | | | llvm-svn: 299740
* Call updateAlignment before assignAddresses.Rafael Espindola2017-04-061-6/+7
| | | | | | | The alignment expression cannot depend on '.', so we can compute it early. llvm-svn: 299717
* Move call to findMemoryRegion before assignAddresses.Rafael Espindola2017-04-061-2/+6
| | | | | | This removes a bit more work from assignAddresses. llvm-svn: 299716
* Remove redundant argument. NFC.Rafael Espindola2017-04-061-3/+3
| | | | llvm-svn: 299713
* Cache the result of findSection.Rafael Espindola2017-04-061-3/+7
| | | | | | | This avoids calling it multiple times. In particular, we don't have to call in in assignAddresses any more. llvm-svn: 299709
* Revert r299635 because it exposed a latent bug.James Henderson2017-04-061-2/+2
| | | | llvm-svn: 299655
* [ELF] Pad x86 executable sections with 0xcc int3 instructionsJames Henderson2017-04-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove unnecessary local variable.Rui Ueyama2017-04-051-7/+4
| | | | | | This patch does what r299506 was trying to do in a different way. llvm-svn: 299554
* Revert r299506 "Simplify. NFC."George Rimar2017-04-051-7/+10
| | | | | | | | It was not NFC unfortunaly, one of changes decrements begin() iterator and that is not allowed by MSVS. llvm-svn: 299525
* Move the parser for the linker script to a separate file.Rui Ueyama2017-04-051-1155/+0
| | | | | | | | LinkerScript.cpp contains both the linker script processor and the linker script parser. I put both into a single file, but the file grown too large, so it's time to put them into two different files. llvm-svn: 299515
* Remove unused typedef.Rui Ueyama2017-04-051-2/+0
| | | | llvm-svn: 299514
* Do not use public inheritance where it is not needed.Rui Ueyama2017-04-051-1/+1
| | | | | | ScriptParser is not a ScriptLexer, so this should be a private inheritance. llvm-svn: 299513
* Simplify. NFC.Rui Ueyama2017-04-051-12/+6
| | | | llvm-svn: 299512
* Simplify. NFC.Rui Ueyama2017-04-051-4/+6
| | | | | | A for-loop is more boring than a find_if, but I think this is easier to read. llvm-svn: 299511
* Fix memory leak found by asan.Rui Ueyama2017-04-051-5/+5
| | | | llvm-svn: 299509
* Simplify and update comment.Rui Ueyama2017-04-051-20/+16
| | | | llvm-svn: 299508
* Simplify. NFC.Rui Ueyama2017-04-051-10/+7
| | | | llvm-svn: 299506
* Use make to create linker script command objects.Rui Ueyama2017-04-051-63/+59
| | | | | | It simplifies variable types. llvm-svn: 299505
* Remove default arguments because they don't improve readability.Rui Ueyama2017-04-051-3/+3
| | | | llvm-svn: 299504
* Add parentheses around `&`.Rui Ueyama2017-04-051-1/+1
| | | | llvm-svn: 299503
* Update comment.Rui Ueyama2017-04-051-4/+3
| | | | llvm-svn: 299502
* Use empty() instead of size().Rui Ueyama2017-04-051-1/+1
| | | | | | `!V.size()` where V is a vector is equivalent to `V.empty()`. llvm-svn: 299501
* Simplify. NFC.Rui Ueyama2017-04-051-8/+4
| | | | llvm-svn: 299500
* Make variable names consistent. NFC.Rui Ueyama2017-04-051-21/+22
| | | | llvm-svn: 299499
* Return a result from computeInputSections instead of mutating its argument.Rui Ueyama2017-04-051-18/+24
| | | | | | This should improve readability. llvm-svn: 299498
* Remove `=` from a lambda that doesn't capture any variable.Rui Ueyama2017-04-051-3/+4
| | | | llvm-svn: 299495
OpenPOWER on IntegriCloud