summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [LinkerScript] Handle symbols defined in linker scriptsRafael Auler2015-03-161-0/+22
| | | | | | | | | | Puts symbols defined in linker script expressions in a runtime file that is added as input to the resolver, making the input object files see symbols defined in linker scripts. http://reviews.llvm.org/D8263 llvm-svn: 232409
* [LinkerScript] Implement semantics for simple sections mappingsRafael Auler2015-03-161-6/+403
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit implements the behaviour of the SECTIONS linker script directive, used to not only define a custom mapping between input and output sections, but also order input sections in the output file. To do this, we modify DefaultLayout with hooks at important places that allow us to re-order input sections according to a custom order. We also add a hook in SegmentChunk to allow us to calculate linker script expressions while assigning virtual addresses to the input sections that live in a segment. Not all SECTIONS constructs are currently supported, but only the ones that do not use special sort orders. It adds two LIT test as practical examples of which sections directives are currently supported. In terms of high-level changes, it creates a new class "script::Sema" that owns all linker script ASTs and the logic for linker script semantics as well. ELFLinkingContext owns a single copy of Sema, which will be used throughout the object file writing process (to layout sections as proposed by the linker script). Other high-level change is that the writer no longer uses a "const" copy of the linking context. This happens because linker script expressions must be calculated *while* calculating final virtual addresses, which is a very late step in object file writing. While calculating these expressions, we need to update the linker script symbol table (inside the semantics object), and, thus, we are "modifying our context" as we prepare to write the file. http://reviews.llvm.org/D8157 llvm-svn: 232402
* LinkerScript: Add parsing of the EXTERN commandMeador Inge2015-03-121-0/+46
| | | | | | | | | This patch implements parsing of the GNU ld EXTERN command [1]. Evaluation will be added at a later point in time. [1] https://sourceware.org/binutils/docs/ld/Miscellaneous-Commands.html#Miscellaneous-Commands llvm-svn: 232110
* LinkerScript: Add parsing of the MEMORY commandMeador Inge2015-03-111-0/+120
| | | | | | | | | | | This patch implements parsing of the GNU ld MEMORY command [1]. The command and the memory block definitions are parsed as specified (including the slightly strange "o" and "l" keywords). Evaluation will be added at a later point in time. [1] https://sourceware.org/binutils/docs-2.25/ld/MEMORY.html llvm-svn: 231928
* [LinkerScript] Implement linker script expression evaluationRafael Auler2015-03-091-2/+74
| | | | | | | | | | | The expression evaluation is needed when interpreting linker scripts, in order to calculate the value for new symbols or to determine a new position to load sections in memory. This commit extends Expression nodes from the linker script AST with evaluation functions, and also contains a unit test. http://reviews.llvm.org/D8156 llvm-svn: 231707
* LinkerScript: Remove leaks in the parserDavid Majnemer2015-02-201-33/+36
| | | | | | | | | | | LinkerScript AST nodes are never destroyed which means that their std::vector members will never be destroyed. Instead, allocate the operand list itself in the Parser's BumpPtrAllocator. This ensures that the storage will be destroyed along with the nodes when the Parser is destroyed. llvm-svn: 229967
* Add a comment to Lexer::canContinueNumber.Rui Ueyama2015-02-041-0/+1
| | | | llvm-svn: 228201
* Early return. NFC.Rui Ueyama2015-02-041-16/+15
| | | | llvm-svn: 228106
* Simplify large switches.Rui Ueyama2015-02-041-54/+5
| | | | | | | | | | This may be a little bit inefficient than the original code but that should be okay as this is not really in a performance critical pass. http://reviews.llvm.org/D7393 llvm-svn: 228077
* ELF: Support INPUT linker script directiveRui Ueyama2015-02-031-10/+13
| | | | | | | | | | INPUT directive is a variant of GROUP in the sense that that specifies a list of input files. The only difference is whether the entire file list is wrapped with a --start-group/--end-group or not. http://reviews.llvm.org/D7390 llvm-svn: 228060
* Make ELFLinkingContext own LinkerScript buffersRafael Auler2015-02-031-14/+13
| | | | | | | | | | | | | | Currently, no one owns script::Parser buffers, but yet ELFLinkingContext gets updated with StringRef pointers to data inside Parser buffers. Since this buffer is locally owned inside GnuLdDriver::evalLinkerScript(), as soon as this function finishes, all pointers in ELFLinkingContext that comes from linker scripts get invalid. The problem is that we need someone to own linker scripts data structures and, since ELFLinkingContext transports references to linker scripts data, we can simply make it also own all linker scripts data. Differential Revision: http://reviews.llvm.org/D7323 llvm-svn: 227975
* [ELF] Support for parsing OUTPUT command in LinkerScriptDavide Italiano2015-02-021-0/+30
| | | | | | | Differential Revision: D7326 Reviewed by: rafaelauler, shankarke, ruiu llvm-svn: 227786
* Revert "Add support library."Shankar Easwaran2014-11-111-2/+107
| | | | | | This reverts commit r221583. llvm-svn: 221649
* Add support library.Shankar Easwaran2014-11-101-107/+2
| | | | | | | | | The parsing routines in the linker script to parse strings encoded in various formats(hexadecimal, octal, decimal, etc), is needed by the GNU driver too. This library provides helper functions for all flavors and flavors to add helper functions which other flavors may make use of. llvm-svn: 221583
* [LinkerScript] Change ErrorOr usage to fix MSVC2012 buildbotsRafael Auler2014-11-031-4/+4
| | | | | | | Number parsing functions used an ErrorOr<> idiom that is not supported in MSVC2012. This patch fixes this. llvm-svn: 221128
* [lld] Teach LLD how to parse most linker scriptsRafael Auler2014-11-031-66/+1597
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch does *not* implement any semantic actions, but it is a first step to teach LLD how to read complete linker scripts. The additional linker scripts statements whose parsing is now supported are: * SEARCH_DIR directive * SECTIONS directive * Symbol definitions inside SECTIONS including PROVIDE and PROVIDE_HIDDEN * C-like expressions used in many places in linker scripts * Input to output sections mapping The goal of this commit was guided towards completely parsing a default GNU ld linker script and the linker script used to link the FreeBSD kernel. Thus, it also adds a test case based on the default linker script used in GNU ld for x86_64 ELF targets. I tested SPEC userland programs linked by GNU ld, using the linker script dump'ed by this parser, and everything went fine. I then tested linking the FreeBSD kernel with a dump'ed linker script, installed the new kernel and booted it, everything went fine. Directives that still need to be implemented: * MEMORY * PHDRS Reviewers: silvas, shankarke and ruiu http://reviews.llvm.org/D5852 llvm-svn: 221126
* [ELF] Implement parsing `-l` prefixed items in the `GROUP` linker script ↵Simon Atanasyan2014-07-151-4/+38
| | | | | | | | | | | | | | | | | | command. There are two forms of `-l` prefixed expression: * -l<libname> * -l:<filename> In the first case a linker should construct a full library name `lib + libname + .[so|a]` and search this library as usual. In the second case a linker should use the `<filename>` as is and search this file through library search directories. The patch reviewed by Shankar Easwaran. llvm-svn: 213077
* [LinkerScript] parse OUTPUT_FORMAT : treat quotedStrings as identifierShankar Easwaran2014-02-251-7/+7
| | | | llvm-svn: 202166
* [LinkerScript] OUTPUT_FORMAT: Parse Quoted StringsShankar Easwaran2014-02-251-3/+39
| | | | llvm-svn: 202111
* [LinkerScript] parse OUTPUT_ARCH.Shankar Easwaran2014-02-251-5/+36
| | | | llvm-svn: 202100
* Fix a variety of typos in function names and commentsAlp Toker2013-12-011-1/+1
| | | | | | No change in functionality. llvm-svn: 196053
* Remove unnecessary namespace qualifier.Rui Ueyama2013-11-051-1/+1
| | | | llvm-svn: 194037
* [lld][ELF] Add parser for linker script ENTRY commandRui Ueyama2013-06-031-24/+43
| | | | | | | | | | | | | This is the parser for the ENTRY command. Note that because the parsing result is currentlyd discarded, lld can parse but just ignore the command. Reviewers: Bigcheese CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D833 llvm-svn: 183141
* Add basic linker script parsing.Michael J. Spencer2013-03-011-0/+270
llvm-svn: 176309
OpenPOWER on IntegriCloud