summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Delete trivial setter.Rafael Espindola2017-02-241-1/+1
| | | | llvm-svn: 296124
* Delete trivial getter.Rafael Espindola2017-02-241-5/+5
| | | | llvm-svn: 296123
* Make InputSection a class. NFC.Rafael Espindola2017-02-231-3/+3
| | | | | | | | | With the current design an InputSection is basically anything that goes directly in a OutputSection. That includes plain input section but also synthetic sections, so this should probably not be a template. llvm-svn: 295993
* [ELF] - Refactoring of LMA offset handling code. NFC.George Rimar2017-02-231-5/+6
| | | | | | Thanks to Rui Ueyama for suggestion. llvm-svn: 295943
* Merge InputSectionData and InputSectionBase.Rafael Espindola2017-02-231-10/+10
| | | | | | | Now that InputSectionBase is not a template there is no reason to have the two. llvm-svn: 295924
* Convert InputSectionBase to a class.Rafael Espindola2017-02-231-20/+19
| | | | | | | Removing this template is not a big win by itself, but opens the way for removing more templates. llvm-svn: 295923
* [ELF] Insert linkerscript symbols directly into symbol tablePetr Hosek2017-02-211-10/+10
| | | | | | | | | | This change exposes the symbol table insert method and uses it to insert the linkerscript defined symbols directly into the symbol table to avoid unnecessarily pulling the object out of an archive. Differential Revision: https://reviews.llvm.org/D30224 llvm-svn: 295780
* [ELF] - Do not segfault when using --gc-sections with linker scriptGeorge Rimar2017-02-211-0/+2
| | | | | | | | | | | Patch fixes PR32024. Sections that were not marked as Live has null output section. Previously we tried to access that field and segfaulted. Differential revision: https://reviews.llvm.org/D30188 llvm-svn: 295727
* [ELF] - Postpone evaluation of LMA offset.George Rimar2017-02-211-2/+4
| | | | | | | | | | | | | | | | | | Previously we evaluated the values of LMA incorrectly for next cases: .text : AT(ADDR(.text) - 0xffffffff80000000) { ... } .data : AT(ADDR(.data) - 0xffffffff80000000) { ... } .init.begin : AT(ADDR(.init.begin) - 0xffffffff80000000) { ... } Reason was that we evaluated offset when VA was not assigned. For case above we ended up with 3 loads that has similar LMA and it was incorrect. That is critical for linux kernel. Patch updates the offset after VA calculation. That fixes the issue. Differential revision: https://reviews.llvm.org/D30163 llvm-svn: 295722
* [ELF] - Improve diagnostic messages for move location counter errors.George Rimar2017-02-211-6/+8
| | | | | | | | | | Previously LLD would error out just "ld.lld: error: unable to move location counter backward" What does not really reveal the place of issue, Patch adds location to the output. Differential revision: https://reviews.llvm.org/D30187 llvm-svn: 295720
* [ELF] - Make ASSERT() return Dot instead of evaluated value.George Rimar2017-02-211-3/+2
| | | | | | | | | | | | | | | | | | | | Previously ASSERT we implemented returned expression value. Ex: . = ASSERT(0x100); would set Dot value to 0x100 Form of assert when it is assigned to Dot was implemented for compatibility with very old GNU ld which required it. Some scripts in the wild, including linux kernel scripts use such ASSERTs at the end for doing different checks. Currently we fail with "unable to move location counter backward" for such scripts. Patch changes ASSERT to return location counter value to fix that. Differential revision: https://reviews.llvm.org/D30171 llvm-svn: 295703
* Fix --print-gc-sections with linker scripts.Rafael Espindola2017-02-171-1/+1
| | | | | | | | Before it would never print anything. Thanks to George Rimar for pointing it out. llvm-svn: 295485
* [ELF] - Move DependentSections vector from InputSection to InputSectionBaseGeorge Rimar2017-02-171-5/+1
| | | | | | | | | | | | | | | | I splitted it from D29273. Since we plan to make relocatable sections as dependent for target ones for --emit-relocs implementation, this change is required to support .eh_frame case. EhInputSection inherets from InputSectionBase and not from InputSection. So for case when it has relocation section, it should be able to access DependentSections vector. This case is real for Linux kernel. Differential revision: https://reviews.llvm.org/D30084 llvm-svn: 295483
* Don't print DISCARD sections as gced.Rafael Espindola2017-02-171-1/+2
| | | | | | | | This is a small difference I noticed to gold and bfd. When given --print-gc-sections, we print sections a linkerscript marks DISCARD. The other linkers don't. llvm-svn: 295467
* Diagnose another case of the location counter moving backwards.Rafael Espindola2017-02-171-14/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | This case should be possible to handle, but it is hard: * In order to create program headers correctly, we have to scan the sections in the order they are in the file. * To find that order, we have to "execute" the linker script. * The linker script can contain SIZEOF_HEADERS. So to support this we have to start with a guess of how many headers we need (3), run the linker script and try to create the program headers. If it turns out we need more headers, we run the script again with a larger SIZEOF_HEADERS. Also, running the linker script depends on knowing the size of the sections, so we have to finalize them. But creating the program headers can change the value stored in some sections, so we have to split size finalization and content finalization. Looks like the last part is also needed for range extension thunks, so we might support this at some point. For now just report an error instead of producing broken files. llvm-svn: 295458
* Reject moving the location counter backwards.Rafael Espindola2017-02-171-21/+24
| | | | | | We were only checking when the assignment was inside a section. llvm-svn: 295454
* Share more output section creation code.Rafael Espindola2017-02-161-14/+2
| | | | | | | We can do this now that the linker script and the writer agree on which sections should be combined. llvm-svn: 295341
* [ELF] - Do not crash when discarding sections that are referenced by others.George Rimar2017-02-161-0/+5
| | | | | | | | | | | | | SHF_LINK_ORDER sections adds special ordering requirements. Such sections references other sections. Previously we would crash if section that other were referenced to was discarded by script. Patch fixes that by discarding all dependent sections in that case. It supports chained dependencies, testcase is provided. Differential revision: https://reviews.llvm.org/D30033 llvm-svn: 295332
* Ignore relocation sections in linker scripts.Rafael Espindola2017-02-161-0/+5
| | | | | | | | | | | | | | Unfortunately, the common way of writing linker scripts seems to be to get the output of ld.bfd --verbose and edit it a bit. Also unfortunately, the bfd default script contains things like .rela.dyn : { *(... .rela.data ...) } but bfd actually ignores that for -emit-relocs, so we have to do the same. llvm-svn: 295324
* Apply different tokenization rules to linker script expressions.Rui Ueyama2017-02-151-4/+10
| | | | | | | | | | | | | | | | The linker script lexer is context-sensitive. In the regular context, arithmetic operator characters are regular characters, but in the expression context, they are independent tokens. This afects how the lexer tokenizes "3*4", for example. (This kind of expression is real; the Linux kernel uses it.) This patch defines function `maybeSplitExpr`. This function splits the current token into multiple expression tokens if the lexer is in the expression context. Differential Revision: https://reviews.llvm.org/D29963 llvm-svn: 295225
* Rename ScriptParser.{cpp,h} -> ScriptLexer.{cpp,h}.Rui Ueyama2017-02-141-3/+3
| | | | | | | These files contain a lexer, so the new names are better. The parser is in LinkerScript.{cpp,h}. llvm-svn: 295022
* ELF: Read all dynamic lists specified on the command line.Peter Collingbourne2017-02-131-1/+2
| | | | | | | | | | | We were previously only reading the last one. Fixes PR31939 (which was likely the issue underlying https://github.com/google/oss-fuzz/issues/295). Differential Revision: https://reviews.llvm.org/D29861 llvm-svn: 294977
* Revert "Simplify symbol computation for non alloc sections."Rafael Espindola2017-02-081-3/+10
| | | | | | | This reverts commit r294346. Looks like it regressed the build of magenta. llvm-svn: 294460
* [ELF] - Linkerscript - fix handling of OUTPUT_ARCH command.George Rimar2017-02-081-3/+3
| | | | | | | | | | | | | | OUTPUT_ARCH command can contain architecture values separated with ":", like: OUTPUT_ARCH(i386:x86-64) We did not support that, because got 3 lexer tokens here after recent changes. This trivial patch fixes the issue, now whole expression inside OUTPUT_ARCH is just ignored. Differential revision: https://reviews.llvm.org/D29640 llvm-svn: 294432
* [ELF] Handle output section alignment in linker scriptsPetr Hosek2017-02-071-0/+4
| | | | | | | | | | LLD already parses ALIGN expression to specifiy alignment for output sections in linker scripts but it never applies the alignment to the output section. This change handles that. Differential Revision: https://reviews.llvm.org/D29689 llvm-svn: 294374
* Simplify symbol computation for non alloc sections.Rafael Espindola2017-02-071-10/+3
| | | | | | | We now just keep the address the section would have if it was allocatable. Only the writer ignores it at the very end. llvm-svn: 294346
* Handle the case where 'local' is the name of a global in a version script:Dmitry Mikulin2017-02-071-1/+1
| | | | | | { global : local; local: *; }; llvm-svn: 294343
* [ELF] - Assign proper values for DefinedSynthetic symbols attached to ↵George Rimar2017-02-071-2/+6
| | | | | | | | | | | | | | | | | | | | non-allocatable sections. DefinedSynthetic symbols are attached to sections, for the case when such symbol was attached to non-allocated section, we calculated its value incorrectly. We subtracted Body->Section->Addr, but non-allocatable sections should have zero VA in output and therefore result value was wrong. And at the same time we have Body->Section->Addr != 0 for them internally because use it for calculation of section size. Patch fixes calculation of such symbols values. Differential revision: https://reviews.llvm.org/D29653 llvm-svn: 294322
* [ELF] - Refactoring: reuse similar method.George Rimar2017-02-071-33/+20
| | | | | | | | | We had assignSymbol and assignSectionSymbol methods which has similar functionality. Patch removes one of copy and reuses another in code. Differential revision: https://reviews.llvm.org/D29582 llvm-svn: 294290
* Handle symbol assignments before the first section switch.Rafael Espindola2017-02-061-8/+16
| | | | | | | | | | We now create a dummy section with index 1 before processing the linker script. Thanks to George Rimar for finding the bug and providing the initial testcase. llvm-svn: 294252
* Simplify. NFC.Rafael Espindola2017-02-031-18/+16
| | | | | | | Now that each OutputSectionCommand maps to just one OutputSection, we can remove a few std::vectors. llvm-svn: 294060
* Handle numbers followed by ":" in linker scripts.Rafael Espindola2017-02-031-6/+11
| | | | | | | | | | | This is a fix for Bugzilla 31813. The problem is that the tokenizer does not create a separate token for ":" unless there's white space before it. Changed it to always create a token for ":" and reworked some logic that relied on ":" being attached to some tokens like "global:" and "local:". llvm-svn: 294006
* Update comments.Rui Ueyama2017-02-021-3/+22
| | | | llvm-svn: 293963
* [ELF] - Recommit r293749. Improve comment. NFC.George Rimar2017-02-011-2/+1
| | | | llvm-svn: 293751
* [ELF] - Revert r293749George Rimar2017-02-011-1/+2
| | | | | | | Accidentally lost the commit title and message, will recommit. llvm-svn: 293750
* (no commit message)George Rimar2017-02-011-2/+1
| | | | llvm-svn: 293749
* [ELF] - Linkerscript: properly mark minus expression with non-absolute flagGeorge Rimar2017-02-011-7/+8
| | | | | | | | | | | | | | | | | | | | | | This is alternative to D28857 which was incorrect. One of linux scripts contains: vvar_start = . - 2 * (1 << 12); vvar_page = vvar_start; vvar_vsyscall_gtod_data = vvar_page + 128; Previously we did not mark first expression as non-absolute, though it contains location counter. And LLD failed with error: relocation R_X86_64_PC32 cannot refer to absolute symbol This patch should fix the issue, and opens road for doing the same for other operators (though not clear if that is needed). Differential revision: https://reviews.llvm.org/D29332 llvm-svn: 293748
* [ELF] - Linkerscript: do not fail on additional semicolons in linkerscript.George Rimar2017-01-311-1/+4
| | | | | | | | | | | | | | | | | | Linux kernel linkerscript contains additional semicolon (last line): .apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) { __apicdrivers = .; *(.apicdrivers); I checked that both gold and bfd are able to parse something like: .text : { ;;*(.text);;S = 0;; } } Patch do the same. Differential revision: https://reviews.llvm.org/D29276 llvm-svn: 293612
* Revert commits r293276 and r293278.Rafael Espindola2017-01-271-1/+1
| | | | | | | | | | | | | | [ELF] Fixed formatting. NFC and [ELF] Bypass section type check Differential revision: https://reviews.llvm.org/D28761 They do the opposite of what was asked for in the code review. llvm-svn: 293320
* [ELF] Bypass section type checkEugene Leviant2017-01-271-1/+1
| | | | | | Differential revision: https://reviews.llvm.org/D28761 llvm-svn: 293276
* Rename NotFlags -> NegFlags.Rui Ueyama2017-01-261-7/+7
| | | | | | Negative flags are still bit flags, so I think "not flag" is a very good name. llvm-svn: 293143
* Use StringRef::lower only once instead of calling ::tolower many times.Rui Ueyama2017-01-261-5/+7
| | | | llvm-svn: 293142
* Split ScriptParser::readMemory.Rui Ueyama2017-01-261-27/+25
| | | | llvm-svn: 293141
* [LinkerScript] Implement `MEMORY` commandMeador Inge2017-01-241-1/+140
| | | | | | | | | | | | | | | | | | | | | | | | As specified here: * https://sourceware.org/binutils/docs/ld/MEMORY.html#MEMORY There are two deviations from what is specified for GNU ld: 1. Only integer constants and *not* constant expressions are allowed in `LENGTH` and `ORIGIN` initializations. 2. The `I` and `L` attributes are *not* implemented. With (1) there is currently no easy way to evaluate integer only constant expressions. This can be enhanced in the future. With (2) it isn't clear how these flags map to the `SHF_*` flags or if they even make sense for an ELF linker. Differential Revision: https://reviews.llvm.org/D28911 llvm-svn: 292875
* [ELF] - Linkerscripts: ignore CONSTRUCTORS in output section declaration.George Rimar2017-01-231-0/+4
| | | | | | | | | | | It is used in linux kernel script: http://lxr.free-electrons.com/source/arch/x86/kernel/vmlinux.lds.S#L140 Though CONSTRUCTORS is ignored for ELF. Differential revision: https://reviews.llvm.org/D28951 llvm-svn: 292777
* Reduce code duplication when allocating program headers.Rafael Espindola2017-01-201-11/+1
| | | | | | This will simplify a bug fix. llvm-svn: 292642
* [ELF] - Do not crash when assign common symbol's values in scriptGeorge Rimar2017-01-201-6/+1
| | | | | | | | | | Found that during attempts of linking linux kernel, previously we partially duplicated code from getOutputSection(), and it missed commons symbol case. Differential revision: https://reviews.llvm.org/D28903 llvm-svn: 292594
* [ELF] - Support optional comma after output section command.George Rimar2017-01-171-0/+3
| | | | | | | | | | | | | | | | | I found this when tried to link linux kernel with LLD: https://github.com/torvalds/linux/blob/master/arch/x86/entry/vdso/vdso-layout.lds.S#L86 Output section command can have optional comma at the end: .text : { *(.text*) } :text =0x90909090, It was documented about 3 years ago for binutils: https://sourceware.org/ml/binutils/2014-04/msg00045.html Differential revision: https://reviews.llvm.org/D28803 llvm-svn: 292225
* Add support for anonymous local symbols.Rafael Espindola2017-01-101-18/+15
| | | | | | | | | This actually simplifies the code a bit as now all local symbols are handled uniformly. This should fix the build of www/webkit2-gtk3. llvm-svn: 291569
* [ELF] Allow defined symbols to be assigned from linker scriptMeador Inge2017-01-091-32/+49
| | | | | | | | This patch allows for linker scripts to assign a new value to a symbol that is already defined (either in an object file or the linker script itself). llvm-svn: 291459
OpenPOWER on IntegriCloud