summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.h
Commit message (Collapse)AuthorAgeFilesLines
* Fix a few typos in lld/ELF to cycle botsNico Weber2019-10-281-1/+1
|
* [ELF] Make MergeInputSection merging aware of output sectionsFangrui Song2019-09-241-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes PR38748 mergeSections() calls getOutputSectionName() to get output section names. Two MergeInputSections may be merged even if they are made different by SECTIONS commands. This patch moves mergeSections() after processSectionCommands() and addOrphanSections() to fix the issue. The new pass is renamed to OutputSection::finalizeInputSections(). processSectionCommands() and addorphanSections() are changed to add sections to InputSectionDescription::sectionBases. finalizeInputSections() merges MergeInputSections and migrates `sectionBases` to `sections`. For the -r case, we drop an optimization that tries keeping sh_entsize non-zero. This is for the simplicity of addOrphanSections(). The updated merge-entsize2.s reflects the change. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D67504 llvm-svn: 372734
* Revert "Revert r370635, it caused PR43241."Fangrui Song2019-09-061-0/+1
| | | | | | This reverts commit 50d2dca22b3b05d0ee4883b0cbf93d7d15f241fc. llvm-svn: 371215
* Revert r370635, it caused PR43241.Nico Weber2019-09-061-1/+0
| | | | llvm-svn: 371202
* [ELF] Do not ICF two sections with different output sections (by SECTIONS ↵Fangrui Song2019-09-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | commands) Fixes PR39418. Complements D47241 (the non-linker-script case). processSectionCommands() assigns input sections to output sections. ICF is called before it, so .text.foo and .text.bar may be folded even if their output sections are made different by SECTIONS commands. ``` markLive<ELFT>() doIcf<ELFT>() // During ICF, we don't know the output sections writeResult() combineEhSections<ELFT>() script->processSectionCommands() // InputSection -> OutputSection assignment ``` This patch splits processSectionCommands() into processSectionCommands() and processSymbolAssignments(), and moves processSectionCommands() before ICF: ``` markLive<ELFT>() combineEhSections<ELFT>() script->processSectionCommands() doIcf<ELFT>() // should remove folded input sections writeResult() script->processSymbolAssignments() ``` An alternative approach is to unfold a section `sec` in processSectionCommands() when we find `sec` and `sec->repl` belong to different output sections. I feel this patch is superior because this can fold more sections and the decouple of SectionCommand/SymbolAssignment gives flexibility: * An ExprValue can't be evaluated before its section is assigned to an output section -> we can delete getOutputSectionVA and simplify another place where we had to check if the output section is null. Moreover, a case in linkerscript/early-assign-symbol.s can be handled now. * processSectionCommands/processSymbolAssignments can be freely moved around. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D66717 llvm-svn: 370635
* [ELF] Make LinkerScript::assignAddresses iterativeFangrui Song2019-08-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PR42990. For `SECTIONS { b = a; . = 0xff00 + (a >> 8); a = .; }`, we currently set st_value(a)=0xff00 while st_value(b)=0xffff. The following call tree demonstrates the problem: ``` link<ELF64LE>(Args); Script->declareSymbols(); // insert a and b as absolute Defined Writer<ELFT>().run(); Script->processSectionCommands(); addSymbol(cmd); // a and b are re-inserted. LinkerScript::getSymbolValue // is lazily called by subsequent evaluation finalizeSections(); forEachRelSec(scanRelocations<ELFT>); processRelocAux // another problem PR42506, not affected by this patch finalizeAddressDependentContent(); // loop executed once script->assignAddresses(); // a = 0, b = 0xff00 script->assignAddresses(); // a = 0xff00, _end = 0xffff ``` We need another assignAddresses() to finalize the value of `a`. This patch 1) modifies assignAddress() to track the original section/value of each symbol and return a symbol whose section/value has changed. 2) moves the post-finalizeSections assignAddress() inside the loop of finalizeAddressDependentContent() and makes it iterative. Symbol assignment may not converge so we make a few attempts before bailing out. Note, assignAddresses() must be called at least twice. The penultimate call finalized section addresses while the last finalized symbol values. It is somewhat obscure and there was no comment. linkerscript/addr-zero.test tests this. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D66279 llvm-svn: 369889
* [Coding style change] Rename variables so that they start with a lowercase ↵Rui Ueyama2019-07-101-106/+106
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | letter This patch is mechanically generated by clang-llvm-rename tool that I wrote using Clang Refactoring Engine just for creating this patch. You can see the source code of the tool at https://reviews.llvm.org/D64123. There's no manual post-processing; you can generate the same patch by re-running the tool against lld's code base. Here is the main discussion thread to change the LLVM coding style: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html In the discussion thread, I proposed we use lld as a testbed for variable naming scheme change, and this patch does that. I chose to rename variables so that they are in camelCase, just because that is a minimal change to make variables to start with a lowercase letter. Note to downstream patch maintainers: if you are maintaining a downstream lld repo, just rebasing ahead of this commit would cause massive merge conflicts because this patch essentially changes every line in the lld subdirectory. But there's a remedy. clang-llvm-rename tool is a batch tool, so you can rename variables in your downstream repo with the tool. Given that, here is how to rebase your repo to a commit after the mass renaming: 1. rebase to the commit just before the mass variable renaming, 2. apply the tool to your downstream repo to mass-rename variables locally, and 3. rebase again to the head. Most changes made by the tool should be identical for a downstream repo and for the head, so at the step 3, almost all changes should be merged and disappear. I'd expect that there would be some lines that you need to merge by hand, but that shouldn't be too many. Differential Revision: https://reviews.llvm.org/D64121 llvm-svn: 365595
* [ELF] Deleted unused forward declarations. NFCFangrui Song2019-05-241-1/+0
| | | | llvm-svn: 361614
* Replace `typedef A B` with `using B = A`. NFC.Rui Ueyama2019-04-011-1/+1
| | | | | | | | I did this using Perl. Differential Revision: https://reviews.llvm.org/D60003 llvm-svn: 357372
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [LLD][ELF] - Linker script: accept using a file name without a list of sections.George Rimar2018-12-061-1/+3
| | | | | | | | | | | | | | | | This is a part of https://bugs.llvm.org/show_bug.cgi?id=39885 Linker script specification says: "You can specify a file name to include sections from a particular file. You would do this if one or more of your files contain special data that needs to be at a particular location in memory." LLD did not accept this syntax. The patch implements it. Differential revision: https://reviews.llvm.org/D55324 llvm-svn: 348463
* Move forward declarations to the top of the file and sort.Rui Ueyama2018-10-231-4/+4
| | | | llvm-svn: 345094
* [ELF] - Eliminate the AssertCommand.George Rimar2018-04-251-10/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently, LLD supports ASSERT as a separate command. We support two forms now. Assign expression-form: . = ASSERT(0x100) (old GNU ld required it and some scripts in the wild are still using something like . = ASSERT((_end - _text <= (512 * 1024 * 1024)), "kernel image bigger than KERNEL_IMAGE_SIZE"); Nowadays above is not a mandatory form and command-like form is commonly used: ASSERT(<expr>, "text); The return value of the ASSERT is Dot. That was implemented in D30171. It looks like (2) is just a short version of (1) then. GNU ld does *not* list ASSERT as a SECTIONS command: https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS Given above we probably can change ASSERT to be an assignment to Dot. That makes the rest of the code much simpler. Patch do that. Differential revision: https://reviews.llvm.org/D45434 llvm-svn: 330814
* [ELF] - Reveal more information in -Map file about assignments.George Rimar2018-04-051-4/+2
| | | | | | | | | | | | | | | | | Currently, LLD print symbol assignment commands to the map file, but it does not do that for assignments that are outside of the section descriptions. Such assignments can affect the layout though. The patch implements the following: * Teaches LLD to print symbol assignments outside of section declaration. * Teaches LLD to print PROVIDE/HIDDEN/PROVIDE hidden commands. In case when symbol is not provided, nothing will be printed. Differential revision: https://reviews.llvm.org/D44894 llvm-svn: 329272
* [ELF] - Cleanup. NFCI.George Rimar2018-04-041-4/+8
| | | | | | | | | Rename field, added comments. This is splitted from the D44894. Requested to be committed as independent cleanup. llvm-svn: 329162
* This is PR36799.George Rimar2018-03-261-0/+1
| | | | | | | | | | | | | | | | Currently, we might have a bug with scripts like below: .foo : ALIGN(8) { *(.foo) } > ram because do not expand the memory region when doing ALIGN. This might result in file range overlaps. The patch fixes the issue. Differential revision: https://reviews.llvm.org/D44730 llvm-svn: 328479
* [ELF] - Fix build bot after rL327612.George Rimar2018-03-151-1/+1
| | | | | | Missed this one. llvm-svn: 327616
* [ELF] - Fix build bot after rL327612.George Rimar2018-03-151-2/+2
| | | | | | | Error was: error: field 'Size' will be initialized after field 'CommandString' [-Werror,-Wreorder] llvm-svn: 327613
* [ELF] - Show data and assignment commands in the map file.George Rimar2018-03-151-4/+20
| | | | | | | | | Patch teaches LLD to print BYTE/SHORT/LONG/QUAD and location move commands to the map file. Differential revision: https://reviews.llvm.org/D44004 llvm-svn: 327612
* [ELF] - Implement INSERT BEFORE.George Rimar2018-03-131-1/+2
| | | | | | | | | | | This finishes PR35877. INSERT BEFORE used similar to INSERT AFTER, it inserts sections before the given target section. Differential revision: https://reviews.llvm.org/D44380 llvm-svn: 327378
* [ELF] - Support "INSERT AFTER" statement.George Rimar2018-03-081-0/+7
| | | | | | | | | | | | | | | | | | | | This implements INSERT AFTER in a following way: During reading scripts it collects all insert statements. After we done and read all files it inserts statements into script commands list. With that: * Rest of code does know nothing about INSERT. * Approach is straightforward and have no visible limitations. * It is also easy to support INSERT BEFORE (was seen in clang code once). * Should work for PR35877 and similar cases. Cons: * It assumes we have "main" scripts that describes sections. Differential revision: https://reviews.llvm.org/D43468 llvm-svn: 327003
* [ELF] - Support moving location counter when MEMORY is used.George Rimar2018-03-051-0/+1
| | | | | | | | | | | | | | | | We do not expand memory region correctly for following scripts: .foo.1 : { *(.foo.1) . += 0x1000; } > ram Patch generalizes expanding of output sections and memory regions in one place and fixes the issue. Differential revision: https://reviews.llvm.org/D43999 llvm-svn: 326688
* Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.Rui Ueyama2018-02-281-1/+1
| | | | | | | | | This should resolve the issue that lld build fails in some hosts that uses case-insensitive file system. Differential Revision: https://reviews.llvm.org/D43788 llvm-svn: 326339
* [ELF] - Do not remove empty output sections that are explicitly assigned to ↵George Rimar2018-02-231-1/+0
| | | | | | | | | | | | | phdr in script. This continues direction started in D43069. We can keep sections that are explicitly assigned to segment in script. It helps to simplify code. Differential revision: https://reviews.llvm.org/D43571 llvm-svn: 325887
* Run dos2unix in a few files. NFC.Rafael Espindola2018-01-301-7/+7
| | | | llvm-svn: 323793
* Sort orphan section if --symbol-ordering-file is given.Rafael Espindola2018-01-301-5/+2
| | | | | | Before this patch orphan sections were not sorted. llvm-svn: 323779
* [ELF] - Define linkerscript symbols early.George Rimar2018-01-301-6/+7
| | | | | | | | | | | | | | | | Currently symbols assigned or created by linkerscript are not processed early enough. As a result it is not possible to version them or assign any other flags/properties. Patch creates Defined symbols for -defsym and linkerscript symbols early, so that issue from above can be addressed. It is based on Rafael Espindola's version of D38239 patch. Fixes PR34121. Differential revision: https://reviews.llvm.org/D41987 llvm-svn: 323729
* Improve LMARegion handling.Rafael Espindola2018-01-251-0/+1
| | | | | | | | | | | | This fixes the crash reported at PR36083. The issue is that we were trying to put all the sections in the same PT_LOAD and crashing trying to write past the end of the file. This also adds accounting for used space in LMARegion, without it all 3 PT_LOADs would have the same physical address. llvm-svn: 323449
* Simplify. NFC.Rafael Espindola2018-01-251-1/+1
| | | | llvm-svn: 323440
* Remove MemRegionOffset. NFC.Rafael Espindola2018-01-251-1/+6
| | | | | | We can just use a member variable in MemoryRegion. llvm-svn: 323399
* Delete dead code. NFC.Rafael Espindola2017-11-291-1/+0
| | | | llvm-svn: 319274
* ELF: Merge DefinedRegular and Defined.Peter Collingbourne2017-11-061-2/+2
| | | | | | | | | 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
* Move OutputSectionFactory to LinkerScript.cpp. NFC.Rui Ueyama2017-11-041-1/+1
| | | | | | | | 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 SymbolBody -> SymbolRui Ueyama2017-11-031-1/+1
| | | | | | | | | | | | | 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] - Fix compilation after r317307.George Rimar2017-11-031-0/+1
| | | | | | | | | Not sure why that seems did not break any llvm bots or my windows local build, but is was required to fix compilation breakage of my ubuntu build when using gcc version 8.0.0 20171019 (experimental) llvm-svn: 317317
* [ELF] - Linkerscript: fixed non-determinism when handling MEMORY.George Rimar2017-11-031-1/+1
| | | | | | | | | | | | | When findMemoryRegion do search to find a region for output section it iterates over MemoryRegions which is DenseMap and so does not guarantee iteration in insertion order. As a result selected region depends on its name and not on its definition position Testcase shows the issue, patch fixes it. Behavior after applying the patch seems consistent with bfd. Differential revision: https://reviews.llvm.org/D39544 llvm-svn: 317307
* [ELF] - Simplify output section creation.George Rimar2017-10-311-1/+0
| | | | | | | | | | | | | 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] Add support for multiple passes to createThunks()Peter Smith2017-10-271-3/+4
| | | | | | | | | | | | | This change allows Thunks to be added on multiple passes. To do this we must merge only the thunks added in each pass, and deal with thunks that have drifted out of range of their callers. A thunk may end out of range of its caller if enough thunks are added in between the caller and the thunk. To handle this we create another thunk. Differential Revision: https://reviews.llvm.org/D34692 llvm-svn: 316754
* [ELF] Record created ThunkSections in InputSectionDescription [NFC].Peter Smith2017-10-271-0/+5
| | | | | | | | | Instead of maintaining a map of the std::vector to ThunkSections, record the ThunkSections directly in InputSectionDescription. Differential Revision: https://reviews.llvm.org/D37743 llvm-svn: 316750
* Make Ctx a plain pointer again.Rafael Espindola2017-10-231-1/+8
| | | | | | | | | | | 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-2/+5
| | | | | | 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
* [ELF] - Make LinkerScript::assignOffsets private. NFC.George Rimar2017-10-181-1/+2
| | | | llvm-svn: 316073
* Split LinkerScript::computeInputSections into two functions.Rui Ueyama2017-10-111-1/+0
| | | | llvm-svn: 315434
* Swap parameters of getSymbolValue.Rui Ueyama2017-10-111-1/+1
| | | | | | | | | 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
* Rename BytesDataCommand -> ByteCommand.Rui Ueyama2017-10-111-6/+6
| | | | llvm-svn: 315431
* Use more precise type.Rui Ueyama2017-10-111-2/+2
| | | | llvm-svn: 315426
* Rename CurAddressState -> Ctx.Rui Ueyama2017-10-111-1/+1
| | | | | | | | | 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
* Make LinkerScript::addSymbol a private member function.Rui Ueyama2017-10-111-2/+2
| | | | llvm-svn: 315416
* Rename processCommands -> processSectionCommands.Rui Ueyama2017-10-111-2/+2
| | | | llvm-svn: 315415
OpenPOWER on IntegriCloud