aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF/ScriptParser.cpp
AgeCommit message (Collapse)AuthorFilesLines
2017-12-26Add a comment about subtracting two non abs symbols. NFC.Rafael Espindola1-0/+1
llvm-svn: 321458
2017-12-26Simplify script lexer.Rui Ueyama1-2/+0
Differential Revision: https://reviews.llvm.org/D41577 llvm-svn: 321453
2017-12-22Result of subtracting two symbols should be absolute.Rafael Espindola1-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
2017-11-28Move Memory.{h,cpp} to Common.Rui Ueyama1-1/+1
Differential Revision: https://reviews.llvm.org/D40571 llvm-svn: 319221
2017-11-20[ELF] Fall back to search dirs for linker scripts specified with -TAlexander Richardson1-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
2017-11-04[ELF] Support expressions with -defsym optionPetr Hosek1-0/+13
Fixes PR34948. Differential Revision: https://reviews.llvm.org/D39511 llvm-svn: 317396
2017-11-03[ELF] - Linkerscript: fixed non-determinism when handling MEMORY.George Rimar1-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
2017-10-25[lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman1-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
2017-10-25[ELF] - Linkerscript: fix issue with SUBALIGN.George Rimar1-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
2017-10-11Return early if it fails to parse a hex string.Rui Ueyama1-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
2017-10-11Swap parameters of getSymbolValue.Rui Ueyama1-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
2017-10-11Rename BytesDataCommand -> ByteCommand.Rui Ueyama1-5/+4
llvm-svn: 315431
2017-10-11Rename Commands -> SectionCommands.Rui Ueyama1-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
2017-10-11Rename HasSections -> HasSectionsComand.Rui Ueyama1-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
2017-10-11Remove ScriptConfiguration class and move the members to LinkerScript class.Rui Ueyama1-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
2017-10-11Remove a constructor from ExprValue. NFC.Rui Ueyama1-4/+4
I think three ctors are too many for this simple class. llvm-svn: 315394
2017-10-08Use llvm::Optional instead of UINT_MAX to represent a null value.Rui Ueyama1-9/+10
llvm-svn: 315168
2017-10-08Make ScriptParser::checkSection a non-member function.Rui Ueyama1-7/+11
This patch also make its return type to `void` because it always returns a given value as-is. llvm-svn: 315165
2017-10-08Remove a trivial function.Rui Ueyama1-1/+1
llvm-svn: 315164
2017-09-20Consider ForceAbsolute again in moveAbsRight.Rafael Espindola1-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
2017-09-20Consider only A.Sec in moveAbsRight.Rafael Espindola1-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
2017-09-12Align addresses, not offsets.Rafael Espindola1-4/+2
This fixes two more cases where we were aligning the offset in a section, instead of the final address. llvm-svn: 312983
2017-09-08Handle empty dynamic lists.Rafael Espindola1-0/+1
llvm-svn: 312820
2017-09-08If --dynamic-list is given, only those symbols are preemptible.Rafael Espindola1-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
2017-09-08[ELF] - Linkerscript: implement REGION_ALIAS.George Rimar1-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
2017-09-08Revert "Revert "Revert r311468: If --dynamic-list is given, only those ↵Rafael Espindola1-15/+2
symbols are preemptible"" This reverts commit r312757. Evgenii Stepanov reports that it broke some tests. llvm-svn: 312771
2017-09-07Revert "Revert r311468: If --dynamic-list is given, only those symbols are ↵Rafael Espindola1-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
2017-09-06Detect linker script INCLUDE cycles.Rui Ueyama1-0/+9
Differential Revision: https://reviews.llvm.org/D37524 llvm-svn: 312656
2017-09-06Add a comment.Rui Ueyama1-0/+1
llvm-svn: 312655
2017-08-22Revert r311468: If --dynamic-list is given, only those symbols are preemptibleRui Ueyama1-15/+2
This reverts commit r311468 because it broke some CFI bots. llvm-svn: 311497
2017-08-22If --dynamic-list is given, only those symbols are preemptibleRui Ueyama1-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
2017-08-10[ELF, LinkerScript] Support ! operator in linker script.Hafiz Abid Qadeer1-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
2017-08-04[ELF] - Remove ScriptLexer::Error field and check ErrorCount instead.George Rimar1-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
2017-08-03[ELF] - Do not segfault if linkerscript tries to access Target too early.George Rimar1-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
2017-07-28[ELF] - Do not crash when ALIGN/DATA_SEGMENT_ALIGN expression used with zero ↵George Rimar1-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
2017-07-27Merge OutputSectionCommand and OutputSection.Rafael Espindola1-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
2017-07-26[ELF, LinkerScript] Memory region name parsing fixMeador Inge1-0/+2
This patch fixes a small issue with respect to how memory region names are parsed on output section descriptions. For example, consider: .text : { *(.text) } > rom That can also be written like: .text : { *(.text) } >rom The latter form is accepted by GNU LD and is fairly common. Differential Revision: https://reviews.llvm.org/D35920 llvm-svn: 309191
2017-07-20[ELF] Align the value if needed when computing the expressionPetr Hosek1-2/+4
Also add the test cases for the addition and subtraction both for the relative and absolute case. Differential Revision: https://reviews.llvm.org/D35346 llvm-svn: 308692
2017-07-20Add the --chroot option for --reproduce.Rui Ueyama1-1/+1
Summary: If the linker is invoked with `--chroot /foo` and `/bar/baz.o`, it tries to read the file from `/foo/bar/baz.o`. This feature is useful when you are dealing with files created by the --reproduce option. Reviewers: grimar Subscribers: llvm-commits, emaste Differential Revision: https://reviews.llvm.org/D35517 llvm-svn: 308646
2017-07-13Move feature-specific functions out of Strings.cpp.Rui Ueyama1-0/+10
Functions declared in Strings.h should provide generic string operations for the linker, but some of them are too specific to some features. This patch moves them to the location where they are used. llvm-svn: 307949
2017-07-07[ELF] Extract temporary state used in assignAddresses()Peter Smith1-2/+1
The assignAddresses() function accumulates state in the LinkerScript that prevents it from being called multiple times. This change moves the state into a separate structure AddressState that is created at the start of the function and disposed of at the end. CurAddressState is used rather than passing a reference to the state as a parameter to the functions used by assignAddresses(). This is because the getSymbolValue function needs to be executed in the context of AddressState but it is stored in ScriptParser when AddressState is not available. The AddressState is also used in a limited context by processCommands() Differential Revision: https://reviews.llvm.org/D34345 llvm-svn: 307367
2017-06-08Fix a bug in output section directive.Rui Ueyama1-15/+32
Previously, it couldn't parse SECTIONS .text (0x1000) : { *(.text) } because "(" was interpreted as the begining of the "(NOLOAD)" directive. llvm-svn: 305006
2017-06-07[ELF] - Linkerscript: implement NOLOAD section type.George Rimar1-4/+14
This is PR32351 Each output section may have a type. The type is a keyword in parentheses. (https://sourceware.org/binutils/docs/ld/Output-Section-Type.html#Output-Section-Type) This patch support only one type, it is NOLOAD. If output section has such type, we force it to be SHT_NOBITS. More details are available on a review page. Differential revision: https://reviews.llvm.org/D33647 llvm-svn: 304925
2017-06-07[ELF] - Linkerscript: improved error reporting.George Rimar1-6/+8
When linking linux kernel LLD currently reports next errors: ld: error: unable to evaluate expression: input section .head.text has no output section assigned ld: error: At least one side of the expression must be absolute ld: error: At least one side of the expression must be absolute That does not provide file/line information and overall looks unclear. Patch adds location information to ExprValue and that allows to provide more clear error messages. Differential revision: https://reviews.llvm.org/D33943 llvm-svn: 304881
2017-06-07Move Object format code to lib/BinaryFormat.Zachary Turner1-1/+1
This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
2017-06-01Move name lookup to script parsing time.Rafael Espindola1-8/+24
We were looking up sections by name during expression evaluation. By keeping track of forward declarations we can do the lookup during script parsing. Doing the lookup earlier will be more efficient when assignAddresses is run twice and removes two uses of OutputSections. llvm-svn: 304381
2017-05-30[ELF] Use late evaluation for ALIGN in expressionPetr Hosek1-1/+5
While the following expression is handled fine: PROVIDE_HIDDEN(newsym = oldsym + address); The following expression triggers an error because the expression is evaluated as absolute: PROVIDE_HIDDEN(newsym = ALIGN(oldsym, CONSTANT(MAXPAGESIZE)) + address); To avoid this error, we use late evaluation for ALIGN by making the alignment an attribute of the expression itself. Differential Revision: https://reviews.llvm.org/D33629 llvm-svn: 304185
2017-05-16[ELF] - Use llvm::to_integer() instead of StringRef::getAsInteger().George Rimar1-6/+6
Switch to llvm::to_integer() everywhere in LLD instead of StringRef::getAsInteger() because API of latter is confusing. It returns true on error and false otherwise what makes reading the code incomfortable. Differential revision: https://reviews.llvm.org/D33187 llvm-svn: 303149
2017-05-09Add memory ORIGIN and LENGTH expression supportRui Ueyama1-0/+12
Adds support for the ORIGIN and LENGTH linker script built in functions. ORIGIN(memory) Return the origin of the memory region LENGTH(memory) Return the length of the memory region Redo of D29775 for refactored linker script parsing. Patch by Robert Clarke Differential Revision: https://reviews.llvm.org/D32934 llvm-svn: 302564
2017-04-13Rename readOutputSectionFiller parseFill.Rui Ueyama1-10/+10
"read" is used as a prefix for functions that read tokens from input streams. This function doesn't really read anything, but just parses a given string as an integer, so rename. llvm-svn: 300281