summaryrefslogtreecommitdiffstats
path: root/lld/ELF
Commit message (Collapse)AuthorAgeFilesLines
...
* Make a member function private and rename it to avoid function overloading.Rui Ueyama2018-10-102-5/+6
| | | | llvm-svn: 344196
* [ELF] Don't warn on undefined symbols if UnresolvedPolicy::Ignore is usedFangrui Song2018-10-101-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Add a condition UnresolvedPolicy::Ignore to elf::warnUnorderedSymbol to suppress Sym->isUndefined() warnings from both 1) --symbol-ordering-file= 2) .llvm.call-graph-profile If --unresolved-symbols=ignore-all is used, no "undefined symbol" error/warning is emitted. It makes sense to not warn unorderable symbols. Otherwise, If an executable is linked, the default policy UnresolvedPolicy::ErrorOrWarn will issue a "undefined symbol" error. The unorderable symbol warning is redundant. If a shared object is linked, it is possible that only part of object files are used and some symbols are left undefined. The warning is not very necessary. In particular for .llvm.call-graph-profile, when linking a shared object, a call graph profile may contain undefined symbols. This case generated a warning before but it will be suppressed by this patch. Reviewers: ruiu, davidxl, espindola Reviewed By: ruiu Subscribers: grimar, emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D53044 llvm-svn: 344195
* Eliminate dependency to formatv(). NFC.Rui Ueyama2018-10-101-4/+3
| | | | llvm-svn: 344177
* Adapt OptTable::PrintHelp change in D51009Fangrui Song2018-10-101-2/+4
| | | | | | | | | | | | | | Summary: Before, OptTable::PrintHelp append "[options] <inputs>" to its parameter `Help`. It is more flexible to change its semantic to `Usage` and let user customize the usage line. Reviewers: rupprecht, ruiu, espindola Reviewed By: rupprecht Subscribers: emaste, sbc100, arichardson, aheejin, llvm-commits Differential Revision: https://reviews.llvm.org/D53054 llvm-svn: 344099
* Merge two overloaded functions into one function. NFC.Rui Ueyama2018-10-091-8/+3
| | | | llvm-svn: 344089
* Return early. NFC.Rui Ueyama2018-10-091-15/+14
| | | | llvm-svn: 344088
* Attempt to fix ubsan.Rui Ueyama2018-10-091-8/+11
| | | | | | | | | | | | | | | | | | Previously, we cast a pointer to Elf{32,64}_Chdr like this auto *Hdr = reinterpret_cast<const ELF64_Chdr>(Ptr); and read from its members like this read32(&Hdr->ch_size); I was thinking that this does not violate alignment requirement, since &Hdr->ch_size doesn't really access memory, but seems like it is a violation in terms of C++ spec (?) In this patch, I use a different struct that allows unaligned access. llvm-svn: 344083
* Calculate an offset only once. NFC.Rui Ueyama2018-10-091-4/+5
| | | | llvm-svn: 344076
* Remove redundant `Symtab->`.Rui Ueyama2018-10-091-7/+7
| | | | | | | | | `SymbolTable` is a singleton class and is a global variable for the unique instance, so we can always refer the symtab by `Symtab->`. However, we don't need to use the global varaible from member functions of SymbolTable class. llvm-svn: 344075
* Simplify. NFC.Rui Ueyama2018-10-092-12/+4
| | | | llvm-svn: 344074
* Remove a use of template to make code less abstracted.Rui Ueyama2018-10-091-19/+26
| | | | | | | Sometimes, code that is a bit longer but doesn't use template is easier to understand than code that uses template. llvm-svn: 344072
* Avoid unnecessary buffer allocation and memcpy for compressed sections.Rui Ueyama2018-10-0812-84/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, we uncompress all compressed sections before doing anything. That works, and that is conceptually simple, but that could results in a waste of CPU time and memory if uncompressed sections are then discarded or just copied to the output buffer. In particular, if .debug_gnu_pub{names,types} are compressed and if no -gdb-index option is given, we wasted CPU and memory because we uncompress them into newly allocated bufers and then memcpy the buffers to the output buffer. That temporary buffer was redundant. This patch changes how to uncompress sections. Now, compressed sections are uncompressed lazily. To do that, `Data` member of `InputSectionBase` is now hidden from outside, and `data()` accessor automatically expands an compressed buffer if necessary. If no one calls `data()`, then `writeTo()` directly uncompresses compressed data into the output buffer. That eliminates the redundant memory allocation and redundant memcpy. This patch significantly reduces memory consumption (20 GiB max RSS to 15 Gib) for an executable whose .debug_gnu_pub{names,types} are in total 5 GiB in an uncompressed form. Differential Revision: https://reviews.llvm.org/D52917 llvm-svn: 343979
* [ELF][HEXAGON] Add R_HEX_GOT_16_X supportSid Manning2018-10-081-1/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D52909 llvm-svn: 343972
* [ELF][HEXAGON] Add support for GOT relocations.Sid Manning2018-10-044-9/+24
| | | | | | | | | | | | | The GOT is referenced through the symbol _GLOBAL_OFFSET_TABLE_ . The relocation added calculates the offset into the global offset table for the entry of a symbol. In order to get the correct TargetVA I needed to create an new relocation expression, HEXAGON_GOT. It does Sym.getGotVA() - In.GotPlt->getVA(). Differential Revision: https://reviews.llvm.org/D52744 llvm-svn: 343784
* [ELF] - Simplify. NFCI.George Rimar2018-10-041-4/+2
| | | | | | Assign the `Link` to parent directly. llvm-svn: 343762
* Use std::make_pair rather than brace initialization.Matt Morehouse2018-10-041-2/+2
| | | | | | | r343732 broke the Windows bot. Seems like the compiler on that bot doesn't like brace initialization. llvm-svn: 343749
* [ELF] Fix crash on invalid undefined local symbolsShoaib Meenai2018-10-031-9/+9
| | | | | | | | | | | | | | | | | | | | r320770 made LLD handle invalid DSOs where local symbols were found in the global part of the symbol table. Unfortunately, it didn't handle the case where those local symbols were also undefined, and r326242 exposed an assertion failure in that case. Just warn on that case instead of crashing, by moving the local binding check before the undefined symbol addition. The input file for the test is crafted by hand, since I don't know of any tool that would produce such a broken DSO. I also don't understand what it even means for a symbol to be undefined but have STB_LOCAL binding - I don't think that combination makes any sense - but we have found broken DSOs of this nature that we were linking against. I've included detailed instructions on how to produce the DSO in the test. Differential Revision: https://reviews.llvm.org/D52815 llvm-svn: 343745
* Minor refacotring of Relocations.cpp. NFC.Rui Ueyama2018-10-031-44/+67
| | | | | | | | This patch splits ThunkCreator::mergeThunks into two smaller functions. Also adds blank lines to various places so that the code doesn't look too dense. llvm-svn: 343732
* [ELF] - Do not forget to include to .dymsym symbols that were converted to ↵George Rimar2018-10-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Defined. This is the fix for "Bug 39104 - LLD links incorrect ELF executable if version script contains "local: *;" (https://bugs.llvm.org/show_bug.cgi?id=39104). The issue happens when we have non-PIC program call to function in a shared library. (for example, the PR above has R_X86_64_PC32 relocation against __libc_start_main) LLD converts symbol to Defined in that case with the use of replaceWithDefined() The issue is that after above we create a broken relocation because do not include the symbol into .dynsym. That happens when the version script is used because we treat the symbol as STB_LOCAL if the following condition match: VersionId == VER_NDX_LOCAL && isDefined() and do not include it to .dynsym because of that. Patch fixes the issue. Differential revision: https://reviews.llvm.org/D52724 llvm-svn: 343668
* [LLD] - Do not crash when reporting errors when .debug_line_str (DWARF5) is usedGeorge Rimar2018-10-032-0/+4
| | | | | | | | | | | | | | | | | | Imagine we have the following code: int foo(); int main() { return foo(); } It will crash if you try to compile it with `clang -O0 -gdwarf-5 test.cpp -o test -g -fuse-ld=lld` The crash happens inside the LLVM DWARF parser because LLD does not provide the .debug_line_str section. At the same time for correct parsing and reporting, we anyways need to provide this section from our side. The patch fixes the issue. llvm-svn: 343667
* Introduce a flag to warn when ifunc symbols are used with text relocations.Ali Tamur2018-10-024-3/+21
| | | | | | | | | | | | | | | | | Summary: This patch adds a new flag, --warn-ifunc-textrel, to work around a glibc bug. When a code with ifunc symbols is used to produce an object file with text relocations, lld always succeeds. However, if that object file is linked using an old version of glibc, the resultant binary just crashes with segmentation fault when it is run (The bug is going to be corrected as of glibc 2.19). Since there is no way to tell beforehand what library the object file will be linked against in the future, there does not seem to be a fool-proof way for lld to give an error only in cases where the binary will crash. So, with this change (dated 2018-09-25), lld starts to give a warning, contingent on a new command line flag that does not have a gnu counter part. The default value for --warn-ifunc-textrel is false, so lld behaviour will not change unless the user explicitly asks lld to give a warning. Users that link with a glibc library with version 2.19 or newer, or does not use ifunc symbols, or does not generate object files with text relocations do not need to take any action. Other users may consider to start passing warn-ifunc-textrel to lld to get early warnings. Reviewers: ruiu, espindola Reviewed By: ruiu Subscribers: grimar, MaskRay, markj, emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D52430 llvm-svn: 343628
* [ELF] Read the call graph profile from object files.Michael J. Spencer2018-10-023-0/+31
| | | | | | | | | | This uses the call graph profile embedded in the object files to construct the call graph. This is read from a SHT_LLVM_CALL_GRAPH_PROFILE (0x6fff4c02) section as (uint32_t, uint32_t, uint64_t) tuples as (from symbol index, to symbol index, weight). Differential Revision: https://reviews.llvm.org/D45850 llvm-svn: 343552
* [ELF] [HEXAGON] Add support for PLT_B22_PCREL and HEX_32_PCRELSid Manning2018-10-011-0/+4
| | | | | | | | Update testcase. Differential Revision: https://reviews.llvm.org/D52734 llvm-svn: 343515
* [ELF][HEXAGON] Add support for dynamic librariesSid Manning2018-09-282-5/+49
| | | | | | | | | Write out the PLT header and stub. Hexagon uses RELA relocations. Differential Revision: https://reviews.llvm.org/D52317 llvm-svn: 343320
* [ELF] llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song2018-09-263-24/+19
| | | | | | | | | | | | 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
* [AArch64] Fix range check of R_AARCH64_TLSLE_ADD_TPREL_HI12Ryan Prichard2018-09-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Summary: An AArch64 LE relocation is a positive ("variant 1") offset. This relocation is used to write the upper 12 bits of a 24-bit offset into an add instruction: add x0, x0, :tprel_hi12:v1 The comment in the ARM docs for R_AARCH64_TLSLE_ADD_TPREL_HI12 is: "Set an ADD immediate field to bits [23:12] of X; check 0 <= X < 2^24." Reviewers: javed.absar, espindola, ruiu, peter.smith, zatrazz Reviewed By: ruiu Subscribers: emaste, arichardson, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D52525 llvm-svn: 343144
* [ELF] - Do not fail on R_*_NONE relocations when parsing the debug info.George Rimar2018-09-2614-1/+22
| | | | | | | | | | | | | | | | | This is https://bugs.llvm.org//show_bug.cgi?id=38919. Currently, LLD may report "unsupported relocation target while parsing debug info" when parsing the debug information. At the same time LLD does that for zeroed R_X86_64_NONE relocations, which obviously has "invalid" targets. The nature of R_*_NONE relocation assumes them should be ignored. This patch teaches LLD to stop reporting the debug information parsing errors for them. Differential revision: https://reviews.llvm.org/D52408 llvm-svn: 343078
* Update a --help message and add -execute-only to the man page.Rui Ueyama2018-09-251-1/+1
| | | | llvm-svn: 343032
* De-template VersionDefinitionSection. NFC.Rui Ueyama2018-09-254-51/+38
| | | | | | | | 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-2517-396/+388
| | | | | | | | | | 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
* Fix an error message. It must start with a lowercase letter.Rui Ueyama2018-09-251-1/+1
| | | | llvm-svn: 342992
* Parallelize .gdb_index string table writes.Rui Ueyama2018-09-251-1/+2
| | | | | | When we are creating a large .gdb_index, this change makes a difference. llvm-svn: 342978
* Align AArch64 and i386 image base to superpageDimitry Andric2018-09-212-0/+8
| | | | | | | | | | | | | | | | | | | Summary: As for x86_64, the default image base for AArch64 and i386 should be aligned to a superpage appropriate for the architecture. On AArch64, this is 2 MiB, on i386 it is 4 MiB. Reviewers: emaste, grimar, javed.absar, espindola, ruiu, peter.smith, srhines, rprichard Reviewed By: ruiu, peter.smith Subscribers: jfb, markj, arichardson, krytarowski, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D50297 llvm-svn: 342746
* [ELF] Use the Repl point to avoid the segfault when using ICFPetr Hosek2018-09-211-1/+1
| | | | | | | | This addresses PR38918. Differential Revision: https://reviews.llvm.org/D52202 llvm-svn: 342704
* 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
* Rename a function. NFC.Rui Ueyama2018-09-201-2/+2
| | | | llvm-svn: 342687
* Make variable names shorter. NFC.Rui Ueyama2018-09-201-11/+10
| | | | llvm-svn: 342686
* Simplify. NFC.Rui Ueyama2018-09-201-7/+3
| | | | llvm-svn: 342685
* [ELF][HEXAGON] Set DefaultMaxPageSize to 64KSid Manning2018-09-201-0/+6
| | | | | | Update testcase to reflect the change. llvm-svn: 342662
* [PPC64] Handle ppc64le triple in getBitcodeMachineKind.Sean Fertile2018-09-201-0/+1
| | | | | | | | Enables lto and thinlto with bitcode targeting ppc64le. Differential Revision: https://reviews.llvm.org/D52265 llvm-svn: 342604
* [PPC64] Helper for offset from a function's global entry to local entry. [NFC]Sean Fertile2018-09-203-10/+41
| | | | | | | | | | | | | The PPC64 elf V2 abi defines 2 entry points for a function. There are a few places we need to calculate the offset from the global entry to the local entry and how this is done is not straight forward. This patch adds a helper function mostly for documentation purposes, explaining how the 2 entry points differ and why we choose one over the other, as well as documenting how the offsets are encoded into a functions st_other field. Differential Revision: https://reviews.llvm.org/D52231 llvm-svn: 342603
* [PPC64] Optimize redundant instructions in global access sequences.Sean Fertile2018-09-204-2/+81
| | | | | | | | | | | | | | | | | | | The access sequence for global variables in the medium and large code models use 2 instructions to add an offset to the toc-pointer. If the offset fits whithin 16-bits then the instruction that sets the high 16 bits is redundant. This patch adds the --toc-optimize option, (on by default) and enables rewriting of 2 instruction global variable accesses into 1 when the offset from the TOC-pointer to the variable (or .got entry) fits in 16 signed bits. eg addis %r3, %r2, 0 --> nop addi %r3, %r3, -0x8000 --> addi %r3, %r2, -0x8000 This rewriting can be disabled with the --no-toc-optimize flag Differential Revision: https://reviews.llvm.org/D49237 llvm-svn: 342602
* [ELF] Set Out::TlsPhdr earlier for encoding packed reloc tablesRyan Prichard2018-09-182-9/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: For --pack-dyn-relocs=android, finalizeSections calls LinkerScript::assignAddresses and AndroidPackedRelocationSection::updateAllocSize in a loop, where assignAddresses lays out the ELF image, then updateAllocSize determines the size of the Android packed relocation table by encoding it. Encoding the table requires knowing the values of relocation addends. To get the addend of a TLS relocation, updateAllocSize can call getSymVA on a TLS symbol before setPhdrs has initialized Out::TlsPhdr, producing an error: <file> has an STT_TLS symbol but doesn't have an SHF_TLS section Fix the problem by initializing Out::TlsPhdr immediately after the program headers are created. The segment's p_vaddr field isn't initialized until setPhdrs, so use FirstSec->Addr, which is what setPhdrs would use. FirstSec will typically refer to the .tdata or .tbss output section, whose (tentative) address was computed by assignAddresses. Android currently avoids this problem because it uses emutls and doesn't support ELF TLS. This problem doesn't apply to --pack-dyn-relocs=relr because SHR_RELR only handles relative relocations without explicit addends or info. Fixes https://bugs.llvm.org/show_bug.cgi?id=37841. Reviewers: ruiu, pcc, chh, javed.absar, espindola Subscribers: emaste, arichardson, llvm-commits, srhines Differential Revision: https://reviews.llvm.org/D51671 llvm-svn: 342432
* [PPC64] Support relaxing R_PPC64_TLSGD16 in TlsGdtoLe relaxation.Sean Fertile2018-09-171-0/+1
| | | | | | | | | | A General-dynamic tls access can be written using a R_PPC64_TLSGD16 relocation if the target got entry is within 16 bits of the TOC-base. This patch adds support for R_PPC64_TLSGD16 by relaxing it the same as a R_PPC64_GOT_TLSGD16_LO. Differential Revision: https://reviews.llvm.org/D52055 llvm-svn: 342411
* [PPC64] Helpers for read/write an instr while relocating a half16 type. [NFC]Sean Fertile2018-09-171-16/+26
| | | | | | | | | | | | There are a growing number of places when we either want to read or write an instruction when handling a half16 relocation type. On big-endian the buffer pointer is pointing into the middle of the word we want and on little-endian it is pointing to the start of the word. These 2 helpers are to simplify reading and writing in these contexts. Differential Revision: https://reviews.llvm.org/D52115 llvm-svn: 342410
* [ELF] Use llvm::toLower instead of libc call tolowerFangrui Song2018-09-151-1/+2
| | | | | | | | | | | | | | | | | | | tolower() has some overhead because current locale is considered (though in lld the default "C" locale is used which does not matter too much). llvm::toLower is more efficient as it compiles to a compare and a conditional jump, as opposed to a libc call if tolower is used. Disregarding locale also matches gdb's behavior (gdb/minsyms.h): #define SYMBOL_HASH_NEXT(hash, c) \ ((hash) * 67 + TOLOWER ((unsigned char) (c)) - 113) where TOLOWER (include/safe-ctype.h) is a macro that uses a lookup table under the hood which is similar to llvm::toLower. Reviewers: ruiu, espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D52128 llvm-svn: 342342
* Style fix. NFC.Rui Ueyama2018-09-141-13/+23
| | | | llvm-svn: 342300
* Rename GdbIndex.{cpp,h} -> DWARF.{cpp,h}.Rui Ueyama2018-09-144-7/+7
| | | | | | | | These files used to contain classes and functions for .gdb_index, but they are moved to SyntheticSections.{cpp,h}, so the name is now irrelevant. llvm-svn: 342299
* Revert r342297: Discard uncompressed buffer after creating .gdb_index contents.Rui Ueyama2018-09-142-10/+8
| | | | | | Looks like it broke some local builds that use -gdb-index. llvm-svn: 342298
* Discard uncompressed buffer after creating .gdb_index contents.Rui Ueyama2018-09-142-8/+10
| | | | | | | | | | | | | | Once we create .gdb_index contents, .zdebug_gnu_pub{names,types} are useless, so there's no need to keep their uncompressed data in memory. I observed that for a test case in which lld creates a 3GB .gdb_index section, the maximum resident set size reduced from 43GB to 29GB after this patch. Differential Revision: https://reviews.llvm.org/D52126 llvm-svn: 342297
OpenPOWER on IntegriCloud