summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Remove ScriptConfiguration class and move the members to LinkerScript class.Rui Ueyama2017-10-111-32/+31
| | | | | | | | | | | | | | | | ScriptConfiguration was a class to contain parsed results of linker scripts. LinkerScript is a class to interpret it. That ditinction was needed because we haven't instantiated LinkerScript early (because, IIRC, LinkerScript class was a ELFT template function). So, when we parse linker scripts, we couldn't directly store the result to a LinkerScript instance. Now, that limitation is gone. We instantiate LinkerScript at the very beginning of our main function. We can directly store parse results to a LinkerScript instance. llvm-svn: 315403
* Inline addRegular into addSymbol.Rui Ueyama2017-10-111-40/+50
| | | | | | | | Because addRegular's functionality is tightly coupled with addSymbol, and the former is called only once, it makes sense to merge the two functions. This patch also adds comments. llvm-svn: 315401
* Remove a constructor from ExprValue. NFC.Rui Ueyama2017-10-111-4/+4
| | | | | | I think three ctors are too many for this simple class. llvm-svn: 315394
* [ELF] Set Dot initially to --image-base value when using linker scriptsJames Henderson2017-10-101-4/+5
| | | | | | | | | | | | | | | | | | | | | 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
* Rename ignoreInterpSection -> needsInterpSection.Rui Ueyama2017-10-081-6/+9
| | | | | | This should improve consistency. Also added comment. llvm-svn: 315169
* Use llvm::Optional instead of UINT_MAX to represent a null value.Rui Ueyama2017-10-081-3/+2
| | | | llvm-svn: 315168
* Make a helper function a non-member function. NFC.Rui Ueyama2017-10-081-17/+16
| | | | llvm-svn: 315167
* Use llvm::Optional instead of a magic number -1 to represent "no result".Rui Ueyama2017-10-081-14/+9
| | | | llvm-svn: 315166
* Remove a trivial function.Rui Ueyama2017-10-081-2/+0
| | | | llvm-svn: 315164
* Remove OutputSection::updateAlignment.Rui Ueyama2017-10-071-1/+2
| | | | | | I feel it is easier to understand without this function. llvm-svn: 315140
* Merge addInputSec with OutputSection::addSection.Rui Ueyama2017-10-071-2/+2
| | | | | | | | | | Previously, when we added an input section to an output section, we called `OutputSectionFactory::addInputSec`. This isn't a good design because, a factory class is intended to create a new object and return it, but in this use case, it will never create a new object. This patch fixes the design flaw. llvm-svn: 315138
* Remove unused parameters.Rui Ueyama2017-10-071-2/+2
| | | | llvm-svn: 315133
* Do not mutate Script->Opt.Commands from a leaf helper function.Rui Ueyama2017-10-061-3/+6
| | | | | | | | Factory::addInputSec added an output section to Script->Opt.Commands, but that is too subtle. This patch makes it explicit so that it is easy to see when a new element is added to Script->Opt.Commands. llvm-svn: 315129
* Simplify LinkerScript::addOrphanSections. NFCI.Rui Ueyama2017-10-061-14/+17
| | | | | | | | | | | | This patch moves a std::find to a new function. It also removes the following piece of code. I believe it should be fine because all tests still pass. unsigned Index = std::distance(Opt.Commands.begin(), I); assert(Sec->SectionIndex == INT_MAX || Sec->SectionIndex == Index); Sec->SectionIndex = Index; llvm-svn: 315125
* Split addSection into two small functions. NFCI.Rui Ueyama2017-10-061-1/+1
| | | | | | | | | addSection function was hard to read because it behaves differently depending on its arguments but what exactly it does is not clear. Now it should be better. Still, it is not clear (not what but) why it does what it does, but I'll take a look at it later. llvm-svn: 315124
* [ELF] - Stop removing sections in removeUnusedSyntheticSections().George Rimar2017-10-021-2/+2
| | | | | | | | | | That makes code a bit more consistent. Instead of removing sections there we can just mark them as dead. So that removeEmptyCommands() will handle the rest. Differential revision: https://reviews.llvm.org/D38393 llvm-svn: 314654
* Fix header location with PHDR.Rafael Espindola2017-09-281-2/+1
| | | | | | | | | We were not subtracting its size, causing it to overlap with section data. Fixes PR34750. llvm-svn: 314440
* Use UINT64_MAX instead of implicitly-type-converted -1.Rui Ueyama2017-09-251-1/+1
| | | | llvm-svn: 314126
* Use a temporary varaible to improve readability. NFC.Rui Ueyama2017-09-251-8/+4
| | | | llvm-svn: 314120
* [ELF] - Report orphan sections if -verbose given.George Rimar2017-09-251-0/+1
| | | | | | | | | 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
* Fix assigning to _gp in linker scripts.Rafael Espindola2017-09-201-0/+1
| | | | | | | | | | | The previous logic was to try to detect if a linker script defined _gp by checking !ElfSym::MipsGp->Value. That doesn't work in all cases as the assigned value can be 0. We now just always defined it Writer.cpp and always overwrite it afterwards if needed. llvm-svn: 313788
* Add a special case for trivial alignment.Rafael Espindola2017-09-201-0/+5
| | | | | | | | | | | 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-1/+1
| | | | | | | | | 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
* [ELF] - Introduce std::vector<InputFile *> global arrays.George Rimar2017-09-191-16/+1
| | | | | | | | | | | | This patch removes lot of static Instances arrays from different input file classes and introduces global arrays for access instead. Similar to arrays we have for InputSections/OutputSectionCommands. It allows to iterate over input files in a non-templated code. Differential revision: https://reviews.llvm.org/D35987 llvm-svn: 313619
* [ELF] - Simplify adjustSectionsBeforeSorting().George Rimar2017-09-181-3/+2
| | | | | | | | | Does not seem we need to set SectionIndex here. It is set in finalizeSections() later. Differential revision: https://reviews.llvm.org/D37815 llvm-svn: 313522
* Remove Offset from Common.Rafael Espindola2017-09-121-1/+1
| | | | | | It is not needed since it is always 0. llvm-svn: 313076
* Align addresses, not offsets.Rafael Espindola2017-09-121-1/+5
| | | | | | | 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-1/+1
| | | | | | | | | | | | | | | 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
* Currently lld creates a single section to collect all commons. There is no wayDmitry Mikulin2017-09-081-10/+10
| | | | | | | | | | | | | | | 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] - Linkerscript: implement REGION_ALIAS.George Rimar2017-09-081-5/+5
| | | | | | | | | | | | 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
* [ELF] - Rename PhdrEntry::First/Last to FirstSec/LastSec. NFC.George Rimar2017-09-071-1/+1
| | | | | | As was suggested in D34956 thread. llvm-svn: 312712
* [ELF] - Store pointer to PT_LOAD instead of pointer to first section in ↵George Rimar2017-09-071-15/+10
| | | | | | | | | | | OutputSection It is a bit more convinent and helps to simplify logic of program headers allocation a little. Differential revision: https://reviews.llvm.org/D34956 llvm-svn: 312711
* [ELF] - Linkerscript: set load address correctly if MEMORY command used.George Rimar2017-09-061-3/+4
| | | | | | | | | | | 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] - Simplify (use llvm::erase_if). NFC.George Rimar2017-08-281-11/+7
| | | | llvm-svn: 311878
* Currently lld uses base names of files to match against file patterns inDmitry Mikulin2017-08-241-7/+11
| | | | | | | | | | 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-231-3/+17
| | | | | | | | | | | | | | | | | | | | | | 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 segfault when doing logical and/or operations on symbols that ↵George Rimar2017-08-211-7/+12
| | | | | | | | | | | 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-2/+7
| | | | | | | | | | | 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: disallow discarding COMMON.George Rimar2017-08-101-2/+2
| | | | | | | | | | | | This patch restricts following construction: /DISCARD/ : { *(COMMON) } Previously LLD would crash. Differential revision: https://reviews.llvm.org/D36468 llvm-svn: 310554
* Move File from SymbolBody to Symbol.Rafael Espindola2017-08-041-2/+2
| | | | | | | | | | | | | With this Symbol has the same size as before, but DefinedRegular goes from 72 to 64 bytes. I also find this a bit easier to read. There are fewer places initializing File for example. This has a small but measurable speed improvement on all tests (1% max). llvm-svn: 310142
* [ELF] - Fix "--symbol-ordering-file doesn't work with linker scripts"George Rimar2017-08-041-0/+30
| | | | | | | | | | | | | | | 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
* Avoid warnings when asserts are disabled.Rafael Espindola2017-07-271-2/+1
| | | | llvm-svn: 309326
* Merge OutputSectionCommand and OutputSection.Rafael Espindola2017-07-271-446/+85
| | | | | | | | | | | | | This is a bit of a hack, but it is *so* convenient. Now that we create synthetic linker scripts when none is provided, we always have to handle paired OutputSection and OutputsectionCommand and keep a mapping from one to the other. This patch simplifies things by merging them and creating what used to be OutputSectionCommands really early. llvm-svn: 309311
* [ELF] - Store PhdrEntry values by pointers instead of storing by value.George Rimar2017-07-271-16/+18
| | | | | | | | | | | That is slightly more convinent as allows to store pointer on program header entry in a more safe way. Change was used in 2 patches currently on review. Differential revision: https://reviews.llvm.org/D35832 llvm-svn: 309253
* Rename ObjectFile -> ObjFile.Rui Ueyama2017-07-261-1/+1
| | | | | | | Rename it because it was too easy to conflict with llvm::object::ObjectFile which broke buildbots several times. llvm-svn: 309199
* Simplify. NFC.Rafael Espindola2017-07-261-17/+2
| | | | llvm-svn: 309153
* Detemplate SymbolTable.Rafael Espindola2017-07-261-21/+6
| | | | | | NFC, just makes it easier to access from non templated code. llvm-svn: 309152
* [ELF] - Fix calculation of memory region offset.George Rimar2017-07-251-1/+2
| | | | | | | | | | | | | | 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
* Don't crash on an empty section with an ALIGN.Rafael Espindola2017-07-221-1/+1
| | | | llvm-svn: 308809
* [ELF] Remove processNonSectionCommandsPetr Hosek2017-07-211-9/+0
| | | | | | | | This method is no longer being used anywhere. Differential Revision: https://reviews.llvm.org/D35706 llvm-svn: 308706
OpenPOWER on IntegriCloud