summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] - Apply clang-format. NFC.George Rimar2017-07-181-2/+2
| | | | llvm-svn: 308297
* [ELF] Use stable_sort for compareByFilePositionShoaib Meenai2017-07-171-1/+1
| | | | | | | | | | | The comment at the top of compareByFilePosition indicates that it relies on stable_sort to preserve the order of synthetic sections. We were using sort instead of stable_sort, however, leading to incorrect synthetic section ordering. Differential Revision: https://reviews.llvm.org/D35473 llvm-svn: 308207
* Move feature-specific functions out of Strings.cpp.Rui Ueyama2017-07-131-0/+13
| | | | | | | | Functions declared in Strings.h should provide generic string operations for the linker, but some of them are too specific to some features. This patch moves them to the location where they are used. llvm-svn: 307949
* [ELF] - Allow moving location counter backward in some cases.George Rimar2017-07-121-7/+3
| | | | | | | | | | | | 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] Add comment to explain LinkerScript::CurAddressState [NFC]Peter Smith2017-07-111-0/+10
| | | | | | | | | | | | | | r307367 via D34345 split out the temporary address state used within processCommands() and assignAddresses(). Due to the way that getSymbolValue is used by the ScriptParser there is no way of giving the current OutputSection to getSymbolValue() without somehow accessing the created addressState. The suggestion was that by making a pointer that would go out of scope we would find out by ASAN/MSAN or a crash if someone had misused currentAddressState. Differential Revision: https://reviews.llvm.org/D34345 llvm-svn: 307637
* [ELF] Extract temporary state used in assignAddresses()Peter Smith2017-07-071-31/+45
| | | | | | | | | | | | | | | | | | The assignAddresses() function accumulates state in the LinkerScript that prevents it from being called multiple times. This change moves the state into a separate structure AddressState that is created at the start of the function and disposed of at the end. CurAddressState is used rather than passing a reference to the state as a parameter to the functions used by assignAddresses(). This is because the getSymbolValue function needs to be executed in the context of AddressState but it is stored in ScriptParser when AddressState is not available. The AddressState is also used in a limited context by processCommands() Differential Revision: https://reviews.llvm.org/D34345 llvm-svn: 307367
* Move fabricateDefaultCommands earlier.Rafael Espindola2017-07-051-0/+86
| | | | | | | It is now just after the OutputSections are created, which is as early as it can possibly go. llvm-svn: 307225
* Simplify. NFC.Rafael Espindola2017-07-051-13/+9
| | | | llvm-svn: 307217
* Remove a function that is now trivial.Rafael Espindola2017-07-051-7/+0
| | | | llvm-svn: 307214
* Merge createOrphanCommands into addOrphanSections.Rafael Espindola2017-07-051-21/+18
| | | | | | This is a bit simpler and avoids a walk over OutputSections. llvm-svn: 307178
* [ELF] Extract allocateHeaders() from assignAddresses()Peter Smith2017-07-051-14/+9
| | | | | | | | | | | | | | | The allocateHeaders() function is called at the end of assignAddresses(), it decides whether the ELF header and program header table can be allocated to a PT_LOAD program header. As the function alters state, it prevents assignAddresses() from being called multiple times. This change splits out the call to allocateHeaders() from assignAddresses() this will permit assignAddresses() to be called while processing range extension thunks without trying to allocateHeaders(). Differential Revision: https://reviews.llvm.org/D34344 llvm-svn: 307131
* [ELF] - Use llvm::find_if instead std::find_if where possible. NFC.George Rimar2017-07-041-6/+5
| | | | | | Two more places. llvm-svn: 307076
* [ELF] - Simplify allocateHeaders(). NFC.George Rimar2017-07-031-10/+7
| | | | | | | * Return type changed to void, because it was unused. * std::find_if -> llvm::find_if llvm-svn: 307039
* [LLD][LinkerScript] Allow non-alloc sections to be assigned to segments.Andrew Ng2017-07-031-5/+8
| | | | | | | | | | | | | | | | | | | | 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
* Move `assert` upwards so that it fails early if it fails.Rui Ueyama2017-06-261-1/+2
| | | | llvm-svn: 306308
* Prefer -Ttext over linker script values.Rafael Espindola2017-06-201-5/+0
| | | | | | | | | | | | | | | | | | | | 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-4/+14
| | | | | | | | | | | | | 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-1/+2
| | | | | | We would crash before. llvm-svn: 305615
* Error when discarding .dynsym.Rafael Espindola2017-06-161-1/+1
| | | | | | We would crash instead before. llvm-svn: 305614
* Error on trying to discard .dynamic.Rafael Espindola2017-06-161-2/+2
| | | | | | We would crash instead before. llvm-svn: 305613
* Update a comment.Rui Ueyama2017-06-161-2/+3
| | | | llvm-svn: 305601
* Move clearOutputSections before sortSections.Rafael Espindola2017-06-151-101/+10
| | | | | | | | | | | | | | | | | | This is probably the main patch left in unifying our intermediary representation. It moves the creation of default commands before section sorting. This has the nice effect that we now have one location where we decide where an orphan section should be placed. Before this patch sortSections would decide the relative location of orphan sections to other sections, but it was up to placeOrphanSection to decide on the exact location. We now only sort sections we created since the linker script is already in the correct order. llvm-svn: 305512
* Simplify. NFC.Rafael Espindola2017-06-131-2/+1
| | | | llvm-svn: 305341
* Make OutputSections and OutputSectionCommands globals.Rafael Espindola2017-06-131-10/+7
| | | | | | | This is similar to what we do for InputSections and makes them easier to access. llvm-svn: 305337
* Set non alloc section address to 0 earlier.Rafael Espindola2017-06-131-7/+4
| | | | | | | | | | | | | | | 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
* Move clearOutputSections before createPhdrs. NFC.Rafael Espindola2017-06-101-2/+4
| | | | llvm-svn: 305156
* Move fabricateDefaultCommands earlier.Rafael Espindola2017-06-081-3/+7
| | | | | | This then requires delaying a call to getHeaderSize. llvm-svn: 304961
* [ELF] - Linkerscript: implement NOLOAD section type.George Rimar2017-06-071-0/+2
| | | | | | | | | | | | | | | 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] Convert Thunks to use InputSectionDescriptionsPeter Smith2017-06-071-45/+0
| | | | | | | | | | | | | | | | Thunks are now generated per InputSectionDescription instead of per OutputSection. This allows created ThunkSections to be inserted directly into InputSectionDescription. Changes in this patch: - Loop over InputSectionDescriptions to find relocations to Thunks - Generate a ThunkSection per InputSectionDescription - Remove synchronize() as we no longer need it - Move fabricateDefaultCommands() before createThunks Differential Revision: https://reviews.llvm.org/D33835 llvm-svn: 304887
* [ELF] - Linkerscript: improved error reporting.George Rimar2017-06-071-4/+4
| | | | | | | | | | | | | | | | 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
* Move Object format code to lib/BinaryFormat.Zachary Turner2017-06-071-1/+1
| | | | | | | | | | | | This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
* Avoid using OutputSection::Sections. NFC.Rafael Espindola2017-06-061-19/+22
| | | | | | | | We now used the InputSectionDescriptions in OutputSectionCommand::finalize. This will allow moving clearOutputSections earlier. llvm-svn: 304827
* Move finalize to OutputSectionCommands. NFC.Rafael Espindola2017-06-061-0/+77
| | | | | | | This removes a mapping from OutputSection to OutputSectionCommand and is another step in moving clearOutputSections earlier. llvm-svn: 304821
* [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
OpenPOWER on IntegriCloud