summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Writer.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] Define __dso_handle symbol if neededPetr Hosek2017-06-051-0/+5
| | | | | | | | | | | | Traditionally, it has been defined in crtbegin.o, which is typically provided by libgcc or as part of the C library on some systems. However, but there's no principled reason for it to be there. We optionaly define this symbol, which can be used on platforms that don't provide __dso_handle in crtbegin.o or which don't use crtbegin.o at all. Differential Revision: https://reviews.llvm.org/D33856 llvm-svn: 304732
* [ELF] - Make LLD remove gnu-lib compression prefix (".z") after ↵George Rimar2017-06-051-4/+5
| | | | | | | | | | | | | | decompression when using -r This is PR33289. Previously LLD leaved section naming as is and that lead to wrong result, because we decompress sections when using -r, and hence should remove ".z" prefix. Differential revision: https://reviews.llvm.org/D33885 llvm-svn: 304711
* [ELF] SHF_LINK_ORDER should sort based on InputSectionDescriptionsPeter Smith2017-06-051-5/+6
| | | | | | | | | | This change alters the sorting for OutputSections with the SHF_LINK_ORDER flag in OutputSection::finalize() to use the InputSectionDescription representation and not the OutputSection::Sections representation. Differential revision: https://reviews.llvm.org/D33772 llvm-svn: 304700
* Convert another OutputSections use.Rafael Espindola2017-06-031-8/+10
| | | | | | This allows moving clearOutputSections a bit earlier. llvm-svn: 304654
* Run fabricateDefaultCommands before fixSectionAlignments.Rafael Espindola2017-06-021-4/+12
| | | | | | | This allows us to remove the PageAlign field. It will also allow moving fabricateDefaultCommands earlier. llvm-svn: 304513
* Move maybeCompress to OutputSectionCommand.Rafael Espindola2017-06-011-4/+4
| | | | | | | This removes a call to getCmd and allows us to move clearOutputSections earlier. llvm-svn: 304439
* Move synchronize earlier.Rafael Espindola2017-06-011-1/+2
| | | | | | | | This is probably the correct location for it: next to fabricateDefaultCommands. If we don't have a linker script, we fabricate one. If we have one, we patch it. llvm-svn: 304436
* Move clearOutputSections earlier.Rafael Espindola2017-06-011-1/+2
| | | | | | | Now it is as early as it can go: just before synchronize. We now have to move synchronize earlier too. llvm-svn: 304434
* Synchronize the linker script with -r.Rafael Espindola2017-06-011-1/+2
| | | | | | | I don't have a testcase in mind, but there is no reason to have the linker script out of sync during a -r link. llvm-svn: 304433
* Convert a few more uses of OutputSections. NFC.Rafael Espindola2017-06-011-1/+1
| | | | | | Also needed to move clearOutputSections earlier. llvm-svn: 304420
* Convert a few user of OutputSections NFC.Rafael Espindola2017-06-011-5/+9
| | | | | | This is needed to move clearOutputSections earlier. llvm-svn: 304419
* Simplify. NFC.Rafael Espindola2017-05-311-6/+6
| | | | | | | The sections are ordered, so we can just use the first one when looking for the lowest address. llvm-svn: 304369
* Merge two nested ifs. NFC.Rafael Espindola2017-05-311-11/+9
| | | | llvm-svn: 304368
* Move clearOutputSections earlier.Rafael Espindola2017-05-311-1/+1
| | | | | | | Another step into merging the linker script and non linker script code paths. llvm-svn: 304339
* Store a single Parent pointer for InputSectionBase.Rafael Espindola2017-05-311-20/+19
| | | | | | | | | | | | | | | Before InputSectionBase had an OutputSection pointer, but that was not always valid. For example, if it was a merge section one actually had to look at MergeSec->OutSec. This was brittle and caused bugs like the one fixed by r304260. We now have a single Parent pointer that points to an OutputSection for InputSection, but to a SyntheticSection for merge sections and .eh_frame. This makes it impossible to accidentally access an invalid OutSec. llvm-svn: 304338
* [ELF] Add .ARM.exidx sentinel section to an OutputSectionDescriptionPeter Smith2017-05-301-4/+14
| | | | | | | | | | When there is a linker script with .ARM.exidx in the SECTIONS command we must add the .ARM.exidx sentinel section to the InputSectionDescriptions as well as to OutputSection::Sections. Differential Revision: https://reviews.llvm.org/D33496 llvm-svn: 304206
* Replace a few more uses of OutputSections.Rafael Espindola2017-05-301-3/+3
| | | | llvm-svn: 304182
* Keep a list of all OutputSectionCommands.Rafael Espindola2017-05-301-17/+12
| | | | | | | | | | Now that we are trying to use the linker script representation as the canonycal one, there are a few loops looking for just OutputSectionCommands. Create a vector with just the OutputSectionCommands once that is stable to simplify the rest of the code. llvm-svn: 304181
* Avoid a couple uses of OutputSections.Rafael Espindola2017-05-261-5/+12
| | | | | | After fabricateDefaultCommands we can look at the script commands. llvm-svn: 304014
* Avoid using EhFrameHdr->Sections.Rafael Espindola2017-05-261-2/+4
| | | | | | This is a necessary step for moving clearOutputSections earlier. llvm-svn: 304009
* Order writable executable sections before writable ones.Rafael Espindola2017-05-261-16/+27
| | | | | | | | | | | | | | On SPARC, .plt is both writeable and executable. The current way sections are sorted means that lld puts it after .data/.bss. but it really needs to be close to .test to make sure branches into .plt don't overflow. I'd argue that because .bss is supposed to come last on all architectures, we should change the default sort order such that writable and executable sections come before sections that are just writeable. read-only executable sections should still come after sections that are just read-only of course. This diff makes this change. llvm-svn: 304008
* Rearrange code for the sake of readability. NFC.Rui Ueyama2017-05-261-18/+20
| | | | llvm-svn: 303961
* Inline a trivial constructor.Rui Ueyama2017-05-261-6/+0
| | | | llvm-svn: 303958
* When uncompressing sections, remove SHF_COMPRESSED bits. NFC.Rui Ueyama2017-05-251-1/+1
| | | | | | | In this way, the content and the flag is always consistent, which I think better than removing the bit when input sections reaches the Writer. llvm-svn: 303926
* Move writeTo to OutputSectionCommand.Rafael Espindola2017-05-241-21/+50
| | | | | | | | | | | | This reduces how many times we have to map from OutputSection to OutputSectionCommand. It is a required step to moving clearOutputSections earlier. In order to always use writeTo in OutputSectionCommand we have to call fabricateDefaultCommands for -r links and move section compression after it. llvm-svn: 303784
* Move clearOutputSections earlier. NFC.Rafael Espindola2017-05-241-1/+1
| | | | llvm-svn: 303781
* Clear OutSec->Sections.Rafael Espindola2017-05-231-4/+11
| | | | | | | | | | | Once the dummy linker script is created, we want it to be used for everything to avoid having two redundant representations that can get out of sync. We were already clearing OutputSections. With this patch we clear the Sections vector of every OutputSection. llvm-svn: 303703
* Use linker script commands in writeMapFile.Rafael Espindola2017-05-181-1/+6
| | | | | | | | | | This converts the last (chronologically) user of OutputSections to use the linker script commands instead. The idea is to convert all uses after fabricateDefaultCommands, so that we have a single representation. llvm-svn: 303384
* Alternative way to detemplate GotSection.Rafael Espindola2017-05-181-1/+1
| | | | | | | | | | | | | | | | | | | | GetSection is a template because write calls relocate. relocate has two parts. The non alloc code really has to be a template, as it is looking a raw input file data. The alloc part is only a template because of getSize. This patch folds the value of getSize early, detemplates getRelocTargetVA and splits relocate into a templated non alloc case and a regular function for the alloc case. This has the nice advantage of making sure we collect all the information we need for relocations before getting to InputSection::relocateNonAlloc. Since we know got is alloc, it can just call the function directly and avoid the template. llvm-svn: 303355
* Fix flag to start with 1 << 0. NFC.Rafael Espindola2017-05-181-16/+16
| | | | | | Thanks to Andrew Ng for noticing it. llvm-svn: 303354
* [ELF] - Detemplate Thunk creation.George Rimar2017-05-171-1/+1
| | | | | | | | | Nothing special here, just detemplates code that became possible to detemplate after recent commits in a straghtforward way. Differential revision: https://reviews.llvm.org/D33234 llvm-svn: 303237
* [ELF] - Detemplate access to SymTab, DynSymTab, GnuHashTab. NFC.George Rimar2017-05-161-42/+26
| | | | | | Follow up for r303150. llvm-svn: 303153
* [ELF] - Detemplate GnuHashTableSection and SymbolTableSection sections.George Rimar2017-05-161-2/+2
| | | | | | | | | | SymbolTableBaseSection was introduced. Detemplation of SymbolTableSection should allow to detemplate more things. Differential revision: https://reviews.llvm.org/D33124 llvm-svn: 303150
* [ELF] - Use llvm::to_integer() instead of StringRef::getAsInteger().George Rimar2017-05-161-1/+1
| | | | | | | | | | | 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
* [ELF] - Apply clang-format. NFC.George Rimar2017-05-121-13/+28
| | | | llvm-svn: 302921
* Optimize orphan placement in a general way.Rafael Espindola2017-05-121-117/+143
| | | | | | | | | | | | | | | | | | | | | | | | | | We used to place orphans by just using compareSectionsNonScript. Then we noticed that since linker scripts can use another order, we should first try match the section to a given PT_LOAD. But there is nothing special about PT_LOAD. The same issue can show up for PT_GNU_RELRO for example. In general, we have to search for the most similar section and put the orphan next to it. Most similar being defined as how long they follow the same code path in compareSecitonsNonScript. That is what this patch does. We now compute a rank for each output section, with a bit for each branch in what was compareSectionsNonScript. With this findOrphanPos is now fully general and orphan placement can be optimized by placing every section with the same rank at once. The included testcase is a variation of many-sections.s that uses allocatable sections to avoid the fast path in the existing code. Without threads it goes form 46 seconds to 0.9 seconds. llvm-svn: 302903
* Detemplate compareSections. NFC.Rafael Espindola2017-05-111-2/+1
| | | | llvm-svn: 302849
* Detemplate compareSectionsNonScript. NFC.Rafael Espindola2017-05-111-5/+3
| | | | llvm-svn: 302848
* Detemplate isRelroSection. NFC.Rafael Espindola2017-05-111-9/+4
| | | | llvm-svn: 302847
* Detemplate the got.Rafael Espindola2017-05-111-4/+4
| | | | | | This is a bit hackish, but allows for a lot of followup cleanups. llvm-svn: 302845
* Reduce templating. NFC.Rafael Espindola2017-05-111-7/+7
| | | | llvm-svn: 302843
* Reduce template usage. NFC.Rafael Espindola2017-05-111-47/+46
| | | | llvm-svn: 302832
* Reduce template usage. NFC.Rafael Espindola2017-05-111-4/+4
| | | | llvm-svn: 302828
* Reduce template usage. NFC.Rafael Espindola2017-05-111-4/+4
| | | | llvm-svn: 302826
* [ELF] Define __ehdr_start unconditionally even when using linker scriptPetr Hosek2017-05-101-3/+6
| | | | | | | | | | This behavior differs from the semantics implemented by GNU linkers which only define this symbol iff ELF headers are in the memory mapped segment. Differential Revision: https://reviews.llvm.org/D33019 llvm-svn: 302687
* Remove another use of section names. NFC.Rafael Espindola2017-05-101-2/+2
| | | | llvm-svn: 302662
* Use a simpler heuristic for placing orphans.Rafael Espindola2017-05-091-27/+30
| | | | | | | | This is a bit easier to read and a lot faster in some cases. A version of many-sections.s with linker scripts goes from 0m41.232s to 0m19.575s. llvm-svn: 302528
* Simplify orphan section positioning.Rafael Espindola2017-05-081-3/+3
| | | | | | | The code following this one already considers every possible insertion point for orphan sections, there is no point in sorting them before. llvm-svn: 302441
* Delete LinkerScript::getSectionIndex.Rafael Espindola2017-05-051-12/+8
| | | | | | | | | We can set SectionIndex tentatively as we process the linker script instead of looking it repeatedly. In general we should try to have as few name lookups as possible. llvm-svn: 302299
* Simplify the header allocation.Rafael Espindola2017-05-041-62/+7
| | | | | | | | | | | | | | | | In the non linker script case we would try very early to find out if we could allocate the headers. Failing to do that would add extra alignment to the first ro section, since we would set PageAlign thinking it was the first section in the PT_LOAD. In the linker script case the header allocation must be done in the end, causing some duplication. We now tentatively add the headers to the first PT_LOAD and if it turns out they don't fit, remove them. With this we only need to allocate the headers in one place in the code. llvm-svn: 302186
OpenPOWER on IntegriCloud