summaryrefslogtreecommitdiffstats
path: root/lld/test/ELF
Commit message (Collapse)AuthorAgeFilesLines
...
* [lld] Add more complete support for the INCLUDE command.Rui Ueyama2018-10-123-0/+85
| | | | | | | | | | | | | Patch by Ian Tessier. This change adds INCLUDE support to the MEMORY and SECTION commands, and to output sections, as per: https://sourceware.org/binutils/docs/ld/File-Commands.html#File-Commands Differential Revision: https://reviews.llvm.org/D52951 llvm-svn: 344368
* [ELF] Fix link failure with Android compressed relocation support.Eli Friedman2018-10-111-0/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Android uses a compressed relocation format, which means the size of the relocation section isn't predictable based on the number of relocations, and can vary if the layout changes in any way. To deal with this, the linker normally runs multiple passes until the layout converges. The layout should converge if the size of the compressed relocation section increases monotonically: if the size of an encoded offset increases by one byte, the larget value which can be encoded is multiplied by 128, so the representable offsets grow much faster than the size of the section itself. The problem here is that there is no code to ensure the size of the section doesn't decrease. If the size of the relocation section decreases, the relative offsets can increase due to alignment restrictions, so that can force the size of the relocation section to increase again. The end result is an infinite loop; the loop gets cut off after 10 iterations with the message "thunk creation not converged". To avoid this issue, this patch adds padding to the end of the relocation section if its size would decrease. The extra padding is harmless because of the way the format is defined: decoding stops after it reaches the number of relocations specified in the section's header. Differential Revision: https://reviews.llvm.org/D53003 llvm-svn: 344300
* [ELF] - Set sh_info and sh_link for .rela.plt sections.George Rimar2018-10-114-7/+12
| | | | | | | | | | | | | | | | | | | | This is https://bugs.llvm.org/show_bug.cgi?id=37538, Currently, LLD may set both sh_link and sh_info for .rela.plt section to zero when we have only .rela.iplt section part used. ELF spec (https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-94076/index.html) says that for SHT_REL and SHT_RELA, sh_link references the associated symbol table and sh_info the "section to which the relocation applies." When we set the sh_link field, for the regular case we use the .dynsym index. For .rela.iplt sections, it is unclear what is the associated symbol table, because R_*_RELATIVE relocations do not use symbol names and we might have no .dynsym section at all so this patch uses .symtab section index. Differential revision: https://reviews.llvm.org/D52830 llvm-svn: 344226
* [ELF] Don't warn on undefined symbols if UnresolvedPolicy::Ignore is usedFangrui Song2018-10-102-8/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix a broken buildbot.Rui Ueyama2018-10-081-1/+1
| | | | llvm-svn: 343983
* Avoid unnecessary buffer allocation and memcpy for compressed sections.Rui Ueyama2018-10-083-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-0/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D52909 llvm-svn: 343972
* [llvm-nm] Write "no symbol" output to stderrPetr Hosek2018-10-051-1/+1
| | | | | | | | | | This matches the output of binutils' nm and ensures that any scripts or tools that use nm and expect empty output in case there no symbols don't break. Differential Revision: https://reviews.llvm.org/D52943 llvm-svn: 343887
* [ELF][HEXAGON] Add support for GOT relocations.Sid Manning2018-10-041-6/+17
| | | | | | | | | | | | | 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] Fix typo. NFCShoaib Meenai2018-10-041-1/+1
| | | | llvm-svn: 343748
* [ELF] Fix crash on invalid undefined local symbolsShoaib Meenai2018-10-032-0/+66
| | | | | | | | | | | | | | | | | | | | 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
* [llvm-nm] Update lld tests based on changed llvm-nm outputJordan Rupprecht2018-10-031-1/+2
| | | | llvm-svn: 343743
* [PPC64] Test documenting toc-restore after interposable recursive call. [NFC]Sean Fertile2018-10-031-0/+52
| | | | | | | | | A test verifying that toc restores are properly inserted following recursive calls, as well as briefly describing why they are needed. Differential Revision: https://reviews.llvm.org/D52564 llvm-svn: 343729
* [PPC64] Add test documenting toc-restore when linking with -Bsymbolic. [NFC]Sean Fertile2018-10-032-0/+82
| | | | | | Differential Revision: https://reviews.llvm.org/D52523 llvm-svn: 343728
* [ELF] - Fix BB after r343668George Rimar2018-10-031-1/+2
| | | | | | | | | This stops testing the value of .rela.plt section offset. Also makes _start global to eliminate 'cannot find entry symbol _start' warning. llvm-svn: 343669
* [ELF] - Do not forget to include to .dymsym symbols that were converted to ↵George Rimar2018-10-031-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | 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-031-0/+136
| | | | | | | | | | | | | | | | | | 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-021-0/+40
| | | | | | | | | | | | | | | | | 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
* [NFC][BUG-FIX][ARM] Add missing data symbolDiogo N. Sampaio2018-10-021-3/+6
| | | | | | | | | | llvm rL343594: [ARM] Emmit data symbol for constant pool data fixed a bug that ommited required data symbols. Such change breaked a test case in lld: test/ELF/arm-thunk-largesection.s llvm-svn: 343604
* [ELF] Read the call graph profile from object files.Michael J. Spencer2018-10-022-0/+78
| | | | | | | | | | 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-13/+21
| | | | | | | | Update testcase. Differential Revision: https://reviews.llvm.org/D52734 llvm-svn: 343515
* [ELF][HEXAGON] Add support for dynamic librariesSid Manning2018-09-282-0/+26
| | | | | | | | | Write out the PLT header and stub. Hexagon uses RELA relocations. Differential Revision: https://reviews.llvm.org/D52317 llvm-svn: 343320
* Allow later -z name=<int> args to override earlier argsRyan Prichard2018-09-261-0/+3
| | | | | | | | | | | | | | | | | | Summary: lld already gives later -z options precedence in getZFlag(). This matches the behavior of ld.bfd and ld.gold, where later options override earlier ones. (I tested with -z max-page-size and -z stack-size.) Reviewers: ruiu, espindola, grimar Reviewed By: ruiu, grimar Subscribers: grimar, emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D52526 llvm-svn: 343145
* [AArch64] Fix range check of R_AARCH64_TLSLE_ADD_TPREL_HI12Ryan Prichard2018-09-261-1/+18
| | | | | | | | | | | | | | | | | | | | | | | 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][test] Use llvm-readelf's short option -r instead of -relocations and ↵Fangrui Song2018-09-269-31/+31
| | | | | | | | | | | | | | remove ignored --wide Reviewers: ruiu, sfertile, espindola Reviewed By: ruiu Subscribers: jsji, emaste, nemanjai, arichardson, kbarton, llvm-commits Differential Revision: https://reviews.llvm.org/D52124 llvm-svn: 343135
* [ELF] - Do not fail on R_*_NONE relocations when parsing the debug info.George Rimar2018-09-262-1/+59
| | | | | | | | | | | | | | | | | 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
* Fix an error message. It must start with a lowercase letter.Rui Ueyama2018-09-251-1/+1
| | | | llvm-svn: 342992
* Align AArch64 and i386 image base to superpageDimitry Andric2018-09-2148-825/+825
| | | | | | | | | | | | | | | | | | | 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-212-0/+68
| | | | | | | | This addresses PR38918. Differential Revision: https://reviews.llvm.org/D52202 llvm-svn: 342704
* [ELF][HEXAGON] Set DefaultMaxPageSize to 64KSid Manning2018-09-201-50/+50
| | | | | | Update testcase to reflect the change. llvm-svn: 342662
* [PPC64] Handle ppc64le triple in getBitcodeMachineKind.Sean Fertile2018-09-201-0/+12
| | | | | | | | Enables lto and thinlto with bitcode targeting ppc64le. Differential Revision: https://reviews.llvm.org/D52265 llvm-svn: 342604
* [PPC64] Optimize redundant instructions in global access sequences.Sean Fertile2018-09-207-6/+365
| | | | | | | | | | | | | | | | | | | 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-0/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/+61
| | | | | | | | | | 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
* lld: add -z interpose supportEd Maste2018-09-141-3/+3
| | | | | | | | | | | -z interpose sets the DF_1_INTERPOSE flag, marking the object as an interposer. Via FreeBSD PR 230604, linking Valgrind with lld failed. Differential Revision: https://reviews.llvm.org/D52094 llvm-svn: 342239
* [ELF] Guard --fix-cortex-a53-843419 against --just-symsPeter Smith2018-09-131-0/+22
| | | | | | | | | | | | | | If --just-syms is used the mapping symbols from the ELF file will be absolute symbols with no section. The code to process mapping symbols in --fix-cortex-a53-843419 assumes that these symbols have a defining section so a crash will result when --just-syms is used. The simple fix is to not process the symbol when it doesn't have a section. Fixes PR37971 Differential Revision: https://reviews.llvm.org/D52038 llvm-svn: 342146
* [ELF] Revert "Also demote lazy symbols."Chih-Hung Hsieh2018-09-112-0/+20
| | | | | | | | | This reverts commit https://reviews.llvm.org/rL330869 for a regression to link Android dex2oatds. Differential Revision: https://reviews.llvm.org/D51892 llvm-svn: 342007
* [ELF] Don't emit .relr.dyn section if there are no relocsPetr Hosek2018-09-101-0/+11
| | | | | | | | This resolves PR38875. Differential Revision: https://reviews.llvm.org/D51834 llvm-svn: 341870
* [ELF] Check if LinkSec is nullptr when initializing SHF_LINK_ORDER sectionsFangrui Song2018-09-071-0/+16
| | | | | | | | | | | | | | Summary: This protects lld from a null pointer dereference when a faulty input file has such invalid sh_link fields. Reviewers: ruiu, espindola Reviewed By: ruiu Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D51743 llvm-svn: 341611
* [LLD] Add test missed from r341206. NFC.Ben Dunbobbin2018-08-311-0/+9
| | | | llvm-svn: 341207
* [LLD] Check too large offsets into merge sections earlierBen Dunbobbin2018-08-312-2/+2
| | | | | | | | | | | | | | | | | This patch moves the checking for too large offsets into merge sections earlier. Without this change the large offset generated in the added test-case will cause an assert (as it happens to be a value reserved as a "tombstone" in the DenseMap implementation) when OffsetMap is queried in getSectionPiece(). To simplify the code and avoid future mistakes I have refactored so that there is only one function that looks up offsets in the OffsetMap. Differential Revision: https://reviews.llvm.org/D51180 llvm-svn: 341206
* [PPC64] Improve a test ppc64_entry_point.sFangrui Song2018-08-311-8/+7
| | | | | | | Rename to ppc64-entry-point.s Deduplicate .text dump of little-endian big-endian llvm-svn: 341153
* [PPC64] Improve a test ppc64-toc-rel.sFangrui Song2018-08-312-20/+12
| | | | | | | Deduplicate dump of .text .data for little-endian and big-endian Fix a RELOCS-NE check line typo llvm-svn: 341148
* [PPC64] Remove unused -z notext from a testFangrui Song2018-08-301-2/+2
| | | | llvm-svn: 341139
* ELF: Don't examine values of linker script symbols during ICF.Peter Collingbourne2018-08-291-0/+11
| | | | | | | | | These symbols are declared early with the same value, so they otherwise appear identical to ICF. Differential Revision: https://reviews.llvm.org/D51376 llvm-svn: 340998
* Always add a .note.GNU-stack section if -r.Rui Ueyama2018-08-296-16/+30
| | | | | | | | | | | | With this patch, lld creates a .note.GNU_stack and adds that to an output file if it is creating a re-linkable object file (i.e. if -r is given). If we don't do this, and if you use GNU linkers as a final linker, they create an executable whose stack area is executable, which is considered pretty bad these days. Differential Revision: https://reviews.llvm.org/D51400 llvm-svn: 340902
* [ELF] Change llvm-objdump -D to -d for check lines that only inspect text ↵Fangrui Song2018-08-299-17/+17
| | | | | | | | | | | | sections Reviewers: ruiu, sfertile, syzaara, espindola Subscribers: emaste, nemanjai, arichardson, kbarton, llvm-commits Differential Revision: https://reviews.llvm.org/D51389 llvm-svn: 340890
* [PPC64] Fix DQ-form instruction handling and emit error for misalignment.Sean Fertile2018-08-283-0/+84
| | | | | | | | | | | | | Relanding r340564, original commit message: Fixes the handling of *_DS relocations used on DQ-form instructions where we were overwriting some of the extended opcode bits. Also adds an alignment check so that the user will receive a diagnostic error if the value we are writing is not properly aligned. Differential Revision: https://reviews.llvm.org/D51124 llvm-svn: 340832
* [LLD][ELD] - Do not reject INFO output section type when used with a start ↵George Rimar2018-08-281-0/+9
| | | | | | | | | | | | | | | | | | | | address. This is https://bugs.llvm.org/show_bug.cgi?id=38625 LLD accept this: ".stack (INFO) : {", but not this: ".stack address_expression (INFO) :" The patch fixes it. Differential revision: https://reviews.llvm.org/D51027 llvm-svn: 340804
* [LLF][ELF] - Support -z global.George Rimar2018-08-281-2/+3
| | | | | | | | -z global is a flag used on Android (see D49198). Differential revision: https://reviews.llvm.org/D49374 llvm-svn: 340802
OpenPOWER on IntegriCloud