summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Do not join sections for relocatable object filesEugene Leviant2016-10-051-1/+1
| | | | | | Differential revision: https://reviews.llvm.org/D25232 llvm-svn: 283307
* [ELF] make KEEP command recognize file patternsEugene Leviant2016-10-051-5/+10
| | | | | | Differential revision: https://reviews.llvm.org/D25242 llvm-svn: 283305
* Start linker scripts at 0.Rafael Espindola2016-09-301-1/+1
| | | | | | | | | We were implicitly creating space for the headers. That is not the behaviour of bfd, which requires the script to use SIZEOF_HEADERS. The difference is important for scripts that don't use SIZEOF_HEADERS and expect the first section to be at 0. llvm-svn: 282818
* Don't error if we can't put the header in a PT_LOAD.Rafael Espindola2016-09-291-9/+16
| | | | | | | | | | If there is not sufficient address space, just give up and don't put the header in the PT_LOAD. This matches bfd behaviour and I found at least one script that depends on having a section at address 0. llvm-svn: 282750
* [ELF] Support -z max-page-size optionPetr Hosek2016-09-281-1/+1
| | | | | | | | | | | | This options issupported by both BFD ld and gold and allows overriding the max page size whose default values are defined by the target. https://llvm.org/bugs/show_bug.cgi?id=30541 Differential Revision: https://reviews.llvm.org/D24891 llvm-svn: 282596
* [ELF] - Linkerscript: implemented BYTE/SHORT/LONG/QUAD commands.George Rimar2016-09-261-0/+75
| | | | | | | | | | | | | | | | | | | The BYTE, SHORT, LONG, and QUAD commands store one, two, four, and eight bytes (respectively). After storing the bytes, the location counter is incremented by the number of bytes stored. Previously our scripts handles these commands incorrectly. For example: SECTIONS { .foo : { *(.foo.1) BYTE(0x11) ... We accepted the script above treating BYTE as input section description. These commands are used in the wild though. Differential revision: https://reviews.llvm.org/D24830 llvm-svn: 282429
* [ELF] - Format. NFC.George Rimar2016-09-261-3/+1
| | | | llvm-svn: 282395
* Combine two StringSwitch::Cases because Cases now can take 6 parameters.Rui Ueyama2016-09-231-2/+1
| | | | llvm-svn: 282307
* Avoid counting sections twice.Rafael Espindola2016-09-231-11/+9
| | | | | | | | | | | | | We were counting the size of the bss section holding common symbols twice: Dot += CurOutSec->getSize(); flush(); The new code is also simpler as now flush is the only function that inserts in AlreadyOutputOS, which makes sense since the set hold fully output sections. llvm-svn: 282285
* Simplify. NFC.Rui Ueyama2016-09-231-14/+6
| | | | llvm-svn: 282268
* [ELF] - Linkerscript: accept space between '=' and expression in section filler.George Rimar2016-09-231-1/+5
| | | | | | | | | | | | | Previously we failed to parse next scripts because disallowed a space between filler value and '=': .text : { ... } :text = 0x9090 Differential revision: https://reviews.llvm.org/D24831 llvm-svn: 282248
* [ELF] - Linkerscript: implement DEFINED() command.George Rimar2016-09-231-0/+12
| | | | | | | | | | | | DEFINED(symbol) Return 1 if symbol is in the linker global symbol table and is defined before the statement using DEFINED in the script, otherwise return 0. Can be used to define default values for symbols. Found it in the wild. Differential revision: https://reviews.llvm.org/D24858 llvm-svn: 282245
* [ELF] - Linkerscript: Implemented >> and <<George Rimar2016-09-231-4/+10
| | | | | | | | | | | Found this operators used in the wild scripts, for example: __got2_entries = (_FIXUP_TABLE_ - _GOT2_TABLE_) >>2; __fixup_entries = (. - _FIXUP_TABLE_)>>2; Differential revision: https://reviews.llvm.org/D24860 llvm-svn: 282243
* Don't move orphan sections past assignments.Rafael Espindola2016-09-221-5/+31
| | | | | | This fixes a case where we would produce an unaligned PT_LOAD. llvm-svn: 282180
* Simplify. NFC.Rafael Espindola2016-09-221-3/+1
| | | | | | | With the recent changes there should always be a 1:1 correspondence in the correct order between OutputSections and OutputSectionCommands. llvm-svn: 282176
* Avoid duplicated code.Rafael Espindola2016-09-221-3/+2
| | | | | | | This also fixes the linker script accounting for the ELF header in some places but not in others. llvm-svn: 282173
* Simplify. NFC.Rafael Espindola2016-09-221-3/+2
| | | | | | | It doesn't matter which direction we rotate and we haven't really started optimizing the linker script code, so keep this simple. llvm-svn: 282166
* Handle empty sections with symbol assignments.Rafael Espindola2016-09-221-1/+26
| | | | | | Before the symbols were becoming undefined. llvm-svn: 282159
* Fix VA computation for tbss.Rafael Espindola2016-09-221-3/+6
| | | | llvm-svn: 282149
* Handle multiple .tbss sections.Rafael Espindola2016-09-221-1/+3
| | | | llvm-svn: 282147
* Implement ONLY_IF_RO/ONLY_IF_RW like bfd.Rafael Espindola2016-09-211-9/+4
| | | | | | | | | | The actual logic is to keep the output section if the output section would have been ro/rw. This is both simpler and more practical, as the intention is linker scripts is to always keep of of a pair of ONLY_IF_RO/ONLY_IF_RW. llvm-svn: 282099
* [ELF] - Linkerscript: support complex section pattern grammar.George Rimar2016-09-211-40/+55
| | | | | | | | | | | | | | | | | | | | | | | This is PR30442. Previously we were failed to parce complex expressions like: foo : { *(SORT_BY_NAME(bar) zed) } Main idea of patch that globs and excludes can be wrapped in a SORT. There is a difference in semanics of ld/gold: ld likes: *(SORT(EXCLUDE_FILE (*file1.o) .foo.1)) gold likes: *(EXCLUDE_FILE (*file1.o) SORT(.foo.1)) Patch implements ld grammar, complex expressions like next is not a problem anymore: .abc : { *(SORT(.foo.* EXCLUDE_FILE (*file1.o) .bar.*) .bar.*) } Differential revision: https://reviews.llvm.org/D24758 llvm-svn: 282078
* Linker script: Fix bug with several .bssEugene Leviant2016-09-211-1/+2
| | | | | | | | When final image has several .bss sections, lld fails because second .bss always has zero VA. This causes link error "Not enough space for ELF and program headers" llvm-svn: 282067
* [ELF] - Linkerscript: reimplement readSectionExcludes()George Rimar2016-09-211-18/+12
| | | | | | | | | | | It is not only a bit more straightforward now, but also next 2 issues are solved: * It just crashed on ".foo : { *(EXCLUDE_FILE (*file1.o)) }" before. * It accepted multiple EXCLUDE_FILEs in a row. Differential revision: https://reviews.llvm.org/D24726 llvm-svn: 282060
* Revert "Revert "Only restrict order if both sections are in the script.""Rafael Espindola2016-09-201-11/+0
| | | | | | | | | | | | | | | | | | | This reverts commit r282021, bringing back r282015. The problem was that the comparison function was not a strict weak ordering anymore, which this patch fixes. Original message: Only restrict order if both sections are in the script. This matches gold and bfd behavior and is required to handle some scripts. The script has to assume where PT_LOADs start in order to align that spot. If we don't allow section it doesn't know about to move to the middle, we can need more PT_LOADs and those will not be aligned. llvm-svn: 282035
* Revert "Only restrict order if both sections are in the script."Rafael Espindola2016-09-201-2/+2
| | | | | | This reverts commit r282015. It broke some bots. llvm-svn: 282021
* Only restrict order if both sections are in the script.Rafael Espindola2016-09-201-2/+2
| | | | | | | | | | This matches gold and bfd behavior and is required to handle some scripts. The script has to assume where PT_LOADs start in order to align that spot. If we don't allow section it doesn't know about to move to the middle, we can need more PT_LOADs and those will not be aligned. llvm-svn: 282015
* Simplify SORT and --sort-section command line option handling.Rui Ueyama2016-09-201-30/+24
| | | | | | Differential Revision: https://reviews.llvm.org/D24685 llvm-svn: 282006
* Remove empty section commands.Rafael Espindola2016-09-201-0/+23
| | | | | | | We were already not creating them, and with this other parts of the code don't have to worry about them. llvm-svn: 281968
* Remove unnecessary const_canst. NFC.Rafael Espindola2016-09-191-9/+3
| | | | llvm-svn: 281901
* [ELF] - LinkerScript: Add workaround for gcc 6.2.0 failure w/autoGeorge Rimar2016-09-191-2/+2
| | | | | | | | | Will Dietz found and reported that lld does not compile with gcc 6.2.0, more details https://llvm.org/bugs/show_bug.cgi?id=30438 And confirmed this change fixes the issue. llvm-svn: 281900
* [ELF] - Fix comment. NFC.George Rimar2016-09-171-1/+1
| | | | llvm-svn: 281836
* [ELF] - Added comments. NFC.George Rimar2016-09-171-0/+4
| | | | llvm-svn: 281835
* [ELF] - SEGMENT_START's default argument can be an expressionGeorge Rimar2016-09-171-4/+2
| | | | | | | | | | | Our implementation supported integer value previously. ld can use expression, for example, it is OK to write . = SEGMENT_START("foobar", .); Patch implements that. llvm-svn: 281831
* [ELF] Linkerscript: fixed bug about commands processing.George Rimar2016-09-171-0/+1
| | | | | | | | | It was possible situation about some commands just were not processed (were skipped) because of a bug appeared when constraint checking used. Testcase is attached. llvm-svn: 281818
* Use named struct instead of unnamed std::pair.Rui Ueyama2016-09-171-10/+14
| | | | | | It is important to give members names for readability. llvm-svn: 281803
* Define a versatile utility function and use it instead of a single purpose one.Rui Ueyama2016-09-171-13/+12
| | | | llvm-svn: 281802
* Remove unnecessary namespace specifiers.Rui Ueyama2016-09-171-7/+7
| | | | llvm-svn: 281801
* Try to fix a few bots.Rafael Espindola2016-09-161-2/+2
| | | | llvm-svn: 281794
* Put SHF_ALLOC sections first, even with linker scripts.Rafael Espindola2016-09-161-6/+37
| | | | | | | | | | | | This matches gold and bfd, and is pretty much required by some linker scripts. They end with commands like foo 0 : { *(bar) } if we put any SHF_ALLOC sections after they can have an address that is too low. llvm-svn: 281778
* Rename SortSectionPolicy::IgnoreConfig to None.Rui Ueyama2016-09-161-12/+10
| | | | | | Because it corresponds to SORT_NONE. None was renamed Default. llvm-svn: 281776
* Only process commands in a ONLY_IF_RO if it matches.Rafael Espindola2016-09-161-15/+18
| | | | | | | This matches bfd behavior. It also makes future changes simpler as we don't have to worry about ignoring these commands in multiple places llvm-svn: 281775
* Fix constraint checking in ONLY_IF_RO.Rafael Espindola2016-09-161-9/+10
| | | | | | We have to look at all the relevant input sections at once. llvm-svn: 281772
* [ELF] - Implemented --sort-section cmd line option and SORT_NONE script command.George Rimar2016-09-161-15/+49
| | | | | | | | | | | | | | | | This fixes Bug 30385 - SORT_NONE not implemented, `SORT_NONE' disables section sorting by ignoring the command line section sorting option. That is why this patch also implements --sort-section option. Description of sorting rules available at https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html Differential revision: https://reviews.llvm.org/D24604 llvm-svn: 281771
* Recommit r281721 "[ELF] - Linkerscript: implement EXCLUDE_FILE in the middle ↵George Rimar2016-09-161-24/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of a input section description." With fix for 2 bots. Details about the fix performed is on a review page. Initial commit message: This is PR30387: From PR description: We fail to parse SECTIONS { foo : { *(sec0 EXCLUDE_FILE (zed1.o) sec1 EXCLUDE_FILE (zed2.o) sec2 ) } } The semantics according to bfd are: Include sec1 from every file but zed1.o Include sec2 from every file but zed2.o Include sec0 from every file Patch implements the support. Differential revision: https://reviews.llvm.org/D24650 llvm-svn: 281754
* Improve handling ASSERT outside SECTIONS blockEugene Leviant2016-09-161-36/+40
| | | | | | Differential revision: https://reviews.llvm.org/D24450 llvm-svn: 281740
* Change how we compute offsets with linker scripts.Rafael Espindola2016-09-161-114/+120
| | | | | | | | | | | | This fixes pr30367, but more importantly, it changes how we compute offsets. Now offset computation in a walk over linker script commands, like the rest of assignAddresses. IMHO this is simpler to understand and if we ever have to create multiple outputsections or chunks to change how we handle test/ELF/linkerscript/alternate-sections.s it should be easier to do it. llvm-svn: 281736
* Reverted r281721 ("[ELF] - Linkerscript: implement EXCLUDE_FILE in the ↵George Rimar2016-09-161-54/+24
| | | | | | | | | middle of a input section description."). It broke build bot: http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/27508 llvm-svn: 281723
* [ELF] - Linkerscript: implement EXCLUDE_FILE in the middle of a input ↵George Rimar2016-09-161-24/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | section description. This is PR30387: From PR description: We fail to parse SECTIONS { foo : { *(sec0 EXCLUDE_FILE (zed1.o) sec1 EXCLUDE_FILE (zed2.o) sec2 ) } } The semantics according to bfd are: Include sec1 from every file but zed1.o Include sec2 from every file but zed2.o Include sec0 from every file Patch implements the support. Differential revision: https://reviews.llvm.org/D24650 llvm-svn: 281721
* Error out instead of producing a corrupt PT_LOAD.Rafael Espindola2016-09-151-3/+6
| | | | | | | What bfd and gold do is give up in putting the headers in the PT_LOAD and just start the PT_LOAD in the second page. llvm-svn: 281660
OpenPOWER on IntegriCloud