summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Writer.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Add CopyRelSection instances to BSS in the regular way.Rui Ueyama2017-02-161-5/+9
| | | | | | | | | | | | | | Previously, space in a BSS section for copy relocations are reserved in a special way. We directly manipulated size of the BSS section. r294577 changed the way of doing it. Now, we create an instance of CopyRelSection (which is a synthetic input section) for each copy relocation. This patch removes the remains of the old way and add CopyRelSections to BSS sections using `addSections` function, which is the usual way to add an input section to an output section. llvm-svn: 295278
* Make --export-dynamic work on non-PIC/PIE targets.Ed Schouten2017-02-151-1/+2
| | | | | | | | | | | | | | | | | | | For CloudABI I'm only interested in generating non-PIC/PIE executables on armv6 and i686, as PIE introduces larger overhead than on aarch64 and x86_64. Still, I want to be able to instruct the linker to generate a dynamic symbol table if requested. One example use for this is that dynamic symbol tables can be used by programs to print nicely formatted stacktraces, including symbol names. Right now there seems to be some logic in LLD that it only wants to emit dynamic symbol tables when either linking against libraries or when building PIC. Let's extend this to also take --export-dynamic into account. Reviewed by: ruiu Differential Revision: https://reviews.llvm.org/D29982 llvm-svn: 295240
* Explicitly return a new value instead of implicitly mutating a reference.Rui Ueyama2017-02-141-7/+7
| | | | | | I think this is more readable than before. llvm-svn: 295121
* Do not store a computable attributes to Config.Rui Ueyama2017-02-141-2/+3
| | | | llvm-svn: 295031
* Create only one section symbol per section.Rafael Espindola2017-02-111-6/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Unfortunately some consumers of our .o files produced with -r expect only one section symbol per section. That is true of at least of go's own linker. Combining them is a somewhat convoluted process. We have to create a symbol for every section since we don't know which ones will be needed. The relocation sections also have to be written first to handle the Elf_Rel addend. I did consider a completely different approach: We could remove the -r special case of relocation sections when reading. We would instead have a copyRelocs function that is used instead of scanRelocs. It would create a DynamicReloc for each relocation and a RelocationSection for each input relocation section. A complication of such change is that DynamicReloc would have to take a section index and a input section instead of a symbol since with -emit-relocs some DynamicReloc would hold relocations referring to the dynamic symbol table and other to the static symbol table. That would be a pretty big change, and if we do it it is probably better to do it as a refactoring. llvm-svn: 294816
* [ELF] Refactor PltSection and IPltSection into PltSection [NFC]Peter Smith2017-02-091-2/+2
| | | | | | | | | | | | Much of the code in PltSection and IPltSection is similar, we identify the IPlt by a HeaderSize of 0 and alter our behaviour in the member functions appropriately: -Iplt does not have a header -Iplt always follows after the Plt Differential Revision: https://reviews.llvm.org/D29664 llvm-svn: 294579
* Recommit r294464 "[ELF] - Added partial support for --emit-relocs (no ↵George Rimar2017-02-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | --gc-section case, no /DISCARD/ support) #3" with temporarily file name fix in testcase. Original commit message: -q, --emit-relocs - Generate relocations in output Simplest implementation: * no GC case, * no "/DISCARD/" linkerscript command support. This patch is extracted from D28612 / D29636, Relative to PR31579. Differential revision: https://reviews.llvm.org/D29663 llvm-svn: 294469
* Reverted r294464 "[ELF] - Added partial support for --emit-relocs (no ↵George Rimar2017-02-081-2/+2
| | | | | | | | | --gc-section case, no /DISCARD/ support) #3" Broked build bot: http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/5835/steps/test/logs/stdio llvm-svn: 294466
* [ELF] - Added partial support for --emit-relocs (no --gc-section case, no ↵George Rimar2017-02-081-2/+2
| | | | | | | | | | | | | | | | | | /DISCARD/ support) #3 -q, --emit-relocs - Generate relocations in output Simplest implementation: * no GC case, * no "/DISCARD/" linkerscript command support. This patch is extracted from D28612 / D29636, Relative to PR31579. Differential revision: https://reviews.llvm.org/D29663 llvm-svn: 294464
* Use a utility function to reduce repetition. NFC.Rui Ueyama2017-02-051-30/+34
| | | | llvm-svn: 294117
* Replace MergeOutputSection with a synthetic section.Rafael Espindola2017-02-031-2/+52
| | | | | | | | | | | | | | With a synthetic merge section we can have, for example, a single .rodata section with stings, fixed sized constants and non merge constants. I can be simplified further by not setting Entsize, but that is probably better done is a followup patch. This should allow some cleanup in the linker script code now that every output section command maps to just one output section. llvm-svn: 294005
* Make `-z stack-size` compatible with ld.bfd.Rui Ueyama2017-02-021-5/+2
| | | | | | | ld.bfd doesn't handle `-z stack-size=0` as a special case. We shouldn't do that too. llvm-svn: 293849
* Simplify createPhdrs. NFC.Rui Ueyama2017-02-011-36/+22
| | | | | | | | Instead of creating multiple PHDRs in a single loop, this patch runs one for loop for each PHDR type. I think this improves code readability. llvm-svn: 293832
* [ELF] Handle multiple discontiguous .note sectionsPetr Hosek2017-02-011-5/+11
| | | | | | | | | | | | | | There could be multiple discontiguous output .note sections in which case we need to put these into separate PT_NOTE segments rather then placing them into a single segment. Where possible, we could reorder the input sections to make sure that all .note are layed out next to each other to avoid creation multiple PT_NOTE segments, but even in that case, it's still possible to construct a discontiguous case e.g. by using a linker script. Differential Revision: https://reviews.llvm.org/D29364 llvm-svn: 293811
* [ELF] Use SyntheticSections for ThunksPeter Smith2017-02-011-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | Thunks are now implemented by redirecting the relocation to the symbol S, to a symbol TS in a Thunk. The Thunk will transfer control to S. This has the following implications: - All the side-effects of Thunks happen within createThunks() - Thunks are no longer stored in InputSections and Symbols no longer need to hold a pointer to a Thunk - The synthetic Thunk sections need to be merged into OutputSections This implementation is almost a direct conversion of the existing Thunks with the following exceptions: - Mips LA25 Thunks are placed before the InputSection that defines the symbol that needs a Thunk. - All ARM Thunks are placed at the end of the OutputSection of the first caller to the Thunk. Range extension Thunks are not supported yet so it is optimistically assumed that all Thunks can be reused. This is a recommit of r293283 with a fixed comparison predicate as std::merge requires a strict weak ordering. Differential revision: https://reviews.llvm.org/D29327 llvm-svn: 293757
* ELF: Align RELRO to the target page size rather than the max page size.Peter Collingbourne2017-01-301-1/+1
| | | | | | | | | | | If no bss sections appear after the relro segment, the loader will round the r/w segment size to the target's page size. Align the relro size in the same way to ensure that it does not extend past the end of the program's own memory region. Differential Revision: https://reviews.llvm.org/D29242 llvm-svn: 293519
* Fix -Werror build.Rafael Espindola2017-01-281-2/+2
| | | | llvm-svn: 293390
* Fix a few symbols that are not actually ABS.Rafael Espindola2017-01-281-27/+46
| | | | | | | | | | | The symbols _end, end, _etext, etext, _edata, edata and __ehdr_start refer to positions in the file and are therefore not absolute. Making them absolute was on unfortunate cargo cult of what bfd was doing. Changing the symbols allows for pc relocations to them to be resolved, which should fix the wine build. llvm-svn: 293385
* Revert "[ELF][ARM] Use SyntheticSections for Thunks"Rui Ueyama2017-01-281-6/+6
| | | | | | This reverts commit r293283 because it broke MSVC build. llvm-svn: 293352
* Revert commits r293276 and r293278.Rafael Espindola2017-01-271-1/+1
| | | | | | | | | | | | | | [ELF] Fixed formatting. NFC and [ELF] Bypass section type check Differential revision: https://reviews.llvm.org/D28761 They do the opposite of what was asked for in the code review. llvm-svn: 293320
* [ELF][ARM] Use SyntheticSections for ThunksPeter Smith2017-01-271-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | Thunks are now implemented by redirecting the relocation to the symbol S, to a symbol TS in a Thunk. The Thunk will transfer control to S. This has the following implications: - All the side-effects of Thunks happen within createThunks() - Thunks are no longer stored in InputSections and Symbols no longer need to hold a pointer to a Thunk - The synthetic Thunk sections need to be merged into OutputSections This implementation is almost a direct conversion of the existing Thunks with the following exceptions: - Mips LA25 Thunks are placed before the InputSection that defines the symbol that needs a Thunk. - All ARM Thunks are placed at the end of the OutputSection of the first caller to the Thunk. Range extension Thunks are not supported yet so it is optimistically assumed that all Thunks can be reused. Differential Revision: https://reviews.llvm.org/D29129 llvm-svn: 293283
* [ELF] Bypass section type checkEugene Leviant2017-01-271-1/+1
| | | | | | Differential revision: https://reviews.llvm.org/D28761 llvm-svn: 293276
* Change the --retain-symbols-file implementation.Rafael Espindola2017-01-251-6/+0
| | | | | | | | | | | | | | | | It now uses the same infrastructure as symbol versions. This fixes us creating a dynamic relocation without a corresponding dynamic symbol. This also means that unlike gold and bfd we keep a STB_LOCAL in the static symbol table. It seems an odd feature to offer precise control over what is in a symbol table that is not used by the dynamic linker. We can bring this back if needed, but it would probably be better to just have --discard option that tells the linker to keep in the static symbol table only what is in the dynamic one. Should fix the eog build. llvm-svn: 293093
* [ELF] Add local mapping symbols to ARM PLT entriesPeter Smith2017-01-251-0/+5
| | | | | | | | | | | | | Mapping symbols allow a mapping symbol aware disassembler to correctly disassemble the PLT when the code immediately prior to the PLT is Thumb. To implement this we add a function to add symbols with local binding to be defined in SyntheticSymbols. Differential Revision: https://reviews.llvm.org/D28956 llvm-svn: 293044
* [ELF] - Stop handling local symbols in a special way.George Rimar2017-01-231-7/+3
| | | | | | | | | | | | | | | | | | | | Previously we stored kept locals in a KeptLocalSyms arrays, belonged to files. Patch makes SymbolTableSection to store locals in Symbols member, that already present and was used for globals. SymbolTableSection already had NumLocals counter member, so change itself is trivial. That allows to simplify handling of -r, Body::DynsymIndex is no more used as "symbol table index" for relocatable output. Change was suggested during review of D28773 and opens road for D28612. Differential revision: https://reviews.llvm.org/D29021 llvm-svn: 292789
* Don't create a bogus PT_PHDR if we don't allocate the headers.Rafael Espindola2017-01-201-6/+12
| | | | llvm-svn: 292644
* Reduce code duplication when allocating program headers.Rafael Espindola2017-01-201-27/+35
| | | | | | This will simplify a bug fix. llvm-svn: 292642
* Simplify. NFC.Rafael Espindola2017-01-201-6/+1
| | | | | | | addIgnored already creates the symbol only if there is a reference to it. llvm-svn: 292628
* Also define 'end' if it is present in a .so.Rafael Espindola2017-01-191-1/+1
| | | | | | I don't know of anything using it, but we should handle it like _end. llvm-svn: 292513
* [ELF] Move createThunks() after scanRelocations()Peter Smith2017-01-181-6/+6
| | | | | | | | | | | | | | | | | | | | A necessary first step towards range extension thunks is to delay the creation of thunks until the layout of InputSections within OutputSections has been done. The change scans the relocations directly from InputSections rather than looking in the ELF File the InputSection came from. This will allow a future change to redirect the relocations to symbols defined by Thunks rather than indirect when resolving relocations. A side-effect of moving ThunkCreation is that the OutSecOff of InputSections may change in an OutputSection that contains Thunks. In well behaved programs thunks are not in OutputSections with dynamic relocations. Differential Revision: https://reviews.llvm.org/D28811 llvm-svn: 292359
* Return early if writeMapFile failed.Rui Ueyama2017-01-181-0/+4
| | | | | | | | This patch adds a test for an invalid output path for -Map option, though that test is not for verifying that we are using error() instead of fatal() in writeMapFile. llvm-svn: 292336
* Add a isInCurrentDSO helper. NFC.Rafael Espindola2017-01-171-2/+2
| | | | llvm-svn: 292228
* [ELF] - Do not create huge garbage files on section offset overflow.George Rimar2017-01-171-0/+3
| | | | | | | | | | | | Patch changes behavior to not try open the output file if we already know about error. That is not just cleaner, but also fixes nasty behavior of linker that could create huge temporarily files under certain conditions. Differential revision: https://reviews.llvm.org/D28107 llvm-svn: 292219
* [ELF][MIPS] Exclude mips .got from PT_GNU_RELRO segmentSimon Atanasyan2017-01-161-2/+12
| | | | | | | | | | | | | On MIPS .got section cannot be included into the PT_GNU_RELRO segment. Sometimes it might work, but in general it is unsupported. One of the problem is that all sections marked by SHF_MIPS_GPREL should be grouped together because data in these sections is addressable with a gp relative address, but such sections might be writable. This patch exclude mips .got from PT_GNU_RELRO segment and group SHF_MIPS_GPREL sections. llvm-svn: 292161
* Implement -Map.Rafael Espindola2017-01-131-0/+2
| | | | | | | The format is not exactly the same as the one in bfd since bfd always follows a linker script and prints it along. llvm-svn: 291958
* [ELF] - Move the addition of synthetics from addPredefinedSections()George Rimar2017-01-131-4/+8
| | | | | | | | | | | These were 3 last synthetics that were added in addPredefinedSections() instead of createSyntheticSections(). Now it is possible to move addition to correct common place. Also patch fixes testcase which discards .shstrtab, by restricting doing that. Differential revision: https://reviews.llvm.org/D28561 llvm-svn: 291908
* Remove error(error_code, const Twine &).Rui Ueyama2017-01-121-2/+2
| | | | | | Now we have the consistent interface for all log/warn/error/fatal functions. llvm-svn: 291847
* ELF: Reserve space for copy relocations of read-only symbols in relro.Peter Collingbourne2017-01-101-0/+6
| | | | | | | | | | | | | | When reserving copy relocation space for a shared symbol, scan the DSO's program headers to see if the symbol is in a read-only segment. If so, reserve space for that symbol in a new synthetic section named .bss.rel.ro which will be covered by the relro program header. This fixes the security issue disclosed on the binutils mailing list at: https://sourceware.org/ml/libc-alpha/2016-12/msg00914.html Differential Revision: https://reviews.llvm.org/D28272 llvm-svn: 291524
* ELF: Place relro sections after non-relro sections in r/w segment.Peter Collingbourne2017-01-101-18/+29
| | | | | | | | | | | | This is in preparation for my next change, which will introduce a relro nobits section. That requires that relro sections appear at the end of the progbits part of the r/w segment so that the relro nobits section can appear contiguously. Because of the amount of churn required in the test suite, I'm making this change separately. llvm-svn: 291523
* Support non-regular output files.Rui Ueyama2017-01-091-4/+6
| | | | | | | | | This patch enables something like "-o /dev/null". Previouly, it failed because such files cannot be renamed. Differential Revision: https://reviews.llvm.org/D28010 llvm-svn: 291496
* ELF: Round p_memsz of the PT_GNU_RELRO program header up to the page size.Peter Collingbourne2017-01-041-1/+6
| | | | | | | | | The glibc dynamic loader rounds the size down, so without this the loader will fail to change the memory protection for the last page. Differential Revision: https://reviews.llvm.org/D28267 llvm-svn: 290986
* ELF: Simplify; addOptionalSynthetic() does not need to return a value. NFC.Peter Collingbourne2017-01-041-9/+6
| | | | llvm-svn: 290932
* [ELF] - Fix mistype in comment. NFC.George Rimar2016-12-251-1/+1
| | | | llvm-svn: 290510
* De-template DefinedSynthetic.Rui Ueyama2016-12-211-4/+3
| | | | | | | | DefinedSynthetic is not created for a real ELF object, so it doesn't have to be a template function. It has a virtual st_value, which is either 32 bit or 64 bit, but we can simply use 64 bit. llvm-svn: 290241
* Move a function defintion to make it static.Rui Ueyama2016-12-211-28/+0
| | | | llvm-svn: 290215
* [ELF] - Treat .openbsd.randomdata as relro sectionGeorge Rimar2016-12-201-1/+1
| | | | | | | | | | | | | | | That was requested by Mark Kettenis in llvm-dev: "It is the intention that .openbsd.randomdata sections are made read-only after initialization. The native (ld.bfd based) OpenBSD toolchain accomplishes this by including .openbsd.randomdata into the PT_GNU_RELRO segment." He suggested code change, I added testcase. Differential revision: https://reviews.llvm.org/D27974 llvm-svn: 290174
* Simplify type of Config->SymbolOrderingFile.Rui Ueyama2016-12-201-15/+16
| | | | | | | | | | | That variable was of type DenseMap<StringRef, unsigned>, but the unsigned numbers needed to be monotonicly increasing numbers because the implementation that used the variable depended on that fact. That was an implementation detail and shouldn't have leaked into Config. This patch simplifies its type to std::vector<StringRef>. llvm-svn: 290151
* Fix corner cases of setting the section address.Rafael Espindola2016-12-191-15/+71
| | | | | | | | | | | | | | | | This handles all the corner cases if setting a section address: - If the address is too low, we cannot allocate the program headers. - If the load address is lowered, we have to do that before finalize This also shares some code with the linker script since it was already hitting similar cases. This is used by the freebsd boot loader. It is not clear if we need to support this with a non binary output, but it is not as bad as I was expecting. llvm-svn: 290136
* [ELF] - Implemented --retain-symbols-file optionGeorge Rimar2016-12-191-0/+6
| | | | | | | | | | | | | | | | --retain-symbols-file=filename Retain only the symbols listed in the file filename, discarding all others. filename is simply a flat file, with one symbol name per line. This option is especially useful in environments (such as VxWorks) where a large global symbol table is accumulated gradually, to conserve run-time memory. Note: though documentation says "--retain-symbols-file does not discard undefined symbols, or symbols needed for relocations.", both bfd and gold do that, and this patch too, like testcase show. Differential revision: https://reviews.llvm.org/D27716 llvm-svn: 290122
* Detemplate PhdrEntry. NFC.Rafael Espindola2016-12-191-63/+63
| | | | llvm-svn: 290115
OpenPOWER on IntegriCloud