summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] Add Section() to expression objectEugene Leviant2016-11-161-44/+57
| | | | | | | | | This allows making symbols containing ADDR(section) synthetic, and defining synthetic symbols outside SECTIONS block. Differential revision: https://reviews.llvm.org/D25441 llvm-svn: 287090
* Rename function to avoid function overloading.Rui Ueyama2016-11-151-3/+3
| | | | | | | We had two functions with the same name to read completely different things. That was confusing. llvm-svn: 286991
* [ELF] - Better diagnostic for relative relocation to an absolute value error.George Rimar2016-11-151-1/+1
| | | | | | | | | | | | | | Patch adds a filename to that error message. I faced next error when debugged one of FreeBSD port: error: relocation R_X86_64_PLT32 cannot refer to absolute symbol __tls_get_addr error message was poor and this patch improves it to show the locations of symbol declaration and using. Differential revision: https://reviews.llvm.org/D26508 llvm-svn: 286940
* Fix program header propagation.Rafael Espindola2016-11-141-18/+30
| | | | | | | | | | Propagate program headers by walking the commands, not the sections. This allows us to propagate program headers even from sections that don't end up in the output. Fixes pr30997. llvm-svn: 286837
* Delay removing empty section commands. NFC.Rafael Espindola2016-11-141-10/+13
| | | | | | | To fix pr30997 we will have to keep them a bit longer, this just splits that part of the diff. llvm-svn: 286827
* Factor out removeEmptyCommands. NFC.Rafael Espindola2016-11-141-1/+5
| | | | llvm-svn: 286826
* Factor out placeOrphanSections. NFC.Rafael Espindola2016-11-141-7/+9
| | | | llvm-svn: 286824
* [ELF] - Removed trailing whitespace. NFC.George Rimar2016-11-141-1/+1
| | | | llvm-svn: 286803
* [ELF] - Removed unused code. NFC.George Rimar2016-11-141-6/+1
| | | | | | | This branch was unused I believe, as Tok can never be empty. llvm-svn: 286802
* [ELF] - Add support for locals list in version script.George Rimar2016-11-121-6/+18
| | | | | | | | | | | | | | | | | | | Previously we did not support anything except "local: *", patch changes that. Actually GNU rules of proccessing wildcards are more complex than that (http://www.airs.com/blog/archives/300): There are 2 iteration for wildcards, at first iteration "*" wildcards are ignored and handled at second iteration. Since we previously decided not to implement such complex rules, I suggest solution that is implemented in this patch. So for "local: *" case nothing changes, but if we have wildcarded locals, they are processed before wildcarded globals. This should fix several FreeBSD ports, one of them is jpeg-turbo-1.5.1 and currently blocks about 5k of ports. Differential revision: https://reviews.llvm.org/D26395 llvm-svn: 286713
* Remove an overloaded function to simplify.Rui Ueyama2016-11-091-2/+2
| | | | | | | This version of addRegular is almost identical to the other except it lacked "size" parameter. llvm-svn: 286416
* Make OutputSectionBase a class instead of class template.Rafael Espindola2016-11-091-30/+28
| | | | | | | | The disadvantage is that we use uint64_t instad of uint32_t for some value in 32 bit files. The advantage is a substantially simpler code, faster builds and less code duplication. llvm-svn: 286414
* Split Header into individual fields.Rafael Espindola2016-11-091-23/+23
| | | | | | | | | This is similar to what was done for InputSection. With this the various fields are stored in host order and only converted to target order when writing. llvm-svn: 286327
* Don't add null and discarded sections to the global list.Rafael Espindola2016-11-081-6/+2
| | | | | | Avoids having to skip them multiple times. llvm-svn: 286261
* Rewrite CommonInputSection as a synthetic input section.Rui Ueyama2016-11-051-6/+2
| | | | | | | | | | | | A CommonInputSection is a section containing all common symbols. That was an input section but was abstracted in a different way than the synthetic input sections because it was written before the synthetic input section was invented. This patch rewrites CommonInputSection as a synthetic input section so that it behaves better with other sections. llvm-svn: 286053
* Create a vector containing all input sections.Rui Ueyama2016-11-051-10/+16
| | | | | | | | | | | | | | | | Previously, we do this piece of code to iterate over all input sections. for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles()) for (InputSectionBase<ELFT> *S : F->getSections()) It turned out that this mechanisms doesn't work well with synthetic input sections because synthetic input sections don't belong to any input file. This patch defines a vector that contains all input sections including synthetic ones. llvm-svn: 286051
* Fix some Clang-tidy modernize-use-default and Include What You Use warnings; ↵Eugene Zelenko2016-11-051-4/+19
| | | | | | | | other minor fixes. Differential revision: https://reviews.llvm.org/D26320 llvm-svn: 286030
* Add [<chars>] to the glob matcher to eliminate use of llvm::Regex.Rui Ueyama2016-11-031-9/+9
| | | | | | | | | | | | | Previously, it didn't support the character class, so we couldn't eliminate the use fo llvm::Regex. Now that it is supported, we can remove compileGlobPattern, which converts a glob pattern to a regex. This patch contains optimization for exact/prefix/suffix matches. Differential Revision: https://reviews.llvm.org/D26284 llvm-svn: 285949
* Use globMatch() instead of llvm::regex in linker scriptsEugene Leviant2016-11-031-5/+5
| | | | | | | | | This can speed up lld up to 5 times when linking applications with large number of sections and using linker script. Differential revision: https://reviews.llvm.org/D26241 llvm-svn: 285895
* Remove Out::Pool and use make() instead.Rui Ueyama2016-11-011-2/+1
| | | | llvm-svn: 285763
* Remove second argument to readProvideOrAssignment.Rafael Espindola2016-11-011-8/+5
| | | | | | With this expressions alone track if they are absolute or not. llvm-svn: 285687
* The expr '.' is not absolute.Rafael Espindola2016-10-311-12/+10
| | | | | | | | | | | | | | With this patch we keep track of the fact that . is a position in the file and therefore not absolute. This allow us to compute relative relocations that involve symbol that are defined in linker scripts with '.'. This fixes https://llvm.org/bugs/show_bug.cgi?id=30406 There is still more work to track absoluteness over the various expressions, but this should unblock linking the EFI bootloader. llvm-svn: 285641
* Delay computation of IsAbsolute.Rafael Espindola2016-10-311-5/+19
| | | | | | | | | | We parse linker scripts very early, but whether an expression is absolute or not can depend on a symbol defined in a .o. Given that, we have to delay the computation of IsAbsolute. We can do that by storing an AST when parsing or by also making IsAbsolute a function like we do for the expression value. This patch implements the second option. llvm-svn: 285628
* Simple numeric constants are absolute.Rafael Espindola2016-10-311-1/+1
| | | | llvm-svn: 285621
* Mark a few more expressions as absolute.Rafael Espindola2016-10-311-3/+5
| | | | llvm-svn: 285611
* Move IsAbsolute from SymbolAssignment to Expr.Rafael Espindola2016-10-311-7/+7
| | | | | | | | | And as a token of the new feature, make ALIGNOF always absolute. This is a step in making it possible to have non absolute symbols out of output sections. llvm-svn: 285608
* Simplify. NFC.Rafael Espindola2016-10-311-4/+4
| | | | | | No need to subtract then add Sec->getVA(). llvm-svn: 285580
* Correctly merge visibility of linkerscript created symbols.Rafael Espindola2016-10-311-2/+2
| | | | llvm-svn: 285567
* Consolidate BumpPtrAllocators.Rui Ueyama2016-10-281-4/+3
| | | | | | | | | | | Previously, we have a lot of BumpPtrAllocators, but all these allocators virtually have the same lifetime because they are not freed until the linker finishes its job. This patch aggregates them into a single allocator. Differential revision: https://reviews.llvm.org/D26042 llvm-svn: 285452
* Don't create a dummy ELF to process a binary file.Rafael Espindola2016-10-271-1/+2
| | | | | | | Now that it is easy to create input section and symbols, this is simple. llvm-svn: 285322
* Delete trivial getters. NFC.Rafael Espindola2016-10-261-3/+3
| | | | llvm-svn: 285190
* Read section headers upfront.Rafael Espindola2016-10-261-1/+1
| | | | | | | | | | | | | | | | | | Instead of storing a pointer, store the members we need. The reason for doing this is that it makes it far easier to create synthetic sections. It also avoids reading data from files multiple times., which might help with cross endian linking and host architectures with slow unaligned access. There are obvious compacting opportunities, but this already has mixed results even on native x86_64 linking. There is also the possibility of better refactoring the code for handling common symbols, but this already shows that a custom class is not necessary. llvm-svn: 285148
* Delete getSectionHdr.Rafael Espindola2016-10-251-4/+3
| | | | | | | | | | | We were fairly inconsistent as to what information should be accessed with getSectionHdr and what information (like alignment) was stored elsewhere. Now all section info has a dedicated getter. The code is also a bit more compact. llvm-svn: 285079
* Don't include PHDRs if linker script doesn't want themEugene Leviant2016-10-201-0/+9
| | | | | | | | | | | | | This script below shouldn't include file and program headers to PT_LOAD segment, because it doesn't have PHDRS and FILEHDR attributes: PHDRS { all PT_LOAD; } SECTIONS { /* list of sections here */ } Differential revision: https://reviews.llvm.org/D25774 llvm-svn: 284709
* [ELF] - Applied clang format. NFC.George Rimar2016-10-201-1/+1
| | | | llvm-svn: 284705
* Read an expression in the form of "ABSOLUTE(<expr>) op <expr> ...".Rui Ueyama2016-10-191-1/+3
| | | | | | Fixes bug 30741. llvm-svn: 284662
* [ELF] Choose default segment when it is not specifiedEugene Leviant2016-10-191-18/+19
| | | | | | | | | | | | | | | | | | | | Linker scripts may specify PHDRS, but not specify section to segment assignments, i.e: PHDRS { seg PT_LOAD; } SECTIONS { .sec1 {} : seg .sec2 {} } In such case linker should still choose some segment for .sec2 section. This patch will add .sec2 to previously opened segments (seg) or to the very first PT_LOAD segment, if no section-to-segment assignments has been made Differential revision: https://reviews.llvm.org/D24795 llvm-svn: 284600
* [ELF] - Linkerscript: accept integer values for PHDRS types.George Rimar2016-10-181-0/+6
| | | | | | | | | | Both gold and ld accepts integers instead of named constants for PHDRS. Patch adds support for that. Differential revision: https://reviews.llvm.org/D25549 llvm-svn: 284470
* Rename skip(StringRef) -> consume(StringRef).Rui Ueyama2016-10-171-24/+24
| | | | | | | | skip() and skip(StringRef) were overloaded functions that have different semantics. This patch rename one of the functions to avoid function overloading. llvm-svn: 284396
* ELF: Add a skip() overload to ignore any tokenJustin Bogner2016-10-171-9/+9
| | | | | | | | | Most functions that return StringRef should check their return values, so I'm planning on marking StringRef [[nodiscard]]. This requires splitting up functions like next() that are sometimes just used for side effects. llvm-svn: 284363
* ELF: Fix a misuse of Twine::toStringRefJustin Bogner2016-10-171-3/+3
| | | | | | | | While the toStringRef API almost certainly ends up populating the SmallString here, the correct way to use this API is to use the return value. llvm-svn: 284361
* [ELF] - Added support of PT_OPENBSD_RANDOMIZEGeorge Rimar2016-10-141-0/+1
| | | | | | | | | | | | | | | This is 30646. PT_OPENBSD_RANDOMIZE The array element specifies the location and size of a part of the memory image of the program that must be filled with random data before any code in the object is executed. The memory region specified by a segment of this type may overlap the region specified by a PT_GNU_RELRO segment, in which case the intersection will be filled with random data before being marked read-only. Reference links: http://man.openbsd.org/OpenBSD-current/man5/elf.5 https://github.com/openbsd/src/commit/c494713c450d98da3f2e1451ee8c7fb675a7c461 Differential revision: https://reviews.llvm.org/D25469 llvm-svn: 284234
* [ELF] - Implemented -z wxneeded.George Rimar2016-10-141-0/+1
| | | | | | | | | | | | | -z wxneeded creates a PHDR PT_OPENBSD_WXNEEDED. PT_OPENBSD_WXNEEDED The array element specifies that a process executing this file may need to be able to map or protect memory regions as simultaneously executable and writable. If the system is unable or unwilling to permit that for this executable then it may fail immediately. This segment type is meaningful only for executable files and is ignored in other objects. http://man.openbsd.org/OpenBSD-current/man5/elf.5 Differential revision: https://reviews.llvm.org/D25472 llvm-svn: 284226
* Support GNU-style ZLIB-compressed input sections.Rui Ueyama2016-10-121-1/+1
| | | | | | | | | | | | | | | | | | Previously, we supported only SHF_COMPRESSED sections because it's new and it's the ELF standard. But there are object files compressed in the GNU style out there, so we had to support it. Sections compressed in the GNU style start with ".zdebug_" and contain different headers than the ELF standard's one. In this patch, getRawCompressedData is responsible to handle it. A tricky thing about GNU-style compressed sections is that we have to rename them when creating output sections. ".zdebug_" prefix implies the section is compressed. We need to rename ".zdebug_" ".debug" because our output sections are not compressed. We do that in this patch. llvm-svn: 284068
* Alternative fix for reloc tareting discarded sectionEugene Leviant2016-10-121-0/+6
| | | | | | | | | | | | r283984 introduced a problem of too many warning messages being shown when -ffunction-sections and -fdata-sections were used in conjunction with --gc-sections linker flag and debugging information present. This happens because lot of relocations from .debug_line section may become invalid in such case. The newer fix doesn't show any warning message but zeroes OutSec pointer in createInputSectionList() to avoid crash, when relocations are written llvm-svn: 284010
* Remove trailing whitespace.Rui Ueyama2016-10-101-1/+1
| | | | llvm-svn: 283786
* [ELF] Don't emit empty PT_LOAD segmentEugene Leviant2016-10-101-0/+11
| | | | | | | | | | | | | Sometimes the very first PT_LOAD segment, created by lld, can be empty. This happens when (all conditions met): - Linker script is used - First section in ELF image is not RO - Not enough space for program headers. Differential revision: https://reviews.llvm.org/D25330 llvm-svn: 283760
* [ELF] Change argument type for findSections. NFCEugene Leviant2016-10-101-5/+5
| | | | llvm-svn: 283742
* [ELF] Linker script: implement LOADADDREugene Leviant2016-10-061-19/+39
| | | | | | Differential revision: https://reviews.llvm.org/D24298 llvm-svn: 283429
* Remove trailing whitespace.Rui Ueyama2016-10-051-2/+2
| | | | llvm-svn: 283372
OpenPOWER on IntegriCloud