summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Writer.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix assigning to _gp in linker scripts.Rafael Espindola2017-09-201-1/+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
* Tweak orphan section placement.Rafael Espindola2017-09-191-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | Given a linker script that ends in .some_sec { ...} ; __stack_start = .; . = . + 0x2000; __stack_end = .; lld would put orphan sections like .comment before __stack_end, corrupting the intended meaning. The reason we don't normally move orphans past assignments to . is to avoid breaking rx_sec : { *(rx_sec) } . = ALIGN(0x1000); /* The RW PT_LOAD starts here*/ but in this case, there is nothing after and it seems safer to put the orphan section last. This seems to match bfd's behavior and is convenient for writing linker scripts that care about the layout of SHF_ALLOC sections, but not of any non SHF_ALLOC sections. llvm-svn: 313646
* [ELF] - Introduce std::vector<InputFile *> global arrays.George Rimar2017-09-191-8/+9
| | | | | | | | | | | | 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] Remove default argument for lambda.Davide Italiano2017-09-181-7/+7
| | | | | | | | | | | This is not really OK in C++11, and GCc triggers a warning. We can switch back to default arguments when C++14 will be the minimum version of the standard supported, see: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#974 Ack'ed by Rafael. llvm-svn: 313550
* Keep some relocations with undefined weak symbols.Rafael Espindola2017-09-151-4/+2
| | | | | | | | | | | | | | | | | | | This fixes pr34301. As the bug points out, we want to keep some relocations with undefined weak symbols. This means that we cannot always claim that these symbols are not preemptible as we do now. Unfortunately, we cannot also just always claim that they are preemptible. Doing so would, for example, cause us to try to create a plt entry when we don't even have a dynamic symbol table. What almost works is to say that weak undefined symbols are preemptible if and only if we have a dynamic symbol table. Almost because we don't want to fail the build trying to create a copy relocation to a weak undefined. llvm-svn: 313372
* Don't make _gp absolute.Rafael Espindola2017-09-151-11/+0
| | | | | | | | _gp points to a position in the file, so it is not really absolute. It is also simpler to not force it to be absolute, so if there is no strong ABI requirement we should not do it. llvm-svn: 313333
* [ELF] - Refactor of Writer<ELFT>::forEachRelSec.George Rimar2017-09-131-18/+11
| | | | | | | | | | | | | There is no need to scan over all input sections for relocatable output. As we do not process or scan relocations anyways. Patch moves check for Config->Relocatable out to avoid that and also removes excessive check for isa<EhInputSection> from first for loop. It is excessive because we handle all of them in a second for loop below. That all allowed to simplify code. Differential revision: https://reviews.llvm.org/D37746 llvm-svn: 313127
* Update comment. NFC.Rafael Espindola2017-09-121-6/+2
| | | | llvm-svn: 313051
* Simplify handling of predefined symbols.Rafael Espindola2017-09-121-68/+49
| | | | | | | Given our representation of symbols as section + offset, we can finalize symbols like _end as soon as the section is known. llvm-svn: 313048
* Remove a redundant local variable.Rui Ueyama2017-09-081-2/+1
| | | | llvm-svn: 312823
* Handle empty dynamic lists.Rafael Espindola2017-09-081-1/+1
| | | | llvm-svn: 312820
* Handle lazy symbols is computeIsPreemptible.Rafael Espindola2017-09-081-1/+1
| | | | llvm-svn: 312812
* Simplify. NFC.Rafael Espindola2017-09-081-1/+1
| | | | | | We handled all undefined symbols before this. llvm-svn: 312808
* Simplify as this runs before copy relocations are created.Rafael Espindola2017-09-081-7/+1
| | | | llvm-svn: 312807
* If --dynamic-list is given, only those symbols are preemptible.Rafael Espindola2017-09-081-3/+10
| | | | | | | | | | | | | This allows combining --dynamic-list and version scripts too. The version script controls which symbols are visible, and --dynamic-list controls which of those are preemptible. Unlike previous versions, undefined symbols are still considered preemptible, which was the issue breaking the cfi tests. This fixes pr34053. llvm-svn: 312806
* Currently lld creates a single section to collect all commons. There is no wayDmitry Mikulin2017-09-081-3/+3
| | | | | | | | | | | | | | | 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] - Simplify #2. NFC.George Rimar2017-09-081-8/+3
| | | | llvm-svn: 312789
* [ELF] - Simplify. NFC.George Rimar2017-09-081-3/+2
| | | | llvm-svn: 312787
* Revert "Revert "Revert r311468: If --dynamic-list is given, only those ↵Rafael Espindola2017-09-081-3/+2
| | | | | | | | | | symbols are preemptible"" This reverts commit r312757. Evgenii Stepanov reports that it broke some tests. llvm-svn: 312771
* Revert "Revert r311468: If --dynamic-list is given, only those symbols are ↵Rafael Espindola2017-09-071-2/+3
| | | | | | | | | | | | | | preemptible" If --dynamic-list is given, only those symbols are preemptible. This allows combining --dynamic-list and version scripts too. The version script controls which symbols are visible, and --dynamic-list controls which of those are preemptible. This fixes pr34053. llvm-svn: 312757
* [ELF] - Rename PhdrEntry::First/Last to FirstSec/LastSec. NFC.George Rimar2017-09-071-19/+19
| | | | | | 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-3/+3
| | | | | | | | | | | 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/Writer] Fix english in a comment. NFCI.Davide Italiano2017-09-061-1/+1
| | | | llvm-svn: 312669
* [ELF] Move fixSectionAlignments() before first call to assignAddresses()Peter Smith2017-09-061-3/+3
| | | | | | | | | | | | The fixSectionAlignments() function may alter the alignment of some OutputSections, this is likely to alter the addresses calculated earlier in assignAddresses(). By moving the call to fixSectionAlignments() we make sure that assignAddresses() is consistent with the early calculation used for RangeThunks and the final call just before writing the image. Differential Revision: https://reviews.llvm.org/D36739 llvm-svn: 312636
* Do not use invalid iterators to fix Windows build.Rui Ueyama2017-09-051-32/+33
| | | | | | | | | | | | | | std::vector::insert invalidates all iterators, so it was not safe to do Script->Opt.Commands.insert(++I, Make(ElfSym::End1)); Script->Opt.Commands.insert(++I, Make(ElfSym::End2)); because after the first line, `I` is no longer valid. This patch rewrites fixes the issue. I belive the new code without higher-order functions is a bit more readable than before. llvm-svn: 312570
* [ELF] Set p_memsz to p_filesz when aligning the last segment to page boundaryPetr Hosek2017-09-011-1/+2
| | | | | | | | Having p_filesz different from p_memsz is confusing some tools. Differential Revision: https://reviews.llvm.org/D37369 llvm-svn: 312384
* [ELF] Generate symbol assignments for predefined symbolsPetr Hosek2017-09-011-36/+81
| | | | | | | | | | | | | | | | | | | The problem with symbol assignments in implicit linker scripts is that they can refer synthetic symbols such as _end, _etext or _edata. The value of these symbols is currently fixed only after all linker script commands are processed, so these assignments will be using non-final and hence invalid value. Rather than fixing the symbol values after all command processing have finished, we instead change the logic to generate symbol assignment commands that set the value of these symbols while processing the commands, this ensures that the value is going to be correct by the time any reference to these symbol is processed and is equivalent to defining these symbols explicitly in linker script as BFD ld does. Differential Revision: https://reviews.llvm.org/D36986 llvm-svn: 312305
* [ELF] - Simplify (use llvm::erase_if). NFC.George Rimar2017-08-281-6/+3
| | | | llvm-svn: 311878
* Update comments: parallel_for_each -> parallelForEachSam Clegg2017-08-231-1/+0
| | | | | | | | Also remove unused include of raw_ostream.h Differential Revision: https://reviews.llvm.org/D37048 llvm-svn: 311587
* Revert r311468: If --dynamic-list is given, only those symbols are preemptibleRui Ueyama2017-08-221-3/+2
| | | | | | This reverts commit r311468 because it broke some CFI bots. llvm-svn: 311497
* If --dynamic-list is given, only those symbols are preemptibleRui Ueyama2017-08-221-2/+3
| | | | | | | | | | | | | | | | | Patch by Rafael Espíndola. This is PR34053. The implementation is a bit of a hack, given the precise location where IsPreemtible is set, it cannot be used from SymbolTable::handleAnonymousVersion. I could add another method to SymbolTable if you think that would be better. Differential Revision: https://reviews.llvm.org/D36499 llvm-svn: 311468
* [ELF] - Recommit "[ELF] - Do not forget to fill last bytes of PT_LOADs with ↵George Rimar2017-08-211-1/+1
| | | | | | | | | | | | | | | | | | trap instructions." With fix: explicitly specify ouput format for hexdump tool call. Original commit message: [ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions. Previously last 4 bytes of executable loads were not filled with trap instructions, patch fixes this bug. Differential revision: https://reviews.llvm.org/D36262 llvm-svn: 311315
* [ELF] - Revert r311310 "[ELF] - Do not forget to fill last bytes of PT_LOADs ↵George Rimar2017-08-211-1/+1
| | | | | | | | | with trap instructions." It broke BB: http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/11792/steps/test_lld/logs/stdio llvm-svn: 311314
* [ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions.George Rimar2017-08-211-1/+1
| | | | | | | | | | Previously last 4 bytes of executable loads were not filled with trap instructions, patch fixes this bug. Differential revision: https://reviews.llvm.org/D36262 llvm-svn: 311310
* Test commit.Ben Dunbobbin2017-08-181-2/+2
| | | | | | Removed extraneous comment markers llvm-svn: 311169
* Remove GdbIndexSection::finalizeContents.Rui Ueyama2017-08-151-8/+12
| | | | | | | | GdbIndexSection doesn't need lazy finalization because when an instance of the class is created, we already know all debug info sections. We can initialize the instnace in the ctor. llvm-svn: 310931
* Update comments as the function does not write to the first page anymore.Rui Ueyama2017-08-141-19/+15
| | | | | | Also refactored the code a bit. llvm-svn: 310886
* Delete what looks like dead code.Rafael Espindola2017-08-111-4/+2
| | | | | | | The start of a segment should not have a gap that needs trap instructions. llvm-svn: 310696
* Garbage-collect common symbols.Rui Ueyama2017-08-101-0/+4
| | | | | | | | | | | | Liveness is usually a notion of input sections, but this patch adds "liveness" bit to common symbols because they don't belong to any input section. This patch is based on https://reviews.llvm.org/D36520 Differential Revision: https://reviews.llvm.org/D36546 llvm-svn: 310617
* Compute isPreemtible only once.Rafael Espindola2017-08-101-0/+36
| | | | | | | | This is probably a small optimization, but the main motivation is having a way of fixing pr34053 that doesn't require a hash lookup in isPreempitible. llvm-svn: 310602
* [lld] Allow rel iplt symbols with dynamic symbol tableShoaib Meenai2017-08-051-1/+1
| | | | | | | | | | | | | | | | Emit these symbols as long as we're building in a static configuration, even if we're emitting a dynamic symbol table. This is consistent with both bfd and gold. Ordinarily, the combination of -static and -export-dynamic wouldn't make much sense. Unfortunately, cmake versions prior to 3.4 forcefully injected -rdynamic [1], so it seems worthwhile to support. [1] https://cmake.org/cmake/help/v3.4/policy/CMP0065.html Differential Revision: https://reviews.llvm.org/D36350 llvm-svn: 310168
* 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-20/+1
| | | | | | | | | | | | | | | 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
* [ELF] - Replace parallelForEach with ranged form.George Rimar2017-08-041-1/+1
| | | | | | | | Makes code a bit more convinent to write/read. Differential revision: https://reviews.llvm.org/D36089 llvm-svn: 310040
* [ELF] When the code segment is the last, align it to the page boundaryPetr Hosek2017-08-021-1/+60
| | | | | | | | | | | When the data segment is the last segment, it is correct to leave it unaligned. However, when the code segment is the last segment, it should be aligned to the page boundary to avoid loading the non-segment parts of the ELF file at the end of the file. Differential Revision: https://reviews.llvm.org/D33630 llvm-svn: 309829
* Merge OutputSectionCommand and OutputSection.Rafael Espindola2017-07-271-180/+132
| | | | | | | | | | | | | 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-64/+64
| | | | | | | | | | | 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-2/+2
| | | | | | | Rename it because it was too easy to conflict with llvm::object::ObjectFile which broke buildbots several times. llvm-svn: 309199
* Try to fix the windows build.Rafael Espindola2017-07-261-1/+1
| | | | llvm-svn: 309162
* Try to fix the windows build.Rafael Espindola2017-07-261-1/+1
| | | | llvm-svn: 309160
OpenPOWER on IntegriCloud