summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Simplify. readAssignment never returns a nullptr.Rui Ueyama2016-07-291-4/+3
| | | | llvm-svn: 277090
* [ELF] - Removed excessive check. NFC.George Rimar2016-07-281-1/+1
| | | | | | Thanks to Rui Ueyama who noticed that. llvm-svn: 277062
* [ELF] - Attempt to fix BB after 277042.George Rimar2016-07-281-1/+1
| | | | | | | | http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/17294 Change: std::make_unique -> llvm::make_unique llvm-svn: 277059
* [ELF] - Cosmetic change. NFC.George Rimar2016-07-281-1/+1
| | | | | | peek()[0] == '*' changed to peek().startswith("*") llvm-svn: 277043
* [ELF] - Linkerscript: implemented filename specification.George Rimar2016-07-281-34/+44
| | | | | | | | | | | | | | | Scripts can contain something like: KEEP (*crtbegin.o(.ctors)) What means that "*crtbegin.o" is a wildcard of file to take the sections from. This is some kind of opposite to EXCLUDE_FILE and used in FreeBSD script: https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l122 Patch implements this. Differential revision: https://reviews.llvm.org/D22852 llvm-svn: 277042
* [ELF] - Linkerscript: implemented += operator.George Rimar2016-07-281-18/+21
| | | | | | | | | | | | | | | | | Sometimes += is used to move the location counter. Example from the wild is: .dbg_excpt _DBG_EXCPT_ADDR (NOLOAD) : { . += (DEFINED (_DEBUGGER) ? 0x8 : 0x0); https://github.com/chipKIT32/pic32-Arduino-USB-Bootloader-original/blob/master/boot-linkerscript.ld Patch implements it and opens way for others type of assignments (-= *= etc), though I think only += is actual to support. Differential revision: https://reviews.llvm.org/D22916 llvm-svn: 277035
* Make CommonInputSection singleton class.Rui Ueyama2016-07-281-6/+4
| | | | | | | | | All other singleton instances are accessible globally. CommonInputSection shouldn't be an exception. Differential Revision: https://reviews.llvm.org/D22935 llvm-svn: 277034
* [ELF] Allows setting section for common symbols in linker scriptEugene Leviant2016-07-281-3/+9
| | | | llvm-svn: 277023
* Add support for SEGMENT_START.Rafael Espindola2016-07-281-0/+9
| | | | | | | | | | | | | | | | | | This is a bit of an odd feature. It is normally used in . = SEGMENT_START(seg, val); In bfd it evaluates to val or to the value of the corresponding -T<seg>-segment. Note that the -T<seg>-segment in bfd doesn't actually change the segment address, just the value this evaluates too, including in the default linker script. In gold the -T<seg>-segment options do change the segment address and seeing this expressions in linker scripts disables the options. For new this just always evaluates the expression to val. llvm-svn: 277014
* [ELF] - Linkerscript: ignore SORT(CONSTRUCTORS)George Rimar2016-07-281-0/+9
| | | | | | | | | | | | | | | Some scripts can contain SORT(CONSTRUCTORS) expression: https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l152 for ELF it just a nop: "When linking object file formats which do not support arbitrary sections, such as ECOFF and XCOFF, the linker will automatically recognize C++ global constructors and destructors by name. For these object file formats, the CONSTRUCTORS command tells the linker to place constructor information in the output section where the CONSTRUCTORS command appears. The CONSTRUCTORS command is ignored for other object file formats." (http://www.sourceware.org/binutils/docs-2.10/ld_3.html) So patch implements ignoring. Differential revision: https://reviews.llvm.org/D22848 llvm-svn: 276965
* Make toPhdrFlags a member function. NFC.Rafael Espindola2016-07-271-4/+4
| | | | llvm-svn: 276868
* [ELF/LinkerScript] Support EXCLUDE_FILE inside KEEP.Davide Italiano2016-07-271-13/+33
| | | | | | Differential Revision: https://reviews.llvm.org/D22795 llvm-svn: 276825
* Remove return type that can trivially be inferred.Rui Ueyama2016-07-261-1/+1
| | | | llvm-svn: 276794
* [ELF] - replace error() with llvm_unreachable. George Rimar2016-07-261-1/+1
| | | | llvm-svn: 276790
* Attemp to fix build bot:George Rimar2016-07-261-0/+2
| | | | | | http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/25329/steps/build_Lld llvm-svn: 276789
* [ELF] Linkerscript: symbol assignments with indentifiers on the right side ↵George Rimar2016-07-261-3/+29
| | | | | | | | | | | | | | | | of expression. In symbol assignments symbol may appear on the right-hand side of the expression: (https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l8) kernphys = CONSTANT (MAXPAGESIZE); . = kernbase + kernphys + SIZEOF_HEADERS; Patch implements that. Differential revision: https://reviews.llvm.org/D22759 llvm-svn: 276784
* [ELF] - Linkerscript: implemented ALIGN modificatior of output sections.George Rimar2016-07-261-0/+13
| | | | | | | | | | | Output section description can contain ALIGN modificator: https://sourceware.org/binutils/docs/ld/Output-Section-Description.html#Output-Section-Description Patch implements it. Differential revision: https://reviews.llvm.org/D22674 llvm-svn: 276780
* [ELF] Linkerscript: implement DATA_SEGMENT_RELRO_END.George Rimar2016-07-261-0/+11
| | | | | | | | | | | | | | | | | | | | In compare with what GNU linkers do (https://sourceware.org/binutils/docs/ld/Builtin-Functions.html), this implementation simple: Do not touch DATA_SEGMENT_ALIGN, it do what it do now - just aligns to the page boundary. Parameters of DATA_SEGMENT_RELRO_END is ignored. That should be correct as it is usually just a 24 bytes shift that allows to protect first 3 entries of got.plt with relro. (https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l146). DATA_SEGMENT_RELRO_END just aligns to the page boundary. That is what expected because all sections that are not affected by relro should be on another memory page. So at fact the difference with documented behavior is that we do not pad DATA_SEGMENT_ALIGN. 3 entries of got.plt are uncovered by relro, but functionality is simple and equal to lld behavior for case when script is not given. Differential revision: https://reviews.llvm.org/D22813 llvm-svn: 276778
* [ELF] - Merged 2 lines. NFC.George Rimar2016-07-261-4/+1
| | | | llvm-svn: 276768
* [ELF] Linkerscript: simplify DATA_SEGMENT_ALIGN evaluationGeorge Rimar2016-07-261-1/+1
| | | | | | | | | | | We can simplify the evaluation of DATA_SEGMENT_ALIGN just to simple align(). That way it will work exactly like we have in non-script case. Change was suggested by Rafael Ávila de Espíndola Differential revision: https://reviews.llvm.org/D22807 llvm-svn: 276745
* [ELF] - Fixed possible iterator overflow.George Rimar2016-07-261-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | We can have Opt.Commands size greater then Sections.size(). For example if we have next script: SECTIONS { .aaa : { *(.aaa) } .bbb : { *(.bbb) } .ccc : { *(.ccc) } } and next code: .global _start _start: nop .section .aaa,"a" .quad 0 Then amount of sections is less than amound of Opt.Commands and if we for example have all commands NoConstraint, that overflowed the iterator used. llvm-svn: 276741
* [ELF/Linkerscript] Remove special handling of TLS/NOTE/RELRO sections (patch ↵Eugene Leviant2016-07-261-23/+0
| | | | | | from ruiu) llvm-svn: 276731
* Split getPhdrsIndices. NFC.Rui Ueyama2016-07-261-11/+16
| | | | llvm-svn: 276717
* Replace std::find_if with plain for loop. NFC.Rui Ueyama2016-07-261-10/+8
| | | | llvm-svn: 276715
* Split LinkerScript::createSections into small functions.Rui Ueyama2016-07-251-37/+48
| | | | | | | | | | | createSections function is getting longer, so it is time to split it into small functions. The reason why the function is long is because it has deeply nested for-loops. This patch constructs temporary data to reduce nesting level. Differential Revision: https://reviews.llvm.org/D22786 llvm-svn: 276706
* Fix parameter names.Rui Ueyama2016-07-251-4/+4
| | | | | | | | match() returns true of the first argument, a target string, matches one of the second argument, a list of glob patterns. Calling the target string, which is not a glob pattern, "Pattern" was very confusing. llvm-svn: 276705
* Do not pass InputFile to reportDiscarded().Rui Ueyama2016-07-251-1/+1
| | | | | | | Because the file from which an input section is created can be obtained using getFile(). llvm-svn: 276702
* Make ConstraintKind an enum class.Rui Ueyama2016-07-251-2/+2
| | | | llvm-svn: 276697
* [LinkerScript] Refactor KEEP handling in a separate functionDavide Italiano2016-07-251-10/+15
| | | | | | | | | | | This will grow because I have a patch to support more complex constructs, e.g.: KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) Let's make this a separate function. llvm-svn: 276695
* Re-commit "Split LinkerScript::createSections".Rui Ueyama2016-07-251-21/+38
| | | | | | Re-commit r276543 with a fix for buildbots. llvm-svn: 276693
* [ELF] - Linkerscript: implemented output section [address] attribute.George Rimar2016-07-251-0/+9
| | | | | | | | | | | | | | | | Output section description in SECTIONS looks like that: section [address] [(type)] : ... { ... } Patch implements support of address atribute. Differential revision: https://reviews.llvm.org/D22689 llvm-svn: 276619
* [ELF] Fix the semantic of PROVIDE in linker scripts.Davide Italiano2016-07-251-1/+3
| | | | | | | | | | PROVIDE request us to define a symbol only if it is referenced and is not defined by any object included in the link. We created the symbol in the symbol table no matter what. Differential Revision: https://reviews.llvm.org/D22739 llvm-svn: 276592
* Simplify. NFC.Rui Ueyama2016-07-241-26/+24
| | | | llvm-svn: 276586
* [ELF] Support PROVIDE/PROVIDE_HIDDEN inside output sections description.Davide Italiano2016-07-241-0/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D22738 llvm-svn: 276579
* Merge readSymbolAssignment with readAssignment. NFC.Rui Ueyama2016-07-241-24/+11
| | | | llvm-svn: 276575
* Make readExpr return an Expr object instead of a vector of tokens.Rui Ueyama2016-07-241-219/+165
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, we handled an expression as a vector of tokens. In other words, an expression was a vector of uncooked raw StringRefs. When we need a value of an expression, we used ExprParser to run the expression. The separation was needed essentially because parse time is too early to evaluate an expression. In order to evaluate an expression, we need to finalize section sizes. Because linker script parsing is done at very early stage of the linking process, we can't evaluate expressions while parsing. The above mechanism worked fairly well, but there were a few drawbacks. One thing is that we sometimes have to parse the same expression more than once in order to find the end of the expression. In some contexts, linker script expressions have no clear end marker. So, we needed to recognize balanced expressions and ternary operators. The other is poor error reporting. Since expressions are parsed basically twice, and some information that is available at the first stage is lost in the second stage, it was hard to print out apprpriate error messages. This patch fixes the issues with a new approach. Now the expression parsing is integrated into ScriptParser. ExprParser class is removed. Expressions are represented as lambdas instead of vectors of tokens. Lambdas captures information they need to run themselves when they are created. In this way, ends of expressions are naturally detected, and errors are handled in the usual way. This patch also reduces the amount of code. Differential Revision: https://reviews.llvm.org/D22728 llvm-svn: 276574
* Rollback r276538 and r276540 to unbreak asan bot.Rui Ueyama2016-07-241-38/+21
| | | | llvm-svn: 276543
* Simplify. NFC.Rui Ueyama2016-07-241-13/+11
| | | | llvm-svn: 276540
* Split LinkerScript::createSections.Rui Ueyama2016-07-241-21/+40
| | | | | | | | createSections is getting longer, so it is probably time to split. Differential Revision: https://reviews.llvm.org/D22730 llvm-svn: 276538
* [ELF/Linkerscript] Define an absolute if we find an undefined.Davide Italiano2016-07-231-1/+2
| | | | | | | | | Otherwhise undefined references to symbols defined in linker scripts are never resolved. Differential Revision: https://reviews.llvm.org/D22664 llvm-svn: 276536
* Remove Phdr typedef.Rui Ueyama2016-07-231-10/+10
| | | | | | I don't think this typedef contributes to readability. llvm-svn: 276525
* Make a pure function a non-member file-scoped function.Rui Ueyama2016-07-231-2/+1
| | | | llvm-svn: 276524
* [ELF] Support PROVIDE and PROVIDE_HIDDEN inside SECTIONSEugene Leviant2016-07-221-11/+48
| | | | llvm-svn: 276398
* [ELF/LinkerScript] Support ONLY_IF_{RO, RW} directive.Davide Italiano2016-07-221-3/+26
| | | | | | Differential Revision: https://reviews.llvm.org/D22660 llvm-svn: 276384
* [ELF] - Basic support of linkerscript commands: DATA_SEGMENT_ALIGN, ↵George Rimar2016-07-211-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | DATA_SEGMENT_END, CONSTANT It is called basic because: CONSTANT expression can refer to COMMONPAGESIZE and MAXPAGESIZE. This sizes are usually different and used for possible optimization of memory consumption. More details are here: https://sourceware.org/ml/binutils/2002-02/msg00265.html We currently do not support this optimization, so both CONSTANT(MAXPAGESIZE) and CONSTANT(COMMONPAGESIZE) just return Target->PageSize value. DATA_SEGMENT_ALIGN and DATA_SEGMENT_END are used as a part of opt. The latter one is just ignored now. According to documentation DATA_SEGMENT_ALIGN has 2 possible calculation, but since we do not support mentioned opt - it is always calculated now as (ALIGN(MAXPAGESIZE) + (. & (MAXPAGESIZE - 1))). In general this should work for now until we deside to support this opt. Differential revision: https://reviews.llvm.org/D19663 llvm-svn: 276323
* Update comment.Rui Ueyama2016-07-211-2/+6
| | | | llvm-svn: 276322
* Fix MSVC 2015 compilation failure around range-for without curly bracesReid Kleckner2016-07-211-1/+2
| | | | | | | | | | | | | | It doesn't appear to like this pattern: for (auto X : Xs) if (...) { ... } else ...; We have heard anecdotes that range based for loops are implemented as a token rewrite in MSVC's lexer, and that the most challenging part of the rewrite is finding the end of the for loop. That makes sense, given that it's a lexer. llvm-svn: 276315
* [ELF] Fix bug in program header FLAGS processing + test case update (found ↵Eugene Leviant2016-07-211-1/+0
| | | | | | by grimar) llvm-svn: 276301
* [ELF] - Cleanup of LinkerScript<ELFT>::assignAddresses()George Rimar2016-07-211-8/+12
| | | | | | | | | | LinkerScript<ELFT>::assignAddresses is becoming larger and looks it can be good time for splitting. I expect to can more SectionsCommand's there, and dispatching some of them separatelly can help to keep method smaller either. Differential revision: https://reviews.llvm.org/D22506 llvm-svn: 276300
* [ELF] - Linkerscript: add InputSectionDescription command to LS parser.George Rimar2016-07-211-23/+46
| | | | | | | | | | | | | | This adds InputSectionDescription command to represent the input section declaration. This leads to next cleanup: SectionRule removed. ScriptConfiguration::Sections mamber removed. LinkerScript<ELFT>::getOutputSection() removed. Differential revision: https://reviews.llvm.org/D22617 llvm-svn: 276283
OpenPOWER on IntegriCloud