From 145a4ac21f065c982b416ca69654081adaad69f6 Mon Sep 17 00:00:00 2001 From: chisuhua Date: Sun, 1 Sep 2019 07:31:42 -0400 Subject: [PATCH] merge upstream (#1) * Return early. NFC. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367200 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Fix finding locations in messages for undefined hidden symbols. Previously, when `--vs-diagnostics` was used, the linker printed something like hidden(undef.s): error: undefined hidden symbol: foo >>> referenced by undef.s:15 Differential Revision: https://reviews.llvm.org/D65499 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367515 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][X86] Improve tests * Add --no-show-raw-insn to llvm-objdump -d tests * When linking an executable with %t.so, the path %t.so will be recorded in the DT_NEEDED entry if %t.so doesn't have DT_SONAME. .dynstr will have varying lengths on different systems. Add -soname so that the string in .dynstr is of fixed length to make tests more robust. * Rename i386-tls-initial-exec-local.s to i386-tls-ie-local.s * Refactor tls-initial-exec-local.s to x86-64-tls-ie-local.s git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367533 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] With --vs-diagnostics, print a separate message for each location of a duplicate symbol. We extract and print the source location in the message header so that Visual Studio is able to parse it and jump there. As duplicate symbols are defined in several locations, it is more convenient to have separate error messages, which allows a user to easily access all the locations. Differential Revision: https://reviews.llvm.org/D65213 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367536 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Add -z separate-code and pad the last page of last PF_X PT_LOAD with traps only if -z separate-code is specified This patch 1) adds -z separate-code and -z noseparate-code (default). 2) changes the condition that the last page of last PF_X PT_LOAD is padded with trap instructions. Current condition (after D33630): if there is no `SECTIONS` commands. After this change: if -z separate-code is specified. -z separate-code was introduced to ld.bfd in 2018, to place the text segment in its own pages. There is no overlap in pages between an executable segment and a non-executable segment: 1) RX cannot load initial contents from R or RW(or non-SHF_ALLOC). 2) R and RW(or non-SHF_ALLOC) cannot load initial contents from RX. lld's current status: - Between R and RX: in `Writer::fixSectionAlignments()`, the start of a segment is always aligned to maxPageSize, so the initial contents loaded by R and RX do not overlap. I plan to allow overlaps in D64906 if -z noseparate-code is in effect. - Between RX and RW(or non-SHF_ALLOC if RW doesn't exist): we currently unconditionally pad the last page to commonPageSize (defaults to 4096 on all targets we support). This patch will make it effective only if -z separate-code is specified. -z separate-code is a dubious feature that intends to reduce the number of ROP gadgets (which is actually ineffective because attackers can find plenty of gadgets in the text segment, no need to find gadgets in non-code regions). With the overlapping PT_LOAD technique D64906, -z noseparate-code removes two more alignments at segment boundaries than -z separate-code. This saves at most defaultCommonPageSize*2 bytes, which are significant on targets with large defaultCommonPageSize (AArch64/MIPS/PPC: 65536). Issues/feedback on alignment at segment boundaries to help understand the implication: * binutils PR24490 (the situation on ld.bfd is worse because they have two R-- on both sides of R-E so more alignments.) * In binutils, the 2018-02-27 commit "ld: Add --enable-separate-code" made -z separate-code the default on Linux. https://github.com/richfelker/musl-cross-make/commit/d969dea983a2cc54a1e0308a0cdeb6c3307e4bfa In musl-cross-make, binutils is configured with --disable-separate-code to address size regressions caused by -z separate-code. (lld actually has the same issue, which I plan to fix in a future patch. The ld.bfd x86 status is worse because they default to max-page-size=0x200000). * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=237676 people want smaller code size. This patch will remove one alignment boundary. * Stef O'Rear: I'm opposed to any kind of page alignment at the text/rodata line (having a partial page of text aliased as rodata and vice versa has no demonstrable harm, and I actually care about small systems). So, make -z noseparate-code the default. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D64903 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367537 91177308-0d34-0410-b5e6-96231b3b80d8 * [COFF] Fix wholearchive with thin archives The Archive object created when loading an archive specified with wholearchive got cleaned up immediately, when the owning std::unique_ptr went out of scope, even if persisted StringRefs pointed to memory that belonged to the archive, which no longer was mapped in memory. This hasn't been an issue with regular (as opposed to thin) archives, as references to the member objects has kept the mapping for the whole archive file alive - but with thin archives, all such references point to other files. Add the std::unique_ptr to the arena allocator, to retain it as long as necessary. This fixes (the last issue raised in) PR42388. Differential Revision: https://reviews.llvm.org/D65565 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367599 91177308-0d34-0410-b5e6-96231b3b80d8 * Fix an unused variable warning. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367643 91177308-0d34-0410-b5e6-96231b3b80d8 * Improve raw_ostream so that you can "write" colors using operator<< 1. raw_ostream supports ANSI colors so that you can write messages to the termina with colors. Previously, in order to change and reset color, you had to call `changeColor` and `resetColor` functions, respectively. So, if you print out "error: " in red, for example, you had to do something like this: OS.changeColor(raw_ostream::RED); OS << "error: "; OS.resetColor(); With this patch, you can write the same code as follows: OS << raw_ostream::RED << "error: " << raw_ostream::RESET; 2. Add a boolean flag to raw_ostream so that you can disable colored output. If you disable colors, changeColor, operator<<(Color), resetColor and other color-related functions have no effect. Most LLVM tools automatically prints out messages using colors, and you can disable it by passing a flag such as `--disable-colors`. This new flag makes it easy to write code that works that way. Differential Revision: https://reviews.llvm.org/D65564 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367649 91177308-0d34-0410-b5e6-96231b3b80d8 * Add a comment for --vs-diagnostics. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367650 91177308-0d34-0410-b5e6-96231b3b80d8 * Add an assert() to catch possible regexp errors. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367651 91177308-0d34-0410-b5e6-96231b3b80d8 * Revert r367649: Improve raw_ostream so that you can "write" colors using operator<< This reverts commit r367649 in an attempt to unbreak Windows bots. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367658 91177308-0d34-0410-b5e6-96231b3b80d8 * [COFF] Avoid loading objects for mingw autoimport, when a defined alias exists This avoids a spurious and confusing log message in cases where both e.g. "alias" and "__imp_alias" exist. Differential Revision: https://reviews.llvm.org/D65598 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367673 91177308-0d34-0410-b5e6-96231b3b80d8 * [COFF] Clarify a comment. NFC. It's the __delayLoadHelper2 function that overwrites the jump table slot, not this thunk. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367674 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Move R_*_IRELATIVE from .rel[a].plt to .rel[a].dyn unless --pack-dyn-relocs=android[+relr] An R_*_IRELATIVE represents the address of a STT_GNU_IFUNC symbol (redirected at runtime) which is non-preemptable and is not associated with a canonical PLT (associated with a symbol with a section index of SHN_UNDEF but a non-zero st_value). .rel[a].plt [DT_JMPREL, DT_JMPREL+DT_JMPRELSZ) contains relocations that can be lazily resolved. R_*_IRELATIVE are always eagerly resolved, so conceptually they do not belong to .rela.plt. "iplt" is mostly a misnomer. glibc powerpc and powerpc64 do not resolve R_*_IRELATIVE if they are in .rela.plt. // a.o - synthesized PLT call stub has an R_*_IRELATIVE void ifunc(); int main() { ifunc(); } // b.o static void real() {} asm (".type ifunc, %gnu_indirect_function"); void *ifunc() { return ℜ } The lld-linked executable crashes. ld.bfd places R_*_IRELATIVE in .rela.dyn and the executable works. glibc i386, x86_64, and aarch64 have logic (glibc/sysdeps/*/dl-machine.h:elf_machine_lazy_rel) to eagerly resolve R_*_IRELATIVE in .rel[a].plt so the lld-linked executable works. Move R_*_IRELATIVE from .rel[a].plt to .rel[a].dyn to fix the crashes on glibc powerpc/powerpc64. This also helps simplifying ifunc implementation in FreeBSD rtld-elf powerpc64. If --pack-dyn-relocs=android[+relr] is specified, the Android packed dynamic relocation format is used for .rela.dyn. We cannot name in.relaIplt ".rela.dyn" because the output section will have mixed formats. This can be improved in the future. Reviewed By: pcc Differential Revision: https://reviews.llvm.org/D65651 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367745 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][test] Delete redundant version-script-*.s tests Delete version-script-missing.s: it is covered by version-script-noundef.s Delete version-script-anonymous-local.s: it is covered by version-script-{glob,weak}.s etc Delete version-script-no-warn{,2}.s: add --fatal-warnings to some version-script.s commands instead git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367778 91177308-0d34-0410-b5e6-96231b3b80d8 * Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFC F_{None,Text,Append} are kept for compatibility since r334221. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367800 91177308-0d34-0410-b5e6-96231b3b80d8 * [COFF] Omit automatically imported symbols from the symbol table These symbols actually point to the symbol's IAT entry, which obviously is different from the symbol itself (which is imported from a different module and doesn't exist in the current one). Omitting this symbol helps gdb inspect automatically imported symbols, see https://sourceware.org/bugzilla/show_bug.cgi?id=24574 for discussion on the matter. Surprisingly, those extra symbols don't seem to be an issue for gdb when the sources have been built with clang, only with gcc. The actual logic in gdb that this depends on still is unknown, but omitting these symbols from the symbol table is the right thing to do in any case. Differential Revision: https://reviews.llvm.org/D65727 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367836 91177308-0d34-0410-b5e6-96231b3b80d8 * [MinGW] Add an lld specific option for requesting to delay load libraries With GNU tools, delayload is handled completely differently. (One creates a specific delayload import library using dlltool and then links against it instead of the normal import library.) Instead of requiring using -Xlink=-delayload:lib.dll, we can provide an lld specific option for this. Differential Revision: https://reviews.llvm.org/D65728 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367837 91177308-0d34-0410-b5e6-96231b3b80d8 * Changing representation of .cv_def_range directives in Codeview debug info assembly format for better readability git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367850 91177308-0d34-0410-b5e6-96231b3b80d8 * Revert "Changing representation of .cv_def_range directives in Codeview debug info assembly format for better readability" This reverts commit a885afa9fa8cab3b34f1ddf3d21535f88b662881. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367861 91177308-0d34-0410-b5e6-96231b3b80d8 * Changing representation of .cv_def_range directives in Codeview debug info assembly format for better readability git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367867 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Consistently prioritize non-* wildcards overs "*" in version scripts We prioritize non-* wildcards overs VER_NDX_LOCAL/VER_NDX_GLOBAL "*". This patch generalizes the rule to "*" of other versions and thus fixes PR40176. I don't feel strongly about this GNU linkers' behavior but the generalization simplifies code. Delete `config->defaultSymbolVersion` which was used to special case VER_NDX_LOCAL/VER_NDX_GLOBAL "*". In `SymbolTable::scanVersionScript`, custom versions are handled the same way as VER_NDX_LOCAL/VER_NDX_GLOBAL. So merge `config->versionScript{Locals,Globals}` into `config->versionDefinitions`. Overall this seems to simplify the code. In `SymbolTable::assign{Exact,Wildcard}Versions`, `sym->verdefIndex == config->defaultSymbolVersion` is changed to `verdefIndex == UINT32_C(-1)`. This allows us to give duplicate assignment diagnostics for `{ global: foo; };` `V1 { global: foo; };` In test/linkerscript/version-script.s: vs_index of an undefined symbol changes from 0 to 1. This doesn't matter (arguably 1 is better because the binding is STB_GLOBAL) because vs_index of an undefined symbol is ignored. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D65716 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367869 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][test] Reorganize some tls-*.s tests Some tls-*.s tests do not test generic TLS behavior but rather are x86 specific. Rename them to i386-*.s or x86-64-*.s Delete tls-static.s: covered by tls-opt.s Delete tls-opt-no-plt.s: add --implicit-check-not=.plt to x86-64-tls-gdie.s to cover it Rename tls-dynamic-i686.s to i386-tls-dynamic.s Rename tls-i686.s to i386-tls-le.s Rename tls-opt-i686.s to i386-tls-opt.s Rename tls-opt-iele-i686-nopic.s to i386-tls-opt-iele-nopic.s Rename tls-dynamic.s to x86-64-tls-dynamic.s . IE should be split off in the future. Rename tls-error.s to x86-64-reloc-tpoff32-error.s Rename tls-opt-gdie.s to x86-64-tls-gdie.s Rename tls-opt-x86_64-noplt.s to x86-64-tls-opt-noplt.s Rename tls-opt-local.s => x86-64-tls-ie-opt-local.s . It can be merged with x86-64-tls-ie-local.s in the future. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@367877 91177308-0d34-0410-b5e6-96231b3b80d8 * [MachO] Update LLD to use 64-bit offsets with DataExtractor (3/5) Differential Revision: https://reviews.llvm.org/D65639 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368032 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Make binding (weak or non-weak) logic consistent for Undefined and SharedSymbol This is a case missed by D64136. If %t1.o has a weak reference on foo, and %t2.so has a non-weak reference on foo: ``` 0. ld.lld %t1.o %t2.so # ok; STB_WEAK; accepted since D64136 1. ld.lld %t2.so %t1.o # undefined symbol: foo; STB_GLOBAL 2. gold %t1.o %t2.so # ok; STB_WEAK 3. gold %t2.so %t1.o # undefined reference to 'foo'; STB_GLOBAL 4. ld.bfd %t1.o %t2.so # undefined reference to `foo'; STB_WEAK 5. ld.bfd %t2.so %t1.o # undefined reference to `foo'; STB_WEAK ``` It can be argued that in both cases, the binding of the undefined foo should be set to STB_WEAK, because the binding should not be affected by referenced from shared objects. --allow-shlib-undefined doesn't suppress errors (3,4,5), but -shared or --noinhibit-exec allows ld.bfd/gold to produce a binary: ``` 3. gold -shared %t2.so %t1.o # ok; STB_GLOBAL 4. ld.bfd -shared %t2.so %t1.o # ok; STB_WEAK 5. ld.bfd -shared %t1.o %t1.o # ok; STB_WEAK ``` If %t2.so has DT_NEEDED entries, ld.bfd will load them (lld/gold don't have the behavior). If one of the DSO defines foo and it is in the link-time search path (e.g. DT_NEEDED entry is an absolute path, via -rpath=, via -rpath-link=, etc), `ld.bfd %t1.o %t2.so` and `ld.bfd %t1.o %t2.so` will not error. In this patch, we make Undefined and SharedSymbol share the same binding computing logic. Case 1 will be allowed: ``` 0. ld.lld %t1.o %t2.so # ok; STB_WEAK; accepted since D64136 1. ld.lld %t2.so %t1.o # ok; STB_WEAK; changed by this patch ``` In the future, we can explore the option that turns both (0,1) into errors if --no-allow-shlib-undefined (default when linking an executable) is in action. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D65584 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368038 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][ARM] Fix /DISCARD/ of section with .ARM.exidx section The combineEhSections runs, by design, before processSectionCommands so that input exception sections like .ARM.exidx and .eh_frame are not assigned to OutputSections. Unfortunately if /DISCARD/ removes InputSections that have associated .ARM.exidx sections without discarding the .ARM.exidx synthetic section then we will end up crashing when trying to sort the InputSections in ascending address order. We fix this by filtering out the sections that have been discarded prior to processing the InputSections in finalizeContents(). fixes pr42890 Differential Revision: https://reviews.llvm.org/D65759 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368041 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][PPC] Don't relax ifunc toc-indirect accesses to toc-relative Fixes PR42759. ``` // If ifunc is taken address in -fPIC code, it may have a toc entry .section .toc,"aw",@progbits .quad ifunc // ifunc may be defined as STT_GNU_IFUNC in another object file .type ifunc, %gnu_indirect_function ``` If ifunc is non-preemptable (e.g. when linking an executable), the toc entry will be relocated by R_PPC64_IRELATIVE. R_*_IRELATIVE represents the symbolic value of a non-preemptable ifunc (not associated with a canonical PLT) in a writable location. It has an unknown value at link time, so we cannot apply toc-indirect to toc-relative relaxation. Reviewed By: luporl, sfertile Differential Revision: https://reviews.llvm.org/D65755 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368057 91177308-0d34-0410-b5e6-96231b3b80d8 * [WebAssembly] Fix null pointer in createInitTLSFunction Summary: `createSyntheticSymbols`, which creates `WasmSym::InitTLS`, is only called when `!config->relocatable`, but this condition is not checked when calling `createInitTLSFunction`. This diff checks `!config->relocatable` before calling `createInitTLSFunction`. Fixes https://github.com/emscripten-core/emscripten/issues/9155. Reviewers: tlively, aheejin, kripken, sbc100 Subscribers: dschuff, jgravelle-google, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65785 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368078 91177308-0d34-0410-b5e6-96231b3b80d8 * Re-submit r367649: Improve raw_ostream so that you can "write" colors using operator<< The original patch broke buildbots, perhaps because it changed the default setting whether colors are enabled or not. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368131 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][X86] Add --no-show-raw-insn and -soname to some i386 tests git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368142 91177308-0d34-0410-b5e6-96231b3b80d8 * Simplify error message output. NFC. Differential Revision: https://reviews.llvm.org/D65855 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368144 91177308-0d34-0410-b5e6-96231b3b80d8 * Handle /align option. Differential Revision: https://reviews.llvm.org/D65736 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368145 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Fix splitting messages for duplicate symbols. D65213 (rL367536) does not work for the case when a source file path includes subdirectories. Differential Revision: https://reviews.llvm.org/D65810 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368153 91177308-0d34-0410-b5e6-96231b3b80d8 * Try to fix windows build bots after r368153. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368169 91177308-0d34-0410-b5e6-96231b3b80d8 * API update for change to LLVM's lib/DebugInfo/DWARF git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368190 91177308-0d34-0410-b5e6-96231b3b80d8 * Add a test demonstrating DWARF parse failures are not causing lld to exit non-zero This bug was/is masking other issues - committing this to demonstrate the problem/track fixing it. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368220 91177308-0d34-0410-b5e6-96231b3b80d8 * gdb-index: Wire up str_offsets section to avoid incorrect error message about offsets_base There's still a need for a deeper fix to the way libDebugInfoDWARF error messages are propagated up to lld - if lld had exited non-zero on this error message we would've found the issue sooner. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368229 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][AArch64] Support for movz, movk tprel relocations This patch Implements the R_AARCH64_TLSLE_MOVW_TPREL_G*[_NC]. These are logically the same calculation as the existing TLSLE relocations with the result written back to mov[nz] and movk instructions. A typical code sequence is: movz x0, #:tprel_g2:foo // bits [47:32] of R_TLS with overflow check movk x0, #:tprel_g1_nc:foo // bits [31:16] of R_TLS with no overflow check movk x0, #:tprel_g0_nc:foo // bits [15:0] of R_TLS with no overflow check This type of code sequence is usually used with a large code model. Differential Revision: https://reviews.llvm.org/D65882 Fixes: PR42853 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368293 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][AArch64] Delete two unused RUN lines from aarch64-movw-tprel.s after D65882 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368298 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][WebAssembly] Add optional symbols after input file handling This allows undefined references in input files be resolved by the optional symbols. Previously we were doing this before input file reading which means it was working only for command line symbols references (i.e. -u or --export). Also use addOptionalDataSymbol for __dso_handle and make all optional symbols hidden by default. Differential Revision: https://reviews.llvm.org/D65920 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368310 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][WebAssembly] Use createGlobalVariable helper function. NFC. Differential Revision: https://reviews.llvm.org/D65911 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368325 91177308-0d34-0410-b5e6-96231b3b80d8 * [WebAssembly][lld] control __data_end export with config->shared Summary: Emscripten expects `__data_end` to show up in PIC code as long as it's not linked with `--shared`. Currently, Emscripten breaks with latest LLVM because `__data_end` is controlled by `config->isPic` instead of `config->shared`.` Reviewers: tlively, sbc100 Reviewed By: sbc100 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65980 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368361 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][WebAssembly] Don't create optional symbols when outputing an object file Summary: This was a bug in rL368310. I'm working on a test case now. Differential Revision: https://reviews.llvm.org/D65985 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368369 91177308-0d34-0410-b5e6-96231b3b80d8 * ELF: Move sections referred to by __start_/__stop_ symbols into the main partition. In the case where C identifier sections have SHF_LINK_ORDER they will most likely be placed in the same partition as the section that they are associated with. But unless this happens to be the main partition, this will cause them to be excluded from the range covered by the __start_ and __stop_ symbols, which may lead to incorrect program behaviour. So we need to move them all into the main partition so that they will be covered by the __start_ and __stop_ symbols. We may want to refine this approach later and allow different __start_/__stop_ symbol values for different partitions. This would only make sense for relocations from SHT_NOTE sections since they are duplicated into each partition. Differential Revision: https://reviews.llvm.org/D65909 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368375 91177308-0d34-0410-b5e6-96231b3b80d8 * DebugInfo: Explicitly handle errors when parsing unit DIEs This ensures these errors produce a non-zero exit and improves the context (providing the name of the input object and section being parsed). git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368378 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Expand regions for gaps due to explicit address If the dot gets moved by an explicit section address, an empty gap between sections could be created. The encompassing region for the section being parsed needs to be expanded to include the gap. Differential Revision: https://reviews.llvm.org/D65722 Patch by Gabriel Smith! git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368379 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] For VS-style diagnostics, prefer printing full paths in the header. The filename part in the message header is used by Visual Studio to fill Error List so that a user can click on an item and jump to the mentioned location. If we use only the name of a source file and not the full path, Visual Studio might be unable to find the right file or, even worse, show a wrong one. Differential Revision: https://reviews.llvm.org/D65875 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368409 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Remove unnecessary assignment to `used` in replaceWithDefined `Symbol::used` is used by Undefined and SharedSymbol to record if a .symtab entry is needed. It is of no use for Defined. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368533 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Remove redundant !isPreemptible in Symbol::computeBinding() !isPreemptible was added in r343668 to fix PR39104: symbols redefined by replaceWithDefined() might be incorrectly considered STB_LOCAL if a version script specified `local: *;`. After r367869 (`config->defaultSymbolVersion` was removed), we will assign VER_NDX_LOCAL to only regular Defined and CommonSymbol, not Defined created by replaceWithDefined() (because scanVersionScript() is called before scanRelocations()). The !isPreemptible is thus redundant and can be deleted. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368535 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Remove redundant isDefined() in Symbol::computeBinding() and delete one redundant call site After r367869, VER_NDX_LOCAL can only be assigned to Defined and CommonSymbol. CommonSymbol becomes Defined after replaceCommonSymbols(), thus `versionId == VER_NDX_LOCAL` will imply `isDefined()`. In maybeReportUndefined(), computeBinding() is called when the symbol is unknown to be Undefined. computeBinding() != STB_LOCAL will always be true. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368536 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Remove unnecessary assignment to `isPreemptible` in replaceWithDefined() After r368535, it is no longer used in the handling of VER_NDX_LOCAL. Drop it. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368550 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld] Remove unnecessary "class Lazy" git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368644 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][test] Add dynamic-list-preempt2.s When producing a DSO, the isPreemptible property of a Defined with default or protected visibility is affected by the --dynamic-list file, but not by interposable symbols in other DSOs. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368649 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Rename odd variable names "New" after r365730. NFC New -> newSym or newFlags Reviewed By: atanasyan Differential Revision: https://reviews.llvm.org/D66127 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368651 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Simplify handling of exportDynamic and isPreemptible In Writer::includeInDynSym(), exportDynamic is used by a Defined with protected or default visibility, to record whether it is required to be exported into .dynsym. It is set when any of the following conditions hold: 1) There is an interposable symbol from a DSO (Undefined or SharedSymbol with default visibility) 2) If -shared or --export-dynamic is specified, any symbol in an object file/bitcode sets this property, unless suppressed by canBeOmittedFromSymbolTable(). 3) --dynamic-list when producing an executable 4) protected symbol from a DSO preempted by copy relocation/canonical PLT when --ignore-{data,function}-address-equality is specified 5) ifunc is exported when -z ifunc-noplt is specified Bullet points 4) and 5) are irrelevant in this patch. Bullet 3) does not play well with 1) and 2). When -shared is specified, exportDynamic of most symbols is true. This makes it incapable to record --dynamic-list marked symbols. We thus have obscure: if (!config->shared) b->exportDynamic = true; else if (b->includeInDynsym()) b->isPreemptible = true; This patch adds another bit `Symbol::inDynamicList` to record 3). We can thus simplify handleDynamicList() by unifying the DSO and executable cases. It also allows us to simplify isPreemptible - now the field is only used in finalizeSections() and later stages. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D66091 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368659 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Don't special case symbolic relocations with 0 addend to ifunc in writable locations Currently the following 3 relocation types do not trigger the creation of a canonical PLT (which changes STT_GNU_IFUNC to STT_FUNC and redirects all references): 1) GOT-generating (`needsGot`) 2) PLT-generating (`needsPlt`) 3) R_ABS with 0 addend in a writable location. This is used for for ifunc function pointers in writable sections such as .data and .toc. This patch deletes case 3) to simplify the R_*_IRELATIVE generating logic added in D57371. Other advantages: * It is guaranteed no more than 1 R_*_IRELATIVE is created for an ifunc. * PPC64: no need to special case ifunc in toc-indirect to toc-relative relaxation. See D65755 The deleted elf::addIRelativeRelocs demonstrates that one-pass scan through relocations makes several optimizations difficult. This is something we can think about in the future. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D65995 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368661 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][test] Update test to print ELF note description data git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368710 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][WebAssembly] Allow linking of pic code into static binaries Summary: See https://github.com/emscripten-core/emscripten/issues/9013 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65922 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368719 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Initialize 2 fields of Symbol in SymbolTable::insert A new symbol is added to elf::symtab in 3 steps: 1) SymbolTable::insert creates a placeholder. 2) Symbol::mergeProperties 3) Symbol::replace Fields referenced by steps 2) and 3) should be initialized in SymbolTable::insert. `traced` and `referenced` were missed previously. This did not cause problems because compilers generated code that initialized them (bit fields) to 0. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D66130 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368784 91177308-0d34-0410-b5e6-96231b3b80d8 * [MinGW] Remove stray/inconsistent comment chars in test file. NFC. Test directives don't need to be in comments in this file. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368814 91177308-0d34-0410-b5e6-96231b3b80d8 * [MinGW] Restructure Options.td to use multiclass where sensible. NFC. Differential Revision: https://reviews.llvm.org/D66065 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368815 91177308-0d34-0410-b5e6-96231b3b80d8 * [MinGW] Correct handling different forms of a few options Support the equals form of the long --entry= option, add a test for the -e form. Add tests for single dash forms of -exclude-all-symbols and -export-all-symbols. Support single-dash forms of -out-implib and -output-def, support the equals form of --output-def=. (We previously had a test to explicitly disallow -out-implib, but it turns out that GNU ld actually does support it just fine, despite also matching the -o option.) Disallow the double-dashed --u form, add a test for -u. Differential Revision: https://reviews.llvm.org/D66066 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368816 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][test] Update silent-ignore.test Some options are implemented now: --no-warn-common : r263413 --allow-shlib-undefined : r352826 Some are ignored but were not reflected in this test. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368837 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] --gdb-index: fix odd variable name cUs after r365730 and replace lower_bound with partition_point. NFC git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368845 91177308-0d34-0410-b5e6-96231b3b80d8 * [LLD] Migrate llvm::make_unique to std::make_unique Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368936 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][PPC] Improve error message for unknown relocations Like rLLD354040. Previously, for unrecognized relocation types, in -no-pie mode: foo.o: unrecognized reloc 256 In -pie/-shared mode: error: can't create dynamic relocation R_PPC_xxx against symbol: yyy in readonly segment git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368964 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][AArch64] Improve error message for unknown relocations Like rLLD354040. Previously, for unrecognized relocation types, in -no-pie/-pie mode, we got something like: foo.o: unrecognized relocation ... In -shared mode: error: can't create dynamic relocation ... against symbol: yyy in readonly segment Delete the default case from AArch64::getRelExpr and add the error there. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D66277 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@368983 91177308-0d34-0410-b5e6-96231b3b80d8 * Fix lld on GCC 5.1 after the C++14 move Summary: libstdc++ in GCC 5.1 has some bugs. The move to C++14 in D66195 triggered one such bug caused by the new constexpr support in C++14, and the implementation doing SFINAE wrong with the comparator to std::stable_sort. Here's a small repro: https://godbolt.org/z/2QC3-n The fix is to inline the lambdas directly into the llvm::stable_sort call instead of erasing them through a std::function. The code is more readable as well. Reviewers: thakis, ruiu, espindola Subscribers: emaste, arichardson, MaskRay, jkorous, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66306 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369023 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][Hexagon]Support HEX_32 when building shared objects Differential Revision: https://reviews.llvm.org/D66105 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369121 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][Hexagon] Replace R_HEXAGON_GOT with R_GOTPLT R_GOTPLT is relative to .got.plt since D59594. Since R_HEXAGON_GOT relocations always have 0 r_addend, they can use R_GOTPLT instead. Reviewed By: sidneym Differential Revision: https://reviews.llvm.org/D66274 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369128 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][PPC] Fix getRelExpr for R_PPC64_REL16_HI Fixes https://github.com/ClangBuiltLinux/linux/issues/640 R_PPC64_REL16_HI was incorrectly computed as an R_ABS relocation. rLLD368964 made it a linker failure. Change it to use R_PC to fix the failures. Add ppc64-reloc-rel.s for these R_PPC64_REL* tests. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369184 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Replace local variable hasExportDynamic with config->exportDynamic. NFC git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369187 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][ARM] Add a test that maxes out the thunk convergence limit Add a test that takes the maximum amount of passes permitted to converge. This will make sure that any symbol defined in a linker script gets the correct value and that any other convergence limit involving symbol address doesn't restrict Thunk convergence. Differential Revision: https://reviews.llvm.org/D66346 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369246 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][Hexagon] Add GOTREL relocations. Add GOTREL relocation support. (S + A - GOT) Differential Revision: https://reviews.llvm.org/D66260 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369258 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][Hexagon] Improve error message for unknown relocations Like rLLD354040 Previously, for unknown relocation types, in -no-pie/-pie mode, we got something like: foo.o: unrecognized relocation ... In -shared mode: error: can't create dynamic relocation ... against symbol: yyy in readonly segment Delete the default case from Hexagon::getRelExpr and add the error there. We will get consistent error message like `error: unknown relocation (1024) against symbol foo` Reviewed By: sidneym Differential Revision: https://reviews.llvm.org/D66275 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369260 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Move (copy relocation/canonical PLT) before error checking In processRelocAux(), we handle errors before copy relocation/canonical PLT. This makes error checking a bit complex because we have to check for conditions that will be allowed by copy relocation/canonical PLT. Instead, move copy relocation/canonical PLT before error checking. This simplifies the previous clumsy error checking code `config->shared || (config->pie && expr == R_ABS && type != target->symbolicRel)` to the simple `config->isPic`. Some diagnostics can be reported in different ways. The code motion changes diagnostics for some contrived test cases: * copy-rel-pie-error.s -> copy-rel-pie2.s: It was rejected before but accepted now. ld.bfd also accepts the case. * copy-errors.s: "cannot preempt symbol" changes to "symbol 'bar' has no type" * got32{,x}-i386.s: the suggestion changes from "-fPIC or -Wl,-z,notext" to "-fPIE" * x86-64-dyn-rel-error5.s: one diagnostic changes for -pie case Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D66007 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369262 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Simplify processRelocAux and allow a corner-case error After D66007/r369262, if the control flow reaches `if (sym.isUndefined())`, we know: * The relocation is not a link-time constant => symbol is preemptable => Undefined or SharedSymbol * Not an undef weak. * -no-pie. * The symbol type is neither STT_OBJECT nor STT_FUNC. ld.lld --export-dynamic --unresolved-symbols=ignore-all %t.o can satisfy these conditions. Delete the isUndefined() test so that we error `symbol '...' has no type`, because we don't know the type to make the decision to create copy relocation/canonical PLT. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369271 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][WebAssembly] Honor --no-export-dynamic even with -shared Differential Revision: https://reviews.llvm.org/D66359 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369276 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][PPC] Allow PT_LOAD to have overlapping p_offset ranges This change affects the non-linker script case (precisely, when the `SECTIONS` command is not used). It deletes 3 alignments at PT_LOAD boundaries for the default case: the size of a powerpc64 binary can be decreased by at most 192kb. The technique can be ported to other targets. Let me demonstrate the idea with a maxPageSize=65536 example: When assigning the address to the first output section of a new PT_LOAD, if the end p_vaddr of the previous PT_LOAD is 0x10020, we advance to the next multiple of maxPageSize: 0x20000. The new PT_LOAD will thus have p_vaddr=0x20000. Because p_offset and p_vaddr are congruent modulo maxPageSize, p_offset will be 0x20000, leaving a p_offset gap [0x10020, 0x20000) in the output. Alternatively, if we advance to 0x20020, the new PT_LOAD will have p_vaddr=0x20020. We can pick either 0x10020 or 0x20020 for p_offset! Obviously 0x10020 is the choice because it leaves no gap. At runtime, p_vaddr will be rounded down by pagesize (65536 if pagesize=maxPageSize). This PT_LOAD will load additional initial contents from p_offset ranges [0x10000,0x10020), which will also be loaded by the previous PT_LOAD. This is fine if -z noseparate-code is in effect or if we are not transiting between executable and non-executable segments. ld.bfd -z noseparate-code leverages this technique to keep output small. This patch implements the technique in lld, which is mostly effective on targets with large defaultMaxPageSize (AArch64/MIPS/PPC: 65536). The 3 removed alignments can save almost 3*65536 bytes. Two places that rely on p_vaddr%pagesize = 0 have to be updated. 1) We used to round p_memsz(PT_GNU_RELRO) up to commonPageSize (defaults to 4096 on all targets). Now p_vaddr%commonPageSize may be non-zero. The updated formula takes account of that factor. 2) Our TP offsets formulae are only correct if p_vaddr%p_align = 0. Fix them. See the updated comments in InputSection.cpp for details. On targets that we enable the technique (only PPC64 now), we can potentially make `p_vaddr(PT_TLS)%p_align(PT_TLS) != 0` if `sh_addralign(.tdata) < sh_addralign(.tbss)` This exposes many problems in ld.so implementations, especially the offsets of dynamic TLS blocks. Known issues: FreeBSD 13.0-CURRENT rtld-elf (i386/amd64/powerpc/arm64) glibc (HEAD) i386 and x86_64 https://sourceware.org/bugzilla/show_bug.cgi?id=24606 musl<=1.1.22 on TLS Variant I architectures (aarch64/powerpc64/...) So, force p_vaddr%p_align = 0 by rounding dot up to p_align(PT_TLS). The technique will be enabled (with updated tests) for other targets in subsequent patches. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D64906 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369343 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][AArch64] Allow PT_LOAD to have overlapping p_offset ranges Ported the D64906 technique to AArch64. It deletes 3 alignments at PT_LOAD boundaries for the default case: the size of an aarch64 binary decreases by at most 192kb. If `sh_addralign(.tdata) < sh_addralign(.tbss)`, we can potentially make `p_vaddr(PT_TLS)%p_align(PT_TLS) != 0`. ld.so that are known to have problems if p_vaddr%p_align!=0: * musl<=1.1.22 * FreeBSD 13.0-CURRENT (and before) rtld-elf arm64 New test aarch64-tls-vaddr-align.s checks that our workaround makes p_vaddr%p_align = 0. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D64930 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369344 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][X86] Allow PT_LOAD to have overlapping p_offset ranges on EM_386 Ported the D64906 technique to EM_386. If `sh_addralign(.tdata) < sh_addralign(.tbss)`, we can potentially make `p_vaddr(PT_TLS)%p_align(PT_TLS) != 0`. ld.so that are known to have problems if p_vaddr%p_align!=0: * FreeBSD 13.0-CURRENT rtld-elf * glibc https://sourceware.org/bugzilla/show_bug.cgi?id=24606 New test i386-tls-vaddr-align.s checks our workaround makes p_vaddr%p_align = 0. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D65865 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369347 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][PPC] Allow PT_LOAD to have overlapping p_offset ranges on EM_PPC Ported the D64906 technique to EM_PPC. Delete ppc-rela.s that is covered by ppc32-abs-pic.s git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369351 91177308-0d34-0410-b5e6-96231b3b80d8 * [COFF] Allow using custom .edata from input object files This is used by Wine for manually crafting export tables. If the input object contains .edata sections, GNU ld references them in the export directory instead of synthesizing an export table using either export directives or the normal auto export mechanism. (AFAIK, historically, way way back, GNU ld didn't support synthesizing the export table - one was supposed to generate it using dlltool and link it in instead.) If faced with --out-implib and --output-def, GNU ld still populates those output files with the same export info as it would have generated otherwise, disregarding the input .edata. As this isn't an intended usage combination, I'm not adding checks for that in tests. Differential Revision: https://reviews.llvm.org/D65903 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369358 91177308-0d34-0410-b5e6-96231b3b80d8 * [COFF] Require an explicit -implib option for creating implibs in mingw mode GNU ld doesn't produce implibs unless explicitly requested. Differential Revision: https://reviews.llvm.org/D66367 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369363 91177308-0d34-0410-b5e6-96231b3b80d8 * [WebAssembly][lld] Fix crash when applying relocations to debug sections Debug sections are special in that they can contain relocations against symbols that are not present in the final output (i.e. not live). However it is also possible to have R_WASM_TABLE_INDEX relocations against symbols that don't have a table index assigned (since they are not address taken by actual code. Fixes: https://github.com/emscripten-core/emscripten/issues/9023 Differential Revision: https://reviews.llvm.org/D66435 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369423 91177308-0d34-0410-b5e6-96231b3b80d8 * [COFF] Print the file name on errors writing the pdb file This avoids confusing contextless error messages such as "No such file or directory" if e.g. the pdb output file should be written to a nonexistent directory. (This can happen with linkrepro scripts, at least old ones.) Differential Revision: https://reviews.llvm.org/D66466 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369425 91177308-0d34-0410-b5e6-96231b3b80d8 * [COFF] Check errorCount before committing the output file This avoids producing an output file if errors appeared late in the linking process (e.g. while fixing relocations, or as in the test, while checking for multiple resources). If an output file is produced, build tools might not retry building it on rebuilds, even if a previous build failed due to the error return code. Differential Revision: https://reviews.llvm.org/D66491 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369445 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] More dynamic relocation packing Currently, with Android dynamic relocation packing, only relative relocations are grouped together. This patch implements similar packing for non-relative relocations. The implementation groups non-relative relocations with the same r_info and r_addend, if using RELA. By requiring a minimum group size of 3, this achieves smaller relocation sections. Building Android for an ARM32 device, I see the total size of /system/lib decrease by 392 KB. Grouping by r_info also allows the runtime dynamic linker to implement an 1-entry cache to reduce the number of symbol lookup required. With such 1-entry cache implemented on Android, I'm seeing 10% to 20% reduction in total time spent in runtime linker for several executables that I tested. As a simple correctness check, I've also built x86_64 Android and booted successfully. Differential Revision: https://reviews.llvm.org/D66491 Patch by Vic Yang! git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369488 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][test] Add CHECK lines omitted in r369488 Add append .o to some object file names git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369489 91177308-0d34-0410-b5e6-96231b3b80d8 * Revert D65242 "[ELF] More dynamic relocation packing" This reverts r369488 and r369489. The change broke build bots: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-ubsan/builds/14511 http://lab.llvm.org:8011/builders/lld-x86_64-freebsd/builds/34407 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369497 91177308-0d34-0410-b5e6-96231b3b80d8 * Reland D65242 "[ELF] More dynamic relocation packing"" This fixed a bug in r369488. When config->isRela is false, i->r_addend is not initialized (see encodeDynamicReloc). So we should check config->isRela before accessing r_addend: - if (j - i < 3 || i->r_addend) + if (j - i < 3 || (config->isRela && i->r_addend != 0)) Original description: Currently, with Android dynamic relocation packing, only relative relocations are grouped together. This patch implements similar packing for non-relative relocations. The implementation groups non-relative relocations with the same r_info and r_addend, if using RELA. By requiring a minimum group size of 3, this achieves smaller relocation sections. Building Android for an ARM32 device, I see the total size of /system/lib decrease by 392 KB. Grouping by r_info also allows the runtime dynamic linker to implement an 1-entry cache to reduce the number of symbol lookup required. With such 1-entry cache implemented on Android, I'm seeing 10% to 20% reduction in total time spent in runtime linker for several executables that I tested. As a simple correctness check, I've also built x86_64 Android and booted successfully. Differential Revision: https://reviews.llvm.org/D65242 Patch by Vic Yang git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369507 91177308-0d34-0410-b5e6-96231b3b80d8 * [LLD][ELF] - Simplify the bad-archive.s test case. This removes the precompiled binary and improves the check of the error reported. Differential revision: https://reviews.llvm.org/D66523 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369516 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][ARM] Simplify some llvm-objdump tests with both ARM/Thumb states llvm-objdump can switch between ARM/Thumb states after D60927. In a few lld tests, we run both * llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t * llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t to test ARM/Thumb parts of the same file. In many cases we can just run one command. There is a problem that prevents us from cleaning more tests (e.g. test/ELF/arm-thumb-interwork-thunk.s): In llvm-objdump, while we have ARM/Thumb (primary and secondary) MCDisassembler and MCSubtargetInfo, we have just one MCInstrAnalysis which is used to resolve the targets of calls in both ARM/Thumb parts. // ThumbMCInstrAnalysis evaluating ARM parts or ARMMCInstrAnalysis evaluating Thumb parts // will have incorrect offsets. // An example of llvm-objdump -d -triple=thumbv7a on ARM part: 1304: 3d ff ff fa blx #-780 # no <...> 1308: 06 00 00 ea b #24 # wrong target due to wrong offset Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D66539 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369535 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld-link] implement -lto-obj-path Summary: This adds the -lto-obj-path option to lld-link. This can be used to specify a path at which to write a native object file for the full LTO part when using LTO unit splitting. Reviewers: ruiu, tejohnson, pcc, rnk Reviewed By: ruiu, rnk Subscribers: mehdi_amini, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65964 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369559 91177308-0d34-0410-b5e6-96231b3b80d8 * [COFF] Add libcall symbols to the link when LTO is being used git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369694 91177308-0d34-0410-b5e6-96231b3b80d8 * Fight a bit against global initializers. NFC. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369695 91177308-0d34-0410-b5e6-96231b3b80d8 * Add a description about multiple linker scripts Differential Revision: https://reviews.llvm.org/D66630 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369737 91177308-0d34-0410-b5e6-96231b3b80d8 * Explain --reproduce option I think --reproduce is no longer a debug-only option but a useful option that a common user may want to use. So, this patch updates the description of the option in the manual page. Differential Revision: https://reviews.llvm.org/D60557 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369740 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Mention contents of reproduce archive and add help description. Building on D60557 mention the name of the linker generated contents of the reproduce archive, response.txt and version.txt. Also write a shorter description in the ld.lld --help that is closer to the documentation. Differential Revision: https://reviews.llvm.org/D66641 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369762 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Align the first section of a PT_LOAD even if its type is SHT_NOBITS Reported at https://reviews.llvm.org/D64930#1642223 If the only section of a PT_LOAD is a SHT_NOBITS section (e.g. .bss), we may not align its sh_offset. p_offset of the PT_LOAD will be set to sh_offset, and we will get p_offset!=p_vaddr (mod p_align). If such executable is mapped by the Linux kernel, it will segfault. After D64906, this may happen the non-linker script case. The linker script case has had this issue for a long time. This was fixed by rL321657 (but the test linkerscript/nobits-offset.s failed to test a SHT_NOBITS section), but broken by rL345154. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D66658 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369828 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Make member function Writer::removeEmptyPTLoad non-member. NFC git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369838 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Simplify with less_second. NFC git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369844 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Delete a redundant dyn_cast. NFC git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369868 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Error if --strip-all and --emit-relocs are used together --strip-all suppresses the creation of in.symtab This can cause a null pointer dereference in OutputSection::finalize() // --emit-relocs => copyRelocs is true if (!config->copyRelocs || (type != SHT_RELA && type != SHT_REL)) return; ... link = in.symTab->getParent()->sectionIndex; // in.symTab is null Let's just disallow the combination. In some cases the combination can cause GNU linkers to fail: * ld.bfd: final link failed: invalid operation * gold: internal error in set_no_output_symtab_entry, at ../../gold/object.h:1814 Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D66704 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369878 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Make LinkerScript::assignAddresses iterative PR42990. For `SECTIONS { b = a; . = 0xff00 + (a >> 8); a = .; }`, we currently set st_value(a)=0xff00 while st_value(b)=0xffff. The following call tree demonstrates the problem: ``` link(Args); Script->declareSymbols(); // insert a and b as absolute Defined Writer().run(); Script->processSectionCommands(); addSymbol(cmd); // a and b are re-inserted. LinkerScript::getSymbolValue // is lazily called by subsequent evaluation finalizeSections(); forEachRelSec(scanRelocations); processRelocAux // another problem PR42506, not affected by this patch finalizeAddressDependentContent(); // loop executed once script->assignAddresses(); // a = 0, b = 0xff00 script->assignAddresses(); // a = 0xff00, _end = 0xffff ``` We need another assignAddresses() to finalize the value of `a`. This patch 1) modifies assignAddress() to track the original section/value of each symbol and return a symbol whose section/value has changed. 2) moves the post-finalizeSections assignAddress() inside the loop of finalizeAddressDependentContent() and makes it iterative. Symbol assignment may not converge so we make a few attempts before bailing out. Note, assignAddresses() must be called at least twice. The penultimate call finalized section addresses while the last finalized symbol values. It is somewhat obscure and there was no comment. linkerscript/addr-zero.test tests this. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D66279 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369889 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] EhFrameSection: postpone FDE liveness check to finalizeSections EhFrameSection::addSection checks liveness of FDE early. This makes it infeasible to move combineEhSections() before ICF. Postpone the check to EhFrameSection::finalizeContents(). This is what ARMExidxSyntheticSection does and it will make a subsequent patch D66717 simpler. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D66727 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369890 91177308-0d34-0410-b5e6-96231b3b80d8 * Copy test data so tests don't traverse test directories. NFC git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@369984 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][WebAssembly] Store table base in config rather than passing it around. NFC. I've got another change that makes more use of this value in other places. Differential Revision: https://reviews.llvm.org/D66777 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370010 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][WebAssembly] Create optional symbols after handling --export/--undefined Handling of --export/--undefined can pull in lazy symbols which in turn can pull in referenced to optional symbols. We need to delay the creation of optional symbols until all possible references to them have been created. Differential Revision: https://reviews.llvm.org/D66768 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370012 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][ARM] Add --no-show-raw-insn and -soname to some ARM tests Delete some insignificant addresses to make it simpler for layout changes. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370048 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][ARM] Allow PT_LOAD to have overlapping p_offset ranges on EM_ARM Port the D64906 technique to ARM. It deletes 3 alignments at PT_LOAD boundaries for the default case: the size of an arm binary decreases by at most 12kb. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D66749 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370049 91177308-0d34-0410-b5e6-96231b3b80d8 * Change the X86 datalayout to add three address spaces for 32 bit signed, 32 bit unsigned, and 64 bit pointers. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370083 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][WebAssembly] Support for growable tables Adds --growable-table flag to handle building wasm modules with tables that can grow. Wasm tables that we use to store function pointers. In order to add functions to that table at runtime, we need to either preallocate space, or grow the table. In order to specify a table with no maximum size, we need some flag to handle that case, separately from a potential --max-table-size= flag. Note that the number of elements in the table isn't knowable until link-time, so it's unclear if we will want a --max-table-size= flag in the future. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370127 91177308-0d34-0410-b5e6-96231b3b80d8 * Revert "Change the X86 datalayout to add three address spaces for 32 bit signed," This reverts commit r370083 because it caused check-lld failures on sanitizer-x86_64-linux-fast. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370142 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][RISCV] Assign st_shndx of __global_pointer$ to 1 if .sdata does not exist This essentially reverts the code change of D63132 and switches to a simpler approach. In an executable/shared object, st_shndx of a symbol can be: 1) SHN_UNDEF: undefined symbol (or canonical PLT) 2) SHN_ABS: absolute symbol 3) any other value (usually a regular section index) represents a relative symbol. The actual value does not matter. Many ld.so (musl, all archs except MIPS of FreeBSD rtld-elf) even treat 2) and 3) the same. If .sdata does not exist, it does not matter what value/section __global_pointer$ has, as long as it is relative (otherwise there will be a pedantic lld error. See D63132). Just set the st_shndx arbitrarily to 1. Dummy st_shndx=1 may be used by __rela_iplt_start, linker-script-defined symbols outside a section, __dso_handle, etc. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D66798 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370172 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][AMDGPU][SPARC] Allow PT_LOAD to have overlapping p_offset ranges on EM_AMDGPU and EM_SPARCV9 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370180 91177308-0d34-0410-b5e6-96231b3b80d8 * [mach-o] Extend LC_DATA_IN_CODE support to x86_64 Patch by LemonBoy Differential Revision: https://reviews.llvm.org/D62185 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370183 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF][RISCV] Allow PT_LOAD to have overlapping p_offset ranges on EM_RISCV Port the D64906 technique to RISC-V. It deletes 3 alignments at PT_LOAD boundaries for the default case: the size of a RISC-V binary decreases by at most 12kb. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370192 91177308-0d34-0410-b5e6-96231b3b80d8 * lld: Make a test not fail if "repro" is part of the build directory name r268231 made it so that the name of the --reproduce archive is no longer listed in the response file. Previously, with "--reproduce repro.tar" the response file would contain repro/home/.../llvm-build-dir/.../foo.o but after that change it contained home/.../llvm-build-dir/.../foo.o instead. The test added for this in r268231 checked that the response file doesn't contain the string "repro", but if the build dir is named e.g. "llvm-build-repro" then the test fails because of that. Change the assert to check that "repro" doesn't exist at the beginning of the line instead. I verified that the test still fails with r268231 reverted. The test technically still fails if someone builds llvm in a directory '/repro' below the root directory. Don't do that :) git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370211 91177308-0d34-0410-b5e6-96231b3b80d8 * [WebAssembly] Implement NO_STRIP This patch implements support for the NO_STRIP flag, which will allow __attribute__((used)) to be implemented. This accompanies https://reviews.llvm.org/D62542, which moves to setting the NO_STRIP flag, and will continue to set EXPORTED for Emscripten targets for compatibility. Differential Revision: https://reviews.llvm.org/D66968 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370416 91177308-0d34-0410-b5e6-96231b3b80d8 * [LLD] [COFF] Support merging resource object files Extend WindowsResourceParser to support using a ResourceSectionRef for loading resources from an object file. Only allow merging resource object files in mingw mode; keep the existing error on multiple resource objects in link mode. If there only is one resource object file and no .res resources, don't parse and recreate the .rsrc section, but just link it in without inspecting it. This allows users to produce any .rsrc section (outside of what the parser supports), just like before. (I don't have a specific need for this, but it reduces the risk of this new feature.) Separate out the .rsrc section chunks in InputFiles.cpp, and only include them in the list of section chunks to link if we've determined that there only was one single resource object. (We need to keep other chunks from those object files, as they can legitimately contain other sections as well, in addition to .rsrc section chunks.) Differential Revision: https://reviews.llvm.org/D66824 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370436 91177308-0d34-0410-b5e6-96231b3b80d8 * [ELF] Set `referenced` bit of Undefined created by BitcodeFile D64136 and D65584, while fixing STB_WEAK issues and improving our compatibility with ld.bfd, can cause another STB_WEAK problem related to LTO: If %tundef.o has an undefined reference on f, and %tweakundef.o has a weak undefined reference on f, %tdef.o has a definition of f ``` ld.lld %tundef.o %tweakundef.o --start-lib %tdef.o --end-lib ``` 1) `%tundef.o` doesn't set the `referenced` bit. 2) `%weakundef.o` changes the binding from STB_GLOBAL to STB_WEAK 3) `%tdef.o` is not fetched because the binding is weak. Step (1) is incorrect. This patch sets the `referenced` bit of Undefined created by bitcode files. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D66992 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370437 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld-link] implement -start-lib and -end-lib Summary: This implements -start-lib and -end-lib flags for lld-link, analogous to the similarly named options in ld.lld. Object files after -start-lib are included in the link only when needed to resolve undefined symbols. The -end-lib flag goes back to the normal behavior of always including object files in the link. This mimics the semantics of static libraries, but without needing to actually create the archive file. Reviewers: ruiu, smeenai, MaskRay Reviewed By: ruiu, MaskRay Subscribers: akhuang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66848 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370487 91177308-0d34-0410-b5e6-96231b3b80d8 * [LLD] [COFF] Add a missing REQUIRES line to a recently added test. NFC. This should fix failing buildbots like http://lab.llvm.org:8011/builders/clang-cmake-aarch64-lld/builds/7180. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370491 91177308-0d34-0410-b5e6-96231b3b80d8 * [lld][WebAssembly] Fix spurious signature mismatch warnings Summary: This a follow up on: https://reviews.llvm.org/D62153 Handle the case where there are multiple object files that contain undefined references to the same function. We only generate a function variant if the existing symbol is directly called. See: https://github.com/emscripten-core/emscripten/issues/8995 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67015 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370509 91177308-0d34-0410-b5e6-96231b3b80d8 * Revert "[lld-link] implement -start-lib and -end-lib" This reverts commit r370487 as it is causing ASan/MSan failures on sanitizer-x86_64-linux-fast git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@370550 91177308-0d34-0410-b5e6-96231b3b80d8 --- COFF/Config.h | 5 + COFF/DLL.cpp | 2 +- COFF/Driver.cpp | 94 ++-- COFF/Driver.h | 7 +- COFF/DriverUtils.cpp | 42 +- COFF/InputFiles.cpp | 10 +- COFF/InputFiles.h | 10 +- COFF/LTO.cpp | 10 +- COFF/MapFile.cpp | 6 +- COFF/MinGW.cpp | 2 +- COFF/Options.td | 3 + COFF/PDB.cpp | 3 +- COFF/SymbolTable.cpp | 16 +- COFF/SymbolTable.h | 1 + COFF/Symbols.cpp | 9 + COFF/Symbols.h | 2 + COFF/Writer.cpp | 47 +- Common/ErrorHandler.cpp | 140 +++--- Common/Strings.cpp | 2 +- ELF/Arch/AArch64.cpp | 36 +- ELF/Arch/Hexagon.cpp | 41 +- ELF/Arch/MipsArchTree.cpp | 20 +- ELF/Arch/PPC.cpp | 13 +- ELF/Arch/PPC64.cpp | 26 +- ELF/CallGraphSort.cpp | 2 +- ELF/Config.h | 14 +- ELF/DWARF.cpp | 11 +- ELF/DWARF.h | 33 +- ELF/Driver.cpp | 32 +- ELF/DriverUtils.cpp | 8 +- ELF/InputFiles.cpp | 37 +- ELF/InputSection.cpp | 42 +- ELF/LTO.cpp | 8 +- ELF/LinkerScript.cpp | 134 ++++-- ELF/LinkerScript.h | 2 +- ELF/MapFile.cpp | 6 +- ELF/MarkLive.cpp | 12 + ELF/Options.td | 2 +- ELF/Relocations.cpp | 169 +++---- ELF/Relocations.h | 1 - ELF/ScriptParser.cpp | 30 +- ELF/SymbolTable.cpp | 78 ++-- ELF/SymbolTable.h | 2 +- ELF/Symbols.cpp | 27 +- ELF/Symbols.h | 55 ++- ELF/SyntheticSections.cpp | 213 ++++++--- ELF/SyntheticSections.h | 16 +- ELF/Writer.cpp | 216 +++++---- ELF/Writer.h | 1 + MinGW/Driver.cpp | 2 + MinGW/Options.td | 65 ++- docs/ReleaseNotes.rst | 5 +- docs/WebAssembly.rst | 2 +- docs/ld.lld.1 | 11 +- include/lld/Common/ErrorHandler.h | 7 +- .../lld/ReaderWriter/MachOLinkingContext.h | 2 +- lib/Driver/DarwinLdDriver.cpp | 10 +- lib/ReaderWriter/FileArchive.cpp | 2 +- lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp | 50 +- lib/ReaderWriter/MachO/CompactUnwindPass.cpp | 2 +- lib/ReaderWriter/MachO/GOTPass.cpp | 2 +- lib/ReaderWriter/MachO/LayoutPass.cpp | 2 +- .../MachO/MachOLinkingContext.cpp | 10 +- .../MachO/MachONormalizedFileBinaryReader.cpp | 4 +- .../MachO/MachONormalizedFileToAtoms.cpp | 20 +- lib/ReaderWriter/MachO/ObjCPass.cpp | 2 +- lib/ReaderWriter/MachO/ShimPass.cpp | 2 +- lib/ReaderWriter/MachO/TLVPass.cpp | 2 +- lib/ReaderWriter/YAML/ReaderWriterYAML.cpp | 2 +- test/COFF/Inputs/alias-implib.lib | Bin 0 -> 1608 bytes test/COFF/Inputs/combined-resources-2.yaml | 137 ++++++ test/COFF/Inputs/combined-resources.yaml | 42 ++ test/COFF/Inputs/libcall-archive.ll | 6 + test/COFF/Inputs/libcall-archive.s | 2 + test/COFF/alias-implib.s | 23 + test/COFF/align.s | 45 ++ test/COFF/autoimport-gnu-implib.s | 7 +- test/COFF/autoimport-x86.s | 9 +- test/COFF/color-diagnostics.test | 4 +- test/COFF/combined-resources.test | 19 + test/COFF/edata.s | 61 +++ test/COFF/force-multipleres.test | 12 +- test/COFF/implib-name-mingw.test | 20 + test/COFF/libcall-archive.ll | 22 + test/COFF/lto-obj-path.ll | 25 + test/COFF/mixed-resource-obj.yaml | 63 +++ test/COFF/multiple-resource-objs.test | 2 + test/COFF/s_udt.s | 6 +- test/COFF/thin-archive.s | 2 + test/ELF/Inputs/bad-archive.a | 2 - test/ELF/Inputs/vs-diagnostics-duplicate3.s | 4 +- test/ELF/aarch64-abs16.s | 6 +- test/ELF/aarch64-abs32.s | 6 +- test/ELF/aarch64-call26-thunk.s | 10 +- test/ELF/aarch64-condb-reloc.s | 98 ++-- test/ELF/aarch64-copy.s | 33 +- test/ELF/aarch64-cortex-a53-843419-large.s | 2 +- .../ELF/aarch64-cortex-a53-843419-recognize.s | 40 +- test/ELF/aarch64-cortex-a53-843419-tlsrelax.s | 12 +- test/ELF/aarch64-data-relocs.s | 7 +- test/ELF/aarch64-feature-bti.s | 244 +++++----- test/ELF/aarch64-feature-btipac.s | 128 ++--- test/ELF/aarch64-feature-pac.s | 129 +++--- test/ELF/aarch64-fpic-got.s | 12 +- test/ELF/aarch64-gnu-ifunc-address.s | 15 +- test/ELF/aarch64-gnu-ifunc-nonpreemptable.s | 40 +- test/ELF/aarch64-gnu-ifunc-nonpreemptable2.s | 36 ++ test/ELF/aarch64-gnu-ifunc-plt.s | 85 ++-- test/ELF/aarch64-gnu-ifunc.s | 50 +- test/ELF/aarch64-gnu-ifunc2.s | 28 +- test/ELF/aarch64-got-weak-undef.s | 2 +- test/ELF/aarch64-ifunc-bti.s | 48 +- test/ELF/aarch64-jump26-thunk.s | 10 +- test/ELF/aarch64-ldprel-lo19-invalid.s | 2 +- test/ELF/aarch64-lo12-alignment.s | 8 +- test/ELF/aarch64-load-alignment.s | 2 +- test/ELF/aarch64-movw-error.s | 19 + test/ELF/aarch64-movw-tprel.s | 63 +++ test/ELF/aarch64-nopic-plt.s | 2 +- test/ELF/aarch64-prel16.s | 10 +- test/ELF/aarch64-prel32.s | 10 +- test/ELF/aarch64-relative.s | 1 + test/ELF/aarch64-relocs.s | 105 ++--- test/ELF/aarch64-relro.s | 4 +- test/ELF/aarch64-thunk-section-location.s | 8 +- test/ELF/aarch64-tls-gdie.s | 16 +- test/ELF/aarch64-tls-gdle.s | 8 +- test/ELF/aarch64-tls-ie.s | 16 +- test/ELF/aarch64-tls-le.s | 12 +- test/ELF/aarch64-tls-vaddr-align.s | 31 ++ test/ELF/aarch64-tlsdesc.s | 30 +- test/ELF/aarch64-tlsld-ldst.s | 22 +- test/ELF/aarch64-tstbr14-reloc.s | 96 ++-- test/ELF/aarch64-undefined-weak.s | 22 +- test/ELF/amdgpu-relocs.s | 18 +- test/ELF/arm-abs32-dyn.s | 12 +- test/ELF/arm-bl-v6-inrange.s | 33 +- test/ELF/arm-bl-v6.s | 20 +- test/ELF/arm-blx.s | 79 ++-- test/ELF/arm-branch-undef-weak-plt-thunk.s | 26 +- test/ELF/arm-copy.s | 25 +- test/ELF/arm-execute-only.s | 13 +- test/ELF/arm-exidx-add-missing.s | 10 +- test/ELF/arm-exidx-canunwind.s | 30 +- test/ELF/arm-exidx-dedup.s | 18 +- test/ELF/arm-exidx-emit-relocs.s | 6 +- test/ELF/arm-exidx-gc.s | 36 +- test/ELF/arm-exidx-order.s | 46 +- test/ELF/arm-exidx-partial-discard.s | 37 ++ test/ELF/arm-exidx-shared.s | 6 +- test/ELF/arm-fpic-got.s | 18 +- test/ELF/arm-gnu-ifunc-plt.s | 90 ++-- test/ELF/arm-gnu-ifunc.s | 50 +- test/ELF/arm-got-relative.s | 20 +- test/ELF/arm-gotoff.s | 18 +- test/ELF/arm-icf-exidx.s | 8 +- test/ELF/arm-mov-relocs.s | 42 +- test/ELF/arm-pie-relative.s | 16 +- test/ELF/arm-plt-reloc.s | 88 ++-- test/ELF/arm-reloc-abs32.s | 4 +- test/ELF/arm-sbrel32.s | 10 +- test/ELF/arm-target1.s | 4 +- test/ELF/arm-target2.s | 10 +- test/ELF/arm-thumb-blx.s | 21 +- test/ELF/arm-thumb-interwork-shared.s | 70 ++- test/ELF/arm-thumb-interwork-thunk-v5.s | 54 ++- test/ELF/arm-thumb-no-undefined-thunk.s | 8 +- test/ELF/arm-thumb-plt-range-thunk-os.s | 16 +- test/ELF/arm-thumb-plt-reloc.s | 137 +++--- test/ELF/arm-thumb-thunk-empty-pass.s | 31 +- test/ELF/arm-thumb-thunk-symbols.s | 6 +- test/ELF/arm-thumb-undefined-weak-narrow.test | 2 +- test/ELF/arm-thumb-undefined-weak.s | 13 +- test/ELF/arm-thunk-largesection.s | 28 +- test/ELF/arm-thunk-many-passes.s | 111 +++++ test/ELF/arm-thunk-multipass-plt.s | 12 +- test/ELF/arm-thunk-nosuitable.s | 8 +- test/ELF/arm-thunk-re-add.s | 12 +- test/ELF/arm-tls-gd-nonpreemptible.s | 10 +- test/ELF/arm-tls-gd32.s | 38 +- test/ELF/arm-tls-ie32.s | 28 +- test/ELF/arm-tls-ldm32.s | 33 +- test/ELF/arm-tls-le32.s | 10 +- test/ELF/arm-tls-norelax-gd-ie.s | 12 +- test/ELF/arm-tls-norelax-gd-le.s | 8 +- test/ELF/arm-tls-norelax-ie-le.s | 8 +- test/ELF/arm-tls-norelax-ld-le.s | 8 +- test/ELF/arm-undefined-weak.s | 13 +- test/ELF/avoid-empty-program-headers.s | 6 +- test/ELF/bad-archive.s | 9 +- test/ELF/basic-aarch64.s | 34 +- test/ELF/basic-i386.s | 34 +- test/ELF/basic-ppc.s | 34 +- test/ELF/basic-ppc64.s | 62 +-- test/ELF/basic-sparcv9.s | 32 +- test/ELF/basic.s | 14 +- test/ELF/build-id.s | 6 +- test/ELF/color-diagnostics.test | 4 +- test/ELF/common-page.s | 12 +- test/ELF/copy-errors.s | 7 +- test/ELF/copy-rel-pie-error.s | 18 - test/ELF/copy-rel-pie2.s | 13 + test/ELF/dynamic-got.s | 12 +- test/ELF/dynamic-list-preempt2.s | 29 ++ test/ELF/fill-trap-ppc.s | 4 +- test/ELF/fill-trap.s | 21 +- test/ELF/gdb-index-parse-fail.s | 28 ++ test/ELF/gdb-index-rng-lists.s | 7 +- .../global-offset-table-position-aarch64.s | 2 +- test/ELF/global-offset-table-position-arm.s | 2 +- test/ELF/global-offset-table-position-i386.s | 2 +- test/ELF/gnu-ifunc-canon.s | 15 +- test/ELF/gnu-ifunc-dyntags.s | 10 +- test/ELF/gnu-ifunc-i386.s | 48 +- test/ELF/gnu-ifunc-noplt-i386.s | 60 +-- test/ELF/gnu-ifunc-plt-i386.s | 74 +-- test/ELF/gnu-ifunc-plt.s | 14 +- test/ELF/gnu-ifunc-relative.s | 2 +- test/ELF/gnu-ifunc-shared.s | 7 +- test/ELF/gnu-ifunc.s | 8 +- test/ELF/got-i386.s | 12 +- test/ELF/got32-i386-pie-rw.s | 4 +- test/ELF/got32-i386.s | 6 +- test/ELF/got32x-i386.s | 13 +- test/ELF/hexagon-gotrel.s | 27 ++ test/ELF/hexagon-shared.s | 25 +- test/ELF/i386-gotoff-shared.s | 10 +- test/ELF/i386-gotpc-dynamic.s | 6 +- test/ELF/i386-gotpc.s | 8 +- test/ELF/i386-merge.s | 4 +- test/ELF/i386-pc8-pc16-addend.s | 8 +- test/ELF/i386-relax-reloc.s | 11 +- test/ELF/i386-reloc-range.s | 4 +- test/ELF/i386-retpoline-nopic-linkerscript.s | 96 ++-- test/ELF/i386-retpoline-nopic.s | 100 ++-- test/ELF/i386-retpoline-pic.s | 94 ++-- test/ELF/i386-tls-dynamic.s | 100 ++++ test/ELF/i386-tls-gdiele.s | 61 +++ ...itial-exec-local.s => i386-tls-ie-local.s} | 0 test/ELF/i386-tls-ie-shared.s | 75 ++- test/ELF/i386-tls-ld-preemptable.s | 2 +- test/ELF/i386-tls-le.s | 71 +++ ...i686-nopic.s => i386-tls-opt-iele-nopic.s} | 50 +- test/ELF/{tls-opt-i686.s => i386-tls-opt.s} | 32 +- test/ELF/i386-tls-vaddr-align.s | 27 ++ test/ELF/image-base.s | 4 +- .../invalid/invalid-relocation-aarch64.test | 31 ++ .../Inputs/arm-thunk-many-passes.s | 70 +++ .../memory-gap-explicit-expr.test | 18 + test/ELF/linkerscript/nobits-offset.s | 25 +- test/ELF/linkerscript/orphan-report.s | 2 +- .../symbol-assign-many-passes.test | 25 + .../symbol-assign-many-passes2.test | 28 ++ .../symbol-assign-not-converge.test | 20 + test/ELF/linkerscript/version-script.s | 2 +- test/ELF/lto/Inputs/undef.ll | 4 + test/ELF/lto/undef-weak-lazy.ll | 23 + test/ELF/map-file-i686.s | 6 +- test/ELF/msp430.s | 2 +- test/ELF/nobits-offset.s | 21 + test/ELF/pack-dyn-relocs-arm2.s | 70 +-- test/ELF/pack-dyn-relocs-loop.s | 2 +- test/ELF/pack-dyn-relocs.s | 437 ++++++++++-------- test/ELF/partition-move-to-main-startstop.s | 43 ++ test/ELF/partition-notes.s | 1 + test/ELF/partition-synthetic-sections.s | 4 +- test/ELF/plt-aarch64.s | 163 +++---- test/ELF/plt-i686.s | 172 ++++--- test/ELF/ppc-rela.s | 11 - test/ELF/ppc32-abs-pic.s | 6 +- test/ELF/ppc32-call-stub-nopic.s | 30 +- test/ELF/ppc32-call-stub-pic.s | 52 ++- test/ELF/ppc32-gnu-ifunc-nonpreemptable.s | 16 +- test/ELF/ppc32-gnu-ifunc.s | 10 +- test/ELF/ppc32-reloc-got.s | 8 +- test/ELF/ppc32-tls-gd.s | 18 +- test/ELF/ppc32-tls-ie.s | 4 +- test/ELF/ppc32-tls-ld.s | 2 +- test/ELF/ppc64-abs64-dyn.s | 8 +- test/ELF/ppc64-bsymbolic-toc-restore.s | 2 +- test/ELF/ppc64-call-reach.s | 26 +- test/ELF/ppc64-dq.s | 6 +- test/ELF/ppc64-dtprel.s | 10 +- test/ELF/ppc64-entry-point.s | 18 +- test/ELF/ppc64-error-missaligned-dq.s | 4 +- test/ELF/ppc64-error-missaligned-ds.s | 4 +- test/ELF/ppc64-func-entry-points.s | 22 +- test/ELF/ppc64-ifunc.s | 41 +- test/ELF/ppc64-local-dynamic.s | 4 +- .../ELF/ppc64-long-branch-localentry-offset.s | 2 +- test/ELF/ppc64-long-branch.s | 12 +- test/ELF/ppc64-plt-stub.s | 12 +- test/ELF/ppc64-rel-calls.s | 20 +- test/ELF/ppc64-reloc-rel.s | 58 +++ test/ELF/ppc64-relocs.s | 97 +--- test/ELF/ppc64-shared-long_branch.s | 15 +- test/ELF/ppc64-tls-gd.s | 16 +- test/ELF/ppc64-tls-ie.s | 8 +- test/ELF/ppc64-tls-vaddr-align.s | 34 ++ test/ELF/ppc64-toc-addis-nop-lqsq.s | 1 + test/ELF/ppc64-toc-addis-nop.s | 73 +-- test/ELF/ppc64-toc-rel.s | 15 +- test/ELF/ppc64-toc-relax-constants.s | 16 +- test/ELF/ppc64-toc-relax-ifunc.s | 34 ++ test/ELF/ppc64-toc-relax-jumptable.s | 8 +- test/ELF/ppc64-toc-relax.s | 30 +- test/ELF/ppc64-toc-restore-recursive-call.s | 6 +- test/ELF/ppc64-toc-restore.s | 22 +- test/ELF/ppc64-weak-undef-call.s | 6 +- test/ELF/pr34660.s | 6 +- test/ELF/relocation-b-aarch64.test | 6 +- test/ELF/relocation-copy-align-common.s | 2 +- test/ELF/relocation-copy-i686.s | 18 +- test/ELF/relocation-i686.s | 46 +- test/ELF/relro-copyrel-bss-script.s | 19 +- test/ELF/reproduce.s | 2 +- test/ELF/riscv-gp-dummy-sdata.s | 25 - test/ELF/riscv-gp-no-sdata.s | 15 + test/ELF/riscv-gp.s | 17 +- test/ELF/riscv-plt.s | 65 +-- test/ELF/riscv-reloc-copy.s | 19 +- test/ELF/riscv-reloc-got.s | 50 +- test/ELF/riscv-tls-gd.s | 58 +-- test/ELF/riscv-tls-ie.s | 54 +-- test/ELF/riscv-tls-ld.s | 44 +- test/ELF/riscv32-reloc-32-pic.s | 6 +- test/ELF/riscv64-reloc-64-pic.s | 6 +- test/ELF/shared.s | 10 +- test/ELF/silent-ignore.test | 8 +- test/ELF/static-with-export-dynamic.s | 2 +- test/ELF/strip-all.s | 3 + test/ELF/tls-dynamic-i686.s | 100 ---- test/ELF/tls-i686.s | 71 --- test/ELF/tls-initial-exec-local.s | 37 -- test/ELF/tls-opt-gdiele-i686.s | 61 --- test/ELF/tls-opt-no-plt.s | 35 -- test/ELF/tls-static.s | 21 - test/ELF/undef-with-plt-addr-i686.s | 6 +- test/ELF/version-script-anonymous-local.s | 61 --- test/ELF/version-script-missing.s | 7 - test/ELF/version-script-no-warn.s | 12 - test/ELF/version-script-no-warn2.s | 9 - test/ELF/version-script-noundef.s | 2 +- test/ELF/version-script-reassign-glob.s | 19 + test/ELF/version-script-reassign.s | 8 +- test/ELF/version-script.s | 4 +- test/ELF/vs-diagnostics-duplicate-split.s | 39 ++ test/ELF/vs-diagnostics-duplicate.s | 19 +- test/ELF/vs-diagnostics-dynamic-relocation.s | 11 + test/ELF/vs-diagnostics-undefined-hidden.s | 48 ++ test/ELF/vs-diagnostics-undefined-symbol-3.s | 10 +- test/ELF/weak-undef-shared.s | 3 + test/ELF/x86-64-dyn-rel-error.s | 3 +- test/ELF/x86-64-dyn-rel-error5.s | 8 +- ...s-error.s => x86-64-reloc-tpoff32-error.s} | 2 +- .../{tls-dynamic.s => x86-64-tls-dynamic.s} | 0 .../ELF/{tls-opt-gdie.s => x86-64-tls-gdie.s} | 21 +- test/ELF/x86-64-tls-ie-local.s | 28 ++ ...-opt-local.s => x86-64-tls-ie-opt-local.s} | 0 ...-x86_64-noplt.s => x86-64-tls-opt-noplt.s} | 0 test/MinGW/driver.test | 35 +- test/wasm/Inputs/optional-symbol.ll | 7 + test/wasm/debuginfo-relocs.s | 23 + test/wasm/export-optional-lazy.ll | 25 + test/wasm/export.ll | 13 +- test/wasm/global-base.test | 12 +- test/wasm/growable-table.test | 17 + test/wasm/optional-symbol.ll | 14 + test/wasm/pic-static.ll | 95 ++++ test/wasm/relocatable.ll | 360 ++++++++------- test/wasm/shared-export-dynamic.ll | 18 + test/wasm/signature-mismatch-unknown.ll | 8 + test/wasm/stack-first.test | 6 +- wasm/Config.h | 7 + wasm/Driver.cpp | 102 ++-- wasm/InputChunks.cpp | 2 +- wasm/InputFiles.cpp | 2 +- wasm/LTO.cpp | 7 +- wasm/MarkLive.cpp | 4 +- wasm/Options.td | 3 + wasm/Relocations.cpp | 18 +- wasm/SymbolTable.cpp | 17 +- wasm/SymbolTable.h | 3 +- wasm/Symbols.cpp | 14 +- wasm/Symbols.h | 6 + wasm/SyntheticSections.cpp | 50 +- wasm/SyntheticSections.h | 12 +- wasm/Writer.cpp | 18 +- 388 files changed, 6454 insertions(+), 4439 deletions(-) create mode 100644 test/COFF/Inputs/alias-implib.lib create mode 100644 test/COFF/Inputs/combined-resources-2.yaml create mode 100644 test/COFF/Inputs/combined-resources.yaml create mode 100644 test/COFF/Inputs/libcall-archive.ll create mode 100644 test/COFF/Inputs/libcall-archive.s create mode 100644 test/COFF/alias-implib.s create mode 100644 test/COFF/align.s create mode 100644 test/COFF/edata.s create mode 100644 test/COFF/implib-name-mingw.test create mode 100644 test/COFF/libcall-archive.ll create mode 100644 test/COFF/lto-obj-path.ll create mode 100644 test/COFF/mixed-resource-obj.yaml delete mode 100644 test/ELF/Inputs/bad-archive.a create mode 100644 test/ELF/aarch64-gnu-ifunc-nonpreemptable2.s create mode 100644 test/ELF/aarch64-movw-tprel.s create mode 100644 test/ELF/aarch64-tls-vaddr-align.s create mode 100644 test/ELF/arm-exidx-partial-discard.s create mode 100644 test/ELF/arm-thunk-many-passes.s delete mode 100644 test/ELF/copy-rel-pie-error.s create mode 100644 test/ELF/copy-rel-pie2.s create mode 100644 test/ELF/dynamic-list-preempt2.s create mode 100644 test/ELF/gdb-index-parse-fail.s create mode 100644 test/ELF/hexagon-gotrel.s create mode 100644 test/ELF/i386-tls-dynamic.s create mode 100644 test/ELF/i386-tls-gdiele.s rename test/ELF/{i386-tls-initial-exec-local.s => i386-tls-ie-local.s} (100%) create mode 100644 test/ELF/i386-tls-le.s rename test/ELF/{tls-opt-iele-i686-nopic.s => i386-tls-opt-iele-nopic.s} (56%) rename test/ELF/{tls-opt-i686.s => i386-tls-opt.s} (54%) create mode 100644 test/ELF/i386-tls-vaddr-align.s create mode 100644 test/ELF/invalid/invalid-relocation-aarch64.test create mode 100644 test/ELF/linkerscript/Inputs/arm-thunk-many-passes.s create mode 100644 test/ELF/linkerscript/memory-gap-explicit-expr.test create mode 100644 test/ELF/linkerscript/symbol-assign-many-passes.test create mode 100644 test/ELF/linkerscript/symbol-assign-many-passes2.test create mode 100644 test/ELF/linkerscript/symbol-assign-not-converge.test create mode 100644 test/ELF/lto/Inputs/undef.ll create mode 100644 test/ELF/lto/undef-weak-lazy.ll create mode 100644 test/ELF/nobits-offset.s create mode 100644 test/ELF/partition-move-to-main-startstop.s delete mode 100644 test/ELF/ppc-rela.s create mode 100644 test/ELF/ppc64-reloc-rel.s create mode 100644 test/ELF/ppc64-tls-vaddr-align.s create mode 100644 test/ELF/ppc64-toc-relax-ifunc.s delete mode 100644 test/ELF/riscv-gp-dummy-sdata.s create mode 100644 test/ELF/riscv-gp-no-sdata.s delete mode 100644 test/ELF/tls-dynamic-i686.s delete mode 100644 test/ELF/tls-i686.s delete mode 100644 test/ELF/tls-initial-exec-local.s delete mode 100644 test/ELF/tls-opt-gdiele-i686.s delete mode 100644 test/ELF/tls-opt-no-plt.s delete mode 100644 test/ELF/tls-static.s delete mode 100644 test/ELF/version-script-anonymous-local.s delete mode 100644 test/ELF/version-script-missing.s delete mode 100644 test/ELF/version-script-no-warn.s delete mode 100644 test/ELF/version-script-no-warn2.s create mode 100644 test/ELF/version-script-reassign-glob.s create mode 100644 test/ELF/vs-diagnostics-duplicate-split.s create mode 100644 test/ELF/vs-diagnostics-undefined-hidden.s rename test/ELF/{tls-error.s => x86-64-reloc-tpoff32-error.s} (77%) rename test/ELF/{tls-dynamic.s => x86-64-tls-dynamic.s} (100%) rename test/ELF/{tls-opt-gdie.s => x86-64-tls-gdie.s} (71%) create mode 100644 test/ELF/x86-64-tls-ie-local.s rename test/ELF/{tls-opt-local.s => x86-64-tls-ie-opt-local.s} (100%) rename test/ELF/{tls-opt-x86_64-noplt.s => x86-64-tls-opt-noplt.s} (100%) create mode 100644 test/wasm/Inputs/optional-symbol.ll create mode 100644 test/wasm/debuginfo-relocs.s create mode 100644 test/wasm/export-optional-lazy.ll create mode 100644 test/wasm/growable-table.test create mode 100644 test/wasm/optional-symbol.ll create mode 100644 test/wasm/pic-static.ll create mode 100644 test/wasm/shared-export-dynamic.ll diff --git a/COFF/Config.h b/COFF/Config.h index 1b0e24042..309e1fbf9 100644 --- a/COFF/Config.h +++ b/COFF/Config.h @@ -122,6 +122,7 @@ struct Configuration { bool dll = false; StringRef implib; std::vector exports; + bool hadExplicitExports; std::set delayLoads; std::map dllOrder; Symbol *delayLoadHelper = nullptr; @@ -189,6 +190,10 @@ struct Configuration { // Used for /thinlto-object-suffix-replace: std::pair thinLTOObjectSuffixReplace; + // Used for /lto-obj-path: + llvm::StringRef ltoObjPath; + + uint64_t align = 4096; uint64_t imageBase = -1; uint64_t fileAlign = 512; uint64_t stackReserve = 1024 * 1024; diff --git a/COFF/DLL.cpp b/COFF/DLL.cpp index 40d1f463a..210f43fd6 100644 --- a/COFF/DLL.cpp +++ b/COFF/DLL.cpp @@ -188,7 +188,7 @@ class DelayDirectoryChunk : public NonSectionChunk { // Initial contents for delay-loaded functions. // This code calls __delayLoadHelper2 function to resolve a symbol -// and then overwrites its jump table slot with the result +// which then overwrites its jump table slot with the result // for subsequent function calls. static const uint8_t thunkX64[] = { 0x48, 0x8D, 0x05, 0, 0, 0, 0, // lea rax, [__imp_] diff --git a/COFF/Driver.cpp b/COFF/Driver.cpp index 3d2660b4b..312c161f8 100644 --- a/COFF/Driver.cpp +++ b/COFF/Driver.cpp @@ -36,6 +36,7 @@ #include "llvm/Option/Option.h" #include "llvm/Support/Debug.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/TarWriter.h" @@ -62,16 +63,16 @@ LinkerDriver *driver; bool link(ArrayRef args, bool canExitEarly, raw_ostream &diag) { errorHandler().logName = args::getFilenameWithoutExe(args[0]); errorHandler().errorOS = &diag; - errorHandler().colorDiagnostics = diag.has_colors(); errorHandler().errorLimitExceededMsg = "too many errors emitted, stopping now" " (use /errorlimit:0 to see all errors)"; errorHandler().exitEarly = canExitEarly; - config = make(); + enableColors(diag.has_colors()); + config = make(); symtab = make(); - driver = make(); + driver->link(args); // Call exit() if we can to avoid calling destructors. @@ -184,8 +185,10 @@ void LinkerDriver::addBuffer(std::unique_ptr mb, if (wholeArchive) { std::unique_ptr file = CHECK(Archive::create(mbref), filename + ": failed to parse archive"); + Archive *archive = file.get(); + make>(std::move(file)); // take ownership - for (MemoryBufferRef m : getArchiveMembers(file.get())) + for (MemoryBufferRef m : getArchiveMembers(archive)) addArchiveBuffer(m, "", filename, 0); return; } @@ -988,30 +991,37 @@ static void parsePDBAltPath(StringRef altPath) { config->pdbAltPath = buf; } -/// Check that at most one resource obj file was used. +/// Convert resource files and potentially merge input resource object +/// trees into one resource tree. /// Call after ObjFile::Instances is complete. -static void diagnoseMultipleResourceObjFiles() { - // The .rsrc$01 section in a resource obj file contains a tree description - // of resources. Merging multiple resource obj files would require merging - // the trees instead of using usual linker section merging semantics. - // Since link.exe disallows linking more than one resource obj file with - // LNK4078, mirror that. The normal use of resource files is to give the - // linker many .res files, which are then converted to a single resource obj - // file internally, so this is not a big restriction in practice. - ObjFile *resourceObjFile = nullptr; - for (ObjFile *f : ObjFile::instances) { - if (!f->isResourceObjFile) - continue; +void LinkerDriver::convertResources() { + std::vector resourceObjFiles; - if (!resourceObjFile) { - resourceObjFile = f; - continue; - } + for (ObjFile *f : ObjFile::instances) { + if (f->isResourceObjFile()) + resourceObjFiles.push_back(f); + } - error(toString(f) + + if (!config->mingw && + (resourceObjFiles.size() > 1 || + (resourceObjFiles.size() == 1 && !resources.empty()))) { + error((!resources.empty() ? "internal .obj file created from .res files" + : toString(resourceObjFiles[1])) + ": more than one resource obj file not allowed, already got " + - toString(resourceObjFile)); + toString(resourceObjFiles.front())); + return; } + + if (resources.empty() && resourceObjFiles.size() <= 1) { + // No resources to convert, and max one resource object file in + // the input. Keep that preconverted resource section as is. + for (ObjFile *f : resourceObjFiles) + f->includeResourceChunks(); + return; + } + ObjFile *f = make(convertResToCOFF(resources, resourceObjFiles)); + symtab->addFile(f); + f->includeResourceChunks(); } // In MinGW, if no symbols are chosen to be exported, then all symbols are @@ -1052,6 +1062,12 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) { }); } +static const char *libcallRoutineNames[] = { +#define HANDLE_LIBCALL(code, name) name, +#include "llvm/IR/RuntimeLibcalls.def" +#undef HANDLE_LIBCALL +}; + void LinkerDriver::link(ArrayRef argsArr) { // Needed for LTO. InitializeAllTargetInfos(); @@ -1420,6 +1436,13 @@ void LinkerDriver::link(ArrayRef argsArr) { for (auto *arg : args.filtered(OPT_section)) parseSection(arg->getValue()); + // Handle /align + if (auto *arg = args.getLastArg(OPT_align)) { + parseNumbers(arg->getValue(), &config->align); + if (!isPowerOf2_64(config->align)) + error("/align: not a power of two: " + StringRef(arg->getValue())); + } + // Handle /aligncomm for (auto *arg : args.filtered(OPT_aligncomm)) parseAligncomm(arg->getValue()); @@ -1465,6 +1488,7 @@ void LinkerDriver::link(ArrayRef argsArr) { getOldNewOptions(args, OPT_thinlto_prefix_replace); config->thinLTOObjectSuffixReplace = getOldNewOptions(args, OPT_thinlto_object_suffix_replace); + config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path); // Handle miscellaneous boolean flags. config->allowBind = args.hasFlag(OPT_allowbind, OPT_allowbind_no, true); config->allowIsolation = @@ -1566,12 +1590,6 @@ void LinkerDriver::link(ArrayRef argsArr) { for (auto *arg : args.filtered(OPT_functionpadmin, OPT_functionpadmin_opt)) parseFunctionPadMin(arg, config->machine); - // Input files can be Windows resource files (.res files). We use - // WindowsResource to convert resource files to a regular COFF file, - // then link the resulting file normally. - if (!resources.empty()) - symtab->addFile(make(convertResToCOFF(resources))); - if (tar) tar->append("response.txt", createResponseFile(args, filePaths, @@ -1747,6 +1765,15 @@ void LinkerDriver::link(ArrayRef argsArr) { u->weakAlias = symtab->addUndefined(to); } + // If any inputs are bitcode files, the LTO code generator may create + // references to library functions that are not explicit in the bitcode + // file's symbol table. If any of those library functions are defined in a + // bitcode file in an archive member, we need to arrange to use LTO to + // compile those archive members by adding them to the link beforehand. + if (!BitcodeFile::instances.empty()) + for (const char *s : libcallRoutineNames) + symtab->addLibcall(s); + // Windows specific -- if __load_config_used can be resolved, resolve it. if (symtab->findUnderscore("_load_config_used")) addUndefined(mangle("_load_config_used")); @@ -1807,6 +1834,7 @@ void LinkerDriver::link(ArrayRef argsArr) { if (errorCount()) return; + config->hadExplicitExports = !config->exports.empty(); if (config->mingw) { // In MinGW, all symbols are automatically exported if no symbols // are chosen to be exported. @@ -1830,10 +1858,12 @@ void LinkerDriver::link(ArrayRef argsArr) { } // Windows specific -- when we are creating a .dll file, we also - // need to create a .lib file. + // need to create a .lib file. In MinGW mode, we only do that when the + // -implib option is given explicitly, for compatibility with GNU ld. if (!config->exports.empty() || config->dll) { fixupExports(); - createImportLibrary(/*asLib=*/false); + if (!config->mingw || !config->implib.empty()) + createImportLibrary(/*asLib=*/false); assignExportOrdinals(); } @@ -1877,7 +1907,7 @@ void LinkerDriver::link(ArrayRef argsArr) { markLive(symtab->getChunks()); // Needs to happen after the last call to addFile(). - diagnoseMultipleResourceObjFiles(); + convertResources(); // Identify identical COMDAT sections to merge them. if (config->doICF) { diff --git a/COFF/Driver.h b/COFF/Driver.h index 01bfb02a5..42aaea333 100644 --- a/COFF/Driver.h +++ b/COFF/Driver.h @@ -98,6 +98,10 @@ class LinkerDriver { // Library search path. The first element is always "" (current directory). std::vector searchPaths; + // Convert resource files and potentially merge input resource object + // trees into one resource tree. + void convertResources(); + void maybeExportMinGWSymbols(const llvm::opt::InputArgList &args); // We don't want to add the same file more than once. @@ -184,7 +188,8 @@ void assignExportOrdinals(); void checkFailIfMismatch(StringRef arg, InputFile *source); // Convert Windows resource files (.res files) to a .obj file. -MemoryBufferRef convertResToCOFF(ArrayRef mbs); +MemoryBufferRef convertResToCOFF(ArrayRef mbs, + ArrayRef objs); void runMSVCLinker(std::string rsp, ArrayRef objects); diff --git a/COFF/DriverUtils.cpp b/COFF/DriverUtils.cpp index 4360ac23b..ab96e227a 100644 --- a/COFF/DriverUtils.cpp +++ b/COFF/DriverUtils.cpp @@ -322,7 +322,7 @@ class TemporaryFile { if (!contents.empty()) { std::error_code ec; - raw_fd_ostream os(path, ec, sys::fs::F_None); + raw_fd_ostream os(path, ec, sys::fs::OF_None); if (ec) fatal("failed to open " + path + ": " + ec.message()); os << contents; @@ -410,7 +410,7 @@ static std::string createManifestXmlWithExternalMt(StringRef defaultXml) { // Create the default manifest file as a temporary file. TemporaryFile Default("defaultxml", "manifest"); std::error_code ec; - raw_fd_ostream os(Default.path, ec, sys::fs::F_Text); + raw_fd_ostream os(Default.path, ec, sys::fs::OF_Text); if (ec) fatal("failed to open " + Default.path + ": " + ec.message()); os << defaultXml; @@ -511,7 +511,7 @@ void createSideBySideManifest() { if (path == "") path = config->outputFile + ".manifest"; std::error_code ec; - raw_fd_ostream out(path, ec, sys::fs::F_Text); + raw_fd_ostream out(path, ec, sys::fs::OF_Text); if (ec) fatal("failed to create manifest: " + ec.message()); out << createManifestXml(); @@ -700,26 +700,40 @@ void checkFailIfMismatch(StringRef arg, InputFile *source) { // Convert Windows resource files (.res files) to a .obj file. // Does what cvtres.exe does, but in-process and cross-platform. -MemoryBufferRef convertResToCOFF(ArrayRef mbs) { +MemoryBufferRef convertResToCOFF(ArrayRef mbs, + ArrayRef objs) { object::WindowsResourceParser parser; + std::vector duplicates; for (MemoryBufferRef mb : mbs) { std::unique_ptr bin = check(object::createBinary(mb)); object::WindowsResource *rf = dyn_cast(bin.get()); if (!rf) fatal("cannot compile non-resource file as resource"); - std::vector duplicates; if (auto ec = parser.parse(rf, duplicates)) fatal(toString(std::move(ec))); + } + + // Note: This processes all .res files before all objs. Ideally they'd be + // handled in the same order they were linked (to keep the right one, if + // there are duplicates that are tolerated due to forceMultipleRes). + for (ObjFile *f : objs) { + object::ResourceSectionRef rsf; + if (auto ec = rsf.load(f->getCOFFObj())) + fatal(toString(f) + ": " + toString(std::move(ec))); - for (const auto &dupeDiag : duplicates) - if (config->forceMultipleRes) - warn(dupeDiag); - else - error(dupeDiag); + if (auto ec = parser.parse(rsf, f->getName(), duplicates)) + fatal(toString(std::move(ec))); } + + for (const auto &dupeDiag : duplicates) + if (config->forceMultipleRes) + warn(dupeDiag); + else + error(dupeDiag); + Expected> e = llvm::object::writeWindowsResourceCOFF(config->machine, parser, config->timestamp); @@ -757,15 +771,15 @@ static void handleColorDiagnostics(opt::InputArgList &args) { if (!arg) return; if (arg->getOption().getID() == OPT_color_diagnostics) { - errorHandler().colorDiagnostics = true; + enableColors(true); } else if (arg->getOption().getID() == OPT_no_color_diagnostics) { - errorHandler().colorDiagnostics = false; + enableColors(false); } else { StringRef s = arg->getValue(); if (s == "always") - errorHandler().colorDiagnostics = true; + enableColors(true); else if (s == "never") - errorHandler().colorDiagnostics = false; + enableColors(false); else if (s != "auto") error("unknown option: --color-diagnostics=" + s); } diff --git a/COFF/InputFiles.cpp b/COFF/InputFiles.cpp index d02fedfd1..c24b59deb 100644 --- a/COFF/InputFiles.cpp +++ b/COFF/InputFiles.cpp @@ -206,10 +206,6 @@ SectionChunk *ObjFile::readSection(uint32_t sectionNumber, if (def) c->checksum = def->CheckSum; - // link.exe uses the presence of .rsrc$01 for LNK4078, so match that. - if (name == ".rsrc$01") - isResourceObjFile = true; - // CodeView sections are stored to a different vector because they are not // linked in the regular manner. if (c->isCodeView()) @@ -226,12 +222,18 @@ SectionChunk *ObjFile::readSection(uint32_t sectionNumber, // relocations, in .rdata, leader symbol name matches the MSVC name mangling // for string literals) are subject to string tail merging. MergeChunk::addSection(c); + else if (name == ".rsrc" || name.startswith(".rsrc$")) + resourceChunks.push_back(c); else chunks.push_back(c); return c; } +void ObjFile::includeResourceChunks() { + chunks.insert(chunks.end(), resourceChunks.begin(), resourceChunks.end()); +} + void ObjFile::readAssociativeDefinition( COFFSymbolRef sym, const coff_aux_section_definition *def) { readAssociativeDefinition(sym, def, def->getNumber(sym.isBigObj())); diff --git a/COFF/InputFiles.h b/COFF/InputFiles.h index 8d3a021a3..d822685dc 100644 --- a/COFF/InputFiles.h +++ b/COFF/InputFiles.h @@ -47,7 +47,6 @@ class Defined; class DefinedImportData; class DefinedImportThunk; class DefinedRegular; -class Lazy; class SectionChunk; class Symbol; class Undefined; @@ -135,6 +134,10 @@ class ObjFile : public InputFile { return symbols.size() - 1; } + void includeResourceChunks(); + + bool isResourceObjFile() const { return !resourceChunks.empty(); } + static std::vector instances; // Flags in the absolute @feat.00 symbol if it is present. These usually @@ -162,9 +165,6 @@ class ObjFile : public InputFile { // precompiled object. Any difference indicates out-of-date objects. llvm::Optional pchSignature; - // Whether this is an object file created from .res files. - bool isResourceObjFile = false; - // Whether this file was compiled with /hotpatch. bool hotPatchable = false; @@ -234,6 +234,8 @@ class ObjFile : public InputFile { // chunks and non-section chunks for common symbols. std::vector chunks; + std::vector resourceChunks; + // CodeView debug info sections. std::vector debugChunks; diff --git a/COFF/LTO.cpp b/COFF/LTO.cpp index eb3c60d66..7aa3b17e2 100644 --- a/COFF/LTO.cpp +++ b/COFF/LTO.cpp @@ -46,7 +46,7 @@ using namespace lld::coff; static std::unique_ptr openFile(StringRef file) { std::error_code ec; auto ret = - llvm::make_unique(file, ec, sys::fs::OpenFlags::F_None); + std::make_unique(file, ec, sys::fs::OpenFlags::OF_None); if (ec) { error("cannot open " + file + ": " + ec.message()); return nullptr; @@ -105,7 +105,7 @@ BitcodeCompiler::BitcodeCompiler() { backend = lto::createInProcessThinBackend(config->thinLTOJobs); } - ltoObj = llvm::make_unique(createConfig(), backend, + ltoObj = std::make_unique(createConfig(), backend, config->ltoPartitions); } @@ -160,8 +160,8 @@ std::vector BitcodeCompiler::compile() { checkError(ltoObj->run( [&](size_t task) { - return llvm::make_unique( - llvm::make_unique(buf[task])); + return std::make_unique( + std::make_unique(buf[task])); }, cache)); @@ -177,6 +177,8 @@ std::vector BitcodeCompiler::compile() { // files. After that, we exit from linker and ThinLTO backend runs in a // distributed environment. if (config->thinLTOIndexOnly) { + if (!config->ltoObjPath.empty()) + saveBuffer(buf[0], config->ltoObjPath); if (indexFile) indexFile->close(); return {}; diff --git a/COFF/MapFile.cpp b/COFF/MapFile.cpp index f98cf8fa6..70017d34c 100644 --- a/COFF/MapFile.cpp +++ b/COFF/MapFile.cpp @@ -35,8 +35,8 @@ using namespace lld::coff; using SymbolMapTy = DenseMap>; -static const std::string indent8 = " "; // 8 spaces -static const std::string indent16 = " "; // 16 spaces +static constexpr char indent8[] = " "; // 8 spaces +static constexpr char indent16[] = " "; // 16 spaces // Print out the first three columns of a line. static void writeHeader(raw_ostream &os, uint64_t addr, uint64_t size, @@ -92,7 +92,7 @@ void coff::writeMapFile(ArrayRef outputSections) { return; std::error_code ec; - raw_fd_ostream os(config->mapFile, ec, sys::fs::F_None); + raw_fd_ostream os(config->mapFile, ec, sys::fs::OF_None); if (ec) fatal("cannot open " + config->mapFile + ": " + ec.message()); diff --git a/COFF/MinGW.cpp b/COFF/MinGW.cpp index 2ca8ca0c0..a22e60914 100644 --- a/COFF/MinGW.cpp +++ b/COFF/MinGW.cpp @@ -148,7 +148,7 @@ bool AutoExporter::shouldExport(Defined *sym) const { void coff::writeDefFile(StringRef name) { std::error_code ec; - raw_fd_ostream os(name, ec, sys::fs::F_None); + raw_fd_ostream os(name, ec, sys::fs::OF_None); if (ec) fatal("cannot open " + name + ": " + ec.message()); diff --git a/COFF/Options.td b/COFF/Options.td index 024b7be8f..6b9b26923 100644 --- a/COFF/Options.td +++ b/COFF/Options.td @@ -191,6 +191,9 @@ def thinlto_object_suffix_replace : P< def thinlto_prefix_replace: P< "thinlto-prefix-replace", "'old;new' replace old prefix with new prefix in ThinLTO outputs">; +def lto_obj_path : P< + "lto-obj-path", + "output native object for merged LTO unit to this path">; def dash_dash_version : Flag<["--"], "version">, HelpText<"Print version information">; defm threads: B<"threads", diff --git a/COFF/PDB.cpp b/COFF/PDB.cpp index a55e5136e..25952b592 100644 --- a/COFF/PDB.cpp +++ b/COFF/PDB.cpp @@ -1150,7 +1150,7 @@ void DebugSHandler::finish() { // string table. Generally the string table subsection appears after the // checksum table, so we have to do this after looping over all the // subsections. - auto newChecksums = make_unique(linker.pdbStrTab); + auto newChecksums = std::make_unique(linker.pdbStrTab); for (FileChecksumEntry &fc : checksums) { SmallString<128> filename = exitOnErr(cVStrTab.getString(fc.FileNameOffset)); @@ -1693,6 +1693,7 @@ void PDBLinker::addSections(ArrayRef outputSections, } void PDBLinker::commit(codeview::GUID *guid) { + ExitOnError exitOnErr((config->pdbPath + ": ").str()); // Write to a file. exitOnErr(builder.commit(config->pdbPath, guid)); } diff --git a/COFF/SymbolTable.cpp b/COFF/SymbolTable.cpp index 0f44c8b35..865791ca8 100644 --- a/COFF/SymbolTable.cpp +++ b/COFF/SymbolTable.cpp @@ -185,6 +185,8 @@ void SymbolTable::loadMinGWAutomaticImports() { continue; if (!sym->isUsedInRegularObj) continue; + if (undef->getWeakAlias()) + continue; StringRef name = undef->getName(); @@ -326,7 +328,7 @@ void SymbolTable::reportUnresolvable() { auto *undef = dyn_cast(sym); if (!undef) continue; - if (Defined *d = undef->getWeakAlias()) + if (undef->getWeakAlias()) continue; StringRef name = undef->getName(); if (name.startswith("__imp_")) { @@ -582,6 +584,18 @@ Symbol *SymbolTable::addImportThunk(StringRef name, DefinedImportData *id, return nullptr; } +void SymbolTable::addLibcall(StringRef name) { + Symbol *sym = findUnderscore(name); + if (!sym) + return; + + if (Lazy *l = dyn_cast(sym)) { + MemoryBufferRef mb = l->getMemberBuffer(); + if (identify_magic(mb.getBuffer()) == llvm::file_magic::bitcode) + addUndefined(sym->getName()); + } +} + std::vector SymbolTable::getChunks() { std::vector res; for (ObjFile *file : ObjFile::instances) { diff --git a/COFF/SymbolTable.h b/COFF/SymbolTable.h index 68febc822..52eb8901e 100644 --- a/COFF/SymbolTable.h +++ b/COFF/SymbolTable.h @@ -100,6 +100,7 @@ class SymbolTable { Symbol *addImportData(StringRef n, ImportFile *f); Symbol *addImportThunk(StringRef name, DefinedImportData *s, uint16_t machine); + void addLibcall(StringRef name); void reportDuplicate(Symbol *existing, InputFile *newFile); diff --git a/COFF/Symbols.cpp b/COFF/Symbols.cpp index acb3b3220..1af11820a 100644 --- a/COFF/Symbols.cpp +++ b/COFF/Symbols.cpp @@ -118,5 +118,14 @@ Defined *Undefined::getWeakAlias() { return d; return nullptr; } + +MemoryBufferRef Lazy::getMemberBuffer() { + Archive::Child c = + CHECK(sym.getMember(), + "could not get the member for symbol " + toCOFFString(sym)); + return CHECK(c.getMemoryBufferRef(), + "could not get the buffer for the member defining symbol " + + toCOFFString(sym)); +} } // namespace coff } // namespace lld diff --git a/COFF/Symbols.h b/COFF/Symbols.h index 10d2b8149..78c357aa2 100644 --- a/COFF/Symbols.h +++ b/COFF/Symbols.h @@ -265,6 +265,8 @@ class Lazy : public Symbol { static bool classof(const Symbol *s) { return s->kind() == LazyKind; } + MemoryBufferRef getMemberBuffer(); + ArchiveFile *file; private: diff --git a/COFF/Writer.cpp b/COFF/Writer.cpp index 3da8b98d3..0adf155e6 100644 --- a/COFF/Writer.cpp +++ b/COFF/Writer.cpp @@ -240,6 +240,8 @@ class Writer { IdataContents idata; Chunk *importTableStart = nullptr; uint64_t importTableSize = 0; + Chunk *edataStart = nullptr; + Chunk *edataEnd = nullptr; Chunk *iatStart = nullptr; uint64_t iatSize = 0; DelayLoadContents delayIdata; @@ -626,6 +628,9 @@ void Writer::run() { writeMapFile(outputSections); + if (errorCount()) + return; + ScopedTimer t2(diskCommitTimer); if (auto e = buffer->commit()) fatal("failed to write the output file: " + toString(std::move(e))); @@ -837,6 +842,7 @@ void Writer::createSections() { } fixPartialSectionChars(".rsrc", data | r); + fixPartialSectionChars(".edata", data | r); // Even in non MinGW cases, we might need to link against GNU import // libraries. bool hasIdata = fixGnuImportChunks(); @@ -1011,10 +1017,19 @@ void Writer::appendImportThunks() { } void Writer::createExportTable() { - if (config->exports.empty()) - return; - for (Chunk *c : edata.chunks) - edataSec->addChunk(c); + if (!edataSec->chunks.empty()) { + // Allow using a custom built export table from input object files, instead + // of having the linker synthesize the tables. + if (config->hadExplicitExports) + warn("literal .edata sections override exports"); + } else if (!config->exports.empty()) { + for (Chunk *c : edata.chunks) + edataSec->addChunk(c); + } + if (!edataSec->chunks.empty()) { + edataStart = edataSec->chunks.front(); + edataEnd = edataSec->chunks.back(); + } } void Writer::removeUnusedSections() { @@ -1095,6 +1110,13 @@ Optional Writer::createSymbol(Defined *def) { } } + // Symbols that are runtime pseudo relocations don't point to the actual + // symbol data itself (as they are imported), but points to the IAT entry + // instead. Avoid emitting them to the symbol table, as they can confuse + // debuggers. + if (def->isRuntimePseudoReloc) + return None; + StringRef name = def->getName(); if (name.size() > COFF::NameSize) { sym.Name.Offset.Zeroes = 0; @@ -1198,9 +1220,11 @@ void Writer::assignAddresses() { sizeOfHeaders += config->is64() ? sizeof(pe32plus_header) : sizeof(pe32_header); sizeOfHeaders = alignTo(sizeOfHeaders, config->fileAlign); - uint64_t rva = pageSize; // The first page is kept unmapped. fileSize = sizeOfHeaders; + // The first page is kept unmapped. + uint64_t rva = alignTo(sizeOfHeaders, config->align); + for (OutputSection *sec : outputSections) { if (sec == relocSec) addBaserels(); @@ -1230,10 +1254,10 @@ void Writer::assignAddresses() { sec->header.SizeOfRawData = rawSize; if (rawSize != 0) sec->header.PointerToRawData = fileSize; - rva += alignTo(virtualSize, pageSize); + rva += alignTo(virtualSize, config->align); fileSize += alignTo(rawSize, config->fileAlign); } - sizeOfImage = alignTo(rva, pageSize); + sizeOfImage = alignTo(rva, config->align); // Assign addresses to sections in MergeChunks. for (MergeChunk *mc : MergeChunk::instances) @@ -1302,7 +1326,7 @@ template void Writer::writeHeader() { pe->MinorLinkerVersion = 0; pe->ImageBase = config->imageBase; - pe->SectionAlignment = pageSize; + pe->SectionAlignment = config->align; pe->FileAlignment = config->fileAlign; pe->MajorImageVersion = config->majorImageVersion; pe->MinorImageVersion = config->minorImageVersion; @@ -1354,9 +1378,10 @@ template void Writer::writeHeader() { // Write data directory auto *dir = reinterpret_cast(buf); buf += sizeof(*dir) * numberOfDataDirectory; - if (!config->exports.empty()) { - dir[EXPORT_TABLE].RelativeVirtualAddress = edata.getRVA(); - dir[EXPORT_TABLE].Size = edata.getSize(); + if (edataStart) { + dir[EXPORT_TABLE].RelativeVirtualAddress = edataStart->getRVA(); + dir[EXPORT_TABLE].Size = + edataEnd->getRVA() + edataEnd->getSize() - edataStart->getRVA(); } if (importTableStart) { dir[IMPORT_TABLE].RelativeVirtualAddress = importTableStart->getRVA(); diff --git a/Common/ErrorHandler.cpp b/Common/ErrorHandler.cpp index 983962db5..b91854c51 100644 --- a/Common/ErrorHandler.cpp +++ b/Common/ErrorHandler.cpp @@ -29,16 +29,14 @@ using namespace lld; // but outs() or errs() are not thread-safe. We protect them using a mutex. static std::mutex mu; -// Prints "\n" or does nothing, depending on Msg contents of -// the previous call of this function. -static void newline(raw_ostream *errorOS, const Twine &msg) { - // True if the previous error message contained "\n". - // We want to separate multi-line error messages with a newline. - static bool flag; - - if (flag) - *errorOS << "\n"; - flag = StringRef(msg.str()).contains('\n'); +// We want to separate multi-line messages with a newline. `sep` is "\n" +// if the last messages was multi-line. Otherwise "". +static StringRef sep; + +static StringRef getSeparator(const Twine &msg) { + if (StringRef(msg.str()).contains('\n')) + return "\n"; + return ""; } ErrorHandler &lld::errorHandler() { @@ -46,6 +44,10 @@ ErrorHandler &lld::errorHandler() { return handler; } +void lld::enableColors(bool enable) { + errorHandler().errorOS->enable_colors(enable); +} + void lld::exitLld(int val) { // Delete any temporary file, while keeping the memory mapping open. if (errorHandler().outputBuffer) @@ -85,56 +87,69 @@ void lld::checkError(Error e) { [&](ErrorInfoBase &eib) { error(eib.message()); }); } -static std::string getLocation(std::string msg, std::string defaultMsg) { - static std::vector Regexes{ - std::regex(R"(^undefined symbol:.*\n>>> referenced by (\S+):(\d+)\n.*)"), +// This is for --vs-diagnostics. +// +// Normally, lld's error message starts with argv[0]. Therefore, it usually +// looks like this: +// +// ld.lld: error: ... +// +// This error message style is unfortunately unfriendly to Visual Studio +// IDE. VS interprets the first word of the first line as an error location +// and make it clickable, thus "ld.lld" in the above message would become a +// clickable text. When you click it, VS opens "ld.lld" executable file with +// a binary editor. +// +// As a workaround, we print out an error location instead of "ld.lld" if +// lld is running in VS diagnostics mode. As a result, error message will +// look like this: +// +// src/foo.c(35): error: ... +// +// This function returns an error location string. An error location is +// extracted from an error message using regexps. +std::string ErrorHandler::getLocation(const Twine &msg) { + if (!vsDiagnostics) + return logName; + + static std::regex regexes[] = { + std::regex( + R"(^undefined (?:\S+ )?symbol:.*\n)" + R"(>>> referenced by .+\((\S+):(\d+)\))"), + std::regex( + R"(^undefined (?:\S+ )?symbol:.*\n>>> referenced by (\S+):(\d+))"), std::regex(R"(^undefined symbol:.*\n>>> referenced by (.*):)"), std::regex( R"(^duplicate symbol: .*\n>>> defined in (\S+)\n>>> defined in.*)"), std::regex( - R"(^duplicate symbol: .*\n>>> defined at (\S+):(\d+).*)"), - std::regex( - R"(.*\n>>> defined in .*\n>>> referenced by (\S+):(\d+))"), + R"(^duplicate symbol: .*\n>>> defined at .+\((\S+):(\d+)\))"), + std::regex(R"(^duplicate symbol: .*\n>>> defined at (\S+):(\d+))"), std::regex( - R"(^undefined (internal|hidden|protected) symbol: .*\n>>> referenced by (\S+):(\d+)\n.*)"), + R"(.*\n>>> defined in .*\n>>> referenced by .+\((\S+):(\d+)\))"), + std::regex(R"(.*\n>>> defined in .*\n>>> referenced by (\S+):(\d+))"), std::regex(R"((\S+):(\d+): unclosed quote)"), }; - std::smatch Match; - for (std::regex &Re : Regexes) { - if (std::regex_search(msg, Match, Re)) { - return Match.size() > 2 ? Match.str(1) + "(" + Match.str(2) + ")" - : Match.str(1); - } - } - return defaultMsg; -} - -void ErrorHandler::printHeader(StringRef s, raw_ostream::Colors c, - const Twine &msg) { + std::string str = msg.str(); + for (std::regex &re : regexes) { + std::smatch m; + if (!std::regex_search(str, m, re)) + continue; - if (vsDiagnostics) { - // A Visual Studio-style error message starts with an error location. - // If a location cannot be extracted then we default to LogName. - *errorOS << getLocation(msg.str(), logName) << ": "; - } else { - *errorOS << logName << ": "; + assert(m.size() == 2 || m.size() == 3); + if (m.size() == 2) + return m.str(1); + return m.str(1) + "(" + m.str(2) + ")"; } - if (colorDiagnostics) { - errorOS->changeColor(c, true); - *errorOS << s; - errorOS->resetColor(); - } else { - *errorOS << s; - } + return logName; } void ErrorHandler::log(const Twine &msg) { - if (verbose) { - std::lock_guard lock(mu); - *errorOS << logName << ": " << msg << "\n"; - } + if (!verbose) + return; + std::lock_guard lock(mu); + *errorOS << logName << ": " << msg << "\n"; } void ErrorHandler::message(const Twine &msg) { @@ -150,26 +165,41 @@ void ErrorHandler::warn(const Twine &msg) { } std::lock_guard lock(mu); - newline(errorOS, msg); - printHeader("warning: ", raw_ostream::MAGENTA, msg); - *errorOS << msg << "\n"; + *errorOS << sep << getLocation(msg) << ": " << Colors::MAGENTA + << "warning: " << Colors::RESET << msg << "\n"; + sep = getSeparator(msg); } void ErrorHandler::error(const Twine &msg) { + // If Visual Studio-style error message mode is enabled, + // this particular error is printed out as two errors. + if (vsDiagnostics) { + static std::regex re(R"(^(duplicate symbol: .*))" + R"((\n>>> defined at \S+:\d+.*\n>>>.*))" + R"((\n>>> defined at \S+:\d+.*\n>>>.*))"); + std::string str = msg.str(); + std::smatch m; + + if (std::regex_match(str, m, re)) { + error(m.str(1) + m.str(2)); + error(m.str(1) + m.str(3)); + return; + } + } + std::lock_guard lock(mu); if (errorLimit == 0 || errorCount < errorLimit) { - newline(errorOS, msg); - printHeader("error: ", raw_ostream::RED, msg); - *errorOS << msg << "\n"; + *errorOS << sep << getLocation(msg) << ": " << Colors::RED + << "error: " << Colors::RESET << msg << "\n"; } else if (errorCount == errorLimit) { - newline(errorOS, msg); - printHeader("error: ", raw_ostream::RED, msg); - *errorOS << errorLimitExceededMsg << "\n"; + *errorOS << sep << getLocation(msg) << ": " << Colors::RED + << "error: " << Colors::RESET << errorLimitExceededMsg << "\n"; if (exitEarly) exitLld(1); } + sep = getSeparator(msg); ++errorCount; } diff --git a/Common/Strings.cpp b/Common/Strings.cpp index 0bf06626c..2240f9644 100644 --- a/Common/Strings.cpp +++ b/Common/Strings.cpp @@ -96,7 +96,7 @@ bool lld::isValidCIdentifier(StringRef s) { // Write the contents of the a buffer to a file void lld::saveBuffer(StringRef buffer, const Twine &path) { std::error_code ec; - raw_fd_ostream os(path.str(), ec, sys::fs::OpenFlags::F_None); + raw_fd_ostream os(path.str(), ec, sys::fs::OpenFlags::OF_None); if (ec) error("cannot create " + path + ": " + ec.message()); os << buffer; diff --git a/ELF/Arch/AArch64.cpp b/ELF/Arch/AArch64.cpp index f864c3688..40f0dd65f 100644 --- a/ELF/Arch/AArch64.cpp +++ b/ELF/Arch/AArch64.cpp @@ -76,6 +76,26 @@ AArch64::AArch64() { RelExpr AArch64::getRelExpr(RelType type, const Symbol &s, const uint8_t *loc) const { switch (type) { + case R_AARCH64_ABS16: + case R_AARCH64_ABS32: + case R_AARCH64_ABS64: + case R_AARCH64_ADD_ABS_LO12_NC: + case R_AARCH64_LDST128_ABS_LO12_NC: + case R_AARCH64_LDST16_ABS_LO12_NC: + case R_AARCH64_LDST32_ABS_LO12_NC: + case R_AARCH64_LDST64_ABS_LO12_NC: + case R_AARCH64_LDST8_ABS_LO12_NC: + case R_AARCH64_MOVW_SABS_G0: + case R_AARCH64_MOVW_SABS_G1: + case R_AARCH64_MOVW_SABS_G2: + case R_AARCH64_MOVW_UABS_G0: + case R_AARCH64_MOVW_UABS_G0_NC: + case R_AARCH64_MOVW_UABS_G1: + case R_AARCH64_MOVW_UABS_G1_NC: + case R_AARCH64_MOVW_UABS_G2: + case R_AARCH64_MOVW_UABS_G2_NC: + case R_AARCH64_MOVW_UABS_G3: + return R_ABS; case R_AARCH64_TLSDESC_ADR_PAGE21: return R_AARCH64_TLSDESC_PAGE; case R_AARCH64_TLSDESC_LD64_LO12: @@ -90,6 +110,11 @@ RelExpr AArch64::getRelExpr(RelType type, const Symbol &s, case R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC: case R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC: case R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC: + case R_AARCH64_TLSLE_MOVW_TPREL_G0: + case R_AARCH64_TLSLE_MOVW_TPREL_G0_NC: + case R_AARCH64_TLSLE_MOVW_TPREL_G1: + case R_AARCH64_TLSLE_MOVW_TPREL_G1_NC: + case R_AARCH64_TLSLE_MOVW_TPREL_G2: return R_TLS; case R_AARCH64_CALL26: case R_AARCH64_CONDBR19: @@ -121,7 +146,9 @@ RelExpr AArch64::getRelExpr(RelType type, const Symbol &s, case R_AARCH64_NONE: return R_NONE; default: - return R_ABS; + error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) + + ") against symbol " + toString(s)); + return R_NONE; } } @@ -376,20 +403,25 @@ void AArch64::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { break; case R_AARCH64_MOVW_PREL_G0: case R_AARCH64_MOVW_SABS_G0: + case R_AARCH64_TLSLE_MOVW_TPREL_G0: checkInt(loc, val, 17, type); LLVM_FALLTHROUGH; case R_AARCH64_MOVW_PREL_G0_NC: + case R_AARCH64_TLSLE_MOVW_TPREL_G0_NC: writeSMovWImm(loc, val); break; case R_AARCH64_MOVW_PREL_G1: case R_AARCH64_MOVW_SABS_G1: + case R_AARCH64_TLSLE_MOVW_TPREL_G1: checkInt(loc, val, 33, type); LLVM_FALLTHROUGH; case R_AARCH64_MOVW_PREL_G1_NC: + case R_AARCH64_TLSLE_MOVW_TPREL_G1_NC: writeSMovWImm(loc, val >> 16); break; case R_AARCH64_MOVW_PREL_G2: case R_AARCH64_MOVW_SABS_G2: + case R_AARCH64_TLSLE_MOVW_TPREL_G2: checkInt(loc, val, 49, type); LLVM_FALLTHROUGH; case R_AARCH64_MOVW_PREL_G2_NC: @@ -411,7 +443,7 @@ void AArch64::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { or32AArch64Imm(loc, val); break; default: - error(getErrorLocation(loc) + "unrecognized relocation " + toString(type)); + llvm_unreachable("unknown relocation"); } } diff --git a/ELF/Arch/Hexagon.cpp b/ELF/Arch/Hexagon.cpp index c497a6df7..355ba9de4 100644 --- a/ELF/Arch/Hexagon.cpp +++ b/ELF/Arch/Hexagon.cpp @@ -29,6 +29,7 @@ class Hexagon final : public TargetInfo { uint32_t calcEFlags() const override; RelExpr getRelExpr(RelType type, const Symbol &s, const uint8_t *loc) const override; + RelType getDynRel(RelType type) const override; void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override; void writePltHeader(uint8_t *buf) const override; void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr, @@ -86,6 +87,20 @@ static uint32_t applyMask(uint32_t mask, uint32_t data) { RelExpr Hexagon::getRelExpr(RelType type, const Symbol &s, const uint8_t *loc) const { switch (type) { + case R_HEX_NONE: + return R_NONE; + case R_HEX_6_X: + case R_HEX_8_X: + case R_HEX_9_X: + case R_HEX_10_X: + case R_HEX_11_X: + case R_HEX_12_X: + case R_HEX_16_X: + case R_HEX_32: + case R_HEX_32_6_X: + case R_HEX_HI16: + case R_HEX_LO16: + return R_ABS; case R_HEX_B9_PCREL: case R_HEX_B9_PCREL_X: case R_HEX_B13_PCREL: @@ -99,12 +114,20 @@ RelExpr Hexagon::getRelExpr(RelType type, const Symbol &s, case R_HEX_B22_PCREL_X: case R_HEX_B32_PCREL_X: return R_PLT_PC; + case R_HEX_GOTREL_11_X: + case R_HEX_GOTREL_16_X: + case R_HEX_GOTREL_32_6_X: + case R_HEX_GOTREL_HI16: + case R_HEX_GOTREL_LO16: + return R_GOTPLTREL; case R_HEX_GOT_11_X: case R_HEX_GOT_16_X: case R_HEX_GOT_32_6_X: - return R_HEXAGON_GOT; + return R_GOTPLT; default: - return R_ABS; + error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) + + ") against symbol " + toString(s)); + return R_NONE; } } @@ -197,6 +220,7 @@ void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { break; case R_HEX_11_X: case R_HEX_GOT_11_X: + case R_HEX_GOTREL_11_X: or32le(loc, applyMask(findMaskR11(read32le(loc)), val & 0x3f)); break; case R_HEX_12_X: @@ -204,6 +228,7 @@ void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { break; case R_HEX_16_X: // These relocs only have 6 effective bits. case R_HEX_GOT_16_X: + case R_HEX_GOTREL_16_X: or32le(loc, applyMask(findMaskR16(read32le(loc)), val & 0x3f)); break; case R_HEX_32: @@ -212,6 +237,7 @@ void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { break; case R_HEX_32_6_X: case R_HEX_GOT_32_6_X: + case R_HEX_GOTREL_32_6_X: or32le(loc, applyMask(0x0fff3fff, val >> 6)); break; case R_HEX_B9_PCREL: @@ -239,15 +265,16 @@ void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { case R_HEX_B32_PCREL_X: or32le(loc, applyMask(0x0fff3fff, val >> 6)); break; + case R_HEX_GOTREL_HI16: case R_HEX_HI16: or32le(loc, applyMask(0x00c03fff, val >> 16)); break; + case R_HEX_GOTREL_LO16: case R_HEX_LO16: or32le(loc, applyMask(0x00c03fff, val)); break; default: - error(getErrorLocation(loc) + "unrecognized relocation " + toString(type)); - break; + llvm_unreachable("unknown relocation"); } } @@ -285,6 +312,12 @@ void Hexagon::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, relocateOne(buf + 4, R_HEX_6_PCREL_X, gotPltEntryAddr - pltEntryAddr); } +RelType Hexagon::getDynRel(RelType type) const { + if (type == R_HEX_32) + return type; + return R_HEX_NONE; +} + TargetInfo *elf::getHexagonTargetInfo() { static Hexagon target; return ⌖ diff --git a/ELF/Arch/MipsArchTree.cpp b/ELF/Arch/MipsArchTree.cpp index f64d03756..f745a87a2 100644 --- a/ELF/Arch/MipsArchTree.cpp +++ b/ELF/Arch/MipsArchTree.cpp @@ -166,17 +166,17 @@ static ArchTreeEdge archTree[] = { {EF_MIPS_ARCH_2, EF_MIPS_ARCH_1}, }; -static bool isArchMatched(uint32_t New, uint32_t res) { - if (New == res) +static bool isArchMatched(uint32_t newFlags, uint32_t res) { + if (newFlags == res) return true; - if (New == EF_MIPS_ARCH_32 && isArchMatched(EF_MIPS_ARCH_64, res)) + if (newFlags == EF_MIPS_ARCH_32 && isArchMatched(EF_MIPS_ARCH_64, res)) return true; - if (New == EF_MIPS_ARCH_32R2 && isArchMatched(EF_MIPS_ARCH_64R2, res)) + if (newFlags == EF_MIPS_ARCH_32R2 && isArchMatched(EF_MIPS_ARCH_64R2, res)) return true; for (const auto &edge : archTree) { if (res == edge.child) { res = edge.parent; - if (res == New) + if (res == newFlags) return true; } } @@ -278,18 +278,18 @@ static uint32_t getArchFlags(ArrayRef files) { uint32_t ret = files[0].flags & (EF_MIPS_ARCH | EF_MIPS_MACH); for (const FileFlags &f : files.slice(1)) { - uint32_t New = f.flags & (EF_MIPS_ARCH | EF_MIPS_MACH); + uint32_t newFlags = f.flags & (EF_MIPS_ARCH | EF_MIPS_MACH); // Check ISA compatibility. - if (isArchMatched(New, ret)) + if (isArchMatched(newFlags, ret)) continue; - if (!isArchMatched(ret, New)) { + if (!isArchMatched(ret, newFlags)) { error("incompatible target ISA:\n>>> " + toString(files[0].file) + ": " + getFullArchName(ret) + "\n>>> " + toString(f.file) + ": " + - getFullArchName(New)); + getFullArchName(newFlags)); return 0; } - ret = New; + ret = newFlags; } return ret; } diff --git a/ELF/Arch/PPC.cpp b/ELF/Arch/PPC.cpp index 46c5891e4..cf4ad4049 100644 --- a/ELF/Arch/PPC.cpp +++ b/ELF/Arch/PPC.cpp @@ -190,6 +190,13 @@ bool PPC::inBranchRange(RelType type, uint64_t src, uint64_t dst) const { RelExpr PPC::getRelExpr(RelType type, const Symbol &s, const uint8_t *loc) const { switch (type) { + case R_PPC_NONE: + return R_NONE; + case R_PPC_ADDR16_HA: + case R_PPC_ADDR16_HI: + case R_PPC_ADDR16_LO: + case R_PPC_ADDR32: + return R_ABS; case R_PPC_DTPREL16: case R_PPC_DTPREL16_HA: case R_PPC_DTPREL16_HI: @@ -227,7 +234,9 @@ RelExpr PPC::getRelExpr(RelType type, const Symbol &s, case R_PPC_TPREL16_HI: return R_TLS; default: - return R_ABS; + error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) + + ") against symbol " + toString(s)); + return R_NONE; } } @@ -319,7 +328,7 @@ void PPC::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { break; } default: - error(getErrorLocation(loc) + "unrecognized relocation " + toString(type)); + llvm_unreachable("unknown relocation"); } } diff --git a/ELF/Arch/PPC64.cpp b/ELF/Arch/PPC64.cpp index 70d284cfa..15ad8db46 100644 --- a/ELF/Arch/PPC64.cpp +++ b/ELF/Arch/PPC64.cpp @@ -175,6 +175,10 @@ bool elf::tryRelaxPPC64TocIndirection(RelType type, const Relocation &rel, if (!d || d->isPreemptible) return false; + // R_PPC64_ADDR64 should have created a canonical PLT for the non-preemptable + // ifunc and changed its type to STT_FUNC. + assert(!d->isGnuIFunc()); + // Two instructions can materialize a 32-bit signed offset from the toc base. uint64_t tocRelative = d->getVA(addend) - getPPC64TocBase(); if (!isInt<32>(tocRelative)) @@ -532,6 +536,21 @@ void PPC64::relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const { RelExpr PPC64::getRelExpr(RelType type, const Symbol &s, const uint8_t *loc) const { switch (type) { + case R_PPC64_NONE: + return R_NONE; + case R_PPC64_ADDR16: + case R_PPC64_ADDR16_DS: + case R_PPC64_ADDR16_HA: + case R_PPC64_ADDR16_HI: + case R_PPC64_ADDR16_HIGHER: + case R_PPC64_ADDR16_HIGHERA: + case R_PPC64_ADDR16_HIGHEST: + case R_PPC64_ADDR16_HIGHESTA: + case R_PPC64_ADDR16_LO: + case R_PPC64_ADDR16_LO_DS: + case R_PPC64_ADDR32: + case R_PPC64_ADDR64: + return R_ABS; case R_PPC64_GOT16: case R_PPC64_GOT16_DS: case R_PPC64_GOT16_HA: @@ -554,6 +573,7 @@ RelExpr PPC64::getRelExpr(RelType type, const Symbol &s, return R_PPC64_CALL_PLT; case R_PPC64_REL16_LO: case R_PPC64_REL16_HA: + case R_PPC64_REL16_HI: case R_PPC64_REL32: case R_PPC64_REL64: return R_PC; @@ -607,7 +627,9 @@ RelExpr PPC64::getRelExpr(RelType type, const Symbol &s, case R_PPC64_TLS: return R_TLSIE_HINT; default: - return R_ABS; + error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) + + ") against symbol " + toString(s)); + return R_NONE; } } @@ -870,7 +892,7 @@ void PPC64::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { write64(loc, val - dynamicThreadPointerOffset); break; default: - error(getErrorLocation(loc) + "unrecognized relocation " + toString(type)); + llvm_unreachable("unknown relocation"); } } diff --git a/ELF/CallGraphSort.cpp b/ELF/CallGraphSort.cpp index 9aaadd481..12f89e4f5 100644 --- a/ELF/CallGraphSort.cpp +++ b/ELF/CallGraphSort.cpp @@ -227,7 +227,7 @@ DenseMap CallGraphSort::run() { if (!config->printSymbolOrder.empty()) { std::error_code ec; - raw_fd_ostream os(config->printSymbolOrder, ec, sys::fs::F_None); + raw_fd_ostream os(config->printSymbolOrder, ec, sys::fs::OF_None); if (ec) { error("cannot open " + config->printSymbolOrder + ": " + ec.message()); return orderMap; diff --git a/ELF/Config.h b/ELF/Config.h index ff9d3dc09..c038b50da 100644 --- a/ELF/Config.h +++ b/ELF/Config.h @@ -71,8 +71,8 @@ struct SymbolVersion { // can be found in version script if it is used for link. struct VersionDefinition { llvm::StringRef name; - uint16_t id = 0; - std::vector globals; + uint16_t id; + std::vector patterns; }; // This struct contains the global configuration for the linker. @@ -117,8 +117,6 @@ struct Configuration { std::vector symbolOrderingFile; std::vector undefined; std::vector dynamicList; - std::vector versionScriptGlobals; - std::vector versionScriptLocals; std::vector buildIdVector; llvm::MapVector, uint64_t> @@ -210,6 +208,7 @@ struct Configuration { bool zOrigin; bool zRelro; bool zRodynamic; + bool zSeparateCode; bool zText; bool zRetpolineplt; bool zWxneeded; @@ -223,7 +222,6 @@ struct Configuration { ARMVFPArgKind armVFPArgs = ARMVFPArgKind::Default; BuildIdKind buildId = BuildIdKind::None; ELFKind ekind = ELFNoneKind; - uint16_t defaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL; uint16_t emachine = llvm::ELF::EM_NONE; llvm::Optional imageBase; uint64_t commonPageSize; @@ -309,6 +307,12 @@ struct Configuration { // The only instance of Configuration struct. extern Configuration *config; +// The first two elements of versionDefinitions represent VER_NDX_LOCAL and +// VER_NDX_GLOBAL. This helper returns other elements. +static inline ArrayRef namedVersionDefs() { + return llvm::makeArrayRef(config->versionDefinitions).slice(2); +} + static inline void errorOrWarn(const Twine &msg) { if (!config->noinhibitExec) error(msg); diff --git a/ELF/DWARF.cpp b/ELF/DWARF.cpp index 1e4b36f71..9ef83caf4 100644 --- a/ELF/DWARF.cpp +++ b/ELF/DWARF.cpp @@ -33,11 +33,12 @@ template LLDDwarfObj::LLDDwarfObj(ObjFile *obj) { if (LLDDWARFSection *m = StringSwitch(sec->name) .Case(".debug_addr", &addrSection) - .Case(".debug_gnu_pubnames", &gnuPubNamesSection) - .Case(".debug_gnu_pubtypes", &gnuPubTypesSection) + .Case(".debug_gnu_pubnames", &gnuPubnamesSection) + .Case(".debug_gnu_pubtypes", &gnuPubtypesSection) .Case(".debug_info", &infoSection) - .Case(".debug_ranges", &rangeSection) - .Case(".debug_rnglists", &rngListsSection) + .Case(".debug_ranges", &rangesSection) + .Case(".debug_rnglists", &rnglistsSection) + .Case(".debug_str_offsets", &strOffsetsSection) .Case(".debug_line", &lineSection) .Default(nullptr)) { m->Data = toStringRef(sec->data()); @@ -50,7 +51,7 @@ template LLDDwarfObj::LLDDwarfObj(ObjFile *obj) { else if (sec->name == ".debug_str") strSection = toStringRef(sec->data()); else if (sec->name == ".debug_line_str") - lineStringSection = toStringRef(sec->data()); + lineStrSection = toStringRef(sec->data()); } } diff --git a/ELF/DWARF.h b/ELF/DWARF.h index 426022945..51ec9092f 100644 --- a/ELF/DWARF.h +++ b/ELF/DWARF.h @@ -32,12 +32,16 @@ template class LLDDwarfObj final : public llvm::DWARFObject { f(infoSection); } - const llvm::DWARFSection &getRangeSection() const override { - return rangeSection; + const llvm::DWARFSection &getRangesSection() const override { + return rangesSection; } const llvm::DWARFSection &getRnglistsSection() const override { - return rngListsSection; + return rnglistsSection; + } + + const llvm::DWARFSection &getStrOffsetsSection() const override { + return strOffsetsSection; } const llvm::DWARFSection &getLineSection() const override { @@ -48,18 +52,18 @@ template class LLDDwarfObj final : public llvm::DWARFObject { return addrSection; } - const llvm::DWARFSection &getGnuPubNamesSection() const override { - return gnuPubNamesSection; + const llvm::DWARFSection &getGnuPubnamesSection() const override { + return gnuPubnamesSection; } - const llvm::DWARFSection &getGnuPubTypesSection() const override { - return gnuPubTypesSection; + const llvm::DWARFSection &getGnuPubtypesSection() const override { + return gnuPubtypesSection; } StringRef getFileName() const override { return ""; } StringRef getAbbrevSection() const override { return abbrevSection; } - StringRef getStringSection() const override { return strSection; } - StringRef getLineStringSection() const override { return lineStringSection; } + StringRef getStrSection() const override { return strSection; } + StringRef getLineStrSection() const override { return lineStrSection; } bool isLittleEndian() const override { return ELFT::TargetEndianness == llvm::support::little; @@ -74,16 +78,17 @@ template class LLDDwarfObj final : public llvm::DWARFObject { uint64_t pos, ArrayRef rels) const; - LLDDWARFSection gnuPubNamesSection; - LLDDWARFSection gnuPubTypesSection; + LLDDWARFSection gnuPubnamesSection; + LLDDWARFSection gnuPubtypesSection; LLDDWARFSection infoSection; - LLDDWARFSection rangeSection; - LLDDWARFSection rngListsSection; + LLDDWARFSection rangesSection; + LLDDWARFSection rnglistsSection; + LLDDWARFSection strOffsetsSection; LLDDWARFSection lineSection; LLDDWARFSection addrSection; StringRef abbrevSection; StringRef strSection; - StringRef lineStringSection; + StringRef lineStrSection; }; } // namespace elf diff --git a/ELF/Driver.cpp b/ELF/Driver.cpp index fbfc71d22..8996386e9 100644 --- a/ELF/Driver.cpp +++ b/ELF/Driver.cpp @@ -82,7 +82,7 @@ bool elf::link(ArrayRef args, bool canExitEarly, "-error-limit=0 to see all errors)"; errorHandler().errorOS = &error; errorHandler().exitEarly = canExitEarly; - errorHandler().colorDiagnostics = error.has_colors(); + enableColors(error.has_colors()); inputSections.clear(); outputSections.clear(); @@ -314,6 +314,9 @@ static void checkOptions() { if (!config->relocatable && !config->defineCommon) error("-no-define-common not supported in non relocatable output"); + if (config->strip == StripPolicy::All && config->emitRelocs) + error("--strip-all and --emit-relocs may not be used together"); + if (config->zText && config->zIfuncNoplt) error("-z text and -z ifunc-noplt may not be used together"); @@ -378,9 +381,10 @@ static bool isKnownZFlag(StringRef s) { s == "execstack" || s == "global" || s == "hazardplt" || s == "ifunc-noplt" || s == "initfirst" || s == "interpose" || s == "keep-text-section-prefix" || s == "lazy" || s == "muldefs" || - s == "nocombreloc" || s == "nocopyreloc" || s == "nodefaultlib" || - s == "nodelete" || s == "nodlopen" || s == "noexecstack" || - s == "nokeep-text-section-prefix" || s == "norelro" || s == "notext" || + s == "separate-code" || s == "nocombreloc" || s == "nocopyreloc" || + s == "nodefaultlib" || s == "nodelete" || s == "nodlopen" || + s == "noexecstack" || s == "nokeep-text-section-prefix" || + s == "norelro" || s == "noseparate-code" || s == "notext" || s == "now" || s == "origin" || s == "relro" || s == "retpolineplt" || s == "rodynamic" || s == "text" || s == "wxneeded" || s.startswith("common-page-size") || s.startswith("max-page-size=") || @@ -935,6 +939,7 @@ static void readConfigs(opt::InputArgList &args) { config->zRelro = getZFlag(args, "relro", "norelro", true); config->zRetpolineplt = hasZOption(args, "retpolineplt"); config->zRodynamic = hasZOption(args, "rodynamic"); + config->zSeparateCode = getZFlag(args, "separate-code", "noseparate-code", false); config->zStackSize = args::getZOptionValue(args, OPT_z, "stack-size", 0); config->zText = getZFlag(args, "text", "notext", true); config->zWxneeded = hasZOption(args, "wxneeded"); @@ -1009,30 +1014,33 @@ static void readConfigs(opt::InputArgList &args) { } } + assert(config->versionDefinitions.empty()); + config->versionDefinitions.push_back({"local", (uint16_t)VER_NDX_LOCAL, {}}); + config->versionDefinitions.push_back( + {"global", (uint16_t)VER_NDX_GLOBAL, {}}); + // If --retain-symbol-file is used, we'll keep only the symbols listed in // the file and discard all others. if (auto *arg = args.getLastArg(OPT_retain_symbols_file)) { - config->defaultSymbolVersion = VER_NDX_LOCAL; + config->versionDefinitions[VER_NDX_LOCAL].patterns.push_back( + {"*", /*isExternCpp=*/false, /*hasWildcard=*/true}); if (Optional buffer = readFile(arg->getValue())) for (StringRef s : args::getLines(*buffer)) - config->versionScriptGlobals.push_back( - {s, /*IsExternCpp*/ false, /*HasWildcard*/ false}); + config->versionDefinitions[VER_NDX_GLOBAL].patterns.push_back( + {s, /*isExternCpp=*/false, /*hasWildcard=*/false}); } - bool hasExportDynamic = - args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false); - // Parses -dynamic-list and -export-dynamic-symbol. They make some // symbols private. Note that -export-dynamic takes precedence over them // as it says all symbols should be exported. - if (!hasExportDynamic) { + if (!config->exportDynamic) { for (auto *arg : args.filtered(OPT_dynamic_list)) if (Optional buffer = readFile(arg->getValue())) readDynamicList(*buffer); for (auto *arg : args.filtered(OPT_export_dynamic_symbol)) config->dynamicList.push_back( - {arg->getValue(), /*IsExternCpp*/ false, /*HasWildcard*/ false}); + {arg->getValue(), /*isExternCpp=*/false, /*hasWildcard=*/false}); } // If --export-dynamic-symbol=foo is given and symbol foo is defined in diff --git a/ELF/DriverUtils.cpp b/ELF/DriverUtils.cpp index 87f0aa2a9..5ed37e017 100644 --- a/ELF/DriverUtils.cpp +++ b/ELF/DriverUtils.cpp @@ -59,15 +59,15 @@ static void handleColorDiagnostics(opt::InputArgList &args) { if (!arg) return; if (arg->getOption().getID() == OPT_color_diagnostics) { - errorHandler().colorDiagnostics = true; + enableColors(true); } else if (arg->getOption().getID() == OPT_no_color_diagnostics) { - errorHandler().colorDiagnostics = false; + enableColors(false); } else { StringRef s = arg->getValue(); if (s == "always") - errorHandler().colorDiagnostics = true; + enableColors(true); else if (s == "never") - errorHandler().colorDiagnostics = false; + enableColors(false); else if (s != "auto") error("unknown option: --color-diagnostics=" + s); } diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp index 95a4de33c..71f28f4a6 100644 --- a/ELF/InputFiles.cpp +++ b/ELF/InputFiles.cpp @@ -127,18 +127,18 @@ static bool isCompatible(InputFile *file) { if (!config->emulation.empty()) { error(toString(file) + " is incompatible with " + config->emulation); - } else { - InputFile *existing; - if (!objectFiles.empty()) - existing = objectFiles[0]; - else if (!sharedFiles.empty()) - existing = sharedFiles[0]; - else - existing = bitcodeFiles[0]; - - error(toString(file) + " is incompatible with " + toString(existing)); + return false; } + InputFile *existing; + if (!objectFiles.empty()) + existing = objectFiles[0]; + else if (!sharedFiles.empty()) + existing = sharedFiles[0]; + else + existing = bitcodeFiles[0]; + + error(toString(file) + " is incompatible with " + toString(existing)); return false; } @@ -252,7 +252,7 @@ std::string InputFile::getSrcMsg(const Symbol &sym, InputSectionBase &sec, } template void ObjFile::initializeDwarf() { - dwarf = llvm::make_unique(make_unique>(this)); + dwarf = std::make_unique(std::make_unique>(this)); for (std::unique_ptr &cu : dwarf->compile_units()) { auto report = [](Error err) { handleAllErrors(std::move(err), @@ -1098,6 +1098,7 @@ template void ObjFile::initializeSymbols() { // Handle global undefined symbols. if (eSym.st_shndx == SHN_UNDEF) { this->symbols[i]->resolve(Undefined{this, name, binding, stOther, type}); + this->symbols[i]->referenced = true; continue; } @@ -1474,10 +1475,12 @@ static Symbol *createBitcodeSymbol(const std::vector &keptComdats, int c = objSym.getComdatIndex(); if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) { - Undefined New(&f, name, binding, visibility, type); + Undefined newSym(&f, name, binding, visibility, type); if (canOmitFromDynSym) - New.exportDynamic = false; - return symtab->addSymbol(New); + newSym.exportDynamic = false; + Symbol *ret = symtab->addSymbol(newSym); + ret->referenced = true; + return ret; } if (objSym.isCommon()) @@ -1485,10 +1488,10 @@ static Symbol *createBitcodeSymbol(const std::vector &keptComdats, CommonSymbol{&f, name, binding, visibility, STT_OBJECT, objSym.getCommonAlignment(), objSym.getCommonSize()}); - Defined New(&f, name, binding, visibility, type, 0, 0, nullptr); + Defined newSym(&f, name, binding, visibility, type, 0, 0, nullptr); if (canOmitFromDynSym) - New.exportDynamic = false; - return symtab->addSymbol(New); + newSym.exportDynamic = false; + return symtab->addSymbol(newSym); } template void BitcodeFile::parse() { diff --git a/ELF/InputSection.cpp b/ELF/InputSection.cpp index c9a02c91c..813423bb5 100644 --- a/ELF/InputSection.cpp +++ b/ELF/InputSection.cpp @@ -608,27 +608,39 @@ static int64_t getTlsTpOffset(const Symbol &s) { if (&s == ElfSym::tlsModuleBase) return 0; + // There are 2 TLS layouts. Among targets we support, x86 uses TLS Variant 2 + // while most others use Variant 1. At run time TP will be aligned to p_align. + + // Variant 1. TP will be followed by an optional gap (which is the size of 2 + // pointers on ARM/AArch64, 0 on other targets), followed by alignment + // padding, then the static TLS blocks. The alignment padding is added so that + // (TP + gap + padding) is congruent to p_vaddr modulo p_align. + // + // Variant 2. Static TLS blocks, followed by alignment padding are placed + // before TP. The alignment padding is added so that (TP - padding - + // p_memsz) is congruent to p_vaddr modulo p_align. + elf::PhdrEntry *tls = Out::tlsPhdr; switch (config->emachine) { + // Variant 1. case EM_ARM: case EM_AARCH64: - // Variant 1. The thread pointer points to a TCB with a fixed 2-word size, - // followed by a variable amount of alignment padding, followed by the TLS - // segment. - return s.getVA(0) + alignTo(config->wordsize * 2, Out::tlsPhdr->p_align); - case EM_386: - case EM_X86_64: - // Variant 2. The TLS segment is located just before the thread pointer. - return s.getVA(0) - alignTo(Out::tlsPhdr->p_memsz, Out::tlsPhdr->p_align); + return s.getVA(0) + config->wordsize * 2 + + ((tls->p_vaddr - config->wordsize * 2) & (tls->p_align - 1)); case EM_MIPS: case EM_PPC: case EM_PPC64: - // The thread pointer points to a fixed offset from the start of the - // executable's TLS segment. An offset of 0x7000 allows a signed 16-bit - // offset to reach 0x1000 of TCB/thread-library data and 0xf000 of the - // program's TLS segment. - return s.getVA(0) - 0x7000; + // Adjusted Variant 1. TP is placed with a displacement of 0x7000, which is + // to allow a signed 16-bit offset to reach 0x1000 of TCB/thread-library + // data and 0xf000 of the program's TLS segment. + return s.getVA(0) + (tls->p_vaddr & (tls->p_align - 1)) - 0x7000; case EM_RISCV: - return s.getVA(0); + return s.getVA(0) + (tls->p_vaddr & (tls->p_align - 1)); + + // Variant 2. + case EM_386: + case EM_X86_64: + return s.getVA(0) - tls->p_memsz - + ((-tls->p_vaddr - tls->p_memsz) & (tls->p_align - 1)); default: llvm_unreachable("unhandled Config->EMachine"); } @@ -672,8 +684,6 @@ static uint64_t getRelocTargetVA(const InputFile *file, RelType type, int64_t a, case R_GOT_PC: case R_RELAX_TLS_GD_TO_IE: return sym.getGotVA() + a - p; - case R_HEXAGON_GOT: - return sym.getGotVA() - in.gotPlt->getVA(); case R_MIPS_GOTREL: return sym.getVA(a) - in.mipsGot->getGp(file); case R_MIPS_GOT_GP: diff --git a/ELF/LTO.cpp b/ELF/LTO.cpp index 36880b1b6..00c87fd5f 100644 --- a/ELF/LTO.cpp +++ b/ELF/LTO.cpp @@ -50,7 +50,7 @@ using namespace lld::elf; static std::unique_ptr openFile(StringRef file) { std::error_code ec; auto ret = - llvm::make_unique(file, ec, sys::fs::OpenFlags::F_None); + std::make_unique(file, ec, sys::fs::OpenFlags::OF_None); if (ec) { error("cannot open " + file + ": " + ec.message()); return nullptr; @@ -141,7 +141,7 @@ BitcodeCompiler::BitcodeCompiler() { backend = lto::createInProcessThinBackend(config->thinLTOJobs); } - ltoObj = llvm::make_unique(createConfig(), backend, + ltoObj = std::make_unique(createConfig(), backend, config->ltoPartitions); // Initialize usedStartStop. @@ -251,8 +251,8 @@ std::vector BitcodeCompiler::compile() { if (!bitcodeFiles.empty()) checkError(ltoObj->run( [&](size_t task) { - return llvm::make_unique( - llvm::make_unique(buf[task])); + return std::make_unique( + std::make_unique(buf[task])); }, cache)); diff --git a/ELF/LinkerScript.cpp b/ELF/LinkerScript.cpp index 49e44d780..2fc9b0b09 100644 --- a/ELF/LinkerScript.cpp +++ b/ELF/LinkerScript.cpp @@ -181,12 +181,12 @@ void LinkerScript::addSymbol(SymbolAssignment *cmd) { // write expressions like this: `alignment = 16; . = ALIGN(., alignment)`. uint64_t symValue = value.sec ? 0 : value.getValue(); - Defined New(nullptr, cmd->name, STB_GLOBAL, visibility, STT_NOTYPE, symValue, - 0, sec); + Defined newSym(nullptr, cmd->name, STB_GLOBAL, visibility, STT_NOTYPE, + symValue, 0, sec); Symbol *sym = symtab->insert(cmd->name); - sym->mergeProperties(New); - sym->replace(New); + sym->mergeProperties(newSym); + sym->replace(newSym); cmd->sym = cast(sym); } @@ -197,19 +197,57 @@ static void declareSymbol(SymbolAssignment *cmd) { return; uint8_t visibility = cmd->hidden ? STV_HIDDEN : STV_DEFAULT; - Defined New(nullptr, cmd->name, STB_GLOBAL, visibility, STT_NOTYPE, 0, 0, - nullptr); + Defined newSym(nullptr, cmd->name, STB_GLOBAL, visibility, STT_NOTYPE, 0, 0, + nullptr); // We can't calculate final value right now. Symbol *sym = symtab->insert(cmd->name); - sym->mergeProperties(New); - sym->replace(New); + sym->mergeProperties(newSym); + sym->replace(newSym); cmd->sym = cast(sym); cmd->provide = false; sym->scriptDefined = true; } +using SymbolAssignmentMap = + DenseMap>; + +// Collect section/value pairs of linker-script-defined symbols. This is used to +// check whether symbol values converge. +static SymbolAssignmentMap +getSymbolAssignmentValues(const std::vector §ionCommands) { + SymbolAssignmentMap ret; + for (BaseCommand *base : sectionCommands) { + if (auto *cmd = dyn_cast(base)) { + if (cmd->sym) // sym is nullptr for dot. + ret.try_emplace(cmd->sym, + std::make_pair(cmd->sym->section, cmd->sym->value)); + continue; + } + for (BaseCommand *sub_base : cast(base)->sectionCommands) + if (auto *cmd = dyn_cast(sub_base)) + if (cmd->sym) + ret.try_emplace(cmd->sym, + std::make_pair(cmd->sym->section, cmd->sym->value)); + } + return ret; +} + +// Returns the lexicographical smallest (for determinism) Defined whose +// section/value has changed. +static const Defined * +getChangedSymbolAssignment(const SymbolAssignmentMap &oldValues) { + const Defined *changed = nullptr; + for (auto &it : oldValues) { + const Defined *sym = it.first; + if (std::make_pair(sym->section, sym->value) != it.second && + (!changed || sym->getName() < changed->getName())) + changed = sym; + } + return changed; +} + // This method is used to handle INSERT AFTER statement. Here we rebuild // the list of script commands to mix sections inserted into. void LinkerScript::processInsertCommands() { @@ -304,30 +342,6 @@ bool LinkerScript::shouldKeep(InputSectionBase *s) { return false; } -// A helper function for the SORT() command. -static std::function -getComparator(SortSectionPolicy k) { - switch (k) { - case SortSectionPolicy::Alignment: - return [](InputSectionBase *a, InputSectionBase *b) { - // ">" is not a mistake. Sections with larger alignments are placed - // before sections with smaller alignments in order to reduce the - // amount of padding necessary. This is compatible with GNU. - return a->alignment > b->alignment; - }; - case SortSectionPolicy::Name: - return [](InputSectionBase *a, InputSectionBase *b) { - return a->name < b->name; - }; - case SortSectionPolicy::Priority: - return [](InputSectionBase *a, InputSectionBase *b) { - return getPriority(a->name) < getPriority(b->name); - }; - default: - llvm_unreachable("unknown sort policy"); - } -} - // A helper function for the SORT() command. static bool matchConstraints(ArrayRef sections, ConstraintKind kind) { @@ -343,8 +357,30 @@ static bool matchConstraints(ArrayRef sections, static void sortSections(MutableArrayRef vec, SortSectionPolicy k) { - if (k != SortSectionPolicy::Default && k != SortSectionPolicy::None) - llvm::stable_sort(vec, getComparator(k)); + auto alignmentComparator = [](InputSectionBase *a, InputSectionBase *b) { + // ">" is not a mistake. Sections with larger alignments are placed + // before sections with smaller alignments in order to reduce the + // amount of padding necessary. This is compatible with GNU. + return a->alignment > b->alignment; + }; + auto nameComparator = [](InputSectionBase *a, InputSectionBase *b) { + return a->name < b->name; + }; + auto priorityComparator = [](InputSectionBase *a, InputSectionBase *b) { + return getPriority(a->name) < getPriority(b->name); + }; + + switch (k) { + case SortSectionPolicy::Default: + case SortSectionPolicy::None: + return; + case SortSectionPolicy::Alignment: + return llvm::stable_sort(vec, alignmentComparator); + case SortSectionPolicy::Name: + return llvm::stable_sort(vec, nameComparator); + case SortSectionPolicy::Priority: + return llvm::stable_sort(vec, priorityComparator); + } } // Sort sections as instructed by SORT-family commands and --sort-section @@ -388,9 +424,11 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd) { // which are common because they are in the default bfd script. // We do not ignore SHT_REL[A] linker-synthesized sections here because // want to support scripts that do custom layout for them. - if (auto *isec = dyn_cast(sec)) - if (isec->getRelocatedSection()) - continue; + // + // It is safe to assume that Sec is an InputSection because mergeable or + // EH input sections have already been handled and eliminated. + if (cast(sec)->getRelocatedSection()) + continue; std::string filename = getFilename(sec->file); if (!cmd->filePat.match(filename) || @@ -398,9 +436,6 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd) { !pat.sectionPat.match(sec->name)) continue; - // It is safe to assume that Sec is an InputSection - // because mergeable or EH input sections have already been - // handled and eliminated. ret.push_back(cast(sec)); sec->assigned = true; } @@ -460,7 +495,7 @@ void LinkerScript::processSectionCommands() { // This is needed as there are some cases where we cannot just // thread the current state through to a lambda function created by the // script parser. - auto deleter = make_unique(); + auto deleter = std::make_unique(); ctx = deleter.get(); ctx->outSec = aether; @@ -772,6 +807,14 @@ void LinkerScript::assignOffsets(OutputSection *sec) { if ((sec->flags & SHF_ALLOC) && sec->addrExpr) setDot(sec->addrExpr, sec->location, false); + // If the address of the section has been moved forward by an explicit + // expression so that it now starts past the current curPos of the enclosing + // region, we need to expand the current region to account for the space + // between the previous section, if any, and the start of this section. + if (ctx->memRegion && ctx->memRegion->curPos < dot) + expandMemoryRegion(ctx->memRegion, dot - ctx->memRegion->curPos, + ctx->memRegion->name, sec->name); + switchTo(sec); if (sec->lmaExpr) @@ -1046,14 +1089,17 @@ static uint64_t getInitialDot() { // Here we assign addresses as instructed by linker script SECTIONS // sub-commands. Doing that allows us to use final VA values, so here // we also handle rest commands like symbol assignments and ASSERTs. -void LinkerScript::assignAddresses() { +// Returns a symbol that has changed its section or value, or nullptr if no +// symbol has changed. +const Defined *LinkerScript::assignAddresses() { dot = getInitialDot(); - auto deleter = make_unique(); + auto deleter = std::make_unique(); ctx = deleter.get(); errorOnMissingSection = true; switchTo(aether); + SymbolAssignmentMap oldValues = getSymbolAssignmentValues(sectionCommands); for (BaseCommand *base : sectionCommands) { if (auto *cmd = dyn_cast(base)) { cmd->addr = dot; @@ -1063,7 +1109,9 @@ void LinkerScript::assignAddresses() { } assignOffsets(cast(base)); } + ctx = nullptr; + return getChangedSymbolAssignment(oldValues); } // Creates program headers as instructed by PHDRS linker script command. diff --git a/ELF/LinkerScript.h b/ELF/LinkerScript.h index 9e9c08ef1..5607b3130 100644 --- a/ELF/LinkerScript.h +++ b/ELF/LinkerScript.h @@ -271,7 +271,7 @@ class LinkerScript final { bool needsInterpSection(); bool shouldKeep(InputSectionBase *s); - void assignAddresses(); + const Defined *assignAddresses(); void allocateHeaders(std::vector &phdrs); void processSectionCommands(); void declareSymbols(); diff --git a/ELF/MapFile.cpp b/ELF/MapFile.cpp index a4a6238fc..678f754ea 100644 --- a/ELF/MapFile.cpp +++ b/ELF/MapFile.cpp @@ -39,8 +39,8 @@ using namespace lld::elf; using SymbolMapTy = DenseMap>; -static const std::string indent8 = " "; // 8 spaces -static const std::string indent16 = " "; // 16 spaces +static constexpr char indent8[] = " "; // 8 spaces +static constexpr char indent16[] = " "; // 16 spaces // Print out the first three columns of a line. static void writeHeader(raw_ostream &os, uint64_t vma, uint64_t lma, @@ -145,7 +145,7 @@ void elf::writeMapFile() { // Open a map file for writing. std::error_code ec; - raw_fd_ostream os(config->mapFile, ec, sys::fs::F_None); + raw_fd_ostream os(config->mapFile, ec, sys::fs::OF_None); if (ec) { error("cannot open " + config->mapFile + ": " + ec.message()); return; diff --git a/ELF/MarkLive.cpp b/ELF/MarkLive.cpp index 36b847f72..bd29be7a4 100644 --- a/ELF/MarkLive.cpp +++ b/ELF/MarkLive.cpp @@ -291,6 +291,10 @@ template void MarkLive::mark() { // GOT, which means that the ifunc must be available when the main partition is // loaded) and TLS symbols (because we only know how to correctly process TLS // relocations for the main partition). +// +// We also need to move sections whose names are C identifiers that are referred +// to from __start_/__stop_ symbols because there will only be one set of +// symbols for the whole program. template void MarkLive::moveToMain() { for (InputFile *file : objectFiles) for (Symbol *s : file->getSymbols()) @@ -299,6 +303,14 @@ template void MarkLive::moveToMain() { d->section->isLive()) markSymbol(s); + for (InputSectionBase *sec : inputSections) { + if (!sec->isLive() || !isValidCIdentifier(sec->name)) + continue; + if (symtab->find(("__start_" + sec->name).str()) || + symtab->find(("__stop_" + sec->name).str())) + enqueue(sec, 0); + } + mark(); } diff --git a/ELF/Options.td b/ELF/Options.td index 3ebb46f2e..6246d8494 100644 --- a/ELF/Options.td +++ b/ELF/Options.td @@ -306,7 +306,7 @@ def push_state: F<"push-state">, def print_map: F<"print-map">, HelpText<"Print a link map to the standard output">; -defm reproduce: Eq<"reproduce", "Dump linker invocation and input files for debugging">; +defm reproduce: Eq<"reproduce", "Write a tar file containing input files and command line options to reproduce link">; defm rpath: Eq<"rpath", "Add a DT_RUNPATH to the output">; diff --git a/ELF/Relocations.cpp b/ELF/Relocations.cpp index 7beef6ec1..f7cd17d1e 100644 --- a/ELF/Relocations.cpp +++ b/ELF/Relocations.cpp @@ -344,9 +344,9 @@ static bool needsPlt(RelExpr expr) { // returns false for TLS variables even though they need GOT, because // TLS variables uses GOT differently than the regular variables. static bool needsGot(RelExpr expr) { - return oneof(expr); + return oneof( + expr); } // True if this expression is of the form Sym - X, where X is a position in the @@ -369,7 +369,7 @@ static bool isRelExpr(RelExpr expr) { static bool isStaticLinkTimeConstant(RelExpr e, RelType type, const Symbol &sym, InputSectionBase &s, uint64_t relOff) { // These expressions always compute a constant - if (oneofunresolvedSymbols == UnresolvedPolicy::Ignore && canBeExternal) return false; @@ -996,56 +993,29 @@ static void processRelocAux(InputSectionBase &sec, RelExpr expr, RelType type, } } - if (!canWrite && (config->isPic && !isRelExpr(expr))) { - error( - "can't create dynamic relocation " + toString(type) + " against " + - (sym.getName().empty() ? "local symbol" : "symbol: " + toString(sym)) + - " in readonly segment; recompile object files with -fPIC " - "or pass '-Wl,-z,notext' to allow text relocations in the output" + - getLocation(sec, sym, offset)); - return; - } - - // Copy relocations (for STT_OBJECT) and canonical PLT (for STT_FUNC) are only - // possible in an executable. - // - // Among R_ABS relocatoin types, symbolicRel has the same size as the word - // size. Others have fewer bits and may cause runtime overflow in -pie/-shared - // mode. Disallow them. - if (config->shared || - (config->pie && expr == R_ABS && type != target->symbolicRel)) { - errorOrWarn( - "relocation " + toString(type) + " cannot be used against " + - (sym.getName().empty() ? "local symbol" : "symbol " + toString(sym)) + - "; recompile with -fPIC" + getLocation(sec, sym, offset)); - return; - } - - // If the symbol is undefined we already reported any relevant errors. - if (sym.isUndefined()) - return; - - if (!canDefineSymbolInExecutable(sym)) { - error("cannot preempt symbol: " + toString(sym) + - getLocation(sec, sym, offset)); - return; - } + // When producing an executable, we can perform copy relocations (for + // STT_OBJECT) and canonical PLT (for STT_FUNC). + if (!config->shared) { + if (!canDefineSymbolInExecutable(sym)) { + errorOrWarn("cannot preempt symbol: " + toString(sym) + + getLocation(sec, sym, offset)); + return; + } - if (sym.isObject()) { - // Produce a copy relocation. - if (auto *ss = dyn_cast(&sym)) { - if (!config->zCopyreloc) - error("unresolvable relocation " + toString(type) + - " against symbol '" + toString(*ss) + - "'; recompile with -fPIC or remove '-z nocopyreloc'" + - getLocation(sec, sym, offset)); - addCopyRelSymbol(*ss); + if (sym.isObject()) { + // Produce a copy relocation. + if (auto *ss = dyn_cast(&sym)) { + if (!config->zCopyreloc) + error("unresolvable relocation " + toString(type) + + " against symbol '" + toString(*ss) + + "'; recompile with -fPIC or remove '-z nocopyreloc'" + + getLocation(sec, sym, offset)); + addCopyRelSymbol(*ss); + } + sec.relocations.push_back({expr, type, offset, addend, &sym}); + return; } - sec.relocations.push_back({expr, type, offset, addend, &sym}); - return; - } - if (sym.isFunc()) { // This handles a non PIC program call to function in a shared library. In // an ideal world, we could just report an error saying the relocation can // overflow at runtime. In the real world with glibc, crt1.o has a @@ -1073,18 +1043,37 @@ static void processRelocAux(InputSectionBase &sec, RelExpr expr, RelType type, // compiled without -fPIE/-fPIC and doesn't maintain ebx. // * If a library definition gets preempted to the executable, it will have // the wrong ebx value. - if (config->pie && config->emachine == EM_386) - errorOrWarn("symbol '" + toString(sym) + - "' cannot be preempted; recompile with -fPIE" + - getLocation(sec, sym, offset)); - if (!sym.isInPlt()) - addPltEntry(in.plt, in.gotPlt, in.relaPlt, target->pltRel, sym); - if (!sym.isDefined()) - replaceWithDefined( - sym, in.plt, - target->pltHeaderSize + target->pltEntrySize * sym.pltIndex, 0); - sym.needsPltAddr = true; - sec.relocations.push_back({expr, type, offset, addend, &sym}); + if (sym.isFunc()) { + if (config->pie && config->emachine == EM_386) + errorOrWarn("symbol '" + toString(sym) + + "' cannot be preempted; recompile with -fPIE" + + getLocation(sec, sym, offset)); + if (!sym.isInPlt()) + addPltEntry(in.plt, in.gotPlt, in.relaPlt, target->pltRel, sym); + if (!sym.isDefined()) + replaceWithDefined( + sym, in.plt, + target->pltHeaderSize + target->pltEntrySize * sym.pltIndex, 0); + sym.needsPltAddr = true; + sec.relocations.push_back({expr, type, offset, addend, &sym}); + return; + } + } + + if (config->isPic) { + if (!canWrite && !isRelExpr(expr)) + errorOrWarn( + "can't create dynamic relocation " + toString(type) + " against " + + (sym.getName().empty() ? "local symbol" + : "symbol: " + toString(sym)) + + " in readonly segment; recompile object files with -fPIC " + "or pass '-Wl,-z,notext' to allow text relocations in the output" + + getLocation(sec, sym, offset)); + else + errorOrWarn( + "relocation " + toString(type) + " cannot be used against " + + (sym.getName().empty() ? "local symbol" : "symbol " + toString(sym)) + + "; recompile with -fPIC" + getLocation(sec, sym, offset)); return; } @@ -1092,15 +1081,6 @@ static void processRelocAux(InputSectionBase &sec, RelExpr expr, RelType type, getLocation(sec, sym, offset)); } -struct IRelativeReloc { - RelType type; - InputSectionBase *sec; - uint64_t offset; - Symbol *sym; -}; - -static std::vector iRelativeRelocs; - template static void scanReloc(InputSectionBase &sec, OffsetGetter &getOffset, RelTy *&i, RelTy *end) { @@ -1268,12 +1248,6 @@ static void scanReloc(InputSectionBase &sec, OffsetGetter &getOffset, RelTy *&i, // correctly, the IRELATIVE relocations are stored in an array which a // statically linked executable's startup code must enumerate using the // linker-defined symbols __rela?_iplt_{start,end}. - // - // - An absolute relocation to a non-preemptible ifunc (such as a global - // variable containing a pointer to the ifunc) needs to be relocated in - // the exact same way as a GOT entry, so we can avoid needing to make the - // PLT entry canonical by translating such relocations into IRELATIVE - // relocations in the relaIplt. if (!sym.isInPlt()) { // Create PLT and GOTPLT slots for the symbol. sym.isInIplt = true; @@ -1290,17 +1264,6 @@ static void scanReloc(InputSectionBase &sec, OffsetGetter &getOffset, RelTy *&i, *directSym); sym.pltIndex = directSym->pltIndex; } - if (expr == R_ABS && addend == 0 && (sec.flags & SHF_WRITE)) { - // We might be able to represent this as an IRELATIVE. But we don't know - // yet whether some later relocation will make the symbol point to a - // canonical PLT, which would make this either a dynamic RELATIVE (PIC) or - // static (non-PIC) relocation. So we keep a record of the information - // required to process the relocation, and after scanRelocs() has been - // called on all relocations, the relocation is resolved by - // addIRelativeRelocs(). - iRelativeRelocs.push_back({type, &sec, offset, &sym}); - return; - } if (needsGot(expr)) { // Redirect GOT accesses to point to the Igot. // @@ -1368,21 +1331,6 @@ template void elf::scanRelocations(InputSectionBase &s) { scanRelocs(s, s.rels()); } -// Figure out which representation to use for any absolute relocs to -// non-preemptible ifuncs that we visited during scanRelocs(). -void elf::addIRelativeRelocs() { - for (IRelativeReloc &r : iRelativeRelocs) { - if (r.sym->type == STT_GNU_IFUNC) - in.relaIplt->addReloc( - {target->iRelativeRel, r.sec, r.offset, true, r.sym, 0}); - else if (config->isPic) - addRelativeReloc(r.sec, r.offset, r.sym, 0, R_ABS, r.type); - else - r.sec->relocations.push_back({R_ABS, r.type, r.offset, 0, r.sym}); - } - iRelativeRelocs.clear(); -} - static bool mergeCmp(const InputSection *a, const InputSection *b) { // std::merge requires a strict weak ordering. if (a->outSecOff < b->outSecOff) @@ -1744,11 +1692,6 @@ bool ThunkCreator::createThunks(ArrayRef outputSections) { if (pass == 0 && target->getThunkSectionSpacing()) createInitialThunkSections(outputSections); - // With Thunk Size much smaller than branch range we expect to - // converge quickly; if we get to 10 something has gone wrong. - if (pass == 10) - fatal("thunk creation not converged"); - // Create all the Thunks and insert them into synthetic ThunkSections. The // ThunkSections are later inserted back into InputSectionDescriptions. // We separate the creation of ThunkSections from the insertion of the diff --git a/ELF/Relocations.h b/ELF/Relocations.h index d74d7b9b4..befe15b8f 100644 --- a/ELF/Relocations.h +++ b/ELF/Relocations.h @@ -82,7 +82,6 @@ enum RelExpr { R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC, R_AARCH64_TLSDESC_PAGE, R_ARM_SBREL, - R_HEXAGON_GOT, R_MIPS_GOTREL, R_MIPS_GOT_GP, R_MIPS_GOT_GP_PC, diff --git a/ELF/ScriptParser.cpp b/ELF/ScriptParser.cpp index 8f0aa6601..40c993df5 100644 --- a/ELF/ScriptParser.cpp +++ b/ELF/ScriptParser.cpp @@ -1344,16 +1344,10 @@ void ScriptParser::readAnonymousDeclaration() { std::vector locals; std::vector globals; std::tie(locals, globals) = readSymbols(); - - for (SymbolVersion v : locals) { - if (v.name == "*") - config->defaultSymbolVersion = VER_NDX_LOCAL; - else - config->versionScriptLocals.push_back(v); - } - - for (SymbolVersion v : globals) - config->versionScriptGlobals.push_back(v); + for (const SymbolVersion &pat : locals) + config->versionDefinitions[VER_NDX_LOCAL].patterns.push_back(pat); + for (const SymbolVersion &pat : globals) + config->versionDefinitions[VER_NDX_GLOBAL].patterns.push_back(pat); expect(";"); } @@ -1365,22 +1359,14 @@ void ScriptParser::readVersionDeclaration(StringRef verStr) { std::vector locals; std::vector globals; std::tie(locals, globals) = readSymbols(); - - for (SymbolVersion v : locals) { - if (v.name == "*") - config->defaultSymbolVersion = VER_NDX_LOCAL; - else - config->versionScriptLocals.push_back(v); - } + for (const SymbolVersion &pat : locals) + config->versionDefinitions[VER_NDX_LOCAL].patterns.push_back(pat); // Create a new version definition and add that to the global symbols. VersionDefinition ver; ver.name = verStr; - ver.globals = globals; - - // User-defined version number starts from 2 because 0 and 1 are - // reserved for VER_NDX_LOCAL and VER_NDX_GLOBAL, respectively. - ver.id = config->versionDefinitions.size() + 2; + ver.patterns = globals; + ver.id = config->versionDefinitions.size(); config->versionDefinitions.push_back(ver); // Each version may have a parent version. For example, "Ver2" diff --git a/ELF/SymbolTable.cpp b/ELF/SymbolTable.cpp index 3faeed8c2..64dd1621c 100644 --- a/ELF/SymbolTable.cpp +++ b/ELF/SymbolTable.cpp @@ -71,21 +71,26 @@ Symbol *SymbolTable::insert(StringRef name) { Symbol *sym = reinterpret_cast(make()); symVector.push_back(sym); + // *sym was not initialized by a constructor. Fields that may get referenced + // when it is a placeholder must be initialized here. sym->setName(name); sym->symbolKind = Symbol::PlaceholderKind; - sym->versionId = config->defaultSymbolVersion; + sym->versionId = VER_NDX_GLOBAL; sym->visibility = STV_DEFAULT; sym->isUsedInRegularObj = false; sym->exportDynamic = false; + sym->inDynamicList = false; sym->canInline = true; + sym->referenced = false; + sym->traced = false; sym->scriptDefined = false; sym->partition = 1; return sym; } -Symbol *SymbolTable::addSymbol(const Symbol &New) { - Symbol *sym = symtab->insert(New.getName()); - sym->resolve(New); +Symbol *SymbolTable::addSymbol(const Symbol &newSym) { + Symbol *sym = symtab->insert(newSym.getName()); + sym->resolve(newSym); return sym; } @@ -162,12 +167,8 @@ void SymbolTable::handleDynamicList() { else syms = findByVersion(ver); - for (Symbol *b : syms) { - if (!config->shared) - b->exportDynamic = true; - else if (b->includeInDynsym()) - b->isPreemptible = true; - } + for (Symbol *sym : syms) + sym->inDynamicList = true; } } @@ -192,7 +193,7 @@ void SymbolTable::assignExactVersion(SymbolVersion ver, uint16_t versionId, return "VER_NDX_LOCAL"; if (ver == VER_NDX_GLOBAL) return "VER_NDX_GLOBAL"; - return ("version '" + config->versionDefinitions[ver - 2].name + "'").str(); + return ("version '" + config->versionDefinitions[ver].name + "'").str(); }; // Assign the version. @@ -203,8 +204,12 @@ void SymbolTable::assignExactVersion(SymbolVersion ver, uint16_t versionId, if (sym->getName().contains('@')) continue; - if (sym->versionId == config->defaultSymbolVersion) + // If the version has not been assigned, verdefIndex is -1. Use an arbitrary + // number (0) to indicate the version has been assigned. + if (sym->verdefIndex == UINT32_C(-1)) { + sym->verdefIndex = 0; sym->versionId = versionId; + } if (sym->versionId == versionId) continue; @@ -214,15 +219,14 @@ void SymbolTable::assignExactVersion(SymbolVersion ver, uint16_t versionId, } void SymbolTable::assignWildcardVersion(SymbolVersion ver, uint16_t versionId) { - if (!ver.hasWildcard) - return; - // Exact matching takes precendence over fuzzy matching, // so we set a version to a symbol only if no version has been assigned // to the symbol. This behavior is compatible with GNU. - for (Symbol *b : findAllByVersion(ver)) - if (b->versionId == config->defaultSymbolVersion) - b->versionId = versionId; + for (Symbol *sym : findAllByVersion(ver)) + if (sym->verdefIndex == UINT32_C(-1)) { + sym->verdefIndex = 0; + sym->versionId = versionId; + } } // This function processes version scripts by updating the versionId @@ -233,26 +237,24 @@ void SymbolTable::assignWildcardVersion(SymbolVersion ver, uint16_t versionId) { void SymbolTable::scanVersionScript() { // First, we assign versions to exact matching symbols, // i.e. version definitions not containing any glob meta-characters. - for (SymbolVersion &ver : config->versionScriptGlobals) - assignExactVersion(ver, VER_NDX_GLOBAL, "global"); - for (SymbolVersion &ver : config->versionScriptLocals) - assignExactVersion(ver, VER_NDX_LOCAL, "local"); for (VersionDefinition &v : config->versionDefinitions) - for (SymbolVersion &ver : v.globals) - assignExactVersion(ver, v.id, v.name); - - // Next, we assign versions to fuzzy matching symbols, - // i.e. version definitions containing glob meta-characters. - for (SymbolVersion &ver : config->versionScriptGlobals) - assignWildcardVersion(ver, VER_NDX_GLOBAL); - for (SymbolVersion &ver : config->versionScriptLocals) - assignWildcardVersion(ver, VER_NDX_LOCAL); - - // Note that because the last match takes precedence over previous matches, - // we iterate over the definitions in the reverse order. + for (SymbolVersion &pat : v.patterns) + assignExactVersion(pat, v.id, v.name); + + // Next, assign versions to wildcards that are not "*". Note that because the + // last match takes precedence over previous matches, we iterate over the + // definitions in the reverse order. for (VersionDefinition &v : llvm::reverse(config->versionDefinitions)) - for (SymbolVersion &ver : v.globals) - assignWildcardVersion(ver, v.id); + for (SymbolVersion &pat : v.patterns) + if (pat.hasWildcard && pat.name != "*") + assignWildcardVersion(pat, v.id); + + // Then, assign versions to "*". In GNU linkers they have lower priority than + // other wildcards. + for (VersionDefinition &v : config->versionDefinitions) + for (SymbolVersion &pat : v.patterns) + if (pat.hasWildcard && pat.name == "*") + assignWildcardVersion(pat, v.id); // Symbol themselves might know their versions because symbols // can contain versions in the form of @. @@ -262,7 +264,7 @@ void SymbolTable::scanVersionScript() { // isPreemptible is false at this point. To correctly compute the binding of a // Defined (which is used by includeInDynsym()), we need to know if it is - // VER_NDX_LOCAL or not. If defaultSymbolVersion is VER_NDX_LOCAL, we should - // compute symbol versions before handling --dynamic-list. + // VER_NDX_LOCAL or not. Compute symbol versions before handling + // --dynamic-list. handleDynamicList(); } diff --git a/ELF/SymbolTable.h b/ELF/SymbolTable.h index b64707f4a..d3be0cb64 100644 --- a/ELF/SymbolTable.h +++ b/ELF/SymbolTable.h @@ -43,7 +43,7 @@ class SymbolTable { Symbol *insert(StringRef name); - Symbol *addSymbol(const Symbol &New); + Symbol *addSymbol(const Symbol &newSym); void scanVersionScript(); diff --git a/ELF/Symbols.cpp b/ELF/Symbols.cpp index a9bc613b9..3845da799 100644 --- a/ELF/Symbols.cpp +++ b/ELF/Symbols.cpp @@ -227,7 +227,7 @@ void Symbol::parseSymbolVersion() { if (isDefault) verstr = verstr.substr(1); - for (VersionDefinition &ver : config->versionDefinitions) { + for (const VersionDefinition &ver : namedVersionDefs()) { if (ver.name != verstr) continue; @@ -276,9 +276,8 @@ MemoryBufferRef LazyArchive::getMemberBuffer() { uint8_t Symbol::computeBinding() const { if (config->relocatable) return binding; - if (visibility != STV_DEFAULT && visibility != STV_PROTECTED) - return STB_LOCAL; - if (versionId == VER_NDX_LOCAL && isDefined() && !isPreemptible) + if ((visibility != STV_DEFAULT && visibility != STV_PROTECTED) || + versionId == VER_NDX_LOCAL) return STB_LOCAL; if (!config->gnuUnique && binding == STB_GNU_UNIQUE) return STB_GLOBAL; @@ -296,7 +295,7 @@ bool Symbol::includeInDynsym() const { if (isUndefWeak() && config->pie && sharedFiles.empty()) return false; - return isUndefined() || isShared() || exportDynamic; + return isUndefined() || isShared() || exportDynamic || inDynamicList; } // Print out a log message for --trace-symbol. @@ -492,17 +491,13 @@ void Symbol::resolveUndefined(const Undefined &other) { if (dyn_cast_or_null(other.file)) return; - if (isUndefined()) { - // The binding may "upgrade" from weak to non-weak. - if (other.binding != STB_WEAK) - binding = other.binding; - } else if (auto *s = dyn_cast(this)) { - // The binding of a SharedSymbol will be weak if there is at least one - // reference and all are weak. The binding has one opportunity to change to - // weak: if the first reference is weak. - if (other.binding != STB_WEAK || !s->referenced) + if (isUndefined() || isShared()) { + // The binding will be weak if there is at least one reference and all are + // weak. The binding has one opportunity to change to weak: if the first + // reference is weak. + if (other.binding != STB_WEAK || !referenced) binding = other.binding; - s->referenced = true; + referenced = true; } } @@ -658,6 +653,6 @@ void Symbol::resolveShared(const SharedSymbol &other) { uint8_t bind = binding; replace(other); binding = bind; - cast(this)->referenced = true; + referenced = true; } } diff --git a/ELF/Symbols.h b/ELF/Symbols.h index 9c1eb387c..713d8be9e 100644 --- a/ELF/Symbols.h +++ b/ELF/Symbols.h @@ -116,21 +116,35 @@ class Symbol { // are unreferenced except by other bitcode objects. unsigned isUsedInRegularObj : 1; - // If this flag is true and the symbol has protected or default visibility, it - // will appear in .dynsym. This flag is set by interposable DSO symbols in - // executables, by most symbols in DSOs and executables built with - // --export-dynamic, and by dynamic lists. + // Used by a Defined symbol with protected or default visibility, to record + // whether it is required to be exported into .dynsym. This is set when any of + // the following conditions hold: + // + // - If there is an interposable symbol from a DSO. + // - If -shared or --export-dynamic is specified, any symbol in an object + // file/bitcode sets this property, unless suppressed by LTO + // canBeOmittedFromSymbolTable(). unsigned exportDynamic : 1; + // True if the symbol is in the --dynamic-list file. A Defined symbol with + // protected or default visibility with this property is required to be + // exported into .dynsym. + unsigned inDynamicList : 1; + // False if LTO shouldn't inline whatever this symbol points to. If a symbol // is overwritten after LTO, LTO shouldn't inline the symbol because it // doesn't know the final contents of the symbol. unsigned canInline : 1; + // Used by Undefined and SharedSymbol to track if there has been at least one + // undefined reference to the symbol. The binding may change to STB_WEAK if + // the first undefined reference from a non-shared object is weak. + unsigned referenced : 1; + // True if this symbol is specified by --trace-symbol option. unsigned traced : 1; - inline void replace(const Symbol &New); + inline void replace(const Symbol &newSym); bool includeInDynsym() const; uint8_t computeBinding() const; @@ -228,9 +242,10 @@ class Symbol { : file(file), nameData(name.data), nameSize(name.size), binding(binding), type(type), stOther(stOther), symbolKind(k), visibility(stOther & 3), isUsedInRegularObj(!file || file->kind() == InputFile::ObjKind), - exportDynamic(isExportDynamic(k, visibility)), canInline(false), - traced(false), needsPltAddr(false), isInIplt(false), gotInIgot(false), - isPreemptible(false), used(!config->gcSections), needsTocRestore(false), + exportDynamic(isExportDynamic(k, visibility)), inDynamicList(false), + canInline(false), referenced(false), traced(false), needsPltAddr(false), + isInIplt(false), gotInIgot(false), isPreemptible(false), + used(!config->gcSections), needsTocRestore(false), scriptDefined(false) {} public: @@ -367,11 +382,6 @@ class SharedSymbol : public Symbol { uint64_t value; // st_value uint64_t size; // st_size uint32_t alignment; - - // This is true if there has been at least one undefined reference to the - // symbol. The binding may change to STB_WEAK if the first undefined reference - // is weak. - bool referenced = false; }; // LazyArchive and LazyObject represent a symbols that is not yet in the link, @@ -511,7 +521,7 @@ size_t Symbol::getSymbolSize() const { // replace() replaces "this" object with a given symbol by memcpy'ing // it over to "this". This function is called as a result of name // resolution, e.g. to replace an undefind symbol with a defined symbol. -void Symbol::replace(const Symbol &New) { +void Symbol::replace(const Symbol &newSym) { using llvm::ELF::STT_TLS; // Symbols representing thread-local variables must be referenced by @@ -519,22 +529,23 @@ void Symbol::replace(const Symbol &New) { // non-TLS relocations, so there's a clear distinction between TLS // and non-TLS symbols. It is an error if the same symbol is defined // as a TLS symbol in one file and as a non-TLS symbol in other file. - if (symbolKind != PlaceholderKind && !isLazy() && !New.isLazy()) { - bool tlsMismatch = (type == STT_TLS && New.type != STT_TLS) || - (type != STT_TLS && New.type == STT_TLS); - if (tlsMismatch) - error("TLS attribute mismatch: " + toString(*this) + "\n>>> defined in " + - toString(New.file) + "\n>>> defined in " + toString(file)); - } + if (symbolKind != PlaceholderKind && !isLazy() && !newSym.isLazy() && + (type == STT_TLS) != (newSym.type == STT_TLS)) + error("TLS attribute mismatch: " + toString(*this) + "\n>>> defined in " + + toString(newSym.file) + "\n>>> defined in " + toString(file)); Symbol old = *this; - memcpy(this, &New, New.getSymbolSize()); + memcpy(this, &newSym, newSym.getSymbolSize()); + // old may be a placeholder. The referenced fields must be initialized in + // SymbolTable::insert. versionId = old.versionId; visibility = old.visibility; isUsedInRegularObj = old.isUsedInRegularObj; exportDynamic = old.exportDynamic; + inDynamicList = old.inDynamicList; canInline = old.canInline; + referenced = old.referenced; traced = old.traced; isPreemptible = old.isPreemptible; scriptDefined = old.scriptDefined; diff --git a/ELF/SyntheticSections.cpp b/ELF/SyntheticSections.cpp index f6d0f190d..2bd9dc2d3 100644 --- a/ELF/SyntheticSections.cpp +++ b/ELF/SyntheticSections.cpp @@ -402,7 +402,7 @@ bool EhFrameSection::isFdeLive(EhSectionPiece &fde, ArrayRef rels) { // a list of FDEs. This function searches an existing CIE or create a new // one and associates FDEs to the CIE. template -void EhFrameSection::addSectionAux(EhInputSection *sec, ArrayRef rels) { +void EhFrameSection::addRecords(EhInputSection *sec, ArrayRef rels) { offsetToCie.clear(); for (EhSectionPiece &piece : sec->pieces) { // The empty record is the end marker. @@ -428,8 +428,17 @@ void EhFrameSection::addSectionAux(EhInputSection *sec, ArrayRef rels) { } } -template void EhFrameSection::addSection(InputSectionBase *c) { - auto *sec = cast(c); +template +void EhFrameSection::addSectionAux(EhInputSection *sec) { + if (!sec->isLive()) + return; + if (sec->areRelocsRela) + addRecords(sec, sec->template relas()); + else + addRecords(sec, sec->template rels()); +} + +void EhFrameSection::addSection(EhInputSection *sec) { sec->parent = this; alignment = std::max(alignment, sec->alignment); @@ -437,14 +446,6 @@ template void EhFrameSection::addSection(InputSectionBase *c) { for (auto *ds : sec->dependentSections) dependentSections.push_back(ds); - - if (sec->pieces.empty()) - return; - - if (sec->areRelocsRela) - addSectionAux(sec, sec->template relas()); - else - addSectionAux(sec, sec->template rels()); } static void writeCieFde(uint8_t *buf, ArrayRef d) { @@ -461,6 +462,28 @@ static void writeCieFde(uint8_t *buf, ArrayRef d) { void EhFrameSection::finalizeContents() { assert(!this->size); // Not finalized. + + switch (config->ekind) { + case ELFNoneKind: + llvm_unreachable("invalid ekind"); + case ELF32LEKind: + for (EhInputSection *sec : sections) + addSectionAux(sec); + break; + case ELF32BEKind: + for (EhInputSection *sec : sections) + addSectionAux(sec); + break; + case ELF64LEKind: + for (EhInputSection *sec : sections) + addSectionAux(sec); + break; + case ELF64BEKind: + for (EhInputSection *sec : sections) + addSectionAux(sec); + break; + } + size_t off = 0; for (CieRecord *rec : cieRecords) { rec->cie->outputOff = off; @@ -1162,10 +1185,12 @@ void StringTableSection::writeTo(uint8_t *buf) { } } -// Returns the number of version definition entries. Because the first entry -// is for the version definition itself, it is the number of versioned symbols -// plus one. Note that we don't support multiple versions yet. -static unsigned getVerDefNum() { return config->versionDefinitions.size() + 1; } +// Returns the number of entries in .gnu.version_d: the number of +// non-VER_NDX_LOCAL-non-VER_NDX_GLOBAL definitions, plus 1. +// Note that we don't support vd_cnt > 1 yet. +static unsigned getVerDefNum() { + return namedVersionDefs().size() + 1; +} template DynamicSection::DynamicSection() @@ -1218,6 +1243,25 @@ void DynamicSection::addSym(int32_t tag, Symbol *sym) { entries.push_back({tag, [=] { return sym->getVA(); }}); } +// The output section .rela.dyn may include these synthetic sections: +// +// - part.relaDyn +// - in.relaIplt: this is included if in.relaIplt is named .rela.dyn +// - in.relaPlt: this is included if a linker script places .rela.plt inside +// .rela.dyn +// +// DT_RELASZ is the total size of the included sections. +static std::function addRelaSz(RelocationBaseSection *relaDyn) { + return [=]() { + size_t size = relaDyn->getSize(); + if (in.relaIplt->getParent() == relaDyn->getParent()) + size += in.relaIplt->getSize(); + if (in.relaPlt->getParent() == relaDyn->getParent()) + size += in.relaPlt->getSize(); + return size; + }; +} + // A Linker script may assign the RELA relocation sections to the same // output section. When this occurs we cannot just use the OutputSection // Size. Moreover the [DT_JMPREL, DT_JMPREL + DT_PLTRELSZ) is permitted to @@ -1306,9 +1350,11 @@ template void DynamicSection::finalizeContents() { if (OutputSection *sec = part.dynStrTab->getParent()) this->link = sec->sectionIndex; - if (part.relaDyn->isNeeded()) { + if (part.relaDyn->isNeeded() || + (in.relaIplt->isNeeded() && + part.relaDyn->getParent() == in.relaIplt->getParent())) { addInSec(part.relaDyn->dynamicTag, part.relaDyn); - addSize(part.relaDyn->sizeDynamicTag, part.relaDyn->getParent()); + entries.push_back({part.relaDyn->sizeDynamicTag, addRelaSz(part.relaDyn)}); bool isRela = config->isRela; addInt(isRela ? DT_RELAENT : DT_RELENT, @@ -1679,6 +1725,56 @@ bool AndroidPackedRelocationSection::updateAllocSize() { relativeGroups.emplace_back(std::move(group)); } + // For non-relative relocations, we would like to: + // 1. Have relocations with the same symbol offset to be consecutive, so + // that the runtime linker can speed-up symbol lookup by implementing an + // 1-entry cache. + // 2. Group relocations by r_info to reduce the size of the relocation + // section. + // Since the symbol offset is the high bits in r_info, sorting by r_info + // allows us to do both. + // + // For Rela, we also want to sort by r_addend when r_info is the same. This + // enables us to group by r_addend as well. + llvm::stable_sort(nonRelatives, [](const Elf_Rela &a, const Elf_Rela &b) { + if (a.r_info != b.r_info) + return a.r_info < b.r_info; + if (config->isRela) + return a.r_addend < b.r_addend; + return false; + }); + + // Group relocations with the same r_info. Note that each group emits a group + // header and that may make the relocation section larger. It is hard to + // estimate the size of a group header as the encoded size of that varies + // based on r_info. However, we can approximate this trade-off by the number + // of values encoded. Each group header contains 3 values, and each relocation + // in a group encodes one less value, as compared to when it is not grouped. + // Therefore, we only group relocations if there are 3 or more of them with + // the same r_info. + // + // For Rela, the addend for most non-relative relocations is zero, and thus we + // can usually get a smaller relocation section if we group relocations with 0 + // addend as well. + std::vector ungroupedNonRelatives; + std::vector> nonRelativeGroups; + for (auto i = nonRelatives.begin(), e = nonRelatives.end(); i != e;) { + auto j = i + 1; + while (j != e && i->r_info == j->r_info && + (!config->isRela || i->r_addend == j->r_addend)) + ++j; + if (j - i < 3 || (config->isRela && i->r_addend != 0)) + ungroupedNonRelatives.insert(ungroupedNonRelatives.end(), i, j); + else + nonRelativeGroups.emplace_back(i, j); + i = j; + } + + // Sort ungrouped relocations by offset to minimize the encoded length. + llvm::sort(ungroupedNonRelatives, [](const Elf_Rela &a, const Elf_Rela &b) { + return a.r_offset < b.r_offset; + }); + unsigned hasAddendIfRela = config->isRela ? RELOCATION_GROUP_HAS_ADDEND_FLAG : 0; @@ -1733,14 +1829,23 @@ bool AndroidPackedRelocationSection::updateAllocSize() { } } - // Finally the non-relative relocations. - llvm::sort(nonRelatives, [](const Elf_Rela &a, const Elf_Rela &b) { - return a.r_offset < b.r_offset; - }); - if (!nonRelatives.empty()) { - add(nonRelatives.size()); + // Grouped non-relatives. + for (ArrayRef g : nonRelativeGroups) { + add(g.size()); + add(RELOCATION_GROUPED_BY_INFO_FLAG); + add(g[0].r_info); + for (const Elf_Rela &r : g) { + add(r.r_offset - offset); + offset = r.r_offset; + } + addend = 0; + } + + // Finally the ungrouped non-relative relocations. + if (!ungroupedNonRelatives.empty()) { + add(ungroupedNonRelatives.size()); add(hasAddendIfRela); - for (Elf_Rela &r : nonRelatives) { + for (Elf_Rela &r : ungroupedNonRelatives) { add(r.r_offset - offset); offset = r.r_offset; add(r.r_info); @@ -2452,6 +2557,10 @@ readAddressAreas(DWARFContext &dwarf, InputSection *sec) { uint32_t cuIdx = 0; for (std::unique_ptr &cu : dwarf.compile_units()) { + if (Error e = cu->tryExtractDIEsIfNeeded(false)) { + error(toString(sec) + ": " + toString(std::move(e))); + return {}; + } Expected ranges = cu->collectAddressRanges(); if (!ranges) { error(toString(sec) + ": " + toString(ranges.takeError())); @@ -2481,9 +2590,9 @@ readAddressAreas(DWARFContext &dwarf, InputSection *sec) { template static std::vector readPubNamesAndTypes(const LLDDwarfObj &obj, - const std::vector &cUs) { - const DWARFSection &pubNames = obj.getGnuPubNamesSection(); - const DWARFSection &pubTypes = obj.getGnuPubTypesSection(); + const std::vector &cus) { + const DWARFSection &pubNames = obj.getGnuPubnamesSection(); + const DWARFSection &pubTypes = obj.getGnuPubtypesSection(); std::vector ret; for (const DWARFSection *pub : {&pubNames, &pubTypes}) { @@ -2493,12 +2602,11 @@ readPubNamesAndTypes(const LLDDwarfObj &obj, // don't know how many compilation units precede this object to compute // cuIndex, we compute (kind << 24 | cuIndexInThisObject) instead, and add // the number of preceding compilation units later. - uint32_t i = - lower_bound(cUs, set.Offset, - [](GdbIndexSection::CuEntry cu, uint32_t offset) { - return cu.cuOffset < offset; - }) - - cUs.begin(); + uint32_t i = llvm::partition_point(cus, + [&](GdbIndexSection::CuEntry cu) { + return cu.cuOffset < set.Offset; + }) - + cus.begin(); for (const DWARFDebugPubTable::Entry &ent : set.Entries) ret.push_back({{ent.Name, computeGdbHash(ent.Name)}, (ent.Descriptor.toBits() << 24) | i}); @@ -2603,7 +2711,7 @@ template GdbIndexSection *GdbIndexSection::create() { parallelForEachN(0, sections.size(), [&](size_t i) { ObjFile *file = sections[i]->getFile(); - DWARFContext dwarf(make_unique>(file)); + DWARFContext dwarf(std::make_unique>(file)); chunks[i].sec = sections[i]; chunks[i].compilationUnits = readCuList(dwarf); @@ -2750,7 +2858,7 @@ StringRef VersionDefinitionSection::getFileDefName() { void VersionDefinitionSection::finalizeContents() { fileDefNameOff = getPartition().dynStrTab->addString(getFileDefName()); - for (VersionDefinition &v : config->versionDefinitions) + for (const VersionDefinition &v : namedVersionDefs()) verDefNameOffs.push_back(getPartition().dynStrTab->addString(v.name)); if (OutputSection *sec = getPartition().dynStrTab->getParent()) @@ -2784,7 +2892,7 @@ void VersionDefinitionSection::writeTo(uint8_t *buf) { writeOne(buf, 1, getFileDefName(), fileDefNameOff); auto nameOffIt = verDefNameOffs.begin(); - for (VersionDefinition &v : config->versionDefinitions) { + for (const VersionDefinition &v : namedVersionDefs()) { buf += EntrySize; writeOne(buf, v.id, v.name, *nameOffIt++); } @@ -3177,11 +3285,20 @@ static bool isDuplicateArmExidxSec(InputSection *prev, InputSection *cur) { // The .ARM.exidx table must be sorted in ascending order of the address of the // functions the table describes. Optionally duplicate adjacent table entries -// can be removed. At the end of the function the ExecutableSections must be +// can be removed. At the end of the function the executableSections must be // sorted in ascending order of address, Sentinel is set to the InputSection // with the highest address and any InputSections that have mergeable // .ARM.exidx table entries are removed from it. void ARMExidxSyntheticSection::finalizeContents() { + // The executableSections and exidxSections that we use to derive the final + // contents of this SyntheticSection are populated before + // processSectionCommands() and ICF. A /DISCARD/ entry in SECTIONS command or + // ICF may remove executable InputSections and their dependent .ARM.exidx + // section that we recorded earlier. + auto isDiscarded = [](const InputSection *isec) { return !isec->isLive(); }; + llvm::erase_if(executableSections, isDiscarded); + llvm::erase_if(exidxSections, isDiscarded); + // Sort the executable sections that may or may not have associated // .ARM.exidx sections by order of ascending address. This requires the // relative positions of InputSections to be known. @@ -3389,23 +3506,6 @@ bool PPC64LongBranchTargetSection::isNeeded() const { return !finalized || !entries.empty(); } -RISCVSdataSection::RISCVSdataSection() - : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, 1, ".sdata") {} - -bool RISCVSdataSection::isNeeded() const { - if (!ElfSym::riscvGlobalPointer) - return false; - - // __global_pointer$ is defined relative to .sdata . If the section does not - // exist, create a dummy one. - for (BaseCommand *base : getParent()->sectionCommands) - if (auto *isd = dyn_cast(base)) - for (InputSection *isec : isd->sections) - if (isec != this) - return false; - return true; -} - static uint8_t getAbiVersion() { // MIPS non-PIC executable gets ABI version 1. if (config->emachine == EM_MIPS) { @@ -3542,11 +3642,6 @@ template void elf::splitSections(); template void elf::splitSections(); template void elf::splitSections(); -template void EhFrameSection::addSection(InputSectionBase *); -template void EhFrameSection::addSection(InputSectionBase *); -template void EhFrameSection::addSection(InputSectionBase *); -template void EhFrameSection::addSection(InputSectionBase *); - template void PltSection::addEntry(Symbol &Sym); template void PltSection::addEntry(Symbol &Sym); template void PltSection::addEntry(Symbol &Sym); diff --git a/ELF/SyntheticSections.h b/ELF/SyntheticSections.h index 1c4dd06e0..684639789 100644 --- a/ELF/SyntheticSections.h +++ b/ELF/SyntheticSections.h @@ -76,7 +76,7 @@ class EhFrameSection final : public SyntheticSection { return SyntheticSection::classof(d) && d->name == ".eh_frame"; } - template void addSection(InputSectionBase *s); + void addSection(EhInputSection *sec); std::vector sections; size_t numFdes = 0; @@ -97,7 +97,9 @@ class EhFrameSection final : public SyntheticSection { uint64_t size = 0; template - void addSectionAux(EhInputSection *s, llvm::ArrayRef rels); + void addRecords(EhInputSection *s, llvm::ArrayRef rels); + template + void addSectionAux(EhInputSection *s); template CieRecord *addCie(EhSectionPiece &piece, ArrayRef rels); @@ -1098,15 +1100,6 @@ class PartitionIndexSection : public SyntheticSection { void writeTo(uint8_t *buf) override; }; -// Create a dummy .sdata for __global_pointer$ if .sdata does not exist. -class RISCVSdataSection final : public SyntheticSection { -public: - RISCVSdataSection(); - size_t getSize() const override { return 0; } - bool isNeeded() const override; - void writeTo(uint8_t *buf) override {} -}; - InputSection *createInterpSection(); MergeInputSection *createCommentSection(); template void splitSections(); @@ -1171,7 +1164,6 @@ struct InStruct { PltSection *plt; PltSection *iplt; PPC32Got2Section *ppc32Got2; - RISCVSdataSection *riscvSdata; RelocationBaseSection *relaPlt; RelocationBaseSection *relaIplt; StringTableSection *shStrTab; diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp index d66a699e9..df8b9a9d9 100644 --- a/ELF/Writer.cpp +++ b/ELF/Writer.cpp @@ -62,7 +62,6 @@ template class Writer { void setReservedSymbolSections(); std::vector createPhdrs(Partition &part); - void removeEmptyPTLoad(std::vector &phdrEntry); void addPhdrForSection(Partition &part, unsigned shType, unsigned pType, unsigned pFlags); void assignFileOffsets(); @@ -142,8 +141,7 @@ static bool needsInterpSection() { template void elf::writeResult() { Writer().run(); } -template -void Writer::removeEmptyPTLoad(std::vector &phdrs) { +static void removeEmptyPTLoad(std::vector &phdrs) { llvm::erase_if(phdrs, [&](const PhdrEntry *p) { if (p->p_type != PT_LOAD) return false; @@ -176,7 +174,7 @@ static void copySectionsIntoPartitions() { newSections.end()); } -template static void combineEhSections() { +void elf::combineEhSections() { for (InputSectionBase *&s : inputSections) { // Ignore dead sections and the partition end marker (.part.end), // whose partition number is out of bounds. @@ -185,7 +183,7 @@ template static void combineEhSections() { Partition &part = s->getPartition(); if (auto *es = dyn_cast(s)) { - part.ehFrame->addSection(es); + part.ehFrame->addSection(es); s = nullptr; } else if (s->kind() == SectionBase::Regular && part.armExidx && part.armExidx->addSection(cast(s))) { @@ -355,6 +353,8 @@ template static void createSyntheticSections() { add(sec); } + StringRef relaDynName = config->isRela ? ".rela.dyn" : ".rel.dyn"; + for (Partition &part : partitions) { auto add = [&](InputSectionBase *sec) { sec->partition = part.getNumber(); @@ -378,13 +378,11 @@ template static void createSyntheticSections() { part.dynStrTab = make(".dynstr", true); part.dynSymTab = make>(*part.dynStrTab); part.dynamic = make>(); - if (config->androidPackDynRelocs) { - part.relaDyn = make>( - config->isRela ? ".rela.dyn" : ".rel.dyn"); - } else { - part.relaDyn = make>( - config->isRela ? ".rela.dyn" : ".rel.dyn", config->zCombreloc); - } + if (config->androidPackDynRelocs) + part.relaDyn = make>(relaDynName); + else + part.relaDyn = + make>(relaDynName, config->zCombreloc); if (needsInterpSection()) add(createInterpSection()); @@ -396,7 +394,7 @@ template static void createSyntheticSections() { part.verSym = make(); add(part.verSym); - if (!config->versionDefinitions.empty()) { + if (!namedVersionDefs().empty()) { part.verDef = make(); add(part.verDef); } @@ -476,11 +474,6 @@ template static void createSyntheticSections() { add(in.ppc64LongBranchTarget); } - if (config->emachine == EM_RISCV) { - in.riscvSdata = make(); - add(in.riscvSdata); - } - in.gotPlt = make(); add(in.gotPlt); in.igotPlt = make(); @@ -504,16 +497,14 @@ template static void createSyntheticSections() { config->isRela ? ".rela.plt" : ".rel.plt", /*sort=*/false); add(in.relaPlt); - // The relaIplt immediately follows .rel.plt (.rel.dyn for ARM) to ensure - // that the IRelative relocations are processed last by the dynamic loader. - // We cannot place the iplt section in .rel.dyn when Android relocation - // packing is enabled because that would cause a section type mismatch. - // However, because the Android dynamic loader reads .rel.plt after .rel.dyn, - // we can get the desired behaviour by placing the iplt section in .rel.plt. + // The relaIplt immediately follows .rel[a].dyn to ensure that the IRelative + // relocations are processed last by the dynamic loader. We cannot place the + // iplt section in .rel.dyn when Android relocation packing is enabled because + // that would cause a section type mismatch. However, because the Android + // dynamic loader reads .rel.plt after .rel.dyn, we can get the desired + // behaviour by placing the iplt section in .rel.plt. in.relaIplt = make>( - (config->emachine == EM_ARM && !config->androidPackDynRelocs) - ? ".rel.dyn" - : in.relaPlt->name, + config->androidPackDynRelocs ? in.relaPlt->name : relaDynName, /*sort=*/false); add(in.relaIplt); @@ -556,7 +547,7 @@ template void Writer::run() { // into synthetic sections. Do that now so that they aren't assigned to // output sections in the usual way. if (!config->relocatable) - combineEhSections(); + combineEhSections(); // We want to process linker script commands. When SECTIONS command // is given we let it create sections. @@ -582,8 +573,6 @@ template void Writer::run() { if (errorCount()) return; - script->assignAddresses(); - // If -compressed-debug-sections is specified, we need to compress // .debug_* sections. Do it right now because it changes the size of // output sections. @@ -1070,7 +1059,7 @@ template void Writer::setReservedSymbolSections() { ElfSym::globalOffsetTable->section = gotSection; } - // .rela_iplt_{start,end} mark the start and the end of .rela.plt section. + // .rela_iplt_{start,end} mark the start and the end of in.relaIplt. if (ElfSym::relaIpltStart && in.relaIplt->isNeeded()) { ElfSym::relaIpltStart->section = in.relaIplt; ElfSym::relaIpltEnd->section = in.relaIplt; @@ -1298,10 +1287,7 @@ sortISDBySectionOrder(InputSectionDescription *isd, } orderedSections.push_back({isec, i->second}); } - llvm::sort(orderedSections, [&](std::pair a, - std::pair b) { - return a.second < b.second; - }); + llvm::sort(orderedSections, llvm::less_second()); // Find an insertion point for the ordered section list in the unordered // section list. On targets with limited-range branches, this is the mid-point @@ -1569,15 +1555,18 @@ template void Writer::resolveShfLinkOrder() { template void Writer::finalizeAddressDependentContent() { ThunkCreator tc; AArch64Err843419Patcher a64p; + script->assignAddresses(); - // For some targets, like x86, this loop iterates only once. + int assignPasses = 0; for (;;) { - bool changed = false; - - script->assignAddresses(); + bool changed = target->needsThunks && tc.createThunks(outputSections); - if (target->needsThunks) - changed |= tc.createThunks(outputSections); + // With Thunk Size much smaller than branch range we expect to + // converge quickly; if we get to 10 something has gone wrong. + if (changed && tc.pass >= 10) { + error("thunk creation not converged"); + break; + } if (config->fixCortexA53Errata843419) { if (changed) @@ -1594,8 +1583,19 @@ template void Writer::finalizeAddressDependentContent() { changed |= part.relrDyn->updateAllocSize(); } - if (!changed) - return; + const Defined *changedSym = script->assignAddresses(); + if (!changed) { + // Some symbols may be dependent on section addresses. When we break the + // loop, the symbol values are finalized because a previous + // assignAddresses() finalized section addresses. + if (!changedSym) + break; + if (++assignPasses == 5) { + errorOrWarn("assignment to symbol " + toString(*changedSym) + + " does not converge"); + break; + } + } } } @@ -1655,13 +1655,13 @@ static bool computeIsPreemptible(const Symbol &b) { if (!b.isDefined()) return true; - // If we have a dynamic list it specifies which local symbols are preemptible. - if (config->hasDynamicList) - return false; - if (!config->shared) return false; + // If the dynamic list is present, it specifies preemptable symbols in a DSO. + if (config->hasDynamicList) + return b.inDynamicList; + // -Bsymbolic means that definitions are not preempted. if (config->bsymbolic || (config->bsymbolicFunctions && b.isFunc())) return false; @@ -1696,12 +1696,16 @@ template void Writer::finalizeSections() { // Define __rel[a]_iplt_{start,end} symbols if needed. addRelIpltSymbols(); - // RISC-V's gp can address +/- 2 KiB, set it to .sdata + 0x800 if not defined. - // This symbol should only be defined in an executable. - if (config->emachine == EM_RISCV && !config->shared) + // RISC-V's gp can address +/- 2 KiB, set it to .sdata + 0x800. This symbol + // should only be defined in an executable. If .sdata does not exist, its + // value/section does not matter but it has to be relative, so set its + // st_shndx arbitrarily to 1 (Out::elfHeader). + if (config->emachine == EM_RISCV && !config->shared) { + OutputSection *sec = findSection(".sdata"); ElfSym::riscvGlobalPointer = - addOptionalRegular("__global_pointer$", findSection(".sdata"), 0x800, - STV_DEFAULT, STB_GLOBAL); + addOptionalRegular("__global_pointer$", sec ? sec : Out::elfHeader, + 0x800, STV_DEFAULT, STB_GLOBAL); + } if (config->emachine == EM_X86_64) { // On targets that support TLSDESC, _TLS_MODULE_BASE_ is defined in such a @@ -1730,10 +1734,8 @@ template void Writer::finalizeSections() { for (Partition &part : partitions) finalizeSynthetic(part.ehFrame); - symtab->forEachSymbol([](Symbol *s) { - if (!s->isPreemptible) - s->isPreemptible = computeIsPreemptible(*s); - }); + symtab->forEachSymbol( + [](Symbol *s) { s->isPreemptible = computeIsPreemptible(*s); }); // Scan relocations. This must be done after every symbol is declared so that // we can correctly decide if a dynamic relocation is needed. @@ -1742,8 +1744,6 @@ template void Writer::finalizeSections() { reportUndefinedSymbols(); } - addIRelativeRelocs(); - if (in.plt && in.plt->isNeeded()) in.plt->addSymbols(); if (in.iplt && in.iplt->isNeeded()) @@ -1880,7 +1880,6 @@ template void Writer::finalizeSections() { finalizeSynthetic(in.plt); finalizeSynthetic(in.iplt); finalizeSynthetic(in.ppc32Got2); - finalizeSynthetic(in.riscvSdata); finalizeSynthetic(in.partIndex); // Dynamic section must be the last one in this list and dynamic @@ -2208,21 +2207,66 @@ void Writer::addPhdrForSection(Partition &part, unsigned shType, part.phdrs.push_back(entry); } -// The first section of each PT_LOAD, the first section in PT_GNU_RELRO and the -// first section after PT_GNU_RELRO have to be page aligned so that the dynamic -// linker can set the permissions. +// Place the first section of each PT_LOAD to a different page (of maxPageSize). +// This is achieved by assigning an alignment expression to addrExpr of each +// such section. template void Writer::fixSectionAlignments() { - auto pageAlign = [](OutputSection *cmd) { - if (cmd && !cmd->addrExpr) - cmd->addrExpr = [=] { - return alignTo(script->getDot(), config->maxPageSize); - }; + const PhdrEntry *prev; + auto pageAlign = [&](const PhdrEntry *p) { + OutputSection *cmd = p->firstSec; + if (cmd && !cmd->addrExpr) { + // Prefer advancing to align(dot, maxPageSize) + dot%maxPageSize to avoid + // padding in the file contents. + // + // When -z separate-code is used we must not have any overlap in pages + // between an executable segment and a non-executable segment. We align to + // the next maximum page size boundary on transitions between executable + // and non-executable segments. + // + // TODO Enable this technique on all targets. + bool enable = config->emachine != EM_HEXAGON && + config->emachine != EM_MIPS && + config->emachine != EM_X86_64; + + if (!enable || (config->zSeparateCode && prev && + (prev->p_flags & PF_X) != (p->p_flags & PF_X))) + cmd->addrExpr = [] { + return alignTo(script->getDot(), config->maxPageSize); + }; + // PT_TLS is at the start of the first RW PT_LOAD. If `p` includes PT_TLS, + // it must be the RW. Align to p_align(PT_TLS) to make sure + // p_vaddr(PT_LOAD)%p_align(PT_LOAD) = 0. Otherwise, if + // sh_addralign(.tdata) < sh_addralign(.tbss), we will set p_align(PT_TLS) + // to sh_addralign(.tbss), while p_vaddr(PT_TLS)=p_vaddr(PT_LOAD) may not + // be congruent to 0 modulo p_align(PT_TLS). + // + // Technically this is not required, but as of 2019, some dynamic loaders + // don't handle p_vaddr%p_align != 0 correctly, e.g. glibc (i386 and + // x86-64) doesn't make runtime address congruent to p_vaddr modulo + // p_align for dynamic TLS blocks (PR/24606), FreeBSD rtld has the same + // bug, musl (TLS Variant 1 architectures) before 1.1.23 handled TLS + // blocks correctly. We need to keep the workaround for a while. + else if (Out::tlsPhdr && Out::tlsPhdr->firstSec == p->firstSec) + cmd->addrExpr = [] { + return alignTo(script->getDot(), config->maxPageSize) + + alignTo(script->getDot() % config->maxPageSize, + Out::tlsPhdr->p_align); + }; + else + cmd->addrExpr = [] { + return alignTo(script->getDot(), config->maxPageSize) + + script->getDot() % config->maxPageSize; + }; + } }; for (Partition &part : partitions) { + prev = nullptr; for (const PhdrEntry *p : part.phdrs) - if (p->p_type == PT_LOAD && p->firstSec) - pageAlign(p->firstSec); + if (p->p_type == PT_LOAD && p->firstSec) { + pageAlign(p); + prev = p; + } } } @@ -2230,25 +2274,26 @@ template void Writer::fixSectionAlignments() { // same with its virtual address modulo the page size, so that the loader can // load executables without any address adjustment. static uint64_t computeFileOffset(OutputSection *os, uint64_t off) { - // File offsets are not significant for .bss sections. By convention, we keep - // section offsets monotonically increasing rather than setting to zero. - if (os->type == SHT_NOBITS) - return off; - - // If the section is not in a PT_LOAD, we just have to align it. - if (!os->ptLoad) - return alignTo(off, os->alignment); - // The first section in a PT_LOAD has to have congruent offset and address // module the page size. - OutputSection *first = os->ptLoad->firstSec; - if (os == first) { + if (os->ptLoad && os->ptLoad->firstSec == os) { uint64_t alignment = std::max(os->alignment, config->maxPageSize); return alignTo(off, alignment, os->addr); } + // File offsets are not significant for .bss sections other than the first one + // in a PT_LOAD. By convention, we keep section offsets monotonically + // increasing rather than setting to zero. + if (os->type == SHT_NOBITS) + return off; + + // If the section is not in a PT_LOAD, we just have to align it. + if (!os->ptLoad) + return alignTo(off, os->alignment); + // If two sections share the same PT_LOAD the file offset is calculated // using this formula: Off2 = Off1 + (VA2 - VA1). + OutputSection *first = os->ptLoad->firstSec; return first->offset + os->addr - first->addr; } @@ -2289,13 +2334,11 @@ template void Writer::assignFileOffsets() { for (OutputSection *sec : outputSections) { off = setFileOffset(sec, off); - if (script->hasSectionsCommand) - continue; // If this is a last section of the last executable segment and that // segment is the last loadable segment, align the offset of the // following section to avoid loading non-segments parts of the file. - if (lastRX && lastRX->lastSec == sec) + if (config->zSeparateCode && lastRX && lastRX->lastSec == sec) off = alignTo(off, config->commonPageSize); } @@ -2350,10 +2393,11 @@ template void Writer::setPhdrs(Partition &part) { p->p_align = std::max(p->p_align, config->maxPageSize); } else if (p->p_type == PT_GNU_RELRO) { p->p_align = 1; - // The glibc dynamic loader rounds the size down, so we need to round up + // musl/glibc ld.so rounds the size down, so we need to round up // to protect the last page. This is a no-op on FreeBSD which always // rounds up. - p->p_memsz = alignTo(p->p_memsz, config->commonPageSize); + p->p_memsz = alignTo(p->p_offset + p->p_memsz, config->commonPageSize) - + p->p_offset; } } } @@ -2568,7 +2612,7 @@ static void fillTrap(uint8_t *i, uint8_t *end) { // We'll leave other pages in segments as-is because the rest will be // overwritten by output sections. template void Writer::writeTrapInstr() { - if (script->hasSectionsCommand) + if (!config->zSeparateCode) return; for (Partition &part : partitions) { diff --git a/ELF/Writer.h b/ELF/Writer.h index 784fba9c7..58d8d3116 100644 --- a/ELF/Writer.h +++ b/ELF/Writer.h @@ -19,6 +19,7 @@ namespace elf { class InputFile; class OutputSection; class InputSectionBase; +void combineEhSections(); template void writeResult(); // This describes a program header entry. diff --git a/MinGW/Driver.cpp b/MinGW/Driver.cpp index 24e18aacb..be1b757e4 100644 --- a/MinGW/Driver.cpp +++ b/MinGW/Driver.cpp @@ -303,6 +303,8 @@ bool mingw::link(ArrayRef argsArr, raw_ostream &diag) { add("-include:" + StringRef(a->getValue())); for (auto *a : args.filtered(OPT_undefined)) add("-includeoptional:" + StringRef(a->getValue())); + for (auto *a : args.filtered(OPT_delayload)) + add("-delayload:" + StringRef(a->getValue())); std::vector searchPaths; for (auto *a : args.filtered(OPT_L)) { diff --git a/MinGW/Options.td b/MinGW/Options.td index 44de98dfc..aa57cb326 100644 --- a/MinGW/Options.td +++ b/MinGW/Options.td @@ -4,13 +4,24 @@ class F: Flag<["--", "-"], name>; class J: Joined<["--", "-"], name>; class S: Separate<["--", "-"], name>; +multiclass Eq { + def NAME: Separate<["--", "-"], name>; + def NAME # _eq: Joined<["--", "-"], name # "=">, Alias(NAME)>, + HelpText; +} + +multiclass EqLong { + def NAME: Separate<["--"], name>; + def NAME # _eq: Joined<["--"], name # "=">, Alias(NAME)>, + HelpText; +} + def L: JoinedOrSeparate<["-"], "L">, MetaVarName<"">, HelpText<"Add a directory to the library search path">; def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries">; def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries">; def dynamicbase: F<"dynamicbase">, HelpText<"Enable ASLR">; -def entry: S<"entry">, MetaVarName<"">, - HelpText<"Name of entry point symbol">; +defm entry: Eq<"entry", "Name of entry point symbol">, MetaVarName<"">; def exclude_all_symbols: F<"exclude-all-symbols">, HelpText<"Don't automatically export any symbols">; def export_all_symbols: F<"export-all-symbols">, @@ -25,24 +36,15 @@ def kill_at: F<"kill-at">, HelpText<"Remove @n from exported symbols">; def l: JoinedOrSeparate<["-"], "l">, MetaVarName<"">, HelpText<"Root name of library to use">; def m: JoinedOrSeparate<["-"], "m">, HelpText<"Set target emulation">; -def major_os_version: Separate<["--"], "major-os-version">, - HelpText<"Set the OS and subsystem major version">; -def major_os_version_eq: Joined<["--"], "major-os-version=">, - Alias; -def major_subsystem_version: Separate<["--"], "major-subsystem-version">, - HelpText<"Set the OS and subsystem major version">; -def major_subsystem_version_eq: Joined<["--"], "major-subsystem-version=">, - Alias; -def map: S<"Map">, HelpText<"Output a linker map">; -def map_eq: J<"Map=">, Alias; -def minor_os_version: Separate<["--"], "minor-os-version">, - HelpText<"Set the OS and subsystem minor version">; -def minor_os_version_eq: Joined<["--"], "minor-os-version=">, - Alias; -def minor_subsystem_version: Separate<["--"], "minor-subsystem-version">, - HelpText<"Set the OS and subsystem minor version">; -def minor_subsystem_version_eq: Joined<["--"], "minor-subsystem-version=">, - Alias; +defm major_os_version: EqLong<"major-os-version", + "Set the OS and subsystem major version">; +defm major_subsystem_version: EqLong<"major-subsystem-version", + "Set the OS and subsystem major version">; +defm map: Eq<"Map", "Output a linker map">; +defm minor_os_version: EqLong<"minor-os-version", + "Set the OS and subsystem minor version">; +defm minor_subsystem_version: EqLong<"minor-subsystem-version", + "Set the OS and subsystem minor version">; def no_insert_timestamp: F<"no-insert-timestamp">, HelpText<"Don't include PE header timestamp">; def no_whole_archive: F<"no-whole-archive">, @@ -52,37 +54,31 @@ def large_address_aware: Flag<["--"], "large-address-aware">, def no_gc_sections: F<"no-gc-sections">, HelpText<"Don't remove unused sections">; def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"">, HelpText<"Path to file to write output">; -def out_implib: Separate<["--"], "out-implib">, HelpText<"Import library name">; -def out_implib_eq: Joined<["--"], "out-implib=">, Alias; -def output_def: S<"output-def">, HelpText<"Output def file">; +defm out_implib: Eq<"out-implib", "Import library name">; +defm output_def: Eq<"output-def", "Output def file">; def shared: F<"shared">, HelpText<"Build a shared object">; -def subs: S<"subsystem">, HelpText<"Specify subsystem">; -def subs_eq: J<"subsystem=">, Alias; +defm subs: Eq<"subsystem", "Specify subsystem">; def stack: S<"stack">; def strip_all: F<"strip-all">, HelpText<"Omit all symbol information from the output binary">; def strip_debug: F<"strip-debug">, HelpText<"Omit all debug information, but keep symbol information">; -def undefined: S<"u">, - HelpText<"Include symbol in the link, if available">; -def undefined_long: S<"undefined">, Alias; -def undefined_eq: J<"undefined=">, Alias; +defm undefined: Eq<"undefined", "Include symbol in the link, if available">; def whole_archive: F<"whole-archive">, HelpText<"Include all object files for following archives">; def v: Flag<["-"], "v">, HelpText<"Display the version number">; def verbose: F<"verbose">, HelpText<"Verbose mode">; def version: F<"version">, HelpText<"Display the version number and exit">; -def require_defined: S<"require-defined">, - HelpText<"Force symbol to be added to symbol table as an undefined one">; -def require_defined_eq: J<"require-defined=">, Alias; +defm require_defined: Eq<"require-defined", + "Force symbol to be added to symbol table as an undefined one">; // LLD specific options def _HASH_HASH_HASH : Flag<["-"], "###">, HelpText<"Print (but do not run) the commands to run for this compilation">; def appcontainer: F<"appcontainer">, HelpText<"Set the appcontainer flag in the executable">; +defm delayload: Eq<"delayload", "DLL to load only on demand">; def mllvm: S<"mllvm">; -def pdb: S<"pdb">, HelpText<"Output PDB debug info file, chosen implicitly if the argument is empty">; -def pdb_eq: J<"pdb=">, Alias; +defm pdb: Eq<"pdb", "Output PDB debug info file, chosen implicitly if the argument is empty">; def Xlink : J<"Xlink=">, MetaVarName<"">, HelpText<"Pass to the COFF linker">; @@ -90,6 +86,7 @@ def Xlink : J<"Xlink=">, MetaVarName<"">, def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias; def alias_strip_s: Flag<["-"], "s">, Alias; def alias_strip_S: Flag<["-"], "S">, Alias; +def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias; // Ignored options def: Joined<["-"], "O">; diff --git a/docs/ReleaseNotes.rst b/docs/ReleaseNotes.rst index 520a9fe5a..8cc70656a 100644 --- a/docs/ReleaseNotes.rst +++ b/docs/ReleaseNotes.rst @@ -44,4 +44,7 @@ MachO Improvements WebAssembly Improvements ------------------------ -* ... +* `__data_end` and `__heap_base` are no longer exported by default, + as it's best to keep them internal when possible. They can be + explicitly exported with `--export=__data_end` and + `--export=__heap_base`, respectively. diff --git a/docs/WebAssembly.rst b/docs/WebAssembly.rst index 41522163b..6384a929d 100644 --- a/docs/WebAssembly.rst +++ b/docs/WebAssembly.rst @@ -109,7 +109,7 @@ trap at runtime (functions that contain only an ``unreachable`` instruction) and use these stub functions at the otherwise invalid call sites. The default behaviour is to generate these stub function and to produce -a warning. The ``--falal-warnings`` flag can be used to disable this behaviour +a warning. The ``--fatal-warnings`` flag can be used to disable this behaviour and error out if mismatched are found. Imports and Exports diff --git a/docs/ld.lld.1 b/docs/ld.lld.1 index c432aacf7..fa1b6cc53 100644 --- a/docs/ld.lld.1 +++ b/docs/ld.lld.1 @@ -407,8 +407,13 @@ Undo the effect of .Fl -push-state. .It Fl -relocatable , Fl r Create relocatable object file. -.It Fl -reproduce Ns = Ns Ar value -Dump linker invocation and input files for debugging. +.It Fl -reproduce Ns = Ns Ar path +Write a tar file to +.Ar path, +containing all the input files needed to reproduce the link, a text file called +response.txt containing the command line options and a text file called +version.txt containing the output of ld.lld --version. The archive when +unpacked can be used to re-run the linker with the same options and input files. .It Fl -retain-symbols-file Ns = Ns Ar file Retain only the symbols listed in the file. .It Fl -rpath Ns = Ns Ar value , Fl R Ar value @@ -424,6 +429,8 @@ and .It Fl -script Ns = Ns Ar file , Fl T Ar file Read linker script from .Ar file . +If multiple linker scripts are given, they are processed as if they +were concatenated in the order they appeared on the command line. .It Fl -section-start Ns = Ns Ar section Ns = Ns Ar address Set address of section. .It Fl -shared , Fl -Bsharable diff --git a/include/lld/Common/ErrorHandler.h b/include/lld/Common/ErrorHandler.h index 7126a7bf4..5086fa986 100644 --- a/include/lld/Common/ErrorHandler.h +++ b/include/lld/Common/ErrorHandler.h @@ -87,7 +87,6 @@ class ErrorHandler { StringRef errorLimitExceededMsg = "too many errors emitted, stopping now"; StringRef logName = "lld"; llvm::raw_ostream *errorOS = &llvm::errs(); - bool colorDiagnostics = llvm::errs().has_colors(); bool exitEarly = true; bool fatalWarnings = false; bool verbose = false; @@ -102,12 +101,16 @@ class ErrorHandler { std::unique_ptr outputBuffer; private: - void printHeader(StringRef s, raw_ostream::Colors c, const Twine &msg); + using Colors = raw_ostream::Colors; + + std::string getLocation(const Twine &msg); }; /// Returns the default error handler. ErrorHandler &errorHandler(); +void enableColors(bool enable); + inline void error(const Twine &msg) { errorHandler().error(msg); } inline LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &msg) { errorHandler().fatal(msg); diff --git a/include/lld/ReaderWriter/MachOLinkingContext.h b/include/lld/ReaderWriter/MachOLinkingContext.h index f48ad7705..a950fd5b1 100644 --- a/include/lld/ReaderWriter/MachOLinkingContext.h +++ b/include/lld/ReaderWriter/MachOLinkingContext.h @@ -101,7 +101,7 @@ class MachOLinkingContext : public LinkingContext { auto file = std::unique_ptr(new T(std::forward(args)...)); auto *filePtr = file.get(); auto *ctx = const_cast(this); - ctx->getNodes().push_back(llvm::make_unique(std::move(file))); + ctx->getNodes().push_back(std::make_unique(std::move(file))); return filePtr; } diff --git a/lib/Driver/DarwinLdDriver.cpp b/lib/Driver/DarwinLdDriver.cpp index 8646d86c0..8566ababc 100644 --- a/lib/Driver/DarwinLdDriver.cpp +++ b/lib/Driver/DarwinLdDriver.cpp @@ -95,7 +95,7 @@ class DarwinLdOptTable : public llvm::opt::OptTable { static std::vector> makeErrorFile(StringRef path, std::error_code ec) { std::vector> result; - result.push_back(llvm::make_unique(path, ec)); + result.push_back(std::make_unique(path, ec)); return result; } @@ -160,7 +160,7 @@ static void addFile(StringRef path, MachOLinkingContext &ctx, std::vector> files = loadFile(ctx, path, loadWholeArchive, upwardDylib); for (std::unique_ptr &file : files) - ctx.getNodes().push_back(llvm::make_unique(std::move(file))); + ctx.getNodes().push_back(std::make_unique(std::move(file))); } // Export lists are one symbol per line. Blank lines are ignored. @@ -1138,7 +1138,7 @@ static void createFiles(MachOLinkingContext &ctx, bool Implicit) { ctx.createInternalFiles(Files); for (auto i = Files.rbegin(), e = Files.rend(); i != e; ++i) { auto &members = ctx.getNodes(); - members.insert(members.begin(), llvm::make_unique(std::move(*i))); + members.insert(members.begin(), std::make_unique(std::move(*i))); } } @@ -1151,7 +1151,7 @@ bool link(llvm::ArrayRef args, bool CanExitEarly, "'-error-limit 0' to see all errors)"; errorHandler().errorOS = &Error; errorHandler().exitEarly = CanExitEarly; - errorHandler().colorDiagnostics = Error.has_colors(); + enableColors(Error.has_colors()); MachOLinkingContext ctx; if (!parse(args, ctx)) @@ -1185,7 +1185,7 @@ bool link(llvm::ArrayRef args, bool CanExitEarly, merged = mergedFile.get(); auto &members = ctx.getNodes(); members.insert(members.begin(), - llvm::make_unique(std::move(mergedFile))); + std::make_unique(std::move(mergedFile))); } resolveTask.end(); diff --git a/lib/ReaderWriter/FileArchive.cpp b/lib/ReaderWriter/FileArchive.cpp index b09bf34dc..98f4d06ee 100644 --- a/lib/ReaderWriter/FileArchive.cpp +++ b/lib/ReaderWriter/FileArchive.cpp @@ -210,7 +210,7 @@ class ArchiveReader : public Reader { const Registry ®) const override { StringRef path = mb->getBufferIdentifier(); std::unique_ptr ret = - llvm::make_unique(std::move(mb), reg, path, _logLoading); + std::make_unique(std::move(mb), reg, path, _logLoading); return std::move(ret); } diff --git a/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp b/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp index 316b5bbc6..687407049 100644 --- a/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp +++ b/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp @@ -181,6 +181,20 @@ class ArchHandler_x86_64 : public ArchHandler { FindAddressForAtom addressForAtom, normalized::Relocations &relocs) override; + bool isDataInCodeTransition(Reference::KindValue refKind) override { + return refKind == modeCode || refKind == modeData; + } + + Reference::KindValue dataInCodeTransitionStart( + const MachODefinedAtom &atom) override { + return modeData; + } + + Reference::KindValue dataInCodeTransitionEnd( + const MachODefinedAtom &atom) override { + return modeCode; + } + private: static const Registry::KindStrings _sKindStrings[]; static const StubInfo _sStubInfo; @@ -188,6 +202,9 @@ class ArchHandler_x86_64 : public ArchHandler { enum X86_64Kind: Reference::KindValue { invalid, /// for error condition + modeCode, /// Content starting at this offset is code. + modeData, /// Content starting at this offset is data. + // Kinds found in mach-o .o files: branch32, /// ex: call _foo ripRel32, /// ex: movq _foo(%rip), %rax @@ -242,24 +259,34 @@ class ArchHandler_x86_64 : public ArchHandler { }; const Registry::KindStrings ArchHandler_x86_64::_sKindStrings[] = { - LLD_KIND_STRING_ENTRY(invalid), LLD_KIND_STRING_ENTRY(branch32), - LLD_KIND_STRING_ENTRY(ripRel32), LLD_KIND_STRING_ENTRY(ripRel32Minus1), - LLD_KIND_STRING_ENTRY(ripRel32Minus2), LLD_KIND_STRING_ENTRY(ripRel32Minus4), + LLD_KIND_STRING_ENTRY(invalid), + LLD_KIND_STRING_ENTRY(modeCode), + LLD_KIND_STRING_ENTRY(modeData), + LLD_KIND_STRING_ENTRY(branch32), + LLD_KIND_STRING_ENTRY(ripRel32), + LLD_KIND_STRING_ENTRY(ripRel32Minus1), + LLD_KIND_STRING_ENTRY(ripRel32Minus2), + LLD_KIND_STRING_ENTRY(ripRel32Minus4), LLD_KIND_STRING_ENTRY(ripRel32Anon), LLD_KIND_STRING_ENTRY(ripRel32Minus1Anon), LLD_KIND_STRING_ENTRY(ripRel32Minus2Anon), LLD_KIND_STRING_ENTRY(ripRel32Minus4Anon), LLD_KIND_STRING_ENTRY(ripRel32GotLoad), LLD_KIND_STRING_ENTRY(ripRel32GotLoadNowLea), - LLD_KIND_STRING_ENTRY(ripRel32Got), LLD_KIND_STRING_ENTRY(ripRel32Tlv), + LLD_KIND_STRING_ENTRY(ripRel32Got), + LLD_KIND_STRING_ENTRY(ripRel32Tlv), LLD_KIND_STRING_ENTRY(lazyPointer), LLD_KIND_STRING_ENTRY(lazyImmediateLocation), - LLD_KIND_STRING_ENTRY(pointer64), LLD_KIND_STRING_ENTRY(pointer64Anon), - LLD_KIND_STRING_ENTRY(delta32), LLD_KIND_STRING_ENTRY(delta64), - LLD_KIND_STRING_ENTRY(delta32Anon), LLD_KIND_STRING_ENTRY(delta64Anon), + LLD_KIND_STRING_ENTRY(pointer64), + LLD_KIND_STRING_ENTRY(pointer64Anon), + LLD_KIND_STRING_ENTRY(delta32), + LLD_KIND_STRING_ENTRY(delta64), + LLD_KIND_STRING_ENTRY(delta32Anon), + LLD_KIND_STRING_ENTRY(delta64Anon), LLD_KIND_STRING_ENTRY(negDelta64), LLD_KIND_STRING_ENTRY(negDelta32), - LLD_KIND_STRING_ENTRY(imageOffset), LLD_KIND_STRING_ENTRY(imageOffsetGot), + LLD_KIND_STRING_ENTRY(imageOffset), + LLD_KIND_STRING_ENTRY(imageOffsetGot), LLD_KIND_STRING_ENTRY(unwindFDEToFunction), LLD_KIND_STRING_ENTRY(unwindInfoToEhFrame), LLD_KIND_STRING_ENTRY(tlvInitSectionOffset), @@ -601,6 +628,8 @@ void ArchHandler_x86_64::applyFixupFinal( case negDelta32: *loc32 = fixupAddress - targetAddress + ref.addend(); return; + case modeCode: + case modeData: case lazyPointer: // Do nothing return; @@ -720,6 +749,8 @@ void ArchHandler_x86_64::applyFixupRelocatable(const Reference &ref, case unwindInfoToEhFrame: llvm_unreachable("fixup implies __unwind_info"); return; + case modeCode: + case modeData: case unwindFDEToFunction: // Do nothing for now return; @@ -743,6 +774,9 @@ void ArchHandler_x86_64::appendSectionRelocations( assert(ref.kindArch() == Reference::KindArch::x86_64); uint32_t sectionOffset = atomSectionOffset + ref.offsetInAtom(); switch (static_cast(ref.kindValue())) { + case modeCode: + case modeData: + return; case branch32: appendReloc(relocs, sectionOffset, symbolIndexForAtom(*ref.target()), 0, X86_64_RELOC_BRANCH | rPcRel | rExtern | rLength4); diff --git a/lib/ReaderWriter/MachO/CompactUnwindPass.cpp b/lib/ReaderWriter/MachO/CompactUnwindPass.cpp index de5adb088..44e6a29a0 100644 --- a/lib/ReaderWriter/MachO/CompactUnwindPass.cpp +++ b/lib/ReaderWriter/MachO/CompactUnwindPass.cpp @@ -573,7 +573,7 @@ class CompactUnwindPass : public Pass { void addCompactUnwindPass(PassManager &pm, const MachOLinkingContext &ctx) { assert(ctx.needsCompactUnwindPass()); - pm.add(llvm::make_unique(ctx)); + pm.add(std::make_unique(ctx)); } } // end namesapce mach_o diff --git a/lib/ReaderWriter/MachO/GOTPass.cpp b/lib/ReaderWriter/MachO/GOTPass.cpp index bc66d49ea..514dd4e09 100644 --- a/lib/ReaderWriter/MachO/GOTPass.cpp +++ b/lib/ReaderWriter/MachO/GOTPass.cpp @@ -176,7 +176,7 @@ class GOTPass : public Pass { void addGOTPass(PassManager &pm, const MachOLinkingContext &ctx) { assert(ctx.needsGOTPass()); - pm.add(llvm::make_unique(ctx)); + pm.add(std::make_unique(ctx)); } } // end namesapce mach_o diff --git a/lib/ReaderWriter/MachO/LayoutPass.cpp b/lib/ReaderWriter/MachO/LayoutPass.cpp index 2718dfcf7..8db6ffb95 100644 --- a/lib/ReaderWriter/MachO/LayoutPass.cpp +++ b/lib/ReaderWriter/MachO/LayoutPass.cpp @@ -478,7 +478,7 @@ llvm::Error LayoutPass::perform(SimpleFile &mergedFile) { } void addLayoutPass(PassManager &pm, const MachOLinkingContext &ctx) { - pm.add(llvm::make_unique( + pm.add(std::make_unique( ctx.registry(), [&](const DefinedAtom * left, const DefinedAtom * right, bool & leftBeforeRight) ->bool { return ctx.customAtomOrderer(left, right, leftBeforeRight); diff --git a/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index 38456024c..221d895a4 100644 --- a/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -802,9 +802,9 @@ void MachOLinkingContext::addSectCreateSection( std::unique_ptr content) { if (!_sectCreateFile) { - auto sectCreateFile = llvm::make_unique(); + auto sectCreateFile = std::make_unique(); _sectCreateFile = sectCreateFile.get(); - getNodes().push_back(llvm::make_unique(std::move(sectCreateFile))); + getNodes().push_back(std::make_unique(std::move(sectCreateFile))); } assert(_sectCreateFile && "sectcreate file does not exist."); @@ -897,8 +897,8 @@ static void addDependencyInfoHelper(llvm::raw_fd_ostream *DepInfo, std::error_code MachOLinkingContext::createDependencyFile(StringRef path) { std::error_code ec; - _dependencyInfo = std::unique_ptr(new - llvm::raw_fd_ostream(path, ec, llvm::sys::fs::F_None)); + _dependencyInfo = std::unique_ptr( + new llvm::raw_fd_ostream(path, ec, llvm::sys::fs::OF_None)); if (ec) { _dependencyInfo.reset(); return ec; @@ -1019,7 +1019,7 @@ void MachOLinkingContext::finalizeInputFiles() { return !isLibrary(a) && isLibrary(b); }); size_t numLibs = std::count_if(elements.begin(), elements.end(), isLibrary); - elements.push_back(llvm::make_unique(numLibs)); + elements.push_back(std::make_unique(numLibs)); } llvm::Error MachOLinkingContext::handleLoadedFile(File &file) { diff --git a/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp b/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp index 38b365374..963f1227f 100644 --- a/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp +++ b/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp @@ -542,7 +542,7 @@ class MachOObjectReader : public Reader { loadFile(std::unique_ptr mb, const Registry ®istry) const override { std::unique_ptr ret = - llvm::make_unique(std::move(mb), &_ctx); + std::make_unique(std::move(mb), &_ctx); return std::move(ret); } @@ -568,7 +568,7 @@ class MachODylibReader : public Reader { loadFile(std::unique_ptr mb, const Registry ®istry) const override { std::unique_ptr ret = - llvm::make_unique(std::move(mb), &_ctx); + std::make_unique(std::move(mb), &_ctx); return std::move(ret); } diff --git a/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp index 879f07fb4..f34857b99 100644 --- a/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp +++ b/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp @@ -717,7 +717,7 @@ llvm::Error parseStabs(MachOFile &file, // FIXME: Kill this off when we can move to sane yaml parsing. std::unique_ptr allocator; if (copyRefs) - allocator = llvm::make_unique(); + allocator = std::make_unique(); enum { start, inBeginEnd } state = start; @@ -812,7 +812,7 @@ llvm::Error parseStabs(MachOFile &file, stabsList.push_back(stab); } - file.setDebugInfo(llvm::make_unique(std::move(stabsList))); + file.setDebugInfo(std::make_unique(std::move(stabsList))); // FIXME: Kill this off when we fix YAML memory ownership. file.debugInfo()->setAllocator(std::move(allocator)); @@ -832,10 +832,10 @@ dataExtractorFromSection(const NormalizedFile &normalizedFile, // FIXME: Cribbed from llvm-dwp -- should share "lightweight CU DIE // inspection" code if possible. -static uint32_t getCUAbbrevOffset(llvm::DataExtractor abbrevData, +static uint64_t getCUAbbrevOffset(llvm::DataExtractor abbrevData, uint64_t abbrCode) { uint64_t curCode; - uint32_t offset = 0; + uint64_t offset = 0; while ((curCode = abbrevData.getULEB128(&offset)) != abbrCode) { // Tag abbrevData.getULEB128(&offset); @@ -853,13 +853,13 @@ static uint32_t getCUAbbrevOffset(llvm::DataExtractor abbrevData, static Expected getIndexedString(const NormalizedFile &normalizedFile, llvm::dwarf::Form form, llvm::DataExtractor infoData, - uint32_t &infoOffset, const Section &stringsSection) { + uint64_t &infoOffset, const Section &stringsSection) { if (form == llvm::dwarf::DW_FORM_string) return infoData.getCStr(&infoOffset); if (form != llvm::dwarf::DW_FORM_strp) return llvm::make_error( "string field encoded without DW_FORM_strp"); - uint32_t stringOffset = infoData.getU32(&infoOffset); + uint64_t stringOffset = infoData.getU32(&infoOffset); llvm::DataExtractor stringsData = dataExtractorFromSection(normalizedFile, stringsSection); return stringsData.getCStr(&stringOffset); @@ -875,7 +875,7 @@ readCompUnit(const NormalizedFile &normalizedFile, StringRef path) { // FIXME: Cribbed from llvm-dwp -- should share "lightweight CU DIE // inspection" code if possible. - uint32_t offset = 0; + uint64_t offset = 0; llvm::dwarf::DwarfFormat Format = llvm::dwarf::DwarfFormat::DWARF32; auto infoData = dataExtractorFromSection(normalizedFile, info); uint32_t length = infoData.getU32(&offset); @@ -897,7 +897,7 @@ readCompUnit(const NormalizedFile &normalizedFile, uint32_t abbrCode = infoData.getULEB128(&offset); auto abbrevData = dataExtractorFromSection(normalizedFile, abbrev); - uint32_t abbrevOffset = getCUAbbrevOffset(abbrevData, abbrCode); + uint64_t abbrevOffset = getCUAbbrevOffset(abbrevData, abbrCode); uint64_t tag = abbrevData.getULEB128(&abbrevOffset); if (tag != llvm::dwarf::DW_TAG_compile_unit) return llvm::make_error("top level DIE is not a compile unit"); @@ -974,11 +974,11 @@ llvm::Error parseDebugInfo(MachOFile &file, // memory ownership. std::unique_ptr allocator; if (copyRefs) { - allocator = llvm::make_unique(); + allocator = std::make_unique(); tuOrErr->name = copyDebugString(tuOrErr->name, *allocator); tuOrErr->path = copyDebugString(tuOrErr->path, *allocator); } - file.setDebugInfo(llvm::make_unique(std::move(*tuOrErr))); + file.setDebugInfo(std::make_unique(std::move(*tuOrErr))); if (copyRefs) file.debugInfo()->setAllocator(std::move(allocator)); } else diff --git a/lib/ReaderWriter/MachO/ObjCPass.cpp b/lib/ReaderWriter/MachO/ObjCPass.cpp index df121f0e1..02a95b5aa 100644 --- a/lib/ReaderWriter/MachO/ObjCPass.cpp +++ b/lib/ReaderWriter/MachO/ObjCPass.cpp @@ -124,7 +124,7 @@ class ObjCPass : public Pass { void addObjCPass(PassManager &pm, const MachOLinkingContext &ctx) { - pm.add(llvm::make_unique(ctx)); + pm.add(std::make_unique(ctx)); } } // end namespace mach_o diff --git a/lib/ReaderWriter/MachO/ShimPass.cpp b/lib/ReaderWriter/MachO/ShimPass.cpp index b0775ad5f..a5b34cfe8 100644 --- a/lib/ReaderWriter/MachO/ShimPass.cpp +++ b/lib/ReaderWriter/MachO/ShimPass.cpp @@ -121,7 +121,7 @@ class ShimPass : public Pass { void addShimPass(PassManager &pm, const MachOLinkingContext &ctx) { - pm.add(llvm::make_unique(ctx)); + pm.add(std::make_unique(ctx)); } } // end namespace mach_o diff --git a/lib/ReaderWriter/MachO/TLVPass.cpp b/lib/ReaderWriter/MachO/TLVPass.cpp index 89b655e1f..5f457b863 100644 --- a/lib/ReaderWriter/MachO/TLVPass.cpp +++ b/lib/ReaderWriter/MachO/TLVPass.cpp @@ -133,7 +133,7 @@ class TLVPass : public Pass { void addTLVPass(PassManager &pm, const MachOLinkingContext &ctx) { assert(ctx.needsTLVPass()); - pm.add(llvm::make_unique(ctx)); + pm.add(std::make_unique(ctx)); } } // end namesapce mach_o diff --git a/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp index 5feff2a05..77936399c 100644 --- a/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ b/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -1299,7 +1299,7 @@ class Writer : public lld::Writer { llvm::Error writeFile(const lld::File &file, StringRef outPath) override { // Create stream to path. std::error_code ec; - llvm::raw_fd_ostream out(outPath, ec, llvm::sys::fs::F_Text); + llvm::raw_fd_ostream out(outPath, ec, llvm::sys::fs::OF_Text); if (ec) return llvm::errorCodeToError(ec); diff --git a/test/COFF/Inputs/alias-implib.lib b/test/COFF/Inputs/alias-implib.lib new file mode 100644 index 0000000000000000000000000000000000000000..7bc18d0162a0e6afc7e67be6392cc3b965827967 GIT binary patch literal 1608 zcmc&!-AV#c5FY<1q@t*splE}x&HoG}Rx-#k6Vq{)z>-p6M4 z%sH*57YjiH=gjZ!%r|q+IV_sPcJC~Htj$u=rwZA>Yg#Is<%owk0IcBp0tk-)B58o= z2Co4??A|acH}%^_(_;$+TB}<9?Syyq3SaZGRl7FIrDh4E?f$?R zc1)-H`qTy`n2v3}uvf_Vb;5ES1!)&1 | FileCheck %s + +# Check that the undefined (weak) alias symbol (with an existing lazy +# __imp_alias) doesn't trigger trying to load __imp_alias for autoimport, +# when the weak alias target actually does exist. + +# CHECK-NOT: Loading lazy{{.*}}for automatic import + + .text + .globl main +main: + call alias + ret + +# alias-implib.lib was created with "llvm-dlltool -m i386:x86-64 +# -l alias-implib.lib -d alias-implib.def" with this def snippet: +# LIBRARY lib.dll +# EXPORTS +# realfunc +# alias == realfunc diff --git a/test/COFF/align.s b/test/COFF/align.s new file mode 100644 index 000000000..67ca349e0 --- /dev/null +++ b/test/COFF/align.s @@ -0,0 +1,45 @@ +# RUN: yaml2obj < %s > %t.obj +# RUN: lld-link /out:%t.exe /entry:main /align:32 %t.obj +# RUN: llvm-readobj --file-headers %t.exe | FileCheck %s + +# CHECK: SectionAlignment: 32 + +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4096 + SectionData: 0000000000000000 + Relocations: + - VirtualAddress: 0 + SymbolName: __ImageBase + Type: IMAGE_REL_AMD64_ADDR64 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 8 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: main + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __ImageBase + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/COFF/autoimport-gnu-implib.s b/test/COFF/autoimport-gnu-implib.s index e6e0ed207..d7d4ed626 100644 --- a/test/COFF/autoimport-gnu-implib.s +++ b/test/COFF/autoimport-gnu-implib.s @@ -7,9 +7,10 @@ # RUN: llvm-ar rcs %t-implib.a %t-dabcdh.o %t-dabcds00000.o %t-dabcdt.o # RUN: llvm-mc -triple=x86_64-windows-gnu %s -filetype=obj -o %t.obj -# RUN: lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-implib.a -verbose +# RUN: lld-link -lldmingw -debug:symtab -out:%t.exe -entry:main %t.obj %t-implib.a -verbose # RUN: llvm-readobj --coff-imports %t.exe | FileCheck -check-prefix=IMPORTS %s +# RUN: llvm-nm %t.exe | FileCheck -check-prefix=SYMBOLS %s # IMPORTS: Import { # IMPORTS-NEXT: Name: foo.dll @@ -18,6 +19,10 @@ # IMPORTS-NEXT: Symbol: data (0) # IMPORTS-NEXT: } +# Check that the automatically imported symbol "data" is not listed in +# the symbol table. +# SYMBOLS-NOT: {{ }}data + .global main .text main: diff --git a/test/COFF/autoimport-x86.s b/test/COFF/autoimport-x86.s index 400cec711..9e0ae1ead 100644 --- a/test/COFF/autoimport-x86.s +++ b/test/COFF/autoimport-x86.s @@ -5,11 +5,12 @@ # RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib # RUN: llvm-mc -triple=x86_64-windows-gnu %s -filetype=obj -o %t.obj -# RUN: lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-lib.lib -verbose +# RUN: lld-link -lldmingw -debug:symtab -out:%t.exe -entry:main %t.obj %t-lib.lib -verbose # RUN: llvm-readobj --coff-imports %t.exe | FileCheck -check-prefix=IMPORTS %s # RUN: llvm-objdump -d %t.exe | FileCheck -check-prefix=DISASM %s # RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=CONTENTS %s +# RUN: llvm-nm %t.exe | FileCheck -check-prefix=SYMBOLS %s # IMPORTS: Import { # IMPORTS-NEXT: Name: autoimport-x86.s.tmp-lib.dll @@ -20,7 +21,7 @@ # DISASM: Disassembly of section .text: # DISASM-EMPTY: -# DISASM: .text: +# DISASM: main: # Relative offset at 0x1002 pointing at the IAT at 0x2080. # DISASM: 140001000: 8b 05 7a 10 00 00 movl 4218(%rip), %eax # DISASM: 140001006: c3 retq @@ -41,6 +42,10 @@ # CONTENTS: 140003000 80200040 01000000 00200040 01000000 # CONTENTS: 140003010 24200040 01000000 +# Check that the automatically imported symbol "variable" is not listed in +# the symbol table. +# SYMBOLS-NOT: variable + .global main .text main: diff --git a/test/COFF/color-diagnostics.test b/test/COFF/color-diagnostics.test index 11cf8aff7..210965d52 100644 --- a/test/COFF/color-diagnostics.test +++ b/test/COFF/color-diagnostics.test @@ -6,8 +6,8 @@ # RUN: not lld-link -xyz --color-diagnostics=always /nosuchfile 2>&1 \ # RUN: | FileCheck -check-prefix=COLOR %s -# COLOR: {{lld-link: .\[0;1;35mwarning: .\[0mignoring unknown argument '-xyz'}} -# COLOR: {{lld-link: .\[0;1;31merror: .\[0mcould not open '/nosuchfile'}} +# COLOR: {{lld-link: .\[0;35mwarning: .\[0mignoring unknown argument '-xyz'}} +# COLOR: {{lld-link: .\[0;31merror: .\[0mcould not open '/nosuchfile'}} # RUN: not lld-link /nosuchfile 2>&1 | FileCheck -check-prefix=NOCOLOR %s # RUN: not lld-link -color-diagnostics=never /nosuchfile 2>&1 \ diff --git a/test/COFF/combined-resources.test b/test/COFF/combined-resources.test index 04cb45c39..e14c8199c 100644 --- a/test/COFF/combined-resources.test +++ b/test/COFF/combined-resources.test @@ -4,6 +4,10 @@ // > rc /fo combined-resources.res /nologo combined-resources.rc // > rc /fo combined-resources-2.res /nologo combined-resources-2.rc +// The object files were generated with GNU windres and MS cvtres.exe, +// > x86_64-w64-mingw32-windres combined-resources.res combined-resources.o +// > cvtres -machine:x64 -out:combined-resources-2.o combined-resources.res + # RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj # RUN: lld-link /out:%t.exe /entry:main %t.obj %p/Inputs/resource.res \ # RUN: %p/Inputs/combined-resources.res %p/Inputs/combined-resources-2.res @@ -11,6 +15,21 @@ # RUN: llvm-readobj --coff-resources --file-headers --section-data %t.exe | \ # RUN: FileCheck %s +# RUN: yaml2obj < %p/Inputs/combined-resources.yaml > %t-combined-resources.o +# RUN: yaml2obj < %p/Inputs/combined-resources-2.yaml > %t-combined-resources-2.o + +# RUN: lld-link /lldmingw /out:%t-resobj.exe /entry:main %t.obj %p/Inputs/resource.res \ +# RUN: %t-combined-resources.o %t-combined-resources-2.o + +// As input resources are traversed in a slightly different order, the +// RVAs of data blobs will end up slightly different, even if they are +// equivalent. Filter out such addresses from llvm-readobj's output, +// and compare the rest to make sure it is equivalent. + +# RUN: llvm-readobj --coff-resources %t.exe | sed -E 's/(RVA|Address|File): .*//' > %t-orig.txt +# RUN: llvm-readobj --coff-resources %t-resobj.exe | sed -E 's/(RVA|Address|File): .*//' > %t-resobj.txt +# RUN: cmp %t-orig.txt %t-resobj.txt + CHECK: ResourceTableRVA: 0x2000 CHECK-NEXT: ResourceTableSize: 0xC20 CHECK-DAG: Resources [ diff --git a/test/COFF/edata.s b/test/COFF/edata.s new file mode 100644 index 000000000..4e3b9daf4 --- /dev/null +++ b/test/COFF/edata.s @@ -0,0 +1,61 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-mingw32 -o %t.o %s +# RUN: lld-link -lldmingw -dll -out:%t.dll %t.o -entry:__ImageBase 2>&1 | FileCheck %s --allow-empty --check-prefix=NOWARNING +# RUN: llvm-readobj --coff-exports %t.dll | FileCheck %s +# RUN: lld-link -lldmingw -dll -out:%t.dll %t.o -entry:__ImageBase -export:otherfunc 2>&1 | FileCheck %s --check-prefix=WARNING +# RUN: llvm-readobj --coff-exports %t.dll | FileCheck %s + +# Check that the export table contains the manually crafted content +# instead of the linker generated exports. + +# CHECK: Export { +# CHECK-NEXT: Ordinal: 1 +# CHECK-NEXT: Name: myfunc +# CHECK-NEXT: RVA: +# CHECK-NEXT: } +# CHECK-EMPTY: + +# NOWARNING-NOT: warning + +# WARNING: warning: literal .edata sections override exports + + .text + .globl myfunc +myfunc: + ret + .globl otherfunc +otherfunc: + ret + +// The object contains a manually crafted .edata section, which exports +// myfunc, not otherfunc. + .section .edata, "drw" + .align 4 +exports: + .long 0 // ExportFlags + .long 0 // TimeDateStamp + .long 0 // MajorVersion + MinorVersion + .rva name // NameRVA + .long 1 // OrdinalBase + .long 1 // AddressTableEntries + .long 1 // NumberOfNamePointers + .rva functions // ExportAddressTableRVA + .rva names // NamePointerRVA + .rva nameordinals // OrdinalTableRVA + +names: + .rva funcname_myfunc + +nameordinals: + .short 0 + +functions: + .rva myfunc + .long 0 + +funcname_myfunc: + .asciz "myfunc" + +name: + .asciz "mydll.dll" diff --git a/test/COFF/force-multipleres.test b/test/COFF/force-multipleres.test index 09329684e..944f63f63 100644 --- a/test/COFF/force-multipleres.test +++ b/test/COFF/force-multipleres.test @@ -9,13 +9,21 @@ RUN: rm -rf %t.dir RUN: mkdir %t.dir RUN: cp %S/Inputs/id.res %t.dir/id1.res RUN: cp %S/Inputs/id.res %t.dir/id2.res +RUN: cp %S/Inputs/id.res.o %t.dir/id1.o +RUN: cp %S/Inputs/id.res.o %t.dir/id2.o RUN: not lld-link /machine:x64 /nodefaultlib /noentry /dll %t.dir/id1.res %t.dir/id2.res 2>&1 | \ RUN: FileCheck -check-prefix=ERR %s -ERR: error: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in {{.*}}id1.res and in {{.*}}id2.res +RUN: not lld-link /lldmingw /machine:x64 /nodefaultlib /noentry /dll %t.dir/id1.res %t.dir/id2.o 2>&1 | \ +RUN: FileCheck -check-prefix=ERR %s +RUN: not lld-link /lldmingw /machine:x64 /nodefaultlib /noentry /dll %t.dir/id1.o %t.dir/id2.o 2>&1 | \ +RUN: FileCheck -check-prefix=ERR %s +ERR: error: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in {{.*}}id1.{{res|o}} and in {{.*}}id2.{{res|o}} RUN: lld-link /force /machine:x64 /nodefaultlib /noentry /dll %t.dir/id1.res %t.dir/id2.res 2>&1 | \ RUN: FileCheck -check-prefix=WARN %s RUN: lld-link /force:multipleres /machine:x64 /nodefaultlib /noentry /dll %t.dir/id1.res %t.dir/id2.res 2>&1 | \ RUN: FileCheck -check-prefix=WARN %s -WARN: warning: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in {{.*}}id1.res and in {{.*}}id2.res +RUN: lld-link /lldmingw /force:multipleres /machine:x64 /nodefaultlib /noentry /dll %t.dir/id1.o %t.dir/id2.o 2>&1 | \ +RUN: FileCheck -check-prefix=WARN %s +WARN: warning: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in {{.*}}id1.{{res|o}} and in {{.*}}id2.{{res|o}} diff --git a/test/COFF/implib-name-mingw.test b/test/COFF/implib-name-mingw.test new file mode 100644 index 000000000..3fb8b363f --- /dev/null +++ b/test/COFF/implib-name-mingw.test @@ -0,0 +1,20 @@ +REQUIRES: x86 +RUN: mkdir -p %t-out +RUN: llvm-mc -triple x86_64-windows-gnu -filetype obj -o %t-out/object.obj %S/Inputs/object.s + +Check that linking without an explicit -implib doesn't produce any implib. + +First test that linking without -lldmingw does produce an implib, but when +adding -lldmingw, it no longer is produced. And when it is explicitly named, +it is created. + +RUN: rm -f %t-out/library.lib +RUN: lld-link -dll -machine:x64 -def:%S/Inputs/named.def -out:%t-out/library.dll %t-out/object.obj -entry:f -subsystem:console +RUN: test -f %t-out/library.lib + +RUN: rm -f %t-out/library.lib +RUN: lld-link -lldmingw -dll -machine:x64 -def:%S/Inputs/named.def -out:%t-out/library.dll %t-out/object.obj -entry:f -subsystem:console +RUN: not test -f %t-out/library.lib + +RUN: lld-link -lldmingw -dll -machine:x64 -def:%S/Inputs/named.def -out:%t-out/library.dll %t-out/object.obj -entry:f -subsystem:console -implib:%t-out/library.lib +RUN: test -f %t-out/library.lib diff --git a/test/COFF/libcall-archive.ll b/test/COFF/libcall-archive.ll new file mode 100644 index 000000000..631503d0d --- /dev/null +++ b/test/COFF/libcall-archive.ll @@ -0,0 +1,22 @@ +; REQUIRES: x86 +; RUN: rm -f %t.a +; RUN: llvm-as -o %t.obj %s +; RUN: llvm-as -o %t2.obj %S/Inputs/libcall-archive.ll +; RUN: llvm-mc -filetype=obj -triple=i686-unknown-windows -o %t3.obj %S/Inputs/libcall-archive.s +; RUN: llvm-ar rcs %t.a %t2.obj %t3.obj +; RUN: lld-link -out:%t.exe -subsystem:console -entry:start -safeseh:no -lldmap:- %t.obj %t.a | FileCheck %s + +; CHECK-NOT: ___sync_val_compare_and_swap_8 +; CHECK: _start +; CHECK: _memcpy + +target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32" +target triple = "i686-unknown-windows" + +define void @start(i8* %a, i8* %b) { +entry: + call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 1024, i1 false) + ret void +} + +declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) diff --git a/test/COFF/lto-obj-path.ll b/test/COFF/lto-obj-path.ll new file mode 100644 index 000000000..db61ba970 --- /dev/null +++ b/test/COFF/lto-obj-path.ll @@ -0,0 +1,25 @@ +; REQUIRES: x86 + +; Test to ensure that thinlto-index-only with lto-obj-path creates +; the native object file. +; RUN: opt -module-summary %s -o %t1.obj +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.obj +; RUN: rm -f %t4.obj +; RUN: lld-link -thinlto-index-only -lto-obj-path:%t4.obj -out:t3.exe \ +; RUN: -entry:main %t1.obj %t2.obj +; RUN: llvm-readobj -h %t4.obj | FileCheck %s +; RUN: llvm-nm %t4.obj 2>&1 | FileCheck %s -check-prefix=SYMBOLS +; RUN: llvm-nm %t4.obj 2>&1 | count 1 + +; CHECK: Format: COFF-x86-64 +; SYMBOLS: @feat.00 + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc19.0.24215" + +declare void @g(...) + +define void @main() { + call void (...) @g() + ret void +} diff --git a/test/COFF/mixed-resource-obj.yaml b/test/COFF/mixed-resource-obj.yaml new file mode 100644 index 000000000..8e122b504 --- /dev/null +++ b/test/COFF/mixed-resource-obj.yaml @@ -0,0 +1,63 @@ +# REQUIRES: x86 + +# RUN: yaml2obj < %s > %t.o + +# Test that we get both the resource and the code from a single object +# file that contains both, while merging resources from another object +# file. + +# RUN: lld-link -lldmingw -out:%t.exe %t.o %p/Inputs/id.res.o -entry:main +# RUN: llvm-readobj --coff-resources %t.exe | FileCheck %s --check-prefix=CHECK-RESOURCES +# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefix=CHECK-DISASM + +# CHECK-RESOURCES: Resources [ +# CHECK-RESOURCES-NEXT: Total Number of Resources: 2 + +# CHECK-DISASM: Disassembly of section .text: +# CHECK-DISASM: .text: +# CHECK-DISASM-NEXT: movl $42, %eax +# CHECK-DISASM-NEXT: retq + +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ IMAGE_FILE_LINE_NUMS_STRIPPED ] +sections: + - Name: .rsrc + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 0000000000000000000000000000010005000000180000800000000000000000000000000100000048000080300000800000000000000000000000000000010009040000600000000A0054004500530054004400490041004C004F0047000000700000006C00000000000000000000000000C0800000000002000A000A00C8002C01000000005400650073007400000001000250000000000A000A00E6000E000100FFFF820043006F006E00740069006E00750065003A0000000000000001500000000042008600A1000D000200FFFF800026004F004B000000000000000000 + Relocations: + - VirtualAddress: 96 + SymbolName: .rsrc + Type: IMAGE_REL_AMD64_ADDR32NB + - Name: '.text' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: B82A000000C3 +symbols: + - Name: .rsrc + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '.text' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 6 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: main + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/test/COFF/multiple-resource-objs.test b/test/COFF/multiple-resource-objs.test index 4263c64be..be5f9a280 100644 --- a/test/COFF/multiple-resource-objs.test +++ b/test/COFF/multiple-resource-objs.test @@ -1,7 +1,9 @@ # RUN: llvm-cvtres /out:%t_resource.obj %S/Inputs/resource.res # RUN: llvm-cvtres /out:%t_id.obj %S/Inputs/id.res +# RUN: rm -f %t.exe # RUN: not lld-link /out:%t.exe /dll /noentry %t_id.obj %t_resource.obj 2>&1 | \ # RUN: FileCheck --check-prefix=TWOOBJ %s +# RUN: not test -f %t.exe TWOOBJ: error: {{.*}}_resource.obj: more than one resource obj file not allowed, already got {{.*}}_id.obj diff --git a/test/COFF/s_udt.s b/test/COFF/s_udt.s index 900948aa8..63e409970 100644 --- a/test/COFF/s_udt.s +++ b/test/COFF/s_udt.s @@ -173,7 +173,7 @@ main: # @main .short 1 # Flags .asciz "argc" .Ltmp13: - .cv_def_range .Ltmp0 .Ltmp1, "B\021\f\000\000\000" + .cv_def_range .Ltmp0 .Ltmp1, frame_ptr_rel, 12 .short .Ltmp15-.Ltmp14 # Record length .Ltmp14: .short 4414 # Record kind: S_LOCAL @@ -181,7 +181,7 @@ main: # @main .short 1 # Flags .asciz "argv" .Ltmp15: - .cv_def_range .Ltmp0 .Ltmp1, "B\021\020\000\000\000" + .cv_def_range .Ltmp0 .Ltmp1, frame_ptr_rel, 16 .short .Ltmp17-.Ltmp16 # Record length .Ltmp16: .short 4414 # Record kind: S_LOCAL @@ -189,7 +189,7 @@ main: # @main .short 0 # Flags .asciz "SPtr" .Ltmp17: - .cv_def_range .Ltmp0 .Ltmp1, "B\021\000\000\000\000" + .cv_def_range .Ltmp0 .Ltmp1, frame_ptr_rel, 0 .short .Ltmp19-.Ltmp18 # Record length .Ltmp18: .short 4360 # Record kind: S_UDT diff --git a/test/COFF/thin-archive.s b/test/COFF/thin-archive.s index 6eb896c57..a1491cb7c 100644 --- a/test/COFF/thin-archive.s +++ b/test/COFF/thin-archive.s @@ -11,6 +11,8 @@ # RUN: FileCheck --allow-empty %s # RUN: lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe 2>&1 | \ # RUN: FileCheck --allow-empty %s +# RUN: lld-link /entry:main %t.main.obj /wholearchive:%t_thin.lib /out:%t.exe 2>&1 | \ +# RUN: FileCheck --allow-empty %s # RUN: rm %t.lib.obj # RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \ diff --git a/test/ELF/Inputs/bad-archive.a b/test/ELF/Inputs/bad-archive.a deleted file mode 100644 index c9c6fbfd9..000000000 --- a/test/ELF/Inputs/bad-archive.a +++ /dev/null @@ -1,2 +0,0 @@ -! -this is malformed archive used in bad-archive.s diff --git a/test/ELF/Inputs/vs-diagnostics-duplicate3.s b/test/ELF/Inputs/vs-diagnostics-duplicate3.s index 81829c82b..dcc458a6c 100644 --- a/test/ELF/Inputs/vs-diagnostics-duplicate3.s +++ b/test/ELF/Inputs/vs-diagnostics-duplicate3.s @@ -1,6 +1,8 @@ .file "duplicate3.s" -.global baz +.global baz, qux .text baz: nop +qux: + nop diff --git a/test/ELF/aarch64-abs16.s b/test/ELF/aarch64-abs16.s index 261413185..af01eb300 100644 --- a/test/ELF/aarch64-abs16.s +++ b/test/ELF/aarch64-abs16.s @@ -14,11 +14,11 @@ _start: // RUN: llvm-objdump -s -section=.data %t2 | FileCheck %s // CHECK: Contents of section .data: -// 210000: S = 0x100, A = 0xfeff +// 220158: S = 0x100, A = 0xfeff // S + A = 0xffff -// 210002: S = 0x100, A = -0x8100 +// 22015c: S = 0x100, A = -0x8100 // S + A = 0x8000 -// CHECK-NEXT: 210000 ffff0080 +// CHECK-NEXT: 220158 ffff0080 // RUN: not ld.lld %t.o %t255.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=OVERFLOW1 // OVERFLOW1: relocation R_AARCH64_ABS16 out of range: -32769 is not in [-32768, 65535] diff --git a/test/ELF/aarch64-abs32.s b/test/ELF/aarch64-abs32.s index 7b697d357..b17258a55 100644 --- a/test/ELF/aarch64-abs32.s +++ b/test/ELF/aarch64-abs32.s @@ -14,11 +14,11 @@ _start: // RUN: llvm-objdump -s -section=.data %t2 | FileCheck %s // CHECK: Contents of section .data: -// 210000: S = 0x100, A = 0xfffffeff +// 220158: S = 0x100, A = 0xfffffeff // S + A = 0xffffffff -// 210004: S = 0x100, A = -0x80000100 +// 22015c: S = 0x100, A = -0x80000100 // S + A = 0x80000000 -// CHECK-NEXT: 210000 ffffffff 00000080 +// CHECK-NEXT: 220158 ffffffff 00000080 // RUN: not ld.lld %t.o %t255.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=OVERFLOW1 // OVERFLOW1: relocation R_AARCH64_ABS32 out of range: -2147483649 is not in [-2147483648, 4294967295] diff --git a/test/ELF/aarch64-call26-thunk.s b/test/ELF/aarch64-call26-thunk.s index 6e93b099e..62b9db1cd 100644 --- a/test/ELF/aarch64-call26-thunk.s +++ b/test/ELF/aarch64-call26-thunk.s @@ -12,11 +12,11 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: _start: -// CHECK-NEXT: 210000: 02 00 00 94 bl #8 +// CHECK-NEXT: 210120: 02 00 00 94 bl #8 // CHECK: __AArch64AbsLongThunk_big: -// CHECK-NEXT: 210008: 50 00 00 58 ldr x16, #8 -// CHECK-NEXT: 21000c: 00 02 1f d6 br x16 +// CHECK-NEXT: 210128: 50 00 00 58 ldr x16, #8 +// CHECK-NEXT: 21012c: 00 02 1f d6 br x16 // CHECK: $d: -// CHECK-NEXT: 210010: 00 00 00 00 .word 0x00000000 -// CHECK-NEXT: 210014: 10 00 00 00 .word 0x00000010 +// CHECK-NEXT: 210130: 00 00 00 00 .word 0x00000000 +// CHECK-NEXT: 210134: 10 00 00 00 .word 0x00000010 diff --git a/test/ELF/aarch64-condb-reloc.s b/test/ELF/aarch64-condb-reloc.s index 1888505bb..50e0c8a35 100644 --- a/test/ELF/aarch64-condb-reloc.s +++ b/test/ELF/aarch64-condb-reloc.s @@ -13,21 +13,21 @@ # CHECK: Disassembly of section .text: # CHECK-EMPTY: # CHECK-NEXT: _foo: -# CHECK-NEXT: 210000: nop -# CHECK-NEXT: 210004: nop -# CHECK-NEXT: 210008: nop -# CHECK-NEXT: 21000c: nop +# CHECK-NEXT: 210120: nop +# CHECK-NEXT: 210124: nop +# CHECK-NEXT: 210128: nop +# CHECK-NEXT: 21012c: nop # CHECK: _bar: -# CHECK-NEXT: 210010: nop -# CHECK-NEXT: 210014: nop -# CHECK-NEXT: 210018: nop +# CHECK-NEXT: 210130: nop +# CHECK-NEXT: 210134: nop +# CHECK-NEXT: 210138: nop # CHECK: _dah: -# CHECK-NEXT: 21001c: nop -# CHECK-NEXT: 210020: nop +# CHECK-NEXT: 21013c: nop +# CHECK-NEXT: 210140: nop # CHECK: _start: -# CHECK-NEXT: 210024: b.eq #-36 <_foo> -# CHECK-NEXT: 210028: b.eq #-24 <_bar> -# CHECK-NEXT: 21002c: b.eq #-16 <_dah> +# CHECK-NEXT: 210144: b.eq #-36 <_foo> +# CHECK-NEXT: 210148: b.eq #-24 <_bar> +# CHECK-NEXT: 21014c: b.eq #-16 <_dah> #DSOREL: Section { #DSOREL: Index: @@ -37,8 +37,8 @@ #DSOREL-NEXT: SHF_ALLOC #DSOREL-NEXT: SHF_WRITE #DSOREL-NEXT: ] -#DSOREL-NEXT: Address: 0x30000 -#DSOREL-NEXT: Offset: 0x30000 +#DSOREL-NEXT: Address: 0x30470 +#DSOREL-NEXT: Offset: 0x470 #DSOREL-NEXT: Size: 48 #DSOREL-NEXT: Link: 0 #DSOREL-NEXT: Info: 0 @@ -47,60 +47,60 @@ #DSOREL-NEXT: } #DSOREL: Relocations [ #DSOREL-NEXT: Section ({{.*}}) .rela.plt { -#DSOREL-NEXT: 0x30018 R_AARCH64_JUMP_SLOT _foo -#DSOREL-NEXT: 0x30020 R_AARCH64_JUMP_SLOT _bar -#DSOREL-NEXT: 0x30028 R_AARCH64_JUMP_SLOT _dah +#DSOREL-NEXT: 0x30488 R_AARCH64_JUMP_SLOT _foo +#DSOREL-NEXT: 0x30490 R_AARCH64_JUMP_SLOT _bar +#DSOREL-NEXT: 0x30498 R_AARCH64_JUMP_SLOT _dah #DSOREL-NEXT: } #DSOREL-NEXT:] #DSO: Disassembly of section .text: #DSO-EMPTY: #DSO-NEXT: _foo: -#DSO-NEXT: 10000: nop -#DSO-NEXT: 10004: nop -#DSO-NEXT: 10008: nop -#DSO-NEXT: 1000c: nop +#DSO-NEXT: 10338: nop +#DSO-NEXT: 1033c: nop +#DSO-NEXT: 10340: nop +#DSO-NEXT: 10344: nop #DSO: _bar: -#DSO-NEXT: 10010: nop -#DSO-NEXT: 10014: nop -#DSO-NEXT: 10018: nop +#DSO-NEXT: 10348: nop +#DSO-NEXT: 1034c: nop +#DSO-NEXT: 10350: nop #DSO: _dah: -#DSO-NEXT: 1001c: nop -#DSO-NEXT: 10020: nop +#DSO-NEXT: 10354: nop +#DSO-NEXT: 10358: nop #DSO: _start: -#DSO-NEXT: 10024: b.eq #44 <_foo@plt> -#DSO-NEXT: 10028: b.eq #56 <_bar@plt> -#DSO-NEXT: 1002c: b.eq #68 <_dah@plt> +#DSO-NEXT: 1035c: b.eq #52 <_foo@plt> +#DSO-NEXT: 10360: b.eq #64 <_bar@plt> +#DSO-NEXT: 10364: b.eq #76 <_dah@plt> #DSO-EMPTY: #DSO-NEXT: Disassembly of section .plt: #DSO-EMPTY: #DSO-NEXT: .plt: -#DSO-NEXT: 10030: stp x16, x30, [sp, #-16]! -#DSO-NEXT: 10034: adrp x16, #131072 -#DSO-NEXT: 10038: ldr x17, [x16, #16] -#DSO-NEXT: 1003c: add x16, x16, #16 -#DSO-NEXT: 10040: br x17 -#DSO-NEXT: 10044: nop -#DSO-NEXT: 10048: nop -#DSO-NEXT: 1004c: nop +#DSO-NEXT: 10370: stp x16, x30, [sp, #-16]! +#DSO-NEXT: 10374: adrp x16, #131072 +#DSO-NEXT: 10378: ldr x17, [x16, #1152] +#DSO-NEXT: 1037c: add x16, x16, #1152 +#DSO-NEXT: 10380: br x17 +#DSO-NEXT: 10384: nop +#DSO-NEXT: 10388: nop +#DSO-NEXT: 1038c: nop #DSO-EMPTY: #DSO-NEXT: _foo@plt: -#DSO-NEXT: 10050: adrp x16, #131072 -#DSO-NEXT: 10054: ldr x17, [x16, #24] -#DSO-NEXT: 10058: add x16, x16, #24 -#DSO-NEXT: 1005c: br x17 +#DSO-NEXT: 10390: adrp x16, #131072 +#DSO-NEXT: 10394: ldr x17, [x16, #1160] +#DSO-NEXT: 10398: add x16, x16, #1160 +#DSO-NEXT: 1039c: br x17 #DSO-EMPTY: #DSO-NEXT: _bar@plt: -#DSO-NEXT: 10060: adrp x16, #131072 -#DSO-NEXT: 10064: ldr x17, [x16, #32] -#DSO-NEXT: 10068: add x16, x16, #32 -#DSO-NEXT: 1006c: br x17 +#DSO-NEXT: 103a0: adrp x16, #131072 +#DSO-NEXT: 103a4: ldr x17, [x16, #1168] +#DSO-NEXT: 103a8: add x16, x16, #1168 +#DSO-NEXT: 103ac: br x17 #DSO-EMPTY: #DSO-NEXT: _dah@plt: -#DSO-NEXT: 10070: adrp x16, #131072 -#DSO-NEXT: 10074: ldr x17, [x16, #40] -#DSO-NEXT: 10078: add x16, x16, #40 -#DSO-NEXT: 1007c: br x17 +#DSO-NEXT: 103b0: adrp x16, #131072 +#DSO-NEXT: 103b4: ldr x17, [x16, #1176] +#DSO-NEXT: 103b8: add x16, x16, #1176 +#DSO-NEXT: 103bc: br x17 .globl _start _start: diff --git a/test/ELF/aarch64-copy.s b/test/ELF/aarch64-copy.s index 1a8973cc0..4b47c94ba 100644 --- a/test/ELF/aarch64-copy.s +++ b/test/ELF/aarch64-copy.s @@ -22,7 +22,7 @@ _start: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x230000 +// CHECK-NEXT: Address: 0x2303F0 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: @@ -31,29 +31,29 @@ _start: // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x230000 R_AARCH64_COPY x 0x0 -// CHECK-NEXT: 0x230010 R_AARCH64_COPY y 0x0 -// CHECK-NEXT: 0x230014 R_AARCH64_COPY z 0x0 +// CHECK-NEXT: 0x2303F0 R_AARCH64_COPY x 0x0 +// CHECK-NEXT: 0x230400 R_AARCH64_COPY y 0x0 +// CHECK-NEXT: 0x230404 R_AARCH64_COPY z 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] // CHECK: Symbols [ // CHECK: Name: x -// CHECK-NEXT: Value: 0x230000 +// CHECK-NEXT: Value: 0x2303F0 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object // CHECK-NEXT: Other: // CHECK-NEXT: Section: .bss // CHECK: Name: y -// CHECK-NEXT: Value: 0x230010 +// CHECK-NEXT: Value: 0x230400 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object // CHECK-NEXT: Other: // CHECK-NEXT: Section: .bss // CHECK: Name: z -// CHECK-NEXT: Value: 0x230014 +// CHECK-NEXT: Value: 0x230404 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -64,16 +64,13 @@ _start: // CODE: Disassembly of section .text: // CODE-EMPTY: // CODE-NEXT: _start: -// S(x) = 0x230000, A = 0, P = 0x210000 -// S + A - P = 0x20000 = 131072 -// CODE-NEXT: 210000: adr x1, #131072 -// S(y) = 0x230010, A = 0, P = 0x210004 -// Page(S + A) - Page(P) = 0x230000 - 0x210000 = 0x20000 = 131072 -// CODE-NEXT: 210004: adrp x2, #131072 -// S(y) = 0x230010, A = 0 -// (S + A) & 0xFFF = 0x10 = 16 -// CODE-NEXT: 210008: add x2, x2, #16 +// S + A - P = 0x2303f0 + 0 - 0x21031c = 131284 +// CODE-NEXT: 21031c: adr x1, #131284 +// Page(S + A) - Page(P) = Page(0x230400) - Page(0x210320) = 131072 +// CODE-NEXT: 210320: adrp x2, #131072 +// (S + A) & 0xFFF = (0x230400 + 0) & 0xFFF = 1024 +// CODE-NEXT: 210324: add x2, x2, #1024 // RODATA: Contents of section .rodata: -// S(z) = 0x230014 -// RODATA-NEXT: 200318 14002300 +// S(z) = 0x230404 +// RODATA-NEXT: 200318 04042300 diff --git a/test/ELF/aarch64-cortex-a53-843419-large.s b/test/ELF/aarch64-cortex-a53-843419-large.s index 37e6af522..a39b21031 100644 --- a/test/ELF/aarch64-cortex-a53-843419-large.s +++ b/test/ELF/aarch64-cortex-a53-843419-large.s @@ -1,6 +1,6 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux %s -o %t.o -// RUN: ld.lld --fix-cortex-a53-843419 %t.o -o %t2 +// RUN: ld.lld --fix-cortex-a53-843419 -z separate-code %t.o -o %t2 // RUN: llvm-objdump -triple=aarch64-linux-gnu -d %t2 -start-address=2162688 -stop-address=2162700 | FileCheck --check-prefix=CHECK1 %s // RUN: llvm-objdump -triple=aarch64-linux-gnu -d %t2 -start-address=2166784 -stop-address=2166788 | FileCheck --check-prefix=CHECK2 %s // RUN: llvm-objdump -triple=aarch64-linux-gnu -d %t2 -start-address=2170872 -stop-address=2170888 | FileCheck --check-prefix=CHECK3 %s diff --git a/test/ELF/aarch64-cortex-a53-843419-recognize.s b/test/ELF/aarch64-cortex-a53-843419-recognize.s index 64d8c1f3a..0a0e1138e 100644 --- a/test/ELF/aarch64-cortex-a53-843419-recognize.s +++ b/test/ELF/aarch64-cortex-a53-843419-recognize.s @@ -1,8 +1,8 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux %s -o %t.o -// RUN: ld.lld -fix-cortex-a53-843419 -verbose %t.o -o %t2 2>&1 | FileCheck -check-prefix CHECK-PRINT %s +// RUN: ld.lld -fix-cortex-a53-843419 -z separate-code -verbose %t.o -o %t2 2>&1 | FileCheck -check-prefix CHECK-PRINT %s // RUN: llvm-objdump -triple=aarch64-linux-gnu -d %t2 | FileCheck %s -check-prefixes=CHECK,CHECK-FIX -// RUN: ld.lld %t.o -o %t3 +// RUN: ld.lld %t.o -z separate-code -o %t3 // RUN: llvm-objdump -triple=aarch64-linux-gnu -d %t3 | FileCheck %s -check-prefixes=CHECK,CHECK-NOFIX // Test cases for Cortex-A53 Erratum 843419 // See ARM-EPM-048406 Cortex_A53_MPCore_Software_Developers_Errata_Notice.pdf @@ -85,7 +85,7 @@ t3_ffc_ldrpost: // CHECK-NEXT: 217ff8: 40 02 00 b0 adrp x0, #299008 // CHECK-NEXT: 217ffc: 21 8c 00 bc str s1, [x1, #8]! // CHECK-FIX: 218000: 09 b0 00 14 b #180260 -// CHECK-NOFIX: 218000: 02 00 40 f9 ldr x2, [x0] +// CHECK-NOFIX: 218000: 02 0c 40 f9 ldr x2, [x0, #24] // CHECK-NEXT: 218004: c0 03 5f d6 ret .section .text.04, "ax", %progbits .balign 4096 @@ -103,7 +103,7 @@ t3_ff8_strpre: // CHECK-NEXT: 219ffc: 3c 02 00 f0 adrp x28, #290816 // CHECK-NEXT: 21a000: 42 00 00 f9 str x2, [x2] // CHECK-FIX: 21a004: 0a a8 00 14 b #172072 -// CHECK-NOFIX: 21a004: 9c 07 00 f9 str x28, [x28, #8] +// CHECK-NOFIX: 21a004: 9c 13 00 f9 str x28, [x28, #32] // CHECK-NEXT: 21a008: c0 03 5f d6 ret .section .text.05, "ax", %progbits .balign 4096 @@ -121,7 +121,7 @@ t3_ffc_str: // CHECK-NEXT: 21bffc: 3c 02 00 b0 adrp x28, #282624 // CHECK-NEXT: 21c000: 44 00 00 b9 str w4, [x2] // CHECK-FIX: 21c004: 0c a0 00 14 b #163888 -// CHECK-NOFIX: 21c004: 84 0b 00 f9 str x4, [x28, #16] +// CHECK-NOFIX: 21c004: 84 17 00 f9 str x4, [x28, #40] // CHECK-NEXT: 21c008: c0 03 5f d6 ret .section .text.06, "ax", %progbits .balign 4096 @@ -192,7 +192,7 @@ t3_ffc_sturh: // CHECK-NEXT: 223ff8: f2 01 00 b0 adrp x18, #249856 // CHECK-NEXT: 223ffc: e3 ff ff 58 ldr x3, #-4 // CHECK-FIX: 224000: 15 80 00 14 b #131156 -// CHECK-NOFIX: 224000: 52 02 40 f9 ldr x18, [x18] +// CHECK-NOFIX: 224000: 52 0e 40 f9 ldr x18, [x18, #24] // CHECK-NEXT: 224004: c0 03 5f d6 ret .section .text.10, "ax", %progbits .balign 4096 @@ -210,7 +210,7 @@ t3_ff8_literal: // CHECK-NEXT: 225ffc: cf 01 00 f0 adrp x15, #241664 // CHECK-NEXT: 226000: 43 68 61 f8 ldr x3, [x2, x1] // CHECK-FIX: 226004: 16 78 00 14 b #122968 -// CHECK-NOFIX: 226004: ea 05 40 f9 ldr x10, [x15, #8] +// CHECK-NOFIX: 226004: ea 11 40 f9 ldr x10, [x15, #32] // CHECK-NEXT: 226008: c0 03 5f d6 ret .section .text.11, "ax", %progbits .balign 4096 @@ -228,7 +228,7 @@ t3_ffc_register: // CHECK-NEXT: 227ff8: d0 01 00 b0 adrp x16, #233472 // CHECK-NEXT: 227ffc: 61 08 00 a9 stp x1, x2, [x3] // CHECK-FIX: 228000: 19 70 00 14 b #114788 -// CHECK-NOFIX: 228000: 0d 0a 40 f9 ldr x13, [x16, #16] +// CHECK-NOFIX: 228000: 0d 16 40 f9 ldr x13, [x16, #40] // CHECK-NEXT: 228004: c0 03 5f d6 ret .section .text.12, "ax", %progbits .balign 4096 @@ -246,7 +246,7 @@ t3_ff8_stp: // CHECK-NEXT: 229ffc: a7 01 00 f0 adrp x7, #225280 // CHECK-NEXT: 22a000: 61 08 00 a8 stnp x1, x2, [x3] // CHECK-FIX: 22a004: 1a 68 00 14 b #106600 -// CHECK-NOFIX: 22a004: e9 00 40 f9 ldr x9, [x7] +// CHECK-NOFIX: 22a004: e9 0c 40 f9 ldr x9, [x7, #24] // CHECK-NEXT: 22a008: c0 03 5f d6 ret .section .text.13, "ax", %progbits .balign 4096 @@ -264,7 +264,7 @@ t3_ffc_stnp: // CHECK-NEXT: 22bffc: b7 01 00 b0 adrp x23, #217088 // CHECK-NEXT: 22c000: 20 04 82 0d st1 { v0.b }[1], [x1], x2 // CHECK-FIX: 22c004: 1c 60 00 14 b #98416 -// CHECK-NOFIX: 22c004: f6 06 40 f9 ldr x22, [x23, #8] +// CHECK-NOFIX: 22c004: f6 12 40 f9 ldr x22, [x23, #32] // CHECK-NEXT: 22c008: c0 03 5f d6 ret .section .text.14, "ax", %progbits .balign 4096 @@ -282,7 +282,7 @@ t3_ffc_st1singlepost: // CHECK-NEXT: 22dff8: 97 01 00 f0 adrp x23, #208896 // CHECK-NEXT: 22dffc: 20 a0 00 4c st1 { v0.16b, v1.16b }, [x1] // CHECK-FIX: 22e000: 1f 58 00 14 b #90236 -// CHECK-NOFIX: 22e000: f8 0a 40 f9 ldr x24, [x23, #16] +// CHECK-NOFIX: 22e000: f8 16 40 f9 ldr x24, [x23, #40] // CHECK-NEXT: 22e004: c0 03 5f d6 ret .section .text.15, "ax", %progbits .balign 4096 @@ -531,13 +531,13 @@ _start: // CHECK-FIX-NEXT: 24401c: 03 08 40 f9 ldr x3, [x0, #16] // CHECK-FIX-NEXT: 244020: fa 47 ff 17 b #-188440 // CHECK-FIX: __CortexA53843419_218000: -// CHECK-FIX-NEXT: 244024: 02 00 40 f9 ldr x2, [x0] +// CHECK-FIX-NEXT: 244024: 02 0c 40 f9 ldr x2, [x0, #24] // CHECK-FIX-NEXT: 244028: f7 4f ff 17 b #-180260 // CHECK-FIX: __CortexA53843419_21A004: -// CHECK-FIX-NEXT: 24402c: 9c 07 00 f9 str x28, [x28, #8] +// CHECK-FIX-NEXT: 24402c: 9c 13 00 f9 str x28, [x28, #32] // CHECK-FIX-NEXT: 244030: f6 57 ff 17 b #-172072 // CHECK-FIX: __CortexA53843419_21C004: -// CHECK-FIX-NEXT: 244034: 84 0b 00 f9 str x4, [x28, #16] +// CHECK-FIX-NEXT: 244034: 84 17 00 f9 str x4, [x28, #40] // CHECK-FIX-NEXT: 244038: f4 5f ff 17 b #-163888 // CHECK-FIX: __CortexA53843419_21E000: // CHECK-FIX-NEXT: 24403c: bd 03 40 f9 ldr x29, [x29] @@ -549,22 +549,22 @@ _start: // CHECK-FIX-NEXT: 24404c: 41 0a 40 f9 ldr x1, [x18, #16] // CHECK-FIX-NEXT: 244050: ee 77 ff 17 b #-139336 // CHECK-FIX: __CortexA53843419_224000: -// CHECK-FIX-NEXT: 244054: 52 02 40 f9 ldr x18, [x18] +// CHECK-FIX-NEXT: 244054: 52 0e 40 f9 ldr x18, [x18, #24] // CHECK-FIX-NEXT: 244058: eb 7f ff 17 b #-131156 // CHECK-FIX: __CortexA53843419_226004: -// CHECK-FIX-NEXT: 24405c: ea 05 40 f9 ldr x10, [x15, #8] +// CHECK-FIX-NEXT: 24405c: ea 11 40 f9 ldr x10, [x15, #32] // CHECK-FIX-NEXT: 244060: ea 87 ff 17 b #-122968 // CHECK-FIX: __CortexA53843419_228000: -// CHECK-FIX-NEXT: 244064: 0d 0a 40 f9 ldr x13, [x16, #16] +// CHECK-FIX-NEXT: 244064: 0d 16 40 f9 ldr x13, [x16, #40] // CHECK-FIX-NEXT: 244068: e7 8f ff 17 b #-114788 // CHECK-FIX: __CortexA53843419_22A004: -// CHECK-FIX-NEXT: 24406c: e9 00 40 f9 ldr x9, [x7] +// CHECK-FIX-NEXT: 24406c: e9 0c 40 f9 ldr x9, [x7, #24] // CHECK-FIX-NEXT: 244070: e6 97 ff 17 b #-106600 // CHECK-FIX: __CortexA53843419_22C004: -// CHECK-FIX-NEXT: 244074: f6 06 40 f9 ldr x22, [x23, #8] +// CHECK-FIX-NEXT: 244074: f6 12 40 f9 ldr x22, [x23, #32] // CHECK-FIX-NEXT: 244078: e4 9f ff 17 b #-98416 // CHECK-FIX: __CortexA53843419_22E000: -// CHECK-FIX-NEXT: 24407c: f8 0a 40 f9 ldr x24, [x23, #16] +// CHECK-FIX-NEXT: 24407c: f8 16 40 f9 ldr x24, [x23, #40] // CHECK-FIX-NEXT: 244080: e1 a7 ff 17 b #-90236 // CHECK-FIX: __CortexA53843419_230004: // CHECK-FIX-NEXT: 244084: 02 00 40 f9 ldr x2, [x0] diff --git a/test/ELF/aarch64-cortex-a53-843419-tlsrelax.s b/test/ELF/aarch64-cortex-a53-843419-tlsrelax.s index bff72d372..b12c0c667 100644 --- a/test/ELF/aarch64-cortex-a53-843419-tlsrelax.s +++ b/test/ELF/aarch64-cortex-a53-843419-tlsrelax.s @@ -24,12 +24,12 @@ _start: ret // CHECK: _start: -// CHECK-NEXT: 210ff8: 41 d0 3b d5 mrs x1, TPIDR_EL0 -// CHECK-NEXT: 210ffc: 00 00 a0 d2 movz x0, #0, lsl #16 -// CHECK-NEXT: 211000: 01 02 80 f2 movk x1, #16 -// CHECK-NEXT: 211004: 00 00 a0 d2 movz x0, #0, lsl #16 -// CHECK-NEXT: 211008: 01 02 80 f2 movk x1, #16 -// CHECK-NEXT: 21100c: c0 03 5f d6 ret +// CHECK-NEXT: 211ff8: 41 d0 3b d5 mrs x1, TPIDR_EL0 +// CHECK-NEXT: 211ffc: 00 00 a0 d2 movz x0, #0, lsl #16 +// CHECK-NEXT: 212000: 01 02 80 f2 movk x1, #16 +// CHECK-NEXT: 212004: 00 00 a0 d2 movz x0, #0, lsl #16 +// CHECK-NEXT: 212008: 01 02 80 f2 movk x1, #16 +// CHECK-NEXT: 21200c: c0 03 5f d6 ret .type v,@object .section .tbss,"awT",@nobits diff --git a/test/ELF/aarch64-data-relocs.s b/test/ELF/aarch64-data-relocs.s index c2769758c..9927215a5 100644 --- a/test/ELF/aarch64-data-relocs.s +++ b/test/ELF/aarch64-data-relocs.s @@ -12,12 +12,11 @@ _start: // S = 0x100, A = 0x24 // S + A = 0x124 // CHECK: Contents of section .R_AARCH64_ABS64: -// CHECK-NEXT: 210000 24010000 00000000 +// CHECK-NEXT: 210120 24010000 00000000 .section .R_AARCH64_PREL64, "ax",@progbits .xword foo - . + 0x24 -// S = 0x100, A = 0x24, P = 0x20008 -// S + A - P = 0xfffffffffffe011c +// S + A - P = 0x100 + 0x24 - 0x210128 = 0xffffffffffdefffc // CHECK: Contents of section .R_AARCH64_PREL64: -// CHECK-NEXT: 210008 1c01dfff ffffffff +// CHECK-NEXT: 210128 fcffdeff ffffffff diff --git a/test/ELF/aarch64-feature-bti.s b/test/ELF/aarch64-feature-bti.s index 7ccf59274..f2889c6fc 100644 --- a/test/ELF/aarch64-feature-bti.s +++ b/test/ELF/aarch64-feature-bti.s @@ -16,33 +16,38 @@ # NOBTIDYN-NOT: 0x0000000070000001 (AARCH64_BTI_PLT) # NOBTIDYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT) -# NOBTI: 0000000000010000 func2: -# NOBTI-NEXT: 10000: bl #48 -# NOBTI-NEXT: 10004: ret +# NOBTI: 00000000000102b8 func2: +# NOBTI-NEXT: 102b8: bl #56 +# NOBTI-NEXT: 102bc: ret # NOBTI: Disassembly of section .plt: -# NOBTI: 0000000000010010 .plt: -# NOBTI-NEXT: 10010: stp x16, x30, [sp, #-16]! -# NOBTI-NEXT: 10014: adrp x16, #131072 -# NOBTI-NEXT: 10018: ldr x17, [x16, #16] -# NOBTI-NEXT: 1001c: add x16, x16, #16 -# NOBTI-NEXT: 10020: br x17 -# NOBTI-NEXT: 10024: nop -# NOBTI-NEXT: 10028: nop -# NOBTI-NEXT: 1002c: nop -# NOBTI: 0000000000010030 func3@plt: -# NOBTI-NEXT: 10030: adrp x16, #131072 -# NOBTI-NEXT: 10034: ldr x17, [x16, #24] -# NOBTI-NEXT: 10038: add x16, x16, #24 -# NOBTI-NEXT: 1003c: br x17 +# NOBTI: 00000000000102d0 .plt: +# NOBTI-NEXT: 102d0: stp x16, x30, [sp, #-16]! +# NOBTI-NEXT: 102d4: adrp x16, #131072 +# NOBTI-NEXT: 102d8: ldr x17, [x16, #960] +# NOBTI-NEXT: 102dc: add x16, x16, #960 +# NOBTI-NEXT: 102e0: br x17 +# NOBTI-NEXT: 102e4: nop +# NOBTI-NEXT: 102e8: nop +# NOBTI-NEXT: 102ec: nop +# NOBTI: 00000000000102f0 func3@plt: +# NOBTI-NEXT: 102f0: adrp x16, #131072 +# NOBTI-NEXT: 102f4: ldr x17, [x16, #968] +# NOBTI-NEXT: 102f8: add x16, x16, #968 +# NOBTI-NEXT: 102fc: br x17 + +## The .got.plt should be identical between the BTI and no BTI DSO PLT. +# SOGOTPLT: Hex dump of section '.got.plt' +# SOGOTPLT-NEXT: 0x000303b0 00000000 00000000 00000000 00000000 +# SOGOTPLT-NEXT: 0x000303c0 00000000 00000000 d0020100 00000000 ## Expect a bti c at the start of plt[0], the plt entries do not need bti c as ## their address doesn't escape the shared object, so they can't be indirectly ## called. Expect no other difference. -# RUN: ld.lld %t1.o %t3.o --shared -o %t.so +# RUN: ld.lld %t1.o %t3.o --shared --soname=t.so -o %t.so # RUN: llvm-readelf -n %t.so | FileCheck --check-prefix BTIPROP %s # RUN: llvm-objdump -d -mattr=+bti --no-show-raw-insn %t.so | FileCheck --check-prefix BTISO %s -# RUN: llvm-readelf -x .got.plt %t.so | FileCheck --check-prefix SOGOTPLT %s +# RUN: llvm-readelf -x .got.plt %t.so | FileCheck --check-prefix SOGOTPLT2 %s # RUN: llvm-readelf --dynamic-table %t.so | FileCheck --check-prefix BTIDYN %s # BTIPROP: Properties: aarch64 feature: BTI @@ -50,61 +55,60 @@ # BTIDYN: 0x0000000070000001 (AARCH64_BTI_PLT) # BTIDYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT) -# BTISO: 0000000000010000 func2: -# BTISO-NEXT: 10000: bl #48 -# BTISO-NEXT: 10004: ret +# BTISO: 0000000000010310 func2: +# BTISO-NEXT: 10310: bl #48 +# BTISO-NEXT: 10314: ret # BTISO: Disassembly of section .plt: -# BTISO: 0000000000010010 .plt: -# BTISO-NEXT: 10010: bti c -# BTISO-NEXT: 10014: stp x16, x30, [sp, #-16]! -# BTISO-NEXT: 10018: adrp x16, #131072 -# BTISO-NEXT: 1001c: ldr x17, [x16, #16] -# BTISO-NEXT: 10020: add x16, x16, #16 -# BTISO-NEXT: 10024: br x17 -# BTISO-NEXT: 10028: nop -# BTISO-NEXT: 1002c: nop -# BTISO: 0000000000010030 func3@plt: -# BTISO-NEXT: 10030: adrp x16, #131072 -# BTISO-NEXT: 10034: ldr x17, [x16, #24] -# BTISO-NEXT: 10038: add x16, x16, #24 -# BTISO-NEXT: 1003c: br x17 - -## The .got.plt should be identical between the BTI and no BTI DSO PLT. -# SOGOTPLT: Hex dump of section '.got.plt' -# SOGOTPLT-NEXT: 0x00030000 00000000 00000000 00000000 00000000 -# SOGOTPLT-NEXT: 0x00030010 00000000 00000000 10000100 00000000 +# BTISO: 0000000000010320 .plt: +# BTISO-NEXT: 10320: bti c +# BTISO-NEXT: 10324: stp x16, x30, [sp, #-16]! +# BTISO-NEXT: 10328: adrp x16, #131072 +# BTISO-NEXT: 1032c: ldr x17, [x16, #1072] +# BTISO-NEXT: 10330: add x16, x16, #1072 +# BTISO-NEXT: 10334: br x17 +# BTISO-NEXT: 10338: nop +# BTISO-NEXT: 1033c: nop +# BTISO: 0000000000010340 func3@plt: +# BTISO-NEXT: 10340: adrp x16, #131072 +# BTISO-NEXT: 10344: ldr x17, [x16, #1080] +# BTISO-NEXT: 10348: add x16, x16, #1080 +# BTISO-NEXT: 1034c: br x17 + +# SOGOTPLT2: Hex dump of section '.got.plt' +# SOGOTPLT2-NEXT: 0x00030420 00000000 00000000 00000000 00000000 +# SOGOTPLT2-NEXT: 0x00030430 00000000 00000000 20030100 00000000 ## Build an executable with all relocatable inputs having the BTI ## .note.gnu.property. We expect a bti c in front of all PLT entries as the ## address of a PLT entry can escape an executable. -# RUN: ld.lld %t2.o --shared -o %t2.so +# RUN: ld.lld %t2.o --shared --soname=t2.so -o %t2.so # RUN: ld.lld %t.o %t.so %t2.so -o %t.exe # RUN: llvm-readelf --dynamic-table -n %t.exe | FileCheck --check-prefix=BTIPROP %s # RUN: llvm-objdump -d -mattr=+bti --no-show-raw-insn %t.exe | FileCheck --check-prefix=EXECBTI %s # EXECBTI: Disassembly of section .text: -# EXECBTI: 0000000000210000 func1: -# EXECBTI-NEXT: 210000: bl #48 -# EXECBTI-NEXT: 210004: ret +# EXECBTI: 0000000000210310 func1: +# EXECBTI-NEXT: 210310: bl #48 +# EXECBTI-NEXT: 210314: ret # EXECBTI: Disassembly of section .plt: -# EXECBTI: 0000000000210010 .plt: -# EXECBTI-NEXT: 210010: bti c -# EXECBTI-NEXT: 210014: stp x16, x30, [sp, #-16]! -# EXECBTI-NEXT: 210018: adrp x16, #131072 -# EXECBTI-NEXT: 21001c: ldr x17, [x16, #16] -# EXECBTI-NEXT: 210020: add x16, x16, #16 -# EXECBTI-NEXT: 210024: br x17 -# EXECBTI-NEXT: 210028: nop -# EXECBTI-NEXT: 21002c: nop -# EXECBTI: 0000000000210030 func2@plt: -# EXECBTI-NEXT: 210030: bti c -# EXECBTI-NEXT: 210034: adrp x16, #131072 -# EXECBTI-NEXT: 210038: ldr x17, [x16, #24] -# EXECBTI-NEXT: 21003c: add x16, x16, #24 -# EXECBTI-NEXT: 210040: br x17 -# EXECBTI-NEXT: 210044: nop +# EXECBTI: 0000000000210320 .plt: +# EXECBTI-NEXT: 210320: bti c +# EXECBTI-NEXT: 210324: stp x16, x30, [sp, #-16]! +# EXECBTI-NEXT: 210328: adrp x16, #131072 +# EXECBTI-NEXT: 21032c: ldr x17, [x16, #1112] +# EXECBTI-NEXT: 210330: add x16, x16, #1112 +# EXECBTI-NEXT: 210334: br x17 +# EXECBTI-NEXT: 210338: nop +# EXECBTI-NEXT: 21033c: nop +# EXECBTI: 0000000000210340 func2@plt: +# EXECBTI-NEXT: 210340: bti c +# EXECBTI-NEXT: 210344: adrp x16, #131072 +# EXECBTI-NEXT: 210348: ldr x17, [x16, #1120] +# EXECBTI-NEXT: 21034c: add x16, x16, #1120 +# EXECBTI-NEXT: 210350: br x17 +# EXECBTI-NEXT: 210354: nop ## We expect the same for PIE, as the address of an ifunc can escape # RUN: ld.lld --pie %t.o %t.so %t2.so -o %tpie.exe @@ -113,26 +117,26 @@ # RUN: llvm-objdump -d -mattr=+bti --no-show-raw-insn %tpie.exe | FileCheck --check-prefix=PIE %s # PIE: Disassembly of section .text: -# PIE: 0000000000010000 func1: -# PIE-NEXT: 10000: bl #48 -# PIE-NEXT: 10004: ret +# PIE: 0000000000010310 func1: +# PIE-NEXT: 10310: bl #48 +# PIE-NEXT: 10314: ret # PIE: Disassembly of section .plt: -# PIE: 0000000000010010 .plt: -# PIE-NEXT: 10010: bti c -# PIE-NEXT: 10014: stp x16, x30, [sp, #-16]! -# PIE-NEXT: 10018: adrp x16, #131072 -# PIE-NEXT: 1001c: ldr x17, [x16, #16] -# PIE-NEXT: 10020: add x16, x16, #16 -# PIE-NEXT: 10024: br x17 -# PIE-NEXT: 10028: nop -# PIE-NEXT: 1002c: nop -# PIE: 0000000000010030 func2@plt: -# PIE-NEXT: 10030: bti c -# PIE-NEXT: 10034: adrp x16, #131072 -# PIE-NEXT: 10038: ldr x17, [x16, #24] -# PIE-NEXT: 1003c: add x16, x16, #24 -# PIE-NEXT: 10040: br x17 -# PIE-NEXT: 10044: nop +# PIE: 0000000000010320 .plt: +# PIE-NEXT: 10320: bti c +# PIE-NEXT: 10324: stp x16, x30, [sp, #-16]! +# PIE-NEXT: 10328: adrp x16, #131072 +# PIE-NEXT: 1032c: ldr x17, [x16, #1112] +# PIE-NEXT: 10330: add x16, x16, #1112 +# PIE-NEXT: 10334: br x17 +# PIE-NEXT: 10338: nop +# PIE-NEXT: 1033c: nop +# PIE: 0000000000010340 func2@plt: +# PIE-NEXT: 10340: bti c +# PIE-NEXT: 10344: adrp x16, #131072 +# PIE-NEXT: 10348: ldr x17, [x16, #1120] +# PIE-NEXT: 1034c: add x16, x16, #1120 +# PIE-NEXT: 10350: br x17 +# PIE-NEXT: 10354: nop ## Build and executable with not all relocatable inputs having the BTI ## .note.property, expect no bti c and no .note.gnu.property entry @@ -142,26 +146,26 @@ # RUN: llvm-objdump -d -mattr=+bti --no-show-raw-insn %tnobti.exe | FileCheck --check-prefix=NOEX %s # NOEX: Disassembly of section .text: -# NOEX: 0000000000210000 func1: -# NOEX-NEXT: 210000: bl #48 -# NOEX-NEXT: 210004: ret -# NOEX: 0000000000210008 func3: -# NOEX-NEXT: 210008: ret +# NOEX: 00000000002102e0 func1: +# NOEX-NEXT: 2102e0: bl #48 +# NOEX-NEXT: 2102e4: ret +# NOEX: 00000000002102e8 func3: +# NOEX-NEXT: 2102e8: ret # NOEX: Disassembly of section .plt: -# NOEX: 0000000000210010 .plt: -# NOEX-NEXT: 210010: stp x16, x30, [sp, #-16]! -# NOEX-NEXT: 210014: adrp x16, #131072 -# NOEX-NEXT: 210018: ldr x17, [x16, #16] -# NOEX-NEXT: 21001c: add x16, x16, #16 -# NOEX-NEXT: 210020: br x17 -# NOEX-NEXT: 210024: nop -# NOEX-NEXT: 210028: nop -# NOEX-NEXT: 21002c: nop -# NOEX: 0000000000210030 func2@plt: -# NOEX-NEXT: 210030: adrp x16, #131072 -# NOEX-NEXT: 210034: ldr x17, [x16, #24] -# NOEX-NEXT: 210038: add x16, x16, #24 -# NOEX-NEXT: 21003c: br x17 +# NOEX: 00000000002102f0 .plt: +# NOEX-NEXT: 2102f0: stp x16, x30, [sp, #-16]! +# NOEX-NEXT: 2102f4: adrp x16, #131072 +# NOEX-NEXT: 2102f8: ldr x17, [x16, #1024] +# NOEX-NEXT: 2102fc: add x16, x16, #1024 +# NOEX-NEXT: 210300: br x17 +# NOEX-NEXT: 210304: nop +# NOEX-NEXT: 210308: nop +# NOEX-NEXT: 21030c: nop +# NOEX: 0000000000210310 func2@plt: +# NOEX-NEXT: 210310: adrp x16, #131072 +# NOEX-NEXT: 210314: ldr x17, [x16, #1032] +# NOEX-NEXT: 210318: add x16, x16, #1032 +# NOEX-NEXT: 21031c: br x17 ## Force BTI entries with the --force-bti command line option. Expect a warning ## from the file without the .note.gnu.property. @@ -176,28 +180,28 @@ # RUN: llvm-objdump -d -mattr=+bti --no-show-raw-insn %tforcebti.exe | FileCheck --check-prefix=FORCE %s # FORCE: Disassembly of section .text: -# FORCE: 0000000000210000 func1: -# FORCE-NEXT: 210000: bl #48 -# FORCE-NEXT: 210004: ret -# FORCE: 0000000000210008 func3: -# FORCE-NEXT: 210008: ret +# FORCE: 0000000000210338 func1: +# FORCE-NEXT: 210338: bl #56 +# FORCE-NEXT: 21033c: ret +# FORCE: 0000000000210340 func3: +# FORCE-NEXT: 210340: ret # FORCE: Disassembly of section .plt: -# FORCE: 0000000000210010 .plt: -# FORCE-NEXT: 210010: bti c -# FORCE-NEXT: 210014: stp x16, x30, [sp, #-16]! -# FORCE-NEXT: 210018: adrp x16, #131072 -# FORCE-NEXT: 21001c: ldr x17, [x16, #16] -# FORCE-NEXT: 210020: add x16, x16, #16 -# FORCE-NEXT: 210024: br x17 -# FORCE-NEXT: 210028: nop -# FORCE-NEXT: 21002c: nop -# FORCE: 0000000000210030 func2@plt: -# FORCE-NEXT: 210030: bti c -# FORCE-NEXT: 210034: adrp x16, #131072 -# FORCE-NEXT: 210038: ldr x17, [x16, #24] -# FORCE-NEXT: 21003c: add x16, x16, #24 -# FORCE-NEXT: 210040: br x17 -# FORCE-NEXT: 210044: nop +# FORCE: 0000000000210350 .plt: +# FORCE-NEXT: 210350: bti c +# FORCE-NEXT: 210354: stp x16, x30, [sp, #-16]! +# FORCE-NEXT: 210358: adrp x16, #131072 +# FORCE-NEXT: 21035c: ldr x17, [x16, #1144] +# FORCE-NEXT: 210360: add x16, x16, #1144 +# FORCE-NEXT: 210364: br x17 +# FORCE-NEXT: 210368: nop +# FORCE-NEXT: 21036c: nop +# FORCE: 0000000000210370 func2@plt: +# FORCE-NEXT: 210370: bti c +# FORCE-NEXT: 210374: adrp x16, #131072 +# FORCE-NEXT: 210378: ldr x17, [x16, #1152] +# FORCE-NEXT: 21037c: add x16, x16, #1152 +# FORCE-NEXT: 210380: br x17 +# FORCE-NEXT: 210384: nop .section ".note.gnu.property", "a" .long 4 diff --git a/test/ELF/aarch64-feature-btipac.s b/test/ELF/aarch64-feature-btipac.s index 9dec79edc..c1fa4c1d3 100644 --- a/test/ELF/aarch64-feature-btipac.s +++ b/test/ELF/aarch64-feature-btipac.s @@ -9,34 +9,34 @@ ## PLT[0] has bti c at start ## PLT[n] has autia1716 before br x17 -# RUN: ld.lld %t1.o %t3btipac.o --shared -o %t.so +# RUN: ld.lld %t1.o %t3btipac.o --shared --soname=t.so -o %t.so # RUN: llvm-readelf -n %t.so | FileCheck --check-prefix BTIPACPROP %s # RUN: llvm-objdump -d -mattr=+v8.5a --no-show-raw-insn %t.so | FileCheck --check-prefix BTIPACSO %s # RUN: llvm-readelf --dynamic-table %t.so | FileCheck --check-prefix BTIPACDYN %s # BTIPACSO: Disassembly of section .text: -# BTIPACSO: 0000000000010000 func2: -# BTIPACSO-NEXT: 10000: bl #48 -# BTIPACSO-NEXT: 10004: ret -# BTIPACSO: 0000000000010008 func3: -# BTIPACSO-NEXT: 10008: ret +# BTIPACSO: 0000000000010310 func2: +# BTIPACSO-NEXT: 10310: bl #48 +# BTIPACSO-NEXT: 10314: ret +# BTIPACSO: 0000000000010318 func3: +# BTIPACSO-NEXT: 10318: ret # BTIPACSO: Disassembly of section .plt: -# BTIPACSO: 0000000000010010 .plt: -# BTIPACSO-NEXT: 10010: bti c -# BTIPACSO-NEXT: 10014: stp x16, x30, [sp, #-16]! -# BTIPACSO-NEXT: 10018: adrp x16, #131072 -# BTIPACSO-NEXT: 1001c: ldr x17, [x16, #16] -# BTIPACSO-NEXT: 10020: add x16, x16, #16 -# BTIPACSO-NEXT: 10024: br x17 -# BTIPACSO-NEXT: 10028: nop -# BTIPACSO-NEXT: 1002c: nop -# BTIPACSO: 0000000000010030 func3@plt: -# BTIPACSO-NEXT: 10030: adrp x16, #131072 -# BTIPACSO-NEXT: 10034: ldr x17, [x16, #24] -# BTIPACSO-NEXT: 10038: add x16, x16, #24 -# BTIPACSO-NEXT: 1003c: autia1716 -# BTIPACSO-NEXT: 10040: br x17 -# BTIPACSO-NEXT: 10044: nop +# BTIPACSO: 0000000000010320 .plt: +# BTIPACSO-NEXT: 10320: bti c +# BTIPACSO-NEXT: 10324: stp x16, x30, [sp, #-16]! +# BTIPACSO-NEXT: 10328: adrp x16, #131072 +# BTIPACSO-NEXT: 1032c: ldr x17, [x16, #1096] +# BTIPACSO-NEXT: 10330: add x16, x16, #1096 +# BTIPACSO-NEXT: 10334: br x17 +# BTIPACSO-NEXT: 10338: nop +# BTIPACSO-NEXT: 1033c: nop +# BTIPACSO: 0000000000010340 func3@plt: +# BTIPACSO-NEXT: 10340: adrp x16, #131072 +# BTIPACSO-NEXT: 10344: ldr x17, [x16, #1104] +# BTIPACSO-NEXT: 10348: add x16, x16, #1104 +# BTIPACSO-NEXT: 1034c: autia1716 +# BTIPACSO-NEXT: 10350: br x17 +# BTIPACSO-NEXT: 10354: nop # BTIPACPROP: Properties: aarch64 feature: BTI, PAC @@ -53,29 +53,29 @@ # RUN: llvm-readelf --dynamic-table %t.exe | FileCheck --check-prefix BTIPACDYN %s # BTIPACEX: Disassembly of section .text: -# BTIPACEX: 0000000000210000 func1: -# BTIPACEX-NEXT: 210000: bl #48 -# BTIPACEX-NEXT: 210004: ret -# BTIPACEX-NEXT: 210008: ret -# BTIPACEX: 000000000021000c func3: -# BTIPACEX-NEXT: 21000c: ret +# BTIPACEX: 0000000000210338 func1: +# BTIPACEX-NEXT: 210338: bl #56 +# BTIPACEX-NEXT: 21033c: ret +# BTIPACEX-NEXT: 210340: ret +# BTIPACEX: 0000000000210344 func3: +# BTIPACEX-NEXT: 210344: ret # BTIPACEX: Disassembly of section .plt: -# BTIPACEX: 0000000000210010 .plt: -# BTIPACEX-NEXT: 210010: bti c -# BTIPACEX-NEXT: 210014: stp x16, x30, [sp, #-16]! -# BTIPACEX-NEXT: 210018: adrp x16, #131072 -# BTIPACEX-NEXT: 21001c: ldr x17, [x16, #16] -# BTIPACEX-NEXT: 210020: add x16, x16, #16 -# BTIPACEX-NEXT: 210024: br x17 -# BTIPACEX-NEXT: 210028: nop -# BTIPACEX-NEXT: 21002c: nop -# BTIPACEX: 0000000000210030 func2@plt: -# BTIPACEX-NEXT: 210030: bti c -# BTIPACEX-NEXT: 210034: adrp x16, #131072 -# BTIPACEX-NEXT: 210038: ldr x17, [x16, #24] -# BTIPACEX-NEXT: 21003c: add x16, x16, #24 -# BTIPACEX-NEXT: 210040: autia1716 -# BTIPACEX-NEXT: 210044: br x17 +# BTIPACEX: 0000000000210350 .plt: +# BTIPACEX-NEXT: 210350: bti c +# BTIPACEX-NEXT: 210354: stp x16, x30, [sp, #-16]! +# BTIPACEX-NEXT: 210358: adrp x16, #131072 +# BTIPACEX-NEXT: 21035c: ldr x17, [x16, #1160] +# BTIPACEX-NEXT: 210360: add x16, x16, #1160 +# BTIPACEX-NEXT: 210364: br x17 +# BTIPACEX-NEXT: 210368: nop +# BTIPACEX-NEXT: 21036c: nop +# BTIPACEX: 0000000000210370 func2@plt: +# BTIPACEX-NEXT: 210370: bti c +# BTIPACEX-NEXT: 210374: adrp x16, #131072 +# BTIPACEX-NEXT: 210378: ldr x17, [x16, #1168] +# BTIPACEX-NEXT: 21037c: add x16, x16, #1168 +# BTIPACEX-NEXT: 210380: autia1716 +# BTIPACEX-NEXT: 210384: br x17 ## Check that combinations of BTI+PAC with 0 properties results in standard PLT @@ -84,27 +84,27 @@ # RUN: llvm-readelf --dynamic-table %t.exe | FileCheck --check-prefix=NODYN %s # EX: Disassembly of section .text: -# EX: 0000000000210000 func1: -# EX-NEXT: 210000: bl #48 -# EX-NEXT: 210004: ret -# EX-NEXT: 210008: ret -# EX: 000000000021000c func3: -# EX-NEXT: 21000c: ret +# EX: 00000000002102e0 func1: +# EX-NEXT: 2102e0: bl #48 +# EX-NEXT: 2102e4: ret +# EX-NEXT: 2102e8: ret +# EX: 00000000002102ec func3: +# EX-NEXT: 2102ec: ret # EX: Disassembly of section .plt: -# EX: 0000000000210010 .plt: -# EX-NEXT: 210010: stp x16, x30, [sp, #-16]! -# EX-NEXT: 210014: adrp x16, #131072 -# EX-NEXT: 210018: ldr x17, [x16, #16] -# EX-NEXT: 21001c: add x16, x16, #16 -# EX-NEXT: 210020: br x17 -# EX-NEXT: 210024: nop -# EX-NEXT: 210028: nop -# EX-NEXT: 21002c: nop -# EX: 0000000000210030 func2@plt: -# EX: 210030: adrp x16, #131072 -# EX-NEXT: 210034: ldr x17, [x16, #24] -# EX-NEXT: 210038: add x16, x16, #24 -# EX-NEXT: 21003c: br x17 +# EX: 00000000002102f0 .plt: +# EX-NEXT: 2102f0: stp x16, x30, [sp, #-16]! +# EX-NEXT: 2102f4: adrp x16, #131072 +# EX-NEXT: 2102f8: ldr x17, [x16, #1024] +# EX-NEXT: 2102fc: add x16, x16, #1024 +# EX-NEXT: 210300: br x17 +# EX-NEXT: 210304: nop +# EX-NEXT: 210308: nop +# EX-NEXT: 21030c: nop +# EX: 0000000000210310 func2@plt: +# EX: 210310: adrp x16, #131072 +# EX-NEXT: 210314: ldr x17, [x16, #1032] +# EX-NEXT: 210318: add x16, x16, #1032 +# EX-NEXT: 21031c: br x17 # NODYN-NOT: 0x0000000070000001 (AARCH64_BTI_PLT) # NODYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT) diff --git a/test/ELF/aarch64-feature-pac.s b/test/ELF/aarch64-feature-pac.s index 39d1f19ff..cb0bcee70 100644 --- a/test/ELF/aarch64-feature-pac.s +++ b/test/ELF/aarch64-feature-pac.s @@ -13,62 +13,65 @@ # RUN: llvm-readelf -x .got.plt %tno.so | FileCheck --check-prefix SOGOTPLT %s # RUN: llvm-readelf --dynamic-table %tno.so | FileCheck --check-prefix NOPACDYN %s -# NOPAC: 0000000000010000 func2: -# NOPAC-NEXT: 10000: bl #48 -# NOPAC-NEXT: 10004: ret +# NOPAC: 00000000000102b8 func2: +# NOPAC-NEXT: 102b8: bl #56 +# NOPAC-NEXT: 102bc: ret # NOPAC: Disassembly of section .plt: -# NOPAC: 0000000000010010 .plt: -# NOPAC-NEXT: 10010: stp x16, x30, [sp, #-16]! -# NOPAC-NEXT: 10014: adrp x16, #131072 -# NOPAC-NEXT: 10018: ldr x17, [x16, #16] -# NOPAC-NEXT: 1001c: add x16, x16, #16 -# NOPAC-NEXT: 10020: br x17 -# NOPAC-NEXT: 10024: nop -# NOPAC-NEXT: 10028: nop -# NOPAC-NEXT: 1002c: nop -# NOPAC: 0000000000010030 func3@plt: -# NOPAC-NEXT: 10030: adrp x16, #131072 -# NOPAC-NEXT: 10034: ldr x17, [x16, #24] -# NOPAC-NEXT: 10038: add x16, x16, #24 -# NOPAC-NEXT: 1003c: br x17 +# NOPAC: 00000000000102d0 .plt: +# NOPAC-NEXT: 102d0: stp x16, x30, [sp, #-16]! +# NOPAC-NEXT: 102d4: adrp x16, #131072 +# NOPAC-NEXT: 102d8: ldr x17, [x16, #960] +# NOPAC-NEXT: 102dc: add x16, x16, #960 +# NOPAC-NEXT: 102e0: br x17 +# NOPAC-NEXT: 102e4: nop +# NOPAC-NEXT: 102e8: nop +# NOPAC-NEXT: 102ec: nop +# NOPAC: 00000000000102f0 func3@plt: +# NOPAC-NEXT: 102f0: adrp x16, #131072 +# NOPAC-NEXT: 102f4: ldr x17, [x16, #968] +# NOPAC-NEXT: 102f8: add x16, x16, #968 +# NOPAC-NEXT: 102fc: br x17 # NOPACDYN-NOT: 0x0000000070000001 (AARCH64_BTI_PLT) # NOPACDYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT) -# RUN: ld.lld %t1.o %t3.o --shared -o %t.so +# RUN: ld.lld %t1.o %t3.o --shared --soname=t.so -o %t.so # RUN: llvm-readelf -n %t.so | FileCheck --check-prefix PACPROP %s # RUN: llvm-objdump -d -mattr=+v8.3a --no-show-raw-insn %t.so | FileCheck --check-prefix PACSO %s -# RUN: llvm-readelf -x .got.plt %t.so | FileCheck --check-prefix SOGOTPLT %s +# RUN: llvm-readelf -x .got.plt %t.so | FileCheck --check-prefix SOGOTPLT2 %s # RUN: llvm-readelf --dynamic-table %t.so | FileCheck --check-prefix PACDYN %s ## PAC has no effect on PLT[0], for PLT[N] autia1716 is used to authenticate ## the address in x17 (context in x16) before branching to it. The dynamic ## loader is responsible for calling pacia1716 on the entry. -# PACSO: 0000000000010000 func2: -# PACSO-NEXT: 10000: bl #48 -# PACSO-NEXT: 10004: ret +# PACSO: 0000000000010310 func2: +# PACSO-NEXT: 10310: bl #48 +# PACSO-NEXT: 10314: ret # PACSO: Disassembly of section .plt: -# PACSO: 0000000000010010 .plt: -# PACSO-NEXT: 10010: stp x16, x30, [sp, #-16]! -# PACSO-NEXT: 10014: adrp x16, #131072 -# PACSO-NEXT: 10018: ldr x17, [x16, #16] -# PACSO-NEXT: 1001c: add x16, x16, #16 -# PACSO-NEXT: 10020: br x17 -# PACSO-NEXT: 10024: nop -# PACSO-NEXT: 10028: nop -# PACSO-NEXT: 1002c: nop -# PACSO: 0000000000010030 func3@plt: -# PACSO-NEXT: 10030: adrp x16, #131072 -# PACSO-NEXT: 10034: ldr x17, [x16, #24] -# PACSO-NEXT: 10038: add x16, x16, #24 -# PACSO-NEXT: 1003c: autia1716 -# PACSO-NEXT: 10040: br x17 -# PACSO-NEXT: 10044: nop - -# The .got.plt should be identical between the PAC and no PAC DSO PLT. +# PACSO: 0000000000010320 .plt: +# PACSO-NEXT: 10320: stp x16, x30, [sp, #-16]! +# PACSO-NEXT: 10324: adrp x16, #131072 +# PACSO-NEXT: 10328: ldr x17, [x16, #1080] +# PACSO-NEXT: 1032c: add x16, x16, #1080 +# PACSO-NEXT: 10330: br x17 +# PACSO-NEXT: 10334: nop +# PACSO-NEXT: 10338: nop +# PACSO-NEXT: 1033c: nop +# PACSO: 0000000000010340 func3@plt: +# PACSO-NEXT: 10340: adrp x16, #131072 +# PACSO-NEXT: 10344: ldr x17, [x16, #1088] +# PACSO-NEXT: 10348: add x16, x16, #1088 +# PACSO-NEXT: 1034c: autia1716 +# PACSO-NEXT: 10350: br x17 +# PACSO-NEXT: 10354: nop + # SOGOTPLT: Hex dump of section '.got.plt': -# SOGOTPLT-NEXT: 0x00030000 00000000 00000000 00000000 00000000 -# SOGOTPLT-NEXT: 0x00030010 00000000 00000000 10000100 00000000 +# SOGOTPLT-NEXT: 0x000303b0 00000000 00000000 00000000 00000000 +# SOGOTPLT-NEXT: 0x000303c0 00000000 00000000 d0020100 00000000 + +# SOGOTPLT2: Hex dump of section '.got.plt': +# SOGOTPLT2-NEXT: 0x00030428 00000000 00000000 00000000 00000000 +# SOGOTPLT2-NEXT: 0x00030438 00000000 00000000 20030100 00000000 # PACPROP: Properties: aarch64 feature: PAC @@ -86,28 +89,28 @@ # RUN: llvm-objdump -d -mattr=+v8.3a --no-show-raw-insn %tpacplt.exe | FileCheck --check-prefix PACPLT %s # PACPLT: Disassembly of section .text: -# PACPLT: 0000000000210000 func1: -# PACPLT-NEXT: 210000: bl #48 -# PACPLT-NEXT: 210004: ret -# PACPLT: 0000000000210008 func3: -# PACPLT-NEXT: 210008: ret +# PACPLT: 0000000000210338 func1: +# PACPLT-NEXT: 210338: bl #56 +# PACPLT-NEXT: 21033c: ret +# PACPLT: 0000000000210340 func3: +# PACPLT-NEXT: 210340: ret # PACPLT: Disassembly of section .plt: -# PACPLT: 0000000000210010 .plt: -# PACPLT-NEXT: 210010: stp x16, x30, [sp, #-16]! -# PACPLT-NEXT: 210014: adrp x16, #131072 -# PACPLT-NEXT: 210018: ldr x17, [x16, #16] -# PACPLT-NEXT: 21001c: add x16, x16, #16 -# PACPLT-NEXT: 210020: br x17 -# PACPLT-NEXT: 210024: nop -# PACPLT-NEXT: 210028: nop -# PACPLT-NEXT: 21002c: nop -# PACPLT: 0000000000210030 func2@plt: -# PACPLT-NEXT: 210030: adrp x16, #131072 -# PACPLT-NEXT: 210034: ldr x17, [x16, #24] -# PACPLT-NEXT: 210038: add x16, x16, #24 -# PACPLT-NEXT: 21003c: autia1716 -# PACPLT-NEXT: 210040: br x17 -# PACPLT-NEXT: 210044: nop +# PACPLT: 0000000000210350 .plt: +# PACPLT-NEXT: 210350: stp x16, x30, [sp, #-16]! +# PACPLT-NEXT: 210354: adrp x16, #131072 +# PACPLT-NEXT: 210358: ldr x17, [x16, #1144] +# PACPLT-NEXT: 21035c: add x16, x16, #1144 +# PACPLT-NEXT: 210360: br x17 +# PACPLT-NEXT: 210364: nop +# PACPLT-NEXT: 210368: nop +# PACPLT-NEXT: 21036c: nop +# PACPLT: 0000000000210370 func2@plt: +# PACPLT-NEXT: 210370: adrp x16, #131072 +# PACPLT-NEXT: 210374: ldr x17, [x16, #1152] +# PACPLT-NEXT: 210378: add x16, x16, #1152 +# PACPLT-NEXT: 21037c: autia1716 +# PACPLT-NEXT: 210380: br x17 +# PACPLT-NEXT: 210384: nop .section ".note.gnu.property", "a" diff --git a/test/ELF/aarch64-fpic-got.s b/test/ELF/aarch64-fpic-got.s index b4b685acd..d6e80b127 100644 --- a/test/ELF/aarch64-fpic-got.s +++ b/test/ELF/aarch64-fpic-got.s @@ -2,7 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux %s -o %t.o # RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux %p/Inputs/shared.s -o %t-lib.o -# RUN: ld.lld -shared %t-lib.o -o %t-lib.so +# RUN: ld.lld -shared %t-lib.o -soname t-lib.so -o %t-lib.so # RUN: ld.lld %t-lib.so %t.o -o %t.exe # RUN: llvm-readobj -r %t.exe | FileCheck --check-prefix=RELOC %s @@ -11,14 +11,14 @@ ## Checks if got access to dynamic objects is done through a got relative ## dynamic relocation and not using plt relative (R_AARCH64_JUMP_SLOT). # RELOC: .rela.dyn { -# RELOC-NEXT: 0x2200C0 R_AARCH64_GLOB_DAT bar 0x0 +# RELOC-NEXT: 0x220320 R_AARCH64_GLOB_DAT bar 0x0 # RELOC-NEXT: } -## page(0x2200C0) - page(0x210000) = 65536 -## page(0x2200C0) & 0xff8 = 192 +## page(0x220320) - page(0x210000) = 65536 +## page(0x220320) & 0xff8 = 800 # DIS: _start: -# DIS-NEXT: 210000: adrp x0, #65536 -# DIS-NEXT: 210004: ldr x0, [x0, #192] +# DIS-NEXT: 210258: adrp x0, #65536 +# DIS-NEXT: 21025c: ldr x0, [x0, #800] .globl _start _start: diff --git a/test/ELF/aarch64-gnu-ifunc-address.s b/test/ELF/aarch64-gnu-ifunc-address.s index ad70ecbc8..a1e289cde 100644 --- a/test/ELF/aarch64-gnu-ifunc-address.s +++ b/test/ELF/aarch64-gnu-ifunc-address.s @@ -20,19 +20,18 @@ main: adrp x8, :got:myfunc ldr x8, [x8, :got_lo12:myfunc] ret -# CHECK: 0000000000010004 main: -# x8 = 0x20000 -# CHECK-NEXT: 10004: adrp x8, #65536 -# x8 = 0x200a0 = .got entry for myfunc with R_AARCH64_GLOB_DAT -# CHECK-NEXT: 10008: ldr x8, [x8, #160] -# CHECK-NEXT: 1000c: ret +# CHECK: 0000000000010284 main: +## myfunc's got entry = page(0x20330)-page(0x10284) + 0x330 = 65536 + 816 +# CHECK-NEXT: 10284: adrp x8, #65536 +# CHECK-NEXT: 10288: ldr x8, [x8, #816] +# CHECK-NEXT: 1028c: ret # CHECK: Disassembly of section .got: # CHECK-EMPTY: -# CHECK-NEXT: 00000000000200a0 .got: +# CHECK-NEXT: 0000000000020330 .got: # CHECK-RELOCS: Relocations [ # CHECK-RELOCS-NEXT: Section {{.*}} .rela.dyn { -# CHECK-RELOCS-NEXT: 0x200A0 R_AARCH64_GLOB_DAT myfunc 0x0 +# CHECK-RELOCS-NEXT: 0x20330 R_AARCH64_GLOB_DAT myfunc 0x0 # CHECK-RELOCS-NEXT: } # CHECK-RELOCS-NEXT: ] diff --git a/test/ELF/aarch64-gnu-ifunc-nonpreemptable.s b/test/ELF/aarch64-gnu-ifunc-nonpreemptable.s index 571d7c29f..4343b92e4 100644 --- a/test/ELF/aarch64-gnu-ifunc-nonpreemptable.s +++ b/test/ELF/aarch64-gnu-ifunc-nonpreemptable.s @@ -31,42 +31,42 @@ main: ## The address of myfunc is the address of the PLT entry for myfunc. # PDE: myfunc_resolver: -# PDE-NEXT: 210000: ret +# PDE-NEXT: 210170: ret # PDE: main: -# PDE-NEXT: 210004: adrp x8, #0 -# PDE-NEXT: 210008: add x8, x8, #16 -# PDE-NEXT: 21000c: ret +# PDE-NEXT: 210174: adrp x8, #0 +# PDE-NEXT: 210178: add x8, x8, #384 +# PDE-NEXT: 21017c: ret # PDE-EMPTY: # PDE-NEXT: Disassembly of section .plt: # PDE-EMPTY: # PDE-NEXT: myfunc: ## page(.got.plt) - page(0x210010) = 65536 -# PDE-NEXT: 210010: adrp x16, #65536 -# PDE-NEXT: 210014: ldr x17, [x16] -# PDE-NEXT: 210018: add x16, x16, #0 -# PDE-NEXT: 21001c: br x17 +# PDE-NEXT: 210180: adrp x16, #65536 +# PDE-NEXT: 210184: ldr x17, [x16, #400] +# PDE-NEXT: 210188: add x16, x16, #400 +# PDE-NEXT: 21018c: br x17 ## The adrp to myfunc should generate a PLT entry and a GOT entry with an ## irelative relocation. -# PDE-RELOC: .rela.plt { -# PDE-RELOC-NEXT: 0x220000 R_AARCH64_IRELATIVE - 0x210000 +# PDE-RELOC: .rela.dyn { +# PDE-RELOC-NEXT: 0x220190 R_AARCH64_IRELATIVE - 0x210170 # PDE-RELOC-NEXT: } # PIE: myfunc_resolver: -# PIE-NEXT: 10000: ret +# PIE-NEXT: 10260: ret # PIE: main: -# PIE-NEXT: 10004: adrp x8, #0 -# PIE-NEXT: 10008: add x8, x8, #16 -# PIE-NEXT: 1000c: ret +# PIE-NEXT: 10264: adrp x8, #0 +# PIE-NEXT: 10268: add x8, x8, #624 +# PIE-NEXT: 1026c: ret # PIE-EMPTY: # PIE-NEXT: Disassembly of section .plt: # PIE-EMPTY: # PIE-NEXT: myfunc: -# PIE-NEXT: 10010: adrp x16, #131072 -# PIE-NEXT: 10014: ldr x17, [x16] -# PIE-NEXT: 10018: add x16, x16, #0 -# PIE-NEXT: 1001c: br x17 +# PIE-NEXT: 10270: adrp x16, #131072 +# PIE-NEXT: 10274: ldr x17, [x16, #880] +# PIE-NEXT: 10278: add x16, x16, #880 +# PIE-NEXT: 1027c: br x17 -# PIE-RELOC: .rela.plt { -# PIE-RELOC-NEXT: 0x30000 R_AARCH64_IRELATIVE - 0x10000 +# PIE-RELOC: .rela.dyn { +# PIE-RELOC-NEXT: 0x30370 R_AARCH64_IRELATIVE - 0x10260 # PIE-RELOC-NEXT: } diff --git a/test/ELF/aarch64-gnu-ifunc-nonpreemptable2.s b/test/ELF/aarch64-gnu-ifunc-nonpreemptable2.s new file mode 100644 index 000000000..1143b4661 --- /dev/null +++ b/test/ELF/aarch64-gnu-ifunc-nonpreemptable2.s @@ -0,0 +1,36 @@ +# REQUIRES: aarch64 +# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readelf -S -s %t | FileCheck %s --check-prefix=SEC +# RUN: llvm-readelf -x .rodata -x .data %t | FileCheck --check-prefix=HEX %s +# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC + +## ifunc is a non-preemptable STT_GNU_IFUNC. Check we create a canonical PLT +## and redirect .rodata and .data references to it. + +# SEC: .text PROGBITS 0000000000210178 +# SEC: .got.plt PROGBITS 0000000000220198 +# SEC: 0000000000210180 0 FUNC GLOBAL DEFAULT 4 ifunc + +## .rodata[0] and .data[0] store the address of the canonical PLT. +# HEX: section '.rodata': +# HEX-NEXT: 0x00200170 80012100 00000000 +# HEX: section '.data': +# HEX-NEXT: 0x00220190 80012100 00000000 + +# RELOC: .rela.dyn { +# RELOC-NEXT: 0x220198 R_AARCH64_IRELATIVE - 0x210178 +# RELOC-NEXT: } + +.globl ifunc +.type ifunc,@gnu_indirect_function +ifunc: + ret + +.rodata +.p2align 3 +.xword ifunc + +.data +.p2align 3 +.xword ifunc diff --git a/test/ELF/aarch64-gnu-ifunc-plt.s b/test/ELF/aarch64-gnu-ifunc-plt.s index 711d1890c..85c9cba70 100644 --- a/test/ELF/aarch64-gnu-ifunc-plt.s +++ b/test/ELF/aarch64-gnu-ifunc-plt.s @@ -9,69 +9,72 @@ // Check that the IRELATIVE relocations are after the JUMP_SLOT in the plt // CHECK: Relocations [ -// CHECK-NEXT: Section (4) .rela.plt { -// CHECK: 0x230018 R_AARCH64_JUMP_SLOT bar2 0x0 -// CHECK-NEXT: 0x230020 R_AARCH64_JUMP_SLOT zed2 0x0 -// CHECK-NEXT: 0x230028 R_AARCH64_IRELATIVE - 0x210000 -// CHECK-NEXT: 0x230030 R_AARCH64_IRELATIVE - 0x210004 +// CHECK-NEXT: Section (4) .rela.dyn { +// CHECK-NEXT: 0x230468 R_AARCH64_IRELATIVE - 0x2102D8 +// CHECK-NEXT: 0x230470 R_AARCH64_IRELATIVE - 0x2102DC +// CHECK-NEXT: } +// CHECK-NEXT: Section (5) .rela.plt { +// CHECK-NEXT: 0x230458 R_AARCH64_JUMP_SLOT bar2 0x0 +// CHECK-NEXT: 0x230460 R_AARCH64_JUMP_SLOT zed2 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] // Check that .got.plt entries point back to PLT header // GOTPLT: Contents of section .got.plt: -// GOTPLT-NEXT: 230000 00000000 00000000 00000000 00000000 -// GOTPLT-NEXT: 230010 00000000 00000000 20002100 00000000 -// GOTPLT-NEXT: 230020 20002100 00000000 20002100 00000000 -// GOTPLT-NEXT: 230030 20002100 00000000 +// GOTPLT-NEXT: 230440 00000000 00000000 00000000 00000000 +// GOTPLT-NEXT: 230450 00000000 00000000 f0022100 00000000 +// GOTPLT-NEXT: 230460 f0022100 00000000 f0022100 00000000 +// GOTPLT-NEXT: 230470 f0022100 00000000 -// Check that the PLTRELSZ tag includes the IRELATIVE relocations +// Check that the PLTRELSZ tag does not include the IRELATIVE relocations // CHECK: DynamicSection [ -// CHECK: 0x0000000000000002 PLTRELSZ 96 (bytes) +// CHECK: 0x0000000000000008 RELASZ 48 (bytes) +// CHECK: 0x0000000000000002 PLTRELSZ 48 (bytes) // Check that a PLT header is written and the ifunc entries appear last // DISASM: Disassembly of section .text: // DISASM-EMPTY: // DISASM-NEXT: foo: -// DISASM-NEXT: 210000: ret +// DISASM-NEXT: 2102d8: ret // DISASM: bar: -// DISASM-NEXT: 210004: ret +// DISASM-NEXT: 2102dc: ret // DISASM: _start: -// DISASM-NEXT: 210008: bl #88 -// DISASM-NEXT: 21000c: bl #100 -// DISASM-NEXT: 210010: bl #48 -// DISASM-NEXT: 210014: bl #60 +// DISASM-NEXT: 2102e0: bl #80 +// DISASM-NEXT: 2102e4: bl #92 +// DISASM-NEXT: 2102e8: bl #40 +// DISASM-NEXT: 2102ec: bl #52 // DISASM-EMPTY: // DISASM-NEXT: Disassembly of section .plt: // DISASM-EMPTY: // DISASM-NEXT: .plt: -// DISASM-NEXT: 210020: stp x16, x30, [sp, #-16]! -// DISASM-NEXT: 210024: adrp x16, #131072 -// DISASM-NEXT: 210028: ldr x17, [x16, #16] -// DISASM-NEXT: 21002c: add x16, x16, #16 -// DISASM-NEXT: 210030: br x17 -// DISASM-NEXT: 210034: nop -// DISASM-NEXT: 210038: nop -// DISASM-NEXT: 21003c: nop +// DISASM-NEXT: 2102f0: stp x16, x30, [sp, #-16]! +// DISASM-NEXT: 2102f4: adrp x16, #131072 +// DISASM-NEXT: 2102f8: ldr x17, [x16, #1104] +// DISASM-NEXT: 2102fc: add x16, x16, #1104 +// DISASM-NEXT: 210300: br x17 +// DISASM-NEXT: 210304: nop +// DISASM-NEXT: 210308: nop +// DISASM-NEXT: 21030c: nop // DISASM-EMPTY: // DISASM-NEXT: bar2@plt: -// DISASM-NEXT: 210040: adrp x16, #131072 -// DISASM-NEXT: 210044: ldr x17, [x16, #24] -// DISASM-NEXT: 210048: add x16, x16, #24 -// DISASM-NEXT: 21004c: br x17 +// DISASM-NEXT: 210310: adrp x16, #131072 +// DISASM-NEXT: 210314: ldr x17, [x16, #1112] +// DISASM-NEXT: 210318: add x16, x16, #1112 +// DISASM-NEXT: 21031c: br x17 // DISASM-EMPTY: // DISASM-NEXT: zed2@plt: -// DISASM-NEXT: 210050: adrp x16, #131072 -// DISASM-NEXT: 210054: ldr x17, [x16, #32] -// DISASM-NEXT: 210058: add x16, x16, #32 -// DISASM-NEXT: 21005c: br x17 -// DISASM-NEXT: 210060: adrp x16, #131072 -// DISASM-NEXT: 210064: ldr x17, [x16, #40] -// DISASM-NEXT: 210068: add x16, x16, #40 -// DISASM-NEXT: 21006c: br x17 -// DISASM-NEXT: 210070: adrp x16, #131072 -// DISASM-NEXT: 210074: ldr x17, [x16, #48] -// DISASM-NEXT: 210078: add x16, x16, #48 -// DISASM-NEXT: 21007c: br x17 +// DISASM-NEXT: 210320: adrp x16, #131072 +// DISASM-NEXT: 210324: ldr x17, [x16, #1120] +// DISASM-NEXT: 210328: add x16, x16, #1120 +// DISASM-NEXT: 21032c: br x17 +// DISASM-NEXT: 210330: adrp x16, #131072 +// DISASM-NEXT: 210334: ldr x17, [x16, #1128] +// DISASM-NEXT: 210338: add x16, x16, #1128 +// DISASM-NEXT: 21033c: br x17 +// DISASM-NEXT: 210340: adrp x16, #131072 +// DISASM-NEXT: 210344: ldr x17, [x16, #1136] +// DISASM-NEXT: 210348: add x16, x16, #1136 +// DISASM-NEXT: 21034c: br x17 .text .type foo STT_GNU_IFUNC diff --git a/test/ELF/aarch64-gnu-ifunc.s b/test/ELF/aarch64-gnu-ifunc.s index c89de9689..6494e001f 100644 --- a/test/ELF/aarch64-gnu-ifunc.s +++ b/test/ELF/aarch64-gnu-ifunc.s @@ -1,13 +1,13 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o // RUN: ld.lld -static %t.o -o %tout -// RUN: llvm-objdump -d %tout | FileCheck %s --check-prefix=DISASM +// RUN: llvm-objdump -d --no-show-raw-insn %tout | FileCheck %s --check-prefix=DISASM // RUN: llvm-readobj -r --symbols --sections %tout | FileCheck %s // CHECK: Sections [ // CHECK: Section { // CHECK: Index: 1 -// CHECK-NEXT: Name: .rela.plt +// CHECK-NEXT: Name: .rela.dyn // CHECK-NEXT: Type: SHT_RELA // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC @@ -21,9 +21,9 @@ // CHECK-NEXT: EntrySize: 24 // CHECK-NEXT: } // CHECK: Relocations [ -// CHECK-NEXT: Section ({{.*}}) .rela.plt { -// CHECK-NEXT: 0x220000 R_AARCH64_IRELATIVE -// CHECK-NEXT: 0x220008 R_AARCH64_IRELATIVE +// CHECK-NEXT: Section ({{.*}}) .rela.dyn { +// CHECK-NEXT: 0x2201C0 R_AARCH64_IRELATIVE +// CHECK-NEXT: 0x2201C8 R_AARCH64_IRELATIVE // CHECK-NEXT: } // CHECK-NEXT: ] // CHECK: Symbols [ @@ -38,7 +38,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: $x.0 -// CHECK-NEXT: Value: 0x210000 +// CHECK-NEXT: Value: 0x210188 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -54,7 +54,7 @@ // CHECK-NEXT: Other [ // CHECK-NEXT: STV_HIDDEN // CHECK-NEXT: ] -// CHECK-NEXT: Section: .rela.plt +// CHECK-NEXT: Section: .rela.dyn // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: __rela_iplt_start @@ -65,11 +65,11 @@ // CHECK-NEXT: Other [ // CHECK-NEXT: STV_HIDDEN // CHECK-NEXT: ] -// CHECK-NEXT: Section: .rela.plt +// CHECK-NEXT: Section: .rela.dyn // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x210008 +// CHECK-NEXT: Value: 0x210190 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None @@ -78,7 +78,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: bar -// CHECK-NEXT: Value: 0x210004 +// CHECK-NEXT: Value: 0x21018C // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: GNU_IFunc @@ -87,7 +87,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: foo -// CHECK-NEXT: Value: 0x210000 +// CHECK-NEXT: Value: 0x210188 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: GNU_IFunc @@ -102,26 +102,26 @@ // DISASM: Disassembly of section .text: // DISASM-EMPTY: // DISASM-NEXT: foo: -// DISASM-NEXT: 210000: c0 03 5f d6 ret +// DISASM-NEXT: 210188: ret // DISASM: bar: -// DISASM-NEXT: 210004: c0 03 5f d6 ret +// DISASM-NEXT: 21018c: ret // DISASM: _start: -// DISASM-NEXT: 210008: 06 00 00 94 bl #24 -// DISASM-NEXT: 21000c: 09 00 00 94 bl #36 -// DISASM-NEXT: 210010: 42 60 05 91 add x2, x2, #344 -// DISASM-NEXT: 210014: 42 20 06 91 add x2, x2, #392 +// DISASM-NEXT: 210190: bl #16 +// DISASM-NEXT: 210194: bl #28 +// DISASM-NEXT: 210198: add x2, x2, #344 +// DISASM-NEXT: 21019c: add x2, x2, #392 // DISASM-EMPTY: // DISASM-NEXT: Disassembly of section .plt: // DISASM-EMPTY: // DISASM-NEXT: .plt: -// DISASM-NEXT: 210020: 90 00 00 90 adrp x16, #65536 -// DISASM-NEXT: 210024: 11 02 40 f9 ldr x17, [x16] -// DISASM-NEXT: 210028: 10 02 00 91 add x16, x16, #0 -// DISASM-NEXT: 21002c: 20 02 1f d6 br x17 -// DISASM-NEXT: 210030: 90 00 00 90 adrp x16, #65536 -// DISASM-NEXT: 210034: 11 06 40 f9 ldr x17, [x16, #8] -// DISASM-NEXT: 210038: 10 22 00 91 add x16, x16, #8 -// DISASM-NEXT: 21003c: 20 02 1f d6 br x17 +// DISASM-NEXT: 2101a0: adrp x16, #65536 +// DISASM-NEXT: 2101a4: ldr x17, [x16, #448] +// DISASM-NEXT: 2101a8: add x16, x16, #448 +// DISASM-NEXT: 2101ac: br x17 +// DISASM-NEXT: 2101b0: adrp x16, #65536 +// DISASM-NEXT: 2101b4: ldr x17, [x16, #456] +// DISASM-NEXT: 2101b8: add x16, x16, #456 +// DISASM-NEXT: 2101bc: br x17 .text .type foo STT_GNU_IFUNC diff --git a/test/ELF/aarch64-gnu-ifunc2.s b/test/ELF/aarch64-gnu-ifunc2.s index 3481bb146..cf2ff4938 100644 --- a/test/ELF/aarch64-gnu-ifunc2.s +++ b/test/ELF/aarch64-gnu-ifunc2.s @@ -1,35 +1,35 @@ # REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o # RUN: ld.lld %t.o -o %t -# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s +# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t | FileCheck %s # RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SEC # RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC # CHECK: Disassembly of section .text: # CHECK-EMPTY: # CHECK-NEXT: myfunc: -# CHECK-NEXT: 210000: +# CHECK-NEXT: 210170: # CHECK: main: -# adrp x8, 0x220000, 0x220000 == address in .got.plt -# CHECK-NEXT: 210004: adrp x8, #65536 -# CHECK-NEXT: 210008: ldr x8, [x8] -# CHECK-NEXT: 21000c: ret +# .got.plt - page(0x210174) = 0x220190 - 0x210000 = 0x10190 +# CHECK-NEXT: 210174: adrp x8, #0x10000 +# CHECK-NEXT: 210178: ldr x8, [x8, #0x190] +# CHECK-NEXT: 21017c: ret # CHECK: Disassembly of section .plt: # CHECK-EMPTY: # CHECK-NEXT: .plt: -# adrp x16, 0x220000, 0x220000 == address in .got.plt -# CHECK-NEXT: 210010: adrp x16, #65536 -# CHECK-NEXT: 210014: ldr x17, [x16] -# CHECK-NEXT: 210018: add x16, x16, #0 -# CHECK-NEXT: 21001c: br x17 +# .got.plt - page(0x210180) = 0x220190 - 0x210000 = 0x10190 +# CHECK-NEXT: 210180: adrp x16, #0x10000 +# CHECK-NEXT: 210184: ldr x17, [x16, #0x190] +# CHECK-NEXT: 210188: add x16, x16, #0x190 +# CHECK-NEXT: 21018c: br x17 -# SEC: .got.plt PROGBITS 0000000000220000 020000 000008 00 WA 0 0 8 +# SEC: .got.plt PROGBITS 0000000000220190 000190 000008 00 WA 0 0 8 # RELOC: Relocations [ -# RELOC-NEXT: Section {{.*}} .rela.plt { -# RELOC-NEXT: 0x220000 R_AARCH64_IRELATIVE - 0x210000 +# RELOC-NEXT: Section {{.*}} .rela.dyn { +# RELOC-NEXT: 0x220190 R_AARCH64_IRELATIVE - 0x210170 # RELOC-NEXT: } # RELOC-NEXT: ] diff --git a/test/ELF/aarch64-got-weak-undef.s b/test/ELF/aarch64-got-weak-undef.s index fcdce49fb..62172b173 100644 --- a/test/ELF/aarch64-got-weak-undef.s +++ b/test/ELF/aarch64-got-weak-undef.s @@ -6,7 +6,7 @@ // RELOC: no relocations -// CHECK: 0x00220000 00000000 00000000 +// CHECK: 0x002201a0 00000000 00000000 .globl _start _start: diff --git a/test/ELF/aarch64-ifunc-bti.s b/test/ELF/aarch64-ifunc-bti.s index a881e9638..6a50b317c 100644 --- a/test/ELF/aarch64-ifunc-bti.s +++ b/test/ELF/aarch64-ifunc-bti.s @@ -2,7 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o # RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %p/Inputs/aarch64-addrifunc.s -o %t1.o -# RUN: ld.lld --shared %t1.o -o %t1.so +# RUN: ld.lld --shared --soname=t1.so %t1.o -o %t1.so # RUN: ld.lld --pie %t1.so %t.o -o %t # RUN: llvm-objdump -d -mattr=+bti -triple=aarch64-linux-gnu %t | FileCheck %s @@ -11,30 +11,30 @@ # we must use bti c. # CHECK: Disassembly of section .plt: -# CHECK: 0000000000010020 .plt: -# CHECK-NEXT: 10020: 5f 24 03 d5 bti c -# CHECK-NEXT: 10024: f0 7b bf a9 stp x16, x30, [sp, #-16]! -# CHECK-NEXT: 10028: 10 01 00 90 adrp x16, #131072 -# CHECK-NEXT: 1002c: 11 0a 40 f9 ldr x17, [x16, #16] -# CHECK-NEXT: 10030: 10 42 00 91 add x16, x16, #16 -# CHECK-NEXT: 10034: 20 02 1f d6 br x17 -# CHECK-NEXT: 10038: 1f 20 03 d5 nop -# CHECK-NEXT: 1003c: 1f 20 03 d5 nop -# CHECK: 0000000000010040 func1@plt: -# CHECK-NEXT: 10040: 5f 24 03 d5 bti c -# CHECK-NEXT: 10044: 10 01 00 90 adrp x16, #131072 -# CHECK-NEXT: 10048: 11 0e 40 f9 ldr x17, [x16, #24] -# CHECK-NEXT: 1004c: 10 62 00 91 add x16, x16, #24 -# CHECK-NEXT: 10050: 20 02 1f d6 br x17 -# CHECK-NEXT: 10054: 1f 20 03 d5 nop +# CHECK: 0000000000010340 .plt: +# CHECK-NEXT: 10340: 5f 24 03 d5 bti c +# CHECK-NEXT: 10344: f0 7b bf a9 stp x16, x30, [sp, #-16]! +# CHECK-NEXT: 10348: 10 01 00 90 adrp x16, #131072 +# CHECK-NEXT: 1034c: 11 5e 42 f9 ldr x17, [x16, #1208] +# CHECK-NEXT: 10350: 10 e2 12 91 add x16, x16, #1208 +# CHECK-NEXT: 10354: 20 02 1f d6 br x17 +# CHECK-NEXT: 10358: 1f 20 03 d5 nop +# CHECK-NEXT: 1035c: 1f 20 03 d5 nop +# CHECK: 0000000000010360 func1@plt: +# CHECK-NEXT: 10360: 5f 24 03 d5 bti c +# CHECK-NEXT: 10364: 10 01 00 90 adrp x16, #131072 +# CHECK-NEXT: 10368: 11 62 42 f9 ldr x17, [x16, #1216] +# CHECK-NEXT: 1036c: 10 02 13 91 add x16, x16, #1216 +# CHECK-NEXT: 10370: 20 02 1f d6 br x17 +# CHECK-NEXT: 10374: 1f 20 03 d5 nop # CHECK-NEXT: ... -# CHECK: 0000000000010060 myfunc: -# CHECK-NEXT: 10060: 5f 24 03 d5 bti c -# CHECK-NEXT: 10064: 10 01 00 90 adrp x16, #131072 -# CHECK-NEXT: 10068: 11 12 40 f9 ldr x17, [x16, #32] -# CHECK-NEXT: 1006c: 10 82 00 91 add x16, x16, #32 -# CHECK-NEXT: 10070: 20 02 1f d6 br x17 -# CHECK-NEXT: 10074: 1f 20 03 d5 nop +# CHECK: 0000000000010380 myfunc: +# CHECK-NEXT: 10380: 5f 24 03 d5 bti c +# CHECK-NEXT: 10384: 10 01 00 90 adrp x16, #131072 +# CHECK-NEXT: 10388: 11 66 42 f9 ldr x17, [x16, #1224] +# CHECK-NEXT: 1038c: 10 22 13 91 add x16, x16, #1224 +# CHECK-NEXT: 10390: 20 02 1f d6 br x17 +# CHECK-NEXT: 10394: 1f 20 03 d5 nop .section ".note.gnu.property", "a" .long 4 diff --git a/test/ELF/aarch64-jump26-thunk.s b/test/ELF/aarch64-jump26-thunk.s index 99860106b..4acac426f 100644 --- a/test/ELF/aarch64-jump26-thunk.s +++ b/test/ELF/aarch64-jump26-thunk.s @@ -12,10 +12,10 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: _start: -// CHECK-NEXT: 210000: b #8 +// CHECK-NEXT: 210120: b #8 // CHECK: __AArch64AbsLongThunk_big: -// CHECK-NEXT: 210008: ldr x16, #8 -// CHECK-NEXT: 21000c: br x16 +// CHECK-NEXT: 210128: ldr x16, #8 +// CHECK-NEXT: 21012c: br x16 // CHECK: $d: -// CHECK-NEXT: 210010: 00 00 00 00 .word 0x00000000 -// CHECK-NEXT: 210014: 10 00 00 00 .word 0x00000010 +// CHECK-NEXT: 210130: 00 00 00 00 .word 0x00000000 +// CHECK-NEXT: 210134: 10 00 00 00 .word 0x00000010 diff --git a/test/ELF/aarch64-ldprel-lo19-invalid.s b/test/ELF/aarch64-ldprel-lo19-invalid.s index be97945a2..6aab836a8 100644 --- a/test/ELF/aarch64-ldprel-lo19-invalid.s +++ b/test/ELF/aarch64-ldprel-lo19-invalid.s @@ -3,7 +3,7 @@ # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-none %s -o %t.o # RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s -# CHECK: relocation R_AARCH64_LD_PREL_LO19 out of range: 2131072 is not in [-1048576, 1048575] +# CHECK: relocation R_AARCH64_LD_PREL_LO19 out of range: 2131192 is not in [-1048576, 1048575] ldr x8, patatino .data diff --git a/test/ELF/aarch64-lo12-alignment.s b/test/ELF/aarch64-lo12-alignment.s index a7ed99751..57dd4e4e0 100644 --- a/test/ELF/aarch64-lo12-alignment.s +++ b/test/ELF/aarch64-lo12-alignment.s @@ -39,7 +39,7 @@ foo4: foo8: .space 8 -// CHECK: improper alignment for relocation R_AARCH64_LDST16_ABS_LO12_NC: 0x220001 is not aligned to 2 bytes -// CHECK-NEXT: improper alignment for relocation R_AARCH64_LDST32_ABS_LO12_NC: 0x220002 is not aligned to 4 bytes -// CHECK-NEXT: improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x220004 is not aligned to 8 bytes -// CHECK-NEXT: improper alignment for relocation R_AARCH64_LDST128_ABS_LO12_NC: 0x220008 is not aligned to 16 bytes +// CHECK: improper alignment for relocation R_AARCH64_LDST16_ABS_LO12_NC: 0x220181 is not aligned to 2 bytes +// CHECK-NEXT: improper alignment for relocation R_AARCH64_LDST32_ABS_LO12_NC: 0x220182 is not aligned to 4 bytes +// CHECK-NEXT: improper alignment for relocation R_AARCH64_LDST64_ABS_LO12_NC: 0x220184 is not aligned to 8 bytes +// CHECK-NEXT: improper alignment for relocation R_AARCH64_LDST128_ABS_LO12_NC: 0x220188 is not aligned to 16 bytes diff --git a/test/ELF/aarch64-load-alignment.s b/test/ELF/aarch64-load-alignment.s index 44304a3a2..ce98ee634 100644 --- a/test/ELF/aarch64-load-alignment.s +++ b/test/ELF/aarch64-load-alignment.s @@ -3,7 +3,7 @@ # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-none %s -o %t.o # RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s -# CHECK: improper alignment for relocation R_AARCH64_LD_PREL_LO19: 0x20005 is not aligned to 4 bytes +# CHECK: improper alignment for relocation R_AARCH64_LD_PREL_LO19: 0x2007D is not aligned to 4 bytes ldr x8, patatino .data diff --git a/test/ELF/aarch64-movw-error.s b/test/ELF/aarch64-movw-error.s index 9974ed434..03575b1fc 100644 --- a/test/ELF/aarch64-movw-error.s +++ b/test/ELF/aarch64-movw-error.s @@ -34,3 +34,22 @@ movn x0, #:prel_g0:.-0x10001 movn x0, #:prel_g1:.-0x100010000 # CHECK: relocation R_AARCH64_MOVW_PREL_G2 out of range: -281479271677952 is not in [-281474976710656, 281474976710655] movn x0, #:prel_g2:.-0x1000100000000 + +movz x0, #:tprel_g0: v1 +# CHECK: relocation R_AARCH64_TLSLE_MOVW_TPREL_G0 out of range: 65552 is not in [-65536, 65535] +movz x0, #:tprel_g1: v2 +# CHECK: relocation R_AARCH64_TLSLE_MOVW_TPREL_G1 out of range: 4295032848 is not in [-4294967296, 4294967295] +movz x0, #:tprel_g2: v3 +# CHECK: relocation R_AARCH64_TLSLE_MOVW_TPREL_G2 out of range: 281479271743496 is not in [-281474976710656, 281474976710655] + +.section .tbss,"awT",@nobits +.balign 16 +.space 0x10000 +v1: +.quad 0 +.space 0x100000000 - 8 +v2: +.quad 0 +.space 0x1000000000000 - 16 +v3: +.quad 0 diff --git a/test/ELF/aarch64-movw-tprel.s b/test/ELF/aarch64-movw-tprel.s new file mode 100644 index 000000000..f2eedf8f1 --- /dev/null +++ b/test/ELF/aarch64-movw-tprel.s @@ -0,0 +1,63 @@ +# REQUIRES: aarch64 +# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-objdump --no-show-raw-insn -d %t | FileCheck %s +# RUN: llvm-readobj --symbols %t | FileCheck --check-prefix=CHECK-SYM %s + +## Test the the local exec relocations that map to: +## R_AARCH64_TLSLE_MOVW_TPREL_G2 +## R_AARCH64_TLSLE_MOVW_TPREL_G1 +## R_AARCH64_TLSLE_MOVW_TPREL_G1_NC +## R_AARCH64_TLSLE_MOVW_TPREL_G0 +## R_AARCH64_TLSLE_MOVW_TPREL_G0_NC +## They calculate the same value as the other TPREL relocations, namely the +## offset from the thread pointer TP. The G0, G1 and G2 refer to partitions +## of the result with G2 bits [47:32], G1 bits [31:16] and G0 bits [15:0] +## the NC variant does not check for overflow. +## In AArch64 the structure of the TLS at runtime is: +## | TCB | Alignment Padding | TLS Block | +## With TP pointing to the start of the TCB. All offsets will be positive. + +.text +## Access variable in first partition +movz x0, #:tprel_g0:v0 +## TCB + 0 == 16 +# CHECK: mov x0, #16 + +# CHECK-SYM: Name: v0 +# CHECK-SYM-NEXT: Value: 0x0 + +## Access variable in second partition +movz x0, #:tprel_g1:v1 +movk x0, #:tprel_g0_nc:v1 + +## TCB + 65536 across movz and movk +# CHECK-NEXT: mov x0, #65536 +# CHECK-NEXT: movk x0, #16 + +# CHECK-SYM: Name: v1 +# CHECK-SYM-NEXT: Value: 0x10000 + +## Access variable in third partition +movz x0, #:tprel_g2:v2 +movk x0, #:tprel_g1_nc:v2 +movk x0, #:tprel_g0_nc:v2 + +## TCB + 65536 + 4294967296 across movz and 2 movk instructions +# CHECK-NEXT: mov x0, #4294967296 +# CHECK-NEXT: movk x0, #1, lsl #16 +# CHECK-NEXT: movk x0, #16 + +# CHECK-SYM: Name: v2 +# CHECK-SYM-NEXT: Value: 0x100010000 + +.section .tbss,"awT",@nobits +.balign 16 +v0: +.quad 0 +.space 0x10000 - 8 +v1: +.quad 0 +.space 0x100000000 - 8 +v2: +.quad 0 diff --git a/test/ELF/aarch64-nopic-plt.s b/test/ELF/aarch64-nopic-plt.s index 89c8908fd..2ab220a28 100644 --- a/test/ELF/aarch64-nopic-plt.s +++ b/test/ELF/aarch64-nopic-plt.s @@ -19,7 +19,7 @@ _start: // CHECK-NEXT: Section: Undefined // CHECK: Name: foo -// CHECK-NEXT: Value: 0x210030 +// CHECK-NEXT: Value: 0x2102F0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Function diff --git a/test/ELF/aarch64-prel16.s b/test/ELF/aarch64-prel16.s index 49c93472d..91f193ed4 100644 --- a/test/ELF/aarch64-prel16.s +++ b/test/ELF/aarch64-prel16.s @@ -7,8 +7,8 @@ .globl _start _start: .data - .hword foo - . + 0x210eff - .hword foo - . + 0x1f8f02 + .hword foo - . + 0x212057 + .hword foo - . + 0x1fa05a // Note: If this test fails, it probably happens because of // the change of the address of the .data section. @@ -18,11 +18,11 @@ _start: // RUN: llvm-objdump -s -section=.data %t2 | FileCheck %s // CHECK: Contents of section .data: -// 201000: S = 0x100, A = 0x210eff, P = 0x201000 +// 202158: S = 0x100, A = 0x212157, P = 0x202158 // S + A - P = 0xffff -// 201002: S = 0x100, A = 0x1f8f02, P = 0x201002 +// 212a5a: S = 0x100, A = 0x1fa05a, P = 0x20215a // S + A - P = 0x8000 -// CHECK-NEXT: 201000 ffff0080 +// CHECK-NEXT: 202158 ffff0080 // RUN: not ld.lld -z max-page-size=4096 %t.o %t255.o -o %t2 2>&1 | FileCheck %s --check-prefix=OVERFLOW1 // OVERFLOW1: relocation R_AARCH64_PREL16 out of range: -32769 is not in [-32768, 65535] diff --git a/test/ELF/aarch64-prel32.s b/test/ELF/aarch64-prel32.s index 7246caf2b..fdcbcb67f 100644 --- a/test/ELF/aarch64-prel32.s +++ b/test/ELF/aarch64-prel32.s @@ -7,8 +7,8 @@ .globl _start _start: .data - .word foo - . + 0x100200eff - .word foo - . - 0x7fdff0fc + .word foo - . + 0x100202057 + .word foo - . - 0x7fdfdfa4 // Note: If this test fails, it probably happens because of // the change of the address of the .data section. @@ -18,11 +18,11 @@ _start: // RUN: llvm-objdump -s -section=.data %t2 | FileCheck %s // CHECK: Contents of section .data: -// 201000: S = 0x100, A = 0x100200eff, P = 0x201000 +// 202158: S = 0x100, A = 0x100202057, P = 0x202158 // S + A - P = 0xffffffff -// 201004: S = 0x100, A = -0x7fdff0fc, P = 0x201004 +// 20215c: S = 0x100, A = -0x7fdfdfa4, P = 0x20215c // S + A - P = 0x80000000 -// CHECK-NEXT: 201000 ffffffff 00000080 +// CHECK-NEXT: 202158 ffffffff 00000080 // RUN: not ld.lld -z max-page-size=4096 %t.o %t255.o -o %t2 2>&1 | FileCheck %s --check-prefix=OVERFLOW1 // OVERFLOW1: relocation R_AARCH64_PREL32 out of range: -2147483649 is not in [-2147483648, 4294967295] diff --git a/test/ELF/aarch64-relative.s b/test/ELF/aarch64-relative.s index b10dd80fa..180801cf1 100644 --- a/test/ELF/aarch64-relative.s +++ b/test/ELF/aarch64-relative.s @@ -3,6 +3,7 @@ // RUN: ld.lld %t.o -o %t.so -shared // RUN: llvm-readobj -r %t.so | FileCheck %s +.p2align 4 adr x8, .Lfoo // R_AARCH64_ADR_PREL_LO21 adrp x8, .Lfoo // R_AARCH64_ADR_PREL_PG_HI21 strb w9, [x8, :lo12:.Lfoo] // R_AARCH64_LDST8_ABS_LO12_NC diff --git a/test/ELF/aarch64-relocs.s b/test/ELF/aarch64-relocs.s index a890d2538..abafe0991 100644 --- a/test/ELF/aarch64-relocs.s +++ b/test/ELF/aarch64-relocs.s @@ -25,14 +25,12 @@ mystr: .asciz "blah" .size mystr, 4 -# S = 0x210012, A = 0x4, P = 0x210012 -# PAGE(S + A) = 0x210000 -# PAGE(P) = 0x210000 +# PAGE(S + A) - PAGE(P) = PAGE(210136) - PAGE(0x210132) = 0 # # CHECK: Disassembly of section .R_AARCH64_ADR_PREL_PG_H121: # CHECK-EMPTY: # CHECK-NEXT: $x.2: -# CHECK-NEXT: 210012: 01 00 00 90 adrp x1, #0 +# CHECK-NEXT: 210132: 01 00 00 90 adrp x1, #0 .section .R_AARCH64_ADD_ABS_LO12_NC,"ax",@progbits add x0, x0, :lo12:.L.str @@ -40,14 +38,13 @@ mystr: .asciz "blah" .size mystr, 4 -# S = 0x21001b, A = 0x4 -# R = (S + A) & 0xFFF = 0x1f -# R << 10 = 0x7c00 +# S = 0x21013b, A = 0x4 +# R = (S + A) & 0xFFF = 319 # # CHECK: Disassembly of section .R_AARCH64_ADD_ABS_LO12_NC: # CHECK-EMPTY: # CHECK-NEXT: $x.4: -# CHECK-NEXT: 21001b: 00 7c 00 91 add x0, x0, #31 +# CHECK-NEXT: 21013b: 00 fc 04 91 add x0, x0, #319 .section .R_AARCH64_LDST64_ABS_LO12_NC,"ax",@progbits ldr x28, [x27, :lo12:foo] @@ -55,13 +52,13 @@ foo: .asciz "foo" .size mystr, 3 -# S = 0x210024, A = 0x4 -# R = ((S + A) & 0xFFF) << 7 = 0x00001400 -# 0x00001400 | 0xf940177c = 0xf940177c +# S = 0x210144, A = 0x4 +# R = ((S + A) & 0xFFF) << 7 = 0x0000a400 +# 0x0000a400 | 0xf940177c = 0xf940a77c # CHECK: Disassembly of section .R_AARCH64_LDST64_ABS_LO12_NC: # CHECK-EMPTY: # CHECK-NEXT: $x.6: -# CHECK-NEXT: 210024: 7c 17 40 f9 ldr x28, [x27, #40] +# CHECK-NEXT: 210144: 7c a7 40 f9 ldr x28, [x27, #328] .section .SUB,"ax",@progbits nop @@ -71,35 +68,35 @@ sub: # CHECK: Disassembly of section .SUB: # CHECK-EMPTY: # CHECK-NEXT: $x.8: -# CHECK-NEXT: 21002c: 1f 20 03 d5 nop +# CHECK-NEXT: 21014c: 1f 20 03 d5 nop # CHECK: sub: -# CHECK-NEXT: 210030: 1f 20 03 d5 nop +# CHECK-NEXT: 210150: 1f 20 03 d5 nop .section .R_AARCH64_CALL26,"ax",@progbits call26: bl sub -# S = 0x21002c, A = 0x4, P = 0x210034 +# S = 0x21014c, A = 0x4, P = 0x210154 # R = S + A - P = -0x4 = 0xfffffffc # (R & 0x0ffffffc) >> 2 = 0x03ffffff # 0x94000000 | 0x03ffffff = 0x97ffffff # CHECK: Disassembly of section .R_AARCH64_CALL26: # CHECK-EMPTY: # CHECK-NEXT: call26: -# CHECK-NEXT: 210034: ff ff ff 97 bl #-4 +# CHECK-NEXT: 210154: ff ff ff 97 bl #-4 .section .R_AARCH64_JUMP26,"ax",@progbits jump26: b sub -# S = 0x21002c, A = 0x4, P = 0x210038 +# S = 0x21014c, A = 0x4, P = 0x210158 # R = S + A - P = -0x8 = 0xfffffff8 # (R & 0x0ffffffc) >> 2 = 0x03fffffe # 0x14000000 | 0x03fffffe = 0x17fffffe # CHECK: Disassembly of section .R_AARCH64_JUMP26: # CHECK-EMPTY: # CHECK-NEXT: jump26: -# CHECK-NEXT: 210038: fe ff ff 17 b #-8 +# CHECK-NEXT: 210158: fe ff ff 17 b #-8 .section .R_AARCH64_LDST32_ABS_LO12_NC,"ax",@progbits ldst32: @@ -108,13 +105,13 @@ foo32: .asciz "foo" .size mystr, 3 -# S = 0x21003c, A = 0x4 -# R = ((S + A) & 0xFFC) << 8 = 0x00004000 -# 0x00004000 | 0xbd4000a4 = 0xbd4040a4 +# S = 0x21015c, A = 0x4 +# R = ((S + A) & 0xFFC) << 8 = 0x00016000 +# 0x00016000 | 0xbd4000a4 = 0xbd4160a4 # CHECK: Disassembly of section .R_AARCH64_LDST32_ABS_LO12_NC: # CHECK-EMPTY: # CHECK-NEXT: ldst32: -# CHECK-NEXT: 21003c: a4 40 40 bd ldr s4, [x5, #64] +# CHECK-NEXT: 21015c: a4 60 41 bd ldr s4, [x5, #352] .section .R_AARCH64_LDST8_ABS_LO12_NC,"ax",@progbits ldst8: @@ -123,13 +120,13 @@ foo8: .asciz "foo" .size mystr, 3 -# S = 0x210044, A = 0x4 -# R = ((S + A) & 0xFFF) << 10 = 0x00012000 -# 0x00012000 | 0x398001ab = 0x398121ab +# S = 0x210164, A = 0x4 +# R = ((S + A) & 0xFFF) << 10 = 0x0005a000 +# 0x0005a000 | 0x398001ab = 0x3985a1ab # CHECK: Disassembly of section .R_AARCH64_LDST8_ABS_LO12_NC: # CHECK-EMPTY: # CHECK-NEXT: ldst8: -# CHECK-NEXT: 210044: ab 21 81 39 ldrsb x11, [x13, #72] +# CHECK-NEXT: 210164: ab a1 85 39 ldrsb x11, [x13, #360] .section .R_AARCH64_LDST128_ABS_LO12_NC,"ax",@progbits ldst128: @@ -138,15 +135,15 @@ foo128: .asciz "foo" .size mystr, 3 -# S = 0x21004c, A = 0x4 -# R = ((S + A) & 0xFF8) << 6 = 0x00001400 -# 0x00001400 | 0x3dc00274 = 0x3dc01674 +# S = 0x21016c, A = 0x4 +# R = ((S + A) & 0xFF8) << 6 = 0x00005c00 +# 0x00005c00 | 0x3dc00274 = 0x3dc05e74 # CHECK: Disassembly of section .R_AARCH64_LDST128_ABS_LO12_NC: # CHECK-EMPTY: # CHECK: ldst128: -# CHECK: 21004c: 74 16 c0 3d ldr q20, [x19, #80] +# CHECK: 21016c: 74 5e c0 3d ldr q20, [x19, #368] #foo128: -# 210050: 66 6f 6f 00 .word +# 210170: 66 6f 6f 00 .word .section .R_AARCH64_LDST16_ABS_LO12_NC,"ax",@progbits ldst16: @@ -157,15 +154,15 @@ foo16: .asciz "foo" .size mystr, 4 -# S = 0x210054, A = 0x4 -# R = ((S + A) & 0x0FFC) << 9 = 0xb000 -# 0xb000 | 0x7d400271 = 0x7d40b271 +# S = 0x210174, A = 0x4 +# R = ((S + A) & 0x0FFC) << 9 = 0x2f000 +# 0x2f000 | 0x7d400271 = 0x7d430271 # CHECK: Disassembly of section .R_AARCH64_LDST16_ABS_LO12_NC: # CHECK-EMPTY: # CHECK-NEXT: ldst16: -# CHECK-NEXT: 210054: 71 c2 40 7d ldr h17, [x19, #96] -# CHECK-NEXT: 210058: 61 c2 40 79 ldrh w1, [x19, #96] -# CHECK-NEXT: 21005c: 62 c6 40 79 ldrh w2, [x19, #98] +# CHECK-NEXT: 210174: 71 02 43 7d ldr h17, [x19, #384] +# CHECK-NEXT: 210178: 61 02 43 79 ldrh w1, [x19, #384] +# CHECK-NEXT: 21017c: 62 06 43 79 ldrh w2, [x19, #386] .section .R_AARCH64_MOVW_UABS,"ax",@progbits movz1: @@ -234,24 +231,24 @@ movz1: # CHECK: Disassembly of section .R_AARCH64_MOVW_PREL: # CHECK-EMPTY: # CHECK-NEXT: : -# CHECK-NEXT: 21009c: 21 00 80 d2 mov x1, #1 -# CHECK-NEXT: 2100a0: 01 00 80 92 mov x1, #-1 -# CHECK-NEXT: 2100a4: 21 00 80 f2 movk x1, #1 -# CHECK-NEXT: 2100a8: e1 ff 9f f2 movk x1, #65535 -# CHECK-NEXT: 2100ac: 42 00 a0 d2 mov x2, #131072 +# CHECK-NEXT: 2101bc: 21 00 80 d2 mov x1, #1 +# CHECK-NEXT: 2101c0: 01 00 80 92 mov x1, #-1 +# CHECK-NEXT: 2101c4: 21 00 80 f2 movk x1, #1 +# CHECK-NEXT: 2101c8: e1 ff 9f f2 movk x1, #65535 +# CHECK-NEXT: 2101cc: 42 00 a0 d2 mov x2, #131072 ## -65537 = 0xfffffffffffeffff -# CHECK-NEXT: 2100b0: 22 00 a0 92 mov x2, #-65537 -# CHECK-NEXT: 2100b4: 42 00 a0 f2 movk x2, #2, lsl #16 -# CHECK-NEXT: 2100b8: c2 ff bf f2 movk x2, #65534, lsl #16 +# CHECK-NEXT: 2101d0: 22 00 a0 92 mov x2, #-65537 +# CHECK-NEXT: 2101d4: 42 00 a0 f2 movk x2, #2, lsl #16 +# CHECK-NEXT: 2101d8: c2 ff bf f2 movk x2, #65534, lsl #16 ## 12884901888 = 0x300000000 -# CHECK-NEXT: 2100bc: 63 00 c0 d2 mov x3, #12884901888 +# CHECK-NEXT: 2101dc: 63 00 c0 d2 mov x3, #12884901888 ## -8589934593 = #0xfffffffdffffffff -# CHECK-NEXT: 2100c0: 43 00 c0 92 mov x3, #-8589934593 -# CHECK-NEXT: 2100c4: 63 00 c0 f2 movk x3, #3, lsl #32 -# CHECK-NEXT: 2100c8: a3 ff df f2 movk x3, #65533, lsl #32 -# CHECK-NEXT: 2100cc: 63 00 c0 d2 mov x3, #12884901888 +# CHECK-NEXT: 2101e0: 43 00 c0 92 mov x3, #-8589934593 +# CHECK-NEXT: 2101e4: 63 00 c0 f2 movk x3, #3, lsl #32 +# CHECK-NEXT: 2101e8: a3 ff df f2 movk x3, #65533, lsl #32 +# CHECK-NEXT: 2101ec: 63 00 c0 d2 mov x3, #12884901888 ## 1125899906842624 = 0x4000000000000 -# CHECK-NEXT: 2100d0: 84 00 e0 d2 mov x4, #1125899906842624 -# CHECK-NEXT: 2100d4: 84 ff ff d2 mov x4, #-1125899906842624 -# CHECK-NEXT: 2100d8: 84 00 e0 f2 movk x4, #4, lsl #48 -# CHECK-NEXT: 2100dc: 84 ff ff f2 movk x4, #65532, lsl #48 +# CHECK-NEXT: 2101f0: 84 00 e0 d2 mov x4, #1125899906842624 +# CHECK-NEXT: 2101f4: 84 ff ff d2 mov x4, #-1125899906842624 +# CHECK-NEXT: 2101f8: 84 00 e0 f2 movk x4, #4, lsl #48 +# CHECK-NEXT: 2101fc: 84 ff ff f2 movk x4, #65532, lsl #48 diff --git a/test/ELF/aarch64-relro.s b/test/ELF/aarch64-relro.s index 6d811c087..4047382c8 100644 --- a/test/ELF/aarch64-relro.s +++ b/test/ELF/aarch64-relro.s @@ -5,10 +5,10 @@ # CHECK: Type: PT_GNU_RELRO # CHECK-NEXT: Offset: -# CHECK-NEXT: VirtualAddress: +# CHECK-NEXT: VirtualAddress: 0x220190 # CHECK-NEXT: PhysicalAddress: # CHECK-NEXT: FileSize: -# CHECK-NEXT: MemSize: 4096 +# CHECK-NEXT: MemSize: 3696 .section .data.rel.ro,"aw",%progbits .byte 1 diff --git a/test/ELF/aarch64-thunk-section-location.s b/test/ELF/aarch64-thunk-section-location.s index 36ba33835..f1bc58498 100644 --- a/test/ELF/aarch64-thunk-section-location.s +++ b/test/ELF/aarch64-thunk-section-location.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t // RUN: ld.lld %t -o %t2 2>&1 -// RUN: llvm-objdump -d -start-address=136118280 -stop-address=136118292 -triple=aarch64-linux-gnu %t2 | FileCheck %s +// RUN: llvm-objdump -d --start-address=0x81d1008 -stop-address=0x81d1014 -triple=aarch64-linux-gnu %t2 | FileCheck %s // Check that the range extension thunks are dumped close to the aarch64 branch // range of 128 MiB .section .text.1, "ax", %progbits @@ -35,7 +35,7 @@ high_target: ret // CHECK: __AArch64AbsLongThunk_high_target: -// CHECK-NEXT: 81d0008: 50 00 00 58 ldr x16, #8 -// CHECK-NEXT: 81d000c: 00 02 1f d6 br x16 +// CHECK-NEXT: 81d1008: 50 00 00 58 ldr x16, #8 +// CHECK-NEXT: 81d100c: 00 02 1f d6 br x16 // CHECK: $d: -// CHECK-NEXT: 81d0010: 00 10 21 08 .word 0x08211000 +// CHECK-NEXT: 81d1010: 00 20 21 08 .word 0x08212000 diff --git a/test/ELF/aarch64-tls-gdie.s b/test/ELF/aarch64-tls-gdie.s index 199be49ee..5da8e739d 100644 --- a/test/ELF/aarch64-tls-gdie.s +++ b/test/ELF/aarch64-tls-gdie.s @@ -21,14 +21,14 @@ _start: // SEC-NEXT: SHF_ALLOC // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x2200B0 +// SEC-NEXT: Address: 0x220300 -// page(0x2200B0) - page(0x20004) = 65536 -// 0x0B0 = 176 +// page(0x220300) - page(0x21023c) = 65536 +// 0x23c = 768 // CHECK: _start: -// CHECK-NEXT: 210000: nop -// CHECK-NEXT: 210004: adrp x0, #65536 -// CHECK-NEXT: 210008: ldr x0, [x0, #176] -// CHECK-NEXT: 21000c: nop -// CHECK-NEXT: 210010: nop +// CHECK-NEXT: 210238: nop +// CHECK-NEXT: 21023c: adrp x0, #65536 +// CHECK-NEXT: 210240: ldr x0, [x0, #768] +// CHECK-NEXT: 210244: nop +// CHECK-NEXT: 210248: nop diff --git a/test/ELF/aarch64-tls-gdle.s b/test/ELF/aarch64-tls-gdle.s index f1a53858c..f53359de4 100644 --- a/test/ELF/aarch64-tls-gdle.s +++ b/test/ELF/aarch64-tls-gdle.s @@ -11,10 +11,10 @@ # TCB size = 0x16 and foo is first element from TLS register. # CHECK-LABEL: _start: -# CHECK-NEXT: 210000: movz x0, #0, lsl #16 -# CHECK-NEXT: 210004: movk x0, #16 -# CHECK-NEXT: 210008: nop -# CHECK-NEXT: 21000c: nop +# CHECK-NEXT: 2101c8: movz x0, #0, lsl #16 +# CHECK-NEXT: 2101cc: movk x0, #16 +# CHECK-NEXT: 2101d0: nop +# CHECK-NEXT: 2101d4: nop .globl _start _start: diff --git a/test/ELF/aarch64-tls-ie.s b/test/ELF/aarch64-tls-ie.s index 260b2530d..4a14f5e34 100644 --- a/test/ELF/aarch64-tls-ie.s +++ b/test/ELF/aarch64-tls-ie.s @@ -14,8 +14,8 @@ # RELOC-NEXT: SHF_ALLOC # RELOC-NEXT: SHF_WRITE # RELOC-NEXT: ] -# RELOC-NEXT: Address: 0x2200B0 -# RELOC-NEXT: Offset: 0x200B0 +# RELOC-NEXT: Address: 0x220338 +# RELOC-NEXT: Offset: 0x338 # RELOC-NEXT: Size: 16 # RELOC-NEXT: Link: 0 # RELOC-NEXT: Info: 0 @@ -24,8 +24,8 @@ # RELOC-NEXT: } # RELOC: Relocations [ # RELOC-NEXT: Section ({{.*}}) .rela.dyn { -# RELOC-NEXT: 0x2200B8 R_AARCH64_TLS_TPREL64 bar 0x0 -# RELOC-NEXT: 0x2200B0 R_AARCH64_TLS_TPREL64 foo 0x0 +# RELOC-NEXT: 0x220340 R_AARCH64_TLS_TPREL64 bar 0x0 +# RELOC-NEXT: 0x220338 R_AARCH64_TLS_TPREL64 foo 0x0 # RELOC-NEXT: } # RELOC-NEXT:] @@ -34,10 +34,10 @@ ## Page(0x2200B8) - Page(0x210000) = 0x10000 = 65536 ## 0x2200B8 & 0xff8 = 0xB8 = 184 # CHECK: _start: -# CHECK-NEXT: 210000: adrp x0, #65536 -# CHECK-NEXT: 210004: ldr x0, [x0, #176] -# CHECK-NEXT: 210008: adrp x0, #65536 -# CHECK-NEXT: 21000c: ldr x0, [x0, #184] +# CHECK-NEXT: 210278: adrp x0, #65536 +# CHECK-NEXT: 21027c: ldr x0, [x0, #824] +# CHECK-NEXT: 210280: adrp x0, #65536 +# CHECK-NEXT: 210284: ldr x0, [x0, #832] .globl _start _start: diff --git a/test/ELF/aarch64-tls-le.s b/test/ELF/aarch64-tls-le.s index 573349f90..6df4ae64f 100644 --- a/test/ELF/aarch64-tls-le.s +++ b/test/ELF/aarch64-tls-le.s @@ -20,12 +20,12 @@ _start: # TCB size = 0x16 and foo is first element from TLS register. #CHECK: Disassembly of section .text: #CHECK: _start: -#CHECK: 210000: 40 d0 3b d5 mrs x0, TPIDR_EL0 -#CHECK: 210004: 00 00 40 91 add x0, x0, #0, lsl #12 -#CHECK: 210008: 00 40 00 91 add x0, x0, #16 -#CHECK: 21000c: 40 d0 3b d5 mrs x0, TPIDR_EL0 -#CHECK: 210010: 00 fc 7f 91 add x0, x0, #4095, lsl #12 -#CHECK: 210014: 00 e0 3f 91 add x0, x0, #4088 +#CHECK: 210158: 40 d0 3b d5 mrs x0, TPIDR_EL0 +#CHECK: 21015c: 00 00 40 91 add x0, x0, #0, lsl #12 +#CHECK: 210160: 00 40 00 91 add x0, x0, #16 +#CHECK: 210164: 40 d0 3b d5 mrs x0, TPIDR_EL0 +#CHECK: 210168: 00 fc 7f 91 add x0, x0, #4095, lsl #12 +#CHECK: 21016c: 00 e0 3f 91 add x0, x0, #4088 .section .tbss,"awT",@nobits diff --git a/test/ELF/aarch64-tls-vaddr-align.s b/test/ELF/aarch64-tls-vaddr-align.s new file mode 100644 index 000000000..5e71c7fb2 --- /dev/null +++ b/test/ELF/aarch64-tls-vaddr-align.s @@ -0,0 +1,31 @@ +# REQUIRES: aarch64 + +# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readelf -S -l %t | FileCheck --check-prefix=SEC %s +# RUN: llvm-objdump -d %t | FileCheck --check-prefix=DIS %s + +# SEC: Name Type Address Off Size ES Flg Lk Inf Al +# SEC: .tdata PROGBITS 0000000000220200 000200 000001 00 WAT 0 0 1 +# SEC: .tbss NOBITS 0000000000220300 000201 000008 00 WAT 0 0 256 + +# SEC: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# SEC: TLS 0x000200 0x0000000000220200 0x0000000000220200 0x000001 0x000108 R 0x100 + +## We currently have a hack in Writer.cpp:fixSectionAlignments() to force +## p_vaddr(PT_TLS)%p_align(PT_TLS)=0, to work around bugs in some dynamic loaders. + +## a@tprel = st_value(a) + GAP + (p_vaddr-GAP_ABOVE_TP & p_align-1) = +## .tbss-.tdata + 16 + GAP_ABOVE_TP + (p_vaddr-GAP_ABOVE_TP & p_align-1) = +## 0x220300-0x220200 + 16 + (0x220200-16 & 0x100-1) = 512 +# DIS: add x0, x0, #512 + +add x0, x0, :tprel_lo12_nc:a + +.section .tdata,"awT" +.byte 0 + +.section .tbss,"awT" +.p2align 8 +a: +.quad 0 diff --git a/test/ELF/aarch64-tlsdesc.s b/test/ELF/aarch64-tlsdesc.s index 103c23ef3..1ae915236 100644 --- a/test/ELF/aarch64-tlsdesc.s +++ b/test/ELF/aarch64-tlsdesc.s @@ -15,10 +15,10 @@ // create target specific dynamic TLSDESC relocation where addend is // the symbol VMA in tls block. -// CHECK: 10000: adrp x0, #65536 -// CHECK-NEXT: 10004: ldr x1, [x0, #144] -// CHECK-NEXT: 10008: add x0, x0, #144 -// CHECK-NEXT: 1000c: blr x1 +// CHECK: 10298: adrp x0, #65536 +// CHECK-NEXT: 1029c: ldr x1, [x0, #856] +// CHECK-NEXT: 102a0: add x0, x0, #856 +// CHECK-NEXT: 102a4: blr x1 adrp x0, :tlsdesc:local1 ldr x1, [x0, :tlsdesc_lo12:local1] @@ -26,10 +26,10 @@ .tlsdesccall a blr x1 -// CHECK: 10010: adrp x0, #65536 -// CHECK-NEXT: 10014: ldr x1, [x0, #160] -// CHECK-NEXT: 10018: add x0, x0, #160 -// CHECK-NEXT: 1001c: blr x1 +// CHECK: 102a8: adrp x0, #65536 +// CHECK-NEXT: 102ac: ldr x1, [x0, #872] +// CHECK-NEXT: 102b0: add x0, x0, #872 +// CHECK-NEXT: 102b4: blr x1 adrp x0, :tlsdesc:local2 ldr x1, [x0, :tlsdesc_lo12:local2] @@ -37,10 +37,10 @@ .tlsdesccall a blr x1 -// CHECK: 10020: adrp x0, #65536 -// CHECK-NEXT: 10024: ldr x1, [x0, #176] -// CHECK-NEXT: 10028: add x0, x0, #176 -// CHECK-NEXT: 1002c: blr x1 +// CHECK: 102b8: adrp x0, #65536 +// CHECK-NEXT: 102bc: ldr x1, [x0, #888] +// CHECK-NEXT: 102c0: add x0, x0, #888 +// CHECK-NEXT: 102c4: blr x1 .section .tbss,"awT",@nobits .type local1,@object @@ -65,8 +65,8 @@ local2: // REL: Relocations [ // REL-NEXT: Section (4) .rela.dyn { -// REL-NEXT: 0x200A0 R_AARCH64_TLSDESC - 0x0 -// REL-NEXT: 0x200B0 R_AARCH64_TLSDESC - 0x8 -// REL-NEXT: 0x20090 R_AARCH64_TLSDESC a 0x0 +// REL-NEXT: 0x20368 R_AARCH64_TLSDESC - 0x0 +// REL-NEXT: 0x20378 R_AARCH64_TLSDESC - 0x8 +// REL-NEXT: 0x20358 R_AARCH64_TLSDESC a 0x0 // REL-NEXT: } // REL-NEXT: ] diff --git a/test/ELF/aarch64-tlsld-ldst.s b/test/ELF/aarch64-tlsld-ldst.s index 3f00630bd..f409fa58d 100644 --- a/test/ELF/aarch64-tlsld-ldst.s +++ b/test/ELF/aarch64-tlsld-ldst.s @@ -25,22 +25,22 @@ _start: mrs x8, TPIDR_EL0 ldrb w0, [x8, :tprel_lo12_nc:var4] // CHECK: _start: -// CHECK-NEXT: 210000: mrs x8, TPIDR_EL0 +// CHECK-NEXT: 210158: mrs x8, TPIDR_EL0 // 0x0 + c10 = 0xc10 = tcb (16-bytes) + var0 -// CHECK-NEXT: 210004: add x8, x8, #0, lsl #12 -// CHECK-NEXT: 210008: ldr q20, [x8, #3088] +// CHECK-NEXT: 21015c: add x8, x8, #0, lsl #12 +// CHECK-NEXT: 210160: ldr q20, [x8, #3088] // 0x1000 + 0x820 = 0x1820 = tcb + var1 -// CHECK-NEXT: 21000c: add x8, x8, #1, lsl #12 -// CHECK-NEXT: 210010: ldr x0, [x8, #2080] +// CHECK-NEXT: 210164: add x8, x8, #1, lsl #12 +// CHECK-NEXT: 210168: ldr x0, [x8, #2080] // 0x2000 + 0x428 = 0x2428 = tcb + var2 -// CHECK-NEXT: 210014: add x8, x8, #2, lsl #12 -// CHECK-NEXT: 210018: ldr w0, [x8, #1064] +// CHECK-NEXT: 21016c: add x8, x8, #2, lsl #12 +// CHECK-NEXT: 210170: ldr w0, [x8, #1064] // 0x3000 + 0x2c = 0x302c = tcb + var3 -// CHECK-NEXT: 21001c: add x8, x8, #3, lsl #12 -// CHECK-NEXT: 210020: ldrh w0, [x8, #44] +// CHECK-NEXT: 210174: add x8, x8, #3, lsl #12 +// CHECK-NEXT: 210178: ldrh w0, [x8, #44] // 0x3000 + 0xc2e = 0x32ce = tcb + var4 -// CHECK-NEXT: 210024: add x8, x8, #3, lsl #12 -// CHECK-NEXT: 210028: ldrb w0, [x8, #3118] +// CHECK-NEXT: 21017c: add x8, x8, #3, lsl #12 +// CHECK-NEXT: 210180: ldrb w0, [x8, #3118] // CHECK-SYMS: 0000000000000c00 0 TLS GLOBAL DEFAULT 2 var0 // CHECK-SYMS-NEXT: 0000000000001810 4 TLS GLOBAL DEFAULT 2 var1 diff --git a/test/ELF/aarch64-tstbr14-reloc.s b/test/ELF/aarch64-tstbr14-reloc.s index 383076dca..9601ad3c7 100644 --- a/test/ELF/aarch64-tstbr14-reloc.s +++ b/test/ELF/aarch64-tstbr14-reloc.s @@ -7,26 +7,20 @@ # RUN: llvm-objdump -d --no-show-raw-insn %t3 | FileCheck -check-prefix=DSO %s # RUN: llvm-readobj -S -r %t3 | FileCheck -check-prefix=DSOREL %s -# 0x1101c - 28 = 0x20000 -# 0x11020 - 16 = 0x20010 -# 0x11024 - 36 = 0x20000 -# 0x11028 - 24 = 0x20010 -# CHECK: Disassembly of section .text: -# CHECK-EMPTY: -# CHECK-NEXT: _foo: -# CHECK-NEXT: 210000: nop -# CHECK-NEXT: 210004: nop -# CHECK-NEXT: 210008: nop -# CHECK-NEXT: 21000c: nop +# CHECK: _foo: +# CHECK-NEXT: 210120: nop +# CHECK-NEXT: 210124: nop +# CHECK-NEXT: 210128: nop +# CHECK-NEXT: 21012c: nop # CHECK: _bar: -# CHECK-NEXT: 210010: nop -# CHECK-NEXT: 210014: nop -# CHECK-NEXT: 210018: nop +# CHECK-NEXT: 210130: nop +# CHECK-NEXT: 210134: nop +# CHECK-NEXT: 210138: nop # CHECK: _start: -# CHECK-NEXT: 21001c: tbnz w3, #15, #-28 -# CHECK-NEXT: 210020: tbnz w3, #15, #-16 -# CHECK-NEXT: 210024: tbz x6, #45, #-36 -# CHECK-NEXT: 210028: tbz x6, #45, #-24 +# CHECK-NEXT: 21013c: tbnz w3, #15, #-28 <_foo> +# CHECK-NEXT: 210140: tbnz w3, #15, #-16 <_bar> +# CHECK-NEXT: 210144: tbz x6, #45, #-36 <_foo> +# CHECK-NEXT: 210148: tbz x6, #45, #-24 <_bar> #DSOREL: Section { #DSOREL: Index: @@ -36,8 +30,8 @@ #DSOREL-NEXT: SHF_ALLOC #DSOREL-NEXT: SHF_WRITE #DSOREL-NEXT: ] -#DSOREL-NEXT: Address: 0x30000 -#DSOREL-NEXT: Offset: 0x30000 +#DSOREL-NEXT: Address: 0x30420 +#DSOREL-NEXT: Offset: 0x420 #DSOREL-NEXT: Size: 40 #DSOREL-NEXT: Link: 0 #DSOREL-NEXT: Info: 0 @@ -46,55 +40,51 @@ #DSOREL-NEXT: } #DSOREL: Relocations [ #DSOREL-NEXT: Section ({{.*}}) .rela.plt { -#DSOREL-NEXT: 0x30018 R_AARCH64_JUMP_SLOT _foo -#DSOREL-NEXT: 0x30020 R_AARCH64_JUMP_SLOT _bar +#DSOREL-NEXT: 0x30438 R_AARCH64_JUMP_SLOT _foo +#DSOREL-NEXT: 0x30440 R_AARCH64_JUMP_SLOT _bar #DSOREL-NEXT: } #DSOREL-NEXT:] #DSO: Disassembly of section .text: #DSO-EMPTY: #DSO-NEXT: _foo: -#DSO-NEXT: 10000: nop -#DSO-NEXT: 10004: nop -#DSO-NEXT: 10008: nop -#DSO-NEXT: 1000c: nop +#DSO-NEXT: 102f8: nop +#DSO-NEXT: 102fc: nop +#DSO-NEXT: 10300: nop +#DSO-NEXT: 10304: nop #DSO: _bar: -#DSO-NEXT: 10010: nop -#DSO-NEXT: 10014: nop -#DSO-NEXT: 10018: nop +#DSO-NEXT: 10308: nop +#DSO-NEXT: 1030c: nop +#DSO-NEXT: 10310: nop #DSO: _start: -# 0x1001c + 52 = 0x10050 = PLT[1] -# 0x10020 + 64 = 0x10060 = PLT[2] -# 0x10024 + 44 = 0x10050 = PLT[1] -# 0x10028 + 56 = 0x10060 = PLT[2] -#DSO-NEXT: 1001c: tbnz w3, #15, #52 -#DSO-NEXT: 10020: tbnz w3, #15, #64 -#DSO-NEXT: 10024: tbz x6, #45, #44 -#DSO-NEXT: 10028: tbz x6, #45, #56 +#DSO-NEXT: 10314: tbnz w3, #15, #60 <_foo@plt> +#DSO-NEXT: 10318: tbnz w3, #15, #72 <_bar@plt> +#DSO-NEXT: 1031c: tbz x6, #45, #52 <_foo@plt> +#DSO-NEXT: 10320: tbz x6, #45, #64 <_bar@plt> #DSO-EMPTY: #DSO-NEXT: Disassembly of section .plt: #DSO-EMPTY: #DSO-NEXT: .plt: -#DSO-NEXT: 10030: stp x16, x30, [sp, #-16]! -#DSO-NEXT: 10034: adrp x16, #131072 -#DSO-NEXT: 10038: ldr x17, [x16, #16] -#DSO-NEXT: 1003c: add x16, x16, #16 -#DSO-NEXT: 10040: br x17 -#DSO-NEXT: 10044: nop -#DSO-NEXT: 10048: nop -#DSO-NEXT: 1004c: nop +#DSO-NEXT: 10330: stp x16, x30, [sp, #-16]! +#DSO-NEXT: 10334: adrp x16, #131072 +#DSO-NEXT: 10338: ldr x17, [x16, #1072] +#DSO-NEXT: 1033c: add x16, x16, #1072 +#DSO-NEXT: 10340: br x17 +#DSO-NEXT: 10344: nop +#DSO-NEXT: 10348: nop +#DSO-NEXT: 1034c: nop #DSO-EMPTY: #DSO-NEXT: _foo@plt: -#DSO-NEXT: 10050: adrp x16, #131072 -#DSO-NEXT: 10054: ldr x17, [x16, #24] -#DSO-NEXT: 10058: add x16, x16, #24 -#DSO-NEXT: 1005c: br x17 +#DSO-NEXT: 10350: adrp x16, #131072 +#DSO-NEXT: 10354: ldr x17, [x16, #1080] +#DSO-NEXT: 10358: add x16, x16, #1080 +#DSO-NEXT: 1035c: br x17 #DSO-EMPTY: #DSO-NEXT: _bar@plt: -#DSO-NEXT: 10060: adrp x16, #131072 -#DSO-NEXT: 10064: ldr x17, [x16, #32] -#DSO-NEXT: 10068: add x16, x16, #32 -#DSO-NEXT: 1006c: br x17 +#DSO-NEXT: 10360: adrp x16, #131072 +#DSO-NEXT: 10364: ldr x17, [x16, #1088] +#DSO-NEXT: 10368: add x16, x16, #1088 +#DSO-NEXT: 1036c: br x17 .globl _start _start: diff --git a/test/ELF/aarch64-undefined-weak.s b/test/ELF/aarch64-undefined-weak.s index 73a214f3e..ee75d40dd 100644 --- a/test/ELF/aarch64-undefined-weak.s +++ b/test/ELF/aarch64-undefined-weak.s @@ -36,15 +36,15 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // 2162688 = 0x210000 -// CHECK: 210000: b #4 -// CHECK-NEXT: 210004: bl #4 -// CHECK-NEXT: 210008: b.eq #4 -// CHECK-NEXT: 21000c: cbz x1, #4 -// CHECK-NEXT: 210010: adr x0, #0 -// CHECK-NEXT: 210014: adrp x0, #0 -// CHECK: 210018: 00 00 00 00 .word 0x00000000 -// CHECK-NEXT: 21001c: 00 00 00 00 .word 0x00000000 -// CHECK-NEXT: 210020: 00 00 00 00 .word 0x00000000 -// CHECK-NEXT: 210024: 00 00 .short 0x0000 +// CHECK: 210120: b #4 +// CHECK-NEXT: 210124: bl #4 +// CHECK-NEXT: 210128: b.eq #4 +// CHECK-NEXT: 21012c: cbz x1, #4 +// CHECK-NEXT: 210130: adr x0, #0 +// CHECK-NEXT: 210134: adrp x0, #0 +// CHECK: 210138: 00 00 00 00 .word 0x00000000 +// CHECK-NEXT: 21013c: 00 00 00 00 .word 0x00000000 +// CHECK-NEXT: 210140: 00 00 00 00 .word 0x00000000 +// CHECK-NEXT: 210144: 00 00 .short 0x0000 // CHECK: $x.2: -// CHECK-NEXT: 210026: ldr x8, #0 +// CHECK-NEXT: 210146: ldr x8, #0 diff --git a/test/ELF/amdgpu-relocs.s b/test/ELF/amdgpu-relocs.s index 88b5c5ec2..caee617cf 100644 --- a/test/ELF/amdgpu-relocs.s +++ b/test/ELF/amdgpu-relocs.s @@ -94,7 +94,7 @@ foo: # linker. # CHECK: Relocations [ # CHECK: .rela.dyn { -# CHECK-NEXT: R_AMDGPU_RELATIVE64 - 0x3008 +# CHECK-NEXT: R_AMDGPU_RELATIVE64 - 0x3928 # CHECK-NEXT: R_AMDGPU_ABS64 common_var0 0x0 # CHECK-NEXT: R_AMDGPU_ABS64 common_var1 0x0 # CHECK-NEXT: R_AMDGPU_ABS64 common_var2 0x0 @@ -114,16 +114,16 @@ foo: # CHECK-NEXT: } # CHECK-NEXT: ] -# NM: 0000000000003010 B common_var0 -# NM: 0000000000003410 B common_var1 -# NM: 0000000000003810 B common_var2 -# NM: 0000000000003008 d temp2 +# NM: 0000000000003930 B common_var0 +# NM: 0000000000003d30 B common_var1 +# NM: 0000000000004130 B common_var2 +# NM: 0000000000003928 d temp2 -# temp2 - foo = 0x3008-0x768 = 0x28a0 +# temp2 - foo = 0x3928-0x768 = 0x31c0 # HEX: section '.rodata': -# HEX-NEXT: 0x00000768 a0280000 00000000 +# HEX-NEXT: 0x00000768 c0310000 00000000 # common_var2+4, common_var1+8, and common_var0+12. # HEX: section 'nonalloc': -# HEX-NEXT: 0x00000000 00000000 14380000 00000000 18340000 -# HEX-NEXT: 0x00000010 00000000 1c300000 +# HEX-NEXT: 0x00000000 00000000 34410000 00000000 383d0000 +# HEX-NEXT: 0x00000010 00000000 3c390000 diff --git a/test/ELF/arm-abs32-dyn.s b/test/ELF/arm-abs32-dyn.s index 36c0353ac..97870accf 100644 --- a/test/ELF/arm-abs32-dyn.s +++ b/test/ELF/arm-abs32-dyn.s @@ -24,18 +24,18 @@ bar: // RUN: llvm-readelf -x .data %t.so | FileCheck --check-prefix=HEX %s // CHECK: Dynamic Relocations { -// CHECK-NEXT: 0x2004 R_ARM_RELATIVE -// CHECK-NEXT: 0x2008 R_ARM_RELATIVE -// CHECK-NEXT: 0x2000 R_ARM_ABS32 foo 0x0 +// CHECK-NEXT: 0x3204 R_ARM_RELATIVE +// CHECK-NEXT: 0x3208 R_ARM_RELATIVE +// CHECK-NEXT: 0x3200 R_ARM_ABS32 foo 0x0 // CHECK-NEXT: } // CHECK: Symbols [ // CHECK: Symbol { // CHECK: Name: bar -// CHECK-NEXT: Value: 0x1000 +// CHECK-NEXT: Value: 0x11A8 // CHECK: Symbol { // CHECK: Name: foo -// CHECK-NEXT: Value: 0x1000 +// CHECK-NEXT: Value: 0x11A8 -// HEX: 0x00002000 00000000 00100000 00100000 +// HEX: 0x00003200 00000000 a8110000 a8110000 diff --git a/test/ELF/arm-bl-v6-inrange.s b/test/ELF/arm-bl-v6-inrange.s index f7cdea748..f6d9f16f8 100644 --- a/test/ELF/arm-bl-v6-inrange.s +++ b/test/ELF/arm-bl-v6-inrange.s @@ -5,8 +5,7 @@ // RUN: .caller 0x500000 : { *(.text) } \ // RUN: .callee2 0x900004 : { *(.callee_high) } } " > %t.script // RUN: ld.lld %t --script %t.script -o %t2 -// RUN: llvm-objdump -d -triple=thumbv6-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-THUMB %s -// RUN: llvm-objdump -d -triple=armv6-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-ARM %s +// RUN: llvm-objdump -d -triple=armv6-none-linux-gnueabi %t2 | FileCheck %s // On older Arm Architectures such as v5 and v6 the Thumb BL and BLX relocation // uses a slightly different encoding that has a lower range. These relocations @@ -27,17 +26,17 @@ _start: .type thumbfunc, %function thumbfunc: bx lr -// CHECK-THUMB: Disassembly of section .callee1: -// CHECK-THUMB-EMPTY: -// CHECK-THUMB-NEXT: thumbfunc: -// CHECK-THUMB-NEXT: 100004: 70 47 bx lr -// CHECK-THUMB-EMPTY: -// CHECK-THUMB-NEXT: Disassembly of section .caller: -// CHECK-THUMB-EMPTY: -// CHECK-THUMB-NEXT: _start: -// CHECK-THUMB-NEXT: 500000: 00 f4 00 f8 bl #-4194304 -// CHECK-THUMB-NEXT: 500004: ff f3 fe ef blx #4194300 -// CHECK-THUMB-NEXT: 500008: 70 47 bx lr +// CHECK: Disassembly of section .callee1: +// CHECK-EMPTY: +// CHECK-NEXT: thumbfunc: +// CHECK-NEXT: 100004: 70 47 bx lr +// CHECK-EMPTY: +// CHECK-NEXT: Disassembly of section .caller: +// CHECK-EMPTY: +// CHECK-NEXT: _start: +// CHECK-NEXT: 500000: 00 f4 00 f8 bl #-4194304 +// CHECK-NEXT: 500004: ff f3 fe ef blx #4194300 +// CHECK-NEXT: 500008: 70 47 bx lr .arm .section .callee_high, "ax", %progbits @@ -45,7 +44,7 @@ thumbfunc: .type armfunc, %function armfunc: bx lr -// CHECK-ARM: Disassembly of section .callee2: -// CHECK-ARM-EMPTY: -// CHECK-ARM-NEXT: armfunc: -// CHECK-ARM-NEXT: 900004: 1e ff 2f e1 bx lr +// CHECK: Disassembly of section .callee2: +// CHECK-EMPTY: +// CHECK-NEXT: armfunc: +// CHECK-NEXT: 900004: 1e ff 2f e1 bx lr diff --git a/test/ELF/arm-bl-v6.s b/test/ELF/arm-bl-v6.s index afaf12c30..24af92469 100644 --- a/test/ELF/arm-bl-v6.s +++ b/test/ELF/arm-bl-v6.s @@ -1,10 +1,10 @@ // REQUIRES: arm // RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv6-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 -// RUN: llvm-objdump -d -triple=armv6-none-linux-gnueabi -start-address=69632 -stop-address=69640 %t2 | FileCheck -check-prefix=CHECK-ARM1 %s -// RUN: llvm-objdump -d -triple=thumbv6-none-linux-gnueabi %t2 -start-address=69640 -stop-address=69644 | FileCheck -check-prefix=CHECK-THUMB1 %s -// RUN: llvm-objdump -d -triple=armv6-none-linux-gnueabi -start-address=2166796 -stop-address=2166804 %t2 | FileCheck -check-prefix=CHECK-ARM2 %s -// RUN: llvm-objdump -d -triple=thumbv6-none-linux-gnueabi %t2 -start-address=6365184 -stop-address=6365186 | FileCheck -check-prefix=CHECK-THUMB2 %s +// RUN: llvm-objdump -d -triple=armv6-none-linux-gnueabi -start-address=0x12000 -stop-address=0x12008 %t2 | FileCheck -check-prefix=CHECK-ARM1 %s +// RUN: llvm-objdump -d -triple=thumbv6-none-linux-gnueabi %t2 -start-address=0x12008 -stop-address=0x1200c | FileCheck -check-prefix=CHECK-THUMB1 %s +// RUN: llvm-objdump -d -triple=armv6-none-linux-gnueabi -start-address=0x21200c -stop-address=0x212014 %t2 | FileCheck -check-prefix=CHECK-ARM2 %s +// RUN: llvm-objdump -d -triple=thumbv6-none-linux-gnueabi %t2 -start-address=0x613000 -stop-address=0x613002 | FileCheck -check-prefix=CHECK-THUMB2 %s // On Arm v6 the range of a Thumb BL instruction is only 4 megabytes as the // extended range encoding is not supported. The following example has a Thumb @@ -28,8 +28,8 @@ _start: // CHECK-ARM1: Disassembly of section .text: // CHECK-ARM1-EMPTY: // CHECK-ARM1-NEXT: _start: -// CHECK-ARM1-NEXT: 11000: 00 00 00 fa blx #0 -// CHECK-ARM1-NEXT: 11004: 1e ff 2f e1 bx lr +// CHECK-ARM1-NEXT: 12000: 00 00 00 fa blx #0 +// CHECK-ARM1-NEXT: 12004: 1e ff 2f e1 bx lr .thumb .section .text.2, "ax", %progbits .globl thumbfunc @@ -38,16 +38,16 @@ thumbfunc: bl farthumbfunc // CHECK-THUMB1: thumbfunc: -// CHECK-THUMB1-NEXT: 11008: 00 f2 00 e8 blx #2097152 +// CHECK-THUMB1-NEXT: 12008: 00 f2 00 e8 blx #2097152 // 6 Megabytes, enough to make farthumbfunc out of range of caller // on a v6 Arm, but not on a v7 Arm. .section .text.3, "ax", %progbits .space 0x200000 // CHECK-ARM2: __ARMv5ABSLongThunk_farthumbfunc: -// CHECK-ARM2-NEXT: 21100c: 04 f0 1f e5 ldr pc, [pc, #-4] +// CHECK-ARM2-NEXT: 21200c: 04 f0 1f e5 ldr pc, [pc, #-4] // CHECK-ARM2: $d: -// CHECK-ARM2-NEXT: 211010: 01 20 61 00 .word 0x00612001 +// CHECK-ARM2-NEXT: 212010: 01 30 61 00 .word 0x00613001 .section .text.4, "ax", %progbits .space 0x200000 @@ -62,4 +62,4 @@ thumbfunc: farthumbfunc: bx lr // CHECK-THUMB2: farthumbfunc: -// CHECK-THUMB2-NEXT: 612000: 70 47 bx lr +// CHECK-THUMB2-NEXT: 613000: 70 47 bx lr diff --git a/test/ELF/arm-blx.s b/test/ELF/arm-blx.s index a61bfee62..a6dbcbd80 100644 --- a/test/ELF/arm-blx.s +++ b/test/ELF/arm-blx.s @@ -9,8 +9,7 @@ // RUN: .callee3 : { *(.callee_high) } \ // RUN: .callee4 : { *(.callee_arm_high) } } " > %t.script // RUN: ld.lld --script %t.script %t %tfar -o %t2 -// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-ARM %s -// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-THUMB %s +// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s // Test BLX instruction is chosen for ARM BL/BLX instruction and Thumb callee // Using two callees to ensure at least one has 2-byte alignment. @@ -73,47 +72,47 @@ callee_high2: callee_arm_high: bx lr -// CHECK-THUMB: Disassembly of section .callee1: -// CHECK-THUMB-EMPTY: -// CHECK-THUMB-NEXT: callee_low: -// CHECK-THUMB-NEXT: b4: 70 47 bx lr -// CHECK-THUMB: callee_low2: -// CHECK-THUMB-NEXT: b6: 70 47 bx lr +// CHECK: Disassembly of section .callee1: +// CHECK-EMPTY: +// CHECK-NEXT: callee_low: +// CHECK-NEXT: b4: 70 47 bx lr +// CHECK: callee_low2: +// CHECK-NEXT: b6: 70 47 bx lr -// CHECK-ARM: Disassembly of section .callee2: -// CHECK-ARM-EMPTY: -// CHECK-ARM-NEXT: callee_arm_low: -// CHECK-ARM-NEXT: 100: 1e ff 2f e1 bx lr +// CHECK: Disassembly of section .callee2: +// CHECK-EMPTY: +// CHECK-NEXT: callee_arm_low: +// CHECK-NEXT: 100: 1e ff 2f e1 bx lr -// CHECK-ARM: Disassembly of section .caller: -// CHECK-ARM-EMPTY: -// CHECK-ARM-NEXT: _start: -// CHECK-ARM-NEXT: 10000: 2b c0 ff fa blx #-65364 -// CHECK-ARM-NEXT: 10004: 2a c0 ff fa blx #-65368 -// CHECK-ARM-NEXT: 10008: 29 c0 ff fb blx #-65370 -// CHECK-ARM-NEXT: 1000c: 28 c0 ff fb blx #-65374 -// CHECK-ARM-NEXT: 10010: 3a 00 00 fa blx #232 -// CHECK-ARM-NEXT: 10014: 39 00 00 fa blx #228 -// CHECK-ARM-NEXT: 10018: 38 00 00 fb blx #226 -// CHECK-ARM-NEXT: 1001c: 37 00 00 fb blx #222 +// CHECK: Disassembly of section .caller: +// CHECK-EMPTY: +// CHECK-NEXT: _start: +// CHECK-NEXT: 10000: 2b c0 ff fa blx #-65364 +// CHECK-NEXT: 10004: 2a c0 ff fa blx #-65368 +// CHECK-NEXT: 10008: 29 c0 ff fb blx #-65370 +// CHECK-NEXT: 1000c: 28 c0 ff fb blx #-65374 +// CHECK-NEXT: 10010: 3a 00 00 fa blx #232 +// CHECK-NEXT: 10014: 39 00 00 fa blx #228 +// CHECK-NEXT: 10018: 38 00 00 fb blx #226 +// CHECK-NEXT: 1001c: 37 00 00 fb blx #222 // 10020 + 1FFFFFC + 8 = 0x2010024 = blx_far -// CHECK-ARM-NEXT: 10020: ff ff 7f fa blx #33554428 +// CHECK-NEXT: 10020: ff ff 7f fa blx #33554428 // 10024 + 1FFFFFC + 8 = 0x2010028 = blx_far2 -// CHECK-ARM-NEXT: 10024: ff ff 7f fa blx #33554428 -// CHECK-ARM-NEXT: 10028: 34 c0 ff eb bl #-65328 -// CHECK-ARM-NEXT: 1002c: 33 c0 ff eb bl #-65332 -// CHECK-ARM-NEXT: 10030: 72 00 00 eb bl #456 -// CHECK-ARM-NEXT: 10034: 71 00 00 eb bl #452 -// CHECK-ARM-NEXT: 10038: 1e ff 2f e1 bx lr +// CHECK-NEXT: 10024: ff ff 7f fa blx #33554428 +// CHECK-NEXT: 10028: 34 c0 ff eb bl #-65328 +// CHECK-NEXT: 1002c: 33 c0 ff eb bl #-65332 +// CHECK-NEXT: 10030: 72 00 00 eb bl #456 +// CHECK-NEXT: 10034: 71 00 00 eb bl #452 +// CHECK-NEXT: 10038: 1e ff 2f e1 bx lr -// CHECK-THUMB: Disassembly of section .callee3: -// CHECK-THUMB-EMPTY: -// CHECK-THUMB: callee_high: -// CHECK-THUMB-NEXT: 10100: 70 47 bx lr -// CHECK-THUMB: callee_high2: -// CHECK-THUMB-NEXT: 10102: 70 47 bx lr +// CHECK: Disassembly of section .callee3: +// CHECK-EMPTY: +// CHECK: callee_high: +// CHECK-NEXT: 10100: 70 47 bx lr +// CHECK: callee_high2: +// CHECK-NEXT: 10102: 70 47 bx lr -// CHECK-ARM: Disassembly of section .callee4: -// CHECK-ARM-EMPTY: -// CHECK-NEXT-ARM: callee_arm_high: -// CHECK-NEXT-ARM: 10200: 1e ff 2f e1 bx lr +// CHECK: Disassembly of section .callee4: +// CHECK-EMPTY: +// CHECK-NEXT: callee_arm_high: +// CHECK-NEXT: 10200: 1e ff 2f e1 bx lr diff --git a/test/ELF/arm-branch-undef-weak-plt-thunk.s b/test/ELF/arm-branch-undef-weak-plt-thunk.s index 4b033d178..e25370b26 100644 --- a/test/ELF/arm-branch-undef-weak-plt-thunk.s +++ b/test/ELF/arm-branch-undef-weak-plt-thunk.s @@ -1,9 +1,9 @@ // REQUIRES: arm -// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/arm-shared.s -o %t -// RUN: ld.lld %t --shared -o %t.so -// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t2 -// RUN: ld.lld %t2 %t.so -o %t3 -// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi -start-address=69632 -stop-address=69664 %t3 | FileCheck %s +// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/arm-shared.s -o %t1.o +// RUN: ld.lld %t1.o --shared -soname=t1.so -o %t1.so +// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o +// RUN: ld.lld %t.o %t1.so -o %t +// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi -start-address=0x111e4 -stop-address=0x11204 %t | FileCheck %s // When we are dynamic linking, undefined weak references have a PLT entry so // we must create a thunk for the branch to the PLT entry. @@ -24,13 +24,13 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: _start: -// CHECK-NEXT: 11000: 00 00 00 ea b #0 <__ARMv7ABSLongThunk_undefined_weak_we_expect_a_plt_entry_for> -// CHECK-NEXT: 11004: 02 00 00 eb bl #8 <__ARMv7ABSLongThunk_bar2> +// CHECK-NEXT: 111e4: 00 00 00 ea b #0 <__ARMv7ABSLongThunk_undefined_weak_we_expect_a_plt_entry_for> +// CHECK-NEXT: 111e8: 02 00 00 eb bl #8 <__ARMv7ABSLongThunk_bar2> // CHECK: __ARMv7ABSLongThunk_undefined_weak_we_expect_a_plt_entry_for: -// CHECK-NEXT: 11008: 40 c0 01 e3 movw r12, #4160 -// CHECK-NEXT: 1100c: 01 c2 40 e3 movt r12, #513 -// CHECK-NEXT: 11010: 1c ff 2f e1 bx r12 +// CHECK-NEXT: 111ec: 30 c2 01 e3 movw r12, #4656 +// CHECK-NEXT: 111f0: 01 c2 40 e3 movt r12, #513 +// CHECK-NEXT: 111f4: 1c ff 2f e1 bx r12 // CHECK: __ARMv7ABSLongThunk_bar2: -// CHECK-NEXT: 11014: 50 c0 01 e3 movw r12, #4176 -// CHECK-NEXT: 11018: 01 c2 40 e3 movt r12, #513 -// CHECK-NEXT: 1101c: 1c ff 2f e1 bx r12 +// CHECK-NEXT: 111f8: 40 c2 01 e3 movw r12, #4672 +// CHECK-NEXT: 111fc: 01 c2 40 e3 movt r12, #513 +// CHECK-NEXT: 11200: 1c ff 2f e1 bx r12 diff --git a/test/ELF/arm-copy.s b/test/ELF/arm-copy.s index 5f54c52bd..df5b2ee82 100644 --- a/test/ELF/arm-copy.s +++ b/test/ELF/arm-copy.s @@ -25,7 +25,7 @@ _start: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x13000 +// CHECK-NEXT: Address: 0x13220 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 8 // CHECK-NEXT: Link: @@ -35,13 +35,13 @@ _start: // CHECK: Relocations [ // CHECK-NEXT: Section {{.*}} .rel.dyn { // CHECK-NEXT: Relocation { -// CHECK-NEXT: Offset: 0x13000 +// CHECK-NEXT: Offset: 0x13220 // CHECK-NEXT: Type: R_ARM_COPY // CHECK-NEXT: Symbol: y // CHECK-NEXT: Addend: 0x0 // CHECK-NEXT: } // CHECK-NEXT: Relocation { -// CHECK-NEXT: Offset: 0x13004 +// CHECK-NEXT: Offset: 0x13224 // CHECK-NEXT: Type: R_ARM_COPY // CHECK-NEXT: Symbol: z // CHECK-NEXT: Addend: 0x0 @@ -50,14 +50,14 @@ _start: // CHECK: Symbols [ // CHECK: Name: y -// CHECK-NEXT: Value: 0x13000 +// CHECK-NEXT: Value: 0x13220 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object // CHECK-NEXT: Other: // CHECK-NEXT: Section: .bss // CHECK: Name: z -// CHECK-NEXT: Value: 0x13004 +// CHECK-NEXT: Value: 0x13224 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -67,16 +67,13 @@ _start: // CODE: Disassembly of section .text: // CODE-EMPTY: // CODE-NEXT: _start: -// S(y) = 0x13000, A = 0 -// (S + A) & 0x0000ffff = 0x3000 = #12288 -// CODE-NEXT: 11000: movw r2, #12288 -// S(y) = 0x13000, A = 0 -// ((S + A) & 0xffff0000) >> 16 = 0x1 -// CODE-NEXT: 11004: movt r2, #1 -// CODE-NEXT: 11008: ldr r3, [pc, #4] -// CODE-NEXT: 1100c: ldr r3, [r3] +// S + A = 0x13220 + 0 = 65536 * 1 + 12832 +// CODE-NEXT: 111b4: movw r2, #12832 +// CODE-NEXT: 111b8: movt r2, #1 +// CODE-NEXT: 111bc: ldr r3, [pc, #4] +// CODE-NEXT: 111c0: ldr r3, [r3] // RODATA: Contents of section .rodata: // S(z) = 0x13004 -// RODATA-NEXT: 101b0 04300100 +// RODATA-NEXT: 101b0 24320100 diff --git a/test/ELF/arm-execute-only.s b/test/ELF/arm-execute-only.s index d28337cf4..1d38cae6e 100644 --- a/test/ELF/arm-execute-only.s +++ b/test/ELF/arm-execute-only.s @@ -4,9 +4,6 @@ // RUN: ld.lld %t.o -o %t.so -shared // RUN: llvm-readelf -l %t.so | FileCheck --implicit-check-not=LOAD %s -// RUN: ld.lld %t.o %t.o -o %t.so -shared -// RUN: llvm-readelf -l %t.so | FileCheck --implicit-check-not=LOAD %s - // RUN: echo ".section .foo,\"ax\"; \ // RUN: bx lr" > %t.s // RUN: llvm-mc -filetype=obj -triple=armv7-pc-linux %t.s -o %t2.o @@ -14,9 +11,9 @@ // RUN: llvm-readelf -l %t.so | FileCheck --check-prefix=DIFF --implicit-check-not=LOAD %s // CHECK: LOAD 0x000000 0x00000000 0x00000000 0x0016d 0x0016d R 0x1000 -// CHECK: LOAD 0x001000 0x00001000 0x00001000 0x{{.*}} 0x{{.*}} R E 0x1000 -// CHECK: LOAD 0x002000 0x00002000 0x00002000 0x{{.*}} 0x{{.*}} E 0x1000 -// CHECK: LOAD 0x003000 0x00003000 0x00003000 0x00038 0x00038 RW 0x1000 +// CHECK: LOAD 0x000170 0x00001170 0x00001170 0x{{.*}} 0x{{.*}} R E 0x1000 +// CHECK: LOAD 0x000174 0x00002174 0x00002174 0x{{.*}} 0x{{.*}} E 0x1000 +// CHECK: LOAD 0x000178 0x00003178 0x00003178 0x00038 0x00038 RW 0x1000 // CHECK: 01 .dynsym .gnu.hash .hash .dynstr // CHECK: 02 .text @@ -24,8 +21,8 @@ // CHECK: 04 .dynamic // DIFF: LOAD 0x000000 0x00000000 0x00000000 0x0014d 0x0014d R 0x1000 -// DIFF: LOAD 0x001000 0x00001000 0x00001000 0x0000c 0x0000c R E 0x1000 -// DIFF: LOAD 0x002000 0x00002000 0x00002000 0x00038 0x00038 RW 0x1000 +// DIFF: LOAD 0x000150 0x00001150 0x00001150 0x0000c 0x0000c R E 0x1000 +// DIFF: LOAD 0x00015c 0x0000215c 0x0000215c 0x00038 0x00038 RW 0x1000 // DIFF: 01 .dynsym .gnu.hash .hash .dynstr // DIFF: 02 .text .foo diff --git a/test/ELF/arm-exidx-add-missing.s b/test/ELF/arm-exidx-add-missing.s index 04feba0ca..566199628 100644 --- a/test/ELF/arm-exidx-add-missing.s +++ b/test/ELF/arm-exidx-add-missing.s @@ -53,14 +53,14 @@ __aeabi_unwind_cpp_pr0: bx lr // f1, f2 -// CHECK: 100d4 2c0f0000 08849780 280f0000 01000000 +// CHECK: 100d4 28100000 08849780 24100000 01000000 // f3, __aeabi_unwind_cpp_pr0 -// CHECK-NEXT: 100e4 240f0000 01000000 200f0000 01000000 +// CHECK-NEXT: 100e4 20100000 01000000 1c100000 01000000 // sentinel -// CHECK-NEXT: 100f4 1c0f0000 01000000 +// CHECK-NEXT: 100f4 18100000 01000000 // f1, (f2, f3, __aeabi_unwind_cpp_pr0) -// CHECK-MERGE: 100d4 2c0f0000 08849780 280f0000 01000000 +// CHECK-MERGE: 100d4 18100000 08849780 14100000 01000000 // sentinel -// CHECK-MERGE-NEXT: 100e4 2c0f0000 01000000 +// CHECK-MERGE-NEXT: 100e4 18100000 01000000 diff --git a/test/ELF/arm-exidx-canunwind.s b/test/ELF/arm-exidx-canunwind.s index 75c772392..1c2f4f98b 100644 --- a/test/ELF/arm-exidx-canunwind.s +++ b/test/ELF/arm-exidx-canunwind.s @@ -55,26 +55,26 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: _start: -// CHECK-NEXT: 11000: bl #4 -// CHECK-NEXT: 11004: bl #4 -// CHECK-NEXT: 11008: bx lr +// CHECK-NEXT: 11108: bl #4 +// CHECK-NEXT: bl #4 +// CHECK-NEXT: bx lr // CHECK: func1: -// CHECK-NEXT: 1100c: bx lr +// CHECK-NEXT: 11114: bx lr // CHECK: func2: -// CHECK-NEXT: 11010: bx lr +// CHECK-NEXT: 11118: bx lr // CHECK: __gxx_personality_v0: -// CHECK-NEXT: 11014: bx lr +// CHECK-NEXT: 1111c: bx lr // CHECK: __aeabi_unwind_cpp_pr0: -// CHECK-NEXT: 11018: bx lr +// CHECK-NEXT: 11120: bx lr -// 100d4 + f2c = 11000 = main (linker generated cantunwind) -// 100dc + f30 = 1100c = func1 (inline unwinding data) -// CHECK-EXIDX: 100d4 2c0f0000 01000000 300f0000 08849780 -// 100e4 + f2c = 11010 = func2 (100e8 + 14 = 100fc = .ARM.extab entry) -// 100ec + f28 = 11014 = __gcc_personality_v0 (linker generated cantunwind) -// CHECK-EXIDX-NEXT: 100e4 2c0f0000 14000000 280f0000 01000000 -// 100f4 + f28 = 1101c = sentinel -// CHECK-EXIDX-NEXT: 100f4 280f0000 01000000 +// 100d4 + 0x1034 = 0x11108 = main (linker generated cantunwind) +// 100dc + 0x1038 = 0x11114 = func1 (inline unwinding data) +// CHECK-EXIDX: 100d4 34100000 01000000 38100000 08849780 +// 100e4 + 0x1034 = 0x11118 = func2 (100e8 + 14 = 100fc = .ARM.extab entry) +// 100ec + 0x1030 = 0x1111c = __gxx_personality_v0 (linker generated cantunwind) +// CHECK-EXIDX-NEXT: 100e4 34100000 14000000 30100000 01000000 +// 100f4 + 0x1030 = 1101c = sentinel +// CHECK-EXIDX-NEXT: 100f4 30100000 01000000 // CHECK-PT: Name: .ARM.exidx // CHECK-PT-NEXT: Type: SHT_ARM_EXIDX (0x70000001) diff --git a/test/ELF/arm-exidx-dedup.s b/test/ELF/arm-exidx-dedup.s index d91641886..b0ad82e5e 100644 --- a/test/ELF/arm-exidx-dedup.s +++ b/test/ELF/arm-exidx-dedup.s @@ -11,19 +11,19 @@ // With duplicate entries // CHECK-DUPS: Contents of section .ARM.exidx: -// CHECK-DUPS-NEXT: 100d4 2c0f0000 01000000 280f0000 01000000 -// CHECK-DUPS-NEXT: 100e4 240f0000 01000000 200f0000 01000000 -// CHECK-DUPS-NEXT: 100f4 1c0f0000 08849780 180f0000 08849780 -// CHECK-DUPS-NEXT: 10104 140f0000 08849780 100f0000 24000000 -// CHECK-DUPS-NEXT: 10114 0c0f0000 28000000 080f0000 01000000 -// CHECK-DUPS-NEXT: 10124 040f0000 01000000 000f0000 01000000 +// CHECK-DUPS-NEXT: 100d4 78100000 01000000 74100000 01000000 +// CHECK-DUPS-NEXT: 100e4 70100000 01000000 6c100000 01000000 +// CHECK-DUPS-NEXT: 100f4 68100000 08849780 64100000 08849780 +// CHECK-DUPS-NEXT: 10104 60100000 08849780 5c100000 24000000 +// CHECK-DUPS-NEXT: 10114 58100000 28000000 54100000 01000000 +// CHECK-DUPS-NEXT: 10124 50100000 01000000 4c100000 01000000 // CHECK-DUPS-NEXT: Contents of section .ARM.extab: // After duplicate entry removal // CHECK: Contents of section .ARM.exidx: -// CHECK-NEXT: 100d4 2c0f0000 01000000 340f0000 08849780 -// CHECK-NEXT: 100e4 380f0000 1c000000 340f0000 20000000 -// CHECK-NEXT: 100f4 300f0000 01000000 300f0000 01000000 +// CHECK-NEXT: 100d4 48100000 01000000 50100000 08849780 +// CHECK-NEXT: 100e4 54100000 1c000000 50100000 20000000 +// CHECK-NEXT: 100f4 4c100000 01000000 4c100000 01000000 // CHECK-NEXT: Contents of section .ARM.extab: .syntax unified diff --git a/test/ELF/arm-exidx-emit-relocs.s b/test/ELF/arm-exidx-emit-relocs.s index e7dff5bbd..8df501788 100644 --- a/test/ELF/arm-exidx-emit-relocs.s +++ b/test/ELF/arm-exidx-emit-relocs.s @@ -64,8 +64,8 @@ __aeabi_unwind_cpp_pr0: bx lr // CHECK: Contents of section .ARM.exidx: -// CHECK-NEXT: 100d4 2c0f0000 08849780 2c0f0000 01000000 -// CHECK-NEXT: 100e4 2c0f0000 08849780 280f0000 01000000 -// CHECK-NEXT: 100f4 240f0000 01000000 +// CHECK-NEXT: 100d4 28100000 08849780 28100000 01000000 +// CHECK-NEXT: 100e4 28100000 08849780 24100000 01000000 +// CHECK-NEXT: 100f4 20100000 01000000 // CHECK-RELOCS-NOT: Relocation section '.rel.ARM.exidx' diff --git a/test/ELF/arm-exidx-gc.s b/test/ELF/arm-exidx-gc.s index 88a068d29..2e0d969e2 100644 --- a/test/ELF/arm-exidx-gc.s +++ b/test/ELF/arm-exidx-gc.s @@ -93,17 +93,17 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: _start: -// CHECK-NEXT: 11000: bl #4 -// CHECK-NEXT: 11004: bl #4 -// CHECK-NEXT: 11008: bx lr +// CHECK-NEXT: 1110c: bl #4 +// CHECK-NEXT: 11110: bl #4 +// CHECK-NEXT: 11114: bx lr // CHECK: func1: -// CHECK-NEXT: 1100c: bx lr +// CHECK-NEXT: 11118: bx lr // CHECK: func2: -// CHECK-NEXT: 11010: bx lr +// CHECK-NEXT: 1111c: bx lr // CHECK: __gxx_personality_v0: -// CHECK-NEXT: 11014: bx lr +// CHECK-NEXT: 11120: bx lr // CHECK: __aeabi_unwind_cpp_pr0: -// CHECK-NEXT: 11018: bx lr +// CHECK-NEXT: 11124: bx lr // GC should have removed table entries for unusedfunc1, unusedfunc2 // and __gxx_personality_v1 @@ -112,15 +112,15 @@ _start: // CHECK-NOT: __gxx_personality_v1 // CHECK-EXIDX: Contents of section .ARM.exidx: -// 100d4 + f2c = 11000 -// 100dc + f30 = 1100c = func1 -// CHECK-EXIDX-NEXT: 100d4 2c0f0000 01000000 300f0000 08849780 -// 100e4 + f2c = 11010 = func2 (100e8 + 1c = 10104 = .ARM.extab) -// 100ec + f28 = 11014 = __gxx_personality_v0 -// CHECK-EXIDX-NEXT: 100e4 2c0f0000 1c000000 280f0000 01000000 -// 100f4 + f24 = 11018 = __aeabi_unwind_cpp_pr0 -// 100fc + f20 = 1101c = __aeabi_unwind_cpp_pr0 + sizeof(__aeabi_unwind_cpp_pr0) -// CHECK-EXIDX-NEXT: 100f4 240f0000 01000000 200f0000 01000000 +// 100d4 + 1038 = 1110c = _start +// 100dc + 103c = 11118 = func1 +// CHECK-EXIDX-NEXT: 100d4 38100000 01000000 3c100000 08849780 +// 100e4 + 1038 = 1111c = func2 (100e8 + 1c = 10104 = .ARM.extab) +// 100ec + 1034 = 11120 = __gxx_personality_v0 +// CHECK-EXIDX-NEXT: 100e4 38100000 1c000000 34100000 01000000 +// 100f4 + 1030 = 11018 = __aeabi_unwind_cpp_pr0 +// 100fc + 102c = 1101c = __aeabi_unwind_cpp_pr0 + sizeof(__aeabi_unwind_cpp_pr0) +// CHECK-EXIDX-NEXT: 100f4 30100000 01000000 2c100000 01000000 // CHECK-EXIDX-NEXT: Contents of section .ARM.extab: -// 10104 + f10 = 11014 = __gxx_personality_v0 -// CHECK-EXIDX-NEXT: 10104 100f0000 b0b0b000 +// 10104 + 101c = 11120 = __gxx_personality_v0 +// CHECK-EXIDX-NEXT: 10104 1c100000 b0b0b000 diff --git a/test/ELF/arm-exidx-order.s b/test/ELF/arm-exidx-order.s index 69469d9bf..ba7551a78 100644 --- a/test/ELF/arm-exidx-order.s +++ b/test/ELF/arm-exidx-order.s @@ -56,29 +56,29 @@ f3: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK: _start: -// CHECK-NEXT: 11000: bx lr +// CHECK-NEXT: 11124: bx lr // CHECK: f1: -// CHECK-NEXT: 11004: bx lr +// CHECK-NEXT: 11128: bx lr // CHECK: f2: -// CHECK-NEXT: 11008: bx lr +// CHECK-NEXT: 1112c: bx lr // CHECK: f3: -// CHECK-NEXT: 1100c: bx lr +// CHECK-NEXT: 11130: bx lr // CHECK: func4: -// CHECK-NEXT: 11010: bx lr +// CHECK-NEXT: 11134: bx lr // CHECK: func5: -// CHECK-NEXT: 11014: bx lr +// CHECK-NEXT: 11138: bx lr // CHECK: Disassembly of section .func1: // CHECK-EMPTY: // CHECK-NEXT: func1: -// CHECK-NEXT: 11018: bx lr +// CHECK-NEXT: 1113c: bx lr // CHECK: Disassembly of section .func2: // CHECK-EMPTY: // CHECK-NEXT: func2: -// CHECK-NEXT: 1101c: bx lr +// CHECK-NEXT: 11140: bx lr // CHECK: Disassembly of section .func3: // CHECK-EMPTY: // CHECK-NEXT: func3: -// CHECK-NEXT: 11020: bx lr +// CHECK-NEXT: 11144: bx lr // Each .ARM.exidx section has two 4 byte fields // Field 1 is the 31-bit offset to the function. The top bit is used to @@ -88,20 +88,20 @@ f3: // We expect to see the entries in the same order as the functions // CHECK-EXIDX: Contents of section .ARM.exidx: -// 100d4 + f2c = 11000 = _start -// 100dc + f28 = 11004 = f1 -// CHECK-EXIDX-NEXT: 100d4 2c0f0000 01000000 280f0000 01000000 -// 100e4 + f24 = 11008 = f2 -// 100ec + f20 = 1100c = f3 -// CHECK-EXIDX-NEXT: 100e4 240f0000 01000000 200f0000 01000000 -// 100f4 + f1c = 11010 = func4 -// 100fc + f18 = 11014 = func5 -// CHECK-EXIDX-NEXT: 100f4 1c0f0000 01000000 180f0000 01000000 -// 10104 + f14 = 11018 = func1 -// 1010c + f10 = 1101c = func2 -// CHECK-EXIDX-NEXT: 10104 140f0000 01000000 100f0000 01000000 -// 10114 + f0c = 11020 = func3 -// CHECK-EXIDX-NEXT: 10114 0c0f0000 01000000 +// 100d4 + 1050 = 11124 = _start +// 100dc + 104c = 11128 = f1 +// CHECK-EXIDX-NEXT: 100d4 50100000 01000000 4c100000 01000000 +// 100e4 + 1048 = 1112c = f2 +// 100ec + 1044 = 11130 = f3 +// CHECK-EXIDX-NEXT: 100e4 48100000 01000000 44100000 01000000 +// 100f4 + 1040 = 11134 = func4 +// 100fc + 103c = 11138 = func5 +// CHECK-EXIDX-NEXT: 100f4 40100000 01000000 3c100000 01000000 +// 10104 + 1038 = 1113c = func1 +// 1010c + 1034 = 11140 = func2 +// CHECK-EXIDX-NEXT: 10104 38100000 01000000 34100000 01000000 +// 10114 + 1030 = 11144 = func3 +// CHECK-EXIDX-NEXT: 10114 30100000 01000000 // Check that PT_ARM_EXIDX program header has been generated that describes // the .ARM.exidx output section diff --git a/test/ELF/arm-exidx-partial-discard.s b/test/ELF/arm-exidx-partial-discard.s new file mode 100644 index 000000000..770a811c1 --- /dev/null +++ b/test/ELF/arm-exidx-partial-discard.s @@ -0,0 +1,37 @@ +// REQUIRES: arm +// RUN: llvm-mc -filetype=obj -triple arm-gnu-linux-eabi -mcpu cortex-a7 -arm-add-build-attributes %s -o %t.o +// RUN: echo "SECTIONS { . = 0x10000; .text : { *(.text) } /DISCARD/ : { *(.exit.text) } }" > %t.script +// RUN: ld.lld -T %t.script %t.o -o %t.elf +// RUN: llvm-readobj -x .ARM.exidx --sections %t.elf | FileCheck %s + +// CHECK-NOT: .exit.text +/// Expect 2 entries both CANTUNWIND as the .ARM.exidx.exit.text +// should have been removed. +// CHECK: Hex dump of section '.ARM.exidx': +// CHECK-NEXT: 0x00010000 10000000 01000000 10000000 01000000 + +/// The /DISCARD/ is evaluated after sections have been assigned to the +/// .ARM.exidx synthetic section. We must account for the /DISCARD/ + .section .exit.text, "ax", %progbits + .globl foo + .type foo, %function +foo: + .fnstart + bx lr + .save {r7, lr} + .setfp r7, sp, #0 + .fnend + + .text + .globl _start + .type _start, %function +_start: + .fnstart + bx lr + .cantunwind + .fnend + + .section .text.__aeabi_unwind_cpp_pr0, "ax", %progbits + .global __aeabi_unwind_cpp_pr0 +__aeabi_unwind_cpp_pr0: + bx lr diff --git a/test/ELF/arm-exidx-shared.s b/test/ELF/arm-exidx-shared.s index 40f3c9064..e5ad085cb 100644 --- a/test/ELF/arm-exidx-shared.s +++ b/test/ELF/arm-exidx-shared.s @@ -38,8 +38,8 @@ __aeabi_unwind_cpp_pr0: // CHECK: Relocations [ // CHECK-NEXT: Section {{.*}} .rel.plt { -// CHECK-NEXT: 0x300C R_ARM_JUMP_SLOT __gxx_personality_v0 +// CHECK-NEXT: 0x32DC R_ARM_JUMP_SLOT __gxx_personality_v0 // CHECK-EXTAB: Contents of section .ARM.extab: -// 0x0238 + 0xdf8 = 0x1030 = __gxx_personality_v0(PLT) -// CHECK-EXTAB-NEXT: 0238 f80d0000 b0b0b000 00000000 +// 0x0238 + 0x1038 = 0x1270 = __gxx_personality_v0(PLT) +// CHECK-EXTAB-NEXT: 0238 38100000 b0b0b000 00000000 diff --git a/test/ELF/arm-fpic-got.s b/test/ELF/arm-fpic-got.s index 81f14519b..179e011ea 100644 --- a/test/ELF/arm-fpic-got.s +++ b/test/ELF/arm-fpic-got.s @@ -3,7 +3,7 @@ // RUN: ld.lld %t.o -o %t // RUN: llvm-readobj -S %t | FileCheck %s // RUN: llvm-readobj -S --symbols %t | FileCheck -check-prefix=SYMBOLS %s -// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t | FileCheck -check-prefix=CODE %s +// RUN: llvm-objdump -d --no-show-raw-insn -triple=armv7a-none-linux-gnueabi %t | FileCheck -check-prefix=CODE %s // Test the R_ARM_GOT_PREL relocation .syntax unified @@ -36,7 +36,7 @@ val: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x12000 +// CHECK-NEXT: Address: 0x12128 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 4 // CHECK-NEXT: Link: @@ -45,7 +45,7 @@ val: // CHECK-NEXT: EntrySize: // SYMBOLS: Name: val -// SYMBOLS-NEXT: Value: 0x13000 +// SYMBOLS-NEXT: Value: 0x1312C // SYMBOLS-NEXT: Size: 4 // SYMBOLS-NEXT: Binding: Global // SYMBOLS-NEXT: Type: Object @@ -55,10 +55,10 @@ val: // CODE: Disassembly of section .text: // CODE-EMPTY: // CODE-NEXT: _start: -// CODE-NEXT: 11000: 08 00 9f e5 ldr r0, [pc, #8] -// CODE-NEXT: 11004: 00 00 9f e7 ldr r0, [pc, r0] -// CODE-NEXT: 11008: 00 00 90 e5 ldr r0, [r0] -// CODE-NEXT: 1100c: 1e ff 2f e1 bx lr +// CODE-NEXT: 11114: ldr r0, [pc, #8] +// CODE-NEXT: 11118: ldr r0, [pc, r0] +// CODE-NEXT: 1111c: ldr r0, [r0] +// CODE-NEXT: 11120: bx lr // CODE: $d.1: -// 0x11004 + 0x0ff4 + 8 = 0x12000 = .got -// CODE-NEXT: 11010: f4 0f 00 00 +// 0x11124 + 0x1008 + 8 = 0x12128 = .got +// CODE-NEXT: 11124: 08 10 00 00 diff --git a/test/ELF/arm-gnu-ifunc-plt.s b/test/ELF/arm-gnu-ifunc-plt.s index e252559e4..a8b3c9de6 100644 --- a/test/ELF/arm-gnu-ifunc-plt.s +++ b/test/ELF/arm-gnu-ifunc-plt.s @@ -1,84 +1,84 @@ // REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-linux-gnueabihf %S/Inputs/arm-shared.s -o %t1.o -// RUN: ld.lld %t1.o --shared -o %t.so +// RUN: ld.lld %t1.o --shared -soname=t.so -o %t.so // RUN: llvm-mc -filetype=obj -triple=armv7a-linux-gnueabihf %s -o %t.o -// RUN: ld.lld --hash-style=sysv %t.so %t.o -o %tout +// RUN: ld.lld %t.so %t.o -o %tout // RUN: llvm-objdump -triple=armv7a-linux-gnueabihf -d --no-show-raw-insn %tout | FileCheck %s --check-prefix=DISASM // RUN: llvm-objdump -s %tout | FileCheck %s --check-prefix=GOTPLT // RUN: llvm-readobj -r --dynamic-table %tout | FileCheck %s // Check that the IRELATIVE relocations are last in the .got // CHECK: Relocations [ -// CHECK-NEXT: Section (4) .rel.dyn { -// CHECK-NEXT: 0x12078 R_ARM_GLOB_DAT bar2 0x0 -// CHECK-NEXT: 0x1207C R_ARM_GLOB_DAT zed2 0x0 -// CHECK-NEXT: 0x12080 R_ARM_IRELATIVE - 0x0 -// CHECK-NEXT: 0x12084 R_ARM_IRELATIVE - 0x0 +// CHECK-NEXT: Section (5) .rel.dyn { +// CHECK-NEXT: 0x122E0 R_ARM_GLOB_DAT bar2 0x0 +// CHECK-NEXT: 0x122E4 R_ARM_GLOB_DAT zed2 0x0 +// CHECK-NEXT: 0x122E8 R_ARM_IRELATIVE - 0x0 +// CHECK-NEXT: 0x122EC R_ARM_IRELATIVE - 0x0 // CHECK-NEXT: } -// CHECK-NEXT: Section (5) .rel.plt { -// CHECK-NEXT: 0x1300C R_ARM_JUMP_SLOT bar2 0x0 -// CHECK-NEXT: 0x13010 R_ARM_JUMP_SLOT zed2 0x0 +// CHECK-NEXT: Section (6) .rel.plt { +// CHECK-NEXT: 0x132FC R_ARM_JUMP_SLOT bar2 0x0 +// CHECK-NEXT: 0x13300 R_ARM_JUMP_SLOT zed2 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] // Check that the GOT entries refer back to the ifunc resolver // GOTPLT: Contents of section .got: -// GOTPLT-NEXT: 12078 00000000 00000000 00100100 04100100 +// GOTPLT-NEXT: 122e0 00000000 00000000 dc110100 e0110100 // GOTPLT: Contents of section .got.plt: -// GOTPLT-NEXT: 13000 00000000 00000000 00000000 20100100 -// GOTPLT-NEXT: 13010 20100100 +// GOTPLT-NEXT: 132f0 00000000 00000000 00000000 00120100 +// GOTPLT-NEXT: 13300 00120100 // DISASM: Disassembly of section .text: // DISASM-EMPTY: // DISASM-NEXT: foo: -// DISASM-NEXT: 11000: bx lr +// DISASM-NEXT: 111dc: bx lr // DISASM: bar: -// DISASM-NEXT: 11004: bx lr +// DISASM-NEXT: 111e0: bx lr // DISASM: _start: -// DISASM-NEXT: 11008: bl #80 -// DISASM-NEXT: 1100c: bl #92 +// DISASM-NEXT: 111e4: bl #84 +// DISASM-NEXT: 111e8: bl #96 // DISASM: $d.1: -// DISASM-NEXT: 11010: 00 00 00 00 .word 0x00000000 -// DISASM-NEXT: 11014: 04 00 00 00 .word 0x00000004 -// DISASM: 11018: bl #32 -// DISASM-NEXT: 1101c: bl #44 +// DISASM-NEXT: 111ec: 00 00 00 00 .word 0x00000000 +// DISASM-NEXT: 111f0: 04 00 00 00 .word 0x00000004 +// DISASM: 111f4: bl #36 +// DISASM-NEXT: 111f8: bl #48 // DISASM-EMPTY: // DISASM-NEXT: Disassembly of section .plt: // DISASM-EMPTY: // DISASM-NEXT: $a: -// DISASM-NEXT: 11020: str lr, [sp, #-4]! -// DISASM-NEXT: 11024: add lr, pc, #0, #12 -// DISASM-NEXT: 11028: add lr, lr, #4096 -// DISASM-NEXT: 1102c: ldr pc, [lr, #4060]! +// DISASM-NEXT: 11200: str lr, [sp, #-4]! +// DISASM-NEXT: 11204: add lr, pc, #0, #12 +// DISASM-NEXT: 11208: add lr, lr, #8192 +// DISASM-NEXT: 1120c: ldr pc, [lr, #236]! // DISASM: $d: -// DISASM-NEXT: 11030: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DISASM-NEXT: 11034: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DISASM-NEXT: 11038: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DISASM-NEXT: 1103c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DISASM-NEXT: 11210: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DISASM-NEXT: 11214: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DISASM-NEXT: 11218: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DISASM-NEXT: 1121c: d4 d4 d4 d4 .word 0xd4d4d4d4 // DISASM: $a: -// DISASM-NEXT: 11040: add r12, pc, #0, #12 -// DISASM-NEXT: 11044: add r12, r12, #4096 -// DISASM-NEXT: 11048: ldr pc, [r12, #4036]! +// DISASM-NEXT: 11220: add r12, pc, #0, #12 +// DISASM-NEXT: 11224: add r12, r12, #8192 +// DISASM-NEXT: 11228: ldr pc, [r12, #212]! // DISASM: $d: -// DISASM-NEXT: 1104c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DISASM-NEXT: 1122c: d4 d4 d4 d4 .word 0xd4d4d4d4 // DISASM: $a: -// DISASM-NEXT: 11050: add r12, pc, #0, #12 -// DISASM-NEXT: 11054: add r12, r12, #4096 -// DISASM-NEXT: 11058: ldr pc, [r12, #4024]! +// DISASM-NEXT: 11230: add r12, pc, #0, #12 +// DISASM-NEXT: 11234: add r12, r12, #8192 +// DISASM-NEXT: 11238: ldr pc, [r12, #200]! // DISASM: $d: -// DISASM-NEXT: 1105c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DISASM-NEXT: 1123c: d4 d4 d4 d4 .word 0xd4d4d4d4 // DISASM: $a: -// DISASM-NEXT: 11060: add r12, pc, #0, #12 -// DISASM-NEXT: 11064: add r12, r12, #4096 -// DISASM-NEXT: 11068: ldr pc, [r12, #24]! +// DISASM-NEXT: 11240: add r12, pc, #0, #12 +// DISASM-NEXT: 11244: add r12, r12, #4096 +// DISASM-NEXT: 11248: ldr pc, [r12, #160]! // DISASM: $d: -// DISASM-NEXT: 1106c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DISASM-NEXT: 1124c: d4 d4 d4 d4 .word 0xd4d4d4d4 // DISASM: $a: -// DISASM-NEXT: 11070: add r12, pc, #0, #12 -// DISASM-NEXT: 11074: add r12, r12, #4096 -// DISASM-NEXT: 11078: ldr pc, [r12, #12]! +// DISASM-NEXT: 11250: add r12, pc, #0, #12 +// DISASM-NEXT: 11254: add r12, r12, #4096 +// DISASM-NEXT: 11258: ldr pc, [r12, #148]! // DISASM: $d: -// DISASM-NEXT: 1107c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DISASM-NEXT: 1125c: d4 d4 d4 d4 .word 0xd4d4d4d4 .syntax unified .text diff --git a/test/ELF/arm-gnu-ifunc.s b/test/ELF/arm-gnu-ifunc.s index 277c1676b..dff101f1d 100644 --- a/test/ELF/arm-gnu-ifunc.s +++ b/test/ELF/arm-gnu-ifunc.s @@ -43,8 +43,8 @@ _start: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_EXECINSTR // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x11020 -// CHECK-NEXT: Offset: 0x1020 +// CHECK-NEXT: Address: 0x11130 +// CHECK-NEXT: Offset: 0x130 // CHECK-NEXT: Size: 32 // CHECK: Index: 4 // CHECK-NEXT: Name: .got @@ -53,13 +53,13 @@ _start: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x12000 -// CHECK-NEXT: Offset: 0x2000 +// CHECK-NEXT: Address: 0x12150 +// CHECK-NEXT: Offset: 0x150 // CHECK-NEXT: Size: 8 // CHECK: Relocations [ // CHECK-NEXT: Section (1) .rel.dyn { -// CHECK-NEXT: 0x12000 R_ARM_IRELATIVE -// CHECK-NEXT: 0x12004 R_ARM_IRELATIVE +// CHECK-NEXT: 0x12150 R_ARM_IRELATIVE +// CHECK-NEXT: 0x12154 R_ARM_IRELATIVE // CHECK-NEXT: } // CHECK-NEXT: ] // CHECK: Symbol { @@ -86,7 +86,7 @@ _start: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x11008 +// CHECK-NEXT: Value: 0x1110C // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None @@ -95,7 +95,7 @@ _start: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: bar -// CHECK-NEXT: Value: 0x11004 +// CHECK-NEXT: Value: 0x11108 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: GNU_IFunc @@ -104,7 +104,7 @@ _start: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: foo -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: 0x11104 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: GNU_IFunc @@ -115,31 +115,31 @@ _start: // DISASM: Disassembly of section .text: // DISASM-EMPTY: // DISASM-NEXT: foo: -// DISASM-NEXT: 11000: bx lr +// DISASM-NEXT: 11104: bx lr // DISASM: bar: -// DISASM-NEXT: 11004: bx lr +// DISASM-NEXT: 11108: bx lr // DISASM: _start: -// DISASM-NEXT: 11008: bl #16 -// DISASM-NEXT: 1100c: bl #28 +// DISASM-NEXT: 1110c: bl #28 +// DISASM-NEXT: 11110: bl #40 // 1 * 65536 + 244 = 0x100f4 __rel_iplt_start -// DISASM-NEXT: 11010: movw r0, #244 -// DISASM-NEXT: 11014: movt r0, #1 +// DISASM-NEXT: 11114: movw r0, #244 +// DISASM-NEXT: 11118: movt r0, #1 // 1 * 65536 + 260 = 0x10104 __rel_iplt_end -// DISASM-NEXT: 11018: movw r0, #260 -// DISASM-NEXT: 1101c: movt r0, #1 +// DISASM-NEXT: 1111c: movw r0, #260 +// DISASM-NEXT: 11120: movt r0, #1 // DISASM-EMPTY: // DISASM-NEXT: Disassembly of section .plt: // DISASM-EMPTY: // DISASM-NEXT: $a: -// DISASM-NEXT: 11020: add r12, pc, #0, #12 -// DISASM-NEXT: 11024: add r12, r12, #0, #20 -// DISASM-NEXT: 11028: ldr pc, [r12, #4056]! +// DISASM-NEXT: 11130: add r12, pc, #0, #12 +// DISASM-NEXT: 11134: add r12, r12, #4096 +// DISASM-NEXT: 11138: ldr pc, [r12, #24]! // DISASM: $d: -// DISASM-NEXT: 1102c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DISASM-NEXT: 1113c: d4 d4 d4 d4 .word 0xd4d4d4d4 // DISASM: $a: -// DISASM-NEXT: 11030: add r12, pc, #0, #12 -// DISASM-NEXT: 11034: add r12, r12, #0, #20 -// DISASM-NEXT: 11038: ldr pc, [r12, #4044]! +// DISASM-NEXT: 11140: add r12, pc, #0, #12 +// DISASM-NEXT: 11144: add r12, r12, #4096 +// DISASM-NEXT: 11148: ldr pc, [r12, #12]! // DISASM: $d: -// DISASM-NEXT: 1103c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DISASM-NEXT: 1114c: d4 d4 d4 d4 .word 0xd4d4d4d4 diff --git a/test/ELF/arm-got-relative.s b/test/ELF/arm-got-relative.s index 89cad2732..4f86863dc 100644 --- a/test/ELF/arm-got-relative.s +++ b/test/ELF/arm-got-relative.s @@ -1,6 +1,6 @@ // REQUIRES: arm // RUN: llvm-mc -position-independent -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o -// RUN: ld.lld --hash-style=sysv %t.o -shared -o %t +// RUN: ld.lld %t.o -shared -o %t // RUN: llvm-readobj -S --symbols --dyn-relocations %t | FileCheck %s // RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t | FileCheck -check-prefix=CODE %s .syntax unified @@ -28,10 +28,10 @@ function: bx lr // CHECK: Dynamic Relocations { -// CHECK-NEXT: 0x2048 R_ARM_GLOB_DAT function 0x0 +// CHECK-NEXT: 0x220C R_ARM_GLOB_DAT function 0x0 // CHECK: Name: _GLOBAL_OFFSET_TABLE_ -// CHECK-NEXT: Value: 0x2048 +// CHECK-NEXT: Value: 0x220C // CHECK-NEXT: Size: // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -43,12 +43,12 @@ function: // CODE: Disassembly of section .text: // CODE-EMPTY: // CODE-NEXT: _start: -// CODE-NEXT: 1000: 08 30 9f e5 ldr r3, [pc, #8] -// CODE-NEXT: 1004: 08 20 9f e5 ldr r2, [pc, #8] -// CODE-NEXT: 1008: 03 00 8f e0 add r0, pc, r3 -// CODE-NEXT: 100c: 1e ff 2f e1 bx lr +// CODE-NEXT: 11a0: 08 30 9f e5 ldr r3, [pc, #8] +// CODE-NEXT: 11a4: 08 20 9f e5 ldr r2, [pc, #8] +// CODE-NEXT: 11a8: 03 00 8f e0 add r0, pc, r3 +// CODE-NEXT: 11ac: 1e ff 2f e1 bx lr // CODE:$d.1: -// (_GLOBAL_OFFSET_TABLE_ = 0x2048) - (0x1008 + 8) 0x1038 -// CODE-NEXT: 1010: 38 10 00 00 +// (_GLOBAL_OFFSET_TABLE_ = 0x220c) - (0x11a8 + 8) = 0x105c +// CODE-NEXT: 11b0: 5c 10 00 00 // (Got(function) - GotBase = 0x0 -// CODE-NEXT: 1014: 00 00 00 00 +// CODE-NEXT: 11b4: 00 00 00 00 diff --git a/test/ELF/arm-gotoff.s b/test/ELF/arm-gotoff.s index b1705c23e..cc53351bc 100644 --- a/test/ELF/arm-gotoff.s +++ b/test/ELF/arm-gotoff.s @@ -12,8 +12,8 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x12000 -// CHECK-NEXT: Offset: 0x2000 +// CHECK-NEXT: Address: 0x12124 +// CHECK-NEXT: Offset: 0x124 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Link: // CHECK-NEXT: Info: @@ -25,7 +25,7 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x12000 +// CHECK-NEXT: Address: 0x13124 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 20 // CHECK-NEXT: Link: @@ -36,7 +36,7 @@ // CHECK: Symbol { // CHECK: Name: bar -// CHECK-NEXT: Value: 0x12000 +// CHECK-NEXT: Value: 0x13124 // CHECK-NEXT: Size: 10 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -45,7 +45,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: obj -// CHECK-NEXT: Value: 0x1200A +// CHECK-NEXT: Value: 0x1312E // CHECK-NEXT: Size: 10 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -55,13 +55,13 @@ // DISASM: Disassembly of section .text: // DISASM-EMPTY: // DISASM-NEXT :_start: -// DISASM-NEXT 11000: 1e ff 2f e1 bx lr +// DISASM-NEXT 11114: 1e ff 2f e1 bx lr // Offset 0 from .got = bar -// DISASM 11004: 00 00 00 00 +// DISASM 11118: 00 10 00 00 // Offset 10 from .got = obj -// DISASM-NEXT 11008: 0a 00 00 00 +// DISASM-NEXT 1111c: 0a 10 00 00 // Offset 15 from .got = obj +5 -// DISASM-NEXT 1100c: 0f 00 00 00 +// DISASM-NEXT 11120: 0f 10 00 00 .syntax unified .globl _start _start: diff --git a/test/ELF/arm-icf-exidx.s b/test/ELF/arm-icf-exidx.s index 0de27a26b..6e89300f3 100644 --- a/test/ELF/arm-icf-exidx.s +++ b/test/ELF/arm-icf-exidx.s @@ -25,10 +25,10 @@ __aeabi_unwind_cpp_pr0: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: g: -// CHECK-NEXT: 11000: 1e ff 2f e1 bx lr +// CHECK-NEXT: 110ec: 1e ff 2f e1 bx lr // CHECK: __aeabi_unwind_cpp_pr0: -// CHECK-NEXT: 11004: 00 f0 20 e3 nop -// CHECK-NEXT: 11008: 1e ff 2f e1 bx lr +// CHECK-NEXT: 110f0: 00 f0 20 e3 nop +// CHECK-NEXT: 110f4: 1e ff 2f e1 bx lr // CHECK: Contents of section .ARM.exidx: -// CHECK-NEXT: 100d4 2c0f0000 b0b0b080 280f0000 01000000 +// CHECK-NEXT: 100d4 18100000 b0b0b080 14100000 01000000 diff --git a/test/ELF/arm-mov-relocs.s b/test/ELF/arm-mov-relocs.s index 030ea8196..c8dbe87c2 100644 --- a/test/ELF/arm-mov-relocs.s +++ b/test/ELF/arm-mov-relocs.s @@ -44,33 +44,33 @@ _start: movw r2, :lower16:label2 + 4 - . movw r3, :lower16:label3 - . movw r4, :lower16:label3 + 0x103c - . -// 0x20000 - 0x11028 = :lower16:0xefd8 (61400) -// CHECK: 11028: movw r0, #61400 -// 0x20004 = 0x1102c = :lower16:0xefd8 (61400) -// CHECK: 1102c: movw r1, #61400 -// 0x20008 - 0x11030 + 4 = :lower16:0xefdc (61404) -// CHECK: 11030: movw r2, #61404 -// 0x2fffc - 0x11034 = :lower16:0x1efc8 (61384) -// CHECK: 11034: movw r3, #61384 -// 0x2fffc - 0x11038 +0x103c :lower16:0x20000 (0) -// CHECK: 11038: movw r4, #0 +// 0x20000 - . = 61188 +// CHECK: 110fc: movw r0, #61188 +// 0x20004 - . = 61188 +// CHECK: 11100: movw r1, #61188 +// 0x20008 - . + 4 = 61192 +// CHECK: 11104: movw r2, #61192 +// 0x2fffc - . = 61172 +// CHECK: 11108: movw r3, #61172 +// 0x2fffc - . +0x103c = 65324 +// CHECK: 1110c: movw r4, #65324 .section .R_ARM_MOVT_PREL, "ax",%progbits movt r0, :upper16:label - . movt r1, :upper16:label1 - . movt r2, :upper16:label2 + 0x4 - . movt r3, :upper16:label3 - . - movt r4, :upper16:label3 + 0x1050 - . -// 0x20000 - 0x1103c = :upper16:0xefc4 = 0 -// CHECK: 1103c: movt r0, #0 -// 0x20004 - 0x11040 = :upper16:0xefc0 = 0 -// CHECK: 11040: movt r1, #0 -// 0x20008 - 0x11044 + 4 = :upper16:0xefc8 = 0 -// CHECK: 11044: movt r2, #0 -// 0x2fffc - 0x11048 = :upper16:0x1efb4 = 1 -// CHECK: 11048: movt r3, #1 -// 0x2fffc - 0x1104c + 0x1050 = :upper16:0x20000 = 2 -// CHECK: 1104c: movt r4, #2 + movt r4, :upper16:label3 + 0x1120 - . +// 0x20000 - . = :upper16:0xeef0 = 0 +// CHECK: 11110: movt r0, #0 +// 0x20004 - . = :upper16:0xeef0 = 0 +// CHECK: 11114: movt r1, #0 +// 0x20008 - . + 4 = :upper16:0xeef4 = 0 +// CHECK: 11118: movt r2, #0 +// 0x2fffc - . = :upper16:0x1eee0 = 1 +// CHECK: 1111c: movt r3, #1 +// 0x2fffc - . + 0x1120 = :upper16:0x20000 = 2 +// CHECK: 11120: movt r4, #1 .section .destination, "aw",%progbits .balign 65536 // 0x20000 diff --git a/test/ELF/arm-pie-relative.s b/test/ELF/arm-pie-relative.s index 55e495774..1767bc9df 100644 --- a/test/ELF/arm-pie-relative.s +++ b/test/ELF/arm-pie-relative.s @@ -1,8 +1,8 @@ // REQUIRES: arm -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t -// RUN: ld.lld --hash-style=sysv %t --pie -o %t2 -// RUN: llvm-readobj -r %t2 | FileCheck %s -// RUN: llvm-objdump -s %t2 | FileCheck %s --check-prefix=GOT +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o +// RUN: ld.lld %t.o --pie -o %t +// RUN: llvm-readobj -r %t | FileCheck %s +// RUN: llvm-readelf -x .got %t | FileCheck %s --check-prefix=GOT // Test that a R_ARM_GOT_BREL relocation with PIE results in a R_ARM_RELATIVE // dynamic relocation @@ -18,8 +18,8 @@ sym: .word 0 // CHECK: Relocations [ -// CHECK-NEXT: Section (4) .rel.dyn { -// CHECK-NEXT: 0x2058 R_ARM_RELATIVE +// CHECK-NEXT: Section (5) .rel.dyn { +// CHECK-NEXT: 0x21DC R_ARM_RELATIVE -// GOT: Contents of section .got: -// GOT-NEXT: 2058 00300000 +// GOT: section '.got': +// GOT-NEXT: 0x000021dc e0310000 diff --git a/test/ELF/arm-plt-reloc.s b/test/ELF/arm-plt-reloc.s index 9c244a873..a2e276290 100644 --- a/test/ELF/arm-plt-reloc.s +++ b/test/ELF/arm-plt-reloc.s @@ -3,7 +3,7 @@ // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t2 // RUN: ld.lld %t1 %t2 -o %t // RUN: llvm-objdump -triple=armv7a-none-linux-gnueabi -d --no-show-raw-insn %t | FileCheck %s -// RUN: ld.lld --hash-style=sysv -shared %t1 %t2 -o %t3 +// RUN: ld.lld -shared %t1 %t2 -o %t3 // RUN: llvm-objdump -triple=armv7a-none-linux-gnueabi -d --no-show-raw-insn %t3 | FileCheck -check-prefix=DSO %s // RUN: llvm-readobj -S -r %t3 | FileCheck -check-prefix=DSOREL %s // @@ -22,68 +22,68 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: func1: -// CHECK-NEXT: 11000: bx lr +// CHECK-NEXT: 110b4: bx lr // CHECK: func2: -// CHECK-NEXT: 11004: bx lr +// CHECK-NEXT: 110b8: bx lr // CHECK: func3: -// CHECK-NEXT: 11008: bx lr +// CHECK-NEXT: 110bc: bx lr // CHECK: _start: -// CHECK-NEXT: 1100c: b #-20 -// CHECK-NEXT: 11010: bl #-20 -// CHECK-NEXT: 11014: beq #-20 +// CHECK-NEXT: 110c0: b #-20 +// CHECK-NEXT: 110c4: bl #-20 +// CHECK-NEXT: 110c8: beq #-20 // Expect PLT entries as symbols can be preempted // The .got.plt and .plt displacement is small so we can use small PLT entries. // DSO: Disassembly of section .text: // DSO-EMPTY: // DSO-NEXT: func1: -// DSO-NEXT: 1000: bx lr +// DSO-NEXT: 1214: bx lr // DSO: func2: -// DSO-NEXT: 1004: bx lr +// DSO-NEXT: 1218: bx lr // DSO: func3: -// DSO-NEXT: 1008: bx lr +// DSO-NEXT: 121c: bx lr // DSO: _start: -// S(0x1040) - P(0x100c) + A(-8) = 0x2c = 32 -// DSO-NEXT: 100c: b #44 -// S(0x1050) - P(0x1010) + A(-8) = 0x38 = 56 -// DSO-NEXT: 1010: bl #56 -// S(0x10160) - P(0x1014) + A(-8) = 0x44 = 68 -// DSO-NEXT: 1014: beq #68 +// S(0x1214) - P(0x1220) + A(-8) = 0x2c = 32 +// DSO-NEXT: 1220: b #40 +// S(0x1218) - P(0x1224) + A(-8) = 0x38 = 56 +// DSO-NEXT: 1224: bl #52 +// S(0x121c) - P(0x1228) + A(-8) = 0x44 = 68 +// DSO-NEXT: 1228: beq #64 // DSO-EMPTY: // DSO-NEXT: Disassembly of section .plt: // DSO-EMPTY: // DSO-NEXT: $a: -// DSO-NEXT: 1020: str lr, [sp, #-4]! -// (0x1024 + 8) + (0 RoR 12) + 4096 + (0xfdc) = 0x3008 = .got.plt[3] -// DSO-NEXT: 1024: add lr, pc, #0, #12 -// DSO-NEXT: 1028: add lr, lr, #4096 -// DSO-NEXT: 102c: ldr pc, [lr, #4060]! +// DSO-NEXT: 1230: str lr, [sp, #-4]! +// (0x1234 + 8) + (0 RoR 12) + 8192 + 164 = 0x32e0 = .got.plt[2] +// DSO-NEXT: 1234: add lr, pc, #0, #12 +// DSO-NEXT: 1238: add lr, lr, #8192 +// DSO-NEXT: 123c: ldr pc, [lr, #164]! // DSO: $d: -// DSO-NEXT: 1030: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DSO-NEXT: 1034: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DSO-NEXT: 1038: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DSO-NEXT: 103c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 1240: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 1244: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 1248: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 124c: d4 d4 d4 d4 .word 0xd4d4d4d4 // DSO: $a: -// (0x1040 + 8) + (0 RoR 12) + 4096 + (0xfc4) = 0x300c -// DSO-NEXT: 1040: add r12, pc, #0, #12 -// DSO-NEXT: 1044: add r12, r12, #4096 -// DSO-NEXT: 1048: ldr pc, [r12, #4036]! +// (0x1250 + 8) + (0 RoR 12) + 8192 + 140 = 0x32e4 +// DSO-NEXT: 1250: add r12, pc, #0, #12 +// DSO-NEXT: 1254: add r12, r12, #8192 +// DSO-NEXT: 1258: ldr pc, [r12, #140]! // DSO: $d: -// DSO-NEXT: 104c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 125c: d4 d4 d4 d4 .word 0xd4d4d4d4 // DSO: $a: -// (0x1050 + 8) + (0 RoR 12) + 4096 + (0xfb8) = 0x3010 -// DSO-NEXT: 1050: add r12, pc, #0, #12 -// DSO-NEXT: 1054: add r12, r12, #4096 -// DSO-NEXT: 1058: ldr pc, [r12, #4024]! +// (0x1260 + 8) + (0 RoR 12) + 8192 + 128 = 0x32e8 +// DSO-NEXT: 1260: add r12, pc, #0, #12 +// DSO-NEXT: 1264: add r12, r12, #8192 +// DSO-NEXT: 1268: ldr pc, [r12, #128]! // DSO: $d: -// DSO-NEXT: 105c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 126c: d4 d4 d4 d4 .word 0xd4d4d4d4 // DSO: $a: -// (0x1060 + 8) + (0 RoR 12) + 4096 + (0xfac) = 0x3014 -// DSO-NEXT: 1060: add r12, pc, #0, #12 -// DSO-NEXT: 1064: add r12, r12, #4096 -// DSO-NEXT: 1068: ldr pc, [r12, #4012]! +// (0x1270 + 8) + (0 RoR 12) + 8192 + 116 = 0x32ec +// DSO-NEXT: 1270: add r12, pc, #0, #12 +// DSO-NEXT: 1274: add r12, r12, #8192 +// DSO-NEXT: 1278: ldr pc, [r12, #116]! // DSO: $d: -// DSO-NEXT: 106c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 127c: d4 d4 d4 d4 .word 0xd4d4d4d4 // DSOREL: Name: .got.plt @@ -92,7 +92,7 @@ _start: // DSOREL-NEXT: SHF_ALLOC // DSOREL-NEXT: SHF_WRITE // DSOREL-NEXT: ] -// DSOREL-NEXT: Address: 0x3000 +// DSOREL-NEXT: Address: 0x32D8 // DSOREL-NEXT: Offset: // DSOREL-NEXT: Size: 24 // DSOREL-NEXT: Link: @@ -101,9 +101,9 @@ _start: // DSOREL-NEXT: EntrySize: // DSOREL: Relocations [ // DSOREL-NEXT: Section {{.*}} .rel.plt { -// DSOREL-NEXT: 0x300C R_ARM_JUMP_SLOT func1 0x0 -// DSOREL-NEXT: 0x3010 R_ARM_JUMP_SLOT func2 0x0 -// DSOREL-NEXT: 0x3014 R_ARM_JUMP_SLOT func3 0x0 +// DSOREL-NEXT: 0x32E4 R_ARM_JUMP_SLOT func1 0x0 +// DSOREL-NEXT: 0x32E8 R_ARM_JUMP_SLOT func2 0x0 +// DSOREL-NEXT: 0x32EC R_ARM_JUMP_SLOT func3 0x0 // Test a large separation between the .plt and .got.plt // The .got.plt and .plt displacement is large but still within the range diff --git a/test/ELF/arm-reloc-abs32.s b/test/ELF/arm-reloc-abs32.s index 5805c3dbc..74676ca3c 100644 --- a/test/ELF/arm-reloc-abs32.s +++ b/test/ELF/arm-reloc-abs32.s @@ -13,10 +13,10 @@ _start: // S + A = 0x124 // CHECK: Disassembly of section .R_ARM_ABS32POS: // CHECK-EMPTY: -// CHECK: 11000: 24 01 00 00 +// CHECK: 24 01 00 00 .section .R_ARM_ABS32NEG, "ax",%progbits .word foo - 0x24 // S = 0x100, A = -0x24 // CHECK: Disassembly of section .R_ARM_ABS32NEG: // CHECK-EMPTY: -// CHECK: 11004: dc 00 00 00 +// CHECK: dc 00 00 00 diff --git a/test/ELF/arm-sbrel32.s b/test/ELF/arm-sbrel32.s index 3a5ba9221..12d6e9981 100644 --- a/test/ELF/arm-sbrel32.s +++ b/test/ELF/arm-sbrel32.s @@ -33,8 +33,8 @@ foo4: .space 4 // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: _start: -// CHECK-NEXT: 11000: 1e ff 2f e1 bx lr -// CHECK: 11004: 00 00 00 00 .word 0x00000000 -// CHECK-NEXT: 11008: 04 00 00 00 .word 0x00000004 -// CHECK-NEXT: 1100c: 08 00 00 00 .word 0x00000008 -// CHECK-NEXT: 11010: 0c 00 00 00 .word 0x0000000c +// CHECK-NEXT: 110d4: 1e ff 2f e1 bx lr +// CHECK: 110d8: 00 00 00 00 .word 0x00000000 +// CHECK-NEXT: 110dc: 04 00 00 00 .word 0x00000004 +// CHECK-NEXT: 110e0: 08 00 00 00 .word 0x00000008 +// CHECK-NEXT: 110e4: 0c 00 00 00 .word 0x0000000c diff --git a/test/ELF/arm-target1.s b/test/ELF/arm-target1.s index 604878aab..46a4f0b6c 100644 --- a/test/ELF/arm-target1.s +++ b/test/ELF/arm-target1.s @@ -28,9 +28,9 @@ // RELATIVE: Disassembly of section .text: // RELATIVE-EMPTY: // RELATIVE: $d.0: -// RELATIVE: 1000: 04 00 00 00 .word 0x00000004 +// RELATIVE: 1150: 04 00 00 00 .word 0x00000004 // RELATIVE: SYMBOL TABLE: -// RELATIVE: 00001004 .text 00000000 patatino +// RELATIVE: 00001154 .text 00000000 patatino // ABS: can't create dynamic relocation R_ARM_TARGET1 against symbol: patatino in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output // ABS: >>> defined in {{.*}}.o diff --git a/test/ELF/arm-target2.s b/test/ELF/arm-target2.s index 304638cd4..15e6c045a 100644 --- a/test/ELF/arm-target2.s +++ b/test/ELF/arm-target2.s @@ -35,16 +35,16 @@ __gxx_personality_v0: _ZTIi: .word 0 // CHECK: Contents of section .ARM.extab: -// 0x1012c + 0x1ed4 = 0x12000 = .got -// CHECK-NEXT: 10124 e00e0000 b0b0b000 d41e0000 +// 0x1012c + 0x2010 = 0x1213c = .got +// CHECK-NEXT: 10124 14100000 b0b0b000 10200000 // CHECK-ABS: Contents of section .ARM.extab: // 0x100f0 = .rodata -// CHECK-ABS-NEXT: 100e4 200f0000 b0b0b000 f0000100 +// CHECK-ABS-NEXT: 100e4 14100000 b0b0b000 f0000100 // CHECK-REL: Contents of section .ARM.extab: // 0x100ec + 4 = 0x100f0 = .rodata -// CHECK-REL-NEXT: 100e4 200f0000 b0b0b000 04000000 +// CHECK-REL-NEXT: 100e4 14100000 b0b0b000 04000000 // CHECK: Contents of section .rodata: // CHECK-NEXT: 10130 00000000 @@ -57,4 +57,4 @@ _ZTIi: .word 0 // CHECK: Contents of section .got: // 10130 = _ZTIi -// CHECK-NEXT: 12000 30010100 +// CHECK-NEXT: 1213c 30010100 diff --git a/test/ELF/arm-thumb-blx.s b/test/ELF/arm-thumb-blx.s index 113cf70af..9398ea445 100644 --- a/test/ELF/arm-thumb-blx.s +++ b/test/ELF/arm-thumb-blx.s @@ -8,8 +8,7 @@ // RUN: .R_ARM_CALL24_callee3 : { *(.R_ARM_CALL24_callee_high) } \ // RUN: .R_ARM_CALL24_callee4 : { *(.R_ARM_CALL24_callee_thumb_high) } } " > %t.script // RUN: ld.lld --script %t.script %t %ttarget -o %t2 -// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-THUMB %s -// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-ARM %s +// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t2 | FileCheck %s // Test BLX instruction is chosen for Thumb BL/BLX instruction and ARM callee // 2 byte nops are used to test the pc-rounding behaviour. As a BLX from a // 2 byte aligned destination is defined as Align(PC,4) + immediate:00 @@ -40,19 +39,19 @@ _start: blx callee_thumb_high bx lr -// CHECK-ARM: Disassembly of section .R_ARM_CALL24_callee1: -// CHECK-ARM-EMPTY: +// CHECK: Disassembly of section .R_ARM_CALL24_callee1: +// CHECK-EMPTY: // CHECK-NEXT-ARM: callee_low: // CHECK-NEXT-ARM: b4: 1e ff 2f e1 bx lr -// CHECK-THUMB: Disassembly of section .R_ARM_CALL24_callee2: -// CHECK-THUMB-EMPTY: +// CHECK: Disassembly of section .R_ARM_CALL24_callee2: +// CHECK-EMPTY: // CHECK-NEXT-THUMB: callee_thumb_low: // CHECK-NEXT-THUMB: 100: 70 47 bx lr -// CHECK-THUMB: Disassembly of section .caller: -// CHECK-THUMB-EMPTY: -// CHECK-THUMB: _start: +// CHECK: Disassembly of section .caller: +// CHECK-EMPTY: +// CHECK: _start: // Align(0x10000,4) - 0xff50 (65360) + 4 = 0xb4 = callee_low // CHECK-NEXT-THUMB: 10000: f0 f7 58 e8 blx #-65360 // CHECK-NEXT-THUMB: 10004: 00 bf nop @@ -79,8 +78,8 @@ _start: // CHECK-NEXT-THUMB: 1002e: 70 47 bx lr -// CHECK-ARM: Disassembly of section .R_ARM_CALL24_callee3: -// CHECK-ARM-EMPTY: +// CHECK: Disassembly of section .R_ARM_CALL24_callee3: +// CHECK-EMPTY: // CHECK-NEXT-ARM: callee_high: // CHECK-NEXT-ARM: 10100: 1e ff 2f e1 bx lr diff --git a/test/ELF/arm-thumb-interwork-shared.s b/test/ELF/arm-thumb-interwork-shared.s index 695afdaed..0b699bdc4 100644 --- a/test/ELF/arm-thumb-interwork-shared.s +++ b/test/ELF/arm-thumb-interwork-shared.s @@ -2,7 +2,6 @@ // RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t --shared -o %t.so // RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t.so | FileCheck %s -// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t.so | FileCheck %s -check-prefix=PLT .syntax unified .global sym1 .global elsewhere @@ -17,41 +16,40 @@ sym1: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: sym1: -// CHECK-NEXT: 1000: 00 f0 02 b8 b.w #4 <__ThumbV7PILongThunk_elsewhere> -// CHECK-NEXT: 1004: 00 f0 06 b8 b.w #12 <__ThumbV7PILongThunk_weakref> +// CHECK-NEXT: 11e0: 00 f0 02 b8 b.w #4 <__ThumbV7PILongThunk_elsewhere> +// CHECK-NEXT: 11e4: 00 f0 06 b8 b.w #12 <__ThumbV7PILongThunk_weakref> // CHECK: __ThumbV7PILongThunk_elsewhere: -// CHECK-NEXT: 1008: 40 f2 2c 0c movw r12, #44 -// CHECK-NEXT: 100c: c0 f2 00 0c movt r12, #0 -// CHECK-NEXT: 1010: fc 44 add r12, pc -// CHECK-NEXT: 1012: 60 47 bx r12 +// CHECK-NEXT: 11e8: 40 f2 2c 0c movw r12, #44 +// CHECK-NEXT: 11ec: c0 f2 00 0c movt r12, #0 +// CHECK-NEXT: 11f0: fc 44 add r12, pc +// CHECK-NEXT: 11f2: 60 47 bx r12 // CHECK: __ThumbV7PILongThunk_weakref: -// CHECK-NEXT: 1014: 40 f2 30 0c movw r12, #48 -// CHECK-NEXT: 1018: c0 f2 00 0c movt r12, #0 -// CHECK-NEXT: 101c: fc 44 add r12, pc -// CHECK-NEXT: 101e: 60 47 bx r12 - -// PLT: Disassembly of section .plt: -// PLT-EMPTY: -// PLT-NEXT: $a: -// PLT-NEXT: 1020: 04 e0 2d e5 str lr, [sp, #-4]! -// PLT-NEXT: 1024: 00 e6 8f e2 add lr, pc, #0, #12 -// PLT-NEXT: 1028: 01 ea 8e e2 add lr, lr, #4096 -// PLT-NEXT: 102c: dc ff be e5 ldr pc, [lr, #4060]! -// PLT: $d: -// PLT-NEXT: 1030: d4 d4 d4 d4 .word 0xd4d4d4d4 -// PLT-NEXT: 1034: d4 d4 d4 d4 .word 0xd4d4d4d4 -// PLT-NEXT: 1038: d4 d4 d4 d4 .word 0xd4d4d4d4 -// PLT-NEXT: 103c: d4 d4 d4 d4 .word 0xd4d4d4d4 -// PLT: $a: -// PLT-NEXT: 1040: 00 c6 8f e2 add r12, pc, #0, #12 -// PLT-NEXT: 1044: 01 ca 8c e2 add r12, r12, #4096 -// PLT-NEXT: 1048: c4 ff bc e5 ldr pc, [r12, #4036]! -// PLT: $d: -// PLT-NEXT: 104c: d4 d4 d4 d4 .word 0xd4d4d4d4 -// PLT: $a: -// PLT-NEXT: 1050: 00 c6 8f e2 add r12, pc, #0, #12 -// PLT-NEXT: 1054: 01 ca 8c e2 add r12, r12, #4096 -// PLT-NEXT: 1058: b8 ff bc e5 ldr pc, [r12, #4024]! -// PLT: $d: -// PLT-NEXT: 105c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK-NEXT: 11f4: 40 f2 30 0c movw r12, #48 +// CHECK-NEXT: 11f8: c0 f2 00 0c movt r12, #0 +// CHECK-NEXT: 11fc: fc 44 add r12, pc +// CHECK-NEXT: 11fe: 60 47 bx r12 +// CHECK: Disassembly of section .plt: +// CHECK-EMPTY: +// CHECK-NEXT: $a: +// CHECK-NEXT: 1200: 04 e0 2d e5 str lr, [sp, #-4]! +// CHECK-NEXT: 1204: 00 e6 8f e2 add lr, pc, #0, #12 +// CHECK-NEXT: 1208: 02 ea 8e e2 add lr, lr, #8192 +// CHECK-NEXT: 120c: 94 f0 be e5 ldr pc, [lr, #148]! +// CHECK: $d: +// CHECK-NEXT: 1210: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK-NEXT: 1214: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK-NEXT: 1218: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK-NEXT: 121c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK: $a: +// CHECK-NEXT: 1220: 00 c6 8f e2 add r12, pc, #0, #12 +// CHECK-NEXT: 1224: 02 ca 8c e2 add r12, r12, #8192 +// CHECK-NEXT: 1228: 7c f0 bc e5 ldr pc, [r12, #124]! +// CHECK: $d: +// CHECK-NEXT: 122c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK: $a: +// CHECK-NEXT: 1230: 00 c6 8f e2 add r12, pc, #0, #12 +// CHECK-NEXT: 1234: 02 ca 8c e2 add r12, r12, #8192 +// CHECK-NEXT: 1238: 70 f0 bc e5 ldr pc, [r12, #112]! +// CHECK: $d: +// CHECK-NEXT: 123c: d4 d4 d4 d4 .word 0xd4d4d4d4 diff --git a/test/ELF/arm-thumb-interwork-thunk-v5.s b/test/ELF/arm-thumb-interwork-thunk-v5.s index 90aa76e4a..cb7ab263a 100644 --- a/test/ELF/arm-thumb-interwork-thunk-v5.s +++ b/test/ELF/arm-thumb-interwork-thunk-v5.s @@ -1,11 +1,9 @@ // REQUIRES: arm // RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv5-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 -// RUN: llvm-objdump -d %t2 -triple=armv5-none-linux-gnueabi | FileCheck -check-prefix=CHECK-ARM %s -// RUN: llvm-objdump -d %t2 -triple=thumbv5-none-linux-gnueabi | FileCheck -check-prefix=CHECK-THUMB %s +// RUN: llvm-objdump -d %t2 -triple=armv5-none-linux-gnueabi | FileCheck %s // RUN: ld.lld %t -o %t3 --shared -// RUN: llvm-objdump -d %t3 -triple=armv5-none-linux-gnueabi | FileCheck -check-prefix=CHECK-ARM-PI %s -// RUN: llvm-objdump -d %t3 -triple=thumbv5-none-linux-gnueabi | FileCheck -check-prefix=CHECK-THUMB-PI %s +// RUN: llvm-objdump -d %t3 -triple=armv5-none-linux-gnueabi | FileCheck --check-prefix=CHECK-PI %s // Test ARM Thumb Interworking on older Arm architectures using Thunks that do // not use MOVT/MOVW instructions. @@ -28,35 +26,35 @@ _start: blx thumb_func bx lr -// CHECK-ARM: _start: -// CHECK-ARM-NEXT: 11000: 03 00 00 ea b #12 <__ARMv5ABSLongThunk_thumb_func> -// CHECK-ARM-NEXT: 11004: 01 00 00 fa blx #4 -// CHECK-ARM-NEXT: 11008: 00 00 00 fa blx #0 -// CHECK-ARM-NEXT: 1100c: 1e ff 2f e1 bx lr +// CHECK: _start: +// CHECK-NEXT: 12000: 03 00 00 ea b #12 <__ARMv5ABSLongThunk_thumb_func> +// CHECK-NEXT: 12004: 01 00 00 fa blx #4 +// CHECK-NEXT: 12008: 00 00 00 fa blx #0 +// CHECK-NEXT: 1200c: 1e ff 2f e1 bx lr -// CHECK-THUMB: thumb_func: -// CHECK-THUMB-NEXT: 11010: 70 47 bx lr +// CHECK: thumb_func: +// CHECK-NEXT: 12010: 70 47 bx lr -// CHECK-ARM: __ARMv5ABSLongThunk_thumb_func: -// CHECK-ARM-NEXT: 11014: 04 f0 1f e5 ldr pc, [pc, #-4] -// CHECK-ARM: $d: -// CHECK-ARM-NEXT: 11018: 11 10 01 00 .word 0x00011011 +// CHECK: __ARMv5ABSLongThunk_thumb_func: +// CHECK-NEXT: 12014: 04 f0 1f e5 ldr pc, [pc, #-4] +// CHECK: $d: +// CHECK-NEXT: 12018: 11 20 01 00 .word 0x00012011 -// CHECK-ARM-PI: _start: -// CHECK-ARM-PI-NEXT: 1000: 03 00 00 ea b #12 <__ARMV5PILongThunk_thumb_func> -// CHECK-ARM-PI-NEXT: 1004: 01 00 00 fa blx #4 -// CHECK-ARM-PI-NEXT: 1008: 00 00 00 fa blx #0 -// CHECK-ARM-PI-NEXT: 100c: 1e ff 2f e1 bx lr +// CHECK-PI: _start: +// CHECK-PI-NEXT: 2000: 03 00 00 ea b #12 <__ARMV5PILongThunk_thumb_func> +// CHECK-PI-NEXT: 2004: 01 00 00 fa blx #4 +// CHECK-PI-NEXT: 2008: 00 00 00 fa blx #0 +// CHECK-PI-NEXT: 200c: 1e ff 2f e1 bx lr -// CHECK-THUMB-PI: thumb_func: -// CHECK-THUMB-PI-NEXT: 1010: 70 47 bx lr +// CHECK-PI: thumb_func: +// CHECK-PI-NEXT: 2010: 70 47 bx lr -// CHECK-ARM-PI: __ARMV5PILongThunk_thumb_func: -// CHECK-ARM-PI-NEXT: 1014: 04 c0 9f e5 ldr r12, [pc, #4] -// CHECK-ARM-PI-NEXT: 1018: 0c c0 8f e0 add r12, pc, r12 -// CHECK-ARM-PI-NEXT: 101c: 1c ff 2f e1 bx r12 -// CHECK-ARM-PI: $d: -// CHECK-ARM-PI-NEXT: 1020: f1 ff ff ff .word 0xfffffff1 +// CHECK-PI: __ARMV5PILongThunk_thumb_func: +// CHECK-PI-NEXT: 2014: 04 c0 9f e5 ldr r12, [pc, #4] +// CHECK-PI-NEXT: 2018: 0c c0 8f e0 add r12, pc, r12 +// CHECK-PI-NEXT: 201c: 1c ff 2f e1 bx r12 +// CHECK-PI: $d: +// CHECK-PI-NEXT: 2020: f1 ff ff ff .word 0xfffffff1 .section .text.1, "ax", %progbits .thumb diff --git a/test/ELF/arm-thumb-no-undefined-thunk.s b/test/ELF/arm-thumb-no-undefined-thunk.s index e722b9c8c..7095093b8 100644 --- a/test/ELF/arm-thumb-no-undefined-thunk.s +++ b/test/ELF/arm-thumb-no-undefined-thunk.s @@ -19,7 +19,7 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: _start: -// 69636 = 0x11004 = next instruction -// CHECK: 11000: {{.*}} bl #0 -// CHECK-NEXT: 11004: {{.*}} b.w #0 <_start+0x8> -// CHECK-NEXT: 11008: {{.*}} b.w #0 <_start+0xc> +// 0x110b8 = next instruction +// CHECK: 110b4: {{.*}} bl #0 +// CHECK-NEXT: 110b8: {{.*}} b.w #0 <_start+0x8> +// CHECK-NEXT: 110bc: {{.*}} b.w #0 <_start+0xc> diff --git a/test/ELF/arm-thumb-plt-range-thunk-os.s b/test/ELF/arm-thumb-plt-range-thunk-os.s index 0b5eacb96..effbd9209 100644 --- a/test/ELF/arm-thumb-plt-range-thunk-os.s +++ b/test/ELF/arm-thumb-plt-range-thunk-os.s @@ -89,8 +89,8 @@ far_nonpreemptible_alias: // CHECK4-NEXT: $a: // CHECK4-NEXT: 4000010: 04 e0 2d e5 str lr, [sp, #-4]! // CHECK4-NEXT: 4000014: 00 e6 8f e2 add lr, pc, #0, #12 -// CHECK4-NEXT: 4000018: 01 ea 8e e2 add lr, lr, #4096 -// CHECK4-NEXT: 400001c: ec ff be e5 ldr pc, [lr, #4076]! +// CHECK4-NEXT: 4000018: 02 ea 8e e2 add lr, lr, #8192 +// CHECK4-NEXT: 400001c: a4 f0 be e5 ldr pc, [lr, #164]! // CHECK4: $d: // CHECK4-NEXT: 4000020: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK4-NEXT: 4000024: d4 d4 d4 d4 .word 0xd4d4d4d4 @@ -98,19 +98,19 @@ far_nonpreemptible_alias: // CHECK4-NEXT: 400002c: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK4: $a: // CHECK4-NEXT: 4000030: 00 c6 8f e2 add r12, pc, #0, #12 -// CHECK4-NEXT: 4000034: 01 ca 8c e2 add r12, r12, #4096 -// CHECK4-NEXT: 4000038: d4 ff bc e5 ldr pc, [r12, #4052]! +// CHECK4-NEXT: 4000034: 02 ca 8c e2 add r12, r12, #8192 +// CHECK4-NEXT: 4000038: 8c f0 bc e5 ldr pc, [r12, #140]! // CHECK4: $d: // CHECK4-NEXT: 400003c: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK4: $a: // CHECK4-NEXT: 4000040: 00 c6 8f e2 add r12, pc, #0, #12 -// CHECK4-NEXT: 4000044: 01 ca 8c e2 add r12, r12, #4096 -// CHECK4-NEXT: 4000048: c8 ff bc e5 ldr pc, [r12, #4040]! +// CHECK4-NEXT: 4000044: 02 ca 8c e2 add r12, r12, #8192 +// CHECK4-NEXT: 4000048: 80 f0 bc e5 ldr pc, [r12, #128]! // CHECK4: $d: // CHECK4-NEXT: 400004c: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK4: $a: // CHECK4-NEXT: 4000050: 00 c6 8f e2 add r12, pc, #0, #12 -// CHECK4-NEXT: 4000054: 01 ca 8c e2 add r12, r12, #4096 -// CHECK4-NEXT: 4000058: bc ff bc e5 ldr pc, [r12, #4028]! +// CHECK4-NEXT: 4000054: 02 ca 8c e2 add r12, r12, #8192 +// CHECK4-NEXT: 4000058: 74 f0 bc e5 ldr pc, [r12, #116]! // CHECK4: $d: // CHECK4-NEXT: 400005c: d4 d4 d4 d4 .word 0xd4d4d4d4 diff --git a/test/ELF/arm-thumb-plt-reloc.s b/test/ELF/arm-thumb-plt-reloc.s index 9980460bb..ca264698d 100644 --- a/test/ELF/arm-thumb-plt-reloc.s +++ b/test/ELF/arm-thumb-plt-reloc.s @@ -3,10 +3,9 @@ // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t2 // RUN: ld.lld %t1 %t2 -o %t // RUN: llvm-objdump -triple=thumbv7a-none-linux-gnueabi -d %t | FileCheck %s -// RUN: ld.lld --hash-style=sysv -shared %t1 %t2 -o %t3 -// RUN: llvm-objdump -triple=thumbv7a-none-linux-gnueabi -d %t3 | FileCheck -check-prefix=DSOTHUMB %s -// RUN: llvm-objdump -triple=armv7a-none-linux-gnueabi -d %t3 | FileCheck -check-prefix=DSOARM %s -// RUN: llvm-readobj -S -r %t3 | FileCheck -check-prefix=DSOREL %s +// RUN: ld.lld -shared %t1 %t2 -o %t.so +// RUN: llvm-objdump -triple=thumbv7a-none-linux-gnueabi -d %t.so | FileCheck -check-prefix=DSO %s +// RUN: llvm-readobj -S -r %t.so | FileCheck -check-prefix=DSOREL %s // // Test PLT entry generation .syntax unified @@ -26,74 +25,74 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: func1: -// CHECK-NEXT: 11000: 70 47 bx lr +// CHECK-NEXT: 110b4: 70 47 bx lr // CHECK: func2: -// CHECK-NEXT: 11002: 70 47 bx lr +// CHECK-NEXT: 110b6: 70 47 bx lr // CHECK: func3: -// CHECK-NEXT: 11004: 70 47 bx lr -// CHECK-NEXT: 11006: d4 d4 +// CHECK-NEXT: 110b8: 70 47 bx lr +// CHECK-NEXT: 110ba: d4 d4 // CHECK: _start: -// 11008 + 4 -12 = 0x11000 = func1 -// CHECK-NEXT: 11008: ff f7 fa ff bl #-12 -// 1100c + 4 -14 = 0x11002 = func2 -// CHECK-NEXT: 1100c: ff f7 f9 ff bl #-14 -// 11010 + 4 -16 = 0x11004 = func3 -// CHECK-NEXT: 11010: ff f7 f8 ff bl #-16 +// . + 4 -12 = 0x110b4 = func1 +// CHECK-NEXT: 110bc: ff f7 fa ff bl #-12 +// . + 4 -14 = 0x110b6 = func2 +// CHECK-NEXT: 110c0: ff f7 f9 ff bl #-14 +// . + 4 -16 = 0x110b8 = func3 +// CHECK-NEXT: 110c4: ff f7 f8 ff bl #-16 // Expect PLT entries as symbols can be preempted // .text is Thumb and .plt is ARM, llvm-objdump can currently only disassemble // as ARM or Thumb. Work around by disassembling twice. -// DSOTHUMB: Disassembly of section .text: -// DSOTHUMB-EMPTY: -// DSOTHUMB-NEXT: func1: -// DSOTHUMB-NEXT: 1000: 70 47 bx lr -// DSOTHUMB: func2: -// DSOTHUMB-NEXT: 1002: 70 47 bx lr -// DSOTHUMB: func3: -// DSOTHUMB-NEXT: 1004: 70 47 bx lr -// DSOTHUMB-NEXT: 1006: d4 d4 bmi #-88 -// DSOTHUMB: _start: -// 0x1008 + 0x34 + 4 = 0x1040 = PLT func1 -// DSOTHUMB-NEXT: 1008: 00 f0 1a e8 blx #52 -// 0x100c + 0x40 + 4 = 0x1050 = PLT func2 -// DSOTHUMB-NEXT: 100c: 00 f0 20 e8 blx #64 -// 0x1010 + 0x4C + 4 = 0x1060 = PLT func3 -// DSOTHUMB-NEXT: 1010: 00 f0 26 e8 blx #76 -// DSOARM: Disassembly of section .plt: -// DSOARM-EMPTY: -// DSOARM-NEXT: $a: -// DSOARM-NEXT: 1020: 04 e0 2d e5 str lr, [sp, #-4]! -// (0x1024 + 8) + (0 RoR 12) + 4096 + (0xfdc) = 0x3008 = .got.plt[3] -// DSOARM-NEXT: 1024: 00 e6 8f e2 add lr, pc, #0, #12 -// DSOARM-NEXT: 1028: 01 ea 8e e2 add lr, lr, #4096 -// DSOARM-NEXT: 102c: dc ff be e5 ldr pc, [lr, #4060]! -// DSOARM: $d: +// DSO: Disassembly of section .text: +// DSO-EMPTY: +// DSO-NEXT: func1: +// DSO-NEXT: 1214: 70 47 bx lr +// DSO: func2: +// DSO-NEXT: 1216: 70 47 bx lr +// DSO: func3: +// DSO-NEXT: 1218: 70 47 bx lr +// DSO-NEXT: 121a: d4 d4 bmi #-88 +// DSO: _start: +// . + 48 + 4 = 0x1250 = PLT func1 +// DSO-NEXT: 121c: 00 f0 18 e8 blx #48 +// . + 60 + 4 = 0x1260 = PLT func2 +// DSO-NEXT: 1220: 00 f0 1e e8 blx #60 +// . + 72 + 4 = 0x1270 = PLT func3 +// DSO-NEXT: 1224: 00 f0 24 e8 blx #72 +// DSO: Disassembly of section .plt: +// DSO-EMPTY: +// DSO-NEXT: $a: +// DSO-NEXT: 1230: 04 e0 2d e5 str lr, [sp, #-4]! +// (0x1234 + 8) + (0 RoR 12) + 8192 + 164 = 0x32e0 = .got.plt[3] +// DSO-NEXT: 1234: 00 e6 8f e2 add lr, pc, #0, #12 +// DSO-NEXT: 1238: 02 ea 8e e2 add lr, lr, #8192 +// DSO-NEXT: 123c: a4 f0 be e5 ldr pc, [lr, #164]! +// DSO: $d: -// DSOARM-NEXT: 1030: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DSOARM-NEXT: 1034: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DSOARM-NEXT: 1038: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DSOARM-NEXT: 103c: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DSOARM: $a: -// (0x1040 + 8) + (0 RoR 12) + 4096 + (0xfc4) = 0x300c -// DSOARM-NEXT: 1040: 00 c6 8f e2 add r12, pc, #0, #12 -// DSOARM-NEXT: 1044: 01 ca 8c e2 add r12, r12, #4096 -// DSOARM-NEXT: 1048: c4 ff bc e5 ldr pc, [r12, #4036]! -// DSOARM: $d: -// DSOARM-NEXT: 104c: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DSOARM: $a: -// (0x1050 + 8) + (0 RoR 12) + 4096 + (0xfb8) = 0x3010 -// DSOARM-NEXT: 1050: 00 c6 8f e2 add r12, pc, #0, #12 -// DSOARM-NEXT: 1054: 01 ca 8c e2 add r12, r12, #4096 -// DSOARM-NEXT: 1058: b8 ff bc e5 ldr pc, [r12, #4024]! -// DSOARM: $d: -// DSOARM-NEXT: 105c: d4 d4 d4 d4 .word 0xd4d4d4d4 -// DSOARM: $a: -// (0x1060 + 8) + (0 RoR 12) + 4096 + (0xfac) = 0x3014 -// DSOARM-NEXT: 1060: 00 c6 8f e2 add r12, pc, #0, #12 -// DSOARM-NEXT: 1064: 01 ca 8c e2 add r12, r12, #4096 -// DSOARM-NEXT: 1068: ac ff bc e5 ldr pc, [r12, #4012]! -// DSOARM: $d: -// DSOARM-NEXT: 106c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 1240: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 1244: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 1248: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO-NEXT: 124c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO: $a: +// (0x1250 + 8) + (0 RoR 12) + 8192 + 140 = 0x32e4 +// DSO-NEXT: 1250: 00 c6 8f e2 add r12, pc, #0, #12 +// DSO-NEXT: 1254: 02 ca 8c e2 add r12, r12, #8192 +// DSO-NEXT: 1258: 8c f0 bc e5 ldr pc, [r12, #140]! +// DSO: $d: +// DSO-NEXT: 125c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO: $a: +// (0x1260 + 8) + (0 RoR 12) + 8192 + 128 = 0x32e8 +// DSO-NEXT: 1260: 00 c6 8f e2 add r12, pc, #0, #12 +// DSO-NEXT: 1264: 02 ca 8c e2 add r12, r12, #8192 +// DSO-NEXT: 1268: 80 f0 bc e5 ldr pc, [r12, #128]! +// DSO: $d: +// DSO-NEXT: 126c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// DSO: $a: +// (0x1270 + 8) + (0 RoR 12) + 8192 + 116 = 0x32ec +// DSO-NEXT: 1270: 00 c6 8f e2 add r12, pc, #0, #12 +// DSO-NEXT: 1274: 02 ca 8c e2 add r12, r12, #8192 +// DSO-NEXT: 1278: 74 f0 bc e5 ldr pc, [r12, #116]! +// DSO: $d: +// DSO-NEXT: 127c: d4 d4 d4 d4 .word 0xd4d4d4d4 // DSOREL: Name: .got.plt // DSOREL-NEXT: Type: SHT_PROGBITS @@ -101,7 +100,7 @@ _start: // DSOREL-NEXT: SHF_ALLOC // DSOREL-NEXT: SHF_WRITE // DSOREL-NEXT: ] -// DSOREL-NEXT: Address: 0x3000 +// DSOREL-NEXT: Address: 0x32D8 // DSOREL-NEXT: Offset: // DSOREL-NEXT: Size: 24 // DSOREL-NEXT: Link: @@ -109,7 +108,7 @@ _start: // DSOREL-NEXT: AddressAlignment: 4 // DSOREL-NEXT: EntrySize: // DSOREL: Relocations [ -// DSOREL-NEXT: Section (4) .rel.plt { -// DSOREL-NEXT: 0x300C R_ARM_JUMP_SLOT func1 0x0 -// DSOREL-NEXT: 0x3010 R_ARM_JUMP_SLOT func2 0x0 -// DSOREL-NEXT: 0x3014 R_ARM_JUMP_SLOT func3 0x0 +// DSOREL-NEXT: Section (5) .rel.plt { +// DSOREL-NEXT: 0x32E4 R_ARM_JUMP_SLOT func1 0x0 +// DSOREL-NEXT: 0x32E8 R_ARM_JUMP_SLOT func2 0x0 +// DSOREL-NEXT: 0x32EC R_ARM_JUMP_SLOT func3 0x0 diff --git a/test/ELF/arm-thumb-thunk-empty-pass.s b/test/ELF/arm-thumb-thunk-empty-pass.s index d01ce3654..b38c6aee5 100644 --- a/test/ELF/arm-thumb-thunk-empty-pass.s +++ b/test/ELF/arm-thumb-thunk-empty-pass.s @@ -1,8 +1,7 @@ // REQUIRES: arm -// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t -// RUN: ld.lld %t -o %t2 -// RUN: llvm-objdump -d %t2 -start-address=69632 -stop-address=69646 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK1 %s -// RUN: llvm-objdump -d %t2 -start-address=16846856 -stop-address=16846874 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK2 %s +// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t.o +// RUN: ld.lld %t.o -o %t +// RUN: llvm-objdump -d %t -triple=thumbv7a | FileCheck %s .syntax unified .global _start, foo .type _start, %function @@ -16,16 +15,16 @@ _start: foo: bl _start -// CHECK1: Disassembly of section .text: -// CHECK1-EMPTY: -// CHECK1-NEXT: _start: -// CHECK1-NEXT: 11000: ff f7 fe ff bl #-4 -// CHECK1: __Thumbv7ABSLongThunk__start: -// CHECK1-NEXT: 11004: ff f7 fc bf b.w #-8 <_start> +// CHECK: Disassembly of section .text: +// CHECK-EMPTY: +// CHECK-NEXT: _start: +// CHECK-NEXT: 110b4: ff f7 fe ff bl #-4 +// CHECK: __Thumbv7ABSLongThunk__start: +// CHECK-NEXT: 110b8: ff f7 fc bf b.w #-8 <_start> -// CHECK2: __Thumbv7ABSLongThunk__start: -// CHECK2: 1011008: 41 f2 01 0c movw r12, #4097 -// CHECK2-NEXT: 101100c: c0 f2 01 0c movt r12, #1 -// CHECK2-NEXT: 1011010: 60 47 bx r12 -// CHECK2: foo: -// CHECK2-NEXT: 1011012: ff f7 f9 ff bl #-14 +// CHECK: __Thumbv7ABSLongThunk__start: +// CHECK: 10110bc: 41 f2 b5 0c movw r12, #4277 +// CHECK-NEXT: 10110c0: c0 f2 01 0c movt r12, #1 +// CHECK-NEXT: 10110c4: 60 47 bx r12 +// CHECK: foo: +// CHECK-NEXT: 10110c6: ff f7 f9 ff bl #-14 diff --git a/test/ELF/arm-thumb-thunk-symbols.s b/test/ELF/arm-thumb-thunk-symbols.s index a9c3ae875..976b3b2f3 100644 --- a/test/ELF/arm-thumb-thunk-symbols.s +++ b/test/ELF/arm-thumb-thunk-symbols.s @@ -25,18 +25,18 @@ arm_fn: b thumb_fn // CHECK: Name: __Thumbv7ABSLongThunk_arm_fn -// CHECK-NEXT: Value: 0x12005 +// CHECK-NEXT: Value: 0x13005 // CHECK-NEXT: Size: 10 // CHECK-NEXT: Binding: Local (0x0) // CHECK-NEXT: Type: Function (0x2) // CHECK: Name: __ARMv7ABSLongThunk_thumb_fn -// CHECK-NEXT: Value: 0x12010 +// CHECK-NEXT: Value: 0x13010 // CHECK-NEXT: Size: 12 // CHECK-NEXT: Binding: Local (0x0) // CHECK-NEXT: Type: Function (0x2) // CHECK-PI: Name: __ThumbV7PILongThunk_arm_fn -// CHECK-PI-NEXT: Value: 0x2005 +// CHECK-PI-NEXT: Value: 0x3005 // CHECK-PI-NEXT: Size: 12 // CHECK-PI-NEXT: Binding: Local (0x0) // CHECK-PI-NEXT: Type: Function (0x2) diff --git a/test/ELF/arm-thumb-undefined-weak-narrow.test b/test/ELF/arm-thumb-undefined-weak-narrow.test index 1fb3ca528..5fd09e9eb 100644 --- a/test/ELF/arm-thumb-undefined-weak-narrow.test +++ b/test/ELF/arm-thumb-undefined-weak-narrow.test @@ -6,7 +6,7 @@ # CHECK: Disassembly of section .text: # CHECK-EMPTY: # CHECK-NEXT:_start: -# CHECK-NEXT: 11000: ff e7 b #-2 +# CHECK-NEXT: ff e7 b #-2 # Test the R_ARM_THM_JUMP11 relocation (102) to an undefined weak reference # It should resolve to the next instruction, which is an offset of -2 which diff --git a/test/ELF/arm-thumb-undefined-weak.s b/test/ELF/arm-thumb-undefined-weak.s index 54c8757aa..b6812b8cc 100644 --- a/test/ELF/arm-thumb-undefined-weak.s +++ b/test/ELF/arm-thumb-undefined-weak.s @@ -29,11 +29,10 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: -// 69636 = 0x11004 -// CHECK: 11000: {{.*}} beq.w #0 <_start+0x4> -// CHECK-NEXT: 11004: {{.*}} b.w #0 <_start+0x8> -// CHECK-NEXT: 11008: {{.*}} bl #0 +// CHECK: 110b4: {{.*}} beq.w #0 <_start+0x4> +// CHECK-NEXT: 110b8: {{.*}} b.w #0 <_start+0x8> +// CHECK-NEXT: 110bc: {{.*}} bl #0 // blx is transformed into bl so we don't change state -// CHECK-NEXT: 1100c: {{.*}} bl #0 -// CHECK-NEXT: 11010: {{.*}} movt r0, #0 -// CHECK-NEXT: 11014: {{.*}} movw r0, #0 +// CHECK-NEXT: 110c0: {{.*}} bl #0 +// CHECK-NEXT: 110c4: {{.*}} movt r0, #0 +// CHECK-NEXT: 110c8: {{.*}} movw r0, #0 diff --git a/test/ELF/arm-thunk-largesection.s b/test/ELF/arm-thunk-largesection.s index 09aa7b683..9ddae477f 100644 --- a/test/ELF/arm-thunk-largesection.s +++ b/test/ELF/arm-thunk-largesection.s @@ -1,11 +1,11 @@ // REQUIRES: arm // RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 -// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi -start-address=69632 -stop-address=69636 %t2 | FileCheck -check-prefix=CHECK1 %s -// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi -start-address=73732 -stop-address=73742 %t2 | FileCheck -check-prefix=CHECK2 %s -// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi -start-address=16850936 -stop-address=16850940 %t2 | FileCheck -check-prefix=CHECK3 %s -// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi -start-address=33628152 -stop-address=33628156 %t2 | FileCheck -check-prefix=CHECK4 %s -// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi -start-address=50405356 -stop-address=50405376 %t2 | FileCheck -check-prefix=CHECK5 %s +// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi --start-address=0x12000 --stop-address=0x12006 %t2 | FileCheck -check-prefix=CHECK1 %s +// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi --start-address=0x13004 --stop-address=0x13008 %t2 | FileCheck -check-prefix=CHECK2 %s +// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi --start-address=0x1012ff8 --stop-address=0x1012ffc %t2 | FileCheck -check-prefix=CHECK3 %s +// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi --start-address=0x2012ff8 --stop-address=0x2012ffc %t2 | FileCheck -check-prefix=CHECK4 %s +// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi --start-address=0x3012fec --stop-address=0x3012ff6 %t2 | FileCheck -check-prefix=CHECK5 %s .syntax unified .balign 0x1000 .thumb @@ -18,14 +18,14 @@ _start: // CHECK1: Disassembly of section .text: // CHECK1-EMPTY: // CHECK1-NEXT:_start: -// CHECK1-NEXT: 11000: 70 47 bx lr +// CHECK1-NEXT: 12000: 70 47 bx lr // CHECK1-EMPTY: -// CHECK-NEXT:$d.1: -// CHECK-NEXT: 11002: 00 00 .short 0x0000 +// CHECK1-NEXT:$d.1: +// CHECK1-NEXT: 12002: 00 00 00 00 .word 0x00000000 // CHECK2: __Thumbv7ABSLongThunk__start: -// CHECK2-NEXT: 12004: fe f7 fc bf b.w #-4104 <_start> +// CHECK2-NEXT: 13004: fe f7 fc bf b.w #-4104 <_start> // Gigantic section where we need a ThunkSection either side of it .section .text.large1, "ax", %progbits @@ -35,10 +35,10 @@ _start: .space (16 * 1024 * 1024) - 4 bl _start .space (16 * 1024 * 1024) - 16 -// CHECK3: 1011ff8: 00 f4 04 d0 bl #-16777208 -// CHECK4: 2011ff8: ff f3 f8 d7 bl #16777200 +// CHECK3: 1012ff8: 00 f4 04 d0 bl #-16777208 +// CHECK4: 2012ff8: ff f3 f8 d7 bl #16777200 // CHECK5: __Thumbv7ABSLongThunk__start: -// CHECK5-NEXT: 3011fec: 41 f2 01 0c movw r12, #4097 -// CHECK5-NEXT: 3011ff0: c0 f2 01 0c movt r12, #1 -// CHECK5-NEXT: 3011ff4: 60 47 bx r12 +// CHECK5-NEXT: 3012fec: 42 f2 01 0c movw r12, #8193 +// CHECK5-NEXT: 3012ff0: c0 f2 01 0c movt r12, #1 +// CHECK5-NEXT: 3012ff4: 60 47 bx r12 diff --git a/test/ELF/arm-thunk-many-passes.s b/test/ELF/arm-thunk-many-passes.s new file mode 100644 index 000000000..f52efcd10 --- /dev/null +++ b/test/ELF/arm-thunk-many-passes.s @@ -0,0 +1,111 @@ +// REQUIRES: arm +// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv7a-linux-gnueabihf %s -o %t +// RUN: echo "SECTIONS { \ +// RUN: . = SIZEOF_HEADERS; \ +// RUN: .text 0x00011000 : { *(.text.*) } \ +// RUN: } \ +// RUN: sym = .;" > %t.script +// RUN: ld.lld --script %t.script %t -o %t2 +// RUN: llvm-readobj --sections --symbols %t2 | FileCheck --check-prefix=CHECK-ELF %s +// RUN: llvm-objdump --no-show-raw-insn --start-address=0x11000 --stop-address=0x1103c -d %t2 | FileCheck %s + +// An example of thunk generation that takes the maximum number of permitted +// passes to converge. We start with a set of branches of which all but one are +// in range. Any thunk added to extend the range of a branch is inserted in +// between the branches and the targets which knocks some more branches out +// of range. At the end of 9 passes of createThunks() every branch has a +// range extension thunk, allowing the final pass to check that no more thunks +// are required. +// +// As the size of the .text section changes 9 times, the symbol sym which +// depends on the size of .text will be updated 9 times. This test checks that +// any iteration limit to updating symbols does not limit thunk convergence. +// up to its pass limit without +// +// CHECK-ELF: Name: .text +// CHECK-ELF-NEXT: Type: SHT_PROGBITS +// CHECK-ELF-NEXT: Flags [ +// CHECK-ELF-NEXT: SHF_ALLOC +// CHECK-ELF-NEXT: SHF_EXECINSTR +// CHECK-ELF-NEXT: ] +// CHECK-ELF-NEXT: Address: 0x11000 +// CHECK-ELF-NEXT: Offset: 0x1000 +// CHECK-ELF-NEXT: Size: 16777292 +// CHECK-ELF: Name: sym +// CHECK-ELF-NEXT: Value: 0x101104C + +// CHECK: 00011000 _start: +// CHECK-NEXT: 11000: b.w #14680132 <__Thumbv7ABSLongThunk_f3> +// CHECK-NEXT: 11004: b.w #14680128 <__Thumbv7ABSLongThunk_f3> +// CHECK-NEXT: 11008: b.w #14680128 <__Thumbv7ABSLongThunk_f4> +// CHECK-NEXT: 1100c: b.w #14680124 <__Thumbv7ABSLongThunk_f4> +// CHECK-NEXT: 11010: b.w #14680124 <__Thumbv7ABSLongThunk_f5> +// CHECK-NEXT: 11014: b.w #14680120 <__Thumbv7ABSLongThunk_f5> +// CHECK-NEXT: 11018: b.w #14680120 <__Thumbv7ABSLongThunk_f6> +// CHECK-NEXT: 1101c: b.w #14680116 <__Thumbv7ABSLongThunk_f6> +// CHECK-NEXT: 11020: b.w #14680116 <__Thumbv7ABSLongThunk_f7> +// CHECK-NEXT: 11024: b.w #14680112 <__Thumbv7ABSLongThunk_f7> +// CHECK-NEXT: 11028: b.w #14680112 <__Thumbv7ABSLongThunk_f8> +// CHECK-NEXT: 1102c: b.w #14680108 <__Thumbv7ABSLongThunk_f8> +// CHECK-NEXT: 11030: b.w #14680108 <__Thumbv7ABSLongThunk_f9> +// CHECK-NEXT: 11034: b.w #14680104 <__Thumbv7ABSLongThunk_f9> +// CHECK-NEXT: 11038: b.w #14680104 <__Thumbv7ABSLongThunk_f10> + + + .thumb + .section .text.00, "ax", %progbits + .globl _start + .thumb_func +_start: b.w f2 + b.w f2 + b.w f3 + b.w f3 + b.w f4 + b.w f4 + b.w f5 + b.w f5 + b.w f6 + b.w f6 + b.w f7 + b.w f7 + b.w f8 + b.w f8 + b.w f9 + b.w f9 + b.w f10 + b.w f10 + + .section .text.01, "ax", %progbits + .space 14 * 1024 * 1024 +// Thunks are inserted here, initially only 1 branch is out of range and needs +// a thunk. However the added thunk is 4-bytes in size which makes another +// branch out of range, which adds another thunk ... + .section .text.02, "ax", %progbits + .space (2 * 1024 * 1024) - 68 + .thumb_func +f2: bx lr + nop + .thumb_func +f3: bx lr + nop + .thumb_func +f4: bx lr + nop + .thumb_func +f5: bx lr + nop + .thumb_func +f6: bx lr + nop + .thumb_func +f7: bx lr + nop + .thumb_func +f8: bx lr + nop + .thumb_func +f9: bx lr + nop + .thumb_func +f10: bx lr + nop diff --git a/test/ELF/arm-thunk-multipass-plt.s b/test/ELF/arm-thunk-multipass-plt.s index 46230fc66..a6b6719c1 100644 --- a/test/ELF/arm-thunk-multipass-plt.s +++ b/test/ELF/arm-thunk-multipass-plt.s @@ -74,8 +74,8 @@ preemptible2: // CHECK-PLT-NEXT: 00d00020 $a: // CHECK-PLT-NEXT: d00020: 04 e0 2d e5 str lr, [sp, #-4]! // CHECK-PLT-NEXT: d00024: 00 e6 8f e2 add lr, pc, #0, #12 -// CHECK-PLT-NEXT: d00028: 01 ea 8e e2 add lr, lr, #4096 -// CHECK-PLT-NEXT: d0002c: dc ff be e5 ldr pc, [lr, #4060]! +// CHECK-PLT-NEXT: d00028: 02 ea 8e e2 add lr, lr, #8192 +// CHECK-PLT-NEXT: d0002c: 94 f0 be e5 ldr pc, [lr, #148]! // CHECK-PLT: 00d00030 $d: // CHECK-PLT-NEXT: d00030: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK-PLT-NEXT: d00034: d4 d4 d4 d4 .word 0xd4d4d4d4 @@ -83,13 +83,13 @@ preemptible2: // CHECK-PLT-NEXT: d0003c: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK-PLT: 00d00040 $a: // CHECK-PLT-NEXT: d00040: 00 c6 8f e2 add r12, pc, #0, #12 -// CHECK-PLT-NEXT: d00044: 01 ca 8c e2 add r12, r12, #4096 -// CHECK-PLT-NEXT: d00048: c4 ff bc e5 ldr pc, [r12, #4036]! +// CHECK-PLT-NEXT: d00044: 02 ca 8c e2 add r12, r12, #8192 +// CHECK-PLT-NEXT: d00048: 7c f0 bc e5 ldr pc, [r12, #124]! // CHECK-PLT: 00d0004c $d: // CHECK-PLT-NEXT: d0004c: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK-PLT: 00d00050 $a: // CHECK-PLT-NEXT: d00050: 00 c6 8f e2 add r12, pc, #0, #12 -// CHECK-PLT-NEXT: d00054: 01 ca 8c e2 add r12, r12, #4096 -// CHECK-PLT-NEXT: d00058: b8 ff bc e5 ldr pc, [r12, #4024]! +// CHECK-PLT-NEXT: d00054: 02 ca 8c e2 add r12, r12, #8192 +// CHECK-PLT-NEXT: d00058: 70 f0 bc e5 ldr pc, [r12, #112]! // CHECK-PLT: 00d0005c $d: // CHECK-PLT-NEXT: d0005c: d4 d4 d4 d4 .word 0xd4d4d4d4 diff --git a/test/ELF/arm-thunk-nosuitable.s b/test/ELF/arm-thunk-nosuitable.s index 0e08f3f94..3334bdb17 100644 --- a/test/ELF/arm-thunk-nosuitable.s +++ b/test/ELF/arm-thunk-nosuitable.s @@ -1,7 +1,7 @@ // REQUIRES: arm // RUN: llvm-mc %s --arm-add-build-attributes --triple=armv7a-linux-gnueabihf --filetype=obj -o %t.o // RUN: ld.lld %t.o -o %t -// RUN: llvm-objdump -triple=thumbv7a-linux-gnueabihf -d -start-address=2166784 -stop-address=2166794 %t | FileCheck %s +// RUN: llvm-objdump -triple=thumbv7a -d --start-address=0x2110b4 --stop-address=0x2110be %t | FileCheck %s // Create a conditional branch too far away from a precreated thunk // section. This will need a thunk section created within range. @@ -20,10 +20,10 @@ _start: bx lr // CHECK: _start: -// CHECK-NEXT: 211000: 00 f0 00 80 beq.w #0 +// CHECK-NEXT: 2110b4: 00 f0 00 80 beq.w #0 // CHECK: __Thumbv7ABSLongThunk_target: -// CHECK-NEXT: 211004: 00 f0 01 90 b.w #12582914 -// CHECK: 211008: 70 47 bx lr +// CHECK-NEXT: 2110b8: 00 f0 01 90 b.w #12582914 +// CHECK: 2110bc: 70 47 bx lr .section .text.2, "ax", %progbits .space 12 * 1024 * 1024 diff --git a/test/ELF/arm-thunk-re-add.s b/test/ELF/arm-thunk-re-add.s index a0b2439b9..0184c7e03 100644 --- a/test/ELF/arm-thunk-re-add.s +++ b/test/ELF/arm-thunk-re-add.s @@ -103,8 +103,8 @@ callers: // CHECK3-NEXT: $a: // CHECK3-NEXT: 1100020: 04 e0 2d e5 str lr, [sp, #-4]! // CHECK3-NEXT: 1100024: 00 e6 8f e2 add lr, pc, #0, #12 -// CHECK3-NEXT: 1100028: 01 ea 8e e2 add lr, lr, #4096 -// CHECK3-NEXT: 110002c: dc ff be e5 ldr pc, [lr, #4060]! +// CHECK3-NEXT: 1100028: 02 ea 8e e2 add lr, lr, #8192 +// CHECK3-NEXT: 110002c: 94 f0 be e5 ldr pc, [lr, #148]! // CHECK3: $d: // CHECK3-NEXT: 1100030: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK3-NEXT: 1100034: d4 d4 d4 d4 .word 0xd4d4d4d4 @@ -112,13 +112,13 @@ callers: // CHECK3-NEXT: 110003c: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK3: $a: // CHECK3-NEXT: 1100040: 00 c6 8f e2 add r12, pc, #0, #12 -// CHECK3-NEXT: 1100044: 01 ca 8c e2 add r12, r12, #4096 -// CHECK3-NEXT: 1100048: c4 ff bc e5 ldr pc, [r12, #4036]! +// CHECK3-NEXT: 1100044: 02 ca 8c e2 add r12, r12, #8192 +// CHECK3-NEXT: 1100048: 7c f0 bc e5 ldr pc, [r12, #124]! // CHECK3: $d: // CHECK3-NEXT: 110004c: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK3: $a: // CHECK3-NEXT: 1100050: 00 c6 8f e2 add r12, pc, #0, #12 -// CHECK3-NEXT: 1100054: 01 ca 8c e2 add r12, r12, #4096 -// CHECK3-NEXT: 1100058: b8 ff bc e5 ldr pc, [r12, #4024]! +// CHECK3-NEXT: 1100054: 02 ca 8c e2 add r12, r12, #8192 +// CHECK3-NEXT: 1100058: 70 f0 bc e5 ldr pc, [r12, #112]! // CHECK3: $d: // CHECK3-NEXT: 110005c: d4 d4 d4 d4 .word 0xd4d4d4d4 diff --git a/test/ELF/arm-tls-gd-nonpreemptible.s b/test/ELF/arm-tls-gd-nonpreemptible.s index e72d422ba..bfb9f495e 100644 --- a/test/ELF/arm-tls-gd-nonpreemptible.s +++ b/test/ELF/arm-tls-gd-nonpreemptible.s @@ -3,7 +3,7 @@ // RUN: ld.lld %t -o %t2 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi // RUN: llvm-objdump -s %t2 | FileCheck %s -// RUN: ld.lld --hash-style=sysv %t --shared -o %t3.so +// RUN: ld.lld %t --shared -o %t3.so // RUN: llvm-objdump -s %t3.so | FileCheck -check-prefix=CHECK-SHARED %s // For an executable, we write the module index 1 and the offset into the TLS @@ -64,9 +64,9 @@ x4: .space 4 // CHECK: Contents of section .got: -// CHECK-NEXT: 12008 01000000 00000000 01000000 04000000 -// CHECK-NEXT: 12018 01000000 08000000 01000000 0c000000 +// CHECK-NEXT: 12140 01000000 00000000 01000000 04000000 +// CHECK-NEXT: 12150 01000000 08000000 01000000 0c000000 // CHECK-SHARED: Contents of section .got: -// CHECK-SHARED-NEXT: 2050 00000000 00000000 00000000 04000000 -// CHECK-SHARED-NEXT: 2060 00000000 00000000 00000000 00000000 +// CHECK-SHARED-NEXT: 22a8 00000000 00000000 00000000 04000000 +// CHECK-SHARED-NEXT: 22b8 00000000 00000000 00000000 00000000 diff --git a/test/ELF/arm-tls-gd32.s b/test/ELF/arm-tls-gd32.s index edbc6a54e..5cf5429bb 100644 --- a/test/ELF/arm-tls-gd32.s +++ b/test/ELF/arm-tls-gd32.s @@ -1,6 +1,6 @@ // REQUIRES: arm // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi -// RUN: ld.lld --hash-style=sysv %t.o -o %t.so -shared +// RUN: ld.lld %t.o -o %t.so -shared // RUN: llvm-readobj -S --dyn-relocations %t.so | FileCheck --check-prefix=SEC %s // RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s @@ -62,7 +62,7 @@ x: // SEC-NEXT: SHF_TLS // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x2000 +// SEC-NEXT: Address: 0x2210 // SEC: Size: 4 // SEC: Name: .tbss // SEC-NEXT: Type: SHT_NOBITS @@ -71,7 +71,7 @@ x: // SEC-NEXT: SHF_TLS // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x2004 +// SEC-NEXT: Address: 0x2214 // SEC: Size: 8 // SEC: Name: .got @@ -80,26 +80,26 @@ x: // SEC-NEXT: SHF_ALLOC // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x204C +// SEC-NEXT: Address: 0x2264 // SEC: Size: 24 // SEC: Dynamic Relocations { -// SEC-NEXT: 0x205C R_ARM_TLS_DTPMOD32 - -// SEC-NEXT: 0x204C R_ARM_TLS_DTPMOD32 x -// SEC-NEXT: 0x2050 R_ARM_TLS_DTPOFF32 x -// SEC-NEXT: 0x2054 R_ARM_TLS_DTPMOD32 y -// SEC-NEXT: 0x2058 R_ARM_TLS_DTPOFF32 y +// SEC-NEXT: 0x2274 R_ARM_TLS_DTPMOD32 - +// SEC-NEXT: 0x2264 R_ARM_TLS_DTPMOD32 x +// SEC-NEXT: 0x2268 R_ARM_TLS_DTPOFF32 x +// SEC-NEXT: 0x226C R_ARM_TLS_DTPMOD32 y +// SEC-NEXT: 0x2270 R_ARM_TLS_DTPOFF32 y -// CHECK-LABEL: 00001000 func: -// CHECK-NEXT: 1000: 00 f0 20 e3 nop -// CHECK-NEXT: 1004: 00 f0 20 e3 nop -// CHECK-NEXT: 1008: 00 f0 20 e3 nop +// CHECK-LABEL: 000011f8 func: +// CHECK-NEXT: 11f8: 00 f0 20 e3 nop +// CHECK-NEXT: 11fc: 00 f0 20 e3 nop +// CHECK-NEXT: 1200: 00 f0 20 e3 nop -// (0x204c - 0x100c) + (0x100c - 0x1000 - 8) = 0x1044 -// CHECK: 100c: 44 10 00 00 -// (0x2054 - 0x1010) + (0x1010 - 0x1004 - 8) = 0x1048 -// CHECK-NEXT: 1010: 48 10 00 00 -// (0x205c - 0x1014) + (0x1014 - 0x1008 - 8) = 0x104c -// CHECK-NEXT: 1014: 4c 10 00 00 +// (0x2264 - 0x1204) + (0x1204 - 0x11f8 - 8) = 0x1064 +// CHECK: 1204: 64 10 00 00 +// (0x226c - 0x1204) + (0x1204 - 0x11fc - 8) = 0x1068 +// CHECK-NEXT: 1208: 68 10 00 00 +// (0x2274 - 0x1204) + (0x1204 - 0x1200 - 8) = 0x106c +// CHECK-NEXT: 120c: 6c 10 00 00 diff --git a/test/ELF/arm-tls-ie32.s b/test/ELF/arm-tls-ie32.s index 3c0db3cd3..acb4e1ca5 100644 --- a/test/ELF/arm-tls-ie32.s +++ b/test/ELF/arm-tls-ie32.s @@ -1,6 +1,6 @@ // REQUIRES: arm // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi -// RUN: ld.lld --hash-style=sysv %t.o -o %t.so -shared +// RUN: ld.lld %t.o -o %t.so -shared // RUN: llvm-readobj -S --dyn-relocations %t.so | FileCheck --check-prefix=SEC %s // RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s @@ -73,25 +73,25 @@ x: // SEC-NEXT: SHF_ALLOC // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x204C +// SEC-NEXT: Address: 0x2254 // SEC: Size: 12 // SEC: Dynamic Relocations { -// SEC: 0x2054 R_ARM_TLS_TPOFF32 -// SEC: 0x204C R_ARM_TLS_TPOFF32 x -// SEC: 0x2050 R_ARM_TLS_TPOFF32 y +// SEC: 0x225C R_ARM_TLS_TPOFF32 +// SEC: 0x2254 R_ARM_TLS_TPOFF32 x +// SEC: 0x2258 R_ARM_TLS_TPOFF32 y // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: func: -// CHECK-NEXT: 1000: 00 f0 20 e3 nop -// CHECK-NEXT: 1004: 00 f0 20 e3 nop -// CHECK-NEXT: 1008: 00 f0 20 e3 nop +// CHECK-NEXT: 11e8: 00 f0 20 e3 nop +// CHECK-NEXT: 11ec: 00 f0 20 e3 nop +// CHECK-NEXT: 11f0: 00 f0 20 e3 nop -// (0x204c - 0x100c) + (0x100c - 0x1000 - 8) = 0x1044 -// CHECK: 100c: 44 10 00 00 -// (0x2050 - 0x1010) + (0x1010 - 0x1004 - 8) = 0x1044 -// CHECK-NEXT: 1010: 44 10 00 00 -// (0x2054 - 0x1014) + (0x1014 - 0x1008 - 8) = 0x1044 -// CHECK-NEXT: 1014: 44 10 00 00 +// (0x2254 - 0x11f4) + (0x11f4 - 0x11e8 - 8) = 0x1064 +// CHECK: 11f4: 64 10 00 00 +// (0x2258 - 0x11f8) + (0x11f8 - 0x11ec - 8) = 0x1064 +// CHECK-NEXT: 11f8: 64 10 00 00 +// (0x225c - 0x11f8) + (0x11f8 - 0x11f0 - 8) = 0x1064 +// CHECK-NEXT: 11fc: 64 10 00 00 diff --git a/test/ELF/arm-tls-ldm32.s b/test/ELF/arm-tls-ldm32.s index 5bf9e93bb..02016abaa 100644 --- a/test/ELF/arm-tls-ldm32.s +++ b/test/ELF/arm-tls-ldm32.s @@ -1,8 +1,10 @@ // REQUIRES: arm // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi -// RUN: ld.lld --hash-style=sysv %t.o -o %t.so -shared +// RUN: ld.lld %t.o -o %t.so -shared // RUN: llvm-readobj -S --dyn-relocations %t.so | FileCheck --check-prefix=SEC %s // RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s +// RUN: ld.lld %t.o -o %t +// RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t | FileCheck --check-prefix=CHECK-EXE %s // Test the handling of the local-dynamic TLS model. Dynamic loader finds // module index R_ARM_TLS_DTPMOD32. The offset in the next GOT slot is 0 @@ -40,7 +42,7 @@ x: // SEC-NEXT: SHF_TLS // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x2000 +// SEC-NEXT: Address: 0x21D0 // SEC: Size: 4 // SEC: Name: .tbss // SEC-NEXT: Type: SHT_NOBITS (0x8) @@ -49,27 +51,24 @@ x: // SEC-NEXT: SHF_TLS // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x2004 +// SEC-NEXT: Address: 0x21D4 // SEC: Size: 4 // SEC: Dynamic Relocations { -// SEC-NEXT: 0x204C R_ARM_TLS_DTPMOD32 - 0x0 +// SEC-NEXT: 0x2224 R_ARM_TLS_DTPMOD32 - 0x0 // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: _start: -// CHECK-NEXT: 1000: 00 f0 20 e3 nop +// CHECK-NEXT: 11c0: 00 f0 20 e3 nop -// (0x204c - 0x1004) + (0x1004 - 0x1000 - 8) = 0x1044 -// CHECK: 1004: 44 10 00 00 -// CHECK-NEXT: 1008: 00 00 00 00 -// CHECK-NEXT: 100c: 04 00 00 00 +// (0x2224 - 0x11c4) + (0x11c4 - 0x11c0 - 8) = 0x105c +// CHECK: 11c4: 5c 10 00 00 +// CHECK-NEXT: 11c8: 00 00 00 00 +// CHECK-NEXT: 11cc: 04 00 00 00 -// CHECK-EXE: Disassembly of section .text: -// CHECK-EXE-EMPTY: -// CHECK-NEXT-EXE: _start: -// CHECK-NEXT-EXE: 11000: 00 f0 20 e3 nop - -// CHECK-EXE: 11004: fc 0f 00 00 -// CHECK-EXE: 11008: 00 00 00 00 -// CHECK-EXE: 1100c: 04 00 00 00 +// CHECK-EXE: _start: +// CHECK-EXE-NEXT: 11114: 00 f0 20 e3 nop +// CHECK-EXE: 11118: 0c 10 00 00 +// CHECK-EXE-NEXT: 1111c: 00 00 00 00 +// CHECK-EXE-NEXT: 11120: 04 00 00 00 diff --git a/test/ELF/arm-tls-le32.s b/test/ELF/arm-tls-le32.s index c3cea8072..31a17e051 100644 --- a/test/ELF/arm-tls-le32.s +++ b/test/ELF/arm-tls-le32.s @@ -52,7 +52,7 @@ x: // SEC-NEXT: SHF_TLS // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x12000 +// SEC-NEXT: Address: 0x12120 // SEC: Size: 4 // SEC: Name: .tbss // SEC-NEXT: Type: SHT_NOBITS @@ -61,7 +61,7 @@ x: // SEC-NEXT: SHF_TLS // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x12004 +// SEC-NEXT: Address: 0x12124 // SEC: Size: 8 // SEC: Dynamic Relocations { @@ -71,8 +71,8 @@ x: // CHECK-EMPTY: // CHECK-NEXT: _start: // offset of x from Thread pointer = (TcbSize + 0x0 = 0x8) -// CHECK-NEXT: 11000: 08 00 00 00 +// CHECK-NEXT: 11114: 08 00 00 00 // offset of z from Thread pointer = (TcbSize + 0x8 = 0x10) -// CHECK-NEXT: 11004: 10 00 00 00 +// CHECK-NEXT: 11118: 10 00 00 00 // offset of y from Thread pointer = (TcbSize + 0x4 = 0xc) -// CHECK-NEXT: 11008: 0c 00 00 00 +// CHECK-NEXT: 1111c: 0c 00 00 00 diff --git a/test/ELF/arm-tls-norelax-gd-ie.s b/test/ELF/arm-tls-norelax-gd-ie.s index 3ea57dc17..261739409 100644 --- a/test/ELF/arm-tls-norelax-gd-ie.s +++ b/test/ELF/arm-tls-norelax-gd-ie.s @@ -1,8 +1,8 @@ // REQUIRES: arm -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-tls-get-addr.s -o %t1 -// RUN: ld.lld %t1 --shared -o %t1.so +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-tls-get-addr.s -o %t1.o +// RUN: ld.lld %t1.o --shared -soname=t1.so -o %t1.so // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi -// RUN: ld.lld --hash-style=sysv %t1.so %t.o -o %t +// RUN: ld.lld %t1.so %t.o -o %t // RUN: llvm-readobj -S --dyn-relocations %t | FileCheck %s // This tls global-dynamic sequence is with respect to a preemptible symbol but @@ -25,6 +25,6 @@ func: .Lt0: .word y(TLSGD) + (. - .L0 - 8) // CHECK: Dynamic Relocations { -// CHECK-NEXT: 0x12078 R_ARM_TLS_DTPMOD32 y -// CHECK-NEXT: 0x1207C R_ARM_TLS_DTPOFF32 y -// CHECK-NEXT: 0x1300C R_ARM_JUMP_SLOT __tls_get_addr +// CHECK-NEXT: 0x12290 R_ARM_TLS_DTPMOD32 y +// CHECK-NEXT: 0x12294 R_ARM_TLS_DTPOFF32 y +// CHECK-NEXT: 0x132A4 R_ARM_JUMP_SLOT __tls_get_addr diff --git a/test/ELF/arm-tls-norelax-gd-le.s b/test/ELF/arm-tls-norelax-gd-le.s index 60532d8cf..5698bb1fd 100644 --- a/test/ELF/arm-tls-norelax-gd-le.s +++ b/test/ELF/arm-tls-norelax-gd-le.s @@ -1,8 +1,8 @@ // REQUIRES: arm -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-tls-get-addr.s -o %t1 -// RUN: ld.lld %t1 --shared -o %t1.so +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-tls-get-addr.s -o %t1.o +// RUN: ld.lld %t1.o --shared -soname=t1.so -o %t1.so // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi -// RUN: ld.lld --hash-style=sysv %t1.so %t.o -o %t +// RUN: ld.lld %t1.so %t.o -o %t // RUN: llvm-objdump -s %t | FileCheck %s // This tls global-dynamic sequence is with respect to a non-preemptible @@ -33,7 +33,7 @@ x: // CHECK: Contents of section .got: // Module index is always 1 for executable -// CHECK-NEXT: 12060 01000000 00000000 +// CHECK-NEXT: 12268 01000000 00000000 // Without any definition of __tls_get_addr we get an error diff --git a/test/ELF/arm-tls-norelax-ie-le.s b/test/ELF/arm-tls-norelax-ie-le.s index 78a30a867..7dfe4bcff 100644 --- a/test/ELF/arm-tls-norelax-ie-le.s +++ b/test/ELF/arm-tls-norelax-ie-le.s @@ -1,8 +1,8 @@ // REQUIRES: arm -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-tls-get-addr.s -o %t1 -// RUN: ld.lld %t1 --shared -o %t1.so +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-tls-get-addr.s -o %t1.o +// RUN: ld.lld %t1.o --shared -soname=t1.so -o %t1.so // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi -// RUN: ld.lld --hash-style=sysv %t1.so %t.o -o %t +// RUN: ld.lld %t1.so %t.o -o %t // RUN: llvm-objdump -s -triple=armv7a-linux-gnueabi %t | FileCheck %s // This tls Initial Exec sequence is with respect to a non-preemptible symbol @@ -38,4 +38,4 @@ x2: // CHECK: Contents of section .got: // x1 at offset 8 from TP, x2 at offset 0xc from TP. Offsets include TCB size of 8 -// CHECK-NEXT: 12064 08000000 0c000000 +// CHECK-NEXT: 1227c 08000000 0c000000 diff --git a/test/ELF/arm-tls-norelax-ld-le.s b/test/ELF/arm-tls-norelax-ld-le.s index 3b4fc945a..45c1e8632 100644 --- a/test/ELF/arm-tls-norelax-ld-le.s +++ b/test/ELF/arm-tls-norelax-ld-le.s @@ -1,8 +1,8 @@ // REQUIRES: arm -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-tls-get-addr.s -o %t1 -// RUN: ld.lld %t1 --shared -o %t1.so +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-tls-get-addr.s -o %t1.o +// RUN: ld.lld %t1.o --shared -soname=t1.so -o %t1.so // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi -// RUN: ld.lld --hash-style=sysv %t1.so %t.o -o %t +// RUN: ld.lld %t1.so %t.o -o %t // RUN: llvm-objdump -s %t | FileCheck %s .global __tls_get_addr @@ -32,4 +32,4 @@ x: .word 10 // CHECK: Contents of section .got: -// CHECK-NEXT: 12064 01000000 00000000 +// CHECK-NEXT: 1227c 01000000 00000000 diff --git a/test/ELF/arm-undefined-weak.s b/test/ELF/arm-undefined-weak.s index f847bf6a6..18805ab32 100644 --- a/test/ELF/arm-undefined-weak.s +++ b/test/ELF/arm-undefined-weak.s @@ -29,12 +29,11 @@ _start: // CHECK: Disassembly of section .text: // CHECK-EMPTY: -// 69636 = 0x11004 -// CHECK: 11000: {{.*}} b #-4 <_start+0x4> -// CHECK-NEXT: 11004: {{.*}} bl #-4 <_start+0x8> +// CHECK: 110b4: {{.*}} b #-4 <_start+0x4> +// CHECK-NEXT: 110b8: {{.*}} bl #-4 <_start+0x8> // blx is transformed into bl so we don't change state -// CHECK-NEXT: 11008: {{.*}} bl #-4 <_start+0xc> -// CHECK-NEXT: 1100c: {{.*}} movt r0, #0 -// CHECK-NEXT: 11010: {{.*}} movw r0, #0 -// CHECK: 11014: {{.*}} .word 0x00000000 +// CHECK-NEXT: 110bc: {{.*}} bl #-4 <_start+0xc> +// CHECK-NEXT: 110c0: {{.*}} movt r0, #0 +// CHECK-NEXT: 110c4: {{.*}} movw r0, #0 +// CHECK: 110c8: {{.*}} .word 0x00000000 diff --git a/test/ELF/avoid-empty-program-headers.s b/test/ELF/avoid-empty-program-headers.s index 109c2abdf..08aecb53b 100644 --- a/test/ELF/avoid-empty-program-headers.s +++ b/test/ELF/avoid-empty-program-headers.s @@ -42,8 +42,8 @@ _start: // CHECK-NEXT: Offset: 0x1000 // CHECK-NEXT: VirtualAddress: 0x201000 // CHECK-NEXT: PhysicalAddress: 0x201000 -// CHECK-NEXT: FileSize: 4096 -// CHECK-NEXT: MemSize: 4096 +// CHECK-NEXT: FileSize: 1 +// CHECK-NEXT: MemSize: 1 // CHECK-NEXT: Flags [ (0x5) // CHECK-NEXT: PF_R (0x4) // CHECK-NEXT: PF_X (0x1) @@ -52,7 +52,7 @@ _start: // CHECK-NEXT: } // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_TLS (0x7) -// CHECK-NEXT: Offset: 0x2000 +// CHECK-NEXT: Offset: 0x1001 // CHECK-NEXT: VirtualAddress: 0x201001 // CHECK-NEXT: PhysicalAddress: 0x201001 // CHECK-NEXT: FileSize: 0 diff --git a/test/ELF/bad-archive.s b/test/ELF/bad-archive.s index 39c8e160f..6d70e5542 100644 --- a/test/ELF/bad-archive.s +++ b/test/ELF/bad-archive.s @@ -2,10 +2,13 @@ // Check bad archive error reporting with --whole-archive // and without it. + +// RUN: echo "!" > %t.a +// RUN: echo "foo" >> %t.a // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -// RUN: not ld.lld %t.o %p/Inputs/bad-archive.a -o %t 2>&1 | FileCheck %s -// RUN: not ld.lld %t.o --whole-archive %p/Inputs/bad-archive.a -o %t 2>&1 | FileCheck %s -// CHECK: bad-archive.a: failed to parse archive +// RUN: not ld.lld %t.o %t.a -o %t 2>&1 | FileCheck -DFILE=%t.a %s +// RUN: not ld.lld %t.o --whole-archive %t.a -o %t 2>&1 | FileCheck -DFILE=%t.a %s +// CHECK: error: [[FILE]]: failed to parse archive: truncated or malformed archive (remaining size of archive too small for next archive member header at offset 8) .globl _start _start: diff --git a/test/ELF/basic-aarch64.s b/test/ELF/basic-aarch64.s index 60bbd5d1b..9882f9d0e 100644 --- a/test/ELF/basic-aarch64.s +++ b/test/ELF/basic-aarch64.s @@ -26,7 +26,7 @@ _start: # CHECK-NEXT: Version: 1 # CHECK-NEXT: Entry: [[ENTRY:0x[0-9A-F]+]] # CHECK-NEXT: ProgramHeaderOffset: 0x40 -# CHECK-NEXT: SectionHeaderOffset: 0x11088 +# CHECK-NEXT: SectionHeaderOffset: 0x1B8 # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 64 @@ -59,8 +59,8 @@ _start: # CHECK-NEXT: SHF_ALLOC (0x2) # CHECK-NEXT: SHF_EXECINSTR (0x4) # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x210000 -# CHECK-NEXT: Offset: 0x10000 +# CHECK-NEXT: Address: 0x210120 +# CHECK-NEXT: Offset: 0x120 # CHECK-NEXT: Size: 12 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -76,7 +76,7 @@ _start: # CHECK-NEXT: SHF_STRINGS (0x20) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x11000 +# CHECK-NEXT: Offset: 0x12C # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -90,7 +90,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x11008 +# CHECK-NEXT: Offset: 0x138 # CHECK-NEXT: Size: 72 # CHECK-NEXT: Link: 5 # CHECK-NEXT: Info: 2 @@ -104,7 +104,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x11050 +# CHECK-NEXT: Offset: 0x180 # CHECK-NEXT: Size: 42 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -118,7 +118,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x1107A +# CHECK-NEXT: Offset: 0x1AA # CHECK-NEXT: Size: 13 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -138,7 +138,7 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: Symbol { # CHECK-NEXT: Name: $x.0 -# CHECK-NEXT: Value: 0x210000 +# CHECK-NEXT: Value: 0x210120 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Local (0x0) # CHECK-NEXT: Type: None (0x0) @@ -159,8 +159,8 @@ _start: # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_PHDR (0x6) # CHECK-NEXT: Offset: 0x40 -# CHECK-NEXT: VirtualAddress: 0x200040 -# CHECK-NEXT: PhysicalAddress: 0x200040 +# CHECK-NEXT: VirtualAddress: 0x210040 +# CHECK-NEXT: PhysicalAddress: 0x210040 # CHECK-NEXT: FileSize: 224 # CHECK-NEXT: MemSize: 224 # CHECK-NEXT: Flags [ (0x4) @@ -171,8 +171,8 @@ _start: # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD (0x1) # CHECK-NEXT: Offset: 0x0 -# CHECK-NEXT: VirtualAddress: 0x200000 -# CHECK-NEXT: PhysicalAddress: 0x200000 +# CHECK-NEXT: VirtualAddress: 0x210000 +# CHECK-NEXT: PhysicalAddress: 0x210000 # CHECK-NEXT: FileSize: 288 # CHECK-NEXT: MemSize: 288 # CHECK-NEXT: Flags [ @@ -182,11 +182,11 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD (0x1) -# CHECK-NEXT: Offset: 0x1000 -# CHECK-NEXT: VirtualAddress: 0x210000 -# CHECK-NEXT: PhysicalAddress: 0x210000 -# CHECK-NEXT: FileSize: 4096 -# CHECK-NEXT: MemSize: 4096 +# CHECK-NEXT: Offset: 0x120 +# CHECK-NEXT: VirtualAddress: 0x210120 +# CHECK-NEXT: PhysicalAddress: 0x210120 +# CHECK-NEXT: FileSize: 12 +# CHECK-NEXT: MemSize: 12 # CHECK-NEXT: Flags [ (0x5) # CHECK-NEXT: PF_R (0x4) # CHECK-NEXT: PF_X (0x1) diff --git a/test/ELF/basic-i386.s b/test/ELF/basic-i386.s index 1f37e7adc..b0f2cda92 100644 --- a/test/ELF/basic-i386.s +++ b/test/ELF/basic-i386.s @@ -23,9 +23,9 @@ _start: # CHECK-NEXT: Type: Executable (0x2) # CHECK-NEXT: Machine: EM_386 (0x3) # CHECK-NEXT: Version: 1 -# CHECK-NEXT: Entry: 0x401000 +# CHECK-NEXT: Entry: 0x4010B4 # CHECK-NEXT: ProgramHeaderOffset: 0x34 -# CHECK-NEXT: SectionHeaderOffset: 0x205C +# CHECK-NEXT: SectionHeaderOffset: 0x11C # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 52 @@ -58,8 +58,8 @@ _start: # CHECK-NEXT: SHF_ALLOC (0x2) # CHECK-NEXT: SHF_EXECINSTR (0x4) # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x401000 -# CHECK-NEXT: Offset: 0x1000 +# CHECK-NEXT: Address: 0x4010B4 +# CHECK-NEXT: Offset: 0xB4 # CHECK-NEXT: Size: 12 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -75,7 +75,7 @@ _start: # CHECK-NEXT: SHF_STRINGS (0x20) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x2000 +# CHECK-NEXT: Offset: 0xC0 # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -89,7 +89,7 @@ _start: # CHECK-NEXT: Flags [ # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x2008 +# CHECK-NEXT: Offset: 0xC8 # CHECK-NEXT: Size: 32 # CHECK-NEXT: Link: 5 # CHECK-NEXT: Info: 1 @@ -103,7 +103,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x2028 +# CHECK-NEXT: Offset: 0xE8 # CHECK-NEXT: Size: 42 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -117,7 +117,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x2052 +# CHECK-NEXT: Offset: 0x112 # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -129,8 +129,8 @@ _start: # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_PHDR (0x6) # CHECK-NEXT: Offset: 0x34 -# CHECK-NEXT: VirtualAddress: 0x400034 -# CHECK-NEXT: PhysicalAddress: 0x400034 +# CHECK-NEXT: VirtualAddress: 0x401034 +# CHECK-NEXT: PhysicalAddress: 0x401034 # CHECK-NEXT: FileSize: 128 # CHECK-NEXT: MemSize: 128 # CHECK-NEXT: Flags [ (0x4) @@ -141,8 +141,8 @@ _start: # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD (0x1) # CHECK-NEXT: Offset: 0x0 -# CHECK-NEXT: VirtualAddress: 0x400000 -# CHECK-NEXT: PhysicalAddress: 0x400000 +# CHECK-NEXT: VirtualAddress: 0x401000 +# CHECK-NEXT: PhysicalAddress: 0x401000 # CHECK-NEXT: FileSize: 180 # CHECK-NEXT: MemSize: 180 # CHECK-NEXT: Flags [ @@ -152,11 +152,11 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD (0x1) -# CHECK-NEXT: Offset: 0x1000 -# CHECK-NEXT: VirtualAddress: 0x401000 -# CHECK-NEXT: PhysicalAddress: 0x401000 -# CHECK-NEXT: FileSize: 4096 -# CHECK-NEXT: MemSize: 4096 +# CHECK-NEXT: Offset: 0xB4 +# CHECK-NEXT: VirtualAddress: 0x4010B4 +# CHECK-NEXT: PhysicalAddress: 0x4010B4 +# CHECK-NEXT: FileSize: 12 +# CHECK-NEXT: MemSize: 12 # CHECK-NEXT: Flags [ (0x5) # CHECK-NEXT: PF_R (0x4) # CHECK-NEXT: PF_X (0x1) diff --git a/test/ELF/basic-ppc.s b/test/ELF/basic-ppc.s index c47f983d9..567b55c13 100644 --- a/test/ELF/basic-ppc.s +++ b/test/ELF/basic-ppc.s @@ -26,9 +26,9 @@ // CHECK-NEXT: Type: Executable (0x2) // CHECK-NEXT: Machine: EM_PPC (0x14) // CHECK-NEXT: Version: 1 -// CHECK-NEXT: Entry: 0x10010000 +// CHECK-NEXT: Entry: 0x100100B4 // CHECK-NEXT: ProgramHeaderOffset: 0x34 -// CHECK-NEXT: SectionHeaderOffset: 0x11044 +// CHECK-NEXT: SectionHeaderOffset: 0x104 // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: HeaderSize: 52 @@ -63,8 +63,8 @@ // CHECK-NEXT: SHF_ALLOC (0x2) // CHECK-NEXT: SHF_EXECINSTR (0x4) // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x10010000 -// CHECK-NEXT: Offset: 0x10000 +// CHECK-NEXT: Address: 0x100100B4 +// CHECK-NEXT: Offset: 0xB4 // CHECK-NEXT: Size: 12 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -83,7 +83,7 @@ // CHECK-NEXT: SHF_STRINGS (0x20) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x11000 +// CHECK-NEXT: Offset: 0xC0 // CHECK-NEXT: Size: 8 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -97,7 +97,7 @@ // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x11008 +// CHECK-NEXT: Offset: 0xC8 // CHECK-NEXT: Size: 16 // CHECK-NEXT: Link: 5 // CHECK-NEXT: Info: 1 @@ -114,7 +114,7 @@ // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x11018 +// CHECK-NEXT: Offset: 0xD8 // CHECK-NEXT: Size: 42 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -128,7 +128,7 @@ // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x11042 +// CHECK-NEXT: Offset: 0x102 // CHECK-NEXT: Size: 1 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -143,8 +143,8 @@ // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_PHDR (0x6) // CHECK-NEXT: Offset: 0x34 -// CHECK-NEXT: VirtualAddress: 0x10000034 -// CHECK-NEXT: PhysicalAddress: 0x10000034 +// CHECK-NEXT: VirtualAddress: 0x10010034 +// CHECK-NEXT: PhysicalAddress: 0x10010034 // CHECK-NEXT: FileSize: 128 // CHECK-NEXT: MemSize: 128 // CHECK-NEXT: Flags [ (0x4) @@ -155,8 +155,8 @@ // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_LOAD (0x1) // CHECK-NEXT: Offset: 0x0 -// CHECK-NEXT: VirtualAddress: 0x10000000 -// CHECK-NEXT: PhysicalAddress: 0x10000000 +// CHECK-NEXT: VirtualAddress: 0x10010000 +// CHECK-NEXT: PhysicalAddress: 0x10010000 // CHECK-NEXT: FileSize: 180 // CHECK-NEXT: MemSize: 180 // CHECK-NEXT: Flags [ (0x4) @@ -166,11 +166,11 @@ // CHECK-NEXT: } // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_LOAD (0x1) -// CHECK-NEXT: Offset: 0x1000 -// CHECK-NEXT: VirtualAddress: 0x10010000 -// CHECK-NEXT: PhysicalAddress: 0x10010000 -// CHECK-NEXT: FileSize: 4096 -// CHECK-NEXT: MemSize: 4096 +// CHECK-NEXT: Offset: 0xB4 +// CHECK-NEXT: VirtualAddress: 0x100100B4 +// CHECK-NEXT: PhysicalAddress: 0x100100B4 +// CHECK-NEXT: FileSize: 12 +// CHECK-NEXT: MemSize: 12 // CHECK-NEXT: Flags [ (0x5) // CHECK-NEXT: PF_R (0x4) // CHECK-NEXT: PF_X (0x1) diff --git a/test/ELF/basic-ppc64.s b/test/ELF/basic-ppc64.s index cab130212..59a406bc8 100644 --- a/test/ELF/basic-ppc64.s +++ b/test/ELF/basic-ppc64.s @@ -33,9 +33,9 @@ // CHECK-NEXT: Type: SharedObject (0x3) // CHECK-NEXT: Machine: EM_PPC64 (0x15) // CHECK-NEXT: Version: 1 -// CHECK-NEXT: Entry: 0x10000 +// CHECK-NEXT: Entry: 0x1022C // CHECK-NEXT: ProgramHeaderOffset: 0x40 -// CHECK-NEXT: SectionHeaderOffset: 0x200F8 +// CHECK-NEXT: SectionHeaderOffset: 0x330 // CHECK-NEXT: Flags [ (0x2) // CHECK-NEXT: 0x2 // CHECK-NEXT: ] @@ -127,8 +127,8 @@ // CHECK-NEXT: SHF_ALLOC (0x2) // CHECK-NEXT: SHF_EXECINSTR (0x4) // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x10000 -// CHECK-NEXT: Offset: 0x10000 +// CHECK-NEXT: Address: 0x1022C +// CHECK-NEXT: Offset: 0x22C // CHECK-NEXT: Size: 12 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -147,8 +147,8 @@ // CHECK-NEXT: SHF_ALLOC (0x2) // CHECK-NEXT: SHF_WRITE (0x1) // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x20000 -// CHECK-NEXT: Offset: 0x20000 +// CHECK-NEXT: Address: 0x20238 +// CHECK-NEXT: Offset: 0x238 // CHECK-NEXT: Size: 96 // CHECK-NEXT: Link: 3 // CHECK-NEXT: Info: 0 @@ -177,8 +177,8 @@ // CHECK-NEXT: SHF_ALLOC (0x2) // CHECK-NEXT: SHF_WRITE (0x1) // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x30000 -// CHECK-NEXT: Offset: 0x20060 +// CHECK-NEXT: Address: 0x30298 +// CHECK-NEXT: Offset: 0x298 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -194,7 +194,7 @@ // CHECK-NEXT: SHF_STRINGS (0x20) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x20060 +// CHECK-NEXT: Offset: 0x298 // CHECK-NEXT: Size: 8 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -211,19 +211,19 @@ // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x20068 +// CHECK-NEXT: Offset: 0x2A0 // CHECK-NEXT: Size: 48 // CHECK-NEXT: Link: 10 // CHECK-NEXT: Info: 2 // CHECK-NEXT: AddressAlignment: 8 // CHECK-NEXT: EntrySize: 24 // CHECK-NEXT: SectionData ( -// LE-NEXT: 0000: 00000000 00000000 00000000 00000000 |................| -// LE-NEXT: 0010: 00000000 00000000 01000000 00020500 |................| -// LE-NEXT: 0020: 00000200 00000000 00000000 00000000 |................| -// BE-NEXT: 0000: 00000000 00000000 00000000 00000000 |................| -// BE-NEXT: 0010: 00000000 00000000 00000001 00020005 |................| -// BE-NEXT: 0020: 00000000 00020000 00000000 00000000 |................| +// LE-NEXT: 0000: 00000000 00000000 00000000 00000000 +// LE-NEXT: 0010: 00000000 00000000 01000000 00020500 +// LE-NEXT: 0020: 38020200 00000000 00000000 00000000 +// BE-NEXT: 0000: 00000000 00000000 00000000 00000000 +// BE-NEXT: 0010: 00000000 00000000 00000001 00020005 +// BE-NEXT: 0020: 00000000 00020238 00000000 00000000 // CHECK-NEXT: ) // CHECK-NEXT: } // CHECK-NEXT: Section { @@ -233,7 +233,7 @@ // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x20098 +// CHECK-NEXT: Offset: 0x2D0 // CHECK-NEXT: Size: 84 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -255,7 +255,7 @@ // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x200EC +// CHECK-NEXT: Offset: 0x324 // CHECK-NEXT: Size: 10 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -293,9 +293,9 @@ // CHECK-NEXT: } // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_LOAD (0x1) -// CHECK-NEXT: Offset: 0x10000 -// CHECK-NEXT: VirtualAddress: 0x10000 -// CHECK-NEXT: PhysicalAddress: 0x10000 +// CHECK-NEXT: Offset: 0x22C +// CHECK-NEXT: VirtualAddress: 0x1022C +// CHECK-NEXT: PhysicalAddress: 0x1022C // CHECK-NEXT: FileSize: 12 // CHECK-NEXT: MemSize: 12 // CHECK-NEXT: Flags [ (0x5) @@ -306,9 +306,9 @@ // CHECK-NEXT: } // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_LOAD (0x1) -// CHECK-NEXT: Offset: 0x20000 -// CHECK-NEXT: VirtualAddress: 0x20000 -// CHECK-NEXT: PhysicalAddress: 0x20000 +// CHECK-NEXT: Offset: 0x238 +// CHECK-NEXT: VirtualAddress: 0x20238 +// CHECK-NEXT: PhysicalAddress: 0x20238 // CHECK-NEXT: FileSize: 96 // CHECK-NEXT: MemSize: 96 // CHECK-NEXT: Flags [ (0x6) @@ -319,9 +319,9 @@ // CHECK-NEXT: } // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_DYNAMIC (0x2) -// CHECK-NEXT: Offset: 0x20000 -// CHECK-NEXT: VirtualAddress: 0x20000 -// CHECK-NEXT: PhysicalAddress: 0x20000 +// CHECK-NEXT: Offset: 0x238 +// CHECK-NEXT: VirtualAddress: 0x20238 +// CHECK-NEXT: PhysicalAddress: 0x20238 // CHECK-NEXT: FileSize: 96 // CHECK-NEXT: MemSize: 96 // CHECK-NEXT: Flags [ (0x6) @@ -332,11 +332,11 @@ // CHECK-NEXT: } // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_GNU_RELRO (0x6474E552) -// CHECK-NEXT: Offset: 0x20000 -// CHECK-NEXT: VirtualAddress: 0x20000 -// CHECK-NEXT: PhysicalAddress: 0x20000 +// CHECK-NEXT: Offset: 0x238 +// CHECK-NEXT: VirtualAddress: 0x20238 +// CHECK-NEXT: PhysicalAddress: 0x20238 // CHECK-NEXT: FileSize: 96 -// CHECK-NEXT: MemSize: 4096 +// CHECK-NEXT: MemSize: 3528 // CHECK-NEXT: Flags [ (0x4) // CHECK-NEXT: PF_R (0x4) // CHECK-NEXT: ] diff --git a/test/ELF/basic-sparcv9.s b/test/ELF/basic-sparcv9.s index caf02352c..820dba556 100644 --- a/test/ELF/basic-sparcv9.s +++ b/test/ELF/basic-sparcv9.s @@ -26,7 +26,7 @@ _start: # CHECK-NEXT: Version: 1 # CHECK-NEXT: Entry: [[ENTRY:0x[0-9A-F]+]] # CHECK-NEXT: ProgramHeaderOffset: 0x40 -# CHECK-NEXT: SectionHeaderOffset: 0x102070 +# CHECK-NEXT: SectionHeaderOffset: 0x1A0 # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 64 @@ -59,8 +59,8 @@ _start: # CHECK-NEXT: SHF_ALLOC (0x2) # CHECK-NEXT: SHF_EXECINSTR (0x4) # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x200000 -# CHECK-NEXT: Offset: 0x100000 +# CHECK-NEXT: Address: 0x200120 +# CHECK-NEXT: Offset: 0x120 # CHECK-NEXT: Size: 12 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -76,7 +76,7 @@ _start: # CHECK-NEXT: SHF_STRINGS (0x20) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x102000 +# CHECK-NEXT: Offset: 0x12C # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -90,7 +90,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x102008 +# CHECK-NEXT: Offset: 0x138 # CHECK-NEXT: Size: 48 # CHECK-NEXT: Link: 5 # CHECK-NEXT: Info: 1 @@ -104,7 +104,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x102038 +# CHECK-NEXT: Offset: 0x168 # CHECK-NEXT: Size: 42 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -118,7 +118,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x102062 +# CHECK-NEXT: Offset: 0x192 # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -150,8 +150,8 @@ _start: # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_PHDR (0x6) # CHECK-NEXT: Offset: 0x40 -# CHECK-NEXT: VirtualAddress: 0x100040 -# CHECK-NEXT: PhysicalAddress: 0x100040 +# CHECK-NEXT: VirtualAddress: 0x200040 +# CHECK-NEXT: PhysicalAddress: 0x200040 # CHECK-NEXT: FileSize: 224 # CHECK-NEXT: MemSize: 224 # CHECK-NEXT: Flags [ (0x4) @@ -162,8 +162,8 @@ _start: # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD (0x1) # CHECK-NEXT: Offset: 0x0 -# CHECK-NEXT: VirtualAddress: 0x100000 -# CHECK-NEXT: PhysicalAddress: 0x100000 +# CHECK-NEXT: VirtualAddress: 0x200000 +# CHECK-NEXT: PhysicalAddress: 0x200000 # CHECK-NEXT: FileSize: 288 # CHECK-NEXT: MemSize: 288 # CHECK-NEXT: Flags [ @@ -173,11 +173,11 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD (0x1) -# CHECK-NEXT: Offset: 0x100000 -# CHECK-NEXT: VirtualAddress: 0x200000 -# CHECK-NEXT: PhysicalAddress: 0x200000 -# CHECK-NEXT: FileSize: 8192 -# CHECK-NEXT: MemSize: 8192 +# CHECK-NEXT: Offset: 0x120 +# CHECK-NEXT: VirtualAddress: 0x200120 +# CHECK-NEXT: PhysicalAddress: 0x200120 +# CHECK-NEXT: FileSize: 12 +# CHECK-NEXT: MemSize: 12 # CHECK-NEXT: Flags [ (0x5) # CHECK-NEXT: PF_R (0x4) # CHECK-NEXT: PF_X (0x1) diff --git a/test/ELF/basic.s b/test/ELF/basic.s index 96bac2a7a..caab27d39 100644 --- a/test/ELF/basic.s +++ b/test/ELF/basic.s @@ -28,7 +28,7 @@ _start: # CHECK-NEXT: Version: 1 # CHECK-NEXT: Entry: [[ENTRY:0x[0-9A-F]+]] # CHECK-NEXT: ProgramHeaderOffset: 0x40 -# CHECK-NEXT: SectionHeaderOffset: 0x2070 +# CHECK-NEXT: SectionHeaderOffset: 0x1080 # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 64 @@ -78,7 +78,7 @@ _start: # CHECK-NEXT: SHF_STRINGS (0x20) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x2000 +# CHECK-NEXT: Offset: 0x1010 # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -92,7 +92,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x2008 +# CHECK-NEXT: Offset: 0x1018 # CHECK-NEXT: Size: 48 # CHECK-NEXT: Link: 5 # CHECK-NEXT: Info: 1 @@ -106,7 +106,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x2038 +# CHECK-NEXT: Offset: 0x1048 # CHECK-NEXT: Size: 42 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -120,7 +120,7 @@ _start: # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x2062 +# CHECK-NEXT: Offset: 0x1072 # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -178,8 +178,8 @@ _start: # CHECK-NEXT: Offset: 0x1000 # CHECK-NEXT: VirtualAddress: 0x201000 # CHECK-NEXT: PhysicalAddress: 0x201000 -# CHECK-NEXT: FileSize: 4096 -# CHECK-NEXT: MemSize: 4096 +# CHECK-NEXT: FileSize: 16 +# CHECK-NEXT: MemSize: 16 # CHECK-NEXT: Flags [ (0x5) # CHECK-NEXT: PF_R (0x4) # CHECK-NEXT: PF_X (0x1) diff --git a/test/ELF/build-id.s b/test/ELF/build-id.s index ebfcb08e2..5e33f6fe4 100644 --- a/test/ELF/build-id.s +++ b/test/ELF/build-id.s @@ -65,15 +65,15 @@ _start: # DEFAULT: Contents of section .note.test: # DEFAULT: Contents of section .note.gnu.build-id: # DEFAULT-NEXT: 04000000 08000000 03000000 474e5500 ............GNU. -# DEFAULT-NEXT: 95849665 2621c734 +# DEFAULT-NEXT: 605e19a6 30469e00 # MD5: Contents of section .note.gnu.build-id: # MD5-NEXT: 04000000 10000000 03000000 474e5500 ............GNU. -# MD5-NEXT: 1882c01f 71698eed 229b3994 eb554c80 +# MD5-NEXT: adbf65c5 42b4a428 184fd7c9 099cdc29 # SHA1: Contents of section .note.gnu.build-id: # SHA1-NEXT: 04000000 14000000 03000000 474e5500 ............GNU. -# SHA1-NEXT: 96820adf d90d5470 0a0c32ff a88c4017 +# SHA1-NEXT: fe148fd4 1add2878 6b298b61 5880148b # UUID: Contents of section .note.gnu.build-id: # UUID-NEXT: 04000000 10000000 03000000 474e5500 ............GNU. diff --git a/test/ELF/color-diagnostics.test b/test/ELF/color-diagnostics.test index 8613074dc..7f1e46c13 100644 --- a/test/ELF/color-diagnostics.test +++ b/test/ELF/color-diagnostics.test @@ -6,8 +6,8 @@ # RUN: not ld.lld -xyz -color-diagnostics=always /nosuchfile 2>&1 \ # RUN: | FileCheck -check-prefix=COLOR %s -# COLOR: {{ld.lld: .\[0;1;31merror: .\[0munknown argument '-xyz'}} -# COLOR: {{ld.lld: .\[0;1;31merror: .\[0mcannot open /nosuchfile}} +# COLOR: {{ld.lld: .\[0;31merror: .\[0munknown argument '-xyz'}} +# COLOR: {{ld.lld: .\[0;31merror: .\[0mcannot open /nosuchfile}} # RUN: not ld.lld -color-diagnostics=foobar 2>&1 | FileCheck -check-prefix=ERR %s # ERR: unknown option: --color-diagnostics=foobar diff --git a/test/ELF/common-page.s b/test/ELF/common-page.s index 4734a49a8..eb0dfcd73 100644 --- a/test/ELF/common-page.s +++ b/test/ELF/common-page.s @@ -54,7 +54,7 @@ _start: # CHECK-MAX-NEXT: SHF_STRINGS (0x20) # CHECK-MAX-NEXT: ] # CHECK-MAX-NEXT: Address: 0x0 -# CHECK-MAX-NEXT: Offset: 0x11000 +# CHECK-MAX-NEXT: Offset: 0x10001 # CHECK-MAX-NEXT: Size: 8 # CHECK-MAX-NEXT: Link: 0 # CHECK-MAX-NEXT: Info: 0 @@ -91,8 +91,8 @@ _start: # CHECK-MAX-NEXT: Offset: 0x10000 # CHECK-MAX-NEXT: VirtualAddress: 0x210000 # CHECK-MAX-NEXT: PhysicalAddress: 0x210000 -# CHECK-MAX-NEXT: FileSize: 4096 -# CHECK-MAX-NEXT: MemSize: 4096 +# CHECK-MAX-NEXT: FileSize: 1 +# CHECK-MAX-NEXT: MemSize: 1 # CHECK-MAX-NEXT: Flags [ (0x5) # CHECK-MAX-NEXT: PF_R (0x4) # CHECK-MAX-NEXT: PF_X (0x1) @@ -164,7 +164,7 @@ _start: # CHECK-COMMON-NEXT: SHF_STRINGS (0x20) # CHECK-COMMON-NEXT: ] # CHECK-COMMON-NEXT: Address: 0x0 -# CHECK-COMMON-NEXT: Offset: 0x20000 +# CHECK-COMMON-NEXT: Offset: 0x10001 # CHECK-COMMON-NEXT: Size: 8 # CHECK-COMMON-NEXT: Link: 0 # CHECK-COMMON-NEXT: Info: 0 @@ -201,8 +201,8 @@ _start: # CHECK-COMMON-NEXT: Offset: 0x10000 # CHECK-COMMON-NEXT: VirtualAddress: 0x210000 # CHECK-COMMON-NEXT: PhysicalAddress: 0x210000 -# CHECK-COMMON-NEXT: FileSize: 65536 -# CHECK-COMMON-NEXT: MemSize: 65536 +# CHECK-COMMON-NEXT: FileSize: 1 +# CHECK-COMMON-NEXT: MemSize: 1 # CHECK-COMMON-NEXT: Flags [ (0x5) # CHECK-COMMON-NEXT: PF_R (0x4) # CHECK-COMMON-NEXT: PF_X (0x1) diff --git a/test/ELF/copy-errors.s b/test/ELF/copy-errors.s index 40f731785..bf3c79255 100644 --- a/test/ELF/copy-errors.s +++ b/test/ELF/copy-errors.s @@ -4,7 +4,7 @@ // RUN: ld.lld %t2.o -o %t2.so -shared // RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | FileCheck %s -// CHECK: cannot preempt symbol: bar +// CHECK: error: cannot preempt symbol: bar // CHECK: >>> defined in {{.*}}.so // CHECK: >>> referenced by {{.*}}.o:(.text+0x1) @@ -12,7 +12,10 @@ // CHECK-NEXT: >>> defined in {{.*}}.so // CHECK-NEXT: >>> referenced by {{.*}}.o:(.text+0x6) -// RUN: not ld.lld --noinhibit-exec %t.o %t2.so -o %t 2>&1 | FileCheck %s --check-prefix=NOINHIBIT +// RUN: ld.lld --noinhibit-exec %t.o %t2.so -o %t 2>&1 | FileCheck %s --check-prefix=NOINHIBIT +// NOINHIBIT: warning: cannot preempt symbol: bar +// NOINHIBIT-NEXT: >>> defined in {{.*}}.so +// NOINHIBIT-NEXT: >>> referenced by {{.*}}.o:(.text+0x1) // NOINHIBIT: warning: symbol 'zed' has no type // NOINHIBIT-NEXT: >>> defined in {{.*}}.so // NOINHIBIT-NEXT: >>> referenced by {{.*}}.o:(.text+0x6) diff --git a/test/ELF/copy-rel-pie-error.s b/test/ELF/copy-rel-pie-error.s deleted file mode 100644 index 379442e11..000000000 --- a/test/ELF/copy-rel-pie-error.s +++ /dev/null @@ -1,18 +0,0 @@ -// REQUIRES: x86 -// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux -// RUN: llvm-mc %p/Inputs/copy-rel-pie.s -o %t2.o -filetype=obj -triple=x86_64-pc-linux -// RUN: ld.lld %t2.o -o %t2.so -shared -// RUN: not ld.lld %t.o %t2.so -o /dev/null -pie 2>&1 | FileCheck %s - -// CHECK: can't create dynamic relocation R_X86_64_64 against symbol: bar in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output -// CHECK: >>> defined in {{.*}}.so -// CHECK: >>> referenced by {{.*}}.o:(.text+0x0) - -// CHECK: can't create dynamic relocation R_X86_64_64 against symbol: foo in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output -// CHECK: >>> defined in {{.*}}.so -// CHECK: >>> referenced by {{.*}}.o:(.text+0x8) - -.global _start -_start: - .quad bar - .quad foo diff --git a/test/ELF/copy-rel-pie2.s b/test/ELF/copy-rel-pie2.s new file mode 100644 index 000000000..81cfac4e3 --- /dev/null +++ b/test/ELF/copy-rel-pie2.s @@ -0,0 +1,13 @@ +// REQUIRES: x86 +// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux +// RUN: llvm-mc %p/Inputs/copy-rel-pie.s -o %t2.o -filetype=obj -triple=x86_64-pc-linux +// RUN: ld.lld %t2.o -o %t2.so -shared +// RUN: ld.lld %t.o %t2.so -o %t -pie +// RUN: llvm-readobj -r %t | FileCheck %s + +// CHECK: R_X86_64_COPY +// CHECK: R_X86_64_JUMP_SLOT + +.rodata +.quad bar +.quad foo diff --git a/test/ELF/dynamic-got.s b/test/ELF/dynamic-got.s index 605e104ef..42f942df5 100644 --- a/test/ELF/dynamic-got.s +++ b/test/ELF/dynamic-got.s @@ -17,7 +17,7 @@ // CHECK-NEXT: AddressAlignment: // CHECK-NEXT: EntrySize: // CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 00200000 +// CHECK-NEXT: 0000: 74210000 // CHECK-NEXT: ) // CHECK: Name: .got.plt @@ -34,19 +34,19 @@ // CHECK-NEXT: AddressAlignment: // CHECK-NEXT: EntrySize: // CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 00200000 00000000 00000000 +// CHECK-NEXT: 0000: 74210000 00000000 00000000 // CHECK-NEXT: ) // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rel.dyn { -// CHECK-NEXT: 0x2050 R_386_RELATIVE - 0x0 +// CHECK-NEXT: 0x21C4 R_386_RELATIVE - 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] // CHECK: Type: PT_DYNAMIC -// CHECK-NEXT: Offset: 0x2000 -// CHECK-NEXT: VirtualAddress: 0x2000 -// CHECK-NEXT: PhysicalAddress: 0x2000 +// CHECK-NEXT: Offset: 0x174 +// CHECK-NEXT: VirtualAddress: 0x2174 +// CHECK-NEXT: PhysicalAddress: 0x2174 calll .L0$pb .L0$pb: diff --git a/test/ELF/dynamic-list-preempt2.s b/test/ELF/dynamic-list-preempt2.s new file mode 100644 index 000000000..16306d201 --- /dev/null +++ b/test/ELF/dynamic-list-preempt2.s @@ -0,0 +1,29 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o +# RUN: ld.lld %t.o -shared -soname=t.so -o %t.so +# RUN: echo '{ foo; };' > %t.list +# RUN: ld.lld %t.o %t.so -shared --dynamic-list %t.list -o %t +# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=SYM %s +# RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s + +## foo and bar interpose symbols in another DSO, so both are exported, +## even if --dynamic-list specifies only foo. + +# SYM-DAG: bar +# SYM-DAG: foo + +## bar is not specified in --dynamic-list, so it is not preemptable when +## producing a DSO, and its PLT does not have an associated JUMP_SLOT. + +# REL: .rela.plt { +# REL-NEXT: R_X86_64_JUMP_SLOT foo 0x0 +# REL-NEXT: } + +.globl foo, bar +foo: +bar: + ret + +call foo@PLT +call bar@PLT diff --git a/test/ELF/fill-trap-ppc.s b/test/ELF/fill-trap-ppc.s index d9a995e37..b7e5fa86b 100644 --- a/test/ELF/fill-trap-ppc.s +++ b/test/ELF/fill-trap-ppc.s @@ -1,12 +1,12 @@ # REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=powerpc64le-linux %s -o %t.o -# RUN: ld.lld %t.o -o %t.ppc64le +# RUN: ld.lld %t.o -z separate-code -o %t.ppc64le # RUN: llvm-readobj -l %t.ppc64le | FileCheck %s # RUN: od -Ax -t x1 -N16 -j0x10ff0 %t.ppc64le | FileCheck %s -check-prefix=LE # RUN: llvm-mc -filetype=obj -triple=powerpc64-linux %s -o %t.o -# RUN: ld.lld %t.o -o %t.ppc64 +# RUN: ld.lld %t.o -z separate-code -o %t.ppc64 # RUN: llvm-readobj -l %t.ppc64 | FileCheck %s # RUN: od -Ax -t x1 -N16 -j0x10ff0 %t.ppc64 | FileCheck %s -check-prefix=BE diff --git a/test/ELF/fill-trap.s b/test/ELF/fill-trap.s index ccd9f6cb5..9fc600045 100644 --- a/test/ELF/fill-trap.s +++ b/test/ELF/fill-trap.s @@ -1,16 +1,27 @@ # REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 -# RUN: llvm-readobj -l %t2 | FileCheck %s -# RUN: od -Ax -x -N16 -j0x1ff0 %t2 | FileCheck %s -check-prefix=FILL +## -z noseparate-code is the default: text segment is not tail padded. +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readobj -l %t | FileCheck %s --check-prefixes=CHECK,NOPAD +# RUN: ld.lld %t.o -z noseparate-code -o %t +# RUN: llvm-readobj -l %t | FileCheck %s --check-prefixes=CHECK,NOPAD + +## -z separate-code pads the tail of text segment with traps. +# RUN: ld.lld %t.o -z separate-code -o %t +# RUN: llvm-readobj -l %t | FileCheck %s --check-prefixes=CHECK,PAD +# RUN: od -Ax -x -N16 -j0x1ff0 %t | FileCheck %s --check-prefix=FILL + +# RUN: ld.lld %t.o -z separate-code -z noseparate-code -o %t +# RUN: llvm-readobj -l %t | FileCheck %s --check-prefixes=CHECK,NOPAD # CHECK: ProgramHeader { # CHECK: Type: PT_LOAD # CHECK: Offset: 0x1000 # CHECK-NEXT: VirtualAddress: # CHECK-NEXT: PhysicalAddress: -# CHECK-NEXT: FileSize: 4096 +# PAD-NEXT: FileSize: 4096 +# NOPAD-NEXT: FileSize: 1 # CHECK-NEXT: MemSize: # CHECK-NEXT: Flags [ # CHECK-NEXT: PF_R diff --git a/test/ELF/gdb-index-parse-fail.s b/test/ELF/gdb-index-parse-fail.s new file mode 100644 index 000000000..8b06a8d92 --- /dev/null +++ b/test/ELF/gdb-index-parse-fail.s @@ -0,0 +1,28 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: not ld.lld --gdb-index %t1.o -o %t 2>&1 | FileCheck %s + +# CHECK: error: {{.*}}:(.debug_info): invalid reference to or invalid content in .debug_str_offsets[.dwo]: insufficient space for 32 bit header prefix + +.section .debug_abbrev,"",@progbits + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 0 # DW_CHILDREN_no + .byte 114 # DW_AT_str_offsets_base + .byte 23 # DW_FORM_sec_offset + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) + +.section .debug_info,"",@progbits + .long .Lunit_end0-.Lunit_begin0 # Length of Unit +.Lunit_begin0: + .short 5 # DWARF version number + .byte 1 # DWARF Unit Type + .byte 8 # Address Size (in bytes) + .long .debug_abbrev # Offset Into Abbrev. Section + + .byte 1 # Abbrev [1] 0xc:0x43 DW_TAG_compile_unit + .long 0 # DW_AT_str_offsets_base +.Lunit_end0: + diff --git a/test/ELF/gdb-index-rng-lists.s b/test/ELF/gdb-index-rng-lists.s index d853d3bb6..e2a63d77f 100644 --- a/test/ELF/gdb-index-rng-lists.s +++ b/test/ELF/gdb-index-rng-lists.s @@ -1,8 +1,13 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o -# RUN: ld.lld --gdb-index %t1.o -o %t +# RUN: ld.lld --gdb-index %t1.o -o %t 2>&1 | FileCheck --check-prefix=LLD %s # RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s +# FIXME: Remove this once lld correctly returns non-zero on errors like this +# There's no other behavior to test hidden behind this error - lld only parses +# the CU for the address ranges, it doesn't need to decode any strings. +# LLD-NOT: error: + ## The code contains DWARF v5 sections .debug_rnglists and .debug_addr. ## Check we are able to build the correct address ## area using address range lists. diff --git a/test/ELF/global-offset-table-position-aarch64.s b/test/ELF/global-offset-table-position-aarch64.s index 4c89cc4c7..cfe3003ba 100644 --- a/test/ELF/global-offset-table-position-aarch64.s +++ b/test/ELF/global-offset-table-position-aarch64.s @@ -20,7 +20,7 @@ _start: .long _GLOBAL_OFFSET_TABLE_ - . // CHECK: Name: _GLOBAL_OFFSET_TABLE_ (11) -// CHECK-NEXT: Value: 0x30008 +// CHECK-NEXT: Value: 0x30360 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local (0x0) // CHECK-NEXT: Type: None (0x0) diff --git a/test/ELF/global-offset-table-position-arm.s b/test/ELF/global-offset-table-position-arm.s index 37d731da5..cce8f3e2f 100644 --- a/test/ELF/global-offset-table-position-arm.s +++ b/test/ELF/global-offset-table-position-arm.s @@ -25,7 +25,7 @@ _start: .data // CHECK: Name: _GLOBAL_OFFSET_TABLE_ -// CHECK-NEXT: Value: 0x2068 +// CHECK-NEXT: Value: 0x2268 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None diff --git a/test/ELF/global-offset-table-position-i386.s b/test/ELF/global-offset-table-position-i386.s index 26b140725..95e3c5a00 100644 --- a/test/ELF/global-offset-table-position-i386.s +++ b/test/ELF/global-offset-table-position-i386.s @@ -22,7 +22,7 @@ addl $_GLOBAL_OFFSET_TABLE_, %eax calll f@PLT // CHECK: Name: _GLOBAL_OFFSET_TABLE_ (1) -// CHECK-NEXT: Value: 0x3000 +// CHECK-NEXT: Value: 0x325C // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local (0x0) // CHECK-NEXT: Type: None (0x0) diff --git a/test/ELF/gnu-ifunc-canon.s b/test/ELF/gnu-ifunc-canon.s index e069a82c6..a7ba3aff7 100644 --- a/test/ELF/gnu-ifunc-canon.s +++ b/test/ELF/gnu-ifunc-canon.s @@ -4,7 +4,7 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/gnu-ifunc-canon-ro-abs.s -o %t-ro-abs.o // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/gnu-ifunc-canon-rw-addend.s -o %t-rw-addend.o // RUN: ld.lld %t.o -o %t1 -// RUN: llvm-readobj -r %t1 | FileCheck --check-prefix=IREL2 %s +// RUN: llvm-readobj -r %t1 | FileCheck --check-prefix=IREL1 %s // RUN: ld.lld %t.o %t-ro-pcrel.o -o %t2 // RUN: llvm-readobj -r %t2 | FileCheck --check-prefix=IREL1 %s // RUN: ld.lld %t.o %t-ro-abs.o -o %t3 @@ -22,7 +22,7 @@ // RUN: ld.lld %t-rw-addend.o %t.o -o %t7 // RUN: llvm-readobj -r %t7 | FileCheck --check-prefix=IREL1 %s // RUN: ld.lld %t.o -o %t8 -pie -// RUN: llvm-readobj -r %t8 | FileCheck --check-prefix=IREL2 %s +// RUN: llvm-readobj -r %t8 | FileCheck --check-prefix=IREL1-REL2 %s // RUN: ld.lld %t.o %t-ro-pcrel.o -o %t9 -pie // RUN: llvm-readobj -r %t9 | FileCheck --check-prefix=IREL1-REL2 %s // RUN: ld.lld %t.o %t-rw-addend.o -o %t10 -pie @@ -32,16 +32,9 @@ // RUN: ld.lld %t-rw-addend.o %t.o -o %t12 -pie // RUN: llvm-readobj -r %t12 | FileCheck --check-prefix=IREL1-REL3 %s -// Two relocs, one for the GOT and the other for .data. -// IREL2-NOT: R_X86_64_ -// IREL2: .rela.plt -// IREL2-NEXT: R_X86_64_IRELATIVE -// IREL2-NEXT: R_X86_64_IRELATIVE -// IREL2-NOT: R_X86_64_ - // One reloc for the canonical PLT. // IREL1-NOT: R_X86_64_ -// IREL1: .rela.plt +// IREL1: .rela.dyn // IREL1-NEXT: R_X86_64_IRELATIVE // IREL1-NOT: R_X86_64_ @@ -51,7 +44,6 @@ // IREL1-REL2: .rela.dyn // IREL1-REL2-NEXT: R_X86_64_RELATIVE // IREL1-REL2-NEXT: R_X86_64_RELATIVE -// IREL1-REL2: .rela.plt // IREL1-REL2-NEXT: R_X86_64_IRELATIVE // IREL1-REL2-NOT: R_X86_64_ @@ -62,7 +54,6 @@ // IREL1-REL3-NEXT: R_X86_64_RELATIVE // IREL1-REL3-NEXT: R_X86_64_RELATIVE // IREL1-REL3-NEXT: R_X86_64_RELATIVE -// IREL1-REL3: .rela.plt // IREL1-REL3-NEXT: R_X86_64_IRELATIVE // IREL1-REL3-NOT: R_X86_64_ diff --git a/test/ELF/gnu-ifunc-dyntags.s b/test/ELF/gnu-ifunc-dyntags.s index b17718335..7bd3567cb 100644 --- a/test/ELF/gnu-ifunc-dyntags.s +++ b/test/ELF/gnu-ifunc-dyntags.s @@ -8,19 +8,21 @@ ## when there are no other relocations except R_*_IRELATIVE. # CHECK: Name Size VMA -# CHECK: .rela.plt 00000030 0000000000000248 +# CHECK: .rela.dyn 00000030 0000000000000248 # CHECK: .got.plt 00000010 0000000000003000 # TAGS: Relocations [ -# TAGS-NEXT: Section {{.*}} .rela.plt { +# TAGS-NEXT: Section {{.*}} .rela.dyn { # TAGS-NEXT: R_X86_64_IRELATIVE # TAGS-NEXT: R_X86_64_IRELATIVE # TAGS-NEXT: } # TAGS-NEXT: ] # TAGS: Tag Type Name/Value -# TAGS: 0x0000000000000017 JMPREL 0x248 -# TAGS: 0x0000000000000002 PLTRELSZ 48 +# TAGS: 0x0000000000000007 RELA 0x248 +# TAGS: 0x0000000000000008 RELASZ 48 (bytes) +# TAGS: 0x0000000000000017 JMPREL 0x0 +# TAGS: 0x0000000000000002 PLTRELSZ 0 (bytes) # TAGS: 0x0000000000000003 PLTGOT 0x3000 # TAGS: 0x0000000000000014 PLTREL RELA diff --git a/test/ELF/gnu-ifunc-i386.s b/test/ELF/gnu-ifunc-i386.s index ea451dd40..2e1a506ee 100644 --- a/test/ELF/gnu-ifunc-i386.s +++ b/test/ELF/gnu-ifunc-i386.s @@ -1,13 +1,13 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o // RUN: ld.lld -static %t.o -o %tout -// RUN: llvm-objdump -d %tout | FileCheck %s --check-prefix=DISASM +// RUN: llvm-objdump -d --no-show-raw-insn %tout | FileCheck %s --check-prefix=DISASM // RUN: llvm-readobj -r --symbols --sections %tout | FileCheck %s // CHECK: Sections [ // CHECK: Section { // CHECK: Index: 1 -// CHECK-NEXT: Name: .rel.plt +// CHECK-NEXT: Name: .rel.dyn // CHECK-NEXT: Type: SHT_REL // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC @@ -21,9 +21,9 @@ // CHECK-NEXT: EntrySize: 8 // CHECK-NEXT: } // CHECK: Relocations [ -// CHECK-NEXT: Section ({{.*}}) .rel.plt { -// CHECK-NEXT: 0x402000 R_386_IRELATIVE -// CHECK-NEXT: 0x402004 R_386_IRELATIVE +// CHECK-NEXT: Section ({{.*}}) .rel.dyn { +// CHECK-NEXT: 0x402120 R_386_IRELATIVE +// CHECK-NEXT: 0x402124 R_386_IRELATIVE // CHECK-NEXT: } // CHECK-NEXT: ] @@ -46,7 +46,7 @@ // CHECK-NEXT: Other [ // CHECK-NEXT: STV_HIDDEN // CHECK-NEXT: ] -// CHECK-NEXT: Section: .rel.plt +// CHECK-NEXT: Section: .rel.dyn // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: __rel_iplt_start @@ -57,11 +57,11 @@ // CHECK-NEXT: Other [ // CHECK-NEXT: STV_HIDDEN // CHECK-NEXT: ] -// CHECK-NEXT: Section: .rel.plt +// CHECK-NEXT: Section: .rel.dyn // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x401002 +// CHECK-NEXT: Value: 0x4010E6 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None @@ -70,7 +70,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: bar -// CHECK-NEXT: Value: 0x401030 +// CHECK-NEXT: Value: 0x401110 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Function @@ -79,7 +79,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: bar_resolver -// CHECK-NEXT: Value: 0x401001 +// CHECK-NEXT: Value: 0x4010E5 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Function @@ -88,7 +88,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: foo -// CHECK-NEXT: Value: 0x401020 +// CHECK-NEXT: Value: 0x401100 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Function @@ -97,7 +97,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: foo_resolver -// CHECK-NEXT: Value: 0x401000 +// CHECK-NEXT: Value: 0x4010E4 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Function @@ -109,25 +109,25 @@ // DISASM: Disassembly of section .text: // DISASM-EMPTY: // DISASM-NEXT: foo_resolver: -// DISASM-NEXT: 401000: c3 retl +// DISASM-NEXT: 4010e4: retl // DISASM: bar_resolver: -// DISASM-NEXT: 401001: c3 retl +// DISASM-NEXT: 4010e5: retl // DISASM: _start: -// DISASM-NEXT: 401002: e8 19 00 00 00 calll 25 -// DISASM-NEXT: 401007: e8 24 00 00 00 calll 36 -// DISASM-NEXT: 40100c: ba d4 00 40 00 movl $4194516, %edx -// DISASM-NEXT: 401011: ba e4 00 40 00 movl $4194532, %edx +// DISASM-NEXT: 4010e6: calll 21 +// DISASM-NEXT: calll 32 +// DISASM-NEXT: movl $4194516, %edx +// DISASM-NEXT: movl $4194532, %edx // DISASM-EMPTY: // DISASM-NEXT: Disassembly of section .plt: // DISASM-EMPTY: // DISASM-NEXT: foo: -// DISASM-NEXT: 401020: ff 25 00 20 40 00 jmpl *4202496 -// DISASM-NEXT: 401026: 68 10 00 00 00 pushl $16 -// DISASM-NEXT: 40102b: e9 e0 ff ff ff jmp -32 <_start+0xe> +// DISASM-NEXT: 401100: jmpl *4202784 +// DISASM-NEXT: pushl $16 +// DISASM-NEXT: jmp -32 <_start+0xa> // DISASM: bar: -// DISASM-NEXT: 401030: ff 25 04 20 40 00 jmpl *4202500 -// DISASM-NEXT: 401036: 68 18 00 00 00 pushl $24 -// DISASM-NEXT: 40103b: e9 d0 ff ff ff jmp -48 <_start+0xe> +// DISASM-NEXT: 401110: jmpl *4202788 +// DISASM-NEXT: pushl $24 +// DISASM-NEXT: jmp -48 <_start+0xa> .text .type foo STT_GNU_IFUNC diff --git a/test/ELF/gnu-ifunc-noplt-i386.s b/test/ELF/gnu-ifunc-noplt-i386.s index d673fc00c..12e01be30 100644 --- a/test/ELF/gnu-ifunc-noplt-i386.s +++ b/test/ELF/gnu-ifunc-noplt-i386.s @@ -1,56 +1,56 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-pc-freebsd %S/Inputs/shared2-x86-64.s -o %t1.o -// RUN: ld.lld %t1.o --shared -o %t.so +// RUN: ld.lld %t1.o --shared --soname=t.so -o %t.so // RUN: llvm-mc -filetype=obj -triple=i686-pc-freebsd %s -o %t.o // RUN: ld.lld -z ifunc-noplt -z notext --hash-style=sysv %t.so %t.o -o %tout -// RUN: llvm-objdump -d --no-show-raw-insn %tout | FileCheck %s --check-prefix=DISASM +// RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %tout | FileCheck %s --check-prefix=DISASM // RUN: llvm-readobj -r --dynamic-table %tout | FileCheck %s // Check that we emitted relocations for the ifunc calls // CHECK: Relocations [ // CHECK-NEXT: Section (4) .rel.dyn { -// CHECK-NEXT: 0x401008 R_386_PLT32 bar -// CHECK-NEXT: 0x401003 R_386_PLT32 foo +// CHECK-NEXT: 0x4011F4 R_386_PLT32 bar +// CHECK-NEXT: 0x4011EF R_386_PLT32 foo // CHECK-NEXT: } // CHECK-NEXT: Section (5) .rel.plt { -// CHECK-NEXT: 0x40300C R_386_JUMP_SLOT bar2 -// CHECK-NEXT: 0x403010 R_386_JUMP_SLOT zed2 +// CHECK-NEXT: 0x4032D4 R_386_JUMP_SLOT bar2 +// CHECK-NEXT: 0x4032D8 R_386_JUMP_SLOT zed2 // CHECK-NEXT: } // Check that ifunc call sites still require relocation // DISASM: Disassembly of section .text: // DISASM-EMPTY: -// DISASM-NEXT: 00401000 foo: -// DISASM-NEXT: 401000: retl +// DISASM-NEXT: 004011ec foo: +// DISASM-NEXT: retl // DISASM-EMPTY: -// DISASM-NEXT: 00401001 bar: -// DISASM-NEXT: 401001: retl +// DISASM-NEXT: 004011ed bar: +// DISASM-NEXT: retl // DISASM-EMPTY: -// DISASM-NEXT: 00401002 _start: -// DISASM-NEXT: 401002: calll -4 <_start+0x1> -// DISASM-NEXT: 401007: calll -4 <_start+0x6> -// DISASM-NEXT: 40100c: calll 31 -// DISASM-NEXT: 401011: calll 42 +// DISASM-NEXT: 004011ee _start: +// DISASM-NEXT: calll -0x4 <_start+0x1> +// DISASM-NEXT: calll -0x4 <_start+0x6> +// DISASM-NEXT: calll 0x23 +// DISASM-NEXT: calll 0x2e // DISASM-EMPTY: // DISASM-NEXT: Disassembly of section .plt: // DISASM-EMPTY: -// DISASM-NEXT: 00401020 .plt: -// DISASM-NEXT: 401020: pushl 4206596 -// DISASM-NEXT: 401026: jmpl *4206600 -// DISASM-NEXT: 40102c: nop -// DISASM-NEXT: 40102d: nop -// DISASM-NEXT: 40102e: nop -// DISASM-NEXT: 40102f: nop +// DISASM-NEXT: 00401210 .plt: +// DISASM-NEXT: pushl 0x4032cc +// DISASM-NEXT: jmpl *0x4032d0 +// DISASM-NEXT: nop +// DISASM-NEXT: nop +// DISASM-NEXT: nop +// DISASM-NEXT: nop // DISASM-EMPTY: -// DISASM-NEXT: 00401030 bar2@plt: -// DISASM-NEXT: 401030: jmpl *4206604 -// DISASM-NEXT: 401036: pushl $0 -// DISASM-NEXT: 40103b: jmp -32 <.plt> +// DISASM-NEXT: 00401220 bar2@plt: +// DISASM-NEXT: jmpl *0x4032d4 +// DISASM-NEXT: pushl $0x0 +// DISASM-NEXT: jmp -0x20 <.plt> // DISASM-EMPTY: -// DISASM-NEXT: 00401040 zed2@plt: -// DISASM-NEXT: 401040: jmpl *4206608 -// DISASM-NEXT: 401046: pushl $8 -// DISASM-NEXT: 40104b: jmp -48 <.plt> +// DISASM-NEXT: 00401230 zed2@plt: +// DISASM-NEXT: jmpl *0x4032d8 +// DISASM-NEXT: pushl $0x8 +// DISASM-NEXT: jmp -0x30 <.plt> .text .type foo STT_GNU_IFUNC diff --git a/test/ELF/gnu-ifunc-plt-i386.s b/test/ELF/gnu-ifunc-plt-i386.s index 533b39311..9fd933dbb 100644 --- a/test/ELF/gnu-ifunc-plt-i386.s +++ b/test/ELF/gnu-ifunc-plt-i386.s @@ -1,68 +1,72 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %S/Inputs/shared2-x86-64.s -o %t1.o -// RUN: ld.lld %t1.o --shared -o %t.so +// RUN: ld.lld %t1.o --shared --soname=t.so -o %t.so // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o // RUN: ld.lld --hash-style=sysv %t.so %t.o -o %tout -// RUN: llvm-objdump -d %tout | FileCheck %s --check-prefix=DISASM +// RUN: llvm-objdump -d --no-show-raw-insn %tout | FileCheck %s --check-prefix=DISASM // RUN: llvm-objdump -s %tout | FileCheck %s --check-prefix=GOTPLT // RUN: llvm-readobj -r --dynamic-table %tout | FileCheck %s // Check that the IRELATIVE relocations are after the JUMP_SLOT in the plt // CHECK: Relocations [ -// CHECK-NEXT: Section (4) .rel.plt { -// CHECK-NEXT: 0x40300C R_386_JUMP_SLOT bar2 -// CHECK-NEXT: 0x403010 R_386_JUMP_SLOT zed2 -// CHECK-NEXT: 0x403014 R_386_IRELATIVE -// CHECK-NEXT: 0x403018 R_386_IRELATIVE +// CHECK-NEXT: Section (4) .rel.dyn { +// CHECK-NEXT: 0x4032AC R_386_IRELATIVE +// CHECK-NEXT: 0x4032B0 R_386_IRELATIVE +// CHECK-NEXT: } +// CHECK-NEXT: Section (5) .rel.plt { +// CHECK-NEXT: 0x4032A4 R_386_JUMP_SLOT bar2 +// CHECK-NEXT: 0x4032A8 R_386_JUMP_SLOT zed2 +// CHECK-NEXT: } // Check that IRELATIVE .got.plt entries point to ifunc resolver and not // back to the plt entry + 6. // GOTPLT: Contents of section .got.plt: -// GOTPLT: 403000 00204000 00000000 00000000 36104000 -// GOTPLT-NEXT: 403010 46104000 00104000 01104000 +// GOTPLT: 403298 20224000 00000000 00000000 e6114000 +// GOTPLT-NEXT: 4032a8 f6114000 b4114000 b5114000 -// Check that the PLTRELSZ tag includes the IRELATIVE relocations +// Check that the PLTRELSZ tag does not include the IRELATIVE relocations // CHECK: DynamicSection [ -// CHECK: 0x00000002 PLTRELSZ 32 (bytes) +// CHECK: 0x00000012 RELSZ 16 (bytes) +// CHECK: 0x00000002 PLTRELSZ 16 (bytes) // Check that a PLT header is written and the ifunc entries appear last // DISASM: Disassembly of section .text: // DISASM-EMPTY: // DISASM-NEXT: foo: -// DISASM-NEXT: 401000: c3 retl +// DISASM-NEXT: 4011b4: retl // DISASM: bar: -// DISASM-NEXT: 401001: c3 retl +// DISASM-NEXT: 4011b5: retl // DISASM: _start: -// DISASM-NEXT: 401002: e8 49 00 00 00 calll 73 -// DISASM-NEXT: 401007: e8 54 00 00 00 calll 84 -// DISASM-NEXT: 40100c: e8 1f 00 00 00 calll 31 -// DISASM-NEXT: 401011: e8 2a 00 00 00 calll 42 +// DISASM-NEXT: 4011b6: calll 69 +// DISASM-NEXT: calll 80 +// DISASM-NEXT: calll 27 +// DISASM-NEXT: calll 38 // DISASM-EMPTY: // DISASM-NEXT: Disassembly of section .plt: // DISASM-EMPTY: // DISASM-NEXT: .plt: -// DISASM-NEXT: 401020: ff 35 04 30 40 00 pushl 4206596 -// DISASM-NEXT: 401026: ff 25 08 30 40 00 jmpl *4206600 -// DISASM-NEXT: 40102c: 90 nop -// DISASM-NEXT: 40102d: 90 nop -// DISASM-NEXT: 40102e: 90 nop -// DISASM-NEXT: 40102f: 90 nop +// DISASM-NEXT: 4011d0: pushl 4207260 +// DISASM-NEXT: jmpl *4207264 +// DISASM-NEXT: nop +// DISASM-NEXT: nop +// DISASM-NEXT: nop +// DISASM-NEXT: nop // DISASM-EMPTY: // DISASM-NEXT: bar2@plt: -// DISASM-NEXT: 401030: ff 25 0c 30 40 00 jmpl *4206604 -// DISASM-NEXT: 401036: 68 00 00 00 00 pushl $0 -// DISASM-NEXT: 40103b: e9 e0 ff ff ff jmp -32 <.plt> +// DISASM-NEXT: 4011e0: jmpl *4207268 +// DISASM-NEXT: pushl $0 +// DISASM-NEXT: jmp -32 <.plt> // DISASM-EMPTY: // DISASM-NEXT: zed2@plt: -// DISASM-NEXT: 401040: ff 25 10 30 40 00 jmpl *4206608 -// DISASM-NEXT: 401046: 68 08 00 00 00 pushl $8 -// DISASM-NEXT: 40104b: e9 d0 ff ff ff jmp -48 <.plt> -// DISASM-NEXT: 401050: ff 25 14 30 40 00 jmpl *4206612 -// DISASM-NEXT: 401056: 68 30 00 00 00 pushl $48 -// DISASM-NEXT: 40105b: e9 e0 ff ff ff jmp -32 -// DISASM-NEXT: 401060: ff 25 18 30 40 00 jmpl *4206616 -// DISASM-NEXT: 401066: 68 38 00 00 00 pushl $56 -// DISASM-NEXT: 40106b: e9 d0 ff ff ff jmp -48 +// DISASM-NEXT: 4011f0: jmpl *4207272 +// DISASM-NEXT: pushl $8 +// DISASM-NEXT: jmp -48 <.plt> +// DISASM-NEXT: jmpl *4207276 +// DISASM-NEXT: pushl $48 +// DISASM-NEXT: jmp -32 +// DISASM-NEXT: jmpl *4207280 +// DISASM-NEXT: pushl $56 +// DISASM-NEXT: jmp -48 .text .type foo STT_GNU_IFUNC diff --git a/test/ELF/gnu-ifunc-plt.s b/test/ELF/gnu-ifunc-plt.s index 28161fe3d..e535888be 100644 --- a/test/ELF/gnu-ifunc-plt.s +++ b/test/ELF/gnu-ifunc-plt.s @@ -9,11 +9,14 @@ // Check that the IRELATIVE relocations are after the JUMP_SLOT in the plt // CHECK: Relocations [ -// CHECK-NEXT: Section (4) .rela.plt { -// CHECK-NEXT: 0x203018 R_X86_64_JUMP_SLOT bar2 0x0 -// CHECK-NEXT: 0x203020 R_X86_64_JUMP_SLOT zed2 0x0 +// CHECK-NEXT: Section (4) .rela.dyn { // CHECK-NEXT: 0x203028 R_X86_64_IRELATIVE - 0x201000 // CHECK-NEXT: 0x203030 R_X86_64_IRELATIVE - 0x201001 +// CHECK-NEXT: } +// CHECK-NEXT: Section (5) .rela.plt { +// CHECK-NEXT: 0x203018 R_X86_64_JUMP_SLOT bar2 0x0 +// CHECK-NEXT: 0x203020 R_X86_64_JUMP_SLOT zed2 0x0 +// CHECK-NEXT: } // Check that .got.plt entries point back to PLT header // GOTPLT: Contents of section .got.plt: @@ -22,9 +25,10 @@ // GOTPLT-NEXT: 203020 46102000 00000000 56102000 00000000 // GOTPLT-NEXT: 203030 66102000 00000000 -// Check that the PLTRELSZ tag includes the IRELATIVE relocations +// Check that the PLTRELSZ tag does not include the IRELATIVE relocations // CHECK: DynamicSection [ -// CHECK: 0x0000000000000002 PLTRELSZ 96 (bytes) +// CHECK: 0x0000000000000008 RELASZ 48 (bytes) +// CHECK: 0x0000000000000002 PLTRELSZ 48 (bytes) // Check that a PLT header is written and the ifunc entries appear last // DISASM: Disassembly of section .text: diff --git a/test/ELF/gnu-ifunc-relative.s b/test/ELF/gnu-ifunc-relative.s index 510f246c3..278bc5021 100644 --- a/test/ELF/gnu-ifunc-relative.s +++ b/test/ELF/gnu-ifunc-relative.s @@ -14,7 +14,7 @@ foo: _start: call foo -// CHECK: Section ({{.*}}) .rela.plt { +// CHECK: Section ({{.*}}) .rela.dyn { // CHECK-NEXT: R_X86_64_IRELATIVE - 0x[[ADDR:.*]] // CHECK-NEXT: } diff --git a/test/ELF/gnu-ifunc-shared.s b/test/ELF/gnu-ifunc-shared.s index 532355f22..237875bf9 100644 --- a/test/ELF/gnu-ifunc-shared.s +++ b/test/ELF/gnu-ifunc-shared.s @@ -41,10 +41,13 @@ // DISASM-NEXT: 105b: e9 e0 ff ff ff jmp -32 // CHECK: Relocations [ -// CHECK-NEXT: Section (4) .rela.plt { +// CHECK-NEXT: Section (4) .rela.dyn { +// CHECK-NEXT: 0x3028 R_X86_64_IRELATIVE - 0x1000 +// CHECK-NEXT: } +// CHECK-NEXT: Section (5) .rela.plt { // CHECK-NEXT: 0x3018 R_X86_64_JUMP_SLOT fct2 0x0 // CHECK-NEXT: 0x3020 R_X86_64_JUMP_SLOT f2 0x0 -// CHECK-NEXT: 0x3028 R_X86_64_IRELATIVE - 0x1000 +// CHECK-NEXT: } // Hidden expect IRELATIVE .globl fct diff --git a/test/ELF/gnu-ifunc.s b/test/ELF/gnu-ifunc.s index 087faba8b..1efd4ab37 100644 --- a/test/ELF/gnu-ifunc.s +++ b/test/ELF/gnu-ifunc.s @@ -7,7 +7,7 @@ // CHECK: Sections [ // CHECK: Section { // CHECK: Index: 1 -// CHECK-NEXT: Name: .rela.plt +// CHECK-NEXT: Name: .rela.dyn // CHECK-NEXT: Type: SHT_RELA // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC @@ -23,7 +23,7 @@ // CHECK: Index: [[GOTPLT]] // CHECK-NEXT: Name: .got.plt // CHECK: Relocations [ -// CHECK-NEXT: Section ({{.*}}) .rela.plt { +// CHECK-NEXT: Section ({{.*}}) .rela.dyn { // CHECK-NEXT: 0x202000 R_X86_64_IRELATIVE // CHECK-NEXT: 0x202008 R_X86_64_IRELATIVE // CHECK-NEXT: } @@ -47,7 +47,7 @@ // CHECK-NEXT: Other [ // CHECK-NEXT: STV_HIDDEN // CHECK-NEXT: ] -// CHECK-NEXT: Section: .rela.plt +// CHECK-NEXT: Section: .rela.dyn // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: __rela_iplt_start @@ -58,7 +58,7 @@ // CHECK-NEXT: Other [ // CHECK-NEXT: STV_HIDDEN // CHECK-NEXT: ] -// CHECK-NEXT: Section: .rela.plt +// CHECK-NEXT: Section: .rela.dyn // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start diff --git a/test/ELF/got-i386.s b/test/ELF/got-i386.s index d51a576f1..0a53d00c8 100644 --- a/test/ELF/got-i386.s +++ b/test/ELF/got-i386.s @@ -10,7 +10,7 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x402000 +// CHECK-NEXT: Address: 0x4020F4 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: // CHECK-NEXT: Link: @@ -19,7 +19,7 @@ // CHECK: Symbol { // CHECK: Name: bar -// CHECK-NEXT: Value: 0x40200C +// CHECK-NEXT: Value: 0x402100 // CHECK-NEXT: Size: 10 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -28,7 +28,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: obj -// CHECK-NEXT: Value: 0x402016 +// CHECK-NEXT: Value: 0x40210A // CHECK-NEXT: Size: 10 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -42,9 +42,9 @@ // DISASM: Disassembly of section .text: // DISASM-EMPTY: // DISASM-NEXT: _start: -// DISASM-NEXT: 401000: c7 81 0c 00 00 00 01 00 00 00 movl $1, 12(%ecx) -// DISASM-NEXT: 40100a: c7 81 16 00 00 00 02 00 00 00 movl $2, 22(%ecx) -// DISASM-NEXT: 401014: c7 81 1b 00 00 00 03 00 00 00 movl $3, 27(%ecx) +// DISASM-NEXT: 4010d4: c7 81 0c 00 00 00 01 00 00 00 movl $1, 12(%ecx) +// DISASM-NEXT: 4010de: c7 81 16 00 00 00 02 00 00 00 movl $2, 22(%ecx) +// DISASM-NEXT: 4010e8: c7 81 1b 00 00 00 03 00 00 00 movl $3, 27(%ecx) .global _start _start: diff --git a/test/ELF/got32-i386-pie-rw.s b/test/ELF/got32-i386-pie-rw.s index 180ba864f..8130806cd 100644 --- a/test/ELF/got32-i386-pie-rw.s +++ b/test/ELF/got32-i386-pie-rw.s @@ -5,9 +5,9 @@ # Unlike bfd and gold we accept this. -# CHECK: .foobar PROGBITS 00001000 +# CHECK: .foobar PROGBITS 00002180 # CHECK: .got PROGBITS [[GOT:[0-9a-z]*]] -# CHECK-DAG: 00001002 00000008 R_386_RELATIVE +# CHECK-DAG: 00002182 00000008 R_386_RELATIVE # CHECK-DAG: [[GOT]] 00000008 R_386_RELATIVE foo: diff --git a/test/ELF/got32-i386.s b/test/ELF/got32-i386.s index 0080e1be1..f3cee3a47 100644 --- a/test/ELF/got32-i386.s +++ b/test/ELF/got32-i386.s @@ -14,10 +14,10 @@ _start: ## 73728 == 0x12000 == ADDR(.got) # CHECK: _start: -# CHECK-NEXT: 401001: 8b 1d {{.*}} movl 4202496, %ebx +# CHECK-NEXT: 4010f5: 8b 1d {{.*}} movl 4202748, %ebx # CHECK: Sections: # CHECK: Name Size VMA -# CHECK: .got 00000004 0000000000402000 +# CHECK: .got 00000004 00000000004020fc # RUN: not ld.lld %t.o -o %t -pie 2>&1 | FileCheck %s --check-prefix=ERR -# ERR: error: can't create dynamic relocation R_386_GOT32 against symbol: foo in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output +# ERR: error: symbol 'foo' cannot be preempted; recompile with -fPIE diff --git a/test/ELF/got32x-i386.s b/test/ELF/got32x-i386.s index 0e601fe74..bc24795dc 100644 --- a/test/ELF/got32x-i386.s +++ b/test/ELF/got32x-i386.s @@ -33,15 +33,14 @@ ## 73728 == 0x12000 == ADDR(.got) # CHECK: _start: -# CHECK-NEXT: 401001: 8b 05 {{.*}} movl 4202496, %eax -# CHECK-NEXT: 401007: 8b 1d {{.*}} movl 4202496, %ebx -# CHECK-NEXT: 40100d: 8b 80 {{.*}} movl -4096(%eax), %eax -# CHECK-NEXT: 401013: 8b 83 {{.*}} movl -4096(%ebx), %eax +# CHECK-NEXT: 401115: 8b 05 {{.*}} movl 4202800, %eax +# CHECK-NEXT: 40111b: 8b 1d {{.*}} movl 4202800, %ebx +# CHECK-NEXT: 401121: 8b 80 {{.*}} movl -4100(%eax), %eax +# CHECK-NEXT: 401127: 8b 83 {{.*}} movl -4100(%ebx), %eax # CHECK: Sections: # CHECK: Name Size VMA -# CHECK: .got.plt 0000000c 0000000000403000 +# CHECK: .got.plt 0000000c 0000000000403134 # RUN: not ld.lld %S/Inputs/i386-got32x-baseless.elf -o %t1 -pie 2>&1 | \ # RUN: FileCheck %s --check-prefix=ERR -# ERR: error: can't create dynamic relocation R_386_GOT32X against symbol: foo in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output -# ERR: error: can't create dynamic relocation R_386_GOT32X against symbol: foo in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output +# ERR-COUNT-2: error: symbol 'foo' cannot be preempted; recompile with -fPIE diff --git a/test/ELF/hexagon-gotrel.s b/test/ELF/hexagon-gotrel.s new file mode 100644 index 000000000..52edc0dc5 --- /dev/null +++ b/test/ELF/hexagon-gotrel.s @@ -0,0 +1,27 @@ +# REQUIRES: hexagon +# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %S/Inputs/hexagon-shared.s -o %t2.o +# RUN: ld.lld -shared %t2.o -o %t2.so +# RUN: ld.lld -shared %t.o %t2.so -o %t3.so +# RUN: llvm-objdump --print-imm-hex -d -j .text %t3.so | FileCheck --check-prefix=TEXT %s + +.global foo +foo: + +.Lpc: + +# R_HEX_GOTREL_LO16 + r0.l = #LO(.Lpc@GOTREL) +# R_HEX_GOTREL_HI16 + r0.h = #HI(.Lpc@GOTREL) +# R_HEX_GOTREL_11_X + r0 = memw(r1+##.Lpc@GOTREL) +# R_HEX_GOTREL_32_6_X and R_HEX_GOTREL_16_X + r0 = ##(.Lpc@GOTREL) + +# TEXT: r0.l = #0x0 } +# TEXT: r0.h = #0xfffe } +# TEXT: immext(#0xfffe0000) +# TEXT: r0 = memw(r1+##-0x20000) } +# TEXT: immext(#0xfffe0000) +# TEXT: r0 = ##-0x20000 } diff --git a/test/ELF/hexagon-shared.s b/test/ELF/hexagon-shared.s index caf872c34..98a5f2ddb 100644 --- a/test/ELF/hexagon-shared.s +++ b/test/ELF/hexagon-shared.s @@ -6,6 +6,7 @@ # RUN: llvm-objdump -d -j .plt %t4.so | FileCheck --check-prefix=PLT %s # RUN: llvm-objdump -d -j .text %t4.so | FileCheck --check-prefix=TEXT %s # RUN: llvm-objdump -D -j .got %t4.so | FileCheck --check-prefix=GOT %s +# RUN: llvm-readelf -r %t4.so | FileCheck --check-prefix=RELO %s .global foo foo: @@ -25,8 +26,22 @@ jumpr r0 # R_HEX_GOT_16_X r0 = add(r1,##bar@GOT) +# R_HEX_32 +.data +.global var +.type var,@object +.p2align 2 +var: + .word 10 + .size var, 4 +.global pvar +.type pvar,@object +pvar: + .word var + .size pvar, 4 + # PLT: { immext(#131008 -# PLT: r28 = add(pc,##131024) } +# PLT: r28 = add(pc,##131032) } # PLT: { r14 -= add(r28,#16) # PLT: r15 = memw(r28+#8) # PLT: r28 = memw(r28+#4) } @@ -34,13 +49,17 @@ r0 = add(r1,##bar@GOT) # PLT: jumpr r28 } # PLT: { trap0(#219) } # PLT: immext(#131008) -# PLT: r14 = add(pc,##131008) } +# PLT: r14 = add(pc,##131016) } # PLT: r28 = memw(r14+#0) } # PLT: jumpr r28 } # TEXT: 10000: 00 00 01 00 00010000 # TEXT: { call 0x10050 } -# TEXT: r0 = add(r1,##-65408) } +# TEXT: r0 = add(r1,##-65416) } # GOT: .got: # GOT: 20080: 00 00 00 00 00000000 + +# RELO: 00020080 00000121 R_HEX_GLOB_DAT +# RELO: 00030004 00000406 R_HEX_32 +# RELO: 00030018 00000122 R_HEX_JMP_SLOT diff --git a/test/ELF/i386-gotoff-shared.s b/test/ELF/i386-gotoff-shared.s index 59369b3e3..de9cb0529 100644 --- a/test/ELF/i386-gotoff-shared.s +++ b/test/ELF/i386-gotoff-shared.s @@ -1,15 +1,15 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o -// RUN: ld.lld --hash-style=sysv %t.o -o %t.so -shared +// RUN: ld.lld %t.o -o %t.so -shared // RUN: llvm-readelf -S %t.so | FileCheck %s -// RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=DISASM %s +// RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=DISASM %s bar: movl bar@GOTOFF(%ebx), %eax mov bar@GOT, %eax -// CHECK: .got.plt PROGBITS 00003000 +// CHECK: .got.plt PROGBITS 000031e0 -// 0x1000 - 0x3000 (.got.plt) = -8192 +// 0x1178 - 0x31e0 (.got.plt) = -8296 -// DISASM: 1000: {{.*}} movl -8192(%ebx), %eax +// DISASM: 1178: movl -8296(%ebx), %eax diff --git a/test/ELF/i386-gotpc-dynamic.s b/test/ELF/i386-gotpc-dynamic.s index c75f0bef4..2292823e7 100644 --- a/test/ELF/i386-gotpc-dynamic.s +++ b/test/ELF/i386-gotpc-dynamic.s @@ -4,10 +4,10 @@ # RUN: llvm-readelf -S %t.so | FileCheck %s # RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=DISASM %s -# CHECK: .got.plt PROGBITS 00003000 +# CHECK: .got.plt PROGBITS 00003190 -## 0x3000 - 0x1000 = 8192 -# DISASM: 1000: {{.*}} movl $8192, %eax +## 0x3190 - 0x1158 = 8248 +# DISASM: 1158: {{.*}} movl $8248, %eax .section .foo,"ax",@progbits foo: diff --git a/test/ELF/i386-gotpc.s b/test/ELF/i386-gotpc.s index 47f303ebd..14528351b 100644 --- a/test/ELF/i386-gotpc.s +++ b/test/ELF/i386-gotpc.s @@ -2,14 +2,14 @@ // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o // RUN: ld.lld --hash-style=sysv %t.o -o %t.so -shared // RUN: llvm-readelf -S %t.so | FileCheck %s -// RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=DISASM %s +// RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=DISASM %s movl $_GLOBAL_OFFSET_TABLE_, %eax -// CHECK: .got.plt PROGBITS 00003000 +// CHECK: .got.plt PROGBITS 00003190 // DISASM: Disassembly of section .text: // DISASM-EMPTY: // DISASM-NEXT: .text: -// DISASM-NEXT: 1000: {{.*}} movl $8192, %eax -// 0x3000 (.got.plt) - 0x1000 = 8192 +// DISASM-NEXT: 1158: movl $8248, %eax +// ^-- 0x3190 (.got.plt) - 0x1158 = 8248 diff --git a/test/ELF/i386-merge.s b/test/ELF/i386-merge.s index 0bda9e87d..2848bd9af 100644 --- a/test/ELF/i386-merge.s +++ b/test/ELF/i386-merge.s @@ -27,8 +27,8 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x2000 -// CHECK-NEXT: Offset: 0x2000 +// CHECK-NEXT: Address: 0x31D4 +// CHECK-NEXT: Offset: 0x1D4 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 diff --git a/test/ELF/i386-pc8-pc16-addend.s b/test/ELF/i386-pc8-pc16-addend.s index 8dad18fb2..7a4d208f7 100644 --- a/test/ELF/i386-pc8-pc16-addend.s +++ b/test/ELF/i386-pc8-pc16-addend.s @@ -4,11 +4,11 @@ # RUN: ld.lld %t1.o -o %t.out # RUN: llvm-objdump -s -t %t.out | FileCheck %s # CHECK: Contents of section .text: -# CHECK-NEXT: 401000 020000 -## 0x401003 - 0x401000 + addend(-1) = 0x02 -## 0x401003 - 0x401001 + addend(-2) = 0x0000 +# CHECK-NEXT: 4010b4 020000 +## 0x4010b7 - 0x4010b4 + addend(-1) = 0x02 +## 0x4010b7 - 0x4010b5 + addend(-2) = 0x0000 # CHECK: SYMBOL TABLE: -# CHECK: 00401003 .und +# CHECK: 004010b7 .und .byte und-.-1 .short und-.-2 diff --git a/test/ELF/i386-relax-reloc.s b/test/ELF/i386-relax-reloc.s index 8aeb53fa9..a230d658d 100644 --- a/test/ELF/i386-relax-reloc.s +++ b/test/ELF/i386-relax-reloc.s @@ -2,15 +2,14 @@ // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o -relax-relocations // RUN: ld.lld -shared %t.o -o %t.so // RUN: llvm-readelf -S %t.so | FileCheck --check-prefix=SEC %s -// RUN: llvm-objdump -d %t.so | FileCheck %s +// RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck %s -// SEC: .got PROGBITS 00002050 -// SEC-NEXT: .got.plt PROGBITS 00003000 +// SEC: .got PROGBITS 000021f0 +// SEC-NEXT: .got.plt PROGBITS 000031f4 -// 0x2050 - 0x3000 = -4016 // CHECK: foo: -// CHECK-NEXT: movl -4016(%ebx), %eax -// CHECK-NEXT: movl -4008(%ebx), %eax +// CHECK-NEXT: 1194: movl -4100(%ebx), %eax +// CHECK-NEXT: movl -4092(%ebx), %eax foo: movl bar@GOT(%ebx), %eax diff --git a/test/ELF/i386-reloc-range.s b/test/ELF/i386-reloc-range.s index c670b0d3b..758cc491b 100644 --- a/test/ELF/i386-reloc-range.s +++ b/test/ELF/i386-reloc-range.s @@ -7,12 +7,12 @@ // RUN: llvm-mc %t2.s -o %t2.o -triple i386-pc-linux -filetype=obj // RUN: ld.lld -Ttext 0x200 %t.o %t1.o -o %t1 -// RUN: llvm-objdump -d -triple=i386-pc-linux-code16 %t1 | FileCheck %s +// RUN: llvm-objdump -d --no-show-raw-insn -triple=i386-pc-linux-code16 %t1 | FileCheck %s // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: _start: -// CHECK-NEXT: 200: {{.*}} jmp -1 +// CHECK-NEXT: 200: jmp -1 // 0x10202 - 0x203 == 0xffff // RUN: not ld.lld -Ttext 0x200 %t.o %t2.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s diff --git a/test/ELF/i386-retpoline-nopic-linkerscript.s b/test/ELF/i386-retpoline-nopic-linkerscript.s index 371f78a81..571267e92 100644 --- a/test/ELF/i386-retpoline-nopic-linkerscript.s +++ b/test/ELF/i386-retpoline-nopic-linkerscript.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux %s -o %t1.o // RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux %p/Inputs/shared.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -shared -soname=t2.so %t2.o -o %t2.so // RUN: echo "SECTIONS { \ // RUN: .text : { *(.text) } \ @@ -10,57 +10,57 @@ // RUN: .dynstr : { *(.dynstr) } \ // RUN: }" > %t.script // RUN: ld.lld %t1.o %t2.so -o %t.exe -z retpolineplt --script %t.script -// RUN: llvm-objdump -d -s %t.exe | FileCheck %s +// RUN: llvm-objdump -d -s --no-show-raw-insn %t.exe | FileCheck %s // CHECK: Disassembly of section .plt: // CHECK-EMPTY: // CHECK-NEXT: .plt: -// CHECK-NEXT: 10: ff 35 ec 00 00 00 pushl 236 -// CHECK-NEXT: 16: 50 pushl %eax -// CHECK-NEXT: 17: a1 f0 00 00 00 movl 240, %eax -// CHECK-NEXT: 1c: e8 0f 00 00 00 calll 15 <.plt+0x20> -// CHECK-NEXT: 21: f3 90 pause -// CHECK-NEXT: 23: 0f ae e8 lfence -// CHECK-NEXT: 26: eb f9 jmp -7 <.plt+0x11> -// CHECK-NEXT: 28: cc int3 -// CHECK-NEXT: 29: cc int3 -// CHECK-NEXT: 2a: cc int3 -// CHECK-NEXT: 2b: cc int3 -// CHECK-NEXT: 2c: cc int3 -// CHECK-NEXT: 2d: cc int3 -// CHECK-NEXT: 2e: cc int3 -// CHECK-NEXT: 2f: cc int3 -// CHECK-NEXT: 30: 89 0c 24 movl %ecx, (%esp) -// CHECK-NEXT: 33: 8b 4c 24 04 movl 4(%esp), %ecx -// CHECK-NEXT: 37: 89 44 24 04 movl %eax, 4(%esp) -// CHECK-NEXT: 3b: 89 c8 movl %ecx, %eax -// CHECK-NEXT: 3d: 59 popl %ecx -// CHECK-NEXT: 3e: c3 retl -// CHECK-NEXT: 3f: cc int3 -// CHECK-NEXT: 40: 50 pushl %eax -// CHECK-NEXT: 41: a1 f4 00 00 00 movl 244, %eax -// CHECK-NEXT: 46: e8 e5 ff ff ff calll -27 <.plt+0x20> -// CHECK-NEXT: 4b: e9 d1 ff ff ff jmp -47 <.plt+0x11> -// CHECK-NEXT: 50: 68 00 00 00 00 pushl $0 -// CHECK-NEXT: 55: e9 b6 ff ff ff jmp -74 <.plt> -// CHECK-NEXT: 5a: cc int3 -// CHECK-NEXT: 5b: cc int3 -// CHECK-NEXT: 5c: cc int3 -// CHECK-NEXT: 5d: cc int3 -// CHECK-NEXT: 5e: cc int3 -// CHECK-NEXT: 5f: cc int3 -// CHECK-NEXT: 60: 50 pushl %eax -// CHECK-NEXT: 61: a1 f8 00 00 00 movl 248, %eax -// CHECK-NEXT: 66: e8 c5 ff ff ff calll -59 <.plt+0x20> -// CHECK-NEXT: 6b: e9 b1 ff ff ff jmp -79 <.plt+0x11> -// CHECK-NEXT: 70: 68 08 00 00 00 pushl $8 -// CHECK-NEXT: 75: e9 96 ff ff ff jmp -106 <.plt> -// CHECK-NEXT: 7a: cc int3 -// CHECK-NEXT: 7b: cc int3 -// CHECK-NEXT: 7c: cc int3 -// CHECK-NEXT: 7d: cc int3 -// CHECK-NEXT: 7e: cc int3 -// CHECK-NEXT: 7f: cc int3 +// CHECK-NEXT: 10: pushl 236 +// CHECK-NEXT: 16: pushl %eax +// CHECK-NEXT: 17: movl 240, %eax +// CHECK-NEXT: 1c: calll 15 <.plt+0x20> +// CHECK-NEXT: 21: pause +// CHECK-NEXT: 23: lfence +// CHECK-NEXT: 26: jmp -7 <.plt+0x11> +// CHECK-NEXT: 28: int3 +// CHECK-NEXT: 29: int3 +// CHECK-NEXT: 2a: int3 +// CHECK-NEXT: 2b: int3 +// CHECK-NEXT: 2c: int3 +// CHECK-NEXT: 2d: int3 +// CHECK-NEXT: 2e: int3 +// CHECK-NEXT: 2f: int3 +// CHECK-NEXT: 30: movl %ecx, (%esp) +// CHECK-NEXT: 33: movl 4(%esp), %ecx +// CHECK-NEXT: 37: movl %eax, 4(%esp) +// CHECK-NEXT: 3b: movl %ecx, %eax +// CHECK-NEXT: 3d: popl %ecx +// CHECK-NEXT: 3e: retl +// CHECK-NEXT: 3f: int3 +// CHECK-NEXT: 40: pushl %eax +// CHECK-NEXT: 41: movl 244, %eax +// CHECK-NEXT: 46: calll -27 <.plt+0x20> +// CHECK-NEXT: 4b: jmp -47 <.plt+0x11> +// CHECK-NEXT: 50: pushl $0 +// CHECK-NEXT: 55: jmp -74 <.plt> +// CHECK-NEXT: 5a: int3 +// CHECK-NEXT: 5b: int3 +// CHECK-NEXT: 5c: int3 +// CHECK-NEXT: 5d: int3 +// CHECK-NEXT: 5e: int3 +// CHECK-NEXT: 5f: int3 +// CHECK-NEXT: 60: pushl %eax +// CHECK-NEXT: 61: movl 248, %eax +// CHECK-NEXT: 66: calll -59 <.plt+0x20> +// CHECK-NEXT: 6b: jmp -79 <.plt+0x11> +// CHECK-NEXT: 70: pushl $8 +// CHECK-NEXT: 75: jmp -106 <.plt> +// CHECK-NEXT: 7a: int3 +// CHECK-NEXT: 7b: int3 +// CHECK-NEXT: 7c: int3 +// CHECK-NEXT: 7d: int3 +// CHECK-NEXT: 7e: int3 +// CHECK-NEXT: 7f: int3 .global _start _start: diff --git a/test/ELF/i386-retpoline-nopic.s b/test/ELF/i386-retpoline-nopic.s index dd3cc6bd9..4520d9ec5 100644 --- a/test/ELF/i386-retpoline-nopic.s +++ b/test/ELF/i386-retpoline-nopic.s @@ -1,64 +1,64 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux %s -o %t1.o // RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux %p/Inputs/shared.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -shared -soname=t2.so %t2.o -o %t2.so // RUN: ld.lld %t1.o %t2.so -o %t.exe -z retpolineplt -// RUN: llvm-objdump -d -s %t.exe | FileCheck %s +// RUN: llvm-objdump -d -s --no-show-raw-insn %t.exe | FileCheck %s // CHECK: Disassembly of section .plt: // CHECK-EMPTY: // CHECK-NEXT: .plt: -// CHECK-NEXT: 401010: ff 35 04 30 40 00 pushl 4206596 -// CHECK-NEXT: 401016: 50 pushl %eax -// CHECK-NEXT: 401017: a1 08 30 40 00 movl 4206600, %eax -// CHECK-NEXT: 40101c: e8 0f 00 00 00 calll 15 <.plt+0x20> -// CHECK-NEXT: 401021: f3 90 pause -// CHECK-NEXT: 401023: 0f ae e8 lfence -// CHECK-NEXT: 401026: eb f9 jmp -7 <.plt+0x11> -// CHECK-NEXT: 401028: cc int3 -// CHECK-NEXT: 401029: cc int3 -// CHECK-NEXT: 40102a: cc int3 -// CHECK-NEXT: 40102b: cc int3 -// CHECK-NEXT: 40102c: cc int3 -// CHECK-NEXT: 40102d: cc int3 -// CHECK-NEXT: 40102e: cc int3 -// CHECK-NEXT: 40102f: cc int3 -// CHECK-NEXT: 401030: 89 0c 24 movl %ecx, (%esp) -// CHECK-NEXT: 401033: 8b 4c 24 04 movl 4(%esp), %ecx -// CHECK-NEXT: 401037: 89 44 24 04 movl %eax, 4(%esp) -// CHECK-NEXT: 40103b: 89 c8 movl %ecx, %eax -// CHECK-NEXT: 40103d: 59 popl %ecx -// CHECK-NEXT: 40103e: c3 retl -// CHECK-NEXT: 40103f: cc int3 -// CHECK-NEXT: 401040: 50 pushl %eax -// CHECK-NEXT: 401041: a1 0c 30 40 00 movl 4206604, %eax -// CHECK-NEXT: 401046: e8 e5 ff ff ff calll -27 <.plt+0x20> -// CHECK-NEXT: 40104b: e9 d1 ff ff ff jmp -47 <.plt+0x11> -// CHECK-NEXT: 401050: 68 00 00 00 00 pushl $0 -// CHECK-NEXT: 401055: e9 b6 ff ff ff jmp -74 <.plt> -// CHECK-NEXT: 40105a: cc int3 -// CHECK-NEXT: 40105b: cc int3 -// CHECK-NEXT: 40105c: cc int3 -// CHECK-NEXT: 40105d: cc int3 -// CHECK-NEXT: 40105e: cc int3 -// CHECK-NEXT: 40105f: cc int3 -// CHECK-NEXT: 401060: 50 pushl %eax -// CHECK-NEXT: 401061: a1 10 30 40 00 movl 4206608, %eax -// CHECK-NEXT: 401066: e8 c5 ff ff ff calll -59 <.plt+0x20> -// CHECK-NEXT: 40106b: e9 b1 ff ff ff jmp -79 <.plt+0x11> -// CHECK-NEXT: 401070: 68 08 00 00 00 pushl $8 -// CHECK-NEXT: 401075: e9 96 ff ff ff jmp -106 <.plt> -// CHECK-NEXT: 40107a: cc int3 -// CHECK-NEXT: 40107b: cc int3 -// CHECK-NEXT: 40107c: cc int3 -// CHECK-NEXT: 40107d: cc int3 -// CHECK-NEXT: 40107e: cc int3 -// CHECK-NEXT: 40107f: cc int3 +// CHECK-NEXT: 4011d0: pushl 4207276 +// CHECK-NEXT: 4011d6: pushl %eax +// CHECK-NEXT: 4011d7: movl 4207280, %eax +// CHECK-NEXT: 4011dc: calll 15 <.plt+0x20> +// CHECK-NEXT: 4011e1: pause +// CHECK-NEXT: 4011e3: lfence +// CHECK-NEXT: 4011e6: jmp -7 <.plt+0x11> +// CHECK-NEXT: 4011e8: int3 +// CHECK-NEXT: 4011e9: int3 +// CHECK-NEXT: 4011ea: int3 +// CHECK-NEXT: 4011eb: int3 +// CHECK-NEXT: 4011ec: int3 +// CHECK-NEXT: 4011ed: int3 +// CHECK-NEXT: 4011ee: int3 +// CHECK-NEXT: 4011ef: int3 +// CHECK-NEXT: 4011f0: movl %ecx, (%esp) +// CHECK-NEXT: 4011f3: movl 4(%esp), %ecx +// CHECK-NEXT: 4011f7: movl %eax, 4(%esp) +// CHECK-NEXT: 4011fb: movl %ecx, %eax +// CHECK-NEXT: 4011fd: popl %ecx +// CHECK-NEXT: 4011fe: retl +// CHECK-NEXT: 4011ff: int3 +// CHECK-NEXT: 401200: pushl %eax +// CHECK-NEXT: 401201: movl 4207284, %eax +// CHECK-NEXT: 401206: calll -27 <.plt+0x20> +// CHECK-NEXT: 40120b: jmp -47 <.plt+0x11> +// CHECK-NEXT: 401210: pushl $0 +// CHECK-NEXT: 401215: jmp -74 <.plt> +// CHECK-NEXT: 40121a: int3 +// CHECK-NEXT: 40121b: int3 +// CHECK-NEXT: 40121c: int3 +// CHECK-NEXT: 40121d: int3 +// CHECK-NEXT: 40121e: int3 +// CHECK-NEXT: 40121f: int3 +// CHECK-NEXT: 401220: pushl %eax +// CHECK-NEXT: 401221: movl 4207288, %eax +// CHECK-NEXT: 401226: calll -59 <.plt+0x20> +// CHECK-NEXT: 40122b: jmp -79 <.plt+0x11> +// CHECK-NEXT: 401230: pushl $8 +// CHECK-NEXT: 401235: jmp -106 <.plt> +// CHECK-NEXT: 40123a: int3 +// CHECK-NEXT: 40123b: int3 +// CHECK-NEXT: 40123c: int3 +// CHECK-NEXT: 40123d: int3 +// CHECK-NEXT: 40123e: int3 +// CHECK-NEXT: 40123f: int3 // CHECK: Contents of section .got.plt: -// CHECK-NEXT: 00204000 00000000 00000000 50104000 -// CHECK-NEXT: 70104000 +// CHECK-NEXT: 40224000 00000000 00000000 10124000 +// CHECK-NEXT: 30124000 .global _start _start: diff --git a/test/ELF/i386-retpoline-pic.s b/test/ELF/i386-retpoline-pic.s index ee31762de..f7eb07928 100644 --- a/test/ELF/i386-retpoline-pic.s +++ b/test/ELF/i386-retpoline-pic.s @@ -1,61 +1,61 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux -position-independent %s -o %t1.o // RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux -position-independent %p/Inputs/shared.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -shared -soname=t2.so %t2.o -o %t2.so // RUN: ld.lld %t1.o %t2.so -o %t.exe -z retpolineplt -pie -// RUN: llvm-objdump -d -s %t.exe | FileCheck %s +// RUN: llvm-objdump -d -s --no-show-raw-insn %t.exe | FileCheck %s // CHECK: Disassembly of section .plt: // CHECK-EMPTY: // CHECK-NEXT: .plt: -// CHECK-NEXT: 1010: ff b3 04 00 00 00 pushl 4(%ebx) -// CHECK-NEXT: 1016: 50 pushl %eax -// CHECK-NEXT: 1017: 8b 83 08 00 00 00 movl 8(%ebx), %eax -// CHECK-NEXT: 101d: e8 0e 00 00 00 calll 14 <.plt+0x20> -// CHECK-NEXT: 1022: f3 90 pause -// CHECK-NEXT: 1024: 0f ae e8 lfence -// CHECK-NEXT: 1027: eb f9 jmp -7 <.plt+0x12> -// CHECK-NEXT: 1029: cc int3 -// CHECK-NEXT: 102a: cc int3 -// CHECK-NEXT: 102b: cc int3 -// CHECK-NEXT: 102c: cc int3 -// CHECK-NEXT: 102d: cc int3 -// CHECK-NEXT: 102e: cc int3 -// CHECK-NEXT: 102f: cc int3 -// CHECK-NEXT: 1030: 89 0c 24 movl %ecx, (%esp) -// CHECK-NEXT: 1033: 8b 4c 24 04 movl 4(%esp), %ecx -// CHECK-NEXT: 1037: 89 44 24 04 movl %eax, 4(%esp) -// CHECK-NEXT: 103b: 89 c8 movl %ecx, %eax -// CHECK-NEXT: 103d: 59 popl %ecx -// CHECK-NEXT: 103e: c3 retl -// CHECK-NEXT: 103f: cc int3 -// CHECK-NEXT: 1040: 50 pushl %eax -// CHECK-NEXT: 1041: 8b 83 0c 00 00 00 movl 12(%ebx), %eax -// CHECK-NEXT: 1047: e8 e4 ff ff ff calll -28 <.plt+0x20> -// CHECK-NEXT: 104c: e9 d1 ff ff ff jmp -47 <.plt+0x12> -// CHECK-NEXT: 1051: 68 00 00 00 00 pushl $0 -// CHECK-NEXT: 1056: e9 b5 ff ff ff jmp -75 <.plt> -// CHECK-NEXT: 105b: cc int3 -// CHECK-NEXT: 105c: cc int3 -// CHECK-NEXT: 105d: cc int3 -// CHECK-NEXT: 105e: cc int3 -// CHECK-NEXT: 105f: cc int3 -// CHECK-NEXT: 1060: 50 pushl %eax -// CHECK-NEXT: 1061: 8b 83 10 00 00 00 movl 16(%ebx), %eax -// CHECK-NEXT: 1067: e8 c4 ff ff ff calll -60 <.plt+0x20> -// CHECK-NEXT: 106c: e9 b1 ff ff ff jmp -79 <.plt+0x12> -// CHECK-NEXT: 1071: 68 08 00 00 00 pushl $8 -// CHECK-NEXT: 1076: e9 95 ff ff ff jmp -107 <.plt> -// CHECK-NEXT: 107b: cc int3 -// CHECK-NEXT: 107c: cc int3 -// CHECK-NEXT: 107d: cc int3 -// CHECK-NEXT: 107e: cc int3 -// CHECK-NEXT: 107f: cc int3 +// CHECK-NEXT: 11d0: pushl 4(%ebx) +// CHECK-NEXT: 11d6: pushl %eax +// CHECK-NEXT: 11d7: movl 8(%ebx), %eax +// CHECK-NEXT: 11dd: calll 14 <.plt+0x20> +// CHECK-NEXT: 11e2: pause +// CHECK-NEXT: 11e4: lfence +// CHECK-NEXT: 11e7: jmp -7 <.plt+0x12> +// CHECK-NEXT: 11e9: int3 +// CHECK-NEXT: 11ea: int3 +// CHECK-NEXT: 11eb: int3 +// CHECK-NEXT: 11ec: int3 +// CHECK-NEXT: 11ed: int3 +// CHECK-NEXT: 11ee: int3 +// CHECK-NEXT: 11ef: int3 +// CHECK-NEXT: 11f0: movl %ecx, (%esp) +// CHECK-NEXT: 11f3: movl 4(%esp), %ecx +// CHECK-NEXT: 11f7: movl %eax, 4(%esp) +// CHECK-NEXT: 11fb: movl %ecx, %eax +// CHECK-NEXT: 11fd: popl %ecx +// CHECK-NEXT: 11fe: retl +// CHECK-NEXT: 11ff: int3 +// CHECK-NEXT: 1200: pushl %eax +// CHECK-NEXT: 1201: movl 12(%ebx), %eax +// CHECK-NEXT: 1207: calll -28 <.plt+0x20> +// CHECK-NEXT: 120c: jmp -47 <.plt+0x12> +// CHECK-NEXT: 1211: pushl $0 +// CHECK-NEXT: 1216: jmp -75 <.plt> +// CHECK-NEXT: 121b: int3 +// CHECK-NEXT: 121c: int3 +// CHECK-NEXT: 121d: int3 +// CHECK-NEXT: 121e: int3 +// CHECK-NEXT: 121f: int3 +// CHECK-NEXT: 1220: pushl %eax +// CHECK-NEXT: 1221: movl 16(%ebx), %eax +// CHECK-NEXT: 1227: calll -60 <.plt+0x20> +// CHECK-NEXT: 122c: jmp -79 <.plt+0x12> +// CHECK-NEXT: 1231: pushl $8 +// CHECK-NEXT: 1236: jmp -107 <.plt> +// CHECK-NEXT: 123b: int3 +// CHECK-NEXT: 123c: int3 +// CHECK-NEXT: 123d: int3 +// CHECK-NEXT: 123e: int3 +// CHECK-NEXT: 123f: int3 // CHECK: Contents of section .got.plt: -// CHECK-NEXT: 3000 00200000 00000000 00000000 51100000 -// CHECK-NEXT: 3010 71100000 +// CHECK-NEXT: 32a8 40220000 00000000 00000000 11120000 +// CHECK-NEXT: 32b8 31120000 .global _start _start: diff --git a/test/ELF/i386-tls-dynamic.s b/test/ELF/i386-tls-dynamic.s new file mode 100644 index 000000000..0b47087eb --- /dev/null +++ b/test/ELF/i386-tls-dynamic.s @@ -0,0 +1,100 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i686 %s -o %t.o +# RUN: ld.lld -shared %t.o -o %t.so +# RUN: llvm-readobj --sections -r %t.so | FileCheck %s +# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck %s --check-prefix=DIS + +.type tls0,@object +.section .tbss,"awT",@nobits +.globl tls0 +.align 4 +tls0: + .long 0 + .size tls0, 4 + +.type tls1,@object +.globl tls1 +.align 4 +tls1: + .long 0 + .size tls1, 4 + +.type tls2,@object +.globl tls2 +.hidden tls2 +.align 4 +tls2: + .long 0 + .size tls2, 8 + +.section .text +.globl _start +_start: +leal tls0@tlsgd(,%ebx,1),%eax +call __tls_get_addr@plt + +leal tls1@tlsgd(,%ebx,1),%eax +call __tls_get_addr@plt + +leal tls2@tlsldm(%ebx),%eax +call __tls_get_addr@plt +leal tls2@dtpoff(%eax),%edx + +leal tls2@tlsldm(%ebx),%eax +call __tls_get_addr@plt +leal tls2@dtpoff+4(%eax),%edx + +movl %gs:0,%eax +addl tls0@gotntpoff(%ebx),%eax + +movl %gs:0,%eax +addl tls1@gotntpoff(%ebx),%eax + +# CHECK: Name: .got ( +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x2358 +# CHECK-NEXT: Offset: 0x358 +# CHECK-NEXT: Size: 32 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 0 + +# CHECK: Relocations [ +# CHECK: Section ({{.+}}) .rel.dyn { +# CHECK-NEXT: 0x2368 R_386_TLS_DTPMOD32 - 0x0 +# CHECK-NEXT: 0x2358 R_386_TLS_DTPMOD32 tls0 0x0 +# CHECK-NEXT: 0x235C R_386_TLS_DTPOFF32 tls0 0x0 +# CHECK-NEXT: 0x2370 R_386_TLS_TPOFF tls0 0x0 +# CHECK-NEXT: 0x2360 R_386_TLS_DTPMOD32 tls1 0x0 +# CHECK-NEXT: 0x2364 R_386_TLS_DTPOFF32 tls1 0x0 +# CHECK-NEXT: 0x2374 R_386_TLS_TPOFF tls1 0x0 +# CHECK-NEXT: } + +# DIS: Disassembly of section .text: +# DIS-EMPTY: +# DIS-NEXT: _start: +## General dynamic model: +## -4128 and -4120 are first and second GOT entries offsets. +## Each one is a pair of records. +# DIS-NEXT: 1260: leal -4128(,%ebx), %eax +# DIS-NEXT: 1267: calll 100 +# DIS-NEXT: 126c: leal -4120(,%ebx), %eax +# DIS-NEXT: 1273: calll 88 +## Local dynamic model: +## -16 is a local module tls index offset. +# DIS-NEXT: 1278: leal -4112(%ebx), %eax +# DIS-NEXT: 127e: calll 77 +# DIS-NEXT: 1283: leal 8(%eax), %edx +# DIS-NEXT: 1289: leal -4112(%ebx), %eax +# DIS-NEXT: 128f: calll 60 +# DIS-NEXT: 1294: leal 12(%eax), %edx +## Initial exec model: +# DIS-NEXT: 129a: movl %gs:0, %eax +# DIS-NEXT: 12a0: addl -4104(%ebx), %eax +# DIS-NEXT: 12a6: movl %gs:0, %eax +# DIS-NEXT: 12ac: addl -4100(%ebx), %eax diff --git a/test/ELF/i386-tls-gdiele.s b/test/ELF/i386-tls-gdiele.s new file mode 100644 index 000000000..303f18720 --- /dev/null +++ b/test/ELF/i386-tls-gdiele.s @@ -0,0 +1,61 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=i686 %p/Inputs/tls-opt-gdiele-i686.s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=i686 %s -o %t1.o +// RUN: ld.lld -shared %t.o -soname=t.so -o %t.so +// RUN: ld.lld --hash-style=sysv %t1.o %t.so -o %tout +// RUN: llvm-readobj -r %tout | FileCheck --check-prefix=NORELOC %s +// RUN: llvm-objdump -d --no-show-raw-insn %tout | FileCheck --check-prefix=DISASM %s + +// NORELOC: Relocations [ +// NORELOC-NEXT: Section ({{.*}}) .rel.dyn { +// NORELOC-NEXT: 0x402258 R_386_TLS_TPOFF tlsshared0 0x0 +// NORELOC-NEXT: 0x40225C R_386_TLS_TPOFF tlsshared1 0x0 +// NORELOC-NEXT: } +// NORELOC-NEXT: ] + +// DISASM: Disassembly of section .text: +// DISASM-EMPTY: +// DISASM-NEXT: _start: +// DISASM-NEXT: 4011d0: movl %gs:0, %eax +// DISASM-NEXT: addl -4104(%ebx), %eax +// DISASM-NEXT: movl %gs:0, %eax +// DISASM-NEXT: addl -4100(%ebx), %eax +// DISASM-NEXT: movl %gs:0, %eax +// DISASM-NEXT: subl $8, %eax +// DISASM-NEXT: movl %gs:0, %eax +// DISASM-NEXT: subl $4, %eax + +.type tlsexe1,@object +.section .tbss,"awT",@nobits +.globl tlsexe1 +.align 4 +tlsexe1: + .long 0 + .size tlsexe1, 4 + +.type tlsexe2,@object +.section .tbss,"awT",@nobits +.globl tlsexe2 +.align 4 +tlsexe2: + .long 0 + .size tlsexe2, 4 + +.section .text +.globl ___tls_get_addr +.type ___tls_get_addr,@function +___tls_get_addr: + +.section .text +.globl _start +_start: +//GD->IE +leal tlsshared0@tlsgd(,%ebx,1),%eax +call ___tls_get_addr@plt +leal tlsshared1@tlsgd(,%ebx,1),%eax +call ___tls_get_addr@plt +//GD->LE +leal tlsexe1@tlsgd(,%ebx,1),%eax +call ___tls_get_addr@plt +leal tlsexe2@tlsgd(,%ebx,1),%eax +call ___tls_get_addr@plt diff --git a/test/ELF/i386-tls-initial-exec-local.s b/test/ELF/i386-tls-ie-local.s similarity index 100% rename from test/ELF/i386-tls-initial-exec-local.s rename to test/ELF/i386-tls-ie-local.s diff --git a/test/ELF/i386-tls-ie-shared.s b/test/ELF/i386-tls-ie-shared.s index abf5e0c25..ec238b260 100644 --- a/test/ELF/i386-tls-ie-shared.s +++ b/test/ELF/i386-tls-ie-shared.s @@ -1,21 +1,20 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %p/Inputs/tls-opt-iele-i686-nopic.s -o %tso.o -// RUN: ld.lld -shared %tso.o -o %tso -// RUN: ld.lld --hash-style=sysv -shared %t.o %tso -o %t1 +// RUN: ld.lld -shared -soname=t.so %tso.o -o %tso +// RUN: ld.lld -shared %t.o %tso -o %t1 // RUN: llvm-readobj -S -r -d %t1 | FileCheck --check-prefix=GOTRELSHARED %s -// RUN: llvm-objdump -d %t1 | FileCheck --check-prefix=DISASMSHARED %s +// RUN: llvm-objdump -d --no-show-raw-insn %t1 | FileCheck --check-prefix=DISASMSHARED %s // GOTRELSHARED: Section { -// GOTRELSHARED: Index: 8 // GOTRELSHARED: Name: .got // GOTRELSHARED-NEXT: Type: SHT_PROGBITS // GOTRELSHARED-NEXT: Flags [ // GOTRELSHARED-NEXT: SHF_ALLOC // GOTRELSHARED-NEXT: SHF_WRITE // GOTRELSHARED-NEXT: ] -// GOTRELSHARED-NEXT: Address: 0x2060 -// GOTRELSHARED-NEXT: Offset: 0x2060 +// GOTRELSHARED-NEXT: Address: 0x3388 +// GOTRELSHARED-NEXT: Offset: 0x388 // GOTRELSHARED-NEXT: Size: 16 // GOTRELSHARED-NEXT: Link: 0 // GOTRELSHARED-NEXT: Info: 0 @@ -24,18 +23,18 @@ // GOTRELSHARED-NEXT: } // GOTRELSHARED: Relocations [ // GOTRELSHARED-NEXT: Section ({{.*}}) .rel.dyn { -// GOTRELSHARED-NEXT: 0x1002 R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x100A R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x1013 R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x101C R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x1024 R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x102D R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x1036 R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x103F R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x2060 R_386_TLS_TPOFF tlslocal0 0x0 -// GOTRELSHARED-NEXT: 0x2064 R_386_TLS_TPOFF tlslocal1 0x0 -// GOTRELSHARED-NEXT: 0x2068 R_386_TLS_TPOFF tlsshared0 0x0 -// GOTRELSHARED-NEXT: 0x206C R_386_TLS_TPOFF tlsshared1 0x0 +// GOTRELSHARED-NEXT: 0x22DA R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x22E2 R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x22EB R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x22F4 R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x22FC R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x2305 R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x230E R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x2317 R_386_RELATIVE - 0x0 +// GOTRELSHARED-NEXT: 0x3390 R_386_TLS_TPOFF tlsshared0 0x0 +// GOTRELSHARED-NEXT: 0x3394 R_386_TLS_TPOFF tlsshared1 0x0 +// GOTRELSHARED-NEXT: 0x3388 R_386_TLS_TPOFF tlslocal0 0x0 +// GOTRELSHARED-NEXT: 0x338C R_386_TLS_TPOFF tlslocal1 0x0 // GOTRELSHARED-NEXT: } // GOTRELSHARED-NEXT: ] // GOTRELSHARED: 0x6FFFFFFA RELCOUNT 8 @@ -43,26 +42,26 @@ // DISASMSHARED: Disassembly of section test: // DISASMSHARED-EMPTY: // DISASMSHARED-NEXT: _start: -// (.got)[0] = 0x2060 = 8288 -// (.got)[1] = 0x2064 = 8292 -// (.got)[2] = 0x2068 = 8296 -// (.got)[3] = 0x206C = 8300 -// DISASMSHARED-NEXT: 1000: {{.*}} movl 8288, %ecx -// DISASMSHARED-NEXT: 1006: {{.*}} movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 1009: {{.*}} movl 8288, %eax -// DISASMSHARED-NEXT: 100e: {{.*}} movl %gs:(%eax), %eax -// DISASMSHARED-NEXT: 1011: {{.*}} addl 8288, %ecx -// DISASMSHARED-NEXT: 1017: {{.*}} movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 101a: {{.*}} movl 8292, %ecx -// DISASMSHARED-NEXT: 1020: {{.*}} movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 1023: {{.*}} movl 8292, %eax -// DISASMSHARED-NEXT: 1028: {{.*}} movl %gs:(%eax), %eax -// DISASMSHARED-NEXT: 102b: {{.*}} addl 8292, %ecx -// DISASMSHARED-NEXT: 1031: {{.*}} movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 1034: {{.*}} movl 8296, %ecx -// DISASMSHARED-NEXT: 103a: {{.*}} movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 103d: {{.*}} addl 8300, %ecx -// DISASMSHARED-NEXT: 1043: {{.*}} movl %gs:(%ecx), %eax +// (.got)[0] = 0x3388 = 13192 +// (.got)[1] = 13196 +// (.got)[2] = 13200 +// (.got)[3] = 13204 +// DISASMSHARED-NEXT: 22d8: movl 13192, %ecx +// DISASMSHARED-NEXT: 22de: movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 22e1: movl 13192, %eax +// DISASMSHARED-NEXT: 22e6: movl %gs:(%eax), %eax +// DISASMSHARED-NEXT: 22e9: addl 13192, %ecx +// DISASMSHARED-NEXT: 22ef: movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 22f2: movl 13196, %ecx +// DISASMSHARED-NEXT: 22f8: movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 22fb: movl 13196, %eax +// DISASMSHARED-NEXT: 2300: movl %gs:(%eax), %eax +// DISASMSHARED-NEXT: 2303: addl 13196, %ecx +// DISASMSHARED-NEXT: 2309: movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 230c: movl 13200, %ecx +// DISASMSHARED-NEXT: 2312: movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 2315: addl 13204, %ecx +// DISASMSHARED-NEXT: 231b: movl %gs:(%ecx), %eax .type tlslocal0,@object .section .tbss,"awT",@nobits diff --git a/test/ELF/i386-tls-ld-preemptable.s b/test/ELF/i386-tls-ld-preemptable.s index 8f9d91a96..aaec5d52c 100644 --- a/test/ELF/i386-tls-ld-preemptable.s +++ b/test/ELF/i386-tls-ld-preemptable.s @@ -3,7 +3,7 @@ # RUN: ld.lld %t.o -shared -o %t.so # RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck %s -# CHECK: 100b: movl (%eax), %eax +# CHECK: 11ef: movl (%eax), %eax # We used to error on R_386_TLS_LDO_32 to preemptable symbols. # i is STB_GLOBAL and preemptable. diff --git a/test/ELF/i386-tls-le.s b/test/ELF/i386-tls-le.s new file mode 100644 index 000000000..e2e5fa6d0 --- /dev/null +++ b/test/ELF/i386-tls-le.s @@ -0,0 +1,71 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i686 %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: ld.lld %t.o -shared -o %t.so +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefix=DIS +# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC +# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck %s --check-prefix=DISSHARED +# RUN: llvm-readobj -r %t.so | FileCheck %s --check-prefix=RELOCSHARED + +.section ".tdata", "awT", @progbits +.globl var +.globl var1 +var: +.long 0 +var1: +.long 1 + +.section test, "awx" +.global _start +_start: + movl $var@tpoff, %edx + movl %gs:0, %ecx + subl %edx, %eax + movl $var1@tpoff, %edx + movl %gs:0, %ecx + subl %edx, %eax + + movl %gs:0, %ecx + leal var@ntpoff(%ecx), %eax + movl %gs:0, %ecx + leal var1@ntpoff+123(%ecx), %eax + +# DIS: Disassembly of section test: +# DIS-EMPTY: +# DIS-NEXT: _start: +# DIS-NEXT: 402134: movl $8, %edx +# DIS-NEXT: 402139: movl %gs:0, %ecx +# DIS-NEXT: 402140: subl %edx, %eax +# DIS-NEXT: 402142: movl $4, %edx +# DIS-NEXT: 402147: movl %gs:0, %ecx +# DIS-NEXT: 40214e: subl %edx, %eax +# DIS-NEXT: 402150: movl %gs:0, %ecx +# DIS-NEXT: 402157: leal -8(%ecx), %eax +# DIS-NEXT: 40215d: movl %gs:0, %ecx +# DIS-NEXT: 402164: leal 119(%ecx), %eax + +# RELOC: Relocations [ +# RELOC-NEXT: ] + +# DISSHARED: Disassembly of section test: +# DISSHARED-EMPTY: +# DISSHARED-NEXT: _start: +# DISSHARED-NEXT: 2218: movl $0, %edx +# DISSHARED-NEXT: 221d: movl %gs:0, %ecx +# DISSHARED-NEXT: 2224: subl %edx, %eax +# DISSHARED-NEXT: 2226: movl $0, %edx +# DISSHARED-NEXT: 222b: movl %gs:0, %ecx +# DISSHARED-NEXT: 2232: subl %edx, %eax +# DISSHARED-NEXT: 2234: movl %gs:0, %ecx +# DISSHARED-NEXT: 223b: leal (%ecx), %eax +# DISSHARED-NEXT: 2241: movl %gs:0, %ecx +# DISSHARED-NEXT: 2248: leal 123(%ecx), %eax + +# RELOCSHARED: Relocations [ +# RELOCSHARED-NEXT: Section (5) .rel.dyn { +# RELOCSHARED-NEXT: 0x2219 R_386_TLS_TPOFF32 var 0x0 +# RELOCSHARED-NEXT: 0x223D R_386_TLS_TPOFF var 0x0 +# RELOCSHARED-NEXT: 0x2227 R_386_TLS_TPOFF32 var1 0x0 +# RELOCSHARED-NEXT: 0x224A R_386_TLS_TPOFF var1 0x0 +# RELOCSHARED-NEXT: } +# RELOCSHARED-NEXT: ] diff --git a/test/ELF/tls-opt-iele-i686-nopic.s b/test/ELF/i386-tls-opt-iele-nopic.s similarity index 56% rename from test/ELF/tls-opt-iele-i686-nopic.s rename to test/ELF/i386-tls-opt-iele-nopic.s index 41e563c78..b3f36ea91 100644 --- a/test/ELF/tls-opt-iele-i686-nopic.s +++ b/test/ELF/i386-tls-opt-iele-nopic.s @@ -1,10 +1,10 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %p/Inputs/tls-opt-iele-i686-nopic.s -o %tso.o -// RUN: ld.lld -shared %tso.o -o %tso +// RUN: ld.lld -shared %tso.o -soname=t.so -o %tso // RUN: ld.lld --hash-style=sysv %t.o %tso -o %t1 // RUN: llvm-readobj -S -r %t1 | FileCheck --check-prefix=GOTREL %s -// RUN: llvm-objdump -d %t1 | FileCheck --check-prefix=DISASM %s +// RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t1 | FileCheck --check-prefix=DISASM %s // GOTREL: Section { // GOTREL: Index: @@ -14,8 +14,8 @@ // GOTREL-NEXT: SHF_ALLOC // GOTREL-NEXT: SHF_WRITE // GOTREL-NEXT: ] -// GOTREL-NEXT: Address: 0x402060 -// GOTREL-NEXT: Offset: 0x2060 +// GOTREL-NEXT: Address: 0x402258 +// GOTREL-NEXT: Offset: 0x258 // GOTREL-NEXT: Size: 8 // GOTREL-NEXT: Link: 0 // GOTREL-NEXT: Info: 0 @@ -24,34 +24,32 @@ // GOTREL-NEXT: } // GOTREL: Relocations [ // GOTREL-NEXT: Section ({{.*}}) .rel.dyn { -// GOTREL-NEXT: 0x402060 R_386_TLS_TPOFF tlsshared0 0x0 -// GOTREL-NEXT: 0x402064 R_386_TLS_TPOFF tlsshared1 0x0 +// GOTREL-NEXT: 0x402258 R_386_TLS_TPOFF tlsshared0 0x0 +// GOTREL-NEXT: 0x40225C R_386_TLS_TPOFF tlsshared1 0x0 // GOTREL-NEXT: } // GOTREL-NEXT: ] // DISASM: Disassembly of section .text: // DISASM-EMPTY: // DISASM-NEXT: _start: -// 4294967288 = 0xFFFFFFF8 -// 4294967292 = 0xFFFFFFFC -// 4202592 = (.got)[0] = 0x402060 -// 4202596 = (.got)[1] = 0x402064 -// DISASM-NEXT: 401000: {{.*}} movl $4294967288, %ecx -// DISASM-NEXT: 401006: {{.*}} movl %gs:(%ecx), %eax -// DISASM-NEXT: 401009: {{.*}} movl $4294967288, %eax -// DISASM-NEXT: 40100e: {{.*}} movl %gs:(%eax), %eax -// DISASM-NEXT: 401011: {{.*}} addl $4294967288, %ecx -// DISASM-NEXT: 401017: {{.*}} movl %gs:(%ecx), %eax -// DISASM-NEXT: 40101a: {{.*}} movl $4294967292, %ecx -// DISASM-NEXT: 401020: {{.*}} movl %gs:(%ecx), %eax -// DISASM-NEXT: 401023: {{.*}} movl $4294967292, %eax -// DISASM-NEXT: 401028: {{.*}} movl %gs:(%eax), %eax -// DISASM-NEXT: 40102b: {{.*}} addl $4294967292, %ecx -// DISASM-NEXT: 401031: {{.*}} movl %gs:(%ecx), %eax -// DISASM-NEXT: 401034: {{.*}} movl 4202592, %ecx -// DISASM-NEXT: 40103a: {{.*}} movl %gs:(%ecx), %eax -// DISASM-NEXT: 40103d: {{.*}} addl 4202596, %ecx -// DISASM-NEXT: 401043: {{.*}} movl %gs:(%ecx), %eax +// DISASM-NEXT: 4011b0: movl $0xfffffff8, %ecx +// DISASM-NEXT: movl %gs:(%ecx), %eax +// DISASM-NEXT: movl $0xfffffff8, %eax +// DISASM-NEXT: movl %gs:(%eax), %eax +// DISASM-NEXT: addl $0xfffffff8, %ecx +// DISASM-NEXT: movl %gs:(%ecx), %eax +// DISASM-NEXT: movl $0xfffffffc, %ecx +// DISASM-NEXT: movl %gs:(%ecx), %eax +// DISASM-NEXT: movl $0xfffffffc, %eax +// DISASM-NEXT: movl %gs:(%eax), %eax +// DISASM-NEXT: addl $0xfffffffc, %ecx +// DISASM-NEXT: movl %gs:(%ecx), %eax +/// &.got[0] +// DISASM-NEXT: movl 0x402258, %ecx +// DISASM-NEXT: movl %gs:(%ecx), %eax +/// &.got[1] +// DISASM-NEXT: addl 0x40225c, %ecx +// DISASM-NEXT: movl %gs:(%ecx), %eax .type tlslocal0,@object .section .tbss,"awT",@nobits diff --git a/test/ELF/tls-opt-i686.s b/test/ELF/i386-tls-opt.s similarity index 54% rename from test/ELF/tls-opt-i686.s rename to test/ELF/i386-tls-opt.s index 23bad884a..9bc028832 100644 --- a/test/ELF/tls-opt-i686.s +++ b/test/ELF/i386-tls-opt.s @@ -11,25 +11,25 @@ // DISASM-EMPTY: // DISASM-NEXT: _start: // LD -> LE: -// DISASM-NEXT: 401000: 65 a1 00 00 00 00 movl %gs:0, %eax -// DISASM-NEXT: 401006: 90 nop -// DISASM-NEXT: 401007: 8d 74 26 00 leal (%esi,%eiz), %esi -// DISASM-NEXT: 40100b: 8d 90 f8 ff ff ff leal -8(%eax), %edx -// DISASM-NEXT: 401011: 65 a1 00 00 00 00 movl %gs:0, %eax -// DISASM-NEXT: 401017: 90 nop -// DISASM-NEXT: 401018: 8d 74 26 00 leal (%esi,%eiz), %esi -// DISASM-NEXT: 40101c: 8d 90 fc ff ff ff leal -4(%eax), %edx +// DISASM-NEXT: 4010f4: 65 a1 00 00 00 00 movl %gs:0, %eax +// DISASM-NEXT: 4010fa: 90 nop +// DISASM-NEXT: 4010fb: 8d 74 26 00 leal (%esi,%eiz), %esi +// DISASM-NEXT: 4010ff: 8d 90 f8 ff ff ff leal -8(%eax), %edx +// DISASM-NEXT: 401105: 65 a1 00 00 00 00 movl %gs:0, %eax +// DISASM-NEXT: 40110b: 90 nop +// DISASM-NEXT: 40110c: 8d 74 26 00 leal (%esi,%eiz), %esi +// DISASM-NEXT: 401110: 8d 90 fc ff ff ff leal -4(%eax), %edx // IE -> LE: // 4294967288 == 0xFFFFFFF8 // 4294967292 == 0xFFFFFFFC -// DISASM-NEXT: 401022: 65 a1 00 00 00 00 movl %gs:0, %eax -// DISASM-NEXT: 401028: c7 c0 f8 ff ff ff movl $4294967288, %eax -// DISASM-NEXT: 40102e: 65 a1 00 00 00 00 movl %gs:0, %eax -// DISASM-NEXT: 401034: c7 c0 fc ff ff ff movl $4294967292, %eax -// DISASM-NEXT: 40103a: 65 a1 00 00 00 00 movl %gs:0, %eax -// DISASM-NEXT: 401040: 8d 80 f8 ff ff ff leal -8(%eax), %eax -// DISASM-NEXT: 401046: 65 a1 00 00 00 00 movl %gs:0, %eax -// DISASM-NEXT: 40104c: 8d 80 fc ff ff ff leal -4(%eax), %eax +// DISASM-NEXT: 401116: 65 a1 00 00 00 00 movl %gs:0, %eax +// DISASM-NEXT: 40111c: c7 c0 f8 ff ff ff movl $4294967288, %eax +// DISASM-NEXT: 401122: 65 a1 00 00 00 00 movl %gs:0, %eax +// DISASM-NEXT: 401128: c7 c0 fc ff ff ff movl $4294967292, %eax +// DISASM-NEXT: 40112e: 65 a1 00 00 00 00 movl %gs:0, %eax +// DISASM-NEXT: 401134: 8d 80 f8 ff ff ff leal -8(%eax), %eax +// DISASM-NEXT: 40113a: 65 a1 00 00 00 00 movl %gs:0, %eax +// DISASM-NEXT: 401140: 8d 80 fc ff ff ff leal -4(%eax), %eax .type tls0,@object .section .tbss,"awT",@nobits .globl tls0 diff --git a/test/ELF/i386-tls-vaddr-align.s b/test/ELF/i386-tls-vaddr-align.s new file mode 100644 index 000000000..917cdabef --- /dev/null +++ b/test/ELF/i386-tls-vaddr-align.s @@ -0,0 +1,27 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=i386 %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readelf -S -l %t | FileCheck --check-prefix=SEC %s +# RUN: llvm-objdump -d %t | FileCheck --check-prefix=DIS %s + +# SEC: Name Type Address Off Size ES Flg Lk Inf Al +# SEC: .tdata PROGBITS 00402200 000200 000001 00 WAT 0 0 1 +# SEC: .tbss NOBITS 00402300 000201 000008 00 WAT 0 0 256 + +# SEC: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# SEC: TLS 0x000200 0x00402200 0x00402200 0x00001 0x00108 R 0x100 + +## a@tprel = st_value(a) - p_memsz - (-p_vaddr-p_memsz & p_align-1) +## = 0 - 256 - 0 = -256 +# DIS: leal -256(%ecx), %eax + +lea a@ntpoff(%ecx), %eax + +.section .tdata,"awT" +.byte 0 + +.section .tbss,"awT" +.p2align 8 +a: +.quad 0 diff --git a/test/ELF/image-base.s b/test/ELF/image-base.s index bbacb426f..d8c6ba700 100644 --- a/test/ELF/image-base.s +++ b/test/ELF/image-base.s @@ -47,8 +47,8 @@ _start: # CHECK-NEXT: Offset: 0x1000 # CHECK-NEXT: VirtualAddress: 0x1001000 # CHECK-NEXT: PhysicalAddress: 0x1001000 -# CHECK-NEXT: FileSize: 4096 -# CHECK-NEXT: MemSize: 4096 +# CHECK-NEXT: FileSize: 1 +# CHECK-NEXT: MemSize: 1 # CHECK-NEXT: Flags [ (0x5) # CHECK-NEXT: PF_R (0x4) # CHECK-NEXT: PF_X (0x1) diff --git a/test/ELF/invalid/invalid-relocation-aarch64.test b/test/ELF/invalid/invalid-relocation-aarch64.test new file mode 100644 index 000000000..84fe86d99 --- /dev/null +++ b/test/ELF/invalid/invalid-relocation-aarch64.test @@ -0,0 +1,31 @@ +# REQUIRES: aarch64 +# RUN: yaml2obj %s -o %t.o +# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s +# CHECK: error: unknown relocation (1024) against symbol foo +# CHECK: error: unknown relocation (1025) against symbol foo + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_AARCH64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + Info: .text + Relocations: + - Offset: 0x0000000000000000 + Symbol: foo + Type: 0x400 + - Offset: 0x0000000000000000 + Symbol: foo + Type: 0x401 +Symbols: + - Name: foo + Section: .text + Binding: STB_GLOBAL diff --git a/test/ELF/linkerscript/Inputs/arm-thunk-many-passes.s b/test/ELF/linkerscript/Inputs/arm-thunk-many-passes.s new file mode 100644 index 000000000..d3fa0f6b8 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/arm-thunk-many-passes.s @@ -0,0 +1,70 @@ +// An example of thunk generation that takes the maximum number of permitted +// passes to converge. We start with a set of branches of which all but one are +// in range. Any thunk added to extend the range of a branch is inserted in +// between the branches and the targets which knocks some more branches out +// of range. At the end of 9 passes of createThunks() every branch has a +// range extension thunk, allowing the final pass to check that no more thunks +// are required. +// +// As the size of the .text section changes 9 times, the symbol sym which +// depends on the size of .text will be updated 9 times. This test checks that +// any iteration limit to updating symbols does not limit thunk convergence. +// up to its pass limit without + + .thumb + .section .text.00, "ax", %progbits + .globl _start + .thumb_func +_start: b.w f2 + b.w f2 + b.w f3 + b.w f3 + b.w f4 + b.w f4 + b.w f5 + b.w f5 + b.w f6 + b.w f6 + b.w f7 + b.w f7 + b.w f8 + b.w f8 + b.w f9 + b.w f9 + b.w f10 + b.w f10 + + .section .text.01, "ax", %progbits + .space 14 * 1024 * 1024 +// Thunks are inserted here, initially only 1 branch is out of range and needs +// a thunk. However the added thunk is 4-bytes in size which makes another +// branch out of range, which adds another thunk ... + .section .text.02, "ax", %progbits + .space (2 * 1024 * 1024) - 68 + .thumb_func +f2: bx lr + nop + .thumb_func +f3: bx lr + nop + .thumb_func +f4: bx lr + nop + .thumb_func +f5: bx lr + nop + .thumb_func +f6: bx lr + nop + .thumb_func +f7: bx lr + nop + .thumb_func +f8: bx lr + nop + .thumb_func +f9: bx lr + nop + .thumb_func +f10: bx lr + nop diff --git a/test/ELF/linkerscript/memory-gap-explicit-expr.test b/test/ELF/linkerscript/memory-gap-explicit-expr.test new file mode 100644 index 000000000..750a925e6 --- /dev/null +++ b/test/ELF/linkerscript/memory-gap-explicit-expr.test @@ -0,0 +1,18 @@ +# REQUIRES: x86 + +# RUN: echo '.section .aaa, "a"; .quad 0; .section .bbb, "a"; .quad 0;' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64 - -o %t.o +# RUN: ld.lld %t.o --script %s -o %t +# RUN: llvm-readelf -S %t | FileCheck %s + +# CHECK: .aaa PROGBITS 0000000000000000 001000 000008 +# CHECK: .bbb PROGBITS 0000000000000014 001014 000008 + +MEMORY { + REGION (rwx) : ORIGIN = 0x0000, LENGTH = 0x100 +} + +SECTIONS { + .aaa 0 : { *(.aaa) } > REGION + .bbb 0x14 : { *(.bbb) } > REGION +} diff --git a/test/ELF/linkerscript/nobits-offset.s b/test/ELF/linkerscript/nobits-offset.s index c41414876..051f3f99d 100644 --- a/test/ELF/linkerscript/nobits-offset.s +++ b/test/ELF/linkerscript/nobits-offset.s @@ -2,17 +2,24 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: echo "SECTIONS { \ # RUN: .sec1 (NOLOAD) : { . += 1; } \ -# RUN: .text : { *(.text) } \ +# RUN: .bss : { *(.bss) } \ # RUN: };" > %t.script # RUN: ld.lld %t.o -T %t.script -o %t -# RUN: llvm-readelf --sections %t | FileCheck %s +# RUN: llvm-readelf -S -l %t | FileCheck %s -# We used to misalign section offsets if the first section in a -# PT_LOAD was SHT_NOBITS. +## If a SHT_NOBITS section is the only section of a PT_LOAD segment, +## p_offset will be set to the sh_offset field of the section. Check we align +## sh_offset to sh_addr modulo max-page-size, so that p_vaddr=p_offset (mod +## p_align). -# CHECK: [ 2] .text PROGBITS 0000000000000010 001010 000010 00 AX 0 0 16 +# CHECK: Name Type Address Off Size ES Flg Lk Inf Al +# CHECK: .bss NOBITS 0000000000000400 001400 000001 00 WA 0 0 1024 -.global _start -_start: - nop -.p2align 4 +# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# CHECK: LOAD 0x001400 0x0000000000000400 0x0000000000000400 0x000000 0x000001 RW 0x1000 + +# CHECK: 00 .bss + +.bss +.p2align 10 +.byte 0 diff --git a/test/ELF/linkerscript/orphan-report.s b/test/ELF/linkerscript/orphan-report.s index 0791b286d..12522b301 100644 --- a/test/ELF/linkerscript/orphan-report.s +++ b/test/ELF/linkerscript/orphan-report.s @@ -32,7 +32,7 @@ # REPORT-NEXT: :(.got.plt) is being placed in '.got.plt' # REPORT-NEXT: :(.got.plt) is being placed in '.got.plt' # REPORT-NEXT: :(.rela.plt) is being placed in '.rela.plt' -# REPORT-NEXT: :(.rela.plt) is being placed in '.rela.plt' +# REPORT-NEXT: :(.rela.dyn) is being placed in '.rela.dyn' # REPORT-NEXT: :(.plt) is being placed in '.plt' # REPORT-NEXT: :(.plt) is being placed in '.plt' # REPORT-NEXT: :(.symtab) is being placed in '.symtab' diff --git a/test/ELF/linkerscript/symbol-assign-many-passes.test b/test/ELF/linkerscript/symbol-assign-many-passes.test new file mode 100644 index 000000000..7e2d2d9ac --- /dev/null +++ b/test/ELF/linkerscript/symbol-assign-many-passes.test @@ -0,0 +1,25 @@ +# REQUIRES: aarch64, x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o %t.o +# RUN: ld.lld %t.o -T %s -o %t +# RUN: llvm-nm %t | FileCheck %s + +## AArch64 needs thunks and has different address finalization process, so test +## it as well. +# RUN: llvm-mc -filetype=obj -triple=aarch64 /dev/null -o %t.o +# RUN: ld.lld %t.o -T %s -o %t +# RUN: llvm-nm %t | FileCheck %s + +# CHECK: 0000000000001004 T a +# CHECK: 0000000000001003 T b +# CHECK: 0000000000001002 T c +# CHECK: 0000000000001001 T d +# CHECK: 0000000000001000 T e + +SECTIONS { + . = 0x1000; + a = b + 1; + b = c + 1; + c = d + 1; + d = e + 1; + e = .; +} diff --git a/test/ELF/linkerscript/symbol-assign-many-passes2.test b/test/ELF/linkerscript/symbol-assign-many-passes2.test new file mode 100644 index 000000000..973a48818 --- /dev/null +++ b/test/ELF/linkerscript/symbol-assign-many-passes2.test @@ -0,0 +1,28 @@ +# REQUIRES: arm +# RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv7a-linux-gnueabihf %S/Inputs/arm-thunk-many-passes.s -o %t.o +# RUN: ld.lld %t.o -T %s -o %t +# RUN: llvm-nm %t | FileCheck %s + +## arm-thunk-many-passes.s is worst case case of thunk generation that takes 9 +## passes to converge. It takes a few more passes to make symbol assignment +## converge. Test that +## 1. we don't error that "thunk creation not converged". +## 2. we check convergence of symbols defined in an output section descriptor. + +# CHECK: 01011050 T a +# CHECK: 0101104f T b +# CHECK: 0101104e T c +# CHECK: 0101104d T d +# CHECK: 0101104c T e + +SECTIONS { + . = SIZEOF_HEADERS; + .text 0x00011000 : { + a = b + 1; + b = c + 1; + c = d + 1; + d = e + 1; + *(.text); + } + e = .; +} diff --git a/test/ELF/linkerscript/symbol-assign-not-converge.test b/test/ELF/linkerscript/symbol-assign-not-converge.test new file mode 100644 index 000000000..38f40640d --- /dev/null +++ b/test/ELF/linkerscript/symbol-assign-not-converge.test @@ -0,0 +1,20 @@ +# REQUIRES: aarch64, x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o %t.o +# RUN: not ld.lld %t.o -T %s -o /dev/null 2>&1 | FileCheck %s + +## AArch64 needs thunks and has different address finalization process, so test +## it as well. +# RUN: llvm-mc -filetype=obj -triple=aarch64 /dev/null -o %t.o +# RUN: not ld.lld %t.o -T %s -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: assignment to symbol a does not converge + +SECTIONS { + . = 0x1000; + a = b; + b = c; + c = d; + d = e; + e = f; + f = .; +} diff --git a/test/ELF/linkerscript/version-script.s b/test/ELF/linkerscript/version-script.s index 67a0fd68c..d751fbf04 100644 --- a/test/ELF/linkerscript/version-script.s +++ b/test/ELF/linkerscript/version-script.s @@ -17,7 +17,7 @@ # CHECK-NEXT: Name: # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Version: 0 +# CHECK-NEXT: Version: 1 # CHECK-NEXT: Name: und # CHECK-NEXT: } # CHECK-NEXT: Symbol { diff --git a/test/ELF/lto/Inputs/undef.ll b/test/ELF/lto/Inputs/undef.ll new file mode 100644 index 000000000..48a4b694e --- /dev/null +++ b/test/ELF/lto/Inputs/undef.ll @@ -0,0 +1,4 @@ +target triple = "x86_64-unknown-linux-gnu" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +declare void @foo() diff --git a/test/ELF/lto/undef-weak-lazy.ll b/test/ELF/lto/undef-weak-lazy.ll new file mode 100644 index 000000000..5ce03ffcd --- /dev/null +++ b/test/ELF/lto/undef-weak-lazy.ll @@ -0,0 +1,23 @@ +; REQUIRES: x86 +; RUN: llvm-as %S/Inputs/undef.ll -o %tundef.o +; RUN: llvm-as %s -o %tweakundef.o +; RUN: llvm-as %S/Inputs/archive-3.ll -o %tdef.o + +;; Test that the lazy bitcode %tdef.o is fetched. +; RUN: ld.lld %tundef.o --start-lib %tdef.o --end-lib -shared -o %t.so +; RUN: llvm-nm %t.so | FileCheck %s + +;; Test %tweakundef.o does not change STB_GLOBAL to STB_WEAK. +; RUN: ld.lld %tundef.o %tweakundef.o --start-lib %tdef.o --end-lib -shared -o %t.so +; RUN: llvm-nm %t.so | FileCheck %s + +;; %tweakundef.o does not fetch %tdef.o but %tundef.o does. +; RUN: ld.lld --start-lib %tdef.o --end-lib %tweakundef.o %tundef.o -shared -o %t.so +; RUN: llvm-nm %t.so | FileCheck %s + +; CHECK: T foo + +target triple = "x86_64-unknown-linux-gnu" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +declare extern_weak void @foo() diff --git a/test/ELF/map-file-i686.s b/test/ELF/map-file-i686.s index 5c8b15491..4cf6e084d 100644 --- a/test/ELF/map-file-i686.s +++ b/test/ELF/map-file-i686.s @@ -8,9 +8,9 @@ _start: nop // CHECK: VMA LMA Size Align Out In Symbol -// CHECK-NEXT: 401000 401000 1 4 .text -// CHECK-NEXT: 401000 401000 1 4 {{.*}}{{/|\\}}map-file-i686.s.tmp1.o:(.text) -// CHECK-NEXT: 401000 401000 0 1 _start +// CHECK-NEXT: 4010b4 4010b4 1 4 .text +// CHECK-NEXT: 4010b4 4010b4 1 4 {{.*}}{{/|\\}}map-file-i686.s.tmp1.o:(.text) +// CHECK-NEXT: 4010b4 4010b4 0 1 _start // CHECK-NEXT: 0 0 8 1 .comment // CHECK-NEXT: 0 0 8 1 :(.comment) // CHECK-NEXT: 0 0 20 4 .symtab diff --git a/test/ELF/msp430.s b/test/ELF/msp430.s index f481a3033..eb645d8b7 100644 --- a/test/ELF/msp430.s +++ b/test/ELF/msp430.s @@ -1,7 +1,7 @@ ; REQUIRES: msp430 ; RUN: llvm-mc -filetype=obj -triple=msp430-elf -o %t1.o %s ; RUN: echo -e '.global _start\n _start: nop' | llvm-mc -filetype=obj -triple=msp430-elf -o %t2.o - -; RUN: ld.lld -o %t.exe --Tdata=0x2000 --Ttext=0x8000 --defsym=_byte=0x21 %t2.o %t1.o +; RUN: ld.lld -o %t.exe --Tdata=0x2000 --Ttext=0x8000 --defsym=_byte=0x21 -z separate-code %t2.o %t1.o ; RUN: llvm-objdump -s -d %t.exe | FileCheck %s ;; Check handling of basic msp430 relocation types. diff --git a/test/ELF/nobits-offset.s b/test/ELF/nobits-offset.s new file mode 100644 index 000000000..b1f175bf8 --- /dev/null +++ b/test/ELF/nobits-offset.s @@ -0,0 +1,21 @@ +# REQUIRES: aarch64 +# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readelf -S -l %t | FileCheck %s + +## If a SHT_NOBITS section is the only section of a PT_LOAD segment, +## p_offset will be set to the sh_offset field of the section. Check we align +## sh_offset to sh_addr modulo max-page-size, so that p_vaddr=p_offset (mod +## p_align). + +# CHECK: Name Type Address Off Size ES Flg Lk Inf Al +# CHECK: .bss NOBITS 0000000000221000 001000 000001 00 WA 0 0 4096 + +# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# CHECK: LOAD 0x001000 0x0000000000221000 0x0000000000221000 0x000000 0x000001 RW 0x10000 + +# CHECK: 02 .bss + +.bss +.p2align 12 +.byte 0 diff --git a/test/ELF/pack-dyn-relocs-arm2.s b/test/ELF/pack-dyn-relocs-arm2.s index 39a5c9bec..bcbde213d 100644 --- a/test/ELF/pack-dyn-relocs-arm2.s +++ b/test/ELF/pack-dyn-relocs-arm2.s @@ -1,47 +1,47 @@ // REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-shared.s -o %t.so.o -// RUN: ld.lld -shared %t.so.o -o %t.so +// RUN: ld.lld -shared %t.so.o -soname=t.so -o %t.so // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o // RUN: ld.lld -pie --pack-dyn-relocs=relr %t.o %t.so -o %t.exe // RUN: llvm-readobj -r %t.exe | FileCheck %s // CHECK: Section (5) .relr.dyn { -// CHECK-NEXT: 0x2000 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2004 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2008 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x200C R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2010 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2014 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2018 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x201C R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2020 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2024 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2028 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x202C R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2030 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2034 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2038 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x203C R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2040 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2044 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2048 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x204C R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2050 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2054 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2058 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x205C R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2060 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2064 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2068 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x206C R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2070 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2074 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2078 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x207C R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2080 R_ARM_RELATIVE - 0x0 -// CHECK-NEXT: 0x2084 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x31E0 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x31E4 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x31E8 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x31EC R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x31F0 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x31F4 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x31F8 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x31FC R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3200 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3204 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3208 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x320C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3210 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3214 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3218 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x321C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3220 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3224 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3228 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x322C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3230 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3234 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3238 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x323C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3240 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3244 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3248 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x324C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3250 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3254 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3258 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x325C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3260 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x3264 R_ARM_RELATIVE - 0x0 // CHECK-NEXT: } // RUN: llvm-readobj -S --dynamic-table %t.exe | FileCheck --check-prefix=HEADER %s diff --git a/test/ELF/pack-dyn-relocs-loop.s b/test/ELF/pack-dyn-relocs-loop.s index 2a5533795..11ba91488 100644 --- a/test/ELF/pack-dyn-relocs-loop.s +++ b/test/ELF/pack-dyn-relocs-loop.s @@ -1,7 +1,7 @@ // REQUIRES: arm, aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-android %s -o %t.o -// RUN: ld.lld -shared %t.o -o %t.so --pack-dyn-relocs=android -z norelro +// RUN: ld.lld -shared %t.o -o %t.so --pack-dyn-relocs=android -z norelro -z separate-code // RUN: llvm-readobj -S %t.so | FileCheck %s // This test is making sure the Android packed relocation support doesn't diff --git a/test/ELF/pack-dyn-relocs.s b/test/ELF/pack-dyn-relocs.s index 943dd52e0..34c9a3cb3 100644 --- a/test/ELF/pack-dyn-relocs.s +++ b/test/ELF/pack-dyn-relocs.s @@ -1,46 +1,52 @@ // REQUIRES: arm, aarch64 // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-shared.s -o %t.a32.so.o -// RUN: ld.lld -shared %t.a32.so.o -o %t.a32.so -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.a32 -// RUN: ld.lld -pie --pack-dyn-relocs=none %t.a32 %t.a32.so -o %t2.a32 +// RUN: ld.lld -shared %t.a32.so.o -soname=so -o %t.a32.so +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.a32.o +// RUN: ld.lld -pie --pack-dyn-relocs=none %t.a32.o %t.a32.so -o %t2.a32 // RUN: llvm-readobj -r %t2.a32 | FileCheck --check-prefix=UNPACKED32 %s // Unpacked should have the relative relocations in their natural order. // UNPACKED32: Section ({{.+}}) .rel.dyn { -// UNPACKED32-NEXT: 0x2000 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2004 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2008 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x200C R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2010 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2014 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2018 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x201C R_ARM_RELATIVE - 0x0 - -// UNPACKED32-NEXT: 0x2024 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2028 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x202C R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2030 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2034 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2038 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x203C R_ARM_RELATIVE - 0x0 - -// UNPACKED32-NEXT: 0x2044 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2048 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x204C R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2050 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2054 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2058 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x205C R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2060 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2064 R_ARM_RELATIVE - 0x0 - -// UNPACKED32-NEXT: 0x2069 R_ARM_RELATIVE - 0x0 -// UNPACKED32-NEXT: 0x2020 R_ARM_ABS32 bar2 0x0 -// UNPACKED32-NEXT: 0x2040 R_ARM_ABS32 zed2 0x0 +// UNPACKED32-NEXT: 0x331C R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3320 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3324 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3328 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x332C R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3330 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3334 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3338 R_ARM_RELATIVE - 0x0 + +// UNPACKED32-NEXT: 0x3340 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3344 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3348 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x334C R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3350 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3354 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3358 R_ARM_RELATIVE - 0x0 + +// UNPACKED32-NEXT: 0x3364 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3368 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x336C R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3370 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3374 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3378 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x337C R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3380 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3384 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x3389 R_ARM_RELATIVE - 0x0 + +// UNPACKED32-NEXT: 0x333C R_ARM_ABS32 bar2 0x0 +// UNPACKED32-NEXT: 0x3360 R_ARM_ABS32 bar2 0x0 +// UNPACKED32-NEXT: 0x338D R_ARM_ABS32 bar2 0x0 +// UNPACKED32-NEXT: 0x3391 R_ARM_ABS32 bar2 0x0 +// UNPACKED32-NEXT: 0x3395 R_ARM_ABS32 bar2 0x0 +// UNPACKED32-NEXT: 0x3399 R_ARM_ABS32 bar2 0x0 +// UNPACKED32-NEXT: 0x339D R_ARM_ABS32 bar2 0x0 +// UNPACKED32-NEXT: 0x335C R_ARM_ABS32 zed2 0x0 // UNPACKED32-NEXT: } -// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a32 %t.a32.so -o %t3.a32 +// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a32.o %t.a32.so -o %t3.a32 // RUN: llvm-readobj -S --dynamic-table %t3.a32 | FileCheck --check-prefix=ANDROID32-HEADERS %s // RUN: llvm-readobj -r %t3.a32 | FileCheck --check-prefix=ANDROID32 %s @@ -63,42 +69,49 @@ // ANDROID32-HEADERS: 0x6000000F ANDROID_REL [[ADDR]] // ANDROID32-HEADERS: 0x60000010 ANDROID_RELSZ [[SIZE]] -// Packed should have the larger groups of relative relocations first, -// i.e. the 8 and 9 followed by the 7. +// Packed should have the groups of non-relative reloations first, followed +// by the larger groups of relative relocations (i.e. the 8 and 9 followed +// by the 7.) // ANDROID32: Section ({{.+}}) .rel.dyn { -// ANDROID32-NEXT: 0x2000 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2004 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2008 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x200C R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2010 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2014 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2018 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x201C R_ARM_RELATIVE - 0x0 - -// ANDROID32-NEXT: 0x2044 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2048 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x204C R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2050 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2054 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2058 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x205C R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2060 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2064 R_ARM_RELATIVE - 0x0 - -// ANDROID32-NEXT: 0x2024 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2028 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x202C R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2030 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2034 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2038 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x203C R_ARM_RELATIVE - 0x0 - -// ANDROID32-NEXT: 0x2069 R_ARM_RELATIVE - 0x0 -// ANDROID32-NEXT: 0x2020 R_ARM_ABS32 bar2 0x0 -// ANDROID32-NEXT: 0x2040 R_ARM_ABS32 zed2 0x0 +// ANDROID32-NEXT: 0x324C R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3250 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3254 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3258 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x325C R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3260 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3264 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3268 R_ARM_RELATIVE - 0 + +// ANDROID32-NEXT: 0x3294 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3298 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x329C R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x32A0 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x32A4 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x32A8 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x32AC R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x32B0 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x32B4 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3270 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3274 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3278 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x327C R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3280 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3284 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x3288 R_ARM_RELATIVE - 0 +// ANDROID32-NEXT: 0x32B9 R_ARM_RELATIVE - 0 + +// ANDROID32-NEXT: 0x326C R_ARM_ABS32 bar2 0 +// ANDROID32-NEXT: 0x3290 R_ARM_ABS32 bar2 0 +// ANDROID32-NEXT: 0x32BD R_ARM_ABS32 bar2 0 +// ANDROID32-NEXT: 0x32C1 R_ARM_ABS32 bar2 0 +// ANDROID32-NEXT: 0x32C5 R_ARM_ABS32 bar2 0 +// ANDROID32-NEXT: 0x32C9 R_ARM_ABS32 bar2 0 +// ANDROID32-NEXT: 0x32CD R_ARM_ABS32 bar2 0 + +// ANDROID32-NEXT: 0x328C R_ARM_ABS32 zed2 0 // ANDROID32-NEXT: } -// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.a32 %t.a32.so -o %t4.a32 +// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.a32.o %t.a32.so -o %t4.a32 // RUN: llvm-readobj -S --dynamic-table %t4.a32 | FileCheck --check-prefix=RELR32-HEADERS %s // RUN: llvm-readobj -r --raw-relr %t4.a32 | FileCheck --check-prefix=RAW-RELR32 %s // RUN: llvm-readobj -r %t4.a32 | FileCheck --check-prefix=RELR32 %s @@ -126,87 +139,99 @@ // SHT_RELR section contains address/bitmap entries // encoding the offsets for relative relocation. // RAW-RELR32: Section ({{.+}}) .relr.dyn { -// RAW-RELR32-NEXT: 0x2000 -// RAW-RELR32-NEXT: 0x3FEFEFF +// RAW-RELR32-NEXT: 0x327C +// RAW-RELR32-NEXT: 0x7FCFEFF // RAW-RELR32-NEXT: } // Decoded SHT_RELR section is same as UNPACKED, // but contains only the relative relocations. // Any relative relocations with odd offset stay in SHT_REL. // RELR32: Section ({{.+}}) .rel.dyn { -// RELR32-NEXT: 0x2069 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2020 R_ARM_ABS32 bar2 0x0 -// RELR32-NEXT: 0x2040 R_ARM_ABS32 zed2 0x0 +// RELR32-NEXT: 0x32E9 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x329C R_ARM_ABS32 bar2 0x0 +// RELR32-NEXT: 0x32C0 R_ARM_ABS32 bar2 0x0 +// RELR32-NEXT: 0x32ED R_ARM_ABS32 bar2 0x0 +// RELR32-NEXT: 0x32F1 R_ARM_ABS32 bar2 0x0 +// RELR32-NEXT: 0x32F5 R_ARM_ABS32 bar2 0x0 +// RELR32-NEXT: 0x32F9 R_ARM_ABS32 bar2 0x0 +// RELR32-NEXT: 0x32FD R_ARM_ABS32 bar2 0x0 +// RELR32-NEXT: 0x32BC R_ARM_ABS32 zed2 0x0 // RELR32-NEXT: } // RELR32-NEXT: Section ({{.+}}) .relr.dyn { -// RELR32-NEXT: 0x2000 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2004 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2008 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x200C R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2010 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2014 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2018 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x201C R_ARM_RELATIVE - 0x0 - -// RELR32-NEXT: 0x2024 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2028 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x202C R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2030 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2034 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2038 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x203C R_ARM_RELATIVE - 0x0 - -// RELR32-NEXT: 0x2044 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2048 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x204C R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2050 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2054 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2058 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x205C R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2060 R_ARM_RELATIVE - 0x0 -// RELR32-NEXT: 0x2064 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x327C R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x3280 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x3284 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x3288 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x328C R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x3290 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x3294 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x3298 R_ARM_RELATIVE - 0x0 + +// RELR32-NEXT: 0x32A0 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32A4 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32A8 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32AC R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32B0 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32B4 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32B8 R_ARM_RELATIVE - 0x0 + +// RELR32-NEXT: 0x32C4 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32C8 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32CC R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32D0 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32D4 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32D8 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32DC R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32E0 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x32E4 R_ARM_RELATIVE - 0x0 // RELR32-NEXT: } // RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %p/Inputs/shared2.s -o %t.a64.so.o -// RUN: ld.lld -shared %t.a64.so.o -o %t.a64.so -// RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %t.a64 -// RUN: ld.lld -pie --pack-dyn-relocs=none %t.a64 %t.a64.so -o %t2.a64 +// RUN: ld.lld -shared %t.a64.so.o -soname=so -o %t.a64.so +// RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %t.a64.o +// RUN: ld.lld -pie --pack-dyn-relocs=none %t.a64.o %t.a64.so -o %t2.a64 // RUN: llvm-readobj -r %t2.a64 | FileCheck --check-prefix=UNPACKED64 %s // UNPACKED64: Section ({{.+}}) .rela.dyn { -// UNPACKED64-NEXT: 0x20000 R_AARCH64_RELATIVE - 0x1 -// UNPACKED64-NEXT: 0x20008 R_AARCH64_RELATIVE - 0x2 -// UNPACKED64-NEXT: 0x20010 R_AARCH64_RELATIVE - 0x3 -// UNPACKED64-NEXT: 0x20018 R_AARCH64_RELATIVE - 0x4 -// UNPACKED64-NEXT: 0x20020 R_AARCH64_RELATIVE - 0x5 -// UNPACKED64-NEXT: 0x20028 R_AARCH64_RELATIVE - 0x6 -// UNPACKED64-NEXT: 0x20030 R_AARCH64_RELATIVE - 0x7 -// UNPACKED64-NEXT: 0x20038 R_AARCH64_RELATIVE - 0x8 - -// UNPACKED64-NEXT: 0x20048 R_AARCH64_RELATIVE - 0x1 -// UNPACKED64-NEXT: 0x20050 R_AARCH64_RELATIVE - 0x2 -// UNPACKED64-NEXT: 0x20058 R_AARCH64_RELATIVE - 0x3 -// UNPACKED64-NEXT: 0x20060 R_AARCH64_RELATIVE - 0x4 -// UNPACKED64-NEXT: 0x20068 R_AARCH64_RELATIVE - 0x5 -// UNPACKED64-NEXT: 0x20070 R_AARCH64_RELATIVE - 0x6 -// UNPACKED64-NEXT: 0x20078 R_AARCH64_RELATIVE - 0x7 - -// UNPACKED64-NEXT: 0x20088 R_AARCH64_RELATIVE - 0x1 -// UNPACKED64-NEXT: 0x20090 R_AARCH64_RELATIVE - 0x2 -// UNPACKED64-NEXT: 0x20098 R_AARCH64_RELATIVE - 0x3 -// UNPACKED64-NEXT: 0x200A0 R_AARCH64_RELATIVE - 0x4 -// UNPACKED64-NEXT: 0x200A8 R_AARCH64_RELATIVE - 0x5 -// UNPACKED64-NEXT: 0x200B0 R_AARCH64_RELATIVE - 0x6 -// UNPACKED64-NEXT: 0x200B8 R_AARCH64_RELATIVE - 0x7 -// UNPACKED64-NEXT: 0x200C0 R_AARCH64_RELATIVE - 0x8 -// UNPACKED64-NEXT: 0x200C8 R_AARCH64_RELATIVE - 0x9 - -// UNPACKED64-NEXT: 0x200D1 R_AARCH64_RELATIVE - 0xA -// UNPACKED64-NEXT: 0x20040 R_AARCH64_ABS64 bar2 0x1 -// UNPACKED64-NEXT: 0x20080 R_AARCH64_ABS64 zed2 0x0 +// UNPACKED64-NEXT: 0x30680 R_AARCH64_RELATIVE - 0x1 +// UNPACKED64-NEXT: 0x30688 R_AARCH64_RELATIVE - 0x2 +// UNPACKED64-NEXT: 0x30690 R_AARCH64_RELATIVE - 0x3 +// UNPACKED64-NEXT: 0x30698 R_AARCH64_RELATIVE - 0x4 +// UNPACKED64-NEXT: 0x306A0 R_AARCH64_RELATIVE - 0x5 +// UNPACKED64-NEXT: 0x306A8 R_AARCH64_RELATIVE - 0x6 +// UNPACKED64-NEXT: 0x306B0 R_AARCH64_RELATIVE - 0x7 +// UNPACKED64-NEXT: 0x306B8 R_AARCH64_RELATIVE - 0x8 + +// UNPACKED64-NEXT: 0x306C8 R_AARCH64_RELATIVE - 0x1 +// UNPACKED64-NEXT: 0x306D0 R_AARCH64_RELATIVE - 0x2 +// UNPACKED64-NEXT: 0x306D8 R_AARCH64_RELATIVE - 0x3 +// UNPACKED64-NEXT: 0x306E0 R_AARCH64_RELATIVE - 0x4 +// UNPACKED64-NEXT: 0x306E8 R_AARCH64_RELATIVE - 0x5 +// UNPACKED64-NEXT: 0x306F0 R_AARCH64_RELATIVE - 0x6 +// UNPACKED64-NEXT: 0x306F8 R_AARCH64_RELATIVE - 0x7 + +// UNPACKED64-NEXT: 0x30710 R_AARCH64_RELATIVE - 0x1 +// UNPACKED64-NEXT: 0x30718 R_AARCH64_RELATIVE - 0x2 +// UNPACKED64-NEXT: 0x30720 R_AARCH64_RELATIVE - 0x3 +// UNPACKED64-NEXT: 0x30728 R_AARCH64_RELATIVE - 0x4 +// UNPACKED64-NEXT: 0x30730 R_AARCH64_RELATIVE - 0x5 +// UNPACKED64-NEXT: 0x30738 R_AARCH64_RELATIVE - 0x6 +// UNPACKED64-NEXT: 0x30740 R_AARCH64_RELATIVE - 0x7 +// UNPACKED64-NEXT: 0x30748 R_AARCH64_RELATIVE - 0x8 +// UNPACKED64-NEXT: 0x30750 R_AARCH64_RELATIVE - 0x9 + +// UNPACKED64-NEXT: 0x30759 R_AARCH64_RELATIVE - 0xA +// UNPACKED64-NEXT: 0x306C0 R_AARCH64_ABS64 bar2 0x1 +// UNPACKED64-NEXT: 0x30708 R_AARCH64_ABS64 bar2 0x0 +// UNPACKED64-NEXT: 0x30761 R_AARCH64_ABS64 bar2 0x0 +// UNPACKED64-NEXT: 0x30769 R_AARCH64_ABS64 bar2 0x0 +// UNPACKED64-NEXT: 0x30771 R_AARCH64_ABS64 bar2 0x1 +// UNPACKED64-NEXT: 0x30779 R_AARCH64_ABS64 bar2 0x1 +// UNPACKED64-NEXT: 0x30781 R_AARCH64_ABS64 bar2 0x0 +// UNPACKED64-NEXT: 0x30700 R_AARCH64_ABS64 zed2 0x0 // UNPACKED64-NEXT: } -// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a64 %t.a64.so -o %t3.a64 +// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a64.o %t.a64.so -o %t3.a64 // RUN: llvm-readobj -S --dynamic-table %t3.a64 | FileCheck --check-prefix=ANDROID64-HEADERS %s // RUN: llvm-readobj -r %t3.a64 | FileCheck --check-prefix=ANDROID64 %s @@ -230,39 +255,45 @@ // ANDROID64-HEADERS: 0x0000000060000012 ANDROID_RELASZ [[SIZE]] // ANDROID64: Section ({{.+}}) .rela.dyn { -// ANDROID64-NEXT: 0x20000 R_AARCH64_RELATIVE - 0x1 -// ANDROID64-NEXT: 0x20008 R_AARCH64_RELATIVE - 0x2 -// ANDROID64-NEXT: 0x20010 R_AARCH64_RELATIVE - 0x3 -// ANDROID64-NEXT: 0x20018 R_AARCH64_RELATIVE - 0x4 -// ANDROID64-NEXT: 0x20020 R_AARCH64_RELATIVE - 0x5 -// ANDROID64-NEXT: 0x20028 R_AARCH64_RELATIVE - 0x6 -// ANDROID64-NEXT: 0x20030 R_AARCH64_RELATIVE - 0x7 -// ANDROID64-NEXT: 0x20038 R_AARCH64_RELATIVE - 0x8 - -// ANDROID64-NEXT: 0x20088 R_AARCH64_RELATIVE - 0x1 -// ANDROID64-NEXT: 0x20090 R_AARCH64_RELATIVE - 0x2 -// ANDROID64-NEXT: 0x20098 R_AARCH64_RELATIVE - 0x3 -// ANDROID64-NEXT: 0x200A0 R_AARCH64_RELATIVE - 0x4 -// ANDROID64-NEXT: 0x200A8 R_AARCH64_RELATIVE - 0x5 -// ANDROID64-NEXT: 0x200B0 R_AARCH64_RELATIVE - 0x6 -// ANDROID64-NEXT: 0x200B8 R_AARCH64_RELATIVE - 0x7 -// ANDROID64-NEXT: 0x200C0 R_AARCH64_RELATIVE - 0x8 -// ANDROID64-NEXT: 0x200C8 R_AARCH64_RELATIVE - 0x9 - -// ANDROID64-NEXT: 0x20048 R_AARCH64_RELATIVE - 0x1 -// ANDROID64-NEXT: 0x20050 R_AARCH64_RELATIVE - 0x2 -// ANDROID64-NEXT: 0x20058 R_AARCH64_RELATIVE - 0x3 -// ANDROID64-NEXT: 0x20060 R_AARCH64_RELATIVE - 0x4 -// ANDROID64-NEXT: 0x20068 R_AARCH64_RELATIVE - 0x5 -// ANDROID64-NEXT: 0x20070 R_AARCH64_RELATIVE - 0x6 -// ANDROID64-NEXT: 0x20078 R_AARCH64_RELATIVE - 0x7 - -// ANDROID64-NEXT: 0x200D1 R_AARCH64_RELATIVE - 0xA -// ANDROID64-NEXT: 0x20040 R_AARCH64_ABS64 bar2 0x1 -// ANDROID64-NEXT: 0x20080 R_AARCH64_ABS64 zed2 0x0 +// ANDROID64-NEXT: 0x303E0 R_AARCH64_RELATIVE - 0x1 +// ANDROID64-NEXT: 0x303E8 R_AARCH64_RELATIVE - 0x2 +// ANDROID64-NEXT: 0x303F0 R_AARCH64_RELATIVE - 0x3 +// ANDROID64-NEXT: 0x303F8 R_AARCH64_RELATIVE - 0x4 +// ANDROID64-NEXT: 0x30400 R_AARCH64_RELATIVE - 0x5 +// ANDROID64-NEXT: 0x30408 R_AARCH64_RELATIVE - 0x6 +// ANDROID64-NEXT: 0x30410 R_AARCH64_RELATIVE - 0x7 +// ANDROID64-NEXT: 0x30418 R_AARCH64_RELATIVE - 0x8 + +// ANDROID64-NEXT: 0x30470 R_AARCH64_RELATIVE - 0x1 +// ANDROID64-NEXT: 0x30478 R_AARCH64_RELATIVE - 0x2 +// ANDROID64-NEXT: 0x30480 R_AARCH64_RELATIVE - 0x3 +// ANDROID64-NEXT: 0x30488 R_AARCH64_RELATIVE - 0x4 +// ANDROID64-NEXT: 0x30490 R_AARCH64_RELATIVE - 0x5 +// ANDROID64-NEXT: 0x30498 R_AARCH64_RELATIVE - 0x6 +// ANDROID64-NEXT: 0x304A0 R_AARCH64_RELATIVE - 0x7 +// ANDROID64-NEXT: 0x304A8 R_AARCH64_RELATIVE - 0x8 +// ANDROID64-NEXT: 0x304B0 R_AARCH64_RELATIVE - 0x9 + +// ANDROID64-NEXT: 0x30428 R_AARCH64_RELATIVE - 0x1 +// ANDROID64-NEXT: 0x30430 R_AARCH64_RELATIVE - 0x2 +// ANDROID64-NEXT: 0x30438 R_AARCH64_RELATIVE - 0x3 +// ANDROID64-NEXT: 0x30440 R_AARCH64_RELATIVE - 0x4 +// ANDROID64-NEXT: 0x30448 R_AARCH64_RELATIVE - 0x5 +// ANDROID64-NEXT: 0x30450 R_AARCH64_RELATIVE - 0x6 +// ANDROID64-NEXT: 0x30458 R_AARCH64_RELATIVE - 0x7 +// ANDROID64-NEXT: 0x304B9 R_AARCH64_RELATIVE - 0xA + +// ANDROID64-NEXT: 0x30468 R_AARCH64_ABS64 bar2 0x0 +// ANDROID64-NEXT: 0x304C1 R_AARCH64_ABS64 bar2 0x0 +// ANDROID64-NEXT: 0x304C9 R_AARCH64_ABS64 bar2 0x0 +// ANDROID64-NEXT: 0x304E1 R_AARCH64_ABS64 bar2 0x0 +// ANDROID64-NEXT: 0x30420 R_AARCH64_ABS64 bar2 0x1 +// ANDROID64-NEXT: 0x30460 R_AARCH64_ABS64 zed2 0x0 +// ANDROID64-NEXT: 0x304D1 R_AARCH64_ABS64 bar2 0x1 +// ANDROID64-NEXT: 0x304D9 R_AARCH64_ABS64 bar2 0x1 // ANDROID64-NEXT: } -// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.a64 %t.a64.so -o %t4.a64 +// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.a64.o %t.a64.so -o %t4.a64 // RUN: llvm-readobj -S --dynamic-table %t4.a64 | FileCheck --check-prefix=RELR64-HEADERS %s // RUN: llvm-readobj -r --raw-relr %t4.a64 | FileCheck --check-prefix=RAW-RELR64 %s // RUN: llvm-readobj -r %t4.a64 | FileCheck --check-prefix=RELR64 %s @@ -290,46 +321,50 @@ // SHT_RELR section contains address/bitmap entries // encoding the offsets for relative relocation. // RAW-RELR64: Section ({{.+}}) .relr.dyn { -// RAW-RELR64-NEXT: 0x20000 -// RAW-RELR64-NEXT: 0x3FEFEFF +// RAW-RELR64-NEXT: 0x30480 +// RAW-RELR64-NEXT: 0x7FCFEFF // RAW-RELR64-NEXT: } // Decoded SHT_RELR section is same as UNPACKED, // but contains only the relative relocations. // Any relative relocations with odd offset stay in SHT_RELA. -// RELR64: Section ({{.+}}) .rela.dyn { -// RELR64-NEXT: 0x200D1 R_AARCH64_RELATIVE - 0xA -// RELR64-NEXT: 0x20040 R_AARCH64_ABS64 bar2 0x1 -// RELR64-NEXT: 0x20080 R_AARCH64_ABS64 zed2 0x0 -// RELR64-NEXT: } -// RELR64-NEXT: Section ({{.+}}) .relr.dyn { -// RELR64-NEXT: 0x20000 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20008 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20010 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20018 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20020 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20028 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20030 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20038 R_AARCH64_RELATIVE - 0x0 - -// RELR64-NEXT: 0x20048 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20050 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20058 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20060 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20068 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20070 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20078 R_AARCH64_RELATIVE - 0x0 - -// RELR64-NEXT: 0x20088 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20090 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x20098 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x200A0 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x200A8 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x200B0 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x200B8 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x200C0 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: 0x200C8 R_AARCH64_RELATIVE - 0x0 -// RELR64-NEXT: } +// RELR64: Section ({{.+}}) .rela.dyn { +// RELR64-NEXT: 0x30559 R_AARCH64_RELATIVE - 0xA +// RELR64-NEXT: 0x304C0 R_AARCH64_ABS64 bar2 0x1 +// RELR64-NEXT: 0x30508 R_AARCH64_ABS64 bar2 0x0 +// RELR64-NEXT: 0x30561 R_AARCH64_ABS64 bar2 0x0 +// RELR64-NEXT: 0x30569 R_AARCH64_ABS64 bar2 0x0 +// RELR64-NEXT: 0x30571 R_AARCH64_ABS64 bar2 0x1 +// RELR64-NEXT: 0x30579 R_AARCH64_ABS64 bar2 0x1 +// RELR64-NEXT: 0x30581 R_AARCH64_ABS64 bar2 0x0 +// RELR64-NEXT: 0x30500 R_AARCH64_ABS64 zed2 0x0 +// RELR64-NEXT: } +// RELR64-NEXT: Section ({{.+}}) .relr.dyn { +// RELR64-NEXT: 0x30480 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30488 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30490 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30498 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304A0 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304A8 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304B0 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304B8 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304C8 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304D0 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304D8 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304E0 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304E8 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304F0 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x304F8 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30510 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30518 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30520 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30528 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30530 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30538 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30540 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30548 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x30550 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: } .data .align 2 @@ -351,6 +386,7 @@ .dc.a __ehdr_start + 6 .dc.a __ehdr_start + 7 .dc.a zed2 +.dc.a bar2 .dc.a __ehdr_start + 1 .dc.a __ehdr_start + 2 @@ -363,3 +399,8 @@ .dc.a __ehdr_start + 9 .byte 00 .dc.a __ehdr_start + 10 +.dc.a bar2 +.dc.a bar2 +.dc.a bar2 + 1 +.dc.a bar2 + 1 +.dc.a bar2 diff --git a/test/ELF/partition-move-to-main-startstop.s b/test/ELF/partition-move-to-main-startstop.s new file mode 100644 index 000000000..76c04957b --- /dev/null +++ b/test/ELF/partition-move-to-main-startstop.s @@ -0,0 +1,43 @@ +// REQUIRES: x86 +// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=x86_64-unknown-linux +// RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections +// RUN: llvm-readelf -S %t | FileCheck --implicit-check-not=has_startstop %s + +// We can't let the has_startstop section be split by partition because it is +// referenced by __start_ and __stop_ symbols, so the split could result in +// some sections being moved out of the __start_/__stop_ range. Make sure that +// that didn't happen by checking that there is only one section. +// +// It's fine for us to split no_startstop because of the lack of +// __start_/__stop_ symbols. + +// CHECK: has_startstop +// CHECK: no_startstop + +// CHECK: no_startstop + +.section .llvm_sympart.f1,"",@llvm_sympart +.asciz "part1" +.quad f1 + +.section .text._start,"ax",@progbits +.globl _start +_start: +call __start_has_startstop +call __stop_has_startstop + +.section .text.f1,"ax",@progbits +.globl f1 +f1: + +.section has_startstop,"ao",@progbits,.text._start,unique,1 +.quad 1 + +.section has_startstop,"ao",@progbits,.text.f1,unique,2 +.quad 2 + +.section no_startstop,"ao",@progbits,.text._start,unique,1 +.quad 3 + +.section no_startstop,"ao",@progbits,.text.f1,unique,2 +.quad 4 diff --git a/test/ELF/partition-notes.s b/test/ELF/partition-notes.s index 0805e8f85..3c16f2c71 100644 --- a/test/ELF/partition-notes.s +++ b/test/ELF/partition-notes.s @@ -18,6 +18,7 @@ // CHECK: Displaying notes found at file offset 0x{{0*}}[[NOTE_OFFSET]] // CHECK-NEXT: Owner // CHECK-NEXT: foo 0x00000004 NT_VERSION (version) +// CHECK-NEXT: description data: 62 61 72 00 // CHECK-NEXT: Displaying notes // CHECK-NEXT: Owner // CHECK-NEXT: GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring) diff --git a/test/ELF/partition-synthetic-sections.s b/test/ELF/partition-synthetic-sections.s index 66f9babaa..4f51b3e92 100644 --- a/test/ELF/partition-synthetic-sections.s +++ b/test/ELF/partition-synthetic-sections.s @@ -4,11 +4,11 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/verneed1.s -o %t1.o // RUN: echo "v1 {}; v2 {}; v3 { local: *; };" > %t1.script -// RUN: ld.lld -shared %t1.o --version-script %t1.script -o %t1.so -soname verneed1.so.0 +// RUN: ld.lld -shared %t1.o --version-script %t1.script -o %t1.so -soname verneed1.so.0 -z separate-code // RUN: llvm-mc %s -o %t.o -filetype=obj --triple=x86_64-unknown-linux // RUN: echo "x1 { global: p0; }; x2 { global: p1; p1alias; };" > %t.script -// RUN: ld.lld %t.o %t1.so --version-script %t.script -o %t --shared --gc-sections --eh-frame-hdr -soname main.so +// RUN: ld.lld %t.o %t1.so --version-script %t.script -o %t --shared --gc-sections --eh-frame-hdr -soname main.so -z separate-code // RUN: llvm-objcopy --extract-main-partition %t %t0 // RUN: llvm-objcopy --extract-partition=part1 %t %t1 diff --git a/test/ELF/plt-aarch64.s b/test/ELF/plt-aarch64.s index 1446f6839..d37d775de 100644 --- a/test/ELF/plt-aarch64.s +++ b/test/ELF/plt-aarch64.s @@ -1,15 +1,15 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-pc-freebsd %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=aarch64-pc-freebsd %p/Inputs/plt-aarch64.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -shared %t2.o -soname=t2.so -o %t2.so // RUN: ld.lld -shared %t.o %t2.so -o %t.so // RUN: ld.lld %t.o %t2.so -o %t.exe // RUN: llvm-readobj -S -r %t.so | FileCheck --check-prefix=CHECKDSO %s // RUN: llvm-objdump -s -section=.got.plt %t.so | FileCheck --check-prefix=DUMPDSO %s -// RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=DISASMDSO %s +// RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t.so | FileCheck --check-prefix=DISASMDSO %s // RUN: llvm-readobj -S -r %t.exe | FileCheck --check-prefix=CHECKEXE %s // RUN: llvm-objdump -s -section=.got.plt %t.exe | FileCheck --check-prefix=DUMPEXE %s -// RUN: llvm-objdump -d %t.exe | FileCheck --check-prefix=DISASMEXE %s +// RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t.exe | FileCheck --check-prefix=DISASMEXE %s // CHECKDSO: Name: .plt // CHECKDSO-NEXT: Type: SHT_PROGBITS @@ -17,7 +17,7 @@ // CHECKDSO-NEXT: SHF_ALLOC // CHECKDSO-NEXT: SHF_EXECINSTR // CHECKDSO-NEXT: ] -// CHECKDSO-NEXT: Address: 0x10010 +// CHECKDSO-NEXT: Address: 0x10340 // CHECKDSO-NEXT: Offset: // CHECKDSO-NEXT: Size: 80 // CHECKDSO-NEXT: Link: @@ -30,7 +30,7 @@ // CHECKDSO-NEXT: SHF_ALLOC // CHECKDSO-NEXT: SHF_WRITE // CHECKDSO-NEXT: ] -// CHECKDSO-NEXT: Address: 0x30000 +// CHECKDSO-NEXT: Address: 0x30450 // CHECKDSO-NEXT: Offset: // CHECKDSO-NEXT: Size: 48 // CHECKDSO-NEXT: Link: @@ -40,79 +40,71 @@ // CHECKDSO: Relocations [ // CHECKDSO-NEXT: Section ({{.*}}) .rela.plt { -// &(.got.plt[3]) = 0x30000 + 3 * 8 = 0x30018 -// CHECKDSO-NEXT: 0x30018 R_AARCH64_JUMP_SLOT foo +// &(.got.plt[3]) = 0x30450 + 3 * 8 = 0x30468 +// CHECKDSO-NEXT: 0x30468 R_AARCH64_JUMP_SLOT foo -// &(.got.plt[4]) = 0x30000 + 4 * 8 = 0x30020 -// CHECKDSO-NEXT: 0x30020 R_AARCH64_JUMP_SLOT bar +// &(.got.plt[4]) = 0x30450 + 4 * 8 = 0x30470 +// CHECKDSO-NEXT: 0x30470 R_AARCH64_JUMP_SLOT bar -// &(.got.plt[5]) = 0x30000 + 5 * 8 = 0x30028 -// CHECKDSO-NEXT: 0x30028 R_AARCH64_JUMP_SLOT weak +// &(.got.plt[5]) = 0x30000 + 5 * 8 = 0x30470 +// CHECKDSO-NEXT: 0x30478 R_AARCH64_JUMP_SLOT weak // CHECKDSO-NEXT: } // CHECKDSO-NEXT: ] // DUMPDSO: Contents of section .got.plt: // .got.plt[0..2] = 0 (reserved) // .got.plt[3..5] = .plt = 0x10010 -// DUMPDSO-NEXT: 30000 00000000 00000000 00000000 00000000 ................ -// DUMPDSO-NEXT: 30010 00000000 00000000 10000100 00000000 ................ -// DUMPDSO-NEXT: 30020 10000100 00000000 10000100 00000000 ................ +// DUMPDSO-NEXT: 30450 00000000 00000000 00000000 00000000 +// DUMPDSO-NEXT: 30460 00000000 00000000 40030100 00000000 +// DUMPDSO-NEXT: 30470 40030100 00000000 40030100 00000000 // DISASMDSO: _start: -// 0x10030 - 0x10000 = 0x30 = 48 -// DISASMDSO-NEXT: 10000: 0c 00 00 14 b #48 -// 0x10040 - 0x10004 = 0x3c = 60 -// DISASMDSO-NEXT: 10004: 0f 00 00 14 b #60 -// 0x10050 - 0x10008 = 0x48 = 72 -// DISASMDSO-NEXT: 10008: 12 00 00 14 b #72 +// DISASMDSO-NEXT: 10330: b #0x30 +// DISASMDSO-NEXT: 10334: b #0x3c +// DISASMDSO-NEXT: 10338: b #0x48 // DISASMDSO: foo: -// DISASMDSO-NEXT: 1000c: 1f 20 03 d5 nop +// DISASMDSO-NEXT: 1033c: nop // DISASMDSO: Disassembly of section .plt: // DISASMDSO-EMPTY: // DISASMDSO-NEXT: .plt: -// DISASMDSO-NEXT: 10010: f0 7b bf a9 stp x16, x30, [sp, #-16]! -// &(.got.plt[2]) = 0x3000 + 2 * 8 = 0x3010 -// Page(0x30010) - Page(0x10014) = 0x30000 - 0x10000 = 0x20000 = 131072 -// DISASMDSO-NEXT: 10014: 10 01 00 90 adrp x16, #131072 -// 0x3010 & 0xFFF = 0x10 = 16 -// DISASMDSO-NEXT: 10018: 11 0a 40 f9 ldr x17, [x16, #16] -// DISASMDSO-NEXT: 1001c: 10 42 00 91 add x16, x16, #16 -// DISASMDSO-NEXT: 10020: 20 02 1f d6 br x17 -// DISASMDSO-NEXT: 10024: 1f 20 03 d5 nop -// DISASMDSO-NEXT: 10028: 1f 20 03 d5 nop -// DISASMDSO-NEXT: 1002c: 1f 20 03 d5 nop - -// foo@plt -// Page(0x30018) - Page(0x10030) = 0x30000 - 0x10000 = 0x20000 = 131072 +// DISASMDSO-NEXT: 10340: stp x16, x30, [sp, #-0x10]! +// &(.got.plt[2]) = 0x30450 + 2 * 8 = 0x30460 +// DISASMDSO-NEXT: 10344: adrp x16, #0x20000 +// DISASMDSO-NEXT: 10348: ldr x17, [x16, #0x460] +// DISASMDSO-NEXT: 1034c: add x16, x16, #0x460 +// DISASMDSO-NEXT: 10350: br x17 +// DISASMDSO-NEXT: 10354: nop +// DISASMDSO-NEXT: 10358: nop +// DISASMDSO-NEXT: 1035c: nop + +// foo@plt 0x30468 +// &.got.plt[foo] = 0x30468 // DISASMDSO-EMPTY: // DISASMDSO-NEXT: foo@plt: -// DISASMDSO-NEXT: 10030: 10 01 00 90 adrp x16, #131072 -// 0x3018 & 0xFFF = 0x18 = 24 -// DISASMDSO-NEXT: 10034: 11 0e 40 f9 ldr x17, [x16, #24] -// DISASMDSO-NEXT: 10038: 10 62 00 91 add x16, x16, #24 -// DISASMDSO-NEXT: 1003c: 20 02 1f d6 br x17 +// DISASMDSO-NEXT: 10360: adrp x16, #0x20000 +// DISASMDSO-NEXT: 10364: ldr x17, [x16, #0x468] +// DISASMDSO-NEXT: 10368: add x16, x16, #0x468 +// DISASMDSO-NEXT: 1036c: br x17 // bar@plt -// Page(0x30020) - Page(0x10040) = 0x30000 - 0x10000 = 0x20000 = 131072 +// &.got.plt[foo] = 0x30470 // DISASMDSO-EMPTY: // DISASMDSO-NEXT: bar@plt: -// DISASMDSO-NEXT: 10040: 10 01 00 90 adrp x16, #131072 -// 0x3020 & 0xFFF = 0x20 = 32 -// DISASMDSO-NEXT: 10044: 11 12 40 f9 ldr x17, [x16, #32] -// DISASMDSO-NEXT: 10048: 10 82 00 91 add x16, x16, #32 -// DISASMDSO-NEXT: 1004c: 20 02 1f d6 br x17 +// DISASMDSO-NEXT: 10370: adrp x16, #0x20000 +// DISASMDSO-NEXT: 10374: ldr x17, [x16, #0x470] +// DISASMDSO-NEXT: 10378: add x16, x16, #0x470 +// DISASMDSO-NEXT: 1037c: br x17 // weak@plt -// Page(0x30028) - Page(0x10050) = 0x30000 - 0x10000 = 0x20000 = 131072 +// 0x30468 = 0x10000 + 131072 + 1128 // DISASMDSO-EMPTY: // DISASMDSO-NEXT: weak@plt: -// DISASMDSO-NEXT: 10050: 10 01 00 90 adrp x16, #131072 -// 0x3028 & 0xFFF = 0x28 = 40 -// DISASMDSO-NEXT: 10054: 11 16 40 f9 ldr x17, [x16, #40] -// DISASMDSO-NEXT: 10058: 10 a2 00 91 add x16, x16, #40 -// DISASMDSO-NEXT: 1005c: 20 02 1f d6 br x17 +// DISASMDSO-NEXT: 10380: adrp x16, #0x20000 +// DISASMDSO-NEXT: 10384: ldr x17, [x16, #0x478] +// DISASMDSO-NEXT: 10388: add x16, x16, #0x478 +// DISASMDSO-NEXT: 1038c: br x17 // CHECKEXE: Name: .plt // CHECKEXE-NEXT: Type: SHT_PROGBITS @@ -120,7 +112,7 @@ // CHECKEXE-NEXT: SHF_ALLOC // CHECKEXE-NEXT: SHF_EXECINSTR // CHECKEXE-NEXT: ] -// CHECKEXE-NEXT: Address: 0x210010 +// CHECKEXE-NEXT: Address: 0x2102E0 // CHECKEXE-NEXT: Offset: // CHECKEXE-NEXT: Size: 64 // CHECKEXE-NEXT: Link: @@ -133,7 +125,7 @@ // CHECKEXE-NEXT: SHF_ALLOC // CHECKEXE-NEXT: SHF_WRITE // CHECKEXE-NEXT: ] -// CHECKEXE-NEXT: Address: 0x230000 +// CHECKEXE-NEXT: Address: 0x2303F0 // CHECKEXE-NEXT: Offset: // CHECKEXE-NEXT: Size: 40 // CHECKEXE-NEXT: Link: @@ -143,64 +135,57 @@ // CHECKEXE: Relocations [ // CHECKEXE-NEXT: Section ({{.*}}) .rela.plt { -// &(.got.plt[3]) = 0x230000 + 3 * 8 = 0x230018 -// CHECKEXE-NEXT: 0x230018 R_AARCH64_JUMP_SLOT bar 0x0 +// &(.got.plt[3]) = 0x2303f0 + 3 * 8 = 0x230408 +// CHECKEXE-NEXT: 0x230408 R_AARCH64_JUMP_SLOT bar 0x0 -// &(.got.plt[4]) = 0x230000 + 4 * 8 = 0x230020 -// CHECKEXE-NEXT: 0x230020 R_AARCH64_JUMP_SLOT weak 0x0 +// &(.got.plt[4]) = 0x2303f0 + 4 * 8 = 0x230410 +// CHECKEXE-NEXT: 0x230410 R_AARCH64_JUMP_SLOT weak 0x0 // CHECKEXE-NEXT: } // CHECKEXE-NEXT: ] // DUMPEXE: Contents of section .got.plt: // .got.plt[0..2] = 0 (reserved) // .got.plt[3..4] = .plt = 0x40010 -// DUMPEXE-NEXT: 230000 00000000 00000000 00000000 00000000 -// DUMPEXE-NEXT: 230010 00000000 00000000 10002100 00000000 -// DUMPEXE-NEXT: 230020 10002100 00000000 +// DUMPEXE-NEXT: 2303f0 00000000 00000000 00000000 00000000 +// DUMPEXE-NEXT: 230400 00000000 00000000 e0022100 00000000 +// DUMPEXE-NEXT: 230410 e0022100 00000000 // DISASMEXE: _start: -// 0x21000c - 0x210000 = 0xc = 12 -// DISASMEXE-NEXT: 210000: 03 00 00 14 b #12 -// 0x210030 - 0x210004 = 0x2c = 44 -// DISASMEXE-NEXT: 210004: 0b 00 00 14 b #44 -// 0x210040 - 0x210008 = 0x38 = 56 -// DISASMEXE-NEXT: 210008: 0e 00 00 14 b #56 +// DISASMEXE-NEXT: 2102c8: b #0xc +// DISASMEXE-NEXT: 2102cc: b #0x34 +// DISASMEXE-NEXT: 2102d0: b #0x40 // DISASMEXE: foo: -// DISASMEXE-NEXT: 21000c: 1f 20 03 d5 nop +// DISASMEXE-NEXT: 2102d4: nop // DISASMEXE: Disassembly of section .plt: // DISASMEXE-EMPTY: // DISASMEXE-NEXT: .plt: -// DISASMEXE-NEXT: 210010: f0 7b bf a9 stp x16, x30, [sp, #-16]! -// &(.got.plt[2]) = 0x2200B0 + 2 * 8 = 0x2200C0 -// Page(0x230010) - Page(0x210014) = 0x230000 - 0x210000 = 0x20000 = 131072 -// DISASMEXE-NEXT: 210014: 10 01 00 90 adrp x16, #131072 -// 0x120c0 & 0xFFF = 0xC0 = 192 -// DISASMEXE-NEXT: 210018: 11 0a 40 f9 ldr x17, [x16, #16] -// DISASMEXE-NEXT: 21001c: 10 42 00 91 add x16, x16, #16 -// DISASMEXE-NEXT: 210020: 20 02 1f d6 br x17 -// DISASMEXE-NEXT: 210024: 1f 20 03 d5 nop -// DISASMEXE-NEXT: 210028: 1f 20 03 d5 nop -// DISASMEXE-NEXT: 21002c: 1f 20 03 d5 nop +// DISASMEXE-NEXT: 2102e0: stp x16, x30, [sp, #-0x10]! +// &(.got.plt[2]) = 0x2303f0 + 2 * 8 = 0x230400 +// DISASMEXE-NEXT: 2102e4: adrp x16, #0x20000 +// DISASMEXE-NEXT: 2102e8: ldr x17, [x16, #0x400] +// DISASMEXE-NEXT: 2102ec: add x16, x16, #0x400 +// DISASMEXE-NEXT: 2102f0: br x17 +// DISASMEXE-NEXT: 2102f4: nop +// DISASMEXE-NEXT: 2102f8: nop +// DISASMEXE-NEXT: 2102fc: nop // bar@plt -// Page(0x230018) - Page(0x210030) = 0x230000 - 0x210000 = 0x20000 = 131072 // DISASMEXE-EMPTY: // DISASMEXE-NEXT: bar@plt: -// DISASMEXE-NEXT: 210030: 10 01 00 90 adrp x16, #131072 -// DISASMEXE-NEXT: 210034: 11 0e 40 f9 ldr x17, [x16, #24] -// DISASMEXE-NEXT: 210038: 10 62 00 91 add x16, x16, #24 -// DISASMEXE-NEXT: 21003c: 20 02 1f d6 br x17 +// DISASMEXE-NEXT: 210300: adrp x16, #0x20000 +// DISASMEXE-NEXT: 210304: ldr x17, [x16, #0x408] +// DISASMEXE-NEXT: 210308: add x16, x16, #0x408 +// DISASMEXE-NEXT: 21030c: br x17 // weak@plt -// Page(0x230020) - Page(0x210040) = 0x230000 - 0x210000 = 0x20000 = 131072 // DISASMEXE-EMPTY: // DISASMEXE-NEXT: weak@plt: -// DISASMEXE-NEXT: 210040: 10 01 00 90 adrp x16, #131072 -// DISASMEXE-NEXT: 210044: 11 12 40 f9 ldr x17, [x16, #32] -// DISASMEXE-NEXT: 210048: 10 82 00 91 add x16, x16, #32 -// DISASMEXE-NEXT: 21004c: 20 02 1f d6 br x17 +// DISASMEXE-NEXT: 210310: adrp x16, #0x20000 +// DISASMEXE-NEXT: 210314: ldr x17, [x16, #0x410] +// DISASMEXE-NEXT: 210318: add x16, x16, #0x410 +// DISASMEXE-NEXT: 21031c: br x17 .global _start,foo,bar .weak weak diff --git a/test/ELF/plt-i686.s b/test/ELF/plt-i686.s index 615bd1ec9..a11f40110 100644 --- a/test/ELF/plt-i686.s +++ b/test/ELF/plt-i686.s @@ -1,15 +1,15 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/Inputs/shared.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -shared %t2.o -soname=t2.so -o %t2.so // RUN: ld.lld %t.o %t2.so -o %t // RUN: llvm-readobj -S -r %t | FileCheck %s -// RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s +// RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t | FileCheck --check-prefix=DISASM %s // RUN: ld.lld -shared %t.o %t2.so -o %t // RUN: llvm-readobj -S -r %t | FileCheck --check-prefix=CHECKSHARED %s -// RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASMSHARED %s +// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DISASMSHARED %s // RUN: ld.lld -pie %t.o %t2.so -o %t -// RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASMPIE %s +// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DISASMPIE %s // CHECK: Name: .plt // CHECK-NEXT: Type: SHT_PROGBITS @@ -17,7 +17,7 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_EXECINSTR // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x401020 +// CHECK-NEXT: Address: 0x4011E0 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 48 // CHECK-NEXT: Link: 0 @@ -30,66 +30,55 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x403000 -// CHECK-NEXT: Offset: 0x3000 +// CHECK-NEXT: Address: 0x403278 +// CHECK-NEXT: Offset: 0x278 // CHECK-NEXT: Size: 20 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 4 // CHECK-NEXT: EntrySize: 0 -// 0x12000 + got.plt.reserved(12) = 0x1200C -// 0x12000 + got.plt.reserved(12) + 4 = 0x12010 +// First 3 slots of .got.plt are reserved. +// &.got.plt[3] = 0x403278 + 12 = 0x403284 +// &.got.plt[4] = 0x403278 + 16 = 0x403288 // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rel.plt { -// CHECK-NEXT: 0x40300C R_386_JUMP_SLOT bar 0x0 -// CHECK-NEXT: 0x403010 R_386_JUMP_SLOT zed 0x0 +// CHECK-NEXT: 0x403284 R_386_JUMP_SLOT bar 0x0 +// CHECK-NEXT: 0x403288 R_386_JUMP_SLOT zed 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] -// Unfortunately FileCheck can't do math, so we have to check for explicit -// values: - -// 16 is the size of PLT[0] -// (0x401010 + 16) - (0x401000 + 1) - 4 = 27 -// (0x401010 + 16) - (0x401005 + 1) - 4 = 22 -// (0x401020 + 16) - (0x40100a + 1) - 4 = 33 - // DISASM: local: -// DISASM-NEXT: 401000: {{.*}} -// DISASM-NEXT: 401002: {{.*}} +// DISASM-NEXT: 4011bc: +// DISASM-NEXT: 4011be: // DISASM: _start: -// 0x401013 + 5 - 24 = 0x401000 -// DISASM-NEXT: 401004: e9 27 00 00 00 jmp 39 -// DISASM-NEXT: 401009: e9 22 00 00 00 jmp 34 -// DISASM-NEXT: 40100e: e9 2d 00 00 00 jmp 45 -// DISASM-NEXT: 401013: e9 e8 ff ff ff jmp -24 +// DISASM-NEXT: 4011c0: jmp 0x2b +// DISASM-NEXT: 4011c5: jmp 0x26 +// DISASM-NEXT: 4011ca: jmp 0x31 +// DISASM-NEXT: 4011cf: jmp -0x18 -// 0x401010 - 0x40102b - 5 = -32 -// 0x401010 - 0x40103b - 5 = -48 -// 4206596 = 0x403004 = .got.plt (0x403000) + 4 -// 4206600 = 0x403008 = .got.plt (0x403000) + 8 -// 4206604 = 0x40300C = .got.plt (0x403000) + got.plt.reserved(12) -// 4206608 = 0x403010 = .got.plt (0x403000) + got.plt.reserved(12) + 4 // DISASM: Disassembly of section .plt: // DISASM-EMPTY: // DISASM-NEXT: .plt: -// DISASM-NEXT: 401020: ff 35 04 30 40 00 pushl 4206596 -// DISASM-NEXT: 401026: ff 25 08 30 40 00 jmpl *4206600 -// DISASM-NEXT: 40102c: 90 nop -// DISASM-NEXT: 40102d: 90 nop -// DISASM-NEXT: 40102e: 90 nop -// DISASM-NEXT: 40102f: 90 nop +/// Push .got.plt[1], then jump to .got.plt[2] +// DISASM-NEXT: 4011e0: pushl 0x40327c +// DISASM-NEXT: jmpl *0x403280 +// DISASM-NEXT: nop +// DISASM-NEXT: nop +// DISASM-NEXT: nop +// DISASM-NEXT: nop // DISASM-EMPTY: -// DISASM-NEXT: bar@plt: -// DISASM-NEXT: 401030: ff 25 0c 30 40 00 jmpl *4206604 -// DISASM-NEXT: 401036: 68 00 00 00 00 pushl $0 -// DISASM-NEXT: 40103b: e9 e0 ff ff ff jmp -32 <.plt> +// DISASM-NEXT: bar@plt: +/// .got.plt[3] = 0x403278 + 12 = 0x403284 +// DISASM-NEXT: 4011f0: jmpl *0x403284 +// DISASM-NEXT: pushl $0x0 +// DISASM-NEXT: jmp -0x20 <.plt> // DISASM-EMPTY: -// DISASM-NEXT: zed@plt: -// DISASM-NEXT: 401040: ff 25 10 30 40 00 jmpl *4206608 -// DISASM-NEXT: 401046: 68 08 00 00 00 pushl $8 -// DISASM-NEXT: 40104b: e9 d0 ff ff ff jmp -48 <.plt> +// DISASM-NEXT: zed@plt: +/// .got.plt[4] = 0x403278 + 16 = 0x403288 +// DISASM-NEXT: 401200: jmpl *0x403288 +// DISASM-NEXT: pushl $0x8 +// DISASM-NEXT: jmp -0x30 <.plt> // CHECKSHARED: Name: .plt // CHECKSHARED-NEXT: Type: SHT_PROGBITS @@ -97,8 +86,8 @@ // CHECKSHARED-NEXT: SHF_ALLOC // CHECKSHARED-NEXT: SHF_EXECINSTR // CHECKSHARED-NEXT: ] -// CHECKSHARED-NEXT: Address: 0x1020 -// CHECKSHARED-NEXT: Offset: 0x1020 +// CHECKSHARED-NEXT: Address: 0x1200 +// CHECKSHARED-NEXT: Offset: 0x200 // CHECKSHARED-NEXT: Size: 48 // CHECKSHARED-NEXT: Link: 0 // CHECKSHARED-NEXT: Info: 0 @@ -111,8 +100,8 @@ // CHECKSHARED-NEXT: SHF_ALLOC // CHECKSHARED-NEXT: SHF_WRITE // CHECKSHARED-NEXT: ] -// CHECKSHARED-NEXT: Address: 0x3000 -// CHECKSHARED-NEXT: Offset: 0x3000 +// CHECKSHARED-NEXT: Address: 0x3290 +// CHECKSHARED-NEXT: Offset: 0x290 // CHECKSHARED-NEXT: Size: 20 // CHECKSHARED-NEXT: Link: 0 // CHECKSHARED-NEXT: Info: 0 @@ -124,56 +113,57 @@ // 0x3000 + got.plt.reserved(12) + 4 = 0x3010 // CHECKSHARED: Relocations [ // CHECKSHARED-NEXT: Section ({{.*}}) .rel.plt { -// CHECKSHARED-NEXT: 0x300C R_386_JUMP_SLOT bar 0x0 -// CHECKSHARED-NEXT: 0x3010 R_386_JUMP_SLOT zed 0x0 +// CHECKSHARED-NEXT: 0x329C R_386_JUMP_SLOT bar 0x0 +// CHECKSHARED-NEXT: 0x32A0 R_386_JUMP_SLOT zed 0x0 // CHECKSHARED-NEXT: } // CHECKSHARED-NEXT: ] -// DISASMSHARED: local: -// DISASMSHARED-NEXT: 1000: {{.*}} -// DISASMSHARED-NEXT: 1002: {{.*}} -// DISASMSHARED: _start: -// 0x1013 + 5 - 24 = 0x1000 -// DISASMSHARED-NEXT: 1004: e9 27 00 00 00 jmp 39 -// DISASMSHARED-NEXT: 1009: e9 22 00 00 00 jmp 34 -// DISASMSHARED-NEXT: 100e: e9 2d 00 00 00 jmp 45 -// DISASMSHARED-NEXT: 1013: e9 e8 ff ff ff jmp -24 +// DISASMSHARED: local: +// DISASMSHARED-NEXT: 11e0: +// DISASMSHARED-NEXT: 11e2: +// DISASMSHARED: _start: +// DISASMSHARED-NEXT: 11e4: jmp 39 +// DISASMSHARED-NEXT: jmp 34 +// DISASMSHARED-NEXT: jmp 45 +// DISASMSHARED-NEXT: jmp -24 // DISASMSHARED-EMPTY: -// DISASMSHARED-NEXT: Disassembly of section .plt: +// DISASMSHARED-NEXT: Disassembly of section .plt: // DISASMSHARED-EMPTY: -// DISASMSHARED-NEXT: .plt: -// DISASMSHARED-NEXT: 1020: ff b3 04 00 00 00 pushl 4(%ebx) -// DISASMSHARED-NEXT: 1026: ff a3 08 00 00 00 jmpl *8(%ebx) -// DISASMSHARED-NEXT: 102c: 90 nop -// DISASMSHARED-NEXT: 102d: 90 nop -// DISASMSHARED-NEXT: 102e: 90 nop -// DISASMSHARED-NEXT: 102f: 90 nop -// DISASMSHARED: bar@plt: -// DISASMSHARED-NEXT: 1030: ff a3 0c 00 00 00 jmpl *12(%ebx) -// DISASMSHARED-NEXT: 1036: 68 00 00 00 00 pushl $0 -// DISASMSHARED-NEXT: 103b: e9 e0 ff ff ff jmp -32 <.plt> -// DISASMSHARED: zed@plt: -// DISASMSHARED-NEXT: 1040: ff a3 10 00 00 00 jmpl *16(%ebx) -// DISASMSHARED-NEXT: 1046: 68 08 00 00 00 pushl $8 -// DISASMSHARED-NEXT: 104b: e9 d0 ff ff ff jmp -48 <.plt> +// DISASMSHARED-NEXT: .plt: +// DISASMSHARED-NEXT: 1200: pushl 4(%ebx) +// DISASMSHARED-NEXT: jmpl *8(%ebx) +// DISASMSHARED-NEXT: nop +// DISASMSHARED-NEXT: nop +// DISASMSHARED-NEXT: nop +// DISASMSHARED-NEXT: nop +// DISASMSHARED: bar@plt: +// DISASMSHARED-NEXT: 1210: jmpl *12(%ebx) +// DISASMSHARED-NEXT: pushl $0 +// DISASMSHARED-NEXT: jmp -32 <.plt> +// DISASMSHARED: zed@plt: +// DISASMSHARED-NEXT: 1220: jmpl *16(%ebx) +// DISASMSHARED-NEXT: pushl $8 +// DISASMSHARED-NEXT: jmp -48 <.plt> // DISASMPIE: Disassembly of section .plt: // DISASMPIE-EMPTY: // DISASMPIE-NEXT: .plt: -// DISASMPIE-NEXT: 1020: ff b3 04 00 00 00 pushl 4(%ebx) -// DISASMPIE-NEXT: 1026: ff a3 08 00 00 00 jmpl *8(%ebx) -// DISASMPIE-NEXT: 102c: 90 nop -// DISASMPIE-NEXT: 102d: 90 nop -// DISASMPIE-NEXT: 102e: 90 nop -// DISASMPIE-NEXT: 102f: 90 nop -// DISASMPIE: bar@plt: -// DISASMPIE-NEXT: 1030: ff a3 0c 00 00 00 jmpl *12(%ebx) -// DISASMPIE-NEXT: 1036: 68 00 00 00 00 pushl $0 -// DISASMPIE-NEXT: 103b: e9 e0 ff ff ff jmp -32 <.plt> -// DISASMPIE: zed@plt: -// DISASMPIE-NEXT: 1040: ff a3 10 00 00 00 jmpl *16(%ebx) -// DISASMPIE-NEXT: 1046: 68 08 00 00 00 pushl $8 -// DISASMPIE-NEXT: 104b: e9 d0 ff ff ff jmp -48 <.plt> +// DISASMPIE-NEXT: 11e0: pushl 4(%ebx) +// DISASMPIE-NEXT: jmpl *8(%ebx) +// DISASMPIE-NEXT: nop +// DISASMPIE-NEXT: nop +// DISASMPIE-NEXT: nop +// DISASMPIE-NEXT: nop +// DISASMPIE-EMPTY: +// DISASMPIE-NEXT: bar@plt: +// DISASMPIE-NEXT: 11f0: jmpl *12(%ebx) +// DISASMPIE-NEXT: pushl $0 +// DISASMPIE-NEXT: jmp -32 <.plt> +// DISASMPIE-EMPTY: +// DISASMPIE-NEXT: zed@plt: +// DISASMPIE-NEXT: 1200: jmpl *16(%ebx) +// DISASMPIE-NEXT: pushl $8 +// DISASMPIE-NEXT: jmp -48 <.plt> local: .long 0 diff --git a/test/ELF/ppc-rela.s b/test/ELF/ppc-rela.s deleted file mode 100644 index 5f19120cb..000000000 --- a/test/ELF/ppc-rela.s +++ /dev/null @@ -1,11 +0,0 @@ -# REQUIRES: ppc -# RUN: llvm-mc -filetype=obj -triple=powerpc-unknown-freebsd %s -o %t -# RUN: ld.lld %t -o %t2 -shared -# RUN: llvm-readobj -r %t2 | FileCheck %s - -.data - .long foo - -// CHECK: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x20000 R_PPC_ADDR32 foo 0x0 -// CHECK-NEXT: } diff --git a/test/ELF/ppc32-abs-pic.s b/test/ELF/ppc32-abs-pic.s index 311220d4a..44a099d3e 100644 --- a/test/ELF/ppc32-abs-pic.s +++ b/test/ELF/ppc32-abs-pic.s @@ -7,11 +7,11 @@ ## R_PPC_ADDR32 is an absolute relocation type. ## In PIC mode, it creates a relative relocation if the symbol is non-preemptable. -# NM: 00020004 d b +# NM: 00030204 d b # RELOC: .rela.dyn { -# RELOC-NEXT: 0x20004 R_PPC_RELATIVE - 0x20004 -# RELOC-NEXT: 0x20000 R_PPC_ADDR32 a 0 +# RELOC-NEXT: 0x30204 R_PPC_RELATIVE - 0x30204 +# RELOC-NEXT: 0x30200 R_PPC_ADDR32 a 0 # RELOC-NEXT: } .globl a, b diff --git a/test/ELF/ppc32-call-stub-nopic.s b/test/ELF/ppc32-call-stub-nopic.s index 2d788adba..d2b9d460a 100644 --- a/test/ELF/ppc32-call-stub-nopic.s +++ b/test/ELF/ppc32-call-stub-nopic.s @@ -11,12 +11,12 @@ # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s # RELOC: .rela.plt { -# RELOC-NEXT: 0x10030000 R_PPC_JMP_SLOT f 0x0 -# RELOC-NEXT: 0x10030004 R_PPC_JMP_SLOT g 0x0 +# RELOC-NEXT: 0x100302C4 R_PPC_JMP_SLOT f 0x0 +# RELOC-NEXT: 0x100302C8 R_PPC_JMP_SLOT g 0x0 # RELOC-NEXT: } -# SEC: .got PROGBITS 10020070 -# RELOC: PPC_GOT 0x10020070 +# SEC: .got PROGBITS 100202b8 +# RELOC: PPC_GOT 0x100202B8 ## .got2+0x8000-0x10004 = 0x30000+0x8000-0x10004 = 65536*2+32764 # CHECK-LABEL: _start: @@ -27,40 +27,40 @@ # CHECK-EMPTY: ## -fno-PIC call stubs of f and g. -## .plt[0] = 0x10030000 = 65536*4099+0 -## .plt[1] = 0x10030004 = 65536*4099+4 +## .plt[0] = 0x100302c4 = 65536*4099+708 +## .plt[1] = 0x100302c8 = 65536*4099+712 # CHECK-NEXT: 00000000.plt_call32.f: # CHECK-NEXT: lis 11, 4099 -# CHECK-NEXT: lwz 11, 0(11) +# CHECK-NEXT: lwz 11, 708(11) # CHECK-NEXT: mtctr 11 # CHECK-NEXT: bctr # CHECK-EMPTY: # CHECK-NEXT: 00000000.plt_call32.g: # CHECK-NEXT: lis 11, 4099 -# CHECK-NEXT: lwz 11, 4(11) +# CHECK-NEXT: lwz 11, 712(11) # CHECK-NEXT: mtctr 11 # CHECK-NEXT: bctr # CHECK-EMPTY: ## In Secure PLT ABI, .plt stores function pointers to first instructions of .glink -# HEX: 0x10030000 10010040 10010044 +# HEX: 0x100302c4 10010200 10010204 ## These instructions are referenced by .plt entries. -# CHECK: 10010040 .glink: +# CHECK: 10010200 .glink: # CHECK-NEXT: b .+8 # CHECK-NEXT: b .+4 ## PLTresolve -## Operands of lis & lwz: .got+4 = 0x10020070+4 = 65536*4098+116 -## Operands of addis & addi: -.glink = -0x10010040 = 65536*-4097-48 +## Operands of lis & lwz: .got+4 = 0x10020070+4 = 65536*4098+700 +## Operands of addis & addi: -.glink = -0x10010200 = 65536*-4097-512 # CHECK-NEXT: lis 12, 4098 # CHECK-NEXT: addis 11, 11, -4097 -# CHECK-NEXT: lwz 0, 116(12) -# CHECK-NEXT: addi 11, 11, -64 +# CHECK-NEXT: lwz 0, 700(12) +# CHECK-NEXT: addi 11, 11, -512 # CHECK-NEXT: mtctr 0 # CHECK-NEXT: add 0, 11, 11 -# CHECK-NEXT: lwz 12, 120(12) +# CHECK-NEXT: lwz 12, 704(12) # CHECK-NEXT: add 11, 0, 11 # CHECK-NEXT: bctr diff --git a/test/ELF/ppc32-call-stub-pic.s b/test/ELF/ppc32-call-stub-pic.s index 30d5192a3..b80434eb3 100644 --- a/test/ELF/ppc32-call-stub-pic.s +++ b/test/ELF/ppc32-call-stub-pic.s @@ -28,15 +28,18 @@ # RELOC-NEXT: R_PPC_JMP_SLOT h 0x0 # RELOC-NEXT: } -# SEC: .got PROGBITS 00020088 -# DYN: PPC_GOT 0x20088 +# SEC: .got PROGBITS 00020374 +# DYN: PPC_GOT 0x20374 ## .got2+0x8000-0x10004 = 0x30000+0x8000-0x10004 = 65536*2+32764 # CHECK-LABEL: _start: -# CHECK-NEXT: bcl 20, 31, .+4 -# CHECK-NEXT: 10004: mflr 30 -# CHECK-NEXT: addis 30, 30, 2 -# CHECK-NEXT: addi 30, 30, 32764 +# CHECK-NEXT: bcl 20, 31, .+4 +# PIE-NEXT: 10210: mflr 30 +# PIE-NEXT: addis 30, 30, 3 +# PIE-NEXT: addi 30, 30, -32400 +# SHARED-NEXT: 10230: mflr 30 +# SHARED-NEXT: addis 30, 30, 3 +# SHARED-NEXT: addi 30, 30, -32408 ## Two bl 00008000.got2.plt_pic32.f # CHECK-NEXT: bl .+40 @@ -80,8 +83,7 @@ ## -fpic call stub of f. # CHECK-NEXT: 00000000.plt_pic32.f: # CHECK-NEXT: addis 11, 30, 2 -# PIE-NEXT: lwz 11, -144(11) -# SHARED-NEXT: lwz 11, -136(11) +# CHECK-NEXT: lwz 11, 4(11) # CHECK-NEXT: mtctr 11 # CHECK-NEXT: bctr # CHECK-EMPTY: @@ -92,36 +94,38 @@ # CHECK-NEXT: 00008000.got2.plt_pic32.f: ## In Secure PLT ABI, .plt stores function pointers to first instructions of .glink -# HEX: 0x0003fff8 00010090 00010094 00010098 +# HEX: 0x00040378 000102a0 000102a4 000102a8 ## These instructions are referenced by .plt entries. -# CHECK: 00010090 .glink: +# PIE: 000102a0 .glink: +# SHARED: 000102c0 .glink: # CHECK-NEXT: b .+12 # CHECK-NEXT: b .+8 # CHECK-NEXT: b .+4 ## PLTresolve ## Operand of addi: 0x100a8-.glink = 24 -# CHECK-NEXT: addis 11, 11, 0 -# CHECK-NEXT: mflr 0 -# CHECK-NEXT: bcl 20, 31, .+4 -# CHECK-NEXT: 100a8: addi 11, 11, 24 +# CHECK-NEXT: addis 11, 11, 0 +# CHECK-NEXT: mflr 0 +# CHECK-NEXT: bcl 20, 31, .+4 +# PIE-NEXT: 102b8: addi 11, 11, 24 +# SHARED-NEXT: 102d8: addi 11, 11, 24 # CHECK-NEXT: mflr 12 # CHECK-NEXT: mtlr 0 # CHECK-NEXT: subf 11, 12, 11 ## Operand of lwz in -pie mode: &.got[1] - 0x100a8 = 0x20088+4 - 0x100a8 = 65536*1-28 -# CHECK-NEXT: addis 12, 12, 1 -# PIE-NEXT: lwz 0, -28(12) -# SHARED-NEXT: lwz 0, -36(12) - -# PIE-NEXT: lwz 12, -24(12) -# SHARED-NEXT: lwz 12, -32(12) -# CHECK-NEXT: mtctr 0 -# CHECK-NEXT: add 0, 11, 11 -# CHECK-NEXT: add 11, 0, 11 -# CHECK-NEXT: bctr +# CHECK-NEXT: addis 12, 12, 1 +# PIE-NEXT: lwz 0, 192(12) +# SHARED-NEXT: lwz 0, 184(12) + +# PIE-NEXT: lwz 12, 196(12) +# SHARED-NEXT: lwz 12, 188(12) +# CHECK-NEXT: mtctr 0 +# CHECK-NEXT: add 0, 11, 11 +# CHECK-NEXT: add 11, 0, 11 +# CHECK-NEXT: bctr .section .got2,"aw" .space 65516 diff --git a/test/ELF/ppc32-gnu-ifunc-nonpreemptable.s b/test/ELF/ppc32-gnu-ifunc-nonpreemptable.s index 388ddf05a..2e2769877 100644 --- a/test/ELF/ppc32-gnu-ifunc-nonpreemptable.s +++ b/test/ELF/ppc32-gnu-ifunc-nonpreemptable.s @@ -6,27 +6,27 @@ # RUN: llvm-readelf -x .got2 %t | FileCheck --check-prefix=HEX %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s -# RELOC: .rela.plt { -# RELOC-NEXT: 0x10020004 R_PPC_IRELATIVE - 0x10010000 +# RELOC: .rela.dyn { +# RELOC-NEXT: 0x10020108 R_PPC_IRELATIVE - 0x100100E0 # RELOC-NEXT: } -# SYM: 10010020 0 FUNC GLOBAL DEFAULT {{.*}} func -# HEX: 0x10020000 10010020 +# SYM: 10010100 0 FUNC GLOBAL DEFAULT {{.*}} func +# HEX: 0x10020104 10010100 .section .got2,"aw" .long func # CHECK: func_resolver: -# CHECK-NEXT: 10010000: blr +# CHECK-NEXT: 100100e0: blr # CHECK: _start: # CHECK-NEXT: bl .+12 # CHECK-NEXT: lis 9, 4097 -# CHECK-NEXT: addi 9, 9, 32 +# CHECK-NEXT: addi 9, 9, 256 # CHECK-EMPTY: # CHECK-NEXT: 00000000.plt_call32.func: -## 10020004 = 65536*4098+4 +## 0x10020108 = 65536*4098+264 # CHECK-NEXT: lis 11, 4098 -# CHECK-NEXT: lwz 11, 4(11) +# CHECK-NEXT: lwz 11, 264(11) .text .globl func diff --git a/test/ELF/ppc32-gnu-ifunc.s b/test/ELF/ppc32-gnu-ifunc.s index 87c1c0bab..ab2c71a5c 100644 --- a/test/ELF/ppc32-gnu-ifunc.s +++ b/test/ELF/ppc32-gnu-ifunc.s @@ -5,15 +5,15 @@ # RUN: llvm-readelf -S -s %t | FileCheck --check-prefixes=SEC,SYM %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s -# RELOC: .rela.plt { -# RELOC-NEXT: 0x10020000 R_PPC_IRELATIVE - 0x10010000 +# RELOC: .rela.dyn { +# RELOC-NEXT: 0x10020114 R_PPC_IRELATIVE - 0x100100E0 # RELOC-NEXT: } -# SEC: .rela.plt RELA 100000d4 0000d4 00000c -# SYM: 10010000 0 FUNC GLOBAL DEFAULT {{.*}} func +# SEC: .rela.dyn RELA 100000d4 0000d4 00000c +# SYM: 100100e0 0 FUNC GLOBAL DEFAULT {{.*}} func # CHECK: func_resolver: -# CHECK-NEXT: 10010000: +# CHECK-NEXT: 100100e0: # CHECK: _start: # CHECK-NEXT: bl .+20 ## .rela.plt = 0x100000d4 = 65536*4096+212 diff --git a/test/ELF/ppc32-reloc-got.s b/test/ELF/ppc32-reloc-got.s index 3e9b644fb..9fc952f79 100644 --- a/test/ELF/ppc32-reloc-got.s +++ b/test/ELF/ppc32-reloc-got.s @@ -1,7 +1,7 @@ # REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=powerpc %s -o %t.o # RUN: echo '.globl b; b:' | llvm-mc -filetype=obj -triple=powerpc - -o %t1.o -# RUN: ld.lld -shared %t1.o -o %t1.so +# RUN: ld.lld -shared %t1.o -soname=t1.so -o %t1.so # RUN: ld.lld %t.o %t1.so -o %t # RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s @@ -14,14 +14,14 @@ # SEC: .got PROGBITS 00020068 020068 000014 # RELOC: .rela.dyn { -# RELOC-NEXT: 0x10020078 R_PPC_GLOB_DAT b 0x0 +# RELOC-NEXT: 0x1002021C R_PPC_GLOB_DAT b 0x0 # RELOC-NEXT: } -# NM: 10030000 d a +# NM: 10030220 d a ## The GOT slot of a can be filled at link time. # HEX: section '.got': -# HEX: 0x10020068 {{[0-9a-f]+}} 00000000 00000000 10030000 +# HEX: 0x1002020c {{[0-9a-f]+}} 00000000 00000000 10030220 ## a: &.got[3] - _GLOBAL_OFFSET_TABLE_ = 12 ## b: &.got[4] - _GLOBAL_OFFSET_TABLE_ = 16 diff --git a/test/ELF/ppc32-tls-gd.s b/test/ELF/ppc32-tls-gd.s index 6d8372dc4..390b4b0a0 100644 --- a/test/ELF/ppc32-tls-gd.s +++ b/test/ELF/ppc32-tls-gd.s @@ -18,15 +18,15 @@ # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=IE %s ## DT_PPC_GOT represents the address of _GLOBAL_OFFSET_TABLE_. -# GD-DYN: PPC_GOT 0x20078 +# GD-DYN: PPC_GOT 0x2035C # GD-REL: .rela.dyn { -# GD-REL-NEXT: 0x20078 R_PPC_DTPMOD32 a 0x0 -# GD-REL-NEXT: 0x2007C R_PPC_DTPREL32 a 0x0 -# GD-REL-NEXT: 0x20080 R_PPC_DTPMOD32 b 0x0 -# GD-REL-NEXT: 0x20084 R_PPC_DTPREL32 b 0x0 -# GD-REL-NEXT: 0x20088 R_PPC_DTPMOD32 c 0x0 -# GD-REL-NEXT: 0x2008C R_PPC_DTPREL32 c 0x0 +# GD-REL-NEXT: 0x2035C R_PPC_DTPMOD32 a 0x0 +# GD-REL-NEXT: 0x20360 R_PPC_DTPREL32 a 0x0 +# GD-REL-NEXT: 0x20364 R_PPC_DTPMOD32 b 0x0 +# GD-REL-NEXT: 0x20368 R_PPC_DTPREL32 b 0x0 +# GD-REL-NEXT: 0x2036C R_PPC_DTPMOD32 c 0x0 +# GD-REL-NEXT: 0x20370 R_PPC_DTPREL32 c 0x0 # GD-REL-NEXT: } ## &DTPMOD(a) - _GLOBAL_OFFSET_TABLE_ = 0x20078 - 0x20078 = 0 @@ -60,8 +60,8 @@ # LE-NEXT: lwz 3, 0(3) # IE-REL: .rela.dyn { -# IE-REL-NEXT: 0x10020068 R_PPC_TPREL32 b 0x0 -# IE-REL-NEXT: 0x1002006C R_PPC_TPREL32 c 0x0 +# IE-REL-NEXT: 0x10020274 R_PPC_TPREL32 b 0x0 +# IE-REL-NEXT: 0x10020278 R_PPC_TPREL32 c 0x0 # IE-REL-NEXT: } ## a is relaxed to use LE. diff --git a/test/ELF/ppc32-tls-ie.s b/test/ELF/ppc32-tls-ie.s index ebd6fa37d..9bc8ffc6e 100644 --- a/test/ELF/ppc32-tls-ie.s +++ b/test/ELF/ppc32-tls-ie.s @@ -11,8 +11,8 @@ ## A non-preemptable symbol (b) has 0 st_shndx. # IE-REL: .rela.dyn { -# IE-REL-NEXT: 0x2005C R_PPC_TPREL32 - 0xC -# IE-REL-NEXT: 0x20058 R_PPC_TPREL32 a 0x0 +# IE-REL-NEXT: 0x20224 R_PPC_TPREL32 - 0xC +# IE-REL-NEXT: 0x20220 R_PPC_TPREL32 a 0x0 # IE-REL-NEXT: } ## &.got[0] - _GLOBAL_OFFSET_TABLE_ = 0 diff --git a/test/ELF/ppc32-tls-ld.s b/test/ELF/ppc32-tls-ld.s index cf6be367c..888eb8e4d 100644 --- a/test/ELF/ppc32-tls-ld.s +++ b/test/ELF/ppc32-tls-ld.s @@ -11,7 +11,7 @@ # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s # LD-REL: .rela.dyn { -# LD-REL-NEXT: 0x20078 R_PPC_DTPMOD32 - 0x0 +# LD-REL-NEXT: 0x202CC R_PPC_DTPMOD32 - 0x0 # LD-REL-NEXT: } ## .got - _GLOBAL_OFFSET_TABLE_ = 0 diff --git a/test/ELF/ppc64-abs64-dyn.s b/test/ELF/ppc64-abs64-dyn.s index f8629c3a1..24976316c 100644 --- a/test/ELF/ppc64-abs64-dyn.s +++ b/test/ELF/ppc64-abs64-dyn.s @@ -12,10 +12,10 @@ ## FIXME the addend for offset 0x20000 should be TOC base+0x8000+1, not 0x80001. # CHECK: .rela.dyn { -# CHECK-NEXT: 0x20000 R_PPC64_RELATIVE - 0x8001 -# CHECK-NEXT: 0x20008 R_PPC64_RELATIVE - 0x20001 -# CHECK-NEXT: 0x20010 R_PPC64_ADDR64 external 0x1 -# CHECK-NEXT: 0x20018 R_PPC64_ADDR64 global 0x1 +# CHECK-NEXT: 0x303B0 R_PPC64_RELATIVE - 0x8001 +# CHECK-NEXT: 0x303B8 R_PPC64_RELATIVE - 0x303B1 +# CHECK-NEXT: 0x303C0 R_PPC64_ADDR64 external 0x1 +# CHECK-NEXT: 0x303C8 R_PPC64_ADDR64 global 0x1 # CHECK-NEXT: } .data diff --git a/test/ELF/ppc64-bsymbolic-toc-restore.s b/test/ELF/ppc64-bsymbolic-toc-restore.s index d467d22ff..ff5eb1482 100644 --- a/test/ELF/ppc64-bsymbolic-toc-restore.s +++ b/test/ELF/ppc64-bsymbolic-toc-restore.s @@ -63,6 +63,6 @@ caller: # CHECK-EMPTY: # CHECK-NEXT: def: # CHECK-NEXT: addis 2, 12, 2 -# CHECK-NEXT: addi 2, 2, -32616 +# CHECK-NEXT: addi 2, 2, -32456 # CHECK-NEXT: li 3, 55 # CHECK-NEXT: blr diff --git a/test/ELF/ppc64-call-reach.s b/test/ELF/ppc64-call-reach.s index 8a32af07a..4b5615b69 100644 --- a/test/ELF/ppc64-call-reach.s +++ b/test/ELF/ppc64-call-reach.s @@ -2,37 +2,37 @@ # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o # RUN: ld.lld --defsym callee=0x12010010 --defsym tail_callee=0x12010020 \ -# RUN: %t.o -o %t +# RUN: -z separate-code %t.o -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s # RUN: ld.lld --defsym callee=0x12010010 --defsym tail_callee=0x12010020 \ -# RUN: %t.o -o %t +# RUN: -z separate-code %t.o -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s # RUN: ld.lld --defsym callee=0xE010014 --defsym tail_callee=0xE010024 \ -# RUN: %t.o -o %t +# RUN: -z separate-code %t.o -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=NEGOFFSET %s # RUN: ld.lld --defsym callee=0x12010018 --defsym tail_callee=0x12010028 \ -# RUN: %t.o -o %t +# RUN: -z separate-code %t.o -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=THUNK %s # RUN: llvm-readelf --sections %t | FileCheck --check-prefix=BRANCHLT %s # RUN: not ld.lld --defsym callee=0x1001002D --defsym tail_callee=0x1001002F \ -# RUN: %t.o -o %t 2>&1 | FileCheck --check-prefix=MISSALIGNED %s +# RUN: -z separate-code %t.o -o %t 2>&1 | FileCheck --check-prefix=MISSALIGNED %s # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o # RUN: ld.lld --defsym callee=0x12010010 --defsym tail_callee=0x12010020 \ -# RUN: %t.o -o %t +# RUN: -z separate-code %t.o -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s # RUN: ld.lld --defsym callee=0x12010010 --defsym tail_callee=0x12010020 \ -# RUN: %t.o -o %t +# RUN: -z separate-code %t.o -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s # RUN: ld.lld --defsym callee=0xE010014 --defsym tail_callee=0xE010024 \ -# RUN: %t.o -o %t +# RUN: -z separate-code %t.o -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=NEGOFFSET %s # RUN: ld.lld --defsym callee=0x12010018 --defsym tail_callee=0x12010028 \ -# RUN: %t.o -o %t +# RUN: -z separate-code %t.o -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=THUNK %s # RUN: llvm-readelf --sections %t | FileCheck --check-prefix=BRANCHLT %s # RUN: not ld.lld --defsym callee=0x1001002D --defsym tail_callee=0x1001002F \ -# RUN: %t.o -o %t 2>&1 | FileCheck --check-prefix=MISSALIGNED %s +# RUN: -z separate-code %t.o -o %t 2>&1 | FileCheck --check-prefix=MISSALIGNED %s # MISSALIGNED: ld.lld: error: {{.*}}.o:(.text+0x14): improper alignment for relocation R_PPC64_REL24: 0x19 is not aligned to 4 bytes # MISSALIGNED: ld.lld: error: {{.*}}.o:(.text+0x24): improper alignment for relocation R_PPC64_REL24: 0xB is not aligned to 4 bytes @@ -72,19 +72,19 @@ test: # .branch_lt[0] # THUNK-LABEL: __long_branch_callee: # THUNK-NEXT: 10010028: addis 12, 2, 1 -# THUNK-NEXT: ld 12, -32768(12) +# THUNK-NEXT: ld 12, -32760(12) # THUNK-NEXT: mtctr 12 # THUNK-NEXT: bctr # .branch_lt[1] # THUNK-LABEL: __long_branch_tail_callee: # THUNK-NEXT: 10010038: addis 12, 2, 1 -# THUNK-NEXT: ld 12, -32760(12) +# THUNK-NEXT: ld 12, -32752(12) # THUNK-NEXT: mtctr 12 # THUNK-NEXT: bctr # The offset from the TOC to the .branch_lt section is (-1 << 16) - 32768. # Name Type Address Off Size # BRANCHLT: .got PROGBITS 0000000010020000 020000 000008 -# BRANCHLT: .branch_lt PROGBITS 0000000010030000 030000 000010 +# BRANCHLT: .branch_lt PROGBITS 0000000010030008 020008 000010 # BRANCHLT-NOT: .plt diff --git a/test/ELF/ppc64-dq.s b/test/ELF/ppc64-dq.s index b29879d02..652bd0f5a 100644 --- a/test/ELF/ppc64-dq.s +++ b/test/ELF/ppc64-dq.s @@ -28,5 +28,7 @@ test: # Verify that we don't overwrite any of the extended opcode bits on a DQ form # instruction. # CHECK-LABEL: test -# CHECK: lxv 3, -32768(3) -# CHECK: stxv 3, -32768(3) +# CHECK: addis 3, 2, 1 +# CHECK-NEXT: lxv 3, -32752(3) +# CHECK-NEXT: addis 3, 2, 1 +# CHECK-NEXT: stxv 3, -32752(3) diff --git a/test/ELF/ppc64-dtprel.s b/test/ELF/ppc64-dtprel.s index 4bb767a48..61ec52e17 100644 --- a/test/ELF/ppc64-dtprel.s +++ b/test/ELF/ppc64-dtprel.s @@ -137,15 +137,15 @@ k: // OutputRelocs-NEXT: R_PPC64_DTPMOD64 -// The got entry for i is at .got+8*3 = 0x420510 +// The got entry for i is at .got+8*1 = 0x4209e0 // i@dtprel = 1024 - 0x8000 = -31744 = 0xffffffffffff8400 // HEX-LE: section '.got': -// HEX-LE-NEXT: 4204f8 f8844200 00000000 00000000 00000000 -// HEX-LE-NEXT: 420508 00000000 00000000 +// HEX-LE-NEXT: 4209d8 d8894200 00000000 00000000 00000000 +// HEX-LE-NEXT: 4209e8 00000000 00000000 // HEX-BE: section '.got': -// HEX-BE-NEXT: 4204f8 00000000 004284f8 00000000 00000000 -// HEX-BE-NEXT: 420508 00000000 00000000 +// HEX-BE-NEXT: 4209d8 00000000 004289d8 00000000 00000000 +// HEX-BE-NEXT: 4209e8 00000000 00000000 // Dis: test: // Dis: addi 4, 3, -31744 diff --git a/test/ELF/ppc64-entry-point.s b/test/ELF/ppc64-entry-point.s index 0977158a4..fdae09e33 100644 --- a/test/ELF/ppc64-entry-point.s +++ b/test/ELF/ppc64-entry-point.s @@ -34,12 +34,12 @@ _start: .Lfunc_end0: .size _start, .Lfunc_end0-.Lfunc_begin0 -# NM-DAG: 0000000010028000 d .TOC. -# NM-DAG: 0000000010010000 T _start - -# 0x10010000 = (4097<<16) + 0 -# CHECK: 10010000: lis 4, 4097 -# CHECK-NEXT: 10010004: addi 4, 4, 0 -# .TOC. - _start = (2<<16) - 32768 -# CHECK-NEXT: 10010008: lis 5, 2 -# CHECK-NEXT: 1001000c: addi 5, 5, -32768 +# NM-DAG: 00000000100281f0 d .TOC. +# NM-DAG: 00000000100101d0 T _start + +# 0x100101d0 = (4097<<16) + 464 +# CHECK: 100101d0: lis 4, 4097 +# CHECK-NEXT: 100101d4: addi 4, 4, 464 +# .TOC. - _start = (2<<16) - 32736 +# CHECK-NEXT: 100101d8: lis 5, 2 +# CHECK-NEXT: 100101dc: addi 5, 5, -32736 diff --git a/test/ELF/ppc64-error-missaligned-dq.s b/test/ELF/ppc64-error-missaligned-dq.s index 68ad2e5c4..a7c43eb28 100644 --- a/test/ELF/ppc64-error-missaligned-dq.s +++ b/test/ELF/ppc64-error-missaligned-dq.s @@ -6,7 +6,7 @@ # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o # RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s -# CHECK: improper alignment for relocation R_PPC64_TOC16_LO_DS: 0x8001 is not aligned to 16 bytes +# CHECK: improper alignment for relocation R_PPC64_TOC16_LO_DS: 0x8009 is not aligned to 16 bytes .global test .p2align 4 @@ -21,6 +21,6 @@ test: lxv 3, qword@toc@l(3) blr + .p2align 4 .comm pad, 1, 1 .comm qword, 16, 1 - diff --git a/test/ELF/ppc64-error-missaligned-ds.s b/test/ELF/ppc64-error-missaligned-ds.s index deee8f9ca..81b19781d 100644 --- a/test/ELF/ppc64-error-missaligned-ds.s +++ b/test/ELF/ppc64-error-missaligned-ds.s @@ -6,7 +6,7 @@ # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o # RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s -# CHECK: improper alignment for relocation R_PPC64_TOC16_LO_DS: 0x8001 is not aligned to 4 bytes +# CHECK: improper alignment for relocation R_PPC64_TOC16_LO_DS: 0x8009 is not aligned to 4 bytes .global test .p2align 4 @@ -21,6 +21,6 @@ test: lwa 3, word@toc@l(3) blr + .p2align 4 .comm pad, 1, 1 .comm word, 4, 1 - diff --git a/test/ELF/ppc64-func-entry-points.s b/test/ELF/ppc64-func-entry-points.s index 9b9e26ab0..1411cbe1c 100644 --- a/test/ELF/ppc64-func-entry-points.s +++ b/test/ELF/ppc64-func-entry-points.s @@ -4,13 +4,13 @@ // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-func-global-entry.s -o %t2.o // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-func-local-entry.s -o %t3.o // RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.o %t3.o -o %t -// RUN: llvm-objdump -d %t | FileCheck %s +// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-func-global-entry.s -o %t2.o // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-func-local-entry.s -o %t3.o // RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.o %t3.o -o %t -// RUN: llvm-objdump -d %t | FileCheck %s +// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s .text .abiversion 2 @@ -69,12 +69,12 @@ glob: # foo_external_diff+8. Also check that foo_external_same has no global entry # point and we branch to start of foo_external_same. -// CHECK: _start: -// CHECK: 10010020: {{.*}} bl .+144 -// CHECK: 10010034: {{.*}} bl .+84 -// CHECK: foo_external_diff: -// CHECK-NEXT: 10010080: {{.*}} addis 2, 12, 1 -// CHECK-NEXT: 10010084: {{.*}} addi 2, 2, 32640 -// CHECK-NEXT: 10010088: {{.*}} addis 5, 2, 1 -// CHECK: foo_external_same: -// CHECK-NEXT: 100100b0: {{.*}} add 3, 4, 3 +// CHECK-LABEL: _start: +// CHECK: 100101f0: bl .+144 +// CHECK: 10010204: bl .+84 +// CHECK-LABEL: foo_external_diff: +// CHECK-NEXT: 10010250: addis 2, 12, 2 +// CHECK-NEXT: 10010254: addi 2, 2, -32696 +// CHECK-NEXT: 10010258: addis 5, 2, 1 +// CHECK-LABEL: foo_external_same: +// CHECK-NEXT: 10010280: add 3, 4, 3 diff --git a/test/ELF/ppc64-ifunc.s b/test/ELF/ppc64-ifunc.s index 32e317f3c..4bc1ce7e0 100644 --- a/test/ELF/ppc64-ifunc.s +++ b/test/ELF/ppc64-ifunc.s @@ -5,50 +5,53 @@ # RUN: llvm-nm %t | FileCheck --check-prefix=NM %s # RUN: llvm-readelf -S %t | FileCheck --check-prefix=SECTIONS %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s -# RUN: llvm-readelf -r %t | FileCheck --check-prefix=DYNREL %s +# RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o # RUN: ld.lld %t.o -o %t # RUN: llvm-nm %t | FileCheck --check-prefix=NM %s # RUN: llvm-readelf -S %t | FileCheck --check-prefix=SECTIONS %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s -# RUN: llvm-readelf -r %t | FileCheck --check-prefix=DYNREL %s +# RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s -# NM-DAG: 0000000010028000 d .TOC. -# NM-DAG: 0000000010010000 T ifunc -# NM-DAG: 0000000010010004 T ifunc2 +# NM-DAG: 0000000010028248 d .TOC. +# NM-DAG: 00000000100101f8 T ifunc +# NM-DAG: 00000000100101fc T ifunc2 -# SECTIONS: .plt NOBITS 0000000010030000 +# SECTIONS: .plt NOBITS 0000000010030250 000250 000010 00 WA 0 0 8 -# __plt_ifunc - . = 0x10010020 - 0x10010010 = 16 -# __plt_ifunc2 - . = 0x10010044 - 0x10010018 = 28 +# __plt_ifunc - . = 0x10010218 - 0x10010208 = 16 +# __plt_ifunc2 - . = 0x1001022c - 0x10010210 = 28 # CHECK: _start: -# CHECK-NEXT: addis 2, 12, 1 -# CHECK-NEXT: addi 2, 2, 32760 -# CHECK-NEXT: 10010010: bl .+16 +# CHECK-NEXT: addis 2, 12, 2 +# CHECK-NEXT: addi 2, 2, -32696 +# CHECK-NEXT: 10010208: bl .+16 # CHECK-NEXT: ld 2, 24(1) -# CHECK-NEXT: 10010018: bl .+28 +# CHECK-NEXT: 10010210: bl .+28 # CHECK-NEXT: ld 2, 24(1) -# .plt[0] - .TOC. = 0x10030000 - 0x10028000 = (1<<16) - 32768 +# .plt[0] - .TOC. = 0x10030250 - 0x10028248 = (1<<16) - 32760 # CHECK: __plt_ifunc: # CHECK-NEXT: std 2, 24(1) # CHECK-NEXT: addis 12, 2, 1 -# CHECK-NEXT: ld 12, -32768(12) +# CHECK-NEXT: ld 12, -32760(12) # CHECK-NEXT: mtctr 12 # CHECK-NEXT: bctr -# .plt[1] - .TOC. = 0x10030000+8 - 0x10028000 = (1<<16) - 32760 +# .plt[1] - .TOC. = 0x10030250+8 - 0x10028248 = (1<<16) - 32752 # CHECK: __plt_ifunc2: # CHECK-NEXT: std 2, 24(1) # CHECK-NEXT: addis 12, 2, 1 -# CHECK-NEXT: ld 12, -32760(12) +# CHECK-NEXT: ld 12, -32752(12) # CHECK-NEXT: mtctr 12 # CHECK-NEXT: bctr -# Check that we emit 2 R_PPC64_IRELATIVE. -# DYNREL: R_PPC64_IRELATIVE 10010000 -# DYNREL: R_PPC64_IRELATIVE 10010004 +## Check that we emit 2 R_PPC64_IRELATIVE in .rela.dyn. +## glibc powerpc64 does not eagerly resolve R_PPC64_IRELATIVE if they are in .rela.plt. +# REL: .rela.dyn { +# REL-NEXT: 0x10030250 R_PPC64_IRELATIVE - 0x100101F8 +# REL-NEXT: 0x10030258 R_PPC64_IRELATIVE - 0x100101FC +# REL-NEXT: } .type ifunc STT_GNU_IFUNC .globl ifunc diff --git a/test/ELF/ppc64-local-dynamic.s b/test/ELF/ppc64-local-dynamic.s index 87e33b784..371b56614 100644 --- a/test/ELF/ppc64-local-dynamic.s +++ b/test/ELF/ppc64-local-dynamic.s @@ -1,14 +1,14 @@ // REQUIRES: ppc // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o -// RUN: ld.lld -shared %t.o -o %t.so +// RUN: ld.lld -shared %t.o -z separate-code -o %t.so // RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s // RUN: llvm-readelf -r %t.so | FileCheck --check-prefix=OutputRelocs %s // RUN: llvm-objdump --section-headers %t.so | FileCheck --check-prefix=CheckGot %s // RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=Dis %s // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o -// RUN: ld.lld -shared %t.o -o %t.so +// RUN: ld.lld -shared %t.o -z separate-code -o %t.so // RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s // RUN: llvm-readelf -r %t.so | FileCheck --check-prefix=OutputRelocs %s // RUN: llvm-objdump --section-headers %t.so | FileCheck --check-prefix=CheckGot %s diff --git a/test/ELF/ppc64-long-branch-localentry-offset.s b/test/ELF/ppc64-long-branch-localentry-offset.s index fd37c13db..9e631747e 100644 --- a/test/ELF/ppc64-long-branch-localentry-offset.s +++ b/test/ELF/ppc64-long-branch-localentry-offset.s @@ -1,7 +1,7 @@ # REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=ppc64le %s -o %t.o -# RUN: ld.lld %t.o -o %t +# RUN: ld.lld %t.o -z separate-code -o %t # RUN: llvm-nm %t | FileCheck %s # CHECK-DAG: 0000000010010000 t __long_branch_callee diff --git a/test/ELF/ppc64-long-branch.s b/test/ELF/ppc64-long-branch.s index bf13b6432..2a6f66dfb 100644 --- a/test/ELF/ppc64-long-branch.s +++ b/test/ELF/ppc64-long-branch.s @@ -1,13 +1,13 @@ # REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o -# RUN: ld.lld --no-toc-optimize %t.o -o %t +# RUN: ld.lld --no-toc-optimize -z separate-code %t.o -o %t # RUN: llvm-nm %t | FileCheck --check-prefix=NM %s # RUN: llvm-readelf -x .branch_lt %t | FileCheck %s -check-prefix=BRANCH-LE # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o -# RUN: ld.lld --no-toc-optimize %t.o -o %t +# RUN: ld.lld --no-toc-optimize -z separate-code %t.o -o %t # RUN: llvm-nm %t | FileCheck --check-prefix=NM %s # RUN: llvm-readelf -x .branch_lt %t | FileCheck %s -check-prefix=BRANCH-BE # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s @@ -82,13 +82,13 @@ a: # CHECK: 12010038: bl .+16 # BRANCH-LE: section '.branch_lt': -# BRANCH-LE-NEXT: 0x12030008 08000110 00000000 +# BRANCH-LE-NEXT: 0x12030018 08000110 00000000 # BRANCH-BE: section '.branch_lt': -# BRANCH-BE-NEXT: 0x12030008 00000000 10010008 +# BRANCH-BE-NEXT: 0x12030018 00000000 10010008 -# .branch_lt - .TOC. = 0x12030008 - 0x12028000 = (1<<16) - 32760 +# .branch_lt - .TOC. = 0x12030018 - 0x12028000 = (1<<16) - 32744 # CHECK: __long_branch_callee: # CHECK-NEXT: 12010048: addis 12, 2, 1 -# CHECK-NEXT: ld 12, -32760(12) +# CHECK-NEXT: ld 12, -32744(12) # CHECK-NEXT: mtctr 12 # CHECK-NEXT: bctr diff --git a/test/ELF/ppc64-plt-stub.s b/test/ELF/ppc64-plt-stub.s index 44ea40dca..1420f43e2 100644 --- a/test/ELF/ppc64-plt-stub.s +++ b/test/ELF/ppc64-plt-stub.s @@ -15,8 +15,8 @@ # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s ## DT_PLTGOT points to .plt -# SEC: .plt NOBITS 0000000010030000 030000 000018 -# SEC: 0x0000000000000003 (PLTGOT) 0x10030000 +# SEC: .plt NOBITS 00000000100303e8 0003e8 000018 +# SEC: 0x0000000000000003 (PLTGOT) 0x100303e8 ## .plt[0] holds the address of _dl_runtime_resolve. ## .plt[1] holds the link map. @@ -24,12 +24,12 @@ # RELOC: 0x10030010 R_PPC64_JMP_SLOT foo 0x0 # CHECK: _start: -# CHECK: 10010008: bl .+16 +# CHECK: 10010298: bl .+16 -# CHECK-LABEL: 0000000010010018 __plt_foo: +# CHECK-LABEL: 00000000100102a8 __plt_foo: # CHECK-NEXT: std 2, 24(1) -# CHECK-NEXT: addis 12, 2, 0 -# CHECK-NEXT: ld 12, 32560(12) +# CHECK-NEXT: addis 12, 2, 1 +# CHECK-NEXT: ld 12, -32744(12) # CHECK-NEXT: mtctr 12 # CHECK-NEXT: bctr diff --git a/test/ELF/ppc64-rel-calls.s b/test/ELF/ppc64-rel-calls.s index 9c0c21c01..9969239d8 100644 --- a/test/ELF/ppc64-rel-calls.s +++ b/test/ELF/ppc64-rel-calls.s @@ -2,11 +2,11 @@ # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t # RUN: ld.lld %t -o %t2 -# RUN: llvm-objdump -d %t2 | FileCheck %s +# RUN: llvm-objdump -d --no-show-raw-insn %t2 | FileCheck %s # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t # RUN: ld.lld %t -o %t2 -# RUN: llvm-objdump -d %t2 | FileCheck %s +# RUN: llvm-objdump -d --no-show-raw-insn %t2 | FileCheck %s # CHECK: Disassembly of section .text: # CHECK-EMPTY: @@ -19,9 +19,9 @@ _start: li 3,42 sc -# CHECK: 10010000: {{.*}} li 0, 1 -# CHECK: 10010004: {{.*}} li 3, 42 -# CHECK: 10010008: {{.*}} sc +# CHECK: 10010158: li 0, 1 +# CHECK: 1001015c: li 3, 42 +# CHECK: 10010160: sc .global bar bar: @@ -31,8 +31,8 @@ bar: nop blr -# CHECK: 1001000c: {{.*}} bl .-12 -# CHECK: 10010010: {{.*}} nop -# CHECK: 10010014: {{.*}} bl .-20 -# CHECK: 10010018: {{.*}} nop -# CHECK: 1001001c: {{.*}} blr +# CHECK: 10010164: bl .-12 +# CHECK-NEXT: nop +# CHECK-NEXT: 1001016c: bl .-20 +# CHECK-NEXT: nop +# CHECK-NEXT: blr diff --git a/test/ELF/ppc64-reloc-rel.s b/test/ELF/ppc64-reloc-rel.s new file mode 100644 index 000000000..be64a4f76 --- /dev/null +++ b/test/ELF/ppc64-reloc-rel.s @@ -0,0 +1,58 @@ +# REQUIRES: ppc + +# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o +# RUN: ld.lld %t.o --defsym=foo=rel16+0x8000 -o %t +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s +# RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=REL %s +# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC %s +# RUN: llvm-readelf -x .eh_frame %t | FileCheck --check-prefix=HEX %s + +.section .R_PPC64_REL14,"ax",@progbits +# FIXME This does not produce a relocation + beq 1f +1: +# CHECK-LABEL: Disassembly of section .R_PPC64_REL14: +# CHECK: bt 2, .+4 + +.section .R_PPC64_REL16,"ax",@progbits +.globl rel16 +rel16: + li 3, foo-rel16-1@ha # R_PPC64_REL16_HA + li 3, foo-rel16@ha + li 4, foo-rel16+0x7fff@h # R_PPC64_REL16_HI + li 4, foo-rel16+0x8000@h + li 5, foo-rel16-1@l # R_PPC64_REL16_LO + li 5, foo-rel16@l +# CHECK-LABEL: Disassembly of section .R_PPC64_REL16: +# CHECK: li 3, 0 +# CHECK-NEXT: li 3, 1 +# CHECK-NEXT: li 4, 0 +# CHECK-NEXT: li 4, 1 +# CHECK-NEXT: li 5, 32767 +# CHECK-NEXT: li 5, -32768 + +.section .R_PPC64_REL24,"ax",@progbits + b rel16 +# CHECK-LABEL: Disassembly of section .R_PPC64_REL24: +# CHECK: b .+67108840 + +.section .REL32_AND_REL64,"ax",@progbits + .cfi_startproc + .cfi_personality 148, rel64 + nop + .cfi_endproc +rel64: + li 3, 0 +# REL: .rela.eh_frame { +# REL-NEXT: 0x12 R_PPC64_REL64 .REL32_AND_REL64 0x4 +# REL-NEXT: 0x28 R_PPC64_REL32 .REL32_AND_REL64 0x0 +# REL-NEXT: } + +# SEC: .REL32_AND_REL64 PROGBITS 00000000100101b4 + +## CIE Personality Address: 0x100101b4-(0x10000168+2)+4 = 0x1004e +## FDE PC Begin: 0x100101b4-(0x10000178+8) = 0x10034 +# HEX: section '.eh_frame': +# HEX-NEXT: 0x10000158 +# HEX-NEXT: 0x10000168 {{....}}4e00 01000000 0000{{....}} +# HEX-NEXT: 0x10000178 {{[0-9a-f]+}} {{[0-9a-f]+}} 34000100 diff --git a/test/ELF/ppc64-relocs.s b/test/ELF/ppc64-relocs.s index 5e8c529e9..0fe0edfc5 100644 --- a/test/ELF/ppc64-relocs.s +++ b/test/ELF/ppc64-relocs.s @@ -18,147 +18,84 @@ _start: li 3,42 sc -.section .rodata,"a",@progbits - .p2align 2 -.LJTI0_0: - .long .LBB0_2-.LJTI0_0 - -.section .toc,"aw",@progbits +.section .toc,"aw",@progbits .L1: -.quad 22, 37, 89, 47 -.LC0: - .tc .LJTI0_0[TC],.LJTI0_0 + .quad 22, 37, 89, 47 .section .R_PPC64_TOC16_LO_DS,"ax",@progbits ld 1, .L1@toc@l(2) # CHECK-LABEL: Disassembly of section .R_PPC64_TOC16_LO_DS: -# CHECK: 1001000c: ld 1, -32768(2) +# CHECK: ld 1, -32768(2) .section .R_PPC64_TOC16_LO,"ax",@progbits addi 1, 2, .L1@toc@l # CHECK-LABEL: Disassembly of section .R_PPC64_TOC16_LO: -# CHECK: 10010010: addi 1, 2, -32768 +# CHECK: addi 1, 2, -32768 .section .R_PPC64_TOC16_HI,"ax",@progbits addis 1, 2, .L1@toc@h # CHECK-LABEL: Disassembly of section .R_PPC64_TOC16_HI: -# CHECK: 10010014: addis 1, 2, -1 +# CHECK: addis 1, 2, -1 .section .R_PPC64_TOC16_HA,"ax",@progbits addis 1, 2, .L1@toc@ha # CHECK-LABEL: Disassembly of section .R_PPC64_TOC16_HA: -# CHECK: 10010018: addis 1, 2, 0 - -.section .R_PPC64_REL24,"ax",@progbits - b 1f -1: - -# CHECK-LABEL: Disassembly of section .R_PPC64_REL24: -# CHECK: 1001001c: b .+4 - -.section .R_PPC64_REL14,"ax",@progbits - beq 1f -1: - -# CHECK-LABEL: Disassembly of section .R_PPC64_REL14: -# CHECK: 10010020: bt 2, .+4 +# CHECK: addis 1, 2, 0 .section .R_PPC64_ADDR16_LO,"ax",@progbits li 1, .Lfoo@l # CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_LO: -# CHECK: 10010024: li 1, 0 +# CHECK: li 1, 464 .section .R_PPC64_ADDR16_HI,"ax",@progbits li 1, .Lfoo@h # CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HI: -# CHECK: 10010028: li 1, 4097 +# CHECK: li 1, 4097 .section .R_PPC64_ADDR16_HA,"ax",@progbits li 1, .Lfoo@ha # CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HA: -# CHECK: 1001002c: li 1, 4097 +# CHECK: li 1, 4097 .section .R_PPC64_ADDR16_HIGHER,"ax",@progbits li 1, .Lfoo@higher # CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HIGHER: -# CHECK: 10010030: li 1, 0 +# CHECK: li 1, 0 .section .R_PPC64_ADDR16_HIGHERA,"ax",@progbits li 1, .Lfoo@highera # CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HIGHERA: -# CHECK: 10010034: li 1, 0 +# CHECK: li 1, 0 .section .R_PPC64_ADDR16_HIGHEST,"ax",@progbits li 1, .Lfoo@highest # CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HIGHEST: -# CHECK: 10010038: li 1, 0 +# CHECK: li 1, 0 .section .R_PPC64_ADDR16_HIGHESTA,"ax",@progbits li 1, .Lfoo@highesta # CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HIGHESTA: -# CHECK: 1001003c: li 1, 0 - -.section .R_PPC64_REL32, "ax",@progbits - addis 5, 2, .LC0@toc@ha - ld 5, .LC0@toc@l(5) -.LBB0_2: - add 3, 3, 4 - -# DATALE: '.rodata': -# DATALE: 0x100001c8 80fe0000 - -# DATABE: '.rodata': -# DATABE: 0x100001c8 0000fe80 - -# Address of rodata + value stored at rodata entry -# should equal address of LBB0_2. -# 0x10000190 + 0xfeb4 = 0x10010044 -# CHECK-LABEL: Disassembly of section .R_PPC64_REL32: -# CHECK: 10010040: addis 5, 2, 0 -# CHECK: 10010044: ld 5, -32736(5) -# CHECK: 10010048: add 3, 3, 4 - -.section .R_PPC64_REL64, "ax",@progbits - .cfi_startproc - .cfi_personality 148, __foo - li 0, 1 - li 3, 55 - sc - .cfi_endproc -__foo: - li 3,0 +# CHECK: li 1, 0 .section .R_PPC64_TOC,"a",@progbits .quad .TOC.@tocbase -# SEC: .got PROGBITS 0000000010020000 +# SEC: .got PROGBITS 0000000010020208 -## tocbase = .got+0x8000 = 0x10028000 +## tocbase = .got+0x8000 = 0x10028208 # DATALE-LABEL: section '.R_PPC64_TOC': -# DATALE: 00800210 00000000 +# DATALE: 08820210 00000000 # DATABE-LABEL: section '.R_PPC64_TOC': -# DATABE: 00000000 10028000 - -# Check that the personality (relocated by R_PPC64_REL64) in the .eh_frame -# equals the address of __foo. -# 0x100001ea + 0xfe6e = 0x10010058 -# DATALE: section '.eh_frame': -# DATALE: 0x100001e8 {{....}}6efe - -# DATABE: section '.eh_frame': -# DATABE: 0x100001e8 {{[0-9a-f]+ [0-9a-f]+}} fe6e{{....}} - -# CHECK: __foo -# CHECK-NEXT: 10010058: li 3, 0 +# DATABE: 00000000 10028208 diff --git a/test/ELF/ppc64-shared-long_branch.s b/test/ELF/ppc64-shared-long_branch.s index 4ffb39251..93b26edc5 100644 --- a/test/ELF/ppc64-shared-long_branch.s +++ b/test/ELF/ppc64-shared-long_branch.s @@ -1,7 +1,7 @@ # REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o -# RUN: ld.lld --no-toc-optimize -shared %t.o -o %t +# RUN: ld.lld --no-toc-optimize -shared -z separate-code %t.o -o %t # RUN: llvm-objdump -d -start-address=0x10000 -stop-address=0x10018 %t | FileCheck %s -check-prefix=CALLEE_DUMP # RUN: llvm-objdump -d -start-address=0x2010020 -stop-address=0x2010070 %t | FileCheck %s -check-prefix=CALLER_DUMP # RUN: llvm-readelf --sections %t | FileCheck %s -check-prefix=SECTIONS @@ -92,11 +92,10 @@ b: # CALLER_DUMP: 2010020: {{.*}} addis 2, 12, 2 # CALLER_DUMP: 2010038: {{.*}} bl .+56 -# Verify the thunks contents: TOC-pointer + offset = .branch_lt[0] -# 0x20280F0 + 32560 = 0x2030020 +## .branch_lt[0] - .TOC. = # CALLER_DUMP: __long_branch_callee: -# CALLER_DUMP: 2010060: {{.*}} addis 12, 2, 0 -# CALLER_DUMP: 2010064: {{.*}} ld 12, 32560(12) +# CALLER_DUMP: 2010060: {{.*}} addis 12, 2, 1 +# CALLER_DUMP: 2010064: {{.*}} ld 12, -32712(12) # CALLER_DUMP: 2010068: {{.*}} mtctr 12 # CALLER_DUMP: 201006c: {{.*}} bctr @@ -104,11 +103,11 @@ b: # .plt section has a 2 entry header and a single entry for the long branch. # [Nr] Name Type Address Off Size # SECTIONS: [10] .got PROGBITS 00000000020200f0 20200f0 000008 -# SECTIONS: [13] .plt NOBITS 0000000002030008 2030008 000018 -# SECTIONS: [14] .branch_lt NOBITS 0000000002030020 2030008 000008 +# SECTIONS: [13] .plt NOBITS 0000000002030110 2020110 000018 +# SECTIONS: [14] .branch_lt NOBITS 0000000002030128 2020110 000008 # There is a relative dynamic relocation for (.plt + 16 bytes), with a base # address equal to callees local entry point (0x10000 + 8). # DYNRELOC: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 3 entries: # DYNRELOC: Offset Info Type Symbol's Value -# DYNRELOC: 0000000002030020 0000000000000016 R_PPC64_RELATIVE 10008 +# DYNRELOC: 0000000002030128 0000000000000016 R_PPC64_RELATIVE 10008 diff --git a/test/ELF/ppc64-tls-gd.s b/test/ELF/ppc64-tls-gd.s index 5b9c9edbb..8c5cd5904 100644 --- a/test/ELF/ppc64-tls-gd.s +++ b/test/ELF/ppc64-tls-gd.s @@ -16,12 +16,12 @@ # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=IE %s # GD-REL: .rela.dyn { -# GD-REL-NEXT: 0x200F0 R_PPC64_DTPMOD64 a 0x0 -# GD-REL-NEXT: 0x200F8 R_PPC64_DTPREL64 a 0x0 -# GD-REL-NEXT: 0x20100 R_PPC64_DTPMOD64 b 0x0 -# GD-REL-NEXT: 0x20108 R_PPC64_DTPREL64 b 0x0 -# GD-REL-NEXT: 0x20110 R_PPC64_DTPMOD64 c 0x0 -# GD-REL-NEXT: 0x20118 R_PPC64_DTPREL64 c 0x0 +# GD-REL-NEXT: 0x20540 R_PPC64_DTPMOD64 a 0x0 +# GD-REL-NEXT: 0x20548 R_PPC64_DTPREL64 a 0x0 +# GD-REL-NEXT: 0x20550 R_PPC64_DTPMOD64 b 0x0 +# GD-REL-NEXT: 0x20558 R_PPC64_DTPREL64 b 0x0 +# GD-REL-NEXT: 0x20560 R_PPC64_DTPMOD64 c 0x0 +# GD-REL-NEXT: 0x20568 R_PPC64_DTPREL64 c 0x0 # GD-REL-NEXT: } ## &DTPMOD(a) - .TOC. = &.got[0] - (.got+0x8000) = -32768 @@ -59,8 +59,8 @@ # LE-NEXT: addi 3, 3, -28656 # IE-REL: .rela.dyn { -# IE-REL-NEXT: 0x100200C0 R_PPC64_TPREL64 b 0x0 -# IE-REL-NEXT: 0x100200C8 R_PPC64_TPREL64 c 0x0 +# IE-REL-NEXT: 0x10020418 R_PPC64_TPREL64 b 0x0 +# IE-REL-NEXT: 0x10020420 R_PPC64_TPREL64 c 0x0 # IE-REL-NEXT: } ## a is relaxed to use LE. diff --git a/test/ELF/ppc64-tls-ie.s b/test/ELF/ppc64-tls-ie.s index aa5509072..3913f666d 100644 --- a/test/ELF/ppc64-tls-ie.s +++ b/test/ELF/ppc64-tls-ie.s @@ -23,10 +23,10 @@ # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s # IE-REL: .rela.dyn { -# IE-REL-NEXT: 0x200B0 R_PPC64_TPREL64 c 0x0 -# IE-REL-NEXT: 0x200C0 R_PPC64_TPREL64 i 0x0 -# IE-REL-NEXT: 0x200C8 R_PPC64_TPREL64 l 0x0 -# IE-REL-NEXT: 0x200B8 R_PPC64_TPREL64 s 0x0 +# IE-REL-NEXT: 0x204A0 R_PPC64_TPREL64 c 0x0 +# IE-REL-NEXT: 0x204B0 R_PPC64_TPREL64 i 0x0 +# IE-REL-NEXT: 0x204B8 R_PPC64_TPREL64 l 0x0 +# IE-REL-NEXT: 0x204A8 R_PPC64_TPREL64 s 0x0 # IE-REL-NEXT: } # INPUT-REL: R_PPC64_GOT_TPREL16_HA c 0x0 diff --git a/test/ELF/ppc64-tls-vaddr-align.s b/test/ELF/ppc64-tls-vaddr-align.s new file mode 100644 index 000000000..df706b704 --- /dev/null +++ b/test/ELF/ppc64-tls-vaddr-align.s @@ -0,0 +1,34 @@ +# REQUIRES: ppc + +# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readelf -S -l %t | FileCheck --check-prefix=SEC %s +# RUN: llvm-objdump -d %t | FileCheck --check-prefix=DIS %s + +# SEC: Name Type Address Off Size ES Flg Lk Inf Al +# SEC: .tdata PROGBITS 0000000010020300 000300 000001 00 WAT 0 0 1 +# SEC: .tbss NOBITS 0000000010020400 000301 000008 00 WAT 0 0 256 + +# SEC: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# SEC: TLS 0x000300 0x0000000010020300 0x0000000010020300 0x000001 0x000108 R 0x100 + +## We currently have a hack in Writer.cpp:fixSectionAlignments() to force +## p_vaddr(PT_TLS)%p_align(PT_TLS)=0, to work around bugs in some dynamic loaders. + +## p_vaddr rounded down to p_align has TP offset -0x7000. +## The first address of PT_TLS (p_vaddr) has TP offset (p_vaddr%p_align - 0x7000). +## Once we delete the hack, it is likely p_vaddr%p_align != 0. + +## a@tprel = st_value(a) + p_vaddr%p_align - 0x7000 = .tbss-.tdata + p_vaddr%p_align - 0x7000 +## = 0x10020400-0x10020300 + 0 - 0x7000 = -28416 +# DIS: ld 3, -28416(13) + +ld 3, a@tprel(13) + +.section .tdata,"awT" +.byte 0 + +.section .tbss,"awT" +.p2align 8 +a: +.quad 0 diff --git a/test/ELF/ppc64-toc-addis-nop-lqsq.s b/test/ELF/ppc64-toc-addis-nop-lqsq.s index 07c41cc32..08ec5f47c 100644 --- a/test/ELF/ppc64-toc-addis-nop-lqsq.s +++ b/test/ELF/ppc64-toc-addis-nop-lqsq.s @@ -1,4 +1,5 @@ # REQUIRES: ppc +# XFAIL: * # RUN: llvm-readelf -relocations --wide %p/Inputs/ppc64le-quadword-ldst.o | FileCheck --check-prefix=QuadInputRelocs %s diff --git a/test/ELF/ppc64-toc-addis-nop.s b/test/ELF/ppc64-toc-addis-nop.s index 76c45b192..067c5b363 100644 --- a/test/ELF/ppc64-toc-addis-nop.s +++ b/test/ELF/ppc64-toc-addis-nop.s @@ -4,12 +4,15 @@ # RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/shared-ppc64.s -o %t2.o -# RUN: ld.lld -shared %t2.o -o %t2.so +# RUN: ld.lld -shared -soname=t2.so %t2.o -o %t2.so + +## Place all sections in the same segment so that .text and .TOC. are on the same page. +# RUN: echo 'PHDRS { all PT_LOAD; }' > %t.script # -# RUN: ld.lld %t2.so %t.o -o %t +# RUN: ld.lld %t2.so %t.o -T %t.script -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=Dis %s # -# RUN: ld.lld --no-toc-optimize %t2.so %t.o -o %t +# RUN: ld.lld %t2.so %t.o -T %t.script --no-toc-optimize -o %t # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=NoOpt %s # InputRelocs: Relocation section '.rela.text' @@ -39,18 +42,18 @@ bytes: # Dis-NEXT: addis # Dis-NEXT: addi # Dis-NEXT: nop -# Dis-NEXT: lbz 3, 32624(2) +# Dis-NEXT: lbz 3, -32752(2) # Dis-NEXT: nop -# Dis-NEXT: stb 3, 32625(2) +# Dis-NEXT: stb 3, -32751(2) # Dis-NEXT: blr # NoOpt-LABEL: bytes: # NoOpt-NEXT: addis # NoOpt-NEXT: addi # NoOpt-NEXT: addis 3, 2, 0 -# NoOpt-NEXT: lbz 3, 32624(3) +# NoOpt-NEXT: lbz 3, -32752(3) # NoOpt-NEXT: addis 4, 2, 0 -# NoOpt-NEXT: stb 3, 32625(4) +# NoOpt-NEXT: stb 3, -32751(4) # NoOpt-NEXT: blr .global halfs @@ -73,22 +76,22 @@ halfs: # Dis-NEXT: addis # Dis-NEXT: addi # Dis-NEXT: nop -# Dis-NEXT: lhz 3, 32626(2) +# Dis-NEXT: lhz 3, -32750(2) # Dis-NEXT: nop -# Dis-NEXT: lha 4, 32626(2) +# Dis-NEXT: lha 4, -32750(2) # Dis-NEXT: nop -# Dis-NEXT: sth 4, 32628(2) +# Dis-NEXT: sth 4, -32748(2) # Dis-NEXT: blr # NoOpt-LABEL: halfs: # NoOpt-NEXT: addis # NoOpt-NEXT: addi # NoOpt-NEXT: addis 3, 2, 0 -# NoOpt-NEXT: lhz 3, 32626(3) +# NoOpt-NEXT: lhz 3, -32750(3) # NoOpt-NEXT: addis 4, 2, 0 -# NoOpt-NEXT: lha 4, 32626(4) +# NoOpt-NEXT: lha 4, -32750(4) # NoOpt-NEXT: addis 5, 2, 0 -# NoOpt-NEXT: sth 4, 32628(5) +# NoOpt-NEXT: sth 4, -32748(5) # NoOpt-NEXT: blr @@ -112,22 +115,22 @@ words: # Dis-NEXT: addis # Dis-NEXT: addi # Dis-NEXT: nop -# Dis-NEXT: lwz 3, 32632(2) +# Dis-NEXT: lwz 3, -32744(2) # Dis-NEXT: nop -# Dis-NEXT: lwa 4, 32632(2) +# Dis-NEXT: lwa 4, -32744(2) # Dis-NEXT: nop -# Dis-NEXT: stw 4, 32636(2) +# Dis-NEXT: stw 4, -32740(2) # Dis-NEXT: blr # NoOpt-LABEL: words # NoOpt-NEXT: addis # NoOpt-NEXT: addi # NoOpt-NEXT: addis 3, 2, 0 -# NoOpt-NEXT: lwz 3, 32632(3) +# NoOpt-NEXT: lwz 3, -32744(3) # NoOpt-NEXT: addis 4, 2, 0 -# NoOpt-NEXT: lwa 4, 32632(4) +# NoOpt-NEXT: lwa 4, -32744(4) # NoOpt-NEXT: addis 5, 2, 0 -# NoOpt-NEXT: stw 4, 32636(5) +# NoOpt-NEXT: stw 4, -32740(5) # NoOpt-NEXT: blr .global doublewords @@ -149,18 +152,18 @@ doublewords: # Dis-NEXT: addis # Dis-NEXT: addi # Dis-NEXT: nop -# Dis-NEXT: ld 3, 32640(2) +# Dis-NEXT: ld 3, -32736(2) # Dis-NEXT: nop -# Dis-NEXT: std 3, 32648(2) +# Dis-NEXT: std 3, -32728(2) # Dis-NEXT: blr # NoOpt-LABEL: doublewords # NoOpt-NEXT: addis # NoOpt-NEXT: addi # NoOpt-NEXT: addis 3, 2, 0 -# NoOpt-NEXT: ld 3, 32640(3) +# NoOpt-NEXT: ld 3, -32736(3) # NoOpt-NEXT: addis 4, 2, 0 -# NoOpt-NEXT: std 3, 32648(4) +# NoOpt-NEXT: std 3, -32728(4) # NoOpt-NEXT: blr .global vec_dq @@ -182,18 +185,18 @@ vec_dq: # Dis-NEXT: addis # Dis-NEXT: addi # Dis-NEXT: nop -# Dis-NEXT: lxv 3, 32656(2) +# Dis-NEXT: lxv 3, -32720(2) # Dis-NEXT: nop -# Dis-NEXT: stxv 3, 32672(2) +# Dis-NEXT: stxv 3, -32704(2) # Dis-NEXT: blr # NoOpt-LABEL: vec_dq: # NoOpt-NEXT: addis # NoOpt-NEXT: addi # NoOpt-NEXT: addis 3, 2, 0 -# NoOpt-NEXT: lxv 3, 32656(3) +# NoOpt-NEXT: lxv 3, -32720(3) # NoOpt-NEXT: addis 3, 2, 0 -# NoOpt-NEXT: stxv 3, 32672(3) +# NoOpt-NEXT: stxv 3, -32704(3) # NoOpt-NEXT: blr .global vec_ds @@ -218,26 +221,26 @@ vec_ds: # Dis-NEXT: addis # Dis-NEXT: addi # Dis-NEXT: nop -# Dis-NEXT: lxsd 3, 32656(2) +# Dis-NEXT: lxsd 3, -32720(2) # Dis-NEXT: nop -# Dis-NEXT: stxsd 3, 32672(2) +# Dis-NEXT: stxsd 3, -32704(2) # Dis-NEXT: nop -# Dis-NEXT: lxssp 3, 32656(2) +# Dis-NEXT: lxssp 3, -32720(2) # Dis-NEXT: nop -# Dis-NEXT: stxssp 3, 32672(2) +# Dis-NEXT: stxssp 3, -32704(2) # Dis-NEXT: blr # NoOpt-LABEL: vec_ds: # NoOpt-NEXT: addis # NoOpt-NEXT: addi # NoOpt-NEXT: addis 3, 2, 0 -# NoOpt-NEXT: lxsd 3, 32656(3) +# NoOpt-NEXT: lxsd 3, -32720(3) # NoOpt-NEXT: addis 3, 2, 0 -# NoOpt-NEXT: stxsd 3, 32672(3) +# NoOpt-NEXT: stxsd 3, -32704(3) # NoOpt-NEXT: addis 3, 2, 0 -# NoOpt-NEXT: lxssp 3, 32656(3) +# NoOpt-NEXT: lxssp 3, -32720(3) # NoOpt-NEXT: addis 3, 2, 0 -# NoOpt-NEXT: stxssp 3, 32672(3) +# NoOpt-NEXT: stxssp 3, -32704(3) # NoOpt-NEXT: blr diff --git a/test/ELF/ppc64-toc-rel.s b/test/ELF/ppc64-toc-rel.s index 7dccaa970..4fff50c3a 100644 --- a/test/ELF/ppc64-toc-rel.s +++ b/test/ELF/ppc64-toc-rel.s @@ -61,17 +61,16 @@ _start: # The .TOC. symbol represents the TOC base address: .got + 0x8000 = 0x10028000, # which is stored in the first entry of .got -# NM: 0000000010028000 d .TOC. -# NM: 0000000010030000 D global_a +# NM: 00000000100281e8 d .TOC. +# NM: 00000000100301f0 D global_a # HEX-LE: section '.got': -# HEX-LE-NEXT: 0x10020000 00800210 00000000 +# HEX-LE-NEXT: 0x100201e8 e8810210 00000000 # HEX-BE: section '.got': -# HEX-BE-NEXT: 0x10020000 00000000 10028000 +# HEX-BE-NEXT: 0x100201e8 00000000 100281e8 # r2 stores the TOC base address. To access global_a with r3, it # computes the address with TOC plus an offset. -# The offset global_a - .TOC. = 0x10030000 - 0x10028000 = 0x8000 -# gets materialized as (1 << 16) - 32768. +# global_a - .TOC. = 0x100301f0 - 0x100281e8 = (1 << 16) - 32760 # CHECK: _start: -# CHECK: 10010008: addis 3, 2, 1 -# CHECK-NEXT: 1001000c: addi 3, 3, -32768 +# CHECK: 100101d0: addis 3, 2, 1 +# CHECK-NEXT: 100101d4: addi 3, 3, -32760 diff --git a/test/ELF/ppc64-toc-relax-constants.s b/test/ELF/ppc64-toc-relax-constants.s index 05be7fe96..6a0adc259 100644 --- a/test/ELF/ppc64-toc-relax-constants.s +++ b/test/ELF/ppc64-toc-relax-constants.s @@ -1,7 +1,7 @@ # REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unkown-linux %p/Inputs/ppc64-toc-relax-shared.s -o %t.o -# RUN: ld.lld -shared %t.o -o %t.so +# RUN: ld.lld -shared -soname=t.so %t.o -o %t.so # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t1.o # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-toc-relax.s -o %t2.o # RUN: llvm-readobj -r %t1.o | FileCheck --check-prefix=RELOCS %s @@ -23,20 +23,20 @@ # RELOCS-NEXT: 0x14 R_PPC64_TOC16_LO_DS .toc 0x10 # RELOCS-NEXT: } -# SECTIONS: .got PROGBITS 0000000010020090 -# SECTIONS: .toc PROGBITS 0000000010020090 +# SECTIONS: .got PROGBITS 00000000100202f8 +# SECTIONS: .toc PROGBITS 00000000100202f8 -# NM: 0000000010030000 D default +# NM: 0000000010030310 D default # .LCONST1 is .toc[0]. -# .LCONST1 - (.got+0x8000) = 0x10020090 - (0x10020090+0x8000) = -32768 +# .LCONST1 - (.got+0x8000) = 0x10020350 - (0x10020350+0x8000) = -32768 # CHECK: nop # CHECK: lwa 3, -32768(2) addis 3, 2, .LCONST1@toc@ha lwa 3, .LCONST1@toc@l(3) # .LCONST2 is .toc[1] -# .LCONST2 - (.got+0x8000) = 0x10020098 - (0x10020090+0x8000) = -32760 +# .LCONST2 - (.got+0x8000) = 0x10020358 - (0x10020350+0x8000) = -32760 # CHECK: nop # CHECK: ld 4, -32760(2) addis 4, 2, .LCONST2@toc@ha @@ -45,8 +45,8 @@ # .Ldefault is .toc[2]. `default` is not preemptable when producing an executable. # After toc-indirection to toc-relative relaxation, it is loaded using an # offset relative to r2. -# CHECK: nop -# CHECK: addi 5, 2, 32624 +# CHECK: addis 5, 2, 1 +# CHECK: addi 5, 5, -32744 # CHECK: lwa 5, 0(5) addis 5, 2, .Ldefault@toc@ha ld 5, .Ldefault@toc@l(5) diff --git a/test/ELF/ppc64-toc-relax-ifunc.s b/test/ELF/ppc64-toc-relax-ifunc.s new file mode 100644 index 000000000..53a76a74b --- /dev/null +++ b/test/ELF/ppc64-toc-relax-ifunc.s @@ -0,0 +1,34 @@ +# REQUIRES: ppc + +# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o +# RUN: echo '.globl ifunc; .type ifunc, %gnu_indirect_function; ifunc:' | \ +# RUN: llvm-mc -filetype=obj -triple=powerpc64le - -o %t1.o +# RUN: ld.lld %t.o %t1.o -o %t +# RUN: llvm-readelf -S -s %t | FileCheck --check-prefix=SEC %s +# RUN: llvm-readelf -x .toc %t | FileCheck --check-prefix=HEX %s +# RUN: llvm-objdump -d %t | FileCheck --check-prefix=DIS %s + +## ifunc is a non-preemptable STT_GNU_IFUNC. The R_PPC64_ADDR64 in .toc +## creates a canonical PLT for it and changes its type to STT_FUNC. We can thus +## still perform toc-indirect to toc-relative relaxation because the distance +## to the address of the canonical PLT is fixed. + +# SEC: .text PROGBITS 00000000100101e0 +# SEC: .plt NOBITS 0000000010030200 +# SEC: 00000000100101f0 0 FUNC GLOBAL DEFAULT 3 ifunc + +## .toc[0] stores the address of the canonical PLT. +# HEX: section '.toc': +# HEX-NEXT: 0x100201f8 f0010110 00000000 + +# REL: .rela.dyn { +# REL-NEXT: 0x10030200 R_PPC64_IRELATIVE - 0x100101e8 +# REL-NEXT: } + +# DIS: addi 3, 3, + +addis 3, 2, .toc@toc@ha +ld 3, .toc@toc@l(3) + +.section .toc,"aw",@progbits + .quad ifunc diff --git a/test/ELF/ppc64-toc-relax-jumptable.s b/test/ELF/ppc64-toc-relax-jumptable.s index 3c1b33503..f95e6d0d4 100644 --- a/test/ELF/ppc64-toc-relax-jumptable.s +++ b/test/ELF/ppc64-toc-relax-jumptable.s @@ -17,15 +17,15 @@ # SECTIONS: .rodata PROGBITS 00000000100001c8 # HEX-LE: section '.toc': -# HEX-LE-NEXT: 10020008 c8010010 00000000 +# HEX-LE-NEXT: 10020228 c8010010 00000000 # HEX-BE: section '.toc': -# HEX-BE-NEXT: 10020008 00000000 100001c8 +# HEX-BE-NEXT: 10020228 00000000 100001c8 # CHECK-LABEL: _start # CHECK: clrldi 3, 3, 62 -# CHECK-NEXT: addis 4, 2, -2 -# CHECK-NEXT: addi 4, 4, -32312 +# CHECK-NEXT: addis 4, 2, -3 +# CHECK-NEXT: addi 4, 4, 32680 # CHECK-NEXT: sldi 3, 3, 2 .text diff --git a/test/ELF/ppc64-toc-relax.s b/test/ELF/ppc64-toc-relax.s index adda57a27..3f14deb01 100644 --- a/test/ELF/ppc64-toc-relax.s +++ b/test/ELF/ppc64-toc-relax.s @@ -1,21 +1,23 @@ # REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-toc-relax-shared.s -o %t.o -# RUN: ld.lld -shared %t.o -o %t.so +# RUN: ld.lld -shared -soname=t.so %t.o -o %t.so # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t1.o # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-toc-relax.s -o %t2.o # RUN: llvm-readobj -r %t1.o | FileCheck --check-prefixes=RELOCS-LE,RELOCS %s # RUN: ld.lld %t1.o %t2.o %t.so -o %t +# RUN: llvm-nm %t | FileCheck --check-prefix=NM %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefixes=COMMON,EXE %s # RUN: ld.lld -shared %t1.o %t2.o %t.so -o %t2.so # RUN: llvm-objdump -d --no-show-raw-insn %t2.so | FileCheck --check-prefixes=COMMON,SHARED %s # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-toc-relax-shared.s -o %t.o -# RUN: ld.lld -shared %t.o -o %t.so +# RUN: ld.lld -shared -soname=t.so %t.o -o %t.so # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t1.o # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-toc-relax.s -o %t2.o # RUN: llvm-readobj -r %t1.o | FileCheck --check-prefixes=RELOCS-BE,RELOCS %s # RUN: ld.lld %t1.o %t2.o %t.so -o %t +# RUN: llvm-nm %t | FileCheck --check-prefix=NM %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefixes=COMMON,EXE %s # RUN: ld.lld -shared %t1.o %t2.o %t.so -o %t2.so @@ -50,22 +52,22 @@ # RELOCS-NEXT: 0x18 R_PPC64_ADDR64 default 0x0 # RELOCS-NEXT: } -# NM-DAG: 0000000010030000 D default -# NM-DAG: 0000000010030000 d hidden -# NM-DAG: 0000000010040000 d hidden2 +# NM-DAG: 00000000100303a0 D default +# NM-DAG: 00000000100303a0 d hidden +# NM-DAG: 00000000100403a0 d hidden2 # 'hidden' is non-preemptable. It is relaxed. -# address(hidden) - (.got+0x8000) = 0x10030000 - (0x100200c0+0x8000) = 32576 -# COMMON: nop -# COMMON: addi 3, 2, 32576 +# address(hidden) - (.got+0x8000) = 0x100303a0 - (0x10020380+0x8000) = (1<<16) - 32736 +# COMMON: addis 3, 2, 1 +# COMMON: addi 3, 3, -32736 # COMMON: lwa 3, 0(3) addis 3, 2, .Lhidden@toc@ha ld 3, .Lhidden@toc@l(3) lwa 3, 0(3) -# address(hidden2) - (.got+0x8000) = 0x10040000 - (0x100200c0+0x8000) = (1<<16)+32576 -# COMMON: addis 3, 2, 1 -# COMMON: addi 3, 3, 32576 +# address(hidden2) - (.got+0x8000) = 0x100403a0 - (0x10020380+0x8000) = (2<<16) - 32736 +# COMMON: addis 3, 2, 2 +# COMMON: addi 3, 3, -32736 # COMMON: lwa 3, 0(3) addis 3, 2, .Lhidden2@toc@ha ld 3, .Lhidden2@toc@l(3) @@ -82,9 +84,9 @@ lwa 4, 0(4) # 'default' has default visibility. It is non-preemptable when producing an executable. -# address(default) - (.got+0x8000) = 0x10030000 - (0x100200c0+0x8000) = 32576 -# EXE: nop -# EXE: addi 5, 2, 32576 +# address(default) - (.got+0x8000) = 0x100303a0 - (0x10020380+0x8000) = (1<<16) - 32736 +# EXE: addis 5, 2, 1 +# EXE: addi 5, 5, -32736 # EXE: lwa 5, 0(5) # SHARED: nop diff --git a/test/ELF/ppc64-toc-restore-recursive-call.s b/test/ELF/ppc64-toc-restore-recursive-call.s index 756a058cc..d6eb154e1 100644 --- a/test/ELF/ppc64-toc-restore-recursive-call.s +++ b/test/ELF/ppc64-toc-restore-recursive-call.s @@ -14,11 +14,11 @@ # for recursive calls as well as keeps the logic for recursive calls consistent # with non-recursive calls. -# CHECK-LABEL: 0000000000010000 recursive_func: -# CHECK: 10028: bl .+32 +# CHECK-LABEL: 0000000000010290 recursive_func: +# CHECK: 102b8: bl .+32 # CHECK-NEXT: ld 2, 24(1) -# CHECK-LABEL: 0000000000010048 __plt_recursive_func: +# CHECK-LABEL: 00000000000102d8 __plt_recursive_func: .abiversion 2 .section ".text" diff --git a/test/ELF/ppc64-toc-restore.s b/test/ELF/ppc64-toc-restore.s index d65bef847..ddc0d4a01 100644 --- a/test/ELF/ppc64-toc-restore.s +++ b/test/ELF/ppc64-toc-restore.s @@ -3,14 +3,14 @@ // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/shared-ppc64.s -o %t2.o // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-func.s -o %t3.o -// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -shared -soname=t2.so %t2.o -o %t2.so // RUN: ld.lld %t.o %t2.so %t3.o -o %t // RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/shared-ppc64.s -o %t2.o // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-func.s -o %t3.o -// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -shared -soname=t2.so %t2.o -o %t2.so // RUN: ld.lld %t.o %t2.so %t3.o -o %t // RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s @@ -29,9 +29,9 @@ _start: nop bl bar_local // CHECK-LABEL: _start: -// CHECK-NEXT: 10010008: bl .+64 -// CHECK-NEXT: 1001000c: ld 2, 24(1) -// CHECK-NEXT: 10010010: bl .-16 +// CHECK-NEXT: 100102c8: bl .+64 +// CHECK-NEXT: 100102cc: ld 2, 24(1) +// CHECK-NEXT: 100102d0: bl .-16 // CHECK-EMPTY: # Calling a function in another object file which will have same @@ -43,16 +43,16 @@ _diff_object: bl foo_not_shared nop // CHECK-LABEL: _diff_object: -// CHECK-NEXT: 10010014: bl .+28 -// CHECK-NEXT: 10010018: bl .+24 -// CHECK-NEXT: 1001001c: nop +// CHECK-NEXT: 100102d4: bl .+28 +// CHECK-NEXT: 100102d8: bl .+24 +// CHECK-NEXT: 100102dc: nop # Branching to a local function does not need a nop .global noretbranch noretbranch: b bar_local // CHECK-LABEL: noretbranch: -// CHECK: 10010020: b .+67108832 +// CHECK: 100102e0: b .+67108832 // CHECK-EMPTY: // This should come last to check the end-of-buffer condition. @@ -61,5 +61,5 @@ last: bl foo nop // CHECK-LABEL: last: -// CHECK-NEXT: 10010024: bl .+36 -// CHECK-NEXT: 10010028: ld 2, 24(1) +// CHECK-NEXT: 100102e4: bl .+36 +// CHECK-NEXT: 100102e8: ld 2, 24(1) diff --git a/test/ELF/ppc64-weak-undef-call.s b/test/ELF/ppc64-weak-undef-call.s index dea10909a..018bc7e6a 100644 --- a/test/ELF/ppc64-weak-undef-call.s +++ b/test/ELF/ppc64-weak-undef-call.s @@ -24,6 +24,6 @@ _start: # be unreachable. But, we should link successfully. We should not, however, # generate a .plt entry (this would be wasted space). For now, we do nothing # (leaving the zero relative offset present in the input). -# CHECK: 10010000: bl .+0 -# CHECK: 10010004: nop -# CHECK: 10010008: blr +# CHECK: 10010158: bl .+0 +# CHECK: 1001015c: nop +# CHECK: 10010160: blr diff --git a/test/ELF/pr34660.s b/test/ELF/pr34660.s index 5aed06951..5181d3fac 100644 --- a/test/ELF/pr34660.s +++ b/test/ELF/pr34660.s @@ -2,7 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-none %s -o %t.o # RUN: ld.lld --hash-style=sysv -shared %t.o -o %t -# RUN: llvm-objdump %t -d | FileCheck %s --check-prefix=DISASM +# RUN: llvm-objdump %t -d --no-show-raw-insn | FileCheck %s --check-prefix=DISASM # RUN: llvm-readelf %t --symbols | FileCheck %s --check-prefix=SYM # It would be much easier to understand/read this test if llvm-objdump would print @@ -15,10 +15,10 @@ # DISASM: Disassembly of section .text: # DISASM-EMPTY: # DISASM-NEXT: $x.0: -# DISASM-NEXT: 10000: 28 00 10 58 ldr x8, #131076 +# DISASM-NEXT: 1022c: ldr x8, #131176 # SYM: Symbol table '.symtab' -# SYM: 0000000000030004 0 NOTYPE LOCAL DEFAULT 6 patatino +# SYM: 0000000000030294 0 NOTYPE LOCAL DEFAULT 6 patatino ldr x8, patatino .data diff --git a/test/ELF/relocation-b-aarch64.test b/test/ELF/relocation-b-aarch64.test index 15ad4a6c1..b5244db5e 100644 --- a/test/ELF/relocation-b-aarch64.test +++ b/test/ELF/relocation-b-aarch64.test @@ -2,7 +2,7 @@ # RUN: yaml2obj %s -o %t.o # RUN: ld.lld %t.o -o %t.out -# RUN: llvm-objdump -d -triple=aarch64-none-linux %t.out | FileCheck %s +# RUN: llvm-objdump -d --no-show-raw-insn %t.out | FileCheck %s # Check that the R_AARCH64_JUMP26 writes the branch opcode as well as the # immediate. We use this property to overwrite instructions with a branch. @@ -10,9 +10,9 @@ # CHECK: Disassembly of section .text: # CHECK-EMPTY: # CHECK-NEXT: foo: -# CHECK-NEXT: 210000: 01 00 00 14 b #4 +# CHECK-NEXT: 210120: b #4 # CHECK: bar: -# CHECK-NEXT: 210004: ff ff ff 17 b #-4 +# CHECK-NEXT: 210124: b #-4 !ELF FileHeader: diff --git a/test/ELF/relocation-copy-align-common.s b/test/ELF/relocation-copy-align-common.s index 124064c71..748f84546 100644 --- a/test/ELF/relocation-copy-align-common.s +++ b/test/ELF/relocation-copy-align-common.s @@ -15,7 +15,7 @@ # CHECK-NEXT: SHF_WRITE # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x203000 -# CHECK-NEXT: Offset: 0x20B0 +# CHECK-NEXT: Offset: 0x3000 # CHECK-NEXT: Size: 16 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 diff --git a/test/ELF/relocation-copy-i686.s b/test/ELF/relocation-copy-i686.s index e5ec99d16..d8f59bd82 100644 --- a/test/ELF/relocation-copy-i686.s +++ b/test/ELF/relocation-copy-i686.s @@ -1,10 +1,10 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %p/Inputs/relocation-copy.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t.so +// RUN: ld.lld -shared %t2.o -soname=t.so -o %t.so // RUN: ld.lld -e main %t.o %t.so -o %t3 // RUN: llvm-readobj -S -r --expand-relocs %t3 | FileCheck %s -// RUN: llvm-objdump -d %t3 | FileCheck -check-prefix=CODE %s +// RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t3 | FileCheck -check-prefix=CODE %s .text .globl main @@ -21,7 +21,7 @@ movl $9, z // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x403000 +// CHECK-NEXT: Address: 0x403270 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 0 @@ -52,13 +52,13 @@ movl $9, z // CHECK-NEXT: } // CHECK-NEXT: ] -// 4206592 = 0x403000 // 16 is alignment here -// 4206608 = 0x403000 + 16 -// 4206612 = 0x403000 + 16 + 4 // CODE: Disassembly of section .text: // CODE-EMPTY: // CODE-NEXT: main: -// CODE-NEXT: 401000: c7 05 00 30 40 00 05 00 00 00 movl $5, 4206592 -// CODE-NEXT: 40100a: c7 05 10 30 40 00 07 00 00 00 movl $7, 4206608 -// CODE-NEXT: 401014: c7 05 14 30 40 00 09 00 00 00 movl $9, 4206612 +/// .bss + 0 = 0x403270 +// CODE-NEXT: 4011f0: movl $0x5, 0x403270 +/// .bss + 16 = 0x403270 + 16 = 0x403280 +// CODE-NEXT: 4011fa: movl $0x7, 0x403280 +/// .bss + 20 = 0x403270 + 20 = 0x403284 +// CODE-NEXT: 401204: movl $0x9, 0x403284 diff --git a/test/ELF/relocation-i686.s b/test/ELF/relocation-i686.s index 388dd9c71..9a3e1a24d 100644 --- a/test/ELF/relocation-i686.s +++ b/test/ELF/relocation-i686.s @@ -1,10 +1,10 @@ // REQUIRES: x86 -// RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t -// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/Inputs/shared.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so -// RUN: ld.lld --hash-style=sysv %t %t2.so -o %t2 -// RUN: llvm-readobj -S %t2 | FileCheck --check-prefix=ADDR %s -// RUN: llvm-objdump -d %t2 | FileCheck %s +// RUN: llvm-mc -filetype=obj -triple=i686 %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=i686 %p/Inputs/shared.s -o %t2.o +// RUN: ld.lld -shared %t2.o -soname=t2.so -o %t2.so +// RUN: ld.lld --hash-style=sysv %t.o %t2.so -o %t +// RUN: llvm-readobj -S %t | FileCheck --check-prefix=ADDR %s +// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s .global _start _start: @@ -28,15 +28,15 @@ R_386_PC32_2: // CHECK: Disassembly of section .R_386_32: // CHECK-EMPTY: // CHECK-NEXT: R_386_32: -// CHECK-NEXT: 401000: {{.*}} movl $4198401, %edx +// CHECK-NEXT: movl $4198829, %edx // CHECK: Disassembly of section .R_386_PC32: // CHECK-EMPTY: // CHECK-NEXT: R_386_PC32: -// CHECK-NEXT: 401005: e8 04 00 00 00 calll 4 +// CHECK-NEXT: calll 4 // CHECK: R_386_PC32_2: -// CHECK-NEXT: 40100e: 90 nop +// CHECK-NEXT: nop // Create a .got movl bar@GOT, %eax @@ -47,8 +47,8 @@ movl bar@GOT, %eax // ADDR-NEXT: SHF_ALLOC // ADDR-NEXT: SHF_EXECINSTR // ADDR-NEXT: ] -// ADDR-NEXT: Address: 0x401040 -// ADDR-NEXT: Offset: 0x1040 +// ADDR-NEXT: Address: 0x4011E0 +// ADDR-NEXT: Offset: 0x1E0 // ADDR-NEXT: Size: 32 // ADDR: Name: .got.plt ( @@ -57,7 +57,7 @@ movl bar@GOT, %eax // ADDR-NEXT: SHF_ALLOC // ADDR-NEXT: SHF_WRITE // ADDR-NEXT: ] -// ADDR-NEXT: Address: 0x403000 +// ADDR-NEXT: Address: 0x403280 // ADDR-NEXT: Offset: // ADDR-NEXT: Size: @@ -65,20 +65,19 @@ movl bar@GOT, %eax R_386_GOTPC: movl $_GLOBAL_OFFSET_TABLE_, %eax -// 0x403000 (.got.plt) - 0x401014 = 8300 - +// .got.plt - 0x4011c0 = 0x403280 - 0x4011c0 = 8384 // CHECK: Disassembly of section .R_386_GOTPC: // CHECK-EMPTY: // CHECK-NEXT: R_386_GOTPC: -// CHECK-NEXT: 401014: {{.*}} movl $8172, %eax +// CHECK-NEXT: 4011c0: movl $8384, %eax .section .dynamic_reloc, "ax",@progbits call bar -// addr(.plt) + 16 - (0x401019 + 5) = 50 +// .plt + 16 - (0x4011c5 + 5) = 0x4011e0 + 16 - 0x4011ca = 38 // CHECK: Disassembly of section .dynamic_reloc: // CHECK-EMPTY: // CHECK-NEXT: .dynamic_reloc: -// CHECK-NEXT: 401019: e8 32 00 00 00 calll 50 +// CHECK-NEXT: 4011c5: calll 38 .section .R_386_GOT32,"ax",@progbits .global R_386_GOT32 @@ -88,12 +87,13 @@ R_386_GOT32: movl bar+8@GOT, %eax movl zed+4@GOT, %eax -// 4294963320 = 0xfffff078 = got[0](0x402078) - .got.plt(0x403000) -// 4294963324 = 0xfffff07c = got[1](0x40207c) - .got(0x403000) +// &.got[0] - .got.plt = 0x402278 - 0x403280 = 4294963192 +// &.got[1] - .got.plt = 0x402278 + 4 - 0x403280 = 4294963196 +// &.got[2] - .got.plt = 0x402278 + 8 - 0x403280 = 4294963200 // CHECK: Disassembly of section .R_386_GOT32: // CHECK-EMPTY: // CHECK-NEXT: R_386_GOT32: -// CHECK-NEXT: 40101e: a1 78 f0 ff ff movl 4294963320, %eax -// CHECK-NEXT: 401023: a1 7c f0 ff ff movl 4294963324, %eax -// CHECK-NEXT: 401028: a1 80 f0 ff ff movl 4294963328, %eax -// CHECK-NEXT: 40102d: a1 80 f0 ff ff movl 4294963328, %eax +// CHECK-NEXT: 4011ca: movl 4294963192, %eax +// CHECK-NEXT: movl 4294963196, %eax +// CHECK-NEXT: movl 4294963200, %eax +// CHECK-NEXT: movl 4294963200, %eax diff --git a/test/ELF/relro-copyrel-bss-script.s b/test/ELF/relro-copyrel-bss-script.s index 5f3b981ca..9a947d898 100644 --- a/test/ELF/relro-copyrel-bss-script.s +++ b/test/ELF/relro-copyrel-bss-script.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t.o // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/copy-in-shared.s -o %t2.o -// RUN: ld.lld -shared %t.o %t2.o -o %t.so +// RUN: ld.lld -shared -soname=t.so %t.o %t2.o -z separate-code -o %t.so // A linker script that will map .bss.rel.ro into .bss. // RUN: echo "SECTIONS { \ @@ -9,8 +9,8 @@ // RUN: } " > %t.script // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t3.o -// RUN: ld.lld %t3.o %t.so -z relro -o %t --script=%t.script 2>&1 -// RUN: llvm-readobj --program-headers %t | FileCheck %s +// RUN: ld.lld %t3.o %t.so -z relro -z separate-code -o %t --script=%t.script 2>&1 +// RUN: llvm-readelf -l %t | FileCheck %s .section .text, "ax", @progbits .global bar .global foo @@ -27,14 +27,5 @@ _start: // as relro. .space 0x2000 -// CHECK: Type: PT_GNU_RELRO (0x6474E552) -// CHECK-NEXT: Offset: -// CHECK-NEXT: VirtualAddress: -// CHECK-NEXT: PhysicalAddress: -// CHECK-NEXT: FileSize: -// CHECK-NEXT: MemSize: 4096 -// CHECK-NEXT: Flags [ (0x4) -// CHECK-NEXT: PF_R (0x4) -// CHECK-NEXT: ] -// CHECK-NEXT: Alignment: 1 -// CHECK-NEXT: } +// CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +// CHECK: GNU_RELRO 0x002150 0x0000000000000150 0x0000000000000150 0x000100 0x000eb0 R 0x1 diff --git a/test/ELF/reproduce.s b/test/ELF/reproduce.s index bfab2e87e..463d604e9 100644 --- a/test/ELF/reproduce.s +++ b/test/ELF/reproduce.s @@ -13,7 +13,7 @@ # RUN: FileCheck %s --check-prefix=RSP < repro/response.txt # RSP: {{^}}--hash-style gnu{{$}} -# RSP-NOT: repro{{[/\\]}} +# RSP-NOT: {{^}}repro{{[/\\]}} # RSP-NEXT: {{[/\\]}}foo.o # RSP-NEXT: -o bar # RSP-NEXT: -shared diff --git a/test/ELF/riscv-gp-dummy-sdata.s b/test/ELF/riscv-gp-dummy-sdata.s deleted file mode 100644 index e04b170d5..000000000 --- a/test/ELF/riscv-gp-dummy-sdata.s +++ /dev/null @@ -1,25 +0,0 @@ -# REQUIRES: riscv -# RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.32.o -# RUN: ld.lld -pie %t.32.o -o %t.32 -# RUN: llvm-readelf -S %t.32 | FileCheck --check-prefix=SEC %s -# RUN: llvm-readelf -s %t.32 | FileCheck --check-prefix=SYM %s - -# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.64.o -# RUN: ld.lld -pie %t.64.o -o %t.64 -# RUN: llvm-readelf -S %t.64 | FileCheck --check-prefix=SEC %s -# RUN: llvm-readelf -s %t.64 | FileCheck --check-prefix=SYM %s - -## If there is an undefined reference to __global_pointer$ but .sdata doesn't -## exist, create a dummy one. - -## __global_pointer$ = .sdata+0x800 -# SEC: [ 7] .sdata PROGBITS {{0*}}00003000 -# SYM: {{0*}}00003800 0 NOTYPE GLOBAL DEFAULT 7 __global_pointer$ - -## If __global_pointer$ is not used, don't create .sdata . - -# RUN: llvm-mc -filetype=obj -triple=riscv32 /dev/null -o %t.32.o -# RUN: ld.lld -pie %t.32.o -o %t.32 -# RUN: llvm-readelf -S %t.32 | FileCheck --implicit-check-not=.sdata /dev/null - -lla gp, __global_pointer$ diff --git a/test/ELF/riscv-gp-no-sdata.s b/test/ELF/riscv-gp-no-sdata.s new file mode 100644 index 000000000..ee86438ec --- /dev/null +++ b/test/ELF/riscv-gp-no-sdata.s @@ -0,0 +1,15 @@ +# REQUIRES: riscv +# RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.32.o +# RUN: ld.lld -pie %t.32.o -o %t.32 +# RUN: llvm-readelf -s %t.32 | FileCheck --check-prefix=SYM %s + +# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.64.o +# RUN: ld.lld -pie %t.64.o -o %t.64 +# RUN: llvm-readelf -s %t.64 | FileCheck --check-prefix=SYM %s + +## If there is an undefined reference to __global_pointer$ but .sdata doesn't +## exist, define __global_pointer$ and set its st_shndx arbitrarily to 1. + +# SYM: {{0*}}00000800 0 NOTYPE GLOBAL DEFAULT 1 __global_pointer$ + +lla gp, __global_pointer$ diff --git a/test/ELF/riscv-gp.s b/test/ELF/riscv-gp.s index 83b5f0dd7..5f0819fcc 100644 --- a/test/ELF/riscv-gp.s +++ b/test/ELF/riscv-gp.s @@ -1,19 +1,22 @@ # REQUIRES: riscv # RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.32.o # RUN: ld.lld -pie %t.32.o -o %t.32 -# RUN: llvm-readelf -s %t.32 | FileCheck --check-prefix=SYM %s -# RUN: llvm-readelf -S %t.32 | FileCheck --check-prefix=SEC %s +# RUN: llvm-readelf -s %t.32 | FileCheck --check-prefix=SYM32 %s +# RUN: llvm-readelf -S %t.32 | FileCheck --check-prefix=SEC32 %s # RUN: not ld.lld -shared %t.32.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s # RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.64.o # RUN: ld.lld -pie %t.64.o -o %t.64 -# RUN: llvm-readelf -s %t.64 | FileCheck --check-prefix=SYM %s -# RUN: llvm-readelf -S %t.64 | FileCheck --check-prefix=SEC %s +# RUN: llvm-readelf -s %t.64 | FileCheck --check-prefix=SYM64 %s +# RUN: llvm-readelf -S %t.64 | FileCheck --check-prefix=SEC64 %s # RUN: not ld.lld -shared %t.64.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s -## __global_pointer$ = .sdata+0x800 = 0x3800 -# SEC: [ 7] .sdata PROGBITS {{0*}}00003000 -# SYM: {{0*}}00003800 0 NOTYPE GLOBAL DEFAULT 7 __global_pointer$ +## __global_pointer$ = .sdata+0x800 = 0x39b8 +# SEC32: [ 7] .sdata PROGBITS {{0*}}000031b8 +# SYM32: {{0*}}000039b8 0 NOTYPE GLOBAL DEFAULT 7 __global_pointer$ + +# SEC64: [ 7] .sdata PROGBITS {{0*}}000032d0 +# SYM64: {{0*}}00003ad0 0 NOTYPE GLOBAL DEFAULT 7 __global_pointer$ ## __global_pointer$ - 0x1000 = 4096*3-2048 # DIS: 1000: auipc gp, 3 diff --git a/test/ELF/riscv-plt.s b/test/ELF/riscv-plt.s index 0afd5b005..0f0567692 100644 --- a/test/ELF/riscv-plt.s +++ b/test/ELF/riscv-plt.s @@ -2,18 +2,18 @@ # RUN: echo '.globl bar, weak; .type bar,@function; .type weak,@function; bar: weak:' > %t1.s # RUN: llvm-mc -filetype=obj -triple=riscv32 %t1.s -o %t1.32.o -# RUN: ld.lld -shared %t1.32.o -o %t1.32.so +# RUN: ld.lld -shared %t1.32.o -soname=t1.32.so -o %t1.32.so # RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.32.o -# RUN: ld.lld %t.32.o %t1.32.so -o %t.32 +# RUN: ld.lld %t.32.o %t1.32.so -z separate-code -o %t.32 # RUN: llvm-readelf -S -s %t.32 | FileCheck --check-prefixes=SEC,NM %s # RUN: llvm-readobj -r %t.32 | FileCheck --check-prefix=RELOC32 %s # RUN: llvm-readelf -x .got.plt %t.32 | FileCheck --check-prefix=GOTPLT32 %s # RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefixes=DIS,DIS32 %s # RUN: llvm-mc -filetype=obj -triple=riscv64 %t1.s -o %t1.64.o -# RUN: ld.lld -shared %t1.64.o -o %t1.64.so +# RUN: ld.lld -shared %t1.64.o -soname=t1.64.so -o %t1.64.so # RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.64.o -# RUN: ld.lld %t.64.o %t1.64.so -o %t.64 +# RUN: ld.lld %t.64.o %t1.64.so -z separate-code -o %t.64 # RUN: llvm-readelf -S -s %t.64 | FileCheck --check-prefixes=SEC,NM %s # RUN: llvm-readobj -r %t.64 | FileCheck --check-prefix=RELOC64 %s # RUN: llvm-readelf -x .got.plt %t.64 | FileCheck --check-prefix=GOTPLT64 %s @@ -29,34 +29,34 @@ ## The .got.plt slots relocated by .rela.plt point to .plt ## This is required by glibc. # RELOC32: .rela.plt { -# RELOC32-NEXT: 0x13008 R_RISCV_JUMP_SLOT bar 0x0 -# RELOC32-NEXT: 0x1300C R_RISCV_JUMP_SLOT weak 0x0 +# RELOC32-NEXT: 0x13070 R_RISCV_JUMP_SLOT bar 0x0 +# RELOC32-NEXT: 0x13074 R_RISCV_JUMP_SLOT weak 0x0 # RELOC32-NEXT: } # GOTPLT32: section '.got.plt' -# GOTPLT32-NEXT: 0x00013000 00000000 00000000 30100100 30100100 +# GOTPLT32-NEXT: 0x00013068 00000000 00000000 30100100 30100100 # RELOC64: .rela.plt { -# RELOC64-NEXT: 0x13010 R_RISCV_JUMP_SLOT bar 0x0 -# RELOC64-NEXT: 0x13018 R_RISCV_JUMP_SLOT weak 0x0 +# RELOC64-NEXT: 0x130E0 R_RISCV_JUMP_SLOT bar 0x0 +# RELOC64-NEXT: 0x130E8 R_RISCV_JUMP_SLOT weak 0x0 # RELOC64-NEXT: } # GOTPLT64: section '.got.plt' -# GOTPLT64-NEXT: 0x00013000 00000000 00000000 00000000 00000000 -# GOTPLT64-NEXT: 0x00013010 30100100 00000000 30100100 00000000 +# GOTPLT64-NEXT: 0x000130d0 00000000 00000000 00000000 00000000 +# GOTPLT64-NEXT: 0x000130e0 30100100 00000000 30100100 00000000 # DIS: _start: ## Direct call ## foo - . = 0x11020-0x11000 = 32 -# DIS-NEXT: auipc ra, 0 -# DIS-NEXT: 11004: jalr 32(ra) -## bar@plt - . = 0x11050-0x1100c = 72 -# DIS-NEXT: auipc ra, 0 -# DIS-NEXT: 1100c: jalr 72(ra) -## bar@plt - . = 0x11050-0x11014 = 64 -# DIS-NEXT: auipc ra, 0 -# DIS-NEXT: 11014: jalr 64(ra) -## weak@plt - . = 0x11060-0x1101c = 72 -# DIS-NEXT: auipc ra, 0 -# DIS-NEXT: 1101c: jalr 72(ra) +# DIS-NEXT: 11000: auipc ra, 0 +# DIS-NEXT: jalr 32(ra) +## bar@plt - . = 0x11050-0x11008 = 72 +# DIS-NEXT: 11008: auipc ra, 0 +# DIS-NEXT: jalr 72(ra) +## bar@plt - . = 0x11050-0x11010 = 64 +# DIS-NEXT: 11010: auipc ra, 0 +# DIS-NEXT: jalr 64(ra) +## weak@plt - . = 0x11060-0x11018 = 72 +# DIS-NEXT: 11018: auipc ra, 0 +# DIS-NEXT: jalr 72(ra) # DIS: foo: # DIS-NEXT: 11020: @@ -64,28 +64,29 @@ # DIS: .plt: # DIS-NEXT: auipc t2, 2 # DIS-NEXT: sub t1, t1, t3 -## .got.plt - .plt = 0x13000 - 0x11030 = 4096*2-48 -# DIS32-NEXT: lw t3, -48(t2) -# DIS64-NEXT: ld t3, -48(t2) +## .got.plt - .plt = 0x13068 - 0x11030 = 4096*2+56 +# DIS32-NEXT: lw t3, 56(t2) +# DIS64-NEXT: ld t3, 160(t2) # DIS-NEXT: addi t1, t1, -44 -# DIS-NEXT: addi t0, t2, -48 +# DIS32-NEXT: addi t0, t2, 56 +# DIS64-NEXT: addi t0, t2, 160 # DIS32-NEXT: srli t1, t1, 2 # DIS64-NEXT: srli t1, t1, 1 # DIS32-NEXT: lw t0, 4(t0) # DIS64-NEXT: ld t0, 8(t0) # DIS-NEXT: jr t3 -## 32-bit: &.got.plt[bar]-. = 0x13008-0x11050 = 4096*2-72 +## 32-bit: &.got.plt[bar]-. = 0x13070-0x11050 = 4096*2+32 # DIS: 11050: auipc t3, 2 -# DIS32-NEXT: lw t3, -72(t3) -# DIS64-NEXT: ld t3, -64(t3) +# DIS32-NEXT: lw t3, 32(t3) +# DIS64-NEXT: ld t3, 144(t3) # DIS-NEXT: jalr t1, t3 # DIS-NEXT: nop -## 32-bit: &.got.plt[weak]-. = 0x1300c-0x11060 = 4096*2-84 +## 32-bit: &.got.plt[weak]-. = 0x13074-0x11060 = 4096*2+20 # DIS: 11060: auipc t3, 2 -# DIS32-NEXT: lw t3, -84(t3) -# DIS64-NEXT: ld t3, -72(t3) +# DIS32-NEXT: lw t3, 20(t3) +# DIS64-NEXT: ld t3, 136(t3) # DIS-NEXT: jalr t1, t3 # DIS-NEXT: nop diff --git a/test/ELF/riscv-reloc-copy.s b/test/ELF/riscv-reloc-copy.s index 94d839d41..17a5902cc 100644 --- a/test/ELF/riscv-reloc-copy.s +++ b/test/ELF/riscv-reloc-copy.s @@ -1,23 +1,24 @@ # REQUIRES: riscv # RUN: llvm-mc -filetype=obj -triple=riscv32 %p/Inputs/relocation-copy.s -o %t1.o -# RUN: ld.lld -shared %t1.o -o %t1.so +# RUN: ld.lld -shared %t1.o -soname=t1.so -o %t1.so # RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.o # RUN: ld.lld %t.o %t1.so -o %t -# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s +# RUN: llvm-readobj -r %t | FileCheck --check-prefixes=REL,REL32 %s # RUN: llvm-nm -S %t | FileCheck --check-prefix=NM32 %s # RUN: llvm-mc -filetype=obj -triple=riscv64 %p/Inputs/relocation-copy.s -o %t1.o -# RUN: ld.lld -shared %t1.o -o %t1.so +# RUN: ld.lld -shared %t1.o -soname=t1.so -o %t1.so # RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.o # RUN: ld.lld %t.o %t1.so -o %t -# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s +# RUN: llvm-readobj -r %t | FileCheck --check-prefixes=REL,REL64 %s # RUN: llvm-nm -S %t | FileCheck --check-prefix=NM64 %s -# RELOC: .rela.dyn { -# RELOC-NEXT: 0x13000 R_RISCV_COPY x 0x0 -# RELOC-NEXT: } +# REL: .rela.dyn { +# REL32-NEXT: 0x13210 R_RISCV_COPY x 0x0 +# REL64-NEXT: 0x13360 R_RISCV_COPY x 0x0 +# REL-NEXT: } -# NM32: 00013000 00000004 B x -# NM64: 0000000000013000 0000000000000004 B x +# NM32: 00013210 00000004 B x +# NM64: 0000000000013360 0000000000000004 B x la a0, x diff --git a/test/ELF/riscv-reloc-got.s b/test/ELF/riscv-reloc-got.s index 1adccd9d0..ce4d648d4 100644 --- a/test/ELF/riscv-reloc-got.s +++ b/test/ELF/riscv-reloc-got.s @@ -1,59 +1,63 @@ # REQUIRES: riscv # RUN: echo '.globl b; b:' | llvm-mc -filetype=obj -triple=riscv32 - -o %t1.o -# RUN: ld.lld -shared %t1.o -o %t1.so +# RUN: ld.lld -shared %t1.o -soname=t1.so -o %t1.so # RUN: llvm-mc -filetype=obj -triple=riscv32 -position-independent %s -o %t.o # RUN: ld.lld %t.o %t1.so -o %t +# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC32 %s # RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC32 %s -# RUN: llvm-nm %t | FileCheck --check-prefix=NM %s +# RUN: llvm-nm %t | FileCheck --check-prefix=NM32 %s # RUN: llvm-readobj -x .got %t | FileCheck --check-prefix=HEX32 %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DIS32 %s # RUN: echo '.globl b; b:' | llvm-mc -filetype=obj -triple=riscv64 - -o %t1.o -# RUN: ld.lld -shared %t1.o -o %t1.so +# RUN: ld.lld -shared %t1.o -soname=t1.so -o %t1.so # RUN: llvm-mc -filetype=obj -triple=riscv64 -position-independent %s -o %t.o # RUN: ld.lld %t.o %t1.so -o %t +# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC64 %s # RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC64 %s -# RUN: llvm-nm %t | FileCheck --check-prefix=NM %s +# RUN: llvm-nm %t | FileCheck --check-prefix=NM64 %s # RUN: llvm-readobj -x .got %t | FileCheck --check-prefix=HEX64 %s # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DIS64 %s -# SEC: .got PROGBITS 00012060 020060 00000c +# SEC32: .got PROGBITS 0001220c 00020c 00000c +# SEC64: .got PROGBITS 0000000000012358 000358 000018 # RELOC32: .rela.dyn { -# RELOC32-NEXT: 0x12068 R_RISCV_32 b 0x0 +# RELOC32-NEXT: 0x12214 R_RISCV_32 b 0x0 # RELOC32-NEXT: } # RELOC64: .rela.dyn { -# RELOC64-NEXT: 0x120D0 R_RISCV_64 b 0x0 +# RELOC64-NEXT: 0x12368 R_RISCV_64 b 0x0 # RELOC64-NEXT: } -# NM: 00013000 d a +# NM32: 00013218 d a +# NM64: 0000000000013370 d a ## .got[0] = _DYNAMIC ## .got[1] = a (filled at link time) ## .got[2] = 0 (relocated by R_RISCV_64 at runtime) # HEX32: section '.got': -# HEX32: 0x00012060 00200100 00300100 00000000 +# HEX32: 0x0001220c ac210100 18320100 00000000 # HEX64: section '.got': -# HEX64: 0x000120c0 00200100 00000000 00300100 00000000 -# HEX64: 0x000120d0 00000000 00000000 +# HEX64: 0x00012358 98220100 00000000 70330100 00000000 +# HEX64: 0x00012368 00000000 00000000 -## &.got[1]-. = 0x12060-0x11000 = 4096*1+100 -# DIS32: 11000: auipc a0, 1 -# DIS32-NEXT: lw a0, 100(a0) -## &.got[2]-. = 0x12064-0x11008 = 4096*1+96 -# DIS32: 11008: auipc a0, 1 -# DIS32-NEXT: lw a0, 96(a0) +## &.got[1]-. = 0x12210-0x1119c = 4096*1+116 +# DIS32: 1119c: auipc a0, 1 +# DIS32-NEXT: lw a0, 116(a0) +## &.got[2]-. = 0x12214-0x111a4 = 4096*1+112 +# DIS32: 111a4: auipc a0, 1 +# DIS32-NEXT: lw a0, 112(a0) -## &.got[1]-. = 0x120c8-0x11000 = 4096*1+100 -# DIS64: 11000: auipc a0, 1 -# DIS64-NEXT: ld a0, 200(a0) -## &.got[2]-. = 0x120d0-0x11008 = 4096*1+200 -# DIS64: 11008: auipc a0, 1 -# DIS64-NEXT: ld a0, 200(a0) +## &.got[1]-. = 0x12360-0x11288 = 4096*1+216 +# DIS64: 11288: auipc a0, 1 +# DIS64-NEXT: ld a0, 216(a0) +## &.got[2]-. = 0x12368-0x11290 = 4096*1+216 +# DIS64: 11290: auipc a0, 1 +# DIS64-NEXT: ld a0, 216(a0) la a0,a la a0,b diff --git a/test/ELF/riscv-tls-gd.s b/test/ELF/riscv-tls-gd.s index 3f5735aab..078199438 100644 --- a/test/ELF/riscv-tls-gd.s +++ b/test/ELF/riscv-tls-gd.s @@ -46,42 +46,42 @@ # RUN: llvm-readelf -x .got %t.64 | FileCheck --check-prefix=IE64-GOT %s # GD32-REL: .rela.dyn { -# GD32-REL-NEXT: 0x2070 R_RISCV_TLS_DTPMOD32 a 0x0 -# GD32-REL-NEXT: 0x2074 R_RISCV_TLS_DTPREL32 a 0x0 -# GD32-REL-NEXT: 0x2078 R_RISCV_TLS_DTPMOD32 b 0x0 -# GD32-REL-NEXT: 0x207C R_RISCV_TLS_DTPREL32 b 0x0 +# GD32-REL-NEXT: 0x2310 R_RISCV_TLS_DTPMOD32 a 0x0 +# GD32-REL-NEXT: 0x2314 R_RISCV_TLS_DTPREL32 a 0x0 +# GD32-REL-NEXT: 0x2318 R_RISCV_TLS_DTPMOD32 b 0x0 +# GD32-REL-NEXT: 0x231C R_RISCV_TLS_DTPREL32 b 0x0 # GD32-REL-NEXT: } -## &DTPMOD(a) - . = 0x2070 - 0x1000 = 4096*1+112 -# GD32: 1000: auipc a0, 1 -# GD32-NEXT: addi a0, a0, 112 +## &DTPMOD(a) - . = 0x2310 - 0x1250 = 4096*1+192 +# GD32: 1250: auipc a0, 1 +# GD32-NEXT: addi a0, a0, 192 # GD32-NEXT: auipc ra, 0 # GD32-NEXT: jalr 56(ra) -## &DTPMOD(b) - . = 0x2078 - 0x1010 = 4096*1+104 -# GD32: 1010: auipc a0, 1 -# GD32-NEXT: addi a0, a0, 104 +## &DTPMOD(b) - . = 0x2318 - 0x1260 = 4096*1+184 +# GD32: 1260: auipc a0, 1 +# GD32-NEXT: addi a0, a0, 184 # GD32-NEXT: auipc ra, 0 # GD32-NEXT: jalr 40(ra) # GD64-REL: .rela.dyn { -# GD64-REL-NEXT: 0x20E0 R_RISCV_TLS_DTPMOD64 a 0x0 -# GD64-REL-NEXT: 0x20E8 R_RISCV_TLS_DTPREL64 a 0x0 -# GD64-REL-NEXT: 0x20F0 R_RISCV_TLS_DTPMOD64 b 0x0 -# GD64-REL-NEXT: 0x20F8 R_RISCV_TLS_DTPREL64 b 0x0 +# GD64-REL-NEXT: 0x24D0 R_RISCV_TLS_DTPMOD64 a 0x0 +# GD64-REL-NEXT: 0x24D8 R_RISCV_TLS_DTPREL64 a 0x0 +# GD64-REL-NEXT: 0x24E0 R_RISCV_TLS_DTPMOD64 b 0x0 +# GD64-REL-NEXT: 0x24E8 R_RISCV_TLS_DTPREL64 b 0x0 # GD64-REL-NEXT: } -## &DTPMOD(a) - . = 0x20e0 - 0x1000 = 4096*1+224 -# GD64: 1000: auipc a0, 1 -# GD64-NEXT: addi a0, a0, 224 +## &DTPMOD(a) - . = 0x24d0 - 0x1398 = 4096*1+312 +# GD64: 1398: auipc a0, 1 +# GD64-NEXT: addi a0, a0, 312 # GD64-NEXT: auipc ra, 0 -# GD64-NEXT: jalr 56(ra) +# GD64-NEXT: jalr 64(ra) -## &DTPMOD(b) - . = 0x20f0 - 0x1010 = 4096*1+224 -# GD64: 1010: auipc a0, 1 -# GD64-NEXT: addi a0, a0, 224 +## &DTPMOD(b) - . = 0x24e0 - 0x13a8 = 4096*1+312 +# GD64: 13a8: auipc a0, 1 +# GD64-NEXT: addi a0, a0, 312 # GD64-NEXT: auipc ra, 0 -# GD64-NEXT: jalr 40(ra) +# GD64-NEXT: jalr 48(ra) # NOREL: no relocations @@ -97,19 +97,19 @@ ## a is local - relaxed to LE - its DTPMOD/DTPREL slots are link-time constants. ## b is external - DTPMOD/DTPREL dynamic relocations are required. # IE32-REL: .rela.dyn { -# IE32-REL-NEXT: 0x12068 R_RISCV_TLS_DTPMOD32 b 0x0 -# IE32-REL-NEXT: 0x1206C R_RISCV_TLS_DTPREL32 b 0x0 +# IE32-REL-NEXT: 0x12230 R_RISCV_TLS_DTPMOD32 b 0x0 +# IE32-REL-NEXT: 0x12234 R_RISCV_TLS_DTPREL32 b 0x0 # IE32-REL-NEXT: } # IE32-GOT: section '.got': -# IE32-GOT-NEXT: 0x00012060 01000000 08f8ffff 00000000 00000000 +# IE32-GOT-NEXT: 0x00012228 01000000 08f8ffff 00000000 00000000 # IE64-REL: .rela.dyn { -# IE64-REL-NEXT: 0x120D0 R_RISCV_TLS_DTPMOD64 b 0x0 -# IE64-REL-NEXT: 0x120D8 R_RISCV_TLS_DTPREL64 b 0x0 +# IE64-REL-NEXT: 0x12390 R_RISCV_TLS_DTPMOD64 b 0x0 +# IE64-REL-NEXT: 0x12398 R_RISCV_TLS_DTPREL64 b 0x0 # IE64-REL-NEXT: } # IE64-GOT: section '.got': -# IE64-GOT-NEXT: 0x000120c0 01000000 00000000 08f8ffff ffffffff -# IE64-GOT-NEXT: 0x000120d0 00000000 00000000 00000000 00000000 +# IE64-GOT-NEXT: 0x00012380 01000000 00000000 08f8ffff ffffffff +# IE64-GOT-NEXT: 0x00012390 00000000 00000000 00000000 00000000 la.tls.gd a0,a call __tls_get_addr@plt diff --git a/test/ELF/riscv-tls-ie.s b/test/ELF/riscv-tls-ie.s index b7497c309..f88c3ed28 100644 --- a/test/ELF/riscv-tls-ie.s +++ b/test/ELF/riscv-tls-ie.s @@ -23,28 +23,28 @@ # RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefixes=LE,LE64 %s # IE32-REL: .rela.dyn { -# IE32-REL-NEXT: 0x205C R_RISCV_TLS_TPREL32 - 0xC -# IE32-REL-NEXT: 0x2058 R_RISCV_TLS_TPREL32 a 0x0 +# IE32-REL-NEXT: 0x2218 R_RISCV_TLS_TPREL32 - 0xC +# IE32-REL-NEXT: 0x2214 R_RISCV_TLS_TPREL32 a 0x0 # IE32-REL-NEXT: } # IE32-REL: FLAGS STATIC_TLS # IE64-REL: .rela.dyn { -# IE64-REL-NEXT: 0x20B8 R_RISCV_TLS_TPREL64 - 0xC -# IE64-REL-NEXT: 0x20B0 R_RISCV_TLS_TPREL64 a 0x0 +# IE64-REL-NEXT: 0x2370 R_RISCV_TLS_TPREL64 - 0xC +# IE64-REL-NEXT: 0x2368 R_RISCV_TLS_TPREL64 a 0x0 # IE64-REL-NEXT: } # IE64-REL: FLAGS STATIC_TLS -## rv32: &.got[1] - . = 0x2058 - . = 4096*1+88 -## rv64: &.got[1] - . = 0x20B0 - . = 4096*1+176 -# IE: 1000: auipc a4, 1 -# IE32-NEXT: lw a4, 88(a4) -# IE64-NEXT: ld a4, 176(a4) +## rv32: &.got[0] - . = 0x2214 - . = 4096*1+112 +## rv64: &.got[0] - . = 0x2368 - . = 4096*1+200 +# IE: auipc a4, 1 +# IE32-NEXT: lw a4, 112(a4) +# IE64-NEXT: ld a4, 200(a4) # IE-NEXT: add a4, a4, tp -## rv32: &.got[0] - . = 0x205C - . = 4096*1+80 -## rv64: &.got[0] - . = 0x20B8 - . = 4096*1+172 -# IE: 100c: auipc a5, 1 -# IE32-NEXT: lw a5, 80(a5) -# IE64-NEXT: ld a5, 172(a5) +## rv32: &.got[1] - . = 0x2218 - . = 4096*1+104 +## rv64: &.got[1] - . = 0x2370 - . = 4096*1+196 +# IE: auipc a5, 1 +# IE32-NEXT: lw a5, 104(a5) +# IE64-NEXT: ld a5, 196(a5) # IE-NEXT: add a5, a5, tp # NOREL: no relocations @@ -52,21 +52,23 @@ # a@tprel = st_value(a) = 0x8 # b@tprel = st_value(a) = 0xc # LE32-GOT: section '.got': -# LE32-GOT-NEXT: 0x00012000 08000000 0c000000 +# LE32-GOT-NEXT: 0x0001212c 08000000 0c000000 # LE64-GOT: section '.got': -# LE64-GOT-NEXT: 0x00012000 08000000 00000000 0c000000 00000000 +# LE64-GOT-NEXT: 0x000121e0 08000000 00000000 0c000000 00000000 -## rv32: &.got[0] - . = 0x12000 - 0x11000 = 4096*1+0 -## rv64: &.got[0] - . = 0x12000 - 0x11000 = 4096*1+0 -# LE: 11000: auipc a4, 1 -# LE32-NEXT: lw a4, 0(a4) -# LE64-NEXT: ld a4, 0(a4) +## rv32: &.got[0] - . = 0x1212c - 0x11114 = 4096*1+24 +## rv64: &.got[0] - . = 0x121e0 - 0x111c8 = 4096*1+24 +# LE32: 11114: auipc a4, 1 +# LE32-NEXT: lw a4, 24(a4) +# LE64: 111c8: auipc a4, 1 +# LE64-NEXT: ld a4, 24(a4) # LE-NEXT: add a4, a4, tp -## rv32: &.got[1] - . = 0x12004 - 0x1100c = 4096*1-8 -## rv64: &.got[1] - . = 0x12008 - 0x1100c = 4096*1-4 -# LE: 1100c: auipc a5, 1 -# LE32-NEXT: lw a5, -8(a5) -# LE64-NEXT: ld a5, -4(a5) +## rv32: &.got[1] - . = 0x12130 - 0x11120 = 4096*1+16 +## rv64: &.got[1] - . = 0x121e8 - 0x111d4 = 4096*1+20 +# LE32: 11120: auipc a5, 1 +# LE32-NEXT: lw a5, 16(a5) +# LE64: 111d4: auipc a5, 1 +# LE64-NEXT: ld a5, 20(a5) # LE-NEXT: add a5, a5, tp la.tls.ie a4,a diff --git a/test/ELF/riscv-tls-ld.s b/test/ELF/riscv-tls-ld.s index 6563cf874..f47964ef3 100644 --- a/test/ELF/riscv-tls-ld.s +++ b/test/ELF/riscv-tls-ld.s @@ -35,44 +35,46 @@ ## a@dtprel = st_value(a)-0x800 = 0xfffff808 is a link-time constant. # LD32-REL: .rela.dyn { -# LD32-REL-NEXT: 0x2084 -# LD32-REL-NEXT: 0x207C R_RISCV_TLS_DTPMOD32 - 0x0 +# LD32-REL-NEXT: 0x22B4 +# LD32-REL-NEXT: 0x22AC R_RISCV_TLS_DTPMOD32 - 0x0 # LD32-REL-NEXT: } # LD32-GOT: section '.got': -# LD32-GOT-NEXT: 0x00002078 00200000 00000000 00f8ffff 00000000 +# LD32-GOT-NEXT: 0x000022a8 30220000 00000000 00f8ffff 00000000 # LD64-REL: .rela.dyn { -# LD64-REL-NEXT: 0x2108 -# LD64-REL-NEXT: 0x20F8 R_RISCV_TLS_DTPMOD64 - 0x0 +# LD64-REL-NEXT: 0x2458 +# LD64-REL-NEXT: 0x2448 R_RISCV_TLS_DTPMOD64 - 0x0 # LD64-REL-NEXT: } # LD64-GOT: section '.got': -# LD64-GOT-NEXT: 0x000020f0 00200000 00000000 00000000 00000000 -# LD64-GOT-NEXT: 0x00002100 00f8ffff ffffffff 00000000 00000000 +# LD64-GOT-NEXT: 0x00002440 50230000 00000000 00000000 00000000 +# LD64-GOT-NEXT: 0x00002450 00f8ffff ffffffff 00000000 00000000 -## rv32: &DTPMOD(a) - . = 0x207c - 0x1000 = 4096*1+124 -## rv64: &DTPMOD(a) - . = 0x20e0 - 0x1000 = 4096*1+248 -# LD: 1000: auipc a0, 1 -# LD32-NEXT: addi a0, a0, 124 -# LD64-NEXT: addi a0, a0, 248 +## rv32: &DTPMOD(a) - . = 0x22ac - 0x11d8 = 4096*1+212 +## rv64: &DTPMOD(a) - . = 0x2448 - 0x12f8 = 4096*1+336 +# LD32: 11d8: auipc a0, 1 +# LD32-NEXT: addi a0, a0, 212 +# LD64: 12f8: auipc a0, 1 +# LD64-NEXT: addi a0, a0, 336 # LD-NEXT: auipc ra, 0 -# LD-NEXT: jalr 56(ra) +# LD-NEXT: jalr 64(ra) # NOREL: no relocations ## a is local - its DTPMOD/DTPREL slots are link-time constants. ## a@dtpmod = 1 (main module) # LE32-GOT: section '.got': -# LE32-GOT-NEXT: 0x00012000 00000000 01000000 00f8ffff 00200100 +# LE32-GOT-NEXT: 0x00012134 00000000 01000000 00f8ffff 34210100 # LE64-GOT: section '.got': -# LE64-GOT-NEXT: 0x00012000 00000000 00000000 01000000 00000000 -# LE64-GOT-NEXT: 0x00012010 00f8ffff ffffffff 00200100 00000000 +# LE64-GOT-NEXT: 0x000121e8 00000000 00000000 01000000 00000000 +# LE64-GOT-NEXT: 0x000121f8 00f8ffff ffffffff e8210100 00000000 -## rv32: DTPMOD(.LANCHOR0) - . = 0x12004 - 0x11000 = 4096*1+4 -## rv64: DTPMOD(.LANCHOR0) - . = 0x12008 - 0x11000 = 4096*1+8 -# LE: 11000: auipc a0, 1 -# LE32-NEXT: addi a0, a0, 4 -# LE64-NEXT: addi a0, a0, 8 +## rv32: DTPMOD(.LANCHOR0) - . = 0x12138 - 0x11114 = 4096*1+36 +## rv64: DTPMOD(.LANCHOR0) - . = 0x121f0 - 0x111c8 = 4096*1+40 +# LE32: 11114: auipc a0, 1 +# LE32-NEXT: addi a0, a0, 36 +# LE64: 111c8: auipc a0, 1 +# LE64-NEXT: addi a0, a0, 40 # LE-NEXT: auipc ra, 0 # LE-NEXT: jalr 24(ra) diff --git a/test/ELF/riscv32-reloc-32-pic.s b/test/ELF/riscv32-reloc-32-pic.s index 7583c1e93..72bb16f12 100644 --- a/test/ELF/riscv32-reloc-32-pic.s +++ b/test/ELF/riscv32-reloc-32-pic.s @@ -7,11 +7,11 @@ ## R_RISCV_32 is an absolute relocation type. ## In PIC mode, it creates a relative relocation if the symbol is non-preemptable. -# NM: 00002004 d b +# NM: 000031fc d b # RELOC: .rela.dyn { -# RELOC-NEXT: 0x2004 R_RISCV_RELATIVE - 0x2004 -# RELOC-NEXT: 0x2000 R_RISCV_32 a 0 +# RELOC-NEXT: 0x31FC R_RISCV_RELATIVE - 0x31FC +# RELOC-NEXT: 0x31F8 R_RISCV_32 a 0 # RELOC-NEXT: } .globl a, b diff --git a/test/ELF/riscv64-reloc-64-pic.s b/test/ELF/riscv64-reloc-64-pic.s index 5bf504c5b..793d17f05 100644 --- a/test/ELF/riscv64-reloc-64-pic.s +++ b/test/ELF/riscv64-reloc-64-pic.s @@ -7,11 +7,11 @@ ## R_RISCV_64 is an absolute relocation type. ## In PIC mode, it creates a relative relocation if the symbol is non-preemptable. -# NM: 0000000000002008 d b +# NM: 0000000000003350 d b # RELOC: .rela.dyn { -# RELOC-NEXT: 0x2008 R_RISCV_RELATIVE - 0x2008 -# RELOC-NEXT: 0x2000 R_RISCV_64 a 0 +# RELOC-NEXT: 0x3350 R_RISCV_RELATIVE - 0x3350 +# RELOC-NEXT: 0x3348 R_RISCV_64 a 0 # RELOC-NEXT: } .globl a, b diff --git a/test/ELF/shared.s b/test/ELF/shared.s index 592c5e3c1..583ed9212 100644 --- a/test/ELF/shared.s +++ b/test/ELF/shared.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/Inputs/shared.s -o %t2.o -// RUN: ld.lld --hash-style=sysv -shared %t2.o -o %t2.so +// RUN: ld.lld --hash-style=sysv -shared %t2.o -soname=t2.so -o %t2.so // RUN: llvm-readobj -S %t2.so | FileCheck --check-prefix=SO %s // RUN: ld.lld --hash-style=sysv -dynamic-linker /lib64/ld-linux-x86-64.so.2 -rpath foo -rpath bar --export-dynamic %t.o %t2.so -o %t // RUN: llvm-readobj --program-headers --dynamic-table --symbols -S --dyn-syms --section-data --hash-table %t | FileCheck %s @@ -14,7 +14,7 @@ // SO-NEXT: Flags [ // SO-NEXT: ] // SO-NEXT: Address: -// SO-NEXT: Offset: 0x1038 +// SO-NEXT: Offset: 0x1D0 // SO-NEXT: Size: // SO-NEXT: Link: // SO-NEXT: Info: @@ -141,7 +141,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _DYNAMIC -// CHECK-NEXT: Value: 0x402000 +// CHECK-NEXT: Value: 0x402210 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -152,7 +152,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x401000 +// CHECK-NEXT: Value: 0x401208 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None @@ -191,7 +191,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x401000 +// CHECK-NEXT: Value: 0x401208 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Non diff --git a/test/ELF/silent-ignore.test b/test/ELF/silent-ignore.test index 91bf89846..3371ed6a2 100644 --- a/test/ELF/silent-ignore.test +++ b/test/ELF/silent-ignore.test @@ -1,15 +1,16 @@ RUN: ld.lld --version \ -RUN: -allow-shlib-undefined \ +RUN: -detect-odr-violations \ RUN: -g \ +RUN: -long-plt \ RUN: -no-add-needed \ -RUN: -no-allow-shlib-undefined \ RUN: -no-copy-dt-needed-entries \ RUN: -no-ctors-in-init-array \ RUN: -no-keep-memory \ +RUN: -no-mmap-output-file \ RUN: -no-pipeline-knowledge \ -RUN: -no-warn-common \ RUN: -no-warn-mismatch \ RUN: -p \ +RUN: -rpath-link . \ RUN: -secure-plt \ RUN: -sort-common \ RUN: -stats \ @@ -18,5 +19,6 @@ RUN: -warn-once \ RUN: -warn-shared-textrel \ RUN: -EB \ RUN: -EL \ +RUN: -G 0 \ RUN: -Qy RUN: not ld.lld --version --not-an-ignored-argument diff --git a/test/ELF/static-with-export-dynamic.s b/test/ELF/static-with-export-dynamic.s index c2d2f12ed..b0349b85e 100644 --- a/test/ELF/static-with-export-dynamic.s +++ b/test/ELF/static-with-export-dynamic.s @@ -18,7 +18,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x401000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None diff --git a/test/ELF/strip-all.s b/test/ELF/strip-all.s index f322119b0..7e05ba816 100644 --- a/test/ELF/strip-all.s +++ b/test/ELF/strip-all.s @@ -21,6 +21,9 @@ #RUN: ld.lld %t.o -s -o %t1 #RUN: llvm-objdump -section-headers %t1 | FileCheck %s -check-prefix AFTER +# RUN: not ld.lld %t.o --strip-all --emit-relocs -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s +# ERR: error: --strip-all and --emit-relocs may not be used together + # exits with return code 42 on linux .globl _start _start: diff --git a/test/ELF/tls-dynamic-i686.s b/test/ELF/tls-dynamic-i686.s deleted file mode 100644 index ed36f530c..000000000 --- a/test/ELF/tls-dynamic-i686.s +++ /dev/null @@ -1,100 +0,0 @@ -// REQUIRES: x86 -// RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t -// RUN: ld.lld --hash-style=sysv -shared -z norelro %t -o %tout -// RUN: llvm-readobj --sections -r %tout | FileCheck %s -// RUN: llvm-objdump -d %tout | FileCheck %s --check-prefix=DIS - -.type tls0,@object -.section .tbss,"awT",@nobits -.globl tls0 -.align 4 -tls0: - .long 0 - .size tls0, 4 - -.type tls1,@object -.globl tls1 -.align 4 -tls1: - .long 0 - .size tls1, 4 - -.type tls2,@object -.globl tls2 -.hidden tls2 -.align 4 -tls2: - .long 0 - .size tls2, 8 - -.section .text -.globl _start -_start: -leal tls0@tlsgd(,%ebx,1),%eax -call __tls_get_addr@plt - -leal tls1@tlsgd(,%ebx,1),%eax -call __tls_get_addr@plt - -leal tls2@tlsldm(%ebx),%eax -call __tls_get_addr@plt -leal tls2@dtpoff(%eax),%edx - -leal tls2@tlsldm(%ebx),%eax -call __tls_get_addr@plt -leal tls2@dtpoff+4(%eax),%edx - -movl %gs:0,%eax -addl tls0@gotntpoff(%ebx),%eax - -movl %gs:0,%eax -addl tls1@gotntpoff(%ebx),%eax - -// CHECK: Name: .got ( -// CHECK-NEXT: Type: SHT_PROGBITS -// CHECK-NEXT: Flags [ -// CHECK-NEXT: SHF_ALLOC -// CHECK-NEXT: SHF_WRITE -// CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x2070 -// CHECK-NEXT: Offset: 0x2070 -// CHECK-NEXT: Size: 32 -// CHECK-NEXT: Link: 0 -// CHECK-NEXT: Info: 0 -// CHECK-NEXT: AddressAlignment: 4 -// CHECK-NEXT: EntrySize: 0 - -// CHECK: Relocations [ -// CHECK: Section ({{.+}}) .rel.dyn { -// CHECK-NEXT: 0x2080 R_386_TLS_DTPMOD32 - 0x0 -// CHECK-NEXT: 0x2070 R_386_TLS_DTPMOD32 tls0 0x0 -// CHECK-NEXT: 0x2074 R_386_TLS_DTPOFF32 tls0 0x0 -// CHECK-NEXT: 0x2088 R_386_TLS_TPOFF tls0 0x0 -// CHECK-NEXT: 0x2078 R_386_TLS_DTPMOD32 tls1 0x0 -// CHECK-NEXT: 0x207C R_386_TLS_DTPOFF32 tls1 0x0 -// CHECK-NEXT: 0x208C R_386_TLS_TPOFF tls1 0x0 -// CHECK-NEXT: } - -// DIS: Disassembly of section .text: -// DIS-EMPTY: -// DIS-NEXT: _start: -// General dynamic model: -// -32 and -24 are first and second GOT entries offsets. -// Each one is a pair of records. -// DIS-NEXT: 1000: {{.*}} leal -32(,%ebx), %eax -// DIS-NEXT: 1007: {{.*}} calll 100 -// DIS-NEXT: 100c: {{.*}} leal -24(,%ebx), %eax -// DIS-NEXT: 1013: {{.*}} calll 88 -// Local dynamic model: -// -16 is a local module tls index offset. -// DIS-NEXT: 1018: {{.*}} leal -16(%ebx), %eax -// DIS-NEXT: 101e: {{.*}} calll 77 -// DIS-NEXT: 1023: {{.*}} leal 8(%eax), %edx -// DIS-NEXT: 1029: {{.*}} leal -16(%ebx), %eax -// DIS-NEXT: 102f: {{.*}} calll 60 -// DIS-NEXT: 1034: {{.*}} leal 12(%eax), %edx -// Initial exec model: -// DIS-NEXT: 103a: {{.*}} movl %gs:0, %eax -// DIS-NEXT: 1040: {{.*}} addl -8(%ebx), %eax -// DIS-NEXT: 1046: {{.*}} movl %gs:0, %eax -// DIS-NEXT: 104c: {{.*}} addl -4(%ebx), %eax diff --git a/test/ELF/tls-i686.s b/test/ELF/tls-i686.s deleted file mode 100644 index 6ff1aa694..000000000 --- a/test/ELF/tls-i686.s +++ /dev/null @@ -1,71 +0,0 @@ -// REQUIRES: x86 -// RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t -// RUN: ld.lld %t -o %tout -// RUN: ld.lld --hash-style=sysv %t -shared -o %tsharedout -// RUN: llvm-objdump -d %tout | FileCheck %s --check-prefix=DIS -// RUN: llvm-readobj -r %tout | FileCheck %s --check-prefix=RELOC -// RUN: llvm-objdump -d %tsharedout | FileCheck %s --check-prefix=DISSHARED -// RUN: llvm-readobj -r %tsharedout | FileCheck %s --check-prefix=RELOCSHARED - -.section ".tdata", "awT", @progbits -.globl var -.globl var1 -var: -.long 0 -var1: -.long 1 - -.section test, "awx" -.global _start -_start: - movl $var@tpoff, %edx - movl %gs:0, %ecx - subl %edx, %eax - movl $var1@tpoff, %edx - movl %gs:0, %ecx - subl %edx, %eax - - movl %gs:0, %ecx - leal var@ntpoff(%ecx), %eax - movl %gs:0, %ecx - leal var1@ntpoff+123(%ecx), %eax - -// DIS: Disassembly of section test: -// DIS-EMPTY: -// DIS-NEXT: _start: -// DIS-NEXT: 401000: ba 08 00 00 00 movl $8, %edx -// DIS-NEXT: 401005: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DIS-NEXT: 40100c: 29 d0 subl %edx, %eax -// DIS-NEXT: 40100e: ba 04 00 00 00 movl $4, %edx -// DIS-NEXT: 401013: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DIS-NEXT: 40101a: 29 d0 subl %edx, %eax -// DIS-NEXT: 40101c: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DIS-NEXT: 401023: 8d 81 f8 ff ff ff leal -8(%ecx), %eax -// DIS-NEXT: 401029: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DIS-NEXT: 401030: 8d 81 77 00 00 00 leal 119(%ecx), %eax - -// RELOC: Relocations [ -// RELOC-NEXT: ] - -// DISSHARED: Disassembly of section test: -// DISSHARED-EMPTY: -// DISSHARED-NEXT: _start: -// DISSHARED-NEXT: 1000: ba 00 00 00 00 movl $0, %edx -// DISSHARED-NEXT: 1005: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DISSHARED-NEXT: 100c: 29 d0 subl %edx, %eax -// DISSHARED-NEXT: 100e: ba 00 00 00 00 movl $0, %edx -// DISSHARED-NEXT: 1013: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DISSHARED-NEXT: 101a: 29 d0 subl %edx, %eax -// DISSHARED-NEXT: 101c: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DISSHARED-NEXT: 1023: 8d 81 00 00 00 00 leal (%ecx), %eax -// DISSHARED-NEXT: 1029: 65 8b 0d 00 00 00 00 movl %gs:0, %ecx -// DISSHARED-NEXT: 1030: 8d 81 7b 00 00 00 leal 123(%ecx), %eax - -// RELOCSHARED: Relocations [ -// RELOCSHARED-NEXT: Section (4) .rel.dyn { -// RELOCSHARED-NEXT: 0x1001 R_386_TLS_TPOFF32 var 0x0 -// RELOCSHARED-NEXT: 0x1025 R_386_TLS_TPOFF var 0x0 -// RELOCSHARED-NEXT: 0x100F R_386_TLS_TPOFF32 var1 0x0 -// RELOCSHARED-NEXT: 0x1032 R_386_TLS_TPOFF var1 0x0 -// RELOCSHARED-NEXT: } -// RELOCSHARED-NEXT: ] diff --git a/test/ELF/tls-initial-exec-local.s b/test/ELF/tls-initial-exec-local.s deleted file mode 100644 index c7dacd554..000000000 --- a/test/ELF/tls-initial-exec-local.s +++ /dev/null @@ -1,37 +0,0 @@ -// REQUIRES: x86 -// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: ld.lld --hash-style=sysv -shared %t.o -o %t -// RUN: llvm-readobj -r -S %t | FileCheck %s -// RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s - -// CHECK: Name: .got -// CHECK-NEXT: Type: SHT_PROGBITS -// CHECK-NEXT: Flags [ -// CHECK-NEXT: SHF_ALLOC (0x2) -// CHECK-NEXT: SHF_WRITE (0x1) -// CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x20A0 - -// CHECK: Relocations [ -// CHECK-NEXT: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x20A0 R_X86_64_TPOFF64 - 0x0 -// CHECK-NEXT: 0x20A8 R_X86_64_TPOFF64 - 0x4 -// CHECK-NEXT: } -// CHECK-NEXT: ] - -// 0x1007 + 4249 = 0x20A0 -// 0x100e + 4250 = 0x20A8 -// DISASM: Disassembly of section .text: -// DISASM-EMPTY: -// DISASM-NEXT: .text: -// DISASM-NEXT: 1000: {{.*}} addq 4249(%rip), %rax -// DISASM-NEXT: 1007: {{.*}} addq 4250(%rip), %rax - - addq foo@GOTTPOFF(%rip), %rax - addq bar@GOTTPOFF(%rip), %rax - - .section .tbss,"awT",@nobits -foo: - .long 0 -bar: - .long 0 diff --git a/test/ELF/tls-opt-gdiele-i686.s b/test/ELF/tls-opt-gdiele-i686.s deleted file mode 100644 index c9df1d089..000000000 --- a/test/ELF/tls-opt-gdiele-i686.s +++ /dev/null @@ -1,61 +0,0 @@ -// REQUIRES: x86 -// RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %p/Inputs/tls-opt-gdiele-i686.s -o %tso.o -// RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o -// RUN: ld.lld -shared %tso.o -o %tso -// RUN: ld.lld --hash-style=sysv %t.o %tso -o %tout -// RUN: llvm-readobj -r %tout | FileCheck --check-prefix=NORELOC %s -// RUN: llvm-objdump -d %tout | FileCheck --check-prefix=DISASM %s - -// NORELOC: Relocations [ -// NORELOC-NEXT: Section ({{.*}}) .rel.dyn { -// NORELOC-NEXT: 0x402058 R_386_TLS_TPOFF tlsshared0 0x0 -// NORELOC-NEXT: 0x40205C R_386_TLS_TPOFF tlsshared1 0x0 -// NORELOC-NEXT: } -// NORELOC-NEXT: ] - -// DISASM: Disassembly of section .text: -// DISASM-EMPTY: -// DISASM-NEXT: _start: -// DISASM-NEXT: 401000: 65 a1 00 00 00 00 movl %gs:0, %eax -// DISASM-NEXT: 401006: 03 83 58 f0 ff ff addl -4008(%ebx), %eax -// DISASM-NEXT: 40100c: 65 a1 00 00 00 00 movl %gs:0, %eax -// DISASM-NEXT: 401012: 03 83 5c f0 ff ff addl -4004(%ebx), %eax -// DISASM-NEXT: 401018: 65 a1 00 00 00 00 movl %gs:0, %eax -// DISASM-NEXT: 40101e: 81 e8 08 00 00 00 subl $8, %eax -// DISASM-NEXT: 401024: 65 a1 00 00 00 00 movl %gs:0, %eax -// DISASM-NEXT: 40102a: 81 e8 04 00 00 00 subl $4, %eax - -.type tlsexe1,@object -.section .tbss,"awT",@nobits -.globl tlsexe1 -.align 4 -tlsexe1: - .long 0 - .size tlsexe1, 4 - -.type tlsexe2,@object -.section .tbss,"awT",@nobits -.globl tlsexe2 -.align 4 -tlsexe2: - .long 0 - .size tlsexe2, 4 - -.section .text -.globl ___tls_get_addr -.type ___tls_get_addr,@function -___tls_get_addr: - -.section .text -.globl _start -_start: -//GD->IE -leal tlsshared0@tlsgd(,%ebx,1),%eax -call ___tls_get_addr@plt -leal tlsshared1@tlsgd(,%ebx,1),%eax -call ___tls_get_addr@plt -//GD->LE -leal tlsexe1@tlsgd(,%ebx,1),%eax -call ___tls_get_addr@plt -leal tlsexe2@tlsgd(,%ebx,1),%eax -call ___tls_get_addr@plt diff --git a/test/ELF/tls-opt-no-plt.s b/test/ELF/tls-opt-no-plt.s deleted file mode 100644 index 9f4365249..000000000 --- a/test/ELF/tls-opt-no-plt.s +++ /dev/null @@ -1,35 +0,0 @@ -// REQUIRES: x86 -// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/tls-opt-gdie.s -o %t2.o -// RUN: ld.lld %t2.o -o %t2.so -shared -// RUN: ld.lld %t.o %t2.so -o %t.exe -// RUN: llvm-readobj -S %t.exe | FileCheck %s - -// CHECK-NOT: .plt - - .global _start -_start: - data16 - leaq foo@TLSGD(%rip), %rdi - data16 - data16 - rex64 - callq __tls_get_addr@PLT - - leaq bar@TLSLD(%rip), %rdi - callq __tls_get_addr@PLT - leaq bar@DTPOFF(%rax), %rax - - .type bar,@object - .section .tdata,"awT",@progbits - .align 8 -bar: - .long 42 - - - .type foo,@object - .section .tdata,"awT",@progbits - .globl foo - .align 8 -foo: - .long 42 diff --git a/test/ELF/tls-static.s b/test/ELF/tls-static.s deleted file mode 100644 index 61d504b2e..000000000 --- a/test/ELF/tls-static.s +++ /dev/null @@ -1,21 +0,0 @@ -// REQUIRES: x86 -// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/shared.s -o %tso -// RUN: ld.lld -static %t -o %tout -// RUN: ld.lld %t -o %tout -// RUN: ld.lld -shared %tso -o %tshared - -.global _start -_start: - data16 - leaq foobar@TLSGD(%rip), %rdi - data16 - data16 - rex64 - callq __tls_get_addr@PLT - - -.section .tdata,"awT",@progbits -.global foobar -foobar: - .long 42 diff --git a/test/ELF/undef-with-plt-addr-i686.s b/test/ELF/undef-with-plt-addr-i686.s index d750cbfb8..2d828dec7 100644 --- a/test/ELF/undef-with-plt-addr-i686.s +++ b/test/ELF/undef-with-plt-addr-i686.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/Inputs/undef-with-plt-addr.s -o %t2.o -// RUN: ld.lld %t2.o -o %t2.so -shared +// RUN: ld.lld %t2.o -o %t2.so -shared -soname=t2.so // RUN: ld.lld %t.o %t2.so -o %t3 // RUN: llvm-readobj --symbols -S %t3 | FileCheck %s @@ -17,7 +17,7 @@ mov $set_data, %eax // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_EXECINSTR // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x401010 +// CHECK-NEXT: Address: 0x4011B0 // CHECK: Name: set_data -// CHECK-NEXT: Value: 0x401020 +// CHECK-NEXT: Value: 0x4011C0 diff --git a/test/ELF/version-script-anonymous-local.s b/test/ELF/version-script-anonymous-local.s deleted file mode 100644 index 9fe30cd7f..000000000 --- a/test/ELF/version-script-anonymous-local.s +++ /dev/null @@ -1,61 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o - -# RUN: echo "{ global: foo; local: bar; };" > %t.script -# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so -# RUN: llvm-readobj --dyn-syms --symbols %t.so | FileCheck %s - -# CHECK: Symbols [ -# CHECK: Name: bar -# CHECK-NEXT: Value: -# CHECK-NEXT: Size: -# CHECK-NEXT: Binding: Local - -# CHECK: Name: foo -# CHECK-NEXT: Value: -# CHECK-NEXT: Size: -# CHECK-NEXT: Binding: Global - -# CHECK: Name: zed -# CHECK-NEXT: Value: -# CHECK-NEXT: Size: -# CHECK-NEXT: Binding: Global - - -# CHECK: DynamicSymbols [ -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: -# CHECK-NEXT: Value: -# CHECK-NEXT: Size: -# CHECK-NEXT: Binding: -# CHECK-NEXT: Type: -# CHECK-NEXT: Other: -# CHECK-NEXT: Section: -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: foo -# CHECK-NEXT: Value: -# CHECK-NEXT: Size: -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: -# CHECK-NEXT: Other: -# CHECK-NEXT: Section: -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: zed -# CHECK-NEXT: Value: -# CHECK-NEXT: Size: -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: -# CHECK-NEXT: Other: -# CHECK-NEXT: Section: -# CHECK-NEXT: } -# CHECK-NEXT: ] - - -.global foo -foo: -.global bar -bar: -.global zed -zed: diff --git a/test/ELF/version-script-missing.s b/test/ELF/version-script-missing.s deleted file mode 100644 index a82a37e41..000000000 --- a/test/ELF/version-script-missing.s +++ /dev/null @@ -1,7 +0,0 @@ -# REQUIRES: x86 - -# We used to crash if a symbol in a version script was not in the symbol table. - -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "{ foobar; };" > %t.script -# RUN: ld.lld --version-script %t.script -shared %t.o -o /dev/null diff --git a/test/ELF/version-script-no-warn.s b/test/ELF/version-script-no-warn.s deleted file mode 100644 index d99b87bf9..000000000 --- a/test/ELF/version-script-no-warn.s +++ /dev/null @@ -1,12 +0,0 @@ -# REQUIRES: x86 - -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %t2.o -# RUN: ld.lld -shared %t2.o -soname shared -o %t2.so - -# RUN: echo "foo { global: bar; local: *; };" > %t.script -# RUN: ld.lld --fatal-warnings --shared --version-script %t.script %t.o %t2.so -o /dev/null - -.global bar -bar: - nop diff --git a/test/ELF/version-script-no-warn2.s b/test/ELF/version-script-no-warn2.s deleted file mode 100644 index 795fbb0b4..000000000 --- a/test/ELF/version-script-no-warn2.s +++ /dev/null @@ -1,9 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/version-script-no-warn2.s -o %t1.o -# RUN: ld.lld %t1.o -o %t1.so -shared -# RUN: echo "{ global: foo; local: *; };" > %t.script -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t2.o -# RUN: ld.lld -shared --version-script %t.script %t2.o %t1.so -o /dev/null --fatal-warnings - -.global foo -foo: diff --git a/test/ELF/version-script-noundef.s b/test/ELF/version-script-noundef.s index 0eae1fcdb..0c48622fd 100644 --- a/test/ELF/version-script-noundef.s +++ b/test/ELF/version-script-noundef.s @@ -2,7 +2,7 @@ # RUN: echo "VERSION_1.0 { global: bar; };" > %t.script # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: ld.lld --version-script %t.script -shared %t.o -o /dev/null --fatal-warnings # RUN: ld.lld --version-script %t.script -shared --undefined-version %t.o -o %t.so # RUN: not ld.lld --version-script %t.script -shared --no-undefined-version \ # RUN: %t.o -o %t.so 2>&1 | FileCheck -check-prefix=ERR1 %s diff --git a/test/ELF/version-script-reassign-glob.s b/test/ELF/version-script-reassign-glob.s new file mode 100644 index 000000000..e25cdacae --- /dev/null +++ b/test/ELF/version-script-reassign-glob.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o + +# RUN: echo 'foo { foo*; }; bar { *; };' > %t.ver +# RUN: ld.lld --version-script %t.ver %t.o -shared -o %t.so --fatal-warnings +# RUN: llvm-readelf --dyn-syms %t.so | FileCheck --check-prefix=FOO %s + +# RUN: echo 'foo { foo*; }; bar { f*; };' > %t.ver +# RUN: ld.lld --version-script %t.ver %t.o -shared -o %t.so --fatal-warnings +# RUN: llvm-readelf --dyn-syms %t.so | FileCheck --check-prefix=BAR %s + +## If both a non-* glob and a * match, non-* wins. +## This is GNU linkers' behavior. We don't feel strongly this should be supported. +# FOO: GLOBAL DEFAULT 7 foo@@foo + +# BAR: GLOBAL DEFAULT 7 foo@@bar + +.globl foo +foo: diff --git a/test/ELF/version-script-reassign.s b/test/ELF/version-script-reassign.s index 62b32cba8..2ed5b15fa 100644 --- a/test/ELF/version-script-reassign.s +++ b/test/ELF/version-script-reassign.s @@ -1,18 +1,22 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o +# RUN: echo '{ global: foo; };' > %tg.ver # RUN: echo '{ local: foo; };' > %tl.ver -# RUN: echo '{ global: foo; local: *; };' > %tg.ver +# RUN: echo '{ global: foo; local: *; };' > %tgl.ver # RUN: echo 'V1 { global: foo; };' > %t1.ver # RUN: echo 'V2 { global: foo; };' > %t2.ver # RUN: echo 'V2 { global: notexist; local: f*; };' > %t2w.ver -## Note, ld.bfd errors on the two cases. +## Note, ld.bfd errors on these cases. # RUN: ld.lld -shared %t.o --version-script %tl.ver --version-script %t1.ver \ # RUN: -o %t.so 2>&1 | FileCheck --check-prefix=LOCAL %s # RUN: llvm-readelf --dyn-syms %t.so | FileCheck --check-prefix=LOCAL-SYM %s # RUN: ld.lld -shared %t.o --version-script %tg.ver --version-script %t1.ver \ # RUN: -o %t.so 2>&1 | FileCheck --check-prefix=GLOBAL %s # RUN: llvm-readelf --dyn-syms %t.so | FileCheck --check-prefix=GLOBAL-SYM %s +# RUN: ld.lld -shared %t.o --version-script %tgl.ver --version-script %t1.ver \ +# RUN: -o %t.so 2>&1 | FileCheck --check-prefix=GLOBAL %s +# RUN: llvm-readelf --dyn-syms %t.so | FileCheck --check-prefix=GLOBAL-SYM %s ## Note, ld.bfd silently accepts this case. # RUN: ld.lld -shared %t.o --version-script %t1.ver --version-script %t2.ver \ diff --git a/test/ELF/version-script.s b/test/ELF/version-script.s index 8bbd769d3..b74a8d612 100644 --- a/test/ELF/version-script.s +++ b/test/ELF/version-script.s @@ -5,7 +5,7 @@ # RUN: echo "{ global: foo1; foo3; local: *; };" > %t.script # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: ld.lld --version-script %t.script -shared %t.o %t2.so -o %t.so +# RUN: ld.lld --version-script %t.script -shared %t.o %t2.so -o %t.so --fatal-warnings # RUN: llvm-readobj --dyn-syms %t.so | FileCheck --check-prefix=DSO %s # RUN: echo "# comment" > %t3.script @@ -17,7 +17,7 @@ ## Also check that both "global:" and "global :" forms are accepted # RUN: echo "VERSION_1.0 { global : foo1; local : *; };" > %t4.script # RUN: echo "VERSION_2.0 { global: foo3; local: *; };" >> %t4.script -# RUN: ld.lld --version-script %t4.script -shared %t.o %t2.so -o %t4.so +# RUN: ld.lld --version-script %t4.script -shared %t.o %t2.so -o %t4.so --fatal-warnings # RUN: llvm-readobj --dyn-syms %t4.so | FileCheck --check-prefix=VERDSO %s # RUN: echo "VERSION_1.0 { global: foo1; local: *; };" > %t5.script diff --git a/test/ELF/vs-diagnostics-duplicate-split.s b/test/ELF/vs-diagnostics-duplicate-split.s new file mode 100644 index 000000000..b3b4eae1c --- /dev/null +++ b/test/ELF/vs-diagnostics-duplicate-split.s @@ -0,0 +1,39 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o +// RUN: not ld.lld --vs-diagnostics --shared %t.o %t.o -o /dev/null 2>&1 | FileCheck %s + +// CHECK: /tmp{{/|\\}}duplicate.s(15): error: duplicate symbol: foo +// CHECK-NEXT: >>> defined at duplicate.s:15 (/tmp{{/|\\}}duplicate.s:15) +// CHECK-NEXT: >>>{{.*}}.o:(.text+0x{{.+}}) +// CHECK: /tmp{{/|\\}}duplicate.s(15): error: duplicate symbol: foo +// CHECK-NEXT: >>> defined at duplicate.s:15 (/tmp{{/|\\}}duplicate.s:15) +// CHECK-NEXT: >>>{{.*}}.o:(.text+0x{{.+}}) + +.file 1 "/tmp" "duplicate.s" + +.global foo +.text +.loc 1 15 +foo: + nop + +.section .debug_abbrev,"",@progbits + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 0 # DW_CHILDREN_no + .byte 16 # DW_AT_stmt_list + .byte 23 # DW_FORM_sec_offset + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) + +.section .debug_info,"",@progbits + .long .Lend0 - .Lbegin0 # Length of Unit +.Lbegin0: + .short 4 # DWARF version number + .long .debug_abbrev # Offset Into Abbrev. Section + .byte 8 # Address Size (in bytes) + .byte 1 # Abbrev [1] 0xb:0x1f DW_TAG_compile_unit + .long .debug_line # DW_AT_stmt_list +.Lend0: + .section .debug_line,"",@progbits diff --git a/test/ELF/vs-diagnostics-duplicate.s b/test/ELF/vs-diagnostics-duplicate.s index efd0cbe5f..11425df9d 100644 --- a/test/ELF/vs-diagnostics-duplicate.s +++ b/test/ELF/vs-diagnostics-duplicate.s @@ -8,8 +8,9 @@ // CHECK: duplicate.s(15): error: duplicate symbol: bar // CHECK-NEXT: >>> defined at duplicate.s:15 // CHECK-NEXT: >>>{{.*}}1.o:(.text+0x{{.+}}) -// CHECK: >>> defined at duplicate2.s:20 -// CHECK: >>>{{.*}}2.o:(.text+0x{{.+}}) +// CHECK: duplicate2.s(20): error: duplicate symbol: bar +// CHECK-NEXT: >>> defined at duplicate2.s:20 +// CHECK-NEXT: >>>{{.*}}2.o:(.text+0x{{.+}}) // Case 2. The source locations are unknown for both symbols. // CHECK: {{.*}}ld.lld{{.*}}: error: duplicate symbol: foo @@ -23,7 +24,14 @@ // CHECK-NEXT: >>> defined at duplicate3.s // CHECK-NEXT: >>> {{.*}}3.o:(.text+0x{{.+}}) -.global _start, foo, bar, baz +// Check that we prefer using the full path of a source file. +// CHECK: /tmp{{/|\\}}duplicate.s(33): error: duplicate symbol: qux +// CHECK-NEXT: >>> defined at duplicate.s:33 (/tmp{{/|\\}}duplicate.s:33) +// CHECK-NEXT: >>> {{.*}}1.o:(.text+0x{{.+}}) +// CHECK-NEXT: >>> defined at duplicate3.s +// CHECK-NEXT: >>> {{.*}}3.o:(.text+0x{{.+}}) + +.global _start, foo, bar, baz, qux .text _start: nop @@ -41,6 +49,11 @@ bar: baz: nop +.file 2 "/tmp" "duplicate.s" +.loc 2 33 +qux: + nop + .section .debug_abbrev,"",@progbits .byte 1 # Abbreviation Code .byte 17 # DW_TAG_compile_unit diff --git a/test/ELF/vs-diagnostics-dynamic-relocation.s b/test/ELF/vs-diagnostics-dynamic-relocation.s index 6575133ec..dec9c7b9b 100644 --- a/test/ELF/vs-diagnostics-dynamic-relocation.s +++ b/test/ELF/vs-diagnostics-dynamic-relocation.s @@ -7,12 +7,23 @@ // CHECK-NEXT: >>> referenced by dyn.s:15 // CHECK-NEXT: >>>{{.*}}.o:(.text+0x{{.+}}) +// CHECK: /tmp{{/|\\}}dyn.s(20): error: can't create dynamic relocation {{.*}} +// CHECK-NEXT: >>> defined in {{.*}}.o +// CHECK-NEXT: >>> referenced by dyn.s:20 (/tmp{{/|\\}}dyn.s:20) +// CHECK-NEXT: >>>{{.*}}.o:(.text+0x{{.+}}) + .file 1 "dyn.s" .loc 1 15 foo: .quad foo +.file 2 "/tmp" "dyn.s" +.loc 2 20 + +bar: +.quad bar + .section .debug_abbrev,"",@progbits .byte 1 # Abbreviation Code .byte 17 # DW_TAG_compile_unit diff --git a/test/ELF/vs-diagnostics-undefined-hidden.s b/test/ELF/vs-diagnostics-undefined-hidden.s new file mode 100644 index 000000000..b562e360c --- /dev/null +++ b/test/ELF/vs-diagnostics-undefined-hidden.s @@ -0,0 +1,48 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o +// RUN: not ld.lld --vs-diagnostics -shared %t.o -o /dev/null 2>&1 \ +// RUN: | FileCheck %s + +// CHECK: undef.s(15): error: undefined hidden symbol: foo +// CHECK-NEXT: >>> referenced by undef.s:15 + +// CHECK: undef.s(27): error: undefined protected symbol: bar +// CHECK-NEXT: >>> referenced by undef.s:27 + +// CHECK: /tmp{{/|\\}}undef.s(13): error: undefined protected symbol: baz +// CHECK-NEXT: >>> referenced by undef.s:13 (/tmp{{/|\\}}undef.s:13) + +.file 1 "undef.s" +.file 2 "/tmp" "undef.s" + +.hidden foo +.protected bar, baz +.text +_start: +.loc 1 15 + jmp foo +.loc 1 27 + jmp bar +.loc 2 13 + jmp baz + +.section .debug_abbrev,"",@progbits + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 0 # DW_CHILDREN_no + .byte 16 # DW_AT_stmt_list + .byte 23 # DW_FORM_sec_offset + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) + +.section .debug_info,"",@progbits + .long .Lend0 - .Lbegin0 # Length of Unit +.Lbegin0: + .short 4 # DWARF version number + .long .debug_abbrev # Offset Into Abbrev. Section + .byte 8 # Address Size (in bytes) + .byte 1 # Abbrev [1] 0xb:0x1f DW_TAG_compile_unit + .long .debug_line # DW_AT_stmt_list +.Lend0: + .section .debug_line,"",@progbits diff --git a/test/ELF/vs-diagnostics-undefined-symbol-3.s b/test/ELF/vs-diagnostics-undefined-symbol-3.s index 3ff9885b7..f2295b7c3 100644 --- a/test/ELF/vs-diagnostics-undefined-symbol-3.s +++ b/test/ELF/vs-diagnostics-undefined-symbol-3.s @@ -10,13 +10,21 @@ // CHECK: >>> referenced by undef3.s:15 // CHECK-NEXT: >>> {{.*}}1.o:(.text+0x{{.+}}) +// ERR: /tmp{{/|\\}}undef3.s(20): error: undefined symbol: bar +// WARN: /tmp{{/|\\}}undef3.s(20): warning: undefined symbol: bar +// CHECK: >>> referenced by undef3.s:20 (/tmp{{/|\\}}undef3.s:20) +// CHECK-NEXT: >>> {{.*}}1.o:(.text+0x{{.+}}) + .file 1 "undef3.s" +.file 2 "/tmp" "undef3.s" -.global _start, foo +.global _start, foo, bar .text _start: .loc 1 15 jmp foo +.loc 2 20 + jmp bar .section .debug_abbrev,"",@progbits .byte 1 # Abbreviation Code diff --git a/test/ELF/weak-undef-shared.s b/test/ELF/weak-undef-shared.s index 990e023b2..0b3e0ec78 100644 --- a/test/ELF/weak-undef-shared.s +++ b/test/ELF/weak-undef-shared.s @@ -30,6 +30,9 @@ # RUN: ld.lld %t1.o %t2.so -o %t # RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=WEAK %s +# RUN: ld.lld %t2.so %t1.o -o %t +# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=WEAK %s + # WEAK: NOTYPE WEAK DEFAULT UND foo # GLOBAL: NOTYPE GLOBAL DEFAULT UND foo diff --git a/test/ELF/x86-64-dyn-rel-error.s b/test/ELF/x86-64-dyn-rel-error.s index 7753a4dc4..1c715dbfb 100644 --- a/test/ELF/x86-64-dyn-rel-error.s +++ b/test/ELF/x86-64-dyn-rel-error.s @@ -11,6 +11,7 @@ _start: // CHECK: relocation R_X86_64_32 cannot be used against symbol zed; recompile with -fPIC -// RUN: ld.lld --noinhibit-exec %t.o %t2.so -o %t 2>&1 | FileCheck --check-prefix=WARN %s +// RUN: ld.lld --noinhibit-exec %t.o %t2.so -o /dev/null 2>&1 | FileCheck --check-prefix=WARN %s +// RUN: not ld.lld --export-dynamic --unresolved-symbols=ignore-all %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=WARN %s // WARN: symbol 'zed' has no type diff --git a/test/ELF/x86-64-dyn-rel-error5.s b/test/ELF/x86-64-dyn-rel-error5.s index 6a85ab298..483aa986b 100644 --- a/test/ELF/x86-64-dyn-rel-error5.s +++ b/test/ELF/x86-64-dyn-rel-error5.s @@ -1,7 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o -# RUN: not ld.lld -pie %t.o -o /dev/null 2>&1 | FileCheck %s -# RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +# RUN: not ld.lld -pie %t.o -o /dev/null 2>&1 | FileCheck --check-prefixes=CHECK,PIE %s +# RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck --check-prefixes=CHECK,SHARED %s ## Check we don't create dynamic relocations in a writable section, ## if the number of bits is smaller than the wordsize. @@ -16,7 +16,9 @@ hidden: # CHECK-NEXT: >>> referenced by {{.*}}.o:(.data+0x0) # CHECK: error: relocation R_X86_64_16 cannot be used against local symbol; recompile with -fPIC # CHECK: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC -# CHECK: error: relocation R_X86_64_32 cannot be used against symbol hidden; recompile with -fPIC + +# PIE: error: cannot preempt symbol: hidden +# SHARED: error: relocation R_X86_64_32 cannot be used against symbol hidden; recompile with -fPIC .data .byte local # R_X86_64_8 diff --git a/test/ELF/tls-error.s b/test/ELF/x86-64-reloc-tpoff32-error.s similarity index 77% rename from test/ELF/tls-error.s rename to test/ELF/x86-64-reloc-tpoff32-error.s index 989a63eb7..10cb3ab5f 100644 --- a/test/ELF/tls-error.s +++ b/test/ELF/x86-64-reloc-tpoff32-error.s @@ -1,5 +1,5 @@ // REQUIRES: x86 -// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +// RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t // RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s // CHECK: R_X86_64_TPOFF32 out of range diff --git a/test/ELF/tls-dynamic.s b/test/ELF/x86-64-tls-dynamic.s similarity index 100% rename from test/ELF/tls-dynamic.s rename to test/ELF/x86-64-tls-dynamic.s diff --git a/test/ELF/tls-opt-gdie.s b/test/ELF/x86-64-tls-gdie.s similarity index 71% rename from test/ELF/tls-opt-gdie.s rename to test/ELF/x86-64-tls-gdie.s index f5d21d6eb..6c0762d0d 100644 --- a/test/ELF/tls-opt-gdie.s +++ b/test/ELF/x86-64-tls-gdie.s @@ -3,25 +3,12 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/tls-opt-gdie.s -o %tso.o // RUN: ld.lld -shared %tso.o -o %t.so // RUN: ld.lld --hash-style=sysv %t.o %t.so -o %t1 -// RUN: llvm-readobj -S -r %t1 | FileCheck --check-prefix=RELOC %s +// RUN: llvm-readobj -S %t1 | FileCheck --check-prefix=SEC --implicit-check-not=.plt %s +// RUN: llvm-readobj -r %t1 | FileCheck --check-prefix=RELOC %s // RUN: llvm-objdump -d %t1 | FileCheck --check-prefix=DISASM %s -//RELOC: Section { -//RELOC: Index: -//RELOC: Name: .got -//RELOC-NEXT: Type: SHT_PROGBITS -//RELOC-NEXT: Flags [ -//RELOC-NEXT: SHF_ALLOC -//RELOC-NEXT: SHF_WRITE -//RELOC-NEXT: ] -//RELOC-NEXT: Address: 0x2020B0 -//RELOC-NEXT: Offset: 0x20B0 -//RELOC-NEXT: Size: 16 -//RELOC-NEXT: Link: 0 -//RELOC-NEXT: Info: 0 -//RELOC-NEXT: AddressAlignment: 8 -//RELOC-NEXT: EntrySize: 0 -//RELOC-NEXT: } +// SEC .got PROGBITS 00000000002020b0 0020b0 000010 00 WA 0 0 8 + //RELOC: Relocations [ //RELOC-NEXT: Section (4) .rela.dyn { //RELOC-NEXT: 0x2020B0 R_X86_64_TPOFF64 tlsshared0 0x0 diff --git a/test/ELF/x86-64-tls-ie-local.s b/test/ELF/x86-64-tls-ie-local.s new file mode 100644 index 000000000..19e0740e6 --- /dev/null +++ b/test/ELF/x86-64-tls-ie-local.s @@ -0,0 +1,28 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o +# RUN: ld.lld -shared %t.o -o %t.so +# RUN: llvm-readelf -S %t.so | FileCheck --check-prefix=SEC %s +# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=REL %s +# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck %s + +# SEC: .got PROGBITS 00000000000020b0 0020b0 000010 00 WA 0 0 8 + +## Dynamic relocations for non-preemptable symbols in a shared object have section index 0. +# REL: .rela.dyn { +# REL-NEXT: 0x20B0 R_X86_64_TPOFF64 - 0x0 +# REL-NEXT: 0x20B8 R_X86_64_TPOFF64 - 0x4 +# REL-NEXT: } + +## &.got[0] - 0x1007 = 0x20B0 - 0x1007 = 4265 +## &.got[1] - 0x100e = 0x20B8 - 0x100e = 4266 +# CHECK: 1000: addq 4265(%rip), %rax +# CHECK-NEXT: 1007: addq 4266(%rip), %rax + +addq foo@GOTTPOFF(%rip), %rax +addq bar@GOTTPOFF(%rip), %rax + +.section .tbss,"awT",@nobits +foo: + .long 0 +bar: + .long 0 diff --git a/test/ELF/tls-opt-local.s b/test/ELF/x86-64-tls-ie-opt-local.s similarity index 100% rename from test/ELF/tls-opt-local.s rename to test/ELF/x86-64-tls-ie-opt-local.s diff --git a/test/ELF/tls-opt-x86_64-noplt.s b/test/ELF/x86-64-tls-opt-noplt.s similarity index 100% rename from test/ELF/tls-opt-x86_64-noplt.s rename to test/ELF/x86-64-tls-opt-noplt.s diff --git a/test/MinGW/driver.test b/test/MinGW/driver.test index cdd802e93..8fa1199af 100644 --- a/test/MinGW/driver.test +++ b/test/MinGW/driver.test @@ -42,14 +42,16 @@ OUT: -out:bar.exe RUN: ld.lld -### foo.o -m i386pep --out-implib bar | FileCheck -check-prefix=IMPLIB %s RUN: ld.lld -### foo.o -m i386pep --out-implib=bar | FileCheck -check-prefix=IMPLIB %s +RUN: ld.lld -### foo.o -m i386pep -out-implib bar | FileCheck -check-prefix=IMPLIB %s +RUN: ld.lld -### foo.o -m i386pep -out-implib=bar | FileCheck -check-prefix=IMPLIB %s IMPLIB: -implib:bar -RUN: ld.lld -### foo.o -m i386pep -out-implib bar | FileCheck -check-prefix=NOIMPLIB %s -NOIMPLIB: -out:ut-implib - RUN: ld.lld -### foo.o -m i386pep -e bar | FileCheck -check-prefix=ENTRY %s +RUN: ld.lld -### foo.o -m i386pep -ebar | FileCheck -check-prefix=ENTRY %s RUN: ld.lld -### foo.o -m i386pep -entry bar | FileCheck -check-prefix=ENTRY %s RUN: ld.lld -### foo.o -m i386pep --entry bar | FileCheck -check-prefix=ENTRY %s +RUN: ld.lld -### foo.o -m i386pep -entry=bar | FileCheck -check-prefix=ENTRY %s +RUN: ld.lld -### foo.o -m i386pep --entry=bar | FileCheck -check-prefix=ENTRY %s ENTRY: -entry:bar RUN: ld.lld -### foo.o -m i386pep -mllvm bar -mllvm baz | FileCheck -check-prefix=MLLVM %s @@ -94,12 +96,17 @@ RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix MINGW-FLAG %s MINGW-FLAG: -lldmingw RUN: ld.lld -### -m i386pep foo.o --exclude-all-symbols | FileCheck -check-prefix EXCLUDE-ALL %s +RUN: ld.lld -### -m i386pep foo.o -exclude-all-symbols | FileCheck -check-prefix EXCLUDE-ALL %s EXCLUDE-ALL: -exclude-all-symbols RUN: ld.lld -### -m i386pep foo.o --export-all-symbols | FileCheck -check-prefix EXPORT-ALL %s +RUN: ld.lld -### -m i386pep foo.o -export-all-symbols | FileCheck -check-prefix EXPORT-ALL %s EXPORT-ALL: -export-all-symbols RUN: ld.lld -### -m i386pep foo.o --output-def out.def | FileCheck -check-prefix OUTPUT-DEF %s +RUN: ld.lld -### -m i386pep foo.o --output-def=out.def | FileCheck -check-prefix OUTPUT-DEF %s +RUN: ld.lld -### -m i386pep foo.o -output-def out.def | FileCheck -check-prefix OUTPUT-DEF %s +RUN: ld.lld -### -m i386pep foo.o -output-def=out.def | FileCheck -check-prefix OUTPUT-DEF %s OUTPUT-DEF: -output-def:out.def RUN: ld.lld -### -m i386pep foo.o -Xlink=-lldmap | FileCheck -check-prefix XLINK %s @@ -176,8 +183,8 @@ MAP: -lldmap:bar.map RUN: ld.lld -### foo.o -m i386pe -require-defined _foo --require-defined _bar -require-defined=_baz --require-defined=_foo2 | FileCheck -check-prefix=REQUIRE-DEFINED %s REQUIRE-DEFINED: -include:_foo -include:_bar -include:_baz -include:_foo2 -RUN: ld.lld -### foo.o -m i386pe -u _foo --undefined _bar -undefined=_baz --undefined=_foo2 | FileCheck -check-prefix=UNDEFINED %s -UNDEFINED: -includeoptional:_foo -includeoptional:_bar -includeoptional:_baz -includeoptional:_foo2 +RUN: ld.lld -### foo.o -m i386pe -u _foo --undefined _bar -undefined=_baz --undefined=_foo2 -u_foo3 | FileCheck -check-prefix=UNDEFINED %s +UNDEFINED: -includeoptional:_foo -includeoptional:_bar -includeoptional:_baz -includeoptional:_foo2 -includeoptional:_foo3 RUN: ld.lld -### -m i386pep foo.o -Llibpath | FileCheck -check-prefix LIBPATH %s LIBPATH: -libpath:libpath @@ -192,11 +199,15 @@ RUN: ld.lld -### -m i386pep foo.o -appcontainer | FileCheck -check-prefix APPCON RUN: ld.lld -### -m i386pep foo.o --appcontainer | FileCheck -check-prefix APPCONTAINER %s APPCONTAINER: -appcontainer -# RUN: ld.lld -m i386pep --version 2>&1 | FileCheck -check-prefix=VERSION %s -# RUN: ld.lld -m i386pep -v 2>&1 | FileCheck -check-prefix=VERSION %s -# RUN: not ld.lld -m i386pep -v xyz 2>&1 | FileCheck -check-prefix=VERSION %s -# VERSION: LLD {{.*}} (compatible with GNU linkers) +RUN: ld.lld -m i386pep --version 2>&1 | FileCheck -check-prefix=VERSION %s +RUN: ld.lld -m i386pep -v 2>&1 | FileCheck -check-prefix=VERSION %s +RUN: not ld.lld -m i386pep -v xyz 2>&1 | FileCheck -check-prefix=VERSION %s +VERSION: LLD {{.*}} (compatible with GNU linkers) + +RUN: ld.lld -m i386pep --help 2>&1 | FileCheck -check-prefix=HELP %s +HELP: USAGE: +HELP: --enable-auto-import -# RUN: ld.lld -m i386pep --help 2>&1 | FileCheck -check-prefix=HELP %s -# HELP: USAGE: -# HELP: --enable-auto-import +RUN: ld.lld -### -m i386pep foo.o -delayload user32.dll --delayload shell32.dll | FileCheck -check-prefix DELAYLOAD %s +RUN: ld.lld -### -m i386pep foo.o -delayload=user32.dll --delayload=shell32.dll | FileCheck -check-prefix DELAYLOAD %s +DELAYLOAD: -delayload:user32.dll -delayload:shell32.dll diff --git a/test/wasm/Inputs/optional-symbol.ll b/test/wasm/Inputs/optional-symbol.ll new file mode 100644 index 000000000..d39a8a4db --- /dev/null +++ b/test/wasm/Inputs/optional-symbol.ll @@ -0,0 +1,7 @@ +target triple = "wasm32-unknown-unknown" + +@__dso_handle = external global i8* + +define i8** @get_optional() { + ret i8** @__dso_handle +} diff --git a/test/wasm/debuginfo-relocs.s b/test/wasm/debuginfo-relocs.s new file mode 100644 index 000000000..bece55f54 --- /dev/null +++ b/test/wasm/debuginfo-relocs.s @@ -0,0 +1,23 @@ +# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s +# RUN: wasm-ld %t.o -o %t.wasm +# RUN: obj2yaml %t.wasm | FileCheck %s + +bar: + .functype bar () -> () + end_function + + .globl _start +_start: + .functype _start () -> () + call bar + end_function + + .section .debug_info,"",@ + .int32 bar + +# Even though `bar` is live in the final binary it doesn't have a table entry +# since its not address taken in the code. In this case any relocations in the +# debug sections see a address of zero. + +# CHECK: Name: .debug_info +# CHECK-NEXT: Payload: '00000000' diff --git a/test/wasm/export-optional-lazy.ll b/test/wasm/export-optional-lazy.ll new file mode 100644 index 000000000..5662b0b05 --- /dev/null +++ b/test/wasm/export-optional-lazy.ll @@ -0,0 +1,25 @@ +; Optional linker-synthetic symbols are only created if they are undefined +; in the final output. +; This test is for a regression where an explict --export of an lazy archive +; symbol caused an undefined referece to an optional symbol to occur *after* +; the optional symbols were created. + +; RUN: llc -filetype=obj %s -o %t.o +; RUN: llc -filetype=obj %S/Inputs/optional-symbol.ll -o %t.a1.o +; RUN: rm -f %t.a +; RUN: llvm-ar rcs %t.a %t.a1.o +; RUN: wasm-ld --export=get_optional %t.o %t.a -o %t.wasm +; RUN: obj2yaml %t.wasm | FileCheck %s + +target triple = "wasm32-unknown-unknown" + +define void @_start() { +entry: + ret void +} + +; CHECK: FunctionNames: +; CHECK-NEXT: - Index: 0 +; CHECK-NEXT: Name: _start +; CHECK-NEXT: - Index: 1 +; CHECK-NEXT: Name: get_optional diff --git a/test/wasm/export.ll b/test/wasm/export.ll index 8dc14ae86..06c5dfc8d 100644 --- a/test/wasm/export.ll +++ b/test/wasm/export.ll @@ -1,8 +1,15 @@ +; Test in default mode ; RUN: llc -filetype=obj %s -o %t.o ; RUN: not wasm-ld --export=missing -o %t.wasm %t.o 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s ; RUN: wasm-ld --export=hidden_function -o %t.wasm %t.o ; RUN: obj2yaml %t.wasm | FileCheck %s +; Now test in Emscripten mode +; RUN: llc -filetype=obj %s -o %t.o -mtriple=wasm32-unknown-emscripten +; RUN: not wasm-ld --export=missing -o %t.wasm %t.o 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s +; RUN: wasm-ld --export=hidden_function -o %t.wasm %t.o +; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN + @llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @used_function to i8*)], section "llvm.metadata" target triple = "wasm32-unknown-unknown" @@ -43,9 +50,9 @@ entry: ; CHECK-NEXT: - Name: hidden_function ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: used_function -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 1 +; EMSCRIPTEN-NEXT: - Name: used_function +; EMSCRIPTEN-NEXT: Kind: FUNCTION +; EMSCRIPTEN-NEXT: Index: 1 ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 2 diff --git a/test/wasm/global-base.test b/test/wasm/global-base.test index 07c8d6308..723b0d79a 100644 --- a/test/wasm/global-base.test +++ b/test/wasm/global-base.test @@ -24,11 +24,7 @@ CHECK-1024-NEXT: Opcode: I32_CONST CHECK-1024-NEXT: Value: 1024 CHECK-1024: - Type: EXPORT -CHECK-1024-NEXT: Exports: -CHECK-1024-NEXT: - Name: memory -CHECK-1024-NEXT: Kind: MEMORY -CHECK-1024-NEXT: Index: 0 -CHECK-1024-NEXT: - Name: __data_end +CHECK-1024: - Name: __data_end CHECK-1024-NEXT: Kind: GLOBAL CHECK-1024-NEXT: Index: 1 CHECK-1024-NEXT: - Name: __global_base @@ -59,11 +55,7 @@ CHECK-16777216-NEXT: Opcode: I32_CONST CHECK-16777216-NEXT: Value: 16777216 CHECK-16777216: - Type: EXPORT -CHECK-16777216-NEXT: Exports: -CHECK-16777216-NEXT: - Name: memory -CHECK-16777216-NEXT: Kind: MEMORY -CHECK-16777216-NEXT: Index: 0 -CHECK-16777216-NEXT: - Name: __data_end +CHECK-16777216: - Name: __data_end CHECK-16777216-NEXT: Kind: GLOBAL CHECK-16777216-NEXT: Index: 1 CHECK-16777216-NEXT: - Name: __global_base diff --git a/test/wasm/growable-table.test b/test/wasm/growable-table.test new file mode 100644 index 000000000..cd52f2e16 --- /dev/null +++ b/test/wasm/growable-table.test @@ -0,0 +1,17 @@ +# RUN: llc -filetype=obj %p/Inputs/start.ll -o %t.start.o +# RUN: wasm-ld --export-table --growable-table -o %t.wasm %t.start.o +# RUN: obj2yaml %t.wasm | FileCheck %s + +# Verify the --growable-table flag creates a growable table + +# CHECK: - Type: TABLE +# CHECK-NEXT: Tables: +# CHECK-NEXT: - ElemType: FUNCREF +# CHECK-NEXT: Limits: +# CHECK-NEXT: Initial: 0x00000001 +# CHECK-NEXT: - Type: +# CHECK: - Type: EXPORT +# CHECK-NEXT: Exports: +# CHECK: - Name: __indirect_function_table +# CHECK-NEXT: Kind: TABLE +# CHECK-NEXT: Index: 0 diff --git a/test/wasm/optional-symbol.ll b/test/wasm/optional-symbol.ll new file mode 100644 index 000000000..ac1a4212f --- /dev/null +++ b/test/wasm/optional-symbol.ll @@ -0,0 +1,14 @@ +; RUN: llc -filetype=obj -o %t.o %s +; RUN: wasm-ld --export=get_handle %t.o -o %t.wasm + +target triple = "wasm32-unknown-unknown" + +@__dso_handle = external global i8* + +define i8** @get_handle() { + ret i8** @__dso_handle +} + +define void @_start() { + ret void +} diff --git a/test/wasm/pic-static.ll b/test/wasm/pic-static.ll new file mode 100644 index 000000000..f0187ec32 --- /dev/null +++ b/test/wasm/pic-static.ll @@ -0,0 +1,95 @@ +; Test that PIC code can be linked into static binaries. +; In this case the GOT entries will end up as internalized wasm globals with +; fixed values. +; RUN: llc -relocation-model=pic -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o +; RUN: llc -relocation-model=pic -filetype=obj %s -o %t.o +; RUN: wasm-ld -o %t.wasm %t.o %t.ret32.o +; RUN: obj2yaml %t.wasm | FileCheck %s + +target triple = "wasm32-unknown-emscripten" + +declare i32 @ret32(float) +@global_float = global float 1.0 +@hidden_float = hidden global float 2.0 + +@ret32_ptr = global i32 (float)* @ret32, align 4 + +define i32 (float)* @getaddr_external() { + ret i32 (float)* @ret32; +} + +define i32 ()* @getaddr_hidden() { + ret i32 ()* @hidden_func; +} + +define hidden i32 @hidden_func() { + ret i32 1 +} + +define void @_start() { +entry: + %f = load float, float* @hidden_float, align 4 + %addr = load i32 (float)*, i32 (float)** @ret32_ptr, align 4 + %arg = load float, float* @global_float, align 4 + call i32 %addr(float %arg) + + %addr2 = call i32 (float)* @getaddr_external() + %arg2 = load float, float* @hidden_float, align 4 + call i32 %addr2(float %arg2) + + %addr3 = call i32 ()* @getaddr_hidden() + call i32 %addr3() + + ret void +} + +; CHECK: - Type: GLOBAL +; CHECK-NEXT: Globals: + +; __stack_pointer +; CHECK-NEXT: - Index: 0 +; CHECK-NEXT: Type: I32 +; CHECK-NEXT: Mutable: true +; CHECK-NEXT: InitExpr: +; CHECK-NEXT: Opcode: I32_CONST +; CHECK-NEXT: Value: 66576 + +; GOT.func.ret32 +; CHECK-NEXT: - Index: 1 +; CHECK-NEXT: Type: I32 +; CHECK-NEXT: Mutable: false +; CHECK-NEXT: InitExpr: +; CHECK-NEXT: Opcode: I32_CONST +; CHECK-NEXT: Value: 2 + +; __table_base +; CHECK-NEXT: - Index: 2 +; CHECK-NEXT: Type: I32 +; CHECK-NEXT: Mutable: false +; CHECK-NEXT: InitExpr: +; CHECK-NEXT: Opcode: I32_CONST +; CHECK-NEXT: Value: 1 + +; GOT.mem.global_float +; CHECK-NEXT: - Index: 3 +; CHECK-NEXT: Type: I32 +; CHECK-NEXT: Mutable: false +; CHECK-NEXT: InitExpr: +; CHECK-NEXT: Opcode: I32_CONST +; CHECK-NEXT: Value: 1024 + +; GOT.mem.ret32_ptr +; CHECK-NEXT: - Index: 4 +; CHECK-NEXT: Type: I32 +; CHECK-NEXT: Mutable: false +; CHECK-NEXT: InitExpr: +; CHECK-NEXT: Opcode: I32_CONST +; CHECK-NEXT: Value: 1032 + +; __memory_base +; CHECK-NEXT: - Index: 5 +; CHECK-NEXT: Type: I32 +; CHECK-NEXT: Mutable: false +; CHECK-NEXT: InitExpr: +; CHECK-NEXT: Opcode: I32_CONST +; CHECK-NEXT: Value: 1024 diff --git a/test/wasm/relocatable.ll b/test/wasm/relocatable.ll index 67f8ac0d8..097adca48 100644 --- a/test/wasm/relocatable.ll +++ b/test/wasm/relocatable.ll @@ -1,7 +1,12 @@ ; RUN: llc -filetype=obj %p/Inputs/hello.ll -o %t.hello.o ; RUN: llc -filetype=obj %s -o %t.o ; RUN: wasm-ld -r -o %t.wasm %t.hello.o %t.o -; RUN: obj2yaml %t.wasm | FileCheck %s +; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes CHECK,NORMAL + +; RUN: llc -filetype=obj %p/Inputs/hello.ll -o %t.hello.bm.o -mattr=+bulk-memory +; RUN: llc -filetype=obj %s -o %t.bm.o -mattr=+bulk-memory +; RUN: wasm-ld -r -o %t.mt.wasm %t.hello.bm.o %t.bm.o --shared-memory --max-memory=131072 +; RUN: obj2yaml %t.mt.wasm | FileCheck %s --check-prefixes CHECK,SHARED target triple = "wasm32-unknown-unknown" @@ -70,13 +75,18 @@ entry: ; CHECK-NEXT: Maximum: 0x00000004 ; CHECK-NEXT: - Type: MEMORY ; CHECK-NEXT: Memories: -; CHECK-NEXT: - Initial: 0x00000001 +; NORMAL-NEXT: - Initial: 0x00000001 +; SHARED-NEXT: - Flags: [ HAS_MAX, IS_SHARED ] +; SHARED-NEXT: Initial: 0x00000001 +; SHARED-NEXT: Maximum: 0x00000002 ; CHECK-NEXT: - Type: ELEM ; CHECK-NEXT: Segments: ; CHECK-NEXT: - Offset: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 1 ; CHECK-NEXT: Functions: [ 4, 1, 2 ] +; SHARED-NEXT: - Type: DATACOUNT +; SHARED-NEXT: Count: 6 ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_SLEB @@ -104,176 +114,176 @@ entry: ; CHECK-NEXT: - Index: 5 ; CHECK-NEXT: Locals: ; CHECK-NEXT: Body: 419C808080000B -; CHECK-NEXT: - Type: DATA -; CHECK-NEXT: Relocations: -; CHECK-NEXT: - Type: R_WASM_TABLE_INDEX_I32 -; CHECK-NEXT: Index: 3 -; CHECK-NEXT: Offset: 0x00000012 -; CHECK-NEXT: - Type: R_WASM_TABLE_INDEX_I32 -; CHECK-NEXT: Index: 4 -; CHECK-NEXT: Offset: 0x0000001B -; CHECK-NEXT: - Type: R_WASM_TABLE_INDEX_I32 -; CHECK-NEXT: Index: 5 -; CHECK-NEXT: Offset: 0x00000024 -; CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_I32 -; CHECK-NEXT: Index: 12 -; CHECK-NEXT: Offset: 0x0000002D -; CHECK-NEXT: Segments: -; CHECK-NEXT: - SectionOffset: 6 -; CHECK-NEXT: InitFlags: 0 -; CHECK-NEXT: Offset: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 0 -; CHECK-NEXT: Content: 68656C6C6F0A00 -; CHECK-NEXT: - SectionOffset: 18 -; CHECK-NEXT: InitFlags: 0 -; CHECK-NEXT: Offset: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 8 -; CHECK-NEXT: Content: '01000000' -; CHECK-NEXT: - SectionOffset: 27 -; CHECK-NEXT: InitFlags: 0 -; CHECK-NEXT: Offset: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 12 -; CHECK-NEXT: Content: '02000000' -; CHECK-NEXT: - SectionOffset: 36 -; CHECK-NEXT: InitFlags: 0 -; CHECK-NEXT: Offset: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 16 -; CHECK-NEXT: Content: '03000000' -; CHECK-NEXT: - SectionOffset: 45 -; CHECK-NEXT: InitFlags: 0 -; CHECK-NEXT: Offset: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 24 -; CHECK-NEXT: Content: '00000000' -; CHECK-NEXT: - SectionOffset: 54 -; CHECK-NEXT: InitFlags: 0 -; CHECK-NEXT: Offset: -; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 28 -; CHECK-NEXT: Content: '616263' -; CHECK-NEXT: - Type: CUSTOM -; CHECK-NEXT: Name: linking -; CHECK-NEXT: Version: 2 -; CHECK-NEXT: SymbolTable: -; CHECK-NEXT: - Index: 0 -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Name: hello -; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: Function: 3 -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Kind: DATA -; CHECK-NEXT: Name: hello_str -; CHECK-NEXT: Flags: [ ] -; CHECK-NEXT: Segment: 0 -; CHECK-NEXT: Size: 7 -; CHECK-NEXT: - Index: 2 -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Name: puts -; CHECK-NEXT: Flags: [ UNDEFINED ] -; CHECK-NEXT: Function: 0 -; CHECK-NEXT: - Index: 3 -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Name: my_func -; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: Function: 4 -; CHECK-NEXT: - Index: 4 -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Name: foo_import -; CHECK-NEXT: Flags: [ UNDEFINED ] -; CHECK-NEXT: Function: 1 -; CHECK-NEXT: - Index: 5 -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Name: bar_import -; CHECK-NEXT: Flags: [ BINDING_WEAK, UNDEFINED ] -; CHECK-NEXT: Function: 2 -; CHECK-NEXT: - Index: 6 -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Name: func_comdat -; CHECK-NEXT: Flags: [ BINDING_WEAK ] -; CHECK-NEXT: Function: 5 -; CHECK-NEXT: - Index: 7 -; CHECK-NEXT: Kind: DATA -; CHECK-NEXT: Name: data_comdat -; CHECK-NEXT: Flags: [ BINDING_WEAK ] -; CHECK-NEXT: Segment: 5 -; CHECK-NEXT: Size: 3 -; CHECK-NEXT: - Index: 8 -; CHECK-NEXT: Kind: DATA -; CHECK-NEXT: Name: func_addr1 -; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: Segment: 1 -; CHECK-NEXT: Size: 4 -; CHECK-NEXT: - Index: 9 -; CHECK-NEXT: Kind: DATA -; CHECK-NEXT: Name: func_addr2 -; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: Segment: 2 -; CHECK-NEXT: Size: 4 -; CHECK-NEXT: - Index: 10 -; CHECK-NEXT: Kind: DATA -; CHECK-NEXT: Name: func_addr3 -; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: Segment: 3 -; CHECK-NEXT: Size: 4 -; CHECK-NEXT: - Index: 11 -; CHECK-NEXT: Kind: DATA -; CHECK-NEXT: Name: data_addr1 -; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; CHECK-NEXT: Segment: 4 -; CHECK-NEXT: Size: 4 -; CHECK-NEXT: - Index: 12 -; CHECK-NEXT: Kind: DATA -; CHECK-NEXT: Name: data_import -; CHECK-NEXT: Flags: [ UNDEFINED ] -; CHECK-NEXT: SegmentInfo: -; CHECK-NEXT: - Index: 0 -; CHECK-NEXT: Name: .rodata.hello_str -; CHECK-NEXT: Alignment: 0 -; CHECK-NEXT: Flags: [ ] -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Name: .data.func_addr1 -; CHECK-NEXT: Alignment: 2 -; CHECK-NEXT: Flags: [ ] -; CHECK-NEXT: - Index: 2 -; CHECK-NEXT: Name: .data.func_addr2 -; CHECK-NEXT: Alignment: 2 -; CHECK-NEXT: Flags: [ ] -; CHECK-NEXT: - Index: 3 -; CHECK-NEXT: Name: .data.func_addr3 -; CHECK-NEXT: Alignment: 2 -; CHECK-NEXT: Flags: [ ] -; CHECK-NEXT: - Index: 4 -; CHECK-NEXT: Name: .data.data_addr1 -; CHECK-NEXT: Alignment: 3 -; CHECK-NEXT: Flags: [ ] -; CHECK-NEXT: - Index: 5 -; CHECK-NEXT: Name: .rodata.data_comdat -; CHECK-NEXT: Alignment: 0 -; CHECK-NEXT: Flags: [ ] -; CHECK-NEXT: Comdats: -; CHECK-NEXT: - Name: func_comdat -; CHECK-NEXT: Entries: -; CHECK-NEXT: - Kind: FUNCTION -; CHECK-NEXT: Index: 5 -; CHECK-NEXT: - Kind: DATA -; CHECK-NEXT: Index: 5 -; CHECK-NEXT: - Type: CUSTOM -; CHECK-NEXT: Name: name -; CHECK-NEXT: FunctionNames: -; CHECK-NEXT: - Index: 0 -; CHECK-NEXT: Name: puts -; CHECK-NEXT: - Index: 1 -; CHECK-NEXT: Name: foo_import -; CHECK-NEXT: - Index: 2 -; CHECK-NEXT: Name: bar_import -; CHECK-NEXT: - Index: 3 -; CHECK-NEXT: Name: hello -; CHECK-NEXT: - Index: 4 -; CHECK-NEXT: Name: my_func -; CHECK-NEXT: - Index: 5 -; CHECK-NEXT: Name: func_comdat -; CHECK-NEXT: ... +; NORMAL-NEXT: - Type: DATA +; NORMAL-NEXT: Relocations: +; NORMAL-NEXT: - Type: R_WASM_TABLE_INDEX_I32 +; NORMAL-NEXT: Index: 3 +; NORMAL-NEXT: Offset: 0x00000012 +; NORMAL-NEXT: - Type: R_WASM_TABLE_INDEX_I32 +; NORMAL-NEXT: Index: 4 +; NORMAL-NEXT: Offset: 0x0000001B +; NORMAL-NEXT: - Type: R_WASM_TABLE_INDEX_I32 +; NORMAL-NEXT: Index: 5 +; NORMAL-NEXT: Offset: 0x00000024 +; NORMAL-NEXT: - Type: R_WASM_MEMORY_ADDR_I32 +; NORMAL-NEXT: Index: 12 +; NORMAL-NEXT: Offset: 0x0000002D +; NORMAL-NEXT: Segments: +; NORMAL-NEXT: - SectionOffset: 6 +; NORMAL-NEXT: InitFlags: 0 +; NORMAL-NEXT: Offset: +; NORMAL-NEXT: Opcode: I32_CONST +; NORMAL-NEXT: Value: 0 +; NORMAL-NEXT: Content: 68656C6C6F0A00 +; NORMAL-NEXT: - SectionOffset: 18 +; NORMAL-NEXT: InitFlags: 0 +; NORMAL-NEXT: Offset: +; NORMAL-NEXT: Opcode: I32_CONST +; NORMAL-NEXT: Value: 8 +; NORMAL-NEXT: Content: '01000000' +; NORMAL-NEXT: - SectionOffset: 27 +; NORMAL-NEXT: InitFlags: 0 +; NORMAL-NEXT: Offset: +; NORMAL-NEXT: Opcode: I32_CONST +; NORMAL-NEXT: Value: 12 +; NORMAL-NEXT: Content: '02000000' +; NORMAL-NEXT: - SectionOffset: 36 +; NORMAL-NEXT: InitFlags: 0 +; NORMAL-NEXT: Offset: +; NORMAL-NEXT: Opcode: I32_CONST +; NORMAL-NEXT: Value: 16 +; NORMAL-NEXT: Content: '03000000' +; NORMAL-NEXT: - SectionOffset: 45 +; NORMAL-NEXT: InitFlags: 0 +; NORMAL-NEXT: Offset: +; NORMAL-NEXT: Opcode: I32_CONST +; NORMAL-NEXT: Value: 24 +; NORMAL-NEXT: Content: '00000000' +; NORMAL-NEXT: - SectionOffset: 54 +; NORMAL-NEXT: InitFlags: 0 +; NORMAL-NEXT: Offset: +; NORMAL-NEXT: Opcode: I32_CONST +; NORMAL-NEXT: Value: 28 +; NORMAL-NEXT: Content: '616263' +; NORMAL-NEXT: - Type: CUSTOM +; NORMAL-NEXT: Name: linking +; NORMAL-NEXT: Version: 2 +; NORMAL-NEXT: SymbolTable: +; NORMAL-NEXT: - Index: 0 +; NORMAL-NEXT: Kind: FUNCTION +; NORMAL-NEXT: Name: hello +; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ] +; NORMAL-NEXT: Function: 3 +; NORMAL-NEXT: - Index: 1 +; NORMAL-NEXT: Kind: DATA +; NORMAL-NEXT: Name: hello_str +; NORMAL-NEXT: Flags: [ ] +; NORMAL-NEXT: Segment: 0 +; NORMAL-NEXT: Size: 7 +; NORMAL-NEXT: - Index: 2 +; NORMAL-NEXT: Kind: FUNCTION +; NORMAL-NEXT: Name: puts +; NORMAL-NEXT: Flags: [ UNDEFINED ] +; NORMAL-NEXT: Function: 0 +; NORMAL-NEXT: - Index: 3 +; NORMAL-NEXT: Kind: FUNCTION +; NORMAL-NEXT: Name: my_func +; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ] +; NORMAL-NEXT: Function: 4 +; NORMAL-NEXT: - Index: 4 +; NORMAL-NEXT: Kind: FUNCTION +; NORMAL-NEXT: Name: foo_import +; NORMAL-NEXT: Flags: [ UNDEFINED ] +; NORMAL-NEXT: Function: 1 +; NORMAL-NEXT: - Index: 5 +; NORMAL-NEXT: Kind: FUNCTION +; NORMAL-NEXT: Name: bar_import +; NORMAL-NEXT: Flags: [ BINDING_WEAK, UNDEFINED ] +; NORMAL-NEXT: Function: 2 +; NORMAL-NEXT: - Index: 6 +; NORMAL-NEXT: Kind: FUNCTION +; NORMAL-NEXT: Name: func_comdat +; NORMAL-NEXT: Flags: [ BINDING_WEAK ] +; NORMAL-NEXT: Function: 5 +; NORMAL-NEXT: - Index: 7 +; NORMAL-NEXT: Kind: DATA +; NORMAL-NEXT: Name: data_comdat +; NORMAL-NEXT: Flags: [ BINDING_WEAK ] +; NORMAL-NEXT: Segment: 5 +; NORMAL-NEXT: Size: 3 +; NORMAL-NEXT: - Index: 8 +; NORMAL-NEXT: Kind: DATA +; NORMAL-NEXT: Name: func_addr1 +; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ] +; NORMAL-NEXT: Segment: 1 +; NORMAL-NEXT: Size: 4 +; NORMAL-NEXT: - Index: 9 +; NORMAL-NEXT: Kind: DATA +; NORMAL-NEXT: Name: func_addr2 +; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ] +; NORMAL-NEXT: Segment: 2 +; NORMAL-NEXT: Size: 4 +; NORMAL-NEXT: - Index: 10 +; NORMAL-NEXT: Kind: DATA +; NORMAL-NEXT: Name: func_addr3 +; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ] +; NORMAL-NEXT: Segment: 3 +; NORMAL-NEXT: Size: 4 +; NORMAL-NEXT: - Index: 11 +; NORMAL-NEXT: Kind: DATA +; NORMAL-NEXT: Name: data_addr1 +; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ] +; NORMAL-NEXT: Segment: 4 +; NORMAL-NEXT: Size: 4 +; NORMAL-NEXT: - Index: 12 +; NORMAL-NEXT: Kind: DATA +; NORMAL-NEXT: Name: data_import +; NORMAL-NEXT: Flags: [ UNDEFINED ] +; NORMAL-NEXT: SegmentInfo: +; NORMAL-NEXT: - Index: 0 +; NORMAL-NEXT: Name: .rodata.hello_str +; NORMAL-NEXT: Alignment: 0 +; NORMAL-NEXT: Flags: [ ] +; NORMAL-NEXT: - Index: 1 +; NORMAL-NEXT: Name: .data.func_addr1 +; NORMAL-NEXT: Alignment: 2 +; NORMAL-NEXT: Flags: [ ] +; NORMAL-NEXT: - Index: 2 +; NORMAL-NEXT: Name: .data.func_addr2 +; NORMAL-NEXT: Alignment: 2 +; NORMAL-NEXT: Flags: [ ] +; NORMAL-NEXT: - Index: 3 +; NORMAL-NEXT: Name: .data.func_addr3 +; NORMAL-NEXT: Alignment: 2 +; NORMAL-NEXT: Flags: [ ] +; NORMAL-NEXT: - Index: 4 +; NORMAL-NEXT: Name: .data.data_addr1 +; NORMAL-NEXT: Alignment: 3 +; NORMAL-NEXT: Flags: [ ] +; NORMAL-NEXT: - Index: 5 +; NORMAL-NEXT: Name: .rodata.data_comdat +; NORMAL-NEXT: Alignment: 0 +; NORMAL-NEXT: Flags: [ ] +; NORMAL-NEXT: Comdats: +; NORMAL-NEXT: - Name: func_comdat +; NORMAL-NEXT: Entries: +; NORMAL-NEXT: - Kind: FUNCTION +; NORMAL-NEXT: Index: 5 +; NORMAL-NEXT: - Kind: DATA +; NORMAL-NEXT: Index: 5 +; NORMAL-NEXT: - Type: CUSTOM +; NORMAL-NEXT: Name: name +; NORMAL-NEXT: FunctionNames: +; NORMAL-NEXT: - Index: 0 +; NORMAL-NEXT: Name: puts +; NORMAL-NEXT: - Index: 1 +; NORMAL-NEXT: Name: foo_import +; NORMAL-NEXT: - Index: 2 +; NORMAL-NEXT: Name: bar_import +; NORMAL-NEXT: - Index: 3 +; NORMAL-NEXT: Name: hello +; NORMAL-NEXT: - Index: 4 +; NORMAL-NEXT: Name: my_func +; NORMAL-NEXT: - Index: 5 +; NORMAL-NEXT: Name: func_comdat +; NORMAL-NEXT:... diff --git a/test/wasm/shared-export-dynamic.ll b/test/wasm/shared-export-dynamic.ll new file mode 100644 index 000000000..c2c4a9ff2 --- /dev/null +++ b/test/wasm/shared-export-dynamic.ll @@ -0,0 +1,18 @@ +; RUN: llc -relocation-model=pic -filetype=obj %s -o %t.o + +; By default all `default` symbols should be exported +; RUN: wasm-ld -shared -o %t.wasm %t.o +; RUN: obj2yaml %t.wasm | FileCheck %s -check-prefix=DEFAULT +; DEFAULT: foo + +; Verify that `--no-export-dynamic` works with `-shared` +; RUN: wasm-ld -shared --no-export-dynamic -o %t2.wasm %t.o +; RUN: obj2yaml %t2.wasm | FileCheck %s -check-prefix=NO-EXPORT +; NO-EXPORT-NOT: foo + +target triple = "wasm32-unknown-emscripten" + +define default i32 @foo() { +entry: + ret i32 0 +} diff --git a/test/wasm/signature-mismatch-unknown.ll b/test/wasm/signature-mismatch-unknown.ll index 65bb31511..9bd97db50 100644 --- a/test/wasm/signature-mismatch-unknown.ll +++ b/test/wasm/signature-mismatch-unknown.ll @@ -3,6 +3,14 @@ ; RUN: wasm-ld --fatal-warnings -o %t.wasm %t.ret32.o %t.main.o ; RUN: wasm-ld --fatal-warnings -o %t.wasm %t.main.o %t.ret32.o +; Also test the case where there are two different object files that contains +; referneces ret32: +; %t.main.o: Does not call ret32 directly; used the wrong signature. +; %t.call-ret32.o: Calls ret32 directly; uses the correct signature. +; RUN: llc -filetype=obj %p/Inputs/call-ret32.ll -o %t.call-ret32.o +; RUN: wasm-ld --export=call_ret32 --fatal-warnings -o %t.wasm %t.main.o %t.call-ret32.o %t.ret32.o +; RUN: wasm-ld --export=call_ret32 --fatal-warnings -o %t.wasm %t.call-ret32.o %t.main.o %t.ret32.o + target triple = "wasm32-unknown-unknown" ; Function declartion with incorrect signature. diff --git a/test/wasm/stack-first.test b/test/wasm/stack-first.test index bc45023c0..805acfb6f 100644 --- a/test/wasm/stack-first.test +++ b/test/wasm/stack-first.test @@ -32,12 +32,12 @@ CHECK-NEXT: Exports: CHECK-NEXT: - Name: memory CHECK-NEXT: Kind: MEMORY CHECK-NEXT: Index: 0 +CHECK-NEXT: - Name: _start +CHECK-NEXT: Kind: FUNCTION +CHECK-NEXT: Index: 0 CHECK-NEXT: - Name: __data_end CHECK-NEXT: Kind: GLOBAL CHECK-NEXT: Index: 1 CHECK-NEXT: - Name: __heap_base CHECK-NEXT: Kind: GLOBAL CHECK-NEXT: Index: 2 -CHECK-NEXT: - Name: _start -CHECK-NEXT: Kind: FUNCTION -CHECK-NEXT: Index: 0 diff --git a/wasm/Config.h b/wasm/Config.h index e502b2f17..90a3c4097 100644 --- a/wasm/Config.h +++ b/wasm/Config.h @@ -31,6 +31,7 @@ struct Configuration { bool exportAll; bool exportDynamic; bool exportTable; + bool growableTable; bool gcSections; bool importMemory; bool sharedMemory; @@ -70,6 +71,12 @@ struct Configuration { // True if we are creating position-independent code. bool isPic; + + // The table offset at which to place function addresses. We reserve zero + // for the null function pointer. This gets set to 1 for exectuables and 0 + // for shared libraries (since they always added to a dynamic offset at + // runtime). + uint32_t tableBase = 0; }; // The only instance of Configuration struct. diff --git a/wasm/Driver.cpp b/wasm/Driver.cpp index a1d22bf66..499c0649f 100644 --- a/wasm/Driver.cpp +++ b/wasm/Driver.cpp @@ -83,10 +83,10 @@ bool lld::wasm::link(ArrayRef args, bool canExitEarly, raw_ostream &error) { errorHandler().logName = args::getFilenameWithoutExe(args[0]); errorHandler().errorOS = &error; - errorHandler().colorDiagnostics = error.has_colors(); errorHandler().errorLimitExceededMsg = "too many errors emitted, stopping now (use " "-error-limit=0 to see all errors)"; + enableColors(error.has_colors()); config = make(); symtab = make(); @@ -134,15 +134,15 @@ static void handleColorDiagnostics(opt::InputArgList &args) { if (!arg) return; if (arg->getOption().getID() == OPT_color_diagnostics) { - errorHandler().colorDiagnostics = true; + enableColors(true); } else if (arg->getOption().getID() == OPT_no_color_diagnostics) { - errorHandler().colorDiagnostics = false; + enableColors(false); } else { StringRef s = arg->getValue(); if (s == "always") - errorHandler().colorDiagnostics = true; + enableColors(true); else if (s == "never") - errorHandler().colorDiagnostics = false; + enableColors(false); else if (s != "auto") error("unknown option: --color-diagnostics=" + s); } @@ -313,9 +313,8 @@ static void readConfigs(opt::InputArgList &args) { config->emitRelocs = args.hasArg(OPT_emit_relocs); config->entry = getEntry(args); config->exportAll = args.hasArg(OPT_export_all); - config->exportDynamic = args.hasFlag(OPT_export_dynamic, - OPT_no_export_dynamic, false); config->exportTable = args.hasArg(OPT_export_table); + config->growableTable = args.hasArg(OPT_growable_table); errorHandler().fatalWarnings = args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false); config->importMemory = args.hasArg(OPT_import_memory); @@ -358,6 +357,10 @@ static void readConfigs(opt::InputArgList &args) { config->zStackSize = args::getZOptionValue(args, OPT_z, "stack-size", WasmPageSize); + // Default value of exportDynamic depends on `-shared` + config->exportDynamic = + args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, config->shared); + if (auto *arg = args.getLastArg(OPT_features)) { config->features = llvm::Optional>(std::vector()); @@ -381,7 +384,6 @@ static void setConfigs() { if (config->shared) { config->importMemory = true; - config->exportDynamic = true; config->allowUndefined = true; } } @@ -463,38 +465,37 @@ static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable, // Create ABI-defined synthetic symbols static void createSyntheticSymbols() { + if (config->relocatable) + return; + static WasmSignature nullSignature = {{}, {}}; static WasmSignature i32ArgSignature = {{}, {ValType::I32}}; static llvm::wasm::WasmGlobalType globalTypeI32 = {WASM_TYPE_I32, false}; static llvm::wasm::WasmGlobalType mutableGlobalTypeI32 = {WASM_TYPE_I32, true}; - if (!config->relocatable) { - WasmSym::callCtors = symtab->addSyntheticFunction( - "__wasm_call_ctors", WASM_SYMBOL_VISIBILITY_HIDDEN, - make(nullSignature, "__wasm_call_ctors")); - - if (config->passiveSegments) { - // Passive segments are used to avoid memory being reinitialized on each - // thread's instantiation. These passive segments are initialized and - // dropped in __wasm_init_memory, which is the first function called from - // __wasm_call_ctors. - WasmSym::initMemory = symtab->addSyntheticFunction( - "__wasm_init_memory", WASM_SYMBOL_VISIBILITY_HIDDEN, - make(nullSignature, "__wasm_init_memory")); - } + WasmSym::callCtors = symtab->addSyntheticFunction( + "__wasm_call_ctors", WASM_SYMBOL_VISIBILITY_HIDDEN, + make(nullSignature, "__wasm_call_ctors")); + + if (config->passiveSegments) { + // Passive segments are used to avoid memory being reinitialized on each + // thread's instantiation. These passive segments are initialized and + // dropped in __wasm_init_memory, which is the first function called from + // __wasm_call_ctors. + WasmSym::initMemory = symtab->addSyntheticFunction( + "__wasm_init_memory", WASM_SYMBOL_VISIBILITY_HIDDEN, + make(nullSignature, "__wasm_init_memory")); + } - if (config->isPic) { - // For PIC code we create a synthetic function __wasm_apply_relocs which - // is called from __wasm_call_ctors before the user-level constructors. - WasmSym::applyRelocs = symtab->addSyntheticFunction( - "__wasm_apply_relocs", WASM_SYMBOL_VISIBILITY_HIDDEN, - make(nullSignature, "__wasm_apply_relocs")); - } + if (config->isPic) { + // For PIC code we create a synthetic function __wasm_apply_relocs which + // is called from __wasm_call_ctors before the user-level constructors. + WasmSym::applyRelocs = symtab->addSyntheticFunction( + "__wasm_apply_relocs", WASM_SYMBOL_VISIBILITY_HIDDEN, + make(nullSignature, "__wasm_apply_relocs")); } - if (!config->shared) - WasmSym::dataEnd = symtab->addOptionalDataSymbol("__data_end"); if (config->isPic) { WasmSym::stackPointer = @@ -510,21 +511,9 @@ static void createSyntheticSymbols() { WasmSym::memoryBase->markLive(); WasmSym::tableBase->markLive(); } else { - llvm::wasm::WasmGlobal global; - global.Type = {WASM_TYPE_I32, true}; - global.InitExpr.Value.Int32 = 0; - global.InitExpr.Opcode = WASM_OPCODE_I32_CONST; - global.SymbolName = "__stack_pointer"; - auto *stackPointer = make(global, nullptr); - stackPointer->live = true; // For non-PIC code - // TODO(sbc): Remove WASM_SYMBOL_VISIBILITY_HIDDEN when the mutable global - // spec proposal is implemented in all major browsers. - // See: https://github.com/WebAssembly/mutable-global - WasmSym::stackPointer = symtab->addSyntheticGlobal( - "__stack_pointer", WASM_SYMBOL_VISIBILITY_HIDDEN, stackPointer); - WasmSym::globalBase = symtab->addOptionalDataSymbol("__global_base"); - WasmSym::heapBase = symtab->addOptionalDataSymbol("__heap_base"); + WasmSym::stackPointer = createGlobalVariable("__stack_pointer", true, 0); + WasmSym::stackPointer->markLive(); } if (config->sharedMemory && !config->shared) { @@ -535,9 +524,23 @@ static void createSyntheticSymbols() { "__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN, make(i32ArgSignature, "__wasm_init_tls")); } +} + +static void createOptionalSymbols() { + if (config->relocatable) + return; - WasmSym::dsoHandle = symtab->addSyntheticDataSymbol( - "__dso_handle", WASM_SYMBOL_VISIBILITY_HIDDEN); + WasmSym::dsoHandle = symtab->addOptionalDataSymbol("__dso_handle"); + + if (!config->shared) + WasmSym::dataEnd = symtab->addOptionalDataSymbol("__data_end"); + + if (!config->isPic) { + WasmSym::globalBase = symtab->addOptionalDataSymbol("__global_base"); + WasmSym::heapBase = symtab->addOptionalDataSymbol("__heap_base"); + WasmSym::definedMemoryBase = symtab->addOptionalDataSymbol("__memory_base"); + WasmSym::definedTableBase = symtab->addOptionalDataSymbol("__table_base"); + } } // Reconstructs command line arguments so that so that you can re-run @@ -706,8 +709,7 @@ void LinkerDriver::link(ArrayRef argsArr) { for (auto *arg : args.filtered(OPT_export)) config->exportedSymbols.insert(arg->getValue()); - if (!config->relocatable) - createSyntheticSymbols(); + createSyntheticSymbols(); createFiles(args); if (errorCount()) @@ -739,6 +741,8 @@ void LinkerDriver::link(ArrayRef argsArr) { config->entry); } + createOptionalSymbols(); + if (errorCount()) return; diff --git a/wasm/InputChunks.cpp b/wasm/InputChunks.cpp index d37b58a5d..9bd75df80 100644 --- a/wasm/InputChunks.cpp +++ b/wasm/InputChunks.cpp @@ -100,7 +100,7 @@ void InputChunk::writeTo(uint8_t *buf) const { verifyRelocTargets(); #endif - LLVM_DEBUG(dbgs() << "applying relocations: " << getName() + LLVM_DEBUG(dbgs() << "applying relocations: " << toString(this) << " count=" << relocations.size() << "\n"); int32_t off = outputOffset - getInputSectionOffset(); diff --git a/wasm/InputFiles.cpp b/wasm/InputFiles.cpp index 33ae3325c..6ec4b9dcd 100644 --- a/wasm/InputFiles.cpp +++ b/wasm/InputFiles.cpp @@ -166,7 +166,7 @@ uint32_t ObjFile::calcNewValue(const WasmRelocation &reloc) const { case R_WASM_TABLE_INDEX_I32: case R_WASM_TABLE_INDEX_SLEB: case R_WASM_TABLE_INDEX_REL_SLEB: - if (config->isPic && !getFunctionSymbol(reloc.Index)->hasTableIndex()) + if (!getFunctionSymbol(reloc.Index)->hasTableIndex()) return 0; return getFunctionSymbol(reloc.Index)->getTableIndex(); case R_WASM_MEMORY_ADDR_SLEB: diff --git a/wasm/LTO.cpp b/wasm/LTO.cpp index fa48f4db7..98584d94c 100644 --- a/wasm/LTO.cpp +++ b/wasm/LTO.cpp @@ -67,7 +67,7 @@ static std::unique_ptr createLTO() { lto::ThinBackend backend; if (config->thinLTOJobs != -1U) backend = lto::createInProcessThinBackend(config->thinLTOJobs); - return llvm::make_unique(std::move(c), backend, + return std::make_unique(std::move(c), backend, config->ltoPartitions); } @@ -105,6 +105,7 @@ void BitcodeCompiler::add(BitcodeFile &f) { // be removed. r.Prevailing = !objSym.isUndefined() && sym->getFile() == &f; r.VisibleToRegularObj = config->relocatable || sym->isUsedInRegularObj || + sym->isNoStrip() || (r.Prevailing && sym->isExported()); if (r.Prevailing) undefine(sym); @@ -137,8 +138,8 @@ std::vector BitcodeCompiler::compile() { checkError(ltoObj->run( [&](size_t task) { - return llvm::make_unique( - llvm::make_unique(buf[task])); + return std::make_unique( + std::make_unique(buf[task])); }, cache)); diff --git a/wasm/MarkLive.cpp b/wasm/MarkLive.cpp index 9399156b7..7656689ea 100644 --- a/wasm/MarkLive.cpp +++ b/wasm/MarkLive.cpp @@ -69,9 +69,9 @@ void lld::wasm::markLive() { if (!config->entry.empty()) enqueue(symtab->find(config->entry)); - // We need to preserve any exported symbol + // We need to preserve any no-strip or exported symbol for (Symbol *sym : symtab->getSymbols()) - if (sym->isExported()) + if (sym->isNoStrip() || sym->isExported()) enqueue(sym); // For relocatable output, we need to preserve all the ctor functions diff --git a/wasm/Options.td b/wasm/Options.td index 4bce790cd..45e3ef9c4 100644 --- a/wasm/Options.td +++ b/wasm/Options.td @@ -134,6 +134,9 @@ def export_all: F<"export-all">, def export_table: F<"export-table">, HelpText<"Export function table to the environment">; +def growable_table: F<"growable-table">, + HelpText<"Remove maximum size from function table, allowing table to grow">; + def global_base: J<"global-base=">, HelpText<"Where to start to place global data">; diff --git a/wasm/Relocations.cpp b/wasm/Relocations.cpp index e39f6987a..ed160a57e 100644 --- a/wasm/Relocations.cpp +++ b/wasm/Relocations.cpp @@ -40,6 +40,20 @@ static void reportUndefined(const Symbol* sym) { error(toString(sym->getFile()) + ": undefined symbol: " + toString(*sym)); } +static void addGOTEntry(Symbol *sym) { + // In PIC mode a GOT entry is an imported global that the dynamic linker + // will assign. + // In non-PIC mode (i.e. when code compiled as fPIC is linked into a static + // binary) we create an internal wasm global with a fixed value that takes the + // place of th GOT entry and effectivly acts as an i32 const. This can + // potentially be optimized away at runtime or with a post-link tool. + // TODO(sbc): Linker relaxation might also be able to optimize this away. + if (config->isPic) + out.importSec->addGOTEntry(sym); + else + out.globalSec->addDummyGOTEntry(sym); +} + void lld::wasm::scanRelocations(InputChunk *chunk) { if (!chunk->live) return; @@ -67,7 +81,7 @@ void lld::wasm::scanRelocations(InputChunk *chunk) { break; case R_WASM_GLOBAL_INDEX_LEB: if (!isa(sym)) - out.importSec->addGOTEntry(sym); + addGOTEntry(sym); break; } @@ -88,7 +102,7 @@ void lld::wasm::scanRelocations(InputChunk *chunk) { // will be converted into code by `generateRelocationCode`. This code // requires the symbols to have GOT entires. if (requiresGOTAccess(sym)) - out.importSec->addGOTEntry(sym); + addGOTEntry(sym); break; } } else { diff --git a/wasm/SymbolTable.cpp b/wasm/SymbolTable.cpp index b61812523..44417b076 100644 --- a/wasm/SymbolTable.cpp +++ b/wasm/SymbolTable.cpp @@ -205,15 +205,15 @@ DefinedFunction *SymbolTable::addSyntheticFunction(StringRef name, // Adds an optional, linker generated, data symbols. The symbol will only be // added if there is an undefine reference to it, or if it is explictly exported // via the --export flag. Otherwise we don't add the symbol and return nullptr. -DefinedData *SymbolTable::addOptionalDataSymbol(StringRef name, uint32_t value, - uint32_t flags) { +DefinedData *SymbolTable::addOptionalDataSymbol(StringRef name, + uint32_t value) { Symbol *s = find(name); if (!s && (config->exportAll || config->exportedSymbols.count(name) != 0)) s = insertName(name).first; else if (!s || s->isDefined()) return nullptr; LLVM_DEBUG(dbgs() << "addOptionalDataSymbol: " << name << "\n"); - auto *rtn = replaceSymbol(s, name, flags); + auto *rtn = replaceSymbol(s, name, WASM_SYMBOL_VISIBILITY_HIDDEN); rtn->setVirtualAddress(value); rtn->referenced = true; return rtn; @@ -425,9 +425,16 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef name, StringRef importName, } if (!existingFunction->signature && sig) existingFunction->signature = sig; - if (isCalledDirectly && !signatureMatches(existingFunction, sig)) - if (getFunctionVariant(s, sig, file, &s)) + if (isCalledDirectly && !signatureMatches(existingFunction, sig)) { + auto* existingUndefined = dyn_cast(existingFunction); + // If the existing undefined functions is not called direcltly then let + // this one take precedence. Otherwise the existing function is either + // direclty called or defined, in which case we need a function variant. + if (existingUndefined && !existingUndefined->isCalledDirectly) replaceSym(); + else if (getFunctionVariant(s, sig, file, &s)) + replaceSym(); + } } return s; diff --git a/wasm/SymbolTable.h b/wasm/SymbolTable.h index 530d5e864..622359b73 100644 --- a/wasm/SymbolTable.h +++ b/wasm/SymbolTable.h @@ -77,8 +77,7 @@ class SymbolTable { InputGlobal *global); DefinedFunction *addSyntheticFunction(StringRef name, uint32_t flags, InputFunction *function); - DefinedData *addOptionalDataSymbol(StringRef name, uint32_t value = 0, - uint32_t flags = 0); + DefinedData *addOptionalDataSymbol(StringRef name, uint32_t value = 0); void handleSymbolVariants(); void handleWeakUndefines(); diff --git a/wasm/Symbols.cpp b/wasm/Symbols.cpp index 05cf2efd9..b7a72d12b 100644 --- a/wasm/Symbols.cpp +++ b/wasm/Symbols.cpp @@ -37,7 +37,9 @@ GlobalSymbol *WasmSym::tlsBase; GlobalSymbol *WasmSym::tlsSize; GlobalSymbol *WasmSym::tlsAlign; UndefinedGlobal *WasmSym::tableBase; +DefinedData *WasmSym::definedTableBase; UndefinedGlobal *WasmSym::memoryBase; +DefinedData *WasmSym::definedMemoryBase; WasmSymbolType Symbol::getWasmType() const { if (isa(this)) @@ -111,9 +113,11 @@ void Symbol::setOutputSymbolIndex(uint32_t index) { void Symbol::setGOTIndex(uint32_t index) { LLVM_DEBUG(dbgs() << "setGOTIndex " << name << " -> " << index << "\n"); assert(gotIndex == INVALID_INDEX); - // Any symbol that is assigned a GOT entry must be exported othewise the - // dynamic linker won't be able create the entry that contains it. - forceExport = true; + if (config->isPic) { + // Any symbol that is assigned a GOT entry must be exported othewise the + // dynamic linker won't be able create the entry that contains it. + forceExport = true; + } gotIndex = index; } @@ -151,6 +155,10 @@ bool Symbol::isExported() const { return flags & WASM_SYMBOL_EXPORTED; } +bool Symbol::isNoStrip() const { + return flags & WASM_SYMBOL_NO_STRIP; +} + uint32_t FunctionSymbol::getFunctionIndex() const { if (auto *f = dyn_cast(this)) return f->function->getFunctionIndex(); diff --git a/wasm/Symbols.h b/wasm/Symbols.h index 83d3926eb..2ea25f550 100644 --- a/wasm/Symbols.h +++ b/wasm/Symbols.h @@ -107,6 +107,10 @@ class Symbol { WasmSymbolType getWasmType() const; bool isExported() const; + // Indicates that the symbol is used in an __attribute__((used)) directive + // or similar. + bool isNoStrip() const; + const WasmSignature* getSignature() const; bool isInGOT() const { return gotIndex != INVALID_INDEX; } @@ -472,10 +476,12 @@ struct WasmSym { // __table_base // Used in PIC code for offset of indirect function table static UndefinedGlobal *tableBase; + static DefinedData *definedTableBase; // __memory_base // Used in PIC code for offset of global data static UndefinedGlobal *memoryBase; + static DefinedData *definedMemoryBase; }; // A buffer class that is large enough to hold any Symbol-derived diff --git a/wasm/SyntheticSections.cpp b/wasm/SyntheticSections.cpp index 6d5d14ff4..2cbe56e65 100644 --- a/wasm/SyntheticSections.cpp +++ b/wasm/SyntheticSections.cpp @@ -103,6 +103,7 @@ uint32_t ImportSection::getNumImports() const { void ImportSection::addGOTEntry(Symbol *sym) { assert(!isSealed); + LLVM_DEBUG(dbgs() << "addGOTEntry: " << toString(*sym) << "\n"); if (sym->hasGOTIndex()) return; sym->setGOTIndex(numImportedGlobals++); @@ -142,7 +143,7 @@ void ImportSection::writeBody() { } if (config->importTable) { - uint32_t tableSize = out.elemSec->elemOffset + out.elemSec->numEntries(); + uint32_t tableSize = config->tableBase + out.elemSec->numEntries(); WasmImport import; import.Module = defaultModule; import.Field = functionTableName; @@ -211,11 +212,15 @@ void FunctionSection::addFunction(InputFunction *func) { } void TableSection::writeBody() { - uint32_t tableSize = out.elemSec->elemOffset + out.elemSec->numEntries(); + uint32_t tableSize = config->tableBase + out.elemSec->numEntries(); raw_ostream &os = bodyOutputStream; writeUleb128(os, 1, "table count"); - WasmLimits limits = {WASM_LIMITS_FLAG_HAS_MAX, tableSize, tableSize}; + WasmLimits limits; + if (config->growableTable) + limits = {0, tableSize, 0}; + else + limits = {WASM_LIMITS_FLAG_HAS_MAX, tableSize, tableSize}; writeTableType(os, WasmTable{WASM_TYPE_FUNCREF, limits}); } @@ -235,11 +240,26 @@ void MemorySection::writeBody() { writeUleb128(os, maxMemoryPages, "max pages"); } +void GlobalSection::assignIndexes() { + uint32_t globalIndex = out.importSec->getNumImportedGlobals(); + for (InputGlobal *g : inputGlobals) + g->setGlobalIndex(globalIndex++); + for (Symbol *sym : gotSymbols) + sym->setGOTIndex(globalIndex++); +} + +void GlobalSection::addDummyGOTEntry(Symbol *sym) { + LLVM_DEBUG(dbgs() << "addDummyGOTEntry: " << toString(*sym) << "\n"); + if (sym->hasGOTIndex()) + return; + gotSymbols.push_back(sym); +} + void GlobalSection::writeBody() { raw_ostream &os = bodyOutputStream; writeUleb128(os, numGlobals(), "global count"); - for (const InputGlobal *g : inputGlobals) + for (InputGlobal *g : inputGlobals) writeGlobal(os, g->global); for (const DefinedData *sym : definedFakeGlobals) { WasmGlobal global; @@ -248,16 +268,22 @@ void GlobalSection::writeBody() { global.InitExpr.Value.Int32 = sym->getVirtualAddress(); writeGlobal(os, global); } + for (const Symbol *sym : gotSymbols) { + WasmGlobal global; + global.Type = {WASM_TYPE_I32, false}; + global.InitExpr.Opcode = WASM_OPCODE_I32_CONST; + if (auto *d = dyn_cast(sym)) + global.InitExpr.Value.Int32 = d->getVirtualAddress(); + else if (auto *f = cast(sym)) + global.InitExpr.Value.Int32 = f->getTableIndex(); + writeGlobal(os, global); + } } void GlobalSection::addGlobal(InputGlobal *global) { if (!global->live) return; - uint32_t globalIndex = - out.importSec->getNumImportedGlobals() + inputGlobals.size(); - LLVM_DEBUG(dbgs() << "addGlobal: " << globalIndex << "\n"); - global->setGlobalIndex(globalIndex); - out.globalSec->inputGlobals.push_back(global); + inputGlobals.push_back(global); } void EventSection::writeBody() { @@ -291,7 +317,7 @@ void ExportSection::writeBody() { void ElemSection::addEntry(FunctionSymbol *sym) { if (sym->hasTableIndex()) return; - sym->setTableIndex(elemOffset + indirectFunctions.size()); + sym->setTableIndex(config->tableBase + indirectFunctions.size()); indirectFunctions.emplace_back(sym); } @@ -306,12 +332,12 @@ void ElemSection::writeBody() { initExpr.Value.Global = WasmSym::tableBase->getGlobalIndex(); } else { initExpr.Opcode = WASM_OPCODE_I32_CONST; - initExpr.Value.Int32 = elemOffset; + initExpr.Value.Int32 = config->tableBase; } writeInitExpr(os, initExpr); writeUleb128(os, indirectFunctions.size(), "elem count"); - uint32_t tableIndex = elemOffset; + uint32_t tableIndex = config->tableBase; for (const FunctionSymbol *sym : indirectFunctions) { assert(sym->getTableIndex() == tableIndex); writeUleb128(os, sym->getFunctionIndex(), "function index"); diff --git a/wasm/SyntheticSections.h b/wasm/SyntheticSections.h index 1d3b8b7a3..f4005b281 100644 --- a/wasm/SyntheticSections.h +++ b/wasm/SyntheticSections.h @@ -52,6 +52,8 @@ class SyntheticSection : public OutputSection { virtual void writeBody() {} + virtual void assignIndexes() {} + void finalizeContents() override { writeBody(); bodyOutputStream.flush(); @@ -173,14 +175,17 @@ class GlobalSection : public SyntheticSection { public: GlobalSection() : SyntheticSection(llvm::wasm::WASM_SEC_GLOBAL) {} uint32_t numGlobals() const { - return inputGlobals.size() + definedFakeGlobals.size(); + return inputGlobals.size() + definedFakeGlobals.size() + gotSymbols.size(); } bool isNeeded() const override { return numGlobals() > 0; } + void assignIndexes() override; void writeBody() override; void addGlobal(InputGlobal *global); + void addDummyGOTEntry(Symbol *sym); std::vector definedFakeGlobals; std::vector inputGlobals; + std::vector gotSymbols; }; // The event section contains a list of declared wasm events associated with the @@ -214,13 +219,12 @@ class ExportSection : public SyntheticSection { class ElemSection : public SyntheticSection { public: - ElemSection(uint32_t offset) - : SyntheticSection(llvm::wasm::WASM_SEC_ELEM), elemOffset(offset) {} + ElemSection() + : SyntheticSection(llvm::wasm::WASM_SEC_ELEM) {} bool isNeeded() const override { return indirectFunctions.size() > 0; }; void writeBody() override; void addEntry(FunctionSymbol *sym); uint32_t numEntries() const { return indirectFunctions.size(); } - uint32_t elemOffset; protected: std::vector indirectFunctions; diff --git a/wasm/Writer.cpp b/wasm/Writer.cpp index 2dbff1bc8..ba71da868 100644 --- a/wasm/Writer.cpp +++ b/wasm/Writer.cpp @@ -87,7 +87,6 @@ class Writer { void writeSections(); uint64_t fileSize = 0; - uint32_t tableBase = 0; std::vector initFunctions; llvm::StringMap> customSectionMapping; @@ -226,7 +225,9 @@ void Writer::layoutMemory() { } if (WasmSym::globalBase) - WasmSym::globalBase->setVirtualAddress(config->globalBase); + WasmSym::globalBase->setVirtualAddress(memoryPtr); + if (WasmSym::definedMemoryBase) + WasmSym::definedMemoryBase->setVirtualAddress(memoryPtr); uint32_t dataStart = memoryPtr; @@ -617,6 +618,8 @@ void Writer::assignIndexes() { for (InputEvent *event : file->events) out.eventSec->addEvent(event); } + + out.globalSec->assignIndexes(); } static StringRef getOutputDataSegmentName(StringRef name) { @@ -848,7 +851,7 @@ void Writer::createSyntheticSections() { out.globalSec = make(); out.eventSec = make(); out.exportSec = make(); - out.elemSec = make(tableBase); + out.elemSec = make(); out.dataCountSec = make(segments.size()); out.linkingSec = make(initFunctions, segments); out.nameSec = make(); @@ -862,8 +865,11 @@ void Writer::run() { // For PIC code the table base is assigned dynamically by the loader. // For non-PIC, we start at 1 so that accessing table index 0 always traps. - if (!config->isPic) - tableBase = 1; + if (!config->isPic) { + config->tableBase = 1; + if (WasmSym::definedTableBase) + WasmSym::definedTableBase->setVirtualAddress(config->tableBase); + } log("-- createOutputSegments"); createOutputSegments(); @@ -901,7 +907,7 @@ void Writer::run() { createCallCtorsFunction(); } - if (config->sharedMemory && !config->shared) + if (!config->relocatable && config->sharedMemory && !config->shared) createInitTLSFunction(); if (errorCount())