summaryrefslogtreecommitdiffstats
path: root/lld/ELF
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF][ARM] Accept and ignore -p and -no-pipleline-knowledgePeter Smith2019-02-251-0/+2
| | | | | | | | | | | | The linux kernel uses an old flag -p/-no-pipeline-knowledge that is accepted by bfd and gold but ignored by modern versions of them. The original option is very old and is pre-ABI, it sometimes comes up in code-bases that had support for pre ABI toolchains. The Linux kernel uses it in 3 places in the ARM specific section. Differential Revision: https://reviews.llvm.org/D58540 llvm-svn: 354769
* Remove a function from header and move the implementation to a .cpp file. NFC.Rui Ueyama2019-02-221-0/+6
| | | | llvm-svn: 354703
* ELF: Remove dead code. NFCI.Peter Collingbourne2019-02-211-3/+2
| | | | | | | | | RelocationBaseSection is not used in -r links, so Config->Relocatable will always be false. Differential Revision: https://reviews.llvm.org/D58489 llvm-svn: 354607
* [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-202-5/+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-202-5/+2
| | | | | | | | This field is unreferenced outside of createSyntheticSections. Differential Revision: https://reviews.llvm.org/D58422 llvm-svn: 354428
* ELF: Fix typo in --build-id option descriptionTom Stellard2019-02-201-1/+1
| | | | | | | | | | | | | | Reviewers: ruiu, espindola Reviewed By: ruiu Subscribers: emaste, arichardson, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58265 llvm-svn: 354422
* Sort enum members so that arch-dependent members are at the right place. NFC.Rui Ueyama2019-02-201-2/+2
| | | | llvm-svn: 354405
* [mips] Create LA25 thunks for MIPS R6 codeSimon Atanasyan2019-02-191-2/+2
| | | | | | | | MIPS R6 code uses the `R_MIPS_PC26_S2` relocation for calls which might cross boundaries of non-PIC-to-PIC code. We need to create a LA25 thunks for that case. llvm-svn: 354312
* [MIPS] Handle cross-mode (regular <-> microMIPS) jumpsSimon Atanasyan2019-02-193-11/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The patch solves two tasks: 1. MIPS ABI allows to mix regular and microMIPS code and perform cross-mode jumps. Linker needs to detect such cases and replace jump/branch instructions by their cross-mode equivalents. 2. Other tools like dunamic linkers need to recognize cases when dynamic table entries, e_entry field of an ELF header etc point to microMIPS symbol. Linker should provide such information. The first task is implemented in the `MIPS<ELFT>::relocateOne()` method. New routine `fixupCrossModeJump` detects ISA mode change, checks and replaces an instruction. The main problem is how to recognize that relocation target is microMIPS symbol. For absolute and section symbols compiler or assembler set the less-significant bit of the symbol's value or sum of the symbol's value and addend. And this bit signals to linker about microMIPS code. For global symbols compiler cannot do the same trick because other tools like, for example, disassembler wants to know an actual position of the symbol. So compiler sets STO_MIPS_MICROMIPS flag in the `st_other` field. In `MIPS<ELFT>::relocateOne()` method we have a symbol's value only and cannot access any symbol's attributes. To pass type of the symbol (regular/microMIPS) to that routine as well as other places where we write a symbol value as-is (.dynamic section, `Elf_Ehdr::e_entry` field etc) we set when necessary a less-significant bit in the `getSymVA` function. Differential revision: https://reviews.llvm.org/D40147 llvm-svn: 354311
* [PPC64] Preserve LocalEntry when linkingRui Ueyama2019-02-151-0/+5
| | | | | | | | | | | | | On PowerPC64, it is necessary to keep the LocalEntry bits in st_other, especially when -r is used. Otherwise, when the resulting object is used in a posterior linking, LocalEntry info will be unavailable and functions may be called through the wrong entrypoint. Patch by Leandro Lupori. Differential Revision: https://reviews.llvm.org/D56782 llvm-svn: 354184
* LLD/AMDGPU: Preserve ABI version during linking ELF for AMDGPUKonstantin Zhuravlyov2019-02-143-3/+17
| | | | | | Differential Revision: https://reviews.llvm.org/D58026 llvm-svn: 354086
* Revert "Revert "[lld] Fix elf::unlinkAsync detached thread""Nick Desaulniers2019-02-141-2/+19
| | | | | | This reverts commit 9934f2ff02dba9fdabe6e27a83f9f95388bf4132. llvm-svn: 354081
* Revert "[lld] Fix elf::unlinkAsync detached thread"Nick Desaulniers2019-02-141-19/+2
| | | | | | This reverts commit 2694810153cf992823eb45253d26b8567424438f. llvm-svn: 354080
* [lld] Fix elf::unlinkAsync detached threadVitaly Buka2019-02-141-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: So this patch just make sure that the thread is at least stated before we return from main. If we just detach then the thread may be actually be stated just after the process returned from main and it's calling atexit handers. Then the thread may try to create own function static variable and it will add new at exit handlers confusing libc. GLIBC before 2.27 had race in that case which corrupted atexit handlers list. Support for this use-case for other implementation is also unclear, so we can try just avoid that. PR40162 Reviewers: ruiu, espindola Subscribers: emaste, arichardson, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58246 llvm-svn: 354078
* Move a function from .h to .cpp and use a shorter name. NFC.Rui Ueyama2019-02-142-55/+55
| | | | llvm-svn: 354054
* Remove a comparator from header and instead use lambdas for simplicity. NFC.Rui Ueyama2019-02-143-20/+13
| | | | llvm-svn: 354052
* Add a comment. NFC.Rui Ueyama2019-02-141-16/+22
| | | | llvm-svn: 354049
* Improve error message for unknown relocations.Rui Ueyama2019-02-147-13/+20
| | | | | | | | | | | | Previously, we showed the following message for an unknown relocation: foo.o: unrecognized reloc 256 This patch improves it so that the error message includes a symbol name: foo.o: unknown relocation (256) against symbol bar llvm-svn: 354040
* ELF: Allow GOT relocs pointing to non-preemptable ifunc to resolve to an ↵Peter Collingbourne2019-02-137-92/+199
| | | | | | | | | | | | | | | | 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
* Recover elf32-bigmips and elf32-powerpc support in LLDRui Ueyama2019-02-132-2/+3
| | | | | | | | | | | | | This fixes a 7.0 -> 8.0 regression when parsing OUTPUT_FORMAT("elf32-powerpc"); or elf32-bigmips directive in ldscripts as well as an unknown emulation error when lld is invoked by clang due to missed elf32ppclinux case. Patch by vit9696 Differential Revision: https://reviews.llvm.org/D58005 llvm-svn: 353968
* Show "Unknown -z option" error message even if --version or --help are given.Rui Ueyama2019-02-131-1/+1
| | | | | | | | | | Previously, we validated -z options after we process --version or --help flags. So, if one of these flags is given, we wouldn't show an "unknown -z option" error. This patch fixes that behavior. Differential Revision: https://reviews.llvm.org/D55446 llvm-svn: 353967
* [PPC64] Sort .toc sections accessed with small code model relocs.Sean Fertile2019-02-125-20/+27
| | | | | | | | | | | | | 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
* lld: unquote possibly quoted `EXTERN("symbol")` entry in linker script.Rui Ueyama2019-02-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | gold accepts quoted strings. binutils requires quoted strings for some kinds of symbols, e.g.: it accepts quoted symbols with @ in name: $ echo 'EXTERN("__libc_start_main@@GLIBC_2.2.5")' > a.script $ g++ a.script /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: error: ld returned 1 exit status but rejects them if unquoted: $ echo 'EXTERN(__libc_start_main@@GLIBC_2.2.5)' > a.script $ g++ a.script a.script: file not recognized: File format not recognized collect2: error: ld returned 1 exit status To maintain compatibility with existing linker scripts support quoted strings in lld as well. Patch by Lucian Adrian Grijincu. Differential Revision: https://reviews.llvm.org/D57987 llvm-svn: 353756
* [ELF] Delete a comment that is no longer correct. Fix a typo. NFCFangrui Song2019-02-091-1/+1
| | | | llvm-svn: 353605
* Fix a bug in R_X86_64_PC{8,16} relocation handling.Rui Ueyama2019-02-071-2/+8
| | | | | | | | R_X86_64_PC{8,16} relocations are sign-extended, so when we check for relocation overflow, we had to use checkInt instead of checkUInt. I confirmed that GNU linkers create the same output for the test case. llvm-svn: 353437
* [LLD][ELF] - Set DF_STATIC_TLS flag for X64 targetGeorge Rimar2019-02-071-0/+3
| | | | | | | | | | | | This is the same as D57749, but for x64 target. "ELF Handling For Thread-Local Storage" p41 says (https://www.akkadia.org/drepper/tls.pdf): R_X86_64_GOTTPOFF relocation is used for IE TLS models. Hence if linker sees this relocation we should add DF_STATIC_TLS flag. Differential revision: https://reviews.llvm.org/D57821 llvm-svn: 353378
* Correct "varaible" typo in commentEd Maste2019-02-061-1/+1
| | | | llvm-svn: 353340
* Remove a small header that is used only by one file. NFC.Rui Ueyama2019-02-062-35/+11
| | | | llvm-svn: 353331
* Add comment.Rui Ueyama2019-02-061-1/+14
| | | | llvm-svn: 353323
* Support R_X86_64_PC8 and R_X86_64_PC16.Rui Ueyama2019-02-061-0/+4
| | | | | | | | They are defined by the x86-64 ELF ABI standard. Differential Revision: https://reviews.llvm.org/D57799 llvm-svn: 353314
* Recommit r353293 "[LLD][ELF] - Set DF_STATIC_TLS flag for i386 target."George Rimar2019-02-063-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With the following changes: 1) Compilation fix: std::atomic<bool> HasStaticTlsModel = false; -> std::atomic<bool> HasStaticTlsModel{false}; 2) Adjusted the comment in code. Initial commit message: DF_STATIC_TLS flag indicates that the shared object or executable contains code using a static thread-local storage scheme. Patch checks if IE/LE relocations were used to check if the code uses a static model. If so it sets the DF_STATIC_TLS flag. Differential revision: https://reviews.llvm.org/D57749 ---- Modified : /lld/trunk/ELF/Arch/X86.cpp Modified : /lld/trunk/ELF/Config.h Modified : /lld/trunk/ELF/SyntheticSections.cpp Added : /lld/trunk/test/ELF/Inputs/i386-static-tls-model1.s Added : /lld/trunk/test/ELF/Inputs/i386-static-tls-model2.s Added : /lld/trunk/test/ELF/Inputs/i386-static-tls-model3.s Added : /lld/trunk/test/ELF/Inputs/i386-static-tls-model4.s Added : /lld/trunk/test/ELF/i386-static-tls-model.s Modified : /lld/trunk/test/ELF/i386-tls-ie-shared.s Modified : /lld/trunk/test/ELF/tls-dynamic-i686.s Modified : /lld/trunk/test/ELF/tls-opt-iele-i686-nopic.s llvm-svn: 353299
* Revert r353293 "[LLD][ELF] - Set DF_STATIC_TLS flag for i386 target."George Rimar2019-02-063-13/+0
| | | | | | | | | | | | It broke BB: http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/43450 http://lab.llvm.org:8011/builders/lld-x86_64-freebsd/builds/27891 Error is: tools/lld/ELF/Config.h:84:41: error: copying member subobject of type 'std::atomic<bool>' invokes deleted constructor std::atomic<bool> HasStaticTlsModel = false; llvm-svn: 353297
* [LLD][ELF] - Set DF_STATIC_TLS flag for i386 target.George Rimar2019-02-063-0/+13
| | | | | | | | | | | | DF_STATIC_TLS flag indicates that the shared object or executable contains code using a static thread-local storage scheme. Patch checks if IE/LE relocations were used to check if the code uses a static model. If so it sets the DF_STATIC_TLS flag. Differential revision: https://reviews.llvm.org/D57749 llvm-svn: 353293
* [PPC64] Set the number of relocations processed for R_PPC64_TLS[GL]D to 2Fangrui Song2019-02-065-5/+29
| | | | | | | | | | | | | | | | | | | | | | Summary: R_PPC64_TLSGD and R_PPC64_TLSLD are used as markers on TLS code sequences. After GD-to-IE or GD-to-LE relaxation, the next relocation R_PPC64_REL24 should be skipped to not create a false dependency on __tls_get_addr. When linking statically, the false dependency may cause an "undefined symbol: __tls_get_addr" error. R_PPC64_GOT_TLSGD16_HA R_PPC64_GOT_TLSGD16_LO R_PPC64_TLSGD R_TLSDESC_CALL R_PPC64_REL24 __tls_get_addr Reviewers: ruiu, sfertile, syzaara, espindola Reviewed By: sfertile Subscribers: emaste, nemanjai, arichardson, kbarton, jsji, llvm-commits, tamur Tags: #llvm Differential Revision: https://reviews.llvm.org/D57673 llvm-svn: 353262
* Inline a trivial function and update comment. NFC.Rui Ueyama2019-02-051-9/+7
| | | | llvm-svn: 353200
* [ELF] Default to --no-allow-shlib-undefined for executablesFangrui Song2019-02-022-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This follows the ld.bfd/gold behavior. The error check is useful as it captures a common type of ld.so undefined symbol errors as link-time errors: // a.cc => a.so (not linked with -z defs) void f(); // f is undefined void g() { f(); } // b.cc => executable with a DT_NEEDED entry on a.so void g(); int main() { g(); } // ld.so errors when g() is executed (lazy binding) or when the program is started (-z now) // symbol lookup error: ... undefined symbol: f Reviewers: ruiu, grimar, pcc, espindola Reviewed By: ruiu Subscribers: llvm-commits, emaste, arichardson Tags: #llvm Differential Revision: https://reviews.llvm.org/D57569 llvm-svn: 352943
* [ELF] Support --{,no-}allow-shlib-undefinedFangrui Song2019-02-018-11/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix names of functions in TargetOptionsCommandFlags.h. NFC.Sam Clegg2019-02-011-4/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D57555 llvm-svn: 352825
* [LTO] Set CGOptLevel in LTO config.Sam Clegg2019-01-301-0/+2
| | | | | | | | | Previously we were never setting this which means it was always being set to Default (-O2/-Os). Differential Revision: https://reviews.llvm.org/D57422 llvm-svn: 352667
* Recognize FreeBSD specific BFD names in OUTPUT_FORMATDimitry Andric2019-01-301-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: After rLLD344952 ("Add OUTPUT_FORMAT linker script directive support"), using BFD names such as `elf64-x86-64-freebsd` the `OUTPUT_FORMAT` linker script command does not work anymore, resulting in errors like: ``` ld: error: /home/dim/src/clang800-import/stand/efi/loader/arch/amd64/ldscript.amd64:2: unknown output format name: elf64-x86-64-freebsd >>> OUTPUT_FORMAT("elf64-x86-64-freebsd", "elf64-x86-64-freebsd", "elf64-x86-64-freebsd") >>> ^ ``` To fix this, recognize a `-freebsd` suffix in BFD names, and also set `Configuration::OSABI` to `ELFOSABI_FREEBSD` for those cases. Add and/or update several test cases to check for the correct results of these new `OUTPUT_FORMAT` arguments. Reviewers: ruiu, atanasyan, grimar, hokein, emaste, espindola Reviewed By: ruiu Subscribers: nemanjai, javed.absar, arichardson, krytarowski, kristof.beyls, kbarton, llvm-commits Differential Revision: https://reviews.llvm.org/D57283 llvm-svn: 352606
* [ELF] Simplify. NFCFangrui Song2019-01-291-1/+1
| | | | llvm-svn: 352499
* [ELF] - Remove dead `readBfdName` declaration. NFC.George Rimar2019-01-291-1/+0
| | | | | | `readBfdName` was removed recently. llvm-svn: 352482
* Attempt to fix build failure with GCC 5.4.Rui Ueyama2019-01-281-2/+2
| | | | llvm-svn: 352435
* ELF: Set sh_info on RelaIplt to point to the IgotPlt output section.Peter Collingbourne2019-01-281-1/+3
| | | | | | | | | | | Previously we were setting it to the GotPlt output section, which is incorrect on ARM where this section is in .got. In static binaries this can lead to sh_info being set to -1 (because there is no .got.plt) which results in various tools rejecting the output file. Differential Revision: https://reviews.llvm.org/D57274 llvm-svn: 352413
* Refactoring. NFC.Rui Ueyama2019-01-281-36/+24
| | | | llvm-svn: 352407
* lld: elf: discard more specific .gnu.linkonce sectionNick Desaulniers2019-01-271-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: lld discards .gnu.linonce.* sections work around a bug in glibc. https://sourceware.org/bugzilla/show_bug.cgi?id=20543 Unfortunately, the Linux kernel uses a section named .gnu.linkonce.this_module to store infomation about kernel modules. The kernel reads data from this section when loading kernel modules, and errors if it fails to find this section. The current behavior of lld discards this section when kernel modules are linked, so kernel modules linked with lld are unloadable by the linux kernel. The Linux kernel should use a comdat section instead of .gnu.linkonce. The minimum version of binutils supported by the kernel supports comdat sections. The kernel is also not relying on the old linkonce behavior; it seems to have chosen a name that contains a deprecated GNU feature. Changing the section name now in the kernel would require all kernel modules to be recompiled to make use of the new section name. Instead, rather than discarding .gnu.linkonce.*, let's discard the more specific section name to continue working around the glibc issue while supporting linking Linux kernel modules. Link: https://github.com/ClangBuiltLinux/linux/issues/329 Reviewers: pcc, espindola Reviewed By: pcc Subscribers: nathanchance, emaste, arichardson, void, srhines Differential Revision: https://reviews.llvm.org/D57294 llvm-svn: 352302
* Remove dead declaration.Rui Ueyama2019-01-261-1/+0
| | | | llvm-svn: 352257
* Simplify. NFC.Rui Ueyama2019-01-251-4/+2
| | | | llvm-svn: 352242
* [PPC64] Reland r351978 'Sort .toc sections accessed with small code model ...'Sean Fertile2019-01-245-0/+42
| | | | | | | | | | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud