summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [ELF] - Early return from writeTo() if section is SHT_NOBITS. NFCi.George Rimar2017-06-061-3/+3
| | | | | | That addresses port commit comments for https://reviews.llvm.org/D33646 llvm-svn: 304777
* Run fabricateDefaultCommands before fixSectionAlignments.Rafael Espindola2017-06-021-4/+0
| | | | | | | This allows us to remove the PageAlign field. It will also allow moving fabricateDefaultCommands earlier. llvm-svn: 304513
* Simplify. NFC.Rafael Espindola2017-06-021-2/+1
| | | | llvm-svn: 304511
* Move maybeCompress to OutputSectionCommand.Rafael Espindola2017-06-011-0/+33
| | | | | | | This removes a call to getCmd and allows us to move clearOutputSections earlier. llvm-svn: 304439
* Convert a few more uses of OutputSections. NFC.Rafael Espindola2017-06-011-8/+15
| | | | | | Also needed to move clearOutputSections earlier. llvm-svn: 304420
* Move name lookup to script parsing time.Rafael Espindola2017-06-011-23/+22
| | | | | | | | | | | We were looking up sections by name during expression evaluation. By keeping track of forward declarations we can do the lookup during script parsing. Doing the lookup earlier will be more efficient when assignAddresses is run twice and removes two uses of OutputSections. llvm-svn: 304381
* Move clearOutputSections earlier.Rafael Espindola2017-05-311-1/+6
| | | | | | | Another step into merging the linker script and non linker script code paths. llvm-svn: 304339
* Store a single Parent pointer for InputSectionBase.Rafael Espindola2017-05-311-2/+2
| | | | | | | | | | | | | | | Before InputSectionBase had an OutputSection pointer, but that was not always valid. For example, if it was a merge section one actually had to look at MergeSec->OutSec. This was brittle and caused bugs like the one fixed by r304260. We now have a single Parent pointer that points to an OutputSection for InputSection, but to a SyntheticSection for merge sections and .eh_frame. This makes it impossible to accidentally access an invalid OutSec. llvm-svn: 304338
* Simplify. NFC.Rafael Espindola2017-05-311-3/+2
| | | | llvm-svn: 304334
* Check Live instead of the section type.Rafael Espindola2017-05-301-2/+4
| | | | | | | By the time we get here all live sections should have been combined into InputSections. llvm-svn: 304243
* Remove unnecessary cast.Rafael Espindola2017-05-301-2/+2
| | | | llvm-svn: 304240
* [ELF] - Do not crash when linkerscript applies fill to .bss.George Rimar2017-05-301-0/+3
| | | | | | | | | | | | | | 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/+3
| | | | | | | | | 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-301-3/+4
| | | | | | | | | | | | | | | | | | 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
* Move writeTo to OutputSectionCommand.Rafael Espindola2017-05-241-9/+61
| | | | | | | | | | | | This reduces how many times we have to map from OutputSection to OutputSectionCommand. It is a required step to moving clearOutputSections earlier. In order to always use writeTo in OutputSectionCommand we have to call fabricateDefaultCommands for -r links and move section compression after it. llvm-svn: 303784
* Do not track section types of previous sections, always use PROGBITS for ↵Dmitry Mikulin2017-05-241-3/+1
| | | | | | | | dummy sections. Fix for PR33029. llvm-svn: 303770
* Use more strict types. NFC.Rafael Espindola2017-05-231-12/+12
| | | | | | | | | By the time we get to linker scripts, all special InputSectionBase should have been combined into synthetic sections, which are a type of InputSection. The net result is that we can use InputSection in a few places that were using InputSectionBase. llvm-svn: 303702
* 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
OpenPOWER on IntegriCloud