diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:08:33 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:08:33 +0000 |
commit | 20d35e67e67f106f617c939725101223211659f0 (patch) | |
tree | 64eb963cbf5ba58765e0a6b64a440965d66a7a4d /test/ELF | |
parent | ae1a339de31cf4065777531959a11e55a2e5fa00 (diff) |
Vendor import of lld trunk r338150:vendor/lld/lld-trunk-r338150
Notes
Notes:
svn path=/vendor/lld/dist/; revision=336821
svn path=/vendor/lld/lld-trunk-r338150/; revision=336822; tag=vendor/lld/lld-trunk-r338150
Diffstat (limited to 'test/ELF')
1045 files changed, 14663 insertions, 3789 deletions
diff --git a/test/ELF/Inputs/amdgpu-kernel-2.o b/test/ELF/Inputs/amdgpu-kernel-2.o Binary files differdeleted file mode 100644 index fa76151f8976..000000000000 --- a/test/ELF/Inputs/amdgpu-kernel-2.o +++ /dev/null diff --git a/test/ELF/Inputs/arm-long-thunk-converge.lds b/test/ELF/Inputs/arm-long-thunk-converge.lds new file mode 100644 index 000000000000..592d400c8dc6 --- /dev/null +++ b/test/ELF/Inputs/arm-long-thunk-converge.lds @@ -0,0 +1,4 @@ +SECTIONS { + .foo : { *(.foo) } + .bar 0x2000000 : { *(.bar) } +} diff --git a/test/ELF/Inputs/as-needed-lazy.s b/test/ELF/Inputs/as-needed-lazy.s new file mode 100644 index 000000000000..7f9c360dda20 --- /dev/null +++ b/test/ELF/Inputs/as-needed-lazy.s @@ -0,0 +1,3 @@ +.global foo +foo: + nop diff --git a/test/ELF/Inputs/comdat-discarded-reloc.s b/test/ELF/Inputs/comdat-discarded-reloc.s new file mode 100644 index 000000000000..9526f5ac95c0 --- /dev/null +++ b/test/ELF/Inputs/comdat-discarded-reloc.s @@ -0,0 +1,6 @@ +.section .text.bar1,"aG",@progbits,group,comdat + +.section .text.bar2 +.global bar +bar: + .quad .text.bar1 diff --git a/test/ELF/Inputs/compress-debug.s b/test/ELF/Inputs/compress-debug.s new file mode 100644 index 000000000000..5fd9d39a98a0 --- /dev/null +++ b/test/ELF/Inputs/compress-debug.s @@ -0,0 +1,5 @@ +.text +.fill 0x44 + +.section .debug_info,"",@progbits +.fill 0x43 diff --git a/test/ELF/Inputs/conflict-debug.s b/test/ELF/Inputs/conflict-debug.s index 03fb01331815..c38771efc20a 100644 --- a/test/ELF/Inputs/conflict-debug.s +++ b/test/ELF/Inputs/conflict-debug.s @@ -3,3 +3,24 @@ .loc 1 4 zed: 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/Inputs/copy-rel-version.s b/test/ELF/Inputs/copy-rel-version.s new file mode 100644 index 000000000000..36bb1ba54c9f --- /dev/null +++ b/test/ELF/Inputs/copy-rel-version.s @@ -0,0 +1,11 @@ +.data +.global foo@v1 +.type foo@v1, @object +.size foo@v1, 4 +.global foo@@v2 +.type foo@@v2, @object +.size foo@@v2, 8 +foo@v1: +foo@@v2: +.int 0 +.int 0 diff --git a/test/ELF/Inputs/copy-relocation-zero-abs-addr.s b/test/ELF/Inputs/copy-relocation-zero-abs-addr.s new file mode 100644 index 000000000000..da81e0372d8b --- /dev/null +++ b/test/ELF/Inputs/copy-relocation-zero-abs-addr.s @@ -0,0 +1,7 @@ +.globl ver1 +.globl ver2 + ver1 = 0x0 + ver2 = 0x0 + +.type foo,@object +.comm foo,16,16 diff --git a/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.s b/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.s new file mode 100644 index 000000000000..26ac7bed195b --- /dev/null +++ b/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.s @@ -0,0 +1,7 @@ +.balign 1024 +.type foo,@object +.globl foo +goo: +foo: + .long 0 + .size foo,4 diff --git a/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.script b/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.script new file mode 100644 index 000000000000..a5807231acd6 --- /dev/null +++ b/test/ELF/Inputs/copy-relocation-zero-nonabs-addr.script @@ -0,0 +1,3 @@ +SECTIONS { + goo = 0; +}; diff --git a/test/ELF/Inputs/eh-frame-pcrel-overflow.s b/test/ELF/Inputs/eh-frame-pcrel-overflow.s new file mode 100644 index 000000000000..7b3cff88b466 --- /dev/null +++ b/test/ELF/Inputs/eh-frame-pcrel-overflow.s @@ -0,0 +1,25 @@ +.text +.global foo +foo: + ret + +.section .eh_frame, "a" + .long 12 # Size + .long 0x00 # ID + .byte 0x01 # Version. + + .byte 0x52 # Augmentation string: 'R','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x00 # DW_EH_PE_absptr + + .byte 0xFF + + .long 12 # Size + .long 0x14 # ID + .quad foo + 0x90000000 diff --git a/test/ELF/Inputs/exclude-libs.ll b/test/ELF/Inputs/exclude-libs.ll new file mode 100644 index 000000000000..8bd947085f31 --- /dev/null +++ b/test/ELF/Inputs/exclude-libs.ll @@ -0,0 +1,3 @@ +@fn2 = global void()* null; + +target triple = "x86_64-unknown-linux" diff --git a/test/ELF/Inputs/exclude-libs.s b/test/ELF/Inputs/exclude-libs.s index 6d05c5e3aa91..eeacae6bccf2 100644 --- a/test/ELF/Inputs/exclude-libs.s +++ b/test/ELF/Inputs/exclude-libs.s @@ -1,3 +1,5 @@ .globl fn fn: nop + +.globl foo diff --git a/test/ELF/Inputs/far-long-arm-abs.s b/test/ELF/Inputs/far-long-arm-abs.s new file mode 100644 index 000000000000..10d9d0292eab --- /dev/null +++ b/test/ELF/Inputs/far-long-arm-abs.s @@ -0,0 +1,13 @@ +.global far +.type far,%function +far = 0x201001c + +.global too_far1 +.type too_far1,%function +too_far1 = 0x2020014 +.global too_far2 +.type too_far2,%function +too_far2 = 0x2020020 +.global too_far3 +.type too_far3,%function +too_far3 = 0x202002c diff --git a/test/ELF/Inputs/gdb-index.s b/test/ELF/Inputs/gdb-index.s index 907a66d350b0..794995c150f9 100644 --- a/test/ELF/Inputs/gdb-index.s +++ b/test/ELF/Inputs/gdb-index.s @@ -1,8 +1,8 @@ .text .Ltext0: -.globl main2 -.type main2, @function -main2: +.globl aaaaaaaaaaaaaaaa +.type aaaaaaaaaaaaaaaa, @function +aaaaaaaaaaaaaaaa: nop nop .Letext0: @@ -59,7 +59,7 @@ main2: .long 0x33 .long 0x18 .byte 0x30 -.string "main2" +.string "aaaaaaaaaaaaaaaa" .long 0 .section .debug_gnu_pubtypes,"",@progbits diff --git a/test/ELF/Inputs/hexagon.s b/test/ELF/Inputs/hexagon.s new file mode 100644 index 000000000000..921a0c409b57 --- /dev/null +++ b/test/ELF/Inputs/hexagon.s @@ -0,0 +1,6 @@ +.global _start +_start: + nop +.global foo +foo: + jumpr lr diff --git a/test/ELF/Inputs/hidden-shared-err.s b/test/ELF/Inputs/hidden-shared-err.s new file mode 100644 index 000000000000..ade79556db7b --- /dev/null +++ b/test/ELF/Inputs/hidden-shared-err.s @@ -0,0 +1,2 @@ +.global foo +foo: diff --git a/test/ELF/Inputs/hidden-shared-err2.s b/test/ELF/Inputs/hidden-shared-err2.s new file mode 100644 index 000000000000..aedd19d396fb --- /dev/null +++ b/test/ELF/Inputs/hidden-shared-err2.s @@ -0,0 +1 @@ +.quad foo diff --git a/test/ELF/Inputs/i386-pic-plt.s b/test/ELF/Inputs/i386-pic-plt.s new file mode 100644 index 000000000000..a7a812194fa3 --- /dev/null +++ b/test/ELF/Inputs/i386-pic-plt.s @@ -0,0 +1,4 @@ + .global foo + .type foo, @function +foo: + nop diff --git a/test/ELF/Inputs/icf-safe.s b/test/ELF/Inputs/icf-safe.s new file mode 100644 index 000000000000..02393f3bbda5 --- /dev/null +++ b/test/ELF/Inputs/icf-safe.s @@ -0,0 +1,9 @@ +.section .text.non_addrsig1,"ax",@progbits +.globl non_addrsig1 +non_addrsig1: +ret + +.section .text.non_addrsig2,"ax",@progbits +.globl non_addrsig2 +non_addrsig2: +ret diff --git a/test/ELF/Inputs/map-file2.s b/test/ELF/Inputs/map-file2.s index d46b06f7345a..b830bbc41d2e 100644 --- a/test/ELF/Inputs/map-file2.s +++ b/test/ELF/Inputs/map-file2.s @@ -1,5 +1,7 @@ foo: +.cfi_startproc nop +.cfi_endproc .global bar bar: nop diff --git a/test/ELF/Inputs/mips-64-got-load.s b/test/ELF/Inputs/mips-64-got-load.s new file mode 100644 index 000000000000..dffc6fb335c9 --- /dev/null +++ b/test/ELF/Inputs/mips-64-got-load.s @@ -0,0 +1,8 @@ + .text + .global foo1 +foo1: + ld $2, %got_disp(local1)($gp) + + .bss +local1: + .word 0 diff --git a/test/ELF/Inputs/mips-gp-dips-corrupt-ver.s b/test/ELF/Inputs/mips-gp-dips-corrupt-ver.s new file mode 100644 index 000000000000..42bd32a1e73a --- /dev/null +++ b/test/ELF/Inputs/mips-gp-dips-corrupt-ver.s @@ -0,0 +1,14 @@ +# Source file for mips-gp-dips-corrupt-ver.so +# +# % cat gpdisp.ver +# LLD_1.0.0 { global: foo; }; +# +# % as mips-gp-dips-corrupt-ver.s -o mips-gp-dips-corrupt-ver.o +# % ld -shared -o mips-gp-dips-corrupt-ver.so \ +# --version-script gpdisp.ver mips-gp-dips-corrupt-ver.o + + .global foo + .text +foo: + lui $t0, %hi(_gp_disp) + addi $t0, $t0, %lo(_gp_disp) diff --git a/test/ELF/Inputs/mips-gp-dips-corrupt-ver.so b/test/ELF/Inputs/mips-gp-dips-corrupt-ver.so Binary files differnew file mode 100755 index 000000000000..289ffa538f0c --- /dev/null +++ b/test/ELF/Inputs/mips-gp-dips-corrupt-ver.so diff --git a/test/ELF/Inputs/mips-mgot-1.s b/test/ELF/Inputs/mips-mgot-1.s new file mode 100644 index 000000000000..def6e5821154 --- /dev/null +++ b/test/ELF/Inputs/mips-mgot-1.s @@ -0,0 +1,10 @@ + .text + .global foo1 +foo1: + addiu $2, $2, %gottprel(tls0) # tls got entry + addiu $2, $2, %gottprel(tls1) # tls got entry + + .section .tdata,"awT",%progbits + .global tls1 +tls1: + .word 0 diff --git a/test/ELF/Inputs/mips-mgot-2.s b/test/ELF/Inputs/mips-mgot-2.s new file mode 100644 index 000000000000..4f6a92d36ffd --- /dev/null +++ b/test/ELF/Inputs/mips-mgot-2.s @@ -0,0 +1,17 @@ + .text + .global foo2 +foo2: + lw $2, %got(.data)($gp) # page entry + addi $2, $2, %lo(.data) + lw $2, %call16(foo0)($gp) # global entry + lw $2, %call16(foo2)($gp) # global entry + addiu $2, $2, %tlsgd(tls0) # tls gd entry + addiu $2, $2, %gottprel(tls0) # tls got entry + + .data + .space 0x20000 + + .section .tdata,"awT",%progbits + .global tls2 +tls2: + .word 0 diff --git a/test/ELF/Inputs/mips-micro-gp0-non-zero.o b/test/ELF/Inputs/mips-micro-gp0-non-zero.o Binary files differnew file mode 100644 index 000000000000..abd67bcd262a --- /dev/null +++ b/test/ELF/Inputs/mips-micro-gp0-non-zero.o diff --git a/test/ELF/Inputs/mips-n32-rels.o b/test/ELF/Inputs/mips-n32-rels.o Binary files differdeleted file mode 100644 index 88cbce699e6d..000000000000 --- a/test/ELF/Inputs/mips-n32-rels.o +++ /dev/null diff --git a/test/ELF/Inputs/mips-n64-gp0-non-zero.o b/test/ELF/Inputs/mips-n64-gp0-non-zero.o Binary files differnew file mode 100644 index 000000000000..43b930b9d9fd --- /dev/null +++ b/test/ELF/Inputs/mips-n64-gp0-non-zero.o diff --git a/test/ELF/Inputs/multiple-cu.s b/test/ELF/Inputs/multiple-cu.s new file mode 100644 index 000000000000..ff29d36a7e0a --- /dev/null +++ b/test/ELF/Inputs/multiple-cu.s @@ -0,0 +1,24 @@ + .file 1 "test2.c" + .loc 1 2 0 + jmp bar + + .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/Inputs/ppc64-func-global-entry.s b/test/ELF/Inputs/ppc64-func-global-entry.s new file mode 100644 index 000000000000..5987db6b5c53 --- /dev/null +++ b/test/ELF/Inputs/ppc64-func-global-entry.s @@ -0,0 +1,35 @@ + .text + .abiversion 2 + .globl foo_external_diff # -- Begin function foo_external_diff + .p2align 4 + .type foo_external_diff,@function +foo_external_diff: # @foo_external_diff +.Lfunc_begin0: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry foo_external_diff, .Lfunc_lep0-.Lfunc_gep0 +# %bb.0: # %entry + addis 5, 2, .LC0@toc@ha + add 3, 4, 3 + ld 5, .LC0@toc@l(5) + lwz 5, 0(5) + add 3, 3, 5 + extsw 3, 3 + blr + .long 0 + .quad 0 +.Lfunc_end0: + .size foo_external_diff, .Lfunc_end0-.Lfunc_begin0 + # -- End function + .section .toc,"aw",@progbits +.LC0: + .tc glob2[TC],glob2 + .type glob2,@object # @glob2 + .data + .globl glob2 + .p2align 2 +glob2: + .long 10 # 0xa + .size glob2, 4 diff --git a/test/ELF/Inputs/ppc64-func-local-entry.s b/test/ELF/Inputs/ppc64-func-local-entry.s new file mode 100644 index 000000000000..fc0a72df762d --- /dev/null +++ b/test/ELF/Inputs/ppc64-func-local-entry.s @@ -0,0 +1,16 @@ + .text + .abiversion 2 + .globl foo_external_same # -- Begin function foo_external_same + .p2align 4 + .type foo_external_same,@function +foo_external_same: # @foo_external_same +.Lfunc_begin0: +# %bb.0: # %entry + add 3, 4, 3 + extsw 3, 3 + blr + .long 0 + .quad 0 +.Lfunc_end0: + .size foo_external_same, .Lfunc_end0-.Lfunc_begin0 + # -- End function diff --git a/test/ELF/Inputs/ppc64-func.s b/test/ELF/Inputs/ppc64-func.s new file mode 100644 index 000000000000..745faf870e6b --- /dev/null +++ b/test/ELF/Inputs/ppc64-func.s @@ -0,0 +1,14 @@ + .text + .abiversion 2 + .globl foo_not_shared + .p2align 4 + .type foo_not_shared,@function + +foo_not_shared: +.Lfunc_begin0: + li 3, 55 + blr + .long 0 + .quad 0 +.Lfunc_end0: + .size foo_not_shared, .Lfunc_end0-.Lfunc_begin0 diff --git a/test/ELF/Inputs/ppc64-tls.s b/test/ELF/Inputs/ppc64-tls.s new file mode 100644 index 000000000000..11d1d1240962 --- /dev/null +++ b/test/ELF/Inputs/ppc64-tls.s @@ -0,0 +1,20 @@ + .text + .abiversion 2 + .type a,@object # @a + .type b,@object # @a + .type c,@object # @a + .section .tdata,"awT",@progbits + .globl a +a: + .long 10 # 0xa + .size a, 4 + + .globl b +b: + .long 10 # 0xa + .size b, 4 + + .globl c +c: + .long 10 # 0xa + .size c, 4 diff --git a/test/ELF/Inputs/print-icf.s b/test/ELF/Inputs/print-icf.s new file mode 100644 index 000000000000..df9bcbc0989d --- /dev/null +++ b/test/ELF/Inputs/print-icf.s @@ -0,0 +1,9 @@ +.section .text.f6, "ax" +f6: + mov $60, %rax + mov $42, %rdi + syscall + + .section .text.f7, "ax" +f7: + mov $0, %rax diff --git a/test/ELF/Inputs/protected-data-access.s b/test/ELF/Inputs/protected-data-access.s new file mode 100644 index 000000000000..50a1c461fd84 --- /dev/null +++ b/test/ELF/Inputs/protected-data-access.s @@ -0,0 +1,7 @@ + .section .rodata,"a" + .global foo + .protected foo + .type foo, @object + .size foo, 8 +foo: + .quad 42 diff --git a/test/ELF/Inputs/protected-function-access.s b/test/ELF/Inputs/protected-function-access.s new file mode 100644 index 000000000000..4dfffe512956 --- /dev/null +++ b/test/ELF/Inputs/protected-function-access.s @@ -0,0 +1,5 @@ + .global foo + .protected foo + .type foo, @function +foo: + ret diff --git a/test/ELF/Inputs/shared-ppc64.s b/test/ELF/Inputs/shared-ppc64.s index b0117ac42963..0e1ecf7ce849 100644 --- a/test/ELF/Inputs/shared-ppc64.s +++ b/test/ELF/Inputs/shared-ppc64.s @@ -1,9 +1,14 @@ -.section ".opd","aw" -.global bar -bar: -.quad .Lbar,.TOC.@tocbase,0 -.quad .Lbar,0,0 + .text + .abiversion 2 + .globl foo + .p2align 4 + .type foo,@function -.text -.Lbar: - blr +foo: +.Lfunc_begin0: + li 3, 55 + blr + .long 0 + .quad 0 +.Lfunc_end0: + .size foo, .Lfunc_end0-.Lfunc_begin0 diff --git a/test/ELF/Inputs/shlib-undefined-ref.s b/test/ELF/Inputs/shlib-undefined-ref.s new file mode 100644 index 000000000000..cfb7c60ebc01 --- /dev/null +++ b/test/ELF/Inputs/shlib-undefined-ref.s @@ -0,0 +1,4 @@ +.globl f +f: + call should_not_be_exported@PLT + ret diff --git a/test/ELF/Inputs/symbol-ordering-file-warnings1.s b/test/ELF/Inputs/symbol-ordering-file-warnings1.s new file mode 100644 index 000000000000..9250a6d42705 --- /dev/null +++ b/test/ELF/Inputs/symbol-ordering-file-warnings1.s @@ -0,0 +1,19 @@ +# This is a "bad" (absolute) instance of the symbol +multi = 1234 + +.text +.global shared +.type shared, @function +shared: + movq %rax, multi + ret + +.section .text.comdat,"axG",@progbits,comdat,comdat +.weak comdat +comdat: + ret + +.section .text.glob_or_wk,"ax",@progbits +.global glob_or_wk +glob_or_wk: + ret diff --git a/test/ELF/Inputs/symbol-ordering-file-warnings2.s b/test/ELF/Inputs/symbol-ordering-file-warnings2.s new file mode 100644 index 000000000000..4d914b240f17 --- /dev/null +++ b/test/ELF/Inputs/symbol-ordering-file-warnings2.s @@ -0,0 +1,6 @@ +.text +.global missing +missing: + callq undefined + # This is a "bad" (undefined) instance of the symbol + callq multi diff --git a/test/ELF/Inputs/undef-bad-debug.s b/test/ELF/Inputs/undef-bad-debug.s new file mode 100644 index 000000000000..e3e9f5edb9db --- /dev/null +++ b/test/ELF/Inputs/undef-bad-debug.s @@ -0,0 +1,134 @@ +.section .text,"ax" +sym: + .quad zed6 +sym2: + .quad zed7 + +.section .debug_line,"",@progbits +.Lunit: + .long .Lunit_end - .Lunit_start # unit length +.Lunit_start: + .short 4 # version + .long .Lprologue_end - .Lprologue_start # prologue length +.Lprologue_start: + .byte 1 # minimum instruction length + .byte 1 # maximum operatiosn per instruction + .byte 1 # default is_stmt + .byte -5 # line base + .byte 14 # line range + .byte 13 # opcode base + .byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # standard opcode lengths + .asciz "dir" # include directories + .byte 0 + .asciz "undef-bad-debug.s" # file names + .byte 1, 0, 0 + .byte 0 + .byte 0 # extraneous byte +.Lprologue_end: + .byte 0, 9, 2 # DW_LNE_set_address + .quad sym + .byte 3 # DW_LNS_advance_line + .byte 10 + .byte 1 # DW_LNS_copy + .byte 2 # DW_LNS_advance_pc + .byte 8 + .byte 0, 1, 1 # DW_LNE_end_sequence +.Lunit_end: + +.Lunit2: + .long .Lunit2_end - .Lunit2_start # unit length +.Lunit2_start: + .short 4 # version + .long .Lprologue2_end - .Lprologue2_start # prologue length +.Lprologue2_start: + .byte 1 # minimum instruction length + .byte 1 # maximum operatiosn per instruction + .byte 1 # default is_stmt + .byte -5 # line base + .byte 14 # line range + .byte 13 # opcode base + .byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # standard opcode lengths + .asciz "dir2" # include directories + .byte 0 + .asciz "undef-bad-debug2.s" # file names + .byte 1, 0, 0 + .byte 0 +.Lprologue2_end: + .byte 0, 9, 2 # DW_LNE_set_address + .quad sym2 + .byte 3 # DW_LNS_advance_line + .byte 10 + .byte 1 # DW_LNS_copy + .byte 2 # DW_LNS_advance_pc + .byte 8 + .byte 0, 1, 1 # DW_LNE_end_sequence + .byte 0, 9, 2 # DW_LNE_set_address + .quad 0x0badbeef + .byte 3 # DW_LNS_advance_line + .byte 99 + .byte 1 # DW_LNS_copy + .byte 99 # DW_LNS_advance_pc + .byte 119 + # Missing end of sequence. +.Lunit2_end: + +.section .debug_info,"",@progbits + .long .Lcu_end - .Lcu_start # Length of Unit +.Lcu_start: + .short 4 # DWARF version number + .long .Lsection_abbrev # Offset Into Abbrev. Section + .byte 8 # Address Size (in bytes) + .byte 1 # Abbrev [1] 0xb:0x79 DW_TAG_compile_unit + .long .Lunit # DW_AT_stmt_list + .byte 2 # Abbrev [2] 0x2a:0x15 DW_TAG_variable + .long .Linfo_string # DW_AT_name + # DW_AT_external + .byte 1 # DW_AT_decl_file + .byte 3 # DW_AT_decl_line + .byte 0 # End Of Children Mark +.Lcu_end: + + .long .Lcu2_end - .Lcu2_start # Length of Unit +.Lcu2_start: + .short 4 # DWARF version number + .long .Lsection_abbrev # Offset Into Abbrev. Section + .byte 8 # Address Size (in bytes) + .byte 1 # Abbrev [1] 0xb:0x79 DW_TAG_compile_unit + .long .Lunit2 # DW_AT_stmt_list + .byte 2 # Abbrev [2] 0x2a:0x15 DW_TAG_variable + .long .Linfo2_string # DW_AT_name + # DW_AT_external + .byte 1 # DW_AT_decl_file + .byte 3 # DW_AT_decl_line + .byte 0 # End Of Children Mark +.Lcu2_end: + +.section .debug_abbrev,"",@progbits +.Lsection_abbrev: + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 1 # DW_CHILDREN_yes + .byte 16 # DW_AT_stmt_list + .byte 23 # DW_FORM_sec_offset + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 2 # Abbreviation Code + .byte 52 # DW_TAG_variable + .byte 0 # DW_CHILDREN_no + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 63 # DW_AT_external + .byte 25 # DW_FORM_flag_present + .byte 58 # DW_AT_decl_file + .byte 11 # DW_FORM_data1 + .byte 59 # DW_AT_decl_line + .byte 11 # DW_FORM_data1 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) + +.section .debug_str,"MS",@progbits,1 +.Linfo_string: + .asciz "sym" +.Linfo2_string: + .asciz "sym2" diff --git a/test/ELF/Inputs/undef-debug.s b/test/ELF/Inputs/undef-debug.s index db8aaf16e6bd..46c1c92d2b1f 100644 --- a/test/ELF/Inputs/undef-debug.s +++ b/test/ELF/Inputs/undef-debug.s @@ -9,3 +9,24 @@ .section .text.2,"ax" .loc 1 11 .quad zed5 + + .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/Inputs/undef-shared2.s b/test/ELF/Inputs/undef-shared2.s new file mode 100644 index 000000000000..8742073726e5 --- /dev/null +++ b/test/ELF/Inputs/undef-shared2.s @@ -0,0 +1,2 @@ +.data +.quad foo diff --git a/test/ELF/Inputs/versiondef.s b/test/ELF/Inputs/versiondef.s new file mode 100644 index 000000000000..911cc146706f --- /dev/null +++ b/test/ELF/Inputs/versiondef.s @@ -0,0 +1,9 @@ +.text +.globl func_impl +func_impl: + ret +.globl func_impl2 +func_impl2: + ret +.symver func_impl, func@@VER2 +.symver func_impl2, func@VER diff --git a/test/ELF/Inputs/weak-and-strong-undef.s b/test/ELF/Inputs/weak-and-strong-undef.s deleted file mode 100644 index a5e476d43160..000000000000 --- a/test/ELF/Inputs/weak-and-strong-undef.s +++ /dev/null @@ -1 +0,0 @@ - .weak foo diff --git a/test/ELF/Inputs/x86-64-split-stack-main.s b/test/ELF/Inputs/x86-64-split-stack-main.s new file mode 100644 index 000000000000..3be9facf51e9 --- /dev/null +++ b/test/ELF/Inputs/x86-64-split-stack-main.s @@ -0,0 +1,16 @@ + .text + + .global non_split + .type non_split,@function +non_split: + retq + .size non_split,. - non_split + + .global non_function_text_symbol +non_function_text_symbol: + .byte 0x01 + .type non_function_text_symbol,@STT_OBJECT + .size non_function_text_symbol, 1 + + + .section .note.GNU-stack,"",@progbits diff --git a/test/ELF/Inputs/ztext-text-notext.s b/test/ELF/Inputs/ztext.s index f66b3ee1e29b..f66b3ee1e29b 100644 --- a/test/ELF/Inputs/ztext-text-notext.s +++ b/test/ELF/Inputs/ztext.s diff --git a/test/ELF/aarch64-call26-thunk.s b/test/ELF/aarch64-call26-thunk.s index 0fe99cec974d..067f6dbc2f7e 100644 --- a/test/ELF/aarch64-call26-thunk.s +++ b/test/ELF/aarch64-call26-thunk.s @@ -1,8 +1,8 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-pc-freebsd %S/Inputs/abs.s -o %tabs // RUN: llvm-mc -filetype=obj -triple=aarch64-pc-freebsd %s -o %t // RUN: ld.lld %t %tabs -o %t2 2>&1 // RUN: llvm-objdump -d -triple=aarch64-pc-freebsd %t2 | FileCheck %s -// REQUIRES: aarch64 .text .globl _start diff --git a/test/ELF/aarch64-condb-reloc.s b/test/ELF/aarch64-condb-reloc.s index 23c16c2db898..8a7581480544 100644 --- a/test/ELF/aarch64-condb-reloc.s +++ b/test/ELF/aarch64-condb-reloc.s @@ -1,3 +1,4 @@ +# REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %p/Inputs/aarch64-condb-reloc.s -o %t1 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t2 # RUN: ld.lld %t1 %t2 -o %t @@ -5,7 +6,6 @@ # RUN: ld.lld -shared %t1 %t2 -o %t3 # RUN: llvm-objdump -d %t3 | FileCheck -check-prefix=DSO %s # RUN: llvm-readobj -s -r %t3 | FileCheck -check-prefix=DSOREL %s -# REQUIRES: aarch64 # 0x11024 - 36 = 0x11000 # 0x11028 - 24 = 0x11010 diff --git a/test/ELF/aarch64-copy.s b/test/ELF/aarch64-copy.s index ffecf2f8a283..32e1c76df771 100644 --- a/test/ELF/aarch64-copy.s +++ b/test/ELF/aarch64-copy.s @@ -1,7 +1,7 @@ // 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/relocation-copy.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -shared %t2.o -soname fixed-length-string.so -o %t2.so // RUN: ld.lld %t.o %t2.so -o %t3 // RUN: llvm-readobj -s -r --expand-relocs -symbols %t3 | FileCheck %s // RUN: llvm-objdump -d %t3 | FileCheck -check-prefix=CODE %s @@ -90,4 +90,4 @@ _start: // RODATA: Contents of section .rodata: // S(z) = 0x40014 -// RODATA-NEXT: 101c8 14000400 +// RODATA-NEXT: 102e0 14000400 diff --git a/test/ELF/aarch64-cortex-a53-843419-address.s b/test/ELF/aarch64-cortex-a53-843419-address.s index e9f6ff4c38db..6c1f04d49fa1 100644 --- a/test/ELF/aarch64-cortex-a53-843419-address.s +++ b/test/ELF/aarch64-cortex-a53-843419-address.s @@ -4,7 +4,8 @@ // RUN: .text : { *(.text) *(.text.*) *(.newisd) } \ // RUN: .text2 : { *.(newos) } \ // RUN: .data : { *(.data) } }" > %t.script -// RUN: ld.lld --script %t.script -fix-cortex-a53-843419 -verbose %t.o -o %t2 | FileCheck -check-prefix=CHECK-PRINT %s +// RUN: ld.lld --script %t.script -fix-cortex-a53-843419 -verbose %t.o -o %t2 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-PRINT %s // RUN: llvm-objdump -triple=aarch64-linux-gnu -d %t2 | FileCheck %s // Test cases for Cortex-A53 Erratum 843419 that involve interactions diff --git a/test/ELF/aarch64-cortex-a53-843419-cli.s b/test/ELF/aarch64-cortex-a53-843419-cli.s index 30abc8f06d20..9c1d4858b3a7 100644 --- a/test/ELF/aarch64-cortex-a53-843419-cli.s +++ b/test/ELF/aarch64-cortex-a53-843419-cli.s @@ -1,6 +1,6 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -// RUN: not ld.lld %t -fix-cortex-a53-843419 -o %t2 2>&1 | FileCheck %s +// RUN: not ld.lld %t -fix-cortex-a53-843419 -o /dev/null 2>&1 | FileCheck %s // CHECK: --fix-cortex-a53-843419 is only supported on AArch64 targets. .globl entry diff --git a/test/ELF/aarch64-cortex-a53-843419-nopatch.s b/test/ELF/aarch64-cortex-a53-843419-nopatch.s index 389bf4505735..4f34ea26da7f 100644 --- a/test/ELF/aarch64-cortex-a53-843419-nopatch.s +++ b/test/ELF/aarch64-cortex-a53-843419-nopatch.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 -verbose -t %t.o -o %t2 | FileCheck %s +// RUN: ld.lld -fix-cortex-a53-843419 -verbose -t %t.o -o /dev/null | FileCheck %s // Test cases for Cortex-A53 Erratum 843419 that we don't expect to recognize // as needing a patch as one or more of the conditions isn't satisfied. // See ARM-EPM-048406 Cortex_A53_MPCore_Software_Developers_Errata_Notice.pdf diff --git a/test/ELF/aarch64-cortex-a53-843419-recognize.s b/test/ELF/aarch64-cortex-a53-843419-recognize.s index 3674dd2744da..174f18164bce 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 | FileCheck -check-prefix CHECK-PRINT %s +// RUN: ld.lld -fix-cortex-a53-843419 -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 -verbose %t.o -o %t3 +// RUN: ld.lld %t.o -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 @@ -30,7 +30,7 @@ // CHECK: t3_ff8_ldr: // CHECK-NEXT: 21ff8: e0 01 00 f0 adrp x0, #258048 // CHECK-NEXT: 21ffc: 21 00 40 f9 ldr x1, [x1] -// CHECK-FIX: 22000: 03 b8 00 14 b #188428 +// CHECK-FIX: 22000: 03 c8 00 14 b #204812 // CHECK-NOFIX: 22000: 00 00 40 f9 ldr x0, [x0] // CHECK-NEXT: 22004: c0 03 5f d6 ret .section .text.01, "ax", %progbits @@ -48,7 +48,7 @@ t3_ff8_ldr: // CHECK: t3_ff8_ldrsimd: // CHECK-NEXT: 23ff8: e0 01 00 b0 adrp x0, #249856 // CHECK-NEXT: 23ffc: 21 00 40 bd ldr s1, [x1] -// CHECK-FIX: 24000: 05 b0 00 14 b #180244 +// CHECK-FIX: 24000: 05 c0 00 14 b #196628 // CHECK-NOFIX: 24000: 02 04 40 f9 ldr x2, [x0, #8] // CHECK-NEXT: 24004: c0 03 5f d6 ret .section .text.02, "ax", %progbits @@ -66,7 +66,7 @@ t3_ff8_ldrsimd: // CHECK: t3_ffc_ldrpost: // CHECK-NEXT: 25ffc: c0 01 00 f0 adrp x0, #241664 // CHECK-NEXT: 26000: 21 84 40 bc ldr s1, [x1], #8 -// CHECK-FIX: 26004: 06 a8 00 14 b #172056 +// CHECK-FIX: 26004: 06 b8 00 14 b #188440 // CHECK-NOFIX: 26004: 03 08 40 f9 ldr x3, [x0, #16] // CHECK-NEXT: 26008: c0 03 5f d6 ret .section .text.03, "ax", %progbits @@ -84,7 +84,7 @@ t3_ffc_ldrpost: // CHECK: t3_ff8_strpre: // CHECK-NEXT: 27ff8: c0 01 00 b0 adrp x0, #233472 // CHECK-NEXT: 27ffc: 21 8c 00 bc str s1, [x1, #8]! -// CHECK-FIX: 28000: 09 a0 00 14 b #163876 +// CHECK-FIX: 28000: 09 b0 00 14 b #180260 // CHECK-NOFIX: 28000: 02 00 40 f9 ldr x2, [x0] // CHECK-NEXT: 28004: c0 03 5f d6 ret .section .text.04, "ax", %progbits @@ -102,7 +102,7 @@ t3_ff8_strpre: // CHECK: t3_ffc_str: // CHECK-NEXT: 29ffc: bc 01 00 f0 adrp x28, #225280 // CHECK-NEXT: 2a000: 42 00 00 f9 str x2, [x2] -// CHECK-FIX: 2a004: 0a 98 00 14 b #155688 +// CHECK-FIX: 2a004: 0a a8 00 14 b #172072 // CHECK-NOFIX: 2a004: 9c 07 00 f9 str x28, [x28, #8] // CHECK-NEXT: 2a008: c0 03 5f d6 ret .section .text.05, "ax", %progbits @@ -120,7 +120,7 @@ t3_ffc_str: // CHECK: t3_ffc_strsimd: // CHECK-NEXT: 2bffc: bc 01 00 b0 adrp x28, #217088 // CHECK-NEXT: 2c000: 44 00 00 b9 str w4, [x2] -// CHECK-FIX: 2c004: 0c 90 00 14 b #147504 +// CHECK-FIX: 2c004: 0c a0 00 14 b #163888 // CHECK-NOFIX: 2c004: 84 0b 00 f9 str x4, [x28, #16] // CHECK-NEXT: 2c008: c0 03 5f d6 ret .section .text.06, "ax", %progbits @@ -138,7 +138,7 @@ t3_ffc_strsimd: // CHECK: t3_ff8_ldrunpriv: // CHECK-NEXT: 2dff8: 9d 01 00 f0 adrp x29, #208896 // CHECK-NEXT: 2dffc: 41 08 40 38 ldtrb w1, [x2] -// CHECK-FIX: 2e000: 0f 88 00 14 b #139324 +// CHECK-FIX: 2e000: 0f 98 00 14 b #155708 // CHECK-NOFIX: 2e000: bd 03 40 f9 ldr x29, [x29] // CHECK-NEXT: 2e004: c0 03 5f d6 ret .section .text.07, "ax", %progbits @@ -156,7 +156,7 @@ t3_ff8_ldrunpriv: // CHECK: t3_ffc_ldur: // CHECK-NEXT: 2fffc: 9d 01 00 b0 adrp x29, #200704 // CHECK-NEXT: 30000: 42 40 40 b8 ldur w2, [x2, #4] -// CHECK-FIX: 30004: 10 80 00 14 b #131136 +// CHECK-FIX: 30004: 10 90 00 14 b #147520 // CHECK-NOFIX: 30004: bd 07 40 f9 ldr x29, [x29, #8] // CHECK-NEXT: 30008: c0 03 5f d6 ret .balign 4096 @@ -173,8 +173,8 @@ t3_ffc_ldur: // CHECK: t3_ffc_sturh: // CHECK-NEXT: 31ffc: 72 01 00 f0 adrp x18, #192512 // CHECK-NEXT: 32000: 43 40 00 78 sturh w3, [x2, #4] -// CHECK-FIX: 32004: 12 78 00 14 b #122952 -// CHECK-NOFIX: 32004: 41 0a 40 f9 ldr x1, [x18, #16] +// CHECK-FIX: 32004: 12 88 00 14 b #139336 +// CHECK-NOFIX: 32004: 41 0a 40 f9 ldr x1, [x18, #16] // CHECK-NEXT: 32008: c0 03 5f d6 ret .section .text.09, "ax", %progbits .balign 4096 @@ -191,7 +191,7 @@ t3_ffc_sturh: // CHECK: t3_ff8_literal: // CHECK-NEXT: 33ff8: 72 01 00 b0 adrp x18, #184320 // CHECK-NEXT: 33ffc: e3 ff ff 58 ldr x3, #-4 -// CHECK-FIX: 34000: 15 70 00 14 b #114772 +// CHECK-FIX: 34000: 15 80 00 14 b #131156 // CHECK-NOFIX: 34000: 52 02 40 f9 ldr x18, [x18] // CHECK-NEXT: 34004: c0 03 5f d6 ret .section .text.10, "ax", %progbits @@ -209,7 +209,7 @@ t3_ff8_literal: // CHECK: t3_ffc_register: // CHECK-NEXT: 35ffc: 4f 01 00 f0 adrp x15, #176128 // CHECK-NEXT: 36000: 43 68 61 f8 ldr x3, [x2, x1] -// CHECK-FIX: 36004: 16 68 00 14 b #106584 +// CHECK-FIX: 36004: 16 78 00 14 b #122968 // CHECK-NOFIX: 36004: ea 05 40 f9 ldr x10, [x15, #8] // CHECK-NEXT: 36008: c0 03 5f d6 ret .section .text.11, "ax", %progbits @@ -227,7 +227,7 @@ t3_ffc_register: // CHECK: t3_ff8_stp: // CHECK-NEXT: 37ff8: 50 01 00 b0 adrp x16, #167936 // CHECK-NEXT: 37ffc: 61 08 00 a9 stp x1, x2, [x3] -// CHECK-FIX: 38000: 19 60 00 14 b #98404 +// CHECK-FIX: 38000: 19 70 00 14 b #114788 // CHECK-NOFIX: 38000: 0d 0a 40 f9 ldr x13, [x16, #16] // CHECK-NEXT: 38004: c0 03 5f d6 ret .section .text.12, "ax", %progbits @@ -245,7 +245,7 @@ t3_ff8_stp: // CHECK: t3_ffc_stnp: // CHECK-NEXT: 39ffc: 27 01 00 f0 adrp x7, #159744 // CHECK-NEXT: 3a000: 61 08 00 a8 stnp x1, x2, [x3] -// CHECK-FIX: 3a004: 1a 58 00 14 b #90216 +// CHECK-FIX: 3a004: 1a 68 00 14 b #106600 // CHECK-NOFIX: 3a004: e9 00 40 f9 ldr x9, [x7] // CHECK-NEXT: 3a008: c0 03 5f d6 ret .section .text.13, "ax", %progbits @@ -262,8 +262,8 @@ t3_ffc_stnp: // CHECK-PRINT: detected cortex-a53-843419 erratum sequence starting at 3BFFC in unpatched output. // CHECK: t3_ffc_st1singlepost: // CHECK-NEXT: 3bffc: 37 01 00 b0 adrp x23, #151552 -// CHECK-NEXT: 3c000: 20 70 82 4c st1 { v0.16b }, [x1], x2 -// CHECK-FIX: 3c004: 1c 50 00 14 b #82032 +// CHECK-NEXT: 3c000: 20 04 82 0d st1 { v0.b }[1], [x1], x2 +// CHECK-FIX: 3c004: 1c 60 00 14 b #98416 // CHECK-NOFIX: 3c004: f6 06 40 f9 ldr x22, [x23, #8] // CHECK-NEXT: 3c008: c0 03 5f d6 ret .section .text.14, "ax", %progbits @@ -273,7 +273,7 @@ t3_ffc_stnp: .space 4096 - 4 t3_ffc_st1singlepost: adrp x23, dat2 - st1 { v0.16b }, [x1], x2 + st1 { v0.b }[1], [x1], x2 ldr x22, [x23, :lo12:dat2] ret @@ -281,7 +281,7 @@ t3_ffc_st1singlepost: // CHECK: t3_ff8_st1multiple: // CHECK-NEXT: 3dff8: 17 01 00 f0 adrp x23, #143360 // CHECK-NEXT: 3dffc: 20 a0 00 4c st1 { v0.16b, v1.16b }, [x1] -// CHECK-FIX: 3e000: 1f 48 00 14 b #73852 +// CHECK-FIX: 3e000: 1f 58 00 14 b #90236 // CHECK-NOFIX: 3e000: f8 0a 40 f9 ldr x24, [x23, #16] // CHECK-NEXT: 3e004: c0 03 5f d6 ret .section .text.15, "ax", %progbits @@ -300,7 +300,7 @@ t3_ff8_st1multiple: // CHECK-NEXT: 3fff8: 00 01 00 b0 adrp x0, #135168 // CHECK-NEXT: 3fffc: 21 00 40 f9 ldr x1, [x1] // CHECK-NEXT: 40000: 42 00 00 8b add x2, x2, x0 -// CHECK-FIX: 40004: 20 40 00 14 b #65664 +// CHECK-FIX: 40004: 20 50 00 14 b #82048 // CHECK-NOFIX: 40004: 02 00 40 f9 ldr x2, [x0] // CHECK-NEXT: 40008: c0 03 5f d6 ret .section .text.16, "ax", %progbits @@ -320,7 +320,7 @@ t4_ff8_ldr: // CHECK-NEXT: 41ffc: fc 00 00 f0 adrp x28, #126976 // CHECK-NEXT: 42000: 42 00 00 f9 str x2, [x2] // CHECK-NEXT: 42004: 20 00 02 cb sub x0, x1, x2 -// CHECK-FIX: 42008: 21 38 00 14 b #57476 +// CHECK-FIX: 42008: 21 48 00 14 b #73860 // CHECK-NOFIX: 42008: 9b 07 00 f9 str x27, [x28, #8] // CHECK-NEXT: 4200c: c0 03 5f d6 ret .section .text.17, "ax", %progbits @@ -340,7 +340,7 @@ t4_ffc_str: // CHECK-NEXT: 43ff8: f0 00 00 b0 adrp x16, #118784 // CHECK-NEXT: 43ffc: 61 08 00 a9 stp x1, x2, [x3] // CHECK-NEXT: 44000: 03 7e 10 9b mul x3, x16, x16 -// CHECK-FIX: 44004: 24 30 00 14 b #49296 +// CHECK-FIX: 44004: 24 40 00 14 b #65680 // CHECK-NOFIX: 44004: 0e 0a 40 f9 ldr x14, [x16, #16] // CHECK-NEXT: 44008: c0 03 5f d6 ret .section .text.18, "ax", %progbits @@ -360,7 +360,7 @@ t4_ff8_stp: // CHECK-NEXT: 45ff8: d0 00 00 f0 adrp x16, #110592 // CHECK-NEXT: 45ffc: 61 08 81 a9 stp x1, x2, [x3, #16]! // CHECK-NEXT: 46000: 03 7e 10 9b mul x3, x16, x16 -// CHECK-FIX: 46004: 26 28 00 14 b #41112 +// CHECK-FIX: 46004: 26 38 00 14 b #57496 // CHECK-NOFIX: 46004: 0e 06 40 f9 ldr x14, [x16, #8] // CHECK-NEXT: 46008: c0 03 5f d6 ret .section .text.19, "ax", %progbits @@ -380,7 +380,7 @@ t4_ff8_stppre: // CHECK-NEXT: 47ff8: d0 00 00 b0 adrp x16, #102400 // CHECK-NEXT: 47ffc: 61 08 81 a8 stp x1, x2, [x3], #16 // CHECK-NEXT: 48000: 03 7e 10 9b mul x3, x16, x16 -// CHECK-FIX: 48004: 28 20 00 14 b #32928 +// CHECK-FIX: 48004: 28 30 00 14 b #49312 // CHECK-NOFIX: 48004: 0e 06 40 f9 ldr x14, [x16, #8] // CHECK-NEXT: 48008: c0 03 5f d6 ret .section .text.20, "ax", %progbits @@ -400,7 +400,7 @@ t4_ff8_stppost: // CHECK-NEXT: 49ffc: b0 00 00 f0 adrp x16, #94208 // CHECK-NEXT: 4a000: 61 08 00 ad stp q1, q2, [x3] // CHECK-NEXT: 4a004: 03 7e 10 9b mul x3, x16, x16 -// CHECK-FIX: 4a008: 29 18 00 14 b #24740 +// CHECK-FIX: 4a008: 29 28 00 14 b #41124 // CHECK-NOFIX: 4a008: 0e 06 40 f9 ldr x14, [x16, #8] // CHECK-NEXT: 4a00c: c0 03 5f d6 ret .section .text.21, "ax", %progbits @@ -420,7 +420,7 @@ t4_ffc_stpsimd: // CHECK-NEXT: 4bffc: a7 00 00 b0 adrp x7, #86016 // CHECK-NEXT: 4c000: 61 08 00 a8 stnp x1, x2, [x3] // CHECK-NEXT: 4c004: 1f 20 03 d5 nop -// CHECK-FIX: 4c008: 2b 10 00 14 b #16556 +// CHECK-FIX: 4c008: 2b 20 00 14 b #32940 // CHECK-NOFIX: 4c008: ea 00 40 f9 ldr x10, [x7] // CHECK-NEXT: 4c00c: c0 03 5f d6 ret .section .text.22, "ax", %progbits @@ -438,9 +438,9 @@ t4_ffc_stnp: // CHECK-PRINT: detected cortex-a53-843419 erratum sequence starting at 4DFFC in unpatched output. // CHECK: t4_ffc_st1: // CHECK-NEXT: 4dffc: 98 00 00 f0 adrp x24, #77824 -// CHECK-NEXT: 4e000: 20 70 00 4c st1 { v0.16b }, [x1] +// CHECK-NEXT: 4e000: 20 80 00 4d st1 { v0.s }[2], [x1] // CHECK-NEXT: 4e004: f6 06 40 f9 ldr x22, [x23, #8] -// CHECK-FIX: 4e008: 2d 08 00 14 b #8372 +// CHECK-FIX: 4e008: 2d 18 00 14 b #24756 // CHECK-NOFIX: 4e008: 18 ff 3f f9 str x24, [x24, #32760] // CHECK-NEXT: 4e00c: c0 03 5f d6 ret .section .text.23, "ax", %progbits @@ -450,7 +450,7 @@ t4_ffc_stnp: .space 4096 - 4 t4_ffc_st1: adrp x24, dat2 - st1 { v0.16b }, [x1] + st1 { v0.s }[2], [x1] ldr x22, [x23, :got_lo12:dat2] str x24, [x24, #32760] ret @@ -459,7 +459,7 @@ t4_ffc_st1: // CHECK: t3_ff8_ldr_once: // CHECK-NEXT: 4fff8: 80 00 00 b0 adrp x0, #69632 // CHECK-NEXT: 4fffc: 20 70 82 4c st1 { v0.16b }, [x1], x2 -// CHECK-FIX: 50000: 31 00 00 14 b #196 +// CHECK-FIX: 50000: 31 10 00 14 b #16580 // CHECK-NOFIX: 50000: 01 08 40 f9 ldr x1, [x0, #16] // CHECK-NEXT: 50004: 02 08 40 f9 ldr x2, [x0, #16] // CHECK-NEXT: 50008: c0 03 5f d6 ret @@ -475,6 +475,46 @@ t3_ff8_ldr_once: ldr x2, [x0, #16] ret +// CHECK-PRINT: detected cortex-a53-843419 erratum sequence starting at 51FF8 in unpatched output. +// CHECK: t3_ff8_ldxr: +// CHECK-NEXT: 51ff8: 60 00 00 f0 adrp x0, #61440 +// CHECK-NEXT: 51ffc: 03 7c 5f c8 ldxr x3, [x0] +// CHECK-FIX: 52000: 33 08 00 14 b #8396 +// CHECK-NOFIX: 52000: 01 08 40 f9 ldr x1, [x0, #16] +// CHECK: 52004: 02 08 40 f9 ldr x2, [x0, #16] +// CHECK-NEXT: 52008: c0 03 5f d6 ret + .section .text.25, "ax", %progbits + .balign 4096 + .globl t3_ff8_ldxr + .type t3_ff8_ldxr, %function + .space 4096 - 8 +t3_ff8_ldxr: + adrp x0, dat3 + ldxr x3, [x0] + ldr x1, [x0, #16] + ldr x2, [x0, #16] + ret + +// CHECK-PRINT: detected cortex-a53-843419 erratum sequence starting at 53FF8 in unpatched output. +// CHECK: t3_ff8_stxr: +// CHECK-NEXT: 53ff8: 60 00 00 b0 adrp x0, #53248 +// CHECK-NEXT: 53ffc: 03 7c 04 c8 stxr w4, x3, [x0] +// CHECK-FIX: 54000: 35 00 00 14 b #212 +// CHECK-NOFIX: 54000: 01 08 40 f9 ldr x1, [x0, #16] +// CHECK: 54004: 02 08 40 f9 ldr x2, [x0, #16] +// CHECK-NEXT: 54008: c0 03 5f d6 ret + .section .text.26, "ax", %progbits + .balign 4096 + .globl t3_ff8_stxr + .type t3_ff8_stxr, %function + .space 4096 - 8 +t3_ff8_stxr: + adrp x0, dat3 + stxr w4, x3, [x0] + ldr x1, [x0, #16] + ldr x2, [x0, #16] + ret + .text .globl _start .type _start, %function @@ -482,78 +522,83 @@ _start: ret // CHECK-FIX: __CortexA53843419_22000: -// CHECK-FIX-NEXT: 5000c: 00 00 40 f9 ldr x0, [x0] -// CHECK-FIX-NEXT: 50010: fd 47 ff 17 b #-188428 +// CHECK-FIX-NEXT: 5400c: 00 00 40 f9 ldr x0, [x0] +// CHECK-FIX-NEXT: 54010: fd 37 ff 17 b #-204812 // CHECK-FIX: __CortexA53843419_24000: -// CHECK-FIX-NEXT: 50014: 02 04 40 f9 ldr x2, [x0, #8] -// CHECK-FIX-NEXT: 50018: fb 4f ff 17 b #-180244 +// CHECK-FIX-NEXT: 54014: 02 04 40 f9 ldr x2, [x0, #8] +// CHECK-FIX-NEXT: 54018: fb 3f ff 17 b #-196628 // CHECK-FIX: __CortexA53843419_26004: -// CHECK-FIX-NEXT: 5001c: 03 08 40 f9 ldr x3, [x0, #16] -// CHECK-FIX-NEXT: 50020: fa 57 ff 17 b #-172056 +// CHECK-FIX-NEXT: 5401c: 03 08 40 f9 ldr x3, [x0, #16] +// CHECK-FIX-NEXT: 54020: fa 47 ff 17 b #-188440 // CHECK-FIX: __CortexA53843419_28000: -// CHECK-FIX-NEXT: 50024: 02 00 40 f9 ldr x2, [x0] -// CHECK-FIX-NEXT: 50028: f7 5f ff 17 b #-163876 +// CHECK-FIX-NEXT: 54024: 02 00 40 f9 ldr x2, [x0] +// CHECK-FIX-NEXT: 54028: f7 4f ff 17 b #-180260 // CHECK-FIX: __CortexA53843419_2A004: -// CHECK-FIX-NEXT: 5002c: 9c 07 00 f9 str x28, [x28, #8] -// CHECK-FIX-NEXT: 50030: f6 67 ff 17 b #-155688 +// CHECK-FIX-NEXT: 5402c: 9c 07 00 f9 str x28, [x28, #8] +// CHECK-FIX-NEXT: 54030: f6 57 ff 17 b #-172072 // CHECK-FIX: __CortexA53843419_2C004: -// CHECK-FIX-NEXT: 50034: 84 0b 00 f9 str x4, [x28, #16] -// CHECK-FIX-NEXT: 50038: f4 6f ff 17 b #-147504 +// CHECK-FIX-NEXT: 54034: 84 0b 00 f9 str x4, [x28, #16] +// CHECK-FIX-NEXT: 54038: f4 5f ff 17 b #-163888 // CHECK-FIX: __CortexA53843419_2E000: -// CHECK-FIX-NEXT: 5003c: bd 03 40 f9 ldr x29, [x29] -// CHECK-FIX-NEXT: 50040: f1 77 ff 17 b #-139324 +// CHECK-FIX-NEXT: 5403c: bd 03 40 f9 ldr x29, [x29] +// CHECK-FIX-NEXT: 54040: f1 67 ff 17 b #-155708 // CHECK-FIX: __CortexA53843419_30004: -// CHECK-FIX-NEXT: 50044: bd 07 40 f9 ldr x29, [x29, #8] -// CHECK-FIX-NEXT: 50048: f0 7f ff 17 b #-131136 +// CHECK-FIX-NEXT: 54044: bd 07 40 f9 ldr x29, [x29, #8] +// CHECK-FIX-NEXT: 54048: f0 6f ff 17 b #-147520 // CHECK-FIX: __CortexA53843419_32004: -// CHECK-FIX-NEXT: 5004c: 41 0a 40 f9 ldr x1, [x18, #16] -// CHECK-FIX-NEXT: 50050: ee 87 ff 17 b #-122952 +// CHECK-FIX-NEXT: 5404c: 41 0a 40 f9 ldr x1, [x18, #16] +// CHECK-FIX-NEXT: 54050: ee 77 ff 17 b #-139336 // CHECK-FIX: __CortexA53843419_34000: -// CHECK-FIX-NEXT: 50054: 52 02 40 f9 ldr x18, [x18] -// CHECK-FIX-NEXT: 50058: eb 8f ff 17 b #-114772 +// CHECK-FIX-NEXT: 54054: 52 02 40 f9 ldr x18, [x18] +// CHECK-FIX-NEXT: 54058: eb 7f ff 17 b #-131156 // CHECK-FIX: __CortexA53843419_36004: -// CHECK-FIX-NEXT: 5005c: ea 05 40 f9 ldr x10, [x15, #8] -// CHECK-FIX-NEXT: 50060: ea 97 ff 17 b #-106584 +// CHECK-FIX-NEXT: 5405c: ea 05 40 f9 ldr x10, [x15, #8] +// CHECK-FIX-NEXT: 54060: ea 87 ff 17 b #-122968 // CHECK-FIX: __CortexA53843419_38000: -// CHECK-FIX-NEXT: 50064: 0d 0a 40 f9 ldr x13, [x16, #16] -// CHECK-FIX-NEXT: 50068: e7 9f ff 17 b #-98404 +// CHECK-FIX-NEXT: 54064: 0d 0a 40 f9 ldr x13, [x16, #16] +// CHECK-FIX-NEXT: 54068: e7 8f ff 17 b #-114788 // CHECK-FIX: __CortexA53843419_3A004: -// CHECK-FIX-NEXT: 5006c: e9 00 40 f9 ldr x9, [x7] -// CHECK-FIX-NEXT: 50070: e6 a7 ff 17 b #-90216 +// CHECK-FIX-NEXT: 5406c: e9 00 40 f9 ldr x9, [x7] +// CHECK-FIX-NEXT: 54070: e6 97 ff 17 b #-106600 // CHECK-FIX: __CortexA53843419_3C004: -// CHECK-FIX-NEXT: 50074: f6 06 40 f9 ldr x22, [x23, #8] -// CHECK-FIX-NEXT: 50078: e4 af ff 17 b #-82032 +// CHECK-FIX-NEXT: 54074: f6 06 40 f9 ldr x22, [x23, #8] +// CHECK-FIX-NEXT: 54078: e4 9f ff 17 b #-98416 // CHECK-FIX: __CortexA53843419_3E000: -// CHECK-FIX-NEXT: 5007c: f8 0a 40 f9 ldr x24, [x23, #16] -// CHECK-FIX-NEXT: 50080: e1 b7 ff 17 b #-73852 +// CHECK-FIX-NEXT: 5407c: f8 0a 40 f9 ldr x24, [x23, #16] +// CHECK-FIX-NEXT: 54080: e1 a7 ff 17 b #-90236 // CHECK-FIX: __CortexA53843419_40004: -// CHECK-FIX-NEXT: 50084: 02 00 40 f9 ldr x2, [x0] -// CHECK-FIX-NEXT: 50088: e0 bf ff 17 b #-65664 +// CHECK-FIX-NEXT: 54084: 02 00 40 f9 ldr x2, [x0] +// CHECK-FIX-NEXT: 54088: e0 af ff 17 b #-82048 // CHECK-FIX: __CortexA53843419_42008: -// CHECK-FIX-NEXT: 5008c: 9b 07 00 f9 str x27, [x28, #8] -// CHECK-FIX-NEXT: 50090: df c7 ff 17 b #-57476 +// CHECK-FIX-NEXT: 5408c: 9b 07 00 f9 str x27, [x28, #8] +// CHECK-FIX-NEXT: 54090: df b7 ff 17 b #-73860 // CHECK-FIX: __CortexA53843419_44004: -// CHECK-FIX-NEXT: 50094: 0e 0a 40 f9 ldr x14, [x16, #16] -// CHECK-FIX-NEXT: 50098: dc cf ff 17 b #-49296 +// CHECK-FIX-NEXT: 54094: 0e 0a 40 f9 ldr x14, [x16, #16] +// CHECK-FIX-NEXT: 54098: dc bf ff 17 b #-65680 // CHECK-FIX: __CortexA53843419_46004: -// CHECK-FIX-NEXT: 5009c: 0e 06 40 f9 ldr x14, [x16, #8] -// CHECK-FIX-NEXT: 500a0: da d7 ff 17 b #-41112 +// CHECK-FIX-NEXT: 5409c: 0e 06 40 f9 ldr x14, [x16, #8] +// CHECK-FIX-NEXT: 540a0: da c7 ff 17 b #-57496 // CHECK-FIX: __CortexA53843419_48004: -// CHECK-FIX-NEXT: 500a4: 0e 06 40 f9 ldr x14, [x16, #8] -// CHECK-FIX-NEXT: 500a8: d8 df ff 17 b #-32928 +// CHECK-FIX-NEXT: 540a4: 0e 06 40 f9 ldr x14, [x16, #8] +// CHECK-FIX-NEXT: 540a8: d8 cf ff 17 b #-49312 // CHECK-FIX: __CortexA53843419_4A008: -// CHECK-FIX-NEXT: 500ac: 0e 06 40 f9 ldr x14, [x16, #8] -// CHECK-FIX-NEXT: 500b0: d7 e7 ff 17 b #-24740 +// CHECK-FIX-NEXT: 540ac: 0e 06 40 f9 ldr x14, [x16, #8] +// CHECK-FIX-NEXT: 540b0: d7 d7 ff 17 b #-41124 // CHECK-FIX: __CortexA53843419_4C008: -// CHECK-FIX-NEXT: 500b4: ea 00 40 f9 ldr x10, [x7] -// CHECK-FIX-NEXT: 500b8: d5 ef ff 17 b #-16556 +// CHECK-FIX-NEXT: 540b4: ea 00 40 f9 ldr x10, [x7] +// CHECK-FIX-NEXT: 540b8: d5 df ff 17 b #-32940 // CHECK-FIX: __CortexA53843419_4E008: -// CHECK-FIX-NEXT: 500bc: 18 ff 3f f9 str x24, [x24, #32760] -// CHECK-FIX-NEXT: 500c0: d3 f7 ff 17 b #-8372 +// CHECK-FIX-NEXT: 540bc: 18 ff 3f f9 str x24, [x24, #32760] +// CHECK-FIX-NEXT: 540c0: d3 e7 ff 17 b #-24756 // CHECK-FIX: __CortexA53843419_50000: -// CHECK-FIX-NEXT: 500c4: 01 08 40 f9 ldr x1, [x0, #16] -// CHECK-FIX-NEXT: 500c8: cf ff ff 17 b #-196 - +// CHECK-FIX-NEXT: 540c4: 01 08 40 f9 ldr x1, [x0, #16] +// CHECK-FIX-NEXT: 540c8: cf ef ff 17 b #-16580 +// CHECK-FIX: __CortexA53843419_52000: +// CHECK-FIX-NEXT: 540cc: 01 08 40 f9 ldr x1, [x0, #16] +// CHECK-FIX-NEXT: 540d0: cd f7 ff 17 b #-8396 +// CHECK-FIX: __CortexA53843419_54000: +// CHECK-FIX-NEXT: 540d4: 01 08 40 f9 ldr x1, [x0, #16] +// CHECK-FIX-NEXT: 540d8: cb ff ff 17 b #-212 .data .globl dat .globl dat2 diff --git a/test/ELF/aarch64-cortex-a53-843419-thunk.s b/test/ELF/aarch64-cortex-a53-843419-thunk.s index 4568095a2fa7..c802f3f605f1 100644 --- a/test/ELF/aarch64-cortex-a53-843419-thunk.s +++ b/test/ELF/aarch64-cortex-a53-843419-thunk.s @@ -3,7 +3,8 @@ // RUN: echo "SECTIONS { \ // RUN: .text1 0x10000 : { *(.text.01) *(.text.02) *(.text.03) } \ // RUN: .text2 0x8010000 : { *(.text.04) } } " > %t.script -// RUN: ld.lld --script %t.script -fix-cortex-a53-843419 -verbose %t.o -o %t2 | FileCheck -check-prefix=CHECK-PRINT %s +// RUN: ld.lld --script %t.script -fix-cortex-a53-843419 -verbose %t.o -o %t2 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-PRINT %s // RUN: llvm-objdump -triple=aarch64-linux-gnu -d %t2 | FileCheck %s // %t2 is 128 Megabytes, so delete it early. diff --git a/test/ELF/aarch64-data-relocs.s b/test/ELF/aarch64-data-relocs.s index 19e11bc3925c..d32871543bf6 100644 --- a/test/ELF/aarch64-data-relocs.s +++ b/test/ELF/aarch64-data-relocs.s @@ -1,8 +1,8 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %S/Inputs/abs256.s -o %t256.o // RUN: ld.lld %t %t256.o -o %t2 // RUN: llvm-objdump -s %t2 | FileCheck %s -// REQUIRES: aarch64 .globl _start _start: diff --git a/test/ELF/aarch64-fpic-abs16.s b/test/ELF/aarch64-fpic-abs16.s index 2b14b11c75db..c180939b7cac 100644 --- a/test/ELF/aarch64-fpic-abs16.s +++ b/test/ELF/aarch64-fpic-abs16.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: relocation R_AARCH64_ABS16 cannot be used against shared object; recompile with -fPIC +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +// CHECK: relocation R_AARCH64_ABS16 cannot be used against symbol foo; recompile with -fPIC // CHECK-NEXT: >>> defined in {{.*}}.o // CHECK-NEXT: >>> referenced by {{.*}}.o:(.data+0x0) diff --git a/test/ELF/aarch64-fpic-add_abs_lo12_nc.s b/test/ELF/aarch64-fpic-add_abs_lo12_nc.s index 9e13fd18af46..fc58e06b3db3 100644 --- a/test/ELF/aarch64-fpic-add_abs_lo12_nc.s +++ b/test/ELF/aarch64-fpic-add_abs_lo12_nc.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_ADD_ABS_LO12_NC against symbol: dat +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +// CHECK: can't create dynamic relocation R_AARCH64_ADD_ABS_LO12_NC against symbol: dat in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output // CHECK: >>> defined in {{.*}}.o // CHECK: >>> referenced by {{.*}}.o:(.text+0x0) diff --git a/test/ELF/aarch64-fpic-adr_prel_lo21.s b/test/ELF/aarch64-fpic-adr_prel_lo21.s index c1e6bc6359bd..4b6f43f1f226 100644 --- a/test/ELF/aarch64-fpic-adr_prel_lo21.s +++ b/test/ELF/aarch64-fpic-adr_prel_lo21.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_ADR_PREL_LO21 against symbol: dat +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +// CHECK: relocation R_AARCH64_ADR_PREL_LO21 cannot be used against symbol dat; recompile with -fPIC // CHECK: >>> defined in {{.*}}.o // CHECK: >>> referenced by {{.*}}.o:(.text+0x0) diff --git a/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s b/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s index e27867b85242..651a32e56868 100644 --- a/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s +++ b/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol: dat +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +// CHECK: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol dat; recompile with -fPIC // CHECK: >>> defined in {{.*}}.o // CHECK: >>> referenced by {{.*}}.o:(.text+0x0) diff --git a/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s b/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s index 02b75a5bfcde..b68b9f23e4ca 100644 --- a/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s +++ b/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_LDST32_ABS_LO12_NC against symbol: dat +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +// CHECK: can't create dynamic relocation R_AARCH64_LDST32_ABS_LO12_NC against symbol: dat in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output // CHECK: >>> defined in {{.*}}.o // CHECK: >>> referenced by {{.*}}.o:(.text+0x0) diff --git a/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s b/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s index 45e4f2032c19..1d5b9439f0f4 100644 --- a/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s +++ b/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_LDST64_ABS_LO12_NC against symbol: dat +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +// CHECK: can't create dynamic relocation R_AARCH64_LDST64_ABS_LO12_NC against symbol: dat in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output // CHECK: >>> defined in {{.*}}.o // CHECK: >>> referenced by {{.*}}.o:(.text+0x0) diff --git a/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s b/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s index 16e7df1bc4a1..a3f8243a080c 100644 --- a/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s +++ b/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_AARCH64_LDST8_ABS_LO12_NC against symbol: dat +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +// CHECK: can't create dynamic relocation R_AARCH64_LDST8_ABS_LO12_NC against symbol: dat in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output // CHECK: >>> defined in {{.*}}.o // CHECK: >>> referenced by {{.*}}.o:(.text+0x0) diff --git a/test/ELF/aarch64-fpic-prel16.s b/test/ELF/aarch64-fpic-prel16.s index 1faef9f866e0..1de7f6f63370 100644 --- a/test/ELF/aarch64-fpic-prel16.s +++ b/test/ELF/aarch64-fpic-prel16.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: R_AARCH64_PREL16 cannot be used against shared object; recompile with -fPIC +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +// CHECK: R_AARCH64_PREL16 cannot be used against symbol foo; recompile with -fPIC // CHECK: >>> defined in {{.*}} // CHECK: >>> referenced by {{.*}}:(.data+0x0) diff --git a/test/ELF/aarch64-fpic-prel32.s b/test/ELF/aarch64-fpic-prel32.s index b797dca2f2c4..0988b26a2b91 100644 --- a/test/ELF/aarch64-fpic-prel32.s +++ b/test/ELF/aarch64-fpic-prel32.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: relocation R_AARCH64_PREL32 cannot be used against shared object; recompile with -fPIC +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +// CHECK: relocation R_AARCH64_PREL32 cannot be used against symbol foo; recompile with -fPIC // CHECK: >>> defined in {{.*}} // CHECK: >>> referenced by {{.*}}:(.data+0x0) diff --git a/test/ELF/aarch64-fpic-prel64.s b/test/ELF/aarch64-fpic-prel64.s index 4c67837eac78..653f54220334 100644 --- a/test/ELF/aarch64-fpic-prel64.s +++ b/test/ELF/aarch64-fpic-prel64.s @@ -1,7 +1,7 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s -// CHECK: relocation R_AARCH64_PREL64 cannot be used against shared object; recompile with -fPIC +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s +// CHECK: relocation R_AARCH64_PREL64 cannot be used against symbol foo; recompile with -fPIC // CHECK: >>> defined in {{.*}} // CHECK: >>> referenced by {{.*}}:(.data+0x0) diff --git a/test/ELF/aarch64-gnu-ifunc-nosym.s b/test/ELF/aarch64-gnu-ifunc-nosym.s index bb3a0b8b5116..aa0124aa3fa2 100644 --- a/test/ELF/aarch64-gnu-ifunc-nosym.s +++ b/test/ELF/aarch64-gnu-ifunc-nosym.s @@ -1,7 +1,7 @@ +// 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-readobj -symbols %tout | FileCheck %s -// REQUIRES: aarch64 // Check that no __rela_iplt_end/__rela_iplt_start // appear in symtab if there is no references to them. diff --git a/test/ELF/aarch64-gnu-ifunc-plt.s b/test/ELF/aarch64-gnu-ifunc-plt.s index 5138675676d3..ca30316c7afe 100644 --- a/test/ELF/aarch64-gnu-ifunc-plt.s +++ b/test/ELF/aarch64-gnu-ifunc-plt.s @@ -1,3 +1,4 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %S/Inputs/shared2.s -o %t1.o // RUN: ld.lld %t1.o --shared -o %t.so // RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o @@ -5,7 +6,6 @@ // RUN: llvm-objdump -d %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 -// REQUIRES: aarch64 // Check that the IRELATIVE relocations are after the JUMP_SLOT in the plt // CHECK: Relocations [ diff --git a/test/ELF/aarch64-gnu-ifunc.s b/test/ELF/aarch64-gnu-ifunc.s index 4e0dc328025d..b3c1571b7604 100644 --- a/test/ELF/aarch64-gnu-ifunc.s +++ b/test/ELF/aarch64-gnu-ifunc.s @@ -1,8 +1,8 @@ +// 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-readobj -r -symbols -sections %tout | FileCheck %s -// REQUIRES: aarch64 // CHECK: Sections [ // CHECK: Section { diff --git a/test/ELF/aarch64-hi21-error.s b/test/ELF/aarch64-hi21-error.s index 9e2b283ea118..07f9e04953b0 100644 --- a/test/ELF/aarch64-hi21-error.s +++ b/test/ELF/aarch64-hi21-error.s @@ -1,7 +1,7 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-pc-freebsd %S/Inputs/abs.s -o %tabs // RUN: llvm-mc -filetype=obj -triple=aarch64-pc-freebsd %s -o %t -// RUN: not ld.lld %tabs %t -o %t2 2>&1 | FileCheck %s -// REQUIRES: aarch64 +// RUN: not ld.lld %tabs %t -o /dev/null 2>&1 | FileCheck %s .globl _start _start: diff --git a/test/ELF/aarch64-jump26-thunk.s b/test/ELF/aarch64-jump26-thunk.s index 088ab3a9e1a5..13c084a0c78e 100644 --- a/test/ELF/aarch64-jump26-thunk.s +++ b/test/ELF/aarch64-jump26-thunk.s @@ -1,8 +1,8 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-pc-freebsd %S/Inputs/abs.s -o %tabs // RUN: llvm-mc -filetype=obj -triple=aarch64-pc-freebsd %s -o %t // RUN: ld.lld %t %tabs -o %t2 2>&1 // RUN: llvm-objdump -d -triple=aarch64-pc-freebsd %t2 | FileCheck %s -// REQUIRES: aarch64 .text .globl _start diff --git a/test/ELF/aarch64-ldprel-lo19-invalid.s b/test/ELF/aarch64-ldprel-lo19-invalid.s index 04df32e05904..cf38b2c84fd0 100644 --- a/test/ELF/aarch64-ldprel-lo19-invalid.s +++ b/test/ELF/aarch64-ldprel-lo19-invalid.s @@ -1,7 +1,7 @@ # REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-none %s -o %t.o -# RUN: not ld.lld -shared %t.o -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s # CHECK: relocation R_AARCH64_LD_PREL_LO19 out of range: 2065536 is not in [-1048576, 1048575] diff --git a/test/ELF/aarch64-lo12-alignment.s b/test/ELF/aarch64-lo12-alignment.s index 2b30022658e6..7edecd4494f5 100644 --- a/test/ELF/aarch64-lo12-alignment.s +++ b/test/ELF/aarch64-lo12-alignment.s @@ -1,6 +1,6 @@ // REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux %s -o %t -// RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s +// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s // Test derived from a typical ODR violation where a global is declared // extern int but defined as a half or byte sized type. diff --git a/test/ELF/aarch64-lo21-error.s b/test/ELF/aarch64-lo21-error.s index 055f8948f6a3..c1fb8a6fa2c2 100644 --- a/test/ELF/aarch64-lo21-error.s +++ b/test/ELF/aarch64-lo21-error.s @@ -1,7 +1,7 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-pc-freebsd %S/Inputs/abs.s -o %tabs // RUN: llvm-mc -filetype=obj -triple=aarch64-pc-freebsd %s -o %t -// RUN: not ld.lld %tabs %t -o %t2 2>&1 | FileCheck %s -// REQUIRES: aarch64 +// RUN: not ld.lld %tabs %t -o /dev/null 2>&1 | FileCheck %s .globl _start _start: diff --git a/test/ELF/aarch64-load-alignment.s b/test/ELF/aarch64-load-alignment.s index 7b1129b7afa5..175f1e6dad74 100644 --- a/test/ELF/aarch64-load-alignment.s +++ b/test/ELF/aarch64-load-alignment.s @@ -1,7 +1,7 @@ # REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-none %s -o %t.o -# RUN: not ld.lld -shared %t.o -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s # CHECK: improper alignment for relocation R_AARCH64_LD_PREL_LO19: 0x10005 is not aligned to 4 bytes diff --git a/test/ELF/aarch64-relocs.s b/test/ELF/aarch64-relocs.s index 9d02bd599b25..79caabcb6bb5 100644 --- a/test/ELF/aarch64-relocs.s +++ b/test/ELF/aarch64-relocs.s @@ -1,8 +1,8 @@ +# REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %p/Inputs/uabs_label.s -o %t2.o # RUN: ld.lld %t %t2.o -o %t2 # RUN: llvm-objdump -d %t2 | FileCheck %s -# REQUIRES: aarch64 .section .R_AARCH64_ADR_PREL_LO21,"ax",@progbits .globl _start diff --git a/test/ELF/aarch64-thunk-pi.s b/test/ELF/aarch64-thunk-pi.s index 91e2b7f0f3cd..d5d956c669b5 100644 --- a/test/ELF/aarch64-thunk-pi.s +++ b/test/ELF/aarch64-thunk-pi.s @@ -1,3 +1,4 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t // RUN: echo "SECTIONS { \ // RUN: .text_low : { *(.text_low) } \ @@ -5,7 +6,6 @@ // RUN: } " > %t.script // RUN: ld.lld --script %t.script --shared %t -o %t2 2>&1 // RUN: llvm-objdump -d -triple=aarch64-linux-gnu %t2 | FileCheck %s -// REQUIRES: aarch64 // Check that Position Independent thunks are generated for shared libraries. .section .text_low, "ax", %progbits @@ -16,8 +16,8 @@ low_target: bl high_target ret // CHECK: low_target: -// CHECK-NEXT: 0: 04 00 00 94 bl #16 -// CHECK-NEXT: 4: c0 03 5f d6 ret +// CHECK-NEXT: 8: 04 00 00 94 bl #16 +// CHECK-NEXT: c: c0 03 5f d6 ret .hidden low_target2 .globl low_target2 @@ -27,19 +27,19 @@ low_target2: bl high_target2 ret // CHECK: low_target2: -// CHECK-NEXT: 8: 05 00 00 94 bl #20 -// CHECK-NEXT: c: c0 03 5f d6 ret +// CHECK-NEXT: 0: 05 00 00 94 bl #20 +// CHECK-NEXT: 4: c0 03 5f d6 ret // Expect range extension thunks for .text_low // adrp calculation is (PC + signed immediate) & (!0xfff) // CHECK: __AArch64ADRPThunk_high_target: -// CHECK-NEXT: 10: 10 00 08 90 adrp x16, #268435456 -// CHECK-NEXT: 14: 10 82 04 91 add x16, x16, #288 -// CHECK-NEXT: 18: 00 02 1f d6 br x16 +// CHECK-NEXT: e8: 10 00 08 90 adrp x16, #268435456 +// CHECK-NEXT: ec: 10 02 01 91 add x16, x16, #64 +// CHECK-NEXT: f0: 00 02 1f d6 br x16 // CHECK: __AArch64ADRPThunk_high_target2: -// CHECK-NEXT: 1c: 10 00 08 90 adrp x16, #268435456 -// CHECK-NEXT: 20: 10 22 00 91 add x16, x16, #8 -// CHECK-NEXT: 24: 00 02 1f d6 br x16 +// CHECK-NEXT: f4: 10 00 08 90 adrp x16, #268435456 +// CHECK-NEXT: f8: 10 22 00 91 add x16, x16, #8 +// CHECK-NEXT: fc: 00 02 1f d6 br x16 .section .text_high, "ax", %progbits @@ -50,7 +50,7 @@ high_target: bl low_target ret // CHECK: high_target: -// CHECK-NEXT: 10000000: 4c 00 00 94 bl #304 +// CHECK-NEXT: 10000000: 14 00 00 94 bl #80 // CHECK-NEXT: 10000004: c0 03 5f d6 ret .hidden high_target2 @@ -68,24 +68,24 @@ high_target2: // CHECK: __AArch64ADRPThunk_low_target2: // CHECK-NEXT: 10000010: 10 00 f8 90 adrp x16, #-268435456 -// CHECK-NEXT: 10000014: 10 22 00 91 add x16, x16, #8 +// CHECK-NEXT: 10000014: 10 82 03 91 add x16, x16, #224 // CHECK-NEXT: 10000018: 00 02 1f d6 br x16 // CHECK: Disassembly of section .plt: // CHECK-NEXT: .plt: -// CHECK-NEXT: 10000100: f0 7b bf a9 stp x16, x30, [sp, #-16]! -// CHECK-NEXT: 10000104: 10 00 00 90 adrp x16, #0 -// CHECK-NEXT: 10000108: 11 aa 40 f9 ldr x17, [x16, #336] -// CHECK-NEXT: 1000010c: 10 42 05 91 add x16, x16, #336 -// CHECK-NEXT: 10000110: 20 02 1f d6 br x17 -// CHECK-NEXT: 10000114: 1f 20 03 d5 nop -// CHECK-NEXT: 10000118: 1f 20 03 d5 nop -// CHECK-NEXT: 1000011c: 1f 20 03 d5 nop -// CHECK-NEXT: 10000120: 10 00 00 90 adrp x16, #0 -// CHECK-NEXT: 10000124: 11 ae 40 f9 ldr x17, [x16, #344] -// CHECK-NEXT: 10000128: 10 62 05 91 add x16, x16, #344 -// CHECK-NEXT: 1000012c: 20 02 1f d6 br x17 -// CHECK-NEXT: 10000130: 10 00 00 90 adrp x16, #0 -// CHECK-NEXT: 10000134: 11 b2 40 f9 ldr x17, [x16, #352] -// CHECK-NEXT: 10000138: 10 82 05 91 add x16, x16, #352 -// CHECK-NEXT: 1000013c: 20 02 1f d6 br x17 +// CHECK-NEXT: 10000020: f0 7b bf a9 stp x16, x30, [sp, #-16]! +// CHECK-NEXT: 10000024: 10 00 00 90 adrp x16, #0 +// CHECK-NEXT: 10000028: 11 3a 40 f9 ldr x17, [x16, #112] +// CHECK-NEXT: 1000002c: 10 c2 01 91 add x16, x16, #112 +// CHECK-NEXT: 10000030: 20 02 1f d6 br x17 +// CHECK-NEXT: 10000034: 1f 20 03 d5 nop +// CHECK-NEXT: 10000038: 1f 20 03 d5 nop +// CHECK-NEXT: 1000003c: 1f 20 03 d5 nop +// CHECK-NEXT: 10000040: 10 00 00 90 adrp x16, #0 +// CHECK-NEXT: 10000044: 11 3e 40 f9 ldr x17, [x16, #120] +// CHECK-NEXT: 10000048: 10 e2 01 91 add x16, x16, #120 +// CHECK-NEXT: 1000004c: 20 02 1f d6 br x17 +// CHECK-NEXT: 10000050: 10 00 00 90 adrp x16, #0 +// CHECK-NEXT: 10000054: 11 42 40 f9 ldr x17, [x16, #128] +// CHECK-NEXT: 10000058: 10 02 02 91 add x16, x16, #128 +// CHECK-NEXT: 1000005c: 20 02 1f d6 br x17 diff --git a/test/ELF/aarch64-thunk-script.s b/test/ELF/aarch64-thunk-script.s index ebfaf72de5f4..1dfdcbc7a562 100644 --- a/test/ELF/aarch64-thunk-script.s +++ b/test/ELF/aarch64-thunk-script.s @@ -1,3 +1,4 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t // RUN: echo "SECTIONS { \ // RUN: .text_low 0x2000: { *(.text_low) } \ @@ -5,7 +6,6 @@ // RUN: } " > %t.script // RUN: ld.lld --script %t.script %t -o %t2 2>&1 // RUN: llvm-objdump -d -triple=aarch64-linux-gnu %t2 | FileCheck %s -// REQUIRES: aarch64 // Check that we have the out of branch range calculation right. The immediate // field is signed so we have a slightly higher negative displacement. diff --git a/test/ELF/aarch64-thunk-section-location.s b/test/ELF/aarch64-thunk-section-location.s index bf70b7c365ba..606c6941579e 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=134086664 -stop-address=134086676 -triple=aarch64-linux-gnu %t2 | FileCheck %s -// REQUIRES: aarch64 // Check that the range extension thunks are dumped close to the aarch64 branch // range of 128 MiB .section .text.1, "ax", %progbits diff --git a/test/ELF/aarch64-tls-gdle.s b/test/ELF/aarch64-tls-gdle.s index a111cacefd29..6763c50838da 100644 --- a/test/ELF/aarch64-tls-gdle.s +++ b/test/ELF/aarch64-tls-gdle.s @@ -1,9 +1,9 @@ +# REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %p/Inputs/aarch64-tls-ie.s -o %ttlsie.o # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %tmain.o # RUN: ld.lld %tmain.o %ttlsie.o -o %tout # RUN: llvm-objdump -d %tout | FileCheck %s # RUN: llvm-readobj -s -r %tout | FileCheck -check-prefix=RELOC %s -# REQUIRES: aarch64 #Local-Dynamic to Initial-Exec relax creates no #RELOC: Relocations [ diff --git a/test/ELF/aarch64-tls-ie.s b/test/ELF/aarch64-tls-ie.s index 8b7431093a26..fba7cd8af51f 100644 --- a/test/ELF/aarch64-tls-ie.s +++ b/test/ELF/aarch64-tls-ie.s @@ -1,11 +1,11 @@ // REQUIRES: aarch64 +# REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %p/Inputs/aarch64-tls-ie.s -o %tdso.o # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %tmain.o # RUN: ld.lld -shared %tdso.o -o %tdso.so # RUN: ld.lld --hash-style=sysv %tmain.o %tdso.so -o %tout # RUN: llvm-objdump -d %tout | FileCheck %s # RUN: llvm-readobj -s -r %tout | FileCheck -check-prefix=RELOC %s -# REQUIRES: aarch64 #RELOC: Section { #RELOC: Index: diff --git a/test/ELF/aarch64-tls-iele.s b/test/ELF/aarch64-tls-iele.s index 208b5cdd5446..c97a578f8dc2 100644 --- a/test/ELF/aarch64-tls-iele.s +++ b/test/ELF/aarch64-tls-iele.s @@ -1,9 +1,9 @@ +# REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %p/Inputs/aarch64-tls-ie.s -o %ttlsie.o # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %tmain.o # RUN: ld.lld %tmain.o %ttlsie.o -o %tout # RUN: llvm-objdump -d %tout | FileCheck %s # RUN: llvm-readobj -s -r %tout | FileCheck -check-prefix=RELOC %s -# REQUIRES: aarch64 # Initial-Exec to Local-Exec relax creates no dynamic relocations. # RELOC: Relocations [ diff --git a/test/ELF/aarch64-tls-le.s b/test/ELF/aarch64-tls-le.s index df943f7f091a..e5b1c208a185 100644 --- a/test/ELF/aarch64-tls-le.s +++ b/test/ELF/aarch64-tls-le.s @@ -1,8 +1,8 @@ +# REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %tmain.o # RUN: ld.lld %tmain.o -o %tout # RUN: llvm-objdump -d %tout | FileCheck %s # RUN: llvm-readobj -s -r %tout | FileCheck -check-prefix=RELOC %s -# REQUIRES: aarch64 #Local-Dynamic to Initial-Exec relax creates no #RELOC: Relocations [ diff --git a/test/ELF/aarch64-tlsld-ldst.s b/test/ELF/aarch64-tlsld-ldst.s new file mode 100644 index 000000000000..9de3a38044d9 --- /dev/null +++ b/test/ELF/aarch64-tlsld-ldst.s @@ -0,0 +1,85 @@ +// REQUIRES: aarch64 +// RUN: llvm-mc -triple=aarch64-linux-gnu -filetype=obj %s -o %t.o +// RUN: ld.lld %t.o -o %t +// RUN: llvm-objdump -d %t | FileCheck %s +// RUN: llvm-readelf --symbols %t | FileCheck -check-prefix CHECK-SYMS %s + + .text + .globl _start + .type _start, %function +_start: mrs x8, TPIDR_EL0 + + add x8, x8, :tprel_hi12:var0 + ldr q20, [x8, :tprel_lo12_nc:var0] + + add x8, x8, :tprel_hi12:var1 + ldr x0, [x8, :tprel_lo12_nc:var1] + + add x8, x8, :tprel_hi12:var2 + ldr w0, [x8, :tprel_lo12_nc:var2] + + add x8, x8, :tprel_hi12:var3 + ldrh w0, [x8, :tprel_lo12_nc:var3] + + add x8, x8, :tprel_hi12:var4 + ldrb w0, [x8, :tprel_lo12_nc:var4] + +// CHECK: _start: +// CHECK-NEXT: 20000: 48 d0 3b d5 mrs x8, TPIDR_EL0 +// 0x0 + c10 = 0xc10 = tcb (16-bytes) + var0 +// CHECK-NEXT: 20004: 08 01 40 91 add x8, x8, #0, lsl #12 +// CHECK-NEXT: 20008: 14 05 c3 3d ldr q20, [x8, #3088] +// 0x1000 + 0x820 = 0x1820 = tcb + var1 +// CHECK-NEXT: 2000c: 08 05 40 91 add x8, x8, #1, lsl #12 +// CHECK-NEXT: 20010: 00 11 44 f9 ldr x0, [x8, #2080] +// 0x2000 + 0x428 = 0x2428 = tcb + var2 +// CHECK-NEXT: 20014: 08 09 40 91 add x8, x8, #2, lsl #12 +// CHECK-NEXT: 20018: 00 29 44 b9 ldr w0, [x8, #1064] +// 0x3000 + 0x2c = 0x302c = tcb + var3 +// CHECK-NEXT: 2001c: 08 0d 40 91 add x8, x8, #3, lsl #12 +// CHECK-NEXT: 20020: 00 59 40 79 ldrh w0, [x8, #44] +// 0x3000 + 0xc2e = 0x32ce = tcb + var4 +// CHECK-NEXT: 20024: 08 0d 40 91 add x8, x8, #3, lsl #12 +// CHECK-NEXT: 20028: 00 b9 70 39 ldrb w0, [x8, #3118] + +// CHECK-SYMS: 0000000000000c00 0 TLS GLOBAL DEFAULT 2 var0 +// CHECK-SYMS-NEXT: 0000000000001810 4 TLS GLOBAL DEFAULT 2 var1 +// CHECK-SYMS-NEXT: 0000000000002418 2 TLS GLOBAL DEFAULT 2 var2 +// CHECK-SYMS-NEXT: 000000000000301c 1 TLS GLOBAL DEFAULT 2 var3 +// CHECK-SYMS-NEXT: 0000000000003c1e 0 TLS GLOBAL DEFAULT 2 var4 + + .globl var0 + .globl var1 + .globl var2 + .globl var3 + .globl var4 + .type var0,@object + .type var1,@object + .type var2,@object + .type var3,@object + +.section .tbss,"awT",@nobits + .balign 16 + .space 1024 * 3 +var0: + .quad 0 + .quad 0 + .size var1, 16 + .space 1024 * 3 +var1: + .quad 0 + .size var1, 8 + .space 1024 * 3 +var2: + .word 0 + .size var1, 4 + + .space 1024 * 3 +var3: + .hword 0 + .size var2, 2 + .space 1024 * 3 +var4: + .byte 0 + .size var3, 1 + .space 1024 * 3 diff --git a/test/ELF/aarch64-tstbr14-reloc.s b/test/ELF/aarch64-tstbr14-reloc.s index c0a0a543a6c5..779ca6b808a8 100644 --- a/test/ELF/aarch64-tstbr14-reloc.s +++ b/test/ELF/aarch64-tstbr14-reloc.s @@ -1,3 +1,4 @@ +# REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %p/Inputs/aarch64-tstbr14-reloc.s -o %t1 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t2 # RUN: ld.lld %t1 %t2 -o %t @@ -5,7 +6,6 @@ # RUN: ld.lld -shared %t1 %t2 -o %t3 # RUN: llvm-objdump -d %t3 | FileCheck -check-prefix=DSO %s # RUN: llvm-readobj -s -r %t3 | FileCheck -check-prefix=DSOREL %s -# REQUIRES: aarch64 # 0x1101c - 28 = 0x20000 # 0x11020 - 16 = 0x20010 diff --git a/test/ELF/aarch64-undefined-weak.s b/test/ELF/aarch64-undefined-weak.s index 35f50417497e..e2316acf36a0 100644 --- a/test/ELF/aarch64-undefined-weak.s +++ b/test/ELF/aarch64-undefined-weak.s @@ -1,7 +1,7 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux %s -o %t // RUN: ld.lld %t -o %t2 2>&1 // RUN: llvm-objdump -triple=aarch64-none-linux -d %t2 | FileCheck %s -// REQUIRES: aarch64 // Check that the ARM 64-bit ABI rules for undefined weak symbols are applied. // Branch instructions are resolved to the next instruction. Undefined diff --git a/test/ELF/abs-conflict.s b/test/ELF/abs-conflict.s index 4662c48a4e40..ea435cc956c0 100644 --- a/test/ELF/abs-conflict.s +++ b/test/ELF/abs-conflict.s @@ -15,4 +15,4 @@ foo = 0x123 // DUP: duplicate symbol: foo // DUP-NEXT: >>> defined in {{.*}}.o -// DUP-NEXT: >>> defined in <internal> +// DUP-NEXT: >>> defined in {{.*}}2.o diff --git a/test/ELF/allow-multiple-definition.s b/test/ELF/allow-multiple-definition.s index c54438d9f1e0..06684f47e616 100644 --- a/test/ELF/allow-multiple-definition.s +++ b/test/ELF/allow-multiple-definition.s @@ -3,13 +3,14 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/allow-multiple-definition.s -o %t2 # RUN: not ld.lld %t1 %t2 -o %t3 -# RUN: ld.lld --allow-multiple-definition %t1 %t2 -o %t3 -# RUN: ld.lld --allow-multiple-definition %t2 %t1 -o %t4 +# RUN: not ld.lld --allow-multiple-definition --no-allow-multiple-definition %t1 %t2 -o %t3 +# RUN: ld.lld --allow-multiple-definition --fatal-warnings %t1 %t2 -o %t3 +# RUN: ld.lld --allow-multiple-definition --fatal-warnings %t2 %t1 -o %t4 # RUN: llvm-objdump -d %t3 | FileCheck %s # RUN: llvm-objdump -d %t4 | FileCheck -check-prefix=REVERT %s -# RUN: ld.lld -z muldefs %t1 %t2 -o %t3 -# RUN: ld.lld -z muldefs %t2 %t1 -o %t4 +# RUN: ld.lld -z muldefs --fatal-warnings %t1 %t2 -o %t3 +# RUN: ld.lld -z muldefs --fatal-warnings %t2 %t1 -o %t4 # RUN: llvm-objdump -d %t3 | FileCheck %s # RUN: llvm-objdump -d %t4 | FileCheck -check-prefix=REVERT %s diff --git a/test/ELF/amdgpu-elf-flags-err.s b/test/ELF/amdgpu-elf-flags-err.s index 4c295b5b92e4..b5619352fb04 100644 --- a/test/ELF/amdgpu-elf-flags-err.s +++ b/test/ELF/amdgpu-elf-flags-err.s @@ -1,7 +1,6 @@ -# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 -filetype=obj %S/Inputs/amdgpu-kernel-0.s -o %t-0.o -# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 -filetype=obj %S/Inputs/amdgpu-kernel-1.s -o %t-1.o -# RUN: not ld.lld -shared %t-0.o %t-1.o %S/Inputs/amdgpu-kernel-2.o -o %t.so 2>&1 | FileCheck %s - # REQUIRES: amdgpu +# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx802 -filetype=obj %S/Inputs/amdgpu-kernel-0.s -o %t-0.o +# RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 -filetype=obj %S/Inputs/amdgpu-kernel-1.s -o %t-1.o +# RUN: not ld.lld -shared %t-0.o %t-1.o -o /dev/null 2>&1 | FileCheck %s -# CHECK: error: incompatible e_flags: {{.*}}amdgpu-kernel-2.o +# CHECK: error: incompatible e_flags: {{.*}}-1.o diff --git a/test/ELF/amdgpu-elf-flags.s b/test/ELF/amdgpu-elf-flags.s index 85f891a98364..d062dac748ea 100644 --- a/test/ELF/amdgpu-elf-flags.s +++ b/test/ELF/amdgpu-elf-flags.s @@ -1,10 +1,9 @@ +# REQUIRES: amdgpu # RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 -filetype=obj %S/Inputs/amdgpu-kernel-0.s -o %t-0.o # RUN: llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx803 -filetype=obj %S/Inputs/amdgpu-kernel-1.s -o %t-1.o # RUN: ld.lld -shared %t-0.o %t-1.o -o %t.so # RUN: llvm-readobj -file-headers %t.so | FileCheck %s -# REQUIRES: amdgpu - -# CHECK: Flags [ (0x2) -# CHECK: EF_AMDGPU_ARCH_GCN (0x2) +# CHECK: Flags [ +# CHECK: EF_AMDGPU_MACH_AMDGCN_GFX803 (0x2A) # CHECK: ] diff --git a/test/ELF/amdgpu-globals.s b/test/ELF/amdgpu-globals.s index e32159b332e7..eadc4ef1e0d6 100644 --- a/test/ELF/amdgpu-globals.s +++ b/test/ELF/amdgpu-globals.s @@ -1,9 +1,8 @@ +# REQUIRES: amdgpu # RUN: llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=kaveri %s -o %t.o # RUN: ld.lld -shared %t.o -o %t # RUN: llvm-readobj -sections -symbols -program-headers %t | FileCheck %s -# REQUIRES: amdgpu - .type glob0, @object .data .globl glob0 diff --git a/test/ELF/amdgpu-kernels.s b/test/ELF/amdgpu-kernels.s index c76613f1a336..01b1ef2757fb 100644 --- a/test/ELF/amdgpu-kernels.s +++ b/test/ELF/amdgpu-kernels.s @@ -1,9 +1,8 @@ +# REQUIRES: amdgpu # RUN: llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=kaveri %s -o %t.o # RUN: ld.lld -shared %t.o -o %t # RUN: llvm-readobj -sections -symbols -program-headers %t | FileCheck %s -# REQUIRES: amdgpu - .hsa_code_object_version 1,0 .hsa_code_object_isa 7,0,0,"AMD","AMDGPU" diff --git a/test/ELF/amdgpu-relocs.s b/test/ELF/amdgpu-relocs.s index 8b5a61ed21f4..eeb7571e21df 100644 --- a/test/ELF/amdgpu-relocs.s +++ b/test/ELF/amdgpu-relocs.s @@ -1,10 +1,9 @@ +# REQUIRES: amdgpu # RUN: llvm-mc -filetype=obj -triple=amdgcn--amdhsa -mcpu=fiji %s -o %t.o # RUN: ld.lld --hash-style=sysv -shared %t.o -o %t.so # RUN: llvm-readobj -r %t.so | FileCheck %s # RUN: llvm-objdump -s %t.so | FileCheck %s --check-prefix=OBJDUMP -# REQUIRES: amdgpu - .text kernel0: @@ -77,6 +76,15 @@ ptr: ptr2: .quad temp2 +# R_AMDGPU_REL64: +.type foo, @object +.rodata + .globl foo + .p2align 3 +foo: + .quad temp2@rel64 + .size foo, 8 + # The relocation for local_var{0, 1, 2} and var should be resolved by the # linker. # CHECK: Relocations [ @@ -101,6 +109,9 @@ ptr2: # CHECK-NEXT: } # CHECK-NEXT: ] +# OBJDUMP: Contents of section .rodata: +# OBJDUMP: d0f8ffff ffffffff + # OBJDUMP: Contents of section nonalloc: # OBJDUMP-NEXT: 0000 00000000 04480000 00000000 08440000 # OBJDUMP-NEXT: 00000000 0c400000 diff --git a/test/ELF/archive.s b/test/ELF/archive.s index 59c96a5fba9b..aa7455764fbf 100644 --- a/test/ELF/archive.s +++ b/test/ELF/archive.s @@ -1,16 +1,21 @@ +# 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/archive.s -o %t2 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive2.s -o %t3 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive3.s -o %t4 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive4.s -o %t5 -# RUN: llvm-ar rcs %tar %t2 %t3 %t4 -# RUN: ld.lld %t %tar %t5 -o %tout -# RUN: llvm-nm %tout | FileCheck %s -# RUN: rm -f %tarthin -# RUN: llvm-ar --format=gnu rcsT %tarthin %t2 %t3 %t4 -# RUN: ld.lld %t %tarthin %t5 -o %tout -# RUN: llvm-nm %tout | FileCheck %s -# REQUIRES: x86 + +# RUN: rm -f %t.a +# RUN: llvm-ar rcs %t.a %t2 %t3 %t4 + +# RUN: ld.lld %t %t.a %t5 -o %t.out +# RUN: llvm-nm %t.out | FileCheck %s + +# RUN: rm -f %t.thin +# RUN: llvm-ar --format=gnu rcsT %t.thin %t2 %t3 %t4 + +# RUN: ld.lld %t %t.thin %t5 -o %t.out +# RUN: llvm-nm %t.out | FileCheck %s # Nothing here. Just needed for the linker to create a undefined _start symbol. @@ -31,8 +36,8 @@ # Test that the hitting the first object file after having a lazy symbol for # _start is handled correctly. -# RUN: ld.lld %tar %t -o %tout -# RUN: llvm-nm %tout | FileCheck --check-prefix=AR-FIRST %s +# RUN: ld.lld %t.a %t -o %t.out +# RUN: llvm-nm %t.out | FileCheck --check-prefix=AR-FIRST %s # AR-FIRST: T _start # AR-FIRST-NEXT: w bar diff --git a/test/ELF/arm-attributes.s b/test/ELF/arm-attributes.s index 14517e8fc789..e4411e79b010 100644 --- a/test/ELF/arm-attributes.s +++ b/test/ELF/arm-attributes.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/arm-attributes1.s -o %t1.o // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t2.o @@ -7,7 +8,6 @@ // RUN: llvm-readobj -arm-attributes %t2 | FileCheck %s // RUN: ld.lld %t1.o %t2.o -r -o %t3 // RUN: llvm-readobj -arm-attributes %t3 | FileCheck %s -// REQUIRES: arm // Check that we retain only 1 SHT_ARM_ATTRIBUTES section. At present we do not // try and merge or use the contents of SHT_ARM_ATTRIBUTES sections. We just diff --git a/test/ELF/arm-bl-v6.s b/test/ELF/arm-bl-v6.s index 6317aa433d6c..c27a99e6b9e7 100644 --- a/test/ELF/arm-bl-v6.s +++ b/test/ELF/arm-bl-v6.s @@ -1,6 +1,6 @@ -// RUN: llvm-mc -filetype=obj -triple=arm-none-linux-gnueabi %s -o %t -// RUN: ld.lld %t -o %t2 2>&1 | FileCheck %s // REQUIRES: arm +// RUN: llvm-mc -filetype=obj -triple=arm-none-linux-gnueabi %s -o %t +// RUN: ld.lld %t -o /dev/null 2>&1 | FileCheck %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 diff --git a/test/ELF/arm-blx-v4t.s b/test/ELF/arm-blx-v4t.s index 858b93fd5891..f526b3b01f4a 100644 --- a/test/ELF/arm-blx-v4t.s +++ b/test/ELF/arm-blx-v4t.s @@ -1,6 +1,6 @@ -// RUN: llvm-mc -filetype=obj -triple=arm-none-linux-gnueabi %s -o %t -// RUN: ld.lld %t -o %t2 2>&1 | FileCheck %s // REQUIRES: arm +// RUN: llvm-mc -filetype=obj -triple=arm-none-linux-gnueabi %s -o %t +// RUN: ld.lld %t -o /dev/null 2>&1 | FileCheck %s // On Arm v4t there is no blx instruction so all interworking must go via // a thunk. At present we don't support v4t so we give a warning for unsupported diff --git a/test/ELF/arm-blx.s b/test/ELF/arm-blx.s index 159eee51c74c..5b44c8416c20 100644 --- a/test/ELF/arm-blx.s +++ b/test/ELF/arm-blx.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/far-arm-thumb-abs.s -o %tfar // RUN: echo "SECTIONS { \ @@ -10,7 +11,6 @@ // RUN: ld.lld --script %t.script %t %tfar -o %t2 2>&1 // 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 -// REQUIRES: arm // 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. diff --git a/test/ELF/arm-branch-rangethunk.s b/test/ELF/arm-branch-rangethunk.s index c61ec899adae..739a7707dbec 100644 --- a/test/ELF/arm-branch-rangethunk.s +++ b/test/ELF/arm-branch-rangethunk.s @@ -1,8 +1,11 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/far-arm-abs.s -o %tfar // RUN: ld.lld %t %tfar -o %t2 2>&1 -// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s -// REQUIRES: arm +// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck --check-prefix=SHORT %s +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/far-long-arm-abs.s -o %tfarlong +// RUN: ld.lld %t %tfarlong -o %t3 2>&1 +// RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t3 | FileCheck --check-prefix=LONG %s .syntax unified .section .text, "ax",%progbits .globl _start @@ -15,20 +18,32 @@ _start: b too_far2 beq too_far3 -// CHECK: Disassembly of section .text: -// CHECK-NEXT: _start: -// CHECK-NEXT: 20000: 01 00 00 eb bl #4 <__ARMv7ABSLongThunk_too_far1> -// CHECK-NEXT: 20004: 03 00 00 ea b #12 <__ARMv7ABSLongThunk_too_far2> -// CHECK-NEXT: 20008: 05 00 00 0a beq #20 <__ARMv7ABSLongThunk_too_far3> -// CHECK: __ARMv7ABSLongThunk_too_far1: -// CHECK-NEXT: 2000c: 08 c0 00 e3 movw r12, #8 -// CHECK-NEXT: 20010: 02 c2 40 e3 movt r12, #514 -// CHECK-NEXT: 20014: 1c ff 2f e1 bx r12 -// CHECK: __ARMv7ABSLongThunk_too_far2: -// CHECK-NEXT: 20018: 0c c0 00 e3 movw r12, #12 -// CHECK-NEXT: 2001c: 02 c2 40 e3 movt r12, #514 -// CHECK-NEXT: 20020: 1c ff 2f e1 bx r12 -// CHECK: __ARMv7ABSLongThunk_too_far3: -// CHECK-NEXT: 20024: 10 c0 00 e3 movw r12, #16 -// CHECK-NEXT: 20028: 02 c2 40 e3 movt r12, #514 -// CHECK-NEXT: 2002c: 1c ff 2f e1 bx r12 +// SHORT: Disassembly of section .text: +// SHORT-NEXT: _start: +// SHORT-NEXT: 20000: 01 00 00 eb bl #4 <__ARMv7ABSLongThunk_too_far1> +// SHORT-NEXT: 20004: 01 00 00 ea b #4 <__ARMv7ABSLongThunk_too_far2> +// SHORT-NEXT: 20008: 01 00 00 0a beq #4 <__ARMv7ABSLongThunk_too_far3> +// SHORT: __ARMv7ABSLongThunk_too_far1: +// SHORT-NEXT: 2000c: fd ff 7f ea b #33554420 <__ARMv7ABSLongThunk_too_far3+0x1fffff4> +// SHORT: __ARMv7ABSLongThunk_too_far2: +// SHORT-NEXT: 20010: fd ff 7f ea b #33554420 <__ARMv7ABSLongThunk_too_far3+0x1fffff8> +// SHORT: __ARMv7ABSLongThunk_too_far3: +// SHORT-NEXT: 20014: fd ff 7f ea b #33554420 <__ARMv7ABSLongThunk_too_far3+0x1fffffc> + +// LONG: Disassembly of section .text: +// LONG-NEXT: _start: +// LONG-NEXT: 20000: 01 00 00 eb bl #4 <__ARMv7ABSLongThunk_too_far1> +// LONG-NEXT: 20004: 03 00 00 ea b #12 <__ARMv7ABSLongThunk_too_far2> +// LONG-NEXT: 20008: 05 00 00 0a beq #20 <__ARMv7ABSLongThunk_too_far3> +// LONG: __ARMv7ABSLongThunk_too_far1: +// LONG-NEXT: 2000c: 14 c0 00 e3 movw r12, #20 +// LONG-NEXT: 20010: 02 c2 40 e3 movt r12, #514 +// LONG-NEXT: 20014: 1c ff 2f e1 bx r12 +// LONG: __ARMv7ABSLongThunk_too_far2: +// LONG-NEXT: 20018: 20 c0 00 e3 movw r12, #32 +// LONG-NEXT: 2001c: 02 c2 40 e3 movt r12, #514 +// LONG-NEXT: 20020: 1c ff 2f e1 bx r12 +// LONG: __ARMv7ABSLongThunk_too_far3: +// LONG-NEXT: 20024: 2c c0 00 e3 movw r12, #44 +// LONG-NEXT: 20028: 02 c2 40 e3 movt r12, #514 +// LONG-NEXT: 2002c: 1c ff 2f e1 bx r12 diff --git a/test/ELF/arm-branch-undef-weak-plt-thunk.s b/test/ELF/arm-branch-undef-weak-plt-thunk.s index f95da0dcec21..f47ed61ca5a6 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 -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 -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 -// REQUIRES: arm // 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. diff --git a/test/ELF/arm-branch.s b/test/ELF/arm-branch.s index 986863d3d80c..48c497724b0d 100644 --- a/test/ELF/arm-branch.s +++ b/test/ELF/arm-branch.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/far-arm-abs.s -o %tfar // RUN: echo "SECTIONS { \ @@ -7,7 +8,6 @@ // RUN: .callee2 : { *(.callee_high) } } " > %t.script // RUN: ld.lld --script %t.script %t %tfar -o %t2 2>&1 // RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s -// REQUIRES: arm .syntax unified .section .callee_low, "ax",%progbits .align 2 diff --git a/test/ELF/arm-copy.s b/test/ELF/arm-copy.s index dc9e3628de4f..e42f93ea5bb6 100644 --- a/test/ELF/arm-copy.s +++ b/test/ELF/arm-copy.s @@ -1,7 +1,7 @@ // REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/relocation-copy-arm.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -shared %t2.o -soname fixed-length-string.so -o %t2.so // RUN: ld.lld --hash-style=sysv %t.o %t2.so -o %t3 // RUN: llvm-readobj -s -r --expand-relocs -symbols %t3 | FileCheck %s // RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t3 | FileCheck -check-prefix=CODE %s @@ -33,7 +33,7 @@ _start: // CHECK-NEXT: AddressAlignment: 16 // CHECK: Relocations [ -// CHECK-NEXT: Section (5) .rel.dyn { +// CHECK-NEXT: Section {{.*}} .rel.dyn { // CHECK-NEXT: Relocation { // CHECK-NEXT: Offset: 0x13000 // CHECK-NEXT: Type: R_ARM_COPY @@ -78,4 +78,4 @@ _start: // RODATA: Contents of section .rodata: // S(z) = 0x13004 -// RODATA-NEXT: 10114 04300100 +// RODATA-NEXT: 10190 04300100 diff --git a/test/ELF/arm-data-prel.s b/test/ELF/arm-data-prel.s index a8c0c280b220..78b42818609b 100644 --- a/test/ELF/arm-data-prel.s +++ b/test/ELF/arm-data-prel.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o %t.o // RUN: echo "SECTIONS { \ // RUN: .text : { *(.text) } \ @@ -6,7 +7,6 @@ // RUN: .TEST1 : { *(.TEST1) } } " > %t.script // RUN: ld.lld --script %t.script %t.o -o %t // RUN: llvm-readobj -s -sd %t | FileCheck --check-prefix=CHECK %s -// REQUIRES: arm // The R_ARM_PREL31 relocation is used in by the .ARM.exidx exception tables // bit31 of the place denotes whether the field is an inline table entry diff --git a/test/ELF/arm-data-relocs.s b/test/ELF/arm-data-relocs.s index ed237850c4c1..586e1a6c8933 100644 --- a/test/ELF/arm-data-relocs.s +++ b/test/ELF/arm-data-relocs.s @@ -1,8 +1,8 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/abs256.s -o %t256.o // RUN: ld.lld %t %t256.o -o %t2 // RUN: llvm-objdump -d %t2 | FileCheck %s -// REQUIRES: arm .syntax unified .globl _start _start: diff --git a/test/ELF/arm-eabi-version.s b/test/ELF/arm-eabi-version.s index 727b805fddd7..a08374c132f0 100644 --- a/test/ELF/arm-eabi-version.s +++ b/test/ELF/arm-eabi-version.s @@ -1,7 +1,7 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o // RUN: ld.lld -static %t.o -o %tout // RUN: llvm-readobj -file-headers %tout | FileCheck %s -// REQUIRES: arm .syntax unified .text .globl _start diff --git a/test/ELF/arm-execute-only.s b/test/ELF/arm-execute-only.s new file mode 100644 index 000000000000..999d88c9e768 --- /dev/null +++ b/test/ELF/arm-execute-only.s @@ -0,0 +1,40 @@ +// REQUIRES: arm + +// RUN: llvm-mc -filetype=obj -triple=armv7-pc-linux %s -o %t.o +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-readelf -l %t.so | FileCheck %s + +// RUN: ld.lld %t.o %t.o -o %t.so -shared +// RUN: llvm-readelf -l %t.so | FileCheck %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 +// RUN: ld.lld %t.o %t2.o -o %t.so -shared +// RUN: llvm-readelf -l %t.so | FileCheck --check-prefix=DIFF %s + +// CHECK-NOT: LOAD +// 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-NOT: LOAD + +// CHECK: 01 .dynsym .gnu.hash .hash .dynstr +// CHECK: 02 .text +// CHECK: 03 .foo +// CHECK: 04 .dynamic + +// DIFF-NOT: LOAD +// 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-NOT: LOAD + +// DIFF: 01 .dynsym .gnu.hash .hash .dynstr +// DIFF: 02 .text .foo +// DIFF: 03 .dynamic + + bx lr + .section .foo,"axy" + bx lr diff --git a/test/ELF/arm-exidx-canunwind.s b/test/ELF/arm-exidx-canunwind.s index 96a7808e8e84..df89d0082fcf 100644 --- a/test/ELF/arm-exidx-canunwind.s +++ b/test/ELF/arm-exidx-canunwind.s @@ -1,9 +1,9 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 2>&1 // RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s // RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-EXIDX %s // RUN: llvm-readobj --program-headers --sections %t2 | FileCheck -check-prefix=CHECK-PT %s -// REQUIRES: arm // Test that inline unwinding table entries and references to .ARM.extab // entries survive the re-ordering of the .ARM.exidx section diff --git a/test/ELF/arm-exidx-dedup.s b/test/ELF/arm-exidx-dedup.s index 1648f77152e9..49d4c2cd1ec3 100644 --- a/test/ELF/arm-exidx-dedup.s +++ b/test/ELF/arm-exidx-dedup.s @@ -1,9 +1,9 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t --no-merge-exidx-entries -o %t2 // RUN: llvm-objdump -s %t2 | FileCheck --check-prefix CHECK-DUPS %s // RUN: ld.lld %t -o %t3 // RUN: llvm-objdump -s %t3 | FileCheck %s -// REQUIRES: arm // Test that lld can at least remove duplicate .ARM.exidx sections. A more // fine grained implementation will be able to remove duplicate entries within // a .ARM.exidx section. diff --git a/test/ELF/arm-exidx-discard.s b/test/ELF/arm-exidx-discard.s new file mode 100644 index 000000000000..2a204a04cd1b --- /dev/null +++ b/test/ELF/arm-exidx-discard.s @@ -0,0 +1,14 @@ +// 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 "ENTRY(__entrypoint) SECTIONS { . = 0x10000; .text : { *(.text .text.*) } /DISCARD/ : { *(.ARM.exidx*) *(.gnu.linkonce.armexidx.*) } }" > %t.script +// RUN: ld.lld -T %t.script %t.o -o %t.elf 2>&1 +// RUN: llvm-readobj -sections %t.elf | FileCheck %s + +.globl __entrypoint +__entrypoint: + bx lr + +// Check that .ARM.exidx/.gnu.linkonce.armexidx +// are correctly removed if they were added. +// CHECK-NOT: .ARM.exidx +// CHECK-NOT: .gnu.linkonce.armexidx. diff --git a/test/ELF/arm-exidx-gc.s b/test/ELF/arm-exidx-gc.s index 34bd9dbe37b2..50c8616ae773 100644 --- a/test/ELF/arm-exidx-gc.s +++ b/test/ELF/arm-exidx-gc.s @@ -1,8 +1,8 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t --no-merge-exidx-entries -o %t2 --gc-sections 2>&1 // RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s // RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-EXIDX %s -// REQUIRES: arm // Test the behavior of .ARM.exidx sections under garbage collection // A .ARM.exidx section is live if it has a relocation to a live executable diff --git a/test/ELF/arm-exidx-order.s b/test/ELF/arm-exidx-order.s index c988ad8a2cfe..7e2d4ce91d92 100644 --- a/test/ELF/arm-exidx-order.s +++ b/test/ELF/arm-exidx-order.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/arm-exidx-cantunwind.s -o %tcantunwind // RUN: ld.lld --no-merge-exidx-entries %t %tcantunwind -o %t2 2>&1 @@ -11,7 +12,6 @@ // RUN: ld.lld --no-merge-exidx-entries --script %t.script %tcantunwind %t -o %t3 2>&1 // RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t3 | FileCheck -check-prefix=CHECK-SCRIPT %s // RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t3 | FileCheck -check-prefix=CHECK-SCRIPT-EXIDX %s -// REQUIRES: arm // Each assembler created .ARM.exidx section has the SHF_LINK_ORDER flag set // with the sh_link containing the section index of the executable section @@ -142,28 +142,28 @@ f3: // CHECK-SCRIPT-NEXT: 11014: 1e ff 2f e1 bx lr // CHECK-SCRIPT-NEXT: Disassembly of section .func1: // CHECK-SCRIPT-NEXT: func1: -// CHECK-SCRIPT-NEXT: 11068: 1e ff 2f e1 bx lr +// CHECK-SCRIPT-NEXT: 11018: 1e ff 2f e1 bx lr // CHECK-SCRIPT-NEXT: Disassembly of section .func2: // CHECK-SCRIPT-NEXT: func2: -// CHECK-SCRIPT-NEXT: 1106c: 1e ff 2f e1 bx lr +// CHECK-SCRIPT-NEXT: 1101c: 1e ff 2f e1 bx lr // CHECK-SCRIPT-NEXT: Disassembly of section .func3: // CHECK-SCRIPT-NEXT: func3: -// CHECK-SCRIPT-NEXT: 11070: 1e ff 2f e1 bx lr +// CHECK-SCRIPT-NEXT: 11020: 1e ff 2f e1 bx lr // Check that the .ARM.exidx section is sorted in order as the functions // The offset in field 1, is 32-bit so in the binary the most significant bit -// 11018 - 18 = 11000 func4 -// 11020 - 1c = 11004 func5 -// CHECK-SCRIPT-EXIDX: 11018 e8ffff7f 01000000 e4ffff7f 01000000 -// 11028 - 20 = 11008 _start -// 11030 - 24 = 1100c f1 -// CHECK-SCRIPT-EXIDX-NEXT: 11028 e0ffff7f 01000000 dcffff7f 01000000 -// 11038 - 28 = 11010 f2 -// 11040 - 2c = 11014 f3 -// CHECK-SCRIPT-EXIDX-NEXT: 11038 d8ffff7f 01000000 d4ffff7f 01000000 -// 11048 + 20 = 11068 func1 -// 11050 + 1c = 1106c func2 -// CHECK-SCRIPT-EXIDX-NEXT: 11048 20000000 01000000 1c000000 01000000 -// 11058 + 18 = 11070 func3 -// 11060 + 14 = 11074 func3 + sizeof(func3) -// CHECK-SCRIPT-EXIDX-NEXT: 11058 18000000 01000000 14000000 01000000 +// 11024 - 24 = 11000 func4 +// 1102c - 28 = 11004 func5 +// CHECK-SCRIPT-EXIDX: 11024 dcffff7f 01000000 d8ffff7f 01000000 +// 11034 - 2c = 11008 _start +// 1103c - 30 = 1100c f1 +// CHECK-SCRIPT-EXIDX-NEXT: 11034 d4ffff7f 01000000 d0ffff7f 01000000 +// 11044 - 34 = 11010 f2 +// 1104c - 38 = 11014 f3 +// CHECK-SCRIPT-EXIDX-NEXT: 11044 ccffff7f 01000000 c8ffff7f 01000000 +// 11054 - 3c = 11018 func1 +// 1105c - 40 = 1101c func2 +// CHECK-SCRIPT-EXIDX-NEXT: 11054 c4ffff7f 01000000 c0ffff7f 01000000 +// 11064 - 44 = 11020 func3 +// 11068 - 48 = 11024 func3 + sizeof(func3) +// CHECK-SCRIPT-EXIDX-NEXT: 11064 bcffff7f 01000000 b8ffff7f 01000000 diff --git a/test/ELF/arm-exidx-output.s b/test/ELF/arm-exidx-output.s index dca43a359934..4c65c274b713 100644 --- a/test/ELF/arm-exidx-output.s +++ b/test/ELF/arm-exidx-output.s @@ -1,7 +1,7 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 2>&1 // RUN: llvm-readobj -sections %t2 | FileCheck %s -// REQUIRES: arm // Check that only a single .ARM.exidx output section is created when // there are input sections of the form .ARM.exidx.<section-name>. The diff --git a/test/ELF/arm-exidx-relocatable.s b/test/ELF/arm-exidx-relocatable.s index 1b6ee3f23a4f..422dfc289ed7 100644 --- a/test/ELF/arm-exidx-relocatable.s +++ b/test/ELF/arm-exidx-relocatable.s @@ -1,9 +1,9 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/arm-exidx-cantunwind.s -o %tcantunwind // Check that relocatable link maintains SHF_LINK_ORDER // RUN: ld.lld -r %t %tcantunwind -o %t4 2>&1 // RUN: llvm-readobj -s %t4 | FileCheck %s -// REQUIRES: arm // Each assembler created .ARM.exidx section has the SHF_LINK_ORDER flag set // with the sh_link containing the section index of the executable section diff --git a/test/ELF/arm-exidx-sentinel-norelocatable.s b/test/ELF/arm-exidx-sentinel-norelocatable.s index 4a5b64d8cd18..22e3a09c573f 100644 --- a/test/ELF/arm-exidx-sentinel-norelocatable.s +++ b/test/ELF/arm-exidx-sentinel-norelocatable.s @@ -1,6 +1,6 @@ +// REQUIRES: arm // RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o %t.o // RUN: ld.lld -r %t.o -o %t -// REQUIRES: arm // RUN: llvm-readobj -s %t | FileCheck %s // Check that when doing a relocatable link we don't add a terminating entry // to the .ARM.exidx section diff --git a/test/ELF/arm-exidx-sentinel-orphan.s b/test/ELF/arm-exidx-sentinel-orphan.s index 0e68c245dd10..9aebc4299184 100644 --- a/test/ELF/arm-exidx-sentinel-orphan.s +++ b/test/ELF/arm-exidx-sentinel-orphan.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // Use Linker script without .ARM.exidx Output Section so it is treated as // an orphan. We must still add the sentinel table entry @@ -6,7 +7,6 @@ // RUN: } " > %t.script // RUN: ld.lld --no-merge-exidx-entries --script %t.script %t -o %t2 // RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s -// REQUIRES: arm .syntax unified .text @@ -20,4 +20,4 @@ _start: // CHECK: Contents of section .ARM.exidx: // 11004 - 4 = 0x11000 = _start // 1100c - 8 = 0x11004 = _start + sizeof(_start) -// CHECK-NEXT: 11004 fcffff7f 01000000 f8ffff7f 01000000 +// CHECK-NEXT: 0000 00100100 01000000 fc0f0100 01000000 diff --git a/test/ELF/arm-exidx-shared.s b/test/ELF/arm-exidx-shared.s index bf7c2dc383e7..631eb0711b8d 100644 --- a/test/ELF/arm-exidx-shared.s +++ b/test/ELF/arm-exidx-shared.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 --shared -o %t2 2>&1 // RUN: llvm-readobj --relocations %t2 | FileCheck %s // RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-EXTAB %s -// REQUIRES: arm // Check that the relative R_ARM_PREL31 relocation can access a PLT entry // for when the personality routine is referenced from a shared library. @@ -37,9 +37,9 @@ __aeabi_unwind_cpp_pr0: bx lr // CHECK: Relocations [ -// CHECK-NEXT: Section (6) .rel.plt { +// CHECK-NEXT: Section {{.*}} .rel.plt { // CHECK-NEXT: 0x200C R_ARM_JUMP_SLOT __gxx_personality_v0 // CHECK-EXTAB: Contents of section .ARM.extab: -// 014c + 0ee4 = 0x1030 = __gxx_personality_v0(PLT) -// CHECK-EXTAB-NEXT: 014c e40e0000 b0b0b000 00000000 +// 0x0210 + 0x0e20 = 0x1030 = __gxx_personality_v0(PLT) +// CHECK-EXTAB-NEXT: 0210 200e0000 b0b0b000 00000000 diff --git a/test/ELF/arm-gnu-ifunc-nosym.s b/test/ELF/arm-gnu-ifunc-nosym.s index fa79aef7ced8..b76ede75b4a1 100644 --- a/test/ELF/arm-gnu-ifunc-nosym.s +++ b/test/ELF/arm-gnu-ifunc-nosym.s @@ -1,7 +1,7 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o // RUN: ld.lld -static %t.o -o %tout // RUN: llvm-readobj -symbols %tout | FileCheck %s -// REQUIRES: arm // Check that no __rel_iplt_end/__rel_iplt_start // appear in symtab if there are no references to them. diff --git a/test/ELF/arm-gnu-ifunc-plt.s b/test/ELF/arm-gnu-ifunc-plt.s index 2ff2ec0a143d..441c31c2bb25 100644 --- a/test/ELF/arm-gnu-ifunc-plt.s +++ b/test/ELF/arm-gnu-ifunc-plt.s @@ -1,3 +1,4 @@ +// 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: llvm-mc -filetype=obj -triple=armv7a-linux-gnueabihf %s -o %t.o @@ -5,7 +6,6 @@ // RUN: llvm-objdump -triple=armv7a-linux-gnueabihf -d %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 -// REQUIRES: arm // Check that the IRELATIVE relocations are last in the .got // CHECK: Relocations [ diff --git a/test/ELF/arm-gnu-ifunc.s b/test/ELF/arm-gnu-ifunc.s index 799b8b17f62b..8a7cb0ae237a 100644 --- a/test/ELF/arm-gnu-ifunc.s +++ b/test/ELF/arm-gnu-ifunc.s @@ -1,8 +1,8 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o // RUN: ld.lld -static %t.o -o %tout // RUN: llvm-objdump -triple armv7a-none-linux-gnueabi -d %tout | FileCheck %s --check-prefix=DISASM // RUN: llvm-readobj -r -symbols -sections %tout | FileCheck %s -// REQUIRES: arm .syntax unified .text .type foo STT_GNU_IFUNC diff --git a/test/ELF/arm-gotoff.s b/test/ELF/arm-gotoff.s index 5169f84e6a01..b9432b20df20 100644 --- a/test/ELF/arm-gotoff.s +++ b/test/ELF/arm-gotoff.s @@ -1,8 +1,8 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-linux-gnueabi %s -o %t.o // RUN: ld.lld %t.o -o %t // RUN: llvm-readobj -s -r -t %t | FileCheck %s // RUN: llvm-objdump -triple=armv7a-linux-gnueabi -d %t | FileCheck --check-prefix=DISASM %s -// REQUIRES: arm // Test the R_ARM_GOTOFF32 relocation diff --git a/test/ELF/arm-long-thunk-converge.s b/test/ELF/arm-long-thunk-converge.s new file mode 100644 index 000000000000..dadc7e5fc9a9 --- /dev/null +++ b/test/ELF/arm-long-thunk-converge.s @@ -0,0 +1,29 @@ +// REQUIRES: arm +// RUN: llvm-mc -triple armv7-unknown-gnu -filetype=obj -o %t %s +// RUN: ld.lld %t %S/Inputs/arm-long-thunk-converge.lds -o %t2 +// RUN: llvm-objdump -d -start-address=0x00000000 -stop-address=0x00000010 -triple=armv7a-linux-gnueabihf %t2 | FileCheck --check-prefix=CHECK1 %s +// RUN: llvm-objdump -d -start-address=0x02000000 -stop-address=0x02000010 -triple=armv7a-linux-gnueabihf %t2 | FileCheck --check-prefix=CHECK2 %s +// RUN: rm -f %t2 + +// CHECK1: __ARMv7ABSLongThunk_bar: +// CHECK1-NEXT: 0: 0c c0 00 e3 movw r12, #12 +// CHECK1-NEXT: 4: 00 c2 40 e3 movt r12, #512 +// CHECK1-NEXT: 8: 1c ff 2f e1 bx r12 +// CHECK1: foo: +// CHECK1-NEXT: c: fb ff ff eb bl #-20 + +.section .foo,"ax",%progbits,unique,1 +foo: +bl bar + +// CHECK2: __ARMv7ABSLongThunk_foo: +// CHECK2-NEXT: 2000000: 0c c0 00 e3 movw r12, #12 +// CHECK2-NEXT: 2000004: 00 c0 40 e3 movt r12, #0 +// CHECK2-NEXT: 2000008: 1c ff 2f e1 bx r12 +// CHECK2: bar: +// CHECK2-NEXT: 200000c: fb ff ff eb bl #-20 <__ARMv7ABSLongThunk_foo> + +.section .bar,"ax",%progbits,unique,1 +bar: +bl foo +.zero 0x1000000 diff --git a/test/ELF/arm-mov-relocs.s b/test/ELF/arm-mov-relocs.s index 7e3ce67e0615..f49e2c102e40 100644 --- a/test/ELF/arm-mov-relocs.s +++ b/test/ELF/arm-mov-relocs.s @@ -1,10 +1,10 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-unknown-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 // RUN: llvm-objdump -d %t2 -triple=armv7a-unknown-linux-gnueabi | FileCheck %s // RUN: llvm-mc -filetype=obj -triple=thumbv7a-unknown-linux-gnueabi %s -o %t3 // RUN: ld.lld %t3 -o %t4 // RUN: llvm-objdump -d %t4 -triple=thumbv7a-unknown-linux-gnueabi | FileCheck %s -// REQUIRES: arm // Test the R_ARM_MOVW_ABS_NC and R_ARM_MOVT_ABS relocations as well as // the R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_ABS relocations. diff --git a/test/ELF/arm-pie-relative.s b/test/ELF/arm-pie-relative.s index f225015eb5f3..582bb8aa03d2 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 -// REQUIRES: arm // Test that a R_ARM_GOT_BREL relocation with PIE results in a R_ARM_RELATIVE // dynamic relocation diff --git a/test/ELF/arm-plt-reloc.s b/test/ELF/arm-plt-reloc.s index f8166d60ffcf..347bc87f6655 100644 --- a/test/ELF/arm-plt-reloc.s +++ b/test/ELF/arm-plt-reloc.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %p/Inputs/arm-plt-reloc.s -o %t1 // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t2 // RUN: ld.lld %t1 %t2 -o %t @@ -5,7 +6,6 @@ // RUN: ld.lld --hash-style=sysv -shared %t1 %t2 -o %t3 // RUN: llvm-objdump -triple=armv7a-none-linux-gnueabi -d %t3 | FileCheck -check-prefix=DSO %s // RUN: llvm-readobj -s -r %t3 | FileCheck -check-prefix=DSOREL %s -// REQUIRES: arm // // Test PLT entry generation .syntax unified @@ -96,7 +96,7 @@ _start: // DSOREL-NEXT: AddressAlignment: 4 // DSOREL-NEXT: EntrySize: // DSOREL: Relocations [ -// DSOREL-NEXT: Section (4) .rel.plt { +// DSOREL-NEXT: Section {{.*}} .rel.plt { // DSOREL-NEXT: 0x200C R_ARM_JUMP_SLOT func1 0x0 // DSOREL-NEXT: 0x2010 R_ARM_JUMP_SLOT func2 0x0 // DSOREL-NEXT: 0x2014 R_ARM_JUMP_SLOT func3 0x0 @@ -162,7 +162,7 @@ _start: // DSORELHIGH-NEXT: ] // DSORELHIGH-NEXT: Address: 0x1100000 // DSORELHIGH: Relocations [ -// DSORELHIGH-NEXT: Section (6) .rel.plt { +// DSORELHIGH-NEXT: Section {{.*}} .rel.plt { // DSORELHIGH-NEXT: 0x110000C R_ARM_JUMP_SLOT func1 0x0 // DSORELHIGH-NEXT: 0x1100010 R_ARM_JUMP_SLOT func2 0x0 // DSORELHIGH-NEXT: 0x1100014 R_ARM_JUMP_SLOT func3 0x0 @@ -227,7 +227,7 @@ _start: // DSORELLONG-NEXT: ] // DSORELLONG-NEXT: Address: 0x11111100 // DSORELLONG: Relocations [ -// DSORELLONG-NEXT: Section (6) .rel.plt { +// DSORELLONG-NEXT: Section {{.*}} .rel.plt { // DSORELLONG-NEXT: 0x1111110C R_ARM_JUMP_SLOT func1 0x0 // DSORELLONG-NEXT: 0x11111110 R_ARM_JUMP_SLOT func2 0x0 // DSORELLONG-NEXT: 0x11111114 R_ARM_JUMP_SLOT func3 0x0 @@ -292,7 +292,7 @@ _start: // DSORELMIX-NEXT: SHF_WRITE // DSORELMIX-NEXT: ] // DSORELMIX-NEXT: Address: 0x8002020 -// DSORELMIX: Section (6) .rel.plt { +// DSORELMIX: Section {{.*}} .rel.plt { // DSORELMIX-NEXT: 0x800202C R_ARM_JUMP_SLOT func1 0x0 // DSORELMIX-NEXT: 0x8002030 R_ARM_JUMP_SLOT func2 0x0 // DSORELMIX-NEXT: 0x8002034 R_ARM_JUMP_SLOT func3 0x0 diff --git a/test/ELF/arm-sbrel32.s b/test/ELF/arm-sbrel32.s index 7f12717195a9..064f59bbd3fe 100644 --- a/test/ELF/arm-sbrel32.s +++ b/test/ELF/arm-sbrel32.s @@ -1,7 +1,7 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 2>&1 // RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s -// REQUIRES: arm // Test the R_ARM_SBREL32 relocation which calculates the offset of the Symbol // from the static base. We define the static base to be the address of the diff --git a/test/ELF/arm-static-defines.s b/test/ELF/arm-static-defines.s index 815c20ca9451..4487ecdc2925 100644 --- a/test/ELF/arm-static-defines.s +++ b/test/ELF/arm-static-defines.s @@ -1,7 +1,7 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld --no-merge-exidx-entries %t --static -o %t2 2>&1 // RUN: llvm-readobj --symbols %t2 | FileCheck %s -// REQUIRES: arm // Check that on ARM we don't get a multiply defined symbol for __tls_get_addr // and undefined symbols for references to __exidx_start and __exidx_end diff --git a/test/ELF/arm-symbol-ordering-file.s b/test/ELF/arm-symbol-ordering-file.s new file mode 100644 index 000000000000..fe3de0d9d013 --- /dev/null +++ b/test/ELF/arm-symbol-ordering-file.s @@ -0,0 +1,32 @@ +# REQUIRES: arm +# RUN: llvm-mc -filetype=obj -triple=armv7-unknown-linux %s -o %t.o + +# RUN: echo ordered > %t_order.txt +# RUN: ld.lld --symbol-ordering-file %t_order.txt %t.o -o %t2.out +# RUN: llvm-nm -n %t2.out | FileCheck %s + +# CHECK: unordered1 +# CHECK-NEXT: unordered2 +# CHECK-NEXT: unordered3 +# CHECK-NEXT: ordered +# CHECK-NEXT: unordered4 + +.section .foo,"ax",%progbits,unique,1 +unordered1: +.zero 1 + +.section .foo,"ax",%progbits,unique,2 +unordered2: +.zero 1 + +.section .foo,"ax",%progbits,unique,3 +unordered3: +.zero 2 + +.section .foo,"ax",%progbits,unique,4 +unordered4: +.zero 4 + +.section .foo,"ax",%progbits,unique,5 +ordered: +.zero 1 diff --git a/test/ELF/arm-target1.s b/test/ELF/arm-target1.s index e77fa57bbf16..2fc0b8bc4281 100644 --- a/test/ELF/arm-target1.s +++ b/test/ELF/arm-target1.s @@ -31,6 +31,6 @@ // RELATIVE: SYMBOL TABLE: // RELATIVE: 00001004 .text 00000000 patatino -// ABS: can't create dynamic relocation R_ARM_TARGET1 against symbol: 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 // ABS: >>> referenced by {{.*}}.o:(.text+0x0) diff --git a/test/ELF/arm-target2.s b/test/ELF/arm-target2.s index a678f7e08fdf..4dbcde88ec31 100644 --- a/test/ELF/arm-target2.s +++ b/test/ELF/arm-target2.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o // RUN: ld.lld %t.o -o %t 2>&1 // RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t | FileCheck %s @@ -7,7 +8,6 @@ // RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t3 | FileCheck -check-prefix=CHECK-ABS %s // RUN: ld.lld %t.o --target2=rel -o %t4 2>&1 // RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t4 | FileCheck -check-prefix=CHECK-REL %s -// REQUIRES: arm // The R_ARM_TARGET2 is present in .ARM.extab sections. It can be handled as // either R_ARM_ABS32, R_ARM_REL32 or R_ARM_GOT_PREL. For ARM linux the default @@ -35,16 +35,16 @@ __gxx_personality_v0: _ZTIi: .word 0 // CHECK: Contents of section .ARM.extab: -// 1011c + 1ee4 = 12000 = .got -// CHECK-NEXT: 10114 f00e0000 b0b0b000 e41e0000 +// 0x1012c + 0x1ed4 = 0x12000 = .got +// CHECK-NEXT: 10124 e00e0000 b0b0b000 d41e0000 // CHECK-ABS: Contents of section .ARM.extab: -// 100f0 = .rodata -// CHECK-ABS-NEXT: 100d4 300f0000 b0b0b000 f0000100 +// 0x100f0 = .rodata +// CHECK-ABS-NEXT: 100e4 200f0000 b0b0b000 f0000100 // CHECK-REL: Contents of section .ARM.extab: -// 100dc + c = 100e8 = .rodata -// CHECK-REL-NEXT: 100d4 300f0000 b0b0b000 14000000 +// 0x100ec + 4 = 0x100f0 = .rodata +// CHECK-REL-NEXT: 100e4 200f0000 b0b0b000 04000000 // CHECK: Contents of section .rodata: // CHECK-NEXT: 10130 00000000 diff --git a/test/ELF/arm-thumb-blx.s b/test/ELF/arm-thumb-blx.s index d79bef1835e3..5316d13dbc28 100644 --- a/test/ELF/arm-thumb-blx.s +++ b/test/ELF/arm-thumb-blx.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %S/Inputs/arm-thumb-blx-targets.s -o %ttarget // RUN: echo "SECTIONS { \ @@ -9,7 +10,6 @@ // RUN: ld.lld --script %t.script %t %ttarget -o %t2 2>&1 // 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 -// REQUIRES: arm // 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 diff --git a/test/ELF/arm-thumb-branch-rangethunk.s b/test/ELF/arm-thumb-branch-rangethunk.s index f83e64144d70..4bbd69214e93 100644 --- a/test/ELF/arm-thumb-branch-rangethunk.s +++ b/test/ELF/arm-thumb-branch-rangethunk.s @@ -1,8 +1,8 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %S/Inputs/far-arm-thumb-abs.s -o %tfar // RUN: ld.lld %t %tfar -o %t2 2>&1 // RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t2 -// REQUIRES: arm .syntax unified .thumb .section .text, "ax",%progbits diff --git a/test/ELF/arm-thumb-branch.s b/test/ELF/arm-thumb-branch.s index 81bf7a3c68a9..89c081a69b88 100644 --- a/test/ELF/arm-thumb-branch.s +++ b/test/ELF/arm-thumb-branch.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %S/Inputs/far-arm-thumb-abs.s -o %tfar // RUN: echo "SECTIONS { \ @@ -7,7 +8,6 @@ // RUN: .callee2 : { *(.callee_high) } } " > %t.script // RUN: ld.lld --script %t.script %t %tfar -o %t2 2>&1 // RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t2 | FileCheck %s -// REQUIRES: arm .syntax unified .thumb diff --git a/test/ELF/arm-thumb-condbranch-thunk.s b/test/ELF/arm-thumb-condbranch-thunk.s index c527e5df297c..c9365efb73a7 100644 --- a/test/ELF/arm-thumb-condbranch-thunk.s +++ b/test/ELF/arm-thumb-condbranch-thunk.s @@ -38,13 +38,9 @@ _start: // CHECK1-NEXT: 80000: 70 47 bx lr // CHECK1-NEXT: 80002: 7f f3 ff d7 bl #16252926 // CHECK1: __Thumbv7ABSLongThunk_tfunc05: -// CHECK1-NEXT: 80008: 40 f2 01 0c movw r12, #1 -// CHECK1-NEXT: 8000c: c0 f2 30 0c movt r12, #48 -// CHECK1-NEXT: 80010: 60 47 bx r12 +// CHECK1-NEXT: 80008: 7f f2 fa bf b.w #2621428 <tfunc05> // CHECK1: __Thumbv7ABSLongThunk_tfunc00: -// CHECK1-NEXT: 80012: 40 f2 01 0c movw r12, #1 -// CHECK1-NEXT: 80016: c0 f2 08 0c movt r12, #8 -// CHECK1-NEXT: 8001a: 60 47 bx r12 +// CHECK1-NEXT: 8000c: ff f7 f8 bf b.w #-16 <tfunc00> FUNCTION 01 // tfunc02 is within range of tfunc02 beq.w tfunc02 @@ -61,7 +57,7 @@ _start: beq.w tfunc00 // CHECK3: 180000: 70 47 bx lr // CHECK3-NEXT: 180002: 40 f4 01 80 bne.w #-1048574 <__Thumbv7ABSLongThunk_tfunc05> -// CHECK3-NEXT: 180006: 00 f4 04 80 beq.w #-1048568 <__Thumbv7ABSLongThunk_tfunc00> +// CHECK3-NEXT: 180006: 00 f4 01 80 beq.w #-1048574 <__Thumbv7ABSLongThunk_tfunc00> FUNCTION 03 FUNCTION 04 FUNCTION 05 @@ -70,9 +66,7 @@ _start: FUNCTION 08 FUNCTION 09 // CHECK4: __Thumbv7ABSLongThunk_tfunc03: -// CHECK4-NEXT: 500004: 40 f2 01 0c movw r12, #1 -// CHECK4-NEXT: 500008: c0 f2 20 0c movt r12, #32 -// CHECK4-NEXT: 50000c: 60 47 bx r12 +// CHECK4-NEXT: 500004: ff f4 fc bf b.w #-3145736 <tfunc03> FUNCTION 10 // We can't reach any Thunk Section, create a new one beq.w tfunc03 @@ -101,17 +95,13 @@ _start: FUNCTION 30 FUNCTION 31 // CHECK6: __Thumbv7ABSLongThunk_tfunc33: -// CHECK6-NEXT: 1000004: 40 f2 01 0c movw r12, #1 -// CHECK6-NEXT: 1000008: c0 f2 10 1c movt r12, #272 -// CHECK6-NEXT: 100000c: 60 47 bx r12 +// CHECK6-NEXT: 1000004: ff f0 fc bf b.w #1048568 <tfunc33> // CHECK6: __Thumbv7ABSLongThunk_tfunc00: -// CHECK6-NEXT: 100000e: 40 f2 01 0c movw r12, #1 -// CHECK6-NEXT: 1000012: c0 f2 08 0c movt r12, #8 -// CHECK6-NEXT: 1000016: 60 47 bx r12 +// CHECK6-NEXT: 1000008: 7f f4 fa 97 b.w #-16252940 <tfunc00> FUNCTION 32 FUNCTION 33 // We should be able to reach an existing ThunkSection. b.w tfunc00 // CHECK7: tfunc33: // CHECK7-NEXT: 1100000: 70 47 bx lr -// CHECK7-NEXT: 1100002: 00 f7 04 b8 b.w #-1048568 <__Thumbv7ABSLongThunk_tfunc00> +// CHECK7-NEXT: 1100002: 00 f7 01 b8 b.w #-1048574 <__Thumbv7ABSLongThunk_tfunc00> diff --git a/test/ELF/arm-thumb-interwork-shared.s b/test/ELF/arm-thumb-interwork-shared.s index cadcd451ad67..030ac29854b2 100644 --- a/test/ELF/arm-thumb-interwork-shared.s +++ b/test/ELF/arm-thumb-interwork-shared.s @@ -1,8 +1,8 @@ +// REQUIRES: arm // RUN: llvm-mc -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 -// REQUIRES: arm .syntax unified .global sym1 .global elsewhere diff --git a/test/ELF/arm-thumb-interwork-thunk-range.s b/test/ELF/arm-thumb-interwork-thunk-range.s index db674f4d5f7c..d59ee1159920 100644 --- a/test/ELF/arm-thumb-interwork-thunk-range.s +++ b/test/ELF/arm-thumb-interwork-thunk-range.s @@ -1,6 +1,6 @@ // REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o -// RUN: ld.lld %t.o -o %t -image-base=0x80000000 +// RUN: ld.lld %t.o -o /dev/null -image-base=0x80000000 // Test that when the thunk is at a high address we don't get confused with it // being out of range. diff --git a/test/ELF/arm-thumb-interwork-thunk.s b/test/ELF/arm-thumb-interwork-thunk.s index 04755c4603cc..df5d6c6b7401 100644 --- a/test/ELF/arm-thumb-interwork-thunk.s +++ b/test/ELF/arm-thumb-interwork-thunk.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: echo "SECTIONS { \ // RUN: . = SIZEOF_HEADERS; \ @@ -8,7 +9,7 @@ // RUN: .thumb_caller : { *(.thumb_caller) } \ // RUN: .R_ARM_JUMP24_callee_2 : { *(.R_ARM_JUMP24_callee_high) } \ // RUN: .R_ARM_THM_JUMP_callee_2 : { *(.R_ARM_THM_JUMP_callee_high) } \ -// RUN: .got.plt 0x1894 : { } } " > %t.script +// RUN: .got.plt 0x18b4 : { } } " > %t.script // RUN: ld.lld --script %t.script %t -o %t2 2>&1 // RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-THUMB -check-prefix=CHECK-ABS-THUMB %s // RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-ARM -check-prefix=CHECK-ABS-ARM %s @@ -19,7 +20,6 @@ // RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t4 | FileCheck -check-prefix=CHECK-THUMB -check-prefix=CHECK-PI-PLT-THUMB %s // RUN: llvm-objdump -d -triple=armv7a-none-linux-gnueabi %t4 | FileCheck -check-prefix=CHECK-ARM -check-prefix=CHECK-PI-PLT-ARM %s // RUN: llvm-readobj -s -r %t4 | FileCheck -check-prefix=CHECK-DSO-REL %s -// REQUIRES: arm // Test ARM Thumb Interworking // The file is linked and checked 3 times to check the following contexts @@ -368,11 +368,11 @@ _start: // CHECK-PI-ARM-PLT-NEXT: 183c: 00 f0 9c e5 ldr pc, [r12] // CHECK-PI-ARM-PLT-NEXT: 1840: 7c 00 00 00 -// CHECK-DSO-REL: 0x18A0 R_ARM_JUMP_SLOT arm_caller -// CHECK-DSO-REL-NEXT: 0x18A4 R_ARM_JUMP_SLOT thumb_caller -// CHECK-DSO-REL-NEXT: 0x18A8 R_ARM_JUMP_SLOT thumb_callee1 -// CHECK-DSO-REL-NEXT: 0x18AC R_ARM_JUMP_SLOT thumb_callee2 -// CHECK-DSO-REL-NEXT: 0x18B0 R_ARM_JUMP_SLOT thumb_callee3 -// CHECK-DSO-REL-NEXT: 0x18B4 R_ARM_JUMP_SLOT arm_callee1 -// CHECK-DSO-REL-NEXT: 0x18B8 R_ARM_JUMP_SLOT arm_callee2 -// CHECK-DSO-REL-NEXT: 0x18BC R_ARM_JUMP_SLOT arm_callee3 +// CHECK-DSO-REL: 0x18C0 R_ARM_JUMP_SLOT arm_caller +// CHECK-DSO-REL-NEXT: 0x18C4 R_ARM_JUMP_SLOT thumb_caller +// CHECK-DSO-REL-NEXT: 0x18C8 R_ARM_JUMP_SLOT thumb_callee1 +// CHECK-DSO-REL-NEXT: 0x18CC R_ARM_JUMP_SLOT thumb_callee2 +// CHECK-DSO-REL-NEXT: 0x18D0 R_ARM_JUMP_SLOT thumb_callee3 +// CHECK-DSO-REL-NEXT: 0x18D4 R_ARM_JUMP_SLOT arm_callee1 +// CHECK-DSO-REL-NEXT: 0x18D8 R_ARM_JUMP_SLOT arm_callee2 +// CHECK-DSO-REL-NEXT: 0x18DC R_ARM_JUMP_SLOT arm_callee3 diff --git a/test/ELF/arm-thumb-mix-range-thunk-os.s b/test/ELF/arm-thumb-mix-range-thunk-os.s index beff4148b6ff..b5db2565f2c9 100644 --- a/test/ELF/arm-thumb-mix-range-thunk-os.s +++ b/test/ELF/arm-thumb-mix-range-thunk-os.s @@ -11,7 +11,7 @@ // RUN: llvm-objdump -d %t2 -start-address=35651584 -stop-address=35651590 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK6 %s // RUN: llvm-objdump -d %t2 -start-address=36700160 -stop-address=36700168 -triple=armv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK7 %s // RUN: llvm-objdump -d %t2 -start-address=48234500 -stop-address=48234512 -triple=armv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK8 %s -// RUN: llvm-objdump -d %t2 -start-address=63963140 -stop-address=63963160 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK9 %s +// RUN: llvm-objdump -d %t2 -start-address=53477380 -stop-address=53477392 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK9 %s // RUN: llvm-objdump -d %t2 -start-address=68157440 -stop-address=68157452 -triple=armv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK10 %s // RUN: llvm-objdump -d %t2 -start-address=69206016 -stop-address=69206024 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK11 %s @@ -155,6 +155,13 @@ _start: ARMFUNCTION 48 THUMBFUNCTION 49 ARMFUNCTION 50 +// Expect precreated Thunk Section here +// CHECK9: __Thumbv7ABSLongThunk_afunc34: +// CHECK9-NEXT: 3300004: 40 f2 00 0c movw r12, #0 +// CHECK9-NEXT: 3300008: c0 f2 30 2c movt r12, #560 +// CHECK9-NEXT: 330000c: 60 47 bx r12 +// CHECK9: __Thumbv7ABSLongThunk_tfunc35: +// CHECK9-NEXT: 330000e: ff f4 f7 97 b.w #-15728658 <tfunc35> THUMBFUNCTION 51 ARMFUNCTION 52 THUMBFUNCTION 53 @@ -165,15 +172,6 @@ _start: ARMFUNCTION 58 THUMBFUNCTION 59 ARMFUNCTION 60 -// Expect precreated Thunk Section here -// CHECK9: __Thumbv7ABSLongThunk_afunc34: -// CHECK9-NEXT: 3d00004: 40 f2 00 0c movw r12, #0 -// CHECK9-NEXT: 3d00008: c0 f2 30 2c movt r12, #560 -// CHECK9-NEXT: 3d0000c: 60 47 bx r12 -// CHECK9: __Thumbv7ABSLongThunk_tfunc35: -// CHECK9-NEXT: 3d0000e: 40 f2 01 0c movw r12, #1 -// CHECK9-NEXT: 3d00012: c0 f2 40 2c movt r12, #576 -// CHECK9-NEXT: 3d00016: 60 47 bx r12 THUMBFUNCTION 61 ARMFUNCTION 62 THUMBFUNCTION 63 @@ -191,5 +189,5 @@ _start: bl tfunc35 // CHECK11: tfunc65: // CHECK11: 4200000: 70 47 bx lr -// CHECK11-NEXT: 4200002: ff f6 ff f7 bl #-5242882 -// CHECK11-NEXT: 4200006: 00 f7 02 f0 bl #-5242876 +// CHECK11-NEXT: 4200002: ff f4 ff d7 bl #-15728642 +// CHECK11-NEXT: 4200006: 00 f5 02 d0 bl #-15728636 diff --git a/test/ELF/arm-thumb-narrow-branch-check.s b/test/ELF/arm-thumb-narrow-branch-check.s index 82a7164f6df6..27bac59787e1 100644 --- a/test/ELF/arm-thumb-narrow-branch-check.s +++ b/test/ELF/arm-thumb-narrow-branch-check.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: echo "SECTIONS { \ // RUN: . = SIZEOF_HEADERS; \ @@ -7,7 +8,6 @@ // RUN: .text : { *(.text) } } " > %t.script // RUN: ld.lld --script %t.script %t %S/Inputs/arm-thumb-narrow-branch.o -o %t2 2>&1 // RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t2 | FileCheck %s -// REQUIRES: arm // Test the R_ARM_PC11 relocation which is used with the narrow encoding of B.N // the source of these relocations is a binary file arm-thumb-narrow-branch.o diff --git a/test/ELF/arm-thumb-no-undefined-thunk.s b/test/ELF/arm-thumb-no-undefined-thunk.s index e8d8d8db684c..5456e7639498 100644 --- a/test/ELF/arm-thumb-no-undefined-thunk.s +++ b/test/ELF/arm-thumb-no-undefined-thunk.s @@ -1,7 +1,7 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 2>&1 // RUN: llvm-objdump -triple=thumbv7a-none-linux-gnueabi -d %t2 | FileCheck %s -// REQUIRES: arm // Check that no thunks are created for an undefined weak symbol .syntax unified diff --git a/test/ELF/arm-thumb-plt-range-thunk-os.s b/test/ELF/arm-thumb-plt-range-thunk-os.s index f412faa98eca..080160bb2474 100644 --- a/test/ELF/arm-thumb-plt-range-thunk-os.s +++ b/test/ELF/arm-thumb-plt-range-thunk-os.s @@ -1,12 +1,12 @@ // REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t -// RUN: ld.lld %t --shared -o %t.so +// RUN: ld.lld %t --shared --icf=all -o %t.so // The output file is large, most of it zeroes. We dissassemble only the // parts we need to speed up the test and avoid a large output file -// RUN: llvm-objdump -d %t.so -start-address=8388608 -stop-address=8388624 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK1 %s -// RUN: llvm-objdump -d %t.so -start-address=16777216 -stop-address=16777256 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK2 %s -// RUN: llvm-objdump -d %t.so -start-address=25165824 -stop-address=25165828 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK3 %s -// RUN: llvm-objdump -d %t.so -start-address=25165828 -stop-address=25165924 -triple=armv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK4 %s +// RUN: llvm-objdump -d %t.so -start-address=0x2000000 -stop-address=0x2000018 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK1 %s +// RUN: llvm-objdump -d %t.so -start-address=0x2800004 -stop-address=0x2800034 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK2 %s +// RUN: llvm-objdump -d %t.so -start-address=0x4000000 -stop-address=0x4000010 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK3 %s +// RUN: llvm-objdump -d %t.so -start-address=0x4000010 -stop-address=0x4000100 -triple=armv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK4 %s .syntax unified .thumb @@ -19,74 +19,96 @@ .type preemptible, %function .global far_preemptible .type far_preemptible, %function + .global far_nonpreemptible + .hidden far_nonpreemptible + .type far_nonpreemptible, %function + .global far_nonpreemptible_alias + .hidden far_nonpreemptible_alias + .type far_nonpreemptible_alias, %function sym1: bl elsewhere bl preemptible bx lr preemptible: bl far_preemptible + bl far_nonpreemptible + bl far_nonpreemptible_alias bx lr // CHECK1: Disassembly of section .text: // CHECK1-NEXT: sym1: -// CHECK1-NEXT: 800000: 00 f0 00 d8 bl #8388608 -// CHECK1-NEXT: 800004: 00 f0 04 d8 bl #8388616 -// CHECK1-NEXT: 800008: 70 47 bx lr +// CHECK1-NEXT: 2000000: 00 f0 00 d8 bl #8388608 +// CHECK1-NEXT: 2000004: 00 f0 04 d8 bl #8388616 +// CHECK1-NEXT: 2000008: 70 47 bx lr // CHECK1: preemptible: -// CHECK1-NEXT: 80000a: 00 f0 07 d8 bl #8388622 -// CHECK1-NEXT: 80000e: 70 47 bx lr +// CHECK1-NEXT: 200000a: 00 f0 07 d8 bl #8388622 +// CHECK1-NEXT: 200000e: 00 f0 0b d8 bl #8388630 +// CHECK1-NEXT: 2000012: 00 f0 09 d8 bl #8388626 +// CHECK1-NEXT: 2000016: 70 47 bx lr .section .text.2, "ax", %progbits .balign 0x0800000 bx lr // CHECK2: __ThumbV7PILongThunk_elsewhere: -// CHECK2-NEXT: 1000004: 40 f2 20 0c movw r12, #32 -// CHECK2-NEXT: 1000008: c0 f2 80 0c movt r12, #128 -// CHECK2-NEXT: 100000c: fc 44 add r12, pc -// CHECK2-NEXT: 100000e: 60 47 bx r12 +// CHECK2-NEXT: 2800004: 40 f2 20 0c movw r12, #32 +// CHECK2-NEXT: 2800008: c0 f2 80 1c movt r12, #384 +// CHECK2-NEXT: 280000c: fc 44 add r12, pc +// CHECK2-NEXT: 280000e: 60 47 bx r12 // CHECK2: __ThumbV7PILongThunk_preemptible: -// CHECK2-NEXT: 1000010: 40 f2 24 0c movw r12, #36 -// CHECK2-NEXT: 1000014: c0 f2 80 0c movt r12, #128 -// CHECK2-NEXT: 1000018: fc 44 add r12, pc -// CHECK2-NEXT: 100001a: 60 47 bx r12 +// CHECK2-NEXT: 2800010: 40 f2 24 0c movw r12, #36 +// CHECK2-NEXT: 2800014: c0 f2 80 1c movt r12, #384 +// CHECK2-NEXT: 2800018: fc 44 add r12, pc +// CHECK2-NEXT: 280001a: 60 47 bx r12 // CHECK2: __ThumbV7PILongThunk_far_preemptible: -// CHECK2-NEXT: 100001c: 40 f2 28 0c movw r12, #40 -// CHECK2-NEXT: 1000020: c0 f2 80 0c movt r12, #128 -// CHECK2-NEXT: 1000024: fc 44 add r12, pc -// CHECK2-NEXT: 1000026: 60 47 bx r12 +// CHECK2-NEXT: 280001c: 40 f2 28 0c movw r12, #40 +// CHECK2-NEXT: 2800020: c0 f2 80 1c movt r12, #384 +// CHECK2-NEXT: 2800024: fc 44 add r12, pc +// CHECK2-NEXT: 2800026: 60 47 bx r12 +// CHECK2: __ThumbV7PILongThunk_far_nonpreemptible: +// CHECK2-NEXT: 2800028: 4f f6 cd 7c movw r12, #65485 +// CHECK2-NEXT: 280002c: c0 f2 7f 1c movt r12, #383 +// CHECK2-NEXT: 2800030: fc 44 add r12, pc +// CHECK2-NEXT: 2800032: 60 47 bx r12 .section .text.3, "ax", %progbits -.balign 0x0800000 +.balign 0x2000000 far_preemptible: +far_nonpreemptible: bl elsewhere + + .section .text.4, "ax", %progbits +.balign 0x2000000 +far_nonpreemptible_alias: + bl elsewhere + // CHECK3: far_preemptible: -// CHECK3: 1800000: 00 f0 16 e8 blx #44 +// CHECK3: 4000000: 00 f0 16 e8 blx #44 // CHECK4: Disassembly of section .plt: // CHECK4-NEXT: $a: -// CHECK4-NEXT: 1800010: 04 e0 2d e5 str lr, [sp, #-4]! -// CHECK4-NEXT: 1800014: 00 e6 8f e2 add lr, pc, #0, #12 -// CHECK4-NEXT: 1800018: 00 ea 8e e2 add lr, lr, #0, #20 -// CHECK4-NEXT: 180001c: ec ff be e5 ldr pc, [lr, #4076]! +// 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: 00 ea 8e e2 add lr, lr, #0, #20 +// CHECK4-NEXT: 400001c: ec ff be e5 ldr pc, [lr, #4076]! // CHECK4: $d: -// CHECK4-NEXT: 1800020: d4 d4 d4 d4 .word 0xd4d4d4d4 -// CHECK4-NEXT: 1800024: d4 d4 d4 d4 .word 0xd4d4d4d4 -// CHECK4-NEXT: 1800028: d4 d4 d4 d4 .word 0xd4d4d4d4 -// CHECK4-NEXT: 180002c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK4-NEXT: 4000020: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK4-NEXT: 4000024: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK4-NEXT: 4000028: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK4-NEXT: 400002c: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK4: $a: -// CHECK4-NEXT: 1800030: 00 c6 8f e2 add r12, pc, #0, #12 -// CHECK4-NEXT: 1800034: 00 ca 8c e2 add r12, r12, #0, #20 -// CHECK4-NEXT: 1800038: d4 ff bc e5 ldr pc, [r12, #4052]! +// CHECK4-NEXT: 4000030: 00 c6 8f e2 add r12, pc, #0, #12 +// CHECK4-NEXT: 4000034: 00 ca 8c e2 add r12, r12, #0, #20 +// CHECK4-NEXT: 4000038: d4 ff bc e5 ldr pc, [r12, #4052]! // CHECK4: $d: -// CHECK4-NEXT: 180003c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK4-NEXT: 400003c: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK4: $a: -// CHECK4-NEXT: 1800040: 00 c6 8f e2 add r12, pc, #0, #12 -// CHECK4-NEXT: 1800044: 00 ca 8c e2 add r12, r12, #0, #20 -// CHECK4-NEXT: 1800048: c8 ff bc e5 ldr pc, [r12, #4040]! +// CHECK4-NEXT: 4000040: 00 c6 8f e2 add r12, pc, #0, #12 +// CHECK4-NEXT: 4000044: 00 ca 8c e2 add r12, r12, #0, #20 +// CHECK4-NEXT: 4000048: c8 ff bc e5 ldr pc, [r12, #4040]! // CHECK4: $d: -// CHECK4-NEXT: 180004c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// CHECK4-NEXT: 400004c: d4 d4 d4 d4 .word 0xd4d4d4d4 // CHECK4: $a: -// CHECK4-NEXT: 1800050: 00 c6 8f e2 add r12, pc, #0, #12 -// CHECK4-NEXT: 1800054: 00 ca 8c e2 add r12, r12, #0, #20 -// CHECK4-NEXT: 1800058: bc ff bc e5 ldr pc, [r12, #4028]! +// CHECK4-NEXT: 4000050: 00 c6 8f e2 add r12, pc, #0, #12 +// CHECK4-NEXT: 4000054: 00 ca 8c e2 add r12, r12, #0, #20 +// CHECK4-NEXT: 4000058: bc ff bc e5 ldr pc, [r12, #4028]! // CHECK4: $d: -// CHECK4-NEXT: 180005c: d4 d4 d4 d4 .word 0xd4d4d4d4 +// 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 dd8770edc3c1..742e95994fff 100644 --- a/test/ELF/arm-thumb-plt-reloc.s +++ b/test/ELF/arm-thumb-plt-reloc.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %p/Inputs/arm-plt-reloc.s -o %t1 // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t2 // RUN: ld.lld %t1 %t2 -o %t @@ -6,7 +7,6 @@ // 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 -// REQUIRES: arm // // Test PLT entry generation .syntax unified diff --git a/test/ELF/arm-thumb-range-thunk-os.s b/test/ELF/arm-thumb-range-thunk-os.s index 588539ddab8c..182b18d79cae 100644 --- a/test/ELF/arm-thumb-range-thunk-os.s +++ b/test/ELF/arm-thumb-range-thunk-os.s @@ -9,8 +9,8 @@ // RUN: llvm-objdump -d %t2 -start-address=4194304 -stop-address=4194310 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK4 %s // RUN: llvm-objdump -d %t2 -start-address=16777216 -stop-address=16777270 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK5 %s // RUN: llvm-objdump -d %t2 -start-address=17825792 -stop-address=17825808 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK6 %s -// RUN: llvm-objdump -d %t2 -start-address=31457280 -stop-address=31457286 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK7 %s -// RUN: llvm-objdump -d %t2 -start-address=32505860 -stop-address=32505880 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK8 %s +// RUN: llvm-objdump -d %t2 -start-address=20971524 -stop-address=20971532 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK7 %s +// RUN: llvm-objdump -d %t2 -start-address=31457280 -stop-address=31457286 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK8 %s // RUN: llvm-objdump -d %t2 -start-address=35651584 -stop-address=35651594 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK9 %s // RUN: llvm-objdump -d %t2 -start-address=36700160 -stop-address=36700170 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK10 %s @@ -60,7 +60,7 @@ _start: b.w tfunc28 // CHECK4: tfunc02: // CHECK4-NEXT: 400000: 70 47 bx lr -// CHECK4-NEXT: 400002: 00 f0 04 90 b.w #12582920 <__Thumbv7ABSLongThunk_tfunc28> +// CHECK4-NEXT: 400002: 00 f0 01 90 b.w #12582914 <__Thumbv7ABSLongThunk_tfunc28> FUNCTION 03 FUNCTION 04 FUNCTION 05 @@ -75,25 +75,19 @@ _start: FUNCTION 14 // Expect precreated ThunkSection here // CHECK5: __Thumbv7ABSLongThunk_tfunc16: -// CHECK5-NEXT: 1000004: 40 f2 01 0c movw r12, #1 -// CHECK5-NEXT: 1000008: c0 f2 20 1c movt r12, #288 -// CHECK5-NEXT: 100000c: 60 47 bx r12 +// CHECK5-NEXT: 1000004: ff f1 fc bf b.w #2097144 <tfunc16> // CHECK5: __Thumbv7ABSLongThunk_tfunc28: -// CHECK5-NEXT: 100000e: 40 f2 01 0c movw r12, #1 -// CHECK5-NEXT: 1000012: c0 f2 e0 1c movt r12, #480 -// CHECK5-NEXT: 1000016: 60 47 bx r12 +// CHECK5-NEXT: 1000008: ff f1 fa 97 b.w #14680052 <tfunc28> // CHECK5: __Thumbv7ABSLongThunk_tfunc32: -// CHECK5-NEXT: 1000018: 40 f2 01 0c movw r12, #1 -// CHECK5-NEXT: 100001c: c0 f2 20 2c movt r12, #544 -// CHECK5-NEXT: 1000020: 60 47 bx r12 +// CHECK5-NEXT: 100000c: 40 f2 01 0c movw r12, #1 +// CHECK5-NEXT: 1000010: c0 f2 20 2c movt r12, #544 +// CHECK5-NEXT: 1000014: 60 47 bx r12 // CHECK5: __Thumbv7ABSLongThunk_tfunc33: -// CHECK5-NEXT: 1000022: 40 f2 01 0c movw r12, #1 -// CHECK5-NEXT: 1000026: c0 f2 30 2c movt r12, #560 -// CHECK5-NEXT: 100002a: 60 47 bx r12 +// CHECK5-NEXT: 1000016: 40 f2 01 0c movw r12, #1 +// CHECK5-NEXT: 100001a: c0 f2 30 2c movt r12, #560 +// CHECK5-NEXT: 100001e: 60 47 bx r12 // CHECK5: __Thumbv7ABSLongThunk_tfunc02: -// CHECK5-NEXT: 100002c: 40 f2 01 0c movw r12, #1 -// CHECK5-NEXT: 1000030: c0 f2 40 0c movt r12, #64 -// CHECK5-NEXT: 1000034: 60 47 bx r12 +// CHECK5-NEXT: 1000020: ff f7 ee 97 b.w #-12582948 <tfunc02> FUNCTION 15 // tfunc00 and tfunc01 are < 16Mb away, expect no range extension thunks bl tfunc00 @@ -106,11 +100,16 @@ _start: // CHECK6-NEXT: 1100000: 70 47 bx lr // CHECK6-NEXT: 1100002: ff f4 fd d7 bl #-15728646 // CHECK6-NEXT: 1100006: ff f5 fb d7 bl #-14680074 -// CHECK6-NEXT: 110000a: 00 f7 05 f8 bl #-1048566 -// CHECK6-NEXT: 110000e: 00 f7 08 f8 bl #-1048560 +// CHECK6-NEXT: 110000a: ff f6 ff ff bl #-1048578 +// CHECK6-NEXT: 110000e: 00 f7 02 f8 bl #-1048572 FUNCTION 16 FUNCTION 17 FUNCTION 18 +// Expect another precreated thunk section here +// CHECK7: __Thumbv7ABSLongThunk_tfunc15: +// CHECK7-NEXT: 1400004: ff f4 fc bf b.w #-3145736 <tfunc15> +// CHECK7: __Thumbv7ABSLongThunk_tfunc16: +// CHECK7-NEXT: 1400008: ff f5 fa bf b.w #-2097164 <tfunc16> FUNCTION 19 FUNCTION 20 FUNCTION 21 @@ -123,21 +122,12 @@ _start: FUNCTION 28 // tfunc02 is > 16Mb away, expect range extension thunks in precreated thunk // section -// CHECK7: tfunc28: -// CHECK7-NEXT: 1e00000: 70 47 bx lr -// CHECK7-NEXT: 1e00002: 00 f6 13 90 b.w #-14680026 <__Thumbv7ABSLongThunk_tfunc02> +// CHECK8: tfunc28: +// CHECK8-NEXT: 1e00000: 70 47 bx lr +// CHECK8-NEXT: 1e00002: 00 f6 0d 90 b.w #-14680038 <__Thumbv7ABSLongThunk_tfunc02> b.w tfunc02 FUNCTION 29 -// Expect another precreated thunk section here -// CHECK8: __Thumbv7ABSLongThunk_tfunc15: -// CHECK8-NEXT: 1f00004: 40 f2 01 0c movw r12, #1 -// CHECK8-NEXT: 1f00008: c0 f2 10 1c movt r12, #272 -// CHECK8-NEXT: 1f0000c: 60 47 bx r12 -// CHECK8: __Thumbv7ABSLongThunk_tfunc16: -// CHECK8-NEXT: 1f0000e: 40 f2 01 0c movw r12, #1 -// CHECK8-NEXT: 1f00012: c0 f2 20 1c movt r12, #288 -// CHECK8-NEXT: 1f00016: 60 47 bx r12 FUNCTION 30 FUNCTION 31 FUNCTION 32 @@ -147,13 +137,13 @@ _start: bl tfunc16 // CHECK9: tfunc32: // CHECK9: 2200000: 70 47 bx lr -// CHECK9-NEXT: 2200002: ff f4 ff ff bl #-3145730 -// CHECK9-NEXT: 2200006: 00 f5 02 f8 bl #-3145724 +// CHECK9-NEXT: 2200002: ff f5 ff d7 bl #-14680066 +// CHECK9-NEXT: 2200006: ff f5 ff d7 bl #-14680066 FUNCTION 33 bl tfunc15 bl tfunc16 // CHECK10: tfunc33: // CHECK10: 2300000: 70 47 bx lr -// CHECK10-NEXT: 2300002: ff f7 ff f7 bl #-4194306 -// CHECK10-NEXT: 2300006: 00 f4 02 f8 bl #-4194300 +// CHECK10-NEXT: 2300002: ff f4 ff d7 bl #-15728642 +// CHECK10-NEXT: 2300006: ff f4 ff d7 bl #-15728642 diff --git a/test/ELF/arm-thumb-thunk-empty-pass.s b/test/ELF/arm-thumb-thunk-empty-pass.s index 9ff6ed6a7807..ab9da1b8a2c2 100644 --- a/test/ELF/arm-thumb-thunk-empty-pass.s +++ b/test/ELF/arm-thumb-thunk-empty-pass.s @@ -2,7 +2,7 @@ // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 2>&1 // 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=16846860 -stop-address=16846874 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK2 %s +// RUN: llvm-objdump -d %t2 -start-address=16846856 -stop-address=16846874 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK2 %s .syntax unified .global _start, foo .type _start, %function @@ -20,13 +20,11 @@ foo: // CHECK1-NEXT: _start: // CHECK1-NEXT: 11000: ff f7 fe ff bl #-4 // CHECK1: __Thumbv7ABSLongThunk__start: -// CHECK1-NEXT: 11004: 41 f2 01 0c movw r12, #4097 -// CHECK1-NEXT: 11008: c0 f2 01 0c movt r12, #1 -// CHECK1-NEXT: 1100c: 60 47 bx r12 +// CHECK1-NEXT: 11004: ff f7 fc bf b.w #-8 <_start> // CHECK2: __Thumbv7ABSLongThunk__start: -// CHECK2: 101100c: 41 f2 01 0c movw r12, #4097 -// CHECK2-NEXT: 1011010: c0 f2 01 0c movt r12, #1 -// CHECK2-NEXT: 1011014: 60 47 bx r12 +// 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: 1011016: ff f7 f9 ff bl #-14 +// CHECK2-NEXT: 1011012: 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 faa39fec0218..457d460997aa 100644 --- a/test/ELF/arm-thumb-thunk-symbols.s +++ b/test/ELF/arm-thumb-thunk-symbols.s @@ -1,9 +1,9 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 2>&1 // RUN: llvm-readobj --symbols %t2 | FileCheck %s // RUN: ld.lld --shared %t -o %t3 2>&1 // RUN: llvm-readobj --symbols %t3 | FileCheck -check-prefix=CHECK-PI %s -// REQUIRES: arm // Check that the symbols generated for Thunks have the correct symbol type // of STT_FUNC and the correct value of bit 0 (0 for ARM 1 for Thumb) diff --git a/test/ELF/arm-thumb-undefined-weak.s b/test/ELF/arm-thumb-undefined-weak.s index 7f481b0ddb89..d973c58f16d8 100644 --- a/test/ELF/arm-thumb-undefined-weak.s +++ b/test/ELF/arm-thumb-undefined-weak.s @@ -1,7 +1,7 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 2>&1 // RUN: llvm-objdump -triple=thumbv7a-none-linux-gnueabi -d %t2 | FileCheck %s -// REQUIRES: arm // Check that the ARM ABI rules for undefined weak symbols are applied. // Branch instructions are resolved to the next instruction. Relative diff --git a/test/ELF/arm-thunk-largesection.s b/test/ELF/arm-thunk-largesection.s index 950f789764a6..d68cd0c76141 100644 --- a/test/ELF/arm-thunk-largesection.s +++ b/test/ELF/arm-thunk-largesection.s @@ -1,11 +1,11 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 2>&1 // 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=16850944 -stop-address=16850948 %t2 | FileCheck -check-prefix=CHECK3 %s -// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi -start-address=33628160 -stop-address=33628164 %t2 | FileCheck -check-prefix=CHECK4 %s -// RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi -start-address=50405364 -stop-address=50405376 %t2 | FileCheck -check-prefix=CHECK5 %s -// REQUIRES: arm +// 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 .syntax unified .balign 0x1000 .thumb @@ -21,9 +21,7 @@ _start: // CHECK1-NEXT: 11002: 00 00 movs r0, r0 // CHECK2: __Thumbv7ABSLongThunk__start: -// CHECK2-NEXT: 12004: 41 f2 01 0c movw r12, #4097 -// CHECK2-NEXT: 12008: c0 f2 01 0c movt r12, #1 -// CHECK2-NEXT: 1200c: 60 47 bx r12 +// CHECK2-NEXT: 12004: fe f7 fc bf b.w #-4104 <_start> // Gigantic section where we need a ThunkSection either side of it .section .text.large1, "ax", %progbits @@ -33,10 +31,10 @@ _start: .space (16 * 1024 * 1024) - 4 bl _start .space (16 * 1024 * 1024) - 16 -// CHECK3: 1012000: 00 f4 00 d0 bl #-16777216 -// CHECK4: 2012000: ff f3 f8 d7 bl #16777200 +// CHECK3: 1011ff8: 00 f4 04 d0 bl #-16777208 +// CHECK4: 2011ff8: ff f3 f8 d7 bl #16777200 // CHECK5: __Thumbv7ABSLongThunk__start: -// CHECK5-NEXT: 3011ff4: 41 f2 01 0c movw r12, #4097 -// CHECK5-NEXT: 3011ff8: c0 f2 01 0c movt r12, #1 -// CHECK5-NEXT: 3011ffc: 60 47 bx r12 +// 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 diff --git a/test/ELF/arm-thunk-linkerscript-dotexpr.s b/test/ELF/arm-thunk-linkerscript-dotexpr.s index bd0e9a293102..ea741708bc90 100644 --- a/test/ELF/arm-thunk-linkerscript-dotexpr.s +++ b/test/ELF/arm-thunk-linkerscript-dotexpr.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: echo "SECTIONS { \ // RUN: . = SIZEOF_HEADERS; \ @@ -6,7 +7,6 @@ // RUN: ld.lld --script %t.script %t -o %t2 2>&1 // RUN: llvm-objdump -d %t2 -start-address=148 -stop-address=188 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK1 %s // RUN: llvm-objdump -d %t2 -start-address=33554620 -stop-address=33554654 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK2 %s -// REQUIRES: arm // Test that range extension thunks can handle location expressions within // a Section Description .syntax unified diff --git a/test/ELF/arm-thunk-linkerscript-large.s b/test/ELF/arm-thunk-linkerscript-large.s index 07cd1dd87976..839d7716c278 100644 --- a/test/ELF/arm-thunk-linkerscript-large.s +++ b/test/ELF/arm-thunk-linkerscript-large.s @@ -79,9 +79,7 @@ _start: FUNCTIONL 08 FUNCTIONL 09 // CHECK3: __Thumbv7ABSLongThunk_tfuncl24: -// CHECK3-NEXT: b00004: 40 f2 01 0c movw r12, #1 -// CHECK3-NEXT: b00008: c0 f2 a0 1c movt r12, #416 -// CHECK3-NEXT: b0000c: 60 47 bx r12 +// CHECK3-NEXT: b00004: ff f2 fc 97 b.w #15728632 <tfuncl24> FUNCTIONL 10 FUNCTIONL 11 FUNCTIONL 12 diff --git a/test/ELF/arm-thunk-linkerscript-sort.s b/test/ELF/arm-thunk-linkerscript-sort.s index 69d176765780..62ea41363f41 100644 --- a/test/ELF/arm-thunk-linkerscript-sort.s +++ b/test/ELF/arm-thunk-linkerscript-sort.s @@ -41,9 +41,7 @@ tfunc\suff\(): FUNCTION 16 FUNCTION 15 // CHECK2: __Thumbv7ABSLongThunk_tfunc31: -// CHECK2-NEXT: 1000004: 40 f2 01 0c movw r12, #1 -// CHECK2-NEXT: 1000008: c0 f2 00 2c movt r12, #512 -// CHECK2-NEXT: 100000c: 60 47 bx r12 +// CHECK2-NEXT: 1000004: ff f3 fc 97 b.w #16777208 <tfunc31> FUNCTION 14 FUNCTION 13 FUNCTION 12 diff --git a/test/ELF/arm-thunk-linkerscript.s b/test/ELF/arm-thunk-linkerscript.s index 9aaa29237cbe..7728ddf76a97 100644 --- a/test/ELF/arm-thunk-linkerscript.s +++ b/test/ELF/arm-thunk-linkerscript.s @@ -1,3 +1,4 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: echo "SECTIONS { \ // RUN: . = SIZEOF_HEADERS; \ @@ -6,7 +7,6 @@ // RUN: } " > %t.script // RUN: ld.lld --script %t.script %t -o %t2 2>&1 // RUN: llvm-objdump -d -triple=thumbv7a-none-linux-gnueabi %t2 | FileCheck %s -// REQUIRES: arm // Simple test that we can support range extension thunks with linker scripts .syntax unified .section .text_low, "ax", %progbits diff --git a/test/ELF/arm-thunk-multipass.s b/test/ELF/arm-thunk-multipass.s index 25bf5235f755..b353bb148ff6 100644 --- a/test/ELF/arm-thunk-multipass.s +++ b/test/ELF/arm-thunk-multipass.s @@ -5,7 +5,7 @@ // parts we need to speed up the test and avoid a large output file // RUN: llvm-objdump -d %t2 -start-address=1048578 -stop-address=1048586 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK1 %s // RUN: llvm-objdump -d %t2 -start-address=16777224 -stop-address=16777254 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK2 %s -// RUN: llvm-objdump -d %t2 -start-address=17825818 -stop-address=17825828 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK3 %s +// RUN: llvm-objdump -d %t2 -start-address=17825812 -stop-address=17825826 -triple=thumbv7a-linux-gnueabihf | FileCheck -check-prefix=CHECK3 %s // In this test case a branch that is in range and does not need its range // extended can be pushed out of range by another Thunk, necessitating another // pass @@ -64,19 +64,15 @@ arm_target: // CHECK2-NEXT: 100000c: c0 f2 00 1c movt r12, #256 // CHECK2-NEXT: 1000010: 60 47 bx r12 // CHECK2: __Thumbv7ABSLongThunk_target: -// CHECK2-NEXT: 1000012: 40 f2 1b 0c movw r12, #27 -// CHECK2-NEXT: 1000016: c0 f2 10 1c movt r12, #272 -// CHECK2-NEXT: 100001a: 60 47 bx r12 +// CHECK2-NEXT: 1000012: ff f0 ff bf b.w #1048574 <target> // CHECK2: __Thumbv7ABSLongThunk_target2: -// CHECK2-NEXT: 100001c: 40 f2 13 0c movw r12, #19 -// CHECK2-NEXT: 1000020: c0 f2 10 0c movt r12, #16 -// CHECK2-NEXT: 1000024: 60 47 bx r12 +// CHECK2-NEXT: 1000016: ff f4 fc 97 b.w #-15728648 <target2> .section .text.17, "ax", %progbits // Just enough space so that bl target is in range if no extension thunks are // generated. - .space 0x100000 - 12 + .space 0x100000 - 6 .section .text.18, "ax", %progbits .thumb @@ -90,7 +86,7 @@ target: nop bx lr // CHECK3: target: -// CHECK3-NEXT: 110001a: ff f6 ff ff bl #-1048578 -// CHECK3-NEXT: 110001e: 00 bf nop -// CHECK3-NEXT: 1100020: 00 bf nop -// CHECK3-NEXT: 1100022: 70 47 bx lr +// CHECK3-NEXT: 1100014: ff f6 ff ff bl #-1048578 +// CHECK3-NEXT: 1100018: 00 bf nop +// CHECK3-NEXT: 110001a: 00 bf nop +// CHECK3-NEXT: 110001c: 70 47 bx lr diff --git a/test/ELF/arm-thunk-nosuitable.s b/test/ELF/arm-thunk-nosuitable.s new file mode 100644 index 000000000000..cde790665c42 --- /dev/null +++ b/test/ELF/arm-thunk-nosuitable.s @@ -0,0 +1,33 @@ +// 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 + + // Create a conditional branch too far away from a precreated thunk + // section. This will need a thunk section created within range. + .syntax unified + .thumb + + .section .text.0, "ax", %progbits + .space 2 * 1024 * 1024 + .globl _start + .type _start, %function +_start: + // Range of +/- 1 Megabyte, new ThunkSection will need creating after + // .text.1 + beq.w target + .section .text.1, "ax", %progbits + bx lr + +// CHECK: _start: +// CHECK-NEXT: 211000: 00 f0 00 80 beq.w #0 +// CHECK: __Thumbv7ABSLongThunk_target: +// CHECK-NEXT: 211004: 00 f0 01 90 b.w #12582914 +// CHECK: $t.1: +// CHECK-NEXT: 211008: 70 47 bx lr + + .section .text.2, "ax", %progbits + .space 12 * 1024 * 1024 + .globl target + .type target, %function +target: bx lr diff --git a/test/ELF/arm-thunk-section-too-large.s b/test/ELF/arm-thunk-section-too-large.s new file mode 100644 index 000000000000..9174093380f7 --- /dev/null +++ b/test/ELF/arm-thunk-section-too-large.s @@ -0,0 +1,21 @@ +// REQUIRES: ARM +// RUN: llvm-mc %s -triple=armv7a-linux-gnueabihf -arm-add-build-attributes -filetype=obj -o %t.o +// RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s + +// CHECK: InputSection too large for range extension thunk + .syntax unified + .thumb + .text + .globl _start + .type _start, %function +_start: + .space 2 * 1024 * 1024 + // conditional branch has range of 1 Mb expect error as we can't place + // a thunk in range of the branch. + beq target + .space 2 * 1024 * 1024 + + .section .text.2, "ax", %progbits + .globl target + .type target, %function +target: bx lr diff --git a/test/ELF/arm-thunk-toolargesection.s b/test/ELF/arm-thunk-toolargesection.s index 28fb94a8ccfd..13d0ea78368b 100644 --- a/test/ELF/arm-thunk-toolargesection.s +++ b/test/ELF/arm-thunk-toolargesection.s @@ -1,6 +1,6 @@ -// RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t -// RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s // REQUIRES: arm +// RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t +// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s .syntax unified .balign 0x1000 .thumb diff --git a/test/ELF/arm-tls-gd-nonpreemptible.s b/test/ELF/arm-tls-gd-nonpreemptible.s index ebaad4788c76..e72d422bad8b 100644 --- a/test/ELF/arm-tls-gd-nonpreemptible.s +++ b/test/ELF/arm-tls-gd-nonpreemptible.s @@ -1,10 +1,10 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // 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: llvm-objdump -s %t3.so | FileCheck -check-prefix=CHECK-SHARED %s -// REQUIRES: arm // For an executable, we write the module index 1 and the offset into the TLS // directly into the GOT. For a shared library we can only write the offset diff --git a/test/ELF/arm-tls-gd32.s b/test/ELF/arm-tls-gd32.s index a32e26f2aeb9..28ef4967aba8 100644 --- a/test/ELF/arm-tls-gd32.s +++ b/test/ELF/arm-tls-gd32.s @@ -1,8 +1,8 @@ +// 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: llvm-readobj -s -dyn-relocations %t.so | FileCheck --check-prefix=SEC %s // RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s -// REQUIRES: arm // Test the handling of the global-dynamic TLS model. Dynamic Loader finds // module index R_ARM_TLS_DTPMOD32 and the offset within the module diff --git a/test/ELF/arm-tls-ie32.s b/test/ELF/arm-tls-ie32.s index 26e1265568c8..b12bc1be3161 100644 --- a/test/ELF/arm-tls-ie32.s +++ b/test/ELF/arm-tls-ie32.s @@ -1,8 +1,8 @@ +// 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: llvm-readobj -s -dyn-relocations %t.so | FileCheck --check-prefix=SEC %s // RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s -// REQUIRES: arm // Test the handling of the initial-exec TLS model. Relative location within // static TLS is a run-time constant computed by dynamic loader as a result diff --git a/test/ELF/arm-tls-ldm32.s b/test/ELF/arm-tls-ldm32.s index 629dcd038899..94931d945761 100644 --- a/test/ELF/arm-tls-ldm32.s +++ b/test/ELF/arm-tls-ldm32.s @@ -1,8 +1,8 @@ +// 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: llvm-readobj -s -dyn-relocations %t.so | FileCheck --check-prefix=SEC %s // RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s -// REQUIRES: arm // 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 diff --git a/test/ELF/arm-tls-le32.s b/test/ELF/arm-tls-le32.s index 4d42a06b0fff..7834dedf1be0 100644 --- a/test/ELF/arm-tls-le32.s +++ b/test/ELF/arm-tls-le32.s @@ -1,8 +1,8 @@ +// REQUIRES: arm // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi // RUN: ld.lld %t.o -o %t // RUN: llvm-readobj -s -dyn-relocations %t | FileCheck --check-prefix=SEC %s // RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t | FileCheck %s -// REQUIRES: arm // Test the handling of the local exec TLS model. TLS can be resolved // statically for an application. The code sequences assume a thread pointer diff --git a/test/ELF/arm-tls-norelax-gd-ie.s b/test/ELF/arm-tls-norelax-gd-ie.s index bcee56165958..ba60521520fe 100644 --- a/test/ELF/arm-tls-norelax-gd-ie.s +++ b/test/ELF/arm-tls-norelax-gd-ie.s @@ -1,9 +1,9 @@ +// 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 %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi // RUN: ld.lld --hash-style=sysv %t1.so %t.o -o %t // RUN: llvm-readobj -s -dyn-relocations %t | FileCheck %s -// REQUIRES: arm // This tls global-dynamic sequence is with respect to a preemptible symbol but // is in an application so a relaxation to Initial Exec would normally be diff --git a/test/ELF/arm-tls-norelax-gd-le.s b/test/ELF/arm-tls-norelax-gd-le.s index 788c845b3f8b..f1e78c4c76b1 100644 --- a/test/ELF/arm-tls-norelax-gd-le.s +++ b/test/ELF/arm-tls-norelax-gd-le.s @@ -1,9 +1,9 @@ +// 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 %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi // RUN: ld.lld --hash-style=sysv %t1.so %t.o -o %t // RUN: llvm-objdump -s %t | FileCheck %s -// REQUIRES: arm // This tls global-dynamic sequence is with respect to a non-preemptible // symbol in an application so a relaxation to Local Exec would normally be diff --git a/test/ELF/arm-tls-norelax-ie-le.s b/test/ELF/arm-tls-norelax-ie-le.s index eb96aa0fad57..be8af9760481 100644 --- a/test/ELF/arm-tls-norelax-ie-le.s +++ b/test/ELF/arm-tls-norelax-ie-le.s @@ -1,9 +1,9 @@ +// 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 %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi // RUN: ld.lld --hash-style=sysv %t1.so %t.o -o %t // RUN: llvm-objdump -s -triple=armv7a-linux-gnueabi %t | FileCheck %s -// REQUIRES: arm // This tls Initial Exec sequence is with respect to a non-preemptible symbol // so a relaxation would normally be possible. This would result in an assertion diff --git a/test/ELF/arm-tls-norelax-ld-le.s b/test/ELF/arm-tls-norelax-ld-le.s index fc5b72b80f9c..ce0697ad9047 100644 --- a/test/ELF/arm-tls-norelax-ld-le.s +++ b/test/ELF/arm-tls-norelax-ld-le.s @@ -1,9 +1,9 @@ +// 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 %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi // RUN: ld.lld --hash-style=sysv %t1.so %t.o -o %t // RUN: llvm-objdump -s %t | FileCheck %s -// REQUIRES: arm .global __tls_get_addr .text diff --git a/test/ELF/arm-undefined-weak.s b/test/ELF/arm-undefined-weak.s index 8af9f4916a95..0d4714a54835 100644 --- a/test/ELF/arm-undefined-weak.s +++ b/test/ELF/arm-undefined-weak.s @@ -1,7 +1,7 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: ld.lld %t -o %t2 2>&1 // RUN: llvm-objdump -triple=armv7a-none-linux-gnueabi -d %t2 | FileCheck %s -// REQUIRES: arm // Check that the ARM ABI rules for undefined weak symbols are applied. // Branch instructions are resolved to the next instruction. Undefined diff --git a/test/ELF/arm-use-r-output.s b/test/ELF/arm-use-r-output.s index 918362466d3a..2d2350863165 100644 --- a/test/ELF/arm-use-r-output.s +++ b/test/ELF/arm-use-r-output.s @@ -1,7 +1,7 @@ // REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o // RUN: ld.lld -r %t.o -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t.so +// RUN: ld.lld -shared %t2.o -o /dev/null // We used to crash using the output of -r because of the relative order of // SHF_LINK_ORDER sections. diff --git a/test/ELF/as-needed-lazy.s b/test/ELF/as-needed-lazy.s new file mode 100644 index 000000000000..e892b9980aad --- /dev/null +++ b/test/ELF/as-needed-lazy.s @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/as-needed-lazy.s -o %t2.o +# RUN: ld.lld %t2.o -o %t2.so -shared +# RUN: rm -f %t2.a +# RUN: llvm-ar rc %t2.a %t2.o +# RUN: ld.lld %t1.o %t2.a --as-needed %t2.so -o %t +# RUN: llvm-readobj -d %t | FileCheck %s + +# CHECK-NOT: NEEDED + +.global _start +_start: + nop diff --git a/test/ELF/as-needed-weak.s b/test/ELF/as-needed-weak.s new file mode 100644 index 000000000000..f009c72d6f48 --- /dev/null +++ b/test/ELF/as-needed-weak.s @@ -0,0 +1,22 @@ +# REQUIRES: x86 + +# RUN: echo '.globl foo; .type foo, @function; foo:' | \ +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t1.o +# RUN: ld.lld -shared -o %t1.so -soname libfoo %t1.o + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o +# RUN: ld.lld -o %t.exe %t2.o --as-needed %t1.so +# RUN: llvm-readelf -dynamic-table -dyn-symbols %t.exe | FileCheck %s + +# CHECK-NOT: libfoo + +# CHECK: Symbol table of .hash for image: +# CHECK-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name +# CHECK-NEXT: 1 1: 0000000000000000 0 FUNC WEAK DEFAULT UND foo@ + +.globl _start +.weak foo + +_start: + mov $foo, %eax + callq foo diff --git a/test/ELF/as-needed.s b/test/ELF/as-needed.s index bcfa32d01f66..a7bba79d57b0 100644 --- a/test/ELF/as-needed.s +++ b/test/ELF/as-needed.s @@ -22,7 +22,7 @@ // RUN: ld.lld --as-needed %t.o %t2.so --no-as-needed %t3.so %t4.so -o %t2 // RUN: llvm-readobj -dynamic-table %t2 | FileCheck %s -/// GROUP directive is the same as --as-needed. +/// GROUP command is the same as listing the files on the command line. // RUN: echo "GROUP(\"%t2.so\" \"%t3.so\" \"%t4.so\")" > %t.script // RUN: ld.lld %t.o %t.script -o %t2 diff --git a/test/ELF/auxiliary.s b/test/ELF/auxiliary.s index 18fbdf05f9ec..86551e3e84bf 100644 --- a/test/ELF/auxiliary.s +++ b/test/ELF/auxiliary.s @@ -2,6 +2,8 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: ld.lld %t.o -shared -f aaa --auxiliary bbb -o %t # RUN: llvm-readobj --dynamic-table %t | FileCheck %s +# RUN: ld.lld %t.o -shared -f aaa --auxiliary=bbb -o %t +# RUN: llvm-readobj --dynamic-table %t | FileCheck %s # CHECK: DynamicSection [ # CHECK-NEXT: Tag Type Name/Value diff --git a/test/ELF/basic-aarch64.s b/test/ELF/basic-aarch64.s index 6527d3dc0def..efbe0080844f 100644 --- a/test/ELF/basic-aarch64.s +++ b/test/ELF/basic-aarch64.s @@ -1,8 +1,8 @@ +# REQUIRES: aarch64 # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t # RUN: ld.lld %t -o %t2 # RUN: llvm-readobj -file-headers -sections -program-headers -symbols %t2 \ # RUN: | FileCheck %s -# REQUIRES: aarch64 # exits with return code 42 on FreeBSD/AArch64 .globl _start diff --git a/test/ELF/basic-freebsd.s b/test/ELF/basic-freebsd.s index 375fdb5f8078..f614bb64b069 100644 --- a/test/ELF/basic-freebsd.s +++ b/test/ELF/basic-freebsd.s @@ -1,9 +1,9 @@ +# REQUIRES: x86 # Verify that OSABI is set to the correct value. # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %t # RUN: ld.lld %t -o %t2 # RUN: llvm-readobj -file-headers %t2 | FileCheck %s -# REQUIRES: x86 .globl _start _start: diff --git a/test/ELF/basic-mips.s b/test/ELF/basic-mips.s index a193529b3487..9ecabff47f6a 100644 --- a/test/ELF/basic-mips.s +++ b/test/ELF/basic-mips.s @@ -1,10 +1,9 @@ +# REQUIRES: mips # RUN: llvm-mc -filetype=obj -triple=mipsel-unknown-linux %s -o %t.o # RUN: ld.lld %t.o -o %t.exe # RUN: llvm-readobj -file-headers -sections -program-headers -symbols %t.exe \ # RUN: | FileCheck %s -# REQUIRES: mips - # Exits with return code 1 on Linux. .globl __start __start: @@ -19,7 +18,7 @@ __start: # CHECK-NEXT: DataEncoding: LittleEndian (0x1) # CHECK-NEXT: FileVersion: 1 # CHECK-NEXT: OS/ABI: SystemV (0x0) -# CHECK-NEXT: ABIVersion: 0 +# CHECK-NEXT: ABIVersion: 1 # CHECK-NEXT: Unused: (00 00 00 00 00 00 00) # CHECK-NEXT: } # CHECK-NEXT: Type: Executable (0x2) diff --git a/test/ELF/basic-ppc.s b/test/ELF/basic-ppc.s index cda32245fd2b..48b146a21d44 100644 --- a/test/ELF/basic-ppc.s +++ b/test/ELF/basic-ppc.s @@ -1,7 +1,7 @@ +# REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=powerpc-unknown-freebsd %s -o %t # RUN: ld.lld --hash-style=sysv -discard-all -shared %t -o %t2 # RUN: llvm-readobj -file-headers -sections -section-data -program-headers %t2 | FileCheck %s -# REQUIRES: ppc # exits with return code 42 on FreeBSD .text @@ -144,9 +144,9 @@ // CHECK-NEXT: AddressAlignment: 4 // CHECK-NEXT: EntrySize: 8 // CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 00000006 00000114 0000000B 00000010 |................| -// CHECK-NEXT: 0010: 00000005 00000134 0000000A 00000001 |.......4........| -// CHECK-NEXT: 0020: 00000004 00000124 00000000 00000000 |.......$........| +// CHECK-NEXT: 0000: 00000006 00000114 0000000B 00000010 +// CHECK-NEXT: 0010: 00000005 00000134 0000000A 00000001 +// CHECK-NEXT: 0020: 00000004 00000124 00000000 00000000 // CHECK-NEXT: ) // CHECK-NEXT: } // CHECK-NEXT: Section { @@ -165,7 +165,7 @@ // CHECK-NEXT: AddressAlignment: 1 // CHECK-NEXT: EntrySize: 1 // CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 4C4C4420 312E3000 |LLD 1.0.| +// CHECK-NEXT: 0000: 4C4C4420 312E3000 |LLD 1.0.| // CHECK-NEXT: ) // CHECK-NEXT: } // CHECK-NEXT: Section { @@ -215,7 +215,7 @@ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 // CHECK-NEXT: Offset: 0x20A1 -// CHECK-NEXT: Size: 1 +// CHECK-NEXT: Size: 10 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 1 diff --git a/test/ELF/basic-ppc64.s b/test/ELF/basic-ppc64.s new file mode 100644 index 000000000000..f586d6320d16 --- /dev/null +++ b/test/ELF/basic-ppc64.s @@ -0,0 +1,323 @@ +# REQUIRES: ppc +# # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t +# RUN: ld.lld --hash-style=sysv -discard-all -shared %t -o %t2 +# RUN: llvm-readobj -file-headers -sections -section-data -program-headers %t2 | FileCheck %s +.abiversion 2 +# Exits with return code 55 on linux. +.text + li 0,1 + li 3,55 + sc + +// CHECK:Format: ELF64-ppc64 +// CHECK-NEXT:Arch: powerpc64le +// CHECK-NEXT:AddressSize: 64bit +// CHECK-NEXT:LoadName: +// CHECK-NEXT:ElfHeader { +// CHECK-NEXT: Ident { +// CHECK-NEXT: Magic: (7F 45 4C 46) +// CHECK-NEXT: Class: 64-bit (0x2) +// CHECK-NEXT: DataEncoding: LittleEndian (0x1) +// CHECK-NEXT: FileVersion: 1 +// CHECK-NEXT: OS/ABI: SystemV (0x0) +// CHECK-NEXT: ABIVersion: 0 +// CHECK-NEXT: Unused: (00 00 00 00 00 00 00) +// CHECK-NEXT: } +// CHECK-NEXT: Type: SharedObject (0x3) +// CHECK-NEXT: Machine: EM_PPC64 (0x15) +// CHECK-NEXT: Version: 1 +// CHECK-NEXT: Entry: 0x10000 +// CHECK-NEXT: ProgramHeaderOffset: 0x40 +// CHECK-NEXT: SectionHeaderOffset: +// CHECK-NEXT: Flags [ (0x2) +// CHECK-NEXT: 0x2 +// CHECK-NEXT: ] +// CHECK-NEXT: HeaderSize: 64 +// CHECK-NEXT: ProgramHeaderEntrySize: 56 +// CHECK-NEXT: ProgramHeaderCount: 7 +// CHECK-NEXT: SectionHeaderEntrySize: 64 +// CHECK-NEXT: SectionHeaderCount: 10 +// CHECK-NEXT: StringTableSectionIndex: 8 +// CHECK-NEXT:} +// CHECK-NEXT:Sections [ +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: 0 +// CHECK-NEXT: Name: (0) +// CHECK-NEXT: Type: SHT_NULL (0x0) +// CHECK-NEXT: Flags [ (0x0) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x0 +// CHECK-NEXT: Offset: 0x0 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Link: 0 +// CHECK-NEXT: Info: 0 +// CHECK-NEXT: AddressAlignment: 0 +// CHECK-NEXT: EntrySize: 0 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: ) +// CHECK-NEXT: } +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: 1 +// CHECK-NEXT: Name: .dynsym (1) +// CHECK-NEXT: Type: SHT_DYNSYM (0xB) +// CHECK-NEXT: Flags [ (0x2) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x1C8 +// CHECK-NEXT: Offset: 0x1C8 +// CHECK-NEXT: Size: 24 +// CHECK-NEXT: Link: 3 +// CHECK-NEXT: Info: 1 +// CHECK-NEXT: AddressAlignment: 8 +// CHECK-NEXT: EntrySize: 24 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 00000000 00000000 00000000 00000000 |................| +// CHECK-NEXT: 0010: 00000000 00000000 |........| +// CHECK-NEXT: ) +// CHECK-NEXT: } +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: 2 +// CHECK-NEXT: Name: .hash (9) +// CHECK-NEXT: Type: SHT_HASH (0x5) +// CHECK-NEXT: Flags [ (0x2) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x1E0 +// CHECK-NEXT: Offset: 0x1E0 +// CHECK-NEXT: Size: 16 +// CHECK-NEXT: Link: 1 +// CHECK-NEXT: Info: 0 +// CHECK-NEXT: AddressAlignment: 4 +// CHECK-NEXT: EntrySize: 4 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 01000000 01000000 00000000 00000000 |................| +// CHECK-NEXT: ) +// CHECK-NEXT: } +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: 3 +// CHECK-NEXT: Name: .dynstr (15) +// CHECK-NEXT: Type: SHT_STRTAB (0x3) +// CHECK-NEXT: Flags [ (0x2) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x1F0 +// CHECK-NEXT: Offset: 0x1F0 +// CHECK-NEXT: Size: 1 +// CHECK-NEXT: Link: 0 +// CHECK-NEXT: Info: 0 +// CHECK-NEXT: AddressAlignment: 1 +// CHECK-NEXT: EntrySize: 0 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 00 |.| +// CHECK-NEXT: ) +// CHECK-NEXT: } +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: 4 +// CHECK-NEXT: Name: .text (23) +// CHECK-NEXT: Type: SHT_PROGBITS (0x1) +// CHECK-NEXT: Flags [ (0x6) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_EXECINSTR (0x4) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x10000 +// CHECK-NEXT: Offset: 0x10000 +// CHECK-NEXT: Size: 12 +// CHECK-NEXT: Link: 0 +// CHECK-NEXT: Info: 0 +// CHECK-NEXT: AddressAlignment: 4 +// CHECK-NEXT: EntrySize: 0 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 01000038 37006038 02000044 |...87.`8...D| +// CHECK-NEXT: ) +// CHECK-NEXT: } +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: 5 +// CHECK-NEXT: Name: .dynamic (29) +// CHECK-NEXT: Type: SHT_DYNAMIC (0x6) +// CHECK-NEXT: Flags [ (0x3) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_WRITE (0x1) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x20000 +// CHECK-NEXT: Offset: 0x20000 +// CHECK-NEXT: Size: 96 +// CHECK-NEXT: Link: 3 +// CHECK-NEXT: Info: 0 +// CHECK-NEXT: AddressAlignment: 8 +// CHECK-NEXT: EntrySize: 16 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 06000000 00000000 C8010000 00000000 |................| +// CHECK-NEXT: 0010: 0B000000 00000000 18000000 00000000 |................| +// CHECK-NEXT: 0020: 05000000 00000000 F0010000 00000000 |................| +// CHECK-NEXT: 0030: 0A000000 00000000 01000000 00000000 |................| +// CHECK-NEXT: 0040: 04000000 00000000 E0010000 00000000 |................| +// CHECK-NEXT: 0050: 00000000 00000000 00000000 00000000 |................| +// CHECK-NEXT: ) +// CHECK-NEXT: } +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: 6 +// CHECK-NEXT: Name: .comment (38) +// CHECK-NEXT: Type: SHT_PROGBITS (0x1) +// CHECK-NEXT: Flags [ (0x30) +// CHECK-NEXT: SHF_MERGE (0x10) +// CHECK-NEXT: SHF_STRINGS (0x20) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x0 +// CHECK-NEXT: Offset: 0x20060 +// CHECK-NEXT: Size: 8 +// CHECK-NEXT: Link: 0 +// CHECK-NEXT: Info: 0 +// CHECK-NEXT: AddressAlignment: 1 +// CHECK-NEXT: EntrySize: 1 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 4C4C4420 312E3000 |LLD 1.0.| +// CHECK-NEXT: ) +// CHECK-NEXT: } +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: 7 +// CHECK-NEXT: Name: .symtab (47) +// CHECK-NEXT: Type: SHT_SYMTAB (0x2) +// CHECK-NEXT: Flags [ (0x0) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x0 +// CHECK-NEXT: Offset: 0x20068 +// CHECK-NEXT: Size: 48 +// CHECK-NEXT: Link: 9 +// CHECK-NEXT: Info: 2 +// CHECK-NEXT: AddressAlignment: 8 +// CHECK-NEXT: EntrySize: 24 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 00000000 00000000 00000000 00000000 |................| +// CHECK-NEXT: 0010: 00000000 00000000 01000000 00020500 |................| +// CHECK-NEXT: 0020: 00000200 00000000 00000000 00000000 |................| +// CHECK-NEXT: ) +// CHECK-NEXT: } +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: 8 +// CHECK-NEXT: Name: .shstrtab (55) +// CHECK-NEXT: Type: SHT_STRTAB (0x3) +// CHECK-NEXT: Flags [ (0x0) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x0 +// CHECK-NEXT: Offset: 0x20098 +// CHECK-NEXT: Size: 73 +// CHECK-NEXT: Link: 0 +// CHECK-NEXT: Info: 0 +// CHECK-NEXT: AddressAlignment: 1 +// CHECK-NEXT: EntrySize: 0 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 002E6479 6E73796D 002E6861 7368002E |..dynsym..hash..| +// CHECK-NEXT: 0010: 64796E73 7472002E 74657874 002E6479 |dynstr..text..dy| +// CHECK-NEXT: 0020: 6E616D69 63002E63 6F6D6D65 6E74002E |namic..comment..| +// CHECK-NEXT: 0030: 73796D74 6162002E 73687374 72746162 |symtab..shstrtab| +// CHECK-NEXT: 0040: 002E7374 72746162 00 |..strtab.| +// CHECK-NEXT: ) +// CHECK-NEXT: } +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: 9 +// CHECK-NEXT: Name: .strtab (65) +// CHECK-NEXT: Type: SHT_STRTAB (0x3) +// CHECK-NEXT: Flags [ (0x0) +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x0 +// CHECK-NEXT: Offset: 0x200E1 +// CHECK-NEXT: Size: 10 +// CHECK-NEXT: Link: 0 +// CHECK-NEXT: Info: 0 +// CHECK-NEXT: AddressAlignment: 1 +// CHECK-NEXT: EntrySize: 0 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 005F4459 4E414D49 4300 |._DYNAMIC.| +// CHECK-NEXT: ) +// CHECK-NEXT: } +// CHECK-NEXT:] +// CHECK-NEXT:ProgramHeaders [ +// CHECK-NEXT: ProgramHeader { +// CHECK-NEXT: Type: PT_PHDR (0x6) +// CHECK-NEXT: Offset: 0x40 +// CHECK-NEXT: VirtualAddress: 0x40 +// CHECK-NEXT: PhysicalAddress: 0x40 +// CHECK-NEXT: FileSize: 392 +// CHECK-NEXT: MemSize: 392 +// CHECK-NEXT: Flags [ (0x4) +// CHECK-NEXT: PF_R (0x4) +// CHECK-NEXT: ] +// CHECK-NEXT: Alignment: 8 +// CHECK-NEXT: } +// CHECK-NEXT: ProgramHeader { +// CHECK-NEXT: Type: PT_LOAD (0x1) +// CHECK-NEXT: Offset: 0x0 +// CHECK-NEXT: VirtualAddress: 0x0 +// CHECK-NEXT: PhysicalAddress: 0x0 +// CHECK-NEXT: FileSize: 497 +// CHECK-NEXT: MemSize: 497 +// CHECK-NEXT: Flags [ (0x4) +// CHECK-NEXT: PF_R (0x4) +// CHECK-NEXT: ] +// CHECK-NEXT: Alignment: 65536 +// 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: FileSize: 12 +// CHECK-NEXT: MemSize: 12 +// CHECK-NEXT: Flags [ (0x5) +// CHECK-NEXT: PF_R (0x4) +// CHECK-NEXT: PF_X (0x1) +// CHECK-NEXT: ] +// CHECK-NEXT: Alignment: 65536 +// 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: FileSize: 96 +// CHECK-NEXT: MemSize: 96 +// CHECK-NEXT: Flags [ (0x6) +// CHECK-NEXT: PF_R (0x4) +// CHECK-NEXT: PF_W (0x2) +// CHECK-NEXT: ] +// CHECK-NEXT: Alignment: 65536 +// 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: FileSize: 96 +// CHECK-NEXT: MemSize: 96 +// CHECK-NEXT: Flags [ (0x6) +// CHECK-NEXT: PF_R (0x4) +// CHECK-NEXT: PF_W (0x2) +// CHECK-NEXT: ] +// CHECK-NEXT: Alignment: 8 +// 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: FileSize: 96 +// CHECK-NEXT: MemSize: 4096 +// CHECK-NEXT: Flags [ (0x4) +// CHECK-NEXT: PF_R (0x4) +// CHECK-NEXT: ] +// CHECK-NEXT: Alignment: 1 +// CHECK-NEXT: } +// CHECK-NEXT: ProgramHeader { +// CHECK-NEXT: Type: PT_GNU_STACK (0x6474E551) +// CHECK-NEXT: Offset: 0x0 +// CHECK-NEXT: VirtualAddress: 0x0 +// CHECK-NEXT: PhysicalAddress: 0x0 +// CHECK-NEXT: FileSize: 0 +// CHECK-NEXT: MemSize: 0 +// CHECK-NEXT: Flags [ (0x6) +// CHECK-NEXT: PF_R (0x4) +// CHECK-NEXT: PF_W (0x2) +// CHECK-NEXT: ] +// CHECK-NEXT: Alignment: 0 +// CHECK-NEXT: } +// CHECK-NEXT:] diff --git a/test/ELF/basic-sparcv9.s b/test/ELF/basic-sparcv9.s index 75c20476a43b..272fe01cfc40 100644 --- a/test/ELF/basic-sparcv9.s +++ b/test/ELF/basic-sparcv9.s @@ -1,8 +1,8 @@ +# REQUIRES: sparc # RUN: llvm-mc -filetype=obj -triple=sparc64-unknown-openbsd %s -o %t # RUN: ld.lld %t -o %t2 # RUN: llvm-readobj -file-headers -sections -program-headers -symbols %t2 \ # RUN: | FileCheck %s -# REQUIRES: sparc # exits with return code 42 on OpenBSD/sparc64 .global _start diff --git a/test/ELF/basic32.s b/test/ELF/basic32.s index 071a06332f0a..72058dc6b168 100644 --- a/test/ELF/basic32.s +++ b/test/ELF/basic32.s @@ -1,7 +1,7 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t # RUN: ld.lld %t -o %t2 # RUN: llvm-readobj -file-headers -sections -program-headers %t2 | FileCheck %s -# REQUIRES: x86 # exits with return code 42 on linux .globl _start diff --git a/test/ELF/basic64be.s b/test/ELF/basic64be.s index d16f4a074175..2bef1545153e 100644 --- a/test/ELF/basic64be.s +++ b/test/ELF/basic64be.s @@ -1,29 +1,14 @@ +# REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t # RUN: ld.lld -discard-all %t -o %t2 # RUN: llvm-readobj -file-headers -sections -section-data -program-headers %t2 | FileCheck %s -# REQUIRES: ppc # exits with return code 42 on linux -.section ".opd","aw" -.global _start -_start: -.quad .Lfoo,.TOC.@tocbase,0 - -# generate .toc and .toc1 sections to make sure that the ordering is as -# intended (.toc before .toc1, and both before .opd). -.section ".toc1","aw" -.quad 22, 37, 89, 47 - -.section ".toc","aw" -.quad 45, 86, 72, 24 - .text -.Lfoo: li 0,1 li 3,42 sc - -# CHECK: ElfHeader { +# CHECK: ElfHeader { # CHECK-NEXT: Ident { # CHECK-NEXT: Magic: (7F 45 4C 46) # CHECK-NEXT: Class: 64-bit (0x2) @@ -36,17 +21,18 @@ _start: # CHECK-NEXT: Type: Executable (0x2) # CHECK-NEXT: Machine: EM_PPC64 (0x15) # CHECK-NEXT: Version: 1 -# CHECK-NEXT: Entry: 0x10020040 +# CHECK-NEXT: Entry: 0x10010000 # CHECK-NEXT: ProgramHeaderOffset: 0x40 -# CHECK-NEXT: SectionHeaderOffset: 0x30080 -# CHECK-NEXT: Flags [ (0x0) +# CHECK-NEXT: SectionHeaderOffset: 0x11050 +# CHECK-NEXT: Flags [ (0x2) +# CHECK-NEXT: 0x2 # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 64 # CHECK-NEXT: ProgramHeaderEntrySize: 56 -# CHECK-NEXT: ProgramHeaderCount: 6 +# CHECK-NEXT: ProgramHeaderCount: 4 # CHECK-NEXT: SectionHeaderEntrySize: 64 -# CHECK-NEXT: SectionHeaderCount: 10 -# CHECK-NEXT: StringTableSectionIndex: 8 +# CHECK-NEXT: SectionHeaderCount: 6 +# CHECK-NEXT: StringTableSectionIndex: 4 # CHECK-NEXT: } # CHECK-NEXT: Sections [ # CHECK-NEXT: Section { @@ -67,7 +53,7 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 1 -# CHECK-NEXT: Name: .text +# CHECK-NEXT: Name: .text (1) # CHECK-NEXT: Type: SHT_PROGBITS (0x1) # CHECK-NEXT: Flags [ (0x6) # CHECK-NEXT: SHF_ALLOC (0x2) @@ -81,152 +67,80 @@ _start: # CHECK-NEXT: AddressAlignment: 4 # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: SectionData ( -# CHECK: ) -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: 2 -# CHECK-NEXT: Name: .toc -# CHECK-NEXT: Type: SHT_PROGBITS (0x1) -# CHECK-NEXT: Flags [ (0x3) -# CHECK-NEXT: SHF_ALLOC (0x2) -# CHECK-NEXT: SHF_WRITE (0x1) -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x10020000 -# CHECK-NEXT: Offset: 0x20000 -# CHECK-NEXT: Size: 32 -# CHECK-NEXT: Link: 0 -# CHECK-NEXT: Info: 0 -# CHECK-NEXT: AddressAlignment: 1 -# CHECK-NEXT: EntrySize: 0 -# CHECK-NEXT: SectionData ( -# CHECK-NEXT: 0000: 00000000 0000002D 00000000 00000056 |.......-.......V| -# CHECK-NEXT: 0010: 00000000 00000048 00000000 00000018 |.......H........| -# CHECK-NEXT: ) -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: 3 -# CHECK-NEXT: Name: .toc1 -# CHECK-NEXT: Type: SHT_PROGBITS (0x1) -# CHECK-NEXT: Flags [ (0x3) -# CHECK-NEXT: SHF_ALLOC (0x2) -# CHECK-NEXT: SHF_WRITE (0x1) -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x10020020 -# CHECK-NEXT: Offset: 0x20020 -# CHECK-NEXT: Size: 32 -# CHECK-NEXT: Link: 0 -# CHECK-NEXT: Info: 0 -# CHECK-NEXT: AddressAlignment: 1 -# CHECK-NEXT: EntrySize: 0 -# CHECK-NEXT: SectionData ( -# CHECK-NEXT: 0000: 00000000 00000016 00000000 00000025 |...............%| -# CHECK-NEXT: 0010: 00000000 00000059 00000000 0000002F |.......Y......./| +# CHECK-NEXT: 0000: 38000001 3860002A 44000002 |8...8`.*D...| # CHECK-NEXT: ) # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 4 -# CHECK-NEXT: Name: .opd -# CHECK-NEXT: Type: SHT_PROGBITS (0x1) -# CHECK-NEXT: Flags [ (0x3) -# CHECK-NEXT: SHF_ALLOC (0x2) -# CHECK-NEXT: SHF_WRITE (0x1) -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x10020040 -# CHECK-NEXT: Offset: 0x20040 -# CHECK-NEXT: Size: 24 -# CHECK-NEXT: Link: 0 -# CHECK-NEXT: Info: 0 -# CHECK-NEXT: AddressAlignment: 1 -# CHECK-NEXT: EntrySize: 0 -# CHECK-NEXT: SectionData ( -# CHECK-NEXT: 0000: 00000000 10010000 00000000 10038000 |................| -# CHECK-NEXT: 0010: 00000000 00000000 |........| -# CHECK-NEXT: ) -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: 5 -# CHECK-NEXT: Name: .got -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: SHF_WRITE -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x10030000 -# CHECK-NEXT: Offset: 0x30000 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Link: 0 -# CHECK-NEXT: Info: 0 -# CHECK-NEXT: AddressAlignment: 8 -# CHECK-NEXT: EntrySize: 0 -# CHECK-NEXT: SectionData ( -# CHECK-NEXT: ) -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: 6 -# CHECK-NEXT: Name: .comment +# CHECK-NEXT: Index: 2 +# CHECK-NEXT: Name: .comment (7) # CHECK-NEXT: Type: SHT_PROGBITS (0x1) # CHECK-NEXT: Flags [ (0x30) # CHECK-NEXT: SHF_MERGE (0x10) # CHECK-NEXT: SHF_STRINGS (0x20) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x30000 +# CHECK-NEXT: Offset: 0x11000 # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 1 # CHECK-NEXT: EntrySize: 1 # CHECK-NEXT: SectionData ( -# CHECK-NEXT: 0000: 4C4C4420 312E3000 |LLD 1.0.| +# CHECK-NEXT: 0000: 4C4C4420 312E3000 |LLD 1.0.| # CHECK-NEXT: ) # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 7 -# CHECK-NEXT: Name: .symtab +# CHECK-NEXT: Index: 3 +# CHECK-NEXT: Name: .symtab (16) # CHECK-NEXT: Type: SHT_SYMTAB (0x2) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x30008 -# CHECK-NEXT: Size: 48 -# CHECK-NEXT: Link: 9 +# CHECK-NEXT: Offset: 0x11008 +# CHECK-NEXT: Size: 24 +# CHECK-NEXT: Link: 5 # CHECK-NEXT: Info: 1 # CHECK-NEXT: AddressAlignment: 8 # CHECK-NEXT: EntrySize: 24 # CHECK-NEXT: SectionData ( -# CHECK: ) +# CHECK-NEXT: 0000: 00000000 00000000 00000000 00000000 |................| +# CHECK-NEXT: 0010: 00000000 00000000 |........| +# CHECK-NEXT: ) # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 8 -# CHECK-NEXT: Name: .shstrtab -# CHECK-NEXT: Type: SHT_STRTAB -# CHECK-NEXT: Flags [ +# CHECK-NEXT: Index: 4 +# CHECK-NEXT: Name: .shstrtab (24) +# CHECK-NEXT: Type: SHT_STRTAB (0x3) +# CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x30038 -# CHECK-NEXT: Size: 63 +# CHECK-NEXT: Offset: 0x11020 +# CHECK-NEXT: Size: 42 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 1 # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: SectionData ( -# CHECK: ) +# CHECK-NEXT: 0000: 002E7465 7874002E 636F6D6D 656E7400 |..text..comment.| +# CHECK-NEXT: 0010: 2E73796D 74616200 2E736873 74727461 |.symtab..shstrta| +# CHECK-NEXT: 0020: 62002E73 74727461 6200 |b..strtab.| +# CHECK-NEXT: ) # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 9 -# CHECK-NEXT: Name: .strtab -# CHECK-NEXT: Type: SHT_STRTAB +# CHECK-NEXT: Index: 5 +# CHECK-NEXT: Name: .strtab (34) +# CHECK-NEXT: Type: SHT_STRTAB (0x3) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x30077 -# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Offset: 0x1104A +# CHECK-NEXT: Size: 1 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 1 # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: SectionData ( -# CHECK-NEXT: 0000: 005F7374 61727400 |._start.| +# CHECK-NEXT: 0000: 00 |.| # CHECK-NEXT: ) # CHECK-NEXT: } # CHECK-NEXT: ] @@ -236,74 +150,49 @@ _start: # CHECK-NEXT: Offset: 0x40 # CHECK-NEXT: VirtualAddress: 0x10000040 # CHECK-NEXT: PhysicalAddress: 0x10000040 -# CHECK-NEXT: FileSize: 336 -# CHECK-NEXT: MemSize: 336 -# CHECK-NEXT: Flags [ -# CHECK-NEXT: PF_R +# CHECK-NEXT: FileSize: 224 +# CHECK-NEXT: MemSize: 224 +# CHECK-NEXT: Flags [ (0x4) +# CHECK-NEXT: PF_R (0x4) # CHECK-NEXT: ] # CHECK-NEXT: Alignment: 8 # CHECK-NEXT: } -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_LOAD (0x1) -# CHECK-NEXT: Offset: 0x0 -# CHECK-NEXT: VirtualAddress: 0x10000000 -# CHECK-NEXT: PhysicalAddress: 0x10000000 -# CHECK-NEXT: FileSize: 400 -# CHECK-NEXT: MemSize: 400 -# CHECK-NEXT: Flags [ -# CHECK-NEXT: PF_R -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 65536 -# CHECK-NEXT: } -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_LOAD (0x1) -# CHECK-NEXT: Offset: 0x10000 -# CHECK-NEXT: VirtualAddress: 0x10010000 -# CHECK-NEXT: PhysicalAddress: 0x10010000 -# CHECK-NEXT: FileSize: 12 -# CHECK-NEXT: MemSize: 12 -# CHECK-NEXT: Flags [ (0x5) -# CHECK-NEXT: PF_R (0x4) -# CHECK-NEXT: PF_X (0x1) -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 65536 -# CHECK-NEXT: } -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_LOAD (0x1) -# CHECK-NEXT: Offset: 0x20000 -# CHECK-NEXT: VirtualAddress: 0x10020000 -# CHECK-NEXT: PhysicalAddress: 0x10020000 -# CHECK-NEXT: FileSize: 65536 -# CHECK-NEXT: MemSize: 65536 -# CHECK-NEXT: Flags [ (0x6) -# CHECK-NEXT: PF_R (0x4) -# CHECK-NEXT: PF_W (0x2) -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 65536 -# CHECK-NEXT: } -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_GNU_RELRO -# CHECK-NEXT: Offset: 0x30000 -# CHECK-NEXT: VirtualAddress: 0x10030000 -# CHECK-NEXT: PhysicalAddress: 0x10030000 -# CHECK-NEXT: FileSize: 0 -# CHECK-NEXT: MemSize: 0 -# CHECK-NEXT: Flags [ (0x4) -# CHECK-NEXT: PF_R (0x4) -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 1 -# CHECK-NEXT: } -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_GNU_STACK (0x6474E551) -# CHECK-NEXT: Offset: 0x0 -# CHECK-NEXT: VirtualAddress: 0x0 -# CHECK-NEXT: PhysicalAddress: 0x0 -# CHECK-NEXT: FileSize: 0 -# CHECK-NEXT: MemSize: 0 -# CHECK-NEXT: Flags [ (0x6) -# CHECK-NEXT: PF_R (0x4) -# CHECK-NEXT: PF_W (0x2) -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 0 -# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD (0x1) +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x10000000 +# CHECK-NEXT: PhysicalAddress: 0x10000000 +# CHECK-NEXT: FileSize: 288 +# CHECK-NEXT: MemSize: 288 +# CHECK-NEXT: Flags [ (0x4) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 65536 +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD (0x1) +# CHECK-NEXT: Offset: 0x10000 +# CHECK-NEXT: VirtualAddress: 0x10010000 +# CHECK-NEXT: PhysicalAddress: 0x10010000 +# CHECK-NEXT: FileSize: 4096 +# CHECK-NEXT: MemSize: 4096 +# CHECK-NEXT: Flags [ (0x5) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: PF_X (0x1) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 65536 +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_GNU_STACK (0x6474E551) +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x0 +# CHECK-NEXT: PhysicalAddress: 0x0 +# CHECK-NEXT: FileSize: 0 +# CHECK-NEXT: MemSize: 0 +# CHECK-NEXT: Flags [ (0x6) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: PF_W (0x2) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 0 +# CHECK-NEXT: } # CHECK-NEXT: ] diff --git a/test/ELF/bss.s b/test/ELF/bss.s index abd7f2e564d7..d35449828aed 100644 --- a/test/ELF/bss.s +++ b/test/ELF/bss.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t // RUN: ld.lld %t -o %t2 // RUN: llvm-readobj -sections %t2 | FileCheck %s -// REQUIRES: x86 // Test that bss takes no space on disk. diff --git a/test/ELF/bsymbolic-undef.s b/test/ELF/bsymbolic-undef.s index 19bb3162fd95..1269cb456228 100644 --- a/test/ELF/bsymbolic-undef.s +++ b/test/ELF/bsymbolic-undef.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o # RUN: ld.lld -shared -Bsymbolic %t.o -o %t.so # RUN: llvm-readobj -dyn-symbols %t.so | FileCheck %s diff --git a/test/ELF/bsymbolic.s b/test/ELF/bsymbolic.s index 5a089d55492d..adb9b3ce3630 100644 --- a/test/ELF/bsymbolic.s +++ b/test/ELF/bsymbolic.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o // RUN: ld.lld -shared %t.o -o %t0.so // RUN: ld.lld -shared -Bsymbolic %t.o -o %t1.so diff --git a/test/ELF/build-id.s b/test/ELF/build-id.s index 9447a14d4e8a..5ff2996dc8ea 100644 --- a/test/ELF/build-id.s +++ b/test/ELF/build-id.s @@ -7,6 +7,8 @@ # RUN: ld.lld --build-id %t -o %t2 -threads # RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=DEFAULT %s +# RUN: ld.lld --build-id=fast %t -o %t2 -threads +# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=DEFAULT %s # RUN: ld.lld --build-id %t -o %t2 -no-threads # RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=DEFAULT %s diff --git a/test/ELF/cgprofile-bad-clusters.s b/test/ELF/cgprofile-bad-clusters.s new file mode 100644 index 000000000000..a6a09bd04252 --- /dev/null +++ b/test/ELF/cgprofile-bad-clusters.s @@ -0,0 +1,70 @@ +# REQUIRES: x86 +# This test checks that CallGraphSort ignores edges that would form "bad" +# clusters. + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "A C 1" > %t.call_graph +# RUN: echo "E B 4" >> %t.call_graph +# RUN: echo "C D 2" >> %t.call_graph +# RUN: echo "B D 1" >> %t.call_graph +# RUN: echo "F G 6" >> %t.call_graph +# RUN: echo "G H 5" >> %t.call_graph +# RUN: echo "H I 4" >> %t.call_graph +# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2 +# RUN: llvm-readobj -symbols %t2 | FileCheck %s + + .section .text.A,"ax",@progbits + .globl A +A: + retq + + .section .text.D,"ax",@progbits +D: + .fill 1000, 1, 0 + + .section .text.E,"ax",@progbits +E: + retq + + .section .text.C,"ax",@progbits +C: + retq + + .section .text.B,"ax",@progbits +B: + .fill 1000, 1, 0 + + .section .text.F,"ax",@progbits +F: + .fill (1024 * 1024) - 1, 1, 0 + + .section .text.G,"ax",@progbits +G: + retq + + .section .text.H,"ax",@progbits +H: + retq + + .section .text.I,"ax",@progbits +I: + .fill 13, 1, 0 + +# CHECK: Name: B +# CHECK-NEXT: Value: 0x201011 +# CHECK: Name: C +# CHECK-NEXT: Value: 0x20100F +# CHECK: Name: D +# CHECK-NEXT: Value: 0x2013F9 +# CHECK: Name: E +# CHECK-NEXT: Value: 0x201010 +# CHECK: Name: F +# CHECK-NEXT: Value: 0x2017E1 +# CHECK: Name: G +# CHECK-NEXT: Value: 0x3017E0 +# CHECK: Name: H +# CHECK-NEXT: Value: 0x201000 +# CHECK: Name: I +# CHECK-NEXT: Value: 0x201001 +# CHECK: Name: A +# CHECK-NEXT: Value: 0x20100E diff --git a/test/ELF/cgprofile-err.s b/test/ELF/cgprofile-err.s new file mode 100644 index 000000000000..6b5425dfafab --- /dev/null +++ b/test/ELF/cgprofile-err.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: echo "A B C 100" > %t.call_graph +# RUN: not ld.lld %t --call-graph-ordering-file \ +# RUN: %t.call_graph -o /dev/null 2>&1 | FileCheck %s + +# CHECK: {{.*}}.call_graph: parse error + +# RUN: echo "A B C" > %t.call_graph +# RUN: not ld.lld %t --call-graph-ordering-file \ +# RUN: %t.call_graph -o /dev/null 2>&1 | FileCheck %s diff --git a/test/ELF/cgprofile-icf.s b/test/ELF/cgprofile-icf.s new file mode 100644 index 000000000000..93b7274a5d33 --- /dev/null +++ b/test/ELF/cgprofile-icf.s @@ -0,0 +1,53 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: echo "A B 100" > %t.call_graph +# RUN: echo "A C 40" >> %t.call_graph +# RUN: echo "C D 61" >> %t.call_graph +# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t.out -icf=all +# RUN: llvm-readobj -symbols %t.out | FileCheck %s +# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2.out +# RUN: llvm-readobj -symbols %t2.out | FileCheck %s --check-prefix=NOICF + + .section .text.D,"ax",@progbits + .globl D +D: + mov $60, %rax + retq + + .section .text.C,"ax",@progbits + .globl C +C: + mov $60, %rax + retq + + .section .text.B,"ax",@progbits + .globl B +B: + mov $2, %rax + retq + + .section .text.A,"ax",@progbits + .globl A +A: + mov $42, %rax + retq + +# CHECK: Name: A +# CHECK-NEXT: Value: 0x201000 +# CHECK: Name: B +# CHECK-NEXT: Value: 0x201010 +# CHECK: Name: C +# CHECK-NEXT: Value: 0x201008 +# CHECK: Name: D +# CHECK-NEXT: Value: 0x201008 + +# NOICF: Name: A +# NOICF-NEXT: Value: 0x201000 +# NOICF: Name: B +# NOICF-NEXT: Value: 0x201008 +# NOICF: Name: C +# NOICF-NEXT: Value: 0x201010 +# NOICF: Name: D +# NOICF-NEXT: Value: 0x201018 diff --git a/test/ELF/cgprofile-txt.s b/test/ELF/cgprofile-txt.s new file mode 100644 index 000000000000..ee5149aac90d --- /dev/null +++ b/test/ELF/cgprofile-txt.s @@ -0,0 +1,185 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld -e A %t -o %t2 +# RUN: llvm-readobj -symbols %t2 | FileCheck %s --check-prefix=NOSORT + +# RUN: echo "A B 10" > %t.call_graph +# RUN: echo "A B 10" >> %t.call_graph +# RUN: echo "Aa B 80" >> %t.call_graph +# RUN: echo "A C 40" >> %t.call_graph +# RUN: echo "B C 30" >> %t.call_graph +# RUN: echo "C D 90" >> %t.call_graph +# RUN: echo "PP TS 100" >> %t.call_graph +# RUN: echo "_init2 _init 24567837" >> %t.call_graph +# RUN: echo "TS QC 9001" >> %t.call_graph +# RUN: echo "TooManyPreds0 TooManyPreds 10" >> %t.call_graph +# RUN: echo "TooManyPreds1 TooManyPreds 10" >> %t.call_graph +# RUN: echo "TooManyPreds2 TooManyPreds 10" >> %t.call_graph +# RUN: echo "TooManyPreds3 TooManyPreds 10" >> %t.call_graph +# RUN: echo "TooManyPreds4 TooManyPreds 10" >> %t.call_graph +# RUN: echo "TooManyPreds5 TooManyPreds 10" >> %t.call_graph +# RUN: echo "TooManyPreds6 TooManyPreds 10" >> %t.call_graph +# RUN: echo "TooManyPreds7 TooManyPreds 10" >> %t.call_graph +# RUN: echo "TooManyPreds8 TooManyPreds 10" >> %t.call_graph +# RUN: echo "TooManyPreds9 TooManyPreds 10" >> %t.call_graph +# RUN: echo "TooManyPreds10 TooManyPreds 11" >> %t.call_graph +# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2 +# RUN: llvm-readobj -symbols %t2 | FileCheck %s + + .section .text.D,"ax",@progbits +D: + retq + + .section .text.C,"ax",@progbits + .globl C +C: + retq + + .section .text.B,"ax",@progbits + .globl B +B: + retq + + .section .text.A,"ax",@progbits + .globl A +A: +Aa: + retq + + .section .ponies,"ax",@progbits,unique,1 + .globl TS +TS: + retq + + .section .ponies,"ax",@progbits,unique,2 + .globl PP +PP: + retq + + .section .other,"ax",@progbits,unique,1 + .globl QC +QC: + retq + + .section .other,"ax",@progbits,unique,2 + .globl GB +GB: + retq + + .section .init,"ax",@progbits,unique,1 + .globl _init +_init: + retq + + .section .init,"ax",@progbits,unique,2 + .globl _init2 +_init2: + retq + + .section .text.TooManyPreds,"ax",@progbits +TooManyPreds: + retq + retq + retq + retq + retq + retq + retq + retq + retq + retq + + .section .text.TooManyPreds0,"ax",@progbits +TooManyPreds0: + retq + + .section .text.TooManyPreds1,"ax",@progbits +TooManyPreds1: + retq + + .section .text.TooManyPreds2,"ax",@progbits +TooManyPreds2: + retq + + .section .text.TooManyPreds3,"ax",@progbits +TooManyPreds3: + retq + + .section .text.TooManyPreds4,"ax",@progbits +TooManyPreds4: + retq + + .section .text.TooManyPreds5,"ax",@progbits +TooManyPreds5: + retq + + .section .text.TooManyPreds6,"ax",@progbits +TooManyPreds6: + retq + + .section .text.TooManyPreds7,"ax",@progbits +TooManyPreds7: + retq + + .section .text.TooManyPreds8,"ax",@progbits +TooManyPreds8: + retq + + .section .text.TooManyPreds9,"ax",@progbits +TooManyPreds9: + retq + + .section .text.TooManyPreds10,"ax",@progbits +TooManyPreds10: + retq + +# CHECK: Name: D +# CHECK-NEXT: Value: 0x201003 +# CHECK: Name: TooManyPreds +# CHECK-NEXT: Value: 0x201004 +# CHECK: Name: TooManyPreds10 +# CHECK-NEXT: Value: 0x201018 +# CHECK: Name: A +# CHECK-NEXT: Value: 0x201000 +# CHECK: Name: B +# CHECK-NEXT: Value: 0x201001 +# CHECK: Name: C +# CHECK-NEXT: Value: 0x201002 +# CHECK: Name: GB +# CHECK-NEXT: Value: 0x20101F +# CHECK: Name: PP +# CHECK-NEXT: Value: 0x20101C +# CHECK: Name: QC +# CHECK-NEXT: Value: 0x20101E +# CHECK: Name: TS +# CHECK-NEXT: Value: 0x20101D +# CHECK: Name: _init +# CHECK-NEXT: Value: 0x201020 +# CHECK: Name: _init2 +# CHECK-NEXT: Value: 0x201021 + +# NOSORT: Name: D +# NOSORT-NEXT: Value: 0x201000 +# NOSORT: Name: TooManyPreds +# NOSORT-NEXT: Value: 0x201004 +# NOSORT: Name: TooManyPreds10 +# NOSORT-NEXT: Value: 0x201018 +# NOSORT: Name: A +# NOSORT-NEXT: Value: 0x201003 +# NOSORT: Name: B +# NOSORT-NEXT: Value: 0x201002 +# NOSORT: Name: C +# NOSORT-NEXT: Value: 0x201001 +# NOSORT: Name: GB +# NOSORT-NEXT: Value: 0x20101C +# NOSORT: Name: PP +# NOSORT-NEXT: Value: 0x20101A +# NOSORT: Name: QC +# NOSORT-NEXT: Value: 0x20101B +# NOSORT: Name: TS +# NOSORT-NEXT: Value: 0x201019 +# NOSORT: Name: _init +# NOSORT-NEXT: Value: 0x20101D +# NOSORT: Name: _init2 +# NOSORT-NEXT: Value: 0x20101E diff --git a/test/ELF/cgprofile-warn.s b/test/ELF/cgprofile-warn.s new file mode 100644 index 000000000000..bfb89c4c3b57 --- /dev/null +++ b/test/ELF/cgprofile-warn.s @@ -0,0 +1,36 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: echo "A B 100" > %t.call_graph +# RUN: echo "A C 40" >> %t.call_graph +# RUN: echo "B C 30" >> %t.call_graph +# RUN: echo "adena1 A 30" >> %t.call_graph +# RUN: echo "A adena2 30" >> %t.call_graph +# RUN: echo "poppy A 30" >> %t.call_graph +# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o /dev/null \ +# RUN: -noinhibit-exec -icf=all 2>&1 | FileCheck %s + + .section .text.C,"ax",@progbits + .globl C +C: + mov poppy, %rax + retq + +B = 0x1234 + + .section .text.A,"ax",@progbits + .globl A +A: + mov poppy, %rax + retq + +# CHECK: unable to order absolute symbol: B +# CHECK: {{.*}}.call_graph: no such symbol: adena1 +# CHECK: {{.*}}.call_graph: no such symbol: adena2 +# CHECK: unable to order undefined symbol: poppy + +# RUN: ld.lld %t --call-graph-ordering-file %t.call_graph -o /dev/null \ +# RUN: -noinhibit-exec -icf=all --no-warn-symbol-ordering 2>&1 \ +# RUN: | FileCheck %s --check-prefix=NOWARN +# NOWARN-NOT: unable to order diff --git a/test/ELF/color-diagnostics.test b/test/ELF/color-diagnostics.test index 074bba29c54a..6dfa0ab1af92 100644 --- a/test/ELF/color-diagnostics.test +++ b/test/ELF/color-diagnostics.test @@ -9,6 +9,9 @@ # COLOR: {{ld.lld: .\[0;1;31merror: .\[0munknown argument: -xyz}} # COLOR: {{ld.lld: .\[0;1;31merror: .\[0mcannot open /nosuchfile}} +# RUN: not ld.lld -color-diagnostics=foobar 2>&1 | FileCheck -check-prefix=ERR %s +# ERR: unknown option: --color-diagnostics=foobar + # RUN: not ld.lld /nosuchfile 2>&1 | FileCheck -check-prefix=NOCOLOR %s # RUN: not ld.lld -color-diagnostics=never /nosuchfile 2>&1 \ # RUN: | FileCheck -check-prefix=NOCOLOR %s diff --git a/test/ELF/combrelocs.s b/test/ELF/combrelocs.s index 3c8be807053b..595f6049f5fa 100644 --- a/test/ELF/combrelocs.s +++ b/test/ELF/combrelocs.s @@ -4,6 +4,9 @@ # RUN: ld.lld -shared %t.o -o %t.out # RUN: llvm-readobj -r --expand-relocs --dynamic-table %t.out | FileCheck %s +# RUN: ld.lld -shared %t.o -o %t.out -z combreloc +# RUN: llvm-readobj -r --expand-relocs --dynamic-table %t.out | FileCheck %s + # CHECK: Relocations [ # CHECK-NEXT: Section ({{.*}}) .rela.dyn { # CHECK-NEXT: Relocation { diff --git a/test/ELF/comdat-discarded-reloc.s b/test/ELF/comdat-discarded-reloc.s new file mode 100644 index 000000000000..d23baf386e92 --- /dev/null +++ b/test/ELF/comdat-discarded-reloc.s @@ -0,0 +1,17 @@ +# 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/comdat-discarded-reloc.s -o %t2.o +# RUN: ld.lld -gc-sections %t.o %t2.o -o %t + +## ELF spec doesn't allow a relocation to point to a deduplicated +## COMDAT section. Unfortunately this happens in practice (e.g. .eh_frame) +## Test case checks we do not crash. + +.global bar, _start + +.section .text.foo,"aG",@progbits,group,comdat + +.section .text +_start: + .quad .text.foo + .quad bar diff --git a/test/ELF/comdat-linkonce.s b/test/ELF/comdat-linkonce.s index 78611b4a9f26..8721f58bb20c 100644 --- a/test/ELF/comdat-linkonce.s +++ b/test/ELF/comdat-linkonce.s @@ -1,3 +1,4 @@ +// 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/comdat.s -o %t2.o // RUN: ld.lld -shared %t.o %t2.o -o %t diff --git a/test/ELF/comdat.s b/test/ELF/comdat.s index 5b190b177ee0..4728dd34af5f 100644 --- a/test/ELF/comdat.s +++ b/test/ELF/comdat.s @@ -1,18 +1,18 @@ +// 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/comdat.s -o %t2.o // RUN: ld.lld -shared %t.o %t.o %t2.o -o %t // RUN: llvm-objdump -d %t | FileCheck %s // RUN: llvm-readobj -s -t %t | FileCheck --check-prefix=READ %s -// REQUIRES: x86 // Check that we don't crash with --gc-section and that we print a list of // reclaimed sections on stderr. // RUN: ld.lld --gc-sections --print-gc-sections -shared %t.o %t.o %t2.o -o %t \ // RUN: 2>&1 | FileCheck --check-prefix=GC %s -// GC: removing unused section from '.text' in file -// GC: removing unused section from '.text3' in file -// GC: removing unused section from '.text' in file -// GC: removing unused section from '.text' in file +// GC: removing unused section {{.*}}.o:(.text) +// GC: removing unused section {{.*}}.o:(.text3) +// GC: removing unused section {{.*}}.o:(.text) +// GC: removing unused section {{.*}}.o:(.text) .section .text2,"axG",@progbits,foo,comdat,unique,0 foo: diff --git a/test/ELF/common.s b/test/ELF/common.s index 7f241ee4d65b..da6657173bfd 100644 --- a/test/ELF/common.s +++ b/test/ELF/common.s @@ -1,8 +1,8 @@ +// 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 %p/Inputs/common.s -o %t2 // RUN: ld.lld %t %t2 -o %t3 // RUN: llvm-readobj -t -s %t3 | FileCheck %s -// REQUIRES: x86 // CHECK: Name: .bss // CHECK-NEXT: Type: SHT_NOBITS diff --git a/test/ELF/compatible-section-types.s b/test/ELF/compatible-section-types.s index a5dadb867dc0..e47006c5514a 100644 --- a/test/ELF/compatible-section-types.s +++ b/test/ELF/compatible-section-types.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: ld.lld -shared %t.o -o %t // RUN: llvm-objdump -section-headers %t | FileCheck %s diff --git a/test/ELF/compress-debug-sections-reloc.s b/test/ELF/compress-debug-sections-reloc.s new file mode 100644 index 000000000000..b4ee4ea6dd97 --- /dev/null +++ b/test/ELF/compress-debug-sections-reloc.s @@ -0,0 +1,26 @@ +# REQUIRES: x86, zlib + +# 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/Inputs/compress-debug.s -o %t2.o +# RUN: ld.lld %t2.o %t.o -o %t1 --compress-debug-sections=zlib -Ttext=0 +# RUN: llvm-dwarfdump %t1 -debug-str | FileCheck %s +# These two checks correspond to the patched values of a_sym and a_debug_sym. +# D = 0x44 - address of .text input section for this file (the start address of +# .text is 0 as requested on the command line, and the size of the +# preceding .text in the other input file is 0x44). +# C = 0x43 - offset of .debug_info section for this file (the size of +# the preceding .debug_info from the other input file is 0x43). +# CHECK: 0x00000000: "D" +# CHECK: 0x00000004: "C" + +.text +a_sym: +nop + +.section .debug_str,"",@progbits +.long a_sym +.long a_debug_sym + +.section .debug_info,"",@progbits +a_debug_sym: +.long 0x88776655 diff --git a/test/ELF/compressed-debug-conflict.s b/test/ELF/compressed-debug-conflict.s index c67bc9201803..e8c24262b7f4 100644 --- a/test/ELF/compressed-debug-conflict.s +++ b/test/ELF/compressed-debug-conflict.s @@ -1,15 +1,15 @@ # REQUIRES: x86, zlib # RUN: llvm-mc -filetype=obj -triple i686-linux-gnu -compress-debug-sections=zlib %s -o %t.o # RUN: llvm-readobj -sections %t.o | FileCheck -check-prefix=OBJ %s -# RUN: not ld.lld %t.o %t.o -o %tout 2>&1 | FileCheck -check-prefix=ERROR %s +# RUN: not ld.lld %t.o %t.o -o /dev/null 2>&1 | FileCheck -check-prefix=ERROR %s # OBJ: Sections [ # OBJ: Section { -# OBJ: Index: 3 -# OBJ-NEXT: Name: .debug_line (16) -# OBJ-NEXT: Type: SHT_PROGBITS (0x1) -# OBJ-NEXT: Flags [ (0x800) -# OBJ-NEXT: SHF_COMPRESSED (0x800) +# OBJ: Index: +# OBJ: Name: .debug_line +# OBJ-NEXT: Type: SHT_PROGBITS +# OBJ-NEXT: Flags [ +# OBJ-NEXT: SHF_COMPRESSED # OBJ-NEXT: ] # ERROR: error: duplicate symbol: main @@ -27,3 +27,24 @@ main: xorl %eax, %eax retl .file 2 "/tmp/repeat/repeat/repeat/repeat" "repeat.h" + + .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 4 # 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/compressed-debug-input-err.s b/test/ELF/compressed-debug-input-err.s new file mode 100644 index 000000000000..e32ba315b342 --- /dev/null +++ b/test/ELF/compressed-debug-input-err.s @@ -0,0 +1,11 @@ +# REQUIRES: zlib, x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s + +## Check we are able to report zlib decompressor errors. +# CHECK: error: {{.*}}.o:(.zdebug_str): decompress failed: zlib error: Z_DATA_ERROR + +.section .zdebug_str,"MS",@progbits,1 + .ascii "ZLIB" + .byte 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1 diff --git a/test/ELF/conflict-debug-variable-file-index.s b/test/ELF/conflict-debug-variable-file-index.s new file mode 100644 index 000000000000..c7bd8bbcbafb --- /dev/null +++ b/test/ELF/conflict-debug-variable-file-index.s @@ -0,0 +1,103 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: not ld.lld %t.o %t.o -o %t 2>&1 | FileCheck %s + +## Check we are able to report errors even if DW_AT_decl_file +## contains invalid file name index. +## We did not try to support this intentionally but have +## an error handling and reporting logic that can take care +## of that and hence needs a test. + +# CHECK: duplicate symbol: foo +# CHECK-NEXT: >>> defined at {{.*}}.o:(foo) +# CHECK-NEXT: >>> {{.*}}.o:(.bss+0x0) + +# Used modified output from the following code and gcc 7.1.0: +# Source (1.c): +# int foo = 0; +# Invocation: g++ -g -S 1.c + +.bss +.globl foo +.type foo, @object +.size foo, 4 +foo: + +.text +.file 1 "1.c" + +.section .debug_info,"",@progbits + .long 0x35 # Compile Unit: length = 0x0000004b) + .value 0x4 # version = 0x0004 + .long 0 # abbr_offset = 0x0 + .byte 0x8 # addr_size = 0x08 + + .uleb128 0x1 # DW_TAG_compile_unit [1] * + .long 0 # DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000000] = ) + .byte 0x4 # DW_AT_language [DW_FORM_data1] (DW_LANG_C_plus_plus) + .string "1.c" # DW_AT_name [DW_FORM_string] ("1.c") + .long 0 # DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x00000000] = ) + .long 0 # DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000) + + .uleb128 0x2 # DW_TAG_variable [2] + .string "foo" # DW_AT_name [DW_FORM_string] ("foo") + .byte 0xFE # DW_AT_decl_file [DW_FORM_data1] <broken file> + .byte 0x1 # DW_AT_decl_line [DW_FORM_data1] (1) + .long 0x32 # DW_AT_type [DW_FORM_ref4] (cu + 0x0032 => {0x00000032}) + .uleb128 0x9 # DW_AT_external [DW_FORM_flag_present] (true) + .byte 0x3 + .quad foo # DW_AT_location [DW_FORM_exprloc] (DW_OP_addr 0x0) + + .uleb128 0x3 # DW_TAG_base_type [3] + .byte 0x4 # DW_AT_byte_size [DW_FORM_data1] (0x04) + .byte 0x5 # DW_AT_encoding [DW_FORM_data1] (DW_ATE_signed) + .string "int" # DW_AT_name [DW_FORM_string] ("int") + +.section .debug_abbrev,"",@progbits + .uleb128 0x1 # Abbreviation code. + .uleb128 0x11 # DW_TAG_compile_unit + + .byte 0x1 # ID + .uleb128 0x25 # DW_AT_producer, DW_FORM_strp + .uleb128 0xe + .uleb128 0x13 # DW_AT_language, DW_FORM_data1 + .uleb128 0xb + .uleb128 0x3 # DW_AT_name, DW_FORM_string + .uleb128 0x8 + .uleb128 0x1b # DW_AT_comp_dir, DW_FORM_strp + .uleb128 0xe + .uleb128 0x10 # DW_AT_stmt_list, DW_FORM_sec_offset + .uleb128 0x17 + .byte 0 + .byte 0 + + .uleb128 0x2 # ID + .uleb128 0x34 # DW_TAG_variable, DW_CHILDREN_no + .byte 0 + .uleb128 0x3 # DW_AT_name, DW_FORM_string + .uleb128 0x8 + .uleb128 0x3a # DW_AT_decl_file, DW_FORM_data1 + .uleb128 0xb + .uleb128 0x3b # DW_AT_decl_line, DW_FORM_data1 + .uleb128 0xb + .uleb128 0x49 # DW_AT_type, DW_FORM_ref4 + .uleb128 0x13 + .uleb128 0x3f # DW_AT_external, DW_FORM_flag_present + .uleb128 0x19 + .uleb128 0x2 # DW_AT_location, DW_FORM_exprloc + .uleb128 0x18 + .byte 0 + .byte 0 + + .uleb128 0x3 # ID + .uleb128 0x24 # DW_TAG_base_type, DW_CHILDREN_no + .byte 0 + .uleb128 0xb # DW_AT_byte_size, DW_FORM_data1 + .uleb128 0xb + .uleb128 0x3e # DW_AT_encoding, DW_FORM_data1 + .uleb128 0xb + .uleb128 0x3 # DW_AT_name, DW_FORM_string + .uleb128 0x8 + .byte 0 + .byte 0 + .byte 0 diff --git a/test/ELF/conflict-debug-variable.s b/test/ELF/conflict-debug-variable.s index 297ed4bbe1ea..244ac146a01b 100644 --- a/test/ELF/conflict-debug-variable.s +++ b/test/ELF/conflict-debug-variable.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o # RUN: llvm-dwarfdump %t.o | FileCheck -check-prefix=INPUT %s # RUN: not ld.lld %t.o %t.o -o %t 2>&1 | FileCheck %s @@ -7,14 +8,14 @@ # INPUT-NEXT: DW_AT_name ("foo") # INPUT-NEXT: DW_AT_decl_file ("1.c") # INPUT-NEXT: DW_AT_decl_line (1) -# INPUT-NEXT: DW_AT_type (cu + 0x0032 "int") +# INPUT-NEXT: DW_AT_type (0x00000032 "int") # INPUT-NEXT: DW_AT_external (true) # INPUT-NEXT: DW_AT_location (DW_OP_addr 0x0) # INPUT: DW_TAG_variable # INPUT-NEXT: DW_AT_name ("bar") # INPUT-NEXT: DW_AT_decl_file ("1.c") # INPUT-NEXT: DW_AT_decl_line (2) -# INPUT-NEXT: DW_AT_type (cu + 0x0032 "int") +# INPUT-NEXT: DW_AT_type (0x00000032 "int") # INPUT-NEXT: DW_AT_external (true) # INPUT-NEXT: DW_AT_location (DW_OP_addr 0x0) @@ -38,6 +39,7 @@ # Source (1.c): # int foo = 0; # int bar = 1; +# static int zed = 3; # Invocation: g++ -g -S 1.c .bss @@ -51,12 +53,16 @@ foo: .type bar, @object .size bar, 4 bar: + .byte 0 + +.local zed +zed: .text .file 1 "1.c" .section .debug_info,"",@progbits - .long 0x4b # Compile Unit: length = 0x0000004b) + .long 0x5a # Compile Unit: length = 0x0000004b) .value 0x4 # version = 0x0004 .long 0 # abbr_offset = 0x0 .byte 0x8 # addr_size = 0x08 @@ -90,6 +96,14 @@ bar: .uleb128 0x9 # DW_AT_external [DW_FORM_flag_present] (true) .byte 0x3 .quad bar # DW_AT_location [DW_FORM_exprloc] (DW_OP_addr 0x0) + + .uleb128 0x4 # DW_TAG_variable [2] + .string "zed" # DW_AT_name [DW_FORM_string] ("zed") + .byte 0x1 # DW_AT_decl_file [DW_FORM_data1] ("1.c") + .byte 0x3 # DW_AT_decl_line [DW_FORM_data1] (2) + .long 0x32 # DW_AT_type [DW_FORM_ref4] (cu + 0x0032 => {0x00000032}) + .quad zed # DW_AT_location [DW_FORM_exprloc] (DW_OP_addr 0x0) + .byte 0 # END @@ -140,5 +154,21 @@ bar: .uleb128 0x8 .byte 0 .byte 0 + + .uleb128 0x4 # ID + .uleb128 0x34 # DW_TAG_variable, DW_CHILDREN_no + .byte 0 + .uleb128 0x3 # DW_AT_name, DW_FORM_string + .uleb128 0x8 + .uleb128 0x3a # DW_AT_decl_file, DW_FORM_data1 + .uleb128 0xb + .uleb128 0x3b # DW_AT_decl_line, DW_FORM_data1 + .uleb128 0xb + .uleb128 0x49 # DW_AT_type, DW_FORM_ref4 + .uleb128 0x13 + .uleb128 0x2 # DW_AT_location, DW_FORM_exprloc + .uleb128 0x18 + .byte 0 .byte 0 + .byte 0 diff --git a/test/ELF/conflict-debug-variable2.s b/test/ELF/conflict-debug-variable2.s index 1fb9b09443b4..3fb59e6b4d02 100644 --- a/test/ELF/conflict-debug-variable2.s +++ b/test/ELF/conflict-debug-variable2.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o # RUN: llvm-dwarfdump -v %t.o | FileCheck -check-prefix=INPUT %s @@ -18,7 +19,7 @@ # INPUT-NEXT: DW_AT_location [DW_FORM_exprloc] (DW_OP_addr 0x0) ## Check we use information from .debug_info in messages. -# RUN: not ld.lld %t.o %t.o -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o %t.o -o /dev/null 2>&1 | FileCheck %s # CHECK: duplicate symbol: bar # CHECK-NEXT: >>> defined at test.c:2 # CHECK-NEXT: >>> {{.*}}:(bar) diff --git a/test/ELF/conflict-variable-linkage-name.s b/test/ELF/conflict-variable-linkage-name.s new file mode 100644 index 000000000000..9b201d93a830 --- /dev/null +++ b/test/ELF/conflict-variable-linkage-name.s @@ -0,0 +1,176 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: not ld.lld %t.o %t.o -o /dev/null 2>&1 | FileCheck %s + +## Check we can report the locations of 2 different "bar" variables. +# CHECK: duplicate symbol: A::bar +# CHECK-NEXT: >>> defined at 1.cpp:2 +# CHECK-NEXT: >>> {{.*}}:(A::bar) +# CHECK-NEXT: >>> defined at 1.cpp:2 +# CHECK-NEXT: >>> {{.*}}:(.bss+0x0) +# CHECK: duplicate symbol: Z::bar +# CHECK-NEXT: >>> defined at 1.cpp:6 +# CHECK-NEXT: >>> {{.*}}:(Z::bar) +# CHECK-NEXT: >>> defined at 1.cpp:6 +# CHECK-NEXT: >>> {{.*}}:(.data+0x0) + +# Used reduced output from following code and clang version 7.0.0 (trunk 332701) +# to produce this input file: +# Source (1.cpp): +# namespace A { +# int bar; +# } +# +# namespace Z { +# int bar; +# } +# Invocation: clang-7 -g -S 1.cpp + +.text +.file "1.cpp" +.file 1 "/path" "1.cpp" + +.type _ZN1A3barE,@object +.bss +.globl _ZN1A3barE +_ZN1A3barE: + .long 0 + .size _ZN1A3barE, 4 + +.type _ZN1Z3barE,@object +.data +.globl _ZN1Z3barE +_ZN1Z3barE: + .long 1 + .size _ZN1Z3barE, 4 + +.section .debug_str,"MS",@progbits,1 +.Linfo_string0: + .asciz "clang version 7.0.0 (trunk 332701)" # string offset=0 +.Linfo_string1: + .asciz "1.cpp" # string offset=35 +.Linfo_string2: + .asciz "/path" # string offset=41 +.Linfo_string3: + .asciz "A" # string offset=87 +.Linfo_string4: + .asciz "bar" # string offset=89 +.Linfo_string5: + .asciz "int" # string offset=93 +.Linfo_string6: + .asciz "_ZN1A3barE" # string offset=97 +.Linfo_string7: + .asciz "Z" # string offset=108 +.Linfo_string8: + .asciz "_ZN1Z3barE" # string offset=110 + +.section .debug_abbrev,"",@progbits + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 1 # DW_CHILDREN_yes + .byte 37 # DW_AT_producer + .byte 14 # DW_FORM_strp + .byte 19 # DW_AT_language + .byte 5 # DW_FORM_data2 + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 16 # DW_AT_stmt_list + .byte 23 # DW_FORM_sec_offset + .byte 27 # DW_AT_comp_dir + .byte 14 # DW_FORM_strp + .ascii "\264B" # DW_AT_GNU_pubnames + .byte 25 # DW_FORM_flag_present + .byte 0 # EOM(1) + .byte 0 # EOM(2) + + .byte 2 # Abbreviation Code + .byte 57 # DW_TAG_namespace + .byte 1 # DW_CHILDREN_yes + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 0 # EOM(1) + .byte 0 # EOM(2) + + .byte 3 # Abbreviation Code + .byte 52 # DW_TAG_variable + .byte 0 # DW_CHILDREN_no + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 63 # DW_AT_external + .byte 25 # DW_FORM_flag_present + .byte 58 # DW_AT_decl_file + .byte 11 # DW_FORM_data1 + .byte 59 # DW_AT_decl_line + .byte 11 # DW_FORM_data1 + .byte 2 # DW_AT_location + .byte 24 # DW_FORM_exprloc + .byte 110 # DW_AT_linkage_name + .byte 14 # DW_FORM_strp + .byte 0 # EOM(1) + .byte 0 # EOM(2) + + .byte 4 # Abbreviation Code + .byte 36 # DW_TAG_base_type + .byte 0 # DW_CHILDREN_no + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 62 # DW_AT_encoding + .byte 11 # DW_FORM_data1 + .byte 11 # DW_AT_byte_size + .byte 11 # DW_FORM_data1 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) + + .section .debug_info,"",@progbits + .long 96 # Length of Unit + .short 4 # DWARF version number + .long .debug_abbrev # Offset Into Abbrev. Section + .byte 8 # Address Size (in bytes) + + .byte 1 # Abbrev [1] 0xb:0x59 DW_TAG_compile_unit + .long .Linfo_string0 # DW_AT_producer + .short 4 # DW_AT_language + .long .Linfo_string1 # DW_AT_name + .long 0 # DW_AT_stmt_list + .long .Linfo_string2 # DW_AT_comp_dir + # DW_AT_GNU_pubnames + + .byte 2 # Abbrev [2] 0x1e:0x1f DW_TAG_namespace + .long .Linfo_string3 # DW_AT_name + + .byte 3 # Abbrev [3] 0x23:0x19 DW_TAG_variable + .long .Linfo_string4 # DW_AT_name + .long 61 # DW_AT_type + # DW_AT_external + .byte 1 # DW_AT_decl_file + .byte 2 # DW_AT_decl_line + .byte 9 # DW_AT_location + .byte 3 + .quad _ZN1A3barE + .long .Linfo_string6 # DW_AT_linkage_name + .byte 0 # End Of Children Mark + + .byte 4 # Abbrev [4] 0x3d:0x7 DW_TAG_base_type + .long .Linfo_string5 # DW_AT_name + .byte 5 # DW_AT_encoding + .byte 4 # DW_AT_byte_size + + .byte 2 # Abbrev [2] 0x44:0x1f DW_TAG_namespace + .long .Linfo_string7 # DW_AT_name + + .byte 3 # Abbrev [3] 0x49:0x19 DW_TAG_variable + .long .Linfo_string4 # DW_AT_name + .long 61 # DW_AT_type + # DW_AT_external + .byte 1 # DW_AT_decl_file + .byte 6 # DW_AT_decl_line + .byte 9 # DW_AT_location + .byte 3 + .quad _ZN1Z3barE + .long .Linfo_string8 # DW_AT_linkage_name + + .byte 0 # End Of Children Mark + .byte 0 # End Of Children Mark diff --git a/test/ELF/conflict.s b/test/ELF/conflict.s index 4318759cbc11..cbe1b5b8845a 100644 --- a/test/ELF/conflict.s +++ b/test/ELF/conflict.s @@ -34,7 +34,7 @@ # ARCHIVE-NEXT: >>> defined at {{.*}}:(.text+0x0) in archive {{.*}}.a # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/conflict-debug.s -o %t-dbg.o -# RUN: not ld.lld %t-dbg.o %t-dbg.o -o %t-dbg 2>&1 | FileCheck -check-prefix=DBGINFO %s +# RUN: not ld.lld %t-dbg.o %t-dbg.o -o /dev/null 2>&1 | FileCheck -check-prefix=DBGINFO %s # DBGINFO: duplicate symbol: zed # DBGINFO-NEXT: >>> defined at conflict-debug.s:4 diff --git a/test/ELF/copy-errors.s b/test/ELF/copy-errors.s index 0af4638120d1..40f73178557d 100644 --- a/test/ELF/copy-errors.s +++ b/test/ELF/copy-errors.s @@ -7,12 +7,19 @@ // CHECK: cannot preempt symbol: bar // CHECK: >>> defined in {{.*}}.so // CHECK: >>> referenced by {{.*}}.o:(.text+0x1) -// CHECK: symbol 'zed' defined in {{.*}}.so has no type + +// CHECK: error: symbol 'zed' has no type +// 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 -// NOINHIBIT: warning: symbol 'zed' defined in {{.*}}.so has no type +// NOINHIBIT: warning: symbol 'zed' has no type +// NOINHIBIT-NEXT: >>> defined in {{.*}}.so +// NOINHIBIT-NEXT: >>> referenced by {{.*}}.o:(.text+0x6) .global _start _start: -call bar -call zed +.byte 0xe8 +.long bar - . +.byte 0xe8 +.long zed - . diff --git a/test/ELF/copy-in-shared.s b/test/ELF/copy-in-shared.s index 70439853c7c1..a5508932d035 100644 --- a/test/ELF/copy-in-shared.s +++ b/test/ELF/copy-in-shared.s @@ -2,9 +2,9 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/copy-in-shared.s -o %t1.o // RUN: ld.lld -shared %t1.o -o %t1.so // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t2.o -// RUN: not ld.lld %t2.o %t1.so -o %t2.so -shared 2>&1 | FileCheck %s +// RUN: not ld.lld %t2.o %t1.so -o /dev/null -shared 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_X86_64_64 against symbol: foo in readonly segment +// 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+0x0) diff --git a/test/ELF/copy-rel-corrupted.s b/test/ELF/copy-rel-corrupted.s index 3cdad7cf8037..76f64fa7725c 100644 --- a/test/ELF/copy-rel-corrupted.s +++ b/test/ELF/copy-rel-corrupted.s @@ -1,10 +1,11 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: llvm-mc %p/Inputs/copy-rel-corrupted.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 %t.exe 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o %t2.so -o /dev/null 2>&1 | FileCheck %s // CHECK: error: cannot create a copy relocation for symbol x .global _start _start: - call x + .long x - . diff --git a/test/ELF/copy-rel-pie-error.s b/test/ELF/copy-rel-pie-error.s index 6f7677e25e3a..379442e1176c 100644 --- a/test/ELF/copy-rel-pie-error.s +++ b/test/ELF/copy-rel-pie-error.s @@ -1,13 +1,14 @@ +// 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 %t.exe -pie 2>&1 | FileCheck %s +// 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 +// 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 +// 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) diff --git a/test/ELF/copy-rel-pie.s b/test/ELF/copy-rel-pie.s index dcccf8e30b1d..9bf91595db12 100644 --- a/test/ELF/copy-rel-pie.s +++ b/test/ELF/copy-rel-pie.s @@ -1,3 +1,4 @@ +// 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 @@ -7,8 +8,10 @@ .global _start _start: - call bar - call foo + .byte 0xe8 + .long bar - . -4 + .byte 0xe8 + .long foo - . -4 // CHECK: Name: .plt // CHECK-NEXT: Type: SHT_PROGBITS diff --git a/test/ELF/copy-rel-version.s b/test/ELF/copy-rel-version.s new file mode 100644 index 000000000000..29fae8ecbb05 --- /dev/null +++ b/test/ELF/copy-rel-version.s @@ -0,0 +1,15 @@ +// 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/copy-rel-version.s -o %t1.o +// RUN: echo "v1 {}; v2 {};" > %t.ver +// RUN: ld.lld %t1.o -shared -soname t1.so --version-script=%t.ver -o %t1.so +// RUN: ld.lld %t.o %t1.so -o %t +// RUN: llvm-readobj -t %t | FileCheck %s + +.global _start +_start: + leaq foo, %rax + +// CHECK: Name: foo ( +// CHECK-NEXT: Value: +// CHECK-NEXT: Size: 8 diff --git a/test/ELF/copy-relocation-zero-abs-addr.s b/test/ELF/copy-relocation-zero-abs-addr.s new file mode 100644 index 000000000000..fae963e9bd9e --- /dev/null +++ b/test/ELF/copy-relocation-zero-abs-addr.s @@ -0,0 +1,44 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/copy-relocation-zero-abs-addr.s -o %t.o +// RUN: ld.lld -shared -o %t2.so %t.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t3.o +// RUN: ld.lld %t2.so %t3.o -o %t4 +// RUN: llvm-readobj -symbols %t2.so | FileCheck -check-prefix=ABSADDR %s +// RUN: llvm-readobj -s -r --expand-relocs %t4 | FileCheck %s + +// This tests that symbols with absolute addresses are properly +// handled. Normal DSO symbols are handled as usual. + +.text +.globl _start +_start: + movl $5, foo + +// ABSADDR: Name: ver1 +// ABSADDR-NEXT: Value: 0x0 +// ABSADDR-NEXT: Size: 0 +// ABSADDR-NEXT: Binding: Global +// ABSADDR-NEXT: Type: None +// ABSADDR-NEXT: Other: 0 +// ABSADDR-NEXT: Section: Absolute (0xFFF1) +// ABSADDR-NEXT: } +// ABSADDR-NEXT: Symbol { +// ABSADDR-NEXT: Name: ver2 +// ABSADDR-NEXT: Value: 0x0 +// ABSADDR-NEXT: Size: 0 +// ABSADDR-NEXT: Binding: Global +// ABSADDR-NEXT: Type: None +// ABSADDR-NEXT: Other: 0 +// ABSADDR-NEXT: Section: Absolute (0xFFF1) +// ABSADDR-NEXT: } + +// CHECK: Relocations [ +// CHECK-NEXT: Section (5) .rela.dyn { +// CHECK-NEXT: Relocation { +// CHECK-NEXT: Offset: +// CHECK-NEXT: Type: R_X86_64_COPY +// CHECK-NEXT: Symbol: foo +// CHECK-NEXT: Addend: +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: ] diff --git a/test/ELF/copy-relocation-zero-nonabs-addr.s b/test/ELF/copy-relocation-zero-nonabs-addr.s new file mode 100644 index 000000000000..50876056b256 --- /dev/null +++ b/test/ELF/copy-relocation-zero-nonabs-addr.s @@ -0,0 +1,29 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/copy-relocation-zero-nonabs-addr.s -o %t1.o +// RUN: ld.lld -Ttext=0 -o %t2.so --script=%p/Inputs/copy-relocation-zero-nonabs-addr.script %t1.o -shared +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t3.o +// RUN: ld.lld %t2.so %t3.o -o %t4 +// RUN: llvm-readobj --symbols %t2.so | FileCheck --check-prefix=CHECKSO %s +// RUN: llvm-readobj --symbols %t4 | FileCheck %s + +.text +.globl _start +_start: + movl $5, foo + +// Make sure foo has st_value == 0. +// CHECKSO: Name: foo +// CHECKSO-NEXT: Value: 0x0 +// CHECKSO-NEXT: Size: 4 +// CHECKSO-NEXT: Binding: Global +// CHECKSO-NEXT: Type: Object +// CHECKSO-NEXT: Other: 0 +// CHECKSO-NEXT: Section: .text + +// When foo has st_value == 0, it carries the section alignment. +// In this case, section alignment is 2^10, 0x202400 meets the requirement. +// CHECK: Name: foo +// CHECK-NEXT: Value: 0x202400 +// CHECK-NEXT: Size: 4 +// CHECK-NEXT: Binding: Global +// CHECK-NEXT: Type: Object diff --git a/test/ELF/corrupted-version-reference.s b/test/ELF/corrupted-version-reference.s index d37f272f445d..203dc2afd8a1 100644 --- a/test/ELF/corrupted-version-reference.s +++ b/test/ELF/corrupted-version-reference.s @@ -1,6 +1,6 @@ -# RUN: llvm-mc -triple=mips64-unknown-freebsd %s -filetype=obj -o %t.o -# RUN: not ld.lld %t.o %S/Inputs/corrupt-version-reference.so -o %t.exe 2>&1 | FileCheck %s # REQUIRES: mips +# RUN: llvm-mc -triple=mips64-unknown-freebsd %s -filetype=obj -o %t.o +# RUN: not ld.lld %t.o %S/Inputs/corrupt-version-reference.so -o /dev/null 2>&1 | FileCheck %s # CHECK: error: corrupt input file: version definition index 9 for symbol __cxa_finalize is out of bounds # CHECK: >>> defined in {{.+}}/corrupt-version-reference.so diff --git a/test/ELF/cref.s b/test/ELF/cref.s new file mode 100644 index 000000000000..2a82f4252e84 --- /dev/null +++ b/test/ELF/cref.s @@ -0,0 +1,33 @@ +// REQUIRES: x86 + +// RUN: echo '.global foo; foo:' | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t1.o +// RUN: echo '.global foo, bar; bar:' | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t2.o +// RUN: echo '.global zed; zed:' | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %ta.o +// RUN: rm -f %t.a +// RUN: llvm-ar rcs %t.a %ta.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t3.o +// RUN: ld.lld -shared -o %t1.so %t1.o +// RUN: ld.lld -o /dev/null %t1.so %t2.o %t3.o %t.a -gc-sections -cref | FileCheck -strict-whitespace %s + +// CHECK: Symbol File +// CHECK-NEXT: bar {{.*}}2.o +// CHECK-NEXT: {{.*}}3.o +// CHECK-NEXT: foo {{.*}}1.so +// CHECK-NEXT: {{.*}}2.o +// CHECK-NEXT: {{.*}}3.o +// CHECK-NEXT: _start {{.*}}3.o +// CHECK-NEXT: baz {{.*}}3.o +// CHECK-NEXT: zed {{.*}}.a({{.*}}a.o) +// CHECK-NEXT: {{.*}}3.o +// CHECK-NOT: discarded + +.global _start, foo, bar, baz, discarded +_start: + call foo + call bar + call zed +localsym: +baz: + +.section .text.a,"ax",@progbits +discarded: diff --git a/test/ELF/ctors_dtors_priority.s b/test/ELF/ctors_dtors_priority.s index fcddcbb020f3..203bf247aa34 100644 --- a/test/ELF/ctors_dtors_priority.s +++ b/test/ELF/ctors_dtors_priority.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ // RUN: %p/Inputs/ctors_dtors_priority1.s -o %t-crtbegin.o @@ -7,7 +8,6 @@ // RUN: %p/Inputs/ctors_dtors_priority3.s -o %t-crtend.o // RUN: ld.lld %t1 %t2 %t-crtend.o %t-crtbegin.o -o %t.exe // RUN: llvm-objdump -s %t.exe | FileCheck %s -// REQUIRES: x86 .globl _start _start: diff --git a/test/ELF/defined-tls_get_addr.s b/test/ELF/defined-tls_get_addr.s index 509c293cca1d..66ec01597566 100644 --- a/test/ELF/defined-tls_get_addr.s +++ b/test/ELF/defined-tls_get_addr.s @@ -1,5 +1,6 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -triple x86_64-pc-linux -filetype=obj -// RUN: ld.lld %t.o -o %t +// RUN: ld.lld %t.o -o /dev/null // Don't error if __tls_get_addr is defined. diff --git a/test/ELF/defsym-reserved-syms.s b/test/ELF/defsym-reserved-syms.s new file mode 100644 index 000000000000..fdab00fed66b --- /dev/null +++ b/test/ELF/defsym-reserved-syms.s @@ -0,0 +1,30 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld -o %t %t.o --defsym=foo2=etext +# RUN: llvm-readobj -t -s %t | FileCheck %s + +## Check 'foo2' value is equal to value of 'etext'. +# CHECK: Symbol { +# CHECK: Name: foo2 +# CHECK-NEXT: Value: 0x[[VAL:.*]] +# CHECK: Symbol { +# CHECK: Name: etext +# CHECK-NEXT: Value: 0x[[VAL]] + +## Check 'foo2' value set correctly when using +## reserved symbol 'etext' in expression. +# RUN: ld.lld -o %t %t.o --defsym=foo2=etext+2 +# RUN: llvm-readobj -t -s %t | FileCheck %s --check-prefix=EXPR +# EXPR: Symbol { +# EXPR: Name: foo2 +# EXPR-NEXT: Value: 0x201007 +# EXPR: Symbol { +# EXPR: Name: etext +# EXPR-NEXT: Value: 0x201005 + +.globl foo1 + foo1 = 0x123 + +.global _start +_start: + movl $foo2, %edx diff --git a/test/ELF/discard-locals.s b/test/ELF/discard-locals.s index 9deaccff11c7..50cf5a04e985 100644 --- a/test/ELF/discard-locals.s +++ b/test/ELF/discard-locals.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -save-temp-labels %s -o %t // RUN: ld.lld -discard-locals %t -o %t2 // RUN: llvm-readobj -s -sd -t %t2 | FileCheck %s -// REQUIRES: x86 .global _start _start: diff --git a/test/ELF/discard-merge-locals.s b/test/ELF/discard-merge-locals.s index 01b4d337cb2d..20be35c6e4e8 100644 --- a/test/ELF/discard-merge-locals.s +++ b/test/ELF/discard-merge-locals.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld %t -o %t2 -shared // RUN: llvm-readobj -t %t2 | FileCheck %s -// REQUIRES: x86 leaq .L.str(%rip), %rdi diff --git a/test/ELF/discard-none.s b/test/ELF/discard-none.s index 89e06fd7b7e4..4a42639c63f1 100644 --- a/test/ELF/discard-none.s +++ b/test/ELF/discard-none.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -save-temp-labels %s -o %t // RUN: ld.lld -discard-none -shared %t -o %t2 // RUN: llvm-readobj -s -sd -t %t2 | FileCheck %s -// REQUIRES: x86 .text .Lmyvar: diff --git a/test/ELF/dont-export-hidden.s b/test/ELF/dont-export-hidden.s index 8088c8d94d89..161e342bea84 100644 --- a/test/ELF/dont-export-hidden.s +++ b/test/ELF/dont-export-hidden.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc %p/Inputs/shared.s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: llvm-mc %s -o %t2.o -filetype=obj -triple=x86_64-pc-linux // RUN: ld.lld %t.o -o %t.so -shared diff --git a/test/ELF/driver.test b/test/ELF/driver.test index ac324cbaac45..20bc79509725 100644 --- a/test/ELF/driver.test +++ b/test/ELF/driver.test @@ -35,25 +35,35 @@ # RUN: not ld.lld -r --gc-sections %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR3 %s # ERR3: -r and --gc-sections may not be used together +## Attempt to use -r and --gdb-index together +# RUN: not ld.lld -r --gdb-index %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR4 %s +# ERR4: -r and --gdb-index may not be used together + ## Attempt to use -r and --icf together -# RUN: not ld.lld -r --icf=all %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR4 %s -# ERR4: -r and --icf may not be used together +# RUN: not ld.lld -r --icf=all %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR5 %s +# ERR5: -r and --icf may not be used together ## Attempt to use -r and -pie together -# RUN: not ld.lld -r -pie %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR5 %s -# ERR5: -r and -pie may not be used together +# RUN: not ld.lld -r -pie %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR6 %s +# ERR6: -r and -pie may not be used together ## Attempt to use -shared and -pie together -# RUN: not ld.lld -shared -pie %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR6 %s -# ERR6: -shared and -pie may not be used together +# RUN: not ld.lld -shared -pie %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR7 %s +# ERR7: -shared and -pie may not be used together ## "--output=foo" is equivalent to "-o foo". -# RUN: not ld.lld %t --output=/no/such/file 2>&1 | FileCheck -check-prefix=ERR7 %s -# ERR7: cannot open output file /no/such/file +# RUN: not ld.lld %t --output=/no/such/file 2>&1 | FileCheck -check-prefix=ERR8 %s +# ERR8: cannot open output file /no/such/file ## "-output=foo" is equivalent to "-o utput=foo". -# RUN: not ld.lld %t -output=/no/such/file 2>&1 | FileCheck -check-prefix=ERR8 %s -# ERR8: cannot open output file utput=/no/such/file +# RUN: not ld.lld %t -output=/no/such/file 2>&1 | FileCheck -check-prefix=ERR9 %s +# ERR9: cannot open output file utput=/no/such/file + +# RUN: not ld.lld %t -z foo 2>&1 | FileCheck -check-prefix=ERR10 %s +# ERR10: unknown -z value: foo + +# RUN: not ld.lld %t -z max-page-size 2>&1 | FileCheck -check-prefix=ERR11 %s +# ERR11: unknown -z value: max-page-size .globl _start _start: diff --git a/test/ELF/dt_flags.s b/test/ELF/dt_flags.s index 431f83df7ab3..e160e0600378 100644 --- a/test/ELF/dt_flags.s +++ b/test/ELF/dt_flags.s @@ -2,19 +2,24 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: ld.lld -shared %t -o %t.so -# RUN: ld.lld -z now -z nodelete -z nodlopen -z origin -Bsymbolic %t %t.so -o %t1 -# RUN: ld.lld %t %t.so -o %t2 + +# RUN: ld.lld -z initfirst -z now -z nodelete -z nodlopen -z origin -Bsymbolic %t %t.so -o %t1 # RUN: llvm-readobj -dynamic-table %t1 | FileCheck -check-prefix=FLAGS %s + +# RUN: ld.lld %t %t.so -o %t2 +# RUN: llvm-readobj -dynamic-table %t2 | FileCheck %s + +# RUN: ld.lld -z lazy %t %t.so -o %t2 # RUN: llvm-readobj -dynamic-table %t2 | FileCheck %s # FLAGS: DynamicSection [ # FLAGS: 0x000000000000001E FLAGS ORIGIN SYMBOLIC BIND_NOW -# FLAGS: 0x000000006FFFFFFB FLAGS_1 NOW NODELETE NOOPEN ORIGIN +# FLAGS: 0x000000006FFFFFFB FLAGS_1 NOW NODELETE INITFIRST NOOPEN ORIGIN # FLAGS: ] # CHECK: DynamicSection [ -# CHECK-NOT: 0x000000000000001E FLAGS ORIGIN SYMBOLIC BIND_NOW -# CHECK-NOT: 0x000000006FFFFFFB FLAGS_1 NOW NODELETE NOOPEN ORIGIN +# CHECK-NOT: FLAGS +# CHECK-NOT: FLAGS_1 # CHECK: ] .globl _start diff --git a/test/ELF/duplicated-synthetic-sym.s b/test/ELF/duplicated-synthetic-sym.s index 92de33ec6278..bc4f5cf7650a 100644 --- a/test/ELF/duplicated-synthetic-sym.s +++ b/test/ELF/duplicated-synthetic-sym.s @@ -1,11 +1,17 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: cd %S -// RUN: not ld.lld %t.o --format=binary duplicated-synthetic-sym.s -o %t.elf 2>&1 | FileCheck %s -// RUN: not ld.lld %t.o --format binary duplicated-synthetic-sym.s -o %t.elf 2>&1 | FileCheck %s +// RUN: rm -rf %t.dir +// RUN: mkdir %t.dir +// RUN: cd %t.dir +// RUN: echo > file.bin -// CHECK: duplicate symbol: _binary_duplicated_synthetic_sym_s_start -// CHECK: defined at <internal>:(.data+0x0) +// RUN: not ld.lld %t.o --format=binary file.bin -o %t.elf 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o --format binary file.bin -o %t.elf 2>&1 | FileCheck %s - .globl _binary_duplicated_synthetic_sym_s_start -_binary_duplicated_synthetic_sym_s_start: - .long 0 +// CHECK: duplicate symbol: _binary_file_bin_start +// CHECK-NEXT: defined at {{.*}}.o:(.text+0x0) +// CHECK-NEXT: defined at file.bin:(.data+0x0) + +.globl _binary_file_bin_start +_binary_file_bin_start: + .long 0 diff --git a/test/ELF/dynamic-got-rela.s b/test/ELF/dynamic-got-rela.s index 0aeb6d477a26..b46afaae0fef 100644 --- a/test/ELF/dynamic-got-rela.s +++ b/test/ELF/dynamic-got-rela.s @@ -1,24 +1,45 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: ld.lld %t.o -o %t.so -shared -// RUN: llvm-readobj -r -s -l -section-data %t.so | FileCheck %s +// RUN: ld.lld %t.o -o %t.so -shared --apply-dynamic-relocs +// RUN: llvm-readobj -r -s -l -section-data %t.so | FileCheck -check-prefix CHECK -check-prefix APPLYDYNREL %s +// RUN: ld.lld %t.o -o %t2.so -shared +// RUN: llvm-readobj -r -s -l -section-data %t2.so | FileCheck -check-prefix CHECK -check-prefix NOAPPLYDYNREL %s +// RUN: ld.lld %t.o -o %t2.so -shared --no-apply-dynamic-relocs +// RUN: llvm-readobj -r -s -l -section-data %t2.so | FileCheck -check-prefix CHECK -check-prefix NOAPPLYDYNREL %s -// CHECK: Name: .got -// CHECK-NEXT: Type: SHT_PROGBITS -// CHECK-NEXT: Flags [ -// CHECK-NEXT: SHF_ALLOC -// CHECK-NEXT: SHF_WRITE -// CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x[[GOT:.*]] -// CHECK-NEXT: Offset: -// CHECK-NEXT: Size: -// CHECK-NEXT: Link: -// CHECK-NEXT: Info: -// CHECK-NEXT: AddressAlignment: -// CHECK-NEXT: EntrySize: -// CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 00000000 00000000 | -// CHECK-NEXT: ) +// APPLYDYNREL: Name: .got +// APPLYDYNREL-NEXT: Type: SHT_PROGBITS +// APPLYDYNREL-NEXT: Flags [ +// APPLYDYNREL-NEXT: SHF_ALLOC +// APPLYDYNREL-NEXT: SHF_WRITE +// APPLYDYNREL-NEXT: ] +// APPLYDYNREL-NEXT: Address: 0x[[GOT:.*]] +// APPLYDYNREL-NEXT: Offset: +// APPLYDYNREL-NEXT: Size: +// APPLYDYNREL-NEXT: Link: +// APPLYDYNREL-NEXT: Info: +// APPLYDYNREL-NEXT: AddressAlignment: +// APPLYDYNREL-NEXT: EntrySize: +// APPLYDYNREL-NEXT: SectionData ( +// APPLYDYNREL-NEXT: 0000: 00200000 00000000 | +// APPLYDYNREL-NEXT: ) + +// NOAPPLYDYNREL: Name: .got +// NOAPPLYDYNREL-NEXT: Type: SHT_PROGBITS +// NOAPPLYDYNREL-NEXT: Flags [ +// NOAPPLYDYNREL-NEXT: SHF_ALLOC +// NOAPPLYDYNREL-NEXT: SHF_WRITE +// NOAPPLYDYNREL-NEXT: ] +// NOAPPLYDYNREL-NEXT: Address: 0x[[GOT:.*]] +// NOAPPLYDYNREL-NEXT: Offset: +// NOAPPLYDYNREL-NEXT: Size: +// NOAPPLYDYNREL-NEXT: Link: +// NOAPPLYDYNREL-NEXT: Info: +// NOAPPLYDYNREL-NEXT: AddressAlignment: +// NOAPPLYDYNREL-NEXT: EntrySize: +// NOAPPLYDYNREL-NEXT: SectionData ( +// NOAPPLYDYNREL-NEXT: 0000: 00000000 00000000 | +// NOAPPLYDYNREL-NEXT: ) // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.dyn { diff --git a/test/ELF/dynamic-got.s b/test/ELF/dynamic-got.s index 385394b9d342..844e4f48b3f7 100644 --- a/test/ELF/dynamic-got.s +++ b/test/ELF/dynamic-got.s @@ -3,6 +3,23 @@ // RUN: ld.lld --hash-style=sysv %t.o -o %t.so -shared // RUN: llvm-readobj -s -l -section-data -r %t.so | FileCheck %s +// CHECK: Name: .got.plt +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: SHF_WRITE +// CHECK-NEXT: ] +// CHECK-NEXT: Address: +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: +// CHECK-NEXT: Link: +// CHECK-NEXT: Info: +// CHECK-NEXT: AddressAlignment: +// CHECK-NEXT: EntrySize: +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 00300000 00000000 00000000 +// CHECK-NEXT: ) + // CHECK: Name: .got // CHECK-NEXT: Type: SHT_PROGBITS // CHECK-NEXT: Flags [ @@ -17,19 +34,19 @@ // CHECK-NEXT: AddressAlignment: // CHECK-NEXT: EntrySize: // CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 00200000 | +// CHECK-NEXT: 0000: 00300000 // CHECK-NEXT: ) // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rel.dyn { -// CHECK-NEXT: 0x2050 R_386_RELATIVE - 0x0 +// CHECK-NEXT: 0x3050 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: 0x3000 +// CHECK-NEXT: VirtualAddress: 0x3000 +// CHECK-NEXT: PhysicalAddress: 0x3000 calll .L0$pb .L0$pb: diff --git a/test/ELF/dynamic-linker.s b/test/ELF/dynamic-linker.s new file mode 100644 index 000000000000..3faf8e8a169e --- /dev/null +++ b/test/ELF/dynamic-linker.s @@ -0,0 +1,24 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %t1.o +# RUN: ld.lld -shared %t1.o -o %t.so +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o + +# RUN: ld.lld --dynamic-linker foo %t.o %t.so -o %t +# RUN: llvm-readelf -program-headers %t | FileCheck %s + +# RUN: ld.lld --dynamic-linker=foo %t.o %t.so -o %t +# RUN: llvm-readelf -program-headers %t | FileCheck %s + +# CHECK: [Requesting program interpreter: foo] + +# RUN: ld.lld %t.o %t.so -o %t +# RUN: llvm-readelf -program-headers %t | FileCheck --check-prefix=NO %s + +# RUN: ld.lld --dynamic-linker foo --no-dynamic-linker %t.o %t.so -o %t +# RUN: llvm-readelf -program-headers %t | FileCheck --check-prefix=NO %s + +# NO-NOT: PT_INTERP + +.globl _start +_start: + nop diff --git a/test/ELF/dynamic-list-archive.s b/test/ELF/dynamic-list-archive.s new file mode 100644 index 000000000000..5879bf1b0a57 --- /dev/null +++ b/test/ELF/dynamic-list-archive.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 + +# RUN: rm -f %t.a +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive2.s -o %t1.o +# RUN: llvm-ar rcs %t.a %t1.o + +# RUN: echo "{ foo; };" > %t.list + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o +# RUN: ld.lld -shared -o %t.so --dynamic-list %t.list %t.a %t2.o + +# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s +# CHECK-NOT: foo + +.global _start +_start: + nop diff --git a/test/ELF/dynamic-list-extern.s b/test/ELF/dynamic-list-extern.s index dfeb31d4fc07..bb06cebf5f52 100644 --- a/test/ELF/dynamic-list-extern.s +++ b/test/ELF/dynamic-list-extern.s @@ -4,12 +4,8 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo '{ \ -# RUN: extern "C" { \ -# RUN: foo; \ -# RUN: }; \ -# RUN: extern "C++" { \ -# RUN: bar; \ -# RUN: }; \ -# RUN: };' > %t.list +# RUN: echo '{ extern "C" { foo; }; extern "C++" { bar; }; };' > %t.list +# RUN: ld.lld --dynamic-list %t.list %t.o -shared -o %t.so + +# RUN: echo '{ extern "C" { foo }; extern "C++" { bar }; };' > %t.list # RUN: ld.lld --dynamic-list %t.list %t.o -shared -o %t.so diff --git a/test/ELF/dynamic-no-rosegment.s b/test/ELF/dynamic-no-rosegment.s index e5ad26e3fa44..f2b5f352d967 100644 --- a/test/ELF/dynamic-no-rosegment.s +++ b/test/ELF/dynamic-no-rosegment.s @@ -7,9 +7,9 @@ # CHECK-NEXT: Tag Type Name/Value # CHECK-NEXT: 0x0000000000000006 SYMTAB 0x120 # CHECK-NEXT: 0x000000000000000B SYMENT 24 (bytes) -# CHECK-NEXT: 0x0000000000000005 STRTAB 0x1D0 +# CHECK-NEXT: 0x0000000000000005 STRTAB 0x1D8 # CHECK-NEXT: 0x000000000000000A STRSZ 1 (bytes) # CHECK-NEXT: 0x000000006FFFFEF5 GNU_HASH 0x138 -# CHECK-NEXT: 0x0000000000000004 HASH 0x150 +# CHECK-NEXT: 0x0000000000000004 HASH 0x154 # CHECK-NEXT: 0x0000000000000000 NULL 0x0 # CHECK-NEXT: ] diff --git a/test/ELF/dynamic-reloc-in-ro.s b/test/ELF/dynamic-reloc-in-ro.s index ecdbfeb6658e..920f1d5fe349 100644 --- a/test/ELF/dynamic-reloc-in-ro.s +++ b/test/ELF/dynamic-reloc-in-ro.s @@ -1,8 +1,8 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment; recompile object files with -fPIC +// CHECK: can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output // CHECK-NEXT: >>> defined in {{.*}}.o // CHECK-NEXT: >>> referenced by {{.*}}.o:(.text+0x0) diff --git a/test/ELF/dynamic-reloc-index.s b/test/ELF/dynamic-reloc-index.s index 47e8c6c4ef7d..0c14d3454571 100644 --- a/test/ELF/dynamic-reloc-index.s +++ b/test/ELF/dynamic-reloc-index.s @@ -1,3 +1,4 @@ +// 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 %p/Inputs/shared.s -o %t2.o // RUN: ld.lld -shared %t2.o -o %t2.so diff --git a/test/ELF/dynamic-reloc-weak.s b/test/ELF/dynamic-reloc-weak.s index b4da2e552e11..8e4840bb4c4b 100644 --- a/test/ELF/dynamic-reloc-weak.s +++ b/test/ELF/dynamic-reloc-weak.s @@ -1,9 +1,9 @@ +// 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 %p/Inputs/dynamic-reloc-weak.s -o %t2.o // RUN: ld.lld -shared %t2.o -o %t2.so // RUN: ld.lld %t.o %t2.so -o %t // RUN: llvm-readobj -r %t | FileCheck %s -// REQUIRES: x86 .globl _start _start: diff --git a/test/ELF/dynamic-reloc.s b/test/ELF/dynamic-reloc.s index 4d95e41fb803..3a957ac0d05e 100644 --- a/test/ELF/dynamic-reloc.s +++ b/test/ELF/dynamic-reloc.s @@ -1,10 +1,10 @@ +// 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 %p/Inputs/shared.s -o %t2.o // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/dynamic-reloc.s -o %t3.o // RUN: ld.lld -shared %t2.o -o %t2.so // RUN: ld.lld --hash-style=sysv %t.o %t3.o %t2.so -o %t // RUN: llvm-readobj -dynamic-table -r --expand-relocs -s %t | FileCheck %s -// REQUIRES: x86 // CHECK: Index: 1 // CHECK-NEXT: Name: .dynsym diff --git a/test/ELF/dynstr-no-rosegment.s b/test/ELF/dynstr-no-rosegment.s index 0e12721dac44..bad6300801e2 100644 --- a/test/ELF/dynstr-no-rosegment.s +++ b/test/ELF/dynstr-no-rosegment.s @@ -1,6 +1,6 @@ +# REQUIRES: x86 # Verify that a .dynstr in the .text segment has null byte terminators -# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: ld.lld %t.o -no-rosegment -o %t.so -shared # RUN: llvm-objdump %t.so -s -j .dynstr | FileCheck %s diff --git a/test/ELF/edata-etext.s b/test/ELF/edata-etext.s index 2358399857de..52070cbc4ce3 100644 --- a/test/ELF/edata-etext.s +++ b/test/ELF/edata-etext.s @@ -10,10 +10,11 @@ ## greater than the address of _etext, the address of _end is same as the address ## of _edata." (https://docs.oracle.com/cd/E53394_01/html/E54766/u-etext-3c.html). ## 3) Address of _end is different from _edata because of 2. +## 4) Addresses of _edata == edata, _end == end and _etext == etext. # CHECK: Sections: # CHECK-NEXT: Idx Name Size Address Type # CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .text 00000001 0000000000201000 TEXT DATA +# CHECK-NEXT: 1 .text 00000001 0000000000201000 TEXT # CHECK-NEXT: 2 .data 00000002 0000000000202000 DATA # CHECK-NEXT: 3 .bss 00000006 0000000000202004 BSS # CHECK: SYMBOL TABLE: @@ -22,6 +23,9 @@ # CHECK-NEXT: 000000000020200a .bss 00000000 _end # CHECK-NEXT: 0000000000201001 .text 00000000 _etext # CHECK-NEXT: 0000000000201000 .text 00000000 _start +# CHECK-NEXT: 0000000000202002 .data 00000000 edata +# CHECK-NEXT: 000000000020200a .bss 00000000 end +# CHECK-NEXT: 0000000000201001 .text 00000000 etext # RUN: ld.lld -r %t.o -o %t2 # RUN: llvm-objdump -t %t2 | FileCheck %s --check-prefix=RELOCATABLE @@ -29,7 +33,7 @@ # RELOCATABLE-NEXT: 0000000000000000 *UND* 00000000 _end # RELOCATABLE-NEXT: 0000000000000000 *UND* 00000000 _etext -.global _start,_end,_etext,_edata +.global _start,_end,_etext,_edata,end,etext,edata .text _start: nop diff --git a/test/ELF/eh-frame-dyn-rel.s b/test/ELF/eh-frame-dyn-rel.s index 289e6c0150d2..f54e62b5eedc 100644 --- a/test/ELF/eh-frame-dyn-rel.s +++ b/test/ELF/eh-frame-dyn-rel.s @@ -1,8 +1,8 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: not ld.lld %t.o %t.o -o %t -shared 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o %t.o -o /dev/null -shared 2>&1 | FileCheck %s -// CHECK: can't create dynamic relocation R_X86_64_64 against symbol: foo +// 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 {{.*}}.o // CHECK: >>> referenced by {{.*}}.o:(.eh_frame+0x12) diff --git a/test/ELF/eh-frame-hdr-abs-fde.s b/test/ELF/eh-frame-hdr-abs-fde.s index c3dc862ceb49..7f75058d4b35 100644 --- a/test/ELF/eh-frame-hdr-abs-fde.s +++ b/test/ELF/eh-frame-hdr-abs-fde.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check reading PC values of FDEs and writing lookup table in the .eh_frame_hdr # if CIE augmentation string has 'L' token and PC values are encoded using # absolute (not relative) format. @@ -6,8 +7,6 @@ # RUN: ld.lld --eh-frame-hdr %t.o -o %t # RUN: llvm-objdump -s -dwarf=frames %t | FileCheck %s -# REQUIRES: mips - # CHECK: Contents of section .eh_frame_hdr: # CHECK-NEXT: 10128 011b033b 00000010 00000001 0000fed8 # ^-- 0x20000 - 0x10138 diff --git a/test/ELF/eh-frame-hdr-augmentation.s b/test/ELF/eh-frame-hdr-augmentation.s index 135f8119662a..934f9200a27c 100644 --- a/test/ELF/eh-frame-hdr-augmentation.s +++ b/test/ELF/eh-frame-hdr-augmentation.s @@ -11,6 +11,7 @@ // CHECK-NEXT: Code alignment factor: 1 // CHECK-NEXT: Data alignment factor: -8 // CHECK-NEXT: Return address column: 16 +// CHECK-NEXT: Personality Address: 00000dad // CHECK-NEXT: Augmentation data: // CHECK: DW_CFA_def_cfa: reg7 +8 @@ -19,6 +20,7 @@ // CHECK-NEXT: DW_CFA_nop: // CHECK: 00000020 00000014 00000024 FDE cie=00000024 pc=00000d98...00000d98 +// CHECK-NEXT: LSDA Address: 00000d8f // CHECK-NEXT: DW_CFA_nop: // CHECK-NEXT: DW_CFA_nop: // CHECK-NEXT: DW_CFA_nop: diff --git a/test/ELF/eh-frame-hdr-icf-fde.s b/test/ELF/eh-frame-hdr-icf-fde.s index 54c2cd8bf8c9..68de65d5724c 100644 --- a/test/ELF/eh-frame-hdr-icf-fde.s +++ b/test/ELF/eh-frame-hdr-icf-fde.s @@ -52,7 +52,7 @@ # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x200178 # CHECK-NEXT: Offset: 0x178 -# CHECK-NEXT: Size: 72 +# CHECK-NEXT: Size: 76 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 8 @@ -62,7 +62,7 @@ # CHECK-NEXT: 0010: 1B0C0708 90010000 14000000 1C000000 # CHECK-NEXT: 0020: 680E0000 01000000 00000000 00000000 # CHECK-NEXT: 0030: 14000000 34000000 520E0000 01000000 -# CHECK-NEXT: 0040: 00000000 00000000 +# CHECK-NEXT: 0040: 00000000 00000000 00000000 # CHECK-NEXT: ) # CHECK-NEXT: } diff --git a/test/ELF/eh-frame-hdr.s b/test/ELF/eh-frame-hdr.s index 4498d7d30eaa..0c33bc6dde3e 100644 --- a/test/ELF/eh-frame-hdr.s +++ b/test/ELF/eh-frame-hdr.s @@ -60,7 +60,7 @@ _start: // HDR-NEXT: Size: 36 // HDR-NEXT: Link: 0 // HDR-NEXT: Info: 0 -// HDR-NEXT: AddressAlignment: 1 +// HDR-NEXT: AddressAlignment: 4 // HDR-NEXT: EntrySize: 0 // HDR-NEXT: SectionData ( // HDR-NEXT: 0000: 011B033B 24000000 03000000 A80E0000 @@ -92,7 +92,7 @@ _start: // HDR-NEXT: ] // HDR-NEXT: Address: 0x200180 // HDR-NEXT: Offset: 0x180 -// HDR-NEXT: Size: 96 +// HDR-NEXT: Size: 100 // HDR-NEXT: Link: 0 // HDR-NEXT: Info: 0 // HDR-NEXT: AddressAlignment: 8 @@ -104,6 +104,7 @@ _start: // HDR-NEXT: 0030: 14000000 34000000 490E0000 01000000 // HDR-NEXT: 0040: 00000000 00000000 14000000 4C000000 // HDR-NEXT: 0050: 320E0000 01000000 00000000 00000000 +// HDR-NEXT: 0060: 00000000 // HDR-NEXT: ) // CIE: 14000000 00000000 017A5200 01781001 1B0C0708 90010000 // FDE(1): 14000000 1C000000 600E0000 01000000 00000000 00000000 @@ -130,5 +131,5 @@ _start: // HDR-NEXT: Flags [ // HDR-NEXT: PF_R // HDR-NEXT: ] -// HDR-NEXT: Alignment: 1 +// HDR-NEXT: Alignment: 4 // HDR-NEXT: } diff --git a/test/ELF/eh-frame-marker.s b/test/ELF/eh-frame-marker.s index 30bac460ae25..f5696bdef36f 100644 --- a/test/ELF/eh-frame-marker.s +++ b/test/ELF/eh-frame-marker.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: ld.lld --eh-frame-hdr %t.o -o %t.so -shared // RUN: llvm-readobj -t -s %t.so | FileCheck %s diff --git a/test/ELF/eh-frame-merge.s b/test/ELF/eh-frame-merge.s index 4b54c173c699..6731d90f844b 100644 --- a/test/ELF/eh-frame-merge.s +++ b/test/ELF/eh-frame-merge.s @@ -27,7 +27,7 @@ // CHECK-NEXT: ] // CHECK-NEXT: Address: // CHECK-NEXT: Offset: -// CHECK-NEXT: Size: 96 +// CHECK-NEXT: Size: 100 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 8 @@ -39,6 +39,7 @@ // CHECK-NEXT: 0030: 14000000 34000000 D20D0000 02000000 | // CHECK-NEXT: 0040: 00000000 00000000 14000000 4C000000 | // CHECK-NEXT: 0050: B90D0000 01000000 00000000 00000000 | +// CHECK-NEXT: 0060: 00000000 // CHECK-NEXT: ) // CHECK: Name: foo diff --git a/test/ELF/eh-frame-multilpe-cie.s b/test/ELF/eh-frame-multilpe-cie.s index 12781ff5b6e9..a52e686d9d15 100644 --- a/test/ELF/eh-frame-multilpe-cie.s +++ b/test/ELF/eh-frame-multilpe-cie.s @@ -1,5 +1,6 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux -// RUN: ld.lld --eh-frame-hdr %t.o -o %t.so -shared +// RUN: ld.lld --eh-frame-hdr %t.o -o /dev/null -shared // We would fail to parse multiple cies in the same file. .cfi_startproc diff --git a/test/ELF/eh-frame-negative-pcrel-sdata2.s b/test/ELF/eh-frame-negative-pcrel-sdata2.s new file mode 100644 index 000000000000..30ee8560f0a3 --- /dev/null +++ b/test/ELF/eh-frame-negative-pcrel-sdata2.s @@ -0,0 +1,85 @@ +# REQUIRES: x86 + +# Test handling of FDE pc negative relative addressing with DW_EH_PE_sdata2. +# This situation can arise when .eh_frame is placed after .text. + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { .text : { *(.text) } .eh_frame : { *(.eh_frame) } }" > %t.script +# RUN: ld.lld --eh-frame-hdr --script %t.script --section-start .text=0x1000 %t.o -o %t +# RUN: llvm-readobj -s -section-data %t | FileCheck %s + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .eh_frame +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x1001 +# CHECK-NEXT: Offset: 0x1001 +# CHECK-NEXT: Size: +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 14000000 00000000 017A5200 01010101 +# CHECK-NEXT: 0010: 1A000000 00000000 0C000000 1C000000 +# CHECK-NEXT: 0020: DFFFFFFF +# ^ +# DFFFFFFF = _start(0x1000) - PC(.eh_frame(0x1001) + 0x20) + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .eh_frame_hdr +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x1030 +# CHECK-NEXT: Offset: 0x1030 +# CHECK-NEXT: Size: 20 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 011B033B CDFFFFFF 01000000 D0FFFFFF +# CHECK-NEXT: 0010: E9FFFFFF +# Header (always 4 bytes): 011B033B +# CDFFFFFF = .eh_frame(0x1001) - .eh_frame_hdr(0x1030) - 4 +# 01000000 = 1 = the number of FDE pointers in the table. +# D0FFFFFF = _start(0x1000) - .eh_frame_hdr(0x1030) +# E9FFFFFF = FDE(.eh_frame(0x1001) + 0x18) - .eh_frame_hdr(0x1030) + +.text +.global _start +_start: + nop + +.section .eh_frame, "a" + .long 16 # Size + .long 0x00 # ID + .byte 0x01 # Version. + + .byte 0x7A # Augmentation string: "zR" + .byte 0x52 + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x01 # LEB128 + .byte 0x1A # DW_EH_PE_pcrel | DW_EH_PE_sdata2 + + .byte 0x00 + .byte 0x00 + .byte 0x00 + + .long 10 # Size + .long 24 # ID +fde: + .long _start - fde + .word 0 diff --git a/test/ELF/eh-frame-negative-pcrel-sdata4.s b/test/ELF/eh-frame-negative-pcrel-sdata4.s new file mode 100644 index 000000000000..71b91cf1f4a6 --- /dev/null +++ b/test/ELF/eh-frame-negative-pcrel-sdata4.s @@ -0,0 +1,85 @@ +# REQUIRES: x86 + +# Test handling of FDE pc negative relative addressing with DW_EH_PE_sdata4. +# This situation can arise when .eh_frame is placed after .text. + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { .text : { *(.text) } .eh_frame : { *(.eh_frame) } }" > %t.script +# RUN: ld.lld --eh-frame-hdr --script %t.script --section-start .text=0x1000 %t.o -o %t +# RUN: llvm-readobj -s -section-data %t | FileCheck %s + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .eh_frame +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x1001 +# CHECK-NEXT: Offset: 0x1001 +# CHECK-NEXT: Size: +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 14000000 00000000 017A5200 01010101 +# CHECK-NEXT: 0010: 1B000000 00000000 0C000000 1C000000 +# CHECK-NEXT: 0020: DFFFFFFF +# ^ +# DFFFFFFF = _start(0x1000) - PC(.eh_frame(0x1001) + 0x20) + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .eh_frame_hdr +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x1030 +# CHECK-NEXT: Offset: 0x1030 +# CHECK-NEXT: Size: 20 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 011B033B CDFFFFFF 01000000 D0FFFFFF +# CHECK-NEXT: 0010: E9FFFFFF +# Header (always 4 bytes): 011B033B +# CDFFFFFF = .eh_frame(0x1001) - .eh_frame_hdr(0x1030) - 4 +# 01000000 = 1 = the number of FDE pointers in the table. +# D0FFFFFF = _start(0x1000) - .eh_frame_hdr(0x1030) +# E9FFFFFF = FDE(.eh_frame(0x1001) + 0x18) - .eh_frame_hdr(0x1030) + +.text +.global _start +_start: + nop + +.section .eh_frame, "a" + .long 16 # Size + .long 0x00 # ID + .byte 0x01 # Version. + + .byte 0x7A # Augmentation string: "zR" + .byte 0x52 + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x01 # LEB128 + .byte 0x1B # DW_EH_PE_pcrel | DW_EH_PE_sdata4 + + .byte 0x00 + .byte 0x00 + .byte 0x00 + + .long 12 # Size + .long 24 # ID +fde: + .long _start - fde + .long 0 diff --git a/test/ELF/eh-frame-negative-pcrel-sdata8.s b/test/ELF/eh-frame-negative-pcrel-sdata8.s new file mode 100644 index 000000000000..2c6c9f27cd38 --- /dev/null +++ b/test/ELF/eh-frame-negative-pcrel-sdata8.s @@ -0,0 +1,85 @@ +# REQUIRES: x86 + +# Test handling of FDE pc negative relative addressing with DW_EH_PE_sdata8. +# This situation can arise when .eh_frame is placed after .text. + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { .text : { *(.text) } .eh_frame : { *(.eh_frame) } }" > %t.script +# RUN: ld.lld --eh-frame-hdr --script %t.script --section-start .text=0x1000 %t.o -o %t +# RUN: llvm-readobj -s -section-data %t | FileCheck %s + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .eh_frame +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x1001 +# CHECK-NEXT: Offset: 0x1001 +# CHECK-NEXT: Size: +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 14000000 00000000 017A5200 01010101 +# CHECK-NEXT: 0010: 1C000000 00000000 14000000 1C000000 +# CHECK-NEXT: 0020: DFFFFFFF FFFFFFFF +# ^ +# DFFFFFFF FFFFFFFF = _start(0x1000) - PC(.eh_frame(0x1001) + 0x20) + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .eh_frame_hdr +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x1038 +# CHECK-NEXT: Offset: 0x1038 +# CHECK-NEXT: Size: 20 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 011B033B C5FFFFFF 01000000 C8FFFFFF +# CHECK-NEXT: 0010: E1FFFFFF +# Header (always 4 bytes): 011B033B +# C5FFFFFF = .eh_frame(0x1001) - .eh_frame_hdr(0x1038) - 4 +# 01000000 = 1 = the number of FDE pointers in the table. +# C8FFFFFF = _start(0x1000) - .eh_frame_hdr(0x1038) +# E1FFFFFF = FDE(.eh_frame(0x1001) + 0x18) - .eh_frame_hdr(0x1038) + +.text +.global _start +_start: + nop + +.section .eh_frame, "a" + .long 16 # Size + .long 0x00 # ID + .byte 0x01 # Version. + + .byte 0x7A # Augmentation string: "zR" + .byte 0x52 + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x01 # LEB128 + .byte 0x1C # DW_EH_PE_pcrel | DW_EH_PE_sdata8 + + .byte 0x00 + .byte 0x00 + .byte 0x00 + + .long 16 # Size + .long 24 # ID +fde: + .quad _start - fde + .long 0 diff --git a/test/ELF/eh-frame-padding-no-rosegment.s b/test/ELF/eh-frame-padding-no-rosegment.s index e106f2989d4b..222ce0da6ca9 100644 --- a/test/ELF/eh-frame-padding-no-rosegment.s +++ b/test/ELF/eh-frame-padding-no-rosegment.s @@ -7,6 +7,7 @@ .global bar .hidden bar bar: + ret // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o @@ -37,8 +38,7 @@ bar: // RUN: llvm-readobj -l --elf-output-style=GNU %t | FileCheck --check-prefix=PHDR %s // PHDR: Segment Sections -// PHDR: .text -// PHDR-SAME: .eh_frame +// PHDR: .eh_frame {{.*}}.text // Check that the CIE and FDE are padded with 0x00 and not 0xCC when the // .eh_frame section is placed in the executable segment @@ -58,7 +58,7 @@ bar: // CHECK-NEXT: EntrySize: // CHECK-NEXT: SectionData ( // CHECK-NEXT: 0000: 1C000000 00000000 017A5052 00017810 -// CHECK-NEXT: 0010: 061BBEFF FFFF1B0C 07089001 00000000 -// CHECK-NEXT: 0020: 14000000 24000000 A8FFFFFF 00000000 +// CHECK-NEXT: 0010: 061B2A00 00001B0C 07089001 00000000 +// CHECK-NEXT: 0020: 14000000 24000000 14000000 00000000 // CHECK-NEXT: 0030: 00000000 00000000 // CHECK-NEXT: ) diff --git a/test/ELF/eh-frame-pcrel-overflow.s b/test/ELF/eh-frame-pcrel-overflow.s new file mode 100644 index 000000000000..9b88edab2a93 --- /dev/null +++ b/test/ELF/eh-frame-pcrel-overflow.s @@ -0,0 +1,33 @@ +# 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/eh-frame-pcrel-overflow.s -o %t1.o +# RUN: ld.lld --eh-frame-hdr -Ttext=0x90000000 %t.o -o /dev/null +# RUN: not ld.lld --eh-frame-hdr %t.o %t1.o -o /dev/null 2>&1 | FileCheck %s +# CHECK: error: {{.*}}.o:(.eh_frame): PC offset is too large: 0x90000eac + +.text +.global _start +_start: + ret + +.section .eh_frame, "a" + .long 12 # Size + .long 0x00 # ID + .byte 0x01 # Version. + + .byte 0x52 # Augmentation string: 'R','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x00 # DW_EH_PE_absptr + + .byte 0xFF + + .long 12 # Size + .long 0x14 # ID + .quad _start + 0x70000000 diff --git a/test/ELF/eh-frame-rel.s b/test/ELF/eh-frame-rel.s index a417dc126087..d633e6a082ec 100644 --- a/test/ELF/eh-frame-rel.s +++ b/test/ELF/eh-frame-rel.s @@ -1,6 +1,6 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o -// RUN: ld.lld %t.o %t.o -o %t -shared +// RUN: ld.lld %t.o %t.o -o /dev/null -shared // We used to try to read the relocations as RELA and error out .cfi_startproc diff --git a/test/ELF/eh-frame-value-format1.s b/test/ELF/eh-frame-value-format1.s new file mode 100644 index 000000000000..a8bcffb4fe4f --- /dev/null +++ b/test/ELF/eh-frame-value-format1.s @@ -0,0 +1,35 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: ld.lld --eh-frame-hdr %t -o /dev/null + +.section .eh_frame + .byte 0x14 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + + .byte 0x50 # Augmentation string: 'P','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x04 # DW_EH_PE_udata8 + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + + .byte 0xFF diff --git a/test/ELF/eh-frame-value-format2.s b/test/ELF/eh-frame-value-format2.s new file mode 100644 index 000000000000..6d2d82e267c7 --- /dev/null +++ b/test/ELF/eh-frame-value-format2.s @@ -0,0 +1,35 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: ld.lld --eh-frame-hdr %t -o /dev/null + +.section .eh_frame + .byte 0x14 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + + .byte 0x50 # Augmentation string: 'P','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x0C # DW_EH_PE_sdata8 + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + + .byte 0xFF diff --git a/test/ELF/eh-frame-value-format3.s b/test/ELF/eh-frame-value-format3.s new file mode 100644 index 000000000000..1f174ae60a0d --- /dev/null +++ b/test/ELF/eh-frame-value-format3.s @@ -0,0 +1,28 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: ld.lld --eh-frame-hdr %t -o /dev/null + +.section .eh_frame + .byte 0x0E + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + + .byte 0x50 # Augmentation string: 'P','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x0A # DW_EH_PE_sdata2 + .byte 0xFF + .byte 0xFF + .byte 0xFF diff --git a/test/ELF/eh-frame-value-format4.s b/test/ELF/eh-frame-value-format4.s new file mode 100644 index 000000000000..d10988a4fc86 --- /dev/null +++ b/test/ELF/eh-frame-value-format4.s @@ -0,0 +1,28 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: ld.lld --eh-frame-hdr %t -o /dev/null + +.section .eh_frame + .byte 0x0E + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + + .byte 0x50 # Augmentation string: 'P','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x02 # DW_EH_PE_udata2 + .byte 0xFF + .byte 0xFF + .byte 0xFF diff --git a/test/ELF/eh-frame-value-format5.s b/test/ELF/eh-frame-value-format5.s new file mode 100644 index 000000000000..fd5b35a8b05e --- /dev/null +++ b/test/ELF/eh-frame-value-format5.s @@ -0,0 +1,35 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: ld.lld --eh-frame-hdr %t -o /dev/null + +.section .eh_frame + .byte 0x14 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + + .byte 0x50 # Augmentation string: 'P','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x08 # DW_EH_PE_signed + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + + .byte 0xFF diff --git a/test/ELF/eh-frame-value-format6.s b/test/ELF/eh-frame-value-format6.s new file mode 100644 index 000000000000..ee76fa7a050f --- /dev/null +++ b/test/ELF/eh-frame-value-format6.s @@ -0,0 +1,35 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: ld.lld --eh-frame-hdr %t -o /dev/null + +.section .eh_frame + .byte 0x14 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + + .byte 0x50 # Augmentation string: 'P','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x00 # DW_EH_PE_absptr + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + .byte 0xFF + + .byte 0xFF diff --git a/test/ELF/eh-frame-value-format7.s b/test/ELF/eh-frame-value-format7.s new file mode 100644 index 000000000000..90543a2b72f2 --- /dev/null +++ b/test/ELF/eh-frame-value-format7.s @@ -0,0 +1,75 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld --eh-frame-hdr --section-start .text=0x1000 %t.o -o %t +# RUN: llvm-readobj -s -section-data %t | FileCheck %s + +## Check we are able to handle DW_EH_PE_udata2 encoding. + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .eh_frame_hdr +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x2000 +# CHECK-NEXT: Offset: 0x2000 +# CHECK-NEXT: Size: 20 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 011B033B 10000000 01000000 34F2FFFF +# CHECK-NEXT: 0010: 24000000 +# Header (always 4 bytes): 011B033B +# 10000000 = .eh_frame(0x2014) - .eh_frame_hdr(0x2000) - 4 +# 01000000 = 1 = the number of FDE pointers in the table. +# 34F2FFFF = foo(0x1000) - 0x234(addend) - .eh_frame_hdr(0x2000) + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .eh_frame +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x2014 +# CHECK-NEXT: Offset: 0x2014 +# CHECK-NEXT: Size: +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 0C000000 00000000 01520001 010102FF +# CHECK-NEXT: 0010: 0C000000 14000000 34120000 00000000 +# ^ +# ---> ADDR(foo) + 0x234 = 0x1234 + +.text +.global foo +foo: + nop + +.section .eh_frame + .long 12 # Size + .long 0x00 # ID + .byte 0x01 # Version. + + .byte 0x52 # Augmentation string: 'R','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x02 # DW_EH_PE_udata2 + + .byte 0xFF + + .long 0x6 # Size + .long 0x14 # ID + .short foo + 0x234 diff --git a/test/ELF/eh-frame-value-format8.s b/test/ELF/eh-frame-value-format8.s new file mode 100644 index 000000000000..60324706665e --- /dev/null +++ b/test/ELF/eh-frame-value-format8.s @@ -0,0 +1,74 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld --eh-frame-hdr --section-start .text=0x1000 %t.o -o %t +# RUN: llvm-readobj -s -section-data %t | FileCheck %s + +## Check we are able to handle DW_EH_PE_absptr encoding. + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .eh_frame_hdr +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x2000 +# CHECK-NEXT: Offset: 0x2000 +# CHECK-NEXT: Size: 20 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 011B033B 10000000 01000000 34F2FFFF +# CHECK-NEXT: 0010: 24000000 +# Header (always 4 bytes): 011B033B +# 10000000 = .eh_frame(0x2014) - .eh_frame_hdr(0x2000) - 4 +# 01000000 = 1 = the number of FDE pointers in the table. +# 34F2FFFF = foo(0x1000) - 0x234(addend) - .eh_frame_hdr(0x2000) + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .eh_frame +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x2014 +# CHECK-NEXT: Offset: 0x2014 +# CHECK-NEXT: Size: +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 0C000000 00000000 01520001 010100FF +# CHECK-NEXT: 0010: 0C000000 14000000 34120000 00000000 +# ^ +# ---> ADDR(foo) + 0x234 = 0x1234 +.text +.global foo +foo: + nop + +.section .eh_frame, "ax" + .long 12 # Size + .long 0x00 # ID + .byte 0x01 # Version. + + .byte 0x52 # Augmentation string: 'R','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x00 # DW_EH_PE_absptr + + .byte 0xFF + + .long 12 # Size + .long 0x14 # ID + .quad foo + 0x234 diff --git a/test/ELF/eh-frame-value-format9.s b/test/ELF/eh-frame-value-format9.s new file mode 100644 index 000000000000..1b9ce6944eea --- /dev/null +++ b/test/ELF/eh-frame-value-format9.s @@ -0,0 +1,28 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: not ld.lld --eh-frame-hdr %t.o -o %t 2>&1 | FileCheck %s +# CHECK: error: unknown FDE size encoding + +.section .eh_frame, "ax" + .long 12 # Size + .long 0x00 # ID + .byte 0x01 # Version. + + .byte 0x52 # Augmentation string: 'R','\0' + .byte 0x00 + +# Code and data alignment factors. + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + +# Return address register. + .byte 0x01 # LEB128 + + .byte 0xFE # 'R' value: invalid <0xFE> + + .byte 0xFF + + .long 12 # Size + .long 0x14 # ID + .quad .eh_frame diff --git a/test/ELF/ehframe-relocation.s b/test/ELF/ehframe-relocation.s index 0213b1bebf83..4ab44c20f8ae 100644 --- a/test/ELF/ehframe-relocation.s +++ b/test/ELF/ehframe-relocation.s @@ -12,7 +12,7 @@ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x200120 // CHECK-NEXT: Offset: -// CHECK-NEXT: Size: 48 +// CHECK-NEXT: Size: 52 // CHECK-NOT: .eh_frame // 0x200120 = 2097440 diff --git a/test/ELF/elf-header.s b/test/ELF/elf-header.s new file mode 100644 index 000000000000..e188650f7311 --- /dev/null +++ b/test/ELF/elf-header.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t1 +# RUN: llvm-readobj -file-headers %t1 | FileCheck %s + +# RUN: ld.lld %t.o -no-rosegment -o %t2 +# RUN: llvm-readobj -file-headers %t2 | FileCheck %s + +# CHECK: ElfHeader { +# CHECK-NEXT: Ident { +# CHECK-NEXT: Magic: (7F 45 4C 46) +# CHECK-NEXT: Class: 64-bit (0x2) +# CHECK-NEXT: DataEncoding: LittleEndian (0x1) +# CHECK-NEXT: FileVersion: 1 +# CHECK-NEXT: OS/ABI: SystemV (0x0) +# CHECK-NEXT: ABIVersion: 0 +# CHECK-NEXT: Unused: (00 00 00 00 00 00 00) +# CHECK-NEXT: } diff --git a/test/ELF/emit-relocs-eh-frame.s b/test/ELF/emit-relocs-eh-frame.s new file mode 100644 index 000000000000..4df88585d341 --- /dev/null +++ b/test/ELF/emit-relocs-eh-frame.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: ld.lld --emit-relocs %t1.o -o %t +# RUN: llvm-readobj -r %t | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: Section {{.*}} .rela.eh_frame { +# CHECK-NEXT: 0x{{.*}} R_X86_64_PC32 .text 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +.text +.globl foo +foo: + .cfi_startproc + .cfi_endproc diff --git a/test/ELF/emit-relocs-gc.s b/test/ELF/emit-relocs-gc.s index 0741e78ab955..9379630e7bff 100644 --- a/test/ELF/emit-relocs-gc.s +++ b/test/ELF/emit-relocs-gc.s @@ -11,8 +11,8 @@ ## .rela.text because we keep .text. # RUN: ld.lld --gc-sections --emit-relocs --print-gc-sections %t.o -o %t \ # RUN: | FileCheck --check-prefix=MSG %s -# MSG: removing unused section from '.bar' in file -# MSG: removing unused section from '.rela.bar' in file +# MSG: removing unused section {{.*}}.o:(.bar) +# MSG: removing unused section {{.*}}.o:(.rela.bar) # RUN: llvm-objdump %t -section-headers | FileCheck %s --check-prefix=GC # GC-NOT: rela.bar # GC: rela.text diff --git a/test/ELF/emit-relocs-icf.s b/test/ELF/emit-relocs-icf.s new file mode 100644 index 000000000000..59e003f38ead --- /dev/null +++ b/test/ELF/emit-relocs-icf.s @@ -0,0 +1,33 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: ld.lld --emit-relocs --icf=all %t1.o -o %t +# RUN: llvm-readobj -r %t | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: Section {{.*}} .rela.text { +# CHECK-NEXT: R_X86_64_32 .text 0x1 +# CHECK-NEXT: R_X86_64_PLT32 fn 0xFFFFFFFFFFFFFFFC +# CHECK-NEXT: } +# CHECK-NEXT: ] + +.section .text.fn,"ax",@progbits,unique,0 +.globl fn +.type fn,@function +fn: + nop + +bar: + movl $bar, %edx + callq fn@PLT + nop + +.section .text.fn2,"ax",@progbits,unique,1 +.globl fn2 +.type fn2,@function +fn2: + nop + +foo: + movl $foo, %edx + callq fn2@PLT + nop diff --git a/test/ELF/emit-relocs-shared.s b/test/ELF/emit-relocs-shared.s index 65a12c15ee2e..cb87d9f84805 100644 --- a/test/ELF/emit-relocs-shared.s +++ b/test/ELF/emit-relocs-shared.s @@ -7,10 +7,10 @@ .quad foo # CHECK: Relocations [ -# CHECK-NEXT: Section (4) .rela.dyn { +# CHECK-NEXT: Section {{.*}} .rela.dyn { # CHECK-NEXT: 0x1000 R_X86_64_64 foo 0x0 # CHECK-NEXT: } -# CHECK-NEXT: Section (8) .rela.data { +# CHECK-NEXT: Section {{.*}} .rela.data { # CHECK-NEXT: 0x1000 R_X86_64_64 foo 0x0 # CHECK-NEXT: } # CHECK-NEXT: ] diff --git a/test/ELF/emit-relocs.s b/test/ELF/emit-relocs.s index 95e70d80acf5..b91bb9abe182 100644 --- a/test/ELF/emit-relocs.s +++ b/test/ELF/emit-relocs.s @@ -13,7 +13,7 @@ # CHECK: Section { # CHECK: Index: 2 -# CHECK-NEXT: Name: .rela.text +# CHECK: Name: .rela.text # CHECK-NEXT: Type: SHT_RELA # CHECK-NEXT: Flags [ # CHECK-NEXT: SHF_INFO_LINK diff --git a/test/ELF/empty-archive.s b/test/ELF/empty-archive.s index ffb0a7814419..72232415a588 100644 --- a/test/ELF/empty-archive.s +++ b/test/ELF/empty-archive.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-ar rc %t.a // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: ld.lld -shared %t.o %t.a -o t +// RUN: ld.lld -shared %t.o %t.a -o /dev/null diff --git a/test/ELF/empty-ver2.s b/test/ELF/empty-ver2.s new file mode 100644 index 000000000000..2aceee128ba3 --- /dev/null +++ b/test/ELF/empty-ver2.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: mkdir -p %t.dir +# RUN: cd %t.dir +# RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux +# RUN: ld.lld %t.o -o t.so -shared -version-script %p/Inputs/empty-ver.ver +# RUN: llvm-readobj -version-info t.so | FileCheck %s + +# CHECK: Symbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Version: 0 +# CHECK-NEXT: Name: @ +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Version: 1 +# CHECK-NEXT: Name: bar@@ +# CHECK-NEXT: } +# CHECK-NEXT: ] + +.global bar@ +bar@: diff --git a/test/ELF/emulation.s b/test/ELF/emulation.s index 05efd0b94cb2..98f78b8ec1df 100644 --- a/test/ELF/emulation.s +++ b/test/ELF/emulation.s @@ -1,3 +1,4 @@ +# REQUIRES: x86,ppc,mips,aarch64 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %tx64 # RUN: ld.lld -m elf_amd64_fbsd %tx64 -o %t2x64 # RUN: llvm-readobj -file-headers %t2x64 | FileCheck --check-prefix=AMD64 %s @@ -208,7 +209,8 @@ # PPC64-NEXT: Entry: # PPC64-NEXT: ProgramHeaderOffset: 0x40 # PPC64-NEXT: SectionHeaderOffset: -# PPC64-NEXT: Flags [ (0x0) +# PPC64-NEXT: Flags [ (0x2) +# PPC64-NEXT: 0x2 # PPC64-NEXT: ] # PPC64-NEXT: HeaderSize: 64 # PPC64-NEXT: ProgramHeaderEntrySize: 56 @@ -218,6 +220,38 @@ # PPC64-NEXT: StringTableSectionIndex: # PPC64-NEXT: } +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %tppc64le +# RUN: ld.lld -m elf64lppc %tppc64le -o %t2ppc64le +# RUN: llvm-readobj -file-headers %t2ppc64le | FileCheck --check-prefix=PPC64LE %s +# RUN: ld.lld %tppc64le -o %t3ppc64le +# RUN: llvm-readobj -file-headers %t3ppc64le | FileCheck --check-prefix=PPC64LE %s +# PPC64LE: ElfHeader { +# PPC64LE-NEXT: Ident { +# PPC64LE-NEXT: Magic: (7F 45 4C 46) +# PPC64LE-NEXT: Class: 64-bit (0x2) +# PPC64LE-NEXT: DataEncoding: LittleEndian (0x1) +# PPC64LE-NEXT: FileVersion: 1 +# PPC64LE-NEXT: OS/ABI: SystemV (0x0) +# PPC64LE-NEXT: ABIVersion: 0 +# PPC64LE-NEXT: Unused: (00 00 00 00 00 00 00) +# PPC64LE-NEXT: } +# PPC64LE-NEXT: Type: Executable (0x2) +# PPC64LE-NEXT: Machine: EM_PPC64 (0x15) +# PPC64LE-NEXT: Version: 1 +# PPC64LE-NEXT: Entry: +# PPC64LE-NEXT: ProgramHeaderOffset: 0x40 +# PPC64LE-NEXT: SectionHeaderOffset: +# PPC64LE-NEXT: Flags [ (0x2) +# PPC64LE-NEXT: 0x2 +# PPC64LE-NEXT: ] +# PPC64LE-NEXT: HeaderSize: 64 +# PPC64LE-NEXT: ProgramHeaderEntrySize: 56 +# PPC64LE-NEXT: ProgramHeaderCount: +# PPC64LE-NEXT: SectionHeaderEntrySize: 64 +# PPC64LE-NEXT: SectionHeaderCount: +# PPC64LE-NEXT: StringTableSectionIndex: +# PPC64LE-NEXT: } + # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %tmips # RUN: ld.lld -m elf32btsmip -e _start %tmips -o %t2mips # RUN: llvm-readobj -file-headers %t2mips | FileCheck --check-prefix=MIPS %s @@ -230,7 +264,7 @@ # MIPS-NEXT: DataEncoding: BigEndian (0x2) # MIPS-NEXT: FileVersion: 1 # MIPS-NEXT: OS/ABI: SystemV (0x0) -# MIPS-NEXT: ABIVersion: 0 +# MIPS-NEXT: ABIVersion: 1 # MIPS-NEXT: Unused: (00 00 00 00 00 00 00) # MIPS-NEXT: } # MIPS-NEXT: Type: Executable (0x2) @@ -259,7 +293,7 @@ # MIPSEL-NEXT: DataEncoding: LittleEndian (0x1) # MIPSEL-NEXT: FileVersion: 1 # MIPSEL-NEXT: OS/ABI: SystemV (0x0) -# MIPSEL-NEXT: ABIVersion: 0 +# MIPSEL-NEXT: ABIVersion: 1 # MIPSEL-NEXT: Unused: (00 00 00 00 00 00 00) # MIPSEL-NEXT: } # MIPSEL-NEXT: Type: Executable (0x2) @@ -333,8 +367,12 @@ # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %taarch64 # RUN: ld.lld -m aarch64linux %taarch64 -o %t2aarch64 # RUN: llvm-readobj -file-headers %t2aarch64 | FileCheck --check-prefix=AARCH64 %s -# RUN: ld.lld %taarch64 -o %t3aarch64 +# RUN: ld.lld -m aarch64elf %taarch64 -o %t3aarch64 # RUN: llvm-readobj -file-headers %t3aarch64 | FileCheck --check-prefix=AARCH64 %s +# RUN: ld.lld -m aarch64_elf64_le_vec %taarch64 -o %t4aarch64 +# RUN: llvm-readobj -file-headers %t4aarch64 | FileCheck --check-prefix=AARCH64 %s +# RUN: ld.lld %taarch64 -o %t5aarch64 +# RUN: llvm-readobj -file-headers %t5aarch64 | FileCheck --check-prefix=AARCH64 %s # AARCH64: ElfHeader { # AARCH64-NEXT: Ident { # AARCH64-NEXT: Magic: (7F 45 4C 46) @@ -354,7 +392,5 @@ # AARCH64-NEXT: Flags [ (0x0) # AARCH64-NEXT: ] -# REQUIRES: x86,ppc,mips,aarch64 - .globl _start _start: diff --git a/test/ELF/end-preserve.s b/test/ELF/end-preserve.s index 71d86d1c8faf..d25170605cb3 100644 --- a/test/ELF/end-preserve.s +++ b/test/ELF/end-preserve.s @@ -1,5 +1,5 @@ -// Should preserve the value of the "end" symbol if it is defined. // REQUIRES: x86 +// Should preserve the value of the "end" symbol if it is defined. // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: ld.lld %t.o -o %t diff --git a/test/ELF/end-update.s b/test/ELF/end-update.s index afb137fd2d73..9ece23ce9ac2 100644 --- a/test/ELF/end-update.s +++ b/test/ELF/end-update.s @@ -1,5 +1,5 @@ -// Should set the value of the "end" symbol if it is undefined. // REQUIRES: x86 +// Should set the value of the "end" symbol if it is undefined. // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: ld.lld %t.o -o %t diff --git a/test/ELF/end.s b/test/ELF/end.s index f40c5db8b5ff..530a00783704 100644 --- a/test/ELF/end.s +++ b/test/ELF/end.s @@ -1,5 +1,5 @@ -// Should set the value of the "_end" symbol to the end of the data segment. // REQUIRES: x86 +// Should set the value of the "_end" symbol to the end of the data segment. // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o diff --git a/test/ELF/entry.s b/test/ELF/entry.s index f288bcf6ae50..cc7a7248f082 100644 --- a/test/ELF/entry.s +++ b/test/ELF/entry.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 # RUN: ld.lld -e foobar %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN1 %s diff --git a/test/ELF/exclude-libs.s b/test/ELF/exclude-libs.s index dc7530068586..c061c484b344 100644 --- a/test/ELF/exclude-libs.s +++ b/test/ELF/exclude-libs.s @@ -3,9 +3,10 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ // RUN: %p/Inputs/exclude-libs.s -o %t2.o +// RUN: llvm-as --data-layout=elf %p/Inputs/exclude-libs.ll -o %t3.o // RUN: mkdir -p %t.dir // RUN: rm -f %t.dir/exc.a -// RUN: llvm-ar rcs %t.dir/exc.a %t2.o +// RUN: llvm-ar rcs %t.dir/exc.a %t2.o %t3.o // RUN: ld.lld -shared %t.o %t.dir/exc.a -o %t.exe // RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=DEFAULT %s @@ -22,6 +23,9 @@ // RUN: ld.lld -shared %t.o %t.dir/exc.a -o %t.exe --exclude-libs=ALL // RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=EXCLUDE %s +// RUN: ld.lld -shared %t.o %t2.o %t3.o %t.dir/exc.a -o %t.exe --exclude-libs=ALL +// RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=DEFAULT %s + // RUN: ld.lld -shared --whole-archive %t.o %t.dir/exc.a -o %t.exe --exclude-libs foo,bar,exc.a // RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=EXCLUDE %s @@ -29,8 +33,13 @@ // RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck --check-prefix=EXCLUDE %s // DEFAULT: Name: fn +// DEFAULT: Name: fn2 +// DEFAULT: Name: foo // EXCLUDE-NOT: Name: fn +// EXCLUDE-NOT: Name: fn2 +// EXCLUDE: Name: foo -.globl fn +.globl fn, fn2, foo foo: call fn@PLT + call fn2@PLT diff --git a/test/ELF/executable-undefined-protected-ignoreall.s b/test/ELF/executable-undefined-protected-ignoreall.s index 37911791e124..967a69388670 100644 --- a/test/ELF/executable-undefined-protected-ignoreall.s +++ b/test/ELF/executable-undefined-protected-ignoreall.s @@ -1,6 +1,6 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: not ld.lld %t -o %tout --unresolved-symbols=ignore-all -pie 2>&1 | FileCheck %s +# RUN: not ld.lld %t -o /dev/null --unresolved-symbols=ignore-all -pie 2>&1 | FileCheck %s # CHECK: error: undefined symbol: foo .protected foo diff --git a/test/ELF/export-dynamic-symbol.s b/test/ELF/export-dynamic-symbol.s new file mode 100644 index 000000000000..22536035424c --- /dev/null +++ b/test/ELF/export-dynamic-symbol.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 + +# RUN: rm -f %t.a +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive2.s -o %t1.o +# RUN: llvm-ar rcs %t.a %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o + +# RUN: ld.lld -shared -o %t.so --export-dynamic-symbol foo %t.a %t2.o +# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s + +# RUN: ld.lld -shared -o %t.so --export-dynamic --export-dynamic-symbol foo %t.a %t2.o +# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s + +# CHECK: foo + +.global _start +_start: + nop diff --git a/test/ELF/fatal-warnings.s b/test/ELF/fatal-warnings.s index 0bc2a2b44476..51f2864a0598 100644 --- a/test/ELF/fatal-warnings.s +++ b/test/ELF/fatal-warnings.s @@ -2,11 +2,11 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/warn-common.s -o %t2.o -# RUN: ld.lld --warn-common %t1.o %t2.o -o %t1.out 2>&1 | \ +# RUN: ld.lld --warn-common %t1.o %t2.o -o /dev/null 2>&1 | \ # RUN: FileCheck -check-prefix=ERR %s # ERR: multiple common of -# RUN: not ld.lld --warn-common --fatal-warnings %t1.o %t2.o -o %t2.out 2>&1 | \ +# RUN: not ld.lld --warn-common --fatal-warnings %t1.o %t2.o -o /dev/null 2>&1 | \ # RUN: FileCheck -check-prefix=ERR %s .globl _start diff --git a/test/ELF/file-sym.s b/test/ELF/file-sym.s deleted file mode 100644 index eddb461490c6..000000000000 --- a/test/ELF/file-sym.s +++ /dev/null @@ -1,12 +0,0 @@ -# Check that we do not keep STT_FILE symbols in the symbol table - -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: ld.lld %t.o -shared -o %t.so -# RUN: llvm-readobj -symbols %t.so | FileCheck %s - -# REQUIRES: x86 - -# CHECK-NOT: xxx - -.file "xxx" -.file "" diff --git a/test/ELF/fill-trap-ppc.s b/test/ELF/fill-trap-ppc.s new file mode 100644 index 000000000000..da7d7cb320bb --- /dev/null +++ b/test/ELF/fill-trap-ppc.s @@ -0,0 +1,31 @@ +# REQUIRES: ppc + +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t.ppc64le +# RUN: llvm-readobj -program-headers %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: llvm-readobj -program-headers %t.ppc64 | FileCheck %s +# RUN: od -Ax -t x1 -N16 -j0x10ff0 %t.ppc64 | FileCheck %s -check-prefix=BE + +# CHECK: ProgramHeader { +# CHECK: Type: PT_LOAD +# CHECK: Offset: 0x10000{{$}} +# CHECK-NEXT: VirtualAddress: +# CHECK-NEXT: PhysicalAddress: +# CHECK-NEXT: FileSize: 4096 +# CHECK-NEXT: MemSize: +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_X +# CHECK-NEXT: ] + +## Check that executable page is filled with traps at its end. +# LE: 010ff0 08 00 e0 7f 08 00 e0 7f 08 00 e0 7f 08 00 e0 7f +# BE: 010ff0 7f e0 00 08 7f e0 00 08 7f e0 00 08 7f e0 00 08 + +.globl _start +_start: + nop diff --git a/test/ELF/filter.s b/test/ELF/filter.s index 4c9104a32510..2b07c01013df 100644 --- a/test/ELF/filter.s +++ b/test/ELF/filter.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: ld.lld %t.o -shared -F foo.so -F boo.so -o %t1 # RUN: llvm-readobj --dynamic-table %t1 | FileCheck %s @@ -15,5 +16,5 @@ # CHECK-NEXT: 0x000000007FFFFFFF FILTER Filter library: [foo.so] # CHECK-NEXT: 0x000000007FFFFFFF FILTER Filter library: [boo.so] -# RUN: not ld.lld %t.o -F x -o %t 2>&1 | FileCheck -check-prefix=ERR %s +# RUN: not ld.lld %t.o -F x -o /dev/null 2>&1 | FileCheck -check-prefix=ERR %s # ERR: -F may not be used without -shared diff --git a/test/ELF/format-binary-non-ascii.s b/test/ELF/format-binary-non-ascii.s index 5a3ad960c30e..36263e5ddaba 100644 --- a/test/ELF/format-binary-non-ascii.s +++ b/test/ELF/format-binary-non-ascii.s @@ -4,9 +4,9 @@ # RUN: ld.lld -o %t.elf %t£.o --format=binary %t£.o # RUN: llvm-readobj -symbols %t.elf | FileCheck %s -# CHECK: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_non_ascii_s_tmp___o_start -# CHECK: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_non_ascii_s_tmp___o_end -# CHECK: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_non_ascii_s_tmp___o_size +# CHECK: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_non_ascii_s_tmp_{{[_]+}}o_start +# CHECK: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_non_ascii_s_tmp_{{[_]+}}o_end +# CHECK: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_non_ascii_s_tmp_{{[_]+}}o_size .text .align 4 diff --git a/test/ELF/gc-absolute.s b/test/ELF/gc-absolute.s index 29e671678ee7..bd0870c263a7 100644 --- a/test/ELF/gc-absolute.s +++ b/test/ELF/gc-absolute.s @@ -1,7 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 -shared --gc-sections +# RUN: ld.lld %t -o /dev/null -shared --gc-sections .global foo foo = 0x123 diff --git a/test/ELF/gc-debuginfo-tls.s b/test/ELF/gc-debuginfo-tls.s index d1a250b9c944..e23578f58c25 100644 --- a/test/ELF/gc-debuginfo-tls.s +++ b/test/ELF/gc-debuginfo-tls.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: ld.lld %t.o --gc-sections -shared -o %t1 # RUN: ld.lld %t.o -shared -o %t2 diff --git a/test/ELF/gc-merge-local-sym.s b/test/ELF/gc-merge-local-sym.s index b02a3a4e4762..b82d0cebae82 100644 --- a/test/ELF/gc-merge-local-sym.s +++ b/test/ELF/gc-merge-local-sym.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: ld.lld %t.o -o %t.so -shared -O3 --gc-sections // RUN: llvm-readobj -s -section-data -t %t.so | FileCheck %s @@ -9,7 +10,7 @@ // CHECK-NEXT: SHF_MERGE // CHECK-NEXT: SHF_STRINGS // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x1C8 +// CHECK-NEXT: Address: 0x235 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 4 // CHECK-NEXT: Link: 0 diff --git a/test/ELF/gc-sections-local-sym.s b/test/ELF/gc-sections-local-sym.s index 89121e289cc2..15bca37ca409 100644 --- a/test/ELF/gc-sections-local-sym.s +++ b/test/ELF/gc-sections-local-sym.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t // RUN: ld.lld %t -o %t2 -shared --gc-sections // RUN: llvm-readobj -t -s -section-data %t2 | FileCheck %s -// REQUIRES: x86 .global foo foo: diff --git a/test/ELF/gc-sections-merge-addend.s b/test/ELF/gc-sections-merge-addend.s index 8595f5802be5..4dd95b43bfc0 100644 --- a/test/ELF/gc-sections-merge-addend.s +++ b/test/ELF/gc-sections-merge-addend.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: ld.lld %t.o -o %t.so -shared --gc-sections // RUN: llvm-readobj -s -section-data %t.so | FileCheck %s diff --git a/test/ELF/gc-sections-merge-implicit-addend.s b/test/ELF/gc-sections-merge-implicit-addend.s index 8a7c804a830a..36bb21126434 100644 --- a/test/ELF/gc-sections-merge-implicit-addend.s +++ b/test/ELF/gc-sections-merge-implicit-addend.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=i386-pc-linux // RUN: ld.lld %t.o -o %t.so -shared --gc-sections // RUN: llvm-readobj -s -section-data %t.so | FileCheck %s diff --git a/test/ELF/gc-sections-merge.s b/test/ELF/gc-sections-merge.s index ef2688659871..08dfdaaea669 100644 --- a/test/ELF/gc-sections-merge.s +++ b/test/ELF/gc-sections-merge.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: ld.lld %t.o -o %t.so -shared // RUN: ld.lld %t.o -o %t.gc.so -shared --gc-sections diff --git a/test/ELF/gc-sections-metadata-startstop.s b/test/ELF/gc-sections-metadata-startstop.s index 10c0b5477b25..ede1899698c4 100644 --- a/test/ELF/gc-sections-metadata-startstop.s +++ b/test/ELF/gc-sections-metadata-startstop.s @@ -1,5 +1,5 @@ -# LINK_ORDER cnamed sections are not kept alive by the __start_* reference. # REQUIRES: x86 +# LINK_ORDER cnamed sections are not kept alive by the __start_* reference. # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: ld.lld --gc-sections %t.o -o %t diff --git a/test/ELF/gc-sections-no-undef-error.s b/test/ELF/gc-sections-no-undef-error.s new file mode 100644 index 000000000000..31945241a77a --- /dev/null +++ b/test/ELF/gc-sections-no-undef-error.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o + +# Sanity check that the link will fail with the undefined error without +# gc-sections. +# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s +# CHECK: error: undefined symbol: undefined + +# RUN: ld.lld %t.o --gc-sections -o %t + +.section .text.unused,"ax",@progbits +unused: + callq undefined + +.text +.global _start +_start: + nop diff --git a/test/ELF/gc-sections-print.s b/test/ELF/gc-sections-print.s index e05824177c1f..a822e9ef3479 100644 --- a/test/ELF/gc-sections-print.s +++ b/test/ELF/gc-sections-print.s @@ -2,8 +2,8 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: ld.lld %t --gc-sections --print-gc-sections -o %t2 2>&1 | FileCheck -check-prefix=PRINT %s -# PRINT: removing unused section from '.text.x' in file -# PRINT-NEXT: removing unused section from '.text.y' in file +# PRINT: removing unused section {{.*}}:(.text.x) +# PRINT-NEXT: removing unused section {{.*}}:(.text.y) # RUN: ld.lld %t --gc-sections --print-gc-sections --no-print-gc-sections -o %t2 >& %t.log # RUN: echo >> %t.log diff --git a/test/ELF/gc-sections-protected.s b/test/ELF/gc-sections-protected.s index 9f1efed5938a..28e779b1b7a1 100644 --- a/test/ELF/gc-sections-protected.s +++ b/test/ELF/gc-sections-protected.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: ld.lld %t.o -o %t.so -shared --gc-sections // RUN: llvm-readobj -s %t.so | FileCheck %s diff --git a/test/ELF/gc-sections-shared.s b/test/ELF/gc-sections-shared.s index 2976213e910a..c0ebf403a333 100644 --- a/test/ELF/gc-sections-shared.s +++ b/test/ELF/gc-sections-shared.s @@ -25,6 +25,15 @@ # CHECK-NEXT: Section: Undefined (0x0) # CHECK-NEXT: } # CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: qux +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Weak +# CHECK-NEXT: Type: +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: Undefined +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { # CHECK-NEXT: Name: bar # CHECK-NEXT: Value: # CHECK-NEXT: Size: @@ -51,15 +60,6 @@ # CHECK-NEXT: Other: # CHECK-NEXT: Section: .text # CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: qux -# CHECK-NEXT: Value: -# CHECK-NEXT: Size: -# CHECK-NEXT: Binding: Weak -# CHECK-NEXT: Type: -# CHECK-NEXT: Other: -# CHECK-NEXT: Section: Undefined -# CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NOT: NEEDED @@ -68,64 +68,12 @@ # Test with %t.o at the end too. # RUN: ld.lld --gc-sections --export-dynamic-symbol foo -o %t --as-needed %t2.so %t3.so %t4.so %t.o -# RUN: llvm-readobj --dynamic-table --dyn-symbols %t | FileCheck --check-prefix=CHECK2 %s - -# CHECK2: DynamicSymbols [ -# CHECK2-NEXT: Symbol { -# CHECK2-NEXT: Name: -# CHECK2-NEXT: Value: -# CHECK2-NEXT: Size: -# CHECK2-NEXT: Binding: Local -# CHECK2-NEXT: Type: -# CHECK2-NEXT: Other: -# CHECK2-NEXT: Section: Undefined (0x0) -# CHECK2-NEXT: } -# CHECK2-NEXT: Symbol { -# CHECK2-NEXT: Name: bar -# CHECK2-NEXT: Value: -# CHECK2-NEXT: Size: -# CHECK2-NEXT: Binding: Global -# CHECK2-NEXT: Type: -# CHECK2-NEXT: Other: -# CHECK2-NEXT: Section: .text -# CHECK2-NEXT: } -# CHECK2-NEXT: Symbol { -# CHECK2-NEXT: Name: baz -# CHECK2-NEXT: Value: -# CHECK2-NEXT: Size: -# CHECK2-NEXT: Binding: Global -# CHECK2-NEXT: Type: -# CHECK2-NEXT: Other: -# CHECK2-NEXT: Section: Undefined -# CHECK2-NEXT: } -# CHECK2-NEXT: Symbol { -# CHECK2-NEXT: Name: qux -# CHECK2-NEXT: Value: -# CHECK2-NEXT: Size: -# CHECK2-NEXT: Binding: Weak -# CHECK2-NEXT: Type: -# CHECK2-NEXT: Other: -# CHECK2-NEXT: Section: Undefined -# CHECK2-NEXT: } -# CHECK2-NEXT: Symbol { -# CHECK2-NEXT: Name: foo -# CHECK2-NEXT: Value: -# CHECK2-NEXT: Size: -# CHECK2-NEXT: Binding: Global -# CHECK2-NEXT: Type: -# CHECK2-NEXT: Other: -# CHECK2-NEXT: Section: .text -# CHECK2-NEXT: } -# CHECK2-NEXT: ] - -# CHECK2-NOT: NEEDED -# CHECK2: NEEDED Shared library: [{{.*}}3.so] -# CHECK2-NOT: NEEDED +# RUN: llvm-readobj --dynamic-table --dyn-symbols %t | FileCheck --check-prefix=CHECK %s .section .text.foo, "ax" .globl foo foo: -call bar +.long bar - . .section .text.bar, "ax" .globl bar @@ -136,9 +84,9 @@ ret .globl _start .weak qux _start: -call baz -call qux +.long baz - . +.long qux - . ret .section .text.unused, "ax" -call bar2 +.long bar2 - . diff --git a/test/ELF/gdb-index-dup-types.s b/test/ELF/gdb-index-dup-types.s deleted file mode 100644 index f5df00c453cc..000000000000 --- a/test/ELF/gdb-index-dup-types.s +++ /dev/null @@ -1,60 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: ld.lld --gdb-index %t.o -o %t -# RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s - -## Testcase is based on output produced by gcc version 5.4.1 20160904 -## it has duplicate entries in .debug_gnu_pubtypes which seems to be -## compiler bug. In that case it is useless to have them in .gdb_index -## and we filter such entries out to reduce size of .gdb_index. - -## CHECK: Constant pool offset = {{.*}}, has 1 CU vectors: -## CHECK-NOT: 0(0x0): 0x90000000 0x90000000 - -.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 - .ascii "\260B" # DW_AT_GNU_dwo_name - .byte 14 # DW_FORM_strp - .byte 27 # DW_AT_comp_dir - .byte 14 # DW_FORM_strp - .ascii "\264B" # DW_AT_GNU_pubnames - .byte 25 # DW_FORM_flag_present - .ascii "\261B" # DW_AT_GNU_dwo_id - .byte 7 # DW_FORM_data8 - .ascii "\263B" # DW_AT_GNU_addr_base - .byte 23 # DW_FORM_sec_offset - .byte 0 # EOM(1) - .byte 0 # EOM(2) - .byte 0 # EOM(3) - -.section .debug_info,"",@progbits -.Lcu_begin0: - .long 32 # Length of Unit - .short 4 # DWARF version number - .long .debug_abbrev # Offset Into Abbrev. Section - .byte 8 # Address Size (in bytes) - .byte 1 # Abbrev [1] 0xb:0x19 DW_TAG_compile_unit - .long 0 # DW_AT_stmt_list - .long 0 # DW_AT_GNU_dwo_name - .long 0 # DW_AT_comp_dir - .quad 0 # DW_AT_GNU_dwo_id - .long 0 # DW_AT_GNU_addr_base - -.section .debug_gnu_pubtypes,"",@progbits -.long .LpubTypes_end0-.LpubTypes_begin0 # Length of Public Types Info -.LpubTypes_begin0: - .short 2 # DWARF Version - .long .Lcu_begin0 # Offset of Compilation Unit Info - .long 36 # Compilation Unit Length - .long 36 # DIE offset - .byte 144 # Kind: TYPE, STATIC - .asciz "int" # External Name - .long 36 # DIE offset - .byte 144 # Kind: TYPE, STATIC - .asciz "int" # External Name - .long 0 # End Mark -.LpubTypes_end0: diff --git a/test/ELF/gdb-index-noranges.s b/test/ELF/gdb-index-noranges.s index 29ba91eb5a75..12080642e6cd 100644 --- a/test/ELF/gdb-index-noranges.s +++ b/test/ELF/gdb-index-noranges.s @@ -10,7 +10,7 @@ ## ## Debug information does not contain any address ranges. ## We crashed in that case. Check we don't. -# RUN: ld.lld --gdb-index %t1.o -o %t +# RUN: ld.lld --gdb-index %t1.o -o /dev/null .section .debug_str,"MS",@progbits,1 .Lskel_string0: diff --git a/test/ELF/gdb-index-tls.s b/test/ELF/gdb-index-tls.s index 0fd7b6115676..785e13f0056f 100644 --- a/test/ELF/gdb-index-tls.s +++ b/test/ELF/gdb-index-tls.s @@ -1,6 +1,6 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: ld.lld --gdb-index -shared %t.o -o %t +# RUN: ld.lld --gdb-index -shared %t.o -o /dev/null # This used to fail trying to compute R_X86_64_DTPOFF64 diff --git a/test/ELF/gdb-index.s b/test/ELF/gdb-index.s index 8fea83d145fa..e7f96066bd02 100644 --- a/test/ELF/gdb-index.s +++ b/test/ELF/gdb-index.s @@ -1,9 +1,19 @@ -# REQUIRES: x86 +# REQUIRES: x86, zlib # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/gdb-index.s -o %t2.o # RUN: ld.lld --gdb-index %t1.o %t2.o -o %t -# RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s + +# RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=DISASM +# RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s --check-prefix=DWARF +# RUN: llvm-readelf -sections %t | FileCheck %s --check-prefix=SECTION + +# RUN: llvm-mc -compress-debug-sections=zlib-gnu -filetype=obj -triple=x86_64-pc-linux \ +# RUN: %p/Inputs/gdb-index.s -o %t2.o +# RUN: ld.lld --gdb-index %t1.o %t2.o -o %t + # RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=DISASM +# RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s --check-prefix=DWARF +# RUN: llvm-readelf -sections %t | FileCheck %s --check-prefix=SECTION # DISASM: Disassembly of section .text: # DISASM: entrypoint: @@ -11,29 +21,31 @@ # DISASM-CHECK: 201001: cc int3 # DISASM-CHECK: 201002: cc int3 # DISASM-CHECK: 201003: cc int3 -# DISASM: main2: +# DISASM: aaaaaaaaaaaaaaaa: # DISASM-CHECK: 201004: 90 nop # DISASM-CHECK: 201005: 90 nop -# CHECK: .gnu_index contents: -# CHECK-NEXT: Version = 7 -# CHECK: CU list offset = 0x18, has 2 entries: -# CHECK-NEXT: 0: Offset = 0x0, Length = 0x34 -# CHECK-NEXT: 1: Offset = 0x34, Length = 0x34 -# CHECK: Address area offset = 0x38, has 2 entries: -# CHECK-NEXT: Low/High address = [0x201000, 0x201001) (Size: 0x1), CU id = 0 -# CHECK-NEXT: Low/High address = [0x201004, 0x201006) (Size: 0x2), CU id = 1 -# CHECK: Symbol table offset = 0x60, size = 1024, filled slots: -# CHECK-NEXT: 754: Name offset = 0x27, CU vector offset = 0x8 -# CHECK-NEXT: String name: int, CU vector index: 1 -# CHECK-NEXT: 822: Name offset = 0x1c, CU vector offset = 0x0 -# CHECK-NEXT: String name: entrypoint, CU vector index: 0 -# CHECK-NEXT: 956: Name offset = 0x2b, CU vector offset = 0x14 -# CHECK-NEXT: String name: main2, CU vector index: 2 -# CHECK: Constant pool offset = 0x2060, has 3 CU vectors: -# CHECK-NEXT: 0(0x0): 0x30000000 -# CHECK-NEXT: 1(0x8): 0x90000000 0x90000001 -# CHECK-NEXT: 2(0x14): 0x30000001 +# DWARF: .gnu_index contents: +# DWARF-NEXT: Version = 7 +# DWARF: CU list offset = 0x18, has 2 entries: +# DWARF-NEXT: 0: Offset = 0x0, Length = 0x34 +# DWARF-NEXT: 1: Offset = 0x34, Length = 0x34 +# DWARF: Address area offset = 0x38, has 2 entries: +# DWARF-NEXT: Low/High address = [0x201000, 0x201001) (Size: 0x1), CU id = 0 +# DWARF-NEXT: Low/High address = [0x201004, 0x201006) (Size: 0x2), CU id = 1 +# DWARF: Symbol table offset = 0x60, size = 1024, filled slots: +# DWARF-NEXT: 512: Name offset = 0x1c, CU vector offset = 0x0 +# DWARF-NEXT: String name: aaaaaaaaaaaaaaaa, CU vector index: 0 +# DWARF-NEXT: 754: Name offset = 0x38, CU vector offset = 0x10 +# DWARF-NEXT: String name: int, CU vector index: 2 +# DWARF-NEXT: 822: Name offset = 0x2d, CU vector offset = 0x8 +# DWARF-NEXT: String name: entrypoint, CU vector index: 1 +# DWARF: Constant pool offset = 0x2060, has 3 CU vectors: +# DWARF-NEXT: 0(0x0): 0x30000001 +# DWARF-NEXT: 1(0x8): 0x30000000 +# DWARF-NEXT: 2(0x10): 0x90000000 0x90000001 + +# SECTION-NOT: debug_gnu_pubnames # RUN: ld.lld --gdb-index --no-gdb-index %t1.o %t2.o -o %t2 # RUN: llvm-readobj -sections %t2 | FileCheck -check-prefix=NOGDB %s diff --git a/test/ELF/global-offset-table-position-aarch64.s b/test/ELF/global-offset-table-position-aarch64.s index 68bc4a4254ed..7fdc7978825f 100644 --- a/test/ELF/global-offset-table-position-aarch64.s +++ b/test/ELF/global-offset-table-position-aarch64.s @@ -1,7 +1,7 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t // RUN: ld.lld --hash-style=sysv -shared %t -o %t2 // RUN: llvm-readobj -t %t2 | FileCheck %s -// REQUIRES: aarch64 .globl a .type a,@object .comm a,4,4 @@ -20,11 +20,11 @@ _start: .long _GLOBAL_OFFSET_TABLE_ - . // CHECK: Name: _GLOBAL_OFFSET_TABLE_ (11) -// CHECK-NEXT: Value: 0x30090 +// CHECK-NEXT: Value: 0x20008 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local (0x0) // CHECK-NEXT: Type: None (0x0) // CHECK-NEXT: Other [ (0x2) // CHECK-NEXT: STV_HIDDEN (0x2) // CHECK-NEXT: ] -// CHECK-NEXT: Section: .got +// CHECK-NEXT: Section: .got.plt diff --git a/test/ELF/global-offset-table-position-arm.s b/test/ELF/global-offset-table-position-arm.s index 19619b2cc9e8..9abca8b46317 100644 --- a/test/ELF/global-offset-table-position-arm.s +++ b/test/ELF/global-offset-table-position-arm.s @@ -1,7 +1,7 @@ +// REQUIRES: arm // RUN: llvm-mc -filetype=obj -triple=armv7a-linux-gnueabihf %s -o %t // RUN: ld.lld --hash-style=sysv -shared %t -o %t2 // RUN: llvm-readobj -t %t2 | FileCheck %s -// REQUIRES: arm // The ARM _GLOBAL_OFFSET_TABLE_ should be defined at the start of the .got .globl a diff --git a/test/ELF/global-offset-table-position-i386.s b/test/ELF/global-offset-table-position-i386.s index 9f778e1efb50..e3d343427015 100644 --- a/test/ELF/global-offset-table-position-i386.s +++ b/test/ELF/global-offset-table-position-i386.s @@ -1,9 +1,10 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t // RUN: ld.lld --hash-style=sysv -shared %t -o %t2 // RUN: llvm-readobj -t %t2 | FileCheck %s -// REQUIRES: x86 -// The X86 _GLOBAL_OFFSET_TABLE_ is defined at the end of the .got section. +// The X86 _GLOBAL_OFFSET_TABLE_ is defined at the start of the .got.plt +// section. .globl a .type a,@object .comm a,4,4 @@ -21,11 +22,11 @@ addl $_GLOBAL_OFFSET_TABLE_, %eax calll f@PLT // CHECK: Name: _GLOBAL_OFFSET_TABLE_ (1) -// CHECK-NEXT: Value: 0x306C +// CHECK-NEXT: Value: 0x2000 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local (0x0) // CHECK-NEXT: Type: None (0x0) // CHECK-NEXT: Other [ (0x2) // CHECK-NEXT: STV_HIDDEN (0x2) // CHECK-NEXT: ] -// CHECK-NEXT: Section: .got (0xA) +// CHECK-NEXT: Section: .got.plt diff --git a/test/ELF/global-offset-table-position-mips.s b/test/ELF/global-offset-table-position-mips.s index 92daed1c7914..a5577f2e1421 100644 --- a/test/ELF/global-offset-table-position-mips.s +++ b/test/ELF/global-offset-table-position-mips.s @@ -1,9 +1,8 @@ +// REQUIRES: mips // RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t // RUN: ld.lld -shared %t -o %t2 // RUN: llvm-readobj -t %t2 | FileCheck %s -// REQUIRES: mips - // The Mips _GLOBAL_OFFSET_TABLE_ should be defined at the start of the .got .globl a diff --git a/test/ELF/global-offset-table-position.s b/test/ELF/global-offset-table-position.s index f1195b2cf674..aa8083654039 100644 --- a/test/ELF/global-offset-table-position.s +++ b/test/ELF/global-offset-table-position.s @@ -1,9 +1,10 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld --hash-style=sysv -shared %t -o %t2 // RUN: llvm-readobj -t %t2 | FileCheck %s -// REQUIRES: x86 -// The X86_64 _GLOBAL_OFFSET_TABLE_ is defined at the end of the .got section. +// The X86_64 _GLOBAL_OFFSET_TABLE_ is defined at the start of the .got.plt +// section. .globl a .type a,@object .comm a,4,4 @@ -21,11 +22,11 @@ callq f@PLT .long _GLOBAL_OFFSET_TABLE_ - . // CHECK: Name: _GLOBAL_OFFSET_TABLE_ -// CHECK-NEXT: Value: 0x30D8 +// CHECK-NEXT: Value: 0x2008 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None (0x0) // CHECK-NEXT: Other [ // CHECK-NEXT: STV_HIDDEN // CHECK-NEXT: ] -// CHECK-NEXT: Section: .got +// CHECK-NEXT: Section: .got.plt diff --git a/test/ELF/global_offset_table.s b/test/ELF/global_offset_table.s index 47e95e9f9b84..3b86f00ae3ab 100644 --- a/test/ELF/global_offset_table.s +++ b/test/ELF/global_offset_table.s @@ -1,5 +1,6 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: ld.lld %t -o %t2 +// RUN: ld.lld %t -o /dev/null .global _start _start: .long _GLOBAL_OFFSET_TABLE_ diff --git a/test/ELF/global_offset_table_shared.s b/test/ELF/global_offset_table_shared.s index 03af02e5805e..7af6a403ac6c 100644 --- a/test/ELF/global_offset_table_shared.s +++ b/test/ELF/global_offset_table_shared.s @@ -1,14 +1,15 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld --hash-style=sysv -shared %t -o %t2 // RUN: llvm-readobj -t %t2 | FileCheck %s .long _GLOBAL_OFFSET_TABLE_ - . // CHECK: Name: _GLOBAL_OFFSET_TABLE_ -// CHECK-NEXT: Value: 0x2060 +// CHECK-NEXT: Value: 0x2000 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None // CHECK-NEXT: Other [ (0x2) // CHECK-NEXT: STV_HIDDEN (0x2) // CHECK-NEXT: ] -// CHECK-NEXT: Section: .got +// CHECK-NEXT: Section: .got.plt diff --git a/test/ELF/gnu-hash-table.s b/test/ELF/gnu-hash-table.s index fa68ba250131..ffbf19fb5c6f 100644 --- a/test/ELF/gnu-hash-table.s +++ b/test/ELF/gnu-hash-table.s @@ -4,30 +4,36 @@ # RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %te.s -o %te-i386.o # RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t-i386.o # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t-x86_64.o -# RUN: llvm-mc -filetype=obj -triple=powerpc64-pc-linux %s -o %t-ppc64.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t-ppc64le.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t-ppc64.o # RUN: echo ".global zed; zed:" > %t2.s # RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %t2.s -o %t2-i386.o # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t2.s -o %t2-x86_64.o -# RUN: llvm-mc -filetype=obj -triple=powerpc64-pc-linux %t2.s -o %t2-ppc64.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %t2.s -o %t2-ppc64le.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %t2.s -o %t2-ppc64.o # RUN: rm -f %t2-i386.a %t2-x86_64.a %t2-ppc64.a # RUN: llvm-ar rc %t2-i386.a %t2-i386.o # RUN: llvm-ar rc %t2-x86_64.a %t2-x86_64.o +# RUN: llvm-ar rc %t2-ppc64le.a %t2-ppc64le.o # RUN: llvm-ar rc %t2-ppc64.a %t2-ppc64.o # RUN: echo ".global xyz; xyz:" > %t3.s # RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %t3.s -o %t3-i386.o # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t3.s -o %t3-x86_64.o -# RUN: llvm-mc -filetype=obj -triple=powerpc64-pc-linux %t3.s -o %t3-ppc64.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %t3.s -o %t3-ppc64le.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %t3.s -o %t3-ppc64.o # RUN: ld.lld -shared %t3-i386.o -o %t3-i386.so # RUN: ld.lld -shared %t3-x86_64.o -o %t3-x86_64.so +# RUN: ld.lld -shared %t3-ppc64le.o -o %t3-ppc64le.so # RUN: ld.lld -shared %t3-ppc64.o -o %t3-ppc64.so # RUN: ld.lld -shared --hash-style=gnu -o %te-i386.so %te-i386.o # RUN: ld.lld -shared -hash-style=gnu -o %t-i386.so %t-i386.o %t2-i386.a %t3-i386.so # RUN: ld.lld -shared -hash-style=gnu -o %t-x86_64.so %t-x86_64.o %t2-x86_64.a %t3-x86_64.so +# RUN: ld.lld -shared --hash-style both -o %t-ppc64le.so %t-ppc64le.o %t2-ppc64le.a %t3-ppc64le.so # RUN: ld.lld -shared --hash-style both -o %t-ppc64.so %t-ppc64.o %t2-ppc64.a %t3-ppc64.so # RUN: llvm-readobj -dyn-symbols -gnu-hash-table %te-i386.so \ @@ -36,6 +42,8 @@ # RUN: | FileCheck %s -check-prefix=I386 # RUN: llvm-readobj -sections -dyn-symbols -gnu-hash-table %t-x86_64.so \ # RUN: | FileCheck %s -check-prefix=X86_64 +# RUN: llvm-readobj -sections -dyn-symbols -gnu-hash-table %t-ppc64le.so \ +# RUN: | FileCheck %s -check-prefix=PPC64 # RUN: llvm-readobj -sections -dyn-symbols -gnu-hash-table %t-ppc64.so \ # RUN: | FileCheck %s -check-prefix=PPC64 @@ -51,12 +59,12 @@ # EMPTY-NEXT: } # EMPTY-NEXT: ] # EMPTY: GnuHashTable { -# EMPTY-NEXT: Num Buckets: 0 +# EMPTY-NEXT: Num Buckets: 1 # EMPTY-NEXT: First Hashed Symbol Index: 2 # EMPTY-NEXT: Num Mask Words: 1 -# EMPTY-NEXT: Shift Count: 5 +# EMPTY-NEXT: Shift Count: 6 # EMPTY-NEXT: Bloom Filter: [0x0] -# EMPTY-NEXT: Buckets: [] +# EMPTY-NEXT: Buckets: [0] # EMPTY-NEXT: Values: [] # EMPTY-NEXT: } @@ -113,8 +121,8 @@ # I386-NEXT: Num Buckets: 1 # I386-NEXT: First Hashed Symbol Index: 4 # I386-NEXT: Num Mask Words: 1 -# I386-NEXT: Shift Count: 5 -# I386-NEXT: Bloom Filter: [0x14000220] +# I386-NEXT: Shift Count: 6 +# I386-NEXT: Bloom Filter: [0x4004204] # I386-NEXT: Buckets: [4] # I386-NEXT: Values: [0xB8860BA, 0xB887389] # I386-NEXT: } diff --git a/test/ELF/gnu-ifunc-dynsym.s b/test/ELF/gnu-ifunc-dynsym.s index fca15462dcb1..3d98ac3a4cfc 100644 --- a/test/ELF/gnu-ifunc-dynsym.s +++ b/test/ELF/gnu-ifunc-dynsym.s @@ -1,7 +1,11 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o + // RUN: ld.lld -static -export-dynamic %t.o -o %tout // RUN: llvm-nm -U %tout | FileCheck %s -// REQUIRES: x86 + +// RUN: ld.lld -export-dynamic %t.o -o %tout +// RUN: llvm-nm -U %tout | FileCheck %s // CHECK: __rela_iplt_end // CHECK: __rela_iplt_start diff --git a/test/ELF/gnu-ifunc-dyntags.s b/test/ELF/gnu-ifunc-dyntags.s new file mode 100644 index 000000000000..81bd338d088d --- /dev/null +++ b/test/ELF/gnu-ifunc-dyntags.s @@ -0,0 +1,41 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld -pie %t.o -o %tout +# RUN: llvm-objdump -section-headers %tout | FileCheck %s +# RUN: llvm-readobj -dynamic-table -r %tout | FileCheck %s --check-prefix=TAGS + +## Check we produce DT_PLTREL/DT_JMPREL/DT_PLTGOT and DT_PLTRELSZ tags +## when there are no other relocations except R_*_IRELATIVE. + +# CHECK: Name Size Address +# CHECK: .rela.plt 00000030 0000000000000210 +# CHECK: .got.plt 00000010 0000000000002000 + +# TAGS: Relocations [ +# TAGS-NEXT: Section {{.*}} .rela.plt { +# TAGS-NEXT: R_X86_64_IRELATIVE +# TAGS-NEXT: R_X86_64_IRELATIVE +# TAGS-NEXT: } +# TAGS-NEXT: ] + +# TAGS: Tag Type Name/Value +# TAGS: 0x0000000000000017 JMPREL 0x210 +# TAGS: 0x0000000000000002 PLTRELSZ 48 +# TAGS: 0x0000000000000003 PLTGOT 0x2000 +# TAGS: 0x0000000000000014 PLTREL RELA + +.text +.type foo STT_GNU_IFUNC +.globl foo +foo: + ret + +.type bar STT_GNU_IFUNC +.globl bar +bar: + ret + +.globl _start +_start: + call foo + call bar diff --git a/test/ELF/gnu-ifunc-i386.s b/test/ELF/gnu-ifunc-i386.s index 4eda32f378d9..f379bf1b28e8 100644 --- a/test/ELF/gnu-ifunc-i386.s +++ b/test/ELF/gnu-ifunc-i386.s @@ -1,8 +1,8 @@ +// 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-readobj -r -symbols -sections %tout | FileCheck %s -// REQUIRES: x86 // CHECK: Sections [ // CHECK: Section { diff --git a/test/ELF/gnu-ifunc-nosym-i386.s b/test/ELF/gnu-ifunc-nosym-i386.s index d22cedbfe6de..564b87e23b32 100644 --- a/test/ELF/gnu-ifunc-nosym-i386.s +++ b/test/ELF/gnu-ifunc-nosym-i386.s @@ -1,7 +1,7 @@ +// 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-readobj -symbols %tout | FileCheck %s -// REQUIRES: x86 // Check that no __rel_iplt_end/__rel_iplt_start // appear in symtab if there is no references to them. diff --git a/test/ELF/gnu-ifunc-nosym.s b/test/ELF/gnu-ifunc-nosym.s index 08e498e97c19..4206f57d1363 100644 --- a/test/ELF/gnu-ifunc-nosym.s +++ b/test/ELF/gnu-ifunc-nosym.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: ld.lld -static %t.o -o %tout // RUN: llvm-readobj -symbols %tout | FileCheck %s -// REQUIRES: x86 // Check that no __rela_iplt_end/__rela_iplt_start // appear in symtab if there is no references to them. diff --git a/test/ELF/gnu-ifunc-plt-i386.s b/test/ELF/gnu-ifunc-plt-i386.s index 243eff62fcbf..14369bf6388b 100644 --- a/test/ELF/gnu-ifunc-plt-i386.s +++ b/test/ELF/gnu-ifunc-plt-i386.s @@ -1,3 +1,4 @@ +// 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: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o @@ -5,7 +6,6 @@ // RUN: llvm-objdump -d %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 -// REQUIRES: x86 // Check that the IRELATIVE relocations are after the JUMP_SLOT in the plt // CHECK: Relocations [ @@ -70,7 +70,7 @@ bar: .globl _start _start: - call foo - call bar - call bar2 - call zed2 + call foo@plt + call bar@plt + call bar2@plt + call zed2@plt diff --git a/test/ELF/gnu-ifunc-plt.s b/test/ELF/gnu-ifunc-plt.s index 88a09931853c..b88f32cb7306 100644 --- a/test/ELF/gnu-ifunc-plt.s +++ b/test/ELF/gnu-ifunc-plt.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/shared2-x86-64.s -o %t1.o // RUN: ld.lld %t1.o --shared -o %t.so // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o @@ -5,7 +6,6 @@ // RUN: llvm-objdump -d %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 -// REQUIRES: x86 // Check that the IRELATIVE relocations are after the JUMP_SLOT in the plt // CHECK: Relocations [ diff --git a/test/ELF/gnu-ifunc-relative.s b/test/ELF/gnu-ifunc-relative.s index dc35102c5787..d797301d03ad 100644 --- a/test/ELF/gnu-ifunc-relative.s +++ b/test/ELF/gnu-ifunc-relative.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: ld.lld -static %t.o -o %tout // RUN: llvm-readobj -r -t %tout | FileCheck %s -// REQUIRES: x86 .type foo STT_GNU_IFUNC .globl foo diff --git a/test/ELF/gnu-ifunc.s b/test/ELF/gnu-ifunc.s index 4911da6bce00..faf51b4b6216 100644 --- a/test/ELF/gnu-ifunc.s +++ b/test/ELF/gnu-ifunc.s @@ -1,8 +1,8 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-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-readobj -r -symbols -sections %tout | FileCheck %s -// REQUIRES: x86 // CHECK: Sections [ // CHECK: Section { diff --git a/test/ELF/gnu-unique.s b/test/ELF/gnu-unique.s index afc0da27063d..06f370434cd8 100644 --- a/test/ELF/gnu-unique.s +++ b/test/ELF/gnu-unique.s @@ -3,6 +3,8 @@ // // RUN: ld.lld %t -shared -o %tout.so // RUN: llvm-readobj -dyn-symbols %tout.so | FileCheck -check-prefix=GNU %s +// RUN: ld.lld %t -shared -o %tout.so --gnu-unique +// RUN: llvm-readobj -dyn-symbols %tout.so | FileCheck -check-prefix=GNU %s // // RUN: ld.lld %t -shared -o %tout.so --no-gnu-unique // RUN: llvm-readobj -dyn-symbols %tout.so | FileCheck -check-prefix=NO %s diff --git a/test/ELF/gnustack.s b/test/ELF/gnustack.s index c506fb807c62..3ab6f16ac7bd 100644 --- a/test/ELF/gnustack.s +++ b/test/ELF/gnustack.s @@ -1,10 +1,15 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 + # RUN: ld.lld %t1 -z execstack -o %t # RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=RWX %s + # RUN: ld.lld %t1 -o %t # RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=RW %s +# RUN: ld.lld %t1 -o %t -z noexecstack +# RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=RW %s + # RW: Type: PT_GNU_STACK # RW-NEXT: Offset: 0x0 # RW-NEXT: VirtualAddress: 0x0 diff --git a/test/ELF/got-aarch64.s b/test/ELF/got-aarch64.s index f46946c9f4aa..c9e20276472f 100644 --- a/test/ELF/got-aarch64.s +++ b/test/ELF/got-aarch64.s @@ -1,8 +1,8 @@ +// REQUIRES: aarch64 // RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %t.o // RUN: ld.lld --hash-style=sysv -shared %t.o -o %t.so // RUN: llvm-readobj -s -r %t.so | FileCheck %s // RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=DISASM %s -// REQUIRES: aarch64 // CHECK: Name: .got // CHECK-NEXT: Type: SHT_PROGBITS diff --git a/test/ELF/got-i386.s b/test/ELF/got-i386.s index 679eb2e4f5ca..7fb87e0dadbd 100644 --- a/test/ELF/got-i386.s +++ b/test/ELF/got-i386.s @@ -1,8 +1,8 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o // RUN: ld.lld %t.o -o %t // RUN: llvm-readobj -s -r -t %t | FileCheck %s // RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s -// REQUIRES: x86 // CHECK: Name: .got // CHECK-NEXT: Type: SHT_PROGBITS diff --git a/test/ELF/got-plt-header.s b/test/ELF/got-plt-header.s index a6b10fa3a0a0..f8412e13c41d 100644 --- a/test/ELF/got-plt-header.s +++ b/test/ELF/got-plt-header.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: ld.lld %t.o -o %t.so -shared // RUN: llvm-readobj -s -section-data %t.so | FileCheck %s diff --git a/test/ELF/got.s b/test/ELF/got.s index f67ea13d3f4e..9d2d804454bf 100644 --- a/test/ELF/got.s +++ b/test/ELF/got.s @@ -1,10 +1,10 @@ +// 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 %p/Inputs/shared.s -o %t2.o // RUN: ld.lld -shared %t2.o -o %t2.so // RUN: ld.lld --hash-style=sysv %t.o %t2.so -o %t // RUN: llvm-readobj -s -r %t | FileCheck %s // RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s -// REQUIRES: x86 // CHECK: Name: .got // CHECK-NEXT: Type: SHT_PROGBITS diff --git a/test/ELF/got32-i386-pie-rw.s b/test/ELF/got32-i386-pie-rw.s index 18b019c2cc9d..45d2ec154675 100644 --- a/test/ELF/got32-i386-pie-rw.s +++ b/test/ELF/got32-i386-pie-rw.s @@ -7,8 +7,8 @@ # CHECK: .foobar PROGBITS 00001000 # CHECK: .got PROGBITS [[GOT:[0-9a-z]*]] -# CHECK: [[GOT]] 00000008 R_386_RELATIVE -# CHECK: 00001002 00000008 R_386_RELATIVE +# CHECK-DAG: 00001002 00000008 R_386_RELATIVE +# CHECK-DAG: [[GOT]] 00000008 R_386_RELATIVE foo: .section .foobar, "awx" diff --git a/test/ELF/got32-i386.s b/test/ELF/got32-i386.s index 00c7c0d6d553..dce50d0afc2e 100644 --- a/test/ELF/got32-i386.s +++ b/test/ELF/got32-i386.s @@ -20,4 +20,4 @@ _start: # CHECK: .got 00000004 0000000000012000 # 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 +# 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 diff --git a/test/ELF/got32x-i386.s b/test/ELF/got32x-i386.s index 1311472cc061..610051e8a962 100644 --- a/test/ELF/got32x-i386.s +++ b/test/ELF/got32x-i386.s @@ -33,15 +33,15 @@ ## 73728 == 0x12000 == ADDR(.got) # CHECK: _start: -# CHECK-NEXT: 11001: 8b 05 {{.*}} movl 73728, %eax -# CHECK-NEXT: 11007: 8b 1d {{.*}} movl 73728, %ebx +# CHECK-NEXT: 11001: 8b 05 {{.*}} movl 77824, %eax +# CHECK-NEXT: 11007: 8b 1d {{.*}} movl 77824, %ebx # CHECK-NEXT: 1100d: 8b 80 {{.*}} movl -4(%eax), %eax # CHECK-NEXT: 11013: 8b 83 {{.*}} movl -4(%ebx), %eax # CHECK: Sections: # CHECK: Name Size Address -# CHECK: .got 00000004 0000000000012000 +# CHECK: .got 00000004 0000000000013000 # 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 -# ERR: error: can't create dynamic relocation R_386_GOT32X against symbol: foo in readonly segment; recompile object files with -fPIC +# 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 diff --git a/test/ELF/gotpcrelx.s b/test/ELF/gotpcrelx.s index 3ccbc56aba94..d9a7b8e048c3 100644 --- a/test/ELF/gotpcrelx.s +++ b/test/ELF/gotpcrelx.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -relax-relocations -triple x86_64-pc-linux-gnu \ // RUN: %s -o %t.o // RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=RELS %s diff --git a/test/ELF/help.s b/test/ELF/help.s index 2554531532b3..aca2ceb76ee1 100644 --- a/test/ELF/help.s +++ b/test/ELF/help.s @@ -1,5 +1,5 @@ # RUN: ld.lld --help 2>&1 | FileCheck %s # CHECK: OPTIONS: -# CHECK: --output=<value> Path to file to write output -# CHECK: --output <value> Path to file to write output +# CHECK: --output=<value> Alias for -o +# CHECK: --output <value> Alias for -o # CHECK: -o <path> Path to file to write output diff --git a/test/ELF/hexagon.s b/test/ELF/hexagon.s new file mode 100644 index 000000000000..8c824ea3c78a --- /dev/null +++ b/test/ELF/hexagon.s @@ -0,0 +1,24 @@ +# REQUIRES: hexagon +# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t +# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %S/Inputs/hexagon.s -o %t2 +# RUN: ld.lld %t2 %t -o %t3 +# RUN: llvm-objdump -d %t3 | FileCheck %s + +# R_HEX_B15_PCREL +if (p0) jump:nt #_start +# CHECK: if (p0) jump:nt 0x11000 + +# R_HEX_B32_PCREL_X +# R_HEX_B15_PCREL_X +if (p0) jump:nt ##_start +# CHECK: if (p0) jump:nt 0x11000 + +# R_HEX_B22_PCREL +call #_start +# CHECK: call 0x11000 + +# R_HEX_B32_PCREL_X +# R_HEX_B22_PCREL_X +call ##_start +# CHECK: immext(#4294967232) +# CHECK: call 0x11000 diff --git a/test/ELF/hidden-shared-err.s b/test/ELF/hidden-shared-err.s new file mode 100644 index 000000000000..e6d424c24824 --- /dev/null +++ b/test/ELF/hidden-shared-err.s @@ -0,0 +1,19 @@ +# 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/hidden-shared-err.s -o %t2.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/hidden-shared-err2.s -o %t3.o + +# RUN: ld.lld -shared -o %t2.so %t2.o +# RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld %t2.so %t.o -o %t 2>&1 | FileCheck %s + +# RUN: not ld.lld %t.o %t3.o %t2.so -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld %t3.o %t.o %t2.so -o %t 2>&1 | FileCheck %s + +# CHECK: undefined symbol: foo + +.global _start +_start: +.quad foo +.hidden foo diff --git a/test/ELF/i386-debug-noabs.test b/test/ELF/i386-debug-noabs.test index 712d0a59cecc..dbc7a57f8f7a 100644 --- a/test/ELF/i386-debug-noabs.test +++ b/test/ELF/i386-debug-noabs.test @@ -1,7 +1,7 @@ # REQUIRES: x86 # RUN: yaml2obj %s -o %t.o -# RUN: ld.lld %t.o -o %t.exe +# RUN: ld.lld %t.o -o /dev/null --entry 0 --fatal-warnings ## This is for https://bugs.llvm.org//show_bug.cgi?id=34852. GCC 8.0 or ## earlier have a bug which creates non-absolute R_386_GOTPC relocations diff --git a/test/ELF/i386-got-and-copy.s b/test/ELF/i386-got-and-copy.s index 81bac22fd66a..78788a55f23c 100644 --- a/test/ELF/i386-got-and-copy.s +++ b/test/ELF/i386-got-and-copy.s @@ -15,6 +15,7 @@ # CHECK: Relocations [ # CHECK-NEXT: Section (4) .rel.dyn { # CHECK-NEXT: 0x{{[0-9A-F]+}} R_386_COPY foo +# CHECK-NEXT: 0x{{[0-9A-F]+}} R_386_GLOB_DAT foo # CHECK-NEXT: } # CHECK-NEXT: ] diff --git a/test/ELF/i386-got-value.s b/test/ELF/i386-got-value.s index 8803fcffb312..2d7bd6804d6a 100644 --- a/test/ELF/i386-got-value.s +++ b/test/ELF/i386-got-value.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc %s -o %t.o -filetype=obj -triple=i386-pc-linux # RUN: ld.lld %t.o -o %t.so -shared # RUN: llvm-readobj --relocations --sections --section-data %t.so | FileCheck %s diff --git a/test/ELF/i386-gotpc.s b/test/ELF/i386-gotpc.s index d2c5ef3d469c..af8380b91153 100644 --- a/test/ELF/i386-gotpc.s +++ b/test/ELF/i386-gotpc.s @@ -6,15 +6,23 @@ movl $_GLOBAL_OFFSET_TABLE_, %eax +// CHECK: Name: .got.plt +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: SHF_WRITE +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x2000 + // CHECK: Name: .got // CHECK-NEXT: Type: SHT_PROGBITS // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x2030 +// CHECK-NEXT: Address: 0x3030 // DISASM: Disassembly of section .text: // DISASM-NEXT: .text: -// DISASM-NEXT: 1000: {{.*}} movl $4144, %eax -// 0x2030 - 0x1000 = 4144 +// DISASM-NEXT: 1000: {{.*}} movl $8240, %eax +// 0x3030 - 0x1000 = 0x2030 diff --git a/test/ELF/i386-merge.s b/test/ELF/i386-merge.s index 00c954945a0f..d895c7327000 100644 --- a/test/ELF/i386-merge.s +++ b/test/ELF/i386-merge.s @@ -9,7 +9,7 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_MERGE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x114 +// CHECK-NEXT: Address: 0x158 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: // CHECK-NEXT: Link: @@ -35,11 +35,10 @@ // CHECK-NEXT: AddressAlignment: 1 // CHECK-NEXT: EntrySize: 0 // CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 14010000 | +// CHECK-NEXT: 0000: 58010000 | // CHECK-NEXT: ) -// The content of .data should be the address of .mysec. 14010000 is 0x114 in -// little endian. +// The content of .data should be the address of .mysec. .data .long .mysec+4 diff --git a/test/ELF/i386-pic-plt.s b/test/ELF/i386-pic-plt.s new file mode 100644 index 000000000000..0d32436899a5 --- /dev/null +++ b/test/ELF/i386-pic-plt.s @@ -0,0 +1,12 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %p/Inputs/i386-pic-plt.s -o %t2.o +// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld %t.o %t2.so -o %t +// RUN: not ld.lld %t.o %t2.so -o %t -pie 2>&1 | FileCheck %s + +// CHECK: error: symbol 'foo' cannot be preempted; recompile with -fPIE + +.global _start +_start: + call foo diff --git a/test/ELF/i386-reloc-16-large-addend.s b/test/ELF/i386-reloc-16-large-addend.s new file mode 100644 index 000000000000..ceb4862d7935 --- /dev/null +++ b/test/ELF/i386-reloc-16-large-addend.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t +# RUN: ld.lld -Ttext 0x7c00 %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 7c00 b800ff + +.code16 +.global _start +_start: + movw $_start+0x8300,%ax diff --git a/test/ELF/i386-reloc-16.s b/test/ELF/i386-reloc-16.s index d69e6fbc49a7..9a099a6ba3ed 100644 --- a/test/ELF/i386-reloc-16.s +++ b/test/ELF/i386-reloc-16.s @@ -4,11 +4,12 @@ // RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/x86-64-reloc-16-error.s -o %t2 // RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t // RUN: ld.lld -shared %t %t1 -o %t3 +// RUN: llvm-objdump -s %t3 | FileCheck %s // CHECK: Contents of section .text: -// CHECK-NEXT: 200000 42 +// CHECK-NEXT: 1000 42 -// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s -// ERROR: relocation R_386_16 out of range: 65536 is not in [0, 65535] +// RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s +// ERROR: relocation R_386_16 out of range: 65536 is not in [-32768, 32767] .short foo diff --git a/test/ELF/i386-reloc-8-large-addend.s b/test/ELF/i386-reloc-8-large-addend.s new file mode 100644 index 000000000000..61d638040847 --- /dev/null +++ b/test/ELF/i386-reloc-8-large-addend.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t +# RUN: ld.lld -Ttext 0x7c %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 007c b4ff + +.code16 +.global _start +_start: + movb $_start+0x83,%ah diff --git a/test/ELF/i386-reloc-8.s b/test/ELF/i386-reloc-8.s index c6ae67120e22..b46aaa688261 100644 --- a/test/ELF/i386-reloc-8.s +++ b/test/ELF/i386-reloc-8.s @@ -4,11 +4,12 @@ // RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/i386-reloc-8-error.s -o %t2 // RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t // RUN: ld.lld -shared %t %t1 -o %t3 +// RUN: llvm-objdump -s %t3 | FileCheck %s // CHECK: Contents of section .text: -// CHECK-NEXT: 200000 42 +// CHECK-NEXT: 1000 ff -// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s -// ERROR: relocation R_386_8 out of range: 256 is not in [0, 255] +// RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s +// ERROR: relocation R_386_8 out of range: 256 is not in [-128, 127] .byte foo diff --git a/test/ELF/i386-reloc-range.s b/test/ELF/i386-reloc-range.s index 6f72f7af73c7..4378bb6f9d18 100644 --- a/test/ELF/i386-reloc-range.s +++ b/test/ELF/i386-reloc-range.s @@ -14,7 +14,7 @@ // CHECK-NEXT: 200: {{.*}} jmp -1 // 0x10202 - 0x203 == 0xffff -// RUN: not ld.lld -Ttext 0x200 %t.o %t2.o -o %t2 2>&1 | FileCheck --check-prefix=ERR %s +// RUN: not ld.lld -Ttext 0x200 %t.o %t2.o -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s // ERR: {{.*}}:(.text+0x1): relocation R_386_PC16 out of range: 65536 is not in [-65536, 65535] diff --git a/test/ELF/i386-retpoline-nopic-linkerscript.s b/test/ELF/i386-retpoline-nopic-linkerscript.s new file mode 100644 index 000000000000..4243761d23e4 --- /dev/null +++ b/test/ELF/i386-retpoline-nopic-linkerscript.s @@ -0,0 +1,67 @@ +// 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: echo "SECTIONS { \ +// RUN: .text : { *(.text) } \ +// RUN: .plt : { *(.plt) } \ +// RUN: .got.plt : { *(.got.plt) } \ +// 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 + +// CHECK: Disassembly of section .plt: +// CHECK-NEXT: .plt: +// CHECK-NEXT: 10: ff 35 84 00 00 00 pushl 132 +// CHECK-NEXT: 16: 50 pushl %eax +// CHECK-NEXT: 17: a1 88 00 00 00 movl 136, %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 8c 00 00 00 movl 140, %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 90 00 00 00 movl 144, %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 + +.global _start +_start: + jmp bar@PLT + jmp zed@PLT diff --git a/test/ELF/i386-retpoline-nopic.s b/test/ELF/i386-retpoline-nopic.s new file mode 100644 index 000000000000..79dd5a63cd69 --- /dev/null +++ b/test/ELF/i386-retpoline-nopic.s @@ -0,0 +1,65 @@ +// 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 %t1.o %t2.so -o %t.exe -z retpolineplt +// RUN: llvm-objdump -d -s %t.exe | FileCheck %s + +// CHECK: Disassembly of section .plt: +// CHECK-NEXT: .plt: +// CHECK-NEXT: 11010: ff 35 04 20 01 00 pushl 73732 +// CHECK-NEXT: 11016: 50 pushl %eax +// CHECK-NEXT: 11017: a1 08 20 01 00 movl 73736, %eax +// CHECK-NEXT: 1101c: e8 0f 00 00 00 calll 15 <.plt+0x20> +// CHECK-NEXT: 11021: f3 90 pause +// CHECK-NEXT: 11023: 0f ae e8 lfence +// CHECK-NEXT: 11026: eb f9 jmp -7 <.plt+0x11> +// CHECK-NEXT: 11028: cc int3 +// CHECK-NEXT: 11029: cc int3 +// CHECK-NEXT: 1102a: cc int3 +// CHECK-NEXT: 1102b: cc int3 +// CHECK-NEXT: 1102c: cc int3 +// CHECK-NEXT: 1102d: cc int3 +// CHECK-NEXT: 1102e: cc int3 +// CHECK-NEXT: 1102f: cc int3 +// CHECK-NEXT: 11030: 89 0c 24 movl %ecx, (%esp) +// CHECK-NEXT: 11033: 8b 4c 24 04 movl 4(%esp), %ecx +// CHECK-NEXT: 11037: 89 44 24 04 movl %eax, 4(%esp) +// CHECK-NEXT: 1103b: 89 c8 movl %ecx, %eax +// CHECK-NEXT: 1103d: 59 popl %ecx +// CHECK-NEXT: 1103e: c3 retl +// CHECK-NEXT: 1103f: cc int3 +// CHECK-NEXT: 11040: 50 pushl %eax +// CHECK-NEXT: 11041: a1 0c 20 01 00 movl 73740, %eax +// CHECK-NEXT: 11046: e8 e5 ff ff ff calll -27 <.plt+0x20> +// CHECK-NEXT: 1104b: e9 d1 ff ff ff jmp -47 <.plt+0x11> +// CHECK-NEXT: 11050: 68 00 00 00 00 pushl $0 +// CHECK-NEXT: 11055: e9 b6 ff ff ff jmp -74 <.plt> +// CHECK-NEXT: 1105a: cc int3 +// CHECK-NEXT: 1105b: cc int3 +// CHECK-NEXT: 1105c: cc int3 +// CHECK-NEXT: 1105d: cc int3 +// CHECK-NEXT: 1105e: cc int3 +// CHECK-NEXT: 1105f: cc int3 +// CHECK-NEXT: 11060: 50 pushl %eax +// CHECK-NEXT: 11061: a1 10 20 01 00 movl 73744, %eax +// CHECK-NEXT: 11066: e8 c5 ff ff ff calll -59 <.plt+0x20> +// CHECK-NEXT: 1106b: e9 b1 ff ff ff jmp -79 <.plt+0x11> +// CHECK-NEXT: 11070: 68 08 00 00 00 pushl $8 +// CHECK-NEXT: 11075: e9 96 ff ff ff jmp -106 <.plt> +// CHECK-NEXT: 1107a: cc int3 +// CHECK-NEXT: 1107b: cc int3 +// CHECK-NEXT: 1107c: cc int3 +// CHECK-NEXT: 1107d: cc int3 +// CHECK-NEXT: 1107e: cc int3 +// CHECK-NEXT: 1107f: cc int3 + +// CHECK: Contents of section .got.plt: +// CHECK-NEXT: 00300100 00000000 00000000 50100100 +// CHECK-NEXT: 70100100 + +.global _start +_start: + jmp bar@PLT + jmp zed@PLT diff --git a/test/ELF/i386-retpoline-pic-linkerscript.s b/test/ELF/i386-retpoline-pic-linkerscript.s new file mode 100644 index 000000000000..6220332f91d1 --- /dev/null +++ b/test/ELF/i386-retpoline-pic-linkerscript.s @@ -0,0 +1,64 @@ +// 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: echo "SECTIONS { \ +// RUN: .text : { *(.text) } \ +// RUN: .plt : { *(.plt) } \ +// RUN: .got.plt : { *(.got.plt) } \ +// RUN: .dynstr : { *(.dynstr) } \ +// RUN: }" > %t.script +// RUN: ld.lld %t1.o %t2.so -o %t.exe -z retpolineplt -pie --script %t.script +// RUN: llvm-objdump -d -s %t.exe | FileCheck %s + +// CHECK: Disassembly of section .plt: +// CHECK-NEXT: .plt: +// CHECK-NEXT: 10: ff b3 84 00 00 00 pushl 132(%ebx) +// CHECK-NEXT: 16: 50 pushl %eax +// CHECK-NEXT: 17: 8b 83 88 00 00 00 movl 136(%ebx), %eax +// CHECK-NEXT: 1d: e8 0e 00 00 00 calll 14 <.plt+0x20> +// CHECK-NEXT: 22: f3 90 pause +// CHECK-NEXT: 24: 0f ae e8 lfence +// CHECK-NEXT: 27: eb f9 jmp -7 <.plt+0x12> +// 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: 8b 83 8c 00 00 00 movl 140(%ebx), %eax +// CHECK-NEXT: 47: e8 e4 ff ff ff calll -28 <.plt+0x20> +// CHECK-NEXT: 4c: e9 d1 ff ff ff jmp -47 <.plt+0x12> +// CHECK-NEXT: 51: 68 00 00 00 00 pushl $0 +// CHECK-NEXT: 56: e9 b5 ff ff ff jmp -75 <.plt> +// 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: 8b 83 90 00 00 00 movl 144(%ebx), %eax +// CHECK-NEXT: 67: e8 c4 ff ff ff calll -60 <.plt+0x20> +// CHECK-NEXT: 6c: e9 b1 ff ff ff jmp -79 <.plt+0x12> +// CHECK-NEXT: 71: 68 08 00 00 00 pushl $8 +// CHECK-NEXT: 76: e9 95 ff ff ff jmp -107 <.plt> +// 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 + +.global _start +_start: + jmp bar@PLT + jmp zed@PLT diff --git a/test/ELF/i386-retpoline-pic.s b/test/ELF/i386-retpoline-pic.s new file mode 100644 index 000000000000..3555950b168a --- /dev/null +++ b/test/ELF/i386-retpoline-pic.s @@ -0,0 +1,62 @@ +// 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 %t1.o %t2.so -o %t.exe -z retpolineplt -pie +// RUN: llvm-objdump -d -s %t.exe | FileCheck %s + +// CHECK: Disassembly of section .plt: +// CHECK-NEXT: .plt: +// CHECK-NEXT: 1010: ff b3 04 20 00 00 pushl 8196(%ebx) +// CHECK-NEXT: 1016: 50 pushl %eax +// CHECK-NEXT: 1017: 8b 83 08 20 00 00 movl 8200(%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 20 00 00 movl 8204(%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 20 00 00 movl 8208(%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: Contents of section .got.plt: +// CHECK-NEXT: 2000 00300000 00000000 00000000 51100000 +// CHECK-NEXT: 2010 71100000 + +.global _start +_start: + jmp bar@PLT + jmp zed@PLT diff --git a/test/ELF/i386-tls-got.s b/test/ELF/i386-tls-got.s index 56be4a138d9b..efd45152164f 100644 --- a/test/ELF/i386-tls-got.s +++ b/test/ELF/i386-tls-got.s @@ -2,6 +2,6 @@ # RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/i386-tls-got.s -o %t1.o # RUN: ld.lld %t1.o -o %t1.so -shared # RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t2.o -# RUN: ld.lld %t2.o %t1.so -o %t +# RUN: ld.lld %t2.o %t1.so -o /dev/null addl foobar@INDNTPOFF, %eax diff --git a/test/ELF/i386-tls-ie-shared.s b/test/ELF/i386-tls-ie-shared.s index 2b842a86eb0f..9e5ed1bcc462 100644 --- a/test/ELF/i386-tls-ie-shared.s +++ b/test/ELF/i386-tls-ie-shared.s @@ -1,3 +1,4 @@ +// 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 diff --git a/test/ELF/icf-absolute.s b/test/ELF/icf-absolute.s index 09f6790907a1..3eef7a2d7e28 100644 --- a/test/ELF/icf-absolute.s +++ b/test/ELF/icf-absolute.s @@ -2,10 +2,10 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-absolute.s -o %t2 -# RUN: ld.lld %t %t2 -o %t3 --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t %t2 -o /dev/null --icf=all --print-icf-sections | FileCheck %s -# CHECK: selected .text.f1 -# CHECK: removed .text.f2 +# CHECK: selected section {{.*}}:(.text.f1) +# CHECK: removing identical section {{.*}}:(.text.f2) .globl _start, f1, f2 _start: diff --git a/test/ELF/icf-c-identifier.s b/test/ELF/icf-c-identifier.s new file mode 100644 index 000000000000..cd11b98b57a6 --- /dev/null +++ b/test/ELF/icf-c-identifier.s @@ -0,0 +1,9 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld %t -o /dev/null --icf=all --print-icf-sections | count 0 + +.section foo,"ax",@progbits,unique,0 +.byte 42 + +.section foo,"ax",@progbits,unique,1 +.byte 42 diff --git a/test/ELF/icf-comdat.s b/test/ELF/icf-comdat.s index aab6a00f484d..761dd2ecdc96 100644 --- a/test/ELF/icf-comdat.s +++ b/test/ELF/icf-comdat.s @@ -1,10 +1,10 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t -o /dev/null --icf=all --print-icf-sections | FileCheck %s -# CHECK: selected .text.f1 -# CHECK: removed .text.f2 +# CHECK: selected section {{.*}}:(.text.f1) +# CHECK: removing identical section {{.*}}:(.text.f2) .globl _start, f1, f2 _start: diff --git a/test/ELF/icf-different-output-sections.s b/test/ELF/icf-different-output-sections.s new file mode 100644 index 000000000000..085573120e4e --- /dev/null +++ b/test/ELF/icf-different-output-sections.s @@ -0,0 +1,9 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld %t -o /dev/null --icf=all --print-icf-sections | count 0 + +.section .foo,"ax" +.byte 42 + +.section .bar,"ax" +.byte 42 diff --git a/test/ELF/icf-i386.s b/test/ELF/icf-i386.s index b01e0503d405..67c7262dadde 100644 --- a/test/ELF/icf-i386.s +++ b/test/ELF/icf-i386.s @@ -2,11 +2,11 @@ # This test is to make sure that we can handle implicit addends properly. # RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck %s -# CHECK: selected .text.f1 -# CHECK: removed .text.f2 -# CHECK-NOT: removed .text.f3 +# CHECK: selected section {{.*}}:(.text.f1) +# CHECK: removing identical section {{.*}}:(.text.f2) +# CHECK-NOT: removing identical section {{.*}}:(.text.f3) .globl _start, f1, f2, f3 _start: diff --git a/test/ELF/icf-keep-unique.s b/test/ELF/icf-keep-unique.s new file mode 100644 index 000000000000..a6f883fc7b2a --- /dev/null +++ b/test/ELF/icf-keep-unique.s @@ -0,0 +1,43 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld %t -o %t2 --icf=all --print-icf-sections | FileCheck %s +# RUN: ld.lld %t -o %t2 --keep-unique f2 --keep-unique f4 --keep-unique f5 --icf=all --print-icf-sections 2>&1 | FileCheck %s -check-prefix=CHECK-KEEP + +// Base case, expect only .text.f1 to be kept +// CHECK: selected section {{.*}}:(.text.f1) +// CHECK-NEXT: removing identical section {{.*}}:(.text.f2) +// CHECK-NEXT: removing identical section {{.*}}:(.text.f3) +// CHECK-NEXT: removing identical section {{.*}}:(.text.f4) +// CHECK-NEXT: removing identical section {{.*}}:(.text.f5) + +// With --keep-unique f2, f4 and f5 we expect only f3 and f5 to be removed. +// f5 is not matched by --keep-unique as it is a local symbol. +// CHECK-KEEP: warning: could not find symbol f5 to keep unique +// CHECK-KEEP: selected section {{.*}}:(.text.f1) +// CHECK-KEEP-NEXT: removing identical section {{.*}}:(.text.f3) +// CHECK-KEEP-NEXT: removing identical section {{.*}}:(.text.f5) + .globl _start, f1, f2, f3, f4 +_start: + ret + + .section .text.f1, "ax" +f1: + nop + + .section .text.f2, "ax" +f2: + nop + +.section .text.f3, "ax" +f3: + nop + +.section .text.f4, "ax" +f4: + nop + +# f5 is local, not found by --keep-unique f5 +.section .text.f5, "ax" +f5: + nop diff --git a/test/ELF/icf-link-order.s b/test/ELF/icf-link-order.s new file mode 100644 index 000000000000..440971de0f03 --- /dev/null +++ b/test/ELF/icf-link-order.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t --icf=all --print-icf-sections | count 0 + +.section .foo,"a",@progbits,unique,1 +foo1: +.byte 1 + +.section .foo,"a",@progbits,unique,2 +foo2: +.byte 2 + +.section .bar,"ao",@progbits,foo1,unique,1 +.byte 3 + +.section .bar,"ao",@progbits,foo2,unique,2 +.byte 3 diff --git a/test/ELF/icf-many-sections.s b/test/ELF/icf-many-sections.s new file mode 100644 index 000000000000..766a003dd77d --- /dev/null +++ b/test/ELF/icf-many-sections.s @@ -0,0 +1,62 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t +# RUN: ld.lld --icf=all --print-icf-sections %t -o /dev/null | FileCheck %s -allow-empty + +# CHECK-NOT: selected + +.macro gen_sections4 z + .section .a\z,"ax" + .section .b\z,"ax" + .section .c\z,"ax" + .section .d\z,"ax" +.endm + +.macro gen_sections8 z + gen_sections4 a\z + gen_sections4 b\z +.endm + +.macro gen_sections16 z + gen_sections8 a\z + gen_sections8 b\z +.endm + +.macro gen_sections32 x + gen_sections16 a\x + gen_sections16 b\x +.endm + +.macro gen_sections64 z + gen_sections32 a\z + gen_sections32 b\z +.endm + +.macro gen_sections128 z + gen_sections64 a\z + gen_sections64 b\z +.endm + +.macro gen_sections256 z + gen_sections128 a\z + gen_sections128 b\z +.endm + +.macro gen_sections512 z + gen_sections256 a\z + gen_sections256 b\z +.endm + +.macro gen_sections1024 z + gen_sections512 a\z + gen_sections512 b\z +.endm + +.macro gen_sections2048 z + gen_sections1024 a\z + gen_sections1024 b\z +.endm + +gen_sections2048 a + +.global _start +_start: diff --git a/test/ELF/icf-merge-sec.s b/test/ELF/icf-merge-sec.s index 1e866a0caa49..060f19d34694 100644 --- a/test/ELF/icf-merge-sec.s +++ b/test/ELF/icf-merge-sec.s @@ -2,10 +2,10 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-merge-sec.s -o %t2 -# RUN: ld.lld %t %t2 -o %t3 --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t %t2 -o /dev/null --icf=all --print-icf-sections | FileCheck %s -# CHECK: selected .text.f1 -# CHECK: removed .text.f2 +# CHECK: selected section {{.*}}:(.text.f1) +# CHECK: removing identical section {{.*}}:(.text.f2) .section .rodata.str,"aMS",@progbits,1 .asciz "foo" diff --git a/test/ELF/icf-merge.s b/test/ELF/icf-merge.s index 06e852fe9dd5..5aa79f9d14ec 100644 --- a/test/ELF/icf-merge.s +++ b/test/ELF/icf-merge.s @@ -2,18 +2,18 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-merge.s -o %t1 -# RUN: ld.lld %t %t1 -o %t1.out --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t %t1 -o /dev/null --icf=all --print-icf-sections | FileCheck %s # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-merge2.s -o %t2 -# RUN: ld.lld %t %t2 -o %t3.out --icf=all --verbose 2>&1 | FileCheck --check-prefix=NOMERGE %s +# RUN: ld.lld %t %t2 -o %t3.out --icf=all --print-icf-sections | FileCheck --check-prefix=NOMERGE %s # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-merge3.s -o %t3 -# RUN: ld.lld %t %t3 -o %t3.out --icf=all --verbose 2>&1 | FileCheck --check-prefix=NOMERGE %s +# RUN: ld.lld %t %t3 -o %t3.out --icf=all --print-icf-sections | FileCheck --check-prefix=NOMERGE %s -# CHECK: selected .text.f1 -# CHECK: removed .text.f2 +# CHECK: selected section {{.*}}:(.text.f1) +# CHECK: removing identical section {{.*}}:(.text.f2) -# NOMERGE-NOT: selected .text.f +# NOMERGE-NOT: selected section {{.*}}:(.text.f) .section .rodata.str,"aMS",@progbits,1 foo: diff --git a/test/ELF/icf-merge2.s b/test/ELF/icf-merge2.s new file mode 100644 index 000000000000..47c4c88d449a --- /dev/null +++ b/test/ELF/icf-merge2.s @@ -0,0 +1,23 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t --icf=all +# RUN: llvm-objdump -d %t | FileCheck %s + +# Test that we don't merge these. +# CHECK: leaq +# CHECK: leaq + + .section .merge1, "aM", @progbits, 8 +.Lfoo: + .quad 42 + + .section .merge2, "aM", @progbits, 4 +.Lbar: + .long 41 + + .section .text.foo, "ax", @progbits + leaq .Lfoo(%rip), %rax + + .section .text.bar, "ax", @progbits + leaq .Lbar(%rip), %rax diff --git a/test/ELF/icf-merged-sections.s b/test/ELF/icf-merged-sections.s new file mode 100644 index 000000000000..1f6e77ec5353 --- /dev/null +++ b/test/ELF/icf-merged-sections.s @@ -0,0 +1,37 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t --icf=all --ignore-data-address-equality --print-icf-sections | FileCheck -allow-empty --check-prefix=NOICF %s +# RUN: llvm-readobj -s -section-data %t | FileCheck %s + +# Check that merge synthetic sections are not merged by ICF. + +# NOICF-NOT: selected section <internal>:(.rodata) + +# CHECK: Name: .rodata +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 16 +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: 8 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 67452301 10325476 67452301 10325476 + +.section .rodata.cst4,"aM",@progbits,4 +rodata4: + .long 0x01234567 + .long 0x76543210 + .long 0x01234567 + .long 0x76543210 + +.section .rodata.cst8,"aM",@progbits,8 +rodata8: + .long 0x01234567 + .long 0x76543210 diff --git a/test/ELF/icf-non-mergeable.s b/test/ELF/icf-non-mergeable.s index 48ba2008cacc..978ac156b70e 100644 --- a/test/ELF/icf-non-mergeable.s +++ b/test/ELF/icf-non-mergeable.s @@ -8,10 +8,10 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ // RUN: %p/Inputs/icf-non-mergeable.s -o %t2 -// RUN: ld.lld %t1 %t2 -o %t3 --icf=all --verbose 2>&1 | FileCheck %s +// RUN: ld.lld %t1 %t2 -o /dev/null --icf=all --verbose 2>&1 | FileCheck %s -// CHECK-NOT: selected .text.f1 -// CHECK-NOT: removed .text.f2 +// CHECK-NOT: selected section '.text.f1' +// CHECK-NOT: removing identical section '.text.f2' .globl _start, f1, f2, d1, d2 _start: diff --git a/test/ELF/icf-none.s b/test/ELF/icf-none.s index 9ec1406de8a4..7c73361c2ce3 100644 --- a/test/ELF/icf-none.s +++ b/test/ELF/icf-none.s @@ -1,9 +1,9 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 --icf=all --icf=none --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t -o /dev/null --icf=all --icf=none --verbose 2>&1 | FileCheck %s -# CHECK-NOT: selected .text.f1 +# CHECK-NOT: selected section '.text.f1' .globl _start, f1, f2 _start: diff --git a/test/ELF/icf-relro.s b/test/ELF/icf-relro.s new file mode 100644 index 000000000000..874fa7b19f97 --- /dev/null +++ b/test/ELF/icf-relro.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld %t -o /dev/null --icf=all --ignore-data-address-equality --print-icf-sections | FileCheck %s + +# CHECK: selected section {{.*}}:(.data.rel.ro) +# CHECK: removing identical section {{.*}}:(.data.rel.ro.foo) + +.section .data.rel.ro,"aw" +.quad foo + +.section .data.rel.ro.foo,"aw" +foo: +.quad foo diff --git a/test/ELF/icf-safe.s b/test/ELF/icf-safe.s new file mode 100644 index 000000000000..b001fcc82ce4 --- /dev/null +++ b/test/ELF/icf-safe.s @@ -0,0 +1,182 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: llvm-objcopy %t1.o %t1copy.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-safe.s -o %t2.o +# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=safe --print-icf-sections | FileCheck %s +# RUN: ld.lld %t1.o %t2.o -o %t3 --icf=safe --print-icf-sections -shared | FileCheck --check-prefix=EXPORT %s +# RUN: ld.lld %t1.o %t2.o -o %t3 --icf=safe --print-icf-sections --export-dynamic | FileCheck --check-prefix=EXPORT %s +# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections | FileCheck --check-prefix=ALL %s +# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections --export-dynamic | FileCheck --check-prefix=ALL-EXPORT %s +# RUN: ld.lld %t1copy.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=OBJCOPY %s + +# CHECK-NOT: selected section {{.*}}:(.rodata.l1) +# CHECK: selected section {{.*}}:(.rodata.l3) +# CHECK: removing identical section {{.*}}:(.rodata.l4) + +# CHECK-NOT: selected section {{.*}}:(.text.f1) +# CHECK: selected section {{.*}}:(.text.f3) +# CHECK: removing identical section {{.*}}:(.text.f4) + +# CHECK-NOT: selected section {{.*}}:(.rodata.h1) +# CHECK: selected section {{.*}}:(.rodata.h3) +# CHECK: removing identical section {{.*}}:(.rodata.h4) + +# CHECK-NOT: selected section {{.*}}:(.rodata.g1) +# CHECK: selected section {{.*}}:(.rodata.g3) +# CHECK: removing identical section {{.*}}:(.rodata.g4) + +# CHECK-NOT: selected section {{.*}}:(.text.non_addrsig{{.}}) + +# With --icf=all address-significance implies keep-unique only for rodata, not +# text. +# ALL-NOT: selected section {{.*}}:(.rodata.l1) +# ALL: selected section {{.*}}:(.rodata.l3) +# ALL: removing identical section {{.*}}:(.rodata.l4) + +# ALL: selected section {{.*}}:(.text.f3) +# ALL: removing identical section {{.*}}:(.text.f4) + +# ALL: selected section {{.*}}:(.text.f1) +# ALL: removing identical section {{.*}}:(.text.f2) +# ALL: removing identical section {{.*}}:(.text.non_addrsig1) +# ALL: removing identical section {{.*}}:(.text.non_addrsig2) + +# ALL-NOT: selected section {{.*}}:(.rodata.h1) +# ALL: selected section {{.*}}:(.rodata.h3) +# ALL: removing identical section {{.*}}:(.rodata.h4) + +# ALL-NOT: selected section {{.*}}:(.rodata.g1) +# ALL: selected section {{.*}}:(.rodata.g3) +# ALL: removing identical section {{.*}}:(.rodata.g4) + +# llvm-mc normally emits an empty .text section into every object file. Since +# nothing actually refers to it via a relocation, it doesn't have any associated +# symbols (thus nor can anything refer to it via a relocation, making it safe to +# merge with the empty section in the other input file). Here we check that the +# only two sections merged are the two empty sections and the sections with only +# STB_LOCAL or STV_HIDDEN symbols. The dynsym entries should have prevented +# anything else from being merged. +# EXPORT-NOT: selected section +# EXPORT: selected section {{.*}}:(.rodata.l3) +# EXPORT: removing identical section {{.*}}:(.rodata.l4) +# EXPORT-NOT: selected section +# EXPORT: selected section {{.*}}:(.rodata.h3) +# EXPORT: removing identical section {{.*}}:(.rodata.h4) +# EXPORT-NOT: selected section +# EXPORT: selected section {{.*}}:(.text) +# EXPORT: removing identical section {{.*}}:(.text) +# EXPORT-NOT: selected section + +# If --icf=all is specified when exporting we can also merge the exported text +# sections, but not the exported rodata. +# ALL-EXPORT-NOT: selected section +# ALL-EXPORT: selected section {{.*}}:(.rodata.l3) +# ALL-EXPORT: removing identical section {{.*}}:(.rodata.l4) +# ALL-EXPORT-NOT: selected section +# ALL-EXPORT: selected section {{.*}}:(.text.f3) +# ALL-EXPORT: removing identical section {{.*}}:(.text.f4) +# ALL-EXPORT-NOT: selected section +# ALL-EXPORT: selected section {{.*}}:(.text.f1) +# ALL-EXPORT: removing identical section {{.*}}:(.text.f2) +# ALL-EXPORT: removing identical section {{.*}}:(.text.non_addrsig1) +# ALL-EXPORT: removing identical section {{.*}}:(.text.non_addrsig2) +# ALL-EXPORT-NOT: selected section +# ALL-EXPORT: selected section {{.*}}:(.rodata.h3) +# ALL-EXPORT: removing identical section {{.*}}:(.rodata.h4) +# ALL-EXPORT-NOT: selected section +# ALL-EXPORT: selected section {{.*}}:(.text) +# ALL-EXPORT: removing identical section {{.*}}:(.text) +# ALL-EXPORT-NOT: selected section + +# OBJCOPY: --icf=safe is incompatible with object files created using objcopy or ld -r + +.section .text.f1,"ax",@progbits +.globl f1 +f1: +ret + +.section .text.f2,"ax",@progbits +.globl f2 +f2: +ret + +.section .text.f3,"ax",@progbits +.globl f3 +f3: +ud2 + +.section .text.f4,"ax",@progbits +.globl f4 +f4: +ud2 + +.section .rodata.g1,"a",@progbits +.globl g1 +g1: +.byte 1 + +.section .rodata.g2,"a",@progbits +.globl g2 +g2: +.byte 1 + +.section .rodata.g3,"a",@progbits +.globl g3 +g3: +.byte 2 + +.section .rodata.g4,"a",@progbits +.globl g4 +g4: +.byte 2 + +.section .rodata.l1,"a",@progbits +l1: +.byte 3 + +.section .rodata.l2,"a",@progbits +l2: +.byte 3 + +.section .rodata.l3,"a",@progbits +l3: +.byte 4 + +.section .rodata.l4,"a",@progbits +l4: +.byte 4 + +.section .rodata.h1,"a",@progbits +.globl h1 +.hidden h1 +h1: +.byte 5 + +.section .rodata.h2,"a",@progbits +.globl h2 +.hidden h2 +h2: +.byte 5 + +.section .rodata.h3,"a",@progbits +.globl h3 +.hidden h3 +h3: +.byte 6 + +.section .rodata.h4,"a",@progbits +.globl h4 +.hidden h4 +h4: +.byte 6 + +.addrsig +.addrsig_sym f1 +.addrsig_sym f2 +.addrsig_sym g1 +.addrsig_sym g2 +.addrsig_sym l1 +.addrsig_sym l2 +.addrsig_sym h1 +.addrsig_sym h2 diff --git a/test/ELF/icf1.s b/test/ELF/icf1.s index e2562b5a83e7..5c6e667d53c7 100644 --- a/test/ELF/icf1.s +++ b/test/ELF/icf1.s @@ -1,10 +1,10 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t -o /dev/null --icf=all --print-icf-sections | FileCheck %s -# CHECK: selected .text.f1 -# CHECK: removed .text.f2 +# CHECK: selected section {{.*}}:(.text.f1) +# CHECK: removing identical section {{.*}}:(.text.f2) .globl _start, f1, f2 _start: diff --git a/test/ELF/icf10.test b/test/ELF/icf10.test new file mode 100644 index 000000000000..96b4caf2f2e5 --- /dev/null +++ b/test/ELF/icf10.test @@ -0,0 +1,40 @@ +# RUN: yaml2obj %s -o %t.o +# RUN: ld.lld --icf=all %t.o -o /dev/null --print-icf-sections 2>&1 | FileCheck %s + +# Checks that ICF does not merge 2 sections the offset of +# the relocations of which differ. + +# CHECK-NOT: selected + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_FREEBSD + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text.foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR] + Content: "FFFFFFFFFFFFFFFF" + - Name: .text.bar + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR] + Content: "FFFFFFFFFFFFFFFF" + - Name: .rela.text.foo + Type: SHT_RELA + Link: .symtab + Info: .text.foo + Relocations: + - Offset: 0x0000000000000000 + Symbol: '' + Type: R_X86_64_NONE + - Name: .rela.text.bar + Type: SHT_RELA + Link: .symtab + Info: .text.bar + Relocations: + - Offset: 0x0000000000000001 + Symbol: '' + Type: R_X86_64_NONE diff --git a/test/ELF/icf11.test b/test/ELF/icf11.test new file mode 100644 index 000000000000..8c3aa93568d7 --- /dev/null +++ b/test/ELF/icf11.test @@ -0,0 +1,52 @@ +# RUN: yaml2obj %s -o %t.o +# RUN: ld.lld --icf=all %t.o -o /dev/null --print-icf-sections 2>&1 | FileCheck %s + +# Checks that ICF does not merge 2 sections the type of +# the relocations of which differ. + +# CHECK-NOT: selected + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_FREEBSD + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Type: SHT_PROGBITS + Name: .text + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: "0000000000000000" + - Name: .text.foo + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR] + Content: "FFFFFFFFFFFFFFFF" + - Name: .text.bar + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR] + Content: "FFFFFFFFFFFFFFFF" + - Name: .rela.text.foo + Type: SHT_RELA + Link: .symtab + Info: .text.foo + Relocations: + - Offset: 0x0000000000000000 + Symbol: '' + Type: R_X86_64_NONE + - Name: .rela.text.bar + Type: SHT_RELA + Link: .symtab + Info: .text.bar + Relocations: + - Offset: 0 + Symbol: zed + Type: R_X86_64_64 +Symbols: + Global: + - Name: zed + Type: STT_FUNC + Section: .text + Value: 0x0 + Size: 8 diff --git a/test/ELF/icf12.s b/test/ELF/icf12.s new file mode 100644 index 000000000000..aa1e8af9ebd6 --- /dev/null +++ b/test/ELF/icf12.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 +# RUN: ld.lld %t1 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s + +# Check that ICF does not merge 2 sections which relocations +# differs in addend only. + +# CHECK-NOT: selected + +.section .text +.globl _start +_start: + ret + +.section .text.foo, "ax" +.quad _start + 1 + +.section .text.bar, "ax" +.quad _start + 2 diff --git a/test/ELF/icf13.s b/test/ELF/icf13.s new file mode 100644 index 000000000000..2fe707f11c76 --- /dev/null +++ b/test/ELF/icf13.s @@ -0,0 +1,20 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 +# RUN: ld.lld -shared -z notext %t1 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s + +## Check that ICF does not merge sections which relocations point to symbols +## that are not of the regular defined kind. + +# CHECK-NOT: selected + +.globl und + +.section .text +.globl _start +_start: + ret + +.section .text.foo, "ax" +.quad _start + +.section .text.bar, "ax" +.quad und diff --git a/test/ELF/icf14.s b/test/ELF/icf14.s new file mode 100644 index 000000000000..caa33e4d14bc --- /dev/null +++ b/test/ELF/icf14.s @@ -0,0 +1,26 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 +# RUN: ld.lld %t1 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s + +# Check that ICF does not merge 2 sections which relocations +# refer to symbols that live in sections of the different types +# (regular input section and mergeable input sections in this case). + +# CHECK-NOT: selected + +.section .text +.globl _start +_start: + ret + +.section .rodata.str,"aMS",@progbits,1 +.globl rodata +rodata: +.asciz "foo" + +.section .text.foo, "ax" +.quad rodata + +.section .text.bar, "ax" +.quad _start diff --git a/test/ELF/icf15.s b/test/ELF/icf15.s new file mode 100644 index 000000000000..57c1735e1518 --- /dev/null +++ b/test/ELF/icf15.s @@ -0,0 +1,23 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 +# RUN: ld.lld %t1 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s + +## Check that ICF does not merge sections which relocations have equal addends, +## but different target values. + +# CHECK-NOT: selected + +.globl und + +.section .text +.globl foo +foo: + .byte 0 +.globl bar +bar: + .byte 0 + +.section .text.foo, "ax" +.quad foo + +.section .text.bar, "ax" +.quad bar diff --git a/test/ELF/icf16.s b/test/ELF/icf16.s new file mode 100644 index 000000000000..e7650af37c3b --- /dev/null +++ b/test/ELF/icf16.s @@ -0,0 +1,23 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 +# RUN: ld.lld -shared -z notext %t1 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s + +## ICF is able to merge sections which relocations referring regular input sections +## or mergeable sections. .eh_frame is represented with a different kind of section, +## here we check that ICF code is able to handle and will not merge sections which +## relocations referring .eh_frame. + +# CHECK-NOT: selected + +.section ".eh_frame", "a", @progbits +.globl foo +foo: + .quad 0 +.globl bar +bar: + .quad 0 + +.section .text.foo, "ax" +.quad foo + +.section .text.bar, "ax" +.quad bar diff --git a/test/ELF/icf2.s b/test/ELF/icf2.s index fd0a311cbd1d..8a456c7ee018 100644 --- a/test/ELF/icf2.s +++ b/test/ELF/icf2.s @@ -2,10 +2,10 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/icf2.s -o %t2 -# RUN: ld.lld %t1 %t2 -o %t --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t1 %t2 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck %s -# CHECK: selected .text.f1 -# CHECK: removed .text.f2 +# CHECK: selected section {{.*}}:(.text.f1) +# CHECK: removing identical section {{.*}}:(.text.f2) .globl _start, f1, f2 _start: diff --git a/test/ELF/icf3.s b/test/ELF/icf3.s index 40067cefb200..7ae4acfb131c 100644 --- a/test/ELF/icf3.s +++ b/test/ELF/icf3.s @@ -2,10 +2,10 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/icf2.s -o %t2 -# RUN: ld.lld %t1 %t2 -o %t --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t1 %t2 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s -# CHECK-NOT: Selected .text.f1 -# CHECK-NOT: Selected .text.f2 +# CHECK-NOT: selected section '.text.f1' from file +# CHECK-NOT: selected section '.text.f2' from file .globl _start, f1, f2 _start: diff --git a/test/ELF/icf4.s b/test/ELF/icf4.s index b7f40e805733..2b047968181c 100644 --- a/test/ELF/icf4.s +++ b/test/ELF/icf4.s @@ -1,10 +1,10 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s -# CHECK-NOT: Selected .text.f1 -# CHECK-NOT: Selected .text.f2 +# CHECK-NOT: selected section '.text.f1' +# CHECK-NOT: selected section '.text.f2' .globl _start, f1, f2 _start: diff --git a/test/ELF/icf5.s b/test/ELF/icf5.s index 749cc5e923a0..86c0bc4b9e40 100644 --- a/test/ELF/icf5.s +++ b/test/ELF/icf5.s @@ -1,10 +1,10 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s -# CHECK-NOT: Selected .text.f1 -# CHECK-NOT: Selected .text.f2 +# CHECK-NOT: selected section '.text.f1' +# CHECK-NOT: selected section '.text.f2' .globl _start, f1, f2 _start: diff --git a/test/ELF/icf6.s b/test/ELF/icf6.s index 6420868523bf..0819d51f1844 100644 --- a/test/ELF/icf6.s +++ b/test/ELF/icf6.s @@ -1,10 +1,10 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s -# CHECK-NOT: Selected .text.f1 -# CHECK-NOT: Selected .text.f2 +# CHECK-NOT: selected section '.text.f1' +# CHECK-NOT: selected section '.text.f2' .globl _start, f1, f2 _start: diff --git a/test/ELF/icf7.s b/test/ELF/icf7.s index 00fca793aeea..00383adbc0eb 100644 --- a/test/ELF/icf7.s +++ b/test/ELF/icf7.s @@ -1,11 +1,11 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t -o %t2 --icf=all --print-icf-sections | FileCheck %s # RUN: llvm-objdump -t %t2 | FileCheck -check-prefix=ALIGN %s -# CHECK: selected .text.f1 -# CHECK: removed .text.f2 +# CHECK: selected section {{.*}}:(.text.f1) +# CHECK: removing identical section {{.*}}:(.text.f2) # ALIGN: 0000000000201000 .text 00000000 _start # ALIGN: 0000000000201100 .text 00000000 f1 diff --git a/test/ELF/icf9.s b/test/ELF/icf9.s index de6db60f9684..809267700497 100644 --- a/test/ELF/icf9.s +++ b/test/ELF/icf9.s @@ -2,20 +2,21 @@ ### Make sure that we do not merge data. # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 --icf=all --verbose 2>&1 | FileCheck %s +# RUN: ld.lld %t -o %t2 --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s # RUN: llvm-readelf -S -W %t2 | FileCheck --check-prefix=SEC %s # SEC: .rodata PROGBITS 0000000000200120 000120 000002 00 A 0 0 1 -# CHECK-NOT: selected .rodata.d1 -# CHECK-NOT: selected .rodata.d2 +# CHECK-NOT: selected section {{.*}}:(.rodata.d1) +# CHECK-NOT: selected section {{.*}}:(.rodata.d2) # We do merge rodata if passed --icf-data -# RUN: ld.lld %t -o %t2 --icf=all --verbose --icf-data 2>&1 | FileCheck --check-prefix=DATA %s +# RUN: ld.lld %t -o %t2 --icf=all --print-icf-sections --ignore-data-address-equality | \ +# RUN: FileCheck --check-prefix=DATA %s # RUN: llvm-readelf -S -W %t2 | FileCheck --check-prefix=DATA-SEC %s -# DATA: selected .rodata.d1 -# DATA: removed .rodata.d2 +# DATA: selected section {{.*}}:(.rodata.d1) +# DATA: removing identical section {{.*}}:(.rodata.d2) # DATA-SEC: .rodata PROGBITS 0000000000200120 000120 000001 00 A 0 0 1 diff --git a/test/ELF/ignore-plugin.test b/test/ELF/ignore-plugin.test new file mode 100644 index 000000000000..fcd3fa64195c --- /dev/null +++ b/test/ELF/ignore-plugin.test @@ -0,0 +1,2 @@ +RUN: not ld.lld --plugin foo 2>&1 | FileCheck %s +CHECK: no input files diff --git a/test/ELF/incompatible-ar-first.s b/test/ELF/incompatible-ar-first.s index e076561d11ae..fbbe9de761ec 100644 --- a/test/ELF/incompatible-ar-first.s +++ b/test/ELF/incompatible-ar-first.s @@ -1,11 +1,11 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/archive.s -o %ta.o // RUN: llvm-ar rc %t.a %ta.o // RUN: llvm-mc -filetype=obj -triple=i686-linux %s -o %tb.o -// RUN: not ld.lld %t.a %tb.o 2>&1 | FileCheck %s +// RUN: not ld.lld %t.a %tb.o -o /dev/null 2>&1 | FileCheck %s // We used to crash when // * The first object seen by the symbol table is from an archive. // * -m was not used. // CHECK: .a({{.*}}a.o) is incompatible with {{.*}}b.o -// REQUIRES: x86 diff --git a/test/ELF/incompatible-section-flags.s b/test/ELF/incompatible-section-flags.s index 25d99945e009..30bbe75d766a 100644 --- a/test/ELF/incompatible-section-flags.s +++ b/test/ELF/incompatible-section-flags.s @@ -1,5 +1,6 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: not ld.lld -shared %t.o -o %t 2>&1 | FileCheck %s +// RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s // CHECK: error: incompatible section flags for .foo // CHECK-NEXT: >>> {{.*}}incompatible-section-flags.s.tmp.o:(.foo): 0x3 diff --git a/test/ELF/incompatible-section-types2.s b/test/ELF/incompatible-section-types2.s index 146e680ab271..3e281ce6c5da 100644 --- a/test/ELF/incompatible-section-types2.s +++ b/test/ELF/incompatible-section-types2.s @@ -1,5 +1,6 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s // CHECK: error: section type mismatch for .shstrtab // CHECK-NEXT: >>> <internal>:(.shstrtab): SHT_STRTAB diff --git a/test/ELF/incompatible.s b/test/ELF/incompatible.s index ce84606ad7e2..44c5b4bfcbf7 100644 --- a/test/ELF/incompatible.s +++ b/test/ELF/incompatible.s @@ -1,3 +1,4 @@ +// REQUIRES: x86,aarch64 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %ta.o // RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %tb.o // RUN: ld.lld -shared %tb.o -o %ti686.so @@ -49,11 +50,10 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/archive2.s -o %ta.o // RUN: llvm-ar rc %t.a %ta.o // RUN: llvm-mc -filetype=obj -triple=i686-linux %s -o %tb.o -// RUN: not ld.lld %t.a %tb.o 2>&1 | FileCheck --check-prefix=ARCHIVE %s +// RUN: not ld.lld %t.a %tb.o 2>&1 -o %t | FileCheck --check-prefix=ARCHIVE %s // ARCHIVE: .a({{.*}}a.o) is incompatible with {{.*}}b.o .global _start _start: .data .long foo -// REQUIRES: x86,aarch64 diff --git a/test/ELF/init_fini_priority.s b/test/ELF/init_fini_priority.s index b10b925063e5..17003ce30dfe 100644 --- a/test/ELF/init_fini_priority.s +++ b/test/ELF/init_fini_priority.s @@ -1,8 +1,8 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t // RUN: llvm-objdump -section-headers %t | FileCheck %s --check-prefix=OBJ // RUN: ld.lld %t -o %t.exe // RUN: llvm-objdump -s %t.exe | FileCheck %s -// REQUIRES: x86 // OBJ: 3 .init_array // OBJ-NEXT: 4 .init_array.100 diff --git a/test/ELF/invalid-cie-length.s b/test/ELF/invalid-cie-length.s index c6da95e609d6..7e73dd8aa5d3 100644 --- a/test/ELF/invalid-cie-length.s +++ b/test/ELF/invalid-cie-length.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s +// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s .section .eh_frame .byte 0 diff --git a/test/ELF/invalid-cie-length2.s b/test/ELF/invalid-cie-length2.s index 9140280ba5a7..a43491c17790 100644 --- a/test/ELF/invalid-cie-length2.s +++ b/test/ELF/invalid-cie-length2.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s +// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s .section .eh_frame .long 42 diff --git a/test/ELF/invalid-cie-length3.s b/test/ELF/invalid-cie-length3.s index fcbfa7f52ba8..3417efcba8fa 100644 --- a/test/ELF/invalid-cie-length3.s +++ b/test/ELF/invalid-cie-length3.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s +// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s .section .eh_frame .long 0xFFFFFFFC diff --git a/test/ELF/invalid-cie-length4.s b/test/ELF/invalid-cie-length4.s index 04f8eb2cca6b..cf3a6f513747 100644 --- a/test/ELF/invalid-cie-length4.s +++ b/test/ELF/invalid-cie-length4.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s +// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s .section .eh_frame .long 0xFFFFFFFF diff --git a/test/ELF/invalid-cie-length5.s b/test/ELF/invalid-cie-length5.s index bfa35edf7db5..223ce125853b 100644 --- a/test/ELF/invalid-cie-length5.s +++ b/test/ELF/invalid-cie-length5.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s +// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s .section .eh_frame .long 0xFFFFFFFF diff --git a/test/ELF/invalid-cie-reference.s b/test/ELF/invalid-cie-reference.s index fba2467e216a..0f64c4a429b4 100644 --- a/test/ELF/invalid-cie-reference.s +++ b/test/ELF/invalid-cie-reference.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s +// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s .section .eh_frame .long 0x14 diff --git a/test/ELF/invalid-eh-frame.s b/test/ELF/invalid-eh-frame.s new file mode 100644 index 000000000000..533442872346 --- /dev/null +++ b/test/ELF/invalid-eh-frame.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: corrupted .eh_frame: unexpected end of CIE +# CHECK-NEXT: >>> defined in {{.*}}:(.eh_frame+0x8) + +.section .eh_frame + .byte 0x04 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 diff --git a/test/ELF/invalid-eh-frame2.s b/test/ELF/invalid-eh-frame2.s new file mode 100644 index 000000000000..c8995cbe1c81 --- /dev/null +++ b/test/ELF/invalid-eh-frame2.s @@ -0,0 +1,22 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: corrupted .eh_frame: corrupted CIE (failed to read string) +# CHECK-NEXT: >>> defined in {{.*}}:(.eh_frame+0x9) + +.section .eh_frame +.align 1 + .byte 0x08 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + .byte 0x01 + .byte 0x01 + .byte 0x01 diff --git a/test/ELF/invalid-eh-frame3.s b/test/ELF/invalid-eh-frame3.s new file mode 100644 index 000000000000..44592cbe3c89 --- /dev/null +++ b/test/ELF/invalid-eh-frame3.s @@ -0,0 +1,21 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: corrupted .eh_frame: corrupted CIE (failed to read LEB128) +# CHECK-NEXT: >>> defined in {{.*}}:(.eh_frame+0xC) + +.section .eh_frame + .byte 0x08 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + .byte 0x01 + .byte 0x00 + .byte 0x01 diff --git a/test/ELF/invalid-eh-frame4.s b/test/ELF/invalid-eh-frame4.s new file mode 100644 index 000000000000..4022c04476dc --- /dev/null +++ b/test/ELF/invalid-eh-frame4.s @@ -0,0 +1,28 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: corrupted .eh_frame: unknown .eh_frame augmentation string: + +.section .eh_frame + .byte 0x0E + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + .byte 0x01 + .byte 0x00 + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x01 + .byte 0x01 + .byte 0x01 + .byte 0x01 diff --git a/test/ELF/invalid-eh-frame5.s b/test/ELF/invalid-eh-frame5.s new file mode 100644 index 000000000000..eb153fa92c49 --- /dev/null +++ b/test/ELF/invalid-eh-frame5.s @@ -0,0 +1,28 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: corrupted .eh_frame: unknown .eh_frame augmentation string: + +.section .eh_frame + .byte 0x0E + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x03 + .byte 0x01 + .byte 0x00 + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x01 + .byte 0x01 + .byte 0x01 + .byte 0x01 diff --git a/test/ELF/invalid-eh-frame6.s b/test/ELF/invalid-eh-frame6.s new file mode 100644 index 000000000000..9b6b7f8bf87a --- /dev/null +++ b/test/ELF/invalid-eh-frame6.s @@ -0,0 +1,31 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: corrupted .eh_frame: unknown FDE encoding +# CHECK-NEXT: >>> defined in {{.*}}:(.eh_frame+0xE) + +.section .eh_frame + .byte 0x0E + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + + .byte 0x50 # Augmentation string: 'P','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x01 + .byte 0x01 + .byte 0x01 + .byte 0x01 diff --git a/test/ELF/invalid-eh-frame7.s b/test/ELF/invalid-eh-frame7.s new file mode 100644 index 000000000000..81a0014049e0 --- /dev/null +++ b/test/ELF/invalid-eh-frame7.s @@ -0,0 +1,30 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: corrupted .eh_frame: DW_EH_PE_aligned encoding is not supported + +.section .eh_frame + .byte 0x0E + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + + .byte 0x50 # Augmentation string: 'P','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x51 + .byte 0x01 + .byte 0x01 + .byte 0x01 diff --git a/test/ELF/invalid-eh-frame8.s b/test/ELF/invalid-eh-frame8.s new file mode 100644 index 000000000000..484fef29f8b3 --- /dev/null +++ b/test/ELF/invalid-eh-frame8.s @@ -0,0 +1,30 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: corrupted .eh_frame: corrupted CIE + +.section .eh_frame + .byte 0x0E + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x01 + + .byte 0x50 # Augmentation string: 'P','\0' + .byte 0x00 + + .byte 0x01 + + .byte 0x01 # LEB128 + .byte 0x01 # LEB128 + + .byte 0x03 + .byte 0x01 + .byte 0x01 + .byte 0x01 diff --git a/test/ELF/invalid-eh-frame9.s b/test/ELF/invalid-eh-frame9.s new file mode 100644 index 000000000000..73a102b4f90d --- /dev/null +++ b/test/ELF/invalid-eh-frame9.s @@ -0,0 +1,15 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: corrupted .eh_frame: CIE is too small + +.section .eh_frame + .byte 0x03 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 diff --git a/test/ELF/invalid-fde-rel.s b/test/ELF/invalid-fde-rel.s index f43b9da30033..f6513225b533 100644 --- a/test/ELF/invalid-fde-rel.s +++ b/test/ELF/invalid-fde-rel.s @@ -33,4 +33,4 @@ .long 0x0 .long 0x0 -// CHECK: 1 .eh_frame 00000018 +// CHECK: 1 .eh_frame 0000001c diff --git a/test/ELF/invalid-relocations.test b/test/ELF/invalid-relocations.test index cfeb44b03c67..7c32058c4353 100644 --- a/test/ELF/invalid-relocations.test +++ b/test/ELF/invalid-relocations.test @@ -1,5 +1,5 @@ # RUN: yaml2obj %s -o %t -# RUN: not ld.lld %t -o %tout 2>&1 | FileCheck %s +# RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s !ELF FileHeader: diff --git a/test/ELF/invalid-undef-section-symbol.test b/test/ELF/invalid-undef-section-symbol.test index f634d6ad8c63..cb89306b781e 100644 --- a/test/ELF/invalid-undef-section-symbol.test +++ b/test/ELF/invalid-undef-section-symbol.test @@ -1,5 +1,5 @@ # RUN: yaml2obj %s -o %t.o -# RUN: not ld.lld -r %t.o -o %2.o 2>&1 | FileCheck %s +# RUN: not ld.lld -r %t.o -o /dev/null 2>&1 | FileCheck %s # We used to crash at this. # CHECK: STT_SECTION symbol should be defined diff --git a/test/ELF/invalid-z.s b/test/ELF/invalid-z.s deleted file mode 100644 index a5343c93e677..000000000000 --- a/test/ELF/invalid-z.s +++ /dev/null @@ -1,9 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: not ld.lld %t.o -o %t -z max-page-size 2>&1 | FileCheck %s -# CHECK: invalid max-page-size -# CHECK-NOT: error - -.global _start -_start: - nop diff --git a/test/ELF/invalid/Inputs/cie-version2.elf b/test/ELF/invalid/Inputs/cie-version2.elf Binary files differdeleted file mode 100644 index 87f8a5be76f4..000000000000 --- a/test/ELF/invalid/Inputs/cie-version2.elf +++ /dev/null diff --git a/test/ELF/invalid/Inputs/too-short.elf b/test/ELF/invalid/Inputs/too-short.elf Binary files differdeleted file mode 100644 index 077f392f1dc4..000000000000 --- a/test/ELF/invalid/Inputs/too-short.elf +++ /dev/null diff --git a/test/ELF/invalid/dynamic-section-size.s b/test/ELF/invalid/dynamic-section-size.s index 323dabaa9016..58a7d0688c25 100644 --- a/test/ELF/invalid/dynamic-section-size.s +++ b/test/ELF/invalid/dynamic-section-size.s @@ -1,4 +1,4 @@ ## dynamic-section-sh_size.elf has incorrect sh_size of dynamic section. -# RUN: not ld.lld %p/Inputs/dynamic-section-sh_size.elf -o %t2 2>&1 | \ +# RUN: not ld.lld %p/Inputs/dynamic-section-sh_size.elf -o /dev/null 2>&1 | \ # RUN: FileCheck %s # CHECK: error: {{.*}}: invalid sh_entsize diff --git a/test/ELF/invalid/eh-frame-hdr-no-out.s b/test/ELF/invalid/eh-frame-hdr-no-out.s index 8379253d9fd0..221ca205e591 100644 --- a/test/ELF/invalid/eh-frame-hdr-no-out.s +++ b/test/ELF/invalid/eh-frame-hdr-no-out.s @@ -1,6 +1,19 @@ // REQUIRES: x86 -// RUN: not ld.lld --eh-frame-hdr %p/Inputs/cie-version2.elf -o %t >& %t.log -// RUN: FileCheck %s < %t.log +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +// RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s -// cie-version2.elf contains unsupported version of CIE = 2. -// CHECK: FDE version 1 or 3 expected, but got 2 +// CHECK: error: corrupted .eh_frame: FDE version 1 or 3 expected, but got 2 + +.section .eh_frame + .byte 0x08 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x00 + .byte 0x02 + .byte 0x00 + .byte 0x00 + .byte 0x00 diff --git a/test/ELF/invalid/executable.s b/test/ELF/invalid/executable.s new file mode 100644 index 000000000000..254075146e15 --- /dev/null +++ b/test/ELF/invalid/executable.s @@ -0,0 +1,9 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld -o %t1.exe %t.o +# RUN: not ld.lld -o /dev/null %t1.exe 2>&1 | FileCheck %s +# CHECK: unknown file type + +.global _start +_start: + ret diff --git a/test/ELF/invalid/invalid-e_shnum.s b/test/ELF/invalid/invalid-e_shnum.s index 0c720ffa1713..34a742e18072 100644 --- a/test/ELF/invalid/invalid-e_shnum.s +++ b/test/ELF/invalid/invalid-e_shnum.s @@ -1,3 +1,3 @@ ## Spec says that "If a file has no section header table, e_shnum holds the value zero.", though ## in this test case it holds non-zero and lld used to crash. -# RUN: ld.lld %p/Inputs/invalid-e_shnum.elf -o %t2 +# RUN: ld.lld %p/Inputs/invalid-e_shnum.elf -o /dev/null diff --git a/test/ELF/invalid/invalid-elf.test b/test/ELF/invalid/invalid-elf.test index 8be0437c0680..80c8f41eb61d 100644 --- a/test/ELF/invalid/invalid-elf.test +++ b/test/ELF/invalid/invalid-elf.test @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc %s -o %t -filetype=obj -triple x86_64-pc-linux # RUN: not ld.lld %t %p/Inputs/data-encoding.a -o %t2 2>&1 | \ diff --git a/test/ELF/invalid/merge-invalid-size.s b/test/ELF/invalid/merge-invalid-size.s index 1dbd7cf95b7d..cc2566d0ee87 100644 --- a/test/ELF/invalid/merge-invalid-size.s +++ b/test/ELF/invalid/merge-invalid-size.s @@ -1,10 +1,10 @@ // REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux -// RUN: not ld.lld %t.o -o %t.so 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s // CHECK: SHF_MERGE section size must be a multiple of sh_entsize // Test that we accept a zero sh_entsize. -// RUN: ld.lld %p/Inputs/shentsize-zero.elf -o %t2 +// RUN: ld.lld %p/Inputs/shentsize-zero.elf -o /dev/null .section .foo,"aM",@progbits,4 .short 42 diff --git a/test/ELF/invalid/mips-invalid-options-descriptor.s b/test/ELF/invalid/mips-invalid-options-descriptor.s index b23ecee6d0d2..c05e34785299 100644 --- a/test/ELF/invalid/mips-invalid-options-descriptor.s +++ b/test/ELF/invalid/mips-invalid-options-descriptor.s @@ -1,5 +1,5 @@ ## mips-invalid-options-descriptor.elf has option descriptor in ## .MIPS.options with size of zero. -# RUN: not ld.lld %p/Inputs/mips-invalid-options-descriptor.elf -o %t2 2>&1 | \ +# RUN: not ld.lld %p/Inputs/mips-invalid-options-descriptor.elf -o /dev/null 2>&1 | \ # RUN: FileCheck %s # CHECK: error: {{.*}}: invalid section offset diff --git a/test/ELF/invalid/reloc-section-reordered.test b/test/ELF/invalid/reloc-section-reordered.test new file mode 100644 index 000000000000..7ff4ed6e8ade --- /dev/null +++ b/test/ELF/invalid/reloc-section-reordered.test @@ -0,0 +1,30 @@ +# REQUIRES: x86 + +# RUN: yaml2obj %s -o %t.o +# RUN: not ld.lld %t.o -o %t.exe 2>&1 | FileCheck %s +# CHECK: unsupported relocation reference + +## YAML below lists .rela.text before .text, we do not support it. + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_FREEBSD + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Type: SHT_REL + Name: .rela.text + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0 + Symbol: .text + Type: R_X86_64_NONE + - Type: SHT_PROGBITS + Name: .text + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: "FFFFFFFFFFFFFFFF" diff --git a/test/ELF/invalid/section-alignment2.s b/test/ELF/invalid/section-alignment2.s index aaef9f8bff5d..879ba8c03c14 100644 --- a/test/ELF/invalid/section-alignment2.s +++ b/test/ELF/invalid/section-alignment2.s @@ -1,5 +1,5 @@ ## section-alignment-notpow2.elf has section alignment ## 0xFFFFFFFF which is not a power of 2. -# RUN: not ld.lld %p/Inputs/section-alignment-notpow2.elf -o %t2 2>&1 | \ +# RUN: not ld.lld %p/Inputs/section-alignment-notpow2.elf -o /dev/null 2>&1 | \ # RUN: FileCheck %s # CHECK: section sh_addralign is not a power of 2 diff --git a/test/ELF/invalid/sht-group.s b/test/ELF/invalid/sht-group.s index f28035f0dac9..a4b684c83fd3 100644 --- a/test/ELF/invalid/sht-group.s +++ b/test/ELF/invalid/sht-group.s @@ -1,3 +1,3 @@ ## sht-group.elf contains SHT_GROUP section with invalid sh_info. -# RUN: not ld.lld %p/Inputs/sht-group.elf -o %t2 2>&1 | FileCheck %s +# RUN: not ld.lld %p/Inputs/sht-group.elf -o /dev/null 2>&1 | FileCheck %s # CHECK: invalid symbol index diff --git a/test/ELF/invalid/symbol-index.s b/test/ELF/invalid/symbol-index.s index 4ad1d6cb232c..e3989b4e1adc 100644 --- a/test/ELF/invalid/symbol-index.s +++ b/test/ELF/invalid/symbol-index.s @@ -5,6 +5,6 @@ ## [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 ## ... ## [ 4] .symtab RELA 0000000000000000 000048 000030 18 1 2 8 -# RUN: not ld.lld %p/Inputs/symbol-index.elf -o %t2 2>&1 | \ +# RUN: not ld.lld %p/Inputs/symbol-index.elf -o /dev/null 2>&1 | \ # RUN: FileCheck --check-prefix=INVALID-SYMBOL-INDEX %s # INVALID-SYMBOL-INDEX: invalid symbol index diff --git a/test/ELF/invalid/symbol-name.s b/test/ELF/invalid/symbol-name.s index 8daee1a3fa78..53a20ef6af9c 100644 --- a/test/ELF/invalid/symbol-name.s +++ b/test/ELF/invalid/symbol-name.s @@ -3,5 +3,5 @@ ## symbol-name-offset.elf contains symbol with invalid (too large) ## st_name value. # RUN: not ld.lld %S/Inputs/symbol-name-offset.elf \ -# RUN: -o %t 2>&1 | FileCheck %s +# RUN: -o /dev/null 2>&1 | FileCheck %s # CHECK: invalid symbol name offset diff --git a/test/ELF/invalid/tls-symbol.s b/test/ELF/invalid/tls-symbol.s index 354ca573d5c0..99c47dc13023 100644 --- a/test/ELF/invalid/tls-symbol.s +++ b/test/ELF/invalid/tls-symbol.s @@ -1,5 +1,5 @@ # REQUIRES: x86 ## The test file contains an STT_TLS symbol but has no TLS section. -# RUN: not ld.lld %S/Inputs/tls-symbol.elf -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld %S/Inputs/tls-symbol.elf -o /dev/null 2>&1 | FileCheck %s # CHECK: has an STT_TLS symbol but doesn't have an SHF_TLS section diff --git a/test/ELF/invalid/too-short.s b/test/ELF/invalid/too-short.s deleted file mode 100644 index deaf8218d6e0..000000000000 --- a/test/ELF/invalid/too-short.s +++ /dev/null @@ -1,5 +0,0 @@ -# REQUIRES: x86 - -## too-short.elf file is a truncated ELF. -# RUN: not ld.lld %S/Inputs/too-short.elf -o %t 2>&1 | FileCheck %s -# CHECK: file is too short diff --git a/test/ELF/just-symbols-cref.s b/test/ELF/just-symbols-cref.s new file mode 100644 index 000000000000..8581c53eb5df --- /dev/null +++ b/test/ELF/just-symbols-cref.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t1.exe -Ttext=0x10000 + +# RUN: ld.lld -just-symbols=%t1.exe -o %t2.exe -cref | FileCheck %s + +# CHECK: Symbol File +# CHECK-NEXT: bar {{.*exe}} +# CHECK-NEXT: foo {{.*exe}} + +.globl foo, bar +foo: + ret + +.section .data +.type bar, @object +.size bar, 40 +bar: + .zero 40 diff --git a/test/ELF/just-symbols.s b/test/ELF/just-symbols.s new file mode 100644 index 000000000000..856cf8c581ec --- /dev/null +++ b/test/ELF/just-symbols.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t1.exe -Ttext=0x10000 + +# RUN: ld.lld -just-symbols=%t1.exe -o %t2.exe +# RUN: llvm-readelf -symbols %t2.exe | FileCheck %s + +# CHECK: 0000000000011000 40 OBJECT GLOBAL DEFAULT ABS bar +# CHECK: 0000000000010000 0 NOTYPE GLOBAL DEFAULT ABS foo + +.globl foo, bar +foo: + ret + +.section .data +.type bar, @object +.size bar, 40 +bar: + .zero 40 diff --git a/test/ELF/libsearch.s b/test/ELF/libsearch.s index d21baf9dd95f..246a5d13951e 100644 --- a/test/ELF/libsearch.s +++ b/test/ELF/libsearch.s @@ -1,3 +1,4 @@ +// 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 \ // RUN: %p/Inputs/libsearch-dyn.s -o %tdyn.o @@ -10,7 +11,6 @@ // RUN: cp -f %t.dir/libls.so %t.dir/libls2.so // RUN: rm -f %t.dir/libls.a // RUN: llvm-ar rcs %t.dir/libls.a %tst.o -// REQUIRES: x86 // Should fail if no library specified // RUN: not ld.lld -l 2>&1 \ diff --git a/test/ELF/linkerscript/Inputs/addr.s b/test/ELF/linkerscript/Inputs/addr.s new file mode 100644 index 000000000000..65d99dcf99cd --- /dev/null +++ b/test/ELF/linkerscript/Inputs/addr.s @@ -0,0 +1,12 @@ +.text +.globl _start +_start: + +.section .foo.1,"a" +.quad 1 + +.section .foo.2,"a" +.quad 2 + +.section .foo.3,"a" +.quad 3 diff --git a/test/ELF/linkerscript/Inputs/align.s b/test/ELF/linkerscript/Inputs/align.s new file mode 100644 index 000000000000..c804536aa543 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/align.s @@ -0,0 +1,13 @@ +.global _start +_start: + nop + +.section .aaa, "a" +.quad 0 + +.section .bbb, "a" +.quad 0 + +.section .ccc, "a" +.quad 0 + diff --git a/test/ELF/linkerscript/Inputs/alignof.s b/test/ELF/linkerscript/Inputs/alignof.s new file mode 100644 index 000000000000..b288f94a12c9 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/alignof.s @@ -0,0 +1,15 @@ +.global _start +_start: + nop + +.section .aaa,"a" + .align 8 + .quad 0 + +.section .bbb,"a" + .align 16 + .quad 0 + +.section .ccc,"a" + .align 32 + .quad 0 diff --git a/test/ELF/linkerscript/Inputs/at2.s b/test/ELF/linkerscript/Inputs/at2.s new file mode 100644 index 000000000000..8c6548b53f69 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/at2.s @@ -0,0 +1,14 @@ +.section .foo1, "ax" +.quad 0 + +.section .foo2, "ax" +.quad 0 + +.section .bar1, "aw" +.quad 0 + +.section .bar2, "aw" +.quad 0 + +.section .bar3, "aw" +.quad 0 diff --git a/test/ELF/linkerscript/Inputs/at3.s b/test/ELF/linkerscript/Inputs/at3.s new file mode 100644 index 000000000000..8005c75723dd --- /dev/null +++ b/test/ELF/linkerscript/Inputs/at3.s @@ -0,0 +1,8 @@ +.section .foo1, "a" +.quad 0 + +.section .foo2, "ax" +.quad 0 + +.section .foo3, "ax" +.quad 0 diff --git a/test/ELF/linkerscript/Inputs/data-commands.s b/test/ELF/linkerscript/Inputs/data-commands.s new file mode 100644 index 000000000000..d5d78cfd9beb --- /dev/null +++ b/test/ELF/linkerscript/Inputs/data-commands.s @@ -0,0 +1,35 @@ +.global a +a = 0x11 + +.global b +b = 0x1122 + +.global c +c = 0x11223344 + +.global d +d = 0x1122334455667788 + +.section .foo.1, "a" + .byte 0xFF + +.section .foo.2, "a" + .byte 0xFF + +.section .foo.3, "a" + .byte 0xFF + +.section .foo.4, "a" + .byte 0xFF + +.section .bar.1, "a" + .byte 0xFF + +.section .bar.2, "a" + .byte 0xFF + +.section .bar.3, "a" + .byte 0xFF + +.section .bar.4, "a" + .byte 0xFF diff --git a/test/ELF/linkerscript/Inputs/data-segment-relro.s b/test/ELF/linkerscript/Inputs/data-segment-relro.s new file mode 100644 index 000000000000..668a2e2ca2a4 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/data-segment-relro.s @@ -0,0 +1,11 @@ +.global _start +_start: + .long bar + jmp *bar2@GOTPCREL(%rip) + +.section .data,"aw" +.quad 0 + +.zero 4 +.section .foo,"aw" +.section .bss,"",@nobits diff --git a/test/ELF/linkerscript/Inputs/define.s b/test/ELF/linkerscript/Inputs/define.s new file mode 100644 index 000000000000..bc60a233dcb4 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/define.s @@ -0,0 +1,8 @@ +.global defined +defined = 0 + +.section .foo,"a" +.quad 1 + +.section .bar,"a" +.quad 1 diff --git a/test/ELF/linkerscript/Inputs/eh-frame-reloc-out-of-range.s b/test/ELF/linkerscript/Inputs/eh-frame-reloc-out-of-range.s new file mode 100644 index 000000000000..19e50488050e --- /dev/null +++ b/test/ELF/linkerscript/Inputs/eh-frame-reloc-out-of-range.s @@ -0,0 +1,11 @@ +.text +.globl _start +_start: + .cfi_startproc + .cfi_lsda 0, _ex + nop + .cfi_endproc + +.data +_ex: + .word 0 diff --git a/test/ELF/linkerscript/Inputs/extend-pt-load.s b/test/ELF/linkerscript/Inputs/extend-pt-load.s new file mode 100644 index 000000000000..8993fb163346 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/extend-pt-load.s @@ -0,0 +1,3 @@ +nop +.section .data.rel.ro, "aw" +.byte 0 diff --git a/test/ELF/linkerscript/Inputs/fill.s b/test/ELF/linkerscript/Inputs/fill.s new file mode 100644 index 000000000000..b8eed890601b --- /dev/null +++ b/test/ELF/linkerscript/Inputs/fill.s @@ -0,0 +1,11 @@ +.text +.globl _start +_start: + +.section .aaa, "a" +.align 1 +.byte 0xAA + +.section .bbb, "a" +.align 1 +.byte 0xBB diff --git a/test/ELF/linkerscript/Inputs/implicit-program-header.script b/test/ELF/linkerscript/Inputs/implicit-program-header.script deleted file mode 100644 index 27dbea84c4e4..000000000000 --- a/test/ELF/linkerscript/Inputs/implicit-program-header.script +++ /dev/null @@ -1,12 +0,0 @@ -PHDRS -{ - ph_write PT_LOAD FLAGS(2); - ph_exec PT_LOAD FLAGS(1); -} - -SECTIONS -{ - .bar : { *(.bar) } : ph_exec - .foo : { *(.foo) } - .text : { *(.text) } : ph_write -} diff --git a/test/ELF/linkerscript/Inputs/insert-after.s b/test/ELF/linkerscript/Inputs/insert-after.s new file mode 100644 index 000000000000..88a6044cc968 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/insert-after.s @@ -0,0 +1,11 @@ +.section .foo.text,"ax" +.quad 0 + +.section .foo.data,"aw" +.quad 0 + +.section .text.1,"ax" +.quad 0 + +.section .data.1,"aw" +.quad 0 diff --git a/test/ELF/linkerscript/Inputs/insert-after.script b/test/ELF/linkerscript/Inputs/insert-after.script new file mode 100644 index 000000000000..cb95878bc5cf --- /dev/null +++ b/test/ELF/linkerscript/Inputs/insert-after.script @@ -0,0 +1,4 @@ +SECTIONS { + .text : { *(.text.*) } + .data : { *(.data.*) } +} diff --git a/test/ELF/linkerscript/Inputs/map-file2.s b/test/ELF/linkerscript/Inputs/map-file2.s new file mode 100644 index 000000000000..daf994eca172 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/map-file2.s @@ -0,0 +1,19 @@ +.global _start +_start: +.global _Z1fi +_Z1fi: +.cfi_startproc +nop +.cfi_endproc + +.section .aaa, "a"; +.quad 1; + +.section .bbb, "a"; +.quad 2; + +.section .ccc, "a"; +.quad 3; + +.section .ddd, "a"; +.quad 4 diff --git a/test/ELF/linkerscript/Inputs/provide-shared2.s b/test/ELF/linkerscript/Inputs/provide-shared2.s new file mode 100644 index 000000000000..f02fd650106a --- /dev/null +++ b/test/ELF/linkerscript/Inputs/provide-shared2.s @@ -0,0 +1,3 @@ +.global foo +.data +.dc.a foo diff --git a/test/ELF/linkerscript/Inputs/sections-va-overflow.s b/test/ELF/linkerscript/Inputs/sections-va-overflow.s new file mode 100644 index 000000000000..6bb049031c7d --- /dev/null +++ b/test/ELF/linkerscript/Inputs/sections-va-overflow.s @@ -0,0 +1,6 @@ +.global _start +_start: + retq + +.bss +.space 0x2000 diff --git a/test/ELF/linkerscript/Inputs/synthetic-symbols.s b/test/ELF/linkerscript/Inputs/synthetic-symbols.s new file mode 100644 index 000000000000..670e65cb80f4 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/synthetic-symbols.s @@ -0,0 +1,16 @@ +.global _start +_start: + nop + +.section .foo,"a" + .quad 0 + +.section .bar,"a" + .long 0 + +.section .dah,"ax",@progbits + .cfi_startproc + nop + .cfi_endproc + +.global _begin_sec, _end_sec, _end_sec_abs diff --git a/test/ELF/linkerscript/absolute-expr.s b/test/ELF/linkerscript/absolute-expr.test index a9a674b859f4..9e8f517d0ac4 100644 --- a/test/ELF/linkerscript/absolute-expr.s +++ b/test/ELF/linkerscript/absolute-expr.test @@ -1,21 +1,19 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS { \ -# RUN: .text : { \ -# RUN: bar1 = ALIGNOF(.text); \ -# RUN: bar2 = CONSTANT (MAXPAGESIZE); \ -# RUN: bar3 = SIZEOF (.text); \ -# RUN: bar4 = SIZEOF_HEADERS; \ -# RUN: bar5 = 0x42; \ -# RUN: bar6 = foo + 1; \ -# RUN: *(.text) \ -# RUN: } \ -# RUN: };" > %t.script -# RUN: ld.lld -o %t.so --script %t.script %t.o -shared +# RUN: echo ".global foo; foo = 0x123" | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t.o +# RUN: ld.lld -o %t.so --script %s %t.o -shared # RUN: llvm-readobj -t %t.so | FileCheck %s -.global foo -foo = 0x123 +SECTIONS { + .text : { + bar1 = ALIGNOF(.text); + bar2 = CONSTANT (MAXPAGESIZE); + bar3 = SIZEOF (.text); + bar4 = SIZEOF_HEADERS; + bar5 = 0x42; + bar6 = foo + 1; + *(.text) + } +} # CHECK: Symbol { # CHECK: Name: foo diff --git a/test/ELF/linkerscript/addr-zero.s b/test/ELF/linkerscript/addr-zero.test index 71251d3acfff..6253f619381b 100644 --- a/test/ELF/linkerscript/addr-zero.s +++ b/test/ELF/linkerscript/addr-zero.test @@ -1,7 +1,6 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "SECTIONS { foo = ADDR(.text) - ABSOLUTE(ADDR(.text)); };" > %t.script -# RUN: ld.lld -o %t.so --script %t.script %t.o -shared +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: ld.lld -o %t.so --script %s %t.o -shared # RUN: llvm-readobj --symbols %t.so | FileCheck %s # Test that the script creates a non absolute symbol with value @@ -9,10 +8,14 @@ # CHECK: Symbol { # CHECK: Name: foo -# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Value: 0x70 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Global # CHECK-NEXT: Type: None # CHECK-NEXT: Other: 0 # CHECK-NEXT: Section: .text # CHECK-NEXT: } + +SECTIONS { + foo = ADDR(.text) - ABSOLUTE(ADDR(.text)); +}; diff --git a/test/ELF/linkerscript/addr.s b/test/ELF/linkerscript/addr.s deleted file mode 100644 index 2d3a7ab35767..000000000000 --- a/test/ELF/linkerscript/addr.s +++ /dev/null @@ -1,32 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "SECTIONS { \ -# RUN: . = 0x1000; \ -# RUN: .text : { *(.text*) } \ -# RUN: .foo.1 : { *(.foo.1) } \ -# RUN: .foo.2 ADDR(.foo.1) + 0x100 : { *(.foo.2) } \ -# RUN: .foo.3 : { *(.foo.3) } \ -# RUN: }" > %t.script -# RUN: ld.lld %t --script %t.script -o %t1 -# RUN: llvm-objdump -section-headers %t1 | FileCheck %s - -# CHECK: Sections: -# CHECK-NEXT: Idx Name Size Address Type -# CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .text 00000000 0000000000001000 TEXT DATA -# CHECK-NEXT: 2 .foo.1 00000008 0000000000001000 DATA -# CHECK-NEXT: 3 .foo.2 00000008 0000000000001100 DATA -# CHECK-NEXT: 4 .foo.3 00000008 0000000000001108 DATA - -.text -.globl _start -_start: - -.section .foo.1,"a" - .quad 1 - -.section .foo.2,"a" - .quad 2 - -.section .foo.3,"a" - .quad 3 diff --git a/test/ELF/linkerscript/addr.test b/test/ELF/linkerscript/addr.test new file mode 100644 index 000000000000..db0568e56c76 --- /dev/null +++ b/test/ELF/linkerscript/addr.test @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/addr.s -o %t +# RUN: ld.lld %t --script %s -o %t1 +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .text 00000000 0000000000001000 TEXT +# CHECK-NEXT: 2 .foo.1 00000008 0000000000001000 DATA +# CHECK-NEXT: 3 .foo.2 00000008 0000000000001100 DATA +# CHECK-NEXT: 4 .foo.3 00000008 0000000000001108 DATA + +SECTIONS { + . = 0x1000; + .text : { *(.text*) } + .foo.1 : { *(.foo.1) } + .foo.2 ADDR(.foo.1) + 0x100 : { *(.foo.2) } + .foo.3 : { *(.foo.3) } +} diff --git a/test/ELF/linkerscript/address-expr-symbols.s b/test/ELF/linkerscript/address-expr-symbols.s new file mode 100644 index 000000000000..0b76c91a5c8b --- /dev/null +++ b/test/ELF/linkerscript/address-expr-symbols.s @@ -0,0 +1,15 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +# RUN: echo "SECTIONS { .bar (foo) : { } };" > %t.script +# RUN: not ld.lld -o %t --script %t.script %t.o 2>&1 | FileCheck %s +# CHECK: symbol not found: foo + +# RUN: echo "SECTIONS { .bar : AT(foo) { } };" > %t.script +# RUN: not ld.lld -o %t --script %t.script %t.o 2>&1 | FileCheck %s + +# RUN: echo "SECTIONS { .bar : ALIGN(foo) { } };" > %t.script +# RUN: not ld.lld -o %t --script %t.script %t.o 2>&1 | FileCheck %s + +# RUN: echo "SECTIONS { .bar : SUBALIGN(foo) { } };" > %t.script +# RUN: not ld.lld -o %t --script %t.script %t.o 2>&1 | FileCheck %s diff --git a/test/ELF/linkerscript/align-empty.s b/test/ELF/linkerscript/align-empty.s deleted file mode 100644 index 3ff71578410a..000000000000 --- a/test/ELF/linkerscript/align-empty.s +++ /dev/null @@ -1,18 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -# RUN: echo "SECTIONS { \ -# RUN: . = SIZEOF_HEADERS; \ -# RUN: abc : { } \ -# RUN: . = ALIGN(0x1000); \ -# RUN: foo : { *(foo) } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -shared -# RUN: llvm-objdump -section-headers %t1 | FileCheck %s -# CHECK: Sections: -# CHECK-NEXT: Idx Name Size Address -# CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 foo 00000001 0000000000001000 - - .section foo, "a" - .byte 0 diff --git a/test/ELF/linkerscript/align-empty.test b/test/ELF/linkerscript/align-empty.test new file mode 100644 index 000000000000..63fe32882c0b --- /dev/null +++ b/test/ELF/linkerscript/align-empty.test @@ -0,0 +1,22 @@ +# REQUIRES: x86 +# RUN: echo '.section foo, "a"; .byte 0' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o + +# RUN: ld.lld -o %t1 --script %s %t.o -shared +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s + +SECTIONS { + . = SIZEOF_HEADERS; + abc : {} + . = ALIGN(0x1000); + foo : { *(foo) } +} + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .dynsym 00000018 0000000000000190 +# CHECK-NEXT: 2 .gnu.hash 0000001c 00000000000001a8 +# CHECK-NEXT: 3 .hash 00000010 00000000000001c4 +# CHECK-NEXT: 4 .dynstr 00000001 00000000000001d4 +# CHECK-NEXT: 5 foo 00000001 0000000000001000 diff --git a/test/ELF/linkerscript/align-r.test b/test/ELF/linkerscript/align-r.test new file mode 100644 index 000000000000..684ac1e92328 --- /dev/null +++ b/test/ELF/linkerscript/align-r.test @@ -0,0 +1,21 @@ +# REQUIRES: x86 + +## Check output section ALIGN modifier with -r + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t1.o +# RUN: ld.lld -r -o %t2.o --script %s %t1.o +# RUN: llvm-readelf -s %t2.o | FileCheck %s + +# CHECK: Section Headers: +# CHECK-NEXT: Name Type Address Off Size ES Flg Lk Inf Al +# CHECK-NEXT: NULL 0000000000000000 000000 000000 00 +# CHECK-NEXT: .aaa PROGBITS 0000000000000000 000040 000008 00 A 0 0 1 +# CHECK-NEXT: .bbb PROGBITS 0000000000000000 001000 000008 00 A 0 0 4096 +# CHECK-NEXT: .ccc PROGBITS 0000000000000000 004000 000008 00 A 0 0 16384 + +SECTIONS { + . = 0x10000; + .aaa : { *(.aaa) } + .bbb : ALIGN(4096) { *(.bbb) } + .ccc : ALIGN(4096 * 4) { *(.ccc) } +} diff --git a/test/ELF/linkerscript/align-section-offset.s b/test/ELF/linkerscript/align-section-offset.s deleted file mode 100644 index 9c1603a19853..000000000000 --- a/test/ELF/linkerscript/align-section-offset.s +++ /dev/null @@ -1,11 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS { .foo : ALIGN(2M) { *(.foo) } }" > %t.script -# RUN: ld.lld -o %t --script %t.script %t.o -shared -# RUN: llvm-readelf -S -l %t | FileCheck %s - -# CHECK: .foo PROGBITS 0000000000200000 200000 000008 00 WA 0 0 2097152 -# CHECK: LOAD 0x200000 0x0000000000200000 0x0000000000200000 {{.*}} RW 0x200000 - - .section .foo, "aw" - .quad 42 diff --git a/test/ELF/linkerscript/align-section-offset.test b/test/ELF/linkerscript/align-section-offset.test new file mode 100644 index 000000000000..66508c472e94 --- /dev/null +++ b/test/ELF/linkerscript/align-section-offset.test @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: echo '.section .foo, "aw"; .quad 42' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t.o +# RUN: ld.lld -o %t --script %s %t.o -shared +# RUN: llvm-readelf -S -l %t | FileCheck %s + +SECTIONS { + .foo : ALIGN(2M) { *(.foo) } +} + +# CHECK: .foo PROGBITS 0000000000200000 200000 000008 00 WA 0 0 2097152 +# CHECK: LOAD 0x200000 0x0000000000200000 0x0000000000200000 {{.*}} RW 0x200000 diff --git a/test/ELF/linkerscript/align-section.s b/test/ELF/linkerscript/align-section.s deleted file mode 100644 index d26f15c87329..000000000000 --- a/test/ELF/linkerscript/align-section.s +++ /dev/null @@ -1,6 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS { .foo : ALIGN(2M) { } }" > %t.script -# RUN: ld.lld -o %t --script %t.script %t.o -shared - -# We would crash if an empty section had an ALIGN. diff --git a/test/ELF/linkerscript/align-section.test b/test/ELF/linkerscript/align-section.test new file mode 100644 index 000000000000..7a28fef2076e --- /dev/null +++ b/test/ELF/linkerscript/align-section.test @@ -0,0 +1,7 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t.o +# RUN: ld.lld -o %t --script %s %t.o -shared + +# lld shouldn't crash. + +SECTIONS { .foo : ALIGN(2M) {} } diff --git a/test/ELF/linkerscript/align.s b/test/ELF/linkerscript/align.s deleted file mode 100644 index 99e7382daa59..000000000000 --- a/test/ELF/linkerscript/align.s +++ /dev/null @@ -1,125 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -## Check that ALIGN command workable using location counter -# RUN: echo "SECTIONS { \ -# RUN: . = 0x10000; \ -# RUN: .aaa : { *(.aaa) } \ -# RUN: . = ALIGN(4096); \ -# RUN: .bbb : { *(.bbb) } \ -# RUN: . = ALIGN(4096 * 4); \ -# RUN: .ccc : { *(.ccc) } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -# RUN: llvm-objdump -section-headers %t1 | FileCheck %s - -## Check that the two argument version of ALIGN command works -# RUN: echo "SECTIONS { \ -# RUN: . = ALIGN(0x1234, 0x10000); \ -# RUN: .aaa : { *(.aaa) } \ -# RUN: . = ALIGN(., 4096); \ -# RUN: .bbb : { *(.bbb) } \ -# RUN: . = ALIGN(., 4096 * 4); \ -# RUN: .ccc : { *(.ccc) } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -# RUN: llvm-objdump -section-headers %t1 | FileCheck %s - -# CHECK: Sections: -# CHECK-NEXT: Idx Name Size Address Type -# CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .aaa 00000008 0000000000010000 DATA -# CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA -# CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA - -## Check output sections ALIGN modificator -# RUN: echo "SECTIONS { \ -# RUN: . = 0x10000; \ -# RUN: .aaa : { *(.aaa) } \ -# RUN: .bbb : ALIGN(4096) { *(.bbb) } \ -# RUN: .ccc : ALIGN(4096 * 4) { *(.ccc) } \ -# RUN: }" > %t2.script -# RUN: ld.lld -o %t2 --script %t2.script %t -# RUN: llvm-objdump -section-headers %t2 | FileCheck %s - -## Check use of variables in align expressions: -# RUN: echo "VAR = 0x1000; \ -# RUN: __code_base__ = 0x10000; \ -# RUN: SECTIONS { \ -# RUN: . = __code_base__; \ -# RUN: .aaa : { *(.aaa) } \ -# RUN: .bbb : ALIGN(VAR) { *(.bbb) } \ -# RUN: . = ALIGN(., VAR * 4); \ -# RUN: .ccc : { *(.ccc) } \ -# RUN: __start_bbb = ADDR(.bbb); \ -# RUN: __end_bbb = ALIGN(__start_bbb + SIZEOF(.bbb), VAR); \ -# RUN: }" > %t3.script -# RUN: ld.lld -o %t3 --script %t3.script %t -# RUN: llvm-objdump -section-headers %t3 | FileCheck %s -# RUN: llvm-objdump -t %t3 | FileCheck -check-prefix SYMBOLS %s - -# SYMBOLS-LABEL: SYMBOL TABLE: -# SYMBOLS-NEXT: 0000000000000000 *UND* 00000000 -# SYMBOLS-NEXT: 0000000000014008 .text 00000000 _start -# SYMBOLS-NEXT: 0000000000010000 *ABS* 00000000 __code_base__ -# SYMBOLS-NEXT: 0000000000001000 *ABS* 00000000 VAR -# SYMBOLS-NEXT: 0000000000011000 .bbb 00000000 __start_bbb -# SYMBOLS-NEXT: 0000000000012000 .bbb 00000000 __end_bbb - -## Check that ALIGN zero do nothing and does not crash #1. -# RUN: echo "SECTIONS { . = ALIGN(0x123, 0); .aaa : { *(.aaa) } }" > %t.script -# RUN: ld.lld -o %t4 --script %t.script %t -# RUN: llvm-objdump -section-headers %t4 | FileCheck %s -check-prefix=ZERO - -# ZERO: Sections: -# ZERO-NEXT: Idx Name Size Address Type -# ZERO-NEXT: 0 00000000 0000000000000000 -# ZERO-NEXT: 1 .aaa 00000008 0000000000000123 DATA - -## Check that ALIGN zero do nothing and does not crash #2. -# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0); .aaa : { *(.aaa) } }" > %t.script -# RUN: ld.lld -o %t5 --script %t.script %t -# RUN: llvm-objdump -section-headers %t5 | FileCheck %s -check-prefix=ZERO - -## Test we fail gracefuly when alignment value is not a power of 2 (#1). -# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0x123, 3); .aaa : { *(.aaa) } }" > %t.script -# RUN: not ld.lld -o %t6 --script %t.script %t 2>&1 | FileCheck -check-prefix=ERR %s -# ERR: {{.*}}.script:1: alignment must be power of 2 - -## Test we fail gracefuly when alignment value is not a power of 2 (#2). -# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(3); .aaa : { *(.aaa) } }" > %t.script -# RUN: not ld.lld -o %t7 --script %t.script %t 2>&1 | FileCheck -check-prefix=ERR %s - -# RUN: echo "SECTIONS { \ -# RUN: . = 0xff8; \ -# RUN: .aaa : { \ -# RUN: *(.aaa) \ -# RUN: foo = ALIGN(., 0x100); \ -# RUN: bar = .; \ -# RUN: zed1 = ALIGN(., 0x100) + 1; \ -# RUN: zed2 = ALIGN(., 0x100) - 1; \ -# RUN: } \ -# RUN: .bbb : { *(.bbb); } \ -# RUN: .ccc : { *(.ccc); } \ -# RUN: .text : { *(.text); } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=OFFSET %s - -# OFFSET: 0000000000001000 .aaa 00000000 foo -# OFFSET: 0000000000001000 .aaa 00000000 bar -# OFFSET: 0000000000001001 .aaa 00000000 zed1 -# OFFSET: 0000000000000fff .aaa 00000000 zed2 - -.global _start -_start: - nop - -.section .aaa, "a" -.quad 0 - -.section .bbb, "a" -.quad 0 - -.section .ccc, "a" -.quad 0 diff --git a/test/ELF/linkerscript/align1.test b/test/ELF/linkerscript/align1.test new file mode 100644 index 000000000000..5804bf933740 --- /dev/null +++ b/test/ELF/linkerscript/align1.test @@ -0,0 +1,44 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +SECTIONS { + . = 0x10000; + .aaa : { *(.aaa) } + . = ALIGN(4096); + .bbb : { *(.bbb) } + . = ALIGN(4096 * 4); + .ccc : { *(.ccc) } +} + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .aaa 00000008 0000000000010000 DATA +# CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA +# CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA + +## Check that ALIGN zero do nothing and does not crash #1. +# RUN: echo "SECTIONS { . = ALIGN(0x123, 0); .aaa : { *(.aaa) } }" > %t.script +# RUN: ld.lld -o %t4 --script %t.script %t.o +# RUN: llvm-objdump -section-headers %t4 | FileCheck %s -check-prefix=ZERO + +# ZERO: Sections: +# ZERO-NEXT: Idx Name Size Address Type +# ZERO-NEXT: 0 00000000 0000000000000000 +# ZERO-NEXT: 1 .aaa 00000008 0000000000000123 DATA + +## Check that ALIGN zero do nothing and does not crash #2. +# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0); .aaa : { *(.aaa) } }" > %t.script +# RUN: ld.lld -o %t5 --script %t.script %t.o +# RUN: llvm-objdump -section-headers %t5 | FileCheck %s -check-prefix=ZERO + +## Test we fail gracefuly when alignment value is not a power of 2 (#1). +# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0x123, 3); .aaa : { *(.aaa) } }" > %t.script +# RUN: not ld.lld -o %t6 --script %t.script %t.o 2>&1 | FileCheck -check-prefix=ERR %s + +# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(3); .aaa : { *(.aaa) } }" > %t.script +# RUN: not ld.lld -o %t7 --script %t.script %t.o 2>&1 | FileCheck -check-prefix=ERR %s + +# ERR: {{.*}}.script:1: alignment must be power of 2 diff --git a/test/ELF/linkerscript/align2.test b/test/ELF/linkerscript/align2.test new file mode 100644 index 000000000000..a9003a403d75 --- /dev/null +++ b/test/ELF/linkerscript/align2.test @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +SECTIONS { + . = ALIGN(0x1234, 0x10000); + .aaa : { *(.aaa) } + . = ALIGN(., 4096); + .bbb : { *(.bbb) } + . = ALIGN(., 4096 * 4); + .ccc : { *(.ccc) } +} + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .aaa 00000008 0000000000010000 DATA +# CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA +# CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA diff --git a/test/ELF/linkerscript/align3.test b/test/ELF/linkerscript/align3.test new file mode 100644 index 000000000000..2a091fcbd6bd --- /dev/null +++ b/test/ELF/linkerscript/align3.test @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +SECTIONS { + . = 0x10000; + .aaa : { *(.aaa) } + .bbb : ALIGN(4096) { *(.bbb) } + .ccc : ALIGN(4096 * 4) { *(.ccc) } +} + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .aaa 00000008 0000000000010000 DATA +# CHECK-NEXT: 2 .bbb 00000008 0000000000011000 DATA +# CHECK-NEXT: 3 .ccc 00000008 0000000000014000 DATA diff --git a/test/ELF/linkerscript/align4.test b/test/ELF/linkerscript/align4.test new file mode 100644 index 000000000000..9440d60f6385 --- /dev/null +++ b/test/ELF/linkerscript/align4.test @@ -0,0 +1,25 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -t %t | FileCheck %s + +# CHECK-LABEL: SYMBOL TABLE: +# CHECK-NEXT: 0000000000000000 *UND* 00000000 +# CHECK-NEXT: 0000000000014008 .text 00000000 _start +# CHECK-NEXT: 0000000000010000 *ABS* 00000000 __code_base__ +# CHECK-NEXT: 0000000000001000 *ABS* 00000000 VAR +# CHECK-NEXT: 0000000000011000 .bbb 00000000 __start_bbb +# CHECK-NEXT: 0000000000012000 .bbb 00000000 __end_bbb + +VAR = 0x1000; +__code_base__ = 0x10000; + +SECTIONS { + . = __code_base__; + .aaa : { *(.aaa) } + .bbb : ALIGN(VAR) { *(.bbb) } + . = ALIGN(., VAR * 4); + .ccc : { *(.ccc) } + __start_bbb = ADDR(.bbb); + __end_bbb = ALIGN(__start_bbb + SIZEOF(.bbb), VAR); +} diff --git a/test/ELF/linkerscript/align5.test b/test/ELF/linkerscript/align5.test new file mode 100644 index 000000000000..47b5c8c03490 --- /dev/null +++ b/test/ELF/linkerscript/align5.test @@ -0,0 +1,23 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/align.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -t %t | FileCheck %s + +SECTIONS { + . = 0xff8; + .aaa : { + *(.aaa) + foo = ALIGN(., 0x100); + bar = .; + zed1 = ALIGN(., 0x100) + 1; + zed2 = ALIGN(., 0x100) - 1; + } + .bbb : { *(.bbb); } + .ccc : { *(.ccc); } + .text : { *(.text); } +} + +# CHECK: 0000000000001000 .aaa 00000000 foo +# CHECK: 0000000000001000 .aaa 00000000 bar +# CHECK: 0000000000001001 .aaa 00000000 zed1 +# CHECK: 0000000000000fff .aaa 00000000 zed2 diff --git a/test/ELF/linkerscript/alignof.s b/test/ELF/linkerscript/alignof.s deleted file mode 100644 index 8880634df243..000000000000 --- a/test/ELF/linkerscript/alignof.s +++ /dev/null @@ -1,41 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -# RUN: echo "SECTIONS { \ -# RUN: .aaa : { *(.aaa) } \ -# RUN: .bbb : { *(.bbb) } \ -# RUN: .ccc : { *(.ccc) } \ -# RUN: _aaa = ALIGNOF(.aaa); \ -# RUN: _bbb = ALIGNOF(.bbb); \ -# RUN: _ccc = ALIGNOF(.ccc); \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -# RUN: llvm-objdump -t %t1 | FileCheck %s -# CHECK: SYMBOL TABLE: -# CHECK: 0000000000000008 *ABS* 00000000 _aaa -# CHECK-NEXT: 0000000000000010 *ABS* 00000000 _bbb -# CHECK-NEXT: 0000000000000020 *ABS* 00000000 _ccc - -## Check that we error out if trying to get alignment of -## section that does not exist. -# RUN: echo "SECTIONS { \ -# RUN: _aaa = ALIGNOF(.foo); \ -# RUN: }" > %t.script -# RUN: not ld.lld -o %t1 --script %t.script %t 2>&1 \ -# RUN: | FileCheck -check-prefix=ERR %s -# ERR: {{.*}}.script:1: undefined section .foo -.global _start -_start: - nop - -.section .aaa,"a" - .align 8 - .quad 0 - -.section .bbb,"a" - .align 16 - .quad 0 - -.section .ccc,"a" - .align 32 - .quad 0 diff --git a/test/ELF/linkerscript/alignof.test b/test/ELF/linkerscript/alignof.test new file mode 100644 index 000000000000..0e3abf6133c9 --- /dev/null +++ b/test/ELF/linkerscript/alignof.test @@ -0,0 +1,24 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/alignof.s -o %t +# RUN: ld.lld -o %t1 --script %s %t +# RUN: llvm-objdump -t %t1 | FileCheck %s +# CHECK: SYMBOL TABLE: +# CHECK: 0000000000000008 *ABS* 00000000 _aaa +# CHECK-NEXT: 0000000000000010 *ABS* 00000000 _bbb +# CHECK-NEXT: 0000000000000020 *ABS* 00000000 _ccc + +SECTIONS { + .aaa : { *(.aaa) } + .bbb : { *(.bbb) } + .ccc : { *(.ccc) } + _aaa = ALIGNOF(.aaa); + _bbb = ALIGNOF(.bbb); + _ccc = ALIGNOF(.ccc); +} + +## Check that we error out if trying to get alignment of +## section that does not exist. +# RUN: echo "SECTIONS { _aaa = ALIGNOF(.foo); }" > %t.script +# RUN: not ld.lld -o %t1 --script %t.script %t 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR %s +# ERR: {{.*}}.script:1: undefined section .foo diff --git a/test/ELF/linkerscript/arm-exidx-order.s b/test/ELF/linkerscript/arm-exidx-order.s deleted file mode 100644 index 1ff1711e60be..000000000000 --- a/test/ELF/linkerscript/arm-exidx-order.s +++ /dev/null @@ -1,19 +0,0 @@ -# REQUIRES: arm -# RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o -# RUN: echo "SECTIONS { . = SIZEOF_HEADERS; \ -# RUN: .ARM.exidx : { *(.ARM.exidx*) } \ -# RUN: .foo : { _foo = 0; } }" > %t.script -# RUN: ld.lld -T %t.script %t.o -shared -o %t.so -# RUN: llvm-readobj -s %t.so | FileCheck %s - -# CHECK: Section { -# CHECK: Index: -# CHECK: Name: .foo -# CHECK-NEXT: Type: SHT_NOBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] - -.fnstart -.cantunwind -.fnend diff --git a/test/ELF/linkerscript/arm-exidx-order.test b/test/ELF/linkerscript/arm-exidx-order.test new file mode 100644 index 000000000000..60abddfd77da --- /dev/null +++ b/test/ELF/linkerscript/arm-exidx-order.test @@ -0,0 +1,19 @@ +# REQUIRES: arm +# RUN: echo ".fnstart; .cantunwind; .fnend" \ +# RUN: | llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi - -o %t.o +# RUN: ld.lld -T %s %t.o -shared -o %t.so +# RUN: llvm-readobj -s %t.so | FileCheck %s + +SECTIONS { + . = SIZEOF_HEADERS; + .ARM.exidx : { *(.ARM.exidx*) } + .foo : { _foo = 0; } +} + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .foo +# CHECK-NEXT: Type: SHT_NOBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] diff --git a/test/ELF/linkerscript/arm-exidx-phdrs.s b/test/ELF/linkerscript/arm-exidx-phdrs.s deleted file mode 100644 index 971702f55d7b..000000000000 --- a/test/ELF/linkerscript/arm-exidx-phdrs.s +++ /dev/null @@ -1,16 +0,0 @@ -// REQUIRES: arm -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o -// RUN: echo "PHDRS { ph_text PT_LOAD; } \ -// RUN: SECTIONS { \ -// RUN: . = SIZEOF_HEADERS; \ -// RUN: .text : { *(.text) } : ph_text \ -// RUN: }" > %t.script -// RUN: ld.lld -T %t.script %t.o -shared -o %t.so -// RUN: llvm-readobj --program-headers %t.so | FileCheck %s - -// CHECK: Type: PT_ARM_EXIDX - -.fnstart -bx lr -.cantunwind -.fnend diff --git a/test/ELF/linkerscript/arm-exidx-phdrs.test b/test/ELF/linkerscript/arm-exidx-phdrs.test new file mode 100644 index 000000000000..208d4d72ad43 --- /dev/null +++ b/test/ELF/linkerscript/arm-exidx-phdrs.test @@ -0,0 +1,13 @@ +# REQUIRES: arm +# RUN: echo ".fnstart; bx lr; .cantunwind; .fnend" \ +# RUN: | llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi - -o %t.o +# RUN: ld.lld -T %s %t.o -shared -o %t.so +# RUN: llvm-readobj --program-headers %t.so | FileCheck %s + +# CHECK: Type: PT_ARM_EXIDX + +PHDRS { ph_text PT_LOAD; } +SECTIONS { + . = SIZEOF_HEADERS; + .text : { *(.text) } : ph_text +} diff --git a/test/ELF/linkerscript/arm-lscript.s b/test/ELF/linkerscript/arm-lscript.s deleted file mode 100644 index c377764e9776..000000000000 --- a/test/ELF/linkerscript/arm-lscript.s +++ /dev/null @@ -1,9 +0,0 @@ -// REQUIRES: arm -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o -// RUN: echo "SECTIONS { \ -// RUN: .rel.dyn : { } \ -// RUN: .zed : { PROVIDE_HIDDEN (foobar = .); } \ -// RUN: }" > %t.script -// This is a test case for PR33029. Making sure that linker can digest -// the above script without dumping core. -// RUN: ld.lld -emit-relocs -T %t.script %t.o -shared -o %t.so diff --git a/test/ELF/linkerscript/arm-lscript.test b/test/ELF/linkerscript/arm-lscript.test new file mode 100644 index 000000000000..af2e6316ea43 --- /dev/null +++ b/test/ELF/linkerscript/arm-lscript.test @@ -0,0 +1,11 @@ +# REQUIRES: arm +# RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi /dev/null -o %t.o + +# This is a test case for PR33029. Making sure that linker can digest +# the above script without dumping core. +# RUN: ld.lld -emit-relocs -T %s %t.o -shared -o %t.so + +SECTIONS { + .rel.dyn : {} + .zed : { PROVIDE_HIDDEN (foobar = .); } +} diff --git a/test/ELF/linkerscript/assert.s b/test/ELF/linkerscript/assert.s index 73cc940669b9..f7113e5b25f0 100644 --- a/test/ELF/linkerscript/assert.s +++ b/test/ELF/linkerscript/assert.s @@ -6,7 +6,7 @@ # RUN: llvm-readobj %t1 > /dev/null # RUN: echo "SECTIONS { ASSERT(0, fail) }" > %t3.script -# RUN: not ld.lld -shared -o %t3 --script %t3.script %t1.o > %t.log 2>&1 +# RUN: not ld.lld -shared -o /dev/null --script %t3.script %t1.o > %t.log 2>&1 # RUN: FileCheck %s -check-prefix=FAIL < %t.log # FAIL: fail @@ -30,10 +30,11 @@ # RUN: ld.lld -shared -o %t6 --script %t6.script %t1.o # RUN: llvm-readobj %t6 > /dev/null +## Unlike the GNU ld, we accept the ASSERT without the semicolon. +## It is consistent with how ASSERT can be written outside of the +## output section declaration. # RUN: echo "SECTIONS { .foo : { ASSERT(1, \"true\") } }" > %t7.script -# RUN: not ld.lld -shared -o %t7 --script %t7.script %t1.o > %t.log 2>&1 -# RUN: FileCheck %s -check-prefix=CHECK-SEMI < %t.log -# CHECK-SEMI: error: {{.*}}.script:1: ; expected, but got } +# RUN: ld.lld -shared -o /dev/null --script %t7.script %t1.o .section .foo, "a" .quad 0 diff --git a/test/ELF/linkerscript/at-self-reference.s b/test/ELF/linkerscript/at-self-reference.s new file mode 100644 index 000000000000..7208a4b9fcd4 --- /dev/null +++ b/test/ELF/linkerscript/at-self-reference.s @@ -0,0 +1,63 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: . = 0x1000; \ +# RUN: .aaa : AT(ADDR(.aaa)) { *(.aaa) } \ +# RUN: .bbb : AT(ADDR(.bbb)) { *(.bbb) } \ +# RUN: }" > %t.script +# RUN: ld.lld %t --script %t.script -o %t2 +# RUN: llvm-readobj -program-headers %t2 | FileCheck %s + +# CHECK: ProgramHeaders [ +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD (0x1) +# CHECK-NEXT: Offset: 0x1000 +# CHECK-NEXT: VirtualAddress: 0x1000 +# CHECK-NEXT: PhysicalAddress: 0x1000 +# CHECK-NEXT: FileSize: 3 +# CHECK-NEXT: MemSize: 3 +# CHECK-NEXT: Flags [ (0x5) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: PF_X (0x1) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 4096 +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD (0x1) +# CHECK-NEXT: Offset: 0x1008 +# CHECK-NEXT: VirtualAddress: 0x1008 +# CHECK-NEXT: PhysicalAddress: 0x1008 +# CHECK-NEXT: FileSize: 9 +# CHECK-NEXT: MemSize: 9 +# CHECK-NEXT: Flags [ (0x5) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: PF_X (0x1) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 4096 +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_GNU_STACK (0x6474E551) +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x0 +# CHECK-NEXT: PhysicalAddress: 0x0 +# CHECK-NEXT: FileSize: 0 +# CHECK-NEXT: MemSize: 0 +# CHECK-NEXT: Flags [ (0x6) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: PF_W (0x2) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 0 +# CHECK-NEXT: } +# CHECK-NEXT:] + +.global _start +_start: + nop + + +.section .aaa, "a" +.asciz "aa" + +.section .bbb, "a" +.align 8 +.quad 0 diff --git a/test/ELF/linkerscript/at2.test b/test/ELF/linkerscript/at2.test new file mode 100644 index 000000000000..82c9ae1d2252 --- /dev/null +++ b/test/ELF/linkerscript/at2.test @@ -0,0 +1,58 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/at2.s -o %t.o +# RUN: ld.lld -o %t.exe %t.o --script %s +# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s +# RUN: llvm-objdump -section-headers %t.exe | FileCheck %s --check-prefix=SECTIONS + +MEMORY { + AX (ax) : ORIGIN = 0x2000, LENGTH = 0x100 + AW (aw) : ORIGIN = 0x3000, LENGTH = 0x100 + FLASH (ax) : ORIGIN = 0x6000, LENGTH = 0x100 + RAM (aw) : ORIGIN = 0x7000, LENGTH = 0x100 +} + +SECTIONS { + .foo1 : { *(.foo1) } > AX AT>FLASH + .foo2 : { *(.foo2) } > AX + .bar1 : { *(.bar1) } > AW AT> RAM + .bar2 : { *(.bar2) } > AW AT > RAM + .bar3 : { *(.bar3) } > AW AT >RAM +} + +# CHECK: ProgramHeaders [ +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x1000 +# CHECK-NEXT: VirtualAddress: 0x2000 +# CHECK-NEXT: PhysicalAddress: 0x6000 +# CHECK-NEXT: FileSize: 16 +# CHECK-NEXT: MemSize: 16 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_X +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x2000 +# CHECK-NEXT: VirtualAddress: 0x3000 +# CHECK-NEXT: PhysicalAddress: 0x7000 +# CHECK-NEXT: FileSize: 24 +# CHECK-NEXT: MemSize: 24 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_W +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 4096 +# CHECK-NEXT: } + +# SECTIONS: Sections: +# SECTIONS-NEXT: Idx Name Size Address +# SECTIONS-NEXT: 0 00000000 0000000000000000 +# SECTIONS-NEXT: 1 .foo1 00000008 0000000000002000 +# SECTIONS-NEXT: 2 .foo2 00000008 0000000000002008 +# SECTIONS-NEXT: 3 .text 00000000 0000000000002010 +# SECTIONS-NEXT: 4 .bar1 00000008 0000000000003000 +# SECTIONS-NEXT: 5 .bar2 00000008 0000000000003008 +# SECTIONS-NEXT: 6 .bar3 00000008 0000000000003010 diff --git a/test/ELF/linkerscript/at3.test b/test/ELF/linkerscript/at3.test new file mode 100644 index 000000000000..6344f38b304d --- /dev/null +++ b/test/ELF/linkerscript/at3.test @@ -0,0 +1,31 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/at3.s -o %t.o +# RUN: ld.lld %t.o --script %s -o %t +# RUN: llvm-readelf -sections -program-headers %t | FileCheck %s + +MEMORY { + FOO (ax) : ORIGIN = 0x1000, LENGTH = 0x100 + BAR (ax) : ORIGIN = 0x2000, LENGTH = 0x100 + ZED (ax) : ORIGIN = 0x3000, LENGTH = 0x100 + FLASH (ax) : ORIGIN = 0x6000, LENGTH = 0x200 +} + +SECTIONS { + .foo1 : { *(.foo1) } > FOO AT>FLASH + .foo2 : { *(.foo2) BYTE(0x42) } > BAR AT>FLASH + .foo3 : { *(.foo3) } > ZED AT>FLASH +} + +# CHECK: .foo1 PROGBITS 0000000000001000 001000 +# CHECK: .foo2 PROGBITS 0000000000002000 002000 +# CHECK: .foo3 PROGBITS 0000000000003000 003000 + +# CHECK: Program Headers: +# CHECK-NOT: LOAD + +# CHECK: Type Offset VirtAddr PhysAddr +# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000006000 +# CHECK-NEXT: LOAD 0x002000 0x0000000000002000 0x0000000000006008 +# CHECK-NEXT: LOAD 0x003000 0x0000000000003000 0x0000000000006011 + +# CHECK-NOT: LOAD diff --git a/test/ELF/linkerscript/at4.s b/test/ELF/linkerscript/at4.s new file mode 100644 index 000000000000..a6fa50820376 --- /dev/null +++ b/test/ELF/linkerscript/at4.s @@ -0,0 +1,36 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: . = 0x1000; \ +# RUN: .aaa : { *(.aaa) } \ +# RUN: .bbb : AT(0x2008) { *(.bbb) } \ +# RUN: .ccc : { *(.ccc) } \ +# RUN: }" > %t.script +# RUN: ld.lld %t --script %t.script -o %t2 +# RUN: llvm-readobj -program-headers %t2 | FileCheck %s + +# CHECK: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x1000 +# CHECK-NEXT: VirtualAddress: 0x1000 +# CHECK-NEXT: PhysicalAddress: 0x1000 +# CHECK-NEXT: FileSize: 8 +# CHECK-NEXT: MemSize: 8 +# CHECK: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x1008 +# CHECK-NEXT: VirtualAddress: 0x1008 +# CHECK-NEXT: PhysicalAddress: 0x2008 +# CHECK-NEXT: FileSize: 17 +# CHECK-NEXT: MemSize: 17 + +.global _start +_start: + nop + +.section .aaa, "a" +.quad 0 + +.section .bbb, "a" +.quad 0 + +.section .ccc, "a" +.quad 0 diff --git a/test/ELF/linkerscript/at5.test b/test/ELF/linkerscript/at5.test new file mode 100644 index 000000000000..8e1ed93bcad9 --- /dev/null +++ b/test/ELF/linkerscript/at5.test @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: not ld.lld -o %t.exe %t.o --script %s 2>&1 | FileCheck %s + +MEMORY { + FLASH (ax) : ORIGIN = 0x2000, LENGTH = 0x100 + RAM (aw) : ORIGIN = 0x5000, LENGTH = 0x100 +} + +SECTIONS { + .foo1 : AT(0x500) { *(.foo1) } > FLASH AT>FLASH +} + +# CHECK: error: section can't have both LMA and a load region diff --git a/test/ELF/linkerscript/broken-memory-declaration.s b/test/ELF/linkerscript/broken-memory-declaration.s new file mode 100644 index 000000000000..197c9cd22b6d --- /dev/null +++ b/test/ELF/linkerscript/broken-memory-declaration.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 + +## Check we do not crash. + +# RUN: echo "MEMORY { FLASH (rx) : ORIGIN = 0x1000< LENGTH" > %t.script +# RUN: not ld.lld -o %t --script %t.script 2>&1 | FileCheck %s +# CHECK: unexpected EOF + +# RUN: echo "MEMORY { FLASH (rx) : ORIGIN = 0x1000< ORIGIN" > %t.script +# RUN: not ld.lld -o %t --script %t.script 2>&1 | FileCheck %s + +# RUN: echo "MEMORY { FLASH (rx) : ORIGIN = 0x1000, LENGTH = CONSTANT" > %t.script +# RUN: not ld.lld -o %t --script %t.script 2>&1 | FileCheck %s diff --git a/test/ELF/linkerscript/bss-fill.s b/test/ELF/linkerscript/bss-fill.s deleted file mode 100644 index 92f9fdf56190..000000000000 --- a/test/ELF/linkerscript/bss-fill.s +++ /dev/null @@ -1,7 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "SECTIONS { .bss : { . += 0x10000; *(.bss) } =0xFF };" > %t.script -# RUN: ld.lld -o %t --script %t.script %t.o - -.section .bss,"",@nobits -.short 0 diff --git a/test/ELF/linkerscript/bss-fill.test b/test/ELF/linkerscript/bss-fill.test new file mode 100644 index 000000000000..b7ed47656172 --- /dev/null +++ b/test/ELF/linkerscript/bss-fill.test @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: echo '.section .bss,"",@nobits; .short 0' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o +# RUN: ld.lld -o %t --script %s %t.o + +## Check we do not crash. + +SECTIONS { + .bss : { + . += 0x10000; + *(.bss) + } =0xFF +} diff --git a/test/ELF/linkerscript/common-filespec.s b/test/ELF/linkerscript/common-filespec.test index 25bb486ed445..2afd91d3d5b7 100644 --- a/test/ELF/linkerscript/common-filespec.s +++ b/test/ELF/linkerscript/common-filespec.test @@ -1,11 +1,17 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tfile0.o +# RUN: echo '.long 0; .comm common_uniq_0,4,4; .comm common_multiple,8,8' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %tfile0.o # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/common-filespec1.s -o %tfile1.o # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/common-filespec2.s -o %tfile2.o -# RUN: echo "SECTIONS { .common_0 : { *file0.o(COMMON) } .common_1 : { *file1.o(COMMON) } .common_2 : { *file2.o(COMMON) } }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %tfile0.o %tfile1.o %tfile2.o +# RUN: ld.lld -o %t1 --script %s %tfile0.o %tfile1.o %tfile2.o # RUN: llvm-readobj -s -t %t1 | FileCheck %s +SECTIONS { + .common_0 : { *file0.o(COMMON) } + .common_1 : { *file1.o(COMMON) } + .common_2 : { *file2.o(COMMON) } +} + # Make sure all 3 sections are allocated and they have sizes and alignments # corresponding to the commons assigned to them # CHECK: Section { @@ -96,10 +102,3 @@ # CHECK-NEXT: Other: 0 # CHECK-NEXT: Section: .common_2 # CHECK-NEXT: } - -.globl _start -_start: - jmp _start - -.comm common_uniq_0,4,4 -.comm common_multiple,8,8 diff --git a/test/ELF/linkerscript/compress-debug-sections-custom.s b/test/ELF/linkerscript/compress-debug-sections-custom.s new file mode 100644 index 000000000000..31fdd56381b0 --- /dev/null +++ b/test/ELF/linkerscript/compress-debug-sections-custom.s @@ -0,0 +1,35 @@ +# REQUIRES: x86, zlib + +# RUN: echo "SECTIONS { \ +# RUN: .text : { . += 0x10; *(.text) } \ +# RUN: .debug_str : { . += 0x10; *(.debug_str) } \ +# RUN: .debug_info : { . += 0x10; *(.debug_info) } \ +# RUN: }" > %t.script + +# 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/../Inputs/compress-debug.s -o %t2.o +# RUN: ld.lld %t2.o %t.o -o %t1 --compress-debug-sections=zlib -T %t.script +# RUN: llvm-dwarfdump %t1 -debug-str | FileCheck %s +# These two checks correspond to the patched values of a_sym and a_debug_sym. +# T = 0x54 - address of .text input section for this file (the start address of +# .text is 0 by default, the size of the preceding .text in the other input +# file is 0x44, and the linker script adds an additional 0x10). +# S = 0x53 - offset of .debug_info section for this file (the size of +# the preceding .debug_info from the other input file is 0x43, and the +# linker script adds an additional 0x10). +# Also note that the .debug_str offsets are also offset by 0x10, as directed by +# the linker script. +# CHECK: 0x00000010: "T" +# CHECK: 0x00000014: "S" + +.text +a_sym: +nop + +.section .debug_str,"",@progbits +.long a_sym +.long a_debug_sym + +.section .debug_info,"",@progbits +a_debug_sym: +.long 0x88776655 diff --git a/test/ELF/linkerscript/constructor.s b/test/ELF/linkerscript/constructor.test index acb86fd88e27..edd2cd297997 100644 --- a/test/ELF/linkerscript/constructor.s +++ b/test/ELF/linkerscript/constructor.test @@ -1,7 +1,7 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "SECTIONS { foo : { *(.foo) CONSTRUCTORS } }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t.o +# RUN: echo '.section foo, "a"; .byte 0' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o +# RUN: ld.lld -o %t1 --script %s %t.o # RUN: llvm-objdump -section-headers %t1 | FileCheck %s # CHECK: Sections: @@ -9,5 +9,9 @@ # CHECK-NEXT: 0 00000000 # CHECK-NEXT: 1 foo 00000001 -.section foo, "a" -.byte 0 +SECTIONS { + foo : { + *(.foo) + CONSTRUCTORS + } +} diff --git a/test/ELF/linkerscript/copy-rel-symbol-value-err.s b/test/ELF/linkerscript/copy-rel-symbol-value-err.s index f134edbb1d0c..cd5262b142f5 100644 --- a/test/ELF/linkerscript/copy-rel-symbol-value-err.s +++ b/test/ELF/linkerscript/copy-rel-symbol-value-err.s @@ -3,7 +3,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/copy-rel-symbol-value.s -o %t2.o # RUN: ld.lld %t2.o -o %t2.so -shared # RUN: echo "SECTIONS { . = . + SIZEOF_HEADERS; foo = bar; }" > %t.script -# RUN: not ld.lld %t.o %t2.so --script %t.script -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o %t2.so --script %t.script -o /dev/null 2>&1 | FileCheck %s # CHECK: symbol not found: bar diff --git a/test/ELF/linkerscript/data-commands-gc.s b/test/ELF/linkerscript/data-commands-gc.s index 1afcc9a3bb81..6d5ae8c9ef9d 100644 --- a/test/ELF/linkerscript/data-commands-gc.s +++ b/test/ELF/linkerscript/data-commands-gc.s @@ -4,7 +4,7 @@ # RUN: ld.lld --gc-sections -o %t %t.o --script %t.script # RUN: llvm-objdump -t %t | FileCheck %s -# CHECK: 0000000000000011 .rodata 00000000 bar +# CHECK: 0000000000000008 .rodata 00000000 bar .section .rodata.bar .quad 0x1122334455667788 diff --git a/test/ELF/linkerscript/data-commands.s b/test/ELF/linkerscript/data-commands.s deleted file mode 100644 index 5a5655620dd9..000000000000 --- a/test/ELF/linkerscript/data-commands.s +++ /dev/null @@ -1,117 +0,0 @@ -# REQUIRES: x86,mips -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "SECTIONS \ -# RUN: { \ -# RUN: .foo : { \ -# RUN: *(.foo.1) \ -# RUN: BYTE(0x11) \ -# RUN: *(.foo.2) \ -# RUN: SHORT(0x1122) \ -# RUN: *(.foo.3) \ -# RUN: LONG(0x11223344) \ -# RUN: *(.foo.4) \ -# RUN: QUAD(0x1122334455667788) \ -# RUN: } \ -# RUN: .bar : { \ -# RUN: *(.bar.1) \ -# RUN: BYTE(a + 1) \ -# RUN: *(.bar.2) \ -# RUN: SHORT(b) \ -# RUN: *(.bar.3) \ -# RUN: LONG(c + 2) \ -# RUN: *(.bar.4) \ -# RUN: QUAD(d) \ -# RUN: } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t %t.o --script %t.script -# RUN: llvm-objdump -s %t | FileCheck %s - -# CHECK: Contents of section .foo: -# CHECK-NEXT: ff11ff22 11ff4433 2211ff88 77665544 -# CHECK-NEXT: 332211 - -# CHECK: Contents of section .bar: -# CHECK-NEXT: ff12ff22 11ff4633 2211ff88 77665544 -# CHECK-NEXT: 332211 - -# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %tmips64be -# RUN: ld.lld --script %t.script %tmips64be -o %t2 -# RUN: llvm-objdump -s %t2 | FileCheck %s --check-prefix=BE -# BE: Contents of section .foo: -# BE-NEXT: ff11ff11 22ff1122 3344ff11 22334455 -# BE-NEXT: 667788 -# BE-NEXT: Contents of section .bar: -# BE-NEXT: ff12ff11 22ff1122 3346ff11 22334455 -# BE-NEXT: 667788 - -# RUN: echo "MEMORY { \ -# RUN: rom (rwx) : ORIGIN = 0x00, LENGTH = 2K \ -# RUN: } \ -# RUN: SECTIONS { \ -# RUN: .foo : { \ -# RUN: *(.foo.1) \ -# RUN: BYTE(0x11) \ -# RUN: *(.foo.2) \ -# RUN: SHORT(0x1122) \ -# RUN: *(.foo.3) \ -# RUN: LONG(0x11223344) \ -# RUN: *(.foo.4) \ -# RUN: QUAD(0x1122334455667788) \ -# RUN: } > rom \ -# RUN: .bar : { \ -# RUN: *(.bar.1) \ -# RUN: BYTE(a + 1) \ -# RUN: *(.bar.2) \ -# RUN: SHORT(b) \ -# RUN: *(.bar.3) \ -# RUN: LONG(c + 2) \ -# RUN: *(.bar.4) \ -# RUN: QUAD(d) \ -# RUN: } > rom \ -# RUN: }" > %t-memory.script -# RUN: ld.lld -o %t-memory %t.o --script %t-memory.script -# RUN: llvm-objdump -s %t-memory | FileCheck %s --check-prefix=MEM - -# MEM: Contents of section .foo: -# MEM-NEXT: 0000 ff11ff22 11ff4433 2211ff88 77665544 -# MEM-NEXT: 0010 332211 - -# MEM: Contents of section .bar: -# MEM-NEXT: 0013 ff12ff22 11ff4633 2211ff88 77665544 -# MEM-NEXT: 0023 332211 - -.global a -a = 0x11 - -.global b -b = 0x1122 - -.global c -c = 0x11223344 - -.global d -d = 0x1122334455667788 - -.section .foo.1, "a" - .byte 0xFF - -.section .foo.2, "a" - .byte 0xFF - -.section .foo.3, "a" - .byte 0xFF - -.section .foo.4, "a" - .byte 0xFF - -.section .bar.1, "a" - .byte 0xFF - -.section .bar.2, "a" - .byte 0xFF - -.section .bar.3, "a" - .byte 0xFF - -.section .bar.4, "a" - .byte 0xFF diff --git a/test/ELF/linkerscript/data-commands1.test b/test/ELF/linkerscript/data-commands1.test new file mode 100644 index 000000000000..32c5978c30a8 --- /dev/null +++ b/test/ELF/linkerscript/data-commands1.test @@ -0,0 +1,45 @@ +# REQUIRES: x86,mips +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/data-commands.s -o %t.o +# RUN: ld.lld -o %t %t.o --script %s +# RUN: llvm-objdump -s %t | FileCheck %s + +SECTIONS { + .foo : { + *(.foo.1) + BYTE(0x11) + *(.foo.2) + SHORT(0x1122) + *(.foo.3) + LONG(0x11223344) + *(.foo.4) + QUAD(0x1122334455667788) + } + .bar : { + *(.bar.1) + BYTE(a + 1) + *(.bar.2) + SHORT(b) + *(.bar.3) + LONG(c + 2) + *(.bar.4) + QUAD(d) + } +} + +# CHECK: Contents of section .foo: +# CHECK-NEXT: ff11ff22 11ff4433 2211ff88 77665544 +# CHECK-NEXT: 332211 + +# CHECK: Contents of section .bar: +# CHECK-NEXT: ff12ff22 11ff4633 2211ff88 77665544 +# CHECK-NEXT: 332211 + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %p/Inputs/data-commands.s -o %t2.o +# RUN: ld.lld --script %s %t2.o -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=BIGENDIAN %s +# BIGENDIAN: Contents of section .foo: +# BIGENDIAN-NEXT: ff11ff11 22ff1122 3344ff11 22334455 +# BIGENDIAN-NEXT: 667788 +# BIGENDIAN-NEXT: Contents of section .bar: +# BIGENDIAN-NEXT: ff12ff11 22ff1122 3346ff11 22334455 +# BIGENDIAN-NEXT: 667788 diff --git a/test/ELF/linkerscript/data-commands2.test b/test/ELF/linkerscript/data-commands2.test new file mode 100644 index 000000000000..e1efa35965cb --- /dev/null +++ b/test/ELF/linkerscript/data-commands2.test @@ -0,0 +1,40 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/data-commands.s -o %t.o +# RUN: ld.lld -o %t %t.o --script %s +# RUN: llvm-objdump -s %t | FileCheck %s + +MEMORY { + rom (rwx) : ORIGIN = 0x00, LENGTH = 2K +} + +SECTIONS { + .foo : { + *(.foo.1) + BYTE(0x11) + *(.foo.2) + SHORT(0x1122) + *(.foo.3) + LONG(0x11223344) + *(.foo.4) + QUAD(0x1122334455667788) + } > rom + + .bar : { + *(.bar.1) + BYTE(a + 1) + *(.bar.2) + SHORT(b) + *(.bar.3) + LONG(c + 2) + *(.bar.4) + QUAD(d) + } > rom +} + +# CHECK: Contents of section .foo: +# CHECK-NEXT: 0000 ff11ff22 11ff4433 2211ff88 77665544 +# CHECK-NEXT: 0010 332211 + +# CHECK: Contents of section .bar: +# CHECK-NEXT: 0013 ff12ff22 11ff4633 2211ff88 77665544 +# CHECK-NEXT: 0023 332211 diff --git a/test/ELF/linkerscript/data-segment-relro.s b/test/ELF/linkerscript/data-segment-relro.test index e835f42e22c6..aeaf08540871 100644 --- a/test/ELF/linkerscript/data-segment-relro.s +++ b/test/ELF/linkerscript/data-segment-relro.test @@ -1,29 +1,37 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/data-segment-relro.s -o %t1.o # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o # RUN: ld.lld -shared %t2.o -o %t2.so -# RUN: echo "SECTIONS { \ -# RUN: . = SIZEOF_HEADERS; \ -# RUN: .plt : { *(.plt) } \ -# RUN: .text : { *(.text) } \ -# RUN: . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); \ -# RUN: .dynamic : { *(.dynamic) } \ -# RUN: .got : { *(.got) } \ -# RUN: . = DATA_SEGMENT_RELRO_END (1 ? 24 : 0, .); \ -# RUN: .got.plt : { *(.got.plt) } \ -# RUN: .data : { *(.data) } \ -# RUN: .bss : { *(.bss) } \ -# RUN: . = DATA_SEGMENT_END (.); \ -# RUN: }" > %t.script - ## With relro or without DATA_SEGMENT_RELRO_END just aligns to ## page boundary. -# RUN: ld.lld --hash-style=sysv -z norelro %t1.o %t2.so --script %t.script -o %t + +# RUN: ld.lld --hash-style=sysv -z norelro %t1.o %t2.so --script %s -o %t # RUN: llvm-readobj -s %t | FileCheck %s -# RUN: ld.lld --hash-style=sysv -z relro %t1.o %t2.so --script %t.script -o %t2 + +# RUN: ld.lld --hash-style=sysv -z relro %t1.o %t2.so --script %s -o %t2 # RUN: llvm-readobj -s %t2 | FileCheck %s +SECTIONS { + . = SIZEOF_HEADERS; + + .plt : { *(.plt) } + .text : { *(.text) } + + . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); + + .dynamic : { *(.dynamic) } + .got : { *(.got) } + + . = DATA_SEGMENT_RELRO_END (1 ? 24 : 0, .); + + .got.plt : { *(.got.plt) } + .data : { *(.data) } + .bss : { *(.bss) } + + . = DATA_SEGMENT_END (.); +} + # CHECK: Section { # CHECK: Index: # CHECK: Name: .got @@ -56,15 +64,3 @@ # CHECK-NEXT: AddressAlignment: # CHECK-NEXT: EntrySize: # CHECK-NEXT: } - -.global _start -_start: - .long bar - jmp *bar2@GOTPCREL(%rip) - -.section .data,"aw" -.quad 0 - -.zero 4 -.section .foo,"aw" -.section .bss,"",@nobits diff --git a/test/ELF/linkerscript/define.s b/test/ELF/linkerscript/define.s deleted file mode 100644 index b5f0b76e9e6b..000000000000 --- a/test/ELF/linkerscript/define.s +++ /dev/null @@ -1,25 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -# RUN: echo "SECTIONS \ -# RUN: { \ -# RUN: . = DEFINED(defined) ? 0x11000 : .; \ -# RUN: .foo : { *(.foo*) } \ -# RUN: . = DEFINED(notdefined) ? 0x12000 : 0x13000; \ -# RUN: .bar : { *(.bar*) } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -# RUN: llvm-objdump -section-headers %t1 | FileCheck %s - -# CHECK: 1 .foo 00000008 0000000000011000 DATA -# CHECK: 2 .bar 00000008 0000000000013000 DATA -# CHECK: 3 .text 00000000 0000000000013008 TEXT DATA - -.global defined -defined = 0 - -.section .foo,"a" -.quad 1 - -.section .bar,"a" -.quad 1 diff --git a/test/ELF/linkerscript/define.test b/test/ELF/linkerscript/define.test new file mode 100644 index 000000000000..3a2e242e015c --- /dev/null +++ b/test/ELF/linkerscript/define.test @@ -0,0 +1,15 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/define.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +SECTIONS { + . = DEFINED(defined) ? 0x11000 : .; + .foo : { *(.foo*) } + . = DEFINED(notdefined) ? 0x12000 : 0x13000; + .bar : { *(.bar*) } +} + +# CHECK: 1 .foo 00000008 0000000000011000 DATA +# CHECK: 2 .bar 00000008 0000000000013000 DATA +# CHECK: 3 .text 00000000 0000000000013008 TEXT diff --git a/test/ELF/linkerscript/defsym.s b/test/ELF/linkerscript/defsym.s new file mode 100644 index 000000000000..467adaeea2f8 --- /dev/null +++ b/test/ELF/linkerscript/defsym.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "foo = 0x22;" > %t.script + +## This testcase checks that we apply -defsym and linker script +## in the same order are they specified in a command line. + +## Check that linker script can override -defsym assignments. +# RUN: ld.lld %t.o -defsym=foo=0x11 -script %t.script -o %t +# RUN: llvm-readobj -t %t | FileCheck %s +# CHECK: Name: foo +# CHECK-NEXT: Value: 0x22 + +## Check that -defsym can override linker script. Check that multiple +## -defsym commands for the same symbol are allowed. +# RUN: ld.lld %t.o -script %t.script -defsym=foo=0x11 -defsym=foo=0x33 -o %t +# RUN: llvm-readobj -t %t | FileCheck %s --check-prefix=REORDER +# REORDER: Name: foo +# REORDER-NEXT: Value: 0x33 diff --git a/test/ELF/linkerscript/diag1.test b/test/ELF/linkerscript/diag1.test new file mode 100644 index 000000000000..73a627ff4ef5 --- /dev/null +++ b/test/ELF/linkerscript/diag1.test @@ -0,0 +1,15 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: not ld.lld -shared %t.o -o %t --script %s 2>&1 | FileCheck -strict-whitespace %s + +SECTIONS { + .text + { *(.text) } + .keep : { *(.keep) } /* + comment line 1 + comment line 2 */ + .temp : { *(.temp) } +} + +CHECK: 6: malformed number: + +CHECK-NEXT: >>> .text + { *(.text) } +CHECK-NEXT: >>> ^ diff --git a/test/ELF/linkerscript/diag2.test b/test/ELF/linkerscript/diag2.test new file mode 100644 index 000000000000..05cd4c3a752a --- /dev/null +++ b/test/ELF/linkerscript/diag2.test @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: not ld.lld -shared %t.o -o %t --script %s 2>&1 | FileCheck -strict-whitespace %s + +UNKNOWN_TAG { + .text : { *(.text) } + .keep : { *(.keep) } + .temp : { *(.temp) } +} + +CHECK: 5: unknown directive: UNKNOWN_TAG +CHECK-NEXT: >>> UNKNOWN_TAG { +CHECK-NEXT: >>> ^ diff --git a/test/ELF/linkerscript/diag3.test b/test/ELF/linkerscript/diag3.test new file mode 100644 index 000000000000..8ffc9d4d864c --- /dev/null +++ b/test/ELF/linkerscript/diag3.test @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: not ld.lld -shared %t.o -o %t --script %s 2>&1 | FileCheck -strict-whitespace %s + +SECTIONS { + .text : { *(.text) } + .keep : { *(.keep) } + boom .temp : { *(.temp) } +} + +# CHECK: 8: malformed number: .temp +# CHECK-NEXT: >>> boom .temp : { *(.temp) } +# CHECK-NEXT: >>> ^ diff --git a/test/ELF/linkerscript/diag4.test b/test/ELF/linkerscript/diag4.test new file mode 100644 index 000000000000..484bdf26fe72 --- /dev/null +++ b/test/ELF/linkerscript/diag4.test @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: echo "INCLUDE \"%s\"" > %t.script +# RUN: not ld.lld -shared %t.o -o %t --script %t.script 2>&1 | FileCheck -strict-whitespace %s + +SECTIONS { + .text : { *(.text) } + .keep : { *(.keep) } + boom .temp : { *(.temp) } +} + +# CHECK: 9: malformed number: .temp +# CHECK-NEXT: >>> boom .temp : { *(.temp) } +# CHECK-NEXT: >>> ^
\ No newline at end of file diff --git a/test/ELF/linkerscript/diag5.test b/test/ELF/linkerscript/diag5.test new file mode 100644 index 000000000000..38a774e747ab --- /dev/null +++ b/test/ELF/linkerscript/diag5.test @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: echo "INCLUDE \"%s\"" > %t.script +# RUN: not ld.lld -shared %t.o -o %t --script %t.script 2>&1 | FileCheck -strict-whitespace %s + +SECTIONS { + .text : { *(.text) } + .keep : { *(.keep) } + boom .temp : { *(.temp) } +} + +# CHECK: 9: malformed number: .temp +# CHECK-NEXT: >>> boom .temp : { *(.temp) } +# CHECK-NEXT: >>> ^ diff --git a/test/ELF/linkerscript/diag6.test b/test/ELF/linkerscript/diag6.test new file mode 100644 index 000000000000..e4ad4d96d1dd --- /dev/null +++ b/test/ELF/linkerscript/diag6.test @@ -0,0 +1,7 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: not ld.lld -shared %t.o -o %t --script %s 2>&1 | FileCheck %s + +SECTIONS /* + +CHECK: error: unclosed comment in a linker script diff --git a/test/ELF/linkerscript/diagnostic.s b/test/ELF/linkerscript/diagnostic.s deleted file mode 100644 index af185729c430..000000000000 --- a/test/ELF/linkerscript/diagnostic.s +++ /dev/null @@ -1,106 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -## Take some valid script with multiline comments -## and check it actually works: -# RUN: echo "SECTIONS {" > %t.script -# RUN: echo ".text : { *(.text) }" >> %t.script -# RUN: echo ".keep : { *(.keep) } /*" >> %t.script -# RUN: echo "comment line 1" >> %t.script -# RUN: echo "comment line 2 */" >> %t.script -# RUN: echo ".temp : { *(.temp) } }" >> %t.script -# RUN: ld.lld -shared %t -o %t1 --script %t.script - -## Change ":" to "+" at line 2, check that error -## message starts from correct line number: -# RUN: echo "SECTIONS {" > %t.script -# RUN: echo ".text + { *(.text) }" >> %t.script -# RUN: echo ".keep : { *(.keep) } /*" >> %t.script -# RUN: echo "comment line 1" >> %t.script -# RUN: echo "comment line 2 */" >> %t.script -# RUN: echo ".temp : { *(.temp) } }" >> %t.script -# RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | FileCheck -check-prefix=ERR1 %s -# ERR1: {{.*}}.script:2: - -## Change ":" to "+" at line 3 now, check correct error line number: -# RUN: echo "SECTIONS {" > %t.script -# RUN: echo ".text : { *(.text) }" >> %t.script -# RUN: echo ".keep + { *(.keep) } /*" >> %t.script -# RUN: echo "comment line 1" >> %t.script -# RUN: echo "comment line 2 */" >> %t.script -# RUN: echo ".temp : { *(.temp) } }" >> %t.script -# RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | FileCheck -check-prefix=ERR2 %s -# ERR2: {{.*}}.script:3: - -## Change ":" to "+" at line 6, after multiline comment, -## check correct error line number: -# RUN: echo "SECTIONS {" > %t.script -# RUN: echo ".text : { *(.text) }" >> %t.script -# RUN: echo ".keep : { *(.keep) } /*" >> %t.script -# RUN: echo "comment line 1" >> %t.script -# RUN: echo "comment line 2 */" >> %t.script -# RUN: echo ".temp + { *(.temp) } }" >> %t.script -# RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | FileCheck -check-prefix=ERR5 %s -# ERR5: {{.*}}.script:6: - -## Check that text of lines and pointer to 'bad' token are working ok. -# RUN: echo "UNKNOWN_TAG {" > %t.script -# RUN: echo ".text : { *(.text) }" >> %t.script -# RUN: echo ".keep : { *(.keep) }" >> %t.script -# RUN: echo ".temp : { *(.temp) } }" >> %t.script -# RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | \ -# RUN: FileCheck -check-prefix=ERR6 -strict-whitespace %s -# ERR6: error: {{.*}}.script:1: unknown directive: UNKNOWN_TAG -# ERR6-NEXT: >>> UNKNOWN_TAG { -# ERR6-NEXT: >>> ^ - -## One more check that text of lines and pointer to 'bad' token are working ok. -# RUN: echo "SECTIONS {" > %t.script -# RUN: echo ".text : { *(.text) }" >> %t.script -# RUN: echo ".keep : { *(.keep) }" >> %t.script -# RUN: echo "boom .temp : { *(.temp) } }" >> %t.script -# RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | \ -# RUN: FileCheck -check-prefix=ERR7 -strict-whitespace %s -# ERR7: error: {{.*}}.script:4: malformed number: .temp -# ERR7-NEXT: >>> boom .temp : { *(.temp) } } -# ERR7-NEXT: >>> ^ - -## Check tokenize() error -# RUN: echo "SECTIONS {}" > %t.script -# RUN: echo "\"" >> %t.script -# RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | \ -# RUN: FileCheck -check-prefix=ERR8 -strict-whitespace %s -# ERR8: {{.*}}.script:2: unclosed quote - -## Check tokenize() error in included script file -# RUN: echo "SECTIONS {}" > %t.script.inc -# RUN: echo "\"" >> %t.script.inc -# RUN: echo "INCLUDE \"%t.script.inc\"" > %t.script -# RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | \ -# RUN: FileCheck -check-prefix=ERR9 -strict-whitespace %s -# ERR9: {{.*}}.script.inc:2: unclosed quote - -## Check error reporting correctness for included files. -# RUN: echo "SECTIONS {" > %t.script.inc -# RUN: echo ".text : { *(.text) }" >> %t.script.inc -# RUN: echo ".keep : { *(.keep) }" >> %t.script.inc -# RUN: echo "boom .temp : { *(.temp) } }" >> %t.script.inc -# RUN: echo "INCLUDE \"%t.script.inc\"" > %t.script -# RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | \ -# RUN: FileCheck -check-prefix=ERR10 -strict-whitespace %s -# ERR10: error: {{.*}}.script.inc:4: malformed number: .temp -# ERR10-NEXT: >>> boom .temp : { *(.temp) } } -# ERR10-NEXT: >>> ^ - -## Check error reporting in script with INCLUDE directive. -# RUN: echo "SECTIONS {" > %t.script.inc -# RUN: echo ".text : { *(.text) }" >> %t.script.inc -# RUN: echo ".keep : { *(.keep) }" >> %t.script.inc -# RUN: echo ".temp : { *(.temp) } }" >> %t.script.inc -# RUN: echo "/* One line before INCLUDE */" > %t.script -# RUN: echo "INCLUDE \"%t.script.inc\"" >> %t.script -# RUN: echo "/* One line ater INCLUDE */" >> %t.script -# RUN: echo "Error" >> %t.script -# RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | \ -# RUN: FileCheck -check-prefix=ERR11 -strict-whitespace %s -# ERR11: error: {{.*}}.script:4: unexpected EOF diff --git a/test/ELF/linkerscript/discard-gnu-hash.s b/test/ELF/linkerscript/discard-gnu-hash.s new file mode 100644 index 000000000000..77f168de9caf --- /dev/null +++ b/test/ELF/linkerscript/discard-gnu-hash.s @@ -0,0 +1,23 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: ld.lld --hash-style both -shared -o %t1 %t +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s +# CHECK: .gnu.hash +# CHECK: .hash + +# RUN: echo "SECTIONS { /DISCARD/ : { *(.hash) } }" > %t.script +# RUN: ld.lld --hash-style both -shared -o %t1 --script %t.script %t +# RUN: llvm-objdump -section-headers %t1 \ +# RUN: | FileCheck %s --check-prefix=HASH +# HASH-NOT: .hash +# HASH: .gnu.hash +# HASH-NOT: .hash + +# RUN: echo "SECTIONS { /DISCARD/ : { *(.gnu.hash) } }" > %t.script +# RUN: ld.lld --hash-style both -shared -o %t1 --script %t.script %t +# RUN: llvm-objdump -section-headers %t1 \ +# RUN: | FileCheck %s --check-prefix=GNUHASH +# GNUHASH-NOT: .gnu.hash +# GNUHASH: .hash +# GNUHASH-NOT: .gnu.hash diff --git a/test/ELF/linkerscript/discard-interp.s b/test/ELF/linkerscript/discard-interp.s deleted file mode 100644 index 261509e2e76b..000000000000 --- a/test/ELF/linkerscript/discard-interp.s +++ /dev/null @@ -1,12 +0,0 @@ -// 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: echo "PHDRS { text PT_LOAD FILEHDR PHDRS; } \ -// RUN: SECTIONS { . = SIZEOF_HEADERS; .text : { *(.text) } : text }" > %t.script -// RUN: ld.lld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -rpath foo -rpath bar --script %t.script --export-dynamic %t.o %t2.so -o %t -// RUN: llvm-readobj -s %t | FileCheck %s - -// CHECK-NOT: Name: .interp - -.global _start -_start: diff --git a/test/ELF/linkerscript/discard-interp.test b/test/ELF/linkerscript/discard-interp.test new file mode 100644 index 000000000000..02e97b99958c --- /dev/null +++ b/test/ELF/linkerscript/discard-interp.test @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux /dev/null -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 -dynamic-linker foo -rpath bar -rpath baz --script %s --export-dynamic %t.o %t2.so -o %t +# RUN: llvm-readobj -s %t | FileCheck %s + +# CHECK-NOT: Name: .interp + +PHDRS { text PT_LOAD FILEHDR PHDRS; } +SECTIONS { + . = SIZEOF_HEADERS; + .text : { *(.text) } : text +} diff --git a/test/ELF/linkerscript/discard-print-gc.s b/test/ELF/linkerscript/discard-print-gc.s index 2a230e53dc2b..c9233ce7b0eb 100644 --- a/test/ELF/linkerscript/discard-print-gc.s +++ b/test/ELF/linkerscript/discard-print-gc.s @@ -15,5 +15,5 @@ .section .foo,"a" .quad 0 -# CHECK: removing unused section from '.foo' -# QUIET-NOT: removing unused section from '.foo' +# CHECK: removing unused section {{.*}}:(.foo) +# QUIET-NOT: removing unused section {{.*}}:(.foo) diff --git a/test/ELF/linkerscript/discard-section-err.s b/test/ELF/linkerscript/discard-section-err.s index 8ad5b486cb39..f1d3b96691ba 100644 --- a/test/ELF/linkerscript/discard-section-err.s +++ b/test/ELF/linkerscript/discard-section-err.s @@ -22,4 +22,14 @@ # RUN: FileCheck -check-prefix=DYNSTR %s # DYNSTR: discarding .dynstr section is not allowed +# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.plt) } }" > %t.script +# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \ +# RUN: FileCheck -check-prefix=RELAPLT %s +# RELAPLT: discarding .rela.plt section is not allowed + +# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.dyn) } }" > %t.script +# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \ +# RUN: FileCheck -check-prefix=RELADYN %s +# RELADYN: discarding .rela.dyn section is not allowed + .comm foo,4,4 diff --git a/test/ELF/linkerscript/dot-is-not-abs.s b/test/ELF/linkerscript/dot-is-not-abs.s index 4532cd59f2a1..a93d1c8b4344 100644 --- a/test/ELF/linkerscript/dot-is-not-abs.s +++ b/test/ELF/linkerscript/dot-is-not-abs.s @@ -1,9 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS { .text : { *(.text) } \ -# RUN: foo = .; \ -# RUN: .bar : { *(.bar) } }" > %t1.script +# RUN: echo "SECTIONS { .text : { *(.text) } foo = .; .bar : { *(.bar) } }" > %t1.script # RUN: ld.lld -o %t1 --script %t1.script %t.o -shared # RUN: llvm-readobj -t -s -section-data %t1 | FileCheck %s diff --git a/test/ELF/linkerscript/double-bss.s b/test/ELF/linkerscript/double-bss.s deleted file mode 100644 index c24332f5e5a6..000000000000 --- a/test/ELF/linkerscript/double-bss.s +++ /dev/null @@ -1,21 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "SECTIONS { . = SIZEOF_HEADERS; " > %t.script -# RUN: echo ".text : { *(.text*) }" >> %t.script -# RUN: echo ".bss1 : { *(.bss) }" >> %t.script -# RUN: echo ".bss2 : { *(COMMON) }" >> %t.script -# RUN: echo "}" >> %t.script - -# RUN: ld.lld -o %t1 --script %t.script %t -# RUN: llvm-objdump -section-headers %t1 | FileCheck %s -# CHECK: .bss1 00000004 0000000000000122 BSS -# CHECK-NEXT: .bss2 00000080 0000000000000128 BSS - -.globl _start -_start: - jmp _start - -.bss -.zero 4 - -.comm q,128,8 diff --git a/test/ELF/linkerscript/double-bss.test b/test/ELF/linkerscript/double-bss.test new file mode 100644 index 000000000000..32b796d01c2e --- /dev/null +++ b/test/ELF/linkerscript/double-bss.test @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: echo '.short 0; .bss; .zero 4; .comm q,128,8' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t +# RUN: ld.lld -o %t1 --script %s %t +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s +# CHECK: .bss1 00000004 0000000000000122 BSS +# CHECK-NEXT: .bss2 00000080 0000000000000128 BSS + +SECTIONS { + . = SIZEOF_HEADERS; + .text : { *(.text*) } + .bss1 : { *(.bss) } + .bss2 : { *(COMMON) } +} diff --git a/test/ELF/linkerscript/edata-etext.s b/test/ELF/linkerscript/edata-etext.s index ab723ce1316e..c15cf4c865c0 100644 --- a/test/ELF/linkerscript/edata-etext.s +++ b/test/ELF/linkerscript/edata-etext.s @@ -1,7 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: echo "SECTIONS { }" > %t.script -# RUN: not ld.lld %t.o -script %t.script -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o -script %t.script -o /dev/null 2>&1 | FileCheck %s # CHECK: error: undefined symbol: _edata # CHECK: >>> referenced by {{.*}}:(.text+0x0) # CHECK: error: undefined symbol: _etext diff --git a/test/ELF/linkerscript/eh-frame-emit-relocs.s b/test/ELF/linkerscript/eh-frame-emit-relocs.s new file mode 100644 index 000000000000..d951cbc261b9 --- /dev/null +++ b/test/ELF/linkerscript/eh-frame-emit-relocs.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: echo "SECTIONS { .foo : { *(.eh_frame) } }" > %t.script +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld --emit-relocs %t.o -T %t.script -o %t +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +# CHECK-NOT: eh_frame +# CHECK: .rela.foo +# CHECK-NOT: eh_frame + +.text + .cfi_startproc + .cfi_endproc diff --git a/test/ELF/linkerscript/eh-frame-hdr.s b/test/ELF/linkerscript/eh-frame-hdr.s index d1545be632a3..a7892b2259e0 100644 --- a/test/ELF/linkerscript/eh-frame-hdr.s +++ b/test/ELF/linkerscript/eh-frame-hdr.s @@ -1,13 +1,10 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "SECTIONS { \ -# RUN: .eh_frame_hdr : {} \ -# RUN: .eh_frame : {} \ -# RUN: }" > %t.script +# RUN: echo "SECTIONS { .eh_frame_hdr : {} .eh_frame : {} }" > %t.script # RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t # RUN: llvm-objdump -s -section=".eh_frame_hdr" %t1 | FileCheck %s -# CHECK: 011b033b 14000000 01000000 49000000 +# CHECK: 011b033b 14000000 01000000 4d000000 # CHECK-NEXT: 30000000 .global _start diff --git a/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s b/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s deleted file mode 100644 index 817e458fa5ef..000000000000 --- a/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s +++ /dev/null @@ -1,27 +0,0 @@ -## Check that error is correctly reported when .eh_frame reloc -## is out of range - -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "PHDRS { eh PT_LOAD; text PT_LOAD; } \ -# RUN: SECTIONS { . = 0x10000; \ -# RUN: .eh_frame_hdr : { *(.eh_frame_hdr*) } : eh \ -# RUN: .eh_frame : { *(.eh_frame) } : eh \ -# RUN: . = 0xF00000000; \ -# RUN: .text : { *(.text*) } : text \ -# RUN: }" > %t.script -# RUN: not ld.lld %t.o -T %t.script -o %t 2>&1 | FileCheck %s - -# CHECK: error: {{.*}}:(.eh_frame+0x20): relocation R_X86_64_PC32 out of range: 64424443872 is not in [-2147483648, 2147483647] - - .text - .globl _start -_start: - .cfi_startproc - .cfi_lsda 0, _ex - nop - .cfi_endproc - - .data -_ex: - .word 0 diff --git a/test/ELF/linkerscript/eh-frame-reloc-out-of-range.test b/test/ELF/linkerscript/eh-frame-reloc-out-of-range.test new file mode 100644 index 000000000000..7f4df21fd4c4 --- /dev/null +++ b/test/ELF/linkerscript/eh-frame-reloc-out-of-range.test @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/eh-frame-reloc-out-of-range.s -o %t.o +# RUN: not ld.lld %t.o -T %s -o %t 2>&1 | FileCheck %s + +PHDRS { eh PT_LOAD; text PT_LOAD; } +SECTIONS { . = 0x10000; + .eh_frame_hdr : { *(.eh_frame_hdr*) } : eh + .eh_frame : { *(.eh_frame) } : eh + . = 0xF00000000; + .text : { *(.text*) } : text +} + +# CHECK: error: {{.*}}:(.eh_frame+0x20): relocation R_X86_64_PC32 out of range: 64424443872 is not in [-2147483648, 2147483647] diff --git a/test/ELF/linkerscript/eh-frame.s b/test/ELF/linkerscript/eh-frame.s index 750f74eb36c6..5e43ec738f7b 100644 --- a/test/ELF/linkerscript/eh-frame.s +++ b/test/ELF/linkerscript/eh-frame.s @@ -1,8 +1,6 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "SECTIONS { \ -# RUN: .eh_frame : { *(.eh_frame) } \ -# RUN: }" > %t.script +# RUN: echo "SECTIONS { .eh_frame : { *(.eh_frame) } }" > %t.script # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -s -section=".eh_frame" %t1 | FileCheck %s diff --git a/test/ELF/linkerscript/emit-reloc-section-names.s b/test/ELF/linkerscript/emit-reloc-section-names.s index 8661ff060a79..7f76057322e8 100644 --- a/test/ELF/linkerscript/emit-reloc-section-names.s +++ b/test/ELF/linkerscript/emit-reloc-section-names.s @@ -1,7 +1,6 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS { .text.zed : { *(.text.foo) } \ -# RUN: .text.qux : { *(.text.bar) } }" > %t.script +# RUN: echo "SECTIONS { .text.zed : { *(.text.foo) } .text.qux : { *(.text.bar) } }" > %t.script # RUN: ld.lld -T %t.script --emit-relocs %t.o -o %t # RUN: llvm-objdump -section-headers %t | FileCheck %s diff --git a/test/ELF/linkerscript/emit-reloc.s b/test/ELF/linkerscript/emit-reloc.s index 2fe127af8590..43ab4e8e47d8 100644 --- a/test/ELF/linkerscript/emit-reloc.s +++ b/test/ELF/linkerscript/emit-reloc.s @@ -9,9 +9,9 @@ # CHECK: Relocations [ # CHECK-NEXT: Section ({{.*}}) .rela.dyn { -# CHECK-NEXT: 0x66 R_X86_64_64 .foo 0x0 +# CHECK-NEXT: 0x68 R_X86_64_64 .foo 0x0 # CHECK-NEXT: } # CHECK-NEXT: Section ({{.*}}) .rela.data { -# CHECK-NEXT: 0x66 R_X86_64_64 .foo 0x0 +# CHECK-NEXT: 0x68 R_X86_64_64 .foo 0x0 # CHECK-NEXT: } # CHECK-NEXT: ] diff --git a/test/ELF/linkerscript/empty-link-order.test b/test/ELF/linkerscript/empty-link-order.test new file mode 100644 index 000000000000..b63b60ca8c15 --- /dev/null +++ b/test/ELF/linkerscript/empty-link-order.test @@ -0,0 +1,21 @@ +# REQUIRES: arm +# RUN: llvm-mc -filetype=obj -triple=arm-arm-none-eabi -o %t.o < /dev/null + +SECTIONS { + .foo : { + bar = .; + *(.ARM.exidx*) + } +} + +# RUN: ld.lld %t.o -o %t --script %s + +## Check we do not crash and do not set SHF_LINK_ORDER flag for .foo +# RUN: llvm-readobj -s %t | FileCheck %s +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .foo +# CHECK-NEXT: Type: SHT_ARM_EXIDX +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] diff --git a/test/ELF/linkerscript/empty-load.s b/test/ELF/linkerscript/empty-load.s index ea58d71402d1..a2b7d8227f60 100644 --- a/test/ELF/linkerscript/empty-load.s +++ b/test/ELF/linkerscript/empty-load.s @@ -1,6 +1,6 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "SECTIONS { .rw : { *(.rw) } .text : { *(.text) } }" > %t.script +# RUN: echo "SECTIONS { .rw : { *(.rw) } .text : { *(.text) } }" > %t.script # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -private-headers %t1 | FileCheck %s diff --git a/test/ELF/linkerscript/empty-section-size.test b/test/ELF/linkerscript/empty-section-size.test new file mode 100644 index 000000000000..665ddf1ddf01 --- /dev/null +++ b/test/ELF/linkerscript/empty-section-size.test @@ -0,0 +1,17 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: ld.lld %t.o --script %s -o %t1 +# RUN: llvm-readobj -symbols %t1 | FileCheck %s + +## We had a bug when LLD increased the size of the output section even +## if it was empty. That happened because of empty synthetic sections included. +## Here we check that size of empty output section is zero. + +# CHECK: Name: foo +# CHECK-NEXT: Value: 0x0 + +SECTIONS { + . = 0x1000; + .bss : { *(.bss*) *(COMMON) } + foo = SIZEOF(.bss); +} diff --git a/test/ELF/linkerscript/empty-sections-expressions.s b/test/ELF/linkerscript/empty-sections-expressions.s new file mode 100644 index 000000000000..3c9a9edf5786 --- /dev/null +++ b/test/ELF/linkerscript/empty-sections-expressions.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +## We remove empty sections that do not reference symbols in address, +## LMA, align and subalign expressions. Here we check that. + +# RUN: echo "SECTIONS { .debug_info 0 : { *(.debug_info) } }" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: llvm-objdump -section-headers %t | FileCheck %s +# CHECK-NOT: .debug_info + +# RUN: echo "SECTIONS { .debug_info foo : { *(.debug_info) } }" > %t2.script +# RUN: ld.lld -o %t2 --script %t2.script %t.o +# RUN: llvm-objdump -section-headers %t2 | FileCheck %s --check-prefix=SEC +# SEC: .debug_info + +.globl foo +foo: diff --git a/test/ELF/linkerscript/empty-synthetic-removed-flags.s b/test/ELF/linkerscript/empty-synthetic-removed-flags.s new file mode 100644 index 000000000000..54a8baba3bec --- /dev/null +++ b/test/ELF/linkerscript/empty-synthetic-removed-flags.s @@ -0,0 +1,36 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { .foo : { *(.foo) } .bar : { *(.got.plt) BYTE(0x11) }}" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: llvm-readobj -s %t | FileCheck %s + +## We have ".got.plt" synthetic section with SHF_ALLOC|SHF_WRITE flags. +## It is empty, so linker removes it, but it has to keep ".got.plt" output +## section because of the BYTE command. Here we check that the output section +## still remembers what the flags of .got.plt are. + +# CHECK: Section { +# CHECK: Index: 2 +# CHECK: Name: .bar +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] + +## Check flags are not the same if we omit empty synthetic section in script. +# RUN: echo "SECTIONS { .foo : { *(.foo) } .bar : { BYTE(0x11) }}" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: llvm-readobj -s %t | FileCheck --check-prefix=EMPTY %s + +# EMPTY: Section { +# EMPTY: Index: 2 +# EMPTY: Name: .bar +# EMPTY-NEXT: Type: SHT_PROGBITS +# EMPTY-NEXT: Flags [ +# EMPTY-NEXT: SHF_ALLOC +# EMPTY-NEXT: SHF_EXECINSTR +# EMPTY-NEXT: ] + +.section .foo,"ax" +.quad 0 diff --git a/test/ELF/linkerscript/empty-tls.s b/test/ELF/linkerscript/empty-tls.s deleted file mode 100644 index 919ccbffbe43..000000000000 --- a/test/ELF/linkerscript/empty-tls.s +++ /dev/null @@ -1,14 +0,0 @@ -// REQUIRES: x86 -// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: echo "PHDRS { ph_tls PT_TLS; }" > %t.script -// RUN: ld.lld -o %t.so -T %t.script %t.o -shared -// RUN: llvm-readobj -l %t.so | FileCheck %s - -// test that we don't crash with an empty PT_TLS - -// CHECK: Type: PT_TLS -// CHECK-NEXT: Offset: 0x0 -// CHECK-NEXT: VirtualAddress: 0x0 -// CHECK-NEXT: PhysicalAddress: 0x0 -// CHECK-NEXT: FileSize: 0 -// CHECK-NEXT: MemSize: 0 diff --git a/test/ELF/linkerscript/empty-tls.test b/test/ELF/linkerscript/empty-tls.test new file mode 100644 index 000000000000..2f473cb55f8c --- /dev/null +++ b/test/ELF/linkerscript/empty-tls.test @@ -0,0 +1,17 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t.o +# RUN: ld.lld -o %t.so -T %s %t.o -shared +# RUN: llvm-readobj -l %t.so | FileCheck %s + +PHDRS { + ph_tls PT_TLS; +} + +# Test that we don't crash with an empty PT_TLS + +# CHECK: Type: PT_TLS +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x0 +# CHECK-NEXT: PhysicalAddress: 0x0 +# CHECK-NEXT: FileSize: 0 +# CHECK-NEXT: MemSize: 0 diff --git a/test/ELF/linkerscript/exidx-crash.s b/test/ELF/linkerscript/exidx-crash.s deleted file mode 100644 index c29d0135414d..000000000000 --- a/test/ELF/linkerscript/exidx-crash.s +++ /dev/null @@ -1,7 +0,0 @@ -# REQUIRES: aarch64 - -# We used to crash on this. - -# RUN: llvm-mc %s -o %t.o -filetype=obj -triple=aarch64-pc-linux -# RUN: echo "SECTIONS { .ARM.exidx : { *(.foo) } }" > %t.script -# RUN: ld.lld -T %t.script %t.o -o %t diff --git a/test/ELF/linkerscript/exidx-crash.test b/test/ELF/linkerscript/exidx-crash.test new file mode 100644 index 000000000000..4d765f4d3380 --- /dev/null +++ b/test/ELF/linkerscript/exidx-crash.test @@ -0,0 +1,10 @@ +# REQUIRES: aarch64 + +# We used to crash on this. + +# RUN: llvm-mc /dev/null -o %t.o -filetype=obj -triple=aarch64-pc-linux +# RUN: ld.lld -T %s %t.o -o %t + +SECTIONS { + .ARM.exidx : { *(.foo) } +} diff --git a/test/ELF/linkerscript/expr-invalid-sec.s b/test/ELF/linkerscript/expr-invalid-sec.s deleted file mode 100644 index 5687751b6806..000000000000 --- a/test/ELF/linkerscript/expr-invalid-sec.s +++ /dev/null @@ -1,6 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "SECTIONS { foo = ADDR(.text) + ADDR(.text); };" > %t.script -# RUN: not ld.lld -o %t.so --script %t.script %t.o -shared 2>&1 | FileCheck %s - -# CHECK: error: {{.*}}.script:1: at least one side of the expression must be absolute diff --git a/test/ELF/linkerscript/expr-invalid-sec.test b/test/ELF/linkerscript/expr-invalid-sec.test new file mode 100644 index 000000000000..946062a0c575 --- /dev/null +++ b/test/ELF/linkerscript/expr-invalid-sec.test @@ -0,0 +1,9 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: not ld.lld -o %t.so --script %s %t.o -shared 2>&1 | FileCheck %s + +# CHECK: error: {{.*}}.test:8: at least one side of the expression must be absolute + +SECTIONS { + foo = ADDR(.text) + ADDR(.text); +}; diff --git a/test/ELF/linkerscript/expr-sections.s b/test/ELF/linkerscript/expr-sections.s deleted file mode 100644 index eb60009cd971..000000000000 --- a/test/ELF/linkerscript/expr-sections.s +++ /dev/null @@ -1,22 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "SECTIONS { \ -# RUN: . = . + 4; \ -# RUN: .text : { \ -# RUN: *(.text) \ -# RUN: foo1 = ADDR(.text) + 1; bar1 = 1 + ADDR(.text); \ -# RUN: foo2 = ADDR(.text) & 1; bar2 = 1 & ADDR(.text); \ -# RUN: foo3 = ADDR(.text) | 1; bar3 = 1 | ADDR(.text); \ -# RUN: } \ -# RUN: };" > %t.script -# RUN: ld.lld -o %t.so --script %t.script %t.o -shared -# RUN: llvm-objdump -t -h %t.so | FileCheck %s - -# CHECK: 1 .text 00000000 0000000000000004 TEXT DATA - -# CHECK: 0000000000000005 .text 00000000 foo1 -# CHECK: 0000000000000005 .text 00000000 bar1 -# CHECK: 0000000000000000 .text 00000000 foo2 -# CHECK: 0000000000000000 .text 00000000 bar2 -# CHECK: 0000000000000005 .text 00000000 foo3 -# CHECK: 0000000000000005 .text 00000000 bar3 diff --git a/test/ELF/linkerscript/expr-sections.test b/test/ELF/linkerscript/expr-sections.test new file mode 100644 index 000000000000..1d16cc2239e9 --- /dev/null +++ b/test/ELF/linkerscript/expr-sections.test @@ -0,0 +1,23 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: ld.lld -o %t.so --script %s %t.o -shared +# RUN: llvm-objdump -t -h %t.so | FileCheck %s + +SECTIONS { + . = . + 4; + .text : { + *(.text) + foo1 = ADDR(.text) + 1; bar1 = 1 + ADDR(.text); + foo2 = ADDR(.text) & 1; bar2 = 1 & ADDR(.text); + foo3 = ADDR(.text) | 1; bar3 = 1 | ADDR(.text); + } +}; + +# CHECK: 5 .text 00000000 000000000000014c + +# CHECK: 000000000000014d .text 00000000 foo1 +# CHECK: 000000000000014d .text 00000000 bar1 +# CHECK: 0000000000000000 .text 00000000 foo2 +# CHECK: 0000000000000000 .text 00000000 bar2 +# CHECK: 000000000000014d .text 00000000 foo3 +# CHECK: 000000000000014d .text 00000000 bar3 diff --git a/test/ELF/linkerscript/extend-pt-load.s b/test/ELF/linkerscript/extend-pt-load.s deleted file mode 100644 index 72740f1092ee..000000000000 --- a/test/ELF/linkerscript/extend-pt-load.s +++ /dev/null @@ -1,68 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o - -# This test demonstrates an odd consequence of the way we handle sections with just symbol -# assignments. - -# First, run a test with no such section. - -# RUN: echo "SECTIONS { \ -# RUN: . = SIZEOF_HEADERS; \ -# RUN: .dynsym : { } \ -# RUN: .hash : { } \ -# RUN: .dynstr : { } \ -# RUN: .text : { *(.text) } \ -# RUN: . = ALIGN(0x1000); \ -# RUN: .data.rel.ro : { *(.data.rel.ro) } \ -# RUN: }" > %t.script -# RUN: ld.lld --hash-style=sysv -o %t1 --script %t.script %t.o -shared -# RUN: llvm-readobj --elf-output-style=GNU -l -s %t1 | FileCheck --check-prefix=CHECK1 %s - -# CHECK1: .text PROGBITS 00000000000001bc 0001bc 000001 00 AX -# CHECK1-NEXT: .data.rel.ro PROGBITS 0000000000001000 001000 000001 00 WA - -# CHECK1: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0001bd 0x0001bd R E -# CHECK1-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000068 0x000068 RW - -# Then add the section bar. Note how bar is given AX flags, which causes the PT_LOAD to now -# cover the padding bits created by ALIGN. - -# RUN: echo "SECTIONS { \ -# RUN: . = SIZEOF_HEADERS; \ -# RUN: .dynsym : { } \ -# RUN: .hash : { } \ -# RUN: .dynstr : { } \ -# RUN: .text : { *(.text) } \ -# RUN: bar : { . = ALIGN(0x1000); } \ -# RUN: .data.rel.ro : { *(.data.rel.ro) } \ -# RUN: }" > %t.script -# RUN: ld.lld --hash-style=sysv -o %t2 --script %t.script %t.o -shared -# RUN: llvm-readobj --elf-output-style=GNU -l -s %t2 | FileCheck --check-prefix=CHECK2 %s - -# CHECK2: .text PROGBITS 00000000000001bc 0001bc 000001 00 AX -# CHECK2-NEXT: bar NOBITS 00000000000001bd 0001bd 000e43 00 AX -# CHECK2-NEXT: .data.rel.ro PROGBITS 0000000000001000 001000 000001 00 WA - -# CHECK2: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0001bd 0x001000 R E -# CHECK2-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000068 0x000068 RW - -# If the current behavior becomes a problem we should consider just moving the commands out -# of the section. That is, handle the above like the following test. - -# RUN: echo "SECTIONS { \ -# RUN: . = SIZEOF_HEADERS; \ -# RUN: .dynsym : { } \ -# RUN: .hash : { } \ -# RUN: .dynstr : { } \ -# RUN: .text : { *(.text) } \ -# RUN: . = ALIGN(0x1000); \ -# RUN: HIDDEN(bar_sym = .); \ -# RUN: .data.rel.ro : { *(.data.rel.ro) } \ -# RUN: }" > %t.script -# RUN: ld.lld --hash-style=sysv -o %t3 --script %t.script %t.o -shared -# RUN: llvm-readobj --elf-output-style=GNU -l -s %t3 | FileCheck --check-prefix=CHECK1 %s - -nop - -.section .data.rel.ro, "aw" -.byte 0 diff --git a/test/ELF/linkerscript/extend-pt-load1.test b/test/ELF/linkerscript/extend-pt-load1.test new file mode 100644 index 000000000000..a1359eace186 --- /dev/null +++ b/test/ELF/linkerscript/extend-pt-load1.test @@ -0,0 +1,23 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/extend-pt-load.s -o %t.o +# RUN: ld.lld --hash-style=sysv -o %t1 --script %s %t.o -shared +# RUN: llvm-readobj --elf-output-style=GNU -l -s %t1 | FileCheck %s + +# This test demonstrates an odd consequence of the way we handle sections with just symbol +# assignments. + +SECTIONS { + . = SIZEOF_HEADERS; + .dynsym : {} + .hash : {} + .dynstr : {} + .text : { *(.text) } + . = ALIGN(0x1000); + .data.rel.ro : { *(.data.rel.ro) } +} + +# CHECK: .text PROGBITS 00000000000001bc 0001bc 000001 00 AX +# CHECK-NEXT: .data.rel.ro PROGBITS 0000000000001000 001000 000001 00 WA + +# CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0001bd 0x0001bd R E +# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000068 0x000068 RW diff --git a/test/ELF/linkerscript/extend-pt-load2.test b/test/ELF/linkerscript/extend-pt-load2.test new file mode 100644 index 000000000000..1aa943703f27 --- /dev/null +++ b/test/ELF/linkerscript/extend-pt-load2.test @@ -0,0 +1,24 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/extend-pt-load.s -o %t.o +# RUN: ld.lld --hash-style=sysv -o %t2 --script %s %t.o -shared +# RUN: llvm-readobj --elf-output-style=GNU -l -s %t2 | FileCheck %s + +# Then add the section bar. Note how bar is given AX flags, which causes the PT_LOAD to now +# cover the padding bits created by ALIGN. + +SECTIONS { + . = SIZEOF_HEADERS; + .dynsym : {} + .hash : {} + .dynstr : {} + .text : { *(.text) } + bar : { . = ALIGN(0x1000); } + .data.rel.ro : { *(.data.rel.ro) } +} + +# CHECK: .text PROGBITS 00000000000001bc 0001bc 000001 00 AX +# CHECK-NEXT: bar NOBITS 00000000000001bd 0001bd 000e43 00 AX +# CHECK-NEXT: .data.rel.ro PROGBITS 0000000000001000 001000 000001 00 WA + +# CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0001bd 0x001000 R E +# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000068 0x000068 RW diff --git a/test/ELF/linkerscript/extend-pt-load3.test b/test/ELF/linkerscript/extend-pt-load3.test new file mode 100644 index 000000000000..1b7ef6fdbf94 --- /dev/null +++ b/test/ELF/linkerscript/extend-pt-load3.test @@ -0,0 +1,24 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/extend-pt-load.s -o %t.o +# RUN: ld.lld --hash-style=sysv -o %t3 --script %s %t.o -shared +# RUN: llvm-readobj --elf-output-style=GNU -l -s %t3 | FileCheck --check-prefix=CHECK %s + +# If the current behavior becomes a problem we should consider just moving the commands out +# of the section. That is, handle the above like the following test. + +SECTIONS { + . = SIZEOF_HEADERS; + .dynsym : {} + .hash : {} + .dynstr : {} + .text : { *(.text) } + . = ALIGN(0x1000); + HIDDEN(bar_sym = .); + .data.rel.ro : { *(.data.rel.ro) } +} + +# CHECK: .text PROGBITS 00000000000001bc 0001bc 000001 00 AX +# CHECK-NEXT: .data.rel.ro PROGBITS 0000000000001000 001000 000001 00 WA + +# CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0001bd 0x0001bd R E +# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000068 0x000068 RW
\ No newline at end of file diff --git a/test/ELF/linkerscript/filename-spec.s b/test/ELF/linkerscript/filename-spec.s index 5f075a8e5005..66fd4178387c 100644 --- a/test/ELF/linkerscript/filename-spec.s +++ b/test/ELF/linkerscript/filename-spec.s @@ -1,55 +1,43 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tfirst.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tx.o # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ -# RUN: %p/Inputs/filename-spec.s -o %tsecond.o +# RUN: %p/Inputs/filename-spec.s -o %ty.o -# RUN: echo "SECTIONS { .foo : { \ -# RUN: KEEP(*first.o(.foo)) \ -# RUN: KEEP(*second.o(.foo)) } }" > %t1.script -# RUN: ld.lld -o %t1 --script %t1.script %tfirst.o %tsecond.o -# RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=FIRSTSECOND %s -# FIRSTSECOND: Contents of section .foo: -# FIRSTSECOND-NEXT: 01000000 00000000 11000000 00000000 +# RUN: echo "SECTIONS{.foo :{ KEEP(*x.o(.foo)) KEEP(*y.o(.foo)) }}" > %t1.script +# RUN: ld.lld -o %t1 --script %t1.script %tx.o %ty.o +# RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=FIRSTY %s +# FIRSTY: Contents of section .foo: +# FIRSTY-NEXT: 01000000 00000000 11000000 00000000 -# RUN: echo "SECTIONS { .foo : { \ -# RUN: KEEP(*second.o(.foo)) \ -# RUN: KEEP(*first.o(.foo)) } }" > %t2.script -# RUN: ld.lld -o %t2 --script %t2.script %tfirst.o %tsecond.o +# RUN: echo "SECTIONS{.foo :{ KEEP(*y.o(.foo)) KEEP(*x.o(.foo)) }}" > %t2.script +# RUN: ld.lld -o %t2 --script %t2.script %tx.o %ty.o # RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SECONDFIRST %s # SECONDFIRST: Contents of section .foo: # SECONDFIRST-NEXT: 11000000 00000000 01000000 00000000 ## Now the same tests but without KEEP. Checking that file name inside ## KEEP is parsed fine. -# RUN: echo "SECTIONS { .foo : { \ -# RUN: *first.o(.foo) \ -# RUN: *second.o(.foo) } }" > %t3.script -# RUN: ld.lld -o %t3 --script %t3.script %tfirst.o %tsecond.o -# RUN: llvm-objdump -s %t3 | FileCheck --check-prefix=FIRSTSECOND %s +# RUN: echo "SECTIONS{.foo :{ *x.o(.foo) *y.o(.foo) }}" > %t3.script +# RUN: ld.lld -o %t3 --script %t3.script %tx.o %ty.o +# RUN: llvm-objdump -s %t3 | FileCheck --check-prefix=FIRSTY %s -# RUN: echo "SECTIONS { .foo : { \ -# RUN: *second.o(.foo) \ -# RUN: *first.o(.foo) } }" > %t4.script -# RUN: ld.lld -o %t4 --script %t4.script %tfirst.o %tsecond.o +# RUN: echo "SECTIONS{.foo :{ *y.o(.foo) *x.o(.foo) }}" > %t4.script +# RUN: ld.lld -o %t4 --script %t4.script %tx.o %ty.o # RUN: llvm-objdump -s %t4 | FileCheck --check-prefix=SECONDFIRST %s -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o filename-spec1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %T/filename-spec1.o # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ -# RUN: %p/Inputs/filename-spec.s -o filename-spec2.o +# RUN: %p/Inputs/filename-spec.s -o %T/filename-spec2.o -# RUN: echo "SECTIONS { .foo : { \ -# RUN: filename-spec2.o(.foo) \ -# RUN: filename-spec1.o(.foo) } }" > %t5.script +# RUN: echo "SECTIONS{.foo :{ %T/filename-spec2.o(.foo) %T/filename-spec1.o(.foo) }}" > %t5.script # RUN: ld.lld -o %t5 --script %t5.script \ -# RUN: filename-spec1.o filename-spec2.o +# RUN: %T/filename-spec1.o %T/filename-spec2.o # RUN: llvm-objdump -s %t5 | FileCheck --check-prefix=SECONDFIRST %s -# RUN: echo "SECTIONS { .foo : { \ -# RUN: filename-spec1.o(.foo) \ -# RUN: filename-spec2.o(.foo) } }" > %t6.script +# RUN: echo "SECTIONS{.foo :{ %T/filename-spec1.o(.foo) %T/filename-spec2.o(.foo) }}" > %t6.script # RUN: ld.lld -o %t6 --script %t6.script \ -# RUN: filename-spec1.o filename-spec2.o -# RUN: llvm-objdump -s %t6 | FileCheck --check-prefix=FIRSTSECOND %s +# RUN: %T/filename-spec1.o %T/filename-spec2.o +# RUN: llvm-objdump -s %t6 | FileCheck --check-prefix=FIRSTY %s # RUN: mkdir -p %t.testdir1 %t.testdir2 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.testdir1/filename-spec1.o @@ -59,33 +47,25 @@ # RUN: llvm-ar rsc %t.testdir2/lib2.a %t.testdir2/filename-spec2.o # Verify matching of archive library names. -# RUN: echo "SECTIONS { .foo : { \ -# RUN: *lib2*(.foo) \ -# RUN: *lib1*(.foo) } }" > %t7.script +# RUN: echo "SECTIONS{.foo :{ *lib2*(.foo) *lib1*(.foo) }}" > %t7.script # RUN: ld.lld -o %t7 --script %t7.script --whole-archive \ # RUN: %t.testdir1/lib1.a %t.testdir2/lib2.a # RUN: llvm-objdump -s %t7 | FileCheck --check-prefix=SECONDFIRST %s # Verify matching directories. -# RUN: echo "SECTIONS { .foo : { \ -# RUN: *testdir2*(.foo) \ -# RUN: *testdir1*(.foo) } }" > %t8.script +# RUN: echo "SECTIONS{.foo :{ *testdir2*(.foo) *testdir1*(.foo) }}" > %t8.script # RUN: ld.lld -o %t8 --script %t8.script --whole-archive \ # RUN: %t.testdir1/lib1.a %t.testdir2/lib2.a # RUN: llvm-objdump -s %t8 | FileCheck --check-prefix=SECONDFIRST %s # Verify matching of archive library names in KEEP. -# RUN: echo "SECTIONS { .foo : { \ -# RUN: KEEP(*lib2*(.foo)) \ -# RUN: KEEP(*lib1*(.foo)) } }" > %t9.script +# RUN: echo "SECTIONS{.foo :{ KEEP(*lib2*(.foo)) KEEP(*lib1*(.foo)) }}" > %t9.script # RUN: ld.lld -o %t9 --script %t9.script --whole-archive \ # RUN: %t.testdir1/lib1.a %t.testdir2/lib2.a # RUN: llvm-objdump -s %t9 | FileCheck --check-prefix=SECONDFIRST %s # Verify matching directories in KEEP. -# RUN: echo "SECTIONS { .foo : { \ -# RUN: KEEP(*testdir2*(.foo)) \ -# RUN: KEEP(*testdir1*(.foo)) } }" > %t10.script +# RUN: echo "SECTIONS{.foo :{ KEEP(*testdir2*(.foo)) KEEP(*testdir1*(.foo)) }}" > %t10.script # RUN: ld.lld -o %t10 --script %t10.script --whole-archive \ # RUN: %t.testdir1/lib1.a %t.testdir2/lib2.a # RUN: llvm-objdump -s %t10 | FileCheck --check-prefix=SECONDFIRST %s diff --git a/test/ELF/linkerscript/fill.s b/test/ELF/linkerscript/fill.s deleted file mode 100644 index 604506084a74..000000000000 --- a/test/ELF/linkerscript/fill.s +++ /dev/null @@ -1,31 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "SECTIONS { \ -# RUN: .out : { \ -# RUN: FILL(0x11111111) \ -# RUN: . += 2; \ -# RUN: *(.aaa) \ -# RUN: . += 4; \ -# RUN: *(.bbb) \ -# RUN: . += 4; \ -# RUN: FILL(0x22222222); \ -# RUN: . += 4; \ -# RUN: } \ -# RUN: }; " > %t.script -# RUN: ld.lld -o %t --script %t.script %t.o -# RUN: llvm-objdump -s %t | FileCheck %s - -# CHECK: Contents of section .out: -# CHECK-NEXT: 2222aa22 222222bb 22222222 22222222 - -.text -.globl _start -_start: - -.section .aaa, "a" -.align 1 -.byte 0xAA - -.section .bbb, "a" -.align 1 -.byte 0xBB diff --git a/test/ELF/linkerscript/fill.test b/test/ELF/linkerscript/fill.test new file mode 100644 index 000000000000..5bf295ec9c14 --- /dev/null +++ b/test/ELF/linkerscript/fill.test @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/fill.s -o %t.o +# RUN: ld.lld -o %t --script %s %t.o +# RUN: llvm-objdump -s %t | FileCheck %s + +SECTIONS { + .out : { + FILL(0x11111111) + . += 2; + *(.aaa) + . += 4; + *(.bbb) + . += 4; + FILL(0x22222222); + . += 4; + } +} + +# CHECK: Contents of section .out: +# CHECK-NEXT: 2222aa22 222222bb 22222222 22222222 diff --git a/test/ELF/linkerscript/header-addr.s b/test/ELF/linkerscript/header-addr.test index 70e6f674bafb..7994c0fc9653 100644 --- a/test/ELF/linkerscript/header-addr.s +++ b/test/ELF/linkerscript/header-addr.test @@ -1,13 +1,15 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "PHDRS {all PT_LOAD PHDRS;} \ -# RUN: SECTIONS { \ -# RUN: . = 0x2000 + SIZEOF_HEADERS; \ -# RUN: .text : {*(.text)} :all \ -# RUN: }" > %t.script -# RUN: ld.lld --hash-style=sysv -o %t.so --script %t.script %t.o -shared +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t.o +# RUN: ld.lld --hash-style=sysv -o %t.so --script %s %t.o -shared # RUN: llvm-readobj -program-headers %t.so | FileCheck %s +PHDRS { all PT_LOAD PHDRS; } + +SECTIONS { + . = 0x2000 + SIZEOF_HEADERS; + .text : {*(.text)} :all +} + # CHECK: ProgramHeaders [ # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD @@ -25,7 +27,7 @@ # CHECK-NEXT: } # CHECK-NEXT: ] -# RUN: ld.lld --hash-style=sysv -o %t2.so --script %t.script %t.o -shared -z max-page-size=0x2000 +# RUN: ld.lld --hash-style=sysv -o %t2.so --script %s %t.o -shared -z max-page-size=0x2000 # RUN: llvm-readobj -program-headers %t2.so \ # RUN: | FileCheck --check-prefix=MAXPAGE %s diff --git a/test/ELF/linkerscript/header-phdr.s b/test/ELF/linkerscript/header-phdr.s deleted file mode 100644 index 8c9097d8dfa5..000000000000 --- a/test/ELF/linkerscript/header-phdr.s +++ /dev/null @@ -1,13 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "PHDRS { foobar PT_LOAD FILEHDR PHDRS; } \ -# RUN: SECTIONS { . = 0x1000; .abc : { *(.zed) } : foobar }" > %t.script -# RUN: ld.lld --script %t.script %t.o -o %t -# RUN: llvm-readelf -l -S -W %t | FileCheck %s - -.section .zed, "a" -.zero 4 - - -# CHECK: [ 1] .abc PROGBITS 0000000000001000 001000 000004 00 A 0 0 1 -# CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x001004 0x001004 R E 0x1000 diff --git a/test/ELF/linkerscript/header-phdr.test b/test/ELF/linkerscript/header-phdr.test new file mode 100644 index 000000000000..72be15b88a94 --- /dev/null +++ b/test/ELF/linkerscript/header-phdr.test @@ -0,0 +1,15 @@ +# REQUIRES: x86 +# RUN: echo '.section .zed, "a"; .zero 4' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o +# RUN: ld.lld --script %s %t.o -o %t +# RUN: llvm-readelf -l -S -W %t | FileCheck %s + +# CHECK: [ 1] .abc PROGBITS 0000000000001000 001000 000004 00 A 0 0 1 +# CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x001004 0x001004 R E 0x1000 + +PHDRS { foobar PT_LOAD FILEHDR PHDRS; } + +SECTIONS { + . = 0x1000; + .abc : { *(.zed) } : foobar +} diff --git a/test/ELF/linkerscript/header-phdr2.s b/test/ELF/linkerscript/header-phdr2.s new file mode 100644 index 000000000000..fbcd03ff6056 --- /dev/null +++ b/test/ELF/linkerscript/header-phdr2.s @@ -0,0 +1,11 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "PHDRS { foobar PT_LOAD FILEHDR PHDRS; }" > %t.script +# RUN: echo "SECTIONS { .text : { *(.text) } : foobar }" >> %t.script +# RUN: not ld.lld --script %t.script %t.o -o /dev/null 2>&1 | FileCheck %s + +# CHECK: could not allocate headers + + .global _start +_start: + retq diff --git a/test/ELF/linkerscript/huge-temporary-file.s b/test/ELF/linkerscript/huge-temporary-file.s index d58709cf8f8d..e30153c28857 100644 --- a/test/ELF/linkerscript/huge-temporary-file.s +++ b/test/ELF/linkerscript/huge-temporary-file.s @@ -3,7 +3,7 @@ # RUN: echo "SECTIONS { .text 0x2000 : {. = 0x10 ; *(.text) } }" > %t.script # RUN: not ld.lld %t --script %t.script -o %t1 -## This inputs previously created a 4gb temporarily fine under 32 bit +## This inputs previously created a 4gb temporarily file under 32 bit ## configuration. Issue was fixed. There is no clean way to check that from here. ## This testcase added for documentation purposes. diff --git a/test/ELF/linkerscript/i386-sections-max-va-overflow.s b/test/ELF/linkerscript/i386-sections-max-va-overflow.s new file mode 100644 index 000000000000..d424112a1ce4 --- /dev/null +++ b/test/ELF/linkerscript/i386-sections-max-va-overflow.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t.o + +# RUN: echo "SECTIONS { . = 0xfffffff1;" > %t.script +# RUN: echo " .bar : { *(.bar*) } }" >> %t.script +# RUN: not ld.lld -o /dev/null --script %t.script %t.o 2>&1 | FileCheck %s -check-prefix=ERR + +## .bar section has data in [0xfffffff1, 0xfffffff1 + 0x10] == [0xffffff1, 0x1]. +## Check we can catch this overflow. +# ERR: error: section .bar at 0xFFFFFFF1 of size 0x10 exceeds available address space + +.section .bar,"ax",@progbits +.zero 0x10 diff --git a/test/ELF/linkerscript/implicit-program-header.s b/test/ELF/linkerscript/implicit-program-header.s deleted file mode 100644 index 95cdf142fe42..000000000000 --- a/test/ELF/linkerscript/implicit-program-header.s +++ /dev/null @@ -1,13 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: ld.lld --hash-style=sysv -o %t1 --script %S/Inputs/implicit-program-header.script \ -# RUN: %t.o -shared -# RUN: llvm-readobj -elf-output-style=GNU -l %t1 | FileCheck %s - -# CHECK: Segment Sections... -# CHECK-NEXT: 00 .text .dynsym .hash .dynstr .dynamic -# CHECK-NEXT: 01 .foo - -.quad 0 -.section .foo,"ax" -.quad 0 diff --git a/test/ELF/linkerscript/implicit-program-header.test b/test/ELF/linkerscript/implicit-program-header.test new file mode 100644 index 000000000000..8a3a4c6684af --- /dev/null +++ b/test/ELF/linkerscript/implicit-program-header.test @@ -0,0 +1,22 @@ +# REQUIRES: x86 + +# RUN: echo '.section .text,"ax"; .quad 0' > %t.s +# RUN: echo '.section .foo,"ax"; .quad 0' >> %t.s +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t.s -o %t.o +# RUN: ld.lld --hash-style=sysv -o %t1 --script %s %t.o -shared +# RUN: llvm-readelf -l %t1 | FileCheck %s + +# CHECK: Segment Sections... +# CHECK-NEXT: 00 .dynsym .hash .dynstr .bar .foo .text .dynamic +# CHECK-NEXT: 01 .bar .foo + +PHDRS { + ph_write PT_LOAD FLAGS(2); + ph_exec PT_LOAD FLAGS(1); +} + +SECTIONS { + .bar : { *(.bar) } : ph_exec + .foo : { *(.foo) } + .text : { *(.text) } : ph_write +} diff --git a/test/ELF/linkerscript/info-section-type.s b/test/ELF/linkerscript/info-section-type.s new file mode 100644 index 000000000000..b718e828ab7d --- /dev/null +++ b/test/ELF/linkerscript/info-section-type.s @@ -0,0 +1,33 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +## In this test we check that output section types such as +## COPY, INFO and OVERLAY marks output section as non-allocatable. + +# RUN: echo "SECTIONS { .bar : { *(.foo) } };" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=DEFAULT +# DEFAULT: Name: .bar +# DEFAULT: Type: SHT_PROGBITS +# DEFAULT-NEXT: Flags [ +# DEFAULT-NEXT: SHF_ALLOC +# DEFAULT-NEXT: ] + +# RUN: echo "SECTIONS { .bar (COPY) : { *(.foo) } };" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC +# NONALLOC: Name: .bar +# NONALLOC: Type: SHT_PROGBITS +# NONALLOC-NEXT: Flags [ +# NONALLOC-NEXT: ] + +# RUN: echo "SECTIONS { .bar (INFO) : { *(.foo) } };" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC + +# RUN: echo "SECTIONS { .bar (OVERLAY) : { *(.foo) } };" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC + +.section .foo,"a",@progbits +.zero 1 diff --git a/test/ELF/linkerscript/insert-after.test b/test/ELF/linkerscript/insert-after.test new file mode 100644 index 000000000000..4260cd77f553 --- /dev/null +++ b/test/ELF/linkerscript/insert-after.test @@ -0,0 +1,29 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/insert-after.s -o %t1.o + +## Main linker script contains .text and .data sections. Here +## we check that can use INSERT AFTER to insert sections .foo.data +## and .foo.text at the right places. + +SECTIONS { + .foo.data : { *(.foo.data) } +} INSERT AFTER .data; + +SECTIONS { + .foo.text : { *(.foo.text) } +} INSERT AFTER .text; + +# RUN: ld.lld %t1.o -o %t1 --script %p/Inputs/insert-after.script --script %s +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .text 00000008 0000000000000000 TEXT +# CHECK-NEXT: 2 .foo.text 00000008 0000000000000008 TEXT +# CHECK-NEXT: 3 .data 00000008 0000000000000010 DATA +# CHECK-NEXT: 4 .foo.data 00000008 0000000000000018 DATA + +# RUN: not ld.lld %t1.o -o %t1 --script %s 2>&1 \ +# RUN: | FileCheck %s --check-prefix=ERR +# ERR-DAG: error: unable to INSERT AFTER/BEFORE .text: section not defined +# ERR-DAG: error: unable to INSERT AFTER/BEFORE .data: section not defined diff --git a/test/ELF/linkerscript/insert-before.test b/test/ELF/linkerscript/insert-before.test new file mode 100644 index 000000000000..52317bef6ac0 --- /dev/null +++ b/test/ELF/linkerscript/insert-before.test @@ -0,0 +1,29 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/insert-after.s -o %t1.o + +## Main linker script contains .text and .data sections. Here +## we check that can use INSERT BEFORE to insert sections .foo.data +## and .foo.text at the right places. + +SECTIONS { + .foo.data : { *(.foo.data) } +} INSERT BEFORE .data; + +SECTIONS { + .foo.text : { *(.foo.text) } +} INSERT BEFORE .text; + +# RUN: ld.lld %t1.o -o %t1 --script %p/Inputs/insert-after.script --script %s +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .foo.text 00000008 0000000000000000 TEXT +# CHECK-NEXT: 2 .text 00000008 0000000000000008 TEXT +# CHECK-NEXT: 3 .foo.data 00000008 0000000000000010 DATA +# CHECK-NEXT: 4 .data 00000008 0000000000000018 DATA + +# RUN: not ld.lld %t1.o -o %t1 --script %s 2>&1 \ +# RUN: | FileCheck %s --check-prefix=ERR +# ERR-DAG: error: unable to INSERT AFTER/BEFORE .text: section not defined +# ERR-DAG: error: unable to INSERT AFTER/BEFORE .data: section not defined diff --git a/test/ELF/linkerscript/insert-broken.test b/test/ELF/linkerscript/insert-broken.test new file mode 100644 index 000000000000..9a295623a2ca --- /dev/null +++ b/test/ELF/linkerscript/insert-broken.test @@ -0,0 +1,6 @@ +SECTIONS { + .foo : { *(.bar) } +} INSERT .data; + +# RUN: not ld.lld -o %t1 --script %s 2>&1 | FileCheck %s +# CHECK: {{.*}}:3: expected AFTER/BEFORE, but got '.data' diff --git a/test/ELF/linkerscript/lazy-symbols.s b/test/ELF/linkerscript/lazy-symbols.test index 22dffeef979b..579df9323865 100644 --- a/test/ELF/linkerscript/lazy-symbols.s +++ b/test/ELF/linkerscript/lazy-symbols.test @@ -1,11 +1,12 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/lazy-symbols.s -o %t1 # RUN: llvm-ar rcs %tar %t1 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2 -# RUN: echo "foo = 1;" > %t.script -# RUN: ld.lld %t2 %tar --script %t.script -o %tout +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t2 +# RUN: ld.lld %t2 %tar --script %s -o %tout # RUN: llvm-readobj -symbols %tout | FileCheck %s +foo = 1; + # This test is to ensure a linker script can define a symbol which have the same # name as a lazy symbol. diff --git a/test/ELF/linkerscript/linker-script-in-search-path.s b/test/ELF/linkerscript/linker-script-in-search-path.s index be83b55b8995..8f1802299de5 100644 --- a/test/ELF/linkerscript/linker-script-in-search-path.s +++ b/test/ELF/linkerscript/linker-script-in-search-path.s @@ -4,16 +4,16 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o # RUN: mkdir -p %T/searchpath -# RUN: echo "OUTPUT(\"%t.out\")" > %T/searchpath/foo.script -# RUN: ld.lld -T%T/searchpath/foo.script %t.o +# RUN: echo 'OUTPUT("%t.out")' > %T/searchpath/%basename_t.script +# RUN: ld.lld -T%T/searchpath/%basename_t.script %t.o # RUN: llvm-readobj %t.out | FileCheck %s # CHECK: Format: ELF64-x86-64 # If the linker script specified with -T is missing we should emit an error -# RUN: not ld.lld -Tfoo.script %t.o 2>&1 | FileCheck %s -check-prefix ERROR -# ERROR: error: cannot find linker script foo.script +# RUN: not ld.lld -T%basename_t.script %t.o 2>&1 | FileCheck %s -check-prefix ERROR +# ERROR: error: cannot find linker script {{.*}}.script # But if it exists in the search path we should fall back to that instead: # RUN: rm %t.out -# RUN: ld.lld -L %T/searchpath -Tfoo.script %t.o +# RUN: ld.lld -L %T/searchpath -T%basename_t.script %t.o # RUN: llvm-readobj %t.out | FileCheck %s diff --git a/test/ELF/linkerscript/linkerscript.s b/test/ELF/linkerscript/linkerscript.s index 6a239ea57c8d..39d2d4620a4f 100644 --- a/test/ELF/linkerscript/linkerscript.s +++ b/test/ELF/linkerscript/linkerscript.s @@ -17,32 +17,32 @@ # RUN: llvm-readobj %t.out > /dev/null # RUN: echo "SEARCH_DIR(/lib/foo/blah)" > %t.script -# RUN: ld.lld %t.script %t +# RUN: ld.lld %t.script %t -o %t.out # RUN: llvm-readobj %t.out > /dev/null # RUN: echo ";SEARCH_DIR(x);SEARCH_DIR(y);" > %t.script -# RUN: ld.lld %t.script %t +# RUN: ld.lld %t.script %t -o %t.out # RUN: llvm-readobj %t.out > /dev/null # RUN: echo ";" > %t.script -# RUN: ld.lld %t.script %t +# RUN: ld.lld %t.script %t -o %t.out # RUN: llvm-readobj %t.out > /dev/null # RUN: echo "INCLUDE \"%t.script2\" OUTPUT(\"%t.out\")" > %t.script1 # RUN: echo "GROUP(\"%t\")" > %t.script2 -# RUN: ld.lld %t.script1 +# RUN: ld.lld %t.script1 -o %t.out # RUN: llvm-readobj %t2 > /dev/null # RUN: echo "INCLUDE \"foo.script\"" > %t.script # RUN: echo "OUTPUT(\"%t.out\")" > %T/foo.script -# RUN: not ld.lld %t.script > %t.log 2>&1 +# RUN: not ld.lld %t.script -o %t.out > %t.log 2>&1 # RUN: FileCheck -check-prefix=INCLUDE_ERR %s < %t.log # INCLUDE_ERR: error: {{.+}}.script:1: cannot find linker script foo.script # INCLUDE_ERR-NEXT: INCLUDE "foo.script" # RUN: ld.lld -L %T %t.script %t # RUN: echo "FOO(BAR)" > %t.script -# RUN: not ld.lld -o foo %t.script > %t.log 2>&1 +# RUN: not ld.lld -o %t.out %t.script > %t.log 2>&1 # RUN: FileCheck -check-prefix=ERR1 %s < %t.log # ERR1: unknown directive: FOO diff --git a/test/ELF/linkerscript/lma-overflow.test b/test/ELF/linkerscript/lma-overflow.test new file mode 100644 index 000000000000..e572c05af344 --- /dev/null +++ b/test/ELF/linkerscript/lma-overflow.test @@ -0,0 +1,16 @@ +# REQUIRES: x86 + +# RUN: echo '.section .foo,"a"; .quad 1' | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o +# RUN: not ld.lld -o %t %t.o --script %s 2>&1 | FileCheck %s +# CHECK: error: section '.foo' will not fit in region 'flash': overflowed by 264 bytes + +MEMORY { + ram (rwx) : org = 0x1000, len = 0x300 + flash (rwx) : org = 0x1000, len = 0x100 +} +SECTIONS { + .foo : { + *(.foo) + . += 0x200; + } > ram AT>flash +} diff --git a/test/ELF/linkerscript/locationcountererr.s b/test/ELF/linkerscript/locationcountererr.s deleted file mode 100644 index 113e102d4bc2..000000000000 --- a/test/ELF/linkerscript/locationcountererr.s +++ /dev/null @@ -1,11 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -# RUN: echo "SECTIONS {" > %t.script -# RUN: echo ".text 0x2000 : {. = 0x10 ; *(.text) } }" >> %t.script -# RUN: not ld.lld %t --script %t.script -o %t1 2>&1 | FileCheck %s -# CHECK: {{.*}}.script:2: unable to move location counter backward for: .text - -.globl _start -_start: -nop diff --git a/test/ELF/linkerscript/locationcountererr.test b/test/ELF/linkerscript/locationcountererr.test new file mode 100644 index 000000000000..6a1b21319c5b --- /dev/null +++ b/test/ELF/linkerscript/locationcountererr.test @@ -0,0 +1,11 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t +# RUN: not ld.lld %t --script %s -o %t1 2>&1 | FileCheck %s +# CHECK: {{.*}}.test:8: unable to move location counter backward for: .text + +SECTIONS { + .text 0x2000 : { + . = 0x10; + *(.text) + } +} diff --git a/test/ELF/linkerscript/locationcountererr2.s b/test/ELF/linkerscript/locationcountererr2.s index 8968f6740ee4..9efe86a7283b 100644 --- a/test/ELF/linkerscript/locationcountererr2.s +++ b/test/ELF/linkerscript/locationcountererr2.s @@ -1,11 +1,11 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: echo "SECTIONS {" > %t.script -# RUN: echo ". = 0x20; . = 0x10; .text : {} }" >> %t.script +# RUN: echo ". = 0x150; . = 0x10; .text : {} }" >> %t.script # RUN: ld.lld %t.o --script %t.script -o %t -shared # RUN: llvm-objdump -section-headers %t | FileCheck %s -# CHECK: Idx Name Size Address -# CHECK: 1 .text 00000000 0000000000000010 +# CHECK: Name Size Address +# CHECK: .text 00000000 0000000000000010 # RUN: echo "SECTIONS { . = 0x20; . = ASSERT(0x1, "foo"); }" > %t2.script # RUN: ld.lld %t.o --script %t2.script -o %t -shared diff --git a/test/ELF/linkerscript/map-file.test b/test/ELF/linkerscript/map-file.test new file mode 100644 index 000000000000..540b8d494887 --- /dev/null +++ b/test/ELF/linkerscript/map-file.test @@ -0,0 +1,60 @@ +# REQUIRES: x86 + +# RUN: echo '.quad sym3; .quad sym4; .section .foo.1, "a"; .quad 1' > %t.s +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o + +# RUN: ld.lld -o %t %t.o -Map=%t.map --script %s +# RUN: FileCheck -strict-whitespace %s < %t.map + +SECTIONS { + . = 0x1000; + .foo : { + BYTE(0x11) + SHORT(0x1122) + LONG(0x11223344) + QUAD(0x1122334455667788) + PROVIDE_HIDDEN(sym4 = .); + . += 0x1000; + *(.foo.1) + PROVIDE(unused1 = 0xff); + HIDDEN(sym6 = .); + . += 0x123 * + (1 + 1); + foo = .; + bar = 0x42 - 0x26; + } + sym1 = .; + . += 0x500; + sym2 = .; + PROVIDE(unused2 = 0xff); + PROVIDE(sym3 = 42); +} + +# CHECK: VMA LMA Size Align Out In Symbol +# CHECK-NEXT: 0 0 1000 1 . = 0x1000 +# CHECK-NEXT: 1000 1000 125d 1 .foo +# CHECK-NEXT: 1000 1000 1 1 BYTE ( 0x11 ) +# CHECK-NEXT: 1001 1001 2 1 SHORT ( 0x1122 ) +# CHECK-NEXT: 1003 1003 4 1 LONG ( 0x11223344 ) +# CHECK-NEXT: 1007 1007 8 1 QUAD ( 0x1122334455667788 ) +# CHECK-NEXT: 100f 100f 0 1 PROVIDE_HIDDEN ( sym4 = . ) +# CHECK-NEXT: 100f 100f 1000 1 . += 0x1000 +# CHECK-NEXT: 200f 200f 8 1 {{.*}}{{/|\\}}map-file.test.tmp.o:(.foo.1) +# CHECK-NEXT: 2017 2017 0 1 HIDDEN ( sym6 = . ) +# CHECK-NEXT: 2017 2017 246 1 . += 0x123 * ( 1 + 1 ) +# CHECK-NEXT: 225d 225d 0 1 foo = . +# CHECK-NEXT: 225d 225d 0 1 bar = 0x42 - 0x26 +# CHECK-NEXT: 225d 0 0 1 sym1 = . +# CHECK-NEXT: 225d 0 500 1 . += 0x500 +# CHECK-NEXT: 275d 0 0 1 sym2 = . +# CHECK-NEXT: 275d 0 0 1 PROVIDE ( sym3 = 42 ) +# CHECK-NEXT: 2760 2760 10 4 .text +# CHECK-NEXT: 2760 2760 10 4 {{.*}}{{/|\\}}map-file.test.tmp.o:(.text) +# CHECK-NEXT: 0 0 8 1 .comment +# CHECK-NEXT: 0 0 8 1 <internal>:(.comment) +# CHECK-NEXT: 0 0 c0 8 .symtab +# CHECK-NEXT: 0 0 c0 8 <internal>:(.symtab) +# CHECK-NEXT: 0 0 2f 1 .shstrtab +# CHECK-NEXT: 0 0 2f 1 <internal>:(.shstrtab) +# CHECK-NEXT: 0 0 22 1 .strtab +# CHECK-NEXT: 0 0 22 1 <internal>:(.strtab) diff --git a/test/ELF/linkerscript/map-file2.test b/test/ELF/linkerscript/map-file2.test new file mode 100644 index 000000000000..d9ed339e228d --- /dev/null +++ b/test/ELF/linkerscript/map-file2.test @@ -0,0 +1,44 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/map-file2.s -o %t.o +# RUN: ld.lld -o %t %t.o -Map=%t.map --script %s +# RUN: FileCheck -strict-whitespace %s < %t.map + +SECTIONS { + . = 0x1000; + .aaa : { *(.aaa.*) } + .bbb : AT(0x2000) { *(.bbb.*) } + .ccc : AT(0x3000) { *(.ccc.*) } + .ddd : { + BYTE(0x11) + . += 0x100; + *(.ddd.*) + } + .text : { *(.text.*) } +} + +# CHECK: VMA LMA Size Align Out In Symbol +# CHECK-NEXT: 0 0 1000 1 . = 0x1000 +# CHECK-NEXT: 1000 1000 8 1 .aaa +# CHECK-NEXT: 1000 1000 8 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.aaa) +# CHECK-NEXT: 1008 2000 8 1 .bbb +# CHECK-NEXT: 1008 2000 8 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.bbb) +# CHECK-NEXT: 1010 3000 8 1 .ccc +# CHECK-NEXT: 1010 3000 8 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.ccc) +# CHECK-NEXT: 1018 3008 109 1 .ddd +# CHECK-NEXT: 1018 3008 1 1 BYTE ( 0x11 ) +# CHECK-NEXT: 1019 3009 100 1 . += 0x100 +# CHECK-NEXT: 1119 3109 8 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.ddd) +# CHECK-NEXT: 1128 3118 34 8 .eh_frame +# CHECK-NEXT: 1128 3118 30 1 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.eh_frame+0x0) +# CHECK-NEXT: 115c 314c 1 4 .text +# CHECK-NEXT: 115c 314c 1 4 {{.*}}{{/|\\}}map-file2.test.tmp.o:(.text) +# CHECK-NEXT: 115c 314c 0 1 f(int) +# CHECK-NEXT: 115c 314c 0 1 _start +# CHECK-NEXT: 0 0 8 1 .comment +# CHECK-NEXT: 0 0 8 1 <internal>:(.comment) +# CHECK-NEXT: 0 0 48 8 .symtab +# CHECK-NEXT: 0 0 48 8 <internal>:(.symtab) +# CHECK-NEXT: 0 0 48 1 .shstrtab +# CHECK-NEXT: 0 0 48 1 <internal>:(.shstrtab) +# CHECK-NEXT: 0 0 e 1 .strtab +# CHECK-NEXT: 0 0 e 1 <internal>:(.strtab) diff --git a/test/ELF/linkerscript/memory-at.s b/test/ELF/linkerscript/memory-at.test index 9e56dbdbd657..0f06a6620a79 100644 --- a/test/ELF/linkerscript/memory-at.s +++ b/test/ELF/linkerscript/memory-at.test @@ -1,16 +1,21 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "MEMORY { \ -# RUN: FLASH (rx) : ORIGIN = 0x1000, LENGTH = 0x100 \ -# RUN: RAM (rwx) : ORIGIN = 0x2000, LENGTH = 0x100 } \ -# RUN: SECTIONS { \ -# RUN: .text : { *(.text*) } > FLASH \ -# RUN: __etext = .; \ -# RUN: .data : AT (__etext) { *(.data*) } > RAM \ -# RUN: }" > %t.script -# RUN: ld.lld %t --script %t.script -o %t2 +# RUN: echo '.section .text,"ax"; .quad 0' > %t.s +# RUN: echo '.section .data,"aw"; .quad 0' >> %t.s +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t +# RUN: ld.lld %t --script %s -o %t2 # RUN: llvm-readobj -program-headers %t2 | FileCheck %s +MEMORY { + FLASH (rx) : ORIGIN = 0x1000, LENGTH = 0x100 + RAM (rwx) : ORIGIN = 0x2000, LENGTH = 0x100 +} + +SECTIONS { + .text : { *(.text*) } > FLASH + __etext = .; + .data : AT (__etext) { *(.data*) } > RAM +} + # CHECK: ProgramHeaders [ # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD @@ -38,9 +43,3 @@ # CHECK-NEXT: ] # CHECK-NEXT: Alignment: # CHECK-NEXT: } - -.section .text, "ax" -.quad 0 - -.section .data, "aw" -.quad 0 diff --git a/test/ELF/linkerscript/memory-data-commands.test b/test/ELF/linkerscript/memory-data-commands.test new file mode 100644 index 000000000000..2762ec9e985f --- /dev/null +++ b/test/ELF/linkerscript/memory-data-commands.test @@ -0,0 +1,22 @@ +# REQUIRES: x86 + +# RUN: echo ".section .foo,\"a\"" > %t.s +# RUN: echo ".quad 1" >> %t.s +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o + +# RUN: not ld.lld -o %t %t.o --script %s 2>&1 | FileCheck %s + +# Check we are able to catch 'ram' overflow caused by BYTE command. +# CHECK: error: section '.foo' will not fit in region 'ram': overflowed by 1 bytes + +MEMORY { + text (rwx): org = 0x0, len = 0x1000 + ram (rwx): org = 0x1000, len = 8 +} +SECTIONS { + .text : { *(.text) } > text + .foo : { + *(.foo) + BYTE(0x1) + } > ram +} diff --git a/test/ELF/linkerscript/memory-loc-counter.test b/test/ELF/linkerscript/memory-loc-counter.test new file mode 100644 index 000000000000..3ca9a2cf6caa --- /dev/null +++ b/test/ELF/linkerscript/memory-loc-counter.test @@ -0,0 +1,37 @@ +# REQUIRES: x86 + +# RUN: echo ".section .foo,\"a\"" > %t.s +# RUN: echo ".quad 1" >> %t.s +# RUN: echo ".section .bar,\"a\"" >> %t.s +# RUN: echo ".quad 1" >> %t.s +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o + +# RUN: ld.lld -o %t %t.o --script %s +# RUN: llvm-readelf -sections -program-headers %t | FileCheck %s + +## Check that we can produce output without errors, +## and .foo section has proper size. +# CHECK: Section Headers: +# CHECK-NEXT: [Nr] Name Type Address Off Size +# CHECK-NEXT: [ 0] NULL 0000000000000000 000000 000000 +# CHECK-NEXT: [ 1] .foo PROGBITS 0000000000001000 001000 000108 +# CHECK-NEXT: [ 2] .bar PROGBITS 0000000000001108 001108 000008 + +## Check that load address is correct. +# CHECK: Program Headers: +# CHECK-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz +# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000002000 0x000110 0x000110 + +MEMORY { + ram (rwx) : org = 0x1000, len = 0x200 + flash (rwx) : org = 0x2000, len = 0x200 +} +SECTIONS { + .foo : { + *(.foo) + . += 0x100; + } > ram AT>flash + .bar : { + *(.bar) + } > ram AT>flash +} diff --git a/test/ELF/linkerscript/memory-region-alignment.test b/test/ELF/linkerscript/memory-region-alignment.test new file mode 100644 index 000000000000..ba9d4e3bab3f --- /dev/null +++ b/test/ELF/linkerscript/memory-region-alignment.test @@ -0,0 +1,58 @@ +# REQUIRES: x86 +# RUN: echo '.section .foo,"a"; .quad 0; .section .zed,"M",@progbits,1; .byte 0' > %t.s +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o + +MEMORY { + ram (rwx): org = 0x1, len = 96K +} + +SECTIONS { + .foo : ALIGN(8) { + *(.foo) + } > ram + + .zed : { + *(.zed) + } > ram +} + +# RUN: ld.lld %t.o -o %t --script %s +# RUN: llvm-readobj -sections %t | FileCheck %s + +# CHECK: Name: .foo +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x8 +# CHECK-NEXT: Offset: 0x1008 +# CHECK-NEXT: Size: 8 + +# CHECK: Name: .text +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_EXECINSTR +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x10 +# CHECK-NEXT: Offset: 0x1010 +# CHECK-NEXT: Size: 0 + +# CHECK: Name: .zed +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x10 +# CHECK-NEXT: Offset: 0x1010 +# CHECK-NEXT: Size: 1 + +# CHECK: Name: .comment +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: SHF_STRINGS +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x0 +# CHECK-NEXT: Offset: 0x1011 +# CHECK-NEXT: Size: 8 diff --git a/test/ELF/linkerscript/memory.s b/test/ELF/linkerscript/memory.s index 172768394d30..0c171425b20a 100644 --- a/test/ELF/linkerscript/memory.s +++ b/test/ELF/linkerscript/memory.s @@ -11,7 +11,7 @@ # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=RAM %s -# RAM: 1 .text 00000001 0000000000008000 TEXT DATA +# RAM: 1 .text 00000001 0000000000008000 TEXT # RAM-NEXT: 2 .data 00001000 0000000000008001 DATA ## Check RAM and ROM memory regions. @@ -27,7 +27,7 @@ # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=RAMROM %s -# RAMROM: 1 .text 00000001 0000000080000000 TEXT DATA +# RAMROM: 1 .text 00000001 0000000080000000 TEXT # RAMROM-NEXT: 2 .data 00001000 0000000000000000 DATA ## Check memory region placement by attributes. @@ -43,7 +43,7 @@ # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=ATTRS %s -# ATTRS: 1 .text 00000001 0000000080000000 TEXT DATA +# ATTRS: 1 .text 00000001 0000000080000000 TEXT # ATTRS: 2 .data 00001000 0000000000000000 DATA ## Check bad `ORIGIN`. diff --git a/test/ELF/linkerscript/memory2.s b/test/ELF/linkerscript/memory2.s index 2e7381fb8914..7f86ecec29b7 100644 --- a/test/ELF/linkerscript/memory2.s +++ b/test/ELF/linkerscript/memory2.s @@ -2,7 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: echo "MEMORY { ram (rwx) : ORIGIN = 0, LENGTH = 2K } \ # RUN: SECTIONS { .text : { *(.text*) } > ram }" > %t.script -# RUN: ld.lld -o %t2 --script %t.script %t +# RUN: ld.lld -o /dev/null --script %t.script %t .text .global _start diff --git a/test/ELF/linkerscript/memory4.test b/test/ELF/linkerscript/memory4.test new file mode 100644 index 000000000000..e73d36085562 --- /dev/null +++ b/test/ELF/linkerscript/memory4.test @@ -0,0 +1,19 @@ +# REQUIRES: x86 +# RUN: echo ".section .text,\"ax\"; nop; .section .data,\"aw\"; nop;" \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t.o +# RUN: ld.lld -o %t.so --script %s %t.o +# RUN: llvm-objdump -section-headers %t.so | FileCheck %s + +# CHECK: 1 .text 00000001 0000000000042000 +# CHECK-NEXT: 2 .data 00000001 0000000000042400 + +## Test that address expressions changes the position in a memory region. + +MEMORY { + ram (wxa) : ORIGIN = 0x42000, LENGTH = 0x100000 +} +SECTIONS { + .text : { *(.text*) } + data_addr = ALIGN(1024); + .data data_addr : { *(.data*) } +} diff --git a/test/ELF/linkerscript/memory5.test b/test/ELF/linkerscript/memory5.test new file mode 100644 index 000000000000..150ddf0e833c --- /dev/null +++ b/test/ELF/linkerscript/memory5.test @@ -0,0 +1,19 @@ +# REQUIRES: x86 +# RUN: echo ".section .text,\"ax\"; nop; .section .data,\"aw\"; nop;" \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t.o +# RUN: ld.lld -o %t.so --script %s %t.o +# RUN: llvm-objdump -section-headers %t.so | FileCheck %s + +# CHECK: 1 .text 00000001 0000000000042000 +# CHECK-NEXT: 2 .data 00000001 0000000000044001 + +## Test that assign to Dot changes the position in a memory region. + +MEMORY { + ram (wxa) : ORIGIN = 0x42000, LENGTH = 0x100000 +} +SECTIONS { + .text : { *(.text*) } + . += 0x2000; + .data : { *(.data*) } +} diff --git a/test/ELF/linkerscript/merge-header-load.s b/test/ELF/linkerscript/merge-header-load.s new file mode 100644 index 000000000000..5fb866abef85 --- /dev/null +++ b/test/ELF/linkerscript/merge-header-load.s @@ -0,0 +1,21 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { \ +# RUN: . = 0xffffffff80000200; \ +# RUN: .text : AT (0x4200) { *(.text) } \ +# RUN: }" > %t.script +# RUN: ld.lld %t.o --script %t.script -o %t +# RUN: llvm-readelf -program-headers %t | FileCheck %s + +# Test that we put the header in the first PT_LOAD. We used to create a PT_LOAD +# just for it and it would have a different virtual to physical address delta. + +# CHECK: Program Headers: +# CHECK: Type Offset VirtAddr PhysAddr +# CHECK-NEXT: PHDR 0x000040 0xffffffff80000040 0x0000000000004040 +# CHECK-NEXT: LOAD 0x000000 0xffffffff80000000 0x0000000000004000 +# CHECK-NOT: LOAD + +.global _start +_start: +nop diff --git a/test/ELF/linkerscript/merge-sections-syms.s b/test/ELF/linkerscript/merge-sections-syms.s index 713d334a1a5a..421749b6f1b9 100644 --- a/test/ELF/linkerscript/merge-sections-syms.s +++ b/test/ELF/linkerscript/merge-sections-syms.s @@ -20,7 +20,7 @@ # CHECK-NEXT: } # CHECK-NEXT: Symbol { # CHECK-NEXT: Name: A -# CHECK-NEXT: Value: 0x195 +# CHECK-NEXT: Value: 0x226 # CHECK-NEXT: Size: # CHECK-NEXT: Binding: # CHECK-NEXT: Type: @@ -29,7 +29,7 @@ # CHECK-NEXT: } # CHECK-NEXT: Symbol { # CHECK-NEXT: Name: B -# CHECK-NEXT: Value: 0x196 +# CHECK-NEXT: Value: 0x227 # CHECK-NEXT: Size: # CHECK-NEXT: Binding: # CHECK-NEXT: Type: diff --git a/test/ELF/linkerscript/merge-sections.s b/test/ELF/linkerscript/merge-sections.s index 2709bdaee444..8fb9e87d616a 100644 --- a/test/ELF/linkerscript/merge-sections.s +++ b/test/ELF/linkerscript/merge-sections.s @@ -28,8 +28,7 @@ # CHECK-NEXT: Value: 0x[[ADDR1]] # CHECK: Name: end -# 0x19E = begin + sizeof(.foo) = 0x190 + 0xE -# CHECK-NEXT: Value: 0x19E +# CHECK-NEXT: Value: 0x236 # Check that we don't crash with --gc-sections # RUN: ld.lld --gc-sections -o %t2 --script %t.script %t -shared diff --git a/test/ELF/linkerscript/no-pt-load.s b/test/ELF/linkerscript/no-pt-load.s deleted file mode 100644 index c70402501391..000000000000 --- a/test/ELF/linkerscript/no-pt-load.s +++ /dev/null @@ -1,5 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "PHDRS {foo PT_DYNAMIC ;} " \ -# RUN: "SECTIONS { .text : { *(.text) } : foo }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t.o diff --git a/test/ELF/linkerscript/no-pt-load.test b/test/ELF/linkerscript/no-pt-load.test new file mode 100644 index 000000000000..16f7f4409984 --- /dev/null +++ b/test/ELF/linkerscript/no-pt-load.test @@ -0,0 +1,11 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t.o +# RUN: ld.lld -o %t1 --script %s %t.o + +## Check we do not crash. + +PHDRS { foo PT_DYNAMIC; } + +SECTIONS { + .text : { *(.text) } : foo +} diff --git a/test/ELF/linkerscript/no-space.s b/test/ELF/linkerscript/no-space.s index 21a38e42b2a3..7232495a3fd4 100644 --- a/test/ELF/linkerscript/no-space.s +++ b/test/ELF/linkerscript/no-space.s @@ -1,13 +1,13 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS {foo 0 : {*(foo*)} }" > %t.script +# RUN: echo "SECTIONS {foo 0 : {*(foo*)} .dynsym : {*(.dynsym)} .dynstr : {*(.dynstr)} }" > %t.script # RUN: ld.lld --hash-style=sysv -o %t --script %t.script %t.o -shared -# RUN: llvm-readobj -elf-output-style=GNU -l %t | FileCheck %s +# RUN: llvm-readelf -l %t | FileCheck %s -# RUN: echo "SECTIONS {foo : {*(foo*)} }" > %t.script +# RUN: echo "SECTIONS {foo : {*(foo*)} .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } }" > %t.script # RUN: ld.lld --hash-style=sysv -o %t --script %t.script %t.o -shared -# RUN: llvm-readobj -elf-output-style=GNU -l %t | FileCheck %s +# RUN: llvm-readelf -l %t | FileCheck %s # There is not enough address space available for the header, so just start the PT_LOAD # after it. Don't create a PT_PHDR as the header is not allocated. @@ -18,7 +18,7 @@ # CHECK: Section to Segment mapping: # CHECK-NEXT: Segment Sections... -# CHECK-NEXT: 00 foo .text .dynsym .hash .dynstr +# CHECK-NEXT: 00 foo .dynsym .dynstr .hash .section foo, "a" .quad 0 diff --git a/test/ELF/linkerscript/nobits-offset.s b/test/ELF/linkerscript/nobits-offset.s new file mode 100644 index 000000000000..c4141487630b --- /dev/null +++ b/test/ELF/linkerscript/nobits-offset.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# 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: };" > %t.script +# RUN: ld.lld %t.o -T %t.script -o %t +# RUN: llvm-readelf --sections %t | FileCheck %s + +# We used to misalign section offsets if the first section in a +# PT_LOAD was SHT_NOBITS. + +# CHECK: [ 2] .text PROGBITS 0000000000000010 001010 000010 00 AX 0 0 16 + +.global _start +_start: + nop +.p2align 4 diff --git a/test/ELF/linkerscript/noload.s b/test/ELF/linkerscript/noload.s index 28be55df1f12..bd49160d80bd 100644 --- a/test/ELF/linkerscript/noload.s +++ b/test/ELF/linkerscript/noload.s @@ -2,12 +2,13 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o # RUN: echo "SECTIONS { \ # RUN: .data_noload_a (NOLOAD) : { *(.data_noload_a) } \ -# RUN: .data_noload_b (0x10000) (NOLOAD) : { *(.data_noload_b) } };" > %t.script +# RUN: .data_noload_b (0x10000) (NOLOAD) : { *(.data_noload_b) } \ +# RUN: .text (0x20000) : { *(.text) } };" > %t.script # RUN: ld.lld -o %t --script %t.script %t.o -# RUN: llvm-readobj --symbols -sections %t | FileCheck %s +# RUN: llvm-readobj -sections -program-headers %t | FileCheck %s # CHECK: Section { -# CHECK: Index: 2 +# CHECK: Index: 1 # CHECK-NEXT: Name: .data_noload_a # CHECK-NEXT: Type: SHT_NOBITS # CHECK-NEXT: Flags [ @@ -15,7 +16,7 @@ # CHECK-NEXT: SHF_WRITE # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x1000 +# CHECK-NEXT: Offset: 0xE8 # CHECK-NEXT: Size: 4096 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -23,7 +24,7 @@ # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 3 +# CHECK-NEXT: Index: 2 # CHECK-NEXT: Name: .data_noload_b # CHECK-NEXT: Type: SHT_NOBITS # CHECK-NEXT: Flags [ @@ -31,13 +32,29 @@ # CHECK-NEXT: SHF_WRITE # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x10000 -# CHECK-NEXT: Offset: 0x1000 +# CHECK-NEXT: Offset: 0xE8 # CHECK-NEXT: Size: 4096 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 1 # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: } +# CHECK: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD (0x1) +# CHECK-NEXT: Offset: 0x1000 +# CHECK-NEXT: VirtualAddress: 0x20000 +# CHECK-NEXT: PhysicalAddress: 0x20000 +# CHECK-NEXT: FileSize: 1 +# CHECK-NEXT: MemSize: 1 +# CHECK-NEXT: Flags [ (0x5) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: PF_X (0x1) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 4096 +# CHECK-NEXT: } + +.section .text,"ax",@progbits + nop .section .data_noload_a,"aw",@progbits .zero 4096 diff --git a/test/ELF/linkerscript/non-absolute.s b/test/ELF/linkerscript/non-absolute.s index a0e9e7dc6782..b4b25a7bbf84 100644 --- a/test/ELF/linkerscript/non-absolute.s +++ b/test/ELF/linkerscript/non-absolute.s @@ -5,9 +5,11 @@ # RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=DUMP # RUN: llvm-readobj -t %t | FileCheck %s --check-prefix=SYMBOL +# B = A + 0x1 = -0x10 + 0x1 = -0xf -> 0xFFFFFFFFFFFFFFF1 +# B - (0x94+6) = -0xf - (0x94+6) = -169 # DUMP: Disassembly of section .text: # DUMP-NEXT: foo: -# DUMP-NEXT: 0: {{.*}} -21(%rip), %eax +# DUMP-NEXT: 94: {{.*}} -169(%rip), %eax # SYMBOL: Symbol { # SYMBOL: Name: B @@ -18,7 +20,7 @@ # SYMBOL-NEXT: Other [ # SYMBOL-NEXT: STV_HIDDEN # SYMBOL-NEXT: ] -# SYMBOL-NEXT: Section: .text +# SYMBOL-NEXT: Section: .dynsym # SYMBOL-NEXT: } .text diff --git a/test/ELF/linkerscript/non-absolute2.s b/test/ELF/linkerscript/non-absolute2.s deleted file mode 100644 index 97c34d31a912..000000000000 --- a/test/ELF/linkerscript/non-absolute2.s +++ /dev/null @@ -1,12 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o -# RUN: echo "SECTIONS { A = . + 0x1; . += 0x1000; }" > %t.script -# RUN: ld.lld -shared %t1.o --script %t.script -o %t -# RUN: llvm-objdump -section-headers -t %t | FileCheck %s - -# CHECK: Sections: -# CHECK-NEXT: Idx Name Size Address -# CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .text 00000000 0000000000001000 - -# CHECK: 0000000000000001 .text 00000000 A diff --git a/test/ELF/linkerscript/non-absolute2.test b/test/ELF/linkerscript/non-absolute2.test new file mode 100644 index 000000000000..b60666412b8a --- /dev/null +++ b/test/ELF/linkerscript/non-absolute2.test @@ -0,0 +1,17 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t1.o +# RUN: ld.lld -shared %t1.o --script %s -o %t +# RUN: llvm-objdump -section-headers -t %t | FileCheck %s + +SECTIONS { + A = . + 0x1; + . += 0x1000; +} + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .dynsym 00000030 0000000000001000 +# CHECK: 5 .text 00000000 000000000000106c + +# CHECK: 0000000000000001 .dynsym 00000000 A diff --git a/test/ELF/linkerscript/non-alloc-segment.s b/test/ELF/linkerscript/non-alloc-segment.s index 229f028a16b2..d9984b3867d4 100644 --- a/test/ELF/linkerscript/non-alloc-segment.s +++ b/test/ELF/linkerscript/non-alloc-segment.s @@ -16,7 +16,7 @@ # RUN: .foo : {*(.foo)} :foo \ # RUN: }" > %t.script # RUN: ld.lld -o %t --script %t.script %t.o -# RUN: llvm-readobj -elf-output-style=GNU -s -l %t | FileCheck %s +# RUN: llvm-readelf -s -l %t | FileCheck %s # RUN: llvm-readobj -l %t | FileCheck --check-prefix=PHDR %s # CHECK: Program Headers: diff --git a/test/ELF/linkerscript/non-alloc.s b/test/ELF/linkerscript/non-alloc.s index 3257cb965565..87f9afff8091 100644 --- a/test/ELF/linkerscript/non-alloc.s +++ b/test/ELF/linkerscript/non-alloc.s @@ -1,9 +1,9 @@ # 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 -o %t.o # RUN: echo "SECTIONS { .foo 0 : {*(foo)} }" > %t.script -# RUN: ld.lld --hash-style=sysv -o %t1 --script %t.script %t -shared -# RUN: llvm-readobj -elf-output-style=GNU -s -l %t1 | FileCheck %s +# RUN: ld.lld --hash-style=sysv -o %t --script %t.script %t.o -shared +# RUN: llvm-readelf -s -l %t | FileCheck %s # Test that we create all necessary PT_LOAD. We use to stop at the first # non-alloc, causing us to not create PT_LOAD for linker generated sections. @@ -15,7 +15,7 @@ # CHECK: Section to Segment mapping: # CHECK-NEXT: Segment Sections... -# CHECK-NEXT: 00 .text .dynsym .hash .dynstr +# CHECK-NEXT: 00 .dynsym .hash .dynstr .text # CHECK-NEXT: 01 .dynamic nop diff --git a/test/ELF/linkerscript/numbers.s b/test/ELF/linkerscript/numbers.s index d4fd13fd8197..98d7e3361343 100644 --- a/test/ELF/linkerscript/numbers.s +++ b/test/ELF/linkerscript/numbers.s @@ -29,12 +29,12 @@ ## Mailformed number errors. # RUN: echo "SECTIONS { . = 0x11h; }" > %t2.script -# RUN: not ld.lld %t --script %t2.script -o %t3 2>&1 | \ +# RUN: not ld.lld %t --script %t2.script -o /dev/null 2>&1 | \ # RUN: FileCheck --check-prefix=ERR1 %s # ERR1: malformed number: 0x11h # RUN: echo "SECTIONS { . = 0x11k; }" > %t3.script -# RUN: not ld.lld %t --script %t3.script -o %t4 2>&1 | \ +# RUN: not ld.lld %t --script %t3.script -o /dev/null 2>&1 | \ # RUN: FileCheck --check-prefix=ERR2 %s # ERR2: malformed number: 0x11k @@ -43,13 +43,28 @@ # RUN: FileCheck --check-prefix=ERR3 %s # ERR3: malformed number: 0x11m +# RUN: echo "SECTIONS { . = 1zh; }" > %t5.script +# RUN: not ld.lld %t --script %t5.script -o %t5 2>&1 | \ +# RUN: FileCheck --check-prefix=ERR4 %s +# ERR4: malformed number: 1zh + +# RUN: echo "SECTIONS { . = 1zk; }" > %t6.script +# RUN: not ld.lld %t --script %t6.script -o %t6 2>&1 | \ +# RUN: FileCheck --check-prefix=ERR5 %s +# ERR5: malformed number: 1zk + +# RUN: echo "SECTIONS { . = 1zm; }" > %t7.script +# RUN: not ld.lld %t --script %t7.script -o /dev/null 2>&1 | \ +# RUN: FileCheck --check-prefix=ERR6 %s +# ERR6: malformed number: 1zm + ## Make sure that numbers can be followed by a ":" with and without a space, ## e.g. "0x100 :" or "0x100:" # RUN: echo "SECTIONS { \ # RUN: .hex1 0x400 : { *(.hex.1) } \ # RUN: .hex2 0x500:{ *(.hex.2) } \ -# RUN: }" > %t5.script -# RUN: ld.lld %t --script %t5.script -o %t6 +# RUN: }" > %t8.script +# RUN: ld.lld %t --script %t8.script -o %t6 # RUN: llvm-objdump -section-headers %t6 | FileCheck -check-prefix=SECADDR %s # SECADDR: Sections: # SECADDR-NEXT: Idx Name Size Address diff --git a/test/ELF/linkerscript/openbsd-bootdata.s b/test/ELF/linkerscript/openbsd-bootdata.s deleted file mode 100644 index 3e90574bb3a3..000000000000 --- a/test/ELF/linkerscript/openbsd-bootdata.s +++ /dev/null @@ -1,7 +0,0 @@ -# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o -# RUN: echo "PHDRS { boot PT_OPENBSD_BOOTDATA; }" > %t.script -# RUN: ld.lld --script %t.script %t.o -o %t -# RUN: llvm-readobj --program-headers -s %t | FileCheck %s - -# CHECK: ProgramHeader { -# CHECK: Type: PT_OPENBSD_BOOTDATA (0x65A41BE6) diff --git a/test/ELF/linkerscript/openbsd-bootdata.test b/test/ELF/linkerscript/openbsd-bootdata.test new file mode 100644 index 000000000000..6846c7f22f86 --- /dev/null +++ b/test/ELF/linkerscript/openbsd-bootdata.test @@ -0,0 +1,9 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux /dev/null -o %t.o +# RUN: ld.lld --script %s %t.o -o %t +# RUN: llvm-readobj --program-headers -s %t | FileCheck %s + +PHDRS { boot PT_OPENBSD_BOOTDATA; } + +# CHECK: ProgramHeader { +# CHECK: Type: PT_OPENBSD_BOOTDATA (0x65A41BE6) diff --git a/test/ELF/linkerscript/openbsd-randomize.s b/test/ELF/linkerscript/openbsd-randomize.s index bf885f423b02..575a6b25be78 100644 --- a/test/ELF/linkerscript/openbsd-randomize.s +++ b/test/ELF/linkerscript/openbsd-randomize.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o # RUN: echo "PHDRS { text PT_LOAD FILEHDR PHDRS; rand PT_OPENBSD_RANDOMIZE; } \ # RUN: SECTIONS { . = SIZEOF_HEADERS; \ diff --git a/test/ELF/linkerscript/openbsd-wxneeded.s b/test/ELF/linkerscript/openbsd-wxneeded.test index d371da9d8645..1868c0e08802 100644 --- a/test/ELF/linkerscript/openbsd-wxneeded.s +++ b/test/ELF/linkerscript/openbsd-wxneeded.test @@ -1,8 +1,10 @@ -# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o -# RUN: echo "PHDRS { text PT_LOAD FILEHDR PHDRS; wxneeded PT_OPENBSD_WXNEEDED; }" > %t.script -# RUN: ld.lld -z wxneeded --script %t.script %t.o -o %t +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux /dev/null -o %t.o +# RUN: ld.lld -z wxneeded --script %s %t.o -o %t # RUN: llvm-readobj --program-headers %t | FileCheck %s +PHDRS { text PT_LOAD FILEHDR PHDRS; wxneeded PT_OPENBSD_WXNEEDED; } + # CHECK: ProgramHeader { # CHECK: Type: PT_OPENBSD_WXNEEDED (0x65A3DBE7) # CHECK-NEXT: Offset: 0x0 diff --git a/test/ELF/linkerscript/operators.s b/test/ELF/linkerscript/operators.test index 494fc08c0f99..2be24dfc2fe3 100644 --- a/test/ELF/linkerscript/operators.s +++ b/test/ELF/linkerscript/operators.test @@ -1,42 +1,57 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "SECTIONS { \ -# RUN: _start = .; \ -# RUN: plus = 1 + 2 + 3; \ -# RUN: minus = 5 - 1; \ -# RUN: div = 6 / 2; \ -# RUN: mul = 1 + 2 * 3; \ -# RUN: nospace = 1+2*6/3; \ -# RUN: braces = 1 + (2 + 3) * 4; \ -# RUN: and = 0xbb & 0xee; \ -# RUN: ternary1 = 1 ? 1 : 2; \ -# RUN: ternary2 = 0 ? 1 : 2; \ -# RUN: less = 1 < 0 ? 1 : 2; \ -# RUN: lesseq = 1 <= 1 ? 1 : 2; \ -# RUN: greater = 0 > 1 ? 1 : 2; \ -# RUN: greatereq = 1 >= 1 ? 1 : 2; \ -# RUN: eq = 1 == 1 ? 1 : 2; \ -# RUN: neq = 1 != 1 ? 1 : 2; \ -# RUN: plusassign = 1; \ -# RUN: plusassign += 2; \ -# RUN: unary = -1 + 3; \ -# RUN: lshift = 1 << 5; \ -# RUN: rshift = 0xff >> 3; \ -# RUN: maxpagesize = CONSTANT (MAXPAGESIZE); \ -# RUN: commonpagesize = CONSTANT (COMMONPAGESIZE); \ -# RUN: . = 0xfff0; \ -# RUN: datasegmentalign = DATA_SEGMENT_ALIGN (0xffff, 0); \ -# RUN: datasegmentalign2 = DATA_SEGMENT_ALIGN (0, 0); \ -# RUN: _end = .; \ -# RUN: minus_rel = _end - 0x10; \ -# RUN: minus_abs = _end - _start; \ -# RUN: }" > %t.script -# RUN: ld.lld %t --script %t.script -o %t2 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t +# RUN: ld.lld %t --script %s -o %t2 # RUN: llvm-objdump -t %t2 | FileCheck %s +SECTIONS { + _start = .; + plus = 1 + 2 + 3; + minus = 5 - 1; + div = 6 / 2; + mod = 20 % 7; + mul = 1 + 2 * 3; + nospace = 1+2*6/3; + braces = 1 + (2 + 3) * 4; + and = 0xbb & 0xee; + ternary1 = 1 ? 1 : 2; + ternary2 = 0 ? 1 : 2; + less = 1 < 0 ? 1 : 2; + lesseq = 1 <= 1 ? 1 : 2; + greater = 0 > 1 ? 1 : 2; + greatereq = 1 >= 1 ? 1 : 2; + eq = 1 == 1 ? 1 : 2; + neq = 1 != 1 ? 1 : 2; + plusassign = 1; + plusassign += 2; + unary = -1 + 3; + lshift = 1 << 5; + rshift = 0xff >> 3; + precedence1 = 1 | 0xff & 1 << 1 + 1 * 2; + precedence2 = (1 | (0xff & (1 << (1 + (1 * 2))))); + maxpagesize = CONSTANT (MAXPAGESIZE); + commonpagesize = CONSTANT (COMMONPAGESIZE); + . = 0xfff0; + datasegmentalign = DATA_SEGMENT_ALIGN (0xffff, 0); + datasegmentalign2 = DATA_SEGMENT_ALIGN (0, 0); + _end = .; + minus_rel = _end - 0x10; + minus_abs = _end - _start; + max = MAX(11, 22); + min = MIN(11, 22); + logicaland1 = 0 && 0; + logicaland2 = 0 && 1; + logicaland3 = 1 && 0; + logicaland4 = 1 && 1; + logicalor1 = 0 || 0; + logicalor2 = 0 || 1; + logicalor3 = 1 || 0; + logicalor4 = 1 || 1; +} + # CHECK: 00000000000006 *ABS* 00000000 plus # CHECK: 00000000000004 *ABS* 00000000 minus # CHECK: 00000000000003 *ABS* 00000000 div +# CHECK: 00000000000006 *ABS* 00000000 mod # CHECK: 00000000000007 *ABS* 00000000 mul # CHECK: 00000000000005 *ABS* 00000000 nospace # CHECK: 00000000000015 *ABS* 00000000 braces @@ -53,12 +68,24 @@ # CHECK: 00000000000002 *ABS* 00000000 unary # CHECK: 00000000000020 *ABS* 00000000 lshift # CHECK: 0000000000001f *ABS* 00000000 rshift +# CHECK: 00000000000009 *ABS* 00000000 precedence1 +# CHECK: 00000000000009 *ABS* 00000000 precedence2 # CHECK: 00000000001000 *ABS* 00000000 maxpagesize # CHECK: 00000000001000 *ABS* 00000000 commonpagesize # CHECK: 0000000000ffff *ABS* 00000000 datasegmentalign # CHECK: 0000000000fff0 *ABS* 00000000 datasegmentalign2 # CHECK: 0000000000ffe0 .text 00000000 minus_rel # CHECK: 0000000000fff0 *ABS* 00000000 minus_abs +# CHECK: 00000000000016 *ABS* 00000000 max +# CHECK: 0000000000000b *ABS* 00000000 min +# CHECK: 00000000000000 *ABS* 00000000 logicaland1 +# CHECK: 00000000000000 *ABS* 00000000 logicaland2 +# CHECK: 00000000000000 *ABS* 00000000 logicaland3 +# CHECK: 00000000000001 *ABS* 00000000 logicaland4 +# CHECK: 00000000000000 *ABS* 00000000 logicalor1 +# CHECK: 00000000000001 *ABS* 00000000 logicalor2 +# CHECK: 00000000000001 *ABS* 00000000 logicalor3 +# CHECK: 00000000000001 *ABS* 00000000 logicalor4 ## Mailformed number error. # RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script @@ -88,14 +115,16 @@ # RUN: echo "SECTIONS { . = 1 / 0; }" > %t.script # RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ # RUN: FileCheck --check-prefix=DIVZERO %s -# DIVZERO: division by zero +# DIVZERO: {{.*}}.script:1: division by zero + +## Mod by zero error. +# RUN: echo "SECTIONS { . = 1 % 0; }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=MODZERO %s +# MODZERO: {{.*}}.script:1: modulo by zero ## Broken ternary operator expression. # RUN: echo "SECTIONS { . = 1 ? 2; }" > %t.script # RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ # RUN: FileCheck --check-prefix=TERNERR %s # TERNERR: : expected, but got ; - -.globl _start -_start: -nop diff --git a/test/ELF/linkerscript/orphan-first-cmd.s b/test/ELF/linkerscript/orphan-first-cmd.s deleted file mode 100644 index 263cb30d6868..000000000000 --- a/test/ELF/linkerscript/orphan-first-cmd.s +++ /dev/null @@ -1,20 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS { \ -# RUN: foo = 123; \ -# RUN: . = 0x1000; \ -# RUN: . = 0x2000; \ -# RUN: .bar : { *(.bar) } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t -T %t.script %t.o -shared -# RUN: llvm-readobj -s %t | FileCheck %s - -# CHECK: Name: .text -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: SHF_EXECINSTR -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x1000 - -.section .bar, "aw" diff --git a/test/ELF/linkerscript/orphan-first-cmd.test b/test/ELF/linkerscript/orphan-first-cmd.test new file mode 100644 index 000000000000..84b183f96efb --- /dev/null +++ b/test/ELF/linkerscript/orphan-first-cmd.test @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: echo '.section .bar, "aw"' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o +# RUN: ld.lld -o %t -T %s %t.o -shared +# RUN: llvm-readobj -s %t | FileCheck %s + +SECTIONS { + foo = 123; + . = 0x1000; + . = 0x2000; + .bar : { *(.bar) } +} + +# CHECK: Name: .text +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_EXECINSTR +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x1070 diff --git a/test/ELF/linkerscript/orphan-phdrs.s b/test/ELF/linkerscript/orphan-phdrs.s index 648911162e97..f9d1467b532a 100644 --- a/test/ELF/linkerscript/orphan-phdrs.s +++ b/test/ELF/linkerscript/orphan-phdrs.s @@ -10,7 +10,7 @@ # RUN: .rw : { *(.rw) } \ # RUN: }" > %t.script # RUN: ld.lld -o %t --script %t.script %t.o -# RUN: llvm-readobj -elf-output-style=GNU -s -l %t | FileCheck %s +# RUN: llvm-readelf -s -l %t | FileCheck %s ## Check that the orphan section is placed correctly and belongs to ## the correct segment. @@ -18,6 +18,7 @@ # CHECK: Section Headers # CHECK: .text # CHECK-NEXT: .orphan +# CHECK-NEXT: .empty # CHECK-NEXT: .rw # CHECK: Segment Sections diff --git a/test/ELF/linkerscript/orphan.s b/test/ELF/linkerscript/orphan.s index f51085383a9e..4dbaf37c687e 100644 --- a/test/ELF/linkerscript/orphan.s +++ b/test/ELF/linkerscript/orphan.s @@ -13,7 +13,7 @@ ## .bss is SHT_NOBITS section and should be last RW section, so some space ## in ELF file could be saved. # CHECK: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .text 00000000 0000000000000000 TEXT DATA +# CHECK-NEXT: 1 .text 00000000 0000000000000000 TEXT # CHECK-NEXT: 2 .rw1 00000008 0000000000000000 DATA # CHECK-NEXT: 3 .rw2 00000008 0000000000000008 DATA # CHECK-NEXT: 4 .rw3 00000008 0000000000000010 DATA diff --git a/test/ELF/linkerscript/out-of-order.s b/test/ELF/linkerscript/out-of-order.s index c43df43e5002..da8c103bb47f 100644 --- a/test/ELF/linkerscript/out-of-order.s +++ b/test/ELF/linkerscript/out-of-order.s @@ -1,19 +1,37 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-linux %s -o %t.o -# RUN: echo "SECTIONS { .data 0x4000 : { *(.data) } .text 0x2000 : { *(.text) } }" > %t.script +# RUN: echo "SECTIONS { .data 0x4000 : {*(.data)} .dynsym 0x2000 : {*(.dynsym)} .dynstr : {*(.dynstr)} }" > %t.script # RUN: ld.lld --hash-style=sysv -o %t.so --script %t.script %t.o -shared # RUN: llvm-objdump -section-headers %t.so | FileCheck %s +# Note: how the layout is done: +# we need to layout 2 segments, each contains sections: +# seg1: .data .dynamic +# seg2: .dynsym .dynstr .text .hash +# for each segment, we start from the first section, regardless +# whether it is an orphan or not (sections that are not listed in the +# linkerscript are orphans): +# for seg1, we assign address: .data(0x4000), .dynamic(0x4008) +# for seg2, we assign address: .dynsym(0x2000), .dynstr(0x2018) ... +# .dynsym is not an orphan, so we take address from script, we assign +# .dynstr current address cursor, which is the end # of .dynsym and so +# on for later sections. + +# Also note, it is absolutely *illegal* to have section addresses of +# the same segment in none-increasing order, authors of linker scripts +# must take responsibility to make sure this does not happen. + # CHECK: Sections: # CHECK-NEXT: Idx Name Size Address Type # CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .data 00000008 0000000000004000 DATA +# CHECK-NEXT: 1 .data 00000008 0000000000004000 # CHECK-NEXT: 2 .dynamic 00000060 0000000000004008 -# CHECK-NEXT: 3 .text 00000008 0000000000002000 TEXT DATA -# CHECK-NEXT: 4 .dynsym 00000018 0000000000002008 -# CHECK-NEXT: 5 .hash 00000010 0000000000002020 -# CHECK-NEXT: 6 .dynstr 00000001 0000000000002030 +# CHECK-NEXT: 3 .dynsym 00000018 0000000000002000 +# CHECK-NEXT: 4 .dynstr 00000001 0000000000002018 +# CHECK-NEXT: 5 .hash 00000010 000000000000201c +# CHECK-NEXT: 6 .text 00000008 000000000000202c .quad 0 .data .quad 0 + diff --git a/test/ELF/linkerscript/output-too-large.s b/test/ELF/linkerscript/output-too-large.s index c892a88a947e..ca85465036fe 100644 --- a/test/ELF/linkerscript/output-too-large.s +++ b/test/ELF/linkerscript/output-too-large.s @@ -1,7 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o # RUN: echo "SECTIONS { .text : { . = 0xffffffff; *(.text*); } }" > %t.script -# RUN: not ld.lld --script %t.script %t.o -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld --no-check-sections --script %t.script %t.o -o /dev/null 2>&1 | FileCheck %s # CHECK: error: output file too large .global _start diff --git a/test/ELF/linkerscript/outputarch.s b/test/ELF/linkerscript/outputarch.s deleted file mode 100644 index dd3bf93611b4..000000000000 --- a/test/ELF/linkerscript/outputarch.s +++ /dev/null @@ -1,4 +0,0 @@ -# REQUIRES: x86 -# RUN: echo "OUTPUT_ARCH(All data written here is ignored)" > %t.script -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %t1 -# RUN: ld.lld -shared -o %t2 %t1 %t.script diff --git a/test/ELF/linkerscript/outputarch.test b/test/ELF/linkerscript/outputarch.test new file mode 100644 index 000000000000..4819a983cfce --- /dev/null +++ b/test/ELF/linkerscript/outputarch.test @@ -0,0 +1,5 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd /dev/null -o %t1 +# RUN: ld.lld -shared -o %t2 %t1 %s + +OUTPUT_ARCH(All data written here is ignored) diff --git a/test/ELF/linkerscript/overlapping-sections.s b/test/ELF/linkerscript/overlapping-sections.s new file mode 100644 index 000000000000..818301fd2b0e --- /dev/null +++ b/test/ELF/linkerscript/overlapping-sections.s @@ -0,0 +1,113 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +# RUN: echo "SECTIONS { \ +# RUN: .sec1 0x8000 : AT(0x8000) { sec1_start = .; *(.first_sec) sec1_end = .;} \ +# RUN: .sec2 0x8800 : AT(0x8080) { sec2_start = .; *(.second_sec) sec2_end = .;} \ +# RUN: }" > %t-lma.script +# RUN: not ld.lld -o %t.so --script %t-lma.script %t.o -shared 2>&1 | FileCheck %s -check-prefix LMA-OVERLAP-ERR +# LMA-OVERLAP-ERR: error: section .sec1 load address range overlaps with .sec2 +# LMA-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF] +# LMA-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8080, 0x817F] + +# Check that we create the expected binary with --noinhibit-exec or --no-check-sections: +# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --noinhibit-exec +# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --no-check-sections -fatal-warnings +# RUN: ld.lld -o %t.so --script %t-lma.script %t.o -shared --check-sections --no-check-sections -fatal-warnings + +# Verify that the .sec2 was indeed placed in a PT_LOAD where the PhysAddr +# overlaps with where .sec1 is loaded: +# RUN: llvm-readobj -sections -program-headers -elf-output-style=GNU %t.so | FileCheck %s -check-prefix BAD-LMA +# BAD-LMA-LABEL: Section Headers: +# BAD-LMA: .sec1 PROGBITS 0000000000008000 002000 000100 00 WA 0 0 1 +# BAD-LMA: .sec2 PROGBITS 0000000000008800 002800 000100 00 WA 0 0 1 +# BAD-LMA-LABEL: Program Headers: +# BAD-LMA-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# BAD-LMA-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000100 0x000100 R E 0x1000 +# BAD-LMA-NEXT: LOAD 0x002000 0x0000000000008000 0x0000000000008000 0x000100 0x000100 RW 0x1000 +# BAD-LMA-NEXT: LOAD 0x002800 0x0000000000008800 0x0000000000008080 0x000170 0x000170 RW 0x1000 +# BAD-LMA-LABEL: Section to Segment mapping: +# BAD-LMA: 01 .sec1 +# BAD-LMA: 02 .sec2 .dynamic + +# Now try a script where the virtual memory addresses overlap but ensure that the +# load addresses don't: +# RUN: echo "SECTIONS { \ +# RUN: .sec1 0x8000 : AT(0x8000) { sec1_start = .; *(.first_sec) sec1_end = .;} \ +# RUN: .sec2 0x8020 : AT(0x8800) { sec2_start = .; *(.second_sec) sec2_end = .;} \ +# RUN: }" > %t-vaddr.script +# RUN: not ld.lld -o %t.so --script %t-vaddr.script %t.o -shared 2>&1 | FileCheck %s -check-prefix VADDR-OVERLAP-ERR +# VADDR-OVERLAP-ERR: error: section .sec1 virtual address range overlaps with .sec2 +# VADDR-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF] +# VADDR-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8020, 0x811F] + +# Check that the expected binary was created with --noinhibit-exec: +# RUN: ld.lld -o %t.so --script %t-vaddr.script %t.o -shared --noinhibit-exec +# RUN: llvm-readobj -sections -program-headers -elf-output-style=GNU %t.so | FileCheck %s -check-prefix BAD-VADDR +# BAD-VADDR-LABEL: Section Headers: +# BAD-VADDR: .sec1 PROGBITS 0000000000008000 002000 000100 00 WA 0 0 1 +# BAD-VADDR: .sec2 PROGBITS 0000000000008020 003020 000100 00 WA 0 0 1 +# BAD-VADDR-LABEL: Program Headers: +# BAD-VADDR-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# BAD-VADDR-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000100 0x000100 R E 0x1000 +# BAD-VADDR-NEXT: LOAD 0x002000 0x0000000000008000 0x0000000000008000 0x000100 0x000100 RW 0x1000 +# BAD-VADDR-NEXT: LOAD 0x003020 0x0000000000008020 0x0000000000008800 0x000170 0x000170 RW 0x1000 +# BAD-VADDR-LABEL: Section to Segment mapping: +# BAD-VADDR: 01 .sec1 +# BAD-VADDR: 02 .sec2 .dynamic + +# Finally check the case where both LMA and vaddr overlap + +# RUN: echo "SECTIONS { \ +# RUN: .sec1 0x8000 : { sec1_start = .; *(.first_sec) sec1_end = .;} \ +# RUN: .sec2 0x8040 : { sec2_start = .; *(.second_sec) sec2_end = .;} \ +# RUN: }" > %t-both-overlap.script + +# RUN: not ld.lld -o %t.so --script %t-both-overlap.script %t.o -shared 2>&1 | FileCheck %s -check-prefix BOTH-OVERLAP-ERR + +# BOTH-OVERLAP-ERR: error: section .sec1 file range overlaps with .sec2 +# BOTH-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x2000, 0x20FF] +# BOTH-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x2040, 0x213F] +# BOTH-OVERLAP-ERR: error: section .sec1 virtual address range overlaps with .sec2 +# BOTH-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF] +# BOTH-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8040, 0x813F] +# BOTH-OVERLAP-ERR: error: section .sec1 load address range overlaps with .sec2 +# BOTH-OVERLAP-ERR-NEXT: >>> .sec1 range is [0x8000, 0x80FF] +# BOTH-OVERLAP-ERR-NEXT: >>> .sec2 range is [0x8040, 0x813F] + +# RUN: ld.lld -o %t.so --script %t-both-overlap.script %t.o -shared --noinhibit-exec +# Note: In case everything overlaps we create a binary with overlapping file +# offsets. ld.bfd seems to place .sec1 to file offset 18000 and .sec2 +# at 18100 so that only virtual addr and LMA overlap +# However, in order to create such a broken binary the user has to ignore a +# fatal error by passing --noinhibit-exec, so this behaviour is fine. + +# RUN: llvm-objdump -s %t.so | FileCheck %s -check-prefix BROKEN-OUTPUT-FILE +# BROKEN-OUTPUT-FILE-LABEL: Contents of section .sec1: +# BROKEN-OUTPUT-FILE-NEXT: 8000 01010101 01010101 01010101 01010101 +# BROKEN-OUTPUT-FILE-NEXT: 8010 01010101 01010101 01010101 01010101 +# BROKEN-OUTPUT-FILE-NEXT: 8020 01010101 01010101 01010101 01010101 +# BROKEN-OUTPUT-FILE-NEXT: 8030 01010101 01010101 01010101 01010101 +# Starting here the contents of .sec2 overwrites .sec1: +# BROKEN-OUTPUT-FILE-NEXT: 8040 02020202 02020202 02020202 02020202 + +# RUN: llvm-readobj -sections -program-headers -elf-output-style=GNU %t.so | FileCheck %s -check-prefix BAD-BOTH +# BAD-BOTH-LABEL: Section Headers: +# BAD-BOTH: .sec1 PROGBITS 0000000000008000 002000 000100 00 WA 0 0 1 +# BAD-BOTH: .sec2 PROGBITS 0000000000008040 002040 000100 00 WA 0 0 1 +# BAD-BOTH-LABEL: Program Headers: +# BAD-BOTH-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# BAD-BOTH-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 0x000100 0x000100 R E 0x1000 +# BAD-BOTH-NEXT: LOAD 0x002000 0x0000000000008000 0x0000000000008000 0x0001b0 0x0001b0 RW 0x1000 +# BAD-BOTH-LABEL: Section to Segment mapping: +# BAD-BOTH: 01 .sec1 .sec2 .dynamic + +.section .first_sec,"aw",@progbits +.rept 0x100 +.byte 1 +.endr + +.section .second_sec,"aw",@progbits +.rept 0x100 +.byte 2 +.endr diff --git a/test/ELF/linkerscript/overlay-reject.test b/test/ELF/linkerscript/overlay-reject.test new file mode 100644 index 000000000000..fcb82b6df4b5 --- /dev/null +++ b/test/ELF/linkerscript/overlay-reject.test @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: not ld.lld %t.o --script %s -o %t 2>&1 | FileCheck %s + +# CHECK: {{.*}}.test:{{.*}}: { expected, but got 0x3000 +# CHECK-NEXT: >>> .out.aaa 0x3000 : { *(.aaa) } +# CHECK-NEXT: >>> ^ + +SECTIONS { + OVERLAY 0x1000 : AT ( 0x2000 ) { + .out.aaa 0x3000 : { *(.aaa) } + } +} diff --git a/test/ELF/linkerscript/overlay-reject2.test b/test/ELF/linkerscript/overlay-reject2.test new file mode 100644 index 000000000000..490533c5fa5e --- /dev/null +++ b/test/ELF/linkerscript/overlay-reject2.test @@ -0,0 +1,17 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o +# RUN: not ld.lld %t.o --script %s -o %t 2>&1 | FileCheck %s + +# CHECK: {{.*}}.test:{{.*}}: { expected, but got AX +# CHECK-NEXT: >>> .out.aaa { *(.aaa) } > AX AT>FLASH +# CHECK-NEXT: >>> ^ + +MEMORY { + AX (ax) : ORIGIN = 0x3000, LENGTH = 0x4000 +} + +SECTIONS { + OVERLAY 0x1000 : AT ( 0x2000 ) { + .out.aaa { *(.aaa) } > AX AT>FLASH + } +} diff --git a/test/ELF/linkerscript/overlay.test b/test/ELF/linkerscript/overlay.test new file mode 100644 index 000000000000..a28ab610ec09 --- /dev/null +++ b/test/ELF/linkerscript/overlay.test @@ -0,0 +1,30 @@ +# REQUIRES: x86 +# RUN: echo 'nop; .section .small, "a"; .long 0; .section .big, "a"; .quad 1;' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o +# RUN: ld.lld %t.o --script %s -o %t + +SECTIONS { + OVERLAY 0x1000 : AT ( 0x4000 ) { + .out.big { *(.big) } + .out.small { *(.small) } + } +} + +## Here we check that can handle OVERLAY which will produce sections +## .out.big and .out.small with the same starting VAs, but different LMAs. +## Section .big is larger than .small, we check that placing of section +## .text does not cause overlapping error and that +## .text's VA is 0x1000 + max(sizeof(.out.big), sizeof(.out.small)). + +# RUN: llvm-readobj -sections -program-headers -elf-output-style=GNU %t | FileCheck %s + +# CHECK: Section Headers: +# CHECK: Name Type Address Off Size +# CHECK: .out.big PROGBITS 0000000000001000 001000 000008 +# CHECK: .out.small PROGBITS 0000000000001000 002000 000004 +# CHECK: .text PROGBITS 0000000000001008 002008 000001 + +# CHECK: Program Headers: +# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000004000 0x000008 0x000008 R E 0x1000 +# CHECK-NEXT: LOAD 0x002000 0x0000000000001000 0x0000000000004008 0x000009 0x000009 R E 0x1000 diff --git a/test/ELF/linkerscript/page-size-align.s b/test/ELF/linkerscript/page-size-align.s deleted file mode 100644 index 771bb13a8e6d..000000000000 --- a/test/ELF/linkerscript/page-size-align.s +++ /dev/null @@ -1,22 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o - -# RUN: echo "SECTIONS { \ -# RUN: . = SIZEOF_HEADERS; \ -# RUN: .text : { *(.text) } \ -# RUN: . = ALIGN(CONSTANT(MAXPAGESIZE)); \ -# RUN: . = . + 0x3000; \ -# RUN: .dynamic : { *(.dynamic) } \ -# RUN: }" > %t.script - -# RUN: ld.lld -T %t.script -z max-page-size=0x4000 %t.o -o %t.so -shared -# RUN: llvm-readobj -s %t.so | FileCheck %s - -# CHECK: Name: .dynamic -# CHECK-NEXT: Type: SHT_DYNAMIC -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: SHF_WRITE -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x7000 -# CHECK-NEXT: Offset: 0x3000 diff --git a/test/ELF/linkerscript/page-size-align.test b/test/ELF/linkerscript/page-size-align.test new file mode 100644 index 000000000000..f69413157426 --- /dev/null +++ b/test/ELF/linkerscript/page-size-align.test @@ -0,0 +1,21 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t.o +# RUN: ld.lld -T %s -z max-page-size=0x4000 %t.o -o %t.so -shared +# RUN: llvm-readobj -s %t.so | FileCheck %s + +SECTIONS { + . = SIZEOF_HEADERS; + .text : { *(.text) } + . = ALIGN(CONSTANT(MAXPAGESIZE)); + . = . + 0x3000; + .dynamic : { *(.dynamic) } +} + +# CHECK: Name: .dynamic +# CHECK-NEXT: Type: SHT_DYNAMIC +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x7000 +# CHECK-NEXT: Offset: 0x3000 diff --git a/test/ELF/linkerscript/parse-section-in-addr.test b/test/ELF/linkerscript/parse-section-in-addr.test new file mode 100644 index 000000000000..6f42a6fe2788 --- /dev/null +++ b/test/ELF/linkerscript/parse-section-in-addr.test @@ -0,0 +1,10 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t.o +# RUN: ld.lld -o %t.so --script %s %t.o -shared +# RUN: llvm-readelf -S %t.so | FileCheck %s + +SECTIONS { + .foo-bar : AT(ADDR(.foo-bar)) { *(.text) } +} + +# CHECK: .foo-bar diff --git a/test/ELF/linkerscript/provide-empty-section.s b/test/ELF/linkerscript/provide-empty-section.s new file mode 100644 index 000000000000..56cb6aca1e3b --- /dev/null +++ b/test/ELF/linkerscript/provide-empty-section.s @@ -0,0 +1,30 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tundefined.o +# RUN: echo "foo=42" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %tdefined.o +# RUN: echo "call foo" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %treference.o + +# RUN: echo "SECTIONS { .bar : { PROVIDE(foo = .); } }" > %t.script + +# Case 1: Provided symbol is undefined and not referenced - empty section should be removed. +# RUN: ld.lld %tundefined.o -T %t.script -o %t1.elf +# RUN: llvm-readobj -sections %t1.elf | FileCheck %s --check-prefix=NOSECTION + +# Case 2: Provided symbol is undefined and referenced - empty section should not be removed. +# RUN: ld.lld %tundefined.o %treference.o -T %t.script -o %t2.elf +# RUN: llvm-readobj -sections %t2.elf | FileCheck %s --check-prefix=SECTION + +# Case 3: Provided symbol is defined and not referenced - empty section should be removed. +# RUN: ld.lld %tdefined.o -T %t.script -o %t3.elf +# RUN: llvm-readobj -sections %t3.elf | FileCheck %s --check-prefix=NOSECTION + +# Case 4: Provided symbol is defined and referenced - empty section should not be removed. +# RUN: ld.lld %tdefined.o %treference.o -T %t.script -o %t4.elf +# RUN: llvm-readobj -sections %t4.elf | FileCheck %s --check-prefix=SECTION + +.global _start +_start: + ret + +# SECTION: .bar +# NOSECTION-NOT: .bar diff --git a/test/ELF/linkerscript/provide-shared2.s b/test/ELF/linkerscript/provide-shared2.s new file mode 100644 index 000000000000..8a3200b6f545 --- /dev/null +++ b/test/ELF/linkerscript/provide-shared2.s @@ -0,0 +1,13 @@ +# 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/provide-shared2.s -o %t2.o +# RUN: ld.lld %t2.o -o %t2.so -shared +# RUN: echo "SECTIONS { . = . + SIZEOF_HEADERS; PROVIDE(foo = 42); }" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o %t2.so +# RUN: llvm-readelf --dyn-symbols %t | FileCheck %s + +# CHECK: 1 1: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS foo@ + +.global _start +_start: + nop diff --git a/test/ELF/linkerscript/pt-interp.test b/test/ELF/linkerscript/pt-interp.test new file mode 100644 index 000000000000..0441817aea6d --- /dev/null +++ b/test/ELF/linkerscript/pt-interp.test @@ -0,0 +1,21 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux /dev/null -o %t.o +# RUN: ld.lld -o %t.so -shared %t.o + +## Check we create PT_INTERP program header when it is specified in PHDRS. +# RUN: echo "PHDRS { interp PT_INTERP; }" > %t1.script +# RUN: ld.lld -o %t1 --script %t1.script %t.o %t.so --dynamic-linker foo +# RUN: llvm-readobj -program-headers %t1 | FileCheck %s +# CHECK: PT_INTERP + +## Check we do not create it if it is not specified, +## but only if PHDRS is not empty by itself. +# RUN: echo "PHDRS { ph_text PT_LOAD; }" > %t2.script +# RUN: ld.lld -o %t1 --script %t2.script %t.o %t.so --dynamic-linker foo +# RUN: llvm-readobj -program-headers %t1 | FileCheck %s --check-prefix=NOINTERP +# NOINTERP-NOT: PT_INTERP + +## Otherwise, if PHDRS is empty, we create PT_INTERP header. +# RUN: echo "PHDRS {}" > %t3.script +# RUN: ld.lld -o %t1 --script %t3.script %t.o %t.so --dynamic-linker foo +# RUN: llvm-readobj -program-headers %t1 | FileCheck %s diff --git a/test/ELF/linkerscript/pt_gnu_eh_frame.s b/test/ELF/linkerscript/pt_gnu_eh_frame.s index 81b4c6307d4c..7f9ebaa8d8d1 100644 --- a/test/ELF/linkerscript/pt_gnu_eh_frame.s +++ b/test/ELF/linkerscript/pt_gnu_eh_frame.s @@ -1,7 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: echo "SECTIONS { /DISCARD/ : { *(.eh_frame*) *(.eh_frame_hdr*) } }" > %t.script -# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t +# RUN: ld.lld -o /dev/null --eh-frame-hdr --script %t.script %t .global _start _start: diff --git a/test/ELF/linkerscript/region-alias.s b/test/ELF/linkerscript/region-alias.s index 8a88f6f5ad9f..af4a0f377ddd 100644 --- a/test/ELF/linkerscript/region-alias.s +++ b/test/ELF/linkerscript/region-alias.s @@ -15,7 +15,7 @@ # RUN: echo "REGION_ALIAS (\"ALIAS_DATA\", RAM);" >> %t.script.inc # RUN: ld.lld %t --script %t.script -o %t2 # RUN: llvm-objdump -section-headers %t2 | FileCheck %s -# CHECK: .text 00000001 0000000000001000 TEXT DATA +# CHECK: .text 00000001 0000000000001000 TEXT # CHECK: .data 00000008 0000000000002000 DATA ## All to ROM. @@ -23,7 +23,7 @@ # RUN: echo "REGION_ALIAS (\"ALIAS_DATA\", ROM);" >> %t.script.inc # RUN: ld.lld %t --script %t.script -o %t2 # RUN: llvm-objdump -section-headers %t2 | FileCheck %s --check-prefix=RAM -# RAM: .text 00000001 0000000000001000 TEXT DATA +# RAM: .text 00000001 0000000000001000 TEXT # RAM: .data 00000008 0000000000001001 DATA ## Redefinition of region. diff --git a/test/ELF/linkerscript/rosegment.s b/test/ELF/linkerscript/rosegment.test index 3201b8bda9fb..41479e609d24 100644 --- a/test/ELF/linkerscript/rosegment.s +++ b/test/ELF/linkerscript/rosegment.test @@ -1,12 +1,14 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t # Test that with linker scripts we don't create a RO PT_LOAD. -# RUN: echo "SECTIONS {}" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -shared +# RUN: ld.lld -o %t1 --script %s %t -shared # RUN: llvm-readobj -l %t1 | FileCheck %s +SECTIONS { +} + # CHECK-NOT: Type: PT_LOAD # CHECK: Type: PT_LOAD diff --git a/test/ELF/linkerscript/section-metadata.s b/test/ELF/linkerscript/section-metadata.s index f447240ac3a9..44547b8ab002 100644 --- a/test/ELF/linkerscript/section-metadata.s +++ b/test/ELF/linkerscript/section-metadata.s @@ -10,15 +10,15 @@ # RUN: llvm-objdump -s %t | FileCheck --check-prefix=INV %s -# CHECK: Contents of section .text: -# CHECK-NEXT: 02000000 00000000 01000000 00000000 # CHECK: Contents of section .rodata: # CHECK-NEXT: 02000000 00000000 01000000 00000000 +# CHECK: Contents of section .text: +# CHECK-NEXT: 02000000 00000000 01000000 00000000 -# INV: Contents of section .text: -# INV-NEXT: 01000000 00000000 02000000 00000000 # INV: Contents of section .rodata: # INV-NEXT: 01000000 00000000 02000000 00000000 +# INV: Contents of section .text: +# INV-NEXT: 01000000 00000000 02000000 00000000 .global _start _start: diff --git a/test/ELF/linkerscript/section-metadata2.s b/test/ELF/linkerscript/section-metadata2.s new file mode 100644 index 000000000000..4a538b6190e7 --- /dev/null +++ b/test/ELF/linkerscript/section-metadata2.s @@ -0,0 +1,37 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { .text : { *(.text.*) } }" > %t.script + +# RUN: echo "_bar" > %t.ord +# RUN: echo "_foo" >> %t.ord +# RUN: ld.lld --symbol-ordering-file %t.ord -o %t --script %t.script %t.o +# RUN: llvm-objdump -s %t | FileCheck %s + +# CHECK: Contents of section .rodata: +# CHECK-NEXT: 02000000 00000000 01000000 00000000 +# CHECK: Contents of section .text: +# CHECK-NEXT: 02000000 00000000 01000000 00000000 + +# RUN: echo "_foo" > %t.ord +# RUN: echo "_bar" >> %t.ord +# RUN: ld.lld --symbol-ordering-file %t.ord -o %t --script %t.script %t.o +# RUN: llvm-objdump -s %t | FileCheck %s --check-prefix=INV + +# INV: Contents of section .rodata: +# INV-NEXT: 01000000 00000000 02000000 00000000 +# INV: Contents of section .text: +# INV-NEXT: 01000000 00000000 02000000 00000000 + +.section .text.foo,"a",@progbits +_foo: +.quad 1 + +.section .text.bar,"a",@progbits +_bar: +.quad 2 + +.section .rodata.foo,"ao",@progbits,.text.foo +.quad 1 + +.section .rodata.bar,"ao",@progbits,.text.bar +.quad 2 diff --git a/test/ELF/linkerscript/sections-keep.s b/test/ELF/linkerscript/sections-keep.s index feb0baca9c3d..2c778e3e936b 100644 --- a/test/ELF/linkerscript/sections-keep.s +++ b/test/ELF/linkerscript/sections-keep.s @@ -1,14 +1,14 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/keep.s -o %t2.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/keep.s -o %t1.o ## First check that section "keep" is garbage collected without using KEEP # RUN: echo "SECTIONS { \ # RUN: .text : { *(.text) } \ # RUN: .keep : { *(.keep) } \ # RUN: .temp : { *(.temp) }}" > %t.script -# RUN: ld.lld --gc-sections -o %t1 --script %t.script %t -# RUN: llvm-objdump -section-headers %t1 | \ +# RUN: ld.lld --gc-sections -o %t --script %t.script %t.o +# RUN: llvm-objdump -section-headers %t | \ # RUN: FileCheck -check-prefix=SECGC %s # SECGC: Sections: # SECGC-NEXT: Idx Name Size @@ -21,8 +21,8 @@ # RUN: .text : { *(.text) } \ # RUN: .keep : { KEEP(*(.keep)) } \ # RUN: .temp : { *(.temp) }}" > %t.script -# RUN: ld.lld --gc-sections -o %t1 --script %t.script %t -# RUN: llvm-objdump -section-headers %t1 | \ +# RUN: ld.lld --gc-sections -o %t --script %t.script %t.o +# RUN: llvm-objdump -section-headers %t | \ # RUN: FileCheck -check-prefix=SECNOGC %s # SECNOGC: Sections: # SECNOGC-NEXT: Idx Name Size @@ -38,14 +38,14 @@ # RUN: . = SIZEOF_HEADERS; \ # RUN: .keep : { KEEP(*(.keep)) } \ # RUN: .nokeep : { *(.keep) }}" > %t.script -# RUN: ld.lld --gc-sections -o %t1 --script %t.script %t -# RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=MIXED1 %s +# RUN: ld.lld --gc-sections -o %t --script %t.script %t.o +# RUN: llvm-objdump -section-headers %t | FileCheck -check-prefix=MIXED1 %s # MIXED1: Sections: # MIXED1-NEXT: Idx Name Size # MIXED1-NEXT: 0 00000000 # MIXED1-NEXT: 1 .keep 00000004 -# MIXED1-NEXT: 2 .text 00000007 00000000000000ec TEXT DATA -# MIXED1-NEXT: 3 .temp 00000004 00000000000000f3 DATA +# MIXED1-NEXT: 2 .temp 00000004 00000000000000ec +# MIXED1-NEXT: 3 .text 00000007 00000000000000f0 # MIXED1-NEXT: 4 .comment 00000008 0000000000000000 # MIXED1-NEXT: 5 .symtab 00000060 0000000000000000 # MIXED1-NEXT: 6 .shstrtab 00000036 0000000000000000 @@ -59,14 +59,14 @@ # RUN: . = SIZEOF_HEADERS; \ # RUN: .nokeep : { *(.keep) } \ # RUN: .keep : { KEEP(*(.keep)) }}" > %t.script -# RUN: ld.lld --gc-sections -o %t1 --script %t.script %t -# RUN: llvm-objdump -section-headers %t1 | FileCheck -check-prefix=MIXED2 %s +# RUN: ld.lld --gc-sections -o %t --script %t.script %t.o +# RUN: llvm-objdump -section-headers %t | FileCheck -check-prefix=MIXED2 %s # MIXED2: Sections: # MIXED2-NEXT: Idx Name Size # MIXED2-NEXT: 0 00000000 -# MIXED2-NEXT: 1 .nokeep 00000004 00000000000000e8 DATA -# MIXED2-NEXT: 2 .text 00000007 00000000000000ec TEXT DATA -# MIXED2-NEXT: 3 .temp 00000004 00000000000000f3 DATA +# MIXED2-NEXT: 1 .nokeep 00000004 00000000000000e8 +# MIXED2-NEXT: 2 .temp 00000004 00000000000000ec +# MIXED2-NEXT: 3 .text 00000007 00000000000000f0 # MIXED2-NEXT: 4 .comment 00000008 0000000000000000 # MIXED2-NEXT: 5 .symtab 00000060 0000000000000000 # MIXED2-NEXT: 6 .shstrtab 00000038 0000000000000000 @@ -75,10 +75,10 @@ # Check file pattern for kept sections. # RUN: echo "SECTIONS { \ # RUN: . = SIZEOF_HEADERS; \ -# RUN: .keep : { KEEP(*2.o(.keep)) } \ +# RUN: .keep : { KEEP(*1.o(.keep)) } \ # RUN: }" > %t.script -# RUN: ld.lld --gc-sections -o %t1 --script %t.script %t2.o %t -# RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=FILEMATCH %s +# RUN: ld.lld --gc-sections -o %t --script %t.script %t1.o %t.o +# RUN: llvm-objdump -s %t | FileCheck -check-prefix=FILEMATCH %s # FILEMATCH: Contents of section .keep: # FILEMATCH-NEXT: 00e8 41414141 AAAA diff --git a/test/ELF/linkerscript/sections-max-va-overflow.s b/test/ELF/linkerscript/sections-max-va-overflow.s new file mode 100644 index 000000000000..ce771b4784c4 --- /dev/null +++ b/test/ELF/linkerscript/sections-max-va-overflow.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +# RUN: echo "SECTIONS { . = 0xfffffffffffffff1;" > %t.script +# RUN: echo " .bar : { *(.bar*) } }" >> %t.script +# RUN: not ld.lld -o /dev/null --script %t.script %t.o 2>&1 | FileCheck %s -check-prefix=ERR + +## .bar section has data in [0xfffffffffffffff1, 0xfffffffffffffff1 + 0x10] == +## [0xfffffffffffffff1, 0x1]. Check we can catch this overflow. +# ERR: error: section .bar at 0xFFFFFFFFFFFFFFF1 of size 0x10 exceeds available address space + +.section .bar,"ax",@progbits +.zero 0x10 diff --git a/test/ELF/linkerscript/sections-sort.s b/test/ELF/linkerscript/sections-sort.s index 99bbbead925c..e665c9aaa74a 100644 --- a/test/ELF/linkerscript/sections-sort.s +++ b/test/ELF/linkerscript/sections-sort.s @@ -13,13 +13,13 @@ nop .section foo, "a" .byte 0 -# CHECK: Id +# CHECK: Idx # CHECK-NEXT: 0 # CHECK-NEXT: 1 .text -# CHECK-NEXT: 2 foo -# CHECK-NEXT: 3 .dynsym -# CHECK-NEXT: 4 .hash -# CHECK-NEXT: 5 .dynstr +# CHECK-NEXT: 2 .dynsym +# CHECK-NEXT: 3 .hash +# CHECK-NEXT: 4 .dynstr +# CHECK-NEXT: 5 foo # CHECK-NEXT: 6 .dynamic # CHECK-NEXT: 7 .comment # CHECK-NEXT: 8 .symtab diff --git a/test/ELF/linkerscript/sections-va-overflow.test b/test/ELF/linkerscript/sections-va-overflow.test new file mode 100644 index 000000000000..7ede6ecc3de8 --- /dev/null +++ b/test/ELF/linkerscript/sections-va-overflow.test @@ -0,0 +1,22 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/sections-va-overflow.s -o %t.o +# RUN: not ld.lld -o /dev/null --script %s %t.o 2>&1 | FileCheck %s -check-prefix=ERR + +PHDRS { + ph_headers PT_PHDR PHDRS; + ph_text PT_LOAD FILEHDR PHDRS FLAGS (0x1 | 0x4); +} + +SECTIONS { + . = 0xffffffff20000000; + .text : { *(.text*) } : ph_text + .test 0x1000 : { BYTE(0) } + .bss : { *(.bss*) } +} + +## Section .test has VA 0x1000 and placed in the same segment as section .text +## with VA 0xffffffff20000000. That might be technically correct, but most probably +## is a result of a broken script file and causes file offset calculation overflow. +## It seems we do not have to support it, so we don't and we report an error in this case. +# ERR: error: unable to place section .text at file offset [0xFFFFFFFF20000000, 0xFFFFFFFE40000000]; check your linker script for overflows +# ERR-NOT: unable to place section .bss diff --git a/test/ELF/linkerscript/sections.s b/test/ELF/linkerscript/sections.s index dd4b12f42b89..b1e8fb5e9a12 100644 --- a/test/ELF/linkerscript/sections.s +++ b/test/ELF/linkerscript/sections.s @@ -16,7 +16,7 @@ # RUN: FileCheck -check-prefix=SEC-DEFAULT %s # Idx Name Size -# SEC-DEFAULT: 1 .text 0000000e {{[0-9a-f]*}} TEXT DATA +# SEC-DEFAULT: 1 .text 0000000e {{[0-9a-f]*}} TEXT # SEC-DEFAULT: 2 .data 00000020 {{[0-9a-f]*}} DATA # SEC-DEFAULT: 3 other 00000003 {{[0-9a-f]*}} DATA # SEC-DEFAULT: 4 .bss 00000002 {{[0-9a-f]*}} BSS @@ -47,7 +47,7 @@ # SEC-ORDER: 5 .strtab 00000008 {{[0-9a-f]*}} # SEC-ORDER: 6 .comment 00000008 {{[0-9a-f]*}} # SEC-ORDER: 7 .data 00000020 {{[0-9a-f]*}} DATA -# SEC-ORDER: 8 .text 0000000e {{[0-9a-f]*}} TEXT DATA +# SEC-ORDER: 8 .text 0000000e {{[0-9a-f]*}} TEXT # .text and .data have swapped names but proper sizes and types. # RUN: echo "SECTIONS { \ @@ -58,7 +58,7 @@ # RUN: FileCheck -check-prefix=SEC-SWAP-NAMES %s # Idx Name Size -# SEC-SWAP-NAMES: 1 .data 0000000e {{[0-9a-f]*}} TEXT DATA +# SEC-SWAP-NAMES: 1 .data 0000000e {{[0-9a-f]*}} TEXT # SEC-SWAP-NAMES: 2 .text 00000020 {{[0-9a-f]*}} DATA # SEC-SWAP-NAMES: 3 other 00000003 {{[0-9a-f]*}} DATA # SEC-SWAP-NAMES: 4 .bss 00000002 {{[0-9a-f]*}} BSS @@ -80,7 +80,7 @@ # RUN: FileCheck -check-prefix=SEC-MULTI %s # Idx Name Size -# SEC-MULTI: 1 .text 0000000e {{[0-9a-f]*}} TEXT DATA +# SEC-MULTI: 1 .text 0000000e {{[0-9a-f]*}} TEXT # SEC-MULTI-NEXT: .data 00000020 {{[0-9a-f]*}} DATA # SEC-MULTI-NEXT: .data 00000003 {{[0-9a-f]*}} DATA # SEC-MULTI-NEXT: .bss 00000002 {{[0-9a-f]*}} BSS diff --git a/test/ELF/linkerscript/segment-none.s b/test/ELF/linkerscript/segment-none.s index d54e835a0c22..06566525caf7 100644 --- a/test/ELF/linkerscript/segment-none.s +++ b/test/ELF/linkerscript/segment-none.s @@ -9,7 +9,7 @@ # RUN: .foo : {*(.foo)} :NONE \ # RUN: }" > %t.script # RUN: ld.lld -o %t --script %t.script %t.o -# RUN: llvm-readobj -elf-output-style=GNU -s -l %t | FileCheck %s +# RUN: llvm-readelf -s -l %t | FileCheck %s ## Test that section .foo is placed in segment NONE when assigned to segment ## NONE in the linker script and segment NONE is defined. @@ -19,7 +19,7 @@ # RUN: .foo : {*(.foo)} :NONE \ # RUN: }" > %t.script # RUN: ld.lld -o %t --script %t.script %t.o -# RUN: llvm-readobj -elf-output-style=GNU -s -l %t | FileCheck --check-prefix=DEFINED %s +# RUN: llvm-readelf -s -l %t | FileCheck --check-prefix=DEFINED %s # CHECK: Section to Segment mapping: # CHECK-NEXT: Segment Sections... diff --git a/test/ELF/linkerscript/segment-start.s b/test/ELF/linkerscript/segment-start.s index 69897d604b3b..cb47cb6cd471 100644 --- a/test/ELF/linkerscript/segment-start.s +++ b/test/ELF/linkerscript/segment-start.s @@ -22,6 +22,6 @@ .quad foobar4 // RUN: echo "SECTIONS { . = SEGMENT_START(\"foobar\", foo); }" > %t.script -// RUN: not ld.lld %t.o %t.script -shared -o %t2.so 2>&1 \ +// RUN: not ld.lld %t.o %t.script -shared -o /dev/null 2>&1 \ // RUN: | FileCheck --check-prefix=ERR %s // ERR: {{.*}}.script:1: symbol not found: foo diff --git a/test/ELF/linkerscript/sort-constructors.s b/test/ELF/linkerscript/sort-constructors.s deleted file mode 100644 index a0c23af6de79..000000000000 --- a/test/ELF/linkerscript/sort-constructors.s +++ /dev/null @@ -1,5 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o -# RUN: echo "SECTIONS { .aaa : { SORT(CONSTRUCTORS) } }" > %t1.script -# RUN: ld.lld -shared -o %t1 --script %t1.script %t1.o -# RUN: llvm-readobj %t1 > /dev/null diff --git a/test/ELF/linkerscript/sort-constructors.test b/test/ELF/linkerscript/sort-constructors.test new file mode 100644 index 000000000000..698208afd54e --- /dev/null +++ b/test/ELF/linkerscript/sort-constructors.test @@ -0,0 +1,8 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t1.o +# RUN: ld.lld -shared -o %t1 --script %s %t1.o +# RUN: llvm-readobj %t1 > /dev/null + +SECTIONS { + .aaa : { SORT(CONSTRUCTORS) } +} diff --git a/test/ELF/linkerscript/sort-non-script.s b/test/ELF/linkerscript/sort-non-script.s index 4611b18d55ef..2477c835e134 100644 --- a/test/ELF/linkerscript/sort-non-script.s +++ b/test/ELF/linkerscript/sort-non-script.s @@ -1,14 +1,14 @@ # 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 -o %t.o # RUN: echo "SECTIONS { foo : {*(foo)} }" > %t.script -# RUN: ld.lld --hash-style=sysv -o %t1 --script %t.script %t -shared -# RUN: llvm-readobj -elf-output-style=GNU -s %t1 | FileCheck %s +# RUN: ld.lld --hash-style=sysv -o %t --script %t.script %t.o -shared +# RUN: llvm-readelf -s %t | FileCheck %s -# CHECK: .text {{.*}} AX -# CHECK-NEXT: .dynsym {{.*}} A +# CHECK: .dynsym {{.*}} A # CHECK-NEXT: .hash {{.*}} A # CHECK-NEXT: .dynstr {{.*}} A +# CHECK-NEXT: .text {{.*}} AX # CHECK-NEXT: foo {{.*}} WA # CHECK-NEXT: .dynamic {{.*}} WA diff --git a/test/ELF/linkerscript/start-end.s b/test/ELF/linkerscript/start-end.s deleted file mode 100644 index b68606abc181..000000000000 --- a/test/ELF/linkerscript/start-end.s +++ /dev/null @@ -1,16 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "SECTIONS { \ -# RUN: .init_array : { \ -# RUN: __init_array_start = .; \ -# RUN: *(.init_array) \ -# RUN: __init_array_end = .; } }" > %t.script -# RUN: ld.lld %t.o -script %t.script -o %t 2>&1 - -.globl _start -.text -_start: - nop - -.section .init_array, "aw" - .quad 0 diff --git a/test/ELF/linkerscript/start-end.test b/test/ELF/linkerscript/start-end.test new file mode 100644 index 000000000000..ab7504dac2d4 --- /dev/null +++ b/test/ELF/linkerscript/start-end.test @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: echo '.section .init_array, "aw"; .quad 0' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o +# RUN: ld.lld %t.o -script %s -o %t 2>&1 + +SECTIONS { + .init_array : { + __init_array_start = .; + *(.init_array) + __init_array_end = .; + } +} diff --git a/test/ELF/linkerscript/subalign.s b/test/ELF/linkerscript/subalign.s index 1396798c82f6..99cb3f19a999 100644 --- a/test/ELF/linkerscript/subalign.s +++ b/test/ELF/linkerscript/subalign.s @@ -36,7 +36,7 @@ ## Test we fail gracefuly when alignment value is not a power of 2. # RUN: echo "SECTIONS { .aaa : SUBALIGN(3) { *(.aaa*) } }" > %t5.script -# RUN: not ld.lld %t1.o --script %t5.script -o %t5 2>&1 | FileCheck -check-prefix=ERR %s +# RUN: not ld.lld %t1.o --script %t5.script -o /dev/null 2>&1 | FileCheck -check-prefix=ERR %s # ERR: {{.*}}.script:1: alignment must be power of 2 .global _start diff --git a/test/ELF/linkerscript/symbol-assignexpr.s b/test/ELF/linkerscript/symbol-assignexpr.s index 9ab03a173f1c..3be7d05931fe 100644 --- a/test/ELF/linkerscript/symbol-assignexpr.s +++ b/test/ELF/linkerscript/symbol-assignexpr.s @@ -47,7 +47,7 @@ # CHECK-NEXT: 0000000000000001 *ABS* 00000000 symbol15 # RUN: echo "SECTIONS { symbol2 = symbol; }" > %t2.script -# RUN: not ld.lld -o %t2 --script %t2.script %t 2>&1 \ +# RUN: not ld.lld -o /dev/null --script %t2.script %t 2>&1 \ # RUN: | FileCheck -check-prefix=ERR %s # ERR: {{.*}}.script:1: symbol not found: symbol diff --git a/test/ELF/linkerscript/symbol-memoryexpr.s b/test/ELF/linkerscript/symbol-memoryexpr.s index 9c75274e1644..cdd821dc585a 100644 --- a/test/ELF/linkerscript/symbol-memoryexpr.s +++ b/test/ELF/linkerscript/symbol-memoryexpr.s @@ -23,7 +23,7 @@ # RUN: no_exist_origin = ORIGIN(ram); \ # RUN: no_exist_length = LENGTH(ram); \ # RUN: }" > %t2.script -# RUN: not ld.lld -o %t2 --script %t2.script %t 2>&1 \ +# RUN: not ld.lld -o /dev/null --script %t2.script %t 2>&1 \ # RUN: | FileCheck -check-prefix=ERR %s # ERR: {{.*}}.script:1: memory region not defined: ram diff --git a/test/ELF/linkerscript/symbol-only-flags.s b/test/ELF/linkerscript/symbol-only-flags.test index 300d8d88da97..cea2539cd6ba 100644 --- a/test/ELF/linkerscript/symbol-only-flags.s +++ b/test/ELF/linkerscript/symbol-only-flags.test @@ -1,11 +1,15 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "SECTIONS { . = SIZEOF_HEADERS; \ -# RUN: .tbss : { *(.tbss) } \ -# RUN: .foo : { bar = .; } }" > %t.script -# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: echo '.section .tbss,"awT",@nobits; .quad 0' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o +# RUN: ld.lld -o %t --script %s %t.o # RUN: llvm-readobj -s %t | FileCheck %s +SECTIONS { + . = SIZEOF_HEADERS; + .tbss : { *(.tbss) } + .foo : { bar = .; } +} + ## Check .foo does not get SHF_TLS flag. # CHECK: Section { # CHECK: Index: @@ -15,6 +19,3 @@ # CHECK-NEXT: SHF_ALLOC # CHECK-NEXT: SHF_WRITE # CHECK-NEXT: ] - -.section .tbss,"awT",@nobits -.quad 0 diff --git a/test/ELF/linkerscript/symbol-only.s b/test/ELF/linkerscript/symbol-only.s deleted file mode 100644 index 76d54f01cdc7..000000000000 --- a/test/ELF/linkerscript/symbol-only.s +++ /dev/null @@ -1,21 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -# RUN: echo "SECTIONS { \ -# RUN: . = SIZEOF_HEADERS; \ -# RUN: abc : { foo = .; } \ -# RUN: . = ALIGN(0x1000); \ -# RUN: bar : { *(bar) } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --script %t.script %t -shared -# RUN: llvm-objdump -section-headers -t %t1 | FileCheck %s -# CHECK: Sections: -# CHECK-NEXT: Idx Name Size Address -# CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK: abc 00000000 [[ADDR:[0-9a-f]*]] BSS -# CHECK-NEXT: bar 00000000 0000000000001000 DATA - -# CHECK: SYMBOL TABLE: -# CHECK: [[ADDR]] abc 00000000 foo - -.section bar, "a" diff --git a/test/ELF/linkerscript/symbol-only.test b/test/ELF/linkerscript/symbol-only.test new file mode 100644 index 000000000000..f2fefdc049b9 --- /dev/null +++ b/test/ELF/linkerscript/symbol-only.test @@ -0,0 +1,21 @@ +# REQUIRES: x86 +# RUN: echo '.section bar, "a"' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t +# RUN: ld.lld -o %t1 --script %s %t -shared +# RUN: llvm-objdump -section-headers -t %t1 | FileCheck %s + +SECTIONS { + . = SIZEOF_HEADERS; + abc : { foo = .; } + . = ALIGN(0x1000); + bar : { *(bar) } +} + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK: abc 00000000 [[ADDR:[0-9a-f]*]] +# CHECK: bar 00000000 0000000000001000 + +# CHECK: SYMBOL TABLE: +# CHECK: [[ADDR]] abc 00000000 foo diff --git a/test/ELF/linkerscript/symbol-ordering-file.s b/test/ELF/linkerscript/symbol-ordering-file.s index be686c420887..dd5e0a152ae9 100644 --- a/test/ELF/linkerscript/symbol-ordering-file.s +++ b/test/ELF/linkerscript/symbol-ordering-file.s @@ -14,6 +14,16 @@ # AFTER: Contents of section .foo: # AFTER-NEXT: 2211 +# RUN: echo "SECTIONS { .text : { *(.text) } }" > %t2.script +# RUN: ld.lld --symbol-ordering-file %t.ord %t.o --script %t2.script -o %t3.out +# RUN: llvm-objdump -s %t3.out| FileCheck %s --check-prefix=AFTER + +# RUN: echo "SECTIONS { .foo : { BYTE(0x33); *(.foo); BYTE(0x44) } }" > %t3.script +# RUN: ld.lld --symbol-ordering-file %t.ord %t.o --script %t3.script -o %t4.out +# RUN: llvm-objdump -s %t4.out| FileCheck %s --check-prefix=COMMANDS +# COMMANDS: Contents of section .foo: +# COMMANDS-NEXT: 33221144 + .section .foo,"ax",@progbits,unique,1 _foo1: .byte 0x11 diff --git a/test/ELF/linkerscript/symbol-ordering-file2.s b/test/ELF/linkerscript/symbol-ordering-file2.s new file mode 100644 index 000000000000..31746ae0a333 --- /dev/null +++ b/test/ELF/linkerscript/symbol-ordering-file2.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o + +## Check we do not crash when trying to order linker script symbol. + +# RUN: echo "bar" > %t.ord +# RUN: echo "SECTIONS { bar = 1; }" > %t.script +# RUN: ld.lld --symbol-ordering-file %t.ord %t.o --script %t.script \ +# RUN: -o %t.out 2>&1 | FileCheck %s +# CHECK: warning: <internal>: unable to order absolute symbol: bar + +## Check we do not crash when trying to order --defsym symbol. + +# RUN: echo "bar" > %t.ord +# RUN: ld.lld --symbol-ordering-file %t.ord %t.o -defsym=bar=1 \ +# RUN: -o %t.out 2>&1 | FileCheck %s diff --git a/test/ELF/linkerscript/symbols-non-alloc.s b/test/ELF/linkerscript/symbols-non-alloc.s deleted file mode 100644 index e51a39ee5d29..000000000000 --- a/test/ELF/linkerscript/symbols-non-alloc.s +++ /dev/null @@ -1,19 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -# RUN: echo "SECTIONS { . = SIZEOF_HEADERS; \ -# RUN: .text : { *(.text) } \ -# RUN: .nonalloc : { *(.nonalloc) } \ -# RUN: Sym = .; \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t2 --script %t.script %t -# RUN: llvm-objdump -section-headers -t %t2 | FileCheck %s - -# CHECK: Sections: -# CHECK: .nonalloc 00000008 0000000000000000 - -# CHECK: SYMBOL TABLE: -# CHECK: 0000000000000008 .nonalloc 00000000 Sym - -.section .nonalloc,"" - .quad 0 diff --git a/test/ELF/linkerscript/symbols-non-alloc.test b/test/ELF/linkerscript/symbols-non-alloc.test new file mode 100644 index 000000000000..6d7580affc26 --- /dev/null +++ b/test/ELF/linkerscript/symbols-non-alloc.test @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# RUN: echo '.section .nonalloc,""; .quad 0' \ +# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t +# RUN: ld.lld -o %t2 --script %s %t +# RUN: llvm-objdump -section-headers -t %t2 | FileCheck %s + +# CHECK: Sections: +# CHECK: .nonalloc 00000008 0000000000000000 + +# CHECK: SYMBOL TABLE: +# CHECK: 0000000000000008 .nonalloc 00000000 Sym + +SECTIONS { + . = SIZEOF_HEADERS; + .text : { *(.text) } + .nonalloc : { *(.nonalloc) } + Sym = .; +} diff --git a/test/ELF/linkerscript/symbols-synthetic.s b/test/ELF/linkerscript/symbols-synthetic.s deleted file mode 100644 index 95cdae9a929e..000000000000 --- a/test/ELF/linkerscript/symbols-synthetic.s +++ /dev/null @@ -1,98 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# Simple symbol assignment within input section list. The '.' symbol -# is not location counter but offset from the beginning of output -# section .foo -# RUN: echo "SECTIONS { \ -# RUN: . = SIZEOF_HEADERS; \ -# RUN: .foo : { \ -# RUN: begin_foo = .; \ -# RUN: PROVIDE(_begin_sec = .); \ -# RUN: *(.foo) \ -# RUN: end_foo = .; \ -# RUN: PROVIDE_HIDDEN(_end_sec = .); \ -# RUN: PROVIDE(_end_sec_abs = ABSOLUTE(.)); \ -# RUN: size_foo_1 = SIZEOF(.foo); \ -# RUN: size_foo_1_abs = ABSOLUTE(SIZEOF(.foo)); \ -# RUN: . = ALIGN(0x1000); \ -# RUN: begin_bar = .; \ -# RUN: *(.bar) \ -# RUN: end_bar = .; \ -# RUN: size_foo_2 = SIZEOF(.foo); } \ -# RUN: size_foo_3 = SIZEOF(.foo); \ -# RUN: .eh_frame_hdr : { \ -# RUN: __eh_frame_hdr_start = .; \ -# RUN: __eh_frame_hdr_start2 = ABSOLUTE(ALIGN(0x10)); \ -# RUN: *(.eh_frame_hdr) \ -# RUN: __eh_frame_hdr_end = .; \ -# RUN: __eh_frame_hdr_end2 = ABSOLUTE(ALIGN(0x10)); } \ -# RUN: .eh_frame : { } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t -# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=SIMPLE %s - -# Check that the following script is processed without errors -# RUN: echo "SECTIONS { \ -# RUN: .eh_frame_hdr : { \ -# RUN: PROVIDE_HIDDEN(_begin_sec = .); \ -# RUN: *(.eh_frame_hdr) \ -# RUN: *(.eh_frame_hdr) \ -# RUN: PROVIDE_HIDDEN(_end_sec_abs = ABSOLUTE(.)); \ -# RUN: PROVIDE_HIDDEN(_end_sec = .); } \ -# RUN: }" > %t.script -# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t - -# Check that we can specify synthetic symbols without defining SECTIONS. -# RUN: echo "PROVIDE_HIDDEN(_begin_sec = _start); \ -# RUN: PROVIDE_HIDDEN(_end_sec = ADDR(.text) + SIZEOF(.text));" > %t.script -# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t -# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=NO-SEC %s - -# Check that we can do the same as above inside SECTIONS block. -# RUN: echo "SECTIONS { \ -# RUN: . = 0x201000; \ -# RUN: .text : { *(.text) } \ -# RUN: PROVIDE_HIDDEN(_begin_sec = ADDR(.text)); \ -# RUN: PROVIDE_HIDDEN(_end_sec = ADDR(.text) + SIZEOF(.text)); }" > %t.script -# RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t -# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=IN-SEC %s - -# SIMPLE: 0000000000000128 .foo 00000000 .hidden _end_sec -# SIMPLE-NEXT: 0000000000000120 .foo 00000000 _begin_sec -# SIMPLE-NEXT: 0000000000000128 *ABS* 00000000 _end_sec_abs -# SIMPLE-NEXT: 0000000000001048 .text 00000000 _start -# SIMPLE-NEXT: 0000000000000120 .foo 00000000 begin_foo -# SIMPLE-NEXT: 0000000000000128 .foo 00000000 end_foo -# SIMPLE-NEXT: 0000000000000008 *ABS* 00000000 size_foo_1 -# SIMPLE-NEXT: 0000000000000008 *ABS* 00000000 size_foo_1_abs -# SIMPLE-NEXT: 0000000000001000 .foo 00000000 begin_bar -# SIMPLE-NEXT: 0000000000001004 .foo 00000000 end_bar -# SIMPLE-NEXT: 0000000000000ee4 *ABS* 00000000 size_foo_2 -# SIMPLE-NEXT: 0000000000000ee4 *ABS* 00000000 size_foo_3 -# SIMPLE-NEXT: 0000000000001004 .eh_frame_hdr 00000000 __eh_frame_hdr_start -# SIMPLE-NEXT: 0000000000001010 *ABS* 00000000 __eh_frame_hdr_start2 -# SIMPLE-NEXT: 0000000000001018 .eh_frame_hdr 00000000 __eh_frame_hdr_end -# SIMPLE-NEXT: 0000000000001020 *ABS* 00000000 __eh_frame_hdr_end2 - -# NO-SEC: 0000000000201000 .text 00000000 .hidden _begin_sec -# NO-SEC-NEXT: 0000000000201001 .text 00000000 .hidden _end_sec - -# IN-SEC: 0000000000201000 .text 00000000 .hidden _begin_sec -# IN-SEC-NEXT: 0000000000201001 .text 00000000 .hidden _end_sec - -.global _start -_start: - nop - -.section .foo,"a" - .quad 0 - -.section .bar,"a" - .long 0 - -.section .dah,"ax",@progbits - .cfi_startproc - nop - .cfi_endproc - -.global _begin_sec, _end_sec, _end_sec_abs diff --git a/test/ELF/linkerscript/synthetic-relsec-layout.s b/test/ELF/linkerscript/synthetic-relsec-layout.s new file mode 100644 index 000000000000..efaa946cbaa9 --- /dev/null +++ b/test/ELF/linkerscript/synthetic-relsec-layout.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { .foo : { *(.rela.dyn) } }" > %t.script +# RUN: ld.lld -T %t.script %t.o -o %t.so -shared +# RUN: llvm-readobj -r %t.so | FileCheck %s + +# Check we are able to do custom layout for synthetic sections. +# (here we check we can place synthetic .rela.dyn into .foo). + +# CHECK: Relocations [ +# CHECK: Section ({{.*}}) .foo { +# CHECK: R_X86_64_64 .foo 0x0 +# CHECK: } + +.data +.quad .foo diff --git a/test/ELF/linkerscript/synthetic-symbols1.test b/test/ELF/linkerscript/synthetic-symbols1.test new file mode 100644 index 000000000000..908a05f49588 --- /dev/null +++ b/test/ELF/linkerscript/synthetic-symbols1.test @@ -0,0 +1,56 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/synthetic-symbols.s -o %t +# RUN: ld.lld -o %t.exe --eh-frame-hdr --script %s %t +# RUN: llvm-objdump -t %t.exe | FileCheck %s + +# Simple symbol assignment within input section list. The '.' symbol +# is not location counter but offset from the beginning of output +# section .foo + +SECTIONS { + . = SIZEOF_HEADERS; + .foo : { + begin_foo = .; + PROVIDE(_begin_sec = .); + *(.foo) + end_foo = .; + PROVIDE_HIDDEN(_end_sec = .); + PROVIDE(_end_sec_abs = ABSOLUTE(.)); + size_foo_1 = SIZEOF(.foo); + size_foo_1_abs = ABSOLUTE(SIZEOF(.foo)); + . = ALIGN(0x1000); + begin_bar = .; + *(.bar) + end_bar = .; + size_foo_2 = SIZEOF(.foo); + } + + size_foo_3 = SIZEOF(.foo); + + .eh_frame_hdr : { + __eh_frame_hdr_start = .; + __eh_frame_hdr_start2 = ABSOLUTE(ALIGN(0x10)); + *(.eh_frame_hdr) + __eh_frame_hdr_end = .; + __eh_frame_hdr_end2 = ABSOLUTE(ALIGN(0x10)); + } + + .eh_frame : {} +} + +# CHECK: 0000000000000128 .foo 00000000 .hidden _end_sec +# CHECK-NEXT: 0000000000000120 .foo 00000000 _begin_sec +# CHECK-NEXT: 0000000000000128 *ABS* 00000000 _end_sec_abs +# CHECK-NEXT: 000000000000104c .text 00000000 _start +# CHECK-NEXT: 0000000000000120 .foo 00000000 begin_foo +# CHECK-NEXT: 0000000000000128 .foo 00000000 end_foo +# CHECK-NEXT: 0000000000000008 *ABS* 00000000 size_foo_1 +# CHECK-NEXT: 0000000000000008 *ABS* 00000000 size_foo_1_abs +# CHECK-NEXT: 0000000000001000 .foo 00000000 begin_bar +# CHECK-NEXT: 0000000000001004 .foo 00000000 end_bar +# CHECK-NEXT: 0000000000000ee4 *ABS* 00000000 size_foo_2 +# CHECK-NEXT: 0000000000000ee4 *ABS* 00000000 size_foo_3 +# CHECK-NEXT: 0000000000001004 .eh_frame_hdr 00000000 __eh_frame_hdr_start +# CHECK-NEXT: 0000000000001010 *ABS* 00000000 __eh_frame_hdr_start2 +# CHECK-NEXT: 0000000000001018 .eh_frame_hdr 00000000 __eh_frame_hdr_end +# CHECK-NEXT: 0000000000001020 *ABS* 00000000 __eh_frame_hdr_end2 diff --git a/test/ELF/linkerscript/synthetic-symbols2.test b/test/ELF/linkerscript/synthetic-symbols2.test new file mode 100644 index 000000000000..5304c1e28f01 --- /dev/null +++ b/test/ELF/linkerscript/synthetic-symbols2.test @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/synthetic-symbols.s -o %t +# RUN: ld.lld -o %t.exe --eh-frame-hdr --script %s %t + +SECTIONS { + .eh_frame_hdr : { + PROVIDE_HIDDEN(_begin_sec = .); + *(.eh_frame_hdr) + *(.eh_frame_hdr) + PROVIDE_HIDDEN(_end_sec_abs = ABSOLUTE(.)); + PROVIDE_HIDDEN(_end_sec = .); + } +} diff --git a/test/ELF/linkerscript/synthetic-symbols3.test b/test/ELF/linkerscript/synthetic-symbols3.test new file mode 100644 index 000000000000..a24ecccedf0b --- /dev/null +++ b/test/ELF/linkerscript/synthetic-symbols3.test @@ -0,0 +1,11 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/synthetic-symbols.s -o %t +# RUN: ld.lld -o %t.exe --eh-frame-hdr --script %s %t +# RUN: llvm-objdump -t %t.exe | FileCheck %s + +# Check that we can specify synthetic symbols without defining SECTIONS. +PROVIDE_HIDDEN(_begin_sec = _start); +PROVIDE_HIDDEN(_end_sec = ADDR(.text) + SIZEOF(.text)); + +# CHECK: 0000000000201000 .text 00000000 .hidden _begin_sec +# CHECK-NEXT: 0000000000201001 .text 00000000 .hidden _end_sec diff --git a/test/ELF/linkerscript/synthetic-symbols4.test b/test/ELF/linkerscript/synthetic-symbols4.test new file mode 100644 index 000000000000..fde06e3f3a44 --- /dev/null +++ b/test/ELF/linkerscript/synthetic-symbols4.test @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/synthetic-symbols.s -o %t.o +# RUN: ld.lld -o %t --eh-frame-hdr --script %s %t.o +# RUN: llvm-objdump -t %t | FileCheck %s + +SECTIONS { + . = 0x201000; + .text : { *(.text) } + PROVIDE_HIDDEN(_begin_sec = ADDR(.text)); + PROVIDE_HIDDEN(_end_sec = ADDR(.text) + SIZEOF(.text)); +} + +# CHECK: 0000000000201054 .text 00000000 .hidden _begin_sec +# CHECK-NEXT: 0000000000201055 .text 00000000 .hidden _end_sec diff --git a/test/ELF/linkerscript/unused-synthetic.s b/test/ELF/linkerscript/unused-synthetic.s index b7cedbc8e09c..6ddbf505ccbb 100644 --- a/test/ELF/linkerscript/unused-synthetic.s +++ b/test/ELF/linkerscript/unused-synthetic.s @@ -1,17 +1,17 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o # RUN: echo "SECTIONS { \ -# RUN: .got : { *(.got) } \ +# RUN: .got : { *(.got) *(.got) } \ # RUN: .plt : { *(.plt) } \ # RUN: .text : { *(.text) } \ # RUN: }" > %t.script # RUN: ld.lld -shared -o %t.so --script %t.script %t.o -# RUN: llvm-objdump -section-headers %t.so | FileCheck %s +# RUN: llvm-readelf -s %t.so | FileCheck %s # CHECK-NOT: .got # CHECK-NOT: .plt +# CHECK: .dynsym # CHECK: .text -# CHECK-NEXT: .dynsym # Test that the size of a removed unused synthetic input section is not added # to the output section size. Adding a symbol assignment prevents removal of diff --git a/test/ELF/linkerscript/unused-synthetic2.test b/test/ELF/linkerscript/unused-synthetic2.test new file mode 100644 index 000000000000..755d1af00be0 --- /dev/null +++ b/test/ELF/linkerscript/unused-synthetic2.test @@ -0,0 +1,12 @@ +# REQUIRES: arm +# RUN: llvm-mc -filetype=obj -triple=armv7-unknown-linux-gnueabi /dev/null -o %t.o + +## We incorrectly removed unused synthetic sections and crashed before. +## Check we do not crash and do not produce .trap output section. +# RUN: ld.lld -shared -o %t.so --script %s %t.o +# RUN: llvm-objdump -section-headers %t.so | FileCheck %s +# CHECK-NOT: .trap + +SECTIONS { + .trap : { *(.ARM.exidx) *(.dummy) } +} diff --git a/test/ELF/linkerscript/va.s b/test/ELF/linkerscript/va.s index 854ebcef0146..c305f0689e11 100644 --- a/test/ELF/linkerscript/va.s +++ b/test/ELF/linkerscript/va.s @@ -5,11 +5,11 @@ # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -section-headers %t1 | FileCheck %s # CHECK: Sections: -# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: Idx Name Size Address # CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .text 00000001 0000000000000000 TEXT DATA -# CHECK-NEXT: 2 .foo 00000004 0000000000000001 DATA -# CHECK-NEXT: 3 .boo 00000004 0000000000000005 DATA +# CHECK-NEXT: 1 .foo 00000004 0000000000000000 +# CHECK-NEXT: 2 .boo 00000004 0000000000000004 +# CHECK-NEXT: 3 .text 00000001 0000000000000008 .global _start _start: diff --git a/test/ELF/linkerscript/version-script.s b/test/ELF/linkerscript/version-script.s new file mode 100644 index 000000000000..df666e1b39ea --- /dev/null +++ b/test/ELF/linkerscript/version-script.s @@ -0,0 +1,57 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +# RUN: echo "bar = foo; VERSION { V { global: foo; bar; local: *; }; }" > %t.script +# RUN: ld.lld -T %t.script -shared --no-undefined-version %t.o -o %t.so +# RUN: llvm-readobj -V %t.so | FileCheck %s + +# RUN: echo "SECTIONS { .text : { bar = foo; *(.text) } }" > %t.script +# RUN: echo "VERSION { V { global: foo; bar; local: *; }; }" >> %t.script +# RUN: ld.lld -T %t.script -shared --no-undefined-version %t.o -o %t.so +# RUN: llvm-readobj -V %t.so | FileCheck %s + +## Check that we are able to version symbols defined in script. +# CHECK: Symbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Version: 0 +# CHECK-NEXT: Name: @ +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Version: 0 +# CHECK-NEXT: Name: und@ +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Version: 2 +# CHECK-NEXT: Name: foo@@V +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Version: 2 +# CHECK-NEXT: Name: bar@@V +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# RUN: echo "bar = und; VERSION { V { global: foo; bar; local: *; }; }" > %t.script +# RUN: not ld.lld -T %t.script -shared --no-undefined-version %t.o -o %t.so \ +# RUN: 2>&1 | FileCheck --check-prefix=ERR %s +# ERR: symbol not found: und + +# RUN: echo "und = 0x1; VERSION { V { global: und; local: *; }; }" > %t.script +# RUN: ld.lld -T %t.script -shared --no-undefined-version %t.o -o %t.so +# RUN: llvm-readobj -V %t.so | FileCheck %s --check-prefix=UNDEF +# UNDEF: Symbols [ +# UNDEF-NEXT: Symbol { +# UNDEF-NEXT: Version: 0 +# UNDEF-NEXT: Name: @ +# UNDEF-NEXT: } +# UNDEF-NEXT: Symbol { +# UNDEF-NEXT: Version: 2 +# UNDEF-NEXT: Name: und@@V +# UNDEF-NEXT: } +# UNDEF-NEXT: ] + +.global und + +.text +.globl foo +.type foo,@function +foo: diff --git a/test/ELF/llvm33-rela-outside-group.s b/test/ELF/llvm33-rela-outside-group.s index 8e7e7c4e6a4d..1c87817e0c75 100644 --- a/test/ELF/llvm33-rela-outside-group.s +++ b/test/ELF/llvm33-rela-outside-group.s @@ -1,7 +1,7 @@ // Input file generated with: // llvm33/llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %S/Inputs/llvm33-rela-outside-group.o // -// RUN: ld.lld -shared %S/Inputs/llvm33-rela-outside-group.o %S/Inputs/llvm33-rela-outside-group.o +// RUN: ld.lld -shared %S/Inputs/llvm33-rela-outside-group.o %S/Inputs/llvm33-rela-outside-group.o -o /dev/null .global bar .weak _Z3fooIiEvv diff --git a/test/ELF/local-dynamic.s b/test/ELF/local-dynamic.s index 797a1071311c..c122074fd7d9 100644 --- a/test/ELF/local-dynamic.s +++ b/test/ELF/local-dynamic.s @@ -1,8 +1,8 @@ +// REQUIRES: x86 // Check that local symbols are not inserted into dynamic table. // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld %t -shared -o %t1.so // RUN: llvm-readobj -t -dyn-symbols %t1.so | FileCheck %s -// REQUIRES: x86 // CHECK: Symbols [ // CHECK-NEXT: Symbol { diff --git a/test/ELF/local-got-pie.s b/test/ELF/local-got-pie.s index b1b213af6659..c89fc1cb4ed4 100644 --- a/test/ELF/local-got-pie.s +++ b/test/ELF/local-got-pie.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o // RUN: ld.lld --hash-style=sysv %t.o -o %t -pie // RUN: llvm-readobj -s -r -d %t | FileCheck %s diff --git a/test/ELF/local-got-shared.s b/test/ELF/local-got-shared.s index c858424cfd96..284135db13e0 100644 --- a/test/ELF/local-got-shared.s +++ b/test/ELF/local-got-shared.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o // RUN: ld.lld --hash-style=sysv %t.o -o %t -shared // RUN: llvm-readobj -s -r -d %t | FileCheck %s diff --git a/test/ELF/local-got.s b/test/ELF/local-got.s index 17517f6a70ea..2c1bd58d7682 100644 --- a/test/ELF/local-got.s +++ b/test/ELF/local-got.s @@ -1,3 +1,4 @@ +// 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 %p/Inputs/shared.s -o %t2.o // RUN: ld.lld -shared %t2.o -o %t2.so diff --git a/test/ELF/local-symbols-order.s b/test/ELF/local-symbols-order.s new file mode 100644 index 000000000000..dfd964f2de27 --- /dev/null +++ b/test/ELF/local-symbols-order.s @@ -0,0 +1,37 @@ +# REQUIRES: x86 + +# RUN: echo '.data; .file "file2"; foo2:; .global bar2; .hidden bar2; bar2:' > %t2.s +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t2.s -o %t2.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o + +# RUN: ld.lld -o %t %t1.o %t2.o --emit-relocs +# RUN: llvm-readobj -symbols -sections -elf-output-style=GNU %t | FileCheck %s + +## Check we sort local symbols to match the following order: +## file1, local1, section1, hidden1, file2, local2, section2, hidden2 ... + +# CHECK: Section Headers: +# CHECK: [Nr] Name +# CHECK: [ [[ST:.*]]] .text +# CHECK: [ [[SD:.*]]] .data +# CHECK: [ [[SC:.*]]] .comment + +# CHECK: Num: Value Size Type Bind Vis Ndx Name +# CHECK-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND +# CHECK-NEXT: 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS file1 +# CHECK-NEXT: 2: 0000000000201000 0 NOTYPE LOCAL DEFAULT 1 foo1 +# CHECK-NEXT: 3: 0000000000201000 0 SECTION LOCAL DEFAULT [[ST]] +# CHECK-NEXT: 4: 0000000000201000 0 NOTYPE LOCAL HIDDEN 1 bar1 +# CHECK-NEXT: 5: 0000000000000000 0 FILE LOCAL DEFAULT ABS file2 +# CHECK-NEXT: 6: 0000000000201000 0 NOTYPE LOCAL DEFAULT 2 foo2 +# CHECK-NEXT: 7: 0000000000201000 0 SECTION LOCAL DEFAULT [[SD]] +# CHECK-NEXT: 8: 0000000000201000 0 NOTYPE LOCAL HIDDEN 2 bar2 +# CHECK-NEXT: 9: 0000000000000000 0 SECTION LOCAL DEFAULT [[SC]] + +foo1: + +.global bar1 +.hidden bar1 +bar1: + +.file "file1" diff --git a/test/ELF/local.s b/test/ELF/local.s index 983d7ff7ba63..cb9adc864852 100644 --- a/test/ELF/local.s +++ b/test/ELF/local.s @@ -1,8 +1,8 @@ +// REQUIRES: x86 // Check that symbol table is correctly populated with local symbols. // RUN: llvm-mc -save-temp-labels -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld %t -o %t1 // RUN: llvm-readobj -t -s %t1 | FileCheck %s -// REQUIRES: x86 // Check that Info is equal to the number of local symbols. // CHECK: Section { diff --git a/test/ELF/lto-plugin-ignore.s b/test/ELF/lto-plugin-ignore.s index 2f45a43b2428..65230f1567e7 100644 --- a/test/ELF/lto-plugin-ignore.s +++ b/test/ELF/lto-plugin-ignore.s @@ -3,9 +3,8 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: ld.lld %t -plugin-opt=/foo/bar -plugin-opt=-fresolution=zed \ # RUN: -plugin-opt=-pass-through=-lgcc -plugin-opt=-function-sections \ -# RUN: -plugin-opt=-data-sections -o /dev/null +# RUN: -plugin-opt=-data-sections -plugin-opt=thinlto -o /dev/null -# RUN: not ld.lld %t -plugin-opt=-data-sectionssss \ -# RUN: -plugin-opt=-function-sectionsss 2>&1 | FileCheck %s -# CHECK: unknown option: -data-sectionsss -# CHECK: unknown option: -function-sectionsss +# RUN: not ld.lld %t -plugin-opt=-abc -plugin-opt=-xyz 2>&1 | FileCheck %s +# CHECK: error: --plugin-opt: ld.lld{{.*}}: Unknown command line argument '-abc' +# CHECK: error: --plugin-opt: ld.lld{{.*}}: Unknown command line argument '-xyz' diff --git a/test/ELF/lto/Inputs/absolute.s b/test/ELF/lto/Inputs/absolute.s new file mode 100644 index 000000000000..63fbc9f9234c --- /dev/null +++ b/test/ELF/lto/Inputs/absolute.s @@ -0,0 +1,2 @@ +.globl blah + blah = 0xdeadbeef diff --git a/test/ELF/lto/Inputs/archive-3.ll b/test/ELF/lto/Inputs/archive-3.ll index ad8fb1e33ef2..37442469aa7e 100644 --- a/test/ELF/lto/Inputs/archive-3.ll +++ b/test/ELF/lto/Inputs/archive-3.ll @@ -1,5 +1,6 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" + define void @foo() { ret void } diff --git a/test/ELF/lto/Inputs/asmundef.ll b/test/ELF/lto/Inputs/asmundef.ll new file mode 100644 index 000000000000..0992f79c9af8 --- /dev/null +++ b/test/ELF/lto/Inputs/asmundef.ll @@ -0,0 +1,4 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @patatino() diff --git a/test/ELF/lto/Inputs/common3.ll b/test/ELF/lto/Inputs/common3.ll index a4efc6591570..8f20a1e8ac2d 100644 --- a/test/ELF/lto/Inputs/common3.ll +++ b/test/ELF/lto/Inputs/common3.ll @@ -1,3 +1,4 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" + @a = common hidden global i64 0, align 4 diff --git a/test/ELF/lto/Inputs/i386-empty.ll b/test/ELF/lto/Inputs/i386-empty.ll new file mode 100644 index 000000000000..6029cb6d0900 --- /dev/null +++ b/test/ELF/lto/Inputs/i386-empty.ll @@ -0,0 +1,2 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "i686-linux-gnu" diff --git a/test/ELF/lto/Inputs/lazy-internal.ll b/test/ELF/lto/Inputs/lazy-internal.ll new file mode 100644 index 000000000000..918791c5d20f --- /dev/null +++ b/test/ELF/lto/Inputs/lazy-internal.ll @@ -0,0 +1,6 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define hidden void @bar() { + ret void +} diff --git a/test/ELF/lto/Inputs/sample-profile.prof b/test/ELF/lto/Inputs/sample-profile.prof new file mode 100644 index 000000000000..0ccd747bd376 --- /dev/null +++ b/test/ELF/lto/Inputs/sample-profile.prof @@ -0,0 +1 @@ +f:0:0 diff --git a/test/ELF/lto/Inputs/thinlto_empty.ll b/test/ELF/lto/Inputs/thinlto_empty.ll new file mode 100644 index 000000000000..a3c99cdfe772 --- /dev/null +++ b/test/ELF/lto/Inputs/thinlto_empty.ll @@ -0,0 +1,2 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/Inputs/weakodr-visibility.ll b/test/ELF/lto/Inputs/weakodr-visibility.ll new file mode 100644 index 000000000000..1bd956059d24 --- /dev/null +++ b/test/ELF/lto/Inputs/weakodr-visibility.ll @@ -0,0 +1,6 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define weak_odr protected i32 @foo(i8* %this) { + ret i32 42 +} diff --git a/test/ELF/lto/abs-resol.ll b/test/ELF/lto/abs-resol.ll new file mode 100644 index 000000000000..4b0fb47a9e21 --- /dev/null +++ b/test/ELF/lto/abs-resol.ll @@ -0,0 +1,17 @@ +; REQUIRES: x86 + +; RUN: llvm-as %s -o %t.o +; RUN: llvm-mc -triple=x86_64-pc-linux %p/Inputs/absolute.s -o %t2.o -filetype=obj +; RUN: ld.lld %t.o %t2.o -o %t3.out -pie + +; RUN: echo "blah = 0xdeadfeef;" > %t.script +; RUN: ld.lld %t.o -T%t.script -o %t4.out -pie + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@blah = external global i8, align 1 + +define i8* @_start() { + ret i8* @blah +} diff --git a/test/ELF/lto/archive-2.ll b/test/ELF/lto/archive-2.ll index 6712d60c11e3..28e349ebd317 100644 --- a/test/ELF/lto/archive-2.ll +++ b/test/ELF/lto/archive-2.ll @@ -3,9 +3,9 @@ ; RUN: rm -f %t.a ; RUN: llvm-ar rcs %t.a %t1.o ; RUN: llvm-as %s -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t2.o %t.a -o %t3 +; RUN: ld.lld %t2.o %t.a -o %t3 ; RUN: llvm-readobj -t %t3 | FileCheck %s -; RUN: ld.lld -m elf_x86_64 %t2.o --whole-archive %t.a -o %t3 -shared +; RUN: ld.lld %t2.o --whole-archive %t.a -o %t3 -shared ; RUN: llvm-readobj -t %t3 | FileCheck %s ; CHECK: Name: _start ( diff --git a/test/ELF/lto/archive-3.ll b/test/ELF/lto/archive-3.ll index 0322e412539a..fec1b6155238 100644 --- a/test/ELF/lto/archive-3.ll +++ b/test/ELF/lto/archive-3.ll @@ -2,12 +2,12 @@ ; RUN: llvm-as %S/Inputs/archive-3.ll -o %t1.o ; RUN: llvm-as %s -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t1.o %t2.o -o %t3 -save-temps +; RUN: ld.lld %t1.o %t2.o -o %t3 -save-temps ; RUN: llvm-dis %t3.0.2.internalize.bc -o - | FileCheck %s ; RUN: rm -f %t.a ; RUN: llvm-ar rcs %t.a %t1.o -; RUN: ld.lld -m elf_x86_64 %t.a %t1.o %t2.o -o %t3 -save-temps +; RUN: ld.lld %t.a %t1.o %t2.o -o %t3 -save-temps ; RUN: llvm-dis %t3.0.2.internalize.bc -o - | FileCheck %s ; CHECK: define internal void @foo() { diff --git a/test/ELF/lto/archive-no-index.ll b/test/ELF/lto/archive-no-index.ll index 48cca0aa0794..5ac2628fefd8 100644 --- a/test/ELF/lto/archive-no-index.ll +++ b/test/ELF/lto/archive-no-index.ll @@ -11,8 +11,8 @@ ; RUN: llvm-ar crS %t1.a %t2.o ; RUN: llvm-ar crs %t2.a %t2.o -; RUN: ld.lld -o %t -emain -m elf_x86_64 %t1.o %t1.a -; RUN: ld.lld -o %t -emain -m elf_x86_64 %t1.o %t2.a +; RUN: ld.lld -o %t -emain %t1.o %t1.a +; RUN: ld.lld -o %t -emain %t1.o %t2.a target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/archive.ll b/test/ELF/lto/archive.ll index b4d011fdb888..6c4ca5e9aaaa 100644 --- a/test/ELF/lto/archive.ll +++ b/test/ELF/lto/archive.ll @@ -3,9 +3,9 @@ ; RUN: rm -f %t.a ; RUN: llvm-ar rcs %t.a %t1.o ; RUN: llvm-as %s -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t2.o %t.a -o %t3 -shared +; RUN: ld.lld %t2.o %t.a -o %t3 -shared ; RUN: llvm-readobj -t %t3 | FileCheck %s -; RUN: ld.lld -m elf_x86_64 %t2.o --whole-archive %t.a -o %t3 -shared +; RUN: ld.lld %t2.o --whole-archive %t.a -o %t3 -shared ; RUN: llvm-readobj -t %t3 | FileCheck %s ; CHECK: Name: g ( diff --git a/test/ELF/lto/asmundef.ll b/test/ELF/lto/asmundef.ll index d03a5e387213..604af8f9380b 100644 --- a/test/ELF/lto/asmundef.ll +++ b/test/ELF/lto/asmundef.ll @@ -1,6 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t -save-temps +; RUN: llvm-as %S/Inputs/asmundef.ll -o %t2.o +; RUN: ld.lld %t.o %t2.o -o %t -save-temps ; RUN: llvm-dis %t.0.4.opt.bc -o - | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" @@ -20,5 +21,5 @@ define void @_start() { ret void } -; CHECK: define void @foo +; CHECK: define dso_local void @foo diff --git a/test/ELF/lto/available-externally.ll b/test/ELF/lto/available-externally.ll index 315e710ec87c..516bec8c8a4e 100644 --- a/test/ELF/lto/available-externally.ll +++ b/test/ELF/lto/available-externally.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t1.o ; RUN: llvm-as %p/Inputs/available-externally.ll -o %t2.o -; RUN: ld.lld %t1.o %t2.o -m elf_x86_64 -o %t.so -shared -save-temps +; RUN: ld.lld %t1.o %t2.o -o %t.so -shared -save-temps ; RUN: llvm-dis < %t.so.0.2.internalize.bc | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/bitcode-nodatalayout.ll b/test/ELF/lto/bitcode-nodatalayout.ll index 5c4883a42444..c99cbb8550f0 100644 --- a/test/ELF/lto/bitcode-nodatalayout.ll +++ b/test/ELF/lto/bitcode-nodatalayout.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: not ld.lld -m elf_x86_64 %t.o -o %t 2>&1 | FileCheck %s +; RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s ; CHECK: input module has no datalayout diff --git a/test/ELF/lto/cache.ll b/test/ELF/lto/cache.ll index 5ab74f5c5457..3f2bea9f2cdf 100644 --- a/test/ELF/lto/cache.ll +++ b/test/ELF/lto/cache.ll @@ -13,7 +13,7 @@ ; RUN: ls %t.cache | count 4 ; Create a file of size 64KB. -; RUN: %python -c "print(' ' * 65536)" > %t.cache/llvmcache-foo +; RUN: "%python" -c "print(' ' * 65536)" > %t.cache/llvmcache-foo ; This should leave the file in place. ; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy cache_size_bytes=128k:prune_interval=0s -o %t3 %t2.o %t.o diff --git a/test/ELF/lto/codemodel.ll b/test/ELF/lto/codemodel.ll index cc126202f299..995575a9a0ab 100644 --- a/test/ELF/lto/codemodel.ll +++ b/test/ELF/lto/codemodel.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %ts -mllvm -code-model=small -; RUN: ld.lld -m elf_x86_64 %t.o -o %tl -mllvm -code-model=large +; RUN: ld.lld %t.o -o %ts -mllvm -code-model=small +; RUN: ld.lld %t.o -o %tl -mllvm -code-model=large ; RUN: llvm-objdump -d %ts | FileCheck %s --check-prefix=CHECK-SMALL ; RUN: llvm-objdump -d %tl | FileCheck %s --check-prefix=CHECK-LARGE diff --git a/test/ELF/lto/combined-lto-object-name.ll b/test/ELF/lto/combined-lto-object-name.ll index 76564f90c665..e0b98740e0f0 100644 --- a/test/ELF/lto/combined-lto-object-name.ll +++ b/test/ELF/lto/combined-lto-object-name.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: not ld.lld -m elf_x86_64 %t.o -o %t2 2>&1 | FileCheck %s +; RUN: not ld.lld %t.o -o %t2 2>&1 | FileCheck %s target triple = "x86_64-unknown-linux-gnu" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/comdat.ll b/test/ELF/lto/comdat.ll index e1384d0abd23..1739351220cd 100644 --- a/test/ELF/lto/comdat.ll +++ b/test/ELF/lto/comdat.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o %t.o -o %t.so -shared +; RUN: ld.lld %t.o %t.o -o %t.so -shared ; RUN: llvm-readobj -t %t.so | FileCheck %s ; CHECK: Name: foo diff --git a/test/ELF/lto/comdat2.ll b/test/ELF/lto/comdat2.ll index 283182155ae6..e7c6ea10b5e2 100644 --- a/test/ELF/lto/comdat2.ll +++ b/test/ELF/lto/comdat2.ll @@ -1,9 +1,9 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o ; RUN: llvm-mc -triple=x86_64-pc-linux %p/Inputs/comdat.s -o %t2.o -filetype=obj -; RUN: ld.lld -m elf_x86_64 %t.o %t2.o -o %t.so -shared +; RUN: ld.lld %t.o %t2.o -o %t.so -shared ; RUN: llvm-readobj -t %t.so | FileCheck %s -; RUN: ld.lld -m elf_x86_64 %t2.o %t.o -o %t2.so -shared +; RUN: ld.lld %t2.o %t.o -o %t2.so -shared ; RUN: llvm-readobj -t %t2.so | FileCheck %s --check-prefix=OTHER diff --git a/test/ELF/lto/common2.ll b/test/ELF/lto/common2.ll index 2345a203b24c..1cb5c322ba05 100644 --- a/test/ELF/lto/common2.ll +++ b/test/ELF/lto/common2.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t1.o -; RUN: ld.lld -m elf_x86_64 %t1.o -o %t -shared -save-temps +; RUN: ld.lld %t1.o -o %t -shared -save-temps ; RUN: llvm-dis < %t.0.2.internalize.bc | FileCheck %s ; RUN: llvm-readobj -t %t | FileCheck %s --check-prefix=SHARED diff --git a/test/ELF/lto/common3.ll b/test/ELF/lto/common3.ll index aea33f443f4c..de52615e24f4 100644 --- a/test/ELF/lto/common3.ll +++ b/test/ELF/lto/common3.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t1.o ; RUN: llvm-as %S/Inputs/common3.ll -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t1.o %t2.o -o %t -shared -save-temps +; RUN: ld.lld %t1.o %t2.o -o %t -shared -save-temps ; RUN: llvm-dis < %t.0.2.internalize.bc | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/cpu-string.ll b/test/ELF/lto/cpu-string.ll new file mode 100644 index 000000000000..ff80dbb9a7b3 --- /dev/null +++ b/test/ELF/lto/cpu-string.ll @@ -0,0 +1,25 @@ +; REQUIRES: x86 +; RUN: llvm-as %s -o %t.o + +; RUN: ld.lld %t.o -o %t.so -shared +; RUN: llvm-objdump -d -section=".text" -no-leading-addr -no-show-raw-insn %t.so | FileCheck %s +; CHECK: nop{{$}} + +; RUN: ld.lld -mllvm -mcpu=znver1 %t.o -o %t.znver1.so -shared +; RUN: llvm-objdump -d -section=".text" -no-leading-addr -no-show-raw-insn %t.znver1.so | FileCheck -check-prefix=ZNVER1 %s +; ZNVER1: nopw + +; Check we are able to use -plugin-opt=mcpu=<CPU> to set CPU string. +; RUN: ld.lld -plugin-opt=mcpu=znver1 %t.o -o %t.znver1.so -shared +; RUN: llvm-objdump -d -section=".text" -no-leading-addr -no-show-raw-insn %t.znver1.so | FileCheck -check-prefix=ZNVER1 %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @foo() #0 { +entry: + call void asm sideeffect ".p2align 4, 0x90", "~{dirflag},~{fpsr},~{flags}"() + ret void +} + +attributes #0 = { "no-frame-pointer-elim"="true" } diff --git a/test/ELF/lto/ctors.ll b/test/ELF/lto/ctors.ll index 7fce645f28f6..f64189711aa5 100644 --- a/test/ELF/lto/ctors.ll +++ b/test/ELF/lto/ctors.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -shared +; RUN: ld.lld %t.o -o %t.so -shared ; RUN: llvm-readobj -sections %t.so | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/data-ordering-lto.s b/test/ELF/lto/data-ordering-lto.s index 0364e587b908..bdacccc35400 100644 --- a/test/ELF/lto/data-ordering-lto.s +++ b/test/ELF/lto/data-ordering-lto.s @@ -8,17 +8,18 @@ # RUN: echo "pat " >> %t_order_lto.txt # RUN: ld.lld --symbol-ordering-file %t_order_lto.txt %t.o %t.bc -o %t2.out -# RUN: llvm-readobj -elf-output-style=GNU -t %t2.out| FileCheck %s +# RUN: llvm-readelf -t %t2.out| FileCheck %s # Check that the order is tin -> dipsy -> pat. -# CHECK: Symbol table '.symtab' contains 5 entries: +# CHECK: Symbol table '.symtab' contains 6 entries: # CHECK-NEXT: Num: Value Size Type Bind Vis Ndx Name # CHECK-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND -# CHECK-NEXT: 1: 0000000000201000 0 NOTYPE GLOBAL DEFAULT 1 _start -# CHECK-NEXT: 2: 0000000000202004 4 OBJECT GLOBAL DEFAULT 2 dipsy -# CHECK-NEXT: 3: 0000000000202008 4 OBJECT GLOBAL DEFAULT 2 pat -# CHECK-NEXT: 4: 0000000000202000 4 OBJECT GLOBAL DEFAULT 2 tin +# CHECK-NEXT: 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS {{.*}}.o +# CHECK-NEXT: 2: 0000000000201000 0 NOTYPE GLOBAL DEFAULT 1 _start +# CHECK-NEXT: 3: 0000000000202004 4 OBJECT GLOBAL DEFAULT 2 dipsy +# CHECK-NEXT: 4: 0000000000202008 4 OBJECT GLOBAL DEFAULT 2 pat +# CHECK-NEXT: 5: 0000000000202000 4 OBJECT GLOBAL DEFAULT 2 tin .globl _start _start: diff --git a/test/ELF/lto/debugger-tune.ll b/test/ELF/lto/debugger-tune.ll new file mode 100644 index 000000000000..b7457756bcb1 --- /dev/null +++ b/test/ELF/lto/debugger-tune.ll @@ -0,0 +1,35 @@ +; REQUIRES: x86 +; RUN: llvm-as %s -o %t.o + +; Here we verify that -debugger-tune=<value> option is +; handled by LLD. DWARF linkage name attributes are optional, +; they normally present, but are missing for SCE debugger tune. + +; RUN: ld.lld %t.o -o %t.exe +; RUN: llvm-dwarfdump %t.exe | FileCheck %s +; CHECK: DW_AT_linkage_name ("name_of_foo") + +; RUN: ld.lld -plugin-opt=-debugger-tune=sce %t.o -o %t.exe +; RUN: llvm-dwarfdump %t.exe | FileCheck --check-prefix=SCE %s +; SCE-NOT: name_of_foo + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@foo = global i32 0, align 4, !dbg !0 + +!llvm.dbg.cu = !{!5} +!llvm.module.flags = !{!8, !9} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "global_foo", linkageName: "name_of_foo", scope: !2, + file: !3, line: 2, type: !4, isLocal: false, isDefinition: true) +!2 = !DINamespace(name: "test", scope: null) +!3 = !DIFile(filename: "test.cpp", directory: "/home/tests") +!4 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", + isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !6, globals: !7) +!6 = !{} +!7 = !{!0} +!8 = !{i32 2, !"Dwarf Version", i32 4} +!9 = !{i32 2, !"Debug Info Version", i32 3} diff --git a/test/ELF/lto/defsym.ll b/test/ELF/lto/defsym.ll index 2ce8570f9b68..e5f0a4875f59 100644 --- a/test/ELF/lto/defsym.ll +++ b/test/ELF/lto/defsym.ll @@ -2,14 +2,18 @@ ; LTO ; RUN: llvm-as %s -o %t.o ; RUN: llvm-as %S/Inputs/defsym-bar.ll -o %t1.o -; RUN: ld.lld %t.o %t1.o -shared -o %t.so -defsym=bar2=bar3 +; RUN: ld.lld %t.o %t1.o -shared -o %t.so -defsym=bar2=bar3 -save-temps +; RUN: llvm-readelf -t %t.so.lto.o | FileCheck --check-prefix=OBJ %s ; RUN: llvm-objdump -d %t.so | FileCheck %s ; ThinLTO ; RUN: opt -module-summary %s -o %t.o ; RUN: opt -module-summary %S/Inputs/defsym-bar.ll -o %t1.o -; RUN: ld.lld %t.o %t1.o -shared -o %t.so -defsym=bar2=bar3 -; RUN: llvm-objdump -d %t.so | FileCheck %s --check-prefix=THIN +; RUN: ld.lld %t.o %t1.o -shared -o %t2.so -defsym=bar2=bar3 -save-temps +; RUN: llvm-readelf -t %t2.so1.lto.o | FileCheck --check-prefix=OBJ %s +; RUN: llvm-objdump -d %t2.so | FileCheck %s --check-prefix=THIN + +; OBJ: UND bar2 ; Call to bar2() should not be inlined and should be routed to bar3() ; Symbol bar3 should not be eliminated diff --git a/test/ELF/lto/discard-value-names.ll b/test/ELF/lto/discard-value-names.ll index f1e95fe75000..485014e94d9b 100644 --- a/test/ELF/lto/discard-value-names.ll +++ b/test/ELF/lto/discard-value-names.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 -shared -save-temps %t.o -o %t2.o +; RUN: ld.lld -shared -save-temps %t.o -o %t2.o ; RUN: llvm-dis < %t2.o.0.0.preopt.bc | FileCheck %s ; CHECK: @GlobalValueName diff --git a/test/ELF/lto/drop-debug-info.ll b/test/ELF/lto/drop-debug-info.ll index 27c0260080eb..f820faf5d0e9 100644 --- a/test/ELF/lto/drop-debug-info.ll +++ b/test/ELF/lto/drop-debug-info.ll @@ -3,7 +3,7 @@ ; drop-debug-info.bc was created from "void f(void) {}" with clang 3.5 and ; -gline-tables-only, so it contains old debug info. ; -; RUN: ld.lld -m elf_x86_64 -shared %p/Inputs/drop-debug-info.bc \ -; RUN: -disable-verify 2>&1 | FileCheck %s +; RUN: ld.lld -shared %p/Inputs/drop-debug-info.bc \ +; RUN: -disable-verify -o %t 2>&1 | FileCheck %s ; CHECK: ignoring debug info with an invalid version (1) in {{.*}}drop-debug-info.bc diff --git a/test/ELF/lto/drop-linkage.ll b/test/ELF/lto/drop-linkage.ll index 1ff179666f0e..f02fa02bc4fd 100644 --- a/test/ELF/lto/drop-linkage.ll +++ b/test/ELF/lto/drop-linkage.ll @@ -1,12 +1,12 @@ -target triple = "x86_64-unknown-linux-gnu" -target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" - ; REQUIRES: x86 ; RUN: llc %s -o %t.o -filetype=obj ; RUN: llvm-as %p/Inputs/drop-linkage.ll -o %t2.o ; RUN: ld.lld %t.o %t2.o -o %t.so -save-temps -shared ; RUN: llvm-dis %t.so.0.4.opt.bc -o - | FileCheck %s +target triple = "x86_64-unknown-linux-gnu" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + define void @foo() { ret void } diff --git a/test/ELF/lto/duplicated.ll b/test/ELF/lto/duplicated.ll index 156748117a23..fc60fbab23c9 100644 --- a/test/ELF/lto/duplicated.ll +++ b/test/ELF/lto/duplicated.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: not ld.lld -m elf_x86_64 %t.o %t.o -o %t.so -shared 2>&1 | FileCheck %s +; RUN: not ld.lld %t.o %t.o -o %t.so -shared 2>&1 | FileCheck %s ; CHECK: duplicate symbol: f ; CHECK-NEXT: >>> defined in {{.*}}.o diff --git a/test/ELF/lto/dynamic-list.ll b/test/ELF/lto/dynamic-list.ll index 0e950b3c83fd..c5473d833380 100644 --- a/test/ELF/lto/dynamic-list.ll +++ b/test/ELF/lto/dynamic-list.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o ; RUN: echo "{ foo; };" > %t.list -; RUN: ld.lld -m elf_x86_64 -o %t --dynamic-list %t.list -pie %t.o +; RUN: ld.lld -o %t --dynamic-list %t.list -pie %t.o ; RUN: llvm-readobj -dyn-symbols %t | FileCheck %s ; CHECK: Name: foo@ diff --git a/test/ELF/lto/dynsym.ll b/test/ELF/lto/dynsym.ll index b2b4157820b5..d056c0b555e3 100644 --- a/test/ELF/lto/dynsym.ll +++ b/test/ELF/lto/dynsym.ll @@ -1,12 +1,12 @@ ; REQUIRES: x86 ; RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux -o %t.o %p/Inputs/dynsym.s -; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -shared +; RUN: ld.lld %t.o -o %t.so -shared ; RUN: llvm-as %s -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t2.o %t.so -o %t +; RUN: ld.lld %t2.o %t.so -o %t ; RUN: llvm-readobj -dyn-symbols %t | FileCheck %s ; Check that we don't crash when gc'ing sections and printing the result. -; RUN: ld.lld -m elf_x86_64 %t2.o %t.so --gc-sections --print-gc-sections \ +; RUN: ld.lld %t2.o %t.so --gc-sections --print-gc-sections \ ; RUN: -o %t ; RUN: llvm-readobj -dyn-symbols %t | FileCheck %s diff --git a/test/ELF/lto/inline-asm.ll b/test/ELF/lto/inline-asm.ll index b6af6a5a5cbb..e0732e6def54 100644 --- a/test/ELF/lto/inline-asm.ll +++ b/test/ELF/lto/inline-asm.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -shared +; RUN: ld.lld %t.o -o %t.so -shared target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/internalize-basic.ll b/test/ELF/lto/internalize-basic.ll index 43c1837528f5..5197654d5880 100644 --- a/test/ELF/lto/internalize-basic.ll +++ b/test/ELF/lto/internalize-basic.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -save-temps +; RUN: ld.lld %t.o -o %t2 -save-temps ; RUN: llvm-dis < %t2.0.2.internalize.bc | FileCheck %s target triple = "x86_64-unknown-linux-gnu" @@ -15,7 +15,7 @@ define hidden void @foo() { } ; Check that _start is not internalized. -; CHECK: define void @_start() +; CHECK: define dso_local void @_start() ; Check that foo function is correctly internalized. ; CHECK: define internal void @foo() diff --git a/test/ELF/lto/internalize-exportdyn.ll b/test/ELF/lto/internalize-exportdyn.ll index 2034a2b3ab72..7c996e19f354 100644 --- a/test/ELF/lto/internalize-exportdyn.ll +++ b/test/ELF/lto/internalize-exportdyn.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o ; RUN: llvm-as %p/Inputs/internalize-exportdyn.ll -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t.o %t2.o -o %t2 --export-dynamic -save-temps +; RUN: ld.lld %t.o %t2.o -o %t2 --export-dynamic -save-temps ; RUN: llvm-dis < %t2.0.2.internalize.bc | FileCheck %s target triple = "x86_64-unknown-linux-gnu" @@ -38,10 +38,10 @@ define linkonce_odr void @baz() { @use_baz = global void ()* @baz ; Check what gets internalized. -; CHECK: define void @_start() -; CHECK: define void @foo() +; CHECK: define dso_local void @_start() +; CHECK: define dso_local void @foo() ; CHECK: define internal void @bar() ; CHECK: define internal void @zed() ; CHECK: define internal void @zed2() -; CHECK: define weak_odr void @bah() -; CHECK: define weak_odr void @baz() +; CHECK: define weak_odr dso_local void @bah() +; CHECK: define weak_odr dso_local void @baz() diff --git a/test/ELF/lto/internalize-llvmused.ll b/test/ELF/lto/internalize-llvmused.ll index 253dcb26d042..7e3d867da596 100644 --- a/test/ELF/lto/internalize-llvmused.ll +++ b/test/ELF/lto/internalize-llvmused.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -save-temps +; RUN: ld.lld %t.o -o %t2 -save-temps ; RUN: llvm-dis < %t2.0.2.internalize.bc | FileCheck %s target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/internalize-undef.ll b/test/ELF/lto/internalize-undef.ll index f76528bda3b0..c0860d8943bd 100644 --- a/test/ELF/lto/internalize-undef.ll +++ b/test/ELF/lto/internalize-undef.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o ; RUN: llvm-as %p/Inputs/internalize-undef.ll -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t.o %t2.o -o %t -save-temps +; RUN: ld.lld %t.o %t2.o -o %t -save-temps ; RUN: llvm-dis < %t.0.2.internalize.bc | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/internalize-version-script.ll b/test/ELF/lto/internalize-version-script.ll index c577e43b50e4..7e242e1a7eff 100644 --- a/test/ELF/lto/internalize-version-script.ll +++ b/test/ELF/lto/internalize-version-script.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o ; RUN: echo "{ global: foo; local: *; };" > %t.script -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -shared --version-script %t.script -save-temps +; RUN: ld.lld %t.o -o %t2 -shared --version-script %t.script -save-temps ; RUN: llvm-dis < %t2.0.2.internalize.bc | FileCheck %s target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/irmover-error.ll b/test/ELF/lto/irmover-error.ll index 8b9836d23ca4..d1c962ff7250 100644 --- a/test/ELF/lto/irmover-error.ll +++ b/test/ELF/lto/irmover-error.ll @@ -1,6 +1,6 @@ ; RUN: llvm-as -o %t1.bc %s ; RUN: llvm-as -o %t2.bc %S/Inputs/irmover-error.ll -; RUN: not ld.lld -m elf_x86_64 %t1.bc %t2.bc -o %t 2>&1 | FileCheck %s +; RUN: not ld.lld %t1.bc %t2.bc -o %t 2>&1 | FileCheck %s ; CHECK: linking module flags 'foo': IDs have conflicting values diff --git a/test/ELF/lto/keep-undefined.ll b/test/ELF/lto/keep-undefined.ll index cb0f4ce491f9..55d2a05b48f9 100644 --- a/test/ELF/lto/keep-undefined.ll +++ b/test/ELF/lto/keep-undefined.ll @@ -2,7 +2,7 @@ ; This test checks that symbols which are specified in "-u" switches ; are kept over LTO if we link an executable. ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %tout -u foo +; RUN: ld.lld %t.o -o %tout -u foo ; RUN: llvm-nm %tout | FileCheck %s ; CHECK: T foo diff --git a/test/ELF/lto/lazy-internal.ll b/test/ELF/lto/lazy-internal.ll new file mode 100644 index 000000000000..1bb2bac3d59e --- /dev/null +++ b/test/ELF/lto/lazy-internal.ll @@ -0,0 +1,19 @@ +; REQUIRES: x86 +; RUN: llvm-as %s -o %t1.o +; RUN: llvm-as %p/Inputs/lazy-internal.ll -o %t2.o +; RUN: rm -f %t2.a +; RUN: llvm-ar rc %t2.a %t2.o +; RUN: ld.lld %t2.a %t1.o -o %t.so -shared -save-temps +; RUN: llvm-dis %t.so.0.2.internalize.bc -o - | FileCheck %s + +; CHECK: define internal void @foo() +; CHECK: define internal void @bar() + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define hidden void @foo() { + call void @bar() + ret void +} +declare void @bar() diff --git a/test/ELF/lto/linkage.ll b/test/ELF/lto/linkage.ll index 5af9b321eeec..9b9390002c7a 100644 --- a/test/ELF/lto/linkage.ll +++ b/test/ELF/lto/linkage.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t1.o -; RUN: ld.lld -m elf_x86_64 %t1.o %t1.o -o %t.so -shared +; RUN: ld.lld %t1.o %t1.o -o %t.so -shared ; RUN: llvm-nm %t.so | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/linker-script-symbols-assign.ll b/test/ELF/lto/linker-script-symbols-assign.ll index 2ffdc823a484..bd7a37402997 100644 --- a/test/ELF/lto/linker-script-symbols-assign.ll +++ b/test/ELF/lto/linker-script-symbols-assign.ll @@ -2,20 +2,11 @@ ; RUN: llvm-as %s -o %t.o ; RUN: echo "foo = 1;" > %t.script -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 --script %t.script -save-temps +; RUN: ld.lld %t.o -o %t2 --script %t.script -save-temps ; RUN: llvm-readobj -symbols %t2.lto.o | FileCheck %s ; CHECK-NOT: bar -; CHECK: Symbol { -; CHECK: Name: foo -; CHECK-NEXT: Value: 0x0 -; CHECK-NEXT: Size: 4 -; CHECK-NEXT: Binding: Weak -; CHECK-NEXT: Type: Object -; CHECK-NEXT: Other: 0 -; CHECK-NEXT: Section: .bss.foo -; CHECK-NEXT: } -; CHECK-NEXT:] +; CHECK-NOT: foo ; RUN: llvm-readobj -symbols %t2 | FileCheck %s --check-prefix=VAL ; VAL: Symbol { @@ -29,7 +20,7 @@ ; VAL-NEXT: } ; RUN: echo "zed = 1;" > %t2.script -; RUN: ld.lld -m elf_x86_64 %t.o -o %t3 --script %t2.script +; RUN: ld.lld %t.o -o %t3 --script %t2.script ; RUN: llvm-readobj -symbols %t3 | FileCheck %s --check-prefix=ABS ; ABS: Symbol { ; ABS: Name: zed diff --git a/test/ELF/lto/linker-script-symbols-ipo.ll b/test/ELF/lto/linker-script-symbols-ipo.ll index 6ac1a83e1ec0..4cc95c6cacaf 100644 --- a/test/ELF/lto/linker-script-symbols-ipo.ll +++ b/test/ELF/lto/linker-script-symbols-ipo.ll @@ -4,7 +4,7 @@ ; RUN: echo "bar = foo;" > %t.script ;; Check that without linkerscript bar is inlined. -; RUN: ld.lld -m elf_x86_64 %t1.o %t2.o -o %t3 -save-temps +; RUN: ld.lld %t1.o %t2.o -o %t3 -save-temps ; RUN: llvm-objdump -d %t3 | FileCheck %s --check-prefix=IPO ; IPO: Disassembly of section .text: ; IPO: _start: @@ -12,13 +12,13 @@ ; IPO-NEXT: 201005: {{.*}} retq ;; Check that LTO does not do IPO for symbols assigned by script. -; RUN: ld.lld -m elf_x86_64 %t1.o %t2.o -o %t4 --script %t.script -save-temps +; RUN: ld.lld %t1.o %t2.o -o %t4 --script %t.script -save-temps ; RUN: llvm-objdump -d %t4 | FileCheck %s --check-prefix=NOIPO ; NOIPO: Disassembly of section .text: ; NOIPO: foo: -; NOIPO-NEXT: 201010: {{.*}} movl $2, %eax +; NOIPO-NEXT: {{.*}} movl $2, %eax ; NOIPO: _start: -; NOIPO-NEXT: 201020: {{.*}} jmp -21 <foo> +; NOIPO-NEXT: {{.*}} jmp -21 <foo> target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/linker-script-symbols.ll b/test/ELF/lto/linker-script-symbols.ll index c2a58b6e841d..28758c052067 100644 --- a/test/ELF/lto/linker-script-symbols.ll +++ b/test/ELF/lto/linker-script-symbols.ll @@ -2,7 +2,7 @@ ; RUN: llvm-as %s -o %t.o ; RUN: echo "foo = bar;" > %t.script -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 --script %t.script -save-temps +; RUN: ld.lld %t.o -o %t2 --script %t.script -save-temps ; RUN: llvm-readobj -symbols %t2.lto.o | FileCheck %s ; CHECK-NOT: zed diff --git a/test/ELF/lto/lto-start.ll b/test/ELF/lto/lto-start.ll index e93eecfbf033..cc1eb4bd5b01 100644 --- a/test/ELF/lto/lto-start.ll +++ b/test/ELF/lto/lto-start.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 +; RUN: ld.lld %t.o -o %t2 ; RUN: llvm-readobj -t %t2 | FileCheck %s ; CHECK: Format: ELF64-x86-64 diff --git a/test/ELF/lto/ltopasses-basic.ll b/test/ELF/lto/ltopasses-basic.ll index 0c4ad8b9f17c..6789bdc95fe1 100644 --- a/test/ELF/lto/ltopasses-basic.ll +++ b/test/ELF/lto/ltopasses-basic.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -save-temps -mllvm -debug-pass=Arguments -shared 2>&1 | FileCheck %s --check-prefix=MLLVM +; RUN: ld.lld %t.o -o %t.so -save-temps -mllvm -debug-pass=Arguments -shared 2>&1 | FileCheck %s --check-prefix=MLLVM ; RUN: llvm-dis %t.so.0.4.opt.bc -o - | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/ltopasses-custom.ll b/test/ELF/lto/ltopasses-custom.ll index a48959a32991..a75000d5cfd3 100644 --- a/test/ELF/lto/ltopasses-custom.ll +++ b/test/ELF/lto/ltopasses-custom.ll @@ -1,8 +1,8 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -save-temps --lto-aa-pipeline=basic-aa \ +; RUN: ld.lld %t.o -o %t.so -save-temps --lto-aa-pipeline=basic-aa \ ; RUN: --lto-newpm-passes=ipsccp -shared -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2.so -save-temps --lto-newpm-passes=loweratomic -shared +; RUN: ld.lld %t.o -o %t2.so -save-temps --lto-newpm-passes=loweratomic -shared ; RUN: llvm-dis %t.so.0.4.opt.bc -o - | FileCheck %s ; RUN: llvm-dis %t2.so.0.4.opt.bc -o - | FileCheck %s --check-prefix=ATOMIC diff --git a/test/ELF/lto/metadata.ll b/test/ELF/lto/metadata.ll index 2eaacaae2726..238b5bd43b70 100644 --- a/test/ELF/lto/metadata.ll +++ b/test/ELF/lto/metadata.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t1.o -; RUN: ld.lld -m elf_x86_64 %t1.o %t1.o -o %t.so -shared +; RUN: ld.lld %t1.o %t1.o -o %t.so -shared target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/mix-platforms2.ll b/test/ELF/lto/mix-platforms2.ll new file mode 100644 index 000000000000..1bd989e86746 --- /dev/null +++ b/test/ELF/lto/mix-platforms2.ll @@ -0,0 +1,9 @@ +; REQUIRES: x86 +; RUN: llvm-as %s -o %tx64.o +; RUN: llvm-as %S/Inputs/i386-empty.ll -o %ti386.o +; RUN: not ld.lld %ti386.o %tx64.o -o %t.out 2>&1 | FileCheck %s + +; CHECK: {{.*}}x64.o is incompatible with {{.*}}i386.o + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/module-asm.ll b/test/ELF/lto/module-asm.ll index 1389b9f5472e..eaf276214221 100644 --- a/test/ELF/lto/module-asm.ll +++ b/test/ELF/lto/module-asm.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t +; RUN: ld.lld %t.o -o %t ; RUN: llvm-nm %t | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/new-pass-manager.ll b/test/ELF/lto/new-pass-manager.ll new file mode 100644 index 000000000000..918b50500166 --- /dev/null +++ b/test/ELF/lto/new-pass-manager.ll @@ -0,0 +1,14 @@ +; REQUIRES: x86 +; RUN: opt -module-summary %s -o %t.o + +; Test new-pass-manager and debug-pass-manager option +; RUN: ld.lld --plugin-opt=new-pass-manager --plugin-opt=debug-pass-manager -o %t2.o %t.o 2>&1 | FileCheck %s +; RUN: ld.lld --plugin-opt=new-pass-manager --lto-debug-pass-manager -o %t2.o %t.o 2>&1 | FileCheck %s +; RUN: ld.lld --lto-new-pass-manager --plugin-opt=debug-pass-manager -o %t2.o %t.o 2>&1 | FileCheck %s +; RUN: ld.lld --lto-new-pass-manager --lto-debug-pass-manager -o %t2.o %t.o 2>&1 | FileCheck %s + +; CHECK: Starting llvm::Module pass manager run +; CHECK: Finished llvm::Module pass manager run + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/opt-level.ll b/test/ELF/lto/opt-level.ll index 57fa3041ac65..5c4ec43a21a5 100644 --- a/test/ELF/lto/opt-level.ll +++ b/test/ELF/lto/opt-level.ll @@ -1,30 +1,30 @@ ; REQUIRES: x86 ; RUN: llvm-as -o %t.o %s -; RUN: ld.lld -o %t0 -m elf_x86_64 -e main --lto-O0 %t.o +; RUN: ld.lld -o %t0 -e main --lto-O0 %t.o ; RUN: llvm-nm %t0 | FileCheck --check-prefix=CHECK-O0 %s -; RUN: ld.lld -o %t0 -m elf_x86_64 -e main --plugin-opt=O0 %t.o +; RUN: ld.lld -o %t0 -e main --plugin-opt=O0 %t.o ; RUN: llvm-nm %t0 | FileCheck --check-prefix=CHECK-O0 %s -; RUN: ld.lld -o %t2 -m elf_x86_64 -e main --lto-O2 %t.o +; RUN: ld.lld -o %t2 -e main --lto-O2 %t.o ; RUN: llvm-nm %t2 | FileCheck --check-prefix=CHECK-O2 %s -; RUN: ld.lld -o %t2a -m elf_x86_64 -e main %t.o +; RUN: ld.lld -o %t2a -e main %t.o ; RUN: llvm-nm %t2a | FileCheck --check-prefix=CHECK-O2 %s -; RUN: ld.lld -o %t2 -m elf_x86_64 -e main --plugin-opt=O2 %t.o +; RUN: ld.lld -o %t2 -e main %t.o --plugin-opt O2 ; RUN: llvm-nm %t2 | FileCheck --check-prefix=CHECK-O2 %s ; Reject invalid optimization levels. -; RUN: not ld.lld -o %t3 -m elf_x86_64 -e main --lto-O6 %t.o 2>&1 | \ +; RUN: not ld.lld -o %t3 -e main --lto-O6 %t.o 2>&1 | \ ; RUN: FileCheck --check-prefix=INVALID1 %s ; INVALID1: invalid optimization level for LTO: 6 -; RUN: not ld.lld -o %t3 -m elf_x86_64 -e main --plugin-opt=O6 %t.o 2>&1 | \ +; RUN: not ld.lld -o %t3 -e main --plugin-opt=O6 %t.o 2>&1 | \ ; RUN: FileCheck --check-prefix=INVALID1 %s -; RUN: not ld.lld -o %t3 -m elf_x86_64 -e main --plugin-opt=Ofoo %t.o 2>&1 | \ +; RUN: not ld.lld -o %t3 -e main --plugin-opt=Ofoo %t.o 2>&1 | \ ; RUN: FileCheck --check-prefix=INVALID2 %s -; INVALID2: --plugin-opt: number expected, but got 'foo' +; INVALID2: --plugin-opt=Ofoo: number expected, but got 'foo' -; RUN: not ld.lld -o %t3 -m elf_x86_64 -e main --lto-O-1 %t.o 2>&1 | \ +; RUN: not ld.lld -o %t3 -e main --lto-O-1 %t.o 2>&1 | \ ; RUN: FileCheck --check-prefix=INVALIDNEGATIVE1 %s ; INVALIDNEGATIVE1: invalid optimization level for LTO: 4294967295 -; RUN: not ld.lld -o %t3 -m elf_x86_64 -e main --plugin-opt=O-1 %t.o 2>&1 | \ +; RUN: not ld.lld -o %t3 -e main --plugin-opt=O-1 %t.o 2>&1 | \ ; RUN: FileCheck --check-prefix=INVALIDNEGATIVE2 %s ; INVALIDNEGATIVE2: invalid optimization level for LTO: 4294967295 diff --git a/test/ELF/lto/parallel-internalize.ll b/test/ELF/lto/parallel-internalize.ll index da5bdc6892a8..f21b3ccd29e9 100644 --- a/test/ELF/lto/parallel-internalize.ll +++ b/test/ELF/lto/parallel-internalize.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as -o %t.bc %s ; RUN: rm -f %t.lto.o %t1.lto.o -; RUN: ld.lld -m elf_x86_64 --lto-partitions=2 -save-temps -o %t %t.bc \ +; RUN: ld.lld --lto-partitions=2 -save-temps -o %t %t.bc \ ; RUN: -e foo --lto-O0 ; RUN: llvm-readobj -t -dyn-symbols %t | FileCheck %s ; RUN: llvm-nm %t.lto.o | FileCheck --check-prefix=CHECK0 %s @@ -18,6 +18,24 @@ ; CHECK-NEXT: Section: Undefined (0x0) ; CHECK-NEXT: } ; CHECK-NEXT: Symbol { +; CHECK-NEXT: Name: {{.*}}.o +; CHECK-NEXT: Value: 0x0 +; CHECK-NEXT: Size: 0 +; CHECK-NEXT: Binding: Local +; CHECK-NEXT: Type: File +; CHECK-NEXT: Other: 0 +; CHECK-NEXT: Section: Absolute +; CHECK-NEXT: } +; CHECK-NEXT: Symbol { +; CHECK-NEXT: Name: {{.*}}.o +; CHECK-NEXT: Value: 0x0 +; CHECK-NEXT: Size: 0 +; CHECK-NEXT: Binding: Local +; CHECK-NEXT: Type: File +; CHECK-NEXT: Other: 0 +; CHECK-NEXT: Section: Absolute +; CHECK-NEXT: } +; CHECK-NEXT: Symbol { ; CHECK-NEXT: Name: bar ; CHECK-NEXT: Value: 0x201010 ; CHECK-NEXT: Size: 8 diff --git a/test/ELF/lto/parallel.ll b/test/ELF/lto/parallel.ll index a1c15af380f0..4ba3fd69d527 100644 --- a/test/ELF/lto/parallel.ll +++ b/test/ELF/lto/parallel.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as -o %t.bc %s ; RUN: rm -f %t.lto.o %t1.lto.o -; RUN: ld.lld -m elf_x86_64 --lto-partitions=2 -save-temps -o %t %t.bc -shared +; RUN: ld.lld --lto-partitions=2 -save-temps -o %t %t.bc -shared ; RUN: llvm-nm %t.lto.o | FileCheck --check-prefix=CHECK0 %s ; RUN: llvm-nm %t1.lto.o | FileCheck --check-prefix=CHECK1 %s diff --git a/test/ELF/lto/relax-relocs.ll b/test/ELF/lto/relax-relocs.ll index 8e8d9d165787..80e5dac77d83 100644 --- a/test/ELF/lto/relax-relocs.ll +++ b/test/ELF/lto/relax-relocs.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 -save-temps -shared %t.o -o %t.so +; RUN: ld.lld -save-temps -shared %t.o -o %t.so ; RUN: llvm-readobj -r %t.so.lto.o | FileCheck %s ; Test that we produce R_X86_64_REX_GOTPCRELX instead of R_X86_64_GOTPCREL diff --git a/test/ELF/lto/relocatable.ll b/test/ELF/lto/relocatable.ll index ef21f84a621a..2ec9144a37b0 100644 --- a/test/ELF/lto/relocatable.ll +++ b/test/ELF/lto/relocatable.ll @@ -14,6 +14,15 @@ ; CHECK-NEXT: Section: Undefined ; CHECK-NEXT: } ; CHECK-NEXT: Symbol { +; CHECK-NEXT: Name: {{.*}}.o +; CHECK-NEXT: Value: 0x0 +; CHECK-NEXT: Size: 0 +; CHECK-NEXT: Binding: Local +; CHECK-NEXT: Type: File +; CHECK-NEXT: Other: 0 +; CHECK-NEXT: Section: Absolute +; CHECK-NEXT: } +; CHECK-NEXT: Symbol { ; CHECK-NEXT: Name: ; CHECK-NEXT: Value: 0x0 ; CHECK-NEXT: Size: 0 diff --git a/test/ELF/lto/sample-profile.ll b/test/ELF/lto/sample-profile.ll new file mode 100644 index 000000000000..a8b110444425 --- /dev/null +++ b/test/ELF/lto/sample-profile.ll @@ -0,0 +1,25 @@ +; REQUIRES: x86 +; RUN: opt -module-summary %s -o %t1.o +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o + +; RUN: rm -f %t1.lto.o %t2.lto.o +; RUN: ld.lld --lto-sample-profile=%p/Inputs/sample-profile.prof %t1.o %t2.o -o %t3 +; RUN opt -S %t3.lto.o | FileCheck %s + +; RUN: rm -f %t1.lto.o %t2.lto.o +; RUN: ld.lld --plugin-opt=sample-profile=%p/Inputs/sample-profile.prof %t1.o %t2.o -o %t3 +; RUN opt -S %t3.lto.o | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: ProfileSummary +declare void @g(...) +declare void @h(...) + +define void @f() { +entry: + call void (...) @g() + call void (...) @h() + ret void +} diff --git a/test/ELF/lto/save-temps.ll b/test/ELF/lto/save-temps.ll index c8e52ff4b4ec..b34134cc5d7f 100644 --- a/test/ELF/lto/save-temps.ll +++ b/test/ELF/lto/save-temps.ll @@ -3,7 +3,7 @@ ; RUN: rm -f a.out a.out.lto.bc a.out.lto.o ; RUN: llvm-as %s -o %t.o ; RUN: llvm-as %p/Inputs/save-temps.ll -o %t2.o -; RUN: ld.lld -shared -m elf_x86_64 %t.o %t2.o -save-temps +; RUN: ld.lld -shared %t.o %t2.o -save-temps ; RUN: llvm-nm a.out | FileCheck %s ; RUN: llvm-nm a.out.0.0.preopt.bc | FileCheck %s ; RUN: llvm-nm a.out.lto.o | FileCheck %s diff --git a/test/ELF/lto/setting-dso-local.ll b/test/ELF/lto/setting-dso-local.ll new file mode 100644 index 000000000000..74ce4e7f16d3 --- /dev/null +++ b/test/ELF/lto/setting-dso-local.ll @@ -0,0 +1,15 @@ +; REQUIRES: x86 +; RUN: llvm-as %s -o %t1.o +; RUN: not ld.lld -o %t %t1.o 2>&1 | FileCheck %s + +; CHECK: undefined symbol: foobar + +; We used to crash setting foobar to non-dso_local + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@foobar = external hidden global i32 +define i32* @_start() { + ret i32* @foobar +} diff --git a/test/ELF/lto/start-lib.ll b/test/ELF/lto/start-lib.ll index ec73954a80ca..024d887a7d0a 100644 --- a/test/ELF/lto/start-lib.ll +++ b/test/ELF/lto/start-lib.ll @@ -4,17 +4,17 @@ ; RUN: llvm-as %p/Inputs/start-lib1.ll -o %t2.o ; RUN: llvm-as %p/Inputs/start-lib2.ll -o %t3.o ; -; RUN: ld.lld -m elf_x86_64 -shared -o %t3 %t1.o %t2.o %t3.o +; RUN: ld.lld -shared -o %t3 %t1.o %t2.o %t3.o ; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST1 %s ; TEST1: Name: bar ; TEST1: Name: foo ; -; RUN: ld.lld -m elf_x86_64 -shared -o %t3 -u bar %t1.o --start-lib %t2.o %t3.o +; RUN: ld.lld -shared -o %t3 -u bar %t1.o --start-lib %t2.o %t3.o ; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST2 %s ; TEST2: Name: bar ; TEST2-NOT: Name: foo ; -; RUN: ld.lld -m elf_x86_64 -shared -o %t3 %t1.o --start-lib %t2.o %t3.o +; RUN: ld.lld -shared -o %t3 %t1.o --start-lib %t2.o %t3.o ; RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST3 %s ; TEST3-NOT: Name: bar ; TEST3-NOT: Name: foo diff --git a/test/ELF/lto/symbol-ordering-lto.s b/test/ELF/lto/symbol-ordering-lto.s index 4c29e54c476e..530b63c669a4 100644 --- a/test/ELF/lto/symbol-ordering-lto.s +++ b/test/ELF/lto/symbol-ordering-lto.s @@ -8,16 +8,17 @@ # RUN: echo "pat " >> %t_order_lto.txt # RUN: ld.lld --symbol-ordering-file %t_order_lto.txt %t.o %t.bc -o %t2.out -# RUN: llvm-readobj -elf-output-style=GNU -t %t2.out| FileCheck %s +# RUN: llvm-readelf -t %t2.out| FileCheck %s # Check that the order is tin -> _start -> pat. -# CHECK: Symbol table '.symtab' contains 4 entries: +# CHECK: Symbol table '.symtab' contains 5 entries: # CHECK-NEXT: Num: Value Size Type Bind Vis Ndx Name # CHECK-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND -# CHECK-NEXT: 1: 0000000000201008 0 NOTYPE GLOBAL DEFAULT 1 _start -# CHECK-NEXT: 2: 0000000000201020 6 FUNC GLOBAL DEFAULT 1 pat -# CHECK-NEXT: 3: 0000000000201000 6 FUNC GLOBAL DEFAULT 1 tin +# CHECK-NEXT: 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS {{.*}}.o +# CHECK-NEXT: 2: 0000000000201008 0 NOTYPE GLOBAL DEFAULT 1 _start +# CHECK-NEXT: 3: 0000000000201020 6 FUNC GLOBAL DEFAULT 1 pat +# CHECK-NEXT: 4: 0000000000201000 6 FUNC GLOBAL DEFAULT 1 tin .globl _start _start: diff --git a/test/ELF/lto/thinlto-cant-write-index.ll b/test/ELF/lto/thinlto-cant-write-index.ll new file mode 100644 index 000000000000..94f2a45c2743 --- /dev/null +++ b/test/ELF/lto/thinlto-cant-write-index.ll @@ -0,0 +1,23 @@ +; REQUIRES: x86 + +; Basic ThinLTO tests. +; RUN: opt -module-summary %s -o %t1.o +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o + +; Ensure lld generates error if unable to write to index files +; RUN: rm -f %t2.o.thinlto.bc +; RUN: touch %t2.o.thinlto.bc +; RUN: chmod 400 %t2.o.thinlto.bc +; RUN: not ld.lld --plugin-opt=thinlto-index-only -shared %t1.o %t2.o -o %t3 2>&1 | FileCheck %s +; CHECK: cannot open {{.*}}2.o.thinlto.bc: {{P|p}}ermission denied + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @g(...) + +define void @f() { +entry: + call void (...) @g() + ret void +} diff --git a/test/ELF/lto/thinlto-debug-fission.ll b/test/ELF/lto/thinlto-debug-fission.ll new file mode 100644 index 000000000000..b779ad4a45f6 --- /dev/null +++ b/test/ELF/lto/thinlto-debug-fission.ll @@ -0,0 +1,21 @@ +; REQUIRES: x86 + +; RUN: opt %s -o %t1.o +; RUN: rm -rf %T/dwo + +; Test to ensure that --plugin-opt=dwo_dir=$DIR creates .dwo files under $DIR +; RUN: ld.lld --plugin-opt=dwo_dir=%T/dwo -shared %t1.o -o /dev/null +; RUN: llvm-readobj -h %T/dwo/0.dwo | FileCheck %s + +; CHECK: Format: ELF64-x86-64 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @g(...) + +define void @f() { +entry: + call void (...) @g() + ret void +} diff --git a/test/ELF/lto/thinlto-emit-imports.ll b/test/ELF/lto/thinlto-emit-imports.ll new file mode 100644 index 000000000000..cae7922682bc --- /dev/null +++ b/test/ELF/lto/thinlto-emit-imports.ll @@ -0,0 +1,55 @@ +; REQUIRES: x86 + +; Generate summary sections and test lld handling. +; RUN: opt -module-summary %s -o %t1.o +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o + +; Include a file with an empty module summary index, to ensure that the expected +; output files are created regardless, for a distributed build system. +; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o %t3.o + +; Ensure lld generates imports files if requested for distributed backends. +; RUN: rm -f %t3.o.imports %t3.o.thinlto.bc +; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=thinlto-emit-imports-files -shared %t1.o %t2.o %t3.o -o %t4 + +; The imports file for this module contains the bitcode file for +; Inputs/thinlto.ll +; RUN: cat %t1.o.imports | count 1 +; RUN: cat %t1.o.imports | FileCheck %s --check-prefix=IMPORTS1 +; IMPORTS1: thinlto-emit-imports.ll.tmp2.o + +; The imports file for Input/thinlto.ll is empty as it does not import anything. +; RUN: cat %t2.o.imports | count 0 + +; The imports file for Input/thinlto_empty.ll is empty but should exist. +; RUN: cat %t3.o.imports | count 0 + +; The index file should be created even for the input with an empty summary. +; RUN: ls %t3.o.thinlto.bc + +; Ensure lld generates error if unable to write to imports file. +; RUN: rm -f %t3.o.imports +; RUN: touch %t3.o.imports +; RUN: chmod 400 %t3.o.imports +; RUN: not ld.lld --plugin-opt=thinlto-index-only --plugin-opt=thinlto-emit-imports-files -shared %t1.o %t2.o %t3.o -o %t4 2>&1 | FileCheck %s --check-prefix=ERR +; ERR: cannot open {{.*}}3.o.imports: {{P|p}}ermission denied + +; Ensure lld doesn't generate import files when thinlto-index-only is not enabled +; RUN: rm -f %t1.o.imports +; RUN: rm -f %t2.o.imports +; RUN: rm -f %t3.o.imports +; RUN: ld.lld --plugin-opt=thinlto-emit-imports-files -shared %t1.o %t2.o %t3.o -o %t4 +; RUN: not ls %t1.o.imports +; RUN: not ls %t2.o.imports +; RUN: not ls %t3.o.imports + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @g(...) + +define void @f() { +entry: + call void (...) @g() + ret void +} diff --git a/test/ELF/lto/thinlto-index-file.ll b/test/ELF/lto/thinlto-index-file.ll new file mode 100644 index 000000000000..91f0b298ca35 --- /dev/null +++ b/test/ELF/lto/thinlto-index-file.ll @@ -0,0 +1,24 @@ +; REQUIRES: x86 + +; Basic ThinLTO tests. +; RUN: opt -module-summary %s -o %t1.o +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o +; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o %t3.o + +; Ensure lld writes linked files to linked objects file +; RUN: ld.lld --plugin-opt=thinlto-index-only=%t.idx -shared %t1.o %t2.o %t3.o -o %t4 +; RUN: FileCheck %s < %t.idx +; CHECK: {{.*}}thinlto-index-file.ll.tmp1.o +; CHECK: {{.*}}thinlto-index-file.ll.tmp2.o +; CHECK: {{.*}}thinlto-index-file.ll.tmp3.o + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @g(...) + +define void @f() { +entry: + call void (...) @g() + ret void +} diff --git a/test/ELF/lto/thinlto-index-only.ll b/test/ELF/lto/thinlto-index-only.ll new file mode 100644 index 000000000000..6263799ee2fd --- /dev/null +++ b/test/ELF/lto/thinlto-index-only.ll @@ -0,0 +1,89 @@ +; REQUIRES: x86 + +; First ensure that the ThinLTO handling in lld handles +; bitcode without summary sections gracefully and generates index file. +; RUN: llvm-as %s -o %t1.o +; RUN: llvm-as %p/Inputs/thinlto.ll -o %t2.o +; RUN: rm -f %t3 +; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %t1.o %t2.o -o %t3 +; RUN: ls %t2.o.thinlto.bc +; RUN: not test -e %t3 +; RUN: ld.lld -shared %t1.o %t2.o -o %t3 +; RUN: llvm-nm %t3 | FileCheck %s --check-prefix=NM + +; Basic ThinLTO tests. +; RUN: opt -module-summary %s -o %t1.o +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o +; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o %t3.o + +; Ensure lld generates an index and not a binary if requested. +; RUN: rm -f %t4 +; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %t1.o %t2.o -o %t4 +; RUN: llvm-bcanalyzer -dump %t1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1 +; RUN: llvm-bcanalyzer -dump %t2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2 +; RUN: not test -e %t4 + +; Ensure lld generates an index even if the file is wrapped in --start-lib/--end-lib +; RUN: rm -f %t2.o.thinlto.bc %t4 +; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %t1.o %t3.o --start-lib %t2.o --end-lib -o %t4 +; RUN: ls %t2.o.thinlto.bc +; RUN: not test -e %t4 + +; Test that LLD generates an empty index even for lazy object file that is not added to link. +; Test LLD generates empty imports file either because of thinlto-emit-imports-files option. +; RUN: rm -f %t1.o.thinlto.bc +; RUN: rm -f %t1.o.imports +; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %t2.o --start-lib %t1.o --end-lib \ +; RUN: --plugin-opt=thinlto-emit-imports-files -o %t3 +; RUN: ls %t1.o.thinlto.bc +; RUN: ls %t1.o.imports + +; Ensure lld generates an error if unable to write an empty index file +; for lazy object file that is not added to link. +; RUN: rm -f %t1.o.thinlto.bc +; RUN: touch %t1.o.thinlto.bc +; RUN: chmod 400 %t1.o.thinlto.bc +; RUN: not ld.lld --plugin-opt=thinlto-index-only -shared %t2.o --start-lib %t1.o --end-lib \ +; RUN: -o %t3 2>&1 | FileCheck %s +; CHECK: cannot open {{.*}}1.o.thinlto.bc: {{P|p}}ermission denied +; RUN: rm -f %t1.o.thinlto.bc + +; NM: T f + +; The backend index for this module contains summaries from itself and +; Inputs/thinlto.ll, as it imports from the latter. +; BACKEND1: <MODULE_STRTAB_BLOCK +; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto-index-only.ll.tmp{{.*}}.o' +; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto-index-only.ll.tmp{{.*}}.o' +; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK +; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK +; BACKEND1: <VERSION +; BACKEND1: <FLAGS +; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}} +; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}} +; BACKEND1: <COMBINED +; BACKEND1: <COMBINED +; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK + +; The backend index for Input/thinlto.ll contains summaries from itself only, +; as it does not import anything. +; BACKEND2: <MODULE_STRTAB_BLOCK +; BACKEND2-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto-index-only.ll.tmp2.o' +; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK +; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK +; BACKEND2-NEXT: <VERSION +; BACKEND2-NEXT: <FLAGS +; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238 +; BACKEND2-NEXT: <COMBINED +; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @g(...) + +define void @f() { +entry: + call void (...) @g() + ret void +} diff --git a/test/ELF/lto/thinlto-no-index.ll b/test/ELF/lto/thinlto-no-index.ll new file mode 100644 index 000000000000..f80cf0e63812 --- /dev/null +++ b/test/ELF/lto/thinlto-no-index.ll @@ -0,0 +1,24 @@ +; REQUIRES: x86 + +; Basic ThinLTO tests. +; RUN: opt -module-summary %s -o %t1.o +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o +; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o %t3.o + +; Ensure lld doesn't generates index files when thinlto-index-only is not enabled +; RUN: rm -f %t1.o.thinlto.bc %t2.o.thinlto.bc %t3.o.thinlto.bc +; RUN: ld.lld -shared %t1.o %t2.o %t3.o -o %t4 +; RUN: not ls %t1.o.thinlto.bc +; RUN: not ls %t2.o.thinlto.bc +; RUN: not ls %t3.o.thinlto.bc + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @g(...) + +define void @f() { +entry: + call void (...) @g() + ret void +} diff --git a/test/ELF/lto/thinlto-obj-path.ll b/test/ELF/lto/thinlto-obj-path.ll new file mode 100644 index 000000000000..bb69bb876a28 --- /dev/null +++ b/test/ELF/lto/thinlto-obj-path.ll @@ -0,0 +1,23 @@ +; REQUIRES: x86 + +; RUN: opt -module-summary %s -o %t1.o +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o + +; Test to ensure that thinlto-index-only with obj-path creates the file. +; RUN: rm -f %t4.o +; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=obj-path=%t4.o -shared %t1.o %t2.o -o %t3 +; RUN: llvm-readobj -h %t4.o | FileCheck %s +; RUN: llvm-nm %t4.o | count 0 + +; CHECK: Format: ELF64-x86-64 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @g(...) + +define void @f() { +entry: + call void (...) @g() + ret void +} diff --git a/test/ELF/lto/thinlto-object-suffix-replace.ll b/test/ELF/lto/thinlto-object-suffix-replace.ll new file mode 100644 index 000000000000..05ce942c70f8 --- /dev/null +++ b/test/ELF/lto/thinlto-object-suffix-replace.ll @@ -0,0 +1,50 @@ +; REQUIRES: x86 + +; Test to make sure the thinlto-object-suffix-replace option is handled +; correctly. + +; Generate bitcode file with summary, as well as a minimized bitcode without +; the debug metadata for the thin link. +; RUN: opt -thinlto-bc %s -thin-link-bitcode-file=%t1.thinlink.bc -o %t1.o + +; First perform the thin link on the normal bitcode file, and save the +; resulting index. +; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %t1.o -o %t3 +; RUN: cp %t1.o.thinlto.bc %t1.o.thinlto.bc.orig + +; Next perform the thin link on the minimized bitcode file, and compare dump +; of the resulting index to the above dump to ensure they are identical. +; RUN: rm -f %t1.o.thinlto.bc +; Make sure it isn't inadvertently using the regular bitcode file. +; RUN: rm -f %t1.o +; RUN: ld.lld --plugin-opt=thinlto-index-only \ +; RUN: --plugin-opt=thinlto-object-suffix-replace=".thinlink.bc;.o" \ +; RUN: -shared %t1.thinlink.bc -o %t3 +; RUN: diff %t1.o.thinlto.bc.orig %t1.o.thinlto.bc + +; Ensure lld generates error if object suffix replace option does not have 'old;new' format +; RUN: rm -f %t1.o.thinlto.bc +; RUN: not ld.lld --plugin-opt=thinlto-index-only \ +; RUN: --plugin-opt=thinlto-object-suffix-replace="abc:def" -shared %t1.thinlink.bc \ +; RUN: -o %t3 2>&1 | FileCheck %s --check-prefix=ERR1 +; ERR1: --plugin-opt=thinlto-object-suffix-replace= expects 'old;new' format, but got abc:def + +; Ensure lld generates error if old suffix doesn't exist in file name +; RUN: rm -f %t1.o +; RUN: not ld.lld --plugin-opt=thinlto-index-only \ +; RUN: --plugin-opt=thinlto-object-suffix-replace=".abc;.o" -shared %t1.thinlink.bc \ +; RUN: -o %t3 2>&1 | FileCheck %s --check-prefix=ERR2 +; ERR2: error: -thinlto-object-suffix-replace=.abc;.o was given, but {{.*}} does not end with the suffix + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @f() { +entry: + ret void +} + +!llvm.dbg.cu = !{} + +!1 = !{i32 2, !"Debug Info Version", i32 3} +!llvm.module.flags = !{!1} diff --git a/test/ELF/lto/thinlto-prefix-replace.ll b/test/ELF/lto/thinlto-prefix-replace.ll new file mode 100644 index 000000000000..c276dae7b260 --- /dev/null +++ b/test/ELF/lto/thinlto-prefix-replace.ll @@ -0,0 +1,23 @@ +; REQUIRES: x86 +; Check that changing the output path via thinlto-prefix-replace works +; RUN: mkdir -p %t/oldpath +; RUN: opt -module-summary %s -o %t/oldpath/thinlto_prefix_replace.o + +; Ensure that there is no existing file at the new path, so we properly +; test the creation of the new file there. +; RUN: rm -f %t/newpath/thinlto_prefix_replace.o.thinlto.bc +; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=thinlto-prefix-replace="%t/oldpath/;%t/newpath/" -shared %t/oldpath/thinlto_prefix_replace.o -o %t/thinlto_prefix_replace +; RUN: ls %t/newpath/thinlto_prefix_replace.o.thinlto.bc + +; Ensure that lld generates error if prefix replace option does not have 'old;new' format +; RUN: rm -f %t/newpath/thinlto_prefix_replace.o.thinlto.bc +; RUN: not ld.lld --plugin-opt=thinlto-index-only --plugin-opt=thinlto-prefix-replace=abc:def -shared %t/oldpath/thinlto_prefix_replace.o -o %t/thinlto_prefix_replace 2>&1 | FileCheck %s --check-prefix=ERR +; ERR: --plugin-opt=thinlto-prefix-replace= expects 'old;new' format, but got abc:def + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @f() { +entry: + ret void +} diff --git a/test/ELF/lto/thinlto.ll b/test/ELF/lto/thinlto.ll index 37d2b88131f6..51c82ece5876 100644 --- a/test/ELF/lto/thinlto.ll +++ b/test/ELF/lto/thinlto.ll @@ -1,30 +1,29 @@ ; REQUIRES: x86 + ; Basic ThinLTO tests. -; RUN: opt -module-summary %s -o %t.o +; RUN: opt -module-summary %s -o %t1.o ; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o ; First force single-threaded mode -; RUN: rm -f %t.lto.o %t1.lto.o -; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared %t.o %t2.o -o %t -; RUN: llvm-nm %t1.lto.o | FileCheck %s --check-prefix=NM1 -; RUN: llvm-nm %t2.lto.o | FileCheck %s --check-prefix=NM2 +; RUN: rm -f %t31.lto.o %t32.lto.o +; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared %t1.o %t2.o -o %t3 +; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1 +; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2 ; Next force multi-threaded mode -; RUN: rm -f %t2.lto.o %t21.lto.o -; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared %t.o %t2.o -o %t2 -; RUN: llvm-nm %t21.lto.o | FileCheck %s --check-prefix=NM1 -; RUN: llvm-nm %t22.lto.o | FileCheck %s --check-prefix=NM2 +; RUN: rm -f %t31.lto.o %t32.lto.o +; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared %t1.o %t2.o -o %t3 +; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1 +; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2 -; NM1: T f -; NM1-NOT: U g +; Then check without --thinlto-jobs (which currently default to hardware_concurrency) +; RUN: ld.lld -shared %t1.o %t2.o -o %t3 +; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1 +; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2 +; NM1: T f ; NM2: T g -; Then check without --thinlto-jobs (which currently default to hardware_concurrency) -; We just check that we don't crash or fail (as it's not sure which tests are -; stable on the final output file itself. -; RUN: ld.lld -shared %t.o %t2.o -o %t2 - target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/timepasses.ll b/test/ELF/lto/timepasses.ll index 5c893e661945..86c9b8ed7951 100644 --- a/test/ELF/lto/timepasses.ll +++ b/test/ELF/lto/timepasses.ll @@ -1,8 +1,7 @@ -; We use lld -flavor gnu because llvm-lit will append --full-shutdown to -; the ld.lld invocation. ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: lld -flavor gnu %t.o -o %t.so -shared -mllvm -time-passes 2>&1 | FileCheck %s +; RUN: env LLD_IN_TEST=0 ld.lld %t.o -o %t.so -shared -mllvm \ +; RUN: -time-passes 2>&1 | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @@ -11,5 +10,5 @@ define void @patatino() { ret void } -; We should get the output of -time-passes even when --full-shutdown is not specified. +; We should get the output of -time-passes even when full shutdown is not specified. ; CHECK: Total Execution Time diff --git a/test/ELF/lto/tls-mixed.ll b/test/ELF/lto/tls-mixed.ll index 524bb4fb44a3..9d5a69303728 100644 --- a/test/ELF/lto/tls-mixed.ll +++ b/test/ELF/lto/tls-mixed.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t1.o ; RUN: llvm-mc %p/Inputs/tls-mixed.s -o %t2.o -filetype=obj -triple=x86_64-pc-linux -; RUN: ld.lld -m elf_x86_64 %t1.o %t2.o -o %t.so -shared +; RUN: ld.lld %t1.o %t2.o -o %t.so -shared target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/tls-preserve.ll b/test/ELF/lto/tls-preserve.ll index 8aebcb783f48..c9b7675cd22f 100644 --- a/test/ELF/lto/tls-preserve.ll +++ b/test/ELF/lto/tls-preserve.ll @@ -1,7 +1,7 @@ ; TLS attribute needs to be preserved. ; REQUIRES: x86 ; RUN: llvm-as %s -o %t1.o -; RUN: ld.lld -shared %t1.o -m elf_x86_64 -o %t1 +; RUN: ld.lld -shared %t1.o -o %t1 ; RUN: llvm-readobj -t %t1 | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/type-merge.ll b/test/ELF/lto/type-merge.ll index d6f196d7c3ba..985c44b796e1 100644 --- a/test/ELF/lto/type-merge.ll +++ b/test/ELF/lto/type-merge.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o ; RUN: llvm-as %p/Inputs/type-merge.ll -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t.o %t2.o -o %t -shared -save-temps +; RUN: ld.lld %t.o %t2.o -o %t -shared -save-temps ; RUN: llvm-dis < %t.0.0.preopt.bc | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/type-merge2.ll b/test/ELF/lto/type-merge2.ll index 6ebbf778dd8e..5944be7e6c09 100644 --- a/test/ELF/lto/type-merge2.ll +++ b/test/ELF/lto/type-merge2.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o ; RUN: llvm-as %p/Inputs/type-merge2.ll -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t.o %t2.o -o %t.so -shared -save-temps +; RUN: ld.lld %t.o %t2.o -o %t.so -shared -save-temps ; RUN: llvm-dis %t.so.0.0.preopt.bc -o - | FileCheck %s target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/undef-weak.ll b/test/ELF/lto/undef-weak.ll index 215978a73df0..e090f5653a09 100644 --- a/test/ELF/lto/undef-weak.ll +++ b/test/ELF/lto/undef-weak.ll @@ -1,13 +1,12 @@ ; REQUIRES: x86 - ; RUN: llvm-as %S/Inputs/archive.ll -o %t1.o ; RUN: rm -f %t.a ; RUN: llvm-ar rcs %t.a %t1.o - ; RUN: llvm-as %s -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t2.o -o %t2.so %t.a -shared +; RUN: ld.lld %t2.o -o %t2.so %t.a -shared ; RUN: llvm-readobj -t %t2.so | FileCheck %s + target triple = "x86_64-unknown-linux-gnu" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/undef.ll b/test/ELF/lto/undef.ll index 41da61052290..4ea7e833df10 100644 --- a/test/ELF/lto/undef.ll +++ b/test/ELF/lto/undef.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -shared +; RUN: ld.lld %t.o -o %t.so -shared ; RUN: llvm-readobj -t %t.so | FileCheck %s target triple = "x86_64-unknown-linux-gnu" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/undefined-puts.ll b/test/ELF/lto/undefined-puts.ll index d13630368de9..6c3dc76be12a 100644 --- a/test/ELF/lto/undefined-puts.ll +++ b/test/ELF/lto/undefined-puts.ll @@ -2,7 +2,7 @@ ; RUN: llvm-mc %p/Inputs/shared.s -o %t1.o -filetype=obj -triple=x86_64-unknown-linux ; RUN: ld.lld %t1.o -o %t1.so -shared ; RUN: llvm-as %s -o %t2.o -; RUN: ld.lld %t1.so %t2.o -m elf_x86_64 -o %t +; RUN: ld.lld %t1.so %t2.o -o %t ; RUN: llvm-readobj -dyn-symbols -dyn-relocations %t | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/test/ELF/lto/unnamed-addr-comdat.ll b/test/ELF/lto/unnamed-addr-comdat.ll index 29a59415851b..38b08ab23ee9 100644 --- a/test/ELF/lto/unnamed-addr-comdat.ll +++ b/test/ELF/lto/unnamed-addr-comdat.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o %t.o -o %t.so -save-temps -shared +; RUN: ld.lld %t.o %t.o -o %t.so -save-temps -shared ; RUN: llvm-dis %t.so.0.2.internalize.bc -o - | FileCheck %s target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/unnamed-addr-drop.ll b/test/ELF/lto/unnamed-addr-drop.ll index e827cbb435e6..ad662b7fe7b6 100644 --- a/test/ELF/lto/unnamed-addr-drop.ll +++ b/test/ELF/lto/unnamed-addr-drop.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t1.o ; RUN: llvm-as %S/Inputs/unnamed-addr-drop.ll -o %t2.o -; RUN: ld.lld -m elf_x86_64 %t1.o %t2.o -o %t.so -save-temps -shared +; RUN: ld.lld %t1.o %t2.o -o %t.so -save-temps -shared ; RUN: llvm-dis %t.so.0.2.internalize.bc -o - | FileCheck %s target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/unnamed-addr-lib.ll b/test/ELF/lto/unnamed-addr-lib.ll index c2bc6016efd5..0c47468e6b4f 100644 --- a/test/ELF/lto/unnamed-addr-lib.ll +++ b/test/ELF/lto/unnamed-addr-lib.ll @@ -2,7 +2,7 @@ ; RUN: llvm-as %s -o %t.o ; RUN: llvm-mc %p/Inputs/unnamed-addr-lib.s -o %t2.o -filetype=obj -triple=x86_64-pc-linux ; RUN: ld.lld %t2.o -shared -o %t2.so -; RUN: ld.lld -m elf_x86_64 %t.o %t2.so -o %t.so -save-temps -shared +; RUN: ld.lld %t.o %t2.so -o %t.so -save-temps -shared ; RUN: llvm-dis %t.so.0.2.internalize.bc -o - | FileCheck %s ; This documents a small limitation of lld's internalization logic. We decide diff --git a/test/ELF/lto/unnamed-addr.ll b/test/ELF/lto/unnamed-addr.ll index 56fe148b0995..7504fdf6733b 100644 --- a/test/ELF/lto/unnamed-addr.ll +++ b/test/ELF/lto/unnamed-addr.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -save-temps -shared +; RUN: ld.lld %t.o -o %t.so -save-temps -shared ; RUN: llvm-dis %t.so.0.4.opt.bc -o - | FileCheck %s target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/verify-invalid.ll b/test/ELF/lto/verify-invalid.ll index e6138a3cca62..9fa0f9e0b5f9 100644 --- a/test/ELF/lto/verify-invalid.ll +++ b/test/ELF/lto/verify-invalid.ll @@ -1,10 +1,10 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -mllvm -debug-pass=Arguments \ +; RUN: ld.lld %t.o -o %t2 -mllvm -debug-pass=Arguments \ ; RUN: 2>&1 | FileCheck -check-prefix=DEFAULT %s -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -mllvm -debug-pass=Arguments \ +; RUN: ld.lld %t.o -o %t2 -mllvm -debug-pass=Arguments \ ; RUN: -disable-verify 2>&1 | FileCheck -check-prefix=DISABLE %s -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -mllvm -debug-pass=Arguments \ +; RUN: ld.lld %t.o -o %t2 -mllvm -debug-pass=Arguments \ ; RUN: --plugin-opt=disable-verify 2>&1 | FileCheck -check-prefix=DISABLE %s target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/version-script.ll b/test/ELF/lto/version-script.ll index c43b443ff749..35a36b5a8d78 100644 --- a/test/ELF/lto/version-script.ll +++ b/test/ELF/lto/version-script.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o ; RUN: echo "VERSION_1.0{ global: foo; local: *; }; VERSION_2.0{ global: bar; local: *; };" > %t.script -; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -shared --version-script %t.script -save-temps +; RUN: ld.lld %t.o -o %t2 -shared --version-script %t.script -save-temps ; RUN: llvm-dis < %t2.0.0.preopt.bc | FileCheck %s ; RUN: llvm-readobj -V -dyn-symbols %t2 | FileCheck --check-prefix=DSO %s diff --git a/test/ELF/lto/version-script2.ll b/test/ELF/lto/version-script2.ll new file mode 100644 index 000000000000..ab8f75a3eecc --- /dev/null +++ b/test/ELF/lto/version-script2.ll @@ -0,0 +1,15 @@ +; REQUIRES: x86 +; RUN: llvm-as %s -o %t.o +; RUN: echo "VER1 {};" > %t.script +; RUN: ld.lld %t.o -o %t.so -shared --version-script %t.script +; RUN: llvm-readobj -dyn-symbols %t.so | FileCheck %s + +; test that we have the correct version. +; CHECK: Name: foo@@VER1 ( + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +module asm ".global foo" +module asm "foo:" +module asm ".symver foo,foo@@@VER1" diff --git a/test/ELF/lto/visibility.ll b/test/ELF/lto/visibility.ll index 9acc0e2efaaf..434b61ef294c 100644 --- a/test/ELF/lto/visibility.ll +++ b/test/ELF/lto/visibility.ll @@ -1,7 +1,8 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t1.o ; RUN: llvm-mc -triple=x86_64-pc-linux %p/Inputs/visibility.s -o %t2.o -filetype=obj -; RUN: ld.lld %t1.o %t2.o -o %t.so -shared +; RUN: ld.lld %t1.o %t2.o -o %t.so -shared -save-temps +; RUN: llvm-dis < %t.so.0.2.internalize.bc | FileCheck --check-prefix=IR %s ; RUN: llvm-readobj -t %t.so | FileCheck %s ; CHECK: Name: g @@ -28,6 +29,8 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" declare hidden void @g() +; IR: declare hidden void @g() + define void @f() { call void @g() ret void diff --git a/test/ELF/lto/weak.ll b/test/ELF/lto/weak.ll index 381ef7a1a347..a807c1325db5 100644 --- a/test/ELF/lto/weak.ll +++ b/test/ELF/lto/weak.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: ld.lld -m elf_x86_64 %t.o %t.o -o %t.so -shared +; RUN: ld.lld %t.o %t.o -o %t.so -shared ; RUN: llvm-readobj -t %t.so | FileCheck %s target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/weakodr-visibility.ll b/test/ELF/lto/weakodr-visibility.ll new file mode 100644 index 000000000000..95bd3e4c5a28 --- /dev/null +++ b/test/ELF/lto/weakodr-visibility.ll @@ -0,0 +1,40 @@ +; REQUIRES: x86 +; RUN: llvm-as %s -o %t1.o +; RUN: llvm-as %p/Inputs/weakodr-visibility.ll -o %t2.o + +; Testcase checks we keep desired visibility of weak +; symbol in a library even if select different definition. +; We change the order of input files in command line and +; check that linker selects different symbol definitions, +; but keeps `protected` visibility. + +; RUN: ld.lld %t1.o %t2.o -o %t.so -shared +; RUN: llvm-readobj -t %t.so | FileCheck %s +; RUN: llvm-objdump -d %t.so | FileCheck %s --check-prefix=FIRST +; CHECK: Symbol { +; CHECK: Name: foo +; CHECK-NEXT: Value: +; CHECK-NEXT: Size: +; CHECK-NEXT: Binding: Weak +; CHECK-NEXT: Type: Function +; CHECK-NEXT: Other [ +; CHECK-NEXT: STV_PROTECTED +; CHECK-NEXT: ] +; CHECK-NEXT: Section: +; CHECK-NEXT: } +; FIRST: foo: +; FIRST-NEXT: movl $41, %eax + +; Now swap the files order. +; RUN: ld.lld %t2.o %t1.o -o %t.so -shared +; RUN: llvm-readobj -t %t.so | FileCheck %s +; RUN: llvm-objdump -d %t.so | FileCheck %s --check-prefix=SECOND +; SECOND: foo: +; SECOND-NEXT: movl $42, %eax + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define weak_odr i32 @foo(i8* %this) { + ret i32 41 +} diff --git a/test/ELF/lto/wrap-1.ll b/test/ELF/lto/wrap-1.ll index 83e09493fb5d..b82bece253d1 100644 --- a/test/ELF/lto/wrap-1.ll +++ b/test/ELF/lto/wrap-1.ll @@ -20,8 +20,8 @@ ; Make sure that the 'r' (linker redefined) bit is set for bar and __wrap_bar ; in the resolutions file. ; RESOLS: ,bar,xr -; RESOLS: ,__wrap_bar,px -; RESOLS: ,__real_bar,pxr +; RESOLS: ,__wrap_bar,plx +; RESOLS: ,__real_bar,plxr target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/map-file-i686.s b/test/ELF/map-file-i686.s new file mode 100644 index 000000000000..bab2c4b377e2 --- /dev/null +++ b/test/ELF/map-file-i686.s @@ -0,0 +1,21 @@ +// REQUIRES: x86 + +// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t1.o +// RUN: ld.lld %t1.o -o /dev/null -M | FileCheck -strict-whitespace %s + +.global _start +_start: + nop + +// CHECK: VMA LMA Size Align Out In Symbol +// CHECK-NEXT: 11000 11000 1 4 .text +// CHECK-NEXT: 11000 11000 1 4 {{.*}}{{/|\\}}map-file-i686.s.tmp1.o:(.text) +// CHECK-NEXT: 11000 11000 0 1 _start +// CHECK-NEXT: 0 0 8 1 .comment +// CHECK-NEXT: 0 0 8 1 <internal>:(.comment) +// CHECK-NEXT: 0 0 20 4 .symtab +// CHECK-NEXT: 0 0 20 4 <internal>:(.symtab) +// CHECK-NEXT: 0 0 2a 1 .shstrtab +// CHECK-NEXT: 0 0 2a 1 <internal>:(.shstrtab) +// CHECK-NEXT: 0 0 8 1 .strtab +// CHECK-NEXT: 0 0 8 1 <internal>:(.strtab) diff --git a/test/ELF/map-file.s b/test/ELF/map-file.s index d1acabe28126..76e50fb5db04 100644 --- a/test/ELF/map-file.s +++ b/test/ELF/map-file.s @@ -15,16 +15,21 @@ .global _start _start: +.cfi_startproc +.cfi_endproc .quad sharedFoo .quad sharedBar - callq sharedFunc1 - callq sharedFunc2 - call baz + .byte 0xe8 + .long sharedFunc1 - . + .byte 0xe8 + .long sharedFunc2 - . + .byte 0xe8 + .long baz - . .global _Z1fi _Z1fi: .cfi_startproc -.cfi_endproc nop +.cfi_endproc .weak bar bar: .long bar - . @@ -35,58 +40,61 @@ local: abs = 0xAB5 labs = 0x1AB5 -// CHECK: Address Size Align Out In Symbol -// CHECK-NEXT: 00000000002001c8 0000000000000078 8 .dynsym -// CHECK-NEXT: 00000000002001c8 0000000000000078 8 <internal>:(.dynsym) -// CHECK-NEXT: 0000000000200240 000000000000002c 8 .gnu.hash -// CHECK-NEXT: 0000000000200240 000000000000002c 8 <internal>:(.gnu.hash) -// CHECK-NEXT: 000000000020026c 0000000000000030 4 .hash -// CHECK-NEXT: 000000000020026c 0000000000000030 4 <internal>:(.hash) -// CHECK-NEXT: 000000000020029c 0000000000000031 1 .dynstr -// CHECK-NEXT: 000000000020029c 0000000000000031 1 <internal>:(.dynstr) -// CHECK-NEXT: 00000000002002d0 0000000000000030 8 .rela.dyn -// CHECK-NEXT: 00000000002002d0 0000000000000030 8 <internal>:(.rela.dyn) -// CHECK-NEXT: 0000000000200300 0000000000000030 8 .rela.plt -// CHECK-NEXT: 0000000000200300 0000000000000030 8 <internal>:(.rela.plt) -// CHECK-NEXT: 0000000000200330 0000000000000030 8 .eh_frame -// CHECK-NEXT: 0000000000200330 0000000000000030 8 <internal>:(.eh_frame) -// CHECK-NEXT: 0000000000201000 000000000000002d 4 .text -// CHECK-NEXT: 0000000000201000 0000000000000028 4 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.text) -// CHECK-NEXT: 0000000000201000 0000000000000000 0 _start -// CHECK-NEXT: 000000000020101f 0000000000000000 0 f(int) -// CHECK-NEXT: 0000000000201028 0000000000000000 0 local -// CHECK-NEXT: 0000000000201028 0000000000000002 4 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.text) -// CHECK-NEXT: 0000000000201028 0000000000000000 0 foo -// CHECK-NEXT: 0000000000201029 0000000000000000 0 bar -// CHECK-NEXT: 000000000020102a 0000000000000000 1 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.text.zed) -// CHECK-NEXT: 000000000020102a 0000000000000000 0 zed -// CHECK-NEXT: 000000000020102c 0000000000000000 4 {{.*}}{{/|\\}}map-file.s.tmp3.o:(.text) -// CHECK-NEXT: 000000000020102c 0000000000000000 0 bah -// CHECK-NEXT: 000000000020102c 0000000000000001 4 {{.*}}{{/|\\}}map-file.s.tmp4.a(map-file.s.tmp4.o):(.text) -// CHECK-NEXT: 000000000020102c 0000000000000000 0 baz -// CHECK-NEXT: 0000000000201030 0000000000000030 16 .plt -// CHECK-NEXT: 0000000000201030 0000000000000030 16 <internal>:(.plt) -// CHECK-NEXT: 0000000000201040 0000000000000000 0 sharedFunc1 -// CHECK-NEXT: 0000000000201050 0000000000000000 0 sharedFunc2 -// CHECK-NEXT: 0000000000202000 0000000000000028 8 .got.plt -// CHECK-NEXT: 0000000000202000 0000000000000028 8 <internal>:(.got.plt) -// CHECK-NEXT: 0000000000203000 0000000000000100 8 .dynamic -// CHECK-NEXT: 0000000000203000 0000000000000100 8 <internal>:(.dynamic) -// CHECK-NEXT: 0000000000204000 0000000000000010 16 .bss -// CHECK-NEXT: 0000000000204000 0000000000000004 16 {{.*}}{{/|\\}}map-file.s.tmp1.o:(COMMON) -// CHECK-NEXT: 0000000000204000 0000000000000004 0 common -// CHECK-NEXT: 0000000000204004 0000000000000004 1 <internal>:(.bss) -// CHECK-NEXT: 0000000000204004 0000000000000004 0 sharedFoo -// CHECK-NEXT: 0000000000204008 0000000000000008 1 <internal>:(.bss) -// CHECK-NEXT: 0000000000204008 0000000000000008 0 sharedBar -// CHECK-NEXT: 0000000000000000 0000000000000008 1 .comment -// CHECK-NEXT: 0000000000000000 0000000000000008 1 <internal>:(.comment) -// CHECK-NEXT: 0000000000000000 0000000000000198 8 .symtab -// CHECK-NEXT: 0000000000000000 0000000000000198 8 <internal>:(.symtab) -// CHECK-NEXT: 0000000000000000 0000000000000084 1 .shstrtab -// CHECK-NEXT: 0000000000000000 0000000000000084 1 <internal>:(.shstrtab) -// CHECK-NEXT: 0000000000000000 000000000000006d 1 .strtab -// CHECK-NEXT: 0000000000000000 000000000000006d 1 <internal>:(.strtab) +// CHECK: VMA LMA Size Align Out In Symbol +// CHECK-NEXT: 2001c8 2001c8 78 8 .dynsym +// CHECK-NEXT: 2001c8 2001c8 78 8 <internal>:(.dynsym) +// CHECK-NEXT: 200240 200240 2c 8 .gnu.hash +// CHECK-NEXT: 200240 200240 2c 8 <internal>:(.gnu.hash) +// CHECK-NEXT: 20026c 20026c 30 4 .hash +// CHECK-NEXT: 20026c 20026c 30 4 <internal>:(.hash) +// CHECK-NEXT: 20029c 20029c 31 1 .dynstr +// CHECK-NEXT: 20029c 20029c 31 1 <internal>:(.dynstr) +// CHECK-NEXT: 2002d0 2002d0 30 8 .rela.dyn +// CHECK-NEXT: 2002d0 2002d0 30 8 <internal>:(.rela.dyn) +// CHECK-NEXT: 200300 200300 30 8 .rela.plt +// CHECK-NEXT: 200300 200300 30 8 <internal>:(.rela.plt) +// CHECK-NEXT: 200330 200330 64 8 .eh_frame +// CHECK-NEXT: 200330 200330 2c 1 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.eh_frame+0x0) +// CHECK-NEXT: 200360 200360 14 1 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.eh_frame+0x2c) +// CHECK-NEXT: 200378 200378 18 1 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.eh_frame+0x18) +// CHECK-NEXT: 201000 201000 2d 4 .text +// CHECK-NEXT: 201000 201000 28 4 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.text) +// CHECK-NEXT: 201000 201000 0 1 _start +// CHECK-NEXT: 20101f 20101f 0 1 f(int) +// CHECK-NEXT: 201028 201028 0 1 local +// CHECK-NEXT: 201028 201028 2 4 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.text) +// CHECK-NEXT: 201028 201028 0 1 foo +// CHECK-NEXT: 201029 201029 0 1 bar +// CHECK-NEXT: 20102a 20102a 0 1 {{.*}}{{/|\\}}map-file.s.tmp2.o:(.text.zed) +// CHECK-NEXT: 20102a 20102a 0 1 zed +// CHECK-NEXT: 20102c 20102c 0 4 {{.*}}{{/|\\}}map-file.s.tmp3.o:(.text) +// CHECK-NEXT: 20102c 20102c 0 1 bah +// CHECK-NEXT: 20102c 20102c 1 4 {{.*}}{{/|\\}}map-file.s.tmp4.a(map-file.s.tmp4.o):(.text) +// CHECK-NEXT: 20102c 20102c 0 1 baz +// CHECK-NEXT: 201030 201030 30 16 .plt +// CHECK-NEXT: 201030 201030 30 16 <internal>:(.plt) +// CHECK-NEXT: 201040 201040 0 1 sharedFunc1 +// CHECK-NEXT: 201050 201050 0 1 sharedFunc2 +// CHECK-NEXT: 202000 202000 28 8 .got.plt +// CHECK-NEXT: 202000 202000 28 8 <internal>:(.got.plt) +// CHECK-NEXT: 203000 203000 100 8 .dynamic +// CHECK-NEXT: 203000 203000 100 8 <internal>:(.dynamic) +// CHECK-NEXT: 204000 204000 10 16 .bss +// CHECK-NEXT: 204000 204000 4 16 {{.*}}{{/|\\}}map-file.s.tmp1.o:(COMMON) +// CHECK-NEXT: 204000 204000 4 1 common +// CHECK-NEXT: 204004 204004 4 1 <internal>:(.bss) +// CHECK-NEXT: 204004 204004 4 1 sharedFoo +// CHECK-NEXT: 204008 204008 8 1 <internal>:(.bss) +// CHECK-NEXT: 204008 204008 8 1 sharedBar +// CHECK-NEXT: 0 0 8 1 .comment +// CHECK-NEXT: 0 0 8 1 <internal>:(.comment) +// CHECK-NEXT: 0 0 198 8 .symtab +// CHECK-NEXT: 0 0 198 8 <internal>:(.symtab) +// CHECK-NEXT: 0 0 84 1 .shstrtab +// CHECK-NEXT: 0 0 84 1 <internal>:(.shstrtab) +// CHECK-NEXT: 0 0 6d 1 .strtab +// CHECK-NEXT: 0 0 6d 1 <internal>:(.strtab) + // RUN: not ld.lld %t1.o %t2.o %t3.o %t4.a -o %t -Map=/ 2>&1 \ // RUN: | FileCheck -check-prefix=FAIL %s diff --git a/test/ELF/map-gc-sections.s b/test/ELF/map-gc-sections.s index 717ab819889d..f69edf591f2f 100644 --- a/test/ELF/map-gc-sections.s +++ b/test/ELF/map-gc-sections.s @@ -1,5 +1,6 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: ld.lld %t.o -o %t -Map=- --gc-sections | FileCheck %s +// RUN: ld.lld %t.o -o /dev/null -Map=- --gc-sections | FileCheck %s .section .tbss,"awT",@nobits // CHECK-NOT: foo diff --git a/test/ELF/merge-gc-piece.s b/test/ELF/merge-gc-piece.s new file mode 100644 index 000000000000..4aec3b2aaed3 --- /dev/null +++ b/test/ELF/merge-gc-piece.s @@ -0,0 +1,38 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t.so -shared --gc-sections +# RUN: llvm-readobj -s -section-data %t.so | FileCheck %s + + +# CHECK: Name: .foo +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x200 + +# CHECK: Name: .bar +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: ] +# CHECK-NEXT: Address: +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 16 +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 01020000 00000000 02020000 00000000 +# CHECK-NEXT: ) + + .section .foo,"aM",@progbits,8 + .quad 42 + .global sym +sym: + .quad 43 + + .section .bar + .quad .foo + 1 + .quad .foo + 2 diff --git a/test/ELF/merge-gc-piece2.s b/test/ELF/merge-gc-piece2.s new file mode 100644 index 000000000000..88e0904caf2e --- /dev/null +++ b/test/ELF/merge-gc-piece2.s @@ -0,0 +1,27 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t.so -shared --gc-sections +# RUN: llvm-readobj -s -section-data %t.so | FileCheck %s + +# CHECK: Name: .bar +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: ] +# CHECK-NEXT: Address: +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 16 +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 01000000 00000000 02000000 00000000 +# CHECK-NEXT: ) + + .section .foo,"aM",@progbits,8 + .quad 42 + .quad 43 + + .section .bar + .quad .foo + 1 + .quad .foo + 2 diff --git a/test/ELF/merge-reloc-O0.s b/test/ELF/merge-reloc-O0.s new file mode 100644 index 000000000000..daf5c34b6c0a --- /dev/null +++ b/test/ELF/merge-reloc-O0.s @@ -0,0 +1,48 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -r -o %t2.o -O0 +# RUN: llvm-readobj -s -section-data %t2.o | FileCheck %s + +# We combine just the sections with the same name and sh_entsize. + +# CHECK: Name: .foo +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 16 +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: 8 +# CHECK-NEXT: EntrySize: 8 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 41000000 00000000 42000000 00000000 +# CHECK-NEXT: ) + +# CHECK: Name: .foo +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 4 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 41000000 42000000 +# CHECK-NEXT: ) + + .section .foo, "aM",@progbits,8,unique,0 + .quad 0x41 + .section .foo, "aM",@progbits,8,unique,1 + .quad 0x42 + .section .foo, "aM",@progbits,4,unique,2 + .long 0x41 + .long 0x42 diff --git a/test/ELF/merge-shared-str.s b/test/ELF/merge-shared-str.s index 2ab03a4d66ab..7502eb93ab36 100644 --- a/test/ELF/merge-shared-str.s +++ b/test/ELF/merge-shared-str.s @@ -19,10 +19,10 @@ // CHECK-NEXT: SHF_MERGE // CHECK-NEXT: SHF_STRINGS // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x1C8 +// CHECK-NEXT: Address: 0x228 // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x{{.*}} R_X86_64_RELATIVE - 0x1C9 +// CHECK-NEXT: 0x{{.*}} R_X86_64_RELATIVE - 0x229 // CHECK-NEXT: } // CHECK-NEXT: ] diff --git a/test/ELF/merge-shared.s b/test/ELF/merge-shared.s index 4c1d7c06a0ba..6615169f1ecd 100644 --- a/test/ELF/merge-shared.s +++ b/test/ELF/merge-shared.s @@ -17,10 +17,10 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_MERGE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x1C8 +// CHECK-NEXT: Address: 0x228 // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x{{.*}} R_X86_64_RELATIVE - 0x1CA +// CHECK-NEXT: 0x{{.*}} R_X86_64_RELATIVE - 0x22A // CHECK-NEXT: } // CHECK-NEXT: ] diff --git a/test/ELF/merge-string-empty.s b/test/ELF/merge-string-empty.s index 0b82ce700a2c..dc6635c96123 100644 --- a/test/ELF/merge-string-empty.s +++ b/test/ELF/merge-string-empty.s @@ -1,8 +1,8 @@ +// REQUIRES: x86 // Ensure that a mergeable string with size 0 does not cause any issue. -// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: ld.lld %t.o -o %t +// RUN: ld.lld %t.o -o /dev/null .globl _start, s .section .rodata.str1.1,"aMS",@progbits,1 diff --git a/test/ELF/merge-string-error.s b/test/ELF/merge-string-error.s index 78895cecca9c..70a361b6ccde 100644 --- a/test/ELF/merge-string-error.s +++ b/test/ELF/merge-string-error.s @@ -1,6 +1,6 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s .section .rodata.str1.1,"aMS",@progbits,1 .asciz "abc" diff --git a/test/ELF/merge-string-no-null.s b/test/ELF/merge-string-no-null.s index fd3f5073810a..ea433fec7d46 100644 --- a/test/ELF/merge-string-no-null.s +++ b/test/ELF/merge-string-no-null.s @@ -1,6 +1,6 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s .section .rodata.str1.1,"aMS",@progbits,1 .ascii "abc" diff --git a/test/ELF/merge-string.s b/test/ELF/merge-string.s index d284d0ab523c..065e8003840a 100644 --- a/test/ELF/merge-string.s +++ b/test/ELF/merge-string.s @@ -28,8 +28,8 @@ zed: // CHECK-NEXT: SHF_MERGE // CHECK-NEXT: SHF_STRINGS // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x1C8 -// CHECK-NEXT: Offset: 0x1C8 +// CHECK-NEXT: Address: 0x20D +// CHECK-NEXT: Offset: 0x20D // CHECK-NEXT: Size: 4 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -46,8 +46,8 @@ zed: // NOTAIL-NEXT: SHF_MERGE // NOTAIL-NEXT: SHF_STRINGS // NOTAIL-NEXT: ] -// NOTAIL-NEXT: Address: 0x1C8 -// NOTAIL-NEXT: Offset: 0x1C8 +// NOTAIL-NEXT: Address: 0x20D +// NOTAIL-NEXT: Offset: 0x20D // NOTAIL-NEXT: Size: 7 // NOTAIL-NEXT: Link: 0 // NOTAIL-NEXT: Info: 0 @@ -64,8 +64,8 @@ zed: // NOMERGE-NEXT: SHF_MERGE // NOMERGE-NEXT: SHF_STRINGS // NOMERGE-NEXT: ] -// NOMERGE-NEXT: Address: 0x1C8 -// NOMERGE-NEXT: Offset: 0x1C8 +// NOMERGE-NEXT: Address: 0x20D +// NOMERGE-NEXT: Offset: 0x20D // NOMERGE-NEXT: Size: 11 // NOMERGE-NEXT: Link: 0 // NOMERGE-NEXT: Info: 0 @@ -82,8 +82,8 @@ zed: // CHECK-NEXT: SHF_MERGE // CHECK-NEXT: SHF_STRINGS // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x1CC -// CHECK-NEXT: Offset: 0x1CC +// CHECK-NEXT: Address: 0x212 +// CHECK-NEXT: Offset: 0x212 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 @@ -95,11 +95,11 @@ zed: // CHECK: Name: bar -// CHECK-NEXT: Value: 0x1C9 +// CHECK-NEXT: Value: 0x20E // CHECK: Name: foo -// CHECK-NEXT: Value: 0x1C8 +// CHECK-NEXT: Value: 0x20D // CHECK: Name: zed -// CHECK-NEXT: Value: 0x1CC +// CHECK-NEXT: Value: 0x212 // CHECK-NEXT: Size: 0 diff --git a/test/ELF/merge-sym.s b/test/ELF/merge-sym.s index 4a4e9824a0de..89becc85531c 100644 --- a/test/ELF/merge-sym.s +++ b/test/ELF/merge-sym.s @@ -15,7 +15,7 @@ foo: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_MERGE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x1C8 +// CHECK-NEXT: Address: 0x210 // CHECK: Name: foo -// CHECK-NEXT: Value: 0x1CA +// CHECK-NEXT: Value: 0x212 diff --git a/test/ELF/merge-to-non-alloc.s b/test/ELF/merge-to-non-alloc.s new file mode 100644 index 000000000000..86f6f260814b --- /dev/null +++ b/test/ELF/merge-to-non-alloc.s @@ -0,0 +1,33 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-readobj -s -section-data -t %t.so | FileCheck %s + +// CHECK: Name: .bar +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: ] +// CHECK-NEXT: Address: +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: 16 +// CHECK-NEXT: Link: +// CHECK-NEXT: Info: +// CHECK-NEXT: AddressAlignment: +// CHECK-NEXT: EntrySize: +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 10020000 00000000 18020000 00000000 | +// CHECK-NEXT: ) + +// CHECK: Name: foo +// CHECK-NEXT: Value: 0x210 + + .section .foo,"aM",@progbits,4 + .align 4 + .global foo + .hidden foo +foo: + .long 0x42 + + .section .bar + .quad foo + .quad foo + 8 diff --git a/test/ELF/mips-26-mask.s b/test/ELF/mips-26-mask.s index 4cf56cfe338c..874d5c4b2338 100644 --- a/test/ELF/mips-26-mask.s +++ b/test/ELF/mips-26-mask.s @@ -1,11 +1,10 @@ +# REQUIRES: mips # Check reading/writing implicit addend for R_MIPS_26 relocation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld %t.o -o %t.exe # RUN: llvm-objdump -d %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Disassembly of section .text: # CHECK: __start: # CHECK-NEXT: 20000: 0e 00 80 00 jal 134348800 diff --git a/test/ELF/mips-26-n32-n64.s b/test/ELF/mips-26-n32-n64.s index 2e24873332a7..92f533152da3 100644 --- a/test/ELF/mips-26-n32-n64.s +++ b/test/ELF/mips-26-n32-n64.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_26 relocation handling in case of N64 ABIs. # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ @@ -5,9 +6,11 @@ # RUN: ld.lld %t-so.o -shared -o %t.so # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t.o # RUN: ld.lld %t.o %t.so -o %t.exe -# RUN: llvm-objdump -d %t.exe | FileCheck %s +# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=CHECK,DEFAULT +# RUN: ld.lld %t-so.o -shared -o %t.so -z hazardplt +# RUN: ld.lld %t.o %t.so -o %t.exe -z hazardplt +# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=CHECK,HAZARDPLT -# REQUIRES: mips # CHECK: Disassembly of section .text: # CHECK-NEXT: __start: @@ -21,11 +24,13 @@ # CHECK-NEXT: 2001c: 03 0e c0 23 subu $24, $24, $14 # CHECK-NEXT: 20020: 03 e0 78 25 move $15, $ra # CHECK-NEXT: 20024: 00 18 c0 c2 srl $24, $24, 3 -# CHECK-NEXT: 20028: 03 20 f8 09 jalr $25 +# DEFAULT: 20028: 03 20 f8 09 jalr $25 +# HAZARDPLT: 20028: 03 20 fc 09 jalr.hb $25 # CHECK-NEXT: 2002c: 27 18 ff fe addiu $24, $24, -2 # CHECK-NEXT: 20030: 3c 0f 00 03 lui $15, 3 # CHECK-NEXT: 20034: 8d f9 00 18 lw $25, 24($15) -# CHECK-NEXT: 20038: 03 20 00 08 jr $25 +# DEFAULT: 20038: 03 20 00 08 jr $25 +# HAZARDPLT: 20038: 03 20 04 08 jr.hb $25 # CHECK-NEXT: 2003c: 25 f8 00 18 addiu $24, $15, 24 .text diff --git a/test/ELF/mips-26.s b/test/ELF/mips-26.s index 749920b88c8b..882129b1fa9e 100644 --- a/test/ELF/mips-26.s +++ b/test/ELF/mips-26.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_26 relocation handling. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t1.o @@ -9,8 +10,6 @@ # RUN: llvm-readobj -dynamic-table -s -r -mips-plt-got %t.exe \ # RUN: | FileCheck -check-prefix=REL %s -# REQUIRES: mips - # CHECK: Disassembly of section .text: # CHECK-NEXT: bar: # CHECK-NEXT: 20000: 0c 00 80 06 jal 131096 <loc> diff --git a/test/ELF/mips-32.s b/test/ELF/mips-32.s index ef97afcc0313..7efcfcd65167 100644 --- a/test/ELF/mips-32.s +++ b/test/ELF/mips-32.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_32 relocation calculation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t-be.o @@ -14,8 +15,6 @@ # RUN: llvm-readobj -r -dynamic-table -mips-plt-got %t-el.so \ # RUN: | FileCheck -check-prefix=REL %s -# REQUIRES: mips - .globl __start __start: nop diff --git a/test/ELF/mips-64-disp.s b/test/ELF/mips-64-disp.s index 29b62dcd050a..5d5049c4cae7 100644 --- a/test/ELF/mips-64-disp.s +++ b/test/ELF/mips-64-disp.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_GOT_DISP relocations against various kind of symbols. # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ @@ -8,8 +9,6 @@ # RUN: llvm-objdump -d -t %t.exe | FileCheck %s # RUN: llvm-readobj -r -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s -# REQUIRES: mips - # CHECK: __start: # CHECK-NEXT: 20000: 24 42 80 40 addiu $2, $2, -32704 # CHECK-NEXT: 20004: 24 42 80 20 addiu $2, $2, -32736 diff --git a/test/ELF/mips-64-got-overflow.s b/test/ELF/mips-64-got-overflow.s new file mode 100644 index 000000000000..5de71b1b366e --- /dev/null +++ b/test/ELF/mips-64-got-overflow.s @@ -0,0 +1,80 @@ +# REQUIRES: mips +# Check the primary GOT cannot be made to overflow + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ +# RUN: %p/Inputs/mips-64-got-load.s -o %t1.so.o +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t2.so.o +# RUN: ld.lld -shared -mips-got-size 32 %t1.so.o %t2.so.o -o %t-sgot.so +# RUN: ld.lld -shared -mips-got-size 24 %t1.so.o %t2.so.o -o %t-mgot.so +# RUN: llvm-readobj -r -dt -mips-plt-got %t-sgot.so | FileCheck -check-prefix=SGOT %s +# RUN: llvm-readobj -r -dt -mips-plt-got %t-mgot.so | FileCheck -check-prefix=MGOT %s + +# SGOT: Primary GOT { +# SGOT-NEXT: Canonical gp value: 0x27FF0 +# SGOT-NEXT: Reserved entries [ +# SGOT-NEXT: Entry { +# SGOT-NEXT: Address: +# SGOT-NEXT: Access: -32752 +# SGOT-NEXT: Initial: 0x0 +# SGOT-NEXT: Purpose: Lazy resolver +# SGOT-NEXT: } +# SGOT-NEXT: Entry { +# SGOT-NEXT: Address: +# SGOT-NEXT: Access: -32744 +# SGOT-NEXT: Initial: 0x80000000 +# SGOT-NEXT: Purpose: Module pointer (GNU extension) +# SGOT-NEXT: } +# SGOT-NEXT: ] +# SGOT-NEXT: Local entries [ +# SGOT-NEXT: Entry { +# SGOT-NEXT: Address: +# SGOT-NEXT: Access: -32736 +# SGOT-NEXT: Initial: 0x20020 +# SGOT-NEXT: } +# SGOT-NEXT: Entry { +# SGOT-NEXT: Address: +# SGOT-NEXT: Access: -32728 +# SGOT-NEXT: Initial: 0x20030 +# SGOT-NEXT: } +# SGOT-NEXT: ] +# SGOT-NEXT: Global entries [ +# SGOT-NEXT: ] +# SGOT-NEXT: Number of TLS and multi-GOT entries: 0 +# SGOT-NEXT: } + +# MGOT: Primary GOT { +# MGOT-NEXT: Canonical gp value: 0x27FF0 +# MGOT-NEXT: Reserved entries [ +# MGOT-NEXT: Entry { +# MGOT-NEXT: Address: +# MGOT-NEXT: Access: -32752 +# MGOT-NEXT: Initial: 0x0 +# MGOT-NEXT: Purpose: Lazy resolver +# MGOT-NEXT: } +# MGOT-NEXT: Entry { +# MGOT-NEXT: Address: +# MGOT-NEXT: Access: -32744 +# MGOT-NEXT: Initial: 0x80000000 +# MGOT-NEXT: Purpose: Module pointer (GNU extension) +# MGOT-NEXT: } +# MGOT-NEXT: ] +# MGOT-NEXT: Local entries [ +# MGOT-NEXT: Entry { +# MGOT-NEXT: Address: +# MGOT-NEXT: Access: -32736 +# MGOT-NEXT: Initial: 0x20020 +# MGOT-NEXT: } +# MGOT-NEXT: ] +# MGOT-NEXT: Global entries [ +# MGOT-NEXT: ] +# MGOT-NEXT: Number of TLS and multi-GOT entries: 1 +# MGOT-NEXT: } + + .text + .global foo2 +foo2: + ld $2, %got_disp(local2)($gp) + + .bss +local2: + .word 0 diff --git a/test/ELF/mips-64-got.s b/test/ELF/mips-64-got.s index f2b4d5b07ab5..e1b1f3475470 100644 --- a/test/ELF/mips-64-got.s +++ b/test/ELF/mips-64-got.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check MIPS N64 ABI GOT relocations # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ @@ -8,8 +9,6 @@ # RUN: llvm-objdump -d -t %t.exe | FileCheck %s # RUN: llvm-readobj -r -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s -# REQUIRES: mips - # CHECK: __start: # CHECK-NEXT: 20000: df 82 80 20 ld $2, -32736($gp) diff --git a/test/ELF/mips-64-gprel-so.s b/test/ELF/mips-64-gprel-so.s index 437238ef5f26..d741dd907137 100644 --- a/test/ELF/mips-64-gprel-so.s +++ b/test/ELF/mips-64-gprel-so.s @@ -1,11 +1,10 @@ +# REQUIRES: mips # Check setup of GP relative offsets in a function's prologue. # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t.o # RUN: ld.lld %t.o -shared -o %t.so # RUN: llvm-objdump -d -t %t.so | FileCheck %s -# REQUIRES: mips - # CHECK: Disassembly of section .text: # CHECK-NEXT: foo: # CHECK-NEXT: 10000: 3c 1c 00 01 lui $gp, 1 diff --git a/test/ELF/mips-64-rels.s b/test/ELF/mips-64-rels.s index 78671554b1cb..e641b326ce56 100644 --- a/test/ELF/mips-64-rels.s +++ b/test/ELF/mips-64-rels.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check handling multiple MIPS N64 ABI relocations packed # into the single relocation record. @@ -6,8 +7,6 @@ # RUN: llvm-objdump -d -s -t %t.exe | FileCheck %s # RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s -# REQUIRES: mips - # CHECK: __start: # CHECK-NEXT: 20000: 3c 1c 00 01 lui $gp, 1 # ^-- 0x20000 - 0x37ff0 diff --git a/test/ELF/mips-64.s b/test/ELF/mips-64.s index dd8a58d604c5..e37b75c070ec 100644 --- a/test/ELF/mips-64.s +++ b/test/ELF/mips-64.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_64 relocation calculation. # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t.o @@ -5,8 +6,6 @@ # RUN: llvm-objdump -t %t.so | FileCheck -check-prefix=SYM %s # RUN: llvm-readobj -r -dynamic-table -mips-plt-got %t.so | FileCheck %s -# REQUIRES: mips - .global __start __start: nop @@ -30,17 +29,16 @@ v2: # SYM: 00020008 g .data 00000008 v2 # CHECK: Relocations [ -# CHECK-NEXT: Section (7) .rela.dyn { -# CHECK-NEXT: 0x20010 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE - 0x20000 -# ^-- v1 -# CHECK-NEXT: 0x20008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE v2 0x8 +# CHECK-NEXT: Section (7) .rel.dyn { +# CHECK-NEXT: 0x20010 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE - 0x0 +# CHECK-NEXT: 0x20008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE v2 0x0 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK: DynamicSection [ # CHECK: Tag Type Name/Value -# CHECK: 0x0000000000000008 RELASZ 48 (bytes) -# CHECK: 0x0000000000000009 RELAENT 24 (bytes) +# CHECK: 0x0000000000000012 RELSZ 32 (bytes) +# CHECK: 0x0000000000000013 RELENT 16 (bytes) # CHECK: Primary GOT { # CHECK-NEXT: Canonical gp value: diff --git a/test/ELF/mips-abs-got.s b/test/ELF/mips-abs-got.s new file mode 100644 index 000000000000..4964c8558325 --- /dev/null +++ b/test/ELF/mips-abs-got.s @@ -0,0 +1,36 @@ +# REQUIRES: mips + +# Check GOT relocations against absolute symbols. + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux -o %t.o %s +# RUN: echo "SECTIONS { \ +# RUN: zero = 0; foo = 0x11004; bar = 0x22000; }" > %t.script +# RUN: ld.lld --script %t.script -o %t.exe %t.o +# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck %s + +# CHECK: Static GOT { +# CHECK: Local entries [ +# CHECK-NEXT: Entry { +# CHECK-NEXT: Address: +# CHECK-NEXT: Access: -32736 +# CHECK-NEXT: Initial: 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: Entry { +# CHECK-NEXT: Address: +# CHECK-NEXT: Access: -32728 +# CHECK-NEXT: Initial: 0x10000 +# CHECK-NEXT: } +# CHECK-NEXT: Entry { +# CHECK-NEXT: Address: +# CHECK-NEXT: Access: -32720 +# CHECK-NEXT: Initial: 0x30000 +# CHECK-NEXT: } +# CHECK-NEXT: ] +# CHECK-NEXT: } + + .text + nop + .reloc 0, R_MIPS_GOT_PAGE, 0 + ld $v0, %got_page(zero)($gp) + ld $v0, %got_page(foo)($gp) + ld $v0, %got_page(bar+0x10008)($gp) diff --git a/test/ELF/mips-align-err.s b/test/ELF/mips-align-err.s index a3bf134e4386..8bf01dc5c382 100644 --- a/test/ELF/mips-align-err.s +++ b/test/ELF/mips-align-err.s @@ -3,7 +3,7 @@ # RUN: -mcpu=mips32r6 # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ # RUN: -mcpu=mips32r6 %S/Inputs/mips-align-err.s -o %t2.o -# RUN: not ld.lld %t.o %t2.o -o %t.exe 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o %t2.o -o /dev/null 2>&1 | FileCheck %s # CHECK: {{.*}}:(.text+0x1): improper alignment for relocation R_MIPS_PC16: 0xB is not aligned to 4 bytes .globl __start diff --git a/test/ELF/mips-call-hilo.s b/test/ELF/mips-call-hilo.s index 2504612f9e34..9c7633a8464d 100644 --- a/test/ELF/mips-call-hilo.s +++ b/test/ELF/mips-call-hilo.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_CALL_HI16 / R_MIPS_CALL_LO16 relocations calculation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o @@ -5,8 +6,6 @@ # RUN: llvm-objdump -d %t.so | FileCheck %s # RUN: llvm-readobj -r -mips-plt-got %t.so | FileCheck -check-prefix=GOT %s -# REQUIRES: mips - # CHECK: Disassembly of section .text: # CHECK-NEXT: foo: # CHECK-NEXT: 10000: 3c 02 00 00 lui $2, 0 diff --git a/test/ELF/mips-call16.s b/test/ELF/mips-call16.s index 4a5d0bf3f871..7b3da0c41ff0 100644 --- a/test/ELF/mips-call16.s +++ b/test/ELF/mips-call16.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_CALL16 relocation calculation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o @@ -6,8 +7,6 @@ # RUN: llvm-readobj -mips-plt-got -symbols %t.exe \ # RUN: | FileCheck -check-prefix=GOT %s -# REQUIRES: mips - .text .globl __start __start: diff --git a/test/ELF/mips-dynamic.s b/test/ELF/mips-dynamic.s index 15afb028c1f1..ebc2625970cb 100644 --- a/test/ELF/mips-dynamic.s +++ b/test/ELF/mips-dynamic.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check MIPS specific .dynamic section entries. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o @@ -6,7 +7,11 @@ # RUN: ld.lld %t.o %td.so -o %t.exe # RUN: llvm-readobj -sections -dynamic-table %t.exe \ -# RUN: | FileCheck -check-prefix=EXE %s +# RUN: | FileCheck -check-prefixes=EXE,NOPIE %s + +# RUN: ld.lld -pie %t.o %td.so -o %t.so +# RUN: llvm-readobj -sections -dyn-symbols -dynamic-table %t.so \ +# RUN: | FileCheck -check-prefixes=EXE,PIE %s # RUN: ld.lld %t.o --image-base=0x123000 %td.so -o %t.exe # RUN: llvm-readobj -sections -dynamic-table %t.exe \ @@ -16,8 +21,6 @@ # RUN: llvm-readobj -sections -dyn-symbols -dynamic-table %t.so \ # RUN: | FileCheck -check-prefix=DSO %s -# REQUIRES: mips - # EXE: Sections [ # EXE: Name: .dynamic # EXE-NEXT: Type: SHT_DYNAMIC @@ -44,17 +47,35 @@ # EXE-NEXT: Offset: # EXE-NEXT: Size: 8 # EXE: ] -# EXE: DynamicSection [ -# EXE-NEXT: Tag Type Name/Value -# EXE-DAG: 0x00000003 PLTGOT [[GOTADDR]] -# EXE-DAG: 0x70000001 MIPS_RLD_VERSION 1 -# EXE-DAG: 0x70000005 MIPS_FLAGS NOTPOT -# EXE-DAG: 0x70000006 MIPS_BASE_ADDRESS 0x10000 -# EXE-DAG: 0x7000000A MIPS_LOCAL_GOTNO 2 -# EXE-DAG: 0x70000011 MIPS_SYMTABNO 2 -# EXE-DAG: 0x70000013 MIPS_GOTSYM 0x2 -# EXE-DAG: 0x70000016 MIPS_RLD_MAP [[RLDMAPADDR]] -# EXE: ] + +# PIE: DynamicSection [ +# PIE-NEXT: Tag Type Name/Value +# PIE: 0x00000004 HASH 0x{{[0-9A-F]+}} +# PIE-NEXT: 0x70000001 MIPS_RLD_VERSION 1 +# PIE-NEXT: 0x70000005 MIPS_FLAGS NOTPOT +# PIE-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x0 +# PIE-NEXT: 0x70000011 MIPS_SYMTABNO 2 +# PIE-NEXT: 0x7000000A MIPS_LOCAL_GOTNO 2 +# PIE-NEXT: 0x70000013 MIPS_GOTSYM 0x2 +# PIE-NEXT: 0x00000003 PLTGOT [[GOTADDR]] +# PIE-NEXT: 0x70000035 MIPS_RLD_MAP_REL 0x{{[0-9A-F]+}} +# PIE-NEXT: 0x00000000 NULL 0x0 +# PIE-NEXT: ] + +# NOPIE: DynamicSection [ +# NOPIE-NEXT: Tag Type Name/Value +# NOPIE: 0x00000004 HASH 0x{{[0-9A-F]+}} +# NOPIE-NEXT: 0x70000001 MIPS_RLD_VERSION 1 +# NOPIE-NEXT: 0x70000005 MIPS_FLAGS NOTPOT +# NOPIE-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x10000 +# NOPIE-NEXT: 0x70000011 MIPS_SYMTABNO 2 +# NOPIE-NEXT: 0x7000000A MIPS_LOCAL_GOTNO 2 +# NOPIE-NEXT: 0x70000013 MIPS_GOTSYM 0x2 +# NOPIE-NEXT: 0x00000003 PLTGOT [[GOTADDR]] +# NOPIE-NEXT: 0x70000016 MIPS_RLD_MAP [[RLDMAPADDR]] +# NOPIE-NEXT: 0x70000035 MIPS_RLD_MAP_REL 0x{{[0-9A-F]+}} +# NOPIE-NEXT: 0x00000000 NULL 0x0 +# NOPIE-NEXT: ] # IMAGE_BASE: 0x70000006 MIPS_BASE_ADDRESS 0x123000 diff --git a/test/ELF/mips-dynsym-sort.s b/test/ELF/mips-dynsym-sort.s index 7d4559cf9335..d1b935b63cff 100644 --- a/test/ELF/mips-dynsym-sort.s +++ b/test/ELF/mips-dynsym-sort.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check the order of dynamic symbols for the MIPS target. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t-be.o @@ -8,8 +9,6 @@ # RUN: ld.lld -shared %t-el.o -o %t-el.so # RUN: llvm-readobj -symbols -dyn-symbols %t-el.so | FileCheck %s -# REQUIRES: mips - .data .globl v1,v2,v3 v1: diff --git a/test/ELF/mips-elf-abi.s b/test/ELF/mips-elf-abi.s new file mode 100644 index 000000000000..86c02f34f6a5 --- /dev/null +++ b/test/ELF/mips-elf-abi.s @@ -0,0 +1,22 @@ +# REQUIRES: mips +# Check EI_ABIVERSION flags + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o +# RUN: ld.lld -shared -o %t.so %t.o +# RUN: llvm-readobj -h %t.so | FileCheck -check-prefix=DSO %s +# RUN: ld.lld -o %t.exe %t.o +# RUN: llvm-readobj -h %t.exe | FileCheck -check-prefix=EXE %s +# RUN: ld.lld -pie -o %t.pie %t.o +# RUN: llvm-readobj -h %t.pie | FileCheck -check-prefix=PIE %s +# RUN: ld.lld -r -o %t.rel %t.o +# RUN: llvm-readobj -h %t.rel | FileCheck -check-prefix=REL %s + +# DSO: ABIVersion: 0 +# EXE: ABIVersion: 1 +# PIE: ABIVersion: 0 +# REL: ABIVersion: 0 + + .global __start + .text +__start: + nop diff --git a/test/ELF/mips-elf-flags-err.s b/test/ELF/mips-elf-flags-err.s index e1ac8c5e015e..caa33ab28c7a 100644 --- a/test/ELF/mips-elf-flags-err.s +++ b/test/ELF/mips-elf-flags-err.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check MIPS ELF ISA flag calculation if input files have different ISAs. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ @@ -24,14 +25,6 @@ # RUN: not ld.lld %t1.o %t2.o -o %t.exe 2>&1 \ # RUN: | FileCheck -check-prefix=R6OCTEON %s -# Check that lld does not allow to link incompatible floating point ABI. - -# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ -# RUN: -mcpu=mips32 %S/Inputs/mips-dynamic.s -o %t1.o -# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ -# RUN: -mcpu=mips32 -mattr=+fp64 %s -o %t2.o -# RUN: not ld.lld %t1.o %t2.o -o %t.exe 2>&1 | FileCheck -check-prefix=FPABI %s - # Check that lld take in account EF_MIPS_MACH_XXX ISA flags # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ @@ -41,24 +34,6 @@ # RUN: ld.lld %t1.o %t2.o -o %t.exe # RUN: llvm-readobj -h %t.exe | FileCheck -check-prefix=OCTEON %s -# Check that lld does not allow to link incompatible ABIs. - -# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ -# RUN: -target-abi n32 %S/Inputs/mips-dynamic.s -o %t1.o -# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ -# RUN: -target-abi o32 %s -o %t2.o -# RUN: not ld.lld %t1.o %t2.o -o %t.exe 2>&1 | FileCheck -check-prefix=N32O32 %s - -# Check that lld does not allow to link modules with incompatible NAN flags. - -# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ -# RUN: -mattr=+nan2008 %S/Inputs/mips-dynamic.s -o %t1.o -# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ -# RUN: %s -o %t2.o -# RUN: not ld.lld %t1.o %t2.o -o %t.exe 2>&1 | FileCheck -check-prefix=NAN %s - -# REQUIRES: mips - .option pic0 .text .global __start @@ -79,14 +54,8 @@ __start: # R6OCTEON-NEXT: >>> {{.+}}mips-elf-flags-err.s.tmp1.o: mips64r6 # R6OCTEON-NEXT: >>> {{.+}}mips-elf-flags-err.s.tmp2.o: mips64r2 (octeon) -# FPABI: target floating point ABI '-mdouble-float' is incompatible with '-mgp32 -mfp64': {{.*}}mips-elf-flags-err.s.tmp2.o - # OCTEON: Flags [ # OCTEON-NEXT: EF_MIPS_ARCH_64R2 # OCTEON-NEXT: EF_MIPS_CPIC # OCTEON-NEXT: EF_MIPS_MACH_OCTEON # OCTEON: ] - -# N32O32: error: {{.*}}mips-elf-flags-err.s.tmp2.o is incompatible with {{.*}}mips-elf-flags-err.s.tmp1.o - -# NAN: target -mnan=2008 is incompatible with -mnan=legacy: {{.*}}mips-elf-flags-err.s.tmp2.o diff --git a/test/ELF/mips-elf-flags-err.test b/test/ELF/mips-elf-flags-err.test new file mode 100644 index 000000000000..12fd418274ce --- /dev/null +++ b/test/ELF/mips-elf-flags-err.test @@ -0,0 +1,89 @@ +# REQUIRES: mips +# +# Check warning and errors in case of input +# files with incompatible ELF header flags. + +# RUN: yaml2obj -docnum 1 %s -o %t-n64.o +# RUN: yaml2obj -docnum 2 %s -o %t-o64.o +# RUN: yaml2obj -docnum 3 %s -o %t-n32.o +# RUN: yaml2obj -docnum 4 %s -o %t-o32.o +# RUN: yaml2obj -docnum 5 %s -o %t-eabi64.o +# RUN: yaml2obj -docnum 6 %s -o %t-eabi32.o + +# RUN: not ld.lld %t-n64.o %t-eabi64.o -shared -o /dev/null 2>&1 \ +# RUN: | FileCheck -check-prefixes=MM64,N64EABI64 %s +# +# RUN: not ld.lld %t-n64.o %t-o64.o -shared -o /dev/null 2>&1 \ +# RUN: | FileCheck -check-prefixes=MM64,N64O64 %s + +# RUN: not ld.lld %t-o32.o %t-eabi32.o -shared -o /dev/null 2>&1 \ +# RUN: | FileCheck -check-prefixes=O32EABI32,FP64,CPIC1 %s + +# RUN: not ld.lld %t-eabi32.o %t-o32.o -shared -o /dev/null 2>&1 \ +# RUN: | FileCheck -check-prefix=CPIC2 %s + +# MM64: {{.*}}n64.o: microMIPS 64-bit is not supported + +# N64EABI64: {{.*}}eabi64.o: ABI 'eabi64' is incompatible with target ABI 'n64' +# N64O64: {{.*}}o64.o: ABI 'o64' is incompatible with target ABI 'n64' +# O32EABI32: {{.*}}eabi32.o: ABI 'eabi32' is incompatible with target ABI 'o32' + +# NAN: {{.*}}o32.o: -mnan=legacy is incompatible with target -mnan=2008 +# FP64: {{.*}}eabi32.o: -mfp64 is incompatible with target -mfp32 + +# CPIC1: {{.*}}tmp-eabi32.o: linking non-abicalls code with abicalls code {{.*}}o32.o +# CPIC2: {{.*}}tmp-o32.o: linking abicalls code with non-abicalls code {{.*}}eabi32.o + +# n64.o +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64, EF_MIPS_MICROMIPS ] + +# o64.o +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ABI_O64, EF_MIPS_ARCH_64 ] + +# n32.o +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64, EF_MIPS_ABI2, EF_MIPS_NAN2008 ] + +# o32.o +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_32, EF_MIPS_ABI_O32, EF_MIPS_CPIC ] + +# eabi64.o +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64, EF_MIPS_ABI_EABI64 ] + +# eabi32.o +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_32, EF_MIPS_ABI_EABI32, EF_MIPS_FP64 ] diff --git a/test/ELF/mips-elf-flags.s b/test/ELF/mips-elf-flags.s index d2b3d929e2f5..68f4cc3008e4 100644 --- a/test/ELF/mips-elf-flags.s +++ b/test/ELF/mips-elf-flags.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check generation of MIPS specific ELF header flags. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ @@ -41,8 +42,6 @@ # RUN: ld.lld %t.o %t-mm.o -o %t.exe # RUN: llvm-readobj -h -mips-abi-flags %t.exe | FileCheck -check-prefix=MICRO %s -# REQUIRES: mips - .text .globl __start __start: diff --git a/test/ELF/mips-fp-flags-err.test b/test/ELF/mips-fp-flags-err.test new file mode 100644 index 000000000000..68a290c2caa1 --- /dev/null +++ b/test/ELF/mips-fp-flags-err.test @@ -0,0 +1,162 @@ +# REQUIRES: mips +# +# Check warning and errors in case of input +# files with incompatible floating point ABI flags. + +# RUN: yaml2obj -docnum 1 %s -o %t-dbl.o +# RUN: yaml2obj -docnum 2 %s -o %t-sgl.o +# RUN: yaml2obj -docnum 3 %s -o %t-soft.o +# RUN: yaml2obj -docnum 4 %s -o %t-fp64.o +# RUN: yaml2obj -docnum 5 %s -o %t-fp64old.o +# RUN: yaml2obj -docnum 6 %s -o %t-fp64a.o +# RUN: yaml2obj -docnum 7 %s -o %t-fpxx.o + +# RUN: not ld.lld %t-dbl.o %t-fp64.o -shared -o /dev/null 2>&1 \ +# RUN: | FileCheck -check-prefixes=DBLFP64 %s + +# RUN: not ld.lld %t-sgl.o %t-fp64old.o -shared -o /dev/null 2>&1 \ +# RUN: | FileCheck -check-prefixes=SGLFP64OLD %s + +# RUN: not ld.lld %t-soft.o %t-fp64a.o -shared -o /dev/null 2>&1 \ +# RUN: | FileCheck -check-prefixes=SOFTFP64A %s + +# RUN: not ld.lld %t-sgl.o %t-fpxx.o -shared -o /dev/null 2>&1 \ +# RUN: | FileCheck -check-prefixes=SGLFPXX %s + +# DBLFP64: {{.*}}fp64.o: floating point ABI '-mgp32 -mfp64' is incompatible with target floating point ABI '-mdouble-float' +# SGLFP64OLD: {{.*}}fp64old.o: floating point ABI '-mgp32 -mfp64 (old)' is incompatible with target floating point ABI '-msingle-float' +# SOFTFP64A: {{.*}}fp64a.o: floating point ABI '-mgp32 -mfp64 -mno-odd-spreg' is incompatible with target floating point ABI '-msoft-float' +# SGLFPXX: {{.*}}fpxx.o: floating point ABI '-mfpxx' is incompatible with target floating point ABI '-msingle-float' + +# dbl.o +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64 ] + +Sections: +- Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + ISA: MIPS64 + ASEs: [] + FpABI: FP_DOUBLE + GPRSize: REG_64 + CPR1Size: REG_64 + CPR2Size: REG_NONE + +# sgl.o +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64 ] + +Sections: +- Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + ISA: MIPS64 + ASEs: [] + FpABI: FP_SINGLE + GPRSize: REG_64 + CPR1Size: REG_64 + CPR2Size: REG_NONE + +# soft.o +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64 ] + +Sections: +- Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + ISA: MIPS64 + ASEs: [] + FpABI: FP_SOFT + GPRSize: REG_64 + CPR1Size: REG_64 + CPR2Size: REG_NONE + +# fp64.o +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64 ] + +Sections: +- Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + ISA: MIPS64 + ASEs: [] + FpABI: FP_64 + GPRSize: REG_64 + CPR1Size: REG_64 + CPR2Size: REG_NONE + +# fp64old.o +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64 ] + +Sections: +- Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + ISA: MIPS64 + ASEs: [] + FpABI: FP_OLD_64 + GPRSize: REG_64 + CPR1Size: REG_64 + CPR2Size: REG_NONE + +# fp64a.o +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64 ] + +Sections: +- Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + ISA: MIPS64 + ASEs: [] + FpABI: FP_64A + GPRSize: REG_64 + CPR1Size: REG_64 + CPR2Size: REG_NONE + +# fpxx.o +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_64 ] + +Sections: +- Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + ISA: MIPS64 + ASEs: [] + FpABI: FP_XX + GPRSize: REG_64 + CPR1Size: REG_64 + CPR2Size: REG_NONE diff --git a/test/ELF/mips-gnu-hash.s b/test/ELF/mips-gnu-hash.s index 288d54043fc1..e66bc893a076 100644 --- a/test/ELF/mips-gnu-hash.s +++ b/test/ELF/mips-gnu-hash.s @@ -1,15 +1,14 @@ +# REQUIRES: mips # Shouldn't allow the GNU hash style to be selected with the MIPS target. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t-be.o -# RUN: not ld.lld -shared -hash-style=gnu %t-be.o -o %t-be.so 2>&1 | FileCheck %s +# RUN: not ld.lld -shared -hash-style=gnu %t-be.o -o /dev/null 2>&1 | FileCheck %s # RUN: llvm-mc -filetype=obj -triple=mipsel-unknown-linux %s -o %t-el.o -# RUN: not ld.lld -shared -hash-style=gnu %t-el.o -o %t-el.so 2>&1 | FileCheck %s +# RUN: not ld.lld -shared -hash-style=gnu %t-el.o -o /dev/null 2>&1 | FileCheck %s # CHECK: the .gnu.hash section is not compatible with the MIPS target. -# REQUIRES: mips - .globl __start __start: nop diff --git a/test/ELF/mips-got-and-copy.s b/test/ELF/mips-got-and-copy.s index 4e3ca5f2804a..f4640bf30dfa 100644 --- a/test/ELF/mips-got-and-copy.s +++ b/test/ELF/mips-got-and-copy.s @@ -23,13 +23,17 @@ # CHECK-NEXT: Reserved entries [ # CHECK: ] # CHECK-NEXT: Local entries [ +# CHECK-NEXT: ] +# CHECK-NEXT: Global entries [ # CHECK-NEXT: Entry { # CHECK-NEXT: Address: # CHECK-NEXT: Access: -32744 # CHECK-NEXT: Initial: 0x[[DATA0]] +# CHECK-NEXT: Value: 0x[[DATA0]] +# CHECK-NEXT: Type: Object +# CHECK-NEXT: Section: .bss +# CHECK-NEXT: Name: data0@ # CHECK-NEXT: } -# CHECK-NEXT: ] -# CHECK-NEXT: Global entries [ # CHECK-NEXT: Entry { # CHECK-NEXT: Address: # CHECK-NEXT: Access: -32740 diff --git a/test/ELF/mips-got-extsym.s b/test/ELF/mips-got-extsym.s index 3af4ba07b234..ea57d77a0353 100644 --- a/test/ELF/mips-got-extsym.s +++ b/test/ELF/mips-got-extsym.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check creation of GOT entries for global symbols in case of executable # file linking. Symbols defined in DSO should get entries in the global part # of the GOT. Symbols defined in the executable itself should get local GOT @@ -10,8 +11,6 @@ # RUN: ld.lld %t.o %t.so -o %t.exe # RUN: llvm-readobj -dt -t -mips-plt-got %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Symbols [ # CHECK: Symbol { # CHECK: Name: _foo diff --git a/test/ELF/mips-got-hilo.s b/test/ELF/mips-got-hilo.s index fa7e752d9f91..1ae24f3472fe 100644 --- a/test/ELF/mips-got-hilo.s +++ b/test/ELF/mips-got-hilo.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_GOT_HI16 / R_MIPS_GOT_LO16 relocations calculation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o @@ -5,8 +6,6 @@ # RUN: llvm-objdump -d %t.so | FileCheck %s # RUN: llvm-readobj -r -mips-plt-got %t.so | FileCheck -check-prefix=GOT %s -# REQUIRES: mips - # CHECK: Disassembly of section .text: # CHECK-NEXT: foo: # CHECK-NEXT: 10000: 3c 02 00 00 lui $2, 0 diff --git a/test/ELF/mips-got-page-script.s b/test/ELF/mips-got-page-script.s index 056e4fda77c2..0ec19fc14ad4 100644 --- a/test/ELF/mips-got-page-script.s +++ b/test/ELF/mips-got-page-script.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check calculation of MIPS GOT page address entries number # when a linker script is provided. @@ -8,8 +9,6 @@ # RUN: ld.lld -shared --script %t.script -o %t.so %t.o # RUN: llvm-readobj -t -mips-plt-got %t.so | FileCheck %s -# REQUIRES: mips - # CHECK: Name: foo1 # CHECK-NEXT: Value: 0x10000 # CHECK: Name: foo2 diff --git a/test/ELF/mips-got-page.s b/test/ELF/mips-got-page.s index e2dc485ba661..46ddf4a7122c 100644 --- a/test/ELF/mips-got-page.s +++ b/test/ELF/mips-got-page.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check the case when small section (less that 0x10000 bytes) occupies # two adjacent 0xffff-bytes pages. We need to create two GOT entries # for R_MIPS_GOT_PAGE relocations. @@ -6,8 +7,6 @@ # RUN: ld.lld --section-start .rodata=0x27FFC -shared -o %t.so %t.o # RUN: llvm-readobj -t -mips-plt-got %t.so | FileCheck %s -# REQUIRES: mips - # CHECK: Name: bar # CHECK-NEXT: Value: 0x28000 # ^ page-address = (0x28000 + 0x8000) & ~0xffff = 0x30000 diff --git a/test/ELF/mips-got-redundant.s b/test/ELF/mips-got-redundant.s index b4c6a2b31a0e..24138ca19995 100644 --- a/test/ELF/mips-got-redundant.s +++ b/test/ELF/mips-got-redundant.s @@ -1,11 +1,10 @@ +# REQUIRES: mips # Check number of redundant entries in the local part of MIPS GOT. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld %t.o -shared -o %t.so # RUN: llvm-readobj -mips-plt-got %t.so | FileCheck %s -# REQUIRES: mips - # CHECK: Local entries [ # CHECK-NEXT: Entry { # CHECK-NEXT: Address: diff --git a/test/ELF/mips-got-relocs.s b/test/ELF/mips-got-relocs.s index 5b443e51938a..d085df06524a 100644 --- a/test/ELF/mips-got-relocs.s +++ b/test/ELF/mips-got-relocs.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_GOT16 relocation calculation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t-be.o @@ -30,8 +31,6 @@ # RUN: llvm-readobj -relocations %t-el.so | FileCheck -check-prefix=NORELOC %s # RUN: llvm-readobj -sections %t-el.so | FileCheck -check-prefix=SHFLAGS %s -# REQUIRES: mips - .text .globl __start __start: diff --git a/test/ELF/mips-got-script.s b/test/ELF/mips-got-script.s index da1858469863..6590c59e1cda 100644 --- a/test/ELF/mips-got-script.s +++ b/test/ELF/mips-got-script.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check number of got entries is adjusted for linker script-added space. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o @@ -5,10 +6,8 @@ # RUN: ld.lld %t.o -shared -o %t.so -T %t.script # RUN: llvm-readobj -mips-plt-got -dynamic-table %t.so | FileCheck %s -# REQUIRES: mips - -# CHECK: 0x7000000A MIPS_LOCAL_GOTNO 5 -# ^-- 2 * header + 3 local entries +# CHECK: 0x7000000A MIPS_LOCAL_GOTNO 4 +# ^-- 2 * header + 2 local entries # CHECK: Local entries [ # CHECK-NEXT: Entry { # CHECK-NEXT: Address: @@ -22,12 +21,6 @@ # CHECK-NEXT: Initial: 0x10000 # ^-- loc2 # CHECK-NEXT: } -# CHECK-NEXT: Entry { -# CHECK-NEXT: Address: -# CHECK-NEXT: Access: -32736 -# CHECK-NEXT: Initial: 0x20000 -# ^-- redundant -# CHECK-NEXT: } # CHECK-NEXT: ] .text diff --git a/test/ELF/mips-got-string.s b/test/ELF/mips-got-string.s index 598865c681f6..cfdd0daf68dd 100644 --- a/test/ELF/mips-got-string.s +++ b/test/ELF/mips-got-string.s @@ -1,14 +1,13 @@ +# REQUIRES: mips # Check R_MIPS_GOT16 relocation against merge section. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -o %t.o %s # RUN: ld.lld -shared -o %t.so %t.o # RUN: llvm-readobj -t -mips-plt-got %t.so | FileCheck %s -# REQUIRES: mips - # CHECK: Symbol { # CHECK: Name: $.str -# CHECK-NEXT: Value: 0xF4 +# CHECK-NEXT: Value: 0x1B1 # CHECK: } # CHECK: Local entries [ diff --git a/test/ELF/mips-got-weak.s b/test/ELF/mips-got-weak.s index e860bb482a2c..478e294f02f3 100644 --- a/test/ELF/mips-got-weak.s +++ b/test/ELF/mips-got-weak.s @@ -1,17 +1,16 @@ +# REQUIRES: mips # Check R_MIPS_GOT16 relocation against weak symbols. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld %t.o -shared -o %t1.so # RUN: llvm-readobj -r -dt -dynamic-table -mips-plt-got %t1.so \ -# RUN: | FileCheck -check-prefix=NOSYM %s +# RUN: | FileCheck -check-prefixes=CHECK,NOSYM %s # RUN: ld.lld %t.o -shared -Bsymbolic -o %t2.so # RUN: llvm-readobj -r -dt -dynamic-table -mips-plt-got %t2.so \ -# RUN: | FileCheck -check-prefix=SYM %s - -# REQUIRES: mips +# RUN: | FileCheck -check-prefixes=CHECK,SYM %s -# NOSYM: Relocations [ -# NOSYM-NEXT: ] +# CHECK: Relocations [ +# CHECK-NEXT: ] # NOSYM: Symbol { # NOSYM: Name: foo @@ -22,17 +21,19 @@ # NOSYM-NEXT: Other: 0 # NOSYM-NEXT: Section: .data # NOSYM-NEXT: } -# NOSYM-NEXT: Symbol { -# NOSYM-NEXT: Name: bar -# NOSYM-NEXT: Value: 0x0 -# NOSYM-NEXT: Size: 0 -# NOSYM-NEXT: Binding: Weak -# NOSYM-NEXT: Type: None -# NOSYM-NEXT: Other: 0 -# NOSYM-NEXT: Section: Undefined -# NOSYM-NEXT: } -# NOSYM-NEXT: Symbol { -# NOSYM-NEXT: Name: sym + +# CHECK: Symbol { +# CHECK: Name: bar +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Weak +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined +# CHECK-NEXT: } + +# NOSYM: Symbol { +# NOSYM: Name: sym # NOSYM-NEXT: Value: 0x20004 # NOSYM-NEXT: Size: 0 # NOSYM-NEXT: Binding: Global @@ -40,30 +41,48 @@ # NOSYM-NEXT: Other: 0 # NOSYM-NEXT: Section: .data # NOSYM-NEXT: } -# NOSYM-NEXT: ] -# NOSYM: 0x70000011 MIPS_SYMTABNO 4 -# NOSYM-NEXT: 0x7000000A MIPS_LOCAL_GOTNO 2 -# NOSYM-NEXT: 0x70000013 MIPS_GOTSYM 0x1 +# CHECK: 0x70000011 MIPS_SYMTABNO 4 -# NOSYM: Primary GOT { -# NOSYM-NEXT: Canonical gp value: -# NOSYM-NEXT: Reserved entries [ -# NOSYM-NEXT: Entry { -# NOSYM-NEXT: Address: -# NOSYM-NEXT: Access: -32752 -# NOSYM-NEXT: Initial: 0x0 -# NOSYM-NEXT: Purpose: Lazy resolver -# NOSYM-NEXT: } -# NOSYM-NEXT: Entry { -# NOSYM-NEXT: Address: -# NOSYM-NEXT: Access: -32748 -# NOSYM-NEXT: Initial: 0x80000000 -# NOSYM-NEXT: Purpose: Module pointer (GNU extension) -# NOSYM-NEXT: } -# NOSYM-NEXT: ] -# NOSYM-NEXT: Local entries [ +# SYM: 0x7000000A MIPS_LOCAL_GOTNO 4 +# SYM: 0x70000013 MIPS_GOTSYM 0x3 + +# NOSYM: 0x7000000A MIPS_LOCAL_GOTNO 2 +# NOSYM: 0x70000013 MIPS_GOTSYM 0x1 + +# CHECK: Primary GOT { +# CHECK-NEXT: Canonical gp value: +# CHECK-NEXT: Reserved entries [ +# CHECK: ] + +# SYM: Local entries [ +# SYM-NEXT: Entry { +# SYM-NEXT: Address: +# SYM-NEXT: Access: -32744 +# SYM-NEXT: Initial: 0x20000 +# SYM-NEXT: } +# SYM-NEXT: Entry { +# SYM-NEXT: Address: +# SYM-NEXT: Access: -32740 +# SYM-NEXT: Initial: 0x20004 +# SYM-NEXT: } +# SYM-NEXT: ] + +# NOSYM: Local entries [ # NOSYM-NEXT: ] + +# SYM-NEXT: Global entries [ +# SYM-NEXT: Entry { +# SYM-NEXT: Address: +# SYM-NEXT: Access: -32736 +# SYM-NEXT: Initial: 0x0 +# SYM-NEXT: Value: 0x0 +# SYM-NEXT: Type: None +# SYM-NEXT: Section: Undefined +# SYM-NEXT: Name: bar +# SYM-NEXT: } +# SYM-NEXT: ] + # NOSYM-NEXT: Global entries [ # NOSYM-NEXT: Entry { # NOSYM-NEXT: Address: @@ -93,68 +112,9 @@ # NOSYM-NEXT: Name: sym # NOSYM-NEXT: } # NOSYM-NEXT: ] -# NOSYM-NEXT: Number of TLS and multi-GOT entries: 0 -# NOSYM-NEXT: } - -# SYM: Relocations [ -# SYM-NEXT: ] - -# SYM: Symbol { -# SYM: Name: bar -# SYM-NEXT: Value: 0x0 -# SYM-NEXT: Size: 0 -# SYM-NEXT: Binding: Weak -# SYM-NEXT: Type: None -# SYM-NEXT: Other: 0 -# SYM-NEXT: Section: Undefined -# SYM-NEXT: } -# SYM-NEXT: ] - -# SYM: 0x70000011 MIPS_SYMTABNO 4 -# SYM-NEXT: 0x7000000A MIPS_LOCAL_GOTNO 4 -# SYM-NEXT: 0x70000013 MIPS_GOTSYM 0x3 - -# SYM: Primary GOT { -# SYM-NEXT: Canonical gp value: -# SYM-NEXT: Reserved entries [ -# SYM-NEXT: Entry { -# SYM-NEXT: Address: -# SYM-NEXT: Access: -32752 -# SYM-NEXT: Initial: 0x0 -# SYM-NEXT: Purpose: Lazy resolver -# SYM-NEXT: } -# SYM-NEXT: Entry { -# SYM-NEXT: Address: -# SYM-NEXT: Access: -32748 -# SYM-NEXT: Initial: 0x80000000 -# SYM-NEXT: Purpose: Module pointer (GNU extension) -# SYM-NEXT: } -# SYM-NEXT: ] -# SYM-NEXT: Local entries [ -# SYM-NEXT: Entry { -# SYM-NEXT: Address: -# SYM-NEXT: Access: -32744 -# SYM-NEXT: Initial: 0x20000 -# SYM-NEXT: } -# SYM-NEXT: Entry { -# SYM-NEXT: Address: -# SYM-NEXT: Access: -32740 -# SYM-NEXT: Initial: 0x20004 -# SYM-NEXT: } -# SYM-NEXT: ] -# SYM-NEXT: Global entries [ -# SYM-NEXT: Entry { -# SYM-NEXT: Address: -# SYM-NEXT: Access: -32736 -# SYM-NEXT: Initial: 0x0 -# SYM-NEXT: Value: 0x0 -# SYM-NEXT: Type: None -# SYM-NEXT: Section: Undefined -# SYM-NEXT: Name: bar -# SYM-NEXT: } -# SYM-NEXT: ] -# SYM-NEXT: Number of TLS and multi-GOT entries: 0 -# SYM-NEXT: } + +# CHECK: Number of TLS and multi-GOT entries: 0 +# CHECK-NEXT: } .text .global sym diff --git a/test/ELF/mips-got16-relocatable.s b/test/ELF/mips-got16-relocatable.s index bbacfdbaa682..04b7cbb8e904 100644 --- a/test/ELF/mips-got16-relocatable.s +++ b/test/ELF/mips-got16-relocatable.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check writing updated addend for R_MIPS_GOT16 relocation, # when produce a relocatable output. @@ -7,8 +8,6 @@ # RUN: ld.lld -shared -o %t.so %t # RUN: llvm-objdump -d %t.so | FileCheck -check-prefix=SO %s -# REQUIRES: mips - # OBJ: Disassembly of section .text: # OBJ-NEXT: .text: # OBJ-NEXT: 0: 8f 99 00 00 lw $25, 0($gp) diff --git a/test/ELF/mips-got16.s b/test/ELF/mips-got16.s index 6ad7b2b0d46e..cf0847da53d3 100644 --- a/test/ELF/mips-got16.s +++ b/test/ELF/mips-got16.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_GOT16 relocation calculation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o @@ -5,8 +6,6 @@ # RUN: llvm-objdump -d -t %t.so | FileCheck %s # RUN: llvm-readobj -r -mips-plt-got %t.so | FileCheck -check-prefix=GOT %s -# REQUIRES: mips - # CHECK: Disassembly of section .text: # CHECK-NEXT: __start: # CHECK-NEXT: 10000: 8f 88 80 18 lw $8, -32744($gp) diff --git a/test/ELF/mips-gp-disp-ver.s b/test/ELF/mips-gp-disp-ver.s new file mode 100644 index 000000000000..8eaee19daf19 --- /dev/null +++ b/test/ELF/mips-gp-disp-ver.s @@ -0,0 +1,14 @@ +# REQUIRES: mips +# MIPS BFD linker puts _gp_disp symbol into DSO files and assigns zero +# version definition index to it. This value means 'unversioned local symbol' +# while _gp_disp is a section global symbol. We have to handle this bug +# in the LLD because BFD linker is used for building MIPS toolchain +# libraries. This test checks such handling. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o %S/Inputs/mips-gp-dips-corrupt-ver.so + + .global __start + .text +__start: + lw $t0, %got(foo)($gp) diff --git a/test/ELF/mips-gp-disp.s b/test/ELF/mips-gp-disp.s index 7a0fd6409d18..1b4226d6022b 100644 --- a/test/ELF/mips-gp-disp.s +++ b/test/ELF/mips-gp-disp.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check that even if _gp_disp symbol is defined in the shared library # we use our own value. @@ -9,8 +10,6 @@ # RUN: llvm-objdump -d -t %t.so | FileCheck -check-prefix=DIS %s # RUN: llvm-readobj -relocations %t.so | FileCheck -check-prefix=REL %s -# REQUIRES: mips - # INT-SO: Name: _gp_disp # INT-SO-NEXT: Value: # INT-SO-NEXT: Size: diff --git a/test/ELF/mips-gp-ext.s b/test/ELF/mips-gp-ext.s index 2fd21b7a9818..9f12f1313166 100644 --- a/test/ELF/mips-gp-ext.s +++ b/test/ELF/mips-gp-ext.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check that the linker use a value of _gp symbol defined # in a linker script to calculate GOT relocations. @@ -24,45 +25,45 @@ # RUN: ld.lld -shared -o %t.abs.so --script %t.abs.script %t.o # RUN: llvm-objdump -s -t %t.abs.so | FileCheck --check-prefix=ABS %s -# REQUIRES: mips +# REL: Contents of section .reginfo: +# REL-NEXT: 0018 10000104 00000000 00000000 00000000 +# REL-NEXT: 0028 00000000 000001ec +# ^-- _gp # REL: Contents of section .text: -# REL-NEXT: 0000 3c080000 2108010c 8f82fffc +# REL-NEXT: 00e0 3c080000 2108010c 8f82ff1c # ^-- %hi(_gp_disp) # ^-- %lo(_gp_disp) -# ^-- 8 - (0x10c - 0x100) +# ^-- 8 - (0x1ec - 0x100) # G - (GP - .got) -# REL: Contents of section .reginfo: -# REL-NEXT: 0028 10000104 00000000 00000000 00000000 -# REL-NEXT: 0038 00000000 0000010c -# ^-- _gp - # REL: Contents of section .data: # REL-NEXT: 00f0 fffffef4 -# ^-- 0-0x10c +# ^-- 0x30-0x1ec +# foo - GP -# REL: 00000000 .text 00000000 foo +# REL: 000000e0 .text 00000000 foo # REL: 00000000 *ABS* 00000000 .hidden _gp_disp -# REL: 0000010c *ABS* 00000000 .hidden _gp +# REL: 000001ec *ABS* 00000000 .hidden _gp + +# ABS: Contents of section .reginfo: +# ABS-NEXT: 0018 10000104 00000000 00000000 00000000 +# ABS-NEXT: 0028 00000000 00000200 +# ^-- _gp # ABS: Contents of section .text: -# ABS-NEXT: 0000 3c080000 21080200 8f82ff08 +# ABS-NEXT: 00e0 3c080000 21080120 8f82ff08 # ^-- %hi(_gp_disp) # ^-- %lo(_gp_disp) # ^-- 8 - (0x200 - 0x100) # G - (GP - .got) -# ABS: Contents of section .reginfo: -# ABS-NEXT: 0028 10000104 00000000 00000000 00000000 -# ABS-NEXT: 0038 00000000 00000200 -# ^-- _gp - # ABS: Contents of section .data: -# ABS-NEXT: 00f0 fffffe00 -# ^-- 0-0x200 +# ABS-NEXT: 00f0 fffffee0 +# ^-- 0xe0-0x200 +# foo - GP -# ABS: 00000000 .text 00000000 foo +# ABS: 000000e0 .text 00000000 foo # ABS: 00000000 *ABS* 00000000 .hidden _gp_disp # ABS: 00000200 *ABS* 00000000 .hidden _gp diff --git a/test/ELF/mips-gp-local.s b/test/ELF/mips-gp-local.s index 8bb3c236edf0..1146af8ff751 100644 --- a/test/ELF/mips-gp-local.s +++ b/test/ELF/mips-gp-local.s @@ -1,11 +1,10 @@ +# REQUIRES: mips # Check handling of relocations against __gnu_local_gp symbol. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld -o %t.exe %t.o # RUN: llvm-objdump -d -t %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Disassembly of section .text: # CHECK-NEXT: __start: # CHECK-NEXT: 20000: 3c 08 00 03 lui $8, 3 diff --git a/test/ELF/mips-gp-lowest.s b/test/ELF/mips-gp-lowest.s index 32a3e85ee9ec..46da50334f5a 100644 --- a/test/ELF/mips-gp-lowest.s +++ b/test/ELF/mips-gp-lowest.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check that default _gp value is calculated relative # to the GP-relative section with the lowest address. @@ -8,8 +9,6 @@ # RUN: ld.lld %t.o --script %t.rel.script -shared -o %t.so # RUN: llvm-readobj -s -t %t.so | FileCheck %s -# REQUIRES: mips - .text .global foo foo: @@ -26,7 +25,7 @@ foo: # CHECK-NEXT: SHF_MIPS_GPREL # CHECK-NEXT: SHF_WRITE # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0xE0 +# CHECK-NEXT: Address: 0xF0 # CHECK: } # CHECK: Section { # CHECK: Name: .got @@ -36,9 +35,9 @@ foo: # CHECK-NEXT: SHF_MIPS_GPREL # CHECK-NEXT: SHF_WRITE # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0xF0 +# CHECK-NEXT: Address: 0x100 # CHECK: } # CHECK: Name: _gp (5) -# CHECK-NEXT: Value: 0x80D0 -# ^-- 0xE0 + 0x7ff0 +# CHECK-NEXT: Value: 0x80E0 +# ^-- 0xF0 + 0x7ff0 diff --git a/test/ELF/mips-gprel-sec.s b/test/ELF/mips-gprel-sec.s index dc54f87216da..7517983895b8 100644 --- a/test/ELF/mips-gprel-sec.s +++ b/test/ELF/mips-gprel-sec.s @@ -1,11 +1,10 @@ +# REQUIRES: mips # Check order of gp-relative sections, i.e. sections with SHF_MIPS_GPREL flag. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld %t.o -shared -o %t.so # RUN: llvm-readobj -s %t.so | FileCheck %s -# REQUIRES: mips - .text nop diff --git a/test/ELF/mips-gprel32-relocs-gp0.s b/test/ELF/mips-gprel32-relocs-gp0.s index 507224e05d15..1abdeec1b11a 100644 --- a/test/ELF/mips-gprel32-relocs-gp0.s +++ b/test/ELF/mips-gprel32-relocs-gp0.s @@ -1,8 +1,5 @@ +# REQUIRES: mips # Check that relocatable object produced by LLD has zero gp0 value. -# Also check an error message if input object file has non-zero gp0 value -# and the linker generates a relocatable object. -# mips-gp0-non-zero.o is a relocatable object produced from the asm code -# below and linked by GNU bfd linker. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld -r -o %t-rel.o %t.o @@ -12,11 +9,6 @@ # RUN: llvm-readobj -mips-reginfo %t.so | FileCheck --check-prefix=DSO %s # RUN: llvm-objdump -s -t %t.so | FileCheck --check-prefix=DUMP %s -# RUN: not ld.lld -r -o %t-rel.o %S/Inputs/mips-gp0-non-zero.o 2>&1 \ -# RUN: | FileCheck --check-prefix=ERR %s - -# REQUIRES: mips - # REL: GP: 0x0 # DSO: GP: 0x27FF0 @@ -31,8 +23,6 @@ # DUMP: 00010004 .text 00000000 foo # DUMP: 00027ff0 .got 00000000 .hidden _gp -# ERR: error: {{.*}}mips-gp0-non-zero.o: unsupported non-zero ri_gp_value - .text .global __start __start: diff --git a/test/ELF/mips-gprel32-relocs.s b/test/ELF/mips-gprel32-relocs.s index 047165f19ae4..8f31aa87411d 100644 --- a/test/ELF/mips-gprel32-relocs.s +++ b/test/ELF/mips-gprel32-relocs.s @@ -1,11 +1,10 @@ +# REQUIRES: mips # Check R_MIPS_GPREL32 relocation calculation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld -shared -o %t.so %t.o # RUN: llvm-objdump -s -section=.rodata -t %t.so | FileCheck %s -# REQUIRES: mips - .text .globl __start __start: diff --git a/test/ELF/mips-higher-highest.s b/test/ELF/mips-higher-highest.s index 123b51a65add..3af7dcb4b527 100644 --- a/test/ELF/mips-higher-highest.s +++ b/test/ELF/mips-higher-highest.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_HIGHER / R_MIPS_HIGHEST relocations calculation. # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t1.o @@ -6,8 +7,6 @@ # RUN: ld.lld %t1.o %t2.o -o %t.exe # RUN: llvm-objdump -d %t.exe | FileCheck %s -# REQUIRES: mips - .global __start __start: lui $6, %highest(_foo+0x300047FFF7FF7) diff --git a/test/ELF/mips-hilo-gp-disp.s b/test/ELF/mips-hilo-gp-disp.s index c7229ee0da25..997074efff16 100644 --- a/test/ELF/mips-hilo-gp-disp.s +++ b/test/ELF/mips-hilo-gp-disp.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_HI16 / LO16 relocations calculation against _gp_disp. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t1.o @@ -8,8 +9,6 @@ # RUN: ld.lld %t1.o %t2.o -shared -o %t.so # RUN: llvm-objdump -d -t %t.so | FileCheck -check-prefix=SO %s -# REQUIRES: mips - .text .globl __start __start: diff --git a/test/ELF/mips-hilo-hi-only.s b/test/ELF/mips-hilo-hi-only.s index 0858e3f6cd17..6fd4c683fd91 100644 --- a/test/ELF/mips-hilo-hi-only.s +++ b/test/ELF/mips-hilo-hi-only.s @@ -1,11 +1,10 @@ +# REQUIRES: mips # Check warning on orphaned R_MIPS_HI16 relocations. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld %t.o -o %t.exe 2>&1 | FileCheck -check-prefix=WARN %s # RUN: llvm-objdump -d -t %t.exe | FileCheck %s -# REQUIRES: mips - .text .globl __start __start: diff --git a/test/ELF/mips-hilo.s b/test/ELF/mips-hilo.s index d5de9422c427..a00ffaa9fb1c 100644 --- a/test/ELF/mips-hilo.s +++ b/test/ELF/mips-hilo.s @@ -1,11 +1,10 @@ +# REQUIRES: mips # Check R_MIPS_HI16 / LO16 relocations calculation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld %t.o -o %t.exe # RUN: llvm-objdump -d -t %t.exe | FileCheck %s -# REQUIRES: mips - .text .globl __start __start: diff --git a/test/ELF/mips-lo16-not-relative.s b/test/ELF/mips-lo16-not-relative.s index 614e6396cc92..2af1eead8847 100644 --- a/test/ELF/mips-lo16-not-relative.s +++ b/test/ELF/mips-lo16-not-relative.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check that R_MIPS_LO16 relocation is handled as non-relative, # and if a target symbol is a DSO data symbol, LLD create a copy # relocation. @@ -9,8 +10,6 @@ # RUN: ld.lld %t.o %t.so -o %t.exe # RUN: llvm-readobj -r %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Relocations [ # CHECK-NEXT: Section (7) .rel.dyn { # CHECK-NEXT: 0x{{[0-9A-F]+}} R_MIPS_COPY data0 0x0 diff --git a/test/ELF/mips-merge-abiflags.s b/test/ELF/mips-merge-abiflags.s index 2e8b43bcc3b8..d061c1b022bd 100644 --- a/test/ELF/mips-merge-abiflags.s +++ b/test/ELF/mips-merge-abiflags.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Test that lld handles input files with concatenated .MIPS.abiflags sections # This happens e.g. with the FreeBSD BFD (BFD 2.17.50 [FreeBSD] 2007-07-03) @@ -8,7 +9,6 @@ # RUN: %p/Inputs/mips-concatenated-abiflags.o | \ # RUN: FileCheck --check-prefix=INPUT-OBJECT %s -# REQUIRES: mips .globl __start __start: nop diff --git a/test/ELF/mips-mgot.s b/test/ELF/mips-mgot.s new file mode 100644 index 000000000000..0bb1a76ea8f5 --- /dev/null +++ b/test/ELF/mips-mgot.s @@ -0,0 +1,117 @@ +# REQUIRES: mips +# Check MIPS multi-GOT layout. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t0.o +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: %p/Inputs/mips-mgot-1.s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: %p/Inputs/mips-mgot-2.s -o %t2.o +# RUN: ld.lld -shared -mips-got-size 52 %t0.o %t1.o %t2.o -o %t.so +# RUN: llvm-objdump -s -section=.got -t %t.so | FileCheck %s +# RUN: llvm-readobj -r -dt -mips-plt-got %t.so | FileCheck -check-prefix=GOT %s + +# CHECK: Contents of section .got: +# CHECK-NEXT: 60000 00000000 80000000 00010000 00010030 +# CHECK-NEXT: 60010 00000000 00000004 00020000 00030000 +# CHECK-NEXT: 60020 00040000 00050000 00060000 00070000 +# CHECK-NEXT: 60030 00000000 00000000 00000000 00000000 +# CHECK-NEXT: 60040 00000000 00000000 00000000 + +# CHECK: SYMBOL TABLE: +# CHECK: 00000000 l .tdata 00000000 loc0 +# CHECK: 00010000 .text 00000000 foo0 +# CHECK: 00000000 g .tdata 00000000 tls0 +# CHECK: 00010020 .text 00000000 foo1 +# CHECK: 00000004 g .tdata 00000000 tls1 +# CHECK: 00010030 .text 00000000 foo2 +# CHECK: 00000008 g .tdata 00000000 tls2 + +# GOT: Relocations [ +# GOT-NEXT: Section (7) .rel.dyn { +# GOT-NEXT: 0x60018 R_MIPS_REL32 - 0x0 +# GOT-NEXT: 0x6001C R_MIPS_REL32 - 0x0 +# GOT-NEXT: 0x60020 R_MIPS_REL32 - 0x0 +# GOT-NEXT: 0x60024 R_MIPS_REL32 - 0x0 +# GOT-NEXT: 0x60028 R_MIPS_REL32 - 0x0 +# GOT-NEXT: 0x6002C R_MIPS_REL32 - 0x0 +# GOT-NEXT: 0x60030 R_MIPS_REL32 foo0 0x0 +# GOT-NEXT: 0x60034 R_MIPS_REL32 foo2 0x0 +# GOT-NEXT: 0x60044 R_MIPS_TLS_DTPMOD32 - 0x0 +# GOT-NEXT: 0x60010 R_MIPS_TLS_TPREL32 tls0 0x0 +# GOT-NEXT: 0x60038 R_MIPS_TLS_TPREL32 tls0 0x0 +# GOT-NEXT: 0x6003C R_MIPS_TLS_DTPMOD32 tls0 0x0 +# GOT-NEXT: 0x60040 R_MIPS_TLS_DTPREL32 tls0 0x0 +# GOT-NEXT: 0x60014 R_MIPS_TLS_TPREL32 tls1 0x0 +# GOT-NEXT: } +# GOT-NEXT: ] + +# GOT: DynamicSymbols [ +# GOT: Symbol { +# GOT: Name: foo0 +# GOT-NEXT: Value: 0x10000 +# GOT: } +# GOT-NEXT: Symbol { +# GOT-NEXT: Name: foo2 +# GOT-NEXT: Value: 0x10030 +# GOT: } +# GOT-NEXT: ] + +# GOT: Primary GOT { +# GOT-NEXT: Canonical gp value: 0x67FF0 +# GOT-NEXT: Reserved entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: +# GOT-NEXT: Access: -32752 +# GOT-NEXT: Initial: 0x0 +# GOT-NEXT: Purpose: Lazy resolver +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: +# GOT-NEXT: Access: -32748 +# GOT-NEXT: Initial: 0x80000000 +# GOT-NEXT: Purpose: Module pointer (GNU extension) +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Local entries [ +# GOT-NEXT: ] +# GOT-NEXT: Global entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: +# GOT-NEXT: Access: -32744 +# GOT-NEXT: Initial: 0x10000 +# GOT-NEXT: Value: 0x10000 +# GOT-NEXT: Type: None +# GOT-NEXT: Section: .text +# GOT-NEXT: Name: foo0 +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: +# GOT-NEXT: Access: -32740 +# GOT-NEXT: Initial: 0x10030 +# GOT-NEXT: Value: 0x10030 +# GOT-NEXT: Type: None +# GOT-NEXT: Section: .text +# GOT-NEXT: Name: foo2 +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Number of TLS and multi-GOT entries: 15 +# GOT-NEXT: } + + .text + .global foo0 +foo0: + lw $2, %got(.data)($gp) # page entry + addi $2, $2, %lo(.data) + lw $2, %call16(foo0)($gp) # global entry + addiu $2, $2, %tlsgd(tls0) # tls gd entry + addiu $2, $2, %gottprel(tls0) # tls got entry + addiu $2, $2, %tlsldm(loc0) # tls ld entry + + .data + .space 0x20000 + + .section .tdata,"awT",%progbits + .global tls0 +tls0: +loc0: + .word 0 diff --git a/test/ELF/mips-micro-got.s b/test/ELF/mips-micro-got.s index 8d077f2800f1..a881e0ae5fcb 100644 --- a/test/ELF/mips-micro-got.s +++ b/test/ELF/mips-micro-got.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check microMIPS GOT relocations for O32 ABI. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -mattr=micromips \ @@ -8,8 +9,6 @@ # RUN: ld.lld %t1.o %t.so -o %t.exe # RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Local entries [ # CHECK-NEXT: Entry { # CHECK-NEXT: Address: diff --git a/test/ELF/mips-micro-got64.s b/test/ELF/mips-micro-got64.s deleted file mode 100644 index 653bfbfbe8ce..000000000000 --- a/test/ELF/mips-micro-got64.s +++ /dev/null @@ -1,48 +0,0 @@ -# Check microMIPS GOT relocations for N64 ABI. - -# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux -mattr=micromips \ -# RUN: %s -o %t1.o -# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux -mattr=micromips \ -# RUN: %S/Inputs/mips-dynamic.s -o %t2.o -# RUN: ld.lld %t2.o -shared -o %t.so -# RUN: ld.lld %t1.o %t.so -o %t.exe -# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck %s - -# REQUIRES: mips - -# CHECK: Local entries [ -# CHECK-NEXT: Entry { -# CHECK-NEXT: Address: -# CHECK-NEXT: Access: -32736 -# CHECK-NEXT: Initial: 0x30000 -# CHECK-NEXT: } -# CHECK-NEXT: Entry { -# CHECK-NEXT: Address: -# CHECK-NEXT: Access: -32728 -# CHECK-NEXT: Initial: 0x40000 -# CHECK-NEXT: } -# CHECK-NEXT: ] -# CHECK-NEXT: Global entries [ -# CHECK-NEXT: Entry { -# CHECK-NEXT: Address: -# CHECK-NEXT: Access: -32720 -# CHECK-NEXT: Initial: 0x0 -# CHECK-NEXT: Value: 0x0 -# CHECK-NEXT: Type: Function -# CHECK-NEXT: Section: Undefined -# CHECK-NEXT: Name: foo0 -# CHECK-NEXT: } -# CHECK-NEXT: ] - - .text - .global __start -__start: - lui $28, %hi(%neg(%gp_rel(foo0))) - addiu $28, $28, %lo(%neg(%gp_rel(foo0))) - lw $4, %got_page(data)($28) - addiu $4, $4, %got_ofst(data) - lw $25, %call16(foo0)($28) - - .data -data: - .word 0 diff --git a/test/ELF/mips-micro-jal.s b/test/ELF/mips-micro-jal.s index 83826126f766..18d41cf13cbc 100644 --- a/test/ELF/mips-micro-jal.s +++ b/test/ELF/mips-micro-jal.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check PLT creation for microMIPS to microMIPS calls. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ @@ -45,8 +46,6 @@ # RUN: llvm-objdump -d -mattr=micromips %teb.exe \ # RUN: | FileCheck --check-prefix=MIXED %s -# REQUIRES: mips - # EB: Disassembly of section .plt: # EB-NEXT: .plt: # EB-NEXT: 20010: 79 80 3f fd addiupc $3, 65524 diff --git a/test/ELF/mips-micro-plt.s b/test/ELF/mips-micro-plt.s index 5671dc420c55..6dcd6fbeec2d 100644 --- a/test/ELF/mips-micro-plt.s +++ b/test/ELF/mips-micro-plt.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check less-significant bit setup for microMIPS PLT. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ @@ -7,13 +8,12 @@ # RUN: -mattr=micromips %s -o %t-exe.o # RUN: ld.lld %t-exe.o %t.so -o %t.exe # RUN: llvm-readobj -t -dt -mips-plt-got %t.exe | FileCheck %s - -# REQUIRES: mips +# RUN: llvm-objdump -d -mattr=micromips %t.exe | FileCheck --check-prefix=ASM %s # CHECK: Symbols [ # CHECK: Symbol { # CHECK: Name: foo -# CHECK-NEXT: Value: 0x20008 +# CHECK-NEXT: Value: 0x20010 # CHECK-NEXT: Size: # CHECK-NEXT: Binding: Local # CHECK-NEXT: Type: None @@ -36,22 +36,28 @@ # CHECK-NEXT: } # CHECK: Symbol { # CHECK: Name: foo0 -# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Value: 0x20040 # CHECK-NEXT: Size: # CHECK-NEXT: Binding: Global # CHECK-NEXT: Type: Function -# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Other [ +# CHECK-NEXT: STO_MIPS_MICROMIPS +# CHECK-NEXT: STO_MIPS_PLT +# CHECK-NEXT: ] # CHECK-NEXT: Section: Undefined # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK: DynamicSymbols [ # CHECK: Symbol { # CHECK: Name: foo0 -# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Value: 0x20041 # CHECK-NEXT: Size: # CHECK-NEXT: Binding: Global # CHECK-NEXT: Type: Function -# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Other [ +# CHECK-NEXT: STO_MIPS_MICROMIPS +# CHECK-NEXT: STO_MIPS_PLT +# CHECK-NEXT: ] # CHECK-NEXT: Section: Undefined # CHECK-NEXT: } # CHECK-NEXT: ] @@ -61,7 +67,7 @@ # CHECK-NEXT: Entry { # CHECK-NEXT: Address: # CHECK-NEXT: Access: -# CHECK-NEXT: Initial: 0x20009 +# CHECK-NEXT: Initial: 0x20011 # CHECK-NEXT: } # CHECK: ] # CHECK: } @@ -70,8 +76,8 @@ # CHECK: Entries [ # CHECK-NEXT: Entry { # CHECK-NEXT: Address: -# CHECK-NEXT: Initial: 0x20011 -# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Initial: 0x20021 +# CHECK-NEXT: Value: 0x20041 # CHECK-NEXT: Type: Function # CHECK-NEXT: Section: Undefined # CHECK-NEXT: Name: foo0@ @@ -79,6 +85,15 @@ # CHECK-NEXT: ] # CHECK-NEXT: } +# ASM: __start: +# ASM-NEXT: 20000: fd 1c 80 18 lw $8, -32744($gp) +# ASM-NEXT: 20004: 11 08 00 10 addi $8, $8, 16 +# ASM-NEXT: 20008: 41 a8 00 02 lui $8, 2 +# ASM-NEXT: 2000c: 11 08 00 40 addi $8, $8, 64 +# +# ASM: foo: +# ASM-NEXT: 20010: f4 01 00 20 jal 131136 + .text .set micromips .global foo @@ -87,5 +102,7 @@ __start: lw $t0,%got(foo)($gp) addi $t0,$t0,%lo(foo) + lui $t0,%hi(foo0) + addi $t0,$t0,%lo(foo0) foo: jal foo0 diff --git a/test/ELF/mips-micro-relocs.s b/test/ELF/mips-micro-relocs.s index 3986711cc7f7..b539aa946763 100644 --- a/test/ELF/mips-micro-relocs.s +++ b/test/ELF/mips-micro-relocs.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check handling of microMIPS relocations. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ @@ -16,8 +17,6 @@ # RUN: llvm-objdump -d -t -mattr=micromips %tel.exe \ # RUN: | FileCheck --check-prefixes=EL,SYM %s -# REQUIRES: mips - # EB: __start: # EB-NEXT: 20010: 41 a3 00 01 lui $3, 1 # EB-NEXT: 20014: 30 63 7f df addiu $3, $3, 32735 diff --git a/test/ELF/mips-micro-thunks.s b/test/ELF/mips-micro-thunks.s index 18a8fc33f53c..0505361e4a66 100644 --- a/test/ELF/mips-micro-thunks.s +++ b/test/ELF/mips-micro-thunks.s @@ -1,44 +1,77 @@ +# REQUIRES: mips # Check microMIPS thunk generation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ -# RUN: -mattr=micromips %s -o %t-eb.o +# RUN: -mcpu=mips32r2 -mattr=micromips %s -o %t-eb.o # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ -# RUN: -position-independent -mattr=micromips \ +# RUN: -position-independent -mcpu=mips32r2 -mattr=micromips \ # RUN: %S/Inputs/mips-micro.s -o %t-eb-pic.o # RUN: ld.lld -o %t-eb.exe %t-eb.o %t-eb-pic.o # RUN: llvm-objdump -d -mattr=+micromips %t-eb.exe \ -# RUN: | FileCheck --check-prefix=EB %s +# RUN: | FileCheck --check-prefix=EB-R2 %s # RUN: llvm-mc -filetype=obj -triple=mipsel-unknown-linux \ -# RUN: -mattr=micromips %s -o %t-el.o +# RUN: -mcpu=mips32r2 -mattr=micromips %s -o %t-el.o # RUN: llvm-mc -filetype=obj -triple=mipsel-unknown-linux \ -# RUN: -position-independent -mattr=micromips \ +# RUN: -position-independent -mcpu=mips32r2 -mattr=micromips \ # RUN: %S/Inputs/mips-micro.s -o %t-el-pic.o # RUN: ld.lld -o %t-el.exe %t-el.o %t-el-pic.o # RUN: llvm-objdump -d -mattr=+micromips %t-el.exe \ -# RUN: | FileCheck --check-prefix=EL %s +# RUN: | FileCheck --check-prefix=EL-R2 %s -# REQUIRES: mips +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: -mcpu=mips32r6 -mattr=micromips %s -o %t-eb-r6.o +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: -position-independent -mcpu=mips32r6 -mattr=micromips \ +# RUN: %S/Inputs/mips-micro.s -o %t-eb-pic-r6.o +# RUN: ld.lld -o %t-eb-r6.exe %t-eb-r6.o %t-eb-pic-r6.o +# RUN: llvm-objdump -d -mattr=+micromips %t-eb-r6.exe \ +# RUN: | FileCheck --check-prefix=EB-R6 %s + +# RUN: llvm-mc -filetype=obj -triple=mipsel-unknown-linux \ +# RUN: -mcpu=mips32r6 -mattr=micromips %s -o %t-el-r6.o +# RUN: llvm-mc -filetype=obj -triple=mipsel-unknown-linux \ +# RUN: -position-independent -mcpu=mips32r6 -mattr=micromips \ +# RUN: %S/Inputs/mips-micro.s -o %t-el-pic-r6.o +# RUN: ld.lld -o %t-el-r6.exe %t-el-r6.o %t-el-pic-r6.o +# RUN: llvm-objdump -d -mattr=+micromips %t-el-r6.exe \ +# RUN: | FileCheck --check-prefix=EL-R6 %s + +# EB-R2: __start: +# EB-R2-NEXT: 20000: f4 01 00 04 jal 131080 <__microLA25Thunk_foo> +# EB-R2-NEXT: 20004: 00 00 00 00 nop + +# EB-R2: __microLA25Thunk_foo: +# EB-R2-NEXT: 20008: 41 b9 00 02 lui $25, 2 +# EB-R2-NEXT: 2000c: d4 01 00 10 j 131104 +# EB-R2-NEXT: 20010: 33 39 00 21 addiu $25, $25, 33 +# EB-R2-NEXT: 20014: 0c 00 nop + +# EL-R2: __start: +# EL-R2-NEXT: 20000: 01 f4 04 00 jal 131080 <__microLA25Thunk_foo> +# EL-R2-NEXT: 20004: 00 00 00 00 nop + +# EL-R2: __microLA25Thunk_foo: +# EL-R2-NEXT: 20008: b9 41 02 00 lui $25, 2 +# EL-R2-NEXT: 2000c: 01 d4 10 00 j 131104 +# EL-R2-NEXT: 20010: 39 33 21 00 addiu $25, $25, 33 +# EL-R2-NEXT: 20014: 00 0c nop + +# EB-R6: __start: +# EB-R6-NEXT: 20000: b4 00 00 00 balc 0 <__start> + +# EB-R6: __microLA25Thunk_foo: +# EB-R6-NEXT: 20004: 13 20 00 02 lui $25, 2 +# EB-R6-NEXT: 20008: 33 39 00 11 addiu $25, $25, 17 +# EB-R6-NEXT: 2000c: 94 00 00 00 bc 0 <__microLA25Thunk_foo+0x8> + +# EL-R6: __start: +# EL-R6-NEXT: 20000: 00 b4 00 00 balc 0 <__start> -# EB: __start: -# EB-NEXT: 20000: f4 01 00 04 jal 131080 <__microLA25Thunk_foo> -# EB-NEXT: 20004: 00 00 00 00 nop - -# EB: __microLA25Thunk_foo: -# EB-NEXT: 20008: 41 b9 00 02 lui $25, 2 -# EB-NEXT: 2000c: d4 01 00 10 j 131104 -# EB-NEXT: 20010: 33 39 00 21 addiu $25, $25, 33 -# EB-NEXT: 20014: 0c 00 nop - -# EL: __start: -# EL-NEXT: 20000: 01 f4 04 00 jal 131080 <__microLA25Thunk_foo> -# EL-NEXT: 20004: 00 00 00 00 nop - -# EL: __microLA25Thunk_foo: -# EL-NEXT: 20008: b9 41 02 00 lui $25, 2 -# EL-NEXT: 2000c: 01 d4 10 00 j 131104 -# EL-NEXT: 20010: 39 33 21 00 addiu $25, $25, 33 -# EL-NEXT: 20014: 00 0c nop +# EL-R6: __microLA25Thunk_foo: +# EL-R6-NEXT: 20004: 20 13 02 00 lui $25, 2 +# EL-R6-NEXT: 20008: 39 33 11 00 addiu $25, $25, 17 +# EL-R6-NEXT: 2000c: 00 94 00 00 bc 0 <__microLA25Thunk_foo+0x8> .text .set micromips diff --git a/test/ELF/mips-micror6-relocs.s b/test/ELF/mips-micror6-relocs.s new file mode 100644 index 000000000000..ca2c1c064f56 --- /dev/null +++ b/test/ELF/mips-micror6-relocs.s @@ -0,0 +1,38 @@ +# REQUIRES: mips + +# Check handling of microMIPS R6 relocations. + +# RUN: llvm-mc -filetype=obj -triple=mips -mcpu=mips32r6 \ +# RUN: %S/Inputs/mips-micro.s -o %t1eb.o +# RUN: llvm-mc -filetype=obj -triple=mips -mcpu=mips32r6 %s -o %t2eb.o +# RUN: ld.lld -o %teb.exe %t1eb.o %t2eb.o +# RUN: llvm-objdump -d -t -mattr=micromips %teb.exe \ +# RUN: | FileCheck --check-prefixes=EB,SYM %s + +# RUN: llvm-mc -filetype=obj -triple=mipsel -mcpu=mips32r6 \ +# RUN: %S/Inputs/mips-micro.s -o %t1el.o +# RUN: llvm-mc -filetype=obj -triple=mipsel -mcpu=mips32r6 %s -o %t2el.o +# RUN: ld.lld -o %tel.exe %t1el.o %t2el.o +# RUN: llvm-objdump -d -t -mattr=micromips %tel.exe \ +# RUN: | FileCheck --check-prefixes=EL,SYM %s + +# EB: __start: +# EB-NEXT: 20010: 78 47 ff fd lapc $2, -12 +# EB-NEXT: 20014: 80 7f ff f6 beqzc $3, -36 +# EB-NEXT: 20018: b7 ff ff f4 balc -24 <foo> + +# EL: __start: +# EL-NEXT: 20010: 47 78 fd ff lapc $2, -12 +# EL-NEXT: 20014: 7f 80 f6 ff beqzc $3, -36 +# EL-NEXT: 20018: ff b7 f4 ff balc -24 <foo> + +# SYM: 00020000 g F .text 00000000 foo +# SYM: 00020010 .text 00000000 __start + + .text + .set micromips + .global __start +__start: + addiupc $2, foo+4 # R_MICROMIPS_PC19_S2 + beqzc $3, foo+4 # R_MICROMIPS_PC21_S1 + balc foo+4 # R_MICROMIPS_PC26_S1 diff --git a/test/ELF/mips-n32-emul.s b/test/ELF/mips-n32-emul.s index d0d81cc1c95f..3385d512d968 100644 --- a/test/ELF/mips-n32-emul.s +++ b/test/ELF/mips-n32-emul.s @@ -1,10 +1,9 @@ +# REQUIRES: mips # Check that LLD shows an error when N32 ABI emulation argument # is combined with non-N32 ABI object files. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o -# RUN: not ld.lld -m elf32btsmipn32 %t.o -o %t.exe 2>&1 | FileCheck %s - -# REQUIRES: mips +# RUN: not ld.lld -m elf32btsmipn32 %t.o -o /dev/null 2>&1 | FileCheck %s .text .global __start diff --git a/test/ELF/mips-n32-rels.s b/test/ELF/mips-n32-rels.s index 954d4c30a157..b59000c06d86 100644 --- a/test/ELF/mips-n32-rels.s +++ b/test/ELF/mips-n32-rels.s @@ -1,29 +1,27 @@ +# REQUIRES: mips # Check handling of N32 ABI relocation records. -# For now llvm-mc generates incorrect object files for N32 ABI. -# We use the binary input file generated by GNU tool. -# llvm-mc -filetype=obj -triple=mips64-unknown-linux \ -# -target-abi n32 %s -o %t.o -# RUN: ld.lld %S/Inputs/mips-n32-rels.o -o %t.exe +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ +# RUN: -target-abi n32 -o %t.o %s +# RUN: ld.lld %t.o -o %t.exe # RUN: llvm-objdump -t -d -s %t.exe | FileCheck %s # RUN: llvm-readobj -h %t.exe | FileCheck -check-prefix=ELF %s -# REQUIRES: mips + .option pic2 + .text + .type __start, @function + .global __start +__start: + lui $gp,%hi(%neg(%gp_rel(__start))) # R_MIPS_GPREL16 + # R_MIPS_SUB + # R_MIPS_HI16 +loc: + daddiu $gp,$gp,%lo(%neg(%gp_rel(__start))) # R_MIPS_GPREL16 + # R_MIPS_SUB + # R_MIPS_LO16 -# .text -# .type __start, @function -# .global __start -# __start: -# lui $gp,%hi(%neg(%gp_rel(__start))) # R_MIPS_GPREL16 -# # R_MIPS_SUB -# # R_MIPS_HI16 -# loc: -# daddiu $gp,$gp,%lo(%neg(%gp_rel(__start))) # R_MIPS_GPREL16 -# # R_MIPS_SUB -# # R_MIPS_LO16 -# -# .section .rodata,"a",@progbits -# .gpword(loc) # R_MIPS_32 + .section .rodata,"a",@progbits + .gpword(loc) # R_MIPS_GPREL32 # CHECK: Disassembly of section .text: # CHECK-NEXT: __start: @@ -38,8 +36,8 @@ # ^-- %lo(0x17ff0) # CHECK: Contents of section .rodata: -# CHECK-NEXT: {{[0-9a-f]+}} 00020004 -# ^-- loc +# CHECK-NEXT: {{[0-9a-f]+}} fffe8014 +# ^-- loc - _gp # CHECK: 00020004 .text 00000000 loc # CHECK: 00037ff0 .got 00000000 .hidden _gp @@ -67,5 +65,7 @@ # ELF-NEXT: SectionHeaderOffset: # ELF-NEXT: Flags [ # ELF-NEXT: EF_MIPS_ABI2 -# ELF-NEXT: EF_MIPS_ARCH_64R2 +# ELF-NEXT: EF_MIPS_ARCH_64 +# ELF-NEXT: EF_MIPS_CPIC +# ELF-NEXT: EF_MIPS_PIC # ELF-NEXT: ] diff --git a/test/ELF/mips-non-zero-gp0.s b/test/ELF/mips-non-zero-gp0.s new file mode 100644 index 000000000000..9e6b13c70725 --- /dev/null +++ b/test/ELF/mips-non-zero-gp0.s @@ -0,0 +1,54 @@ +# REQUIRES: mips + +# Check addend adjustment in case of generating a relocatable object +# if some input files have non-zero GP0 value. + +# We have to use GNU as and ld.bfd 2.28 to generate relocatable object +# files with non-zero GP0 value using the following command lines: +# +# as -mips32 -o test.o \ +# && ld.bfd -m elf32btsmip -r test.o -o mips-gp0-non-zero.o +# as -mips64 -o test.o \ +# && ld.bfd -m elf64btsmip -r test.o -o mips-n64-gp0-non-zero.o + +# Source code for mips-gp0-non-zero.o: +# .text +# .global __start +# __start: +# lw $t0,%call16(__start)($gp) +# foo: +# nop +# bar: +# nop +# +# .section .rodata, "a" +# v: +# .gpword foo +# .gpword bar + +# Source code for mips-n64-gp0-non-zero.o and mips-micro-gp0-non-zero.o: +# .text +# .global __start +# __start: +# foo: +# lui $gp,%hi(%neg(%gp_rel(foo))) + +# RUN: ld.lld -r -o %t-32.r %S/Inputs/mips-gp0-non-zero.o +# RUN: llvm-readobj -mips-reginfo %t-32.r | FileCheck --check-prefix=GPVAL %s +# RUN: llvm-objdump -s %t-32.r | FileCheck --check-prefix=ADDEND32 %s + +# RUN: ld.lld -r -o %t-64.r %S/Inputs/mips-n64-gp0-non-zero.o +# RUN: llvm-readobj -mips-options %t-64.r | FileCheck --check-prefix=GPVAL %s +# RUN: llvm-readobj -r %S/Inputs/mips-n64-gp0-non-zero.o %t-64.r \ +# RUN: | FileCheck --check-prefix=ADDEND64 %s + +# GPVAL: GP: 0x0 + +# ADDEND32: Contents of section .rodata: +# ADDEND32-NEXT: 0000 00007ff4 00007ff8 +# ^ 4+GP0 ^ 8+GP0 + +# ADDEND64: File: {{.*}}{{/|\\}}mips-n64-gp0-non-zero.o +# ADDEND64: .text 0xFFFFFFFFFFFF8011 +# ADDEND64: File: {{.*}}{{/|\\}}mips-non-zero-gp0.s.tmp-64.r +# ADDEND64: .text 0x0 diff --git a/test/ELF/mips-nonalloc.s b/test/ELF/mips-nonalloc.s index 7b0aa9469f9f..38d4599c689d 100644 --- a/test/ELF/mips-nonalloc.s +++ b/test/ELF/mips-nonalloc.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check reading addends for relocations in non-allocatable sections. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t1.o @@ -6,8 +7,6 @@ # RUN: ld.lld %t1.o %t2.o -o %t.exe # RUN: llvm-objdump -s %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Contents of section .debug_info: # CHECK-NEXT: 0000 ffffffff 00020000 00020000 # ^--------^-- __start diff --git a/test/ELF/mips-options.s b/test/ELF/mips-options.s index 18f5af8ece6e..ad634171eff7 100644 --- a/test/ELF/mips-options.s +++ b/test/ELF/mips-options.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check MIPS .MIPS.options section generation. # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t1.o @@ -9,8 +10,6 @@ # RUN: ld.lld %t1.o %t2.o --gc-sections --script %t.rel.script -shared -o %t.so # RUN: llvm-readobj -symbols -mips-options %t.so | FileCheck %s -# REQUIRES: mips - .text .globl __start __start: diff --git a/test/ELF/mips-out-of-bounds-call16-reloc.s b/test/ELF/mips-out-of-bounds-call16-reloc.s index 64e9ab3aa7e2..cc2494af5948 100644 --- a/test/ELF/mips-out-of-bounds-call16-reloc.s +++ b/test/ELF/mips-out-of-bounds-call16-reloc.s @@ -1,8 +1,8 @@ +# REQUIRES: mips # Check that we create an error on an out-of-bounds R_MIPS_CALL_16 -# REQUIRES: mips # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t1.o -# RUN: not ld.lld %t1.o -o %t.exe 2>&1 | FileCheck %s +# RUN: not ld.lld %t1.o -o /dev/null 2>&1 | FileCheck %s # CHECK: relocation R_MIPS_CALL16 out of range: 32768 is not in [-32768, 32767] diff --git a/test/ELF/mips-pc-relocs.s b/test/ELF/mips-pc-relocs.s index e0f39e7ed7c4..46c2b75578d9 100644 --- a/test/ELF/mips-pc-relocs.s +++ b/test/ELF/mips-pc-relocs.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check R_MIPS_PCxxx relocations calculation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ @@ -7,8 +8,6 @@ # RUN: ld.lld %t1.o %t2.o -o %t.exe # RUN: llvm-objdump -mcpu=mips32r6 -d -t -s %t.exe | FileCheck %s -# REQUIRES: mips - .text .globl __start __start: diff --git a/test/ELF/mips-plt-copy.s b/test/ELF/mips-plt-copy.s index 58883d884563..e035c5bd588c 100644 --- a/test/ELF/mips-plt-copy.s +++ b/test/ELF/mips-plt-copy.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check creating of R_MIPS_COPY and R_MIPS_JUMP_SLOT dynamic relocations # and corresponding PLT entries. @@ -8,16 +9,14 @@ # RUN: ld.lld %t.o %t.so -o %t.exe # RUN: llvm-readobj -r -mips-plt-got %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Relocations [ # CHECK-NEXT: Section ({{.*}}) .rel.dyn { -# CHECK-NEXT: 0x{{[0-9A-F]+}} R_MIPS_COPY data0 0x0 -# CHECK-NEXT: 0x{{[0-9A-F]+}} R_MIPS_COPY data1 0x0 +# CHECK-DAG: 0x{{[0-9A-F]+}} R_MIPS_COPY data0 0x0 +# CHECK-DAG: 0x{{[0-9A-F]+}} R_MIPS_COPY data1 0x0 # CHECK-NEXT: } # CHECK-NEXT: Section ({{.*}}) .rel.plt { -# CHECK-NEXT: 0x{{[0-9A-F]+}} R_MIPS_JUMP_SLOT foo0 0x0 -# CHECK-NEXT: 0x{{[0-9A-F]+}} R_MIPS_JUMP_SLOT foo1 0x0 +# CHECK-DAG: 0x{{[0-9A-F]+}} R_MIPS_JUMP_SLOT foo0 0x0 +# CHECK-DAG: 0x{{[0-9A-F]+}} R_MIPS_JUMP_SLOT foo1 0x0 # CHECK-NEXT: } # CHECK-NEXT: ] diff --git a/test/ELF/mips-plt-n32.s b/test/ELF/mips-plt-n32.s new file mode 100644 index 000000000000..06699fc1d045 --- /dev/null +++ b/test/ELF/mips-plt-n32.s @@ -0,0 +1,43 @@ +# REQUIRES: mips + +# Check PLT entries generation in case of using N32 ABI. + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ +# RUN: -target-abi n32 %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ +# RUN: -target-abi n32 %S/Inputs/mips-dynamic.s -o %t2.o +# RUN: ld.lld %t2.o -shared -o %t.so +# RUN: ld.lld %t1.o %t.so -o %t.exe +# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=DEFAULT,CHECK +# RUN: ld.lld %t2.o -shared -o %t.so -z hazardplt +# RUN: ld.lld %t1.o %t.so -o %t.exe -z hazardplt +# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=HAZARDPLT,CHECK + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: __start: +# CHECK-NEXT: 20000: 0c 00 80 0c jal 131120 +# ^-- 0x20030 gotplt[foo0] +# CHECK-NEXT: 20004: 00 00 00 00 nop +# +# CHECK-NEXT: Disassembly of section .plt: +# CHECK-NEXT: .plt: +# CHECK-NEXT: 20010: 3c 0e 00 03 lui $14, 3 +# CHECK-NEXT: 20014: 8d d9 00 04 lw $25, 4($14) +# CHECK-NEXT: 20018: 25 ce 00 04 addiu $14, $14, 4 +# CHECK-NEXT: 2001c: 03 0e c0 23 subu $24, $24, $14 +# CHECK-NEXT: 20020: 03 e0 78 25 move $15, $ra +# CHECK-NEXT: 20024: 00 18 c0 82 srl $24, $24, 2 +# DEFAULT: 20028: 03 20 f8 09 jalr $25 +# HAZARDPLT: 20028: 03 20 fc 09 jalr.hb $25 +# CHECK-NEXT: 2002c: 27 18 ff fe addiu $24, $24, -2 + +# CHECK-NEXT: 20030: 3c 0f 00 03 lui $15, 3 +# CHECK-NEXT: 20034: 8d f9 00 0c lw $25, 12($15) +# DEFAULT: 20038: 03 20 00 08 jr $25 +# HAZARDPLT: 20038: 03 20 04 08 jr.hb $25 +# CHECK-NEXT: 2003c: 25 f8 00 0c addiu $24, $15, 12 + + .text + .global __start +__start: + jal foo0 # R_MIPS_26 against 'foo0' from DSO diff --git a/test/ELF/mips-plt-r6.s b/test/ELF/mips-plt-r6.s index 4bab21c32eb9..b0ceb8214f02 100644 --- a/test/ELF/mips-plt-r6.s +++ b/test/ELF/mips-plt-r6.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check PLT entries generation in case of R6 ABI version. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ @@ -6,9 +7,10 @@ # RUN: -mcpu=mips32r6 %S/Inputs/mips-dynamic.s -o %t2.o # RUN: ld.lld %t2.o -shared -o %t.so # RUN: ld.lld %t1.o %t.so -o %t.exe -# RUN: llvm-objdump -d %t.exe | FileCheck %s - -# REQUIRES: mips +# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=DEFAULT,CHECK +# RUN: ld.lld %t2.o -shared -o %t.so -z hazardplt +# RUN: ld.lld %t1.o %t.so -o %t.exe -z hazardplt +# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=HAZARDPLT,CHECK # CHECK: Disassembly of section .text: # CHECK-NEXT: __start: @@ -24,12 +26,14 @@ # CHECK-NEXT: 2001c: 03 1c c0 23 subu $24, $24, $gp # CHECK-NEXT: 20020: 03 e0 78 25 move $15, $ra # CHECK-NEXT: 20024: 00 18 c0 82 srl $24, $24, 2 -# CHECK-NEXT: 20028: 03 20 f8 09 jalr $25 +# DEFAULT: 20028: 03 20 f8 09 jalr $25 +# HAZARDPLT: 20028: 03 20 fc 09 jalr.hb $25 # CHECK-NEXT: 2002c: 27 18 ff fe addiu $24, $24, -2 # CHECK-NEXT: 20030: 3c 0f 00 03 aui $15, $zero, 3 # CHECK-NEXT: 20034: 8d f9 00 0c lw $25, 12($15) -# CHECK-NEXT: 20038: 03 20 00 09 jr $25 +# DEFAULT: 20038: 03 20 00 09 jr $25 +# HAZARDPLT: 20038: 03 20 04 09 jr.hb $25 # CHECK-NEXT: 2003c: 25 f8 00 0c addiu $24, $15, 12 .text diff --git a/test/ELF/mips-reginfo.s b/test/ELF/mips-reginfo.s index 4024a2f6634f..049950d7424b 100644 --- a/test/ELF/mips-reginfo.s +++ b/test/ELF/mips-reginfo.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check MIPS .reginfo section generation. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t1.o @@ -6,8 +7,6 @@ # RUN: ld.lld %t1.o %t2.o --gc-sections -shared -o %t.so # RUN: llvm-readobj -symbols -mips-reginfo %t.so | FileCheck %s -# REQUIRES: mips - .text .globl __start __start: diff --git a/test/ELF/mips-relocatable.s b/test/ELF/mips-relocatable.s index 168ddf736e1e..0ab62774a4d8 100644 --- a/test/ELF/mips-relocatable.s +++ b/test/ELF/mips-relocatable.s @@ -1,11 +1,10 @@ +# REQUIRES: mips # Check linking MIPS code in case of -r linker's option. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld -r -o %t-r.o %t.o # RUN: llvm-objdump -s -t %t-r.o | FileCheck %s -# REQUIRES: mips - .text .global __start __start: diff --git a/test/ELF/mips-sto-pic-flag.s b/test/ELF/mips-sto-pic-flag.s index 3960ba322387..ae496979f7c6 100644 --- a/test/ELF/mips-sto-pic-flag.s +++ b/test/ELF/mips-sto-pic-flag.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # In case of linking PIC and non-PIC code together and generation # of a relocatable object, all PIC symbols should have STO_MIPS_PIC # flag in the symbol table of the ouput file. @@ -8,8 +9,6 @@ # RUN: ld.lld -r %t-npic.o %t-pic.o -o %t-rel.o # RUN: llvm-readobj -t %t-rel.o | FileCheck %s -# REQUIRES: mips - # CHECK: Symbol { # CHECK: Name: main # CHECK-NEXT: Value: diff --git a/test/ELF/mips-sto-plt.s b/test/ELF/mips-sto-plt.s index bd8de416680a..b4d3ee391414 100644 --- a/test/ELF/mips-sto-plt.s +++ b/test/ELF/mips-sto-plt.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check assigning STO_MIPS_PLT flag to symbol needs a pointer equality. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ @@ -7,8 +8,6 @@ # RUN: ld.lld %t.o %t.so -o %t.exe # RUN: llvm-readobj -dt -mips-plt-got %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Symbol { # CHECK: Name: foo0@ # CHECK-NEXT: Value: 0x0 @@ -18,9 +17,9 @@ # CHECK-NEXT: Other: 0 # CHECK-NEXT: Section: Undefined # CHECK-NEXT: } -# CHECK: Symbol { -# CHECK: Name: foo1@ -# CHECK-NEXT: Value: 0x20050 +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: foo1@ +# CHECK-NEXT: Value: 0x[[FOO1:[0-9A-F]+]] # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Global # CHECK-NEXT: Type: Function @@ -48,7 +47,7 @@ # CHECK-NEXT: Entry { # CHECK-NEXT: Address: # CHECK-NEXT: Initial: -# CHECK-NEXT: Value: 0x20050 +# CHECK-NEXT: Value: 0x[[FOO1]] # CHECK-NEXT: Type: Function # CHECK-NEXT: Section: Undefined # CHECK-NEXT: Name: foo1 diff --git a/test/ELF/mips-tls-64-pic-local-variable.s b/test/ELF/mips-tls-64-pic-local-variable.s new file mode 100644 index 000000000000..04d916f42c6c --- /dev/null +++ b/test/ELF/mips-tls-64-pic-local-variable.s @@ -0,0 +1,49 @@ +# REQUIRES: mips +# MIPS TLS variables that are marked as local by a version script were previously +# writing values to the GOT that caused runtime crashes. This was happending when +# linking jemalloc_tsd.c in FreeBSD libc. Check that we do the right thing now: + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-freebsd %s -o %t.o +# RUN: echo "{ global: foo; local: *; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-objdump --section=.got -s %t.so | FileCheck %s -check-prefix GOT +# RUN: llvm-readobj -r %t.so | FileCheck %s -check-prefix RELOCS + +# GOT: Contents of section .got: +# GOT-NEXT: 20000 00000000 00000000 80000000 00000000 +# GOT-NEXT: 20010 00000000 00000000 00000000 00000000 +# GOT-NEXT: 20020 ffffffff ffff8000 + +# RELOCS: Section ({{.+}}) .rel.dyn { +# RELOCS-NEXT: 0x20018 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE +# RELOCS-NEXT: } + +# Test case generated using clang -mcpu=mips4 -target mips64-unknown-freebsd12.0 -fpic -O -G0 -EB -mabi=n64 -msoft-float -std=gnu99 -S %s -o %t.s +# from the following source: +# +# _Thread_local int x; +# int foo() { return x; } +# + .text + .globl foo + .p2align 3 + .type foo,@function + .ent foo +foo: + lui $1, %hi(%neg(%gp_rel(foo))) + daddu $1, $1, $25 + daddiu $gp, $1, %lo(%neg(%gp_rel(foo))) + ld $25, %call16(__tls_get_addr)($gp) + jalr $25 + daddiu $4, $gp, %tlsgd(x) + .end foo + + .type x,@object + .section .tbss,"awT",@nobits + .globl x + .p2align 2 +x: + .4byte 0 + .size x, 4 + + diff --git a/test/ELF/mips-tls-64.s b/test/ELF/mips-tls-64.s index db29789ee117..f000755b4e82 100644 --- a/test/ELF/mips-tls-64.s +++ b/test/ELF/mips-tls-64.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check MIPS TLS 64-bit relocations handling. # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ @@ -13,31 +14,29 @@ # RUN: llvm-objdump -d -s -t %t-out.so | FileCheck -check-prefix=DIS-SO %s # RUN: llvm-readobj -r -mips-plt-got %t-out.so | FileCheck -check-prefix=SO %s -# REQUIRES: mips - # DIS: __start: -# DIS-NEXT: 20000: 24 62 80 20 addiu $2, $3, -32736 -# DIS-NEXT: 20004: 24 62 80 30 addiu $2, $3, -32720 -# DIS-NEXT: 20008: 24 62 80 38 addiu $2, $3, -32712 -# DIS-NEXT: 2000c: 24 62 80 48 addiu $2, $3, -32696 -# DIS-NEXT: 20010: 24 62 80 58 addiu $2, $3, -32680 +# DIS-NEXT: 20000: 24 62 80 30 addiu $2, $3, -32720 +# DIS-NEXT: 20004: 24 62 80 20 addiu $2, $3, -32736 +# DIS-NEXT: 20008: 24 62 80 40 addiu $2, $3, -32704 +# DIS-NEXT: 2000c: 24 62 80 50 addiu $2, $3, -32688 +# DIS-NEXT: 20010: 24 62 80 28 addiu $2, $3, -32728 # DIS: Contents of section .got: # DIS-NEXT: 30010 00000000 00000000 80000000 00000000 -# DIS-NEXT: 30020 00000000 00000000 00000000 00000000 -# DIS-NEXT: 30030 00000000 00000000 00000000 00000001 -# DIS-NEXT: 30040 00000000 00000000 00000000 00000001 -# DIS-NEXT: 30050 ffffffff ffff8004 ffffffff ffff9004 +# DIS-NEXT: 30020 00000000 00000000 ffffffff ffff9004 +# DIS-NEXT: 30030 00000000 00000000 00000000 00000000 +# DIS-NEXT: 30040 00000000 00000001 00000000 00000000 +# DIS-NEXT: 30050 00000000 00000001 ffffffff ffff8004 # DIS: 0000000000000000 l .tdata 00000000 loc # DIS: 0000000000000004 g .tdata 00000000 bar # DIS: 0000000000000000 g *UND* 00000000 foo # CHECK: Relocations [ -# CHECK-NEXT: Section (7) .rela.dyn { -# CHECK-NEXT: 0x30020 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 -# CHECK-NEXT: 0x30028 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 -# CHECK-NEXT: 0x30030 R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# CHECK-NEXT: Section (7) .rel.dyn { +# CHECK-NEXT: 0x30020 R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# CHECK-NEXT: 0x30030 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# CHECK-NEXT: 0x30038 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: Primary GOT { @@ -49,31 +48,31 @@ # CHECK-NEXT: Global entries [ # CHECK-NEXT: ] # CHECK-NEXT: Number of TLS and multi-GOT entries: 8 -# ^-- -32736 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD64 foo -# ^-- -32728 R_MIPS_TLS_DTPREL64 foo -# ^-- -32720 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL64 foo -# ^-- -32712 R_MIPS_TLS_LDM 1 loc -# ^-- -32704 0 loc -# ^-- -32696 R_MIPS_TLS_GD 1 bar -# ^-- -32688 VA - 0x8000 bar -# ^-- -32680 R_MIPS_TLS_GOTTPREL VA - 0x7000 bar +# ^-- -32736 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL64 foo +# ^-- -32728 R_MIPS_TLS_GOTTPREL VA - 0x7000 bar +# ^-- -32720 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD64 foo +# ^-- -32712 R_MIPS_TLS_DTPREL64 foo +# ^-- -32704 R_MIPS_TLS_LDM 1 loc +# ^-- -32696 0 loc +# ^-- -32688 R_MIPS_TLS_GD 1 bar +# ^-- -32680 VA - 0x8000 bar # DIS-SO: Contents of section .got: # DIS-SO-NEXT: 20000 00000000 00000000 80000000 00000000 -# DIS-SO-NEXT: 20010 00000000 00000000 00000000 00000000 +# DIS-SO-NEXT: 20010 00000000 00000000 00000000 00000004 # DIS-SO-NEXT: 20020 00000000 00000000 00000000 00000000 # DIS-SO-NEXT: 20030 00000000 00000000 00000000 00000000 # DIS-SO-NEXT: 20040 00000000 00000000 00000000 00000000 # SO: Relocations [ -# SO-NEXT: Section (7) .rela.dyn { -# SO-NEXT: 0x20028 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE - 0x0 -# SO-NEXT: 0x20038 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE bar 0x0 -# SO-NEXT: 0x20040 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE bar 0x0 -# SO-NEXT: 0x20048 R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE bar 0x0 -# SO-NEXT: 0x20010 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 -# SO-NEXT: 0x20018 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 -# SO-NEXT: 0x20020 R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# SO-NEXT: Section (7) .rel.dyn { +# SO-NEXT: 0x20030 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE - 0x0 +# SO-NEXT: 0x20018 R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE bar 0x0 +# SO-NEXT: 0x20040 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE bar 0x0 +# SO-NEXT: 0x20048 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE bar 0x0 +# SO-NEXT: 0x20010 R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# SO-NEXT: 0x20020 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# SO-NEXT: 0x20028 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 # SO-NEXT: } # SO-NEXT: ] # SO-NEXT: Primary GOT { @@ -85,14 +84,14 @@ # SO-NEXT: Global entries [ # SO-NEXT: ] # SO-NEXT: Number of TLS and multi-GOT entries: 8 -# ^-- -32736 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD64 foo -# ^-- -32728 R_MIPS_TLS_DTPREL64 foo -# ^-- -32720 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL64 foo -# ^-- -32712 R_MIPS_TLS_LDM R_MIPS_TLS_DTPMOD64 loc -# ^-- -32704 0 loc -# ^-- -32696 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD64 bar -# ^-- -32688 R_MIPS_TLS_DTPREL64 bar -# ^-- -32680 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL64 bar +# ^-- -32736 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL64 foo +# ^-- -32728 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL64 bar +# ^-- -32720 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD64 foo +# ^-- -32712 R_MIPS_TLS_DTPREL64 foo +# ^-- -32704 R_MIPS_TLS_LDM R_MIPS_TLS_DTPMOD64 loc +# ^-- -32696 0 loc +# ^-- -32688 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD64 bar +# ^-- -32680 R_MIPS_TLS_DTPREL64 bar .text .global __start diff --git a/test/ELF/mips-tls-hilo.s b/test/ELF/mips-tls-hilo.s index 47fadaa34b80..ae54602327a9 100644 --- a/test/ELF/mips-tls-hilo.s +++ b/test/ELF/mips-tls-hilo.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check MIPS R_MIPS_TLS_DTPREL_HI16/LO16 and R_MIPS_TLS_TPREL_HI16/LO16 # relocations handling. @@ -9,8 +10,6 @@ # RUN: ld.lld %t.o -shared -o %t.so # RUN: llvm-readobj -r -mips-plt-got %t.so | FileCheck -check-prefix=SO %s -# REQUIRES: mips - # DIS: __start: # DIS-NEXT: 20000: 24 62 00 00 addiu $2, $3, 0 # %hi(loc0 - .tdata - 0x8000) --^ diff --git a/test/ELF/mips-tls-static-64.s b/test/ELF/mips-tls-static-64.s index 6f88e86a3f44..04f18fa57585 100644 --- a/test/ELF/mips-tls-static-64.s +++ b/test/ELF/mips-tls-static-64.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check handling TLS related relocations and symbols when linking # a 64-bit static executable. @@ -5,8 +6,6 @@ # RUN: ld.lld -static %t -o %t.exe # RUN: llvm-objdump -s -t %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Contents of section .data: # CHECK-NEXT: 30000 00020004 ffffffff ffff8004 ffffffff # CHECK-NEXT: 30010 ffff9004 diff --git a/test/ELF/mips-tls-static.s b/test/ELF/mips-tls-static.s index 84b56cb42240..b09f5516bc89 100644 --- a/test/ELF/mips-tls-static.s +++ b/test/ELF/mips-tls-static.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check handling TLS related relocations and symbols when linking # a static executable. @@ -5,13 +6,11 @@ # RUN: ld.lld -static %t -o %t.exe # RUN: llvm-objdump -s -t %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Contents of section .data: # CHECK-NEXT: 30000 0002000c ffff8004 ffff9004 # CHECK: Contents of section .got: -# CHECK-NEXT: 30010 00000000 80000000 00000001 ffff8000 -# CHECK-NEXT: 30020 00000001 00000000 ffff9000 +# CHECK-NEXT: 30010 00000000 80000000 ffff9000 00000001 +# CHECK-NEXT: 30020 ffff8000 00000001 00000000 # # CHECK: SYMBOL TABLE: # CHECK: 0002000c .text 00000000 __tls_get_addr diff --git a/test/ELF/mips-tls.s b/test/ELF/mips-tls.s index b64f8db75731..ece55c69b303 100644 --- a/test/ELF/mips-tls.s +++ b/test/ELF/mips-tls.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check MIPS TLS relocations handling. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ @@ -13,19 +14,17 @@ # RUN: llvm-objdump -d -s -t %t-out.so | FileCheck -check-prefix=DIS-SO %s # RUN: llvm-readobj -r -mips-plt-got %t-out.so | FileCheck -check-prefix=SO %s -# REQUIRES: mips - # DIS: __start: -# DIS-NEXT: 20000: 24 62 80 18 addiu $2, $3, -32744 -# DIS-NEXT: 20004: 24 62 80 20 addiu $2, $3, -32736 -# DIS-NEXT: 20008: 24 62 80 24 addiu $2, $3, -32732 -# DIS-NEXT: 2000c: 24 62 80 2c addiu $2, $3, -32724 -# DIS-NEXT: 20010: 24 62 80 34 addiu $2, $3, -32716 +# DIS-NEXT: 20000: 24 62 80 20 addiu $2, $3, -32736 +# DIS-NEXT: 20004: 24 62 80 18 addiu $2, $3, -32744 +# DIS-NEXT: 20008: 24 62 80 28 addiu $2, $3, -32728 +# DIS-NEXT: 2000c: 24 62 80 30 addiu $2, $3, -32720 +# DIS-NEXT: 20010: 24 62 80 1c addiu $2, $3, -32740 # DIS: Contents of section .got: -# DIS-NEXT: 30010 00000000 80000000 00000000 00000000 -# DIS-NEXT: 30020 00000000 00000001 00000000 00000001 -# DIS-NEXT: 30030 ffff8004 ffff9004 +# DIS-NEXT: 30010 00000000 80000000 00000000 ffff9004 +# DIS-NEXT: 30020 00000000 00000000 00000001 00000000 +# DIS-NEXT: 30030 00000001 ffff8004 # DIS: 00000000 l .tdata 00000000 loc # DIS: 00000004 g .tdata 00000000 bar @@ -33,9 +32,9 @@ # CHECK: Relocations [ # CHECK-NEXT: Section (7) .rel.dyn { -# CHECK-NEXT: 0x30018 R_MIPS_TLS_DTPMOD32 foo 0x0 -# CHECK-NEXT: 0x3001C R_MIPS_TLS_DTPREL32 foo 0x0 -# CHECK-NEXT: 0x30020 R_MIPS_TLS_TPREL32 foo 0x0 +# CHECK-NEXT: 0x30018 R_MIPS_TLS_TPREL32 foo 0x0 +# CHECK-NEXT: 0x30020 R_MIPS_TLS_DTPMOD32 foo 0x0 +# CHECK-NEXT: 0x30024 R_MIPS_TLS_DTPREL32 foo 0x0 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: Primary GOT { @@ -47,29 +46,29 @@ # CHECK-NEXT: Global entries [ # CHECK-NEXT: ] # CHECK-NEXT: Number of TLS and multi-GOT entries: 8 -# ^-- -32744 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD32 foo -# ^-- -32740 R_MIPS_TLS_DTPREL32 foo -# ^-- -32736 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL32 foo -# ^-- -32732 R_MIPS_TLS_LDM 1 loc -# ^-- -32728 0 loc -# ^-- -32724 R_MIPS_TLS_GD 1 bar -# ^-- -32720 VA - 0x8000 bar -# ^-- -32716 R_MIPS_TLS_GOTTPREL VA - 0x7000 bar +# ^-- -32744 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL32 foo +# ^-- -32740 R_MIPS_TLS_GOTTPREL VA - 0x7000 bar +# ^-- -32736 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD32 foo +# ^-- -32732 R_MIPS_TLS_DTPREL32 foo +# ^-- -32728 R_MIPS_TLS_LDM 1 loc +# ^-- -32724 0 loc +# ^-- -32720 R_MIPS_TLS_GD 1 bar +# ^-- -32716 VA - 0x8000 bar # DIS-SO: Contents of section .got: -# DIS-SO-NEXT: 20000 00000000 80000000 00000000 00000000 +# DIS-SO-NEXT: 20000 00000000 80000000 00000000 00000004 # DIS-SO-NEXT: 20010 00000000 00000000 00000000 00000000 # DIS-SO-NEXT: 20020 00000000 00000000 # SO: Relocations [ # SO-NEXT: Section (7) .rel.dyn { -# SO-NEXT: 0x20014 R_MIPS_TLS_DTPMOD32 - 0x0 -# SO-NEXT: 0x2001C R_MIPS_TLS_DTPMOD32 bar 0x0 -# SO-NEXT: 0x20020 R_MIPS_TLS_DTPREL32 bar 0x0 -# SO-NEXT: 0x20024 R_MIPS_TLS_TPREL32 bar 0x0 -# SO-NEXT: 0x20008 R_MIPS_TLS_DTPMOD32 foo 0x0 -# SO-NEXT: 0x2000C R_MIPS_TLS_DTPREL32 foo 0x0 -# SO-NEXT: 0x20010 R_MIPS_TLS_TPREL32 foo 0x0 +# SO-NEXT: 0x20018 R_MIPS_TLS_DTPMOD32 - 0x0 +# SO-NEXT: 0x2000C R_MIPS_TLS_TPREL32 bar 0x0 +# SO-NEXT: 0x20020 R_MIPS_TLS_DTPMOD32 bar 0x0 +# SO-NEXT: 0x20024 R_MIPS_TLS_DTPREL32 bar 0x0 +# SO-NEXT: 0x20008 R_MIPS_TLS_TPREL32 foo 0x0 +# SO-NEXT: 0x20010 R_MIPS_TLS_DTPMOD32 foo 0x0 +# SO-NEXT: 0x20014 R_MIPS_TLS_DTPREL32 foo 0x0 # SO-NEXT: } # SO-NEXT: ] # SO-NEXT: Primary GOT { @@ -81,14 +80,14 @@ # SO-NEXT: Global entries [ # SO-NEXT: ] # SO-NEXT: Number of TLS and multi-GOT entries: 8 -# ^-- -32744 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD32 foo -# ^-- -32740 R_MIPS_TLS_DTPREL32 foo -# ^-- -32736 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL32 foo -# ^-- -32732 R_MIPS_TLS_LDM R_MIPS_TLS_DTPMOD32 loc -# ^-- -32728 0 loc -# ^-- -32724 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD32 bar -# ^-- -32720 R_MIPS_TLS_DTPREL32 bar -# ^-- -32716 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL32 bar +# ^-- -32744 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL32 foo +# ^-- -32740 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL32 bar +# ^-- -32736 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD32 foo +# ^-- -32732 R_MIPS_TLS_DTPREL32 foo +# ^-- -32728 R_MIPS_TLS_LDM R_MIPS_TLS_DTPMOD32 loc +# ^-- -32724 0 loc +# ^-- -32720 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD32 bar +# ^-- -32716 R_MIPS_TLS_DTPREL32 bar .text .global __start diff --git a/test/ELF/mips-xgot-order.s b/test/ELF/mips-xgot-order.s index 911731c713cd..c44cf64edd5a 100644 --- a/test/ELF/mips-xgot-order.s +++ b/test/ELF/mips-xgot-order.s @@ -1,3 +1,4 @@ +# REQUIRES: mips # Check that GOT entries accessed via 16-bit indexing are allocated # in the beginning of the GOT. @@ -5,8 +6,6 @@ # RUN: ld.lld %t.o -o %t.exe # RUN: llvm-objdump -d -s -t %t.exe | FileCheck %s -# REQUIRES: mips - # CHECK: Disassembly of section .text: # CHECK-NEXT: __start: # CHECK-NEXT: 20000: 3c 02 00 00 lui $2, 0 diff --git a/test/ELF/mips64-eh-abs-reloc.s b/test/ELF/mips64-eh-abs-reloc.s index 7bc500137992..7c31e1b51eda 100644 --- a/test/ELF/mips64-eh-abs-reloc.s +++ b/test/ELF/mips64-eh-abs-reloc.s @@ -1,5 +1,5 @@ -# Having an R_MIPS_64 relocation in eh_frame would previously crash LLD # REQUIRES: mips +# Having an R_MIPS_64 relocation in eh_frame would previously crash LLD # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-freebsd %s -o %t.o # RUN: llvm-readobj -r %t.o | FileCheck %s -check-prefix OBJ # RUN: ld.lld --eh-frame-hdr -shared -z notext -o %t.so %t.o @@ -20,8 +20,8 @@ # OBJ-NEXT: } # PIC-RELOCS: Relocations [ -# PIC-RELOCS-NEXT: Section (7) .rela.dyn { -# PIC-RELOCS-NEXT: {{0x.+}} R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE - 0x10000 +# PIC-RELOCS-NEXT: Section (7) .rel.dyn { +# PIC-RELOCS-NEXT: {{0x.+}} R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE - 0x0 # PIC-RELOCS-NEXT: } # PIC-RELOCS-NEXT:] diff --git a/test/ELF/multiple-cu.s b/test/ELF/multiple-cu.s new file mode 100644 index 000000000000..996a7bcd06d4 --- /dev/null +++ b/test/ELF/multiple-cu.s @@ -0,0 +1,38 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/multiple-cu.s -o %t2.o +# RUN: ld.lld -r -o %t.o %t1.o %t2.o +# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: undefined symbol: foo +# CHECK-NEXT: referenced by test1.c:2 + +# CHECK: error: undefined symbol: bar +# CHECK-NEXT: referenced by test2.c:2 + + .globl _start +_start: + .file 1 "test1.c" + .loc 1 2 0 + jmp foo + + .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/new-dtags.test b/test/ELF/new-dtags.test index 1ae328c6b502..bceea4bd6d65 100644 --- a/test/ELF/new-dtags.test +++ b/test/ELF/new-dtags.test @@ -1,8 +1,12 @@ # REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: ld.lld %t.o -rpath=/somepath -shared --disable-new-dtags -o %t -// RUN: ld.lld %t.o -rpath=/somepath -shared --enable-new-dtags -o %t2 // RUN: llvm-readobj --dynamic-table %t | FileCheck --check-prefix=DISABLE %s + +// RUN: ld.lld %t.o -rpath=/somepath -shared --enable-new-dtags -o %t2 +// RUN: llvm-readobj --dynamic-table %t2 | FileCheck --check-prefix=ENABLE %s + +// RUN: ld.lld %t.o -rpath=/somepath -shared --disable-new-dtags --enable-new-dtags -o %t2 // RUN: llvm-readobj --dynamic-table %t2 | FileCheck --check-prefix=ENABLE %s // DISABLE: DynamicSection [ diff --git a/test/ELF/no-augmentation.s b/test/ELF/no-augmentation.s index 31cd92e39b1c..f4912ba68366 100644 --- a/test/ELF/no-augmentation.s +++ b/test/ELF/no-augmentation.s @@ -1,7 +1,6 @@ -// RUN: llvm-mc -filetype=obj -triple=mips64-unknown-freebsd %s -o %t.o -// RUN: ld.lld --eh-frame-hdr %t.o -o %t | FileCheck -allow-empty %s - // REQUIRES: mips +// RUN: llvm-mc -filetype=obj -triple=mips64-unknown-freebsd %s -o %t.o +// RUN: ld.lld --eh-frame-hdr %t.o -o /dev/null | FileCheck -allow-empty %s // CHECK-NOT: corrupted or unsupported CIE information // CHECK-NOT: corrupted CIE diff --git a/test/ELF/no-dynamic-linker.s b/test/ELF/no-dynamic-linker.s deleted file mode 100644 index f5c7f4b8d072..000000000000 --- a/test/ELF/no-dynamic-linker.s +++ /dev/null @@ -1,12 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %tso.o -# RUN: ld.lld -shared %tso.o -o %t.so -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o - -# RUN: ld.lld -dynamic-linker foo --no-dynamic-linker %t.o %t.so -o %t -# RUN: llvm-readobj --program-headers %t | FileCheck %s --check-prefix=NODL -# NODL-NOT: PT_INTERP - -# RUN: ld.lld --no-dynamic-linker -dynamic-linker foo %t.o %t.so -o %t -# RUN: llvm-readobj --program-headers %t | FileCheck %s --check-prefix=WITHDL -# WITHDL: PT_INTERP diff --git a/test/ELF/no-inhibit-exec.s b/test/ELF/no-inhibit-exec.s index afb7aed94c12..1535f6e7b87e 100644 --- a/test/ELF/no-inhibit-exec.s +++ b/test/ELF/no-inhibit-exec.s @@ -1,9 +1,9 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: not ld.lld %t -o %t2 # RUN: ld.lld %t --noinhibit-exec -o %t2 # RUN: llvm-objdump -d %t2 | FileCheck %s # RUN: llvm-readobj -r %t2 | FileCheck %s --check-prefix=RELOC -# REQUIRES: x86 # CHECK: Disassembly of section .text: # CHECK-NEXT: _start diff --git a/test/ELF/no-line-parser-errors-if-empty-section.s b/test/ELF/no-line-parser-errors-if-empty-section.s new file mode 100644 index 000000000000..808052e7ff0b --- /dev/null +++ b/test/ELF/no-line-parser-errors-if-empty-section.s @@ -0,0 +1,21 @@ +# REQUIRES: x86 + +# LLD uses the debug data to get information for error messages, if possible. +# However, if the debug line section is empty, we should not attempt to parse +# it, as that would result in errors from the parser. + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s + +# CHECK-NOT: warning: +# CHECK-NOT: error: +# CHECK: error: undefined symbol: undefined +# CHECK-NEXT: {{.*}}.o:(.text+0x1) +# CHECK-NOT: warning: +# CHECK-NOT: error: + +.globl _start +_start: + callq undefined + +.section .debug_line,"",@progbits diff --git a/test/ELF/no-line-parser-errors-if-no-section.s b/test/ELF/no-line-parser-errors-if-no-section.s new file mode 100644 index 000000000000..4624601315d6 --- /dev/null +++ b/test/ELF/no-line-parser-errors-if-no-section.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 + +# LLD uses the debug data to get information for error messages, if possible. +# However, if there is no debug line section, we should not attempt to parse +# it, as that would result in errors from the parser. + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s + +# CHECK-NOT: warning: +# CHECK-NOT: error: +# CHECK: error: undefined symbol: undefined +# CHECK-NEXT: {{.*}}.o:(.text+0x1) +# CHECK-NOT: warning: +# CHECK-NOT: error: + +.globl _start +_start: + callq undefined diff --git a/test/ELF/no-obj.s b/test/ELF/no-obj.s index 693cdf1e9d3f..1a4bf98c181e 100644 --- a/test/ELF/no-obj.s +++ b/test/ELF/no-obj.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: llvm-ar rcs %t.a %t.o -// RUN: not ld.lld -o %t2 -u _start %t.a 2>&1 | FileCheck %s +// RUN: not ld.lld -o /dev/null -u _start %t.a 2>&1 | FileCheck %s // CHECK: target emulation unknown: -m or at least one .o file required diff --git a/test/ELF/no-symtab.s b/test/ELF/no-symtab.s index af9df13e9768..2468c4f05fc4 100644 --- a/test/ELF/no-symtab.s +++ b/test/ELF/no-symtab.s @@ -1,5 +1,5 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: ld.lld %t.o %p/Inputs/no-symtab.o -o %t +// RUN: ld.lld %t.o %p/Inputs/no-symtab.o -o /dev/null .global _start _start: diff --git a/test/ELF/no-undefined.s b/test/ELF/no-undefined.s index 493a38987091..854114b6a072 100644 --- a/test/ELF/no-undefined.s +++ b/test/ELF/no-undefined.s @@ -1,7 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: not ld.lld --no-undefined -shared %t -o %t.so -# RUN: ld.lld -shared %t -o %t1.so +# RUN: not ld.lld --no-undefined -shared %t -o /dev/null +# RUN: ld.lld -shared %t -o /dev/null .globl _shared _shared: diff --git a/test/ELF/non-abs-reloc.s b/test/ELF/non-abs-reloc.s index 454104cca076..ac69915b1b53 100644 --- a/test/ELF/non-abs-reloc.s +++ b/test/ELF/non-abs-reloc.s @@ -1,11 +1,21 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s -// CHECK: {{.*}}:(.dummy+0x0): has non-ABS relocation R_X86_64_GOTPCREL against symbol 'foo' +// RUN: ld.lld %t.o -o %t 2>&1 | FileCheck %s +// CHECK: (.nonalloc+0x1): has non-ABS relocation R_X86_64_PC32 against symbol '_start' +// CHECK: (.nonalloc+0x6): has non-ABS relocation R_X86_64_PC32 against symbol '_start' + +// RUN: llvm-objdump -D %t | FileCheck --check-prefix=DISASM %s +// DISASM: Disassembly of section .nonalloc: +// DISASM-NEXT: .nonalloc: +// DISASM-NEXT: 0: {{.*}} callq {{.*}} <_start> +// DISASM-NEXT: 5: {{.*}} callq {{.*}} <_start> .globl _start _start: nop -.section .dummy - .long foo@gotpcrel +.section .nonalloc + .byte 0xe8 + .long _start - . - 4 + .byte 0xe8 + .long _start - . - 4 diff --git a/test/ELF/non-alloc-link-order-gc.s b/test/ELF/non-alloc-link-order-gc.s new file mode 100644 index 000000000000..8147c45090d9 --- /dev/null +++ b/test/ELF/non-alloc-link-order-gc.s @@ -0,0 +1,34 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t1 --gc-sections +# RUN: llvm-objdump -section-headers -D %t1 | FileCheck %s + +## Check that we are able to GC non-allocatable metadata sections without crash. + +# CHECK: Disassembly of section .stack_sizes: +# CHECK-NEXT: .stack_sizes: +# CHECK-NEXT: 01 + +# CHECK: Name Size +# CHECK: .stack_sizes 00000001 + +.section .text.live,"ax",@progbits +.globl live +live: + nop + +.section .stack_sizes,"o",@progbits,.text.live,unique,0 +.byte 1 + +.section .text.dead,"ax",@progbits +.globl dead +dead: + nop + +.section .stack_sizes,"o",@progbits,.text.dead,unique,1 +.byte 2 + +.section .text.main,"ax",@progbits +.globl _start +_start: + callq live@PLT diff --git a/test/ELF/note-contiguous.s b/test/ELF/note-contiguous.s index f49d0b68ca33..7b04e9849320 100644 --- a/test/ELF/note-contiguous.s +++ b/test/ELF/note-contiguous.s @@ -1,24 +1,42 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: echo "SECTIONS { \ -// RUN: .note : { *(.note.a) *(.note.b) } \ -// RUN: }" > %t.script -// RUN: ld.lld %t.o --script %t.script -o %t -// RUN: llvm-readobj -program-headers %t | FileCheck %s + +// RUN: ld.lld %t.o -o %t1 +// RUN: llvm-readobj -program-headers %t1 | FileCheck %s // CHECK: Type: PT_NOTE -// CHECK-NEXT: Offset: 0x1000 -// CHECK-NEXT: VirtualAddress: 0x0 -// CHECK-NEXT: PhysicalAddress: 0x0 +// CHECK-NEXT: Offset: +// CHECK-NEXT: VirtualAddress: +// CHECK-NEXT: PhysicalAddress: // CHECK-NEXT: FileSize: 16 // CHECK-NEXT: MemSize: 16 -// CHECK-NEXT: Flags [ +// CHECK-NEXT: Flags [ // CHECK-NEXT: PF_R // CHECK-NEXT: ] // CHECK-NEXT: Alignment: 1 +// CHECK-NOT: Type: PT_NOTE + +// RUN: echo "SECTIONS { .note : { *(.note.a) *(.note.b) } }" > %t.script +// RUN: ld.lld %t.o --script %t.script -o %t2 +// RUN: llvm-readobj -program-headers %t2 | FileCheck -check-prefix=SCRIPT %s + +// SCRIPT: Type: PT_NOTE +// SCRIPT-NEXT: Offset: +// SCRIPT-NEXT: VirtualAddress: +// SCRIPT-NEXT: PhysicalAddress: +// SCRIPT-NEXT: FileSize: 16 +// SCRIPT-NEXT: MemSize: 16 +// SCRIPT-NEXT: Flags [ +// SCRIPT-NEXT: PF_R +// SCRIPT-NEXT: ] +// SCRIPT-NEXT: Alignment: 1 +// SCRIPT-NOT: Type: PT_NOTE .section .note.a, "a", @note .quad 0 +.section .foo, "a" +.quad 0 + .section .note.b, "a", @note .quad 0 diff --git a/test/ELF/note-loadaddr.c b/test/ELF/note-loadaddr.s index 6d2ebaeeaa0a..6d2ebaeeaa0a 100644 --- a/test/ELF/note-loadaddr.c +++ b/test/ELF/note-loadaddr.s diff --git a/test/ELF/note-noalloc.s b/test/ELF/note-noalloc.s new file mode 100644 index 000000000000..80c7a4d23a03 --- /dev/null +++ b/test/ELF/note-noalloc.s @@ -0,0 +1,38 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: ld.lld %t.o -o %t -shared +// RUN: llvm-readobj -program-headers -sections %t | FileCheck %s + +// PR37361: A note without SHF_ALLOC should not be included into a PT_NOTE program header. + +// CHECK: Section { +// CHECK: Index: +// CHECK: Name: .note.a +// CHECK-NEXT: Type: SHT_NOTE +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x[[ADDR:.*]] + +// Check we still emit the non-alloc SHT_NOTE section and keep its type. + +// CHECK: Name: .note.b +// CHECK-NEXT: Type: SHT_NOTE +// CHECK-NEXT: Flags [ +// CHECK-NEXT: ] + +// CHECK: ProgramHeader { +// CHECK: Type: PT_NOTE +// CHECK-NEXT: Offset: +// CHECK-NEXT: VirtualAddress: 0x[[ADDR]] +// CHECK-NEXT: PhysicalAddress: 0x[[ADDR]] +// CHECK-NEXT: FileSize: 16 +// CHECK-NEXT: MemSize: 16 +// CHECK-NOT: PT_NOTE + +.section .note.a,"a",@note +.quad 1 +.quad 2 + +.section .note.b,"",@note +.quad 3 diff --git a/test/ELF/note-noalloc2.s b/test/ELF/note-noalloc2.s new file mode 100644 index 000000000000..3705799d45cb --- /dev/null +++ b/test/ELF/note-noalloc2.s @@ -0,0 +1,11 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readobj -program-headers %t | FileCheck %s + +## Check we do not create a PT_NOTE segment for non-allocatable note section. + +# CHECK-NOT: PT_NOTE + +.section .note,"",@note +.quad 0 diff --git a/test/ELF/oformat-binary.s b/test/ELF/oformat-binary.s index acd95c7cef36..44c7b5ac2d8d 100644 --- a/test/ELF/oformat-binary.s +++ b/test/ELF/oformat-binary.s @@ -15,7 +15,7 @@ # RUN: ld.lld -o %t2.out --script %t.script %t --oformat binary # RUN: od -t x1 -v %t2.out | FileCheck %s -# RUN: not ld.lld -o %t3.out %t --oformat foo 2>&1 \ +# RUN: not ld.lld -o /dev/null %t --oformat foo 2>&1 \ # RUN: | FileCheck %s --check-prefix ERR # ERR: unknown --oformat value: foo diff --git a/test/ELF/output-section.s b/test/ELF/output-section.s index 68505254686c..2a119d998218 100644 --- a/test/ELF/output-section.s +++ b/test/ELF/output-section.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t // RUN: ld.lld %t -o %t2 // RUN: llvm-readobj -t %t2 | FileCheck %s -// REQUIRES: x86 // CHECK: Symbol { // CHECK: Name: bar_sym diff --git a/test/ELF/pack-dyn-relocs.s b/test/ELF/pack-dyn-relocs.s index cb8674318ec6..b37729dd890b 100644 --- a/test/ELF/pack-dyn-relocs.s +++ b/test/ELF/pack-dyn-relocs.s @@ -5,12 +5,10 @@ // 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: llvm-readobj -relocations %t2.a32 | FileCheck --check-prefix=UNPACKED32 %s -// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a32 %t.a32.so -o %t3.a32 -// RUN: llvm-readobj -s -dynamic-table %t3.a32 | FileCheck --check-prefix=PACKED32-HEADERS %s -// RUN: llvm-readobj -relocations %t3.a32 | FileCheck --check-prefix=PACKED32 %s // Unpacked should have the relative relocations in their natural order. -// UNPACKED32: 0x1000 R_ARM_RELATIVE - 0x0 +// UNPACKED32: Section ({{.+}}) .rel.dyn { +// UNPACKED32-NEXT: 0x1000 R_ARM_RELATIVE - 0x0 // UNPACKED32-NEXT: 0x1004 R_ARM_RELATIVE - 0x0 // UNPACKED32-NEXT: 0x1008 R_ARM_RELATIVE - 0x0 // UNPACKED32-NEXT: 0x100C R_ARM_RELATIVE - 0x0 @@ -37,70 +35,146 @@ // UNPACKED32-NEXT: 0x1060 R_ARM_RELATIVE - 0x0 // UNPACKED32-NEXT: 0x1064 R_ARM_RELATIVE - 0x0 +// UNPACKED32-NEXT: 0x1069 R_ARM_RELATIVE - 0x0 // UNPACKED32-NEXT: 0x1020 R_ARM_ABS32 bar2 0x0 // UNPACKED32-NEXT: 0x1040 R_ARM_ABS32 zed2 0x0 +// UNPACKED32-NEXT: } + +// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a32 %t.a32.so -o %t3.a32 +// RUN: llvm-readobj -s -dynamic-table %t3.a32 | FileCheck --check-prefix=ANDROID32-HEADERS %s +// RUN: llvm-readobj -relocations %t3.a32 | FileCheck --check-prefix=ANDROID32 %s + +// ANDROID32-HEADERS: Index: 1 +// ANDROID32-HEADERS-NEXT: Name: .dynsym + +// ANDROID32-HEADERS: Name: .rel.dyn +// ANDROID32-HEADERS-NEXT: Type: SHT_ANDROID_REL +// ANDROID32-HEADERS-NEXT: Flags [ (0x2) +// ANDROID32-HEADERS-NEXT: SHF_ALLOC (0x2) +// ANDROID32-HEADERS-NEXT: ] +// ANDROID32-HEADERS-NEXT: Address: [[ADDR:.*]] +// ANDROID32-HEADERS-NEXT: Offset: [[ADDR]] +// ANDROID32-HEADERS-NEXT: Size: [[SIZE:.*]] +// ANDROID32-HEADERS-NEXT: Link: 1 +// ANDROID32-HEADERS-NEXT: Info: 0 +// ANDROID32-HEADERS-NEXT: AddressAlignment: 4 +// ANDROID32-HEADERS-NEXT: EntrySize: 1 -// PACKED32-HEADERS: Index: 1 -// PACKED32-HEADERS-NEXT: Name: .dynsym - -// PACKED32-HEADERS: Name: .rel.dyn -// PACKED32-HEADERS-NEXT: Type: SHT_ANDROID_REL -// PACKED32-HEADERS-NEXT: Flags [ (0x2) -// PACKED32-HEADERS-NEXT: SHF_ALLOC (0x2) -// PACKED32-HEADERS-NEXT: ] -// PACKED32-HEADERS-NEXT: Address: [[ADDR:.*]] -// PACKED32-HEADERS-NEXT: Offset: [[ADDR]] -// PACKED32-HEADERS-NEXT: Size: [[SIZE:.*]] -// PACKED32-HEADERS-NEXT: Link: 1 -// PACKED32-HEADERS-NEXT: Info: 0 -// PACKED32-HEADERS-NEXT: AddressAlignment: 4 -// PACKED32-HEADERS-NEXT: EntrySize: 1 - -// PACKED32-HEADERS: 0x6000000F ANDROID_REL [[ADDR]] -// PACKED32-HEADERS: 0x60000010 ANDROID_RELSZ [[SIZE]] +// 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. -// PACKED32: 0x1000 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1004 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1008 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x100C R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1010 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1014 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1018 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x101C R_ARM_RELATIVE - 0x0 - -// PACKED32-NEXT: 0x1044 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1048 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x104C R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1050 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1054 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1058 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x105C R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1060 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1064 R_ARM_RELATIVE - 0x0 - -// PACKED32-NEXT: 0x1024 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1028 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x102C R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1030 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1034 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x1038 R_ARM_RELATIVE - 0x0 -// PACKED32-NEXT: 0x103C R_ARM_RELATIVE - 0x0 - -// PACKED32-NEXT: 0x1020 R_ARM_ABS32 bar2 0x0 -// PACKED32-NEXT: 0x1040 R_ARM_ABS32 zed2 0x0 +// ANDROID32: Section ({{.+}}) .rel.dyn { +// ANDROID32-NEXT: 0x1000 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1004 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1008 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x100C R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1010 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1014 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1018 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x101C R_ARM_RELATIVE - 0x0 + +// ANDROID32-NEXT: 0x1044 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1048 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x104C R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1050 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1054 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1058 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x105C R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1060 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1064 R_ARM_RELATIVE - 0x0 + +// ANDROID32-NEXT: 0x1024 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1028 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x102C R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1030 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1034 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1038 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x103C R_ARM_RELATIVE - 0x0 + +// ANDROID32-NEXT: 0x1069 R_ARM_RELATIVE - 0x0 +// ANDROID32-NEXT: 0x1020 R_ARM_ABS32 bar2 0x0 +// ANDROID32-NEXT: 0x1040 R_ARM_ABS32 zed2 0x0 +// ANDROID32-NEXT: } + +// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.a32 %t.a32.so -o %t4.a32 +// RUN: llvm-readobj -s -dynamic-table %t4.a32 | FileCheck --check-prefix=RELR32-HEADERS %s +// RUN: llvm-readobj -relocations -raw-relr %t4.a32 | FileCheck --check-prefix=RAW-RELR32 %s +// RUN: llvm-readobj -relocations %t4.a32 | FileCheck --check-prefix=RELR32 %s + +// RELR32-HEADERS: Index: 1 +// RELR32-HEADERS-NEXT: Name: .dynsym + +// RELR32-HEADERS: Name: .relr.dyn +// RELR32-HEADERS-NEXT: Type: SHT_RELR +// RELR32-HEADERS-NEXT: Flags [ (0x2) +// RELR32-HEADERS-NEXT: SHF_ALLOC (0x2) +// RELR32-HEADERS-NEXT: ] +// RELR32-HEADERS-NEXT: Address: [[ADDR:.*]] +// RELR32-HEADERS-NEXT: Offset: [[ADDR]] +// RELR32-HEADERS-NEXT: Size: 8 +// RELR32-HEADERS-NEXT: Link: 0 +// RELR32-HEADERS-NEXT: Info: 0 +// RELR32-HEADERS-NEXT: AddressAlignment: 4 +// RELR32-HEADERS-NEXT: EntrySize: 4 + +// RELR32-HEADERS: 0x00000024 RELR [[ADDR]] +// RELR32-HEADERS: 0x00000023 RELRSZ 0x8 +// RELR32-HEADERS: 0x00000025 RELRENT 0x4 + +// SHT_RELR section contains address/bitmap entries +// encoding the offsets for relative relocation. +// RAW-RELR32: Section ({{.+}}) .relr.dyn { +// RAW-RELR32-NEXT: 0x1000 +// RAW-RELR32-NEXT: 0x3FEFEFF +// 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: 0x1069 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1020 R_ARM_ABS32 bar2 0x0 +// RELR32-NEXT: 0x1040 R_ARM_ABS32 zed2 0x0 +// RELR32-NEXT: } +// RELR32-NEXT: Section ({{.+}}) .relr.dyn { +// RELR32-NEXT: 0x1000 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1004 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1008 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x100C R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1010 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1014 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1018 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x101C R_ARM_RELATIVE - 0x0 + +// RELR32-NEXT: 0x1024 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1028 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x102C R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1030 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1034 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1038 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x103C R_ARM_RELATIVE - 0x0 + +// RELR32-NEXT: 0x1044 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1048 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x104C R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1050 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1054 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1058 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x105C R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1060 R_ARM_RELATIVE - 0x0 +// RELR32-NEXT: 0x1064 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: llvm-readobj -relocations %t2.a64 | FileCheck --check-prefix=UNPACKED64 %s -// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a64 %t.a64.so -o %t3.a64 -// RUN: llvm-readobj -s -dynamic-table %t3.a64 | FileCheck --check-prefix=PACKED64-HEADERS %s -// RUN: llvm-readobj -relocations %t3.a64 | FileCheck --check-prefix=PACKED64 %s -// UNPACKED64: 0x10000 R_AARCH64_RELATIVE - 0x1 +// UNPACKED64: Section ({{.+}}) .rela.dyn { +// UNPACKED64-NEXT: 0x10000 R_AARCH64_RELATIVE - 0x1 // UNPACKED64-NEXT: 0x10008 R_AARCH64_RELATIVE - 0x2 // UNPACKED64-NEXT: 0x10010 R_AARCH64_RELATIVE - 0x3 // UNPACKED64-NEXT: 0x10018 R_AARCH64_RELATIVE - 0x4 @@ -127,59 +201,138 @@ // UNPACKED64-NEXT: 0x100C0 R_AARCH64_RELATIVE - 0x8 // UNPACKED64-NEXT: 0x100C8 R_AARCH64_RELATIVE - 0x9 +// UNPACKED64-NEXT: 0x100D1 R_AARCH64_RELATIVE - 0xA // UNPACKED64-NEXT: 0x10040 R_AARCH64_ABS64 bar2 0x1 // UNPACKED64-NEXT: 0x10080 R_AARCH64_ABS64 zed2 0x0 +// UNPACKED64-NEXT: } + +// RUN: ld.lld -pie --pack-dyn-relocs=android %t.a64 %t.a64.so -o %t3.a64 +// RUN: llvm-readobj -s -dynamic-table %t3.a64 | FileCheck --check-prefix=ANDROID64-HEADERS %s +// RUN: llvm-readobj -relocations %t3.a64 | FileCheck --check-prefix=ANDROID64 %s + +// ANDROID64-HEADERS: Index: 1 +// ANDROID64-HEADERS-NEXT: Name: .dynsym + +// ANDROID64-HEADERS: Name: .rela.dyn +// ANDROID64-HEADERS-NEXT: Type: SHT_ANDROID_RELA +// ANDROID64-HEADERS-NEXT: Flags [ (0x2) +// ANDROID64-HEADERS-NEXT: SHF_ALLOC (0x2) +// ANDROID64-HEADERS-NEXT: ] +// ANDROID64-HEADERS-NEXT: Address: [[ADDR:.*]] +// ANDROID64-HEADERS-NEXT: Offset: [[ADDR]] +// ANDROID64-HEADERS-NEXT: Size: [[SIZE:.*]] +// ANDROID64-HEADERS-NEXT: Link: 1 +// ANDROID64-HEADERS-NEXT: Info: 0 +// ANDROID64-HEADERS-NEXT: AddressAlignment: 8 +// ANDROID64-HEADERS-NEXT: EntrySize: 1 + +// ANDROID64-HEADERS: 0x0000000060000011 ANDROID_RELA [[ADDR]] +// ANDROID64-HEADERS: 0x0000000060000012 ANDROID_RELASZ [[SIZE]] + +// ANDROID64: Section ({{.+}}) .rela.dyn { +// ANDROID64-NEXT: 0x10000 R_AARCH64_RELATIVE - 0x1 +// ANDROID64-NEXT: 0x10008 R_AARCH64_RELATIVE - 0x2 +// ANDROID64-NEXT: 0x10010 R_AARCH64_RELATIVE - 0x3 +// ANDROID64-NEXT: 0x10018 R_AARCH64_RELATIVE - 0x4 +// ANDROID64-NEXT: 0x10020 R_AARCH64_RELATIVE - 0x5 +// ANDROID64-NEXT: 0x10028 R_AARCH64_RELATIVE - 0x6 +// ANDROID64-NEXT: 0x10030 R_AARCH64_RELATIVE - 0x7 +// ANDROID64-NEXT: 0x10038 R_AARCH64_RELATIVE - 0x8 + +// ANDROID64-NEXT: 0x10088 R_AARCH64_RELATIVE - 0x1 +// ANDROID64-NEXT: 0x10090 R_AARCH64_RELATIVE - 0x2 +// ANDROID64-NEXT: 0x10098 R_AARCH64_RELATIVE - 0x3 +// ANDROID64-NEXT: 0x100A0 R_AARCH64_RELATIVE - 0x4 +// ANDROID64-NEXT: 0x100A8 R_AARCH64_RELATIVE - 0x5 +// ANDROID64-NEXT: 0x100B0 R_AARCH64_RELATIVE - 0x6 +// ANDROID64-NEXT: 0x100B8 R_AARCH64_RELATIVE - 0x7 +// ANDROID64-NEXT: 0x100C0 R_AARCH64_RELATIVE - 0x8 +// ANDROID64-NEXT: 0x100C8 R_AARCH64_RELATIVE - 0x9 + +// ANDROID64-NEXT: 0x10048 R_AARCH64_RELATIVE - 0x1 +// ANDROID64-NEXT: 0x10050 R_AARCH64_RELATIVE - 0x2 +// ANDROID64-NEXT: 0x10058 R_AARCH64_RELATIVE - 0x3 +// ANDROID64-NEXT: 0x10060 R_AARCH64_RELATIVE - 0x4 +// ANDROID64-NEXT: 0x10068 R_AARCH64_RELATIVE - 0x5 +// ANDROID64-NEXT: 0x10070 R_AARCH64_RELATIVE - 0x6 +// ANDROID64-NEXT: 0x10078 R_AARCH64_RELATIVE - 0x7 + +// ANDROID64-NEXT: 0x100D1 R_AARCH64_RELATIVE - 0xA +// ANDROID64-NEXT: 0x10040 R_AARCH64_ABS64 bar2 0x1 +// ANDROID64-NEXT: 0x10080 R_AARCH64_ABS64 zed2 0x0 +// ANDROID64-NEXT: } + +// RUN: ld.lld -pie --pack-dyn-relocs=relr %t.a64 %t.a64.so -o %t4.a64 +// RUN: llvm-readobj -s -dynamic-table %t4.a64 | FileCheck --check-prefix=RELR64-HEADERS %s +// RUN: llvm-readobj -relocations -raw-relr %t4.a64 | FileCheck --check-prefix=RAW-RELR64 %s +// RUN: llvm-readobj -relocations %t4.a64 | FileCheck --check-prefix=RELR64 %s + +// RELR64-HEADERS: Index: 1 +// RELR64-HEADERS-NEXT: Name: .dynsym + +// RELR64-HEADERS: Name: .relr.dyn +// RELR64-HEADERS-NEXT: Type: SHT_RELR +// RELR64-HEADERS-NEXT: Flags [ (0x2) +// RELR64-HEADERS-NEXT: SHF_ALLOC (0x2) +// RELR64-HEADERS-NEXT: ] +// RELR64-HEADERS-NEXT: Address: [[ADDR:.*]] +// RELR64-HEADERS-NEXT: Offset: [[ADDR]] +// RELR64-HEADERS-NEXT: Size: 16 +// RELR64-HEADERS-NEXT: Link: 0 +// RELR64-HEADERS-NEXT: Info: 0 +// RELR64-HEADERS-NEXT: AddressAlignment: 8 +// RELR64-HEADERS-NEXT: EntrySize: 8 + +// RELR64-HEADERS: 0x0000000000000024 RELR [[ADDR]] +// RELR64-HEADERS: 0x0000000000000023 RELRSZ 0x10 +// RELR64-HEADERS: 0x0000000000000025 RELRENT 0x8 + +// SHT_RELR section contains address/bitmap entries +// encoding the offsets for relative relocation. +// RAW-RELR64: Section ({{.+}}) .relr.dyn { +// RAW-RELR64-NEXT: 0x10000 +// RAW-RELR64-NEXT: 0x3FEFEFF +// 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: 0x100D1 R_AARCH64_RELATIVE - 0xA +// RELR64-NEXT: 0x10040 R_AARCH64_ABS64 bar2 0x1 +// RELR64-NEXT: 0x10080 R_AARCH64_ABS64 zed2 0x0 +// RELR64-NEXT: } +// RELR64-NEXT: Section ({{.+}}) .relr.dyn { +// RELR64-NEXT: 0x10000 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10008 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10010 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10018 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10020 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10028 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10030 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10038 R_AARCH64_RELATIVE - 0x0 + +// RELR64-NEXT: 0x10048 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10050 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10058 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10060 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10068 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10070 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10078 R_AARCH64_RELATIVE - 0x0 -// PACKED64: 0x10000 R_AARCH64_RELATIVE - 0x1 -// PACKED64-NEXT: 0x10008 R_AARCH64_RELATIVE - 0x2 -// PACKED64-NEXT: 0x10010 R_AARCH64_RELATIVE - 0x3 -// PACKED64-NEXT: 0x10018 R_AARCH64_RELATIVE - 0x4 -// PACKED64-NEXT: 0x10020 R_AARCH64_RELATIVE - 0x5 -// PACKED64-NEXT: 0x10028 R_AARCH64_RELATIVE - 0x6 -// PACKED64-NEXT: 0x10030 R_AARCH64_RELATIVE - 0x7 -// PACKED64-NEXT: 0x10038 R_AARCH64_RELATIVE - 0x8 - -// PACKED64-NEXT: 0x10088 R_AARCH64_RELATIVE - 0x1 -// PACKED64-NEXT: 0x10090 R_AARCH64_RELATIVE - 0x2 -// PACKED64-NEXT: 0x10098 R_AARCH64_RELATIVE - 0x3 -// PACKED64-NEXT: 0x100A0 R_AARCH64_RELATIVE - 0x4 -// PACKED64-NEXT: 0x100A8 R_AARCH64_RELATIVE - 0x5 -// PACKED64-NEXT: 0x100B0 R_AARCH64_RELATIVE - 0x6 -// PACKED64-NEXT: 0x100B8 R_AARCH64_RELATIVE - 0x7 -// PACKED64-NEXT: 0x100C0 R_AARCH64_RELATIVE - 0x8 -// PACKED64-NEXT: 0x100C8 R_AARCH64_RELATIVE - 0x9 - -// PACKED64-NEXT: 0x10048 R_AARCH64_RELATIVE - 0x1 -// PACKED64-NEXT: 0x10050 R_AARCH64_RELATIVE - 0x2 -// PACKED64-NEXT: 0x10058 R_AARCH64_RELATIVE - 0x3 -// PACKED64-NEXT: 0x10060 R_AARCH64_RELATIVE - 0x4 -// PACKED64-NEXT: 0x10068 R_AARCH64_RELATIVE - 0x5 -// PACKED64-NEXT: 0x10070 R_AARCH64_RELATIVE - 0x6 -// PACKED64-NEXT: 0x10078 R_AARCH64_RELATIVE - 0x7 - -// PACKED64-NEXT: 0x10040 R_AARCH64_ABS64 bar2 0x1 -// PACKED64-NEXT: 0x10080 R_AARCH64_ABS64 zed2 0x0 - -// PACKED64-HEADERS: Index: 1 -// PACKED64-HEADERS-NEXT: Name: .dynsym - -// PACKED64-HEADERS: Name: .rela.dyn -// PACKED64-HEADERS-NEXT: Type: SHT_ANDROID_RELA -// PACKED64-HEADERS-NEXT: Flags [ (0x2) -// PACKED64-HEADERS-NEXT: SHF_ALLOC (0x2) -// PACKED64-HEADERS-NEXT: ] -// PACKED64-HEADERS-NEXT: Address: [[ADDR:.*]] -// PACKED64-HEADERS-NEXT: Offset: [[ADDR]] -// PACKED64-HEADERS-NEXT: Size: [[SIZE:.*]] -// PACKED64-HEADERS-NEXT: Link: 1 -// PACKED64-HEADERS-NEXT: Info: 0 -// PACKED64-HEADERS-NEXT: AddressAlignment: 8 -// PACKED64-HEADERS-NEXT: EntrySize: 1 - -// PACKED64-HEADERS: 0x0000000060000011 ANDROID_RELA [[ADDR]] -// PACKED64-HEADERS: 0x0000000060000012 ANDROID_RELASZ [[SIZE]] +// RELR64-NEXT: 0x10088 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10090 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x10098 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x100A0 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x100A8 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x100B0 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x100B8 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x100C0 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: 0x100C8 R_AARCH64_RELATIVE - 0x0 +// RELR64-NEXT: } .data +.align 2 .dc.a __ehdr_start + 1 .dc.a __ehdr_start + 2 .dc.a __ehdr_start + 3 @@ -208,3 +361,5 @@ .dc.a __ehdr_start + 7 .dc.a __ehdr_start + 8 .dc.a __ehdr_start + 9 +.byte 00 +.dc.a __ehdr_start + 10 diff --git a/test/ELF/pack-dyn-relocs2.s b/test/ELF/pack-dyn-relocs2.s new file mode 100644 index 000000000000..20c7176a6061 --- /dev/null +++ b/test/ELF/pack-dyn-relocs2.s @@ -0,0 +1,85 @@ +// REQUIRES: arm, aarch64 + +// 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: 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 -relocations %t.exe | FileCheck %s + +// CHECK: Section (5) .relr.dyn { +// CHECK-NEXT: 0x1000 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1004 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1008 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x100C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1010 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1014 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1018 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x101C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1020 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1024 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1028 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x102C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1030 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1034 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1038 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x103C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1040 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1044 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1048 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x104C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1050 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1054 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1058 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x105C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1060 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1064 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1068 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x106C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1070 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1074 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1078 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x107C R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1080 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: 0x1084 R_ARM_RELATIVE - 0x0 +// CHECK-NEXT: } + +// RUN: llvm-readobj -s -dynamic-table %t.exe | FileCheck --check-prefix=HEADER %s +// HEADER: 0x00000023 RELRSZ 0xC + +.data +.align 2 +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start +.dc.a __ehdr_start diff --git a/test/ELF/pie.s b/test/ELF/pie.s index 5964db5c9399..ccab1623cd5c 100644 --- a/test/ELF/pie.s +++ b/test/ELF/pie.s @@ -48,7 +48,9 @@ # CHECK: Type: PT_DYNAMIC ## Check -nopie -# RUN: ld.lld -nopie %t1.o -o %t2 +# RUN: ld.lld -no-pie %t1.o -o %t2 +# RUN: llvm-readobj -file-headers -r %t2 | FileCheck %s --check-prefix=NOPIE +# RUN: ld.lld -no-pic-executable %t1.o -o %t2 # RUN: llvm-readobj -file-headers -r %t2 | FileCheck %s --check-prefix=NOPIE # NOPIE-NOT: Type: SharedObject diff --git a/test/ELF/plt-aarch64.s b/test/ELF/plt-aarch64.s index 372186b4b1f4..8f637bf593f4 100644 --- a/test/ELF/plt-aarch64.s +++ b/test/ELF/plt-aarch64.s @@ -1,3 +1,4 @@ +// 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 @@ -10,8 +11,6 @@ // 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 -// REQUIRES: aarch64 - // CHECKDSO: Name: .plt // CHECKDSO-NEXT: Type: SHT_PROGBITS // CHECKDSO-NEXT: Flags [ diff --git a/test/ELF/plt-i686.s b/test/ELF/plt-i686.s index 9a2c7f53dc59..c24cab20e769 100644 --- a/test/ELF/plt-i686.s +++ b/test/ELF/plt-i686.s @@ -1,3 +1,4 @@ +// 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 @@ -9,7 +10,6 @@ // RUN: llvm-objdump -d %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 -// REQUIRES: x86 // CHECK: Name: .plt // CHECK-NEXT: Type: SHT_PROGBITS diff --git a/test/ELF/plt.s b/test/ELF/plt.s index 4ab81aaaed91..cce60d732063 100644 --- a/test/ELF/plt.s +++ b/test/ELF/plt.s @@ -1,3 +1,4 @@ +// 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 %p/Inputs/shared.s -o %t2.o // RUN: ld.lld -shared %t2.o -o %t2.so @@ -8,8 +9,6 @@ // RUN: llvm-readobj -s -r %t3 | FileCheck --check-prefix=CHECK2 %s // RUN: llvm-objdump -d %t3 | FileCheck --check-prefix=DISASM2 %s -// REQUIRES: x86 - // CHECK: Name: .plt // CHECK-NEXT: Type: SHT_PROGBITS // CHECK-NEXT: Flags [ diff --git a/test/ELF/ppc-rela.s b/test/ELF/ppc-rela.s new file mode 100644 index 000000000000..430c5a748181 --- /dev/null +++ b/test/ELF/ppc-rela.s @@ -0,0 +1,11 @@ +# 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: 0x1000 R_PPC_ADDR32 foo 0x0 +// CHECK-NEXT: } diff --git a/test/ELF/ppc-relocs.s b/test/ELF/ppc-relocs.s index 5aa3474e6339..26810008bd12 100644 --- a/test/ELF/ppc-relocs.s +++ b/test/ELF/ppc-relocs.s @@ -1,7 +1,7 @@ +# REQUIRES: ppc # RUN: llvm-mc -filetype=obj -triple=powerpc-unknown-freebsd %s -o %t # RUN: ld.lld %t -o %t2 # RUN: llvm-objdump -d %t2 | FileCheck %s -# REQUIRES: ppc .section .R_PPC_ADDR16_HA,"ax",@progbits .globl _start diff --git a/test/ELF/ppc64-abi-version.s b/test/ELF/ppc64-abi-version.s new file mode 100644 index 000000000000..806a71ed8fa1 --- /dev/null +++ b/test/ELF/ppc64-abi-version.s @@ -0,0 +1,11 @@ +# REQUIRES: ppc + +# RUN: echo '.abiversion 1' | llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux - -o %t1.o +# RUN: not ld.lld -o /dev/null %t1.o 2>&1 | FileCheck -check-prefix=ERR1 %s + +# ERR1: ABI version 1 is not supported + +# RUN: echo '.abiversion 3' | llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux - -o %t1.o +# RUN: not ld.lld -o /dev/null %t1.o 2>&1 | FileCheck -check-prefix=ERR2 %s + +# ERR2: unrecognized e_flags: 3 diff --git a/test/ELF/ppc64-addr16-error.s b/test/ELF/ppc64-addr16-error.s index f16ca69957a3..5ffca587d6e5 100644 --- a/test/ELF/ppc64-addr16-error.s +++ b/test/ELF/ppc64-addr16-error.s @@ -1,7 +1,12 @@ +// REQUIRES: ppc + +// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t +// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-addr16-error.s -o %t2 +// RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck %s + // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-addr16-error.s -o %t2 -// RUN: not ld.lld -shared %t %t2 -o %t3 2>&1 | FileCheck %s -// REQUIRES: ppc +// RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck %s .short sym+65539 diff --git a/test/ELF/ppc64-dtprel.s b/test/ELF/ppc64-dtprel.s new file mode 100644 index 000000000000..43922fa80382 --- /dev/null +++ b/test/ELF/ppc64-dtprel.s @@ -0,0 +1,204 @@ +// 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: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: llvm-readelf -relocations --wide %t.so | FileCheck --check-prefix=OutputRelocs %s +// RUN: llvm-objdump -D %t.so | FileCheck --check-prefix=Dis %s +// RUN: llvm-objdump -D %t.so | FileCheck --check-prefix=GotDisLE %s + +// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o +// RUN: ld.lld -shared %t.o -o %t.so +// RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: llvm-readelf -relocations --wide %t.so | FileCheck --check-prefix=OutputRelocs %s +// RUN: llvm-objdump -D %t.so | FileCheck --check-prefix=Dis %s +// RUN: llvm-objdump -D %t.so | FileCheck --check-prefix=GotDisBE %s + + .text + .abiversion 2 + .globl test + .p2align 4 + .type test,@function +test: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry test, .Lfunc_lep0-.Lfunc_gep0 + mflr 0 + std 0, 16(1) + stdu 1, -32(1) + addis 3, 2, i@got@tlsld@ha + addi 3, 3, i@got@tlsld@l + bl __tls_get_addr(i@tlsld) + nop + addi 4, 3, i@dtprel + lwa 4, i@dtprel(3) + ld 0, 16(1) + mtlr 0 + blr + + .globl test_64 + .p2align 4 + .type test_64,@function + + .globl test_adjusted + .p2align 4 + .type test_adjusted,@function +test_adjusted: +.Lfunc_gep1: + addis 2, 12, .TOC.-.Lfunc_gep1@ha + addi 2, 2, .TOC.-.Lfunc_gep1@l +.Lfunc_lep1: + .localentry test_adjusted, .Lfunc_lep1-.Lfunc_gep1 + mflr 0 + std 0, 16(1) + stdu 1, -32(1) + addis 3, 2, k@got@tlsld@ha + addi 3, 3, k@got@tlsld@l + bl __tls_get_addr(k@tlsld) + nop + lis 4, k@dtprel@highesta + ori 4, 4, k@dtprel@highera + lis 5, k@dtprel@ha + addi 5, 5, k@dtprel@l + sldi 4, 4, 32 + or 4, 4, 5 + add 3, 3, 4 + addi 1, 1, 32 + ld 0, 16(1) + mtlr 0 + blr + + .globl test_not_adjusted + .p2align 4 + .type test_not_adjusted,@function +test_not_adjusted: +.Lfunc_gep2: + addis 2, 12, .TOC.-.Lfunc_gep2@ha + addi 2, 2, .TOC.-.Lfunc_gep2@l +.Lfunc_lep2: + .localentry test_not_adjusted, .Lfunc_lep2-.Lfunc_gep2 + mflr 0 + std 0, 16(1) + stdu 1, -32(1) + addis 3, 2, i@got@tlsld@ha + addi 3, 3, i@got@tlsld@l + bl __tls_get_addr(k@tlsld) + nop + lis 4, k@dtprel@highest + ori 4, 4, k@dtprel@higher + sldi 4, 4, 32 + oris 4, 4, k@dtprel@h + ori 4, 4, k@dtprel@l + add 3, 3, 4 + addi 1, 1, 32 + ld 0, 16(1) + mtlr 0 + blr + + .globl test_got_dtprel + .p2align 4 + .type test_got_dtprel,@function +test_got_dtprel: + addis 3, 2, i@got@dtprel@ha + ld 3, i@got@dtprel@l(3) + addis 3, 2, i@got@dtprel@h + addi 3, 2, i@got@dtprel + + .section .debug_addr,"",@progbits + .quad i@dtprel+32768 + + .type i,@object + .section .tdata,"awT",@progbits + .space 1024 + .p2align 2 +i: + .long 55 + .size i, 4 + + .space 1024 * 1024 * 4 + .type k,@object + .p2align 2 +k: + .long 128 + .size k,4 + +// Verify the input has all the remaining DTPREL based relocations we want to +// test. +// InputRelocs: Relocation section '.rela.text' +// InputRelocs: R_PPC64_DTPREL16 {{[0-9a-f]+}} i + 0 +// InputRelocs: R_PPC64_DTPREL16_DS {{[0-9a-f]+}} i + 0 +// InputRelocs: R_PPC64_DTPREL16_HIGHESTA {{[0-9a-f]+}} k + 0 +// InputRelocs: R_PPC64_DTPREL16_HIGHERA {{[0-9a-f]+}} k + 0 +// InputRelocs: R_PPC64_DTPREL16_HA {{[0-9a-f]+}} k + 0 +// InputRelocs: R_PPC64_DTPREL16_LO {{[0-9a-f]+}} k + 0 +// InputRelocs: R_PPC64_DTPREL16_HIGHEST {{[0-9a-f]+}} k + 0 +// InputRelocs: R_PPC64_DTPREL16_HIGHER {{[0-9a-f]+}} k + 0 +// InputRelocs: R_PPC64_DTPREL16_HI {{[0-9a-f]+}} k + 0 +// InputRelocs: R_PPC64_DTPREL16_LO {{[0-9a-f]+}} k + 0 +// InputRelocs: R_PPC64_GOT_DTPREL16_HA {{[0-9a-f]+}} i + 0 +// InputRelocs: R_PPC64_GOT_DTPREL16_LO_DS {{[0-9a-f]+}} i + 0 +// InputRelocs: R_PPC64_GOT_DTPREL16_HI {{[0-9a-f]+}} i + 0 +// InputRelocs: R_PPC64_GOT_DTPREL16_DS {{[0-9a-f]+}} i + 0 +// InputRelocs: Relocation section '.rela.debug_addr' +// InputRelocs: R_PPC64_DTPREL64 {{[0-9a-f]+}} i + 8000 + +// Expect a single dynamic relocation in the '.rela.dyn section for the module id. +// OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 1 entries: +// OutputRelocs-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend +// OutputRelocs-NEXT: R_PPC64_DTPMOD64 + + +// i@dtprel --> (1024 - 0x8000) = -31744 +// Dis: test: +// Dis: addi 4, 3, -31744 +// Dis: lwa 4, -31744(3) + +// #k@dtprel(1024 + 4 + 1024 * 1024 * 4) = 0x400404 + +// #highesta(k@dtprel) --> ((0x400404 - 0x8000 + 0x8000) >> 48) & 0xffff = 0 +// #highera(k@dtprel) --> ((0x400404 - 0x8000 + 0x8000) >> 32) & 0xffff = 0 +// #ha(k@dtprel) --> ((0x400404 - 0x8000 + 0x8000) >> 16) & 0xffff = 64 +// #lo(k@dtprel) --> ((0x400404 - 0x8000) & 0xffff = -31740 +// Dis: test_adjusted: +// Dis: lis 4, 0 +// Dis: ori 4, 4, 0 +// Dis: lis 5, 64 +// Dis: addi 5, 5, -31740 + +// #highest(k@dtprel) --> ((0x400404 - 0x8000) >> 48) & 0xffff = 0 +// #higher(k@dtprel) --> ((0x400404 - 0x8000) >> 32) & 0xffff = 0 +// #hi(k@dtprel) --> ((0x400404 - 0x8000) >> 16) & 0xffff = 63 +// #lo(k@dtprel) --> ((0x400404 - 0x8000) & 0xffff = 33796 +// Dis: test_not_adjusted: +// Dis: lis 4, 0 +// Dis: ori 4, 4, 0 +// Dis: oris 4, 4, 63 +// Dis: ori 4, 4, 33796 + +// Check for GOT entry for i. There should be a got entry which holds the offset +// of i relative to the dynamic thread pointer. +// i@dtprel -> (1024 - 0x8000) = 0xffff8400 +// GotDisBE: Disassembly of section .got: +// GotDisBE: 4204f8: 00 00 00 00 +// GotDisBE: 4204fc: 00 42 84 f8 +// GotDisBE: 420510: ff ff ff ff +// GotDisBE: 420514: ff ff 84 00 + +// GotDisLE: Disassembly of section .got: +// GotDisLE: 4204f8: f8 84 42 00 +// GotDisLE: 420510: 00 84 ff ff +// GotDisLE: 420514: ff ff ff ff + +// Check that we have the correct offset to the got entry for i@got@dtprel +// The got entry for i is 0x420510, and the TOC pointer is 0x4284f8. +// #ha(i@got@dtprel) --> ((0x420510 - 0x4284f8 + 0x8000) >> 16) & 0xffff = 0 +// #lo(i@got@dtprel) --> (0x420510 - 0x4284f8) & 0xffff = -32744 +// #hi(i@got@dtprel) --> ((0x420510 - 0x4284f8) >> 16) & 0xffff = -1 +// i@got@dtprel --> 0x420510 - 0x4284f8 = -32744 +// Dis: test_got_dtprel: +// Dis: addis 3, 2, 0 +// Dis: ld 3, -32744(3) +// Dis: addis 3, 2, -1 +// Dis: addi 3, 2, -32744 diff --git a/test/ELF/ppc64-dynamic-relocations.s b/test/ELF/ppc64-dynamic-relocations.s new file mode 100644 index 000000000000..2d9dfc6f804c --- /dev/null +++ b/test/ELF/ppc64-dynamic-relocations.s @@ -0,0 +1,50 @@ +// REQUIRES: ppc + +// 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: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld %t.o %t2.so -o %t +// RUN: llvm-readobj -dyn-relocations %t | FileCheck %s +// RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=DIS %s +// RUN: llvm-readelf -dynamic-table %t | FileCheck --check-prefix=DT %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: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld %t.o %t2.so -o %t +// RUN: llvm-readobj -dyn-relocations %t | FileCheck %s +// RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=DIS %s +// RUN: llvm-readelf -dynamic-table %t | FileCheck --check-prefix=DT %s + + +// The dynamic relocation for foo should point to 16 bytes past the start of +// the .plt section. +// CHECK: Dynamic Relocations { +// CHECK-NEXT: 0x10030010 R_PPC64_JMP_SLOT foo 0x0 + +// There should be 2 reserved doublewords before the first entry. The dynamic +// linker will fill those in with the address of the resolver entry point and +// the dynamic object identifier. +// DIS: Idx Name Size Address Type +// DIS: .plt 00000018 0000000010030000 BSS + +// DT_PLTGOT should point to the start of the .plt section. +// DT: 0x0000000000000003 PLTGOT 0x10030000 + + .text + .abiversion 2 + .globl _start + .p2align 4 + .type _start,@function +_start: +.Lfunc_begin0: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry _start, .Lfunc_lep0-.Lfunc_gep0 + bl foo + nop + li 0, 1 + sc + .size _start, .-.Lfunc_begin0 diff --git a/test/ELF/ppc64-error-toc-restore.s b/test/ELF/ppc64-error-toc-restore.s new file mode 100644 index 000000000000..19153b730ce1 --- /dev/null +++ b/test/ELF/ppc64-error-toc-restore.s @@ -0,0 +1,20 @@ +// REQUIRES: ppc + +// 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: ld.lld -shared %t2.o -o %t2.so +// RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | 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: ld.lld -shared %t2.o -o %t2.so +// RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | FileCheck %s + +# Calling external function bar needs a nop +// CHECK: call lacks nop, can't restore toc + .text + .abiversion 2 + +.global _start +_start: + bl foo diff --git a/test/ELF/ppc64-error-toc-tail-call.s b/test/ELF/ppc64-error-toc-tail-call.s new file mode 100644 index 000000000000..da8fea26cc23 --- /dev/null +++ b/test/ELF/ppc64-error-toc-tail-call.s @@ -0,0 +1,20 @@ +// REQUIRES: ppc + +// 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: ld.lld -shared %t2.o -o %t2.so +// RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | 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: ld.lld -shared %t2.o -o %t2.so +// RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | FileCheck %s + +# A tail call to an external function without a nop should issue an error. +// CHECK: call lacks nop, can't restore toc + .text + .abiversion 2 + +.global _start +_start: + b foo diff --git a/test/ELF/ppc64-func-entry-points.s b/test/ELF/ppc64-func-entry-points.s new file mode 100644 index 000000000000..640c94fe8cfb --- /dev/null +++ b/test/ELF/ppc64-func-entry-points.s @@ -0,0 +1,80 @@ +// REQUIRES: ppc + +// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o +// 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-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 + + .text + .abiversion 2 + .globl _start # -- Begin function _start + .p2align 4 + .type _start,@function +_start: # @_start +.Lfunc_begin0: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry _start, .Lfunc_lep0-.Lfunc_gep0 +# %bb.0: # %entry + mflr 0 + std 0, 16(1) + stdu 1, -48(1) + li 3, 1 + li 4, 1 + std 30, 32(1) # 8-byte Folded Spill + bl foo_external_same + nop + mr 30, 3 + li 3, 2 + li 4, 2 + bl foo_external_diff + nop + addis 4, 2, .LC0@toc@ha + add 3, 3, 30 + ld 30, 32(1) # 8-byte Folded Reload + ld 4, .LC0@toc@l(4) + lwz 4, 0(4) + add 3, 3, 4 + extsw 3, 3 + addi 1, 1, 48 + ld 0, 16(1) + li 0, 1 + sc + .long 0 + .quad 0 +.Lfunc_end0: + .size _start, .Lfunc_end0-.Lfunc_begin0 + # -- End function + .section .toc,"aw",@progbits +.LC0: + .tc glob[TC],glob + .type glob,@object # @glob + .data + .globl glob + .p2align 2 +glob: + .long 10 # 0xa + .size glob, 4 + +# Check that foo_external_diff has a global entry point and we branch to +# 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, 2 +// CHECK-NEXT: 10010084: {{.*}} addi 2, 2, 32640 +// CHECK-NEXT: 10010088: {{.*}} addis 5, 2, 0 +// CHECK: foo_external_same: +// CHECK-NEXT: 100100b0: {{.*}} add 3, 4, 3 diff --git a/test/ELF/ppc64-gd-to-ie.s b/test/ELF/ppc64-gd-to-ie.s new file mode 100644 index 000000000000..1a6cc5b5f2a0 --- /dev/null +++ b/test/ELF/ppc64-gd-to-ie.s @@ -0,0 +1,104 @@ +# REQUIRES: ppc + +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-tls.s -o %t2.o +# RUN: ld.lld -shared %t2.o -o %t3.so +# RUN: ld.lld %t.o %t3.so -o %t +# RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=CheckGot %s +# RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %s +# RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=OutputRelocs %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-tls.s -o %t2.o +# RUN: ld.lld -shared %t2.o -o %t3.so +# RUN: ld.lld %t.o %t3.so -o %t +# RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=CheckGot %s +# RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %s +# RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=OutputRelocs %s + + .text + .abiversion 2 + .globl _start + .p2align 4 + .type _start,@function +_start: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry _start, .Lfunc_lep0-.Lfunc_gep0 + mflr 0 + std 0, 16(1) + stdu 1, -32(1) + addis 3, 2, a@got@tlsgd@ha + addi 3, 3, a@got@tlsgd@l + bl __tls_get_addr(a@tlsgd) + nop + lwa 3, 0(3) + addi 1, 1, 32 + ld 0, 16(1) + mtlr 0 + blr + + + .globl other_reg + .p2align 4 + .type other_reg,@function +other_reg: +.Lfunc_gep1: + addis 2, 12, .TOC.-.Lfunc_gep1@ha + addi 2, 2, .TOC.-.Lfunc_gep1@l +.Lfunc_lep1: + .localentry other_reg, .Lfunc_lep1-.Lfunc_gep1 + mflr 0 + std 0, 16(1) + stdu 1, -32(1) + addis 5, 2, a@got@tlsgd@ha + addi 3, 5, a@got@tlsgd@l + bl __tls_get_addr(a@tlsgd) + nop + lwa 4, 0(3) + addis 30, 2, b@got@tlsgd@ha + addi 3, 30, b@got@tlsgd@l + bl __tls_get_addr(b@tlsgd) + nop + lwa 3, 0(3) + add 3, 4, 3 + addi 1, 1, 32 + ld 0, 16(1) + mtlr 0 + blr + + .globl __tls_get_addr + .type __tls_get_addr,@function +__tls_get_addr: + + +# CheckGot: .got 00000018 00000000100200c0 DATA +# .got is at 0x100200c0 so the toc-base is 100280c0. +# `a` is at .got[1], we expect the offsets to be: +# Ha(a) = ((0x100200c8 - 0x100280c0) + 0x8000) >> 16 = 0 +# Lo(a) = (0x100200c8 - 0x100280c0) = -32760 + +# Dis-LABEL: _start +# Dis: addis 3, 2, 0 +# Dis-NEXT: ld 3, -32760(3) +# Dis-NEXT: nop +# Dis-NEXT: add 3, 3, 13 + +# Dis-LABEL: other_reg +# Dis: addis 5, 2, 0 +# Dis-NEXT: ld 3, -32760(5) +# Dis-NEXT: nop +# Dis-NEXT: add 3, 3, 13 +# Dis: addis 30, 2, 0 +# Dis: ld 3, -32752(30) +# Dis-NEXT: nop +# Dis-NEXT: add 3, 3, 13 + +# Verify that the only dynamic relocations we emit are TPREL ones rather then +# the DTPMOD64/DTPREL64 pair for general-dynamic. +# OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 2 entries: +# OutputRelocs-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend +# OutputRelocs-NEXT: {{[0-9a-f]+}} {{[0-9a-f]+}} R_PPC64_TPREL64 {{[0-9a-f]+}} a + 0 +# OutputRelocs-NEXT: {{[0-9a-f]+}} {{[0-9a-f]+}} R_PPC64_TPREL64 {{[0-9a-f]+}} b + 0 diff --git a/test/ELF/ppc64-general-dynamic-tls.s b/test/ELF/ppc64-general-dynamic-tls.s new file mode 100644 index 000000000000..66dab936575f --- /dev/null +++ b/test/ELF/ppc64-general-dynamic-tls.s @@ -0,0 +1,112 @@ +// 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: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: llvm-readelf -relocations --wide %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: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: llvm-readelf -relocations --wide %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 + + .text + .abiversion 2 + .globl test + .p2align 4 + .type test,@function +test: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry test, .Lfunc_lep0-.Lfunc_gep0 + mflr 0 + std 31, -8(1) + std 0, 16(1) + stdu 1, -48(1) + mr 31, 1 + std 30, 32(31) + addis 3, 2, i@got@tlsgd@ha + addi 3, 3, i@got@tlsgd@l + bl __tls_get_addr(i@tlsgd) + nop + lwz 30, 0(3) + extsw 3, 30 + ld 30, 32(31) + addi 1, 1, 48 + ld 0, 16(1) + ld 31, -8(1) + mtlr 0 + blr + + +test_hi: +.Lfunc_gep1: + addis 2, 12, .TOC.-.Lfunc_gep1@ha + addi 2, 2, .TOC.-.Lfunc_gep1@l +.Lfunc_lep1: + .localentry test2, .Lfunc_lep1-.Lfunc_gep1 + addis 3, 0, j@got@tlsgd@h + blr + +test_16: +.Lfunc_gep2: + addis 2, 12, .TOC.-.Lfunc_gep2@ha + addi 2, 2, .TOC.-.Lfunc_gep2@l +.Lfunc_lep2: + .localentry test16, .Lfunc_lep2-.Lfunc_gep2 + addi 3, 0, k@got@tlsgd + blr + +// Verify that the input has every general-dynamic tls relocation type. +// InputRelocs: Relocation section '.rela.text' +// InputRelocs: R_PPC64_GOT_TLSGD16_HA {{0+}} i + 0 +// InputRelocs: R_PPC64_GOT_TLSGD16_LO {{0+}} i + 0 +// InputRelocs: R_PPC64_TLSGD {{0+}} i + 0 +// InputRelocs: R_PPC64_GOT_TLSGD16_HI {{0+}} j + 0 +// InputRelocs: R_PPC64_GOT_TLSGD16 {{0+}} k + 0 + +// There is 2 got entries for each tls variable that is accessed with the +// general-dynamic model. The entries can be though of as a structure to be +// filled in by the dynamic linker: +// typedef struct { +// unsigned long int ti_module; --> R_PPC64_DTPMOD64 +// unsigned long int ti_offset; --> R_PPC64_DTPREL64 +//} tls_index; +// OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 6 entries: +// OutputRelocs: R_PPC64_DTPMOD64 {{0+}} i + 0 +// OutputRelocs: R_PPC64_DTPREL64 {{0+}} i + 0 +// OutputRelocs: R_PPC64_DTPMOD64 {{0+}} j + 0 +// OutputRelocs: R_PPC64_DTPREL64 {{0+}} j + 0 +// OutputRelocs: R_PPC64_DTPMOD64 {{0+}} k + 0 +// OutputRelocs: R_PPC64_DTPREL64 {{0+}} k + 0 + +// Check that the got has 7 entires. (1 for the TOC and 3 structures of +// 2 entries for the tls variables). Also verify the address so we can check +// the offsets we calculated for each relocation type. +// CheckGot: got 00000038 00000000000200f0 + +// got starts at 0x200f0, so .TOC. will be 0x280f0. + +// We are building the address of the first tls_index in the got which starts at +// 0x200f8 (got[1]). +// #ha(i@got@tlsgd) --> (0x200f8 - 0x280f0 + 0x8000) >> 16 = 0 +// #lo(i@got@tlsgd) --> (0x200f8 - 0x280f0) & 0xFFFF = -7ff8 = -32760 +// Dis: test: +// Dis: addis 3, 2, 0 +// Dis: addi 3, 3, -32760 + +// Second tls_index starts at got[3]. +// #hi(j@got@tlsgd) --> (0x20108 - 0x280f0) >> 16 = -1 +// Dis: test_hi: +// Dis: lis 3, -1 + +// Third tls index is at got[5]. +// k@got@tlsgd --> (0x20118 - 0x280f0) = -0x7fd8 = -32728 +// Dis: test_16: +// Dis: li 3, -32728 diff --git a/test/ELF/ppc64-got-indirect.s b/test/ELF/ppc64-got-indirect.s new file mode 100644 index 000000000000..2837582c4d6b --- /dev/null +++ b/test/ELF/ppc64-got-indirect.s @@ -0,0 +1,115 @@ +# REQUIRES: ppc + +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o +# RUN: llvm-readobj -relocations %t.o | FileCheck -check-prefix=RELOCS-LE %s +# RUN: ld.lld %t.o -o %t2 +# RUN: llvm-objdump -D %t2 | FileCheck %s --check-prefix=CHECK-LE +# RUN: llvm-objdump -D %t2 | FileCheck %s + +# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o +# RUN: llvm-readobj -relocations %t.o | FileCheck -check-prefix=RELOCS-BE %s +# RUN: ld.lld %t.o -o %t2 +# RUN: llvm-objdump -D %t2 | FileCheck %s --check-prefix=CHECK-BE +# RUN: llvm-objdump -D %t2 | FileCheck %s + +# Make sure we calculate the offset correctly for a got-indirect access to a +# global variable as described by the PPC64 ELF V2 abi. + .text + .abiversion 2 + .globl _start # -- Begin function _start + .p2align 4 + .type _start,@function +_start: # @_start +.Lfunc_begin0: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry _start, .Lfunc_lep0-.Lfunc_gep0 +# %bb.0: # %entry + addis 3, 2, .LC0@toc@ha + ld 3, .LC0@toc@l(3) + li 4, 0 + stw 4, -12(1) + li 0,1 + lwa 3, 0(3) + sc + .long 0 + .quad 0 +.Lfunc_end0: + .size _start, .Lfunc_end0-.Lfunc_begin0 + # -- End function + .section .toc,"aw",@progbits +.LC0: + .tc glob[TC],glob + .type glob,@object # @glob + .data + .globl glob + .p2align 2 +glob: + .long 55 # 0x37 + .size glob, 4 + +# Verify the relocations emitted for glob are through the .toc + +# RELOCS-LE: Relocations [ +# RELOCS-LE: .rela.text { +# RELOCS-LE: 0x0 R_PPC64_REL16_HA .TOC. 0x0 +# RELOCS-LE: 0x4 R_PPC64_REL16_LO .TOC. 0x4 +# RELOCS-LE: 0x8 R_PPC64_TOC16_HA .toc 0x0 +# RELOCS-LE: 0xC R_PPC64_TOC16_LO_DS .toc 0x0 +# RELOCS-LE: } +# RELOCS-LE: .rela.toc { +# RELOCS-LE: 0x0 R_PPC64_ADDR64 glob 0x0 +# RELOCS-LE: } + +# RELOCS-BE: Relocations [ +# RELOCS-BE: .rela.text { +# RELOCS-BE: 0x2 R_PPC64_REL16_HA .TOC. 0x2 +# RELOCS-BE: 0x6 R_PPC64_REL16_LO .TOC. 0x6 +# RELOCS-BE: 0xA R_PPC64_TOC16_HA .toc 0x0 +# RELOCS-BE: 0xE R_PPC64_TOC16_LO_DS .toc 0x0 +# RELOCS-BE: } +# RELOCS-BE: .rela.toc { +# RELOCS-BE: 0x0 R_PPC64_ADDR64 glob 0x0 +# RELOCS-BE: } +# RELOCS-BE:] + +# Verify that the global variable access is done through the correct +# toc entry: +# r2 = .TOC. = 0x10038000. +# r3 = r2 - 32760 = 0x10030008 -> .toc entry for glob. + +# CHECK: _start: +# CHECK-NEXT: 10010000: {{.*}} addis 2, 12, 3 +# CHECK-NEXT: 10010004: {{.*}} addi 2, 2, -32768 +# CHECK-NEXT: 10010008: {{.*}} addis 3, 2, 0 +# CHECK-NEXT: 1001000c: {{.*}} ld 3, -32760(3) +# CHECK: 1001001c: {{.*}} lwa 3, 0(3) + +# CHECK-LE: Disassembly of section .data: +# CHECK-LE-NEXT: glob: +# CHECK-LE-NEXT: 10020000: 37 00 00 00 + +# CHECK-LE: Disassembly of section .got: +# CHECK-LE-NEXT: .got: +# CHECK-LE-NEXT: 10030000: 00 80 03 10 +# CHECK-LE-NEXT: 10030004: 00 00 00 00 + +# Verify that .toc comes right after .got +# CHECK-LE: Disassembly of section .toc: +# CHECK-LE: 10030008: 00 00 02 10 + +# CHECK-BE: Disassembly of section .data: +# CHECK-BE-NEXT: glob: +# CHECK-BE-NEXT: 10020000: 00 00 00 37 + +# CHECK-BE: Disassembly of section .got: +# CHECK-BE-NEXT: .got: +# CHECK-BE-NEXT: 10030000: 00 00 00 00 +# CHECK-BE-NEXT: 10030004: 10 03 80 00 + +# Verify that .toc comes right after .got +# CHECK-BE: Disassembly of section .toc: +# CHECK-BE: 10030008: 00 00 00 00 +# CHECK-BE: 1003000c: 10 02 00 00 diff --git a/test/ELF/ppc64-ifunc.s b/test/ELF/ppc64-ifunc.s new file mode 100644 index 000000000000..6f2d3318b9c2 --- /dev/null +++ b/test/ELF/ppc64-ifunc.s @@ -0,0 +1,87 @@ +# REQUIRES: ppc + +# 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: ld.lld -shared %t2.o -o %t2.so +# RUN: ld.lld %t.o %t2.so -o %t +# RUN: llvm-objdump -D %t | FileCheck %s +# RUN: llvm-readelf -dynamic-table %t | FileCheck --check-prefix=DT %s +# RUN: llvm-readelf -dyn-relocations %t | FileCheck --check-prefix=DYNREL %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: ld.lld -shared %t2.o -o %t2.so +# RUN: ld.lld %t.o %t2.so -o %t +# RUN: llvm-objdump -D %t | FileCheck %s +# RUN: llvm-readelf -dynamic-table %t | FileCheck --check-prefix=DT %s +# RUN: llvm-readelf -dyn-relocations %t | FileCheck --check-prefix=DYNREL %s + +# CHECK: Disassembly of section .text: + +# Tocbase + (0 << 16) + 32560 +# 0x100280e0 + 0 + 32560 = 0x10030010 (.plt[2]) +# CHECK: __plt_foo: +# CHECK-NEXT: std 2, 24(1) +# CHECK-NEXT: addis 12, 2, 0 +# CHECK-NEXT: ld 12, 32560(12) +# CHECK-NEXT: mtctr 12 +# CHECK-NEXT: bctr + +# Tocbase + (0 << 16) + 32568 +# 0x100280e0 + 0 + 32568 = 0x1003018 (.plt[3]) +# CHECK: __plt_ifunc: +# CHECK-NEXT: std 2, 24(1) +# CHECK-NEXT: addis 12, 2, 0 +# CHECK-NEXT: ld 12, 32568(12) +# CHECK-NEXT: mtctr 12 +# CHECK-NEXT: bctr + +# CHECK: ifunc: +# CHECK-NEXT: 10010028: {{.*}} nop + +# CHECK: _start: +# CHECK-NEXT: addis 2, 12, 2 +# CHECK-NEXT: addi 2, 2, -32588 +# CHECK-NEXT: bl .+67108812 +# CHECK-NEXT: ld 2, 24(1) +# CHECK-NEXT: bl .+67108824 +# CHECK-NEXT: ld 2, 24(1) + +# Check tocbase +# CHECK: Disassembly of section .got: +# CHECK-NEXT: .got: +# CHECK-NEXT: 100200e0 + +# Check .plt address +# DT_PLTGOT should point to the start of the .plt section. +# DT: 0x0000000000000003 PLTGOT 0x10030000 + +# Check that we emit the correct dynamic relocation type for an ifunc +# DYNREL: 'PLT' relocation section at offset 0x{{[0-9a-f]+}} contains 48 bytes: +# 48 bytes --> 2 Elf64_Rela relocations +# DYNREL-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend +# DYNREL-NEXT: {{[0-9a-f]+}} {{[0-9a-f]+}} R_PPC64_JMP_SLOT {{0+}} foo + 0 +# DYNREL-NEXT: {{[0-9a-f]+}} {{[0-9a-f]+}} R_PPC64_IRELATIVE 10010028 + + + .text + .abiversion 2 + +.type ifunc STT_GNU_IFUNC +.globl ifunc +ifunc: + nop + + .global _start + .type _start,@function + +_start: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry _start, .Lfunc_lep0-.Lfunc_gep0 + bl foo + nop + bl ifunc + nop diff --git a/test/ELF/ppc64-initial-exec-tls.s b/test/ELF/ppc64-initial-exec-tls.s new file mode 100644 index 000000000000..5218b68828ee --- /dev/null +++ b/test/ELF/ppc64-initial-exec-tls.s @@ -0,0 +1,102 @@ +// REQUIRES: ppc + +// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-tls.s -o %t2.o +// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.so -o %t +// RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=OutputRelocs %s +// RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=CheckGot %s +// RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %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-tls.s -o %t2.o +// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.so -o %t +// RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=OutputRelocs %s +// RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=CheckGot %s +// RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %s + + .text + .abiversion 2 + .file "intial_exec.c" + .globl test_initial_exec # -- Begin function test_initial_exec + .p2align 4 + .type test_initial_exec,@function +test_initial_exec: # @test_initial_exec +.Lfunc_begin0: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry test_initial_exec, .Lfunc_lep0-.Lfunc_gep0 +# %bb.0: # %entry + li 3, 0 + stw 3, -12(1) + addis 3, 2, a@got@tprel@ha + ld 3, a@got@tprel@l(3) + lwzx 4, 3, a@tls + extsw 3, 4 + blr + + +test_hi: +.Lfunc_gep1: + addis 2, 12, .TOC.-.Lfunc_gep1@ha + addi 2, 2, .TOC.-.Lfunc_gep1@l +.Lfunc_lep1: + .localentry test2, .Lfunc_lep1-.Lfunc_gep1 + addis 3, 0, b@got@tprel@h + blr + +test_ds: +.Lfunc_gep2: + addis 2, 12, .TOC.-.Lfunc_gep2@ha + addi 2, 2, .TOC.-.Lfunc_gep2@l +.Lfunc_lep2: + .localentry test16, .Lfunc_lep2-.Lfunc_gep2 + addi 3, 0, c@got@tprel + blr + +// Verify that the input has every initial-exec tls relocation type. +// InputRelocs: Relocation section '.rela.text' +// InputRelocs: R_PPC64_GOT_TPREL16_HA {{0+}} a + 0 +// InputRelocs: R_PPC64_GOT_TPREL16_LO_DS {{0+}} a + 0 +// InputRelocs: R_PPC64_TLS {{0+}} a + 0 +// InputRelocs: R_PPC64_GOT_TPREL16_HI {{0+}} b + 0 +// InputRelocs: R_PPC64_GOT_TPREL16_DS {{0+}} c + 0 + +// There is a got entry for each tls variable that is accessed with the +// initial-exec model to be filled in by the dynamic linker. +// OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 3 entries: +// OutputRelocs: R_PPC64_TPREL64 {{0+}} a + 0 +// OutputRelocs: R_PPC64_TPREL64 {{0+}} b + 0 +// OutputRelocs: R_PPC64_TPREL64 {{0+}} c + 0 + +// Check that the got has 4 entires. (1 for the TOC and 3 entries for TLS +// variables). Also verify the address so we can check +// the offsets we calculated for each relocation type. +// CheckGot: got 00000020 00000000100200c0 + +// GOT stats at 0x100200c0, so TOC will be 0x100280c0 + +// We are building the address of the first TLS got entry which contains the +// offset of the tls variable relative to the thread pointer. +// 0x100200c8 (got[1]). +// #ha(a@got@tprel) --> (0x100200c8 - 0x100280c0 + 0x8000) >> 16 = 0 +// #lo(a@got@tprel)) --> (0x100200c8 - 0x100280c0) & 0xFFFF = -7ff8 = -32760 +// Dis: test_initial_exec: +// Dis: addis 3, 2, 0 +// Dis: ld 3, -32760(3) +// Dis: lwzx 4, 3, 13 + +// Second TLS got entry starts at got[2] 0x100200d0 +// #hi(b@got@tprel) --> (0x100200d0 - 0x100280c0) >> 16 = -1 +// Dis: test_hi: +// Dis: lis 3, -1 + +// Third TLS got entry starts at got[3] 0x100200d8. +// c@got@tprel--> (0x100200d8. - 0x100280c0) = -0x7fe8 = 32744 +// Dis: test_ds: +// Dis: li 3, -32744 diff --git a/test/ELF/ppc64-local-dynamic.s b/test/ELF/ppc64-local-dynamic.s new file mode 100644 index 000000000000..57f324edbc63 --- /dev/null +++ b/test/ELF/ppc64-local-dynamic.s @@ -0,0 +1,128 @@ +// 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: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: llvm-readelf -relocations --wide %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: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: llvm-readelf -relocations --wide %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 + + .text + .abiversion 2 + .globl test + .p2align 4 + .type test,@function +test: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry test, .Lfunc_lep0-.Lfunc_gep0 + mflr 0 + std 0, 16(1) + stdu 1, -32(1) + addis 3, 2, i@got@tlsld@ha + addi 3, 3, i@got@tlsld@l + bl __tls_get_addr(i@tlsld) + nop + addis 3, 3, i@dtprel@ha + lwa 3, i@dtprel@l(3) + ld 0, 16(1) + mtlr 0 + blr + + .globl test_hi + .p2align 4 + .type test_hi,@function +test_hi: + lis 3, j@got@tlsld@h + blr + + .globl test_16 + .p2align 4 + .type test_16,@function +test_16: + li 3, k@got@tlsld + blr + + .type i,@object + .section .tdata,"awT",@progbits + .p2align 2 +i: + .long 55 + .size i, 4 + + .type j,@object + .section .tbss,"awT",@nobits + .p2align 2 +j: + .long 0 + .size j, 4 + + .type k,@object + .section .tdata,"awT",@progbits + .p2align 3 +k: + .quad 66 + .size k, 8 + +// Verify that the input contains all the R_PPC64_GOT_TLSLD16* relocations, as +// well as the DTPREL relocations used in a typical medium code model +// local-dynamic variable access. +// InputRelocs: Relocation section '.rela.text' +// InputRelocs: R_PPC64_GOT_TLSLD16_HA {{[0-9a-f]+}} i + 0 +// InputRelocs: R_PPC64_GOT_TLSLD16_LO {{[0-9a-f]+}} i + 0 +// InputRelocs: R_PPC64_TLSLD {{[0-9a-f]+}} i + 0 +// InputRelocs: R_PPC64_DTPREL16_HA {{[0-9a-f]+}} i + 0 +// InputRelocs: R_PPC64_DTPREL16_LO_DS {{[0-9a-f]+}} i + 0 +// InputRelocs: R_PPC64_GOT_TLSLD16_HI {{[0-9a-f]+}} j + 0 +// InputRelocs: R_PPC64_GOT_TLSLD16 {{[0-9a-f]+}} k + 0 + +// The local dynamic version of tls needs to use the same mechanism to look up +// a variables address as general-dynamic. ie a call to __tls_get_addr with the +// address of a tls_index struct as the argument. However for local-dynamic +// variables all will have the same ti_module, and the offset field is left as +// as 0, so the same struct can be used for every local-dynamic variable +// used in the shared-object. +// OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 1 entries: +// OutputRelocs-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend +// OutputRelocs-NEXT: R_PPC64_DTPMOD64 + +// Check that the got has 3 entries, 1 for the TOC and 1 stucture of 2 entries +// for the tls variables. Also verify the address so we can check the offsets +// we calculate for each relocation type. +// CheckGot: got 00000018 0000000000020100 + +// got starts at 0x20100 so .TOC. will be 0x28100, and the tls_index struct is +// at 0x20108. + +// #ha(i@got@tlsld) --> (0x20108 - 0x28100 + 0x8000) >> 16 = 0 +// #lo(i@got@tlsld) --> (0x20108 - 0x28100) = -7ff8 = -32760 +// When calculating offset relative to the dynamic thread pointer we have to +// adjust by 0x8000 since each DTV pointer points 0x8000 bytes past the start of +// its TLS block. +// #ha(i@dtprel) --> (0x0 -0x8000 + 0x8000) >> 16 = 0 +// #lo(i@dtprel) --> (0x0 -0x8000) = -0x8000 = -32768 +// Dis: test: +// Dis: addis 3, 2, 0 +// Dis-NEXT: addi 3, 3, -32760 +// Dis-NEXT: bl .+67108804 +// Dis-NEXT: ld 2, 24(1) +// Dis-NEXT: addis 3, 3, 0 +// Dis-NEXT: lwa 3, -32768(3) + + +// #hi(j@got@tlsld) --> (0x20108 - 0x28100 ) > 16 = -1 +// Dis: test_hi: +// Dis: lis 3, -1 + +// k@got@tlsld --> (0x20108 - 0x28100) = -7ff8 = -32760 +// Dis: test_16: +// Dis: li 3, -32760 diff --git a/test/ELF/ppc64-local-exec-tls.s b/test/ELF/ppc64-local-exec-tls.s new file mode 100644 index 000000000000..ff8c2b90102c --- /dev/null +++ b/test/ELF/ppc64-local-exec-tls.s @@ -0,0 +1,163 @@ +// REQUIRES: ppc +// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o +// RUN: ld.lld %t.o -o %t +// RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %s + + .text + .abiversion 2 + .globl test_local_exec # -- Begin function test_local_exec + .p2align 4 + .type test_local_exec,@function +test_local_exec: # @test_local_exec +.Lfunc_begin0: +# %bb.0: # %entry + li 3, 0 + stw 3, -12(1) + addis 3, 13, a@tprel@ha + addi 3, 3, a@tprel@l + ld 3, 0(3) + mr 4, 3 + extsw 3, 4 + blr + .long 0 + .quad 0 +.Lfunc_end0: + .size test_local_exec, .Lfunc_end0-.Lfunc_begin0 + # -- End function +test_tprel: +.Lfunc_gep1: + addis 2, 12, .TOC.-.Lfunc_gep1@ha + addi 2, 2, .TOC.-.Lfunc_gep1@l +.Lfunc_lep1: + .localentry test_tprel, .Lfunc_lep1-.Lfunc_gep1 + addi 3, 13, b@tprel + blr + + +test_hi: +.Lfunc_gep2: + addis 2, 12, .TOC.-.Lfunc_gep2@ha + addi 2, 2, .TOC.-.Lfunc_gep2@l +.Lfunc_lep2: + .localentry test_hi, .Lfunc_lep2-.Lfunc_gep2 + addis 3, 13, b@tprel@h + blr + +test_ds: +.Lfunc_gep3: + addis 2, 12, .TOC.-.Lfunc_gep3@ha + addi 2, 2, .TOC.-.Lfunc_gep3@l +.Lfunc_lep3: + .localentry test_ds, .Lfunc_lep3-.Lfunc_gep3 + ld 3, b@tprel, 13 + blr + +test_lo_ds: +.Lfunc_gep4: + addis 2, 12, .TOC.-.Lfunc_gep4@ha + addi 2, 2, .TOC.-.Lfunc_gep4@l +.Lfunc_lep4: + .localentry test_lo_ds, .Lfunc_lep4-.Lfunc_gep4 + ld 3, b@tprel@l, 13 + blr + +test_highest_a: +.Lfunc_gep5: + addis 2, 12, .TOC.-.Lfunc_gep5@ha + addi 2, 2, .TOC.-.Lfunc_gep5@l +.Lfunc_lep5: + .localentry test_highest_a, .Lfunc_lep5-.Lfunc_gep5 + lis 4, b@tprel@highesta + ori 4, 4, b@tprel@highera + lis 5, b@tprel@ha + addi 5, 5, b@tprel@l + sldi 4, 4, 32 + or 4, 4, 5 + add 3, 13, 4 + blr + +test_highest: +.Lfunc_gep6: + addis 2, 12, .TOC.-.Lfunc_gep6@ha + addi 2, 2, .TOC.-.Lfunc_gep6@l +.Lfunc_lep6: + .localentry test_highest, .Lfunc_lep6-.Lfunc_gep6 + lis 4, b@tprel@highest + ori 4, 4, b@tprel@higher + sldi 4, 4, 32 + oris 4, 4, b@tprel@h + ori 4, 4, b@tprel@l + add 3, 13, 4 + blr + + .type a,@object # @a + .type b,@object # @b + .section .tdata,"awT",@progbits + .p2align 3 +a: + .quad 55 # 0x37 + .size a, 8 + +b: + .quad 55 # 0x37 + .size b, 8 + +// Verify that the input has every initial-exec tls relocation type. +// InputRelocs: Relocation section '.rela.text' +// InputRelocs: R_PPC64_TPREL16_HA {{0+}} a + 0 +// InputRelocs: R_PPC64_TPREL16_LO {{0+}} a + 0 +// InputRelocs: R_PPC64_TPREL16 {{0+8}} b + 0 +// InputRelocs: R_PPC64_TPREL16_HI {{0+8}} b + 0 +// InputRelocs: R_PPC64_TPREL16_DS {{0+8}} b + 0 +// InputRelocs: R_PPC64_TPREL16_LO_DS {{0+8}} b + 0 +// InputRelocs: R_PPC64_TPREL16_HIGHESTA {{0+8}} b + 0 +// InputRelocs: R_PPC64_TPREL16_HIGHERA {{0+8}} b + 0 +// InputRelocs: R_PPC64_TPREL16_HIGHEST {{0+8}} b + 0 +// InputRelocs: R_PPC64_TPREL16_HIGHER {{0+8}} b + 0 + +// The start of the TLS storage area is 0x7000 bytes before the thread pointer (r13). +// We are building the address of the first TLS variable, relative to the thread pointer. +// #ha(a@tprel) --> (0 - 0x7000 + 0x8000) >> 16 = 0 +// #lo(a@tprel)) --> (0 - 0x7000) & 0xFFFF = -0x7000 = -28672 +// Dis: test_local_exec: +// Dis: addis 3, 13, 0 +// Dis: addi 3, 3, -28672 + +// We are building the offset for the second TLS variable +// Offset within tls storage - 0x7000 +// b@tprel = 8 - 0x7000 = 28664 +// Dis: test_tprel: +// Dis: addi 3, 13, -28664 + +// #hi(b@tprel) --> (8 - 0x7000) >> 16 = -1 +// Dis: test_hi: +// Dis: addis 3, 13, -1 + +// b@tprel = 8 - 0x7000 = -28664 +// Dis: test_ds: +// Dis: ld 3, -28664(13) + +// #lo(b@tprel) --> (8 - 0x7000) & 0xFFFF = -28664 +// Dis: test_lo_ds: +// Dis: ld 3, -28664(13) + +// #highesta(b@tprel) --> ((0x8 - 0x7000 + 0x8000) >> 48) & 0xFFFF = 0 +// #highera(b@tprel) --> ((0x8 - 0x7000 + 0x8000) >> 32) & 0xFFFF = 0 +// #ha(k@dtprel) --> ((0x8 - 0x7000 + 0x8000) >> 16) & 0xFFFF = 0 +// #lo(k@dtprel) --> ((0x8 - 0x7000) & 0xFFFF = -28664 +// Dis: test_highest_a: +// Dis: lis 4, 0 +// Dis: ori 4, 4, 0 +// Dis: lis 5, 0 +// Dis: addi 5, 5, -28664 + +// #highest(b@tprel) --> ((0x8 - 0x7000) >> 48) & 0xFFFF = 0xFFFF = -1 +// #higher(b@tprel) --> ((0x8 - 0x7000) >> 32) & 0xFFFF = 0xFFFF = 65535 +// #hi(k@dtprel) --> ((0x8 - 0x7000) >> 16) & 0xFFFF = 0xFFFF = 65535 +// #lo(k@dtprel) --> ((0x8 - 0x7000) & 0xFFFF = 33796 +// Dis: test_highest: +// Dis: lis 4, -1 +// Dis: ori 4, 4, 65535 +// Dis: oris 4, 4, 65535 +// Dis: ori 4, 4, 36872 diff --git a/test/ELF/ppc64-plt-stub.s b/test/ELF/ppc64-plt-stub.s new file mode 100644 index 000000000000..a644f487b8be --- /dev/null +++ b/test/ELF/ppc64-plt-stub.s @@ -0,0 +1,42 @@ +// REQUIRES: ppc + +// 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: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld %t.o %t2.so -o %t +// RUN: llvm-objdump -d %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: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld %t.o %t2.so -o %t +// RUN: llvm-objdump -d %t | FileCheck %s + +// CHECK: Disassembly of section .text: +// CHECK-NEXT: __plt_foo: +// CHECK-NEXT: std 2, 24(1) +// CHECK-NEXT: addis 12, 2, 0 +// CHECK-NEXT: ld 12, 32560(12) +// CHECK-NEXT: mtctr 12 +// CHECK-NEXT: bctr + + +// CHECK: _start: +// CHECK: bl .+67108824 + .text + .abiversion 2 + .globl _start + .p2align 4 + .type _start,@function +_start: +.Lfunc_begin0: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry _start, .Lfunc_lep0-.Lfunc_gep0 + bl foo + nop + li 0, 1 + sc + .size _start, .-.Lfunc_begin0 diff --git a/test/ELF/ppc64-rel-calls.s b/test/ELF/ppc64-rel-calls.s index f3b309f33dfb..4c79498dc56b 100644 --- a/test/ELF/ppc64-rel-calls.s +++ b/test/ELF/ppc64-rel-calls.s @@ -1,32 +1,29 @@ +# REQUIRES: ppc + +# 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-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t # RUN: ld.lld %t -o %t2 # RUN: llvm-objdump -d %t2 | FileCheck %s -# REQUIRES: ppc # CHECK: Disassembly of section .text: -.section ".opd","aw" +.text .global _start _start: -.quad .Lfoo,.TOC.@tocbase,0 - -.text .Lfoo: li 0,1 li 3,42 sc -# CHECK: 10010000: 38 00 00 01 li 0, 1 -# CHECK: 10010004: 38 60 00 2a li 3, 42 -# CHECK: 10010008: 44 00 00 02 sc +# CHECK: 10010000: {{.*}} li 0, 1 +# CHECK: 10010004: {{.*}} li 3, 42 +# CHECK: 10010008: {{.*}} sc -.section ".opd","aw" .global bar bar: -.quad .Lbar,.TOC.@tocbase,0 - -.text -.Lbar: bl _start nop bl .Lfoo @@ -34,9 +31,8 @@ bar: blr # FIXME: The printing here is misleading, the branch offset here is negative. -# CHECK: 1001000c: 4b ff ff f5 bl .+67108852 -# CHECK: 10010010: 60 00 00 00 nop -# CHECK: 10010014: 4b ff ff ed bl .+67108844 -# CHECK: 10010018: 60 00 00 00 nop -# CHECK: 1001001c: 4e 80 00 20 blr - +# CHECK: 1001000c: {{.*}} bl .+67108852 +# CHECK: 10010010: {{.*}} nop +# CHECK: 10010014: {{.*}} bl .+67108844 +# CHECK: 10010018: {{.*}} nop +# CHECK: 1001001c: {{.*}} blr diff --git a/test/ELF/ppc64-rel-so-local-calls.s b/test/ELF/ppc64-rel-so-local-calls.s new file mode 100644 index 000000000000..834dbd50aa90 --- /dev/null +++ b/test/ELF/ppc64-rel-so-local-calls.s @@ -0,0 +1,87 @@ +// REQUIRES: ppc + +// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o +// RUN: ld.lld -shared -z notext %t.o -o %t.so +// RUN: llvm-readelf -dyn-relocations %t.so | FileCheck %s + +// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o +// RUN: ld.lld -shared -z notext %t.o -o %t.so +// RUN: llvm-readelf -dyn-relocations %t.so | FileCheck %s + + +// CHECK-NOT: foo +// CHECK-NOT: bar + + .text + .abiversion 2 + .globl baz + .p2align 4 + .type baz,@function +baz: +.Lfunc_begin0: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry baz, .Lfunc_lep0-.Lfunc_gep0 + mflr 0 + std 0, 16(1) + stdu 1, -64(1) + std 30, 48(1) + std 29, 40(1) + mr 30, 3 + bl foo + mr 29, 3 + mr 3, 30 + bl bar + mullw 3, 3, 29 + ld 30, 48(1) + ld 29, 40(1) + extsw 3, 3 + addi 1, 1, 64 + ld 0, 16(1) + mtlr 0 + blr + .long 0 + .quad 0 +.Lfunc_end0: + .size baz, .Lfunc_end0-.Lfunc_begin0 + + .p2align 4 + .type foo,@function +foo: +.Lfunc_begin1: + mullw 3, 3, 3 + extsw 3, 3 + blr + .long 0 + .quad 0 +.Lfunc_end1: + .size foo, .Lfunc_end1-.Lfunc_begin1 + + .p2align 4 + .type bar,@function +bar: +.Lfunc_begin2: +.Lfunc_gep2: + addis 2, 12, .TOC.-.Lfunc_gep2@ha + addi 2, 2, .TOC.-.Lfunc_gep2@l +.Lfunc_lep2: + .localentry bar, .Lfunc_lep2-.Lfunc_gep2 + mflr 0 + std 0, 16(1) + stdu 1, -48(1) + std 30, 32(1) + mr 30, 3 + bl foo + mullw 3, 3, 30 + ld 30, 32(1) + extsw 3, 3 + addi 1, 1, 48 + ld 0, 16(1) + mtlr 0 + blr + .long 0 + .quad 0 +.Lfunc_end2: + .size bar, .Lfunc_end2-.Lfunc_begin2 diff --git a/test/ELF/ppc64-relocs.s b/test/ELF/ppc64-relocs.s index cb6177dfe305..88e3d4b13e5d 100644 --- a/test/ELF/ppc64-relocs.s +++ b/test/ELF/ppc64-relocs.s @@ -1,22 +1,33 @@ +# REQUIRES: ppc + +# 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 --check-prefix=DATALE +# RUN: llvm-objdump -D %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 -# REQUIRES: ppc +# RUN: llvm-objdump -D %t2 | FileCheck %s --check-prefix=DATABE +# RUN: llvm-objdump -D %t2 | FileCheck %s -.section ".opd","aw" +.text .global _start _start: -.quad .Lfoo,.TOC.@tocbase,0 - -.text .Lfoo: li 0,1 li 3,42 sc -.section ".toc","aw" +.section .rodata,"a",@progbits + .p2align 2 +.LJTI0_0: + .long .LBB0_2-.LJTI0_0 + +.section .toc,"aw",@progbits .L1: .quad 22, 37, 89, 47 +.LC0: + .tc .LJTI0_0[TC],.LJTI0_0 .section .R_PPC64_TOC16_LO_DS,"ax",@progbits .globl .FR_PPC64_TOC16_LO_DS @@ -25,7 +36,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_TOC16_LO_DS: # CHECK: .FR_PPC64_TOC16_LO_DS: -# CHECK: 1001000c: e8 22 80 00 ld 1, -32768(2) +# CHECK: 1001000c: {{.*}} ld 1, -32768(2) .section .R_PPC64_TOC16_LO,"ax",@progbits .globl .FR_PPC64_TOC16_LO @@ -34,7 +45,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_TOC16_LO: # CHECK: .FR_PPC64_TOC16_LO: -# CHECK: 10010010: 38 22 80 00 addi 1, 2, -32768 +# CHECK: 10010010: {{.*}} addi 1, 2, -32768 .section .R_PPC64_TOC16_HI,"ax",@progbits .globl .FR_PPC64_TOC16_HI @@ -43,7 +54,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_TOC16_HI: # CHECK: .FR_PPC64_TOC16_HI: -# CHECK: 10010014: 3c 22 ff fe addis 1, 2, -2 +# CHECK: 10010014: {{.*}} addis 1, 2, -1 .section .R_PPC64_TOC16_HA,"ax",@progbits .globl .FR_PPC64_TOC16_HA @@ -52,7 +63,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_TOC16_HA: # CHECK: .FR_PPC64_TOC16_HA: -# CHECK: 10010018: 3c 22 ff ff addis 1, 2, -1 +# CHECK: 10010018: {{.*}} addis 1, 2, 0 .section .R_PPC64_REL24,"ax",@progbits .globl .FR_PPC64_REL24 @@ -63,7 +74,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_REL24: # CHECK: .FR_PPC64_REL24: -# CHECK: 1001001c: 48 00 00 04 b .+4 +# CHECK: 1001001c: {{.*}} b .+4 .section .R_PPC64_ADDR16_LO,"ax",@progbits .globl .FR_PPC64_ADDR16_LO @@ -72,7 +83,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_ADDR16_LO: # CHECK: .FR_PPC64_ADDR16_LO: -# CHECK: 10010020: 38 20 00 00 li 1, 0 +# CHECK: 10010020: {{.*}} li 1, 0 .section .R_PPC64_ADDR16_HI,"ax",@progbits .globl .FR_PPC64_ADDR16_HI @@ -81,7 +92,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_ADDR16_HI: # CHECK: .FR_PPC64_ADDR16_HI: -# CHECK: 10010024: 38 20 10 01 li 1, 4097 +# CHECK: 10010024: {{.*}} li 1, 4097 .section .R_PPC64_ADDR16_HA,"ax",@progbits .globl .FR_PPC64_ADDR16_HA @@ -90,7 +101,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_ADDR16_HA: # CHECK: .FR_PPC64_ADDR16_HA: -# CHECK: 10010028: 38 20 10 01 li 1, 4097 +# CHECK: 10010028: {{.*}} li 1, 4097 .section .R_PPC64_ADDR16_HIGHER,"ax",@progbits .globl .FR_PPC64_ADDR16_HIGHER @@ -99,7 +110,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_ADDR16_HIGHER: # CHECK: .FR_PPC64_ADDR16_HIGHER: -# CHECK: 1001002c: 38 20 00 00 li 1, 0 +# CHECK: 1001002c: {{.*}} li 1, 0 .section .R_PPC64_ADDR16_HIGHERA,"ax",@progbits .globl .FR_PPC64_ADDR16_HIGHERA @@ -108,7 +119,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_ADDR16_HIGHERA: # CHECK: .FR_PPC64_ADDR16_HIGHERA: -# CHECK: 10010030: 38 20 00 00 li 1, 0 +# CHECK: 10010030: {{.*}} li 1, 0 .section .R_PPC64_ADDR16_HIGHEST,"ax",@progbits .globl .FR_PPC64_ADDR16_HIGHEST @@ -117,7 +128,7 @@ _start: # CHECK: Disassembly of section .R_PPC64_ADDR16_HIGHEST: # CHECK: .FR_PPC64_ADDR16_HIGHEST: -# CHECK: 10010034: 38 20 00 00 li 1, 0 +# CHECK: 10010034: {{.*}} li 1, 0 .section .R_PPC64_ADDR16_HIGHESTA,"ax",@progbits .globl .FR_PPC64_ADDR16_HIGHESTA @@ -126,5 +137,57 @@ _start: # CHECK: Disassembly of section .R_PPC64_ADDR16_HIGHESTA: # CHECK: .FR_PPC64_ADDR16_HIGHESTA: -# CHECK: 10010038: 38 20 00 00 li 1, 0 - +# CHECK: 10010038: {{.*}} li 1, 0 + +.section .R_PPC64_REL32, "ax",@progbits +.globl .FR_PPC64_REL32 +.FR_PPC64_REL32: + addis 5, 2, .LC0@toc@ha + ld 5, .LC0@toc@l(5) +.LBB0_2: + add 3, 3, 4 + +# DATALE: Disassembly of section .rodata: +# DATALE: .rodata: +# DATALE: 10000190: b4 fe 00 00 + +# DATABE: Disassembly of section .rodata: +# DATABE: .rodata: +# DATABE: 10000190: 00 00 fe b4 + +# Address of rodata + value stored at rodata entry +# should equal address of LBB0_2. +# 0x10000190 + 0xfeb4 = 0x10010044 +# CHECK: Disassembly of section .R_PPC64_REL32: +# CHECK: .FR_PPC64_REL32: +# CHECK: 1001003c: {{.*}} addis 5, 2, 0 +# CHECK: 10010040: {{.*}} ld 5, -32736(5) +# CHECK: 10010044: {{.*}} add 3, 3, 4 + +.section .R_PPC64_REL64, "ax",@progbits +.globl .FR_PPC64_REL64 +.FR_PPC64_REL64: + .cfi_startproc + .cfi_personality 148, __foo + li 0, 1 + li 3, 55 + sc + .cfi_endproc +__foo: + li 3,0 + +# Check that address of eh_frame entry + value stored +# should equal the address of foo. Since it is not aligned, +# the entry is not stored exactly at 100001a8. It starts at +# address 0x100001aa and has the value 0xfeaa. +# 0x100001aa + 0xfeaa = 0x10010054 +# DATALE: Disassembly of section .eh_frame: +# DATALE: .eh_frame: +# DATALE: 100001a8: {{.*}} aa fe + +# DATABE: Disassembly of section .eh_frame: +# DATABE: .eh_frame: +# DATABE: 100001b0: fe aa {{.*}} + +# CHECK: __foo +# CHECK-NEXT: 10010054: {{.*}} li 3, 0 diff --git a/test/ELF/ppc64-shared-rel-toc.s b/test/ELF/ppc64-shared-rel-toc.s deleted file mode 100644 index 445011bf8e26..000000000000 --- a/test/ELF/ppc64-shared-rel-toc.s +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o -// RUN: ld.lld -shared %t.o -o %t.so -// RUN: llvm-readobj -t -r -dyn-symbols %t.so | FileCheck %s -// REQUIRES: ppc - -// When we create the TOC reference in the shared library, make sure that the -// R_PPC64_RELATIVE relocation uses the correct (non-zero) offset. - - .globl foo - .align 2 - .type foo,@function - .section .opd,"aw",@progbits -foo: # @foo - .align 3 - .quad .Lfunc_begin0 - .quad .TOC.@tocbase - .quad 0 - .text -.Lfunc_begin0: - blr - -// CHECK: 0x20000 R_PPC64_RELATIVE - 0x10000 -// CHECK: 0x20008 R_PPC64_RELATIVE - 0x8000 - -// CHECK: Name: foo -// CHECK-NEXT: Value: 0x20000 - diff --git a/test/ELF/ppc64-tls-gd-le.s b/test/ELF/ppc64-tls-gd-le.s new file mode 100644 index 000000000000..c55ae5f670c1 --- /dev/null +++ b/test/ELF/ppc64-tls-gd-le.s @@ -0,0 +1,83 @@ +// REQUIRES: ppc + +// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o +// RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: ld.lld %t.o -o %t +// RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %s +// RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=OutputRelocs %s + +// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o +// RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: ld.lld %t.o -o %t +// RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %s +// RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=OutputRelocs %s + + .text + .abiversion 2 + .globl _start # -- Begin function _start + .p2align 4 + .type _start,@function +_start: # @_start +.Lfunc_begin0: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry _start, .Lfunc_lep0-.Lfunc_gep0 +# %bb.0: # %entry + mflr 0 + std 31, -8(1) + std 0, 16(1) + stdu 1, -64(1) + mr 31, 1 + std 30, 48(31) # 8-byte Folded Spill + li 3, 0 + stw 3, 44(31) + addis 3, 2, a@got@tlsgd@ha + addi 3, 3, a@got@tlsgd@l + bl __tls_get_addr(a@tlsgd) + nop + lwz 30, 0(3) + extsw 3, 30 + ld 30, 48(31) # 8-byte Folded Reload + addi 1, 1, 64 + ld 0, 16(1) + ld 31, -8(1) + mtlr 0 + blr + .long 0 + .quad 0 +.Lfunc_end0: + .size _start, .Lfunc_end0-.Lfunc_begin0 + +.globl __tls_get_addr +.type __tls_get_addr,@function +__tls_get_addr: + + # -- End function + .type a,@object # @a + .section .tdata,"awT",@progbits + .globl a + .p2align 2 +a: + .long 55 # 0x37 + .size a, 4 + +// Verify that the input has general-dynamic tls relocation types +// InputRelocs: Relocation section '.rela.text' +// InputRelocs: R_PPC64_GOT_TLSGD16_HA {{0+}} a + 0 +// InputRelocs: R_PPC64_GOT_TLSGD16_LO {{0+}} a + 0 +// InputRelocs: R_PPC64_TLSGD {{0+}} a + 0 + +// Verify that the general-dynamic sequence is relaxed to local exec. +// #ha(a@tprel) --> (0 - 0x7000 + 0x8000) >> 16 = 0 +// #lo(a@tprel)) --> (0 - 0x7000) & 0xFFFF = -0x7000 = -28672 +// Dis: _start: +// Dis: nop +// Dis: addis 3, 13, 0 +// Dis: nop +// Dis: addi 3, 3, -28672 + +// Verify that no general-dynamic relocations exist for the dynamic linker. +// OutputRelocs-NOT: R_PPC64_DTPMOD64 +// OutputRelocs-NOT: R_PPC64_DTPREL64 diff --git a/test/ELF/ppc64-tls-ld-le.s b/test/ELF/ppc64-tls-ld-le.s new file mode 100644 index 000000000000..d42d7b983c84 --- /dev/null +++ b/test/ELF/ppc64-tls-ld-le.s @@ -0,0 +1,84 @@ +// REQUIRES: ppc + +// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o +// RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: ld.lld %t.o -o %t +// RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %s +// RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=OutputRelocs %s + +// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o +// RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s +// RUN: ld.lld %t.o -o %t +// RUN: llvm-objdump -D %t | FileCheck --check-prefix=Dis %s +// RUN: llvm-readelf -relocations --wide %t | FileCheck --check-prefix=OutputRelocs %s + + .text + .abiversion 2 + .globl _start # -- Begin function _start + .p2align 4 + .type _start,@function +_start: # @_start +.Lfunc_begin0: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry _start, .Lfunc_lep0-.Lfunc_gep0 +# %bb.0: # %entry + mflr 0 + std 31, -8(1) + std 0, 16(1) + stdu 1, -64(1) + mr 31, 1 + std 30, 48(31) # 8-byte Folded Spill + li 3, 0 + stw 3, 44(31) + addis 3, 2, a@got@tlsld@ha + addi 3, 3, a@got@tlsld@l + bl __tls_get_addr(a@tlsld) + nop + addis 3, 3, a@dtprel@ha + addi 3, 3, a@dtprel@l + lwz 30, 0(3) + extsw 3, 30 + ld 30, 48(31) # 8-byte Folded Reload + addi 1, 1, 64 + ld 0, 16(1) + ld 31, -8(1) + mtlr 0 + blr + .long 0 + .quad 0 +.Lfunc_end0: + .size _start, .Lfunc_end0-.Lfunc_begin0 + # -- End function +.globl __tls_get_addr +.type __tls_get_addr,@function +__tls_get_addr: + .type a,@object # @a + .section .tdata,"awT",@progbits + .p2align 2 +a: + .long 2 # 0x2 + .size a, 4 + +// Verify that the input has local-dynamic tls relocation types +// InputRelocs: Relocation section '.rela.text' +// InputRelocs: R_PPC64_GOT_TLSLD16_HA {{0+}} a + 0 +// InputRelocs: R_PPC64_GOT_TLSLD16_LO {{0+}} a + 0 +// InputRelocs: R_PPC64_TLSLD {{0+}} a + 0 + +// Verify that the local-dynamic sequence is relaxed to local exec. +// Dis: _start: +// Dis: nop +// Dis: addis 3, 13, 0 +// Dis: nop +// Dis: addi 3, 3, 4096 + +// #ha(a@dtprel) --> (0x0 -0x8000 + 0x8000) >> 16 = 0 +// #lo(a@dtprel) --> (0x0 -0x8000) = -0x8000 = -32768 +// Dis: addis 3, 3, 0 +// Dis: addi 3, 3, -32768 + +// Verify that no local-dynamic relocations exist for the dynamic linker. +// OutputRelocs-NOT: R_PPC64_DTPMOD64 diff --git a/test/ELF/ppc64-toc-rel.s b/test/ELF/ppc64-toc-rel.s new file mode 100644 index 000000000000..ac156c78b3a4 --- /dev/null +++ b/test/ELF/ppc64-toc-rel.s @@ -0,0 +1,90 @@ +# REQUIRES: ppc + +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o +# RUN: llvm-readobj -relocations %t.o | FileCheck -check-prefix=RELOCS %s +# RUN: ld.lld %t.o -o %t2 +# RUN: llvm-objdump -D %t2 | FileCheck %s + +# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o +# RUN: llvm-readobj -relocations %t.o | FileCheck -check-prefix=RELOCS-BE %s +# RUN: ld.lld %t.o -o %t2 +# RUN: llvm-objdump -D %t2 | FileCheck -check-prefix=CHECK-BE %s + +# Make sure we calculate the offset correctly for a toc-relative access to a +# global variable as described by the PPC64 Elf V2 abi. +.abiversion 2 + +# int global_a = 55 + .globl global_a + .section ".data" + .align 2 + .type global_a, @object + .size global_a, 4 + .p2align 2 +global_a: + .long 41 + + + .section ".text" + .align 2 + .global _start + .type _start, @function +_start: +.Lfunc_gep0: + addis 2, 12, .TOC.-.Lfunc_gep0@ha + addi 2, 2, .TOC.-.Lfunc_gep0@l +.Lfunc_lep0: + .localentry _start, .Lfunc_lep0-.Lfunc_gep0 + + addis 3, 2, global_a@toc@ha + addi 3, 3, global_a@toc@l + li 0,1 + lwa 3, 0(3) + sc +.size _start,.-_start + +# Verify the relocations that get emitted for the global variable are the +# expected ones. +# RELOCS: Relocations [ +# RELOCS-NEXT: .rela.text { +# RELOCS: 0x8 R_PPC64_TOC16_HA global_a 0x0 +# RELOCS: 0xC R_PPC64_TOC16_LO global_a 0x0 + +# RELOCS-BE: Relocations [ +# RELOCS-BE-NEXT: .rela.text { +# RELOCS-BE: 0xA R_PPC64_TOC16_HA global_a 0x0 +# RELOCS-NE: 0xE R_PPC64_TOC16_LO global_a 0x0 + +# Want to check _start for the values used to build the offset from the TOC base +# to global_a. The .TOC. symbol is expected at address 0x10030000, and the +# TOC base is address-of(.TOC.) + 0x8000. The expected offset is: +# 0x10020000(global_a) - 0x10038000(Toc base) = -0x18000(Offset) +# which gets materialized into r3 as ((-1 << 16) - 32768). + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: _start: +# CHECK: 10010008: {{.*}} addis 3, 2, -1 +# CHECK-NEXT: 1001000c: {{.*}} addi 3, 3, -32768 + +# CHECK: Disassembly of section .data: +# CHECK-NEXT: global_a: +# CHECK-NEXT: 10020000: {{.*}} + +# CHECK: Disassembly of section .got: +# CHECK-NEXT: .got: +# CHECK-NEXT: 10030000: 00 80 03 10 + + +# CHECK-BE: Disassembly of section .text: +# CHECK-BE-NEXT: _start: +# CHECK-BE: 10010008: {{.*}} addis 3, 2, -1 +# CHECK-BE-NEXT: 1001000c: {{.*}} addi 3, 3, -32768 + +# CHECK-BE: Disassembly of section .data: +# CHECK-BE-NEXT: global_a: +# CHECK-BE-NEXT: 10020000: {{.*}} + +# CHECK-BE: Disassembly of section .got: +# CHECK-BE-NEXT: .got: +# CHECK-BE-NEXT: 10030000: 00 00 00 00 +# CHECK-BE-NEXT: 10030004: 10 03 80 00 diff --git a/test/ELF/ppc64-toc-restore.s b/test/ELF/ppc64-toc-restore.s index 0c3d30b2d31a..9efe0e81f5e5 100644 --- a/test/ELF/ppc64-toc-restore.s +++ b/test/ELF/ppc64-toc-restore.s @@ -1,62 +1,72 @@ +// REQUIRES: ppc + +// 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 %t.o %t2.so %t3.o -o %t +// RUN: llvm-objdump -d %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 %t.o %t2.so -o %t +// RUN: ld.lld %t.o %t2.so %t3.o -o %t // RUN: llvm-objdump -d %t | FileCheck %s -// REQUIRES: ppc -// CHECK: Disassembly of section .text: + .text + .abiversion 2 +.global bar_local +bar_local: + li 3, 2 + blr +# Calling external function foo in a shared object needs a nop. +# Calling local function bar_local doe snot need a nop. .global _start _start: - bl bar + bl foo nop + bl bar_local -// CHECK: _start: -// CHECK: 10010000: 48 00 00 21 bl .+32 -// CHECK-NOT: 10010004: 60 00 00 00 nop -// CHECK: 10010004: e8 41 00 28 ld 2, 40(1) - -.global noret -noret: - bl bar - li 5, 7 -// CHECK: noret: -// CHECK: 10010008: 48 00 00 19 bl .+24 -// CHECK: 1001000c: 38 a0 00 07 li 5, 7 - -.global noretend -noretend: - bl bar +// CHECK: Disassembly of section .text: +// CHECK: _start: +// CHECK: 1001001c: {{.*}} bl .+67108836 +// CHECK-NOT: 10010020: {{.*}} nop +// CHECK: 10010020: {{.*}} ld 2, 24(1) +// CHECK: 10010024: {{.*}} bl .+67108848 +// CHECK-NOT: 10010028: {{.*}} nop +// CHECK-NOT: 10010028: {{.*}} ld 2, 24(1) -// CHECK: noretend: -// CHECK: 10010010: 48 00 00 11 bl .+16 +# Calling a function in another object file which will have same +# TOC base does not need a nop. If nop present, do not rewrite to +# a toc restore +.global diff_object +_diff_object: + bl foo_not_shared + bl foo_not_shared + nop -.global noretb -noretb: - b bar +// CHECK: _diff_object: +// CHECK-NEXT: 10010028: {{.*}} bl .+24 +// CHECK-NEXT: 1001002c: {{.*}} bl .+20 +// CHECK-NEXT: 10010030: {{.*}} nop -// CHECK: noretb: -// CHECK: 10010014: 48 00 00 0c b .+12 +# Branching to a local function does not need a nop +.global noretbranch +noretbranch: + b bar_local +// CHECK: noretbranch: +// CHECK: 10010034: {{.*}} b .+67108832 +// CHECK-NOT: 10010038: {{.*}} nop +// CHECK-NOT: 1001003c: {{.*}} ld 2, 24(1) // This should come last to check the end-of-buffer condition. .global last last: - bl bar + bl foo nop - // CHECK: last: -// CHECK: 10010018: 48 00 00 09 bl .+8 -// CHECK: 1001001c: e8 41 00 28 ld 2, 40(1) - -// CHECK: Disassembly of section .plt: -// CHECK: .plt: -// CHECK: 10010020: f8 41 00 28 std 2, 40(1) -// CHECK: 10010024: 3d 62 10 02 addis 11, 2, 4098 -// CHECK: 10010028: e9 8b 80 18 ld 12, -32744(11) -// CHECK: 1001002c: e9 6c 00 00 ld 11, 0(12) -// CHECK: 10010030: 7d 69 03 a6 mtctr 11 -// CHECK: 10010034: e8 4c 00 08 ld 2, 8(12) -// CHECK: 10010038: e9 6c 00 10 ld 11, 16(12) -// CHECK: 1001003c: 4e 80 04 20 bctr +// CHECK: 10010038: {{.*}} bl .+67108808 +// CHECK-NEXT: 1001003c: {{.*}} ld 2, 24(1) diff --git a/test/ELF/ppc64-weak-undef-call-shared.s b/test/ELF/ppc64-weak-undef-call-shared.s index 2c27a27c5a10..db4824762a0f 100644 --- a/test/ELF/ppc64-weak-undef-call-shared.s +++ b/test/ELF/ppc64-weak-undef-call-shared.s @@ -1,7 +1,12 @@ +# 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: llvm-readobj -t -r -dyn-symbols %t.so | FileCheck %s + # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o # RUN: ld.lld -shared %t.o -o %t.so # RUN: llvm-readobj -t -r -dyn-symbols %t.so | FileCheck %s -# REQUIRES: ppc .section ".toc","aw" .quad weakfunc @@ -10,7 +15,7 @@ .text .Lfoo: bl weakfunc + nop // CHECK-NOT: R_PPC64_REL24 .weak weakfunc - diff --git a/test/ELF/ppc64-weak-undef-call.s b/test/ELF/ppc64-weak-undef-call.s index 55443cb55b99..30c168656e20 100644 --- a/test/ELF/ppc64-weak-undef-call.s +++ b/test/ELF/ppc64-weak-undef-call.s @@ -1,17 +1,18 @@ +# REQUIRES: ppc + +# 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-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t # RUN: ld.lld %t -o %t2 # RUN: llvm-objdump -d %t2 | FileCheck %s -# REQUIRES: ppc # CHECK: Disassembly of section .text: -.section ".opd","aw" +.text .global _start _start: -.quad .Lfoo,.TOC.@tocbase,0 - -.text -.Lfoo: bl weakfunc nop blr @@ -22,6 +23,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: 48 00 00 01 bl .+0 -# CHECK: 10010004: 60 00 00 00 nop -# CHECK: 10010008: 4e 80 00 20 blr +# CHECK: 10010000: {{.*}} bl .+0 +# CHECK: 10010004: {{.*}} nop +# CHECK: 10010008: {{.*}} blr diff --git a/test/ELF/ppc64_entry_point.s b/test/ELF/ppc64_entry_point.s new file mode 100644 index 000000000000..a6f426c7eb10 --- /dev/null +++ b/test/ELF/ppc64_entry_point.s @@ -0,0 +1,50 @@ +# REQUIRES: ppc + +# 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-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t +# RUN: ld.lld %t -o %t2 +# RUN: llvm-objdump -D %t2 | FileCheck -check-prefix=CHECK-BE %s + +.text +.abiversion 2 +.globl _start +.p2align 4 +.type _start,@function + +_start: +.Lfunc_begin0: +.Lfunc_gep0: + lis 4, .Lfunc_gep0@ha + addi 4, 4, .Lfunc_gep0@l + # now r4 should contain the address of _start + + lis 5, .TOC.-.Lfunc_gep0@ha + addi 5, 5, .TOC.-.Lfunc_gep0@l + # now r5 should contain the offset s.t. r4 + r5 = TOC base + + # exit 55 + li 0, 1 + li 3, 55 + sc +.Lfunc_end0: + .size _start, .Lfunc_end0-.Lfunc_begin0 + +// CHECK: 10010000: {{.*}} lis 4, 4097 +// CHECK-NEXT: 10010004: {{.*}} addi 4, 4, 0 +// CHECK-NEXT: 10010008: {{.*}} lis 5, 2 +// CHECK-NEXT: 1001000c: {{.*}} addi 5, 5, -32768 +// CHECK: Disassembly of section .got: +// CHECK-NEXT: .got: +// CHECK-NEXT: 10020000: 00 80 02 10 + +// CHECK-BE: 10010000: {{.*}} lis 4, 4097 +// CHECK-BE-NEXT: 10010004: {{.*}} addi 4, 4, 0 +// CHECK-BE-NEXT: 10010008: {{.*}} lis 5, 2 +// CHECK-BE-NEXT: 1001000c: {{.*}} addi 5, 5, -32768 +// CHECK-BE: Disassembly of section .got: +// CHECK-BE-NEXT: .got: +// CHECK-BE-NEXT: 10020000: 00 00 00 00 {{.*}} +// CHECK-BE-NEXT: 10020004: 10 02 80 00 {{.*}} diff --git a/test/ELF/pr34660.s b/test/ELF/pr34660.s index 7c78bbc11c7b..53998ad0f728 100644 --- a/test/ELF/pr34660.s +++ b/test/ELF/pr34660.s @@ -3,7 +3,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-readobj -elf-output-style=GNU %t -t | FileCheck %s --check-prefix=SYM +# RUN: llvm-readelf %t -t | FileCheck %s --check-prefix=SYM # It would be much easier to understand/read this test if llvm-objdump would print # the immediates in hex. diff --git a/test/ELF/pr34872.s b/test/ELF/pr34872.s index c656be2a9279..c6ca81972096 100644 --- a/test/ELF/pr34872.s +++ b/test/ELF/pr34872.s @@ -1,8 +1,9 @@ +# REQUIRES: x86 # RUN: llvm-mc %s -filetype=obj -triple=x86_64-pc-linux -o %t.o # RUN: llvm-mc %p/Inputs/undefined-error.s -filetype=obj \ # RUN: -triple=x86_64-pc-linux -o %t2.o # RUN: ld.lld -shared %t2.o -o %t2.so -# RUN: not ld.lld %t2.so %t.o 2>&1 | FileCheck %s +# RUN: not ld.lld %t2.so %t.o -o /dev/null 2>&1 | FileCheck %s # CHECK: undefined symbol: fmod # Check we're not emitting other diagnostics for this symbol. diff --git a/test/ELF/pr36475.s b/test/ELF/pr36475.s new file mode 100644 index 000000000000..0228974b1c45 --- /dev/null +++ b/test/ELF/pr36475.s @@ -0,0 +1,30 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "PHDRS {" > %t.script +# RUN: echo " ph_text PT_LOAD FLAGS (0x1 | 0x4);" >> %t.script +# RUN: echo " ph_data PT_LOAD FLAGS (0x2 | 0x4);" >> %t.script +# RUN: echo "}" >> %t.script +# RUN: echo "SECTIONS {" >> %t.script +# RUN: echo " .text : { *(.text*) } : ph_text" >> %t.script +# RUN: echo " . = ALIGN(0x4000);" >> %t.script +# RUN: echo " .got.plt : { BYTE(42); *(.got); } : ph_data" >> %t.script +# RUN: echo "}" >> %t.script +# RUN: ld.lld -T %t.script %t.o -o %t.elf +# RUN: llvm-readobj -l -elf-output-style=GNU %t.elf | FileCheck %s + +# CHECK: Section to Segment mapping: +# CHECK-NEXT: Segment Sections... +# CHECK-NEXT: 00 .text executable +# CHECK-NEXT: 01 .got.plt + +.text +.globl _start +.type _start,@function +_start: + callq custom_func + ret + +.section executable,"ax",@progbits +.type custom_func,@function +custom_func: + ret diff --git a/test/ELF/pr37735.s b/test/ELF/pr37735.s new file mode 100644 index 000000000000..7e25d1b6f4df --- /dev/null +++ b/test/ELF/pr37735.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %s -o %t.o +# RUN: ld.lld -r %t.o %t.o -o %t1.o +# RUN: llvm-objdump -s -section=.bar %t1.o | FileCheck %s + +.section .foo + .byte 0 + +# CHECK: Contents of section .bar: +# CHECK-NEXT: 0000 00000000 01000000 +.section .bar + .dc.a .foo diff --git a/test/ELF/pre_init_fini_array.s b/test/ELF/pre_init_fini_array.s index 1192fd0dc851..cf716ab681eb 100644 --- a/test/ELF/pre_init_fini_array.s +++ b/test/ELF/pre_init_fini_array.s @@ -1,10 +1,10 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2 // RUN: ld.lld %t2 -o %t2.so -shared // RUN: ld.lld %t %t2.so -o %t2 // RUN: llvm-readobj -r -symbols -sections -dynamic-table %t2 | FileCheck %s // RUN: llvm-objdump -d %t2 | FileCheck --check-prefix=DISASM %s -// REQUIRES: x86 .globl _start _start: diff --git a/test/ELF/pre_init_fini_array_missing.s b/test/ELF/pre_init_fini_array_missing.s index 7dabfa7a6966..d5b998443a24 100644 --- a/test/ELF/pre_init_fini_array_missing.s +++ b/test/ELF/pre_init_fini_array_missing.s @@ -1,9 +1,9 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t // RUN: ld.lld %t -o %t2 // RUN: llvm-objdump -d %t2 | FileCheck %s // RUN: ld.lld -pie %t -o %t3 // RUN: llvm-objdump -d %t3 | FileCheck --check-prefix=PIE %s -// REQUIRES: x86 .globl _start _start: @@ -14,30 +14,27 @@ _start: call __fini_array_start call __fini_array_end -// With no .init_array section the symbols resolve to 0 -// 0 - (0x201000 + 5) = -2101253 -// 0 - (0x201005 + 5) = -2101258 -// 0 - (0x20100a + 5) = -2101263 -// 0 - (0x20100f + 5) = -2101268 -// 0 - (0x201014 + 5) = -2101273 -// 0 - (0x201019 + 5) = -2101278 +// With no .init_array section the symbols resolve to .text. +// 0x201000 - (0x201000 + 5) = -5 +// 0x201000 - (0x201005 + 5) = -10 +// ... // CHECK: Disassembly of section .text: // CHECK-NEXT: _start: -// CHECK-NEXT: 201000: e8 fb ef df ff callq -2101253 -// CHECK-NEXT: 201005: e8 f6 ef df ff callq -2101258 -// CHECK-NEXT: 20100a: e8 f1 ef df ff callq -2101263 -// CHECK-NEXT: 20100f: e8 ec ef df ff callq -2101268 -// CHECK-NEXT: 201014: e8 e7 ef df ff callq -2101273 -// CHECK-NEXT: 201019: e8 e2 ef df ff callq -2101278 +// CHECK-NEXT: 201000: e8 fb ff ff ff callq -5 +// CHECK-NEXT: 201005: e8 f6 ff ff ff callq -10 +// CHECK-NEXT: 20100a: e8 f1 ff ff ff callq -15 +// CHECK-NEXT: 20100f: e8 ec ff ff ff callq -20 +// CHECK-NEXT: 201014: e8 e7 ff ff ff callq -25 +// CHECK-NEXT: 201019: e8 e2 ff ff ff callq -30 -// In position-independent binaries, they resolve to the image base. +// In position-independent binaries, they resolve to .text too. // PIE: Disassembly of section .text: // PIE-NEXT: _start: -// PIE-NEXT: 1000: e8 fb ef ff ff callq -4101 -// PIE-NEXT: 1005: e8 f6 ef ff ff callq -4106 -// PIE-NEXT: 100a: e8 f1 ef ff ff callq -4111 -// PIE-NEXT: 100f: e8 ec ef ff ff callq -4116 -// PIE-NEXT: 1014: e8 e7 ef ff ff callq -4121 -// PIE-NEXT: 1019: e8 e2 ef ff ff callq -4126 +// PIE-NEXT: 1000: e8 fb ff ff ff callq -5 +// PIE-NEXT: 1005: e8 f6 ff ff ff callq -10 +// PIE-NEXT: 100a: e8 f1 ff ff ff callq -15 +// PIE-NEXT: 100f: e8 ec ff ff ff callq -20 +// PIE-NEXT: 1014: e8 e7 ff ff ff callq -25 +// PIE-NEXT: 1019: e8 e2 ff ff ff callq -30 diff --git a/test/ELF/print-icf.s b/test/ELF/print-icf.s new file mode 100644 index 000000000000..cb6116d51cdc --- /dev/null +++ b/test/ELF/print-icf.s @@ -0,0 +1,48 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/print-icf.s -o %t1 +# RUN: ld.lld %t %t1 -o %t2 --icf=all --print-icf-sections | FileCheck %s +# RUN: ld.lld %t %t1 -o %t2 --icf=all --no-print-icf-sections --print-icf-sections | FileCheck %s +# RUN: ld.lld %t %t1 -o %t2 --icf=all --print-icf-sections --no-print-icf-sections | FileCheck -allow-empty -check-prefix=PRINT %s + +# CHECK: selected section {{.*}}:(.text.f2) +# CHECK: removing identical section {{.*}}:(.text.f4) +# CHECK: removing identical section {{.*}}:(.text.f7) +# CHECK: selected section {{.*}}:(.text.f1) +# CHECK: removing identical section {{.*}}:(.text.f3) +# CHECK: removing identical section {{.*}}:(.text.f5) +# CHECK: removing identical section {{.*}}:(.text.f6) + +# PRINT-NOT: selected +# PRINT-NOT: removing + +.globl _start, f1, f2 +_start: + ret + +.section .text.f1, "ax" +f1: + mov $60, %rax + mov $42, %rdi + syscall + + .section .text.f2, "ax" +f2: + mov $0, %rax + +.section .text.f3, "ax" +f3: + mov $60, %rax + mov $42, %rdi + syscall + +.section .text.f4, "ax" +f4: + mov $0, %rax + +.section .text.f5, "ax" +f5: + mov $60, %rax + mov $42, %rdi + syscall diff --git a/test/ELF/program-header-layout.s b/test/ELF/program-header-layout.s index 57759c946dac..949a96e4f438 100644 --- a/test/ELF/program-header-layout.s +++ b/test/ELF/program-header-layout.s @@ -1,7 +1,7 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: ld.lld %t -o %t2 # RUN: llvm-readobj -sections -program-headers %t2 | FileCheck %s -# REQUIRES: x86 # Check that different output sections with the same flags are merged into a # single Read/Write PT_LOAD. diff --git a/test/ELF/protected-data-access.s b/test/ELF/protected-data-access.s new file mode 100644 index 000000000000..530710751d6b --- /dev/null +++ b/test/ELF/protected-data-access.s @@ -0,0 +1,27 @@ +# REQUIRES: x86 +# RUN: llvm-mc -triple x86_64-pc-linux -filetype=obj %p/Inputs/protected-data-access.s -o %t2.o +# RUN: ld.lld %t2.o -o %t2.so -shared +# RUN: llvm-mc -triple x86_64-pc-linux -filetype=obj %s -o %t.o + +# RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | FileCheck --check-prefix=ERR %s +# ERR: error: cannot preempt symbol: foo + +# RUN: ld.lld --ignore-data-address-equality %t.o %t2.so -o %t +# RUN: llvm-readobj --dyn-symbols --relocations %t | FileCheck %s + +# Check that we have a copy relocation. + +# CHECK: R_X86_64_COPY foo 0x0 + +# CHECK: Name: foo +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Object +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: .bss.rel.ro + +.global _start +_start: + .quad foo + diff --git a/test/ELF/protected-function-access.s b/test/ELF/protected-function-access.s new file mode 100644 index 000000000000..2fa682b412fd --- /dev/null +++ b/test/ELF/protected-function-access.s @@ -0,0 +1,27 @@ +# REQUIRES: x86 +# RUN: llvm-mc -triple x86_64-pc-linux -filetype=obj %p/Inputs/protected-function-access.s -o %t2.o +# RUN: ld.lld %t2.o -o %t2.so -shared +# RUN: llvm-mc -triple x86_64-pc-linux -filetype=obj %s -o %t.o + +# RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | FileCheck --check-prefix=ERR %s +# ERR: error: cannot preempt symbol: foo + +# RUN: ld.lld --ignore-function-address-equality %t.o %t2.so -o %t +# RUN: llvm-readobj --dyn-symbols --relocations %t | FileCheck %s + +# Check that we have a relocation and an undefined symbol with a non zero address + +# CHECK: R_X86_64_JUMP_SLOT foo 0x0 + +# CHECK: Name: foo +# CHECK-NEXT: Value: 0x201020 +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Function +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: Undefined + +.global _start +_start: + .quad foo + diff --git a/test/ELF/push-state.s b/test/ELF/push-state.s new file mode 100644 index 000000000000..5a01cd2eeedd --- /dev/null +++ b/test/ELF/push-state.s @@ -0,0 +1,36 @@ +// REQUIRES: x86 + +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ +// RUN: %p/Inputs/whole-archive.s -o %t2.o +// RUN: rm -f %t.a +// RUN: llvm-ar rcs %t.a %t2.o + +// RUN: ld.lld -o %t.exe -push-state -whole-archive %t.a %t1.o -M | \ +// RUN: FileCheck -check-prefix=WHOLE %s +// WHOLE: _bar + +// RUN: ld.lld -o %t.exe -push-state -whole-archive -pop-state %t.a %t1.o -M | \ +// RUN: FileCheck -check-prefix=NO-WHOLE %s +// NO-WHOLE-NOT: _bar + + +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t3.o +// RUN: ld.lld -shared %t3.o -soname libfoo -o %t.so + +// RUN: ld.lld -o %t.exe -push-state -as-needed %t.so %t1.o +// RUN: llvm-readobj -dynamic-table %t.exe | FileCheck -check-prefix=AS-NEEDED %s +// AS-NEEDED-NOT: NEEDED Shared library: [libfoo] + +// RUN: ld.lld -o %t.exe -push-state -as-needed -pop-state %t.so %t1.o +// RUN: llvm-readobj -dynamic-table %t.exe | FileCheck -check-prefix=NO-AS-NEEDED %s +// NO-AS-NEEDED: NEEDED Shared library: [libfoo] + + +// RUN: mkdir -p %t.dir +// RUN: cp %t.so %t.dir/libfoo.so +// RUN: ld.lld -o %t.exe -L%t.dir -push-state -static -pop-state %t1.o -lfoo +// RUN: not ld.lld -o %t.exe -L%t.dir -push-state -static %t1.o -lfoo + +.globl _start +_start: diff --git a/test/ELF/rel-addend-with-rela-input.s b/test/ELF/rel-addend-with-rela-input.s new file mode 100644 index 000000000000..11eac97ed519 --- /dev/null +++ b/test/ELF/rel-addend-with-rela-input.s @@ -0,0 +1,43 @@ +# REQUIRES: mips +# Check that we correctly write addends if the output use Elf_Rel but the input +# uses Elf_Rela + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t-rela.o +# RUN: llvm-readobj -h -s -section-data -relocations %t-rela.o | FileCheck -check-prefix INPUT-RELA %s +# INPUT-RELA: ElfHeader { +# INPUT-RELA: Class: 64-bit +# INPUT-RELA: DataEncoding: BigEndian +# INPUT-RELA: Section { +# INPUT-RELA: Name: .data +# INPUT-RELA: SectionData ( +# INPUT-RELA-NEXT: 0000: 00000000 00000000 ABCDEF00 12345678 |.............4Vx| +# ^--- No addend here since it uses RELA +# INPUT-RELA: Relocations [ +# INPUT-RELA-NEXT: Section ({{.+}}) .rela.data { +# INPUT-RELA-NEXT: 0x0 R_MIPS_64/R_MIPS_NONE/R_MIPS_NONE foo 0x5544 +# INPUT-RELA-NEXT: } +# INPUT-RELA-NEXT: ] + +# Previously the addend to the dynamic relocation in the .data section was not copied if +# the input file used RELA and the output uses REL. Check that it works now: +# RUN: ld.lld -shared -o %t.so %t-rela.o -verbose +# RUN: llvm-readobj -h -s -section-data -relocations %t.so | FileCheck -check-prefix RELA-TO-REL %s +# RELA-TO-REL: ElfHeader { +# RELA-TO-REL: Class: 64-bit +# RELA-TO-REL: DataEncoding: BigEndian +# RELA-TO-REL: Section { +# RELA-TO-REL: Name: .data +# RELA-TO-REL: SectionData ( +# RELA-TO-REL-NEXT: 0000: 00000000 00005544 ABCDEF00 12345678 |......UD.....4Vx| +# ^--- Addend for relocation in .rel.dyn +# RELA-TO-REL: Relocations [ +# RELA-TO-REL-NEXT: Section ({{.+}}) .rel.dyn { +# RELA-TO-REL-NEXT: 0x10000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE foo 0x0 +# RELA-TO-REL-NEXT: } +# RELA-TO-REL-NEXT: ] + +.extern foo + +.data +.quad foo + 0x5544 +.quad 0xabcdef0012345678 diff --git a/test/ELF/relative-dynamic-reloc-ppc64.s b/test/ELF/relative-dynamic-reloc-ppc64.s index 65d0e8e83984..83190a270048 100644 --- a/test/ELF/relative-dynamic-reloc-ppc64.s +++ b/test/ELF/relative-dynamic-reloc-ppc64.s @@ -1,7 +1,11 @@ +// 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: llvm-readobj -t -r -dyn-symbols %t.so | FileCheck %s + // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o // RUN: ld.lld -shared %t.o -o %t.so // RUN: llvm-readobj -t -r -dyn-symbols %t.so | FileCheck %s -// REQUIRES: ppc // Test that we create R_PPC64_RELATIVE relocations but don't put any // symbols in the dynamic symbol table. diff --git a/test/ELF/relocatable-build-id.s b/test/ELF/relocatable-build-id.s new file mode 100644 index 000000000000..5ac205c2b287 --- /dev/null +++ b/test/ELF/relocatable-build-id.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: ld.lld --build-id=0xcafebabe -o %t2.o %t1.o -r +# RUN: ld.lld --build-id=0xdeadbeef -o %t.exe %t2.o +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK-NOT: cafebabe +# CHECK: deadbeef + +.global _start +_start: + ret diff --git a/test/ELF/relocatable-comdat-multiple.s b/test/ELF/relocatable-comdat-multiple.s index 4c3e7ce7f6d4..bb7a78490fdd 100644 --- a/test/ELF/relocatable-comdat-multiple.s +++ b/test/ELF/relocatable-comdat-multiple.s @@ -8,6 +8,8 @@ # CHECK-NEXT: Group { # CHECK-NEXT: Name: .group # CHECK-NEXT: Index: 2 +# CHECK-NEXT: Link: 8 +# CHECK-NEXT: Info: 1 # CHECK-NEXT: Type: COMDAT # CHECK-NEXT: Signature: aaa # CHECK-NEXT: Section(s) in group [ @@ -18,6 +20,8 @@ # CHECK-NEXT: Group { # CHECK-NEXT: Name: .group # CHECK-NEXT: Index: 5 +# CHECK-NEXT: Link: 8 +# CHECK-NEXT: Info: 6 # CHECK-NEXT: Type: COMDAT # CHECK-NEXT: Signature: bbb # CHECK-NEXT: Section(s) in group [ diff --git a/test/ELF/relocatable-comdat.s b/test/ELF/relocatable-comdat.s index 24504d23884f..11aa30c7e6bd 100644 --- a/test/ELF/relocatable-comdat.s +++ b/test/ELF/relocatable-comdat.s @@ -30,6 +30,8 @@ # CHECK-NEXT: Group { # CHECK-NEXT: Name: .group # CHECK-NEXT: Index: 2 +# CHECK-NEXT: Link: 5 +# CHECK-NEXT: Info: 1 # CHECK-NEXT: Type: COMDAT # CHECK-NEXT: Signature: abc # CHECK-NEXT: Section(s) in group [ diff --git a/test/ELF/relocatable-comdat2.s b/test/ELF/relocatable-comdat2.s index 2643e645fda9..27844feae16e 100644 --- a/test/ELF/relocatable-comdat2.s +++ b/test/ELF/relocatable-comdat2.s @@ -13,6 +13,8 @@ # CHECK-NEXT: Group { # CHECK-NEXT: Name: .group # CHECK-NEXT: Index: 2 +# CHECK-NEXT: Link: 7 +# CHECK-NEXT: Info: 1 # CHECK-NEXT: Type: COMDAT # CHECK-NEXT: Signature: bar # CHECK-NEXT: Section(s) in group [ @@ -22,6 +24,8 @@ # CHECK-NEXT: Group { # CHECK-NEXT: Name: .group # CHECK-NEXT: Index: 4 +# CHECK-NEXT: Link: 7 +# CHECK-NEXT: Info: 2 # CHECK-NEXT: Type: COMDAT # CHECK-NEXT: Signature: zed # CHECK-NEXT: Section(s) in group [ diff --git a/test/ELF/relocatable-eh-frame.s b/test/ELF/relocatable-eh-frame.s index c2e5ec63f865..dee906acb87f 100644 --- a/test/ELF/relocatable-eh-frame.s +++ b/test/ELF/relocatable-eh-frame.s @@ -5,7 +5,7 @@ # RUN: ld.lld %t -o %t.so -shared # RUN: llvm-objdump -h %t.so | FileCheck --check-prefix=DSO %s -# DSO: .eh_frame 00000030 +# DSO: .eh_frame 00000034 # CHECK: Relocations [ # CHECK-NEXT: Section ({{.*}}) .rela.eh_frame { diff --git a/test/ELF/relocatable-many-sections.s b/test/ELF/relocatable-many-sections.s new file mode 100644 index 000000000000..df22154d0c9f --- /dev/null +++ b/test/ELF/relocatable-many-sections.s @@ -0,0 +1,92 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t.o +# RUN: ld.lld -r %t.o -o %t +# RUN: llvm-readobj -file-headers %t | FileCheck %s + +## Check we are able to emit a valid ELF header when +## sections amount is greater than SHN_LORESERVE. +# CHECK: ElfHeader { +# CHECK: SectionHeaderCount: 0 (65541) +# CHECK-NEXT: StringTableSectionIndex: 65535 (65539) + +## Check that 65539 is really the index of .shstrtab section. +# RUN: llvm-objdump -section-headers -section=.shstrtab %t \ +# RUN: | FileCheck %s --check-prefix=SHSTRTAB +# SHSTRTAB: Sections: +# SHSTRTAB-NEXT: Idx Name +# SHSTRTAB-NEXT: 65539 .shstrtab + +.macro gen_sections4 x + .section a\x + .section b\x + .section c\x + .section d\x +.endm + +.macro gen_sections8 x + gen_sections4 a\x + gen_sections4 b\x +.endm + +.macro gen_sections16 x + gen_sections8 a\x + gen_sections8 b\x +.endm + +.macro gen_sections32 x + gen_sections16 a\x + gen_sections16 b\x +.endm + +.macro gen_sections64 x + gen_sections32 a\x + gen_sections32 b\x +.endm + +.macro gen_sections128 x + gen_sections64 a\x + gen_sections64 b\x +.endm + +.macro gen_sections256 x + gen_sections128 a\x + gen_sections128 b\x +.endm + +.macro gen_sections512 x + gen_sections256 a\x + gen_sections256 b\x +.endm + +.macro gen_sections1024 x + gen_sections512 a\x + gen_sections512 b\x +.endm + +.macro gen_sections2048 x + gen_sections1024 a\x + gen_sections1024 b\x +.endm + +.macro gen_sections4096 x + gen_sections2048 a\x + gen_sections2048 b\x +.endm + +.macro gen_sections8192 x + gen_sections4096 a\x + gen_sections4096 b\x +.endm + +.macro gen_sections16384 x + gen_sections8192 a\x + gen_sections8192 b\x +.endm + +gen_sections16384 a +gen_sections16384 b +gen_sections16384 c +gen_sections16384 d + +.global _start +_start: diff --git a/test/ELF/relocatable-symbols.s b/test/ELF/relocatable-symbols.s index 79608e7b74f0..46d8ab7395fc 100644 --- a/test/ELF/relocatable-symbols.s +++ b/test/ELF/relocatable-symbols.s @@ -174,21 +174,33 @@ .global _start .text _start: - call __start_foo - call __stop_foo + .byte 0xe8 + .long __start_foo - . -4 + .byte 0xe8 + .long __stop_foo - . -4 - call __start_bar - call __stop_bar + .byte 0xe8 + .long __start_bar - . -4 + .byte 0xe8 + .long __stop_bar - . -4 - call __start_doo - call __stop_doo + .byte 0xe8 + .long __start_doo - . -4 + .byte 0xe8 + .long __stop_doo - . -4 - call __preinit_array_start - call __preinit_array_end - call __init_array_start - call __init_array_end - call __fini_array_start - call __fini_array_end + .byte 0xe8 + .long __preinit_array_start - . -4 + .byte 0xe8 + .long __preinit_array_end - . -4 + .byte 0xe8 + .long __init_array_start - . -4 + .byte 0xe8 + .long __init_array_end - . -4 + .byte 0xe8 + .long __fini_array_start - . -4 + .byte 0xe8 + .long __fini_array_end - . -4 .section foo,"ax" nop diff --git a/test/ELF/relocatable-versioned.s b/test/ELF/relocatable-versioned.s new file mode 100644 index 000000000000..2b6c49eb5baa --- /dev/null +++ b/test/ELF/relocatable-versioned.s @@ -0,0 +1,9 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: ld.lld -o %t2.o -r %t1.o +# RUN: llvm-nm %t2.o | FileCheck %s +# CHECK: foo@VERSION + +.global "foo@VERSION" +"foo@VERSION": + ret diff --git a/test/ELF/relocation-absolute.s b/test/ELF/relocation-absolute.s index 20d54eca9205..b882987bb694 100644 --- a/test/ELF/relocation-absolute.s +++ b/test/ELF/relocation-absolute.s @@ -1,8 +1,8 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/abs.s -o %tabs // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld %tabs %t -o %tout // RUN: llvm-objdump -d %tout | FileCheck %s -// REQUIRES: x86 .global _start _start: diff --git a/test/ELF/relocation-common.s b/test/ELF/relocation-common.s index 28276bfe0750..71b1ac0e2e24 100644 --- a/test/ELF/relocation-common.s +++ b/test/ELF/relocation-common.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld %t -o %tout // RUN: llvm-objdump -t -d %tout | FileCheck %s -// REQUIRES: x86 .global _start _start: diff --git a/test/ELF/relocation-dtrace.test b/test/ELF/relocation-dtrace.test index ef2cc4956ca6..9007a265bfaa 100644 --- a/test/ELF/relocation-dtrace.test +++ b/test/ELF/relocation-dtrace.test @@ -1,5 +1,5 @@ # RUN: yaml2obj %s -o %t.o -# RUN: ld.lld -shared %t.o -o %t.so +# RUN: ld.lld -shared %t.o -o /dev/null # Test that we can handle R_X86_64_NONE as produced by dtrace. diff --git a/test/ELF/relocation-i686.s b/test/ELF/relocation-i686.s index 3986357d66f2..fdec7caa33be 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 -// REQUIRES: x86 .global _start _start: diff --git a/test/ELF/relocation-local.s b/test/ELF/relocation-local.s index 8173dac0522f..383c5c82f64a 100644 --- a/test/ELF/relocation-local.s +++ b/test/ELF/relocation-local.s @@ -1,8 +1,8 @@ +// REQUIRES: x86 // Test that relocation of local symbols is working. // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld %t -o %t2 // RUN: llvm-objdump -s -d %t2 | FileCheck %s -// REQUIRES: x86 .global _start diff --git a/test/ELF/relocation-nocopy.s b/test/ELF/relocation-nocopy.s index 533277dc8ec3..70e99334796d 100644 --- a/test/ELF/relocation-nocopy.s +++ b/test/ELF/relocation-nocopy.s @@ -2,7 +2,7 @@ // 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/relocation-copy.s -o %t2.o // RUN: ld.lld -shared %t2.o -o %t.so -// RUN: not ld.lld -z nocopyreloc %t.o %t.so -o %t3 2>&1 | FileCheck %s +// RUN: not ld.lld -z nocopyreloc %t.o %t.so -o /dev/null 2>&1 | FileCheck %s // CHECK: unresolvable relocation R_X86_64_32S against symbol 'x' // CHECK: unresolvable relocation R_X86_64_32S against symbol 'y' diff --git a/test/ELF/relocation-non-alloc.s b/test/ELF/relocation-non-alloc.s index 1ad15a4e5787..95166fbe0d4a 100644 --- a/test/ELF/relocation-non-alloc.s +++ b/test/ELF/relocation-non-alloc.s @@ -1,25 +1,47 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +// RUN: ld.lld %t -o %t2 -shared --apply-dynamic-relocs +// RUN: llvm-readobj -s -section-data -r %t2 | FileCheck -check-prefix CHECK -check-prefix APPLYDYNREL %s + // RUN: ld.lld %t -o %t2 -shared -// RUN: llvm-readobj -s -section-data -r %t2 | FileCheck %s +// RUN: llvm-readobj -s -section-data -r %t2 | FileCheck -check-prefix CHECK -check-prefix NOAPPLYDYNREL %s +// RUN: ld.lld %t -o %t2 -shared --no-apply-dynamic-relocs +// RUN: llvm-readobj -s -section-data -r %t2 | FileCheck -check-prefix CHECK -check-prefix NOAPPLYDYNREL %s -// CHECK: Name: .data -// CHECK-NEXT: Type: SHT_PROGBITS -// CHECK-NEXT: Flags [ -// CHECK-NEXT: SHF_ALLOC -// CHECK-NEXT: SHF_WRITE -// CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x1000 -// CHECK-NEXT: Offset: 0x1000 -// CHECK-NEXT: Size: 16 -// CHECK-NEXT: Link: 0 -// CHECK-NEXT: Info: 0 -// CHECK-NEXT: AddressAlignment: 1 -// CHECK-NEXT: EntrySize: 0 -// CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 00000000 00000000 00000000 00000000 -// CHECK-NEXT: ) +// APPLYDYNREL: Name: .data +// APPLYDYNREL-NEXT: Type: SHT_PROGBITS +// APPLYDYNREL-NEXT: Flags [ +// APPLYDYNREL-NEXT: SHF_ALLOC +// APPLYDYNREL-NEXT: SHF_WRITE +// APPLYDYNREL-NEXT: ] +// APPLYDYNREL-NEXT: Address: 0x1000 +// APPLYDYNREL-NEXT: Offset: 0x1000 +// APPLYDYNREL-NEXT: Size: 16 +// APPLYDYNREL-NEXT: Link: 0 +// APPLYDYNREL-NEXT: Info: 0 +// APPLYDYNREL-NEXT: AddressAlignment: 1 +// APPLYDYNREL-NEXT: EntrySize: 0 +// APPLYDYNREL-NEXT: SectionData ( +// APPLYDYNREL-NEXT: 0000: 00100000 00000000 00000000 00000000 +// APPLYDYNREL-NEXT: ) + +// NOAPPLYDYNREL: Name: .data +// NOAPPLYDYNREL-NEXT: Type: SHT_PROGBITS +// NOAPPLYDYNREL-NEXT: Flags [ +// NOAPPLYDYNREL-NEXT: SHF_ALLOC +// NOAPPLYDYNREL-NEXT: SHF_WRITE +// NOAPPLYDYNREL-NEXT: ] +// NOAPPLYDYNREL-NEXT: Address: 0x1000 +// NOAPPLYDYNREL-NEXT: Offset: 0x1000 +// NOAPPLYDYNREL-NEXT: Size: 16 +// NOAPPLYDYNREL-NEXT: Link: 0 +// NOAPPLYDYNREL-NEXT: Info: 0 +// NOAPPLYDYNREL-NEXT: AddressAlignment: 1 +// NOAPPLYDYNREL-NEXT: EntrySize: 0 +// NOAPPLYDYNREL-NEXT: SectionData ( +// NOAPPLYDYNREL-NEXT: 0000: 00000000 00000000 00000000 00000000 +// NOAPPLYDYNREL-NEXT: ) // CHECK: Name: foo // CHECK-NEXT: Type: SHT_PROGBITS diff --git a/test/ELF/relocation-none-aarch64.test b/test/ELF/relocation-none-aarch64.test index dd67c8c0fb2e..e77989a54a83 100644 --- a/test/ELF/relocation-none-aarch64.test +++ b/test/ELF/relocation-none-aarch64.test @@ -1,7 +1,7 @@ # REQUIRES: aarch64 # RUN: yaml2obj %s -o %t.o -# RUN: ld.lld %t.o -o %t.out +# RUN: ld.lld %t.o -o /dev/null !ELF FileHeader: diff --git a/test/ELF/relocation-none-i686.test b/test/ELF/relocation-none-i686.test index d8eed8f7a129..82dc4e608c03 100644 --- a/test/ELF/relocation-none-i686.test +++ b/test/ELF/relocation-none-i686.test @@ -1,5 +1,5 @@ # RUN: yaml2obj %s -o %t.o -# RUN: ld.lld %t.o -o %t.out +# RUN: ld.lld %t.o -o /dev/null # Test that we can handle R_386_NONE. diff --git a/test/ELF/relocation-past-merge-end.s b/test/ELF/relocation-past-merge-end.s index d08bde7b9f6c..a3e7b59a415a 100644 --- a/test/ELF/relocation-past-merge-end.s +++ b/test/ELF/relocation-past-merge-end.s @@ -1,6 +1,6 @@ // REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux -// RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s // CHECK: relocation-past-merge-end.s.tmp.o:(.foo): entry is past the end of the section .data diff --git a/test/ELF/relocation-relative-absolute.s b/test/ELF/relocation-relative-absolute.s index 2a343fddca76..21f50025e92b 100644 --- a/test/ELF/relocation-relative-absolute.s +++ b/test/ELF/relocation-relative-absolute.s @@ -2,7 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %tinput1.o # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux \ # RUN: %S/Inputs/relocation-relative-absolute.s -o %tinput2.o -# RUN: not ld.lld %tinput1.o %tinput2.o -o %t -pie 2>&1 | FileCheck %s +# RUN: not ld.lld %tinput1.o %tinput2.o -o /dev/null -pie 2>&1 | FileCheck %s .globl _start _start: diff --git a/test/ELF/relocation-shared.s b/test/ELF/relocation-shared.s index 4fba7a5683b0..81537cec1ef5 100644 --- a/test/ELF/relocation-shared.s +++ b/test/ELF/relocation-shared.s @@ -8,7 +8,7 @@ // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x1C8 +// CHECK-NEXT: Address: 0x20D // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 8 // CHECK-NEXT: Link: 0 @@ -16,8 +16,8 @@ // CHECK-NEXT: AddressAlignment: 1 // CHECK-NEXT: EntrySize: 0 // CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 380E0000 00000000 -// 0x1000 - 0x1C8 = 0xE38 +// CHECK-NEXT: 0000: F30D0000 00000000 +// 0x1000 - 0x20D = 0xDF3 // CHECK-NEXT: ) // CHECK: Name: .text diff --git a/test/ELF/relocation-size-err.s b/test/ELF/relocation-size-err.s new file mode 100644 index 000000000000..8783fe9568da --- /dev/null +++ b/test/ELF/relocation-size-err.s @@ -0,0 +1,12 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s + +// CHECK: error: can't create dynamic relocation R_X86_64_SIZE64 against symbol: foo in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output + + .global foo +foo: + .quad 42 + .size foo, 8 + + .quad foo@SIZE diff --git a/test/ELF/relocation-size-shared.s b/test/ELF/relocation-size-shared.s index cea9e64d58ed..f60f0929e705 100644 --- a/test/ELF/relocation-size-shared.s +++ b/test/ELF/relocation-size-shared.s @@ -1,3 +1,4 @@ +// 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 %p/Inputs/relocation-size-shared.s -o %tso.o // RUN: ld.lld -shared %tso.o -o %tso diff --git a/test/ELF/relocation-size.s b/test/ELF/relocation-size.s index 419b8a17fad9..525b1e1d1331 100644 --- a/test/ELF/relocation-size.s +++ b/test/ELF/relocation-size.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o // RUN: ld.lld %t.o -o %t1 // RUN: llvm-readobj -r %t1 | FileCheck --check-prefix=NORELOC %s diff --git a/test/ELF/relocation-undefined-weak.s b/test/ELF/relocation-undefined-weak.s index 6aa84ec483f4..7ea247fd5d6e 100644 --- a/test/ELF/relocation-undefined-weak.s +++ b/test/ELF/relocation-undefined-weak.s @@ -1,8 +1,8 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld %t -o %tout // RUN: llvm-readobj -sections %tout | FileCheck %s // RUN: llvm-objdump -d %tout | FileCheck %s --check-prefix DISASM -// REQUIRES: x86 // Check that undefined weak symbols are treated as having a VA of 0. diff --git a/test/ELF/relocation.s b/test/ELF/relocation.s index 3359a8badda6..00b75d25f968 100644 --- a/test/ELF/relocation.s +++ b/test/ELF/relocation.s @@ -1,10 +1,10 @@ +// 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 %p/Inputs/shared.s -o %t2 -// RUN: ld.lld %t2 -o %t2.so -shared +// RUN: ld.lld %t2 -soname fixed-length-string.so -o %t2.so -shared // RUN: ld.lld --hash-style=sysv %t %t2.so -o %t3 // RUN: llvm-readobj -s %t3 | FileCheck --check-prefix=SEC %s // RUN: llvm-objdump -s -d %t3 | FileCheck %s -// REQUIRES: x86 // SEC: Name: .plt // SEC-NEXT: Type: SHT_PROGBITS @@ -113,17 +113,16 @@ R_X86_64_64: .quad R_X86_64_64 // CHECK: Contents of section .R_X86_64_64: -// CHECK-NEXT: 2001c8 c8012000 00000000 +// CHECK-NEXT: 2002c0 c0022000 00000000 .section .R_X86_64_GOTPCREL,"a",@progbits .global R_X86_64_GOTPCREL R_X86_64_GOTPCREL: .long zed@gotpcrel -// 0x2020F8 - 0x2001D8 = 7952 -// 7952 = 0x101f0000 in little endian +// 0x2030F0(.got) - 0x2002c8(.R_X86_64_GOTPCREL) = 0x2e28 // CHECK: Contents of section .R_X86_64_GOTPCREL -// CHECK-NEXT: 2001d0 202f0000 +// CHECK-NEXT: 2002c8 282e0000 .section .R_X86_64_GOT32,"a",@progbits .global R_X86_64_GOT32 diff --git a/test/ELF/relro-non-contiguous.s b/test/ELF/relro-non-contiguous.s index ce6680860edf..8fdf64a37456 100644 --- a/test/ELF/relro-non-contiguous.s +++ b/test/ELF/relro-non-contiguous.s @@ -1,3 +1,4 @@ +// 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 @@ -15,7 +16,6 @@ // RUN: not ld.lld %t3.o %t.so -z relro -o %t --script=%t.script 2>&1 | FileCheck %s // No error when we do not request relro. // RUN: ld.lld %t3.o %t.so -z norelro -o %t --script=%t.script -// REQUIRES: x86 // CHECK: error: section: .bss.rel.ro is not contiguous with other relro sections .section .text, "ax", @progbits diff --git a/test/ELF/relro-omagic.s b/test/ELF/relro-omagic.s index 97c3a812406d..ba0ca72e219b 100644 --- a/test/ELF/relro-omagic.s +++ b/test/ELF/relro-omagic.s @@ -1,3 +1,4 @@ +# 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 %p/Inputs/shared.s -o %t2.o # RUN: ld.lld -shared %t2.o -o %t2.so -soname relro-omagic.s.tmp2.so @@ -13,8 +14,8 @@ # NORELRO-NEXT: 3 .dynstr 00000021 0000000000200188 # NORELRO-NEXT: 4 .rela.dyn 00000018 00000000002001b0 # NORELRO-NEXT: 5 .rela.plt 00000018 00000000002001c8 -# NORELRO-NEXT: 6 .text 0000000a 00000000002001e0 TEXT DATA -# NORELRO-NEXT: 7 .plt 00000020 00000000002001f0 TEXT DATA +# NORELRO-NEXT: 6 .text 0000000a 00000000002001e0 TEXT +# NORELRO-NEXT: 7 .plt 00000020 00000000002001f0 TEXT # NORELRO-NEXT: 8 .data 00000008 0000000000200210 DATA # NORELRO-NEXT: 9 .foo 00000004 0000000000200218 DATA # NORELRO-NEXT: 10 .dynamic 000000f0 0000000000200220 diff --git a/test/ELF/relro-script.s b/test/ELF/relro-script.s index f0dca67a3422..c71c8e5decdc 100644 --- a/test/ELF/relro-script.s +++ b/test/ELF/relro-script.s @@ -16,7 +16,7 @@ // RUN: .got.plt : { *(.got.plt) } \ // RUN: } " > %t.script // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t3.o -// RUN: ld.lld %t3.o %t.so -o %t --script=%t.script --print-map | FileCheck %s +// RUN: ld.lld %t3.o %t.so -o /dev/null --script=%t.script --print-map | FileCheck %s // CHECK: .data.rel.ro // CHECK-NEXT: <internal>:(.bss.rel.ro) diff --git a/test/ELF/relro.s b/test/ELF/relro.s index b21e514303ab..0f721318c784 100644 --- a/test/ELF/relro.s +++ b/test/ELF/relro.s @@ -1,13 +1,17 @@ +// 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 %p/Inputs/shared.s -o %t2.o // RUN: ld.lld -shared %t2.o -o %t2.so -// RUN: ld.lld %t.o %t2.so -z now -z relro -o %t + +// RUN: ld.lld %t.o %t2.so -z now -z norelro -z relro -o %t // RUN: llvm-readobj -l --elf-output-style=GNU %t | FileCheck --check-prefix=CHECK --check-prefix=FULLRELRO %s -// RUN: ld.lld %t.o %t2.so -z relro -o %t + +// RUN: ld.lld %t.o %t2.so -z norelro -z relro -o %t // RUN: llvm-readobj -l --elf-output-style=GNU %t | FileCheck --check-prefix=CHECK --check-prefix=PARTRELRO %s + // RUN: ld.lld %t.o %t2.so -z norelro -o %t // RUN: llvm-readobj -l --elf-output-style=GNU %t | FileCheck --check-prefix=NORELRO %s -// REQUIRES: x86 // CHECK: Program Headers: // CHECK-NEXT: Type diff --git a/test/ELF/reproduce-backslash.s b/test/ELF/reproduce-backslash.s index 53feb5ff3223..7a9964db62aa 100644 --- a/test/ELF/reproduce-backslash.s +++ b/test/ELF/reproduce-backslash.s @@ -2,8 +2,8 @@ # Test that we don't erroneously replace \ with / on UNIX, as it's # legal for a filename to contain backslashes. -# RUN: llvm-mc %s -o foo\\.o -filetype=obj -triple=x86_64-pc-linux -# RUN: ld.lld foo\\.o --reproduce repro.tar -# RUN: tar tf repro.tar | FileCheck %s +# RUN: llvm-mc %s -o %T/foo\\.o -filetype=obj -triple=x86_64-pc-linux +# RUN: ld.lld %T/foo\\.o --reproduce %T/repro.tar -o /dev/null +# RUN: tar tf %T/repro.tar | FileCheck %s # CHECK: repro/{{.*}}/foo\\.o diff --git a/test/ELF/reproduce-error.s b/test/ELF/reproduce-error.s index e2de8a4feeba..3a99815d7708 100644 --- a/test/ELF/reproduce-error.s +++ b/test/ELF/reproduce-error.s @@ -1,5 +1,5 @@ -# Extracting the tar archive can get over the path limit on windows. # REQUIRES: shell +# Extracting the tar archive can get over the path limit on windows. # RUN: rm -rf %t.dir # RUN: mkdir -p %t.dir diff --git a/test/ELF/reproduce.s b/test/ELF/reproduce.s index 69671a088473..bfab2e87e80b 100644 --- a/test/ELF/reproduce.s +++ b/test/ELF/reproduce.s @@ -1,7 +1,7 @@ # REQUIRES: x86 +# REQUIRES: shell # Extracting the tar archive can get over the path limit on windows. -# REQUIRES: shell # RUN: rm -rf %t.dir # RUN: mkdir -p %t.dir/build1 diff --git a/test/ELF/resolution-end.s b/test/ELF/resolution-end.s index 26858372ce09..c8c5a044e602 100644 --- a/test/ELF/resolution-end.s +++ b/test/ELF/resolution-end.s @@ -1,9 +1,9 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/resolution-end.s -o %t2.o # RUN: ld.lld -shared -o %t2.so %t2.o # RUN: ld.lld --hash-style=sysv %t1.o %t2.so -o %t # RUN: llvm-readobj -t -s -section-data %t | FileCheck %s -# REQUIRES: x86 # Test that we resolve _end to the this executable. diff --git a/test/ELF/resolution-shared.s b/test/ELF/resolution-shared.s index e1eac070e5af..2d61d268c6f9 100644 --- a/test/ELF/resolution-shared.s +++ b/test/ELF/resolution-shared.s @@ -1,9 +1,9 @@ +// 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/resolution-shared.s -o %t2.o // RUN: ld.lld %t2.o -o %t2.so -shared // RUN: ld.lld %t.o %t2.so -o %t3 -shared // RUN: llvm-readobj -t %t3 | FileCheck %s -// REQUIRES: x86 .weak foo foo: diff --git a/test/ELF/resolution.s b/test/ELF/resolution.s index 4a42d941eab6..f72f487e68ea 100644 --- a/test/ELF/resolution.s +++ b/test/ELF/resolution.s @@ -1,8 +1,8 @@ +// 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 %p/Inputs/resolution.s -o %t2 // RUN: ld.lld -discard-all %t %t2 -o %t3 // RUN: llvm-readobj -t %t3 | FileCheck %s -// REQUIRES: x86 // This is an exhaustive test for checking which symbol is kept when two // have the same name. Each symbol has a different size which is used diff --git a/test/ELF/rodynamic.s b/test/ELF/rodynamic.s index 441e5c395e7c..49d59cec4a6a 100644 --- a/test/ELF/rodynamic.s +++ b/test/ELF/rodynamic.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux # RUN: llvm-mc %p/Inputs/rodynamic.s -o %t.so.o -filetype=obj -triple=x86_64-pc-linux diff --git a/test/ELF/section-align-0.test b/test/ELF/section-align-0.test index 35783f5a894b..8827ecf740b3 100644 --- a/test/ELF/section-align-0.test +++ b/test/ELF/section-align-0.test @@ -1,5 +1,5 @@ # RUN: yaml2obj %s -o %t -# RUN: ld.lld %t -o %tout +# RUN: ld.lld %t -o /dev/null # Verify that lld can handle sections with an alignment of zero. diff --git a/test/ELF/section-layout.s b/test/ELF/section-layout.s index 7febec85a629..0832109fa898 100644 --- a/test/ELF/section-layout.s +++ b/test/ELF/section-layout.s @@ -1,7 +1,7 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: ld.lld %t -o %tout # RUN: llvm-readobj -sections %tout | FileCheck %s -# REQUIRES: x86 # Check that sections are laid out in the correct order. @@ -26,9 +26,10 @@ _start: .section e,"awT" .section d,"ax",@nobits .section c,"ax" -.section b,"a",@nobits -.section a,"a" +.section a,"a",@nobits +.section b,"a" +// For non-executable and non-writable sections, PROGBITS appear after others. // CHECK: Name: a // CHECK: Name: b // CHECK: Name: c diff --git a/test/ELF/section-metadata-err.s b/test/ELF/section-metadata-err.s index 1bcbedfbab71..c9104303e434 100644 --- a/test/ELF/section-metadata-err.s +++ b/test/ELF/section-metadata-err.s @@ -1,9 +1,9 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s -# CHECK: error: a section with SHF_LINK_ORDER should not refer a non-regular section: {{.*}}section-metadata-err.s.tmp.o:(.foo) +# CHECK: error: a section .bar with SHF_LINK_ORDER should not refer a non-regular section: {{.*}}section-metadata-err.s.tmp.o:(.foo) .global _start _start: @@ -12,4 +12,4 @@ _start: .section .foo,"aM",@progbits,8 .quad 0 -.section bar,"ao",@progbits,.foo +.section .bar,"ao",@progbits,.foo diff --git a/test/ELF/section-metadata-err2.s b/test/ELF/section-metadata-err2.s new file mode 100644 index 000000000000..3191c1f4d3b6 --- /dev/null +++ b/test/ELF/section-metadata-err2.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s + +## Check we do not crash and report proper errors. +# CHECK: error: a section .bar with SHF_LINK_ORDER should not refer a non-regular section: {{.*}}section-metadata-err2.s.tmp.o:(.foo) +# CHECK: error: a section .bar with SHF_LINK_ORDER should not refer a non-regular section: {{.*}}section-metadata-err2.s.tmp.o:(.foo) + +.section .foo,"aM",@progbits,8 +.quad 0 + +.section .bar,"ao",@progbits,.foo,unique,1 +.quad 0 + +.section .bar,"ao",@progbits,.foo,unique,2 +.quad 1 diff --git a/test/ELF/section-metadata-err3.s b/test/ELF/section-metadata-err3.s new file mode 100644 index 000000000000..5c4875b9da5e --- /dev/null +++ b/test/ELF/section-metadata-err3.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: incompatible section flags for .bar +# CHECK-NEXT: >>> {{.*}}section-metadata-err3.s.tmp.o:(.bar): 0x2 +# CHECK-NEXT: >>> output section .bar: 0x82 + +.section .foo,"a",@progbits +.quad 0 + +.section .bar,"ao",@progbits,.foo,unique,1 +.quad 0 + +.section .bar,"a",@progbits,unique,2 +.quad 1 diff --git a/test/ELF/section-name.s b/test/ELF/section-name.s index caf574f2c106..4f010c81963c 100644 --- a/test/ELF/section-name.s +++ b/test/ELF/section-name.s @@ -1,7 +1,7 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: ld.lld %t -o %tout # RUN: llvm-objdump --section-headers %tout | FileCheck %s -# REQUIRES: x86 .global _start .text diff --git a/test/ELF/section-symbol.s b/test/ELF/section-symbol.s index 5cf71aceec72..495c38db5da9 100644 --- a/test/ELF/section-symbol.s +++ b/test/ELF/section-symbol.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t // RUN: ld.lld %t -o %t.so -shared -discard-none // RUN: llvm-readobj -t %t.so | FileCheck %s diff --git a/test/ELF/section-symbols.test b/test/ELF/section-symbols.test index 2ef77a828b65..973b1102fdf3 100644 --- a/test/ELF/section-symbols.test +++ b/test/ELF/section-symbols.test @@ -1,5 +1,5 @@ # RUN: yaml2obj %s -o %t -# RUN: ld.lld -shared %t -o %tout +# RUN: ld.lld -shared %t -o /dev/null # Verify that lld can handle STT_SECTION symbols associated # with SHT_REL[A]/SHT_SYMTAB/SHT_STRTAB sections. diff --git a/test/ELF/sectionstart-noallochdr.s b/test/ELF/sectionstart-noallochdr.s index e9267a5372a5..be8e0c568e1e 100644 --- a/test/ELF/sectionstart-noallochdr.s +++ b/test/ELF/sectionstart-noallochdr.s @@ -7,7 +7,7 @@ # CHECK: Sections: # CHECK-NEXT: Idx Name Size Address Type # CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .text 00000001 0000000000000010 TEXT DATA +# CHECK-NEXT: 1 .text 00000001 0000000000000010 TEXT # CHECK-NEXT: 2 .data 00000004 0000000000000020 DATA # CHECK-NEXT: 3 .bss 00000004 0000000000000030 BSS diff --git a/test/ELF/sectionstart.s b/test/ELF/sectionstart.s index 23574c14748a..be8b5f0cfb40 100644 --- a/test/ELF/sectionstart.s +++ b/test/ELF/sectionstart.s @@ -1,13 +1,13 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: ld.lld %t.o --section-start .text=0x100000 \ -# RUN: --section-start .data=0x110000 --section-start .bss=0x200000 -o %t +# RUN: --section-start=.data=0x110000 --section-start .bss=0x200000 -o %t # RUN: llvm-objdump -section-headers %t | FileCheck %s # CHECK: Sections: # CHECK-NEXT: Idx Name Size Address Type # CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .text 00000001 0000000000100000 TEXT DATA +# CHECK-NEXT: 1 .text 00000001 0000000000100000 TEXT # CHECK-NEXT: 2 .data 00000004 0000000000110000 DATA # CHECK-NEXT: 3 .bss 00000004 0000000000200000 BSS @@ -35,11 +35,11 @@ # RUN: llvm-objdump -section-headers %t4 | FileCheck %s ## Errors: -# RUN: not ld.lld %t.o --section-start .text100000 -o %t2 2>&1 \ +# RUN: not ld.lld %t.o --section-start .text100000 -o /dev/null 2>&1 \ # RUN: | FileCheck -check-prefix=ERR1 %s # ERR1: invalid argument: --section-start .text100000 -# RUN: not ld.lld %t.o --section-start .text=1Q0000 -o %t3 2>&1 \ +# RUN: not ld.lld %t.o --section-start .text=1Q0000 -o /dev/null 2>&1 \ # RUN: | FileCheck -check-prefix=ERR2 %s # ERR2: invalid argument: --section-start .text=1Q0000 diff --git a/test/ELF/shared-lazy.s b/test/ELF/shared-lazy.s index bc1e61c3c949..36b8f16e1794 100644 --- a/test/ELF/shared-lazy.s +++ b/test/ELF/shared-lazy.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o // RUN: rm -f %t1.a // RUN: llvm-ar rc %t1.a %t1.o diff --git a/test/ELF/shared-be.s b/test/ELF/shared-ppc64.s index 0b941d373720..f2280a1e8c1c 100644 --- a/test/ELF/shared-be.s +++ b/test/ELF/shared-ppc64.s @@ -1,9 +1,16 @@ +// REQUIRES: ppc + +// 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.s -o %t2.o +// RUN: ld.lld -shared %t2.o -o %t2.so +// RUN: ld.lld -dynamic-linker /lib64/ld64.so.1 -rpath foo -rpath bar --export-dynamic %t.o %t2.so -o %t +// RUN: llvm-readobj --dynamic-table -s %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.s -o %t2.o // RUN: ld.lld -shared %t2.o -o %t2.so // RUN: ld.lld -dynamic-linker /lib64/ld64.so.1 -rpath foo -rpath bar --export-dynamic %t.o %t2.so -o %t // RUN: llvm-readobj --dynamic-table -s %t | FileCheck %s -// REQUIRES: ppc // CHECK: Name: .rela.dyn // CHECK-NEXT: Type: SHT_REL diff --git a/test/ELF/shared.s b/test/ELF/shared.s index 65ad2c61359b..3a8fedec9240 100644 --- a/test/ELF/shared.s +++ b/test/ELF/shared.s @@ -1,3 +1,4 @@ +// 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 @@ -6,7 +7,6 @@ // RUN: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data -hash-table %t | FileCheck %s // RUN: ld.lld --hash-style=sysv %t.o %t2.so %t2.so -o %t2 // RUN: llvm-readobj -dyn-symbols %t2 | FileCheck --check-prefix=DONT_EXPORT %s -// REQUIRES: x86 // Make sure .symtab is properly aligned. // SO: Name: .symtab @@ -73,8 +73,8 @@ // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 4 // CHECK-NEXT: EntrySize: 4 - -// CHECK: Index: [[DYNSTR]] +// CHECK: Section { +// CHECK-NEXT: Index: [[DYNSTR]] // CHECK-NEXT: Name: .dynstr // CHECK-NEXT: Type: SHT_STRTAB // CHECK-NEXT: Flags [ @@ -87,9 +87,6 @@ // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 1 // CHECK-NEXT: EntrySize: 0 -// CHECK-NEXT: SectionData ( -// CHECK: ) -// CHECK-NEXT: } // CHECK: Name: .rel.dyn // CHECK-NEXT: Type: SHT_REL diff --git a/test/ELF/shlib-undefined-archive.s b/test/ELF/shlib-undefined-archive.s new file mode 100644 index 000000000000..940d8d7bc0c5 --- /dev/null +++ b/test/ELF/shlib-undefined-archive.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 + +# Undefined symbols in a DSO should pull out object files from archives +# to resolve them. + +# RUN: echo '.globl foo' | llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t1.o - +# RUN: ld.lld -shared -o %t.so %t1.o + +# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t2.o %s +# RUN: rm -f %t.a +# RUN: llvm-ar cru %t.a %t2.o +# RUN: ld.lld -o %t.exe %t.so %t.a +# RUN: llvm-nm -D %t.exe | FileCheck %s + +# CHECK: T foo + +.globl foo +foo: + ret diff --git a/test/ELF/shlib-undefined-local.s b/test/ELF/shlib-undefined-local.s new file mode 100644 index 000000000000..8fceec1bf60f --- /dev/null +++ b/test/ELF/shlib-undefined-local.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t1.o %S/Inputs/shlib-undefined-ref.s +# RUN: ld.lld -shared -o %t.so %t1.o + +# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t2.o %s +# RUN: echo "{ local: *; };" > %t.script +# RUN: ld.lld -version-script %t.script -o %t %t2.o %t.so +# RUN: llvm-nm -g %t | FileCheck -allow-empty %s + +# CHECK-NOT: should_not_be_exported + +.globl should_not_be_exported +should_not_be_exported: + ret + +.globl _start +_start: + ret diff --git a/test/ELF/shlib-undefined-shared.s b/test/ELF/shlib-undefined-shared.s new file mode 100644 index 000000000000..6d60d01bfabe --- /dev/null +++ b/test/ELF/shlib-undefined-shared.s @@ -0,0 +1,15 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t1.o %S/Inputs/shlib-undefined-ref.s +# RUN: ld.lld -shared -o %t1.so %t1.o + +# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t2.o %s +# RUN: echo "{ local: *; };" > %t.script +# RUN: ld.lld -shared -version-script %t.script -o %t2.so %t2.o %t1.so +# RUN: llvm-nm -g %t2.so | FileCheck -allow-empty %s + +# CHECK-NOT: should_not_be_exported + +.globl should_not_be_exported +should_not_be_exported: + ret diff --git a/test/ELF/sht-group-gold-r.test b/test/ELF/sht-group-gold-r.test index 3a3889eabd81..d1757eee6e7d 100644 --- a/test/ELF/sht-group-gold-r.test +++ b/test/ELF/sht-group-gold-r.test @@ -1,3 +1,4 @@ +# REQUIRES: x86 # GNU gold 1.14 (the newest version as of July 2017) seems to create # non-standard-compliant SHT_GROUP sections when the -r option is given. # diff --git a/test/ELF/silent-ignore.test b/test/ELF/silent-ignore.test index 6655754ace58..adfc2442d4ed 100644 --- a/test/ELF/silent-ignore.test +++ b/test/ELF/silent-ignore.test @@ -1,6 +1,5 @@ RUN: ld.lld --version \ RUN: -allow-shlib-undefined \ -RUN: -cref \ RUN: -g \ RUN: -no-add-needed \ RUN: -no-allow-shlib-undefined \ diff --git a/test/ELF/soname.s b/test/ELF/soname.s index a26bb30f7a17..25c969dab745 100644 --- a/test/ELF/soname.s +++ b/test/ELF/soname.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: ld.lld %t.o -shared -soname=bar -o %t.so // RUN: ld.lld %t.o -shared --soname=bar -o %t2.so diff --git a/test/ELF/soname2.s b/test/ELF/soname2.s index 9fb8da519bfb..67a9c24af5cd 100644 --- a/test/ELF/soname2.s +++ b/test/ELF/soname2.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: ld.lld %t.o -shared -soname=foo.so -o %t // RUN: llvm-readobj --dynamic-table %t | FileCheck %s diff --git a/test/ELF/sort-norosegment.s b/test/ELF/sort-norosegment.s index bd74f2eb330a..cd4fc9ebae16 100644 --- a/test/ELF/sort-norosegment.s +++ b/test/ELF/sort-norosegment.s @@ -1,13 +1,13 @@ # 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 -o %t.o -# RUN: ld.lld --hash-style=sysv -no-rosegment -o %t1 %t -shared -# RUN: llvm-readobj -elf-output-style=GNU -s %t1 | FileCheck %s +# RUN: ld.lld --hash-style=sysv -no-rosegment -o %t %t.o -shared +# RUN: llvm-readelf -s %t | FileCheck %s -# CHECK: .text {{.*}} AX -# CHECK-NEXT: .dynsym {{.*}} A +# CHECK: .dynsym {{.*}} A # CHECK-NEXT: .hash {{.*}} A # CHECK-NEXT: .dynstr {{.*}} A +# CHECK-NEXT: .text {{.*}} AX # CHECK-NEXT: foo {{.*}} WA # CHECK-NEXT: .dynamic {{.*}} WA diff --git a/test/ELF/splitstacks.s b/test/ELF/splitstacks.s deleted file mode 100644 index 3b7e67e5c2b0..000000000000 --- a/test/ELF/splitstacks.s +++ /dev/null @@ -1,11 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o - -# RUN: not ld.lld %t1.o -o %t 2>&1 | FileCheck %s -# CHECK: .o: object file compiled with -fsplit-stack is not supported - -.globl _start -_start: - nop - -.section .note.GNU-split-stack,"",@progbits diff --git a/test/ELF/start-lib.s b/test/ELF/start-lib.s index 013a2b206a1f..b79d9efc325a 100644 --- a/test/ELF/start-lib.s +++ b/test/ELF/start-lib.s @@ -21,5 +21,14 @@ // TEST3-NOT: Name: bar // TEST3-NOT: Name: foo +// RUN: not ld.lld %t1.o --start-lib --start-lib 2>&1 | FileCheck -check-prefix=NESTED-LIB %s +// NESTED-LIB: nested --start-lib + +// RUN: not ld.lld %t1.o --start-group --start-lib 2>&1 | FileCheck -check-prefix=LIB-IN-GROUP %s +// LIB-IN-GROUP: may not nest --start-lib in --start-group + +// RUN: not ld.lld --end-lib 2>&1 | FileCheck -check-prefix=END %s +// END: stray --end-lib + .globl _start _start: diff --git a/test/ELF/startstop-shared.s b/test/ELF/startstop-shared.s index 80ccf3df0aad..4d3192a35734 100644 --- a/test/ELF/startstop-shared.s +++ b/test/ELF/startstop-shared.s @@ -11,18 +11,30 @@ .quad __start_bar .section bar,"a" -// Test that we are able to hide the symbol. -// CHECK: R_X86_64_RELATIVE - 0x[[ADDR:.*]] +// CHECK: Relocations [ +// CHECK-NEXT: Section {{.*}} .rela.dyn { +// CHECK-NEXT: R_X86_64_RELATIVE +// CHECK-NEXT: R_X86_64_RELATIVE +// CHECK-NEXT: } +// CHECK-NEXT: ] -// By default the symbol is visible and we need a dynamic reloc. -// CHECK: R_X86_64_64 __start_foo 0x0 +// Test that we are able to hide the symbol. +// By default the symbol is protected. // CHECK: Name: __start_bar -// CHECK-NEXT: Value: 0x[[ADDR]] +// CHECK-NEXT: Value: // CHECK-NEXT: Size: // CHECK-NEXT: Binding: Local +// CHECK-NEXT: Type: None +// CHECK-NEXT: Other [ +// CHECK-NEXT: STV_HIDDEN +// CHECK-NEXT: ] // CHECK: Name: __start_foo // CHECK-NEXT: Value: // CHECK-NEXT: Size: // CHECK-NEXT: Binding: Global +// CHECK-NEXT: Type: None +// CHECK-NEXT: Other [ +// CHECK-NEXT: STV_PROTECTED +// CHECK-NEXT: ] diff --git a/test/ELF/startstop.s b/test/ELF/startstop.s index 1e75042a0c8c..470298eee37d 100644 --- a/test/ELF/startstop.s +++ b/test/ELF/startstop.s @@ -19,13 +19,12 @@ // DISASM: 1013: 90 nop // DISASM: 1014: 90 nop - // SYMBOL: Relocations [ // SYMBOL-NEXT: Section ({{.*}}) .rela.dyn { -// SYMBOL-NEXT: 0x2010 R_X86_64_64 __stop_zed1 0x0 -// SYMBOL-NEXT: 0x2018 R_X86_64_64 __stop_zed1 0x1 -// SYMBOL-NEXT: 0x2000 R_X86_64_64 __stop_zed2 0x0 -// SYMBOL-NEXT: 0x2008 R_X86_64_64 __stop_zed2 0x1 +// SYMBOL-NEXT: R_X86_64_RELATIVE +// SYMBOL-NEXT: R_X86_64_RELATIVE +// SYMBOL-NEXT: R_X86_64_RELATIVE +// SYMBOL-NEXT: R_X86_64_RELATIVE // SYMBOL-NEXT: } // SYMBOL-NEXT: ] @@ -45,20 +44,20 @@ // SYMBOL: Symbol { // SYMBOL: Name: __stop_foo // SYMBOL: Value: 0x1012 -// STMBOL: STV_HIDDEN +// SYMBOL: STV_HIDDEN // SYMBOL: Section: foo // SYMBOL: } // SYMBOL: Symbol { // SYMBOL: Name: __stop_zed1 // SYMBOL: Value: 0x2010 -// STMBOL: Other: 0 +// SYMBOL: STV_PROTECTED // SYMBOL: Section: zed1 // SYMBOL: } // SYMBOL: Symbol { // SYMBOL: Name: __stop_zed2 // SYMBOL: Value: 0x2020 -// STMBOL: Other: 0 +// SYMBOL: STV_PROTECTED // SYMBOL: Section: zed2 // SYMBOL: } diff --git a/test/ELF/static-with-export-dynamic.s b/test/ELF/static-with-export-dynamic.s index 8634835d9aa7..f0c67df22623 100644 --- a/test/ELF/static-with-export-dynamic.s +++ b/test/ELF/static-with-export-dynamic.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-unknown-cloudabi %s -o %t.o // RUN: ld.lld --export-dynamic %t.o -o %t // RUN: llvm-readobj -dyn-symbols %t | FileCheck %s -// REQUIRES: x86 // Ensure that a dynamic symbol table is present when --export-dynamic // is passed in, even when creating statically linked executables. diff --git a/test/ELF/string-gc.s b/test/ELF/string-gc.s index 96c75e9236f4..8e4ee14e0f47 100644 --- a/test/ELF/string-gc.s +++ b/test/ELF/string-gc.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: ld.lld %t.o -o %t --gc-sections // RUN: llvm-readobj -symbols %t | FileCheck %s diff --git a/test/ELF/string-table.s b/test/ELF/string-table.s index 490c4d574cf1..2a975501d951 100644 --- a/test/ELF/string-table.s +++ b/test/ELF/string-table.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t // RUN: ld.lld %t -o %t2 // RUN: llvm-readobj -sections %t2 | FileCheck %s -// REQUIRES: x86 .global _start _start: diff --git a/test/ELF/symbol-ordering-file-icf.s b/test/ELF/symbol-ordering-file-icf.s new file mode 100644 index 000000000000..93e377cb53b0 --- /dev/null +++ b/test/ELF/symbol-ordering-file-icf.s @@ -0,0 +1,32 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "zed" > %t.order +# RUN: echo "bar" >> %t.order +# RUN: echo "foo" >> %t.order +# RUN: ld.lld --icf=all --symbol-ordering-file %t.order -shared %t.o -o %t.so +# RUN: llvm-nm %t.so | FileCheck %s + +## Check that after ICF merges 'foo' and 'zed' we still +## place them before 'bar', in according to ordering file. +# CHECK-DAG: 0000000000001000 T foo +# CHECK-DAG: 0000000000001000 T zed +# CHECK-DAG: 0000000000001004 T bar + +.section .text.foo,"ax",@progbits +.align 4 +.global foo +foo: + retq + +.section .text.bar,"ax",@progbits +.align 4 +.global bar +bar: + nop + retq + +.section .text.zed,"ax",@progbits +.align 4 +.global zed +zed: + retq diff --git a/test/ELF/symbol-ordering-file-warnings.s b/test/ELF/symbol-ordering-file-warnings.s new file mode 100644 index 000000000000..71414bf58098 --- /dev/null +++ b/test/ELF/symbol-ordering-file-warnings.s @@ -0,0 +1,165 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/symbol-ordering-file-warnings1.s -o %t2.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/symbol-ordering-file-warnings2.s -o %t3.o +# RUN: ld.lld -shared %t2.o -o %t.so + +# Check that a warning is emitted for entries in the file that are not present in any used input. +# RUN: echo "missing" > %t-order-missing.txt +# RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-missing.txt \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,MISSING + +# Check that the warning can be disabled. +# RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-missing.txt \ +# RUN: --unresolved-symbols=ignore-all --no-warn-symbol-ordering 2>&1 | \ +# RUN: FileCheck %s --check-prefixes=WARN --allow-empty + +# Check that the warning can be re-enabled +# RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-missing.txt \ +# RUN: --unresolved-symbols=ignore-all --no-warn-symbol-ordering --warn-symbol-ordering 2>&1 | \ +# RUN: FileCheck %s --check-prefixes=WARN,MISSING + +# Check that a warning is emitted for undefined symbols. +# RUN: echo "undefined" > %t-order-undef.txt +# RUN: ld.lld %t1.o %t3.o -o %t --symbol-ordering-file %t-order-undef.txt \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,UNDEFINED + +# Check that a warning is emitted for imported shared symbols. +# RUN: echo "shared" > %t-order-shared.txt +# RUN: ld.lld %t1.o %t.so -o %t --symbol-ordering-file %t-order-shared.txt \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,SHARED + +# Check that a warning is emitted for absolute symbols. +# RUN: echo "absolute" > %t-order-absolute.txt +# RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-absolute.txt \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,ABSOLUTE + +# Check that a warning is emitted for symbols discarded due to --gc-sections. +# RUN: echo "gc" > %t-order-gc.txt +# RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-gc.txt --gc-sections \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,GC + +# Check that a warning is not emitted for the symbol removed due to --icf. +# RUN: echo "icf1" > %t-order-icf.txt +# RUN: echo "icf2" >> %t-order-icf.txt +# RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-icf.txt --icf=all \ +# RUN: --unresolved-symbols=ignore-all --fatal-warnings + +# RUN: echo "_GLOBAL_OFFSET_TABLE_" > %t-order-synthetic.txt +# RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-synthetic.txt --icf=all \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,SYNTHETIC + +# Check that a warning is emitted for symbols discarded due to a linker script /DISCARD/ section. +# RUN: echo "discard" > %t-order-discard.txt +# RUN: echo "SECTIONS { /DISCARD/ : { *(.text.discard) } }" > %t.script +# RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-discard.txt -T %t.script \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,DISCARD + +# Check that LLD does not warn for discarded COMDAT symbols, if they are present in the kept instance. +# RUN: echo "comdat" > %t-order-comdat.txt +# RUN: ld.lld %t1.o %t2.o -o %t --symbol-ordering-file %t-order-comdat.txt \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN --allow-empty + +# Check that if a COMDAT was unused and discarded via --gc-sections, warn for each instance. +# RUN: ld.lld %t1.o %t2.o -o %t --symbol-ordering-file %t-order-comdat.txt --gc-sections \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,COMDAT + +# Check that if a weak symbol is not kept, because of an equivalent global symbol, no warning is emitted. +# RUN: echo "glob_or_wk" > %t-order-weak.txt +# RUN: ld.lld %t1.o %t2.o -o %t --symbol-ordering-file %t-order-weak.txt \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN --allow-empty + +# Check that symbols only in unused archive members result in a warning. +# RUN: rm -f %t.a +# RUN: llvm-ar rc %t.a %t3.o +# RUN: ld.lld %t1.o %t.a -o %t --symbol-ordering-file %t-order-missing.txt \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,MISSING --allow-empty + +# Check that a warning for each same-named symbol with an issue. +# RUN: echo "multi" > %t-order-same-name.txt +# RUN: ld.lld %t1.o %t2.o %t3.o -o %t --symbol-ordering-file %t-order-same-name.txt \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,MULTI + +# Check that a warning is emitted if the same symbol is mentioned multiple times in the ordering file. +# RUN: echo "_start" > %t-order-multiple-same.txt +# RUN: echo "_start" >> %t-order-multiple-same.txt +# RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-multiple-same.txt \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,SAMESYM + +# Check that all warnings can be emitted from the same input. +# RUN: echo "missing_sym" > %t-order-multi.txt +# RUN: echo "undefined" >> %t-order-multi.txt +# RUN: echo "_start" >> %t-order-multi.txt +# RUN: echo "shared" >> %t-order-multi.txt +# RUN: echo "absolute" >> %t-order-multi.txt +# RUN: echo "gc" >> %t-order-multi.txt +# RUN: echo "discard" >> %t-order-multi.txt +# RUN: echo "_GLOBAL_OFFSET_TABLE_" >> %t-order-multi.txt +# RUN: echo "_start" >> %t-order-multi.txt +# RUN: ld.lld %t1.o %t3.o %t.so -o %t --symbol-ordering-file %t-order-multi.txt --gc-sections -T %t.script \ +# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,SAMESYM,ABSOLUTE,SHARED,UNDEFINED,GC,DISCARD,MISSING2,SYNTHETIC + +# WARN-NOT: warning: +# SAMESYM: warning: {{.*}}.txt: duplicate ordered symbol: _start +# WARN-NOT: warning: +# SYNTHETIC: warning: <internal>: unable to order synthetic symbol: _GLOBAL_OFFSET_TABLE_ +# WARN-NOT: warning: +# DISCARD: warning: {{.*}}1.o: unable to order discarded symbol: discard +# WARN-NOT: warning: +# GC: warning: {{.*}}1.o: unable to order discarded symbol: gc +# WARN-NOT: warning: +# SHARED: warning: {{.*}}.so: unable to order shared symbol: shared +# WARN-NOT: warning: +# UNDEFINED: warning: {{.*}}3.o: unable to order undefined symbol: undefined +# WARN-NOT: warning: +# ABSOLUTE: warning: {{.*}}1.o: unable to order absolute symbol: absolute +# WARN-NOT: warning: +# MISSING: warning: symbol ordering file: no such symbol: missing +# MISSING2: warning: symbol ordering file: no such symbol: missing_sym +# COMDAT: warning: {{.*}}1.o: unable to order discarded symbol: comdat +# MULTI: warning: {{.*}}3.o: unable to order undefined symbol: multi +# MULTI-NEXT: warning: {{.*}}2.o: unable to order absolute symbol: multi +# WARN-NOT: warning: + +absolute = 0x1234 + +.section .text.gc,"ax",@progbits +.global gc +gc: + nop + +.section .text.discard,"ax",@progbits +.global discard +discard: + nop + +.section .text.comdat,"axG",@progbits,comdat,comdat +.weak comdat +comdat: + nop + +.section .text.glob_or_wk,"ax",@progbits +.weak glob_or_wk +glob_or_wk: + nop + +.section .text._start,"ax",@progbits +.global _start +_start: + movq %rax, absolute + callq shared + +.section .text.icf1,"ax",@progbits +.global icf1 +icf1: + ret + +.section .text.icf2,"ax",@progbits +.global icf2 +icf2: + ret + +# This is a "good" instance of the symbol +.section .text.multi,"ax",@progbits +multi: + .quad _GLOBAL_OFFSET_TABLE_ diff --git a/test/ELF/symbol-ordering-file.s b/test/ELF/symbol-ordering-file.s index 5a88b8c0827f..34d67701933e 100644 --- a/test/ELF/symbol-ordering-file.s +++ b/test/ELF/symbol-ordering-file.s @@ -5,6 +5,8 @@ # BEFORE: Contents of section .foo: # BEFORE-NEXT: 201000 11223344 5566 +# BEFORE: Contents of section .init: +# BEFORE-NEXT: 201006 1122 # RUN: echo "_foo4 " > %t_order.txt # RUN: echo " _foo3" >> %t_order.txt @@ -14,12 +16,18 @@ # RUN: echo "_foo4" >> %t_order.txt # RUN: echo "_bar1" >> %t_order.txt # RUN: echo "_foo1" >> %t_order.txt +# RUN: echo "_init2" >> %t_order.txt +# RUN: echo "_init1" >> %t_order.txt # RUN: ld.lld --symbol-ordering-file %t_order.txt %t.o -o %t2.out # RUN: llvm-objdump -s %t2.out| FileCheck %s --check-prefix=AFTER +# RUN: ld.lld --symbol-ordering-file=%t_order.txt %t.o -o %t2.out +# RUN: llvm-objdump -s %t2.out| FileCheck %s --check-prefix=AFTER # AFTER: Contents of section .foo: # AFTER-NEXT: 201000 44335566 2211 +# AFTER: Contents of section .init: +# AFTER-NEXT: 201006 1122 .section .foo,"ax",@progbits,unique,1 _foo1: @@ -42,3 +50,11 @@ _foo5: .byte 0x55 _bar1: .byte 0x66 + +.section .init,"ax",@progbits,unique,1 +_init1: + .byte 0x11 + +.section .init,"ax",@progbits,unique,2 +_init2: + .byte 0x22 diff --git a/test/ELF/symbol-override.s b/test/ELF/symbol-override.s index 8b62d8749aa0..2c3573381c1c 100644 --- a/test/ELF/symbol-override.s +++ b/test/ELF/symbol-override.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/symbol-override.s -o %t2.o // RUN: ld.lld -shared %t2.o -o %t2.so diff --git a/test/ELF/symbols.s b/test/ELF/symbols.s index 54dfcbd087cd..e87b6438494a 100644 --- a/test/ELF/symbols.s +++ b/test/ELF/symbols.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t // RUN: ld.lld %t -o %t2 // RUN: llvm-readobj -symbols -sections %t2 | FileCheck %s -// REQUIRES: x86 .type _start, @function .globl _start diff --git a/test/ELF/symver-archive.s b/test/ELF/symver-archive.s index be50503a3f5d..3e22dd24b66d 100644 --- a/test/ELF/symver-archive.s +++ b/test/ELF/symver-archive.s @@ -4,7 +4,7 @@ # RUN: llvm-ar rcs %t.a %t1 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/symver-archive1.s -o %t2.o # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/symver-archive2.s -o %t3.o -# RUN: ld.lld -o %t.out %t2.o %t3.o %t.a +# RUN: ld.lld -o /dev/null %t2.o %t3.o %t.a .text .globl x diff --git a/test/ELF/sysroot.s b/test/ELF/sysroot.s index 6b40c7d3952a..e9d6862b7a32 100644 --- a/test/ELF/sysroot.s +++ b/test/ELF/sysroot.s @@ -1,10 +1,10 @@ +// REQUIRES: x86 // RUN: mkdir -p %t/lib // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t/m.o // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ // RUN: %p/Inputs/libsearch-st.s -o %t/st.o // RUN: rm -f %t/lib/libls.a // RUN: llvm-ar rcs %t/lib/libls.a %t/st.o -// REQUIRES: x86 // Should not link because of undefined symbol _bar // RUN: not ld.lld -o %t/r %t/m.o 2>&1 \ diff --git a/test/ELF/sysv-hash-no-rosegment.s b/test/ELF/sysv-hash-no-rosegment.s new file mode 100644 index 000000000000..31b9d2fbec05 --- /dev/null +++ b/test/ELF/sysv-hash-no-rosegment.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld -shared --no-rosegment -o %t %t.o +# RUN: llvm-readobj -hash-table %t | FileCheck %s + +# CHECK: HashTable { +# CHECK-NEXT: Num Buckets: 2 +# CHECK-NEXT: Num Chains: 2 +# CHECK-NEXT: Buckets: [1, 0] +# CHECK-NEXT: Chains: [0, 0] +# CHECK-NEXT: } + +callq undef@PLT diff --git a/test/ELF/text-section-prefix.s b/test/ELF/text-section-prefix.s new file mode 100644 index 000000000000..e39536da387d --- /dev/null +++ b/test/ELF/text-section-prefix.s @@ -0,0 +1,39 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld -z keep-text-section-prefix %t -o %t2 +# RUN: llvm-readelf -l %t2 | FileCheck %s +# RUN: ld.lld %t -o %t3 +# RUN: llvm-readelf -l %t3 | FileCheck --check-prefix=CHECKNO %s +# RUN: ld.lld -z nokeep-text-section-prefix %t -o %t4 +# RUN: llvm-readelf -l %t4 | FileCheck --check-prefix=CHECKNO %s + +# CHECK: .text +# CHECK: .text.hot +# CHECK: .text.startup +# CHECK: .text.exit +# CHECK: .text.unlikely +# CHECKNO: .text +# CHECKNO-NOT: .text.hot + +_start: + ret + +.section .text.f,"ax" +f: + nop + +.section .text.hot.f_hot,"ax" +f_hot: + nop + +.section .text.startup.f_startup,"ax" +f_startup: + nop + +.section .text.exit.f_exit,"ax" +f_exit: + nop + +.section .text.unlikely.f_unlikely,"ax" +f_unlikely: + nop diff --git a/test/ELF/tls-archive.s b/test/ELF/tls-archive.s index 9a88fddffd36..640e68ac3a7f 100644 --- a/test/ELF/tls-archive.s +++ b/test/ELF/tls-archive.s @@ -3,7 +3,7 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/tls-mismatch.s -o %t2 // RUN: rm -f %t.a // RUN: llvm-ar cru %t.a %t2 -// RUN: ld.lld %t.a %t -o %t3 +// RUN: ld.lld %t.a %t -o /dev/null .globl _start,tlsvar _start: diff --git a/test/ELF/tls-error.s b/test/ELF/tls-error.s index b61789901049..989a63eb709b 100644 --- a/test/ELF/tls-error.s +++ b/test/ELF/tls-error.s @@ -1,6 +1,6 @@ // REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -// RUN: not ld.lld %t -o %tout 2>&1 | FileCheck %s +// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s // CHECK: R_X86_64_TPOFF32 out of range .global _start diff --git a/test/ELF/tls-got.s b/test/ELF/tls-got.s index b1686cd6d5f4..bedaaebeeb3c 100644 --- a/test/ELF/tls-got.s +++ b/test/ELF/tls-got.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/tls-got.s -o %t2.o // RUN: ld.lld -shared %t2.o -o %t2.so @@ -25,13 +26,13 @@ // CHECK: Relocations [ // CHECK-NEXT: Section (4) .rela.dyn { // CHECK-NEXT: 0x2020B8 R_X86_64_TPOFF64 tls0 0x0 -// CHECK-NEXT: [[ADDR]] R_X86_64_TPOFF64 tls1 0x0 +// CHECK-NEXT: 0x2020B0 R_X86_64_TPOFF64 tls1 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] -//0x201000 + 4249 + 7 = 0x2020B0 -//0x20100A + 4247 + 7 = 0x2020B8 -//0x201014 + 4237 + 7 = 0x2020B8 +//0x201000 + 4265 + 7 = 0x2020B0 +//0x20100A + 4263 + 7 = 0x2020B8 +//0x201014 + 4253 + 7 = 0x2020B8 //DISASM: Disassembly of section .text: //DISASM-NEXT: main: //DISASM-NEXT: 201000: 48 8b 05 a9 10 00 00 movq 4265(%rip), %rax diff --git a/test/ELF/tls-in-archive.s b/test/ELF/tls-in-archive.s index 71f60e380f33..ac1b4cc11ea4 100644 --- a/test/ELF/tls-in-archive.s +++ b/test/ELF/tls-in-archive.s @@ -2,7 +2,7 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/tls-in-archive.s -o %t1.o // RUN: llvm-ar cru %t.a %t1.o // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t2.o -// RUN: ld.lld %t2.o %t.a -o %tout +// RUN: ld.lld %t2.o %t.a -o /dev/null .globl _start _start: diff --git a/test/ELF/tls-mismatch.s b/test/ELF/tls-mismatch.s index 21994d19af32..d7ce224c1fbb 100644 --- a/test/ELF/tls-mismatch.s +++ b/test/ELF/tls-mismatch.s @@ -1,7 +1,7 @@ // 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 %p/Inputs/tls-mismatch.s -o %t2 -// RUN: not ld.lld %t %t2 -o %t3 2>&1 | FileCheck %s +// RUN: not ld.lld %t %t2 -o /dev/null 2>&1 | FileCheck %s // CHECK: TLS attribute mismatch: tlsvar // CHECK: >>> defined in diff --git a/test/ELF/tls-opt-gdie.s b/test/ELF/tls-opt-gdie.s index 6e8531257714..6d0eb979149a 100644 --- a/test/ELF/tls-opt-gdie.s +++ b/test/ELF/tls-opt-gdie.s @@ -1,3 +1,4 @@ +// 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 %p/Inputs/tls-opt-gdie.s -o %tso.o // RUN: ld.lld -shared %tso.o -o %t.so diff --git a/test/ELF/tls-opt-gdiele-i686.s b/test/ELF/tls-opt-gdiele-i686.s index 2dc3731eba57..b39f933e2fdb 100644 --- a/test/ELF/tls-opt-gdiele-i686.s +++ b/test/ELF/tls-opt-gdiele-i686.s @@ -1,3 +1,4 @@ +// 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 diff --git a/test/ELF/tls-opt-i686.s b/test/ELF/tls-opt-i686.s index dec45b4e5c41..d8b1d0eca0b7 100644 --- a/test/ELF/tls-opt-i686.s +++ b/test/ELF/tls-opt-i686.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o // RUN: ld.lld %t.o -o %t1 // RUN: llvm-readobj -r %t1 | FileCheck --check-prefix=NORELOC %s @@ -11,11 +12,11 @@ // LD -> LE: // DISASM-NEXT: 11000: 65 a1 00 00 00 00 movl %gs:0, %eax // DISASM-NEXT: 11006: 90 nop -// DISASM-NEXT: 11007: 8d 74 26 00 leal (%esi), %esi +// DISASM-NEXT: 11007: 8d 74 26 00 leal (%esi,%eiz), %esi // DISASM-NEXT: 1100b: 8d 90 f8 ff ff ff leal -8(%eax), %edx // DISASM-NEXT: 11011: 65 a1 00 00 00 00 movl %gs:0, %eax // DISASM-NEXT: 11017: 90 nop -// DISASM-NEXT: 11018: 8d 74 26 00 leal (%esi), %esi +// DISASM-NEXT: 11018: 8d 74 26 00 leal (%esi,%eiz), %esi // DISASM-NEXT: 1101c: 8d 90 fc ff ff ff leal -4(%eax), %edx // IE -> LE: // 4294967288 == 0xFFFFFFF8 diff --git a/test/ELF/tls-opt-iele-i686-nopic.s b/test/ELF/tls-opt-iele-i686-nopic.s index 02148b5dbff9..50655e34a4ff 100644 --- a/test/ELF/tls-opt-iele-i686-nopic.s +++ b/test/ELF/tls-opt-iele-i686-nopic.s @@ -1,3 +1,4 @@ +// 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 diff --git a/test/ELF/tls-opt-local.s b/test/ELF/tls-opt-local.s index 633c22b0611c..e937d4d5d972 100644 --- a/test/ELF/tls-opt-local.s +++ b/test/ELF/tls-opt-local.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o // RUN: ld.lld %t.o -o %t1 // RUN: llvm-readobj -r %t1 | FileCheck --check-prefix=NORELOC %s diff --git a/test/ELF/tls-opt-no-plt.s b/test/ELF/tls-opt-no-plt.s index 53655d0934d5..c61388648fb1 100644 --- a/test/ELF/tls-opt-no-plt.s +++ b/test/ELF/tls-opt-no-plt.s @@ -1,3 +1,4 @@ +// 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 diff --git a/test/ELF/tls-opt.s b/test/ELF/tls-opt.s index 6835e06f3402..856e82c4b323 100644 --- a/test/ELF/tls-opt.s +++ b/test/ELF/tls-opt.s @@ -1,3 +1,4 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o // RUN: ld.lld %t.o -o %t1 // RUN: llvm-readobj -r %t1 | FileCheck --check-prefix=NORELOC %s diff --git a/test/ELF/tls-static.s b/test/ELF/tls-static.s index 338d95c817ee..3e1aead01a30 100644 --- a/test/ELF/tls-static.s +++ b/test/ELF/tls-static.s @@ -1,10 +1,10 @@ +// 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 // RUN: ld.lld -static %t %tshared -o %tout -// REQUIRES: x86 .global _start _start: diff --git a/test/ELF/trace-symbols.s b/test/ELF/trace-symbols.s index c8ba9b21bcdb..b5c1ddc2a558 100644 --- a/test/ELF/trace-symbols.s +++ b/test/ELF/trace-symbols.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # Test -y symbol and -trace-symbol=symbol # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t @@ -28,7 +29,7 @@ # RUN: ld.lld -y foo -trace-symbol=common -trace-symbol=hsymbol \ # RUN: %t %t1 %t2 -o %t3 2>&1 | FileCheck -check-prefix=OBJECTD2FOO %s # RUN: ld.lld -y foo -y common --trace-symbol=hsymbol \ -# RUN: %t %t2 %t1 -o %t4 2>&1 | FileCheck -check-prefix=OBJECTD2FOO %s +# RUN: %t %t2 %t1 -o /dev/null 2>&1 | FileCheck -check-prefix=OBJECTD2FOO %s # RUN: ld.lld -y foo -y common %t %t1.so %t2 -o %t3 2>&1 | \ # RUN: FileCheck -check-prefix=OBJECTD2FOO %s # OBJECTD2FOO: trace-symbols.s.tmp2: definition of foo @@ -69,12 +70,15 @@ # RUN: ld.lld -y foo -y bar %t %t1.so %t2.so -o %t3 | \ # RUN: FileCheck -check-prefix=SHLIBRBAR %s -# SHLIBRBAR-NOT: trace-symbols.s.tmp1.so: reference to bar +# SHLIBRBAR: trace-symbols.s.tmp1.so: reference to bar # RUN: ld.lld -y foo -y bar %t -u bar --start-lib %t1 %t2 --end-lib -o %t3 | \ # RUN: FileCheck -check-prefix=STARTLIB %s # STARTLIB: trace-symbols.s.tmp1: reference to bar +## Check we do not crash when trying to trace special symbol. +# RUN: not ld.lld -trace-symbol=_end %t -o /dev/null + .hidden hsymbol .globl _start .type _start, @function diff --git a/test/ELF/typed-undef.s b/test/ELF/typed-undef.s index d00e07f82518..879a80975bc8 100644 --- a/test/ELF/typed-undef.s +++ b/test/ELF/typed-undef.s @@ -3,7 +3,7 @@ # We used to crash on this, check that we don't # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: ld.lld %t.o -o %t -pie --unresolved-symbols=ignore-all +# RUN: ld.lld %t.o -o /dev/null -pie --unresolved-symbols=ignore-all .global _start _start: diff --git a/test/ELF/undef-broken-debug.test b/test/ELF/undef-broken-debug.test index 1238ebe70aca..b93d399f36c2 100644 --- a/test/ELF/undef-broken-debug.test +++ b/test/ELF/undef-broken-debug.test @@ -1,6 +1,6 @@ # REQUIRES: x86 # RUN: yaml2obj %s -o %t.o -# RUN: not ld.lld %t.o -o %t.exe 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s # The debug info has a broken relocation. Check that we don't crash # and still report the undefined symbol. @@ -40,6 +40,27 @@ Sections: - Offset: 0x0000000000000029 Symbol: bar Type: R_X86_64_64 + - Name: .debug_info + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: 0C000000040000000000080100000000 + - Name: .rela.debug_info + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .debug_info + Relocations: + - Offset: 0x0000000000000006 + Symbol: .debug_abbrev + Type: R_X86_64_32 + - Offset: 0x000000000000000C + Symbol: .debug_line + Type: R_X86_64_32 + - Name: .debug_abbrev + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '0111001017000000' + Symbols: Global: - Name: _start diff --git a/test/ELF/undef-shared.s b/test/ELF/undef-shared.s index bc38b6082765..701f70ea94e6 100644 --- a/test/ELF/undef-shared.s +++ b/test/ELF/undef-shared.s @@ -1,5 +1,6 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s # CHECK: error: undefined symbol: hidden # CHECK: >>> referenced by {{.*}}:(.data+0x0) diff --git a/test/ELF/undef-shared2.s b/test/ELF/undef-shared2.s new file mode 100644 index 000000000000..cae5ea45642d --- /dev/null +++ b/test/ELF/undef-shared2.s @@ -0,0 +1,11 @@ +# 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/undef-shared2.s -o %t2.o +# RUN: not ld.lld %t.o %t2.o -o %t.so -shared 2>&1 | FileCheck %s +# RUN: not ld.lld %t2.o %t.o -o %t.so -shared 2>&1 | FileCheck %s + +# CHECK: error: undefined symbol: foo + +.data +.quad foo +.protected foo diff --git a/test/ELF/undef-start.s b/test/ELF/undef-start.s index 590d0a80096b..5c591bf70d52 100644 --- a/test/ELF/undef-start.s +++ b/test/ELF/undef-start.s @@ -1,3 +1,5 @@ -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld %t -o %t2 2>&1 # REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s + +# CHECK: warning: cannot find entry symbol _start diff --git a/test/ELF/undef-version-script.s b/test/ELF/undef-version-script.s index 024ac1dc0727..712589e2444f 100644 --- a/test/ELF/undef-version-script.s +++ b/test/ELF/undef-version-script.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o # RUN: echo "{ local: *; };" > %t.script # RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so diff --git a/test/ELF/undef.s b/test/ELF/undef.s index 49f84108f64a..07e3b689a236 100644 --- a/test/ELF/undef.s +++ b/test/ELF/undef.s @@ -2,9 +2,10 @@ # 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/undef.s -o %t2.o # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/undef-debug.s -o %t3.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/undef-bad-debug.s -o %t4.o # RUN: llvm-ar rc %t2.a %t2.o -# RUN: not ld.lld %t.o %t2.a %t3.o -o %t.exe 2>&1 | FileCheck %s -# RUN: not ld.lld -pie %t.o %t2.a %t3.o -o %t.exe 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o %t2.a %t3.o %t4.o -o %t.exe 2>&1 | FileCheck %s +# RUN: not ld.lld -pie %t.o %t2.a %t3.o %t4.o -o %t.exe 2>&1 | FileCheck %s # CHECK: error: undefined symbol: foo # CHECK: >>> referenced by undef.s @@ -33,6 +34,19 @@ # CHECK: >>> referenced by undef-debug.s:11 (dir{{/|\\}}undef-debug.s:11) # CHECK: >>> {{.*}}.o:(.text.2+0x0) +# Show that all line table problems are mentioned as soon as the object's line information +# is requested, even if that particular part of the line information is not currently required. +# CHECK: warning: parsing line table prologue at 0x00000000 should have ended at 0x00000038 but it ended at 0x00000037 +# CHECK: warning: last sequence in debug line table is not terminated! +# CHECK: error: undefined symbol: zed6 +# CHECK: >>> referenced by {{.*}}tmp4.o:(.text+0x0) + +# Show that a problem with one line table's information doesn't affect getting information from +# a different one in the same object. +# CHECK: error: undefined symbol: zed7 +# CHECK: >>> referenced by undef-bad-debug2.s:11 (dir2{{/|\\}}undef-bad-debug2.s:11) +# CHECK: >>> {{.*}}tmp4.o:(.text+0x8) + # RUN: not ld.lld %t.o %t2.a -o %t.exe -no-demangle 2>&1 | \ # RUN: FileCheck -check-prefix=NO-DEMANGLE %s # NO-DEMANGLE: error: undefined symbol: _Z3fooi diff --git a/test/ELF/undefined-opt.s b/test/ELF/undefined-opt.s index d8b793d7bab4..9e93e0fdce4d 100644 --- a/test/ELF/undefined-opt.s +++ b/test/ELF/undefined-opt.s @@ -1,3 +1,4 @@ +# 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 \ # RUN: %p/Inputs/abs.s -o %tabs.o @@ -5,7 +6,6 @@ # RUN: %p/Inputs/shared.s -o %tshared.o # RUN: rm -f %tar.a # RUN: llvm-ar rcs %tar.a %tabs.o %tshared.o -# REQUIRES: x86 # Symbols from the archive are not in if not needed # RUN: ld.lld -o %t1 %t.o %tar.a diff --git a/test/ELF/unresolved-symbols.s b/test/ELF/unresolved-symbols.s index 97ecd5014b12..69da3e63c6d4 100644 --- a/test/ELF/unresolved-symbols.s +++ b/test/ELF/unresolved-symbols.s @@ -21,7 +21,7 @@ ## case when --no-undefined specified. # RUN: ld.lld %t2.o -o %t1_1 --unresolved-symbols=ignore-all # RUN: llvm-readobj %t1_1 > /dev/null 2>&1 -# RUN: not ld.lld %t2.o -o %t1_2 --unresolved-symbols=ignore-all --no-undefined 2>&1 | \ +# RUN: not ld.lld %t2.o -o /dev/null --unresolved-symbols=ignore-all --no-undefined 2>&1 | \ # RUN: FileCheck -check-prefix=ERRUND %s # ERRUND: error: undefined symbol: undef # ERRUND: >>> referenced by {{.*}}:(.text+0x1) @@ -34,11 +34,11 @@ # RUN: ld.lld %t1.o %t2.o -o %t2 --unresolved-symbols=ignore-in-object-files # RUN: llvm-readobj %t2 > /dev/null 2>&1 ## And still should not should produce for undefines from DSOs. -# RUN: ld.lld %t1.o %t.so -o %t2_1 --unresolved-symbols=ignore-in-object-files +# RUN: ld.lld %t1.o %t.so -o /dev/null --unresolved-symbols=ignore-in-object-files # RUN: llvm-readobj %t2 > /dev/null 2>&1 ## Ignoring undefines in shared should produce error for symbol from object. -# RUN: not ld.lld %t2.o -o %t3 --unresolved-symbols=ignore-in-shared-libs 2>&1 | \ +# RUN: not ld.lld %t2.o -o /dev/null --unresolved-symbols=ignore-in-shared-libs 2>&1 | \ # RUN: FileCheck -check-prefix=ERRUND %s ## And should not produce errors for symbols from DSO. # RUN: ld.lld %t1.o %t.so -o %t3_1 --unresolved-symbols=ignore-in-shared-libs @@ -60,9 +60,9 @@ # RUN: llvm-readobj %t6 > /dev/null 2>&1 # RUN: ld.lld -shared %t1.o %t.so -o %t6_1 # RUN: llvm-readobj %t6_1 > /dev/null 2>&1 -# RUN: not ld.lld %t2.o -o %t7 --unresolved-symbols=report-all 2>&1 | \ +# RUN: not ld.lld %t2.o -o /dev/null --unresolved-symbols=report-all 2>&1 | \ # RUN: FileCheck -check-prefix=ERRUND %s -# RUN: not ld.lld %t2.o -o %t7_1 2>&1 | FileCheck -check-prefix=ERRUND %s +# RUN: not ld.lld %t2.o -o /dev/null 2>&1 | FileCheck -check-prefix=ERRUND %s .globl _start _start: diff --git a/test/ELF/user_def_init_array_start.s b/test/ELF/user_def_init_array_start.s index 6c33166d1d4e..a06dbd84ea43 100644 --- a/test/ELF/user_def_init_array_start.s +++ b/test/ELF/user_def_init_array_start.s @@ -1,5 +1,6 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: ld.lld %t.o -o %t2.so -shared +// RUN: ld.lld %t.o -o /dev/null -shared // Allow user defined __init_array_start. This is used by musl because of the // the bfd linker not handling these properly. We always create them as // hidden, musl should not have problems with lld. diff --git a/test/ELF/verdef-defaultver.s b/test/ELF/verdef-defaultver.s index 496a29e3db5a..c8444c4e0663 100644 --- a/test/ELF/verdef-defaultver.s +++ b/test/ELF/verdef-defaultver.s @@ -196,6 +196,6 @@ .globl _start _start: - callq a - callq b - callq c + .long a - . + .long b - . + .long c - . diff --git a/test/ELF/verneed-local.s b/test/ELF/verneed-local.s index 208d8ecf8f62..d779a48c024d 100644 --- a/test/ELF/verneed-local.s +++ b/test/ELF/verneed-local.s @@ -4,7 +4,7 @@ # RUN: ld.lld -shared %t1.o --version-script %t.script -o %t.so # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: not ld.lld %t.o %t.so -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o %t.so -o /dev/null 2>&1 | FileCheck %s # CHECK: error: undefined symbol: f3 # CHECK: >>> referenced by {{.*}}:(.text+0x1) diff --git a/test/ELF/verneed.s b/test/ELF/verneed.s index 27ab047e8222..6e87f046e304 100644 --- a/test/ELF/verneed.s +++ b/test/ELF/verneed.s @@ -10,67 +10,69 @@ # RUN: llvm-readobj -V -sections -section-data -dyn-symbols -dynamic-table %t | FileCheck %s # CHECK: Section { -# CHECK: Index: 1 -# CHECK-NEXT: Name: .dynsym -# CHECK-NEXT: Type: SHT_DYNSYM (0xB) +# CHECK: Index: 1 +# CHECK-NEXT: Name: .dynsym +# CHECK-NEXT: Type: SHT_DYNSYM (0xB) +# CHECK-NEXT: Flags [ (0x2) +# CHECK-NEXT: SHF_ALLOC (0x2) +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x2001C8 +# CHECK-NEXT: Offset: 0x1C8 +# CHECK-NEXT: Size: 96 +# CHECK-NEXT: Link: [[DYNSTR:.*]] +# CHECK-NEXT: Info: 1 +# CHECK-NEXT: AddressAlignment: 8 +# CHECK-NEXT: EntrySize: 24 + +# CHECK: Section { +# CHECK-NEXT: Index: 2 +# CHECK-NEXT: Name: .gnu.version +# CHECK-NEXT: Type: SHT_GNU_versym (0x6FFFFFFF) # CHECK-NEXT: Flags [ (0x2) # CHECK-NEXT: SHF_ALLOC (0x2) # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x2001C8 -# CHECK-NEXT: Offset: 0x1C8 -# CHECK-NEXT: Size: 96 -# CHECK-NEXT: Link: 5 -# CHECK-NEXT: Info: 1 -# CHECK-NEXT: AddressAlignment: 8 -# CHECK-NEXT: EntrySize: 24 -# CHECK: Section { -# CHECK-NEXT: Index: 2 -# CHECK-NEXT: Name: .gnu.version -# CHECK-NEXT: Type: SHT_GNU_versym (0x6FFFFFFF) -# CHECK-NEXT: Flags [ (0x2) -# CHECK-NEXT: SHF_ALLOC (0x2) -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x200228 -# CHECK-NEXT: Offset: 0x228 -# CHECK-NEXT: Size: 8 -# CHECK-NEXT: Link: 1 -# CHECK-NEXT: Info: 0 -# CHECK-NEXT: AddressAlignment: 2 -# CHECK-NEXT: EntrySize: 2 +# CHECK-NEXT: Address: [[VERSYM:.*]] +# CHECK-NEXT: Offset: [[VERSYM_OFFSET:.*]] +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Link: 1 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 2 +# CHECK-NEXT: EntrySize: 2 + # CHECK: Section { -# CHECK-NEXT: Index: 3 -# CHECK-NEXT: Name: .gnu.version_r -# CHECK-NEXT: Type: SHT_GNU_verneed (0x6FFFFFFE) -# CHECK-NEXT: Flags [ (0x2) -# CHECK-NEXT: SHF_ALLOC (0x2) -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x200230 -# CHECK-NEXT: Offset: 0x230 -# CHECK-NEXT: Size: 80 -# CHECK-NEXT: Link: 5 -# CHECK-NEXT: Info: 2 -# CHECK-NEXT: AddressAlignment: 4 -# CHECK-NEXT: EntrySize: 0 -# CHECK: Section { -# CHECK: Index: 5 -# CHECK-NEXT: Name: .dynstr -# CHECK-NEXT: Type: SHT_STRTAB -# CHECK-NEXT: Flags [ (0x2) -# CHECK-NEXT: SHF_ALLOC (0x2) -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x2002A8 -# CHECK-NEXT: Offset: 0x2A8 -# CHECK-NEXT: Size: 47 -# CHECK-NEXT: Link: 0 -# CHECK-NEXT: Info: 0 -# CHECK-NEXT: AddressAlignment: 1 -# CHECK-NEXT: EntrySize: 0 -# CHECK-NEXT: SectionData ( -# CHECK-NEXT: 0000: 00766572 6E656564 312E736F 2E300076 |.verneed1.so.0.v| -# CHECK-NEXT: 0010: 65726E65 6564322E 736F2E30 00663100 |erneed2.so.0.f1.| -# CHECK-NEXT: 0020: 76330066 32007632 00673100 763100 |v3.f2.v2.g1.v1.| -# CHECK-NEXT: ) -# CHECK-NEXT: } +# CHECK-NEXT: Index: 3 +# CHECK-NEXT: Name: .gnu.version_r +# CHECK-NEXT: Type: SHT_GNU_verneed (0x6FFFFFFE) +# CHECK-NEXT: Flags [ (0x2) +# CHECK-NEXT: SHF_ALLOC (0x2) +# CHECK-NEXT: ] +# CHECK-NEXT: Address: [[VERNEED:.*]] +# CHECK-NEXT: Offset: 0x230 +# CHECK-NEXT: Size: 80 +# CHECK-NEXT: Link: 5 +# CHECK-NEXT: Info: 2 +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 0 + +# CHECK: Index: [[DYNSTR]] +# CHECK-NEXT: Name: .dynstr +# CHECK-NEXT: Type: SHT_STRTAB (0x3) +# CHECK-NEXT: Flags [ (0x2) +# CHECK-NEXT: SHF_ALLOC (0x2) +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x2002A8 +# CHECK-NEXT: Offset: 0x2A8 +# CHECK-NEXT: Size: 47 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 1 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 00766572 6E656564 312E736F 2E300076 |.verneed1.so.0.v| +# CHECK-NEXT: 0010: 65726E65 6564322E 736F2E30 00663100 |erneed2.so.0.f1.| +# CHECK-NEXT: 0020: 76330066 32007632 00673100 763100 |v3.f2.v2.g1.v1.| +# CHECK-NEXT: ) +# CHECK-NEXT: } # CHECK: DynamicSymbols [ # CHECK-NEXT: Symbol { @@ -111,14 +113,14 @@ # CHECK-NEXT: } # CHECK-NEXT: ] -# CHECK: 0x000000006FFFFFF0 VERSYM 0x200228 -# CHECK-NEXT: 0x000000006FFFFFFE VERNEED 0x200230 +# CHECK: 0x000000006FFFFFF0 VERSYM [[VERSYM]] +# CHECK-NEXT: 0x000000006FFFFFFE VERNEED [[VERNEED]] # CHECK-NEXT: 0x000000006FFFFFFF VERNEEDNUM 2 # CHECK: Version symbols { # CHECK-NEXT: Section Name: .gnu.version -# CHECK-NEXT: Address: 0x200228 -# CHECK-NEXT: Offset: 0x228 +# CHECK-NEXT: Address: [[VERSYM]] +# CHECK-NEXT: Offset: [[VERSYM_OFFSET]] # CHECK-NEXT: Link: 1 # CHECK-NEXT: Symbols [ # CHECK-NEXT: Symbol { diff --git a/test/ELF/version-exclude-libs.s b/test/ELF/version-exclude-libs.s new file mode 100644 index 000000000000..7335c2315eba --- /dev/null +++ b/test/ELF/version-exclude-libs.s @@ -0,0 +1,30 @@ +// REQUIRES: x86 +// RUN: llvm-mc %p/Inputs/versiondef.s -o %t.o -filetype=obj -triple=x86_64-pc-linux +// RUN: llvm-ar -r %t.a %t.o +// RUN: llvm-mc %s -o %t2.o -filetype=obj -triple=x86_64-pc-linux +// RUN: ld.lld %t2.o %t.a --shared --exclude-libs ALL -o %t.so +// RUN: llvm-readobj -symbols %t.so | FileCheck %s +// RUN: llvm-readobj -dyn-symbols %t.so | FileCheck -check-prefix CHECK-DYN %s +// RUN: not ld.lld %t2.o %t.a --shared -o %t.so 2>&1 | FileCheck -check-prefix=CHECK-ERR %s + +// Test that we do not give an error message for undefined versions when the +// symbol is not exported to the dynamic symbol table. + +// CHECK: Name: func +// CHECK-NEXT: Value: +// CHECK-NEXT: Size: +// CHECK-NEXT: Binding: Local (0x0) + +// CHECK-DYN-NOT: func + +// CHECK-ERR: symbol func@@VER2 has undefined version VER2 +// CHECK-ERR-NEXT: symbol func@VER has undefined version VER + + .text + .globl _start + .globl func +_start: + ret + + .data + .quad func diff --git a/test/ELF/version-script-complex-wildcards.s b/test/ELF/version-script-complex-wildcards.s index 61e1069e2eac..ce001d0b76c3 100644 --- a/test/ELF/version-script-complex-wildcards.s +++ b/test/ELF/version-script-complex-wildcards.s @@ -46,7 +46,7 @@ # RUN: llvm-readobj -V %t8.so | FileCheck %s --check-prefix=ABBABC # RUN: echo "FOO { global: extern \"C++\" { a[; }; };" > %t9.script -# RUN: not ld.lld --version-script %t9.script -shared %t.o -o %t9.so 2>&1 \ +# RUN: not ld.lld --version-script %t9.script -shared %t.o -o /dev/null 2>&1 \ # RUN: | FileCheck %s --check-prefix=ERROR # ERROR: invalid glob pattern: a[ diff --git a/test/ELF/version-script-extern-undefined.s b/test/ELF/version-script-extern-undefined.s new file mode 100644 index 000000000000..518b122ce7cd --- /dev/null +++ b/test/ELF/version-script-extern-undefined.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "FOO { global: extern \"C++\" { \"abb(int)\"; }; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -V %t.so | FileCheck %s + +# CHECK: Symbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Version: 0 +# CHECK-NEXT: Name: @ +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Version: 1 +# CHECK-NEXT: Name: _Z3abbi@ +# CHECK-NEXT: } +# CHECK-NEXT: ] + +.globl _Z3abbi diff --git a/test/ELF/version-script-extern.s b/test/ELF/version-script-extern.s index c63ff817fb40..16f400354356 100644 --- a/test/ELF/version-script-extern.s +++ b/test/ELF/version-script-extern.s @@ -7,7 +7,7 @@ # RUN: echo "LIBSAMPLE_2.0 { global:" >> %t.script # RUN: echo ' extern "C" { _Z3bari; };' >> %t.script # RUN: echo "};" >> %t.script -# RUN: ld.lld --hash-style=sysv --version-script %t.script -shared %t.o -o %t.so +# RUN: ld.lld --hash-style=sysv --version-script %t.script -soname fixed-length-string -shared %t.o -o %t.so # RUN: llvm-readobj -V -dyn-symbols %t.so | FileCheck --check-prefix=DSO %s # DSO: DynamicSymbols [ diff --git a/test/ELF/version-script-extern2.s b/test/ELF/version-script-extern2.s new file mode 100644 index 000000000000..834bbe1122e5 --- /dev/null +++ b/test/ELF/version-script-extern2.s @@ -0,0 +1,22 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "FOO { global: extern \"C++\" { \"bar\"; }; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -V %t.so | FileCheck %s + +# CHECK: Symbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Version: 0 +# CHECK-NEXT: Name: @ +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Version: 2 +# CHECK-NEXT: Name: bar@@FOO +# CHECK-NEXT: } +# CHECK-NEXT: ] + +.globl bar +.type bar,@function +bar: +retq diff --git a/test/ELF/version-script-glob.s b/test/ELF/version-script-glob.s index 8149ead8292f..d9ead0503d64 100644 --- a/test/ELF/version-script-glob.s +++ b/test/ELF/version-script-glob.s @@ -48,7 +48,7 @@ local: # CHECK-NEXT: ] # RUN: echo "{ global : local; local: *; };" > %t1.script -# RUN: ld.lld -shared --version-script %t1.script %t.o -o %t1.so +# RUN: ld.lld -shared --version-script %t1.script %t.o -o /dev/null # LOCAL: DynamicSymbols [ # LOCAL-NEXT: Symbol { diff --git a/test/ELF/version-script-in-search-path.s b/test/ELF/version-script-in-search-path.s new file mode 100644 index 000000000000..948f33792a9c --- /dev/null +++ b/test/ELF/version-script-in-search-path.s @@ -0,0 +1,10 @@ +# REQUIRES: x86 +# Check that we fall back to search paths if a version script was not found +# This behaviour matches ld.bfd. + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: mkdir -p %T/searchpath +# RUN: echo '{};' > %T/searchpath/%basename_t.script +# RUN: ld.lld -L%T/searchpath --version-script=%basename_t.script %t.o -o /dev/null +# RUN: not ld.lld --version-script=%basename_t.script %t.o 2>&1 | FileCheck -check-prefix ERROR %s +# ERROR: error: cannot find version script diff --git a/test/ELF/version-script-missing.s b/test/ELF/version-script-missing.s index ad4786e70cc5..a82a37e41271 100644 --- a/test/ELF/version-script-missing.s +++ b/test/ELF/version-script-missing.s @@ -4,4 +4,4 @@ # 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 %t.so +# 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 index 6a897159d2d0..d99b87bf937b 100644 --- a/test/ELF/version-script-no-warn.s +++ b/test/ELF/version-script-no-warn.s @@ -5,7 +5,7 @@ # 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 +# RUN: ld.lld --fatal-warnings --shared --version-script %t.script %t.o %t2.so -o /dev/null .global bar bar: diff --git a/test/ELF/version-script-no-warn2.s b/test/ELF/version-script-no-warn2.s index 52beff366bb7..795fbb0b4f28 100644 --- a/test/ELF/version-script-no-warn2.s +++ b/test/ELF/version-script-no-warn2.s @@ -1,8 +1,9 @@ +# 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 %t2.so --fatal-warnings +# 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 247752cac844..0eae1fcdb05a 100644 --- a/test/ELF/version-script-noundef.s +++ b/test/ELF/version-script-noundef.s @@ -2,6 +2,8 @@ # 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 --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 # ERR1: version script assignment of 'VERSION_1.0' to symbol 'bar' failed: symbol not defined diff --git a/test/ELF/version-script-symver.s b/test/ELF/version-script-symver.s index 0a4eddd46cec..b6355949fad0 100644 --- a/test/ELF/version-script-symver.s +++ b/test/ELF/version-script-symver.s @@ -1,6 +1,6 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: ld.lld %t.o -o %t +# RUN: ld.lld %t.o -o /dev/null .global _start .global bar diff --git a/test/ELF/version-script.s b/test/ELF/version-script.s index abc716250eba..75083ac9a767 100644 --- a/test/ELF/version-script.s +++ b/test/ELF/version-script.s @@ -34,9 +34,9 @@ # RUN: echo "VERSION_1.0 { global: foo1; local: *; };" > %t6.script # RUN: echo "VERSION_2.0 { global: foo1; local: *; };" >> %t6.script -# RUN: ld.lld --version-script %t6.script -shared %t.o %t2.so -o %t6.so 2>&1 | \ -# RUN: FileCheck -check-prefix=WARN2 %s -# WARN2: duplicate symbol 'foo1' in version script +# RUN: not ld.lld --version-script %t6.script -shared %t.o %t2.so -o /dev/null 2>&1 | \ +# RUN: FileCheck -check-prefix=ERR3 %s +# ERR3: duplicate symbol 'foo1' in version script # RUN: echo "{ foo1; foo2; };" > %t.list # RUN: ld.lld --version-script %t.script --dynamic-list %t.list %t.o %t2.so -o %t2 @@ -213,6 +213,9 @@ # ALL-NEXT: } # ALL-NEXT: ] +# RUN: echo "VERSION_1.0 { global: foo1; foo1; local: *; };" > %t8.script +# RUN: ld.lld --version-script %t8.script -shared %t.o -o /dev/null --fatal-warnings + .globl foo1 foo1: call bar@PLT diff --git a/test/ELF/version-symbol-error.s b/test/ELF/version-symbol-error.s index fb83b359485b..f916fe7b34f8 100644 --- a/test/ELF/version-symbol-error.s +++ b/test/ELF/version-symbol-error.s @@ -1,7 +1,7 @@ // REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: echo "V1 {};" > %t.script -// RUN: not ld.lld -shared -version-script=%t.script %t.o -o %t.so 2>&1 \ +// RUN: not ld.lld -shared -version-script=%t.script %t.o -o /dev/null 2>&1 \ // RUN: | FileCheck %s // CHECK: .o: symbol foo@V2 has undefined version V2 diff --git a/test/ELF/version-undef-sym.s b/test/ELF/version-undef-sym.s index 20e92e61f647..13a6dc41fd10 100644 --- a/test/ELF/version-undef-sym.s +++ b/test/ELF/version-undef-sym.s @@ -35,7 +35,7 @@ // CHECK: Name: bar // But now we can successfully find bar. -// RUN: ld.lld %t.o %p/Inputs/version-undef-sym.so -o %t.exe +// RUN: ld.lld %t.o %p/Inputs/version-undef-sym.so -o /dev/null .global _start _start: diff --git a/test/ELF/visibility.s b/test/ELF/visibility.s index 7af29c957b52..0582d718e8ee 100644 --- a/test/ELF/visibility.s +++ b/test/ELF/visibility.s @@ -1,8 +1,8 @@ +// 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 %p/Inputs/visibility.s -o %t2 // RUN: ld.lld -shared %t %t2 -o %t3 // RUN: llvm-readobj -t -dyn-symbols %t3 | FileCheck %s -// REQUIRES: x86 // CHECK: Symbols [ // CHECK-NEXT: Symbol { diff --git a/test/ELF/warn-backrefs.s b/test/ELF/warn-backrefs.s new file mode 100644 index 000000000000..28937e199cae --- /dev/null +++ b/test/ELF/warn-backrefs.s @@ -0,0 +1,48 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: echo ".globl foo; foo:" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t2.o +# RUN: rm -f %t2.a +# RUN: llvm-ar rcs %t2.a %t2.o + +# RUN: ld.lld --fatal-warnings -o %t.exe %t1.o %t2.a +# RUN: ld.lld --fatal-warnings -o %t.exe %t2.a %t1.o +# RUN: ld.lld --fatal-warnings --warn-backrefs -o %t.exe %t1.o %t2.a +# RUN: ld.lld --fatal-warnings --warn-backrefs -o %t.exe %t1.o --start-lib %t2.o --end-lib + +# RUN: ld.lld --fatal-warnings --warn-backrefs -o %t.exe --start-group %t2.a %t1.o --end-group +# RUN: ld.lld --fatal-warnings --warn-backrefs -o %t.exe "-(" %t2.a %t1.o "-)" + +# RUN: echo "INPUT(\"%t1.o\" \"%t2.a\")" > %t1.script +# RUN: ld.lld --fatal-warnings --warn-backrefs -o %t.exe %t1.script + +# RUN: echo "GROUP(\"%t2.a\" \"%t1.o\")" > %t2.script +# RUN: ld.lld --fatal-warnings --warn-backrefs -o %t.exe %t2.script + +# RUN: not ld.lld --fatal-warnings --warn-backrefs -o %t.exe %t2.a %t1.o 2>&1 | FileCheck %s +# RUN: not ld.lld --fatal-warnings --warn-backrefs -o %t.exe %t2.a "-(" %t1.o "-)" 2>&1 | FileCheck %s +# RUN: not ld.lld --fatal-warnings --warn-backrefs -o %t.exe --start-group %t2.a --end-group %t1.o 2>&1 | FileCheck %s + +# RUN: echo "GROUP(\"%t2.a\")" > %t3.script +# RUN: not ld.lld --fatal-warnings --warn-backrefs -o %t.exe %t3.script %t1.o 2>&1 | FileCheck %s +# RUN: ld.lld --fatal-warnings --warn-backrefs -o %t.exe "-(" %t3.script %t1.o "-)" + +# CHECK: backward reference detected: foo in {{.*}}1.o refers to {{.*}}2.a + +# RUN: not ld.lld --fatal-warnings --start-group --start-group 2>&1 | FileCheck -check-prefix=START %s +# START: nested --start-group + +# RUN: not ld.lld --fatal-warnings --end-group 2>&1 | FileCheck -check-prefix=END %s +# END: stray --end-group + +# RUN: echo ".globl bar; bar:" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t3.o +# RUN: echo ".globl foo; foo: call bar" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t4.o +# RUN: ld.lld --fatal-warnings --warn-backrefs %t1.o --start-lib %t3.o %t4.o --end-lib -o /dev/null + +# We don't report backward references to weak symbols as they can be overriden later. +# RUN: echo ".weak foo; foo:" | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t5.o +# RUN: ld.lld --fatal-warnings --warn-backrefs --start-lib %t5.o --end-lib %t1.o %t2.o -o /dev/null + +.globl _start, foo +_start: + call foo diff --git a/test/ELF/warn-common.s b/test/ELF/warn-common.s index 783a9ab77b56..ddb4b687a5aa 100644 --- a/test/ELF/warn-common.s +++ b/test/ELF/warn-common.s @@ -7,9 +7,7 @@ # RUN: ld.lld --warn-common %t1.o %t2.o -o %t.out 2>&1 | FileCheck %s --check-prefix=WARN # WARN: multiple common of arr -## no-warn-common is ignored -# RUN: ld.lld --no-warn-common %t1.o %t2.o -o %t.out -# RUN: llvm-readobj %t.out > /dev/null +# RUN: ld.lld --fatal-warnings --warn-common --no-warn-common %t1.o %t2.o -o %t.out ## Report if common is overridden # RUN: ld.lld --warn-common %t1.o %t3.o -o %t.out 2>&1 | FileCheck %s --check-prefix=OVER diff --git a/test/ELF/warn-unresolved-symbols-hidden.s b/test/ELF/warn-unresolved-symbols-hidden.s index 04691f9af948..9e3d9e152104 100644 --- a/test/ELF/warn-unresolved-symbols-hidden.s +++ b/test/ELF/warn-unresolved-symbols-hidden.s @@ -1,6 +1,6 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: not ld.lld -shared %t.o -o %t.so -z defs --warn-unresolved-symbols 2>&1| FileCheck %s +# RUN: not ld.lld -shared %t.o -o /dev/null -z defs --warn-unresolved-symbols 2>&1| FileCheck %s # CHECK: warning: undefined symbol: foo # CHECK: error: undefined symbol: bar diff --git a/test/ELF/warn-unresolved-symbols.s b/test/ELF/warn-unresolved-symbols.s index 3342c6ce50a2..608b35580291 100644 --- a/test/ELF/warn-unresolved-symbols.s +++ b/test/ELF/warn-unresolved-symbols.s @@ -2,11 +2,11 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o ## The link should fail with an undef error by default -# RUN: not ld.lld %t1.o -o %t3 2>&1 | \ +# RUN: not ld.lld %t1.o -o /dev/null 2>&1 | \ # RUN: FileCheck -check-prefix=ERRUND %s ## --error-unresolved-symbols should generate an error -# RUN: not ld.lld %t1.o -o %t4 --error-unresolved-symbols 2>&1 | \ +# RUN: not ld.lld %t1.o -o /dev/null --error-unresolved-symbols 2>&1 | \ # RUN: FileCheck -check-prefix=ERRUND %s ## --warn-unresolved-symbols should generate a warning @@ -16,19 +16,19 @@ ## Test that the last option wins # RUN: ld.lld %t1.o -o %t5 --error-unresolved-symbols --warn-unresolved-symbols 2>&1 | \ # RUN: FileCheck -check-prefix=WARNUND %s -# RUN: not ld.lld %t1.o -o %t6 --warn-unresolved-symbols --error-unresolved-symbols 2>&1 | \ +# RUN: not ld.lld %t1.o -o /dev/null --warn-unresolved-symbols --error-unresolved-symbols 2>&1 | \ # RUN: FileCheck -check-prefix=ERRUND %s ## Do not report undefines if linking relocatable or shared. ## And while we're at it, check that we can accept single - ## variants of these options. -# RUN: ld.lld -r %t1.o -o %t7 -error-unresolved-symbols 2>&1 | \ +# RUN: ld.lld -r %t1.o -o /dev/null -error-unresolved-symbols 2>&1 | \ # RUN: FileCheck -allow-empty -check-prefix=NOERR %s -# RUN: ld.lld -shared %t1.o -o %t8.so --error-unresolved-symbols 2>&1 | \ +# RUN: ld.lld -shared %t1.o -o /dev/null --error-unresolved-symbols 2>&1 | \ # RUN: FileCheck -allow-empty -check-prefix=NOERR %s -# RUN: ld.lld -r %t1.o -o %t9 -warn-unresolved-symbols 2>&1 | \ +# RUN: ld.lld -r %t1.o -o /dev/null -warn-unresolved-symbols 2>&1 | \ # RUN: FileCheck -allow-empty -check-prefix=NOWARN %s -# RUN: ld.lld -shared %t1.o -o %t10.so --warn-unresolved-symbols 2>&1 | \ +# RUN: ld.lld -shared %t1.o -o /dev/null --warn-unresolved-symbols 2>&1 | \ # RUN: FileCheck -allow-empty -check-prefix=NOWARN %s # ERRUND: error: undefined symbol: undef diff --git a/test/ELF/weak-and-strong-undef.s b/test/ELF/weak-and-strong-undef.s index db93470636df..32ce649bb147 100644 --- a/test/ELF/weak-and-strong-undef.s +++ b/test/ELF/weak-and-strong-undef.s @@ -1,6 +1,6 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/weak-and-strong-undef.s -o %t2.o +# RUN: echo ".weak foo" | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t2.o # RUN: not ld.lld %t1.o %t2.o -o %t 2>&1 | FileCheck %s # RUN: not ld.lld %t2.o %t1.o -o %t 2>&1 | FileCheck %s diff --git a/test/ELF/weak-shared-gc.s b/test/ELF/weak-shared-gc.s new file mode 100644 index 000000000000..2cafbe8dbb08 --- /dev/null +++ b/test/ELF/weak-shared-gc.s @@ -0,0 +1,21 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: echo -e '.globl __cxa_finalize\n__cxa_finalize:' | \ +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t2.o +# RUN: ld.lld %t2.o -o %t2.so -shared +# RUN: ld.lld %t1.o --as-needed --gc-sections %t2.so -o %t +# RUN: llvm-readelf -dynamic-table -dyn-symbols %t | FileCheck %s + +# The crt files on linux have a weak reference to __cxa_finalize. It +# is important that a weak undefined reference is produced. Like +# other weak undefined references, the shared library is not marked as +# needed. + +# CHECK-NOT: NEEDED +# CHECK: WEAK DEFAULT UND __cxa_finalize +# CHECK-NOT: NEEDED + + .global _start +_start: + .weak __cxa_finalize + call __cxa_finalize@PLT diff --git a/test/ELF/weak-undef-lazy.s b/test/ELF/weak-undef-lazy.s index 113013ea2e0f..0a4188fca271 100644 --- a/test/ELF/weak-undef-lazy.s +++ b/test/ELF/weak-undef-lazy.s @@ -3,7 +3,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/weak-undef-lazy.s -o %t2.o # RUN: rm -f %t2.a # RUN: llvm-ar rc %t2.a %t2.o -# RUN: ld.lld %t.o %t2.a -o %t --export-dynamic +# RUN: ld.lld %t.o %t2.a -o /dev/null --export-dynamic .global _start _start: diff --git a/test/ELF/weak-undef-lib.s b/test/ELF/weak-undef-lib.s new file mode 100644 index 000000000000..e4e7f46ebaa9 --- /dev/null +++ b/test/ELF/weak-undef-lib.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: echo -e '.globl foo\nfoo: ret' | \ +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t2.o + +# RUN: ld.lld -shared -o %t.so %t1.o --start-lib %t2.o +# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck %s + +# CHECK: Name: foo +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Weak +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined + +.weak foo +.data +.quad foo diff --git a/test/ELF/weak-undef-rw.s b/test/ELF/weak-undef-rw.s new file mode 100644 index 000000000000..c75e7d67db3d --- /dev/null +++ b/test/ELF/weak-undef-rw.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t --export-dynamic +# RUN: llvm-readobj -r %t | FileCheck %s + +# CHECK: R_X86_64_64 foobar 0x0 + + .global _start +_start: + .data + .weak foobar + .quad foobar diff --git a/test/ELF/whole-archive-name.s b/test/ELF/whole-archive-name.s new file mode 100644 index 000000000000..1cf7962e62fd --- /dev/null +++ b/test/ELF/whole-archive-name.s @@ -0,0 +1,15 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +// RUN: mkdir -p %t.dir +// RUN: rm -f %t.dir/liba.a +// RUN: llvm-ar rcs %t.dir/liba.a %t.o +// RUN: ld.lld -L%t.dir --whole-archive -la -o /dev/null -Map=- | FileCheck %s + +.globl _start +_start: + nop + +// There was a use after free of an archive name. +// Valgrind/asan would detect it. +// CHECK: liba.a(whole-archive-name.s.tmp.o):(.text) +// CHECK-NEXT: _start diff --git a/test/ELF/wrap.s b/test/ELF/wrap.s index b96917b7be49..a02592e24ebd 100644 --- a/test/ELF/wrap.s +++ b/test/ELF/wrap.s @@ -6,6 +6,8 @@ // RUN: llvm-objdump -d -print-imm-hex %t3 | FileCheck %s // RUN: ld.lld -o %t3 %t %t2 --wrap foo -wrap=nosuchsym // RUN: llvm-objdump -d -print-imm-hex %t3 | FileCheck %s +// RUN: ld.lld -o %t3 %t %t2 --wrap foo --wrap foo -wrap=nosuchsym +// RUN: llvm-objdump -d -print-imm-hex %t3 | FileCheck %s // CHECK: _start: // CHECK-NEXT: movl $0x11010, %edx diff --git a/test/ELF/writable-merge.s b/test/ELF/writable-merge.s index 3006fa387fb5..91a7e07d7ce5 100644 --- a/test/ELF/writable-merge.s +++ b/test/ELF/writable-merge.s @@ -1,6 +1,6 @@ // REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux -// RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s // CHECK: writable SHF_MERGE section is not supported .section .foo,"awM",@progbits,4 diff --git a/test/ELF/writable-sec-plt-reloc.s b/test/ELF/writable-sec-plt-reloc.s index 97a21b5fac02..c44ca6a696c5 100644 --- a/test/ELF/writable-sec-plt-reloc.s +++ b/test/ELF/writable-sec-plt-reloc.s @@ -11,4 +11,4 @@ .section .bar,"awx" .global _start _start: - call foo + .long foo - . diff --git a/test/ELF/x86-64-dyn-rel-error.s b/test/ELF/x86-64-dyn-rel-error.s index 7a705eb54177..7753a4dc4aec 100644 --- a/test/ELF/x86-64-dyn-rel-error.s +++ b/test/ELF/x86-64-dyn-rel-error.s @@ -9,6 +9,8 @@ _start: .data .long zed -// CHECK: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC +// 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 %s +// RUN: ld.lld --noinhibit-exec %t.o %t2.so -o %t 2>&1 | FileCheck --check-prefix=WARN %s + +// WARN: symbol 'zed' has no type diff --git a/test/ELF/x86-64-dyn-rel-error2.s b/test/ELF/x86-64-dyn-rel-error2.s index 9b731e268875..b3259395d245 100644 --- a/test/ELF/x86-64-dyn-rel-error2.s +++ b/test/ELF/x86-64-dyn-rel-error2.s @@ -2,9 +2,9 @@ // 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 %t2.o -shared -o %t2.so -// RUN: not ld.lld -shared %t.o %t2.so -o %t 2>&1 | FileCheck %s +// RUN: not ld.lld -shared %t.o %t2.so -o /dev/null 2>&1 | FileCheck %s -// CHECK: relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC +// CHECK: relocation R_X86_64_PC32 cannot be used against symbol zed; recompile with -fPIC // CHECK: >>> defined in {{.*}}.so // CHECK: >>> referenced by {{.*}}.o:(.data+0x0) diff --git a/test/ELF/x86-64-dyn-rel-error3.s b/test/ELF/x86-64-dyn-rel-error3.s new file mode 100644 index 000000000000..86cef1426df9 --- /dev/null +++ b/test/ELF/x86-64-dyn-rel-error3.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: not ld.lld %t.o -shared -o /dev/null 2>&1 | FileCheck %s + +# CHECK: relocation R_X86_64_8 cannot be used against symbol foo; recompile with -fPIC +# CHECK: relocation R_X86_64_16 cannot be used against symbol foo; recompile with -fPIC +# CHECK: relocation R_X86_64_PC8 cannot be used against symbol foo; recompile with -fPIC +# CHECK: relocation R_X86_64_PC16 cannot be used against symbol foo; recompile with -fPIC + +.global foo + +.data +.byte foo # R_X86_64_8 +.short foo # R_X86_64_16 +.byte foo - . # R_X86_64_PC8 +.short foo - . # R_X86_64_PC16 diff --git a/test/ELF/x86-64-plt-high-addr.s b/test/ELF/x86-64-plt-high-addr.s new file mode 100644 index 000000000000..4acccb63f4a7 --- /dev/null +++ b/test/ELF/x86-64-plt-high-addr.s @@ -0,0 +1,24 @@ +// REQUIRES: x86 + +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t1.o +// RUN: ld.lld -o %t.so -shared %t1.o + +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o +// RUN: ld.lld -o %t1.exe %t2.o %t.so -image-base=0xcafe00000000 +// RUN: llvm-objdump -s -j .got.plt %t1.exe | FileCheck %s + +// CHECK: Contents of section .got.plt: +// CHECK-NEXT: cafe00002000 00300000 feca0000 00000000 00000000 +// CHECK-NEXT: cafe00002010 00000000 00000000 26100000 feca0000 + +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o +// RUN: ld.lld -o %t2.exe %t2.o %t.so -image-base=0xcafe00000000 -z retpolineplt +// RUN: llvm-objdump -s -j .got.plt %t2.exe | FileCheck -check-prefix=RETPOLINE %s + +// RETPOLINE: Contents of section .got.plt: +// RETPOLINE-NEXT: cafe00002000 00300000 feca0000 00000000 00000000 +// RETPOLINE-NEXT: cafe00002010 00000000 00000000 51100000 feca0000 + +.global _start +_start: + jmp bar@PLT diff --git a/test/ELF/x86-64-reloc-16.s b/test/ELF/x86-64-reloc-16.s index 4822ec71757b..5157c3706fef 100644 --- a/test/ELF/x86-64-reloc-16.s +++ b/test/ELF/x86-64-reloc-16.s @@ -3,12 +3,12 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-16.s -o %t1 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-16-error.s -o %t2 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: ld.lld -shared %t %t1 -o %t3 +// RUN: ld.lld -shared %t %t1 -o /dev/null // CHECK: Contents of section .text: // CHECK-NEXT: 200000 42 -// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s +// RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s // ERROR: relocation R_X86_64_16 out of range: 65536 is not in [0, 65535] .short foo diff --git a/test/ELF/x86-64-reloc-32-fpic.s b/test/ELF/x86-64-reloc-32-fpic.s index e3e7c6834d21..1c4754f1e2c6 100644 --- a/test/ELF/x86-64-reloc-32-fpic.s +++ b/test/ELF/x86-64-reloc-32-fpic.s @@ -1,8 +1,8 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s +# RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s -# CHECK: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC +# CHECK: relocation R_X86_64_32 cannot be used against symbol _shared; recompile with -fPIC # CHECK: >>> defined in {{.*}} # CHECK: >>> referenced by {{.*}}:(.data+0x0) diff --git a/test/ELF/x86-64-reloc-8.s b/test/ELF/x86-64-reloc-8.s index 8f6ba5aa14bb..f71bafb7ffb1 100644 --- a/test/ELF/x86-64-reloc-8.s +++ b/test/ELF/x86-64-reloc-8.s @@ -3,12 +3,12 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-8.s -o %t1 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-8-error.s -o %t2 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: ld.lld -shared %t %t1 -o %t3 +// RUN: ld.lld -shared %t %t1 -o /dev/null // CHECK: Contents of section .text: // CHECK-NEXT: 200000 42 -// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s +// RUN: not ld.lld -shared %t %t2 -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s // ERROR: relocation R_X86_64_8 out of range: 256 is not in [0, 255] .byte foo diff --git a/test/ELF/x86-64-reloc-debug-overflow.s b/test/ELF/x86-64-reloc-debug-overflow.s new file mode 100644 index 000000000000..d6e6650acd3e --- /dev/null +++ b/test/ELF/x86-64-reloc-debug-overflow.s @@ -0,0 +1,9 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-error.s -o %tabs +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: not ld.lld -shared %tabs %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: (.debug_info+0x0): relocation R_X86_64_32 out of range: 281474976710656 is not in [0, 4294967295]; consider recompiling with -fdebug-types-section to reduce size of debug sections + +.section .debug_info,"",@progbits + .long .debug_info + 0x1000000000000 diff --git a/test/ELF/x86-64-reloc-error-reporting.s b/test/ELF/x86-64-reloc-error-reporting.s new file mode 100644 index 000000000000..bb9c8be8accb --- /dev/null +++ b/test/ELF/x86-64-reloc-error-reporting.s @@ -0,0 +1,19 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-error.s -o %tabs +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t + +// We have some code in error reporting to check that +// section belongs to the output section. Without that +// check, the linker would crash, so it is useful to test it. +// And the easy way to do that is to trigger GC. That way .text.dumb +// be collected and mentioned check will execute. + +// RUN: not ld.lld -gc-sections -shared %tabs %t -o /dev/null + +.section .text.dumb,"ax" + nop + +.section .text,"ax" +.globl _start +_start: + movl $big, %edx diff --git a/test/ELF/x86-64-reloc-error.s b/test/ELF/x86-64-reloc-error.s index cb600d9bf1e3..0c3bebef04b5 100644 --- a/test/ELF/x86-64-reloc-error.s +++ b/test/ELF/x86-64-reloc-error.s @@ -1,7 +1,7 @@ +// REQUIRES: x86 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-error.s -o %tabs // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t -// RUN: not ld.lld -shared %tabs %t -o %t2 2>&1 | FileCheck %s -// REQUIRES: x86 +// RUN: not ld.lld -shared %tabs %t -o /dev/null 2>&1 | FileCheck %s movl $big, %edx movq $foo - 0x1000000000000, %rdx diff --git a/test/ELF/x86-64-reloc-error2.s b/test/ELF/x86-64-reloc-error2.s new file mode 100644 index 000000000000..d49b67522654 --- /dev/null +++ b/test/ELF/x86-64-reloc-error2.s @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s + +## Check we are able to find a function symbol that encloses +## a given location when reporting error messages. +# CHECK: {{.*}}.o:(function func): relocation R_X86_64_32S out of range: -281474974609408 is not in [-2147483648, 2147483647] + +.section .text.func, "ax", %progbits +.globl func +.type func,@function +.size func, 0x10 +func: + movq func - 0x1000000000000, %rdx diff --git a/test/ELF/x86-64-reloc-gotoff64.s b/test/ELF/x86-64-reloc-gotoff64.s new file mode 100644 index 000000000000..697ac17917a2 --- /dev/null +++ b/test/ELF/x86-64-reloc-gotoff64.s @@ -0,0 +1,32 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: ld.lld %t.o -shared -o %t.so +// RUN: llvm-readelf -s %t.so | FileCheck %s -check-prefix=SECTION +// RUN: llvm-objdump -d %t.so | FileCheck %s + +// SECTION: .dynamic DYNAMIC 0000000000003000 +// SECTION: .got PROGBITS 0000000000003070 003070 000000 + +// All the _GLOBAL_OFFSET_TABLE_ occurrences below refer to the address +// of GOT base, not the address of the symbol _GLOBAL_OFFSET_TABLE_. These +// instructions are special and produce GOT base relative relocations. We +// currently use .got end as the GOT base, which is not equal to +// the address of the special symbol _GLOBAL_OFFSET_TABLE_. + +// The assembly is generated by +// gcc -O2 -S -mcmodel=medium -fPIC a.c +// This computes the pc-relative address (runtime address) of _DYNAMIC. +// +// extern long _DYNAMIC[] __attribute__((visibility("hidden"))); +// long* dynamic() { return _DYNAMIC; } + +// 0x3070 (.got end) - 0x1007 = 8297 +// 0x3000 (_DYNAMIC) - 0x3070 (.got end) = -112 +// CHECK: 1000: {{.*}} leaq 8297(%rip), %rdx +// CHECK-NEXT: 1007: {{.*}} movabsq $-112, %rax +.global dynamic +dynamic: + leaq _GLOBAL_OFFSET_TABLE_(%rip), %rdx + movabsq $_DYNAMIC@GOTOFF, %rax + addq %rdx, %rax + ret diff --git a/test/ELF/x86-64-reloc-gotpc64.s b/test/ELF/x86-64-reloc-gotpc64.s new file mode 100644 index 000000000000..f07376f41218 --- /dev/null +++ b/test/ELF/x86-64-reloc-gotpc64.s @@ -0,0 +1,14 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: ld.lld %t.o -shared -o %t.so +// RUN: llvm-readelf -s %t.so | FileCheck %s -check-prefix=SECTION +// RUN: llvm-objdump -d %t.so | FileCheck %s + +// SECTION: .got PROGBITS 0000000000003070 003070 000000 + +// 0x3070 (.got end) - 0x1000 = 8304 +// CHECK: gotpc64: +// CHECK-NEXT: 1000: {{.*}} movabsq $8304, %r11 +.global gotpc64 +gotpc64: + movabsq $_GLOBAL_OFFSET_TABLE_-., %r11 diff --git a/test/ELF/x86-64-reloc-pc32-fpic.s b/test/ELF/x86-64-reloc-pc32-fpic.s index 399bf604f806..2dfd1bfb444c 100644 --- a/test/ELF/x86-64-reloc-pc32-fpic.s +++ b/test/ELF/x86-64-reloc-pc32-fpic.s @@ -1,10 +1,11 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s +# RUN: not ld.lld -shared %t.o -o /dev/null 2>&1 | FileCheck %s -# CHECK: relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC +# CHECK: relocation R_X86_64_PC32 cannot be used against symbol _shared; recompile with -fPIC # CHECK: >>> defined in {{.*}} # CHECK: >>> referenced by {{.*}}:(.data+0x1) .data -call _shared + .byte 0xe8 + .long _shared - . diff --git a/test/ELF/x86-64-reloc-range-debug-loc.s b/test/ELF/x86-64-reloc-range-debug-loc.s new file mode 100644 index 000000000000..8be4df3c5202 --- /dev/null +++ b/test/ELF/x86-64-reloc-range-debug-loc.s @@ -0,0 +1,36 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-error.s -o %tabs +# RUN: llvm-mc %s -o %t.o -triple x86_64-pc-linux -filetype=obj +# RUN: not ld.lld %tabs %t.o -o /dev/null -shared 2>&1 | FileCheck %s + +## Check we are able to report file and location from debug information +## when reporting such kind of errors. +# CHECK: error: test.s:3: relocation R_X86_64_32 out of range: 68719476736 is not in [0, 4294967295] + +.section .text,"ax",@progbits +foo: +.file 1 "test.s" +.loc 1 3 + movl $big, %edx + +.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/x86-64-reloc-range.s b/test/ELF/x86-64-reloc-range.s index 2913458ab5cb..c58a692821ec 100644 --- a/test/ELF/x86-64-reloc-range.s +++ b/test/ELF/x86-64-reloc-range.s @@ -1,5 +1,6 @@ +// REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -triple x86_64-pc-linux -filetype=obj -// RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s // CHECK: {{.*}}:(.text+0x3): relocation R_X86_64_PC32 out of range: 2147483648 is not in [-2147483648, 2147483647] // CHECK-NOT: relocation diff --git a/test/ELF/x86-64-reloc-tpoff32-fpic.s b/test/ELF/x86-64-reloc-tpoff32-fpic.s index 5be3dc317012..edb04c1d4487 100644 --- a/test/ELF/x86-64-reloc-tpoff32-fpic.s +++ b/test/ELF/x86-64-reloc-tpoff32-fpic.s @@ -1,8 +1,8 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: not ld.lld %t.o -shared -o %t.so 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o -shared -o /dev/null 2>&1 | FileCheck %s -# CHECK: relocation R_X86_64_TPOFF32 cannot be used against shared object; recompile with -fPIC +# CHECK: relocation R_X86_64_TPOFF32 cannot be used against symbol var; recompile with -fPIC # CHECK: >>> defined in {{.*}}.o # CHECK: >>> referenced by {{.*}}.o:(.tdata+0xC) diff --git a/test/ELF/x86-64-retpoline-linkerscript.s b/test/ELF/x86-64-retpoline-linkerscript.s new file mode 100644 index 000000000000..82d2ca6374c1 --- /dev/null +++ b/test/ELF/x86-64-retpoline-linkerscript.s @@ -0,0 +1,67 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o +// RUN: ld.lld -shared %t2.o -o %t2.so + +// RUN: echo "SECTIONS { \ +// RUN: .text : { *(.text) } \ +// RUN: .plt : { *(.plt) } \ +// RUN: .got.plt : { *(.got.plt) } \ +// RUN: .dynstr : { *(.dynstr) } \ +// RUN: }" > %t.script +// RUN: ld.lld -shared %t1.o %t2.so -o %t.exe -z retpolineplt --script %t.script +// RUN: llvm-objdump -d -s %t.exe | FileCheck %s + +// CHECK: Disassembly of section .plt: +// CHECK-NEXT: .plt: +// CHECK-NEXT: 10: ff 35 72 00 00 00 pushq 114(%rip) +// CHECK-NEXT: 16: 4c 8b 1d 73 00 00 00 movq 115(%rip), %r11 +// CHECK-NEXT: 1d: e8 0e 00 00 00 callq 14 <.plt+0x20> +// CHECK-NEXT: 22: f3 90 pause +// CHECK-NEXT: 24: 0f ae e8 lfence +// CHECK-NEXT: 27: eb f9 jmp -7 <.plt+0x12> +// 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: 4c 89 1c 24 movq %r11, (%rsp) +// CHECK-NEXT: 34: c3 retq +// CHECK-NEXT: 35: cc int3 +// CHECK-NEXT: 36: cc int3 +// CHECK-NEXT: 37: cc int3 +// CHECK-NEXT: 38: cc int3 +// CHECK-NEXT: 39: cc int3 +// CHECK-NEXT: 3a: cc int3 +// CHECK-NEXT: 3b: cc int3 +// CHECK-NEXT: 3c: cc int3 +// CHECK-NEXT: 3d: cc int3 +// CHECK-NEXT: 3e: cc int3 +// CHECK-NEXT: 3f: cc int3 +// CHECK-NEXT: 40: 4c 8b 1d 51 00 00 00 movq 81(%rip), %r11 +// CHECK-NEXT: 47: e8 e4 ff ff ff callq -28 <.plt+0x20> +// CHECK-NEXT: 4c: e9 d1 ff ff ff jmp -47 <.plt+0x12> +// CHECK-NEXT: 51: 68 00 00 00 00 pushq $0 +// CHECK-NEXT: 56: e9 b5 ff ff ff jmp -75 <.plt> +// 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: 4c 8b 1d 39 00 00 00 movq 57(%rip), %r11 +// CHECK-NEXT: 67: e8 c4 ff ff ff callq -60 <.plt+0x20> +// CHECK-NEXT: 6c: e9 b1 ff ff ff jmp -79 <.plt+0x12> +// CHECK-NEXT: 71: 68 01 00 00 00 pushq $1 +// CHECK-NEXT: 76: e9 95 ff ff ff jmp -107 <.plt> +// 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 + +.global _start +_start: + jmp bar@PLT + jmp zed@PLT diff --git a/test/ELF/x86-64-retpoline-znow-linkerscript.s b/test/ELF/x86-64-retpoline-znow-linkerscript.s new file mode 100644 index 000000000000..20196058d251 --- /dev/null +++ b/test/ELF/x86-64-retpoline-znow-linkerscript.s @@ -0,0 +1,54 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o +// RUN: ld.lld -shared %t2.o -o %t2.so + +// RUN: echo "SECTIONS { \ +// RUN: .text : { *(.text) } \ +// RUN: .plt : { *(.plt) } \ +// RUN: .got.plt : { *(.got.plt) } \ +// RUN: .dynstr : { *(.dynstr) } \ +// RUN: }" > %t.script +// RUN: ld.lld -shared %t1.o %t2.so -o %t.exe -z retpolineplt -z now --script %t.script +// RUN: llvm-objdump -d -s %t.exe | FileCheck %s + +// CHECK: Disassembly of section .plt: +// CHECK-NEXT: .plt: +// CHECK-NEXT: 10: e8 0b 00 00 00 callq 11 <.plt+0x10> +// CHECK-NEXT: 15: f3 90 pause +// CHECK-NEXT: 17: 0f ae e8 lfence +// CHECK-NEXT: 1a: eb f9 jmp -7 <.plt+0x5> +// CHECK-NEXT: 1c: cc int3 +// CHECK-NEXT: 1d: cc int3 +// CHECK-NEXT: 1e: cc int3 +// CHECK-NEXT: 1f: cc int3 +// CHECK-NEXT: 20: 4c 89 1c 24 movq %r11, (%rsp) +// CHECK-NEXT: 24: c3 retq +// CHECK-NEXT: 25: cc int3 +// CHECK-NEXT: 26: cc int3 +// CHECK-NEXT: 27: cc int3 +// 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: 4c 8b 1d 31 00 00 00 movq 49(%rip), %r11 +// CHECK-NEXT: 37: e9 d4 ff ff ff jmp -44 <.plt> +// CHECK-NEXT: 3c: cc int3 +// CHECK-NEXT: 3d: cc int3 +// CHECK-NEXT: 3e: cc int3 +// CHECK-NEXT: 3f: cc int3 +// CHECK-NEXT: 40: 4c 8b 1d 29 00 00 00 movq 41(%rip), %r11 +// CHECK-NEXT: 47: e9 c4 ff ff ff jmp -60 <.plt> +// CHECK-NEXT: 4c: cc int3 +// CHECK-NEXT: 4d: cc int3 +// CHECK-NEXT: 4e: cc int3 +// CHECK-NEXT: 4f: cc int3 + +.global _start +_start: + jmp bar@PLT + jmp zed@PLT diff --git a/test/ELF/x86-64-retpoline-znow.s b/test/ELF/x86-64-retpoline-znow.s new file mode 100644 index 000000000000..6464e2c0971f --- /dev/null +++ b/test/ELF/x86-64-retpoline-znow.s @@ -0,0 +1,53 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o +// RUN: ld.lld -shared %t2.o -o %t2.so + +// RUN: ld.lld -shared %t1.o %t2.so -o %t.exe -z retpolineplt -z now +// RUN: llvm-objdump -d -s %t.exe | FileCheck %s + +// CHECK: Disassembly of section .plt: +// CHECK-NEXT: .plt: +// CHECK-NEXT: 1010: e8 0b 00 00 00 callq 11 <.plt+0x10> +// CHECK-NEXT: 1015: f3 90 pause +// CHECK-NEXT: 1017: 0f ae e8 lfence +// CHECK-NEXT: 101a: eb f9 jmp -7 <.plt+0x5> +// CHECK-NEXT: 101c: cc int3 +// CHECK-NEXT: 101d: cc int3 +// CHECK-NEXT: 101e: cc int3 +// CHECK-NEXT: 101f: cc int3 +// CHECK-NEXT: 1020: 4c 89 1c 24 movq %r11, (%rsp) +// CHECK-NEXT: 1024: c3 retq +// CHECK-NEXT: 1025: cc int3 +// CHECK-NEXT: 1026: cc int3 +// CHECK-NEXT: 1027: cc int3 +// CHECK-NEXT: 1028: cc int3 +// 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: 4c 8b 1d c1 10 00 00 movq 4289(%rip), %r11 +// CHECK-NEXT: 1037: e9 d4 ff ff ff jmp -44 <.plt> +// CHECK-NEXT: 103c: cc int3 +// CHECK-NEXT: 103d: cc int3 +// CHECK-NEXT: 103e: cc int3 +// CHECK-NEXT: 103f: cc int3 +// CHECK-NEXT: 1040: 4c 8b 1d b9 10 00 00 movq 4281(%rip), %r11 +// CHECK-NEXT: 1047: e9 c4 ff ff ff jmp -60 <.plt> +// CHECK-NEXT: 104c: cc int3 +// CHECK-NEXT: 104d: cc int3 +// CHECK-NEXT: 104e: cc int3 +// CHECK-NEXT: 104f: cc int3 + +// CHECK: Contents of section .got.plt: +// CHECK-NEXT: 20e0 00200000 00000000 00000000 00000000 +// CHECK-NEXT: 20f0 00000000 00000000 00000000 00000000 +// CHECK-NEXT: 2100 00000000 00000000 + +.global _start +_start: + jmp bar@PLT + jmp zed@PLT diff --git a/test/ELF/x86-64-retpoline.s b/test/ELF/x86-64-retpoline.s new file mode 100644 index 000000000000..535f56533193 --- /dev/null +++ b/test/ELF/x86-64-retpoline.s @@ -0,0 +1,66 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o +// RUN: ld.lld -shared %t2.o -o %t2.so + +// RUN: ld.lld -shared %t1.o %t2.so -o %t.exe -z retpolineplt +// RUN: llvm-objdump -d -s %t.exe | FileCheck %s + +// CHECK: Disassembly of section .plt: +// CHECK-NEXT: .plt: +// CHECK-NEXT: 1010: ff 35 f2 0f 00 00 pushq 4082(%rip) +// CHECK-NEXT: 1016: 4c 8b 1d f3 0f 00 00 movq 4083(%rip), %r11 +// CHECK-NEXT: 101d: e8 0e 00 00 00 callq 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: 4c 89 1c 24 movq %r11, (%rsp) +// CHECK-NEXT: 1034: c3 retq +// CHECK-NEXT: 1035: cc int3 +// CHECK-NEXT: 1036: cc int3 +// CHECK-NEXT: 1037: cc int3 +// CHECK-NEXT: 1038: cc int3 +// CHECK-NEXT: 1039: cc int3 +// CHECK-NEXT: 103a: cc int3 +// CHECK-NEXT: 103b: cc int3 +// CHECK-NEXT: 103c: cc int3 +// CHECK-NEXT: 103d: cc int3 +// CHECK-NEXT: 103e: cc int3 +// CHECK-NEXT: 103f: cc int3 +// CHECK-NEXT: 1040: 4c 8b 1d d1 0f 00 00 movq 4049(%rip), %r11 +// CHECK-NEXT: 1047: e8 e4 ff ff ff callq -28 <.plt+0x20> +// CHECK-NEXT: 104c: e9 d1 ff ff ff jmp -47 <.plt+0x12> +// CHECK-NEXT: 1051: 68 00 00 00 00 pushq $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: 4c 8b 1d b9 0f 00 00 movq 4025(%rip), %r11 +// CHECK-NEXT: 1067: e8 c4 ff ff ff callq -60 <.plt+0x20> +// CHECK-NEXT: 106c: e9 b1 ff ff ff jmp -79 <.plt+0x12> +// CHECK-NEXT: 1071: 68 01 00 00 00 pushq $1 +// 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: Contents of section .got.plt: +// CHECK-NEXT: 2000 00300000 00000000 00000000 00000000 +// CHECK-NEXT: 2010 00000000 00000000 51100000 00000000 +// CHECK-NEXT: 2020 71100000 00000000 + +.global _start +_start: + jmp bar@PLT + jmp zed@PLT diff --git a/test/ELF/x86-64-split-stack-prologue-adjust-fail.s b/test/ELF/x86-64-split-stack-prologue-adjust-fail.s new file mode 100644 index 000000000000..0ae3de5ea611 --- /dev/null +++ b/test/ELF/x86-64-split-stack-prologue-adjust-fail.s @@ -0,0 +1,31 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/x86-64-split-stack-main.s -o %t2.o + +# RUN: not ld.lld --defsym __morestack=0x100 %t1.o %t2.o -o %t 2>&1 | FileCheck %s + +# An unknown prologue gives a match failure +# CHECK: unable to adjust the enclosing function's + +# RUN: not ld.lld -r --defsym __morestack=0x100 %t1.o %t2.o -o %t 2>&1 | FileCheck %s -check-prefix=RELOCATABLE +# RELOCATABLE: Cannot mix split-stack and non-split-stack in a relocatable link + + .text + + .global unknown_prologue + .type unknown_prologue,@function +unknown_prologue: + push %rbp + mov %rsp,%rbp + cmp %fs:0x70,%rsp + jae 1f + callq __morestack + retq +1: + callq non_split + leaveq + retq + + .size unknown_prologue,. - unknown_prologue + + .section .note.GNU-split-stack,"",@progbits diff --git a/test/ELF/x86-64-split-stack-prologue-adjust-silent.s b/test/ELF/x86-64-split-stack-prologue-adjust-silent.s new file mode 100644 index 000000000000..353eabef0de7 --- /dev/null +++ b/test/ELF/x86-64-split-stack-prologue-adjust-silent.s @@ -0,0 +1,32 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/x86-64-split-stack-main.s -o %t2.o + +# RUN: ld.lld --defsym __morestack=0x100 %t1.o %t2.o -o %t +# RUN: llvm-objdump -d %t 2>&1 | FileCheck %s + +# An unknown prologue ordinarily gives a match failure, except that this +# object file includes a .note.GNU-no-split-stack section, which tells the +# linker to expect such prologues, and therefore not error. + +# CHECK: __morestack + + .text + + .global unknown_prologue + .type unknown_prologue,@function +unknown_prologue: + push %rbp + mov %rsp,%rbp + cmp %fs:0x70,%rsp + jae 1f + callq __morestack + retq +1: + callq non_split + leaveq + retq + + .size unknown_prologue,. - unknown_prologue + .section .note.GNU-split-stack,"",@progbits + .section .note.GNU-no-split-stack,"",@progbits diff --git a/test/ELF/x86-64-split-stack-prologue-adjust-success.s b/test/ELF/x86-64-split-stack-prologue-adjust-success.s new file mode 100644 index 000000000000..bad26677f3fd --- /dev/null +++ b/test/ELF/x86-64-split-stack-prologue-adjust-success.s @@ -0,0 +1,124 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/x86-64-split-stack-main.s -o %t2.o + +# RUN: ld.lld --defsym __morestack=0x100 --defsym __morestack_non_split=0x200 %t1.o %t2.o -o %t -z notext +# RUN: llvm-objdump -d %t | FileCheck %s + +# Avoid duplicating the prologue for every test via macros. + +.macro prologue1 function_to_call + .global prologue1_calls_\function_to_call + .type prologue1_calls_\function_to_call,@function +prologue1_calls_\function_to_call: + cmp %fs:0x70,%rsp + jae 1f + callq __morestack + retq +1: + # Various and duplicate calls to ensure every code path is taken. + callq \function_to_call + callq \function_to_call + callq 1b + callq non_function_text_symbol + retq + .size prologue1_calls_\function_to_call,. - prologue1_calls_\function_to_call +.endm + +.macro prologue2 function_to_call register + .global prologue2_calls_\function_to_call\register + .type prologue2_calls_\function_to_call\register,@function +prologue2_calls_\function_to_call\register: + lea -0x200(%rsp),%\register + cmp %fs:0x70,%\register + jae 1f + callq __morestack + retq +1: + # Various and duplicate calls to ensure every code path is taken. + callq \function_to_call + callq \function_to_call + callq 1b + callq non_function_text_symbol + retq + .size prologue2_calls_\function_to_call\register,. - prologue2_calls_\function_to_call\register +.endm + + .local foo +foo: + .section .text,"ax",@progbits + .quad foo + + .text + +# For split-stack code calling split-stack code, ensure prologue v1 still +# calls plain __morestack, and that any raw bytes written to the prologue +# make sense. +# CHECK: prologue1_calls_split: +# CHECK-NEXT: cmp{{.*}}%fs:{{[^,]*}},{{.*}}%rsp +# CHECK: jae{{.*$}} +# CHECK-NEXT: callq{{.*}}<__morestack> + +prologue1 split + +# For split-stack code calling split-stack code, ensure prologue v2 still +# calls plain __morestack, that any raw bytes written to the prologue +# make sense, and that the register number is preserved. +# CHECK: prologue2_calls_splitr10: +# CHECK-NEXT: lea{{.*}} -{{[0-9]+}}(%rsp),{{.*}}%r10 +# CHECK: cmp{{.*}}%fs:{{[^,]*}},{{.*}}%r{{[0-9]+}} +# CHECK: jae{{.*}} +# CHECK-NEXT: callq{{.*}}<__morestack> + +prologue2 split r10 + +# CHECK: prologue2_calls_splitr11: +# CHECK-NEXT: lea{{.*}} -{{[0-9]+}}(%rsp),{{.*}}%r11 +# CHECK: cmp{{.*}}%fs:{{[^,]*}},{{.*}}%r{{[0-9]+}} +# CHECK: jae{{.*}} +# CHECK-NEXT: callq{{.*}}<__morestack> + +prologue2 split r11 + +# For split-stack code calling non-split-stack code, ensure prologue v1 +# calls __morestack_non_split, and that any raw bytes written to the prologue +# make sense. +# CHECK: prologue1_calls_non_split: +# CHECK-NEXT: stc{{.*$}} +# CHECK-NEXT: nopl{{.*$}} +# CHECK: jae{{.*$}} +# CHECK-NEXT: callq{{.*}}<__morestack_non_split> + +prologue1 non_split + +# For split-stack code calling non-split-stack code, ensure prologue v2 +# calls __morestack_non_split, that any raw bytes written to the prologue +# make sense, and that the register number is preserved +# CHECK: prologue2_calls_non_splitr10: +# CHECK-NEXT: lea{{.*$}} +# CHECK: cmp{{.*}}%fs:{{[^,]*}},{{.*}}%r10 +# CHECK: jae{{.*$}} +# CHECK-NEXT: callq{{.*}}<__morestack_non_split> + +prologue2 non_split r10 + +# CHECK: prologue2_calls_non_splitr11: +# CHECK-NEXT: lea{{.*$}} +# CHECK: cmp{{.*}}%fs:{{[^,]*}},{{.*}}%r11 +# CHECK: jae{{.*$}} +# CHECK-NEXT: callq{{.*}}<__morestack_non_split> + +prologue2 non_split r11 +# call foo@plt # for code-coverage. + + + + .global split + .type split,@function +split: + retq + + .size split,. - split + + .section .note.GNU-stack,"",@progbits + .section .note.GNU-split-stack,"",@progbits diff --git a/test/ELF/x86-64-tls-ld-local.s b/test/ELF/x86-64-tls-ld-local.s new file mode 100644 index 000000000000..6daba638367f --- /dev/null +++ b/test/ELF/x86-64-tls-ld-local.s @@ -0,0 +1,29 @@ +// REQUIRES: x86 +// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-readobj -r -s %t.so | FileCheck %s + +// CHECK: Relocations [ +// CHECK-NEXT: Section ({{.*}}) .rela.dyn { +// CHECK-NEXT: R_X86_64_DTPMOD64 - 0x0 +// CHECK-NEXT: R_X86_64_DTPMOD64 - 0x0 +// CHECK-NEXT: } +// CHECK-NEXT: Section ({{.*}}) .rela.plt { +// CHECK-NEXT: R_X86_64_JUMP_SLOT __tls_get_addr 0x0 +// CHECK-NEXT: } +// CHECK-NEXT: ] + + data16 + leaq bar@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 + + .section .tdata,"awT",@progbits +bar: + .long 42 diff --git a/test/ELF/zdefs.s b/test/ELF/zdefs.s index 93c61e14ccb6..21bec77b3bfb 100644 --- a/test/ELF/zdefs.s +++ b/test/ELF/zdefs.s @@ -1,3 +1,4 @@ +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o # RUN: ld.lld -shared %t.o -o %t1.so diff --git a/test/ELF/znotext-plt-relocations-protected.s b/test/ELF/znotext-plt-relocations-protected.s index 03d20b12e352..4fd8065a2873 100644 --- a/test/ELF/znotext-plt-relocations-protected.s +++ b/test/ELF/znotext-plt-relocations-protected.s @@ -2,10 +2,10 @@ # 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/znotext-plt-relocations-protected.s -o %t2.o # RUN: ld.lld %t2.o -o %t2.so -shared -# RUN: not ld.lld -z notext %t.o %t2.so -o %t 2>&1 | FileCheck %s +# RUN: not ld.lld -z notext %t.o %t2.so -o /dev/null 2>&1 | FileCheck %s # CHECK: error: cannot preempt symbol: foo .global _start _start: -callq foo + .long foo - . diff --git a/test/ELF/znotext-weak-undef.s b/test/ELF/znotext-weak-undef.s index d606d872bc4f..72bb6e2d5e18 100644 --- a/test/ELF/znotext-weak-undef.s +++ b/test/ELF/znotext-weak-undef.s @@ -1,7 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: not ld.lld -z notext -shared %t.o -o %t 2>&1 | FileCheck %s -# CHECK: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC +# CHECK: relocation R_X86_64_32 cannot be used against symbol foo; recompile with -fPIC # RUN: ld.lld -z notext %t.o -o %t # RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=EXE diff --git a/test/ELF/ztext-text-notext.s b/test/ELF/ztext.s index 964ffe1fa6d8..1757769b29a2 100644 --- a/test/ELF/ztext-text-notext.s +++ b/test/ELF/ztext.s @@ -1,7 +1,8 @@ # 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/ztext-text-notext.s -o %t2.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/ztext.s -o %t2.o # RUN: ld.lld %t2.o -o %t2.so -shared + # RUN: ld.lld -z notext %t.o %t2.so -o %t -shared # RUN: llvm-readobj -dynamic-table -r %t | FileCheck %s # RUN: ld.lld -z notext %t.o %t2.so -o %t2 -pie @@ -9,26 +10,34 @@ # RUN: ld.lld -z notext %t.o %t2.so -o %t3 # RUN: llvm-readobj -dynamic-table -r %t3 | FileCheck --check-prefix=STATIC %s +# RUN: not ld.lld %t.o %t2.so -o %t -shared 2>&1 | FileCheck --check-prefix=ERR %s +# RUN: not ld.lld -z text %t.o %t2.so -o %t -shared 2>&1 | FileCheck --check-prefix=ERR %s +# ERR: error: can't create dynamic relocation + # If the preference is to have text relocations, don't create plt of copy relocations. # CHECK: Relocations [ -# CHECK-NEXT: Section {{.*}} .rela.dyn { -# CHECK-NEXT: 0x1000 R_X86_64_RELATIVE - 0x1000 -# CHECK-NEXT: 0x1008 R_X86_64_64 bar 0x0 -# CHECK-NEXT: 0x1010 R_X86_64_PC64 zed 0x0 -# CHECK-NEXT: } -# CHECK-NEXT: ] +# CHECK-NEXT: Section {{.*}} .rela.dyn { +# CHECK-NEXT: 0x1000 R_X86_64_RELATIVE - 0x1000 +# CHECK-NEXT: 0x1008 R_X86_64_64 bar 0x0 +# CHECK-NEXT: 0x1010 R_X86_64_PC64 zed 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + # CHECK: DynamicSection [ -# CHECK: 0x0000000000000016 TEXTREL 0x0 +# CHECK: FLAGS TEXTREL +# CHECK: TEXTREL 0x0 # STATIC: Relocations [ -# STATIC-NEXT: Section {{.*}} .rela.dyn { -# STATIC-NEXT: 0x201008 R_X86_64_64 bar 0x0 -# STATIC-NEXT: 0x201010 R_X86_64_PC64 zed 0x0 -# STATIC-NEXT: } -# STATIC-NEXT: ] +# STATIC-NEXT: Section {{.*}} .rela.dyn { +# STATIC-NEXT: 0x201008 R_X86_64_64 bar 0x0 +# STATIC-NEXT: 0x201010 R_X86_64_PC64 zed 0x0 +# STATIC-NEXT: } +# STATIC-NEXT: ] + # STATIC: DynamicSection [ -# STATIC: 0x0000000000000016 TEXTREL 0x0 +# STATIC: FLAGS TEXTREL +# STATIC: TEXTREL 0x0 foo: .quad foo |