summaryrefslogtreecommitdiffstats
path: root/lld/ELF/ScriptParser.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Merging r344368:Tom Stellard2018-10-221-5/+13
| | | | | | | | | | | | | | | | | | | ------------------------------------------------------------------------ r344368 | ruiu | 2018-10-12 10:07:32 -0700 (Fri, 12 Oct 2018) | 10 lines [lld] Add more complete support for the INCLUDE command. Patch by Ian Tessier. This change adds INCLUDE support to the MEMORY and SECTION commands, and to output sections, as per: https://sourceware.org/binutils/docs/ld/File-Commands.html#File-Commands Differential Revision: https://reviews.llvm.org/D52951 ------------------------------------------------------------------------ llvm-svn: 344926
* [ELF] Use search paths for --version-script=Fangrui Song2018-07-251-1/+1
| | | | | | | | | | | | Summary: This behavior matches ld.bfd -Ld --version-script=t.script a.o Reviewers: ruiu, espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D49820 llvm-svn: 337969
* [ELF] - Add support for '||' and '&&' in linker scripts.George Rimar2018-07-031-6/+12
| | | | | | | This is https://bugs.llvm.org//show_bug.cgi?id=37976, we had no support, but seems someone faced it. llvm-svn: 336197
* [ELF] - Implement linker script OVERLAYs.George Rimar2018-06-271-0/+62
| | | | | | | | | | | | | | | | | | This is PR36768. Linker script OVERLAYs are described in 4.6.9. Overlay Description of the spec: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/sections.html They are used to allow output sections which have different LMAs but the same VAs and used for embedded programming. Currently, LLD restricts overlapping of sections and that seems to be the most desired behaviour for defaults. My thoughts about possible approaches for PR36768 are on the bug page, this patch implements OVERLAY keyword and allows VAs overlapping for sections that within the overlay. Differential revision: https://reviews.llvm.org/D44780 llvm-svn: 335714
* [ELF] - Eliminate the AssertCommand.George Rimar2018-04-251-30/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently, LLD supports ASSERT as a separate command. We support two forms now. Assign expression-form: . = ASSERT(0x100) (old GNU ld required it and some scripts in the wild are still using something like . = ASSERT((_end - _text <= (512 * 1024 * 1024)), "kernel image bigger than KERNEL_IMAGE_SIZE"); Nowadays above is not a mandatory form and command-like form is commonly used: ASSERT(<expr>, "text); The return value of the ASSERT is Dot. That was implemented in D30171. It looks like (2) is just a short version of (1) then. GNU ld does *not* list ASSERT as a SECTIONS command: https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS Given above we probably can change ASSERT to be an assignment to Dot. That makes the rest of the code much simpler. Patch do that. Differential revision: https://reviews.llvm.org/D45434 llvm-svn: 330814
* [ELF] Increase NextGroupId with --end-groupFangrui Song2018-04-191-0/+2
| | | | | | | | | | Reviewers: ruiu, espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D45846 llvm-svn: 330379
* Add --warn-backrefs to maintain compatibility with other linkersRui Ueyama2018-04-091-8/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm proposing a new command line flag, --warn-backrefs in this patch. The flag and the feature proposed below don't exist in GNU linkers nor the current lld. --warn-backrefs is an option to detect reverse or cyclic dependencies between static archives, and it can be used to keep your program compatible with GNU linkers after you switch to lld. I'll explain the feature and why you may find it useful below. lld's symbol resolution semantics is more relaxed than traditional Unix linkers. Therefore, ld.lld foo.a bar.o succeeds even if bar.o contains an undefined symbol that have to be resolved by some object file in foo.a. Traditional Unix linkers don't allow this kind of backward reference, as they visit each file only once from left to right in the command line while resolving all undefined symbol at the moment of visiting. In the above case, since there's no undefined symbol when a linker visits foo.a, no files are pulled out from foo.a, and because the linker forgets about foo.a after visiting, it can't resolve undefined symbols that could have been resolved otherwise. That lld accepts more relaxed form means (besides it makes more sense) that you can accidentally write a command line or a build file that works only with lld, even if you have a plan to distribute it to wider users who may be using GNU linkers. With --check-library-dependency, you can detect a library order that doesn't work with other Unix linkers. The option is also useful to detect cyclic dependencies between static archives. Again, lld accepts ld.lld foo.a bar.a even if foo.a and bar.a depend on each other. With --warn-backrefs it is handled as an error. Here is how the option works. We assign a group ID to each file. A file with a smaller group ID can pull out object files from an archive file with an equal or greater group ID. Otherwise, it is a reverse dependency and an error. A file outside --{start,end}-group gets a fresh ID when instantiated. All files within the same --{start,end}-group get the same group ID. E.g. ld.lld A B --start-group C D --end-group E A and B form group 0, C, D and their member object files form group 1, and E forms group 2. I think that you can see how this group assignment rule simulates the traditional linker's semantics. Differential Revision: https://reviews.llvm.org/D45195 llvm-svn: 329636
* [ELF] - Reveal more information in -Map file about assignments.George Rimar2018-04-051-14/+13
| | | | | | | | | | | | | | | | | Currently, LLD print symbol assignment commands to the map file, but it does not do that for assignments that are outside of the section descriptions. Such assignments can affect the layout though. The patch implements the following: * Teaches LLD to print symbol assignments outside of section declaration. * Teaches LLD to print PROVIDE/HIDDEN/PROVIDE hidden commands. In case when symbol is not provided, nothing will be printed. Differential revision: https://reviews.llvm.org/D44894 llvm-svn: 329272
* [ELF] - Linkerscript: support MIN and MAX.George Rimar2018-03-281-0/+10
| | | | | | | | | | | | | | Sample for the OVERLAY command from the spec (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/sections.html) uses MAX command that we do not support currently: . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1)); This patch implements support for MIN and MAX. Differential revision: https://reviews.llvm.org/D44734 llvm-svn: 328696
* Fix linker script operator precedence.Rui Ueyama2018-03-151-5/+6
| | | | | | | | | | | "&" should have higher priority than "|" [1]. Previously, they had the same priority. [1] https://sourceware.org/binutils/docs/ld/Operators.html Differential Revision: https://reviews.llvm.org/D43880 llvm-svn: 327684
* [ELF] - Show data and assignment commands in the map file.George Rimar2018-03-151-3/+15
| | | | | | | | | Patch teaches LLD to print BYTE/SHORT/LONG/QUAD and location move commands to the map file. Differential revision: https://reviews.llvm.org/D44004 llvm-svn: 327612
* [ELF] - Implement INSERT BEFORE.George Rimar2018-03-131-3/+9
| | | | | | | | | | | This finishes PR35877. INSERT BEFORE used similar to INSERT AFTER, it inserts sections before the given target section. Differential revision: https://reviews.llvm.org/D44380 llvm-svn: 327378
* [ELF] - Removed excessive lookup. NFC.George Rimar2018-03-121-3/+2
| | | | llvm-svn: 327272
* [ELF] - Change consume()->expect() in INSERT AFTER parsing.George Rimar2018-03-121-1/+1
| | | | | | | | AFTER keyword is mandatory and consume() was used by mistake here. We accepted broken script before this patch, testcase shows the issue. llvm-svn: 327260
* [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
OpenPOWER on IntegriCloud