summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Add linker-script-included files to reproduce tar files.Rui Ueyama2017-01-091-9/+10
| | | | | | | | Previously, files added using INCLUDE directive weren't added to reproduce archives. In this patch, I defined a function to open a file and use that from Driver and LinkerScript. llvm-svn: 291413
* Change which input sections we concatenateRafael Espindola2017-01-051-31/+1
| | | | | | | | | | | | | | | | | | | | | After Mark's patch I was wondering what was the rationale for the ELF spec requiring us to merge only sections with matching flags and types. I tried emailing https://groups.google.com/forum/#!forum/generic-abi, but looks like my emails are not being posted (the list is probably moderated). I emailed Cary Coutant instead. Cary pointed out that the section was a late addition and didn't got the scrutiny it deserved. Given that and the problems found by implementing the letter of the standard, I propose changing lld to merge all sections with the same name and issue errors if the types or some critical flags are different. This should allow an unmodified firefox linked with lld to run. This also merges some code with the linkerscript path. llvm-svn: 291107
* Remove Driver::OwningMB and instead use make().Rui Ueyama2016-12-231-2/+3
| | | | | | | We managed new MemoryBuffers in different ways in LinkerScript.cpp and Driver.cpp. With this patch, they are managed in the same way. llvm-svn: 290411
* [ELF] Linkerscript: print location of undefined symbol usageEugene Leviant2016-12-221-7/+12
| | | | | | Differential revision: https://reviews.llvm.org/D27194 llvm-svn: 290339
* [ELF] - Linkerscript: Fall back to search paths when INCLUDE not foundGeorge Rimar2016-12-211-2/+8
| | | | | | | | | | | | From https://sourceware.org/binutils/docs/ld/File-Commands.html: The file will be searched for in the current directory, and in any directory specified with the -L option. Patch done by Alexander Richardson. Differential revision: https://reviews.llvm.org/D27831 llvm-svn: 290247
* De-template DefinedSynthetic.Rui Ueyama2016-12-211-4/+3
| | | | | | | | DefinedSynthetic is not created for a real ELF object, so it doesn't have to be a template function. It has a virtual st_value, which is either 32 bit or 64 bit, but we can simply use 64 bit. llvm-svn: 290241
* [ELF] - Fix use of freed memory.George Rimar2016-12-211-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It was revealed by D27831. If we have linkerscript that includes another one that sets OUTPUT for example: RUN: echo "INCLUDE \"foo.script\"" > %t.script RUN: echo "OUTPUT(\"%t.out\")" > %T/foo.script then we do: void ScriptParser::readInclude() { ... std::unique_ptr<MemoryBuffer> &MB = *MBOrErr; tokenize(MB->getMemBufferRef()); OwningMBs.push_back(std::move(MB)); } void ScriptParser::readOutput() { ... Config->OutputFile = unquote(Tok); ... } Problem is that OwningMBs are destroyed after script parser do its job. So all Toks are dead and Config->OutputFile points to destroyed data. Patch suggests to save all included scripts into using string Saver. Differential revision: https://reviews.llvm.org/D27987 llvm-svn: 290238
* Fix corner cases of setting the section address.Rafael Espindola2016-12-191-11/+2
| | | | | | | | | | | | | | | | This handles all the corner cases if setting a section address: - If the address is too low, we cannot allocate the program headers. - If the load address is lowered, we have to do that before finalize This also shares some code with the linker script since it was already hitting similar cases. This is used by the freebsd boot loader. It is not clear if we need to support this with a non binary output, but it is not as bad as I was expecting. llvm-svn: 290136
* Detemplate PhdrEntry. NFC.Rafael Espindola2016-12-191-10/+8
| | | | llvm-svn: 290115
* Remove lld/Support/Memory.h.Rui Ueyama2016-12-181-1/+1
| | | | | | | | | | | | I thought for a while about how to remove it, but it looks like we can just copy the file for now. Of course I'm not happy about that, but it's just less than 50 lines of code, and we already have duplicate code in Error.h and some other places. I want to solve them all at once later. Differential Revision: https://reviews.llvm.org/D27819 llvm-svn: 290062
* [ELF] - Linkerscript: Implement two argument version of ALIGN()Rui Ueyama2016-12-161-1/+8
| | | | | | | | | | Fixes http://llvm.org/PR31129 Patch by Alexander Richardson! Differential Revision: https://reviews.llvm.org/D27848 llvm-svn: 289968
* [ELF] - Apply format. NFC.George Rimar2016-12-151-5/+4
| | | | llvm-svn: 289823
* [ELF] - Do not crash when move location counter backward.George Rimar2016-12-151-1/+5
| | | | | | | | | | | | | | | | | PR31335 shows that we do that in next case: SECTIONS { .text 0x2000 : {. = 0x100 ; *(.text) } } though documentations says that "If . is used inside a section description however, it refers to the byte offset from the start of that section, not an absolute address. " looks does not work as documented in bfd (as mentioned in comments for PR31335). Until we find out the expected behavior was suggested at least not to 'crash', what we do after trying to generate huge file. Differential revision: https://reviews.llvm.org/D27712 llvm-svn: 289782
* Fix parsing when one extern follows another.Rafael Espindola2016-12-091-1/+3
| | | | llvm-svn: 289224
* [ELF] Allow output section data commands to take expressionsMeador Inge2016-12-081-8/+2
| | | | | | | | | | | | The current implementation of the output section data store commands can only handle integer literals, but it should really handle arbitrary expressions [1]. This commit fixes that. [1] https://sourceware.org/binutils/docs-2.27/ld/Output-Section-Data.html#Output-Section-Data Differential Revision: https://reviews.llvm.org/D27561 llvm-svn: 289152
* Move Memory.{h,cpp} to lld/Support so that we can use them from COFF.Rui Ueyama2016-12-081-1/+1
| | | | llvm-svn: 289084
* Change the implementation of --dynamic-list to use linker script parsing.Rafael Espindola2016-12-081-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | The feature is documented as ----------------------------- The format of the dynamic list is the same as the version node without scope and node name. See *note VERSION:: for more information. -------------------------------- And indeed qt uses a dynamic list with an 'extern "C++"' in it. With this patch we support that The change to gc-sections-shared makes us match bfd. Just because we kept bar doesn't mean it has to be in the dynamic symbol table. The changes to invalid-dynamic-list.test and reproduce.s are because of the new parser. The changes to version-script.s are the only case where we change behavior with regards to bfd, but I would like to see a mix of --version-script and --dynamic-list used in the wild before complicating the code. llvm-svn: 289082
* Add support for 'extern "C"'.Rafael Espindola2016-12-081-2/+5
| | | | | | It is used by Qt. llvm-svn: 289074
* Delete dead code.Rafael Espindola2016-12-081-13/+0
| | | | | | Thanks to George Rimar for pointing it out. llvm-svn: 289020
* [ELF] - Teach LLD to recognize PT_OPENBSD_BOOTDATAGeorge Rimar2016-12-061-0/+1
| | | | | | | | | | | Minor patch to fix PR31288 OpenBSD commit: https://github.com/openbsd/src/commit/d39116912b9536bd77326260dc5c6e593fd4ee24 Differential revision: https://reviews.llvm.org/D27458 llvm-svn: 288832
* [ELF] Print file:line for unknown PHDR errorEugene Leviant2016-12-051-3/+4
| | | | | | Differential revision: https://reviews.llvm.org/D27335 llvm-svn: 288678
* Make get{Line,Column}Number members of StringParser.Rui Ueyama2016-12-011-1/+1
| | | | | | This patch also renames currentLocation getCurrentLocation. llvm-svn: 288308
* [ELF] - Add support of proccessing of the rest allocatable synthetic ↵George Rimar2016-11-291-0/+9
| | | | | | | | | | | sections from linkerscript. This change continues what was started by D27040 Now all allocatable synthetics should be available from script side. Differential revision: https://reviews.llvm.org/D27131 llvm-svn: 288150
* [ELF] - Set Config->SingleRoRx differently. NFC.George Rimar2016-11-281-0/+5
| | | | | | | | | | | Previously Config->SingleRoRx was set in createFiles() and used HasSections. This change moves it to readConfigs at place of common flags handling, and adds logic that sets this flag separatelly from ScriptParser if SECTIONS present. llvm-svn: 288021
* [ELF] Print file:line for 'undefined section' errorsEugene Leviant2016-11-281-8/+12
| | | | | | Differential revision: https://reviews.llvm.org/D27108 llvm-svn: 288019
* Also skip regular symbol assignment at the start of a script.Rafael Espindola2016-11-271-11/+24
| | | | | | | | | | | | Unfortunatelly some scripts look like kernphys = ... . = .... and the expectation in that every orphan section is after the assignment. llvm-svn: 287996
* Don't put an orphan before the first . assignment.Rafael Espindola2016-11-271-3/+11
| | | | | | | | This is an horrible special case, but seems to match bfd's behaviour and is important for avoiding placing an orphan section before the expected start of the file. llvm-svn: 287994
* Create sections with just assignments as STT_NOBITS.Rafael Espindola2016-11-261-1/+1
| | | | | | | This matches the behaviour of bfd ld. Using 0 was causing problems with strip, which would remove these sections. llvm-svn: 287969
* Remove a parameter from ScriptParser.Rui Ueyama2016-11-251-14/+14
| | | | llvm-svn: 287944
* Remove HasError and use ErrorCount instead.Rui Ueyama2016-11-241-1/+1
| | | | | | HasError was always true if ErrorCount > 0, so we can use ErrorCount instead. llvm-svn: 287849
* [ELF] Allow `ASSERT` in output section descriptionsMeador Inge2016-11-221-6/+15
| | | | | | | | GNU LD allows `ASSERT` commands to be in output section descriptions. Note that LD also mandates that `ASSERT` commands in this context must end with a semicolon. llvm-svn: 287677
* Use the correct page size.Rafael Espindola2016-11-211-1/+1
| | | | | | | Config->MaxPageSize is what we use for the segment alignment, so that is the one that we have to use for placing the header. llvm-svn: 287569
* Fix address computation for headers.Rafael Espindola2016-11-211-15/+12
| | | | | | | | | | | | | | | | If the linker script has SECTIONS, the address computation is now always done in LinkerScript::assignAddresses, like for any other section. Before fixHeaders would do a tentative computation that assignAddresses would sometimes override. This patch also splits the cases where assignAddresses needs to add the headers to the first PT_LOAD and the address computation. The net effect is that we no longer create an empty page for no reason in the included test case, which matches bfd behavior. llvm-svn: 287565
* [ELF] Better error reporting for linker scriptsEugene Leviant2016-11-211-8/+8
| | | | | | Differential revision: https://reviews.llvm.org/D26795 llvm-svn: 287547
* Add comments.Rui Ueyama2016-11-211-20/+33
| | | | | | This patch rearranges code a bit to make it easy to explain. llvm-svn: 287515
* Simplify. NFC.Rui Ueyama2016-11-211-21/+18
| | | | llvm-svn: 287514
* Add a flag to InputSectionBase for linker script.Rui Ueyama2016-11-201-16/+5
| | | | | | | | | | | | | Previously, we set (uintptr_t)-1 to InputSectionBase::OutSec to record that a section has already been set to be assigned to some output section by linker scripts. Later, we restored nullptr to the pointer to use the field for the original purpose. That overloading is not very easy to understand. This patch adds a bit flag for that purpose, so that we don't need to piggyback the flag on an unrelated pointer. llvm-svn: 287508
* Use Optional<std::string> instead of "" to represent a failure.Rui Ueyama2016-11-191-4/+3
| | | | llvm-svn: 287456
* Simplify. NFC.Rui Ueyama2016-11-191-10/+6
| | | | llvm-svn: 287446
* Change filler type from ArrayRef<uint8_t> to uint32_t.Rui Ueyama2016-11-191-12/+11
| | | | | | | Filler expressions in linker script "=fillexp" are always handled as 32-bit integers. Thus the new type is more natural. llvm-svn: 287445
* Update comment.Rui Ueyama2016-11-181-6/+11
| | | | llvm-svn: 287325
* Omit empty parameter list.Rui Ueyama2016-11-181-7/+7
| | | | llvm-svn: 287324
* Use consume() instead of peek() and skip().Rui Ueyama2016-11-181-3/+6
| | | | llvm-svn: 287323
* Split ScriptParser::readVersionDeclaration.Rui Ueyama2016-11-181-39/+58
| | | | | | | | | | | readVersionDeclaration was to read anonymous version definition and named version definition. Splitting it into two functions should improve readability as the two cases are different enough. I also changed a few helper functions to return values instead of mutating given references. llvm-svn: 287319
* Allow SIZEOF() command on nonexistent section.Rui Ueyama2016-11-171-2/+15
| | | | | | | | | | | | | | | | | | | | | | Linker script doesn't create a section if it has no content. So the following script doesn't create .norelocs section if it doesn't have any .rel* sections. .norelocs : { *(.rel*) } Later, if you assert that the size of .norelocs is 0, LLD printed out an error message, because it didn't allow calling SIZEOF() on nonexistent sections. This patch allows SIZEOF() on nonexistent sections, so that you can do something like this. ASSERT(SIZEOF(.norelocs), "shouldn't contain .rel sections!") Note that this behavior is compatible with GNU. Differential Revision: https://reviews.llvm.org/D26810 llvm-svn: 287257
* Avoid accessing an end() iterator.Rafael Espindola2016-11-171-1/+3
| | | | llvm-svn: 287225
* Simplify and use consistent variable name. NFC.Rui Ueyama2016-11-171-13/+9
| | | | llvm-svn: 287200
* Use uint16_t instead of size_t for symbol version ID.Rui Ueyama2016-11-171-1/+1
| | | | | | Because it is uint16_t in the ELF spec. Using size_t was confusing. llvm-svn: 287198
* [ELF] - Separate locals list from versions.George Rimar2016-11-161-1/+1
| | | | | | | | | This change separates all versioned locals to be a separate list in config, that was suggested by Rafael and simplifies the logic a bit. Differential revision: https://reviews.llvm.org/D26754 llvm-svn: 287132
* [ELF] - Added support for extern "c++" local symbols in version script.George Rimar2016-11-161-23/+20
| | | | | | | | | Previously we did not support them, patch implements this functionality Differential revision: https://reviews.llvm.org/D26604 llvm-svn: 287124
OpenPOWER on IntegriCloud