summaryrefslogtreecommitdiffstats
path: root/lld/test/ELF/linkerscript
Commit message (Collapse)AuthorAgeFilesLines
...
* Change section flag character for SHF_LINK_ORDER to "o".Evgeniy Stepanov2017-04-041-3/+3
| | | | | | See matching MC change in https://reviews.llvm.org/D31554. llvm-svn: 299480
* Change the error message format for undefined symbols.Rui Ueyama2017-03-302-4/+8
| | | | | | | | | | | | | | | | | | | | Previously, undefined symbol errors are one line like this and wasn't easy to read. /ssd/clang/bin/ld.lld: error: /ssd/llvm-project/lld/ELF/Writer.cpp:207: undefined symbol 'lld::elf::EhFrameSection<llvm::object::ELFType<(llvm::support::endianness)0, true> >::addSection(lld::elf::InputSectionBase*)' This patch make it more structured like this. bin/ld.lld: error: undefined symbol: lld::elf::EhFrameSection<llvm::object::ELFType<(llvm::support::endianness)0, true> >>> Referenced by Writer.cpp:207 (/ssd/llvm-project/lld/ELF/Writer.cpp:207) >>> Writer.cpp.o in archive lib/liblldELF.a Discussion thread: http://lists.llvm.org/pipermail/llvm-dev/2017-March/111459.html Differential Revision: https://reviews.llvm.org/D31481 llvm-svn: 299097
* [ELF] Allow references to reserved symbols in linker scriptsPetr Hosek2017-03-231-0/+16
| | | | | | | | | This requires collectign all symbols referenced in the linker script and adding them to symbol table as undefined symbol. Differential Revision: https://reviews.llvm.org/D31147 llvm-svn: 298577
* Handle & and | of non abs values.Rafael Espindola2017-03-171-30/+17
| | | | | | | Handling & in particular is probably important because of its use in aligning addresses. llvm-svn: 298096
* Refuse to add two non absolute symbols.Rafael Espindola2017-03-171-0/+6
| | | | | | | Since there is no way to produce the correct answer at runtime, it is probably better to just err. llvm-svn: 298094
* Support non abs values in the rhs of +.Rafael Espindola2017-03-171-0/+35
| | | | llvm-svn: 298088
* Add a test that now passes.Rafael Espindola2017-03-171-0/+18
| | | | llvm-svn: 298083
* Change our linker script expr representation.Rafael Espindola2017-03-171-0/+19
| | | | | | | | | | | | | | This fixes pr32031 by representing the expressions results as a SectionBase and offset. This allows us to use an input section directly instead of getting lost trying to compute an offset in an outputsection when not all the information is available yet. This also creates a struct to represent the *value* of and expression, allowing the expression itself to be a simple typedef. I think this is easier to read and will make it easier to extend the expression computation to handle more complicated cases. llvm-svn: 298079
* Support ABSOLUTE on the right hand side in linker scriptsPetr Hosek2017-03-151-0/+17
| | | | | | | | | | | | This also requires postponing the assignment the assignment of symbols defined in input linker scripts since those can refer to output sections and in case we don't have a SECTIONS command, we need to wait until all output sections have been created and assigned addresses. Differential Revision: https://reviews.llvm.org/D30851 llvm-svn: 297802
* [ELF] Fix LMA offset calculationEugene Leviant2017-03-141-0/+20
| | | | | | Differential revision: https://reviews.llvm.org/D30832 llvm-svn: 297713
* [ELF] Fix crash when .eh_frame(_hdr) is discardedEugene Leviant2017-03-141-0/+13
| | | | | | | | | lld crashes when .eh_frame or .eh_frame_hdr section is discarded in linker script and there is no PHDRS directive. Differential revision: https://reviews.llvm.org/D30885 llvm-svn: 297712
* [ELF] Fix error reporting for synthetic sectionsEugene Leviant2017-03-141-0/+27
| | | | | | | | | | | Synthetic sections don't belong to any input file, but still they are input sections. Whenever problem occurs with relocations in these sections lld crashes in error reporting, trying to print input file name. Differential revision: https://reviews.llvm.org/D30889 llvm-svn: 297711
* [ELF] Propely handle .eh_frame in linker scriptsPetr Hosek2017-03-101-0/+19
| | | | | | | | | | | Using .eh_frame input section pattern in linker script currently causes a crash; this is because .eh_frame input sections require special handling since they're all combined into a synthetic section rather than regular output section. Differential Revision: https://reviews.llvm.org/D30627 llvm-svn: 297501
* Fully precise gc handling of __start and __stop symbols.Rafael Espindola2017-03-061-1/+1
| | | | | | | | | | | | | | | This puts us at parity with bfd, which could already gc this case. I noticed the sections not being gced when linking a modified freebsd kernel. A section that was not gced and not mentioned in the linker script would end up breaking the expected layout. Since fixing the gc is relatively simple and an improvement, that seems better than trying to hack the orphan placement code. There are 173 input section in the entire link whose names are valid C identifiers, so this is probably not too performance critical. llvm-svn: 297049
* Simplify test by producing an executable.Rafael Espindola2017-03-021-11/+5
| | | | llvm-svn: 296786
* Make gc a bit more aggressive.Rafael Espindola2017-03-021-0/+37
| | | | | | | | | | | We were not gcing any section whose name was a C identifier. Both gold and bfd only keep those if they are used. To avoid having to create the __start/__stop symbols early or doing string lookups in resolvedReloc, this patch just looks for undefined symbols __start/__stop to decide if a section is needed or not. llvm-svn: 296723
* Revert "Add terminator to .eh_frame sections"Rafael Espindola2017-02-282-2/+2
| | | | | | | | | | | | | | This reverts commit r296378. I am pretty sure this is incorrect. In particular, for just .cfi_startproc nop .cfi_endproc We now add an extra 4 zeros that neither bfd nor gold add. llvm-svn: 296503
* Add terminator to .eh_frame sectionsRui Ueyama2017-02-272-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Patch by Mark Kettenis. Currenlty ld.lld does not add a terminator (a CIE with its length field set to zero) to the .eh_frame sections it generates. While the relevant standards (the AMD64 SysV ABI and the Linux LSB) are not explicit about this, such a terminator is expected by some unwinder implementations and seems to be always emitted by ld.bfd. In addition to that, the Linux LSB https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html#EHFRAME explicitly says that The .eh_frame section shall contain 1 or more Call Frame Information (CFI) records. Currently, if the .eh_frame sections of the input files only contain terminators, ld.lld emits a zero=sized .eh_frame section which clearly doesn't meet that requirement. The diff makes sure a terminator gets added to each .eh_frame section and adjusts all the relevant tests to account for that. An additional test isn't needed as these adjustments mean that the existence of the terminator is tested for by several tests already. Differential Revision: https://reviews.llvm.org/D30335 llvm-svn: 296378
* [ELF] Insert linkerscript symbols directly into symbol tablePetr Hosek2017-02-212-0/+15
| | | | | | | | | | 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/+19
| | | | | | | | | | | 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] - Shortify at-addr.s testcase.George Rimar2017-02-211-79/+16
| | | | llvm-svn: 295724
* [ELF] - Postpone evaluation of LMA offset.George Rimar2017-02-211-0/+102
| | | | | | | | | | | | | | | | | | 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-213-5/+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-212-4/+3
| | | | | | | | | | | | | | | | | | | | 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
* [ELF] - Added support of linkerscript's "/DISCARD/" for --emit-relocsGeorge Rimar2017-02-172-0/+25
| | | | | | | | | | | | Previously LLD crashed on on provided testcases because "/DISCARD/" was not supported. Patch implements that. After this I think there is no known issues with --emit-relocs implementation required for linux kernel linking. Differential revision: https://reviews.llvm.org/D29273 llvm-svn: 295488
* Fix --print-gc-sections with linker scripts.Rafael Espindola2017-02-171-1/+7
| | | | | | | | Before it would never print anything. Thanks to George Rimar for pointing it out. llvm-svn: 295485
* Don't print DISCARD sections as gced.Rafael Espindola2017-02-171-0/+13
| | | | | | | | 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-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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-0/+5
| | | | | | We were only checking when the assignment was inside a section. llvm-svn: 295454
* [ELF] - Do not crash when discarding sections that are referenced by others.George Rimar2017-02-161-0/+32
| | | | | | | | | | | | | 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/+17
| | | | | | | | | | | | | | 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-0/+2
| | | | | | | | | | | | | | | | 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
* Simplify operator tests.Rui Ueyama2017-02-151-150/+52
| | | | llvm-svn: 295222
* Rename a test as they are tests for operators.Rui Ueyama2017-02-151-0/+0
| | | | llvm-svn: 295221
* [ELF] - Linkerscript - fix handling of OUTPUT_ARCH command.George Rimar2017-02-081-6/+1
| | | | | | | | | | | | | | 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] - Rename the test. NFC.George Rimar2017-02-081-0/+0
| | | | | | | Addressing post commit comments, it do nothing relative with orphans. llvm-svn: 294429
* [ELF] Handle output section alignment in linker scriptsPetr Hosek2017-02-071-0/+62
| | | | | | | | | | 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
* [ELF] - Assign proper values for DefinedSynthetic symbols attached to ↵George Rimar2017-02-071-0/+16
| | | | | | | | | | | | | | | | | | | | 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] - Removed excessive check call from outputarch.s. NFC.George Rimar2017-02-071-1/+0
| | | | | | | For case when LLD should error out, llm-readobj was called, what worked because argument was an output from first test run. llvm-svn: 294310
* Handle symbol assignments before the first section switch.Rafael Espindola2017-02-061-0/+12
| | | | | | | | | | 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
* Stop propagating Entsize.Rafael Espindola2017-02-031-1/+1
| | | | | | | Now that we combine multiple synthetic merge section into one output section there is no point in trying to propagate a value. llvm-svn: 294048
* Handle numbers followed by ":" in linker scripts.Rafael Espindola2017-02-031-0/+14
| | | | | | | | | | | 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
* Replace MergeOutputSection with a synthetic section.Rafael Espindola2017-02-033-65/+74
| | | | | | | | | | | | | | With a synthetic merge section we can have, for example, a single .rodata section with stings, fixed sized constants and non merge constants. I can be simplified further by not setting Entsize, but that is probably better done is a followup patch. This should allow some cleanup in the linker script code now that every output section command maps to just one output section. llvm-svn: 294005
* [ELF] - Linkerscript: properly mark minus expression with non-absolute flagGeorge Rimar2017-02-011-0/+30
| | | | | | | | | | | | | | | | | | | | | | 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-0/+5
| | | | | | | | | | | | | | | | | | 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-13/+0
| | | | | | | | | | | | | | [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-0/+13
| | | | | | Differential revision: https://reviews.llvm.org/D28761 llvm-svn: 293276
* [LinkerScript] Implement `MEMORY` commandMeador Inge2017-01-241-0/+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] - Committed missing ld.ldd invocation to constructor.sGeorge Rimar2017-01-231-0/+1
| | | | | | Thanks to Meador Ingle for noticing. llvm-svn: 292799
* [ELF] - Linkerscripts: ignore CONSTRUCTORS in output section declaration.George Rimar2017-01-231-0/+12
| | | | | | | | | | | 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
OpenPOWER on IntegriCloud