summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Writer.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* ELF: Don't add .dynamic strings to .dynstr early.Peter Collingbourne2019-03-121-1/+0
| | | | | | | | | | This does not appear to be necessary because StringTableSection does not need to be finalized, which also means that we can remove the call to finalizeSynthetic on .dynstr. Differential Revision: https://reviews.llvm.org/D59240 llvm-svn: 355977
* Fail early if an output file is not writableRui Ueyama2019-03-111-1/+1
| | | | | | | | Fixes https://bugs.llvm.org/show_bug.cgi?id=36478 Differential Revision: https://reviews.llvm.org/D43664 llvm-svn: 355834
* ELF: De-template OutputSection::finalize() and MipsGotSection::build(). NFCI.Peter Collingbourne2019-03-061-2/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D58810 llvm-svn: 355479
* ELF: Extract a non-ELFT base class for VersionNeedSection.Peter Collingbourne2019-03-061-7/+7
| | | | | | | | | | | We're going to need a separate VersionNeedSection for each partition, and the partition data structure won't be templated. With this the VersionTableSection class no longer needs ELFT, so detemplate it. Differential Revision: https://reviews.llvm.org/D58808 llvm-svn: 355478
* ELF: Change FileSize back to a uint64_t.Peter Collingbourne2019-03-011-3/+3
| | | | | | | | | This lets us detect file size overflows when creating a 64-bit binary on a 32-bit machine. Differential Revision: https://reviews.llvm.org/D58840 llvm-svn: 355218
* [ELF][ARM] Fix clang-armv7-linux-build-cache builds of LLD [NFC]Peter Smith2019-03-011-1/+1
| | | | | | | | r355153 introduced a build failure on a build bot that uses clang natively on an armv7-a machine. This a temporary fix to use size_t rather than uint64_t. llvm-svn: 355195
* ELF: Write .eh_frame_hdr explicitly after writing .eh_frame.Peter Collingbourne2019-02-281-32/+19
| | | | | | | | | | | This lets us remove the special case from Writer::writeSections(), and also fixes a bug where .eh_frame_hdr isn't necessarily written in the correct order if a linker script moves .eh_frame and .eh_frame_hdr into the same output section. Differential Revision: https://reviews.llvm.org/D58795 llvm-svn: 355153
* [mips] Put some MIPS-specific sections to separate segmentsSimon Atanasyan2019-02-201-12/+20
| | | | | | | | | | | | | | Three MIPS-specific sections `.reginfo`, `.MIPS.options`, and `.MIPS.abiflags` are used by loader to read their contents and setup environment for running a program. Loader looks up these data in the corresponding segments: `PT_MIPS_REGINFO`, `PT_MIPS_OPTIONS`, and `PT_MIPS_ABIFLAGS` respectively. This patch put these sections to separate segments like we do already for ARM `SHT_ARM_EXIDX` section. Differential Revision: http://reviews.llvm.org/D58381 llvm-svn: 354468
* ELF: Remove field for .gdb_index in InStruct. NFC.Fangrui Song2019-02-201-4/+2
| | | | | | | | | | | | | | | | Summary: This field is unreferenced outside of createSyntheticSections. Reviewers: ruiu, pcc, espindola, grimar Reviewed By: grimar Subscribers: grimar, emaste, arichardson, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58423 llvm-svn: 354449
* ELF: Remove field for .interp in InStruct. NFC.Peter Collingbourne2019-02-201-4/+2
| | | | | | | | This field is unreferenced outside of createSyntheticSections. Differential Revision: https://reviews.llvm.org/D58422 llvm-svn: 354428
* LLD/AMDGPU: Preserve ABI version during linking ELF for AMDGPUKonstantin Zhuravlyov2019-02-141-3/+15
| | | | | | Differential Revision: https://reviews.llvm.org/D58026 llvm-svn: 354086
* ELF: Allow GOT relocs pointing to non-preemptable ifunc to resolve to an ↵Peter Collingbourne2019-02-131-0/+2
| | | | | | | | | | | | | | | | IRELATIVE where possible. Non-GOT non-PLT relocations to non-preemptible ifuncs result in the creation of a canonical PLT, which now takes the identity of the IFUNC in the symbol table. This (a) ensures address consistency inside and outside the module, and (b) fixes a bug where some of these relocations end up pointing to the resolver. Fixes (at least) PR40474 and PR40501. Differential Revision: https://reviews.llvm.org/D57371 llvm-svn: 353981
* [PPC64] Sort .toc sections accessed with small code model relocs.Sean Fertile2019-02-121-2/+2
| | | | | | | | | | | | | A follow up to the intial patch that unblocked linking against libgcc. For lld we don't need to bother tracking which objects have got based small code model relocations. This is due to the fact that the compilers on powerpc64 use the .toc section to generate indirections to symbols (rather then using got relocations) which keeps the got small. This makes overflowing a small code model got relocation very unlikely. Differential Revision: https://reviews.llvm.org/D57245 llvm-svn: 353849
* [ELF] Support --{,no-}allow-shlib-undefinedFangrui Song2019-02-011-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In ld.bfd/gold, --no-allow-shlib-undefined is the default when linking an executable. This patch implements a check to error on undefined symbols in a shared object, if all of its DT_NEEDED entries are seen. Our approach resembles the one used in gold, achieves a good balance to be useful but not too smart (ld.bfd traces all DSOs and emulates the behavior of a dynamic linker to catch more cases). The error is issued based on the symbol table, different from undefined reference errors issued for relocations. It is most effective when there are DSOs that were not linked with -z defs (e.g. when static sanitizers runtime is used). gold has a comment that some system libraries on GNU/Linux may have spurious undefined references and thus system libraries should be excluded (https://sourceware.org/bugzilla/show_bug.cgi?id=6811). The story may have changed now but we make --allow-shlib-undefined the default for now. Its interaction with -shared can be discussed in the future. Reviewers: ruiu, grimar, pcc, espindola Reviewed By: ruiu Subscribers: joerg, emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D57385 llvm-svn: 352826
* [PPC64] Reland r351978 'Sort .toc sections accessed with small code model ...'Sean Fertile2019-01-241-0/+18
| | | | | | | | | | | | | | | | | | | | | | | Guessing that the slashes used in the scripts SECTION command was causing the windows related failures in the added test. Original commit message: Small code model global variable access on PPC64 has a very limited range of addressing. The instructions the relocations are used on add an offset in the range [-0x8000, 0x7FFC] to the toc pointer which points to .got +0x8000, giving an addressable range of [.got, .got + 0xFFFC]. While user code can be recompiled with medium and large code models when the binary grows too large for small code model, there are small code model relocations in the crt files and libgcc.a which are typically shipped with the distros, and the ABI dictates that linkers must allow linking of relocatable object files using different code models. To minimze the chance of relocation overflow, any file that contains a small code model relocation should have its .toc section placed closer to the .got then any .toc from a file without small code model relocations. Differential Revision: https://reviews.llvm.org/D56920 llvm-svn: 352071
* Revert "[PPC64] Sort .toc sections accessed with small code model ..."Sean Fertile2019-01-231-18/+0
| | | | | | | This reverts commit ca87c57a3aa4770c9cf0defd4b2feccbc342ee93. Added test fails on several windows buildbots. llvm-svn: 351985
* [PPC64] Sort .toc sections accessed with small code model relocs close to .got.Sean Fertile2019-01-231-0/+18
| | | | | | | | | | | | | | | | | | | Small code model global variable access on PPC64 has a very limited range of addressing. The instructions the relocations are used on add an offset in the range [-0x8000, 0x7FFC] to the toc pointer which points to .got +0x8000, giving an addressable range of [.got, .got + 0xFFFC]. While user code can be recompiled with medium and large code models when the binary grows too large for small code model, there are small code model relocations in the crt files and libgcc.a which are typically shipped with the distros, and the ABI dictates that linkers must allow linking of relocatable object files using different code models. To minimze the chance of relocation overflow, any file that contains a small code model relocation should have its .toc section placed closer to the .got then any .toc from a file without small code model relocations. Differential Revision: https://reviews.llvm.org/D56920 llvm-svn: 351978
* 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
* Do not emit a corrupt symbol table entry for .rela_iplt_{start,end}.Rui Ueyama2019-01-151-6/+16
| | | | | | | | | | | | | If .rela.iplt does not exist, we used to emit a corrupt symbol table that contains two symbols, .rela_iplt_{start,end}, pointing to a nonexisting section. This patch fixes the issue by setting section index 0 to the symbols if .rel.iplt section does not exist. Differential Revision: https://reviews.llvm.org/D56623 llvm-svn: 351218
* [ARM][AArch64] Increase TLS alignment to reserve space for Android's TCBRyan Prichard2019-01-091-4/+16
| | | | | | | | | | | | | | | | | | | | | | | | ARM and AArch64 use TLS variant 1, where the first two words after the thread pointer are reserved for the TCB, followed by the executable's TLS segment. Both the thread pointer and the TLS segment are aligned to at least the TLS segment's alignment. Android/Bionic historically has not supported ELF TLS, and it has allocated memory after the thread pointer for several Bionic TLS slots (currently 9 but soon only 8). At least one of these allocations (TLS_SLOT_STACK_GUARD == 5) is widespread throughout Android/AArch64 binaries and can't be changed. To reconcile this disagreement about TLS memory layout, set the minimum alignment for executable TLS segments to 8 words on ARM/AArch64, which reserves at least 8 words of memory after the TP (2 for the ABI-specified TCB and 6 for alignment padding). For simplicity, and because lld doesn't know when it's targeting Android, increase the alignment regardless of operating system. Differential Revision: https://reviews.llvm.org/D53906 llvm-svn: 350681
* [ELF] Place .note in the first page to ensure they are available in core filesFangrui Song2018-12-181-21/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Other large sections (e.g. .rela.dyn .dynstr) may push .note.* off the first page. They won't be available in core files if RLIMIT_CORE is limited. This patch gives priority to alloctable SHT_NOTE sections so that they are assuredly in the first page and will be available in core files. They are small and contain important information (e.g. .note.gnu.build-id identifies the origin of the core, .note.tag stores NT_FREEBSD_ABI_TAG). Note: gold Output_section_order has a similar rule: // Loadable read-only note sections come next so that the PT_NOTE // segment is on the first page of the executable. ORDER_RO_NOTE, Reviewers: ruiu, pcc, espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D55800 llvm-svn: 349524
* [LLD][ELF] - Support discarding the .dynamic section.George Rimar2018-12-101-4/+3
| | | | | | | | | | | This is a part of https://bugs.llvm.org/show_bug.cgi?id=39810. Seems it turns out that supporting /DISCARD/ for the .dynamic section with the linker script is something we can do easily. The patch does this. Differential revision: https://reviews.llvm.org/D55211 llvm-svn: 348749
* Show a proper error message if output file is too large.Rui Ueyama2018-12-031-1/+2
| | | | | | | | | At least on Linux, if a file size given to FileOutputBuffer is greater than 2^63, it fails with "Invalid argument" error, which is not a user-friendly error message. With this patch, lld prints out "output file too large" instead. llvm-svn: 348153
* [LLD][ELF] - Remove the excessive condition. NFC.George Rimar2018-12-031-1/+1
| | | | | | | | There is no need to check that In.DynSymTab != nullptr, because `includeInDynsym` already checks for `!Config->HasDynSymTab` and `HasDynSymTab` is the pre-condition for In.DynSymTab creation. llvm-svn: 348143
* [LLD][ELF] Error if _GLOBAL_OFFSET_TABLE_ is defined in input objectsPeter Smith2018-11-291-3/+14
| | | | | | | | | | | | | | | | | The _GLOBAL_OFFSET_TABLE_ is a linker defined symbol that is placed at some location relative to the .got, .got.plt or .toc section. On some targets such as Arm the correctness of some code sequences using a relocation to _GLOBAL_OFFSET_TABLE_ depend on the value of the symbol being in the linker defined place. Follow the ld.gold example and give a multiple symbol definition error. The ld.bfd behaviour is to ignore the definition in the input object and redefine it, which seems like it could be more surprising. fixes pr39587 Differential Revision: https://reviews.llvm.org/D54624 llvm-svn: 347854
* [ELF] - Make SymbolTable::addDefined return Defined.George Rimar2018-11-221-6/+5
| | | | | | | | | Now it returns Symbol. This should be NFC that avoids doing cast at the caller's sides. Differential revision: https://reviews.llvm.org/D54627 llvm-svn: 347455
* [PPC64] Long branch thunks.Sean Fertile2018-11-141-0/+6
| | | | | | | | | | | | | | | | | | On PowerPC64, when a function call offset is too large to encode in a call instruction the address is stored in a table in the data segment. A thunk is used to load the branch target address from the table relative to the TOC-pointer and indirectly branch to the callee. When linking position-dependent code the addresses are stored directly in the table, for position-independent code the table is allocated and filled in at load time by the dynamic linker. For position-independent code the branch targets could have gone in the .got.plt but using the .branch_lt section for both position dependent and position independent binaries keeps it consitent and helps keep this PPC64 specific logic seperated from the target-independent code handling the .got.plt. Differential Revision: https://reviews.llvm.org/D53408 llvm-svn: 346877
* Rename warnUnorderableSymbol maybeWarnUnorderableSymbol because the function ↵Rui Ueyama2018-10-261-1/+1
| | | | | | doesn't always emit a warning. llvm-svn: 345393
* Do not call computeIsPreemptible() if its result is discarded. NFC.Rui Ueyama2018-10-241-1/+3
| | | | llvm-svn: 345208
* Add more blank lines so that code doesn't look too dense. NFC.Rui Ueyama2018-10-241-13/+31
| | | | llvm-svn: 345205
* Add a comment for PPC64 .toc and GNU relro.Rui Ueyama2018-10-241-0/+5
| | | | llvm-svn: 345204
* Include input section name and output section name in an error message.Rui Ueyama2018-10-241-1/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D53645 llvm-svn: 345172
* Refactor assignFileOffsets. NFC.Rui Ueyama2018-10-241-30/+29
| | | | llvm-svn: 345154
* Split a function. NFC.Rui Ueyama2018-10-241-11/+17
| | | | llvm-svn: 345143
* Add parenthese around a bitand.Rui Ueyama2018-10-241-1/+1
| | | | llvm-svn: 345139
* Make a local variable scope narrower. NFC.Rui Ueyama2018-10-241-3/+3
| | | | llvm-svn: 345138
* [ELF] Remove a superfluous semicolon, fixing warnings. NFC.Martin Storsjo2018-10-241-1/+1
| | | | llvm-svn: 345116
* Factor out code to a new function. NFC.Rui Ueyama2018-10-231-27/+52
| | | | llvm-svn: 345088
* Simplify. NFC.Rui Ueyama2018-10-231-34/+29
| | | | | | A higher order function `applySyntehtic` can be replaced with a simpler function. llvm-svn: 345081
* Remove a global variable that is set but not used.Rui Ueyama2018-10-231-7/+3
| | | | llvm-svn: 345080
* Add a comment.Rui Ueyama2018-10-231-0/+4
| | | | llvm-svn: 345062
* Remove a global variable that we can live without.Rui Ueyama2018-10-231-1/+0
| | | | | | | | | | Out::DebugInfo was used only by GdbIndex class to determine if we need to create a .gdb_index section, but we can do the same check without it. Added a test that this patch doesn't change the existing behavior. llvm-svn: 345058
* Don't mess up RelIplt symbols during relocatable processingDimitry Andric2018-10-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: During upgrading of the FreeBSD source tree with lld 7.0.0, I noticed that it started complaining about `crt1.o` having an "index past the end of the symbol table". Such a symbol table looks approximately like this, viewed with `readelf -s` (note the `Ndx` field being messed up): ``` Symbol table '.symtab' contains 4 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 SECTION LOCAL DEFAULT 1 2: 00000000 0 NOTYPE WEAK HIDDEN RSV[0xffff] __rel_iplt_end 3: 00000000 0 NOTYPE WEAK HIDDEN RSV[0xffff] __rel_iplt_start ``` At first, it seemed that recent ifunc relocation work had caused this: <https://reviews.freebsd.org/rS339351>, but it turned out that it was due to incorrect processing of the object files by lld, when using `-r` (a.k.a. --relocatable). Bisecting showed that rL324421 ("Convert a use of Config->Static") was the commit where this new behavior began. Simply reverting it solved the issue, and the `__rel_iplt` symbols had an index of `UND` again. Looking at Rafael's commit message, I think he simply missed the possibility of `--relocatable` being in effect, so I have added an additional check for it. I also added a simple regression test case. Reviewers: grimar, ruiu, emaste, espindola Reviewed By: ruiu Subscribers: arichardson, krytarowski, llvm-commits Differential Revision: https://reviews.llvm.org/D53515 llvm-svn: 345002
* Add an addAbsolute static function to Writer.cppAlexander Richardson2018-10-201-8/+8
| | | | | | | | | | | | | | | | | Summary: SymbolTable::addAbsolute() was removed in rL344305. To me this is more readable than the lambda named `Add` and in our out-of-tree CHERI target we use addAbsolute() in another function. Reviewers: ruiu, espindola Reviewed By: ruiu Subscribers: kristina, emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D53393 llvm-svn: 344842
* Remove SymbolTable::addAbsolute().Rui Ueyama2018-10-111-5/+8
| | | | | | addAbsolute() could be implemented as a non-member function. llvm-svn: 344305
* Rename SymbolTable::addRegular -> SymbolTable::addDefined.Rui Ueyama2018-10-111-2/+2
| | | | | | | We have addAbsolute, addBitcode, addCommon, etc. addRegular looked a bit inconsistent. llvm-svn: 344294
* [ELF] llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song2018-09-261-9/+7
| | | | | | | | | | | | Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: ruiu, espindola Subscribers: emaste, arichardson, mgrang, llvm-commits Differential Revision: https://reviews.llvm.org/D52569 llvm-svn: 343146
* De-template VersionDefinitionSection. NFC.Rui Ueyama2018-09-251-3/+3
| | | | | | | | When we write a struct to a mmap'ed buffer, we usually use write16/32/64, but we didn't for VersionDefinitionSection, so we needed to template that class. llvm-svn: 343024
* Reset input section pointers to null on each linker invocation.Rui Ueyama2018-09-251-122/+137
| | | | | | | | | | Previously, if you invoke lld's `main` more than once in the same process, the second invocation could fail or produce a wrong result due to a stale pointer values of the previous run. Differential Revision: https://reviews.llvm.org/D52506 llvm-svn: 343009
* Make a member function non-member. NFC.Rui Ueyama2018-09-201-2/+1
| | | | | | | | Non-member functions are generally preferred over member functions because it is clear that non-member functions don't depend on an internal state of an object. llvm-svn: 342695
OpenPOWER on IntegriCloud