summaryrefslogtreecommitdiffstats
path: root/lld/ELF/ScriptParser.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] - Support "INSERT AFTER" statement.George Rimar2018-03-081-1/+12
| | | | | | | | | | | | | | | | | | | | This implements INSERT AFTER in a following way: During reading scripts it collects all insert statements. After we done and read all files it inserts statements into script commands list. With that: * Rest of code does know nothing about INSERT. * Approach is straightforward and have no visible limitations. * It is also easy to support INSERT BEFORE (was seen in clang code once). * Should work for PR35877 and similar cases. Cons: * It assumes we have "main" scripts that describes sections. Differential revision: https://reviews.llvm.org/D43468 llvm-svn: 327003
* Remove redundant casts.Rui Ueyama2018-03-051-2/+2
| | | | llvm-svn: 326753
* [ELF] - Report location for div/mod by zero.George Rimar2018-03-051-19/+20
| | | | | | | | | | | "division by zero" or "modulo by zero" are not very informative errors and even probably confusing as does not let to know that error is coming from linker script. Patch adds location reporting. Differential revision: https://reviews.llvm.org/D43934 llvm-svn: 326686
* [ELF] - Don't crash on broken MEMORY declaration.George Rimar2018-03-011-3/+7
| | | | | | | | | | | LLD crashes with broken scripts shown in testcase, because fails to read memory regon name and accesses MemoryRegions's element which is nullptr. Patch fixes it. Differential revision: https://reviews.llvm.org/D43866 llvm-svn: 326431
* [ELF] - Do not remove empty sections that use symbols in expressions.George Rimar2018-03-011-0/+4
| | | | | | | | | | | | | | | This is PR36515. Currenly if we have a script like .debug_info 0 : { *(.debug_info) }, we would not remove this section and keep it in the output. That does not work, because it is common case for debug sections to have a zero address expression. Patch changes behavior so that we remove only sections that do not use symbols in its expressions. Differential revision: https://reviews.llvm.org/D43863 llvm-svn: 326430
* Add "%" operator to the linker script.Rui Ueyama2018-02-281-1/+10
| | | | | | | | This patch improves compatibility with GNU linkers. Differential Revision: https://reviews.llvm.org/D43883 llvm-svn: 326348
* Inline a trivial function. NFC.Rui Ueyama2018-02-281-5/+1
| | | | llvm-svn: 326347
* [ELF] - Fix comment. NFC.George Rimar2018-02-161-1/+1
| | | | | | Addresses forgotten comment for D43071. llvm-svn: 325332
* [ELF] - Support COPY, INFO, OVERLAY output sections attributes.George Rimar2018-02-161-4/+11
| | | | | | | | | | | | | | This is PR36298. (COPY), (INFO), (OVERLAY) all have the same effect: section should be marked as non-allocatable. (https://www.eecs.umich.edu/courses/eecs373/readings/Linker.pdf, 3.6.8.1 Output Section Type) Differential revision: https://reviews.llvm.org/D43071 llvm-svn: 325331
* Relax the grammar of the version script.Rui Ueyama2018-02-011-0/+5
| | | | | | | | | In GNU linkers, the last semicolon is optional. We can't link libstdc++ with lld because of that difference. Differential Revision: https://reviews.llvm.org/D42820 llvm-svn: 324036
* Remove MemRegionOffset. NFC.Rafael Espindola2018-01-251-2/+2
| | | | | | We can just use a member variable in MemoryRegion. llvm-svn: 323399
* Handle parsing AT(ADDR(.foo-bar)).Rafael Espindola2018-01-181-0/+3
| | | | | | | | The problem we had with it is that anything inside an AT is an expression, so we failed to parse the section name because of the - in it. llvm-svn: 322801
* Remove dead code.Rui Ueyama2018-01-141-7/+0
| | | | | | | | | parseInt assumed that it could take a negative number literal (e.g. "-123"). However, such number is in reality already handled as a unary operator '-' followed by a number literal, so the number literal is always non-negative. Thus, this code is dead. llvm-svn: 322453
* [ELF] - Fix for ld.lld does not accept "AT" syntax for declaring LMA regionGeorge Rimar2018-01-121-0/+8
| | | | | | | | | | | AT> lma_region expression allows to specify the memory region for section load address. Should fix PR35684. Differential revision: https://reviews.llvm.org/D41397 llvm-svn: 322359
* Add a comment about subtracting two non abs symbols. NFC.Rafael Espindola2017-12-261-0/+1
| | | | llvm-svn: 321458
* Simplify script lexer.Rui Ueyama2017-12-261-2/+0
| | | | | | Differential Revision: https://reviews.llvm.org/D41577 llvm-svn: 321453
* Result of subtracting two symbols should be absolute.Rafael Espindola2017-12-221-0/+2
| | | | | | | | | | When two linker script symbols are subtracted, the result should be absolute. This is the behavior of binutils' ld. Patch by Erick Reyes! llvm-svn: 321390
* Move Memory.{h,cpp} to Common.Rui Ueyama2017-11-281-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40571 llvm-svn: 319221
* [ELF] Fall back to search dirs for linker scripts specified with -TAlexander Richardson2017-11-201-10/+2
| | | | | | | | | | | | | | | | | | | | Summary: This matches the behaviour of ld.bfd: https://sourceware.org/binutils/docs/ld/Options.html#Options If scriptfile does not exist in the current directory, ld looks for it in the directories specified by any preceding '-L' options. Multiple '-T' options accumulate. Reviewers: ruiu, grimar Reviewed By: ruiu, grimar Subscribers: emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D40129 llvm-svn: 318655
* [ELF] Support expressions with -defsym optionPetr Hosek2017-11-041-0/+13
| | | | | | | | Fixes PR34948. Differential Revision: https://reviews.llvm.org/D39511 llvm-svn: 317396
* [ELF] - Linkerscript: fixed non-determinism when handling MEMORY.George Rimar2017-11-031-1/+1
| | | | | | | | | | | | | When findMemoryRegion do search to find a region for output section it iterates over MemoryRegions which is DenseMap and so does not guarantee iteration in insertion order. As a result selected region depends on its name and not on its definition position Testcase shows the issue, patch fixes it. Behavior after applying the patch seems consistent with bfd. Differential revision: https://reviews.llvm.org/D39544 llvm-svn: 317307
* [lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman2017-10-251-18/+18
| | | | | | | | | | | | | | | | | | | Summary: The COFF linker and the ELF linker have long had similar but separate Error.h and Error.cpp files to implement error handling. This change introduces new error handling code in Common/ErrorHandler.h, changes the COFF and ELF linkers to use it, and removes the old, separate implementations. Reviewers: ruiu Reviewed By: ruiu Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits Differential Revision: https://reviews.llvm.org/D39259 llvm-svn: 316624
* [ELF] - Linkerscript: fix issue with SUBALIGN.George Rimar2017-10-251-8/+20
| | | | | | | | | | | | | | | This is PR34886. SUBALIGN command currently triggers failture if result expression is zero. Patch fixes the issue, treating zero as 1, what is consistent with other places and ELF spec it seems. Patch also adds "is power of 2" check for this and other expressions returning alignment. Differential revision: https://reviews.llvm.org/D38846 llvm-svn: 316580
* Return early if it fails to parse a hex string.Rui Ueyama2017-10-111-2/+8
| | | | | | | | This patch doesn't change the behavior of the program because it would eventually return None at end of the function. But it is better to return None early if we know it will eventually happen. llvm-svn: 315495
* Swap parameters of getSymbolValue.Rui Ueyama2017-10-111-3/+3
| | | | | | | | | Usually, a function that does symbol lookup takes symbol name as its first argument. Also, if a function takes a source location hint, it is usually the last parameter. So the previous parameter order was counter-intuitive. llvm-svn: 315433
* Rename BytesDataCommand -> ByteCommand.Rui Ueyama2017-10-111-5/+4
| | | | llvm-svn: 315431
* Rename Commands -> SectionCommands.Rui Ueyama2017-10-111-7/+7
| | | | | | | | | | "Commands" was ambiguous because in the linker script, everything is a command. We used to handle only SECTIONS commands, and at the time, it might make sense to call them the commands, but it is no longer the case. We handle not only SECTIONS but also MEMORY, PHDRS, VERSION, etc., and they are all commands. llvm-svn: 315409
* Rename HasSections -> HasSectionsComand.Rui Ueyama2017-10-111-1/+1
| | | | | | | | HasSections is true if there is at least one SECTIONS linker script command, and it is not directly related to whether we have section objects or not. So I think the new name is better. llvm-svn: 315405
* Remove ScriptConfiguration class and move the members to LinkerScript class.Rui Ueyama2017-10-111-16/+16
| | | | | | | | | | | | | | | | ScriptConfiguration was a class to contain parsed results of linker scripts. LinkerScript is a class to interpret it. That ditinction was needed because we haven't instantiated LinkerScript early (because, IIRC, LinkerScript class was a ELFT template function). So, when we parse linker scripts, we couldn't directly store the result to a LinkerScript instance. Now, that limitation is gone. We instantiate LinkerScript at the very beginning of our main function. We can directly store parse results to a LinkerScript instance. llvm-svn: 315403
* Remove a constructor from ExprValue. NFC.Rui Ueyama2017-10-111-4/+4
| | | | | | I think three ctors are too many for this simple class. llvm-svn: 315394
* Use llvm::Optional instead of UINT_MAX to represent a null value.Rui Ueyama2017-10-081-9/+10
| | | | llvm-svn: 315168
* Make ScriptParser::checkSection a non-member function.Rui Ueyama2017-10-081-7/+11
| | | | | | | This patch also make its return type to `void` because it always returns a given value as-is. llvm-svn: 315165
* Remove a trivial function.Rui Ueyama2017-10-081-1/+1
| | | | llvm-svn: 315164
* Consider ForceAbsolute again in moveAbsRight.Rafael Espindola2017-09-201-1/+1
| | | | | | | | | This patch goes back to considering ForceAbsolute in moveAbsRight, but only if the second argument is not already absolute. With this we can handle "foo + ABSOLUTE(foo)" and "ABSOLUTE(foo) + foo". llvm-svn: 313800
* Consider only A.Sec in moveAbsRight.Rafael Espindola2017-09-201-1/+1
| | | | | | | | | | | | | | The idea of this function is to simplify the implementation of binary operators like add. A value might be absolute because of an ABSOLUTE expression, but it still depends on the value of a section and we might not be able to evaluate it early. We should keep such values on the LHS, so that we can delay the evaluation. We can now handle both "1 + ABSOLUTE(foo)" and "ABSOLUTE(foo) + 1". llvm-svn: 313794
* Align addresses, not offsets.Rafael Espindola2017-09-121-4/+2
| | | | | | | This fixes two more cases where we were aligning the offset in a section, instead of the final address. llvm-svn: 312983
* Handle empty dynamic lists.Rafael Espindola2017-09-081-0/+1
| | | | llvm-svn: 312820
* If --dynamic-list is given, only those symbols are preemptible.Rafael Espindola2017-09-081-2/+15
| | | | | | | | | | | | | 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
* [ELF] - Linkerscript: implement REGION_ALIAS.George Rimar2017-09-081-7/+24
| | | | | | | | | | | | REGION_ALIAS(alias, region) Alias names can be added to existing memory regions created with the MEMORY command. Each name corresponds to at most one memory region. Differential revision: https://reviews.llvm.org/D37477 llvm-svn: 312777
* Revert "Revert "Revert r311468: If --dynamic-list is given, only those ↵Rafael Espindola2017-09-081-15/+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/+15
| | | | | | | | | | | | | | 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
* Detect linker script INCLUDE cycles.Rui Ueyama2017-09-061-0/+9
| | | | | | Differential Revision: https://reviews.llvm.org/D37524 llvm-svn: 312656
* Add a comment.Rui Ueyama2017-09-061-0/+1
| | | | llvm-svn: 312655
* Revert r311468: If --dynamic-list is given, only those symbols are preemptibleRui Ueyama2017-08-221-15/+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/+15
| | | | | | | | | | | | | | | | | 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, LinkerScript] Support ! operator in linker script.Hafiz Abid Qadeer2017-08-101-0/+4
| | | | | | | | | | | | | | Summary: This small patch adds the support for ! operator in linker scripts. Reviewers: ruiu, rafael Reviewed By: ruiu Subscribers: meadori, grimar, emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D36451 llvm-svn: 310607
* [ELF] - Remove ScriptLexer::Error field and check ErrorCount instead.George Rimar2017-08-041-18/+18
| | | | | | | | | | | | D35945 introduces change when there is useless to check Error flag in few places, but ErrorCount must be checked instead. But then we probably can just check ErrorCount always. That should simplify things. Patch do that. Differential revision: https://reviews.llvm.org/D36266 llvm-svn: 310046
* [ELF] - Do not segfault if linkerscript tries to access Target too early.George Rimar2017-08-031-10/+22
| | | | | | | | | | | | | | Following possible scripts triggered accessing to Target when it was not yet initialized (was nullptr). MEMORY { name : ORIGIN = DATA_SEGMENT_RELRO_END; } MEMORY { name : ORIGIN = CONSTANT(COMMONPAGESIZE); } Patch errors out instead. Differential revision: https://reviews.llvm.org/D36140 llvm-svn: 309953
* [ELF] - Do not crash when ALIGN/DATA_SEGMENT_ALIGN expression used with zero ↵George Rimar2017-07-281-3/+7
| | | | | | | | | | | | | value. Previously we would crash when tried to ALIGN(0). Patch uses value 1 instead in this case, that looks to be consistent with GNU linkers and reasonable and simple behavior itself. Differential revision: https://reviews.llvm.org/D35942 llvm-svn: 309372
* Merge OutputSectionCommand and OutputSection.Rafael Espindola2017-07-271-18/+14
| | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud