summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.h
Commit message (Collapse)AuthorAgeFilesLines
...
* Inline small functions.Rui Ueyama2017-10-111-4/+8
| | | | llvm-svn: 315414
* Rename Commands -> SectionCommands.Rui Ueyama2017-10-111-1/+1
| | | | | | | | | | "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
* Remove ScriptConfiguration class and move the members to LinkerScript class.Rui Ueyama2017-10-111-25/+20
| | | | | | | | | | | | | | | | ScriptConfiguration was a class to contain parsed results of linker scripts. LinkerScript is a class to interpret it. That ditinction was needed because we haven't instantiated LinkerScript early (because, IIRC, LinkerScript class was a ELFT template function). So, when we parse linker scripts, we couldn't directly store the result to a LinkerScript instance. Now, that limitation is gone. We instantiate LinkerScript at the very beginning of our main function. We can directly store parse results to a LinkerScript instance. llvm-svn: 315403
* Inline addRegular into addSymbol.Rui Ueyama2017-10-111-2/+2
| | | | | | | | Because addRegular's functionality is tightly coupled with addSymbol, and the former is called only once, it makes sense to merge the two functions. This patch also adds comments. llvm-svn: 315401
* Remove a constructor from ExprValue. NFC.Rui Ueyama2017-10-111-3/+0
| | | | | | I think three ctors are too many for this simple class. llvm-svn: 315394
* Add comments.Rui Ueyama2017-10-111-8/+19
| | | | llvm-svn: 315393
* Rename ignoreInterpSection -> needsInterpSection.Rui Ueyama2017-10-081-1/+1
| | | | | | This should improve consistency. Also added comment. llvm-svn: 315169
* Use llvm::Optional instead of UINT_MAX to represent a null value.Rui Ueyama2017-10-081-5/+5
| | | | llvm-svn: 315168
* Make a helper function a non-member function. NFC.Rui Ueyama2017-10-081-1/+0
| | | | llvm-svn: 315167
* Use llvm::Optional instead of a magic number -1 to represent "no result".Rui Ueyama2017-10-081-1/+1
| | | | llvm-svn: 315166
* Remove a trivial function.Rui Ueyama2017-10-081-1/+0
| | | | llvm-svn: 315164
* Move new lld's code to Common subdirectory.Rui Ueyama2017-10-021-1/+1
| | | | | | | | | | New lld's files are spread under lib subdirectory, and it isn't easy to find which files are actually maintained. This patch moves maintained files to Common subdirectory. Differential Revision: https://reviews.llvm.org/D37645 llvm-svn: 314719
* Align addresses, not offsets.Rafael Espindola2017-09-121-0/+1
| | | | | | | This fixes two more cases where we were aligning the offset in a section, instead of the final address. llvm-svn: 312983
* [ELF] - Linkerscript: implement REGION_ALIAS.George Rimar2017-09-081-1/+1
| | | | | | | | | | | | REGION_ALIAS(alias, region) Alias names can be added to existing memory regions created with the MEMORY command. Each name corresponds to at most one memory region. Differential revision: https://reviews.llvm.org/D37477 llvm-svn: 312777
* Merge OutputSectionCommand and OutputSection.Rafael Espindola2017-07-271-42/+7
| | | | | | | | | | | | | This is a bit of a hack, but it is *so* convenient. Now that we create synthetic linker scripts when none is provided, we always have to handle paired OutputSection and OutputsectionCommand and keep a mapping from one to the other. This patch simplifies things by merging them and creating what used to be OutputSectionCommands really early. llvm-svn: 309311
* [ELF] - Store PhdrEntry values by pointers instead of storing by value.George Rimar2017-07-271-2/+2
| | | | | | | | | | | That is slightly more convinent as allows to store pointer on program header entry in a more safe way. Change was used in 2 patches currently on review. Differential revision: https://reviews.llvm.org/D35832 llvm-svn: 309253
* [ELF] Remove processNonSectionCommandsPetr Hosek2017-07-211-1/+0
| | | | | | | | This method is no longer being used anywhere. Differential Revision: https://reviews.llvm.org/D35706 llvm-svn: 308706
* [ELF] Extract temporary state used in assignAddresses()Peter Smith2017-07-071-6/+12
| | | | | | | | | | | | | | | | | | The assignAddresses() function accumulates state in the LinkerScript that prevents it from being called multiple times. This change moves the state into a separate structure AddressState that is created at the start of the function and disposed of at the end. CurAddressState is used rather than passing a reference to the state as a parameter to the functions used by assignAddresses(). This is because the getSymbolValue function needs to be executed in the context of AddressState but it is stored in ScriptParser when AddressState is not available. The AddressState is also used in a limited context by processCommands() Differential Revision: https://reviews.llvm.org/D34345 llvm-svn: 307367
* Move fabricateDefaultCommands earlier.Rafael Espindola2017-07-051-0/+4
| | | | | | | It is now just after the OutputSections are created, which is as early as it can possibly go. llvm-svn: 307225
* Simplify. NFC.Rafael Espindola2017-07-051-1/+1
| | | | llvm-svn: 307217
* Remove a function that is now trivial.Rafael Espindola2017-07-051-1/+0
| | | | llvm-svn: 307214
* Merge createOrphanCommands into addOrphanSections.Rafael Espindola2017-07-051-1/+0
| | | | | | This is a bit simpler and avoids a walk over OutputSections. llvm-svn: 307178
* [ELF] Extract allocateHeaders() from assignAddresses()Peter Smith2017-07-051-2/+2
| | | | | | | | | | | | | | | The allocateHeaders() function is called at the end of assignAddresses(), it decides whether the ELF header and program header table can be allocated to a PT_LOAD program header. As the function alters state, it prevents assignAddresses() from being called multiple times. This change splits out the call to allocateHeaders() from assignAddresses() this will permit assignAddresses() to be called while processing range extension thunks without trying to allocateHeaders(). Differential Revision: https://reviews.llvm.org/D34344 llvm-svn: 307131
* Move clearOutputSections before sortSections.Rafael Espindola2017-06-151-1/+1
| | | | | | | | | | | | | | | | | | This is probably the main patch left in unifying our intermediary representation. It moves the creation of default commands before section sorting. This has the nice effect that we now have one location where we decide where an orphan section should be placed. Before this patch sortSections would decide the relative location of orphan sections to other sections, but it was up to placeOrphanSection to decide on the exact location. We now only sort sections we created since the linker script is already in the correct order. llvm-svn: 305512
* Make OutputSections and OutputSectionCommands globals.Rafael Espindola2017-06-131-5/+2
| | | | | | | This is similar to what we do for InputSections and makes them easier to access. llvm-svn: 305337
* Move clearOutputSections before createPhdrs. NFC.Rafael Espindola2017-06-101-1/+2
| | | | llvm-svn: 305156
* [ELF] - Linkerscript: implement NOLOAD section type.George Rimar2017-06-071-0/+1
| | | | | | | | | | | | | | | This is PR32351 Each output section may have a type. The type is a keyword in parentheses. (https://sourceware.org/binutils/docs/ld/Output-Section-Type.html#Output-Section-Type) This patch support only one type, it is NOLOAD. If output section has such type, we force it to be SHT_NOBITS. More details are available on a review page. Differential revision: https://reviews.llvm.org/D33647 llvm-svn: 304925
* [ELF] Convert Thunks to use InputSectionDescriptionsPeter Smith2017-06-071-1/+0
| | | | | | | | | | | | | | | | Thunks are now generated per InputSectionDescription instead of per OutputSection. This allows created ThunkSections to be inserted directly into InputSectionDescription. Changes in this patch: - Loop over InputSectionDescriptions to find relocations to Thunks - Generate a ThunkSection per InputSectionDescription - Remove synchronize() as we no longer need it - Move fabricateDefaultCommands() before createThunks Differential Revision: https://reviews.llvm.org/D33835 llvm-svn: 304887
* [ELF] - Linkerscript: improved error reporting.George Rimar2017-06-071-7/+6
| | | | | | | | | | | | | | | | When linking linux kernel LLD currently reports next errors: ld: error: unable to evaluate expression: input section .head.text has no output section assigned ld: error: At least one side of the expression must be absolute ld: error: At least one side of the expression must be absolute That does not provide file/line information and overall looks unclear. Patch adds location information to ExprValue and that allows to provide more clear error messages. Differential revision: https://reviews.llvm.org/D33943 llvm-svn: 304881
* Move finalize to OutputSectionCommands. NFC.Rafael Espindola2017-06-061-0/+1
| | | | | | | This removes a mapping from OutputSection to OutputSectionCommand and is another step in moving clearOutputSections earlier. llvm-svn: 304821
* Move maybeCompress to OutputSectionCommand.Rafael Espindola2017-06-011-0/+1
| | | | | | | This removes a call to getCmd and allows us to move clearOutputSections earlier. llvm-svn: 304439
* Convert a few more uses of OutputSections. NFC.Rafael Espindola2017-06-011-1/+2
| | | | | | Also needed to move clearOutputSections earlier. llvm-svn: 304420
* Move name lookup to script parsing time.Rafael Espindola2017-06-011-3/+7
| | | | | | | | | | | We were looking up sections by name during expression evaluation. By keeping track of forward declarations we can do the lookup during script parsing. Doing the lookup earlier will be more efficient when assignAddresses is run twice and removes two uses of OutputSections. llvm-svn: 304381
* [ELF] Use late evaluation for ALIGN in expressionPetr Hosek2017-05-301-0/+5
| | | | | | | | | | | | | | | | | | While the following expression is handled fine: PROVIDE_HIDDEN(newsym = oldsym + address); The following expression triggers an error because the expression is evaluated as absolute: PROVIDE_HIDDEN(newsym = ALIGN(oldsym, CONSTANT(MAXPAGESIZE)) + address); To avoid this error, we use late evaluation for ALIGN by making the alignment an attribute of the expression itself. Differential Revision: https://reviews.llvm.org/D33629 llvm-svn: 304185
* Move writeTo to OutputSectionCommand.Rafael Espindola2017-05-241-3/+4
| | | | | | | | | | | | 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
* Use more strict types. NFC.Rafael Espindola2017-05-231-2/+2
| | | | | | | | | By the time we get to linker scripts, all special InputSectionBase should have been combined into synthetic sections, which are a type of InputSection. The net result is that we can use InputSection in a few places that were using InputSectionBase. llvm-svn: 303702
* Use a DenseMap in LinkerScript::getCmd.Rafael Espindola2017-05-101-1/+2
| | | | | | This improves many-sections.s with a linker script from 22s to 0.9s. llvm-svn: 302708
* Refactor OutputSection to OutputSectionCommand mapping.Rafael Espindola2017-05-101-0/+1
| | | | | | We now always use getCmd. I will optimize it in a followup commit. llvm-svn: 302706
* Mark LinkerScript as final.Rafael Espindola2017-05-101-2/+1
| | | | | | We used to inherit from it, but don't need it anymore. llvm-svn: 302675
* Remove another use of section names. NFC.Rafael Espindola2017-05-101-1/+1
| | | | llvm-svn: 302671
* Remove another use of section names. NFC.Rafael Espindola2017-05-101-1/+1
| | | | llvm-svn: 302662
* Don't use section names in getFiller. NFC.Rafael Espindola2017-05-101-1/+1
| | | | | | This is just faster and avoids using names. llvm-svn: 302661
* Delete LinkerScript::getSectionIndex.Rafael Espindola2017-05-051-2/+1
| | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | 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
* Fix accounting of tbss.Rafael Espindola2017-05-041-0/+1
| | | | | | | | | | | | | We were correctly computing the size contribution of a .tbss input section (it is none), but we were incorrectly considering the alignment of the output section: it was advancing Dot instead of ThreadBssOffset. As far as I can tell this was always wrong in our linkerscript implementation, but that became more visible now that the code is shared with the non linker script case. llvm-svn: 302107
* Bring back r301678.Rafael Espindola2017-04-291-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This version uses a set to speed up the synchronize method. Original message: Remove LinkerScript::flush. This patch replaces flush with a last ditch attempt at synchronizing the section list with the linker script "AST". The synchronization is a bit of a hack and should in time be avoided by creating the AST earlier so that modifications can be made directly to it instead of modifying the section list and synchronizing it back. This is the main step for fixing https://bugs.llvm.org/show_bug.cgi?id=32816. With this in place I think the only missing thing would be to have processCommands assign section indexes as dummy offsets so that the sort in OutputSection::finalize works. With this LinkerScript::assignAddresses becomes much simpler, which should help with the thunk work. llvm-svn: 301745
* Revert r301678: Remove LinkerScript::flush.Rui Ueyama2017-04-281-1/+4
| | | | | | | | This reverts commit r301678 since that change significantly slowed down the linker. Before this patch, LLD could link clang in 8 seconds, but with this patch it took 40 seconds. llvm-svn: 301709
* Remove LinkerScript::flush.Rafael Espindola2017-04-281-4/+1
| | | | | | | | | | | | | | | | | | | | This patch replaces flush with a last ditch attempt at synchronizing the section list with the linker script "AST". The synchronization is a bit of a hack and should in time be avoided by creating the AST earlier so that modifications can be made directly to it instead of modifying the section list and synchronizing it back. This is the main step for fixing https://bugs.llvm.org/show_bug.cgi?id=32816. With this in place I think the only missing thing would be to have processCommands assign section indexes as dummy offsets so that the sort in OutputSection::finalize works. With this LinkerScript::assignAddresses becomes much simpler, which should help with the thunk work. llvm-svn: 301678
* [ELF] Always use Script::assignAddresses()Peter Smith2017-04-191-0/+1
| | | | | | | | | | | | | | | | | | | This change fabricates linker script commands for the case where there is no linker script SECTIONS to control address assignment. This permits us to have a single Script->assignAddresses() function. There is a small change in user-visible-behavior with respect to the handling of .tbss SHT_NOBITS, SHF_TLS as the Script->assignAddresses() requires setDot() to be called with monotically increasing addresses. The tls-offset.s test has been updated so that the script and non-script results match. This change should make the non-script behavior of lld closer to an equivalent linker script. Differential Revision: https://reviews.llvm.org/D31888 llvm-svn: 300687
OpenPOWER on IntegriCloud