summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Remove MemRegionOffset. NFC.Rafael Espindola2018-01-251-5/+5
| | | | | | We can just use a member variable in MemoryRegion. llvm-svn: 323399
* Only lookup LMARegion once. NFC.Rafael Espindola2018-01-251-7/+9
| | | | | | This is similar to how we handle MemRegion. llvm-svn: 323396
* Use lookup instead of find. NFC, just simpler.Rafael Espindola2018-01-251-3/+2
| | | | llvm-svn: 323395
* Fix incorrect physical address on self-referencing AT command.Rafael Espindola2018-01-121-8/+8
| | | | | | | | | | | | When a section placement (AT) command references the section itself, the physical address of the section in the ELF header was calculated incorrectly due to alignment happening right after the location pointer's value was captured. The problem was diagnosed and the first version of the patch written by Erick Reyes. llvm-svn: 322421
* [ELF] - Fix for ld.lld does not accept "AT" syntax for declaring LMA regionGeorge Rimar2018-01-121-0/+9
| | | | | | | | | | | AT> lma_region expression allows to specify the memory region for section load address. Should fix PR35684. Differential revision: https://reviews.llvm.org/D41397 llvm-svn: 322359
* [ELF] Compress debug sections after assignAddresses and support custom layoutJames Henderson2018-01-081-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, in r320472, I moved the calculation of section offsets and sizes for compressed debug sections into maybeCompress, which happens before assignAddresses, so that the compression had the required information. However, I failed to take account of relocations that patch such sections. This had two effects: 1. A race condition existed when a debug section referred to a different debug section (see PR35788). 2. References to symbols in non-debug sections would be patched incorrectly. This is because the addresses of such symbols are not calculated until after assignAddresses (this was a partial regression caused by r320472, but they could still have been broken before, in the event that a custom layout was used in a linker script). assignAddresses does not need to know about the output section size of non-allocatable sections, because they do not affect the value of Dot. This means that there is no longer a reason not to support custom layout of compressed debug sections, as far as I'm aware. These two points allow for delaying when maybeCompress can be called, removing the need for the loop I previously added to calculate the section size, and therefore the race condition. Furthermore, by delaying, we fix the issues of relocations getting incorrect symbol values, because they have now all been finalized. llvm-svn: 321986
* Fix output section offset and contents when linker script uses memory region ↵Rafael Espindola2017-12-241-0/+2
| | | | | | | | | | | | | | | | | and data commands. Advance the memory region offset when handling a linker script data command such as BYTE or LONG. Failure to advance the offset results in corrupted output with overlapping sections. Update tests to check for this combination of both a) memory regions and b) data commands. Fixes https://bugs.llvm.org/show_bug.cgi?id=35565 Patch by Owen Shaw! llvm-svn: 321418
* [ELF] Reset OutputSection size prior to processing linker script commandsJames Henderson2017-12-121-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The size of an OutputSection is calculated early, to aid handling of compressed debug sections. However, subsequent to this point, unused synthetic sections are removed. In the event that an OutputSection, from which such an InputSection is removed, is still required (e.g. because it has a symbol assignment), and no longer has any InputSections, dot assignments, or BYTE()-family directives, the size member is never updated when processing the commands. If the removed InputSection had a non-zero size (such as a .got.plt section), the section ends up with the wrong size in the output. The fix is to reset the OutputSection size prior to processing the linker script commands relating to that OutputSection. This ensures that the size is correct even in the above situation. Additionally, to reduce the risk of developers misusing OutputSection Size and InputSection OutSecOff, they are set to simply the number of InputSections in an OutputSection, and the corresponding index respectively. We cannot completely stop using them, due to SHF_LINK_ORDER sections requiring them. Compressed debug sections also require the full size. This is now calculated in maybeCompress for these kinds of sections. Reviewers: ruiu, rafael Differential Revision: https://reviews.llvm.org/D38361 llvm-svn: 320472
* [ELF] Change default output section type to SHT_NOBITSJake Ehrlich2017-12-111-1/+1
| | | | | | | | | | | | | | | | When an output section has no byte commands and has no input sections then it would be ideal if the type of the section is SHT_NOBITS so that the file can take up less space. This change sets the default type of of output sections to SHT_NOBITS instead of SHT_PROGBITS to allow this. This required some minor test changes (which double as tests for this new behavior) but extend-pt-load.s had be changed in a non-trivial way. Since it seems to me that the point of the test is to point out the consequences of how flags are assigned to output sections that don't have input sections I changed the test to work and still show how the memsize of the executable segment was changed. Differential Revision: https://reviews.llvm.org/D41082 llvm-svn: 320437
* Add an early return.Rafael Espindola2017-12-061-0/+2
| | | | | | | Total memory allocation when linking clang goes from 281.80MB to 270.96MB. llvm-svn: 319930
* [ELF] - Produce relocation section name consistent with output section name ↵George Rimar2017-12-011-1/+1
| | | | | | | | | | | | | | | | | when --emit-reloc used with linker script. This is for "Bug 35474 - --emit-relocs produces wrongly-named reloc sections". LLD currently for scripts like: .text.boot : { *(.text.boot) } emits relocation section with name .rela.text because does not take redefined name of output section into account and builds section name using rules for non-scripted case. Patch fixes this oddness. Differential revision: https://reviews.llvm.org/D40652 llvm-svn: 319526
* Handle copy relocations in symbol assignments.Rafael Espindola2017-11-301-2/+7
| | | | | | | | | | | When a linker script has "foo = bar" and bar is the result of a copy relocation foo should point to the same location in .bss. This is part of a growing evidence that copy relocations should be implemented by using replaceSymbol to replace the SharedSymbol with a Defined. llvm-svn: 319449
* Move Memory.{h,cpp} to Common.Rui Ueyama2017-11-281-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40571 llvm-svn: 319221
* [ELF] - Allow applying SHF_MERGE optimization for relocatable output.George Rimar2017-11-171-3/+3
| | | | | | | | | | | This fixes PR35223. Here I enabled SHF_MERGE section content merging for -r like we do for regular linking. Differential revision: https://reviews.llvm.org/D40026 llvm-svn: 318516
* Remove IsLocal.Rafael Espindola2017-11-171-2/+1
| | | | | | | Since we always have Binding in the current symbol design IsLocal is redundant. llvm-svn: 318497
* ELF: Merge DefinedRegular and Defined.Peter Collingbourne2017-11-061-4/+4
| | | | | | | | | Now that DefinedRegular is the only remaining derived class of Defined, we can merge the two classes. Differential Revision: https://reviews.llvm.org/D39667 llvm-svn: 317448
* Inline a small function.Rui Ueyama2017-11-041-8/+5
| | | | llvm-svn: 317428
* Move OutputSectionFactory to LinkerScript.cpp. NFC.Rui Ueyama2017-11-041-2/+100
| | | | | | | | That class is used only by LinkerScript.cpp, so we should move it to that file. Also, it no longer has to be a "factory" class. It can just be a non-member function. llvm-svn: 317427
* Rename replaceBody -> replaceSymbol.Rui Ueyama2017-11-031-2/+2
| | | | llvm-svn: 317383
* Rename SymbolBody -> SymbolRui Ueyama2017-11-031-2/+2
| | | | | | | | | | | | | Now that we have only SymbolBody as the symbol class. So, "SymbolBody" is a bit strange name now. This is a mechanical change generated by perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF) nd clang-format-diff. Differential Revision: https://reviews.llvm.org/D39459 llvm-svn: 317370
* [ELF] - Cleanup of processSectionCommands().George Rimar2017-11-011-19/+11
| | | | | | | | | | | | | | The way we handle ONLY_IF_RO/ONLY_IF_RW constraints in processSectionCommands is a bit tricky. If input sections does no satisfy given constraint we remove command from commands list. It seems too complex, what we can do instead is to make the OutputCommand empty. So that at later steps LLD will remove it just like it deal with other empty output commands. That allows to simplify the loop a bit. Differential revision: https://reviews.llvm.org/D39094 llvm-svn: 317082
* Merge SymbolBody and Symbol into one class, SymbolBody.Rui Ueyama2017-10-311-2/+2
| | | | | | | | | | | | | | | | | | | SymbolBody and Symbol were separated classes due to a historical reason. Symbol used to be a pointer to a SymbolBody, and the relationship between Symbol and SymbolBody was n:1. r2681780 changed that. Since that patch, SymbolBody and Symbol are allocated next to each other to improve memory locality, and they have 1:1 relationship now. So, the separation of Symbol and SymbolBody no longer makes sense. This patch merges them into one class. In order to avoid updating too many places, I chose SymbolBody as a unified name. I'll rename it Symbol in a follow-up patch. Differential Revision: https://reviews.llvm.org/D39406 llvm-svn: 317006
* [ELF] - Simplify output section creation.George Rimar2017-10-311-24/+30
| | | | | | | | | | | | | When there is no SECTION commands given, all sections are technically orphans, but now we handle script orphans sections and regular "orphans" sections for non-scripted case differently, though we can handle them at one place. Patch do that change. Differential revision: https://reviews.llvm.org/D39045 llvm-svn: 316984
* [ELF] - Simplify reporting of garbage collected sections.George Rimar2017-10-271-6/+1
| | | | | | | | | This moves reporting of garbage collected sections right after we do GC. That simplifies things. Differential revision: https://reviews.llvm.org/D39058 llvm-svn: 316759
* Unassign sections if they are "assigned" to /DISCARD/.Rui Ueyama2017-10-251-1/+3
| | | | | | | | | | | | | | | | "/DISCARD/" is a special section name in the linker script to discard input sections. Previously, we handled it as if it were a real section, so an input section can be assigned but dead. However, allowing sections to be - assigned and alive (will be emitted), - not assigned and dead (removed), or - assigned but dead (???) feels logically wrong and practically error-prone. This patch removes the last combination of the states. llvm-svn: 316622
* [ELF] - Implement --orphan-handling option.George Rimar2017-10-251-1/+8
| | | | | | | | | | | | | | | | | | It is PR34946. Spec (http://man7.org/linux/man-pages/man1/ld.1.html) tells about --orphan-handling=MODE, option where MODE can be one of four: "place", "discard", "warn", "error". Currently we already report orphans when -verbose given, what becomes excessive with option implemented. Patch stops reporting orphans when -versbose is given, and support "place", "warn" and "error" modes. It is not yet clear that "discard" mode is useful so it is not supported. Differential revision: https://reviews.llvm.org/D39000 llvm-svn: 316583
* Make Ctx a plain pointer again.Rafael Espindola2017-10-231-6/+4
| | | | | | | | | | | If a struct has a std::unique_ptr member, the logical interpretation is that that member will be destroyed with the struct. That is not the case for Ctx. It is has to be deleted earlier and its lifetime is defined by the functions where the AddressState is created. llvm-svn: 316378
* Don't call buildSectionOrder multiple times.Rafael Espindola2017-10-211-6/+7
| | | | | | This takes linking the linux kernel from 1.52s to 0.58s. llvm-svn: 316251
* Remove unused argument.Rafael Espindola2017-10-201-1/+1
| | | | llvm-svn: 316248
* [lld] Move Threads to CommonBob Haarman2017-10-131-1/+1
| | | | | | | | | | | | | | | | Summary: This will allow using the functionality from other linkers. It is also a prerequisite for sharing the error logging code. Reviewers: ruiu Reviewed By: ruiu Subscribers: emaste, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D38822 llvm-svn: 315725
* [ELF] - Do not set output section flags except SHF_{ALLOC,WRITE,EXECINSTR}.George Rimar2017-10-111-4/+20
| | | | | | | | | | | | | | | | | | | | | | | This is PR34546. Currently LLD creates output sections even if it has no input sections, but its command contains an assignment. Committed code just assigns the same flag that was used in previous live section. That does not work sometimes. For example if we have following script: .ARM.exidx : { *(.ARM.exidx*) } .foo : { _foo = 0; } } Then first section has SHF_LINK_ORDER flag. But section foo should not. That was a reason of crash in OutputSection::finalize(). LLD tried to calculate Link value, calling front() on empty input sections list. We should only keep access flags and omit all others when creating such sections. Patch fixes the crash observed. Differential revision: https://reviews.llvm.org/D37736 llvm-svn: 315441
* Split LinkerScript::computeInputSections into two functions.Rui Ueyama2017-10-111-32/+37
| | | | llvm-svn: 315434
* Swap parameters of getSymbolValue.Rui Ueyama2017-10-111-4/+4
| | | | | | | | | 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
* Do not handle DefinedCommon in linker scripts.Rui Ueyama2017-10-111-6/+4
| | | | | | | | Because of r314495, DefinedCommon symbols cannot reach to getSymbolValue function. When they reach the fucntion, they have already been converted to DefinedRegular symbols. llvm-svn: 315432
* Rename BytesDataCommand -> ByteCommand.Rui Ueyama2017-10-111-1/+1
| | | | llvm-svn: 315431
* Inline LinkerScript::process.Rui Ueyama2017-10-111-43/+45
| | | | | | "process" was not a good name because everything can be named it. llvm-svn: 315430
* Split a loop into two to make it clear that it did two different things.Rui Ueyama2017-10-111-5/+13
| | | | llvm-svn: 315427
* Use more precise type.Rui Ueyama2017-10-111-16/+13
| | | | llvm-svn: 315426
* Remove a static local varaible.Rui Ueyama2017-10-111-8/+6
| | | | | | We should generally avoid static local variables. llvm-svn: 315425
* Avoid a pointer to a pointer to an input section.Rui Ueyama2017-10-111-11/+11
| | | | llvm-svn: 315424
* Add comment.Rui Ueyama2017-10-111-0/+3
| | | | llvm-svn: 315423
* Remove useless cast.Rui Ueyama2017-10-111-3/+2
| | | | llvm-svn: 315421
* Rename filename -> getFilename.Rui Ueyama2017-10-111-3/+3
| | | | llvm-svn: 315420
* Rename Align -> Alignment.Rui Ueyama2017-10-111-2/+2
| | | | llvm-svn: 315419
* Rename CurAddressState -> Ctx.Rui Ueyama2017-10-111-44/+39
| | | | | | | | | We used CurAddressState to capture a dynamic context just like we use lambdas to capture static contexts. So, CurAddressState is used everywhere in LinkerScript.cpp. It is worth a shorter name. llvm-svn: 315418
* Rename processCommands -> processSectionCommands.Rui Ueyama2017-10-111-3/+3
| | | | llvm-svn: 315415
* Inline small functions.Rui Ueyama2017-10-111-16/+0
| | | | llvm-svn: 315414
* Rename Commands -> SectionCommands.Rui Ueyama2017-10-111-18/+19
| | | | | | | | | | "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
* Rename HasSections -> HasSectionsComand.Rui Ueyama2017-10-111-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
* Move a loop invariant outside the loop.Rui Ueyama2017-10-111-3/+2
| | | | llvm-svn: 315404
OpenPOWER on IntegriCloud