diff options
Diffstat (limited to 'test/ELF')
577 files changed, 11978 insertions, 2978 deletions
diff --git a/test/ELF/arm-attributes-remove.s b/test/ELF/Inputs/arm-attributes1.s index 010f366cd7fb2..da67c49b6b391 100644 --- a/test/ELF/arm-attributes-remove.s +++ b/test/ELF/Inputs/arm-attributes1.s @@ -1,20 +1,4 @@ -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o -// RUN: ld.lld %t.o -o %t -// RUN: llvm-readobj -s %t | FileCheck %s -// RUN: ld.lld %t.o -shared -o %t2 -// RUN: llvm-readobj -s %t2 | FileCheck %s -// RUN: ld.lld %t.o -r -o %t3 -// RUN: llvm-readobj -s %t3 | FileCheck %s - -// The .ARM.attributes section should be removed from executables and -// shared objects. - -// At present we remove it from the -r object output as well which isn't ideal. -// Unfortunately combining per-object attributes cannot be safely done by just -// concatentation of input sections. - -// CHECK-NOT: Name: .ARM.attributes -// REQUIRES: arm +// Input that generates an object with a populated SHT_ARM_ATTRIBUTES section .text .syntax unified .eabi_attribute 67, "2.09" @ Tag_conformance @@ -38,8 +22,8 @@ .eabi_attribute 26, 2 @ Tag_ABI_enum_size .eabi_attribute 14, 0 @ Tag_ABI_PCS_R9_use .eabi_attribute 68, 1 @ Tag_Virtualization_use - .globl _start + .globl func .p2align 2 - .type _start,%function -_start: + .type func,%function +func: bx lr diff --git a/test/ELF/Inputs/arm-exidx-cantunwind.s b/test/ELF/Inputs/arm-exidx-cantunwind.s new file mode 100644 index 0000000000000..679cc75130966 --- /dev/null +++ b/test/ELF/Inputs/arm-exidx-cantunwind.s @@ -0,0 +1,40 @@ +// Functions that will generate a .ARM.exidx section with SHF_LINK_ORDER +// dependency on the progbits section containing the .cantunwind directive + .syntax unified + .section .func1, "ax",%progbits + .globl func1 +func1: + .fnstart + bx lr + .cantunwind + .fnend + + .section .func2, "ax", %progbits + .globl func2 +func2: + .fnstart + bx lr + .cantunwind + .fnend + + .section .func3, "ax",%progbits + .globl func3 +func3: + .fnstart + bx lr + .cantunwind + .fnend + + .section .text, "ax",%progbits + .globl func4 +func4: + .fnstart + bx lr + .cantunwind + .fnend + .globl func5 +func5: + .fnstart + bx lr + .cantunwind + .fnend diff --git a/test/ELF/Inputs/arm-shared.s b/test/ELF/Inputs/arm-shared.s new file mode 100644 index 0000000000000..4330a1db1591a --- /dev/null +++ b/test/ELF/Inputs/arm-shared.s @@ -0,0 +1,8 @@ +.syntax unified +.global bar2 +.type bar2, %function +bar2: + +.global zed2 +.type zed2, %function +zed2: diff --git a/test/ELF/Inputs/arm-tls-get-addr.s b/test/ELF/Inputs/arm-tls-get-addr.s new file mode 100644 index 0000000000000..f3212ad974bef --- /dev/null +++ b/test/ELF/Inputs/arm-tls-get-addr.s @@ -0,0 +1,13 @@ + .syntax unified + .text + .globl __tls_get_addr + .type __tls_get_addr,%function +__tls_get_addr: + bx lr + +.section .tbss,"awT",%nobits + .p2align 2 +y: + .space 4 + .globl y + .type y, %object diff --git a/test/ELF/Inputs/bad-archive.a b/test/ELF/Inputs/bad-archive.a new file mode 100644 index 0000000000000..c9c6fbfd91462 --- /dev/null +++ b/test/ELF/Inputs/bad-archive.a @@ -0,0 +1,2 @@ +!<arch> +this is malformed archive used in bad-archive.s diff --git a/test/ELF/Inputs/comment-gc.s b/test/ELF/Inputs/comment-gc.s new file mode 100644 index 0000000000000..2453ce9d7367d --- /dev/null +++ b/test/ELF/Inputs/comment-gc.s @@ -0,0 +1 @@ +.ident "bar" diff --git a/test/ELF/Inputs/conflict-debug.s b/test/ELF/Inputs/conflict-debug.s new file mode 100644 index 0000000000000..03fb013318152 --- /dev/null +++ b/test/ELF/Inputs/conflict-debug.s @@ -0,0 +1,5 @@ +.file 1 "conflict-debug.s" +.globl zed +.loc 1 4 +zed: + nop diff --git a/test/ELF/Inputs/gdb-index-a.elf b/test/ELF/Inputs/gdb-index-a.elf Binary files differnew file mode 100644 index 0000000000000..9b90b0dc233e9 --- /dev/null +++ b/test/ELF/Inputs/gdb-index-a.elf diff --git a/test/ELF/Inputs/gdb-index-b.elf b/test/ELF/Inputs/gdb-index-b.elf Binary files differnew file mode 100644 index 0000000000000..b3356d8c773b2 --- /dev/null +++ b/test/ELF/Inputs/gdb-index-b.elf diff --git a/test/ELF/Inputs/i386-tls-got.s b/test/ELF/Inputs/i386-tls-got.s new file mode 100644 index 0000000000000..42d16b1af169c --- /dev/null +++ b/test/ELF/Inputs/i386-tls-got.s @@ -0,0 +1,5 @@ + .type foobar,@object + .section .tdata,"awT",@progbits + .globl foobar +foobar: + .long 42 diff --git a/test/ELF/Inputs/icf-non-mergeable.s b/test/ELF/Inputs/icf-non-mergeable.s new file mode 100644 index 0000000000000..0c42a654963e1 --- /dev/null +++ b/test/ELF/Inputs/icf-non-mergeable.s @@ -0,0 +1,8 @@ +.globl d1, d2 +.section .data.d1, "aw" +d1: + .quad 0 + +.section .data.d2, "aw" +d2: + .quad 0 diff --git a/test/ELF/Inputs/invalid-shstrndx.so b/test/ELF/Inputs/invalid-shstrndx.so Binary files differdeleted file mode 100755 index dc332b9292eac..0000000000000 --- a/test/ELF/Inputs/invalid-shstrndx.so +++ /dev/null diff --git a/test/ELF/Inputs/mips-concatenated-abiflags.o b/test/ELF/Inputs/mips-concatenated-abiflags.o Binary files differnew file mode 100644 index 0000000000000..404530919fc3a --- /dev/null +++ b/test/ELF/Inputs/mips-concatenated-abiflags.o diff --git a/test/ELF/Inputs/mips-fnpic.s b/test/ELF/Inputs/mips-fnpic.s new file mode 100644 index 0000000000000..d8bf0ba34f528 --- /dev/null +++ b/test/ELF/Inputs/mips-fnpic.s @@ -0,0 +1,6 @@ + .option pic0 + .text + .global fnpic + .type fnpic, @function +fnpic: + nop diff --git a/test/ELF/Inputs/mips-fpic.s b/test/ELF/Inputs/mips-fpic.s new file mode 100644 index 0000000000000..b7af281c32537 --- /dev/null +++ b/test/ELF/Inputs/mips-fpic.s @@ -0,0 +1,6 @@ + .option pic2 + .text + .global fpic + .type fpic, @function +fpic: + nop diff --git a/test/ELF/Inputs/mips-gp0-non-zero.o b/test/ELF/Inputs/mips-gp0-non-zero.o Binary files differnew file mode 100755 index 0000000000000..4c8234336baae --- /dev/null +++ b/test/ELF/Inputs/mips-gp0-non-zero.o diff --git a/test/ELF/Inputs/mips-n32-rels.o b/test/ELF/Inputs/mips-n32-rels.o Binary files differnew file mode 100644 index 0000000000000..88cbce699e6df --- /dev/null +++ b/test/ELF/Inputs/mips-n32-rels.o diff --git a/test/ELF/Inputs/relocatable-tls.s b/test/ELF/Inputs/relocatable-tls.s new file mode 100644 index 0000000000000..296beb474c879 --- /dev/null +++ b/test/ELF/Inputs/relocatable-tls.s @@ -0,0 +1 @@ +callq __tls_get_addr@PLT diff --git a/test/ELF/Inputs/relocation-relative-absolute.s b/test/ELF/Inputs/relocation-relative-absolute.s new file mode 100644 index 0000000000000..2341f69b162a3 --- /dev/null +++ b/test/ELF/Inputs/relocation-relative-absolute.s @@ -0,0 +1,2 @@ +.globl answer +answer = 42 diff --git a/test/ELF/Inputs/shared2-x86-64.s b/test/ELF/Inputs/shared2-x86-64.s new file mode 100644 index 0000000000000..925e6a427fac8 --- /dev/null +++ b/test/ELF/Inputs/shared2-x86-64.s @@ -0,0 +1,9 @@ +.global bar2 +.type bar2, @function +bar2: + ret + +.global zed2 +.type zed2, @function +zed2: + ret diff --git a/test/ELF/Inputs/shf-info-link.test b/test/ELF/Inputs/shf-info-link.test new file mode 100644 index 0000000000000..b877969168e82 --- /dev/null +++ b/test/ELF/Inputs/shf-info-link.test @@ -0,0 +1,21 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + Info: .text + Relocations: + - Offset: 0x0000000000000000 + Symbol: foo + Type: R_X86_64_64 +Symbols: + Global: + - Name: foo diff --git a/test/ELF/Inputs/startstop-shared2.s b/test/ELF/Inputs/startstop-shared2.s new file mode 100644 index 0000000000000..414bf6dc876ea --- /dev/null +++ b/test/ELF/Inputs/startstop-shared2.s @@ -0,0 +1,2 @@ +.globl __start_foo +__start_foo: diff --git a/test/ELF/Inputs/symbol-override.s b/test/ELF/Inputs/symbol-override.s index 21f3ae244c777..ab3bf8dc74b0b 100644 --- a/test/ELF/Inputs/symbol-override.s +++ b/test/ELF/Inputs/symbol-override.s @@ -11,6 +11,6 @@ nop .globl do .type do,@function -do: +do: callq foo@PLT callq bar@PLT diff --git a/test/ELF/Inputs/uabs_label.s b/test/ELF/Inputs/uabs_label.s new file mode 100644 index 0000000000000..b2a67216a5928 --- /dev/null +++ b/test/ELF/Inputs/uabs_label.s @@ -0,0 +1,4 @@ +# Sample label to test R_AARCH64_MOVW_UABS relocations + +.globl uabs_label +uabs_label = 0xF000E000D000C diff --git a/test/ELF/Inputs/undef-debug.s b/test/ELF/Inputs/undef-debug.s new file mode 100644 index 0000000000000..db8aaf16e6bd1 --- /dev/null +++ b/test/ELF/Inputs/undef-debug.s @@ -0,0 +1,11 @@ +.file 1 "dir/undef-debug.s" +.loc 1 3 + .quad zed3 + +.section .text.1,"ax" +.loc 1 7 + .quad zed4 + +.section .text.2,"ax" +.loc 1 11 + .quad zed5 diff --git a/test/ELF/Inputs/use-bar.s b/test/ELF/Inputs/use-bar.s new file mode 100644 index 0000000000000..cc82b6fbb1439 --- /dev/null +++ b/test/ELF/Inputs/use-bar.s @@ -0,0 +1,2 @@ +.section .bar,"a" + .quad _bar diff --git a/test/ELF/Inputs/verdef-defaultver.s b/test/ELF/Inputs/verdef-defaultver.s index 2e1d1c36fb928..6664d62c90f59 100644 --- a/test/ELF/Inputs/verdef-defaultver.s +++ b/test/ELF/Inputs/verdef-defaultver.s @@ -1,5 +1,5 @@ -b@LIBSAMPLE_1.0 = b_1 -b@@LIBSAMPLE_2.0 = b_2 +b@V1 = b_1 +b@@V2 = b_2 .globl a .type a,@function diff --git a/test/ELF/aarch64-abs16.s b/test/ELF/aarch64-abs16.s index e41abc43ee0da..c4f5b3e44b584 100644 --- a/test/ELF/aarch64-abs16.s +++ b/test/ELF/aarch64-abs16.s @@ -18,7 +18,7 @@ _start: // S + A = 0xffff // 11002: S = 0x100, A = -0x8100 // S + A = 0x8000 -// CHECK-NEXT: 11000 ffff0080 +// CHECK-NEXT: 20000 ffff0080 // RUN: not ld.lld %t.o %t255.o -o %t2 // | FileCheck %s --check-prefix=OVERFLOW diff --git a/test/ELF/aarch64-abs32.s b/test/ELF/aarch64-abs32.s index c2460d15e8257..b051692374b12 100644 --- a/test/ELF/aarch64-abs32.s +++ b/test/ELF/aarch64-abs32.s @@ -14,11 +14,11 @@ _start: // RUN: llvm-objdump -s -section=.data %t2 | FileCheck %s // CHECK: Contents of section .data: -// 11000: S = 0x100, A = 0xfffffeff +// 20000: S = 0x100, A = 0xfffffeff // S + A = 0xffffffff -// 11004: S = 0x100, A = -0x80000100 +// 20004: S = 0x100, A = -0x80000100 // S + A = 0x80000000 -// CHECK-NEXT: 11000 ffffffff 00000080 +// CHECK-NEXT: 20000 ffffffff 00000080 // RUN: not ld.lld %t.o %t255.o -o %t2 // | FileCheck %s --check-prefix=OVERFLOW diff --git a/test/ELF/aarch64-condb-reloc.s b/test/ELF/aarch64-condb-reloc.s index 630e3430f4e53..b2af445f4b6dd 100644 --- a/test/ELF/aarch64-condb-reloc.s +++ b/test/ELF/aarch64-condb-reloc.s @@ -12,21 +12,21 @@ # 0x1102c - 16 = 0x1101c # CHECK: Disassembly of section .text: # CHECK-NEXT: _foo: -# CHECK-NEXT: 11000: {{.*}} nop -# CHECK-NEXT: 11004: {{.*}} nop -# CHECK-NEXT: 11008: {{.*}} nop -# CHECK-NEXT: 1100c: {{.*}} nop +# CHECK-NEXT: 20000: {{.*}} nop +# CHECK-NEXT: 20004: {{.*}} nop +# CHECK-NEXT: 20008: {{.*}} nop +# CHECK-NEXT: 2000c: {{.*}} nop # CHECK: _bar: -# CHECK-NEXT: 11010: {{.*}} nop -# CHECK-NEXT: 11014: {{.*}} nop -# CHECK-NEXT: 11018: {{.*}} nop +# CHECK-NEXT: 20010: {{.*}} nop +# CHECK-NEXT: 20014: {{.*}} nop +# CHECK-NEXT: 20018: {{.*}} nop # CHECK: _dah: -# CHECK-NEXT: 1101c: {{.*}} nop -# CHECK-NEXT: 11020: {{.*}} nop +# CHECK-NEXT: 2001c: {{.*}} nop +# CHECK-NEXT: 20020: {{.*}} nop # CHECK: _start: -# CHECK-NEXT: 11024: {{.*}} b.eq #-36 -# CHECK-NEXT: 11028: {{.*}} b.eq #-24 -# CHECK-NEXT: 1102c: {{.*}} b.eq #-16 +# CHECK-NEXT: 20024: {{.*}} b.eq #-36 +# CHECK-NEXT: 20028: {{.*}} b.eq #-24 +# CHECK-NEXT: 2002c: {{.*}} b.eq #-16 #DSOREL: Section { #DSOREL: Index: @@ -36,8 +36,8 @@ #DSOREL-NEXT: SHF_ALLOC #DSOREL-NEXT: SHF_WRITE #DSOREL-NEXT: ] -#DSOREL-NEXT: Address: 0x3000 -#DSOREL-NEXT: Offset: 0x3000 +#DSOREL-NEXT: Address: 0x30000 +#DSOREL-NEXT: Offset: 0x30000 #DSOREL-NEXT: Size: 48 #DSOREL-NEXT: Link: 0 #DSOREL-NEXT: Info: 0 @@ -46,51 +46,51 @@ #DSOREL-NEXT: } #DSOREL: Relocations [ #DSOREL-NEXT: Section ({{.*}}) .rela.plt { -#DSOREL-NEXT: 0x3018 R_AARCH64_JUMP_SLOT _foo -#DSOREL-NEXT: 0x3020 R_AARCH64_JUMP_SLOT _bar -#DSOREL-NEXT: 0x3028 R_AARCH64_JUMP_SLOT _dah +#DSOREL-NEXT: 0x30018 R_AARCH64_JUMP_SLOT _foo +#DSOREL-NEXT: 0x30020 R_AARCH64_JUMP_SLOT _bar +#DSOREL-NEXT: 0x30028 R_AARCH64_JUMP_SLOT _dah #DSOREL-NEXT: } #DSOREL-NEXT:] #DSO: Disassembly of section .text: #DSO-NEXT: _foo: -#DSO-NEXT: 1000: {{.*}} nop -#DSO-NEXT: 1004: {{.*}} nop -#DSO-NEXT: 1008: {{.*}} nop -#DSO-NEXT: 100c: {{.*}} nop +#DSO-NEXT: 10000: {{.*}} nop +#DSO-NEXT: 10004: {{.*}} nop +#DSO-NEXT: 10008: {{.*}} nop +#DSO-NEXT: 1000c: {{.*}} nop #DSO: _bar: -#DSO-NEXT: 1010: {{.*}} nop -#DSO-NEXT: 1014: {{.*}} nop -#DSO-NEXT: 1018: {{.*}} nop +#DSO-NEXT: 10010: {{.*}} nop +#DSO-NEXT: 10014: {{.*}} nop +#DSO-NEXT: 10018: {{.*}} nop #DSO: _dah: -#DSO-NEXT: 101c: {{.*}} nop -#DSO-NEXT: 1020: {{.*}} nop +#DSO-NEXT: 1001c: {{.*}} nop +#DSO-NEXT: 10020: {{.*}} nop #DSO: _start: -#DSO-NEXT: 1024: {{.*}} b.eq #44 -#DSO-NEXT: 1028: {{.*}} b.eq #56 -#DSO-NEXT: 102c: {{.*}} b.eq #68 +#DSO-NEXT: 10024: {{.*}} b.eq #44 +#DSO-NEXT: 10028: {{.*}} b.eq #56 +#DSO-NEXT: 1002c: {{.*}} b.eq #68 #DSO-NEXT: Disassembly of section .plt: #DSO-NEXT: .plt: -#DSO-NEXT: 1030: {{.*}} stp x16, x30, [sp, #-16]! -#DSO-NEXT: 1034: {{.*}} adrp x16, #8192 -#DSO-NEXT: 1038: {{.*}} ldr x17, [x16, #16] -#DSO-NEXT: 103c: {{.*}} add x16, x16, #16 -#DSO-NEXT: 1040: {{.*}} br x17 -#DSO-NEXT: 1044: {{.*}} nop -#DSO-NEXT: 1048: {{.*}} nop -#DSO-NEXT: 104c: {{.*}} nop -#DSO-NEXT: 1050: {{.*}} adrp x16, #8192 -#DSO-NEXT: 1054: {{.*}} ldr x17, [x16, #24] -#DSO-NEXT: 1058: {{.*}} add x16, x16, #24 -#DSO-NEXT: 105c: {{.*}} br x17 -#DSO-NEXT: 1060: {{.*}} adrp x16, #8192 -#DSO-NEXT: 1064: {{.*}} ldr x17, [x16, #32] -#DSO-NEXT: 1068: {{.*}} add x16, x16, #32 -#DSO-NEXT: 106c: {{.*}} br x17 -#DSO-NEXT: 1070: {{.*}} adrp x16, #8192 -#DSO-NEXT: 1074: {{.*}} ldr x17, [x16, #40] -#DSO-NEXT: 1078: {{.*}} add x16, x16, #40 -#DSO-NEXT: 107c: {{.*}} br x17 +#DSO-NEXT: 10030: {{.*}} stp x16, x30, [sp, #-16]! +#DSO-NEXT: 10034: {{.*}} adrp x16, #131072 +#DSO-NEXT: 10038: {{.*}} ldr x17, [x16, #16] +#DSO-NEXT: 1003c: {{.*}} add x16, x16, #16 +#DSO-NEXT: 10040: {{.*}} br x17 +#DSO-NEXT: 10044: {{.*}} nop +#DSO-NEXT: 10048: {{.*}} nop +#DSO-NEXT: 1004c: {{.*}} nop +#DSO-NEXT: 10050: {{.*}} adrp x16, #131072 +#DSO-NEXT: 10054: {{.*}} ldr x17, [x16, #24] +#DSO-NEXT: 10058: {{.*}} add x16, x16, #24 +#DSO-NEXT: 1005c: {{.*}} br x17 +#DSO-NEXT: 10060: {{.*}} adrp x16, #131072 +#DSO-NEXT: 10064: {{.*}} ldr x17, [x16, #32] +#DSO-NEXT: 10068: {{.*}} add x16, x16, #32 +#DSO-NEXT: 1006c: {{.*}} br x17 +#DSO-NEXT: 10070: {{.*}} adrp x16, #131072 +#DSO-NEXT: 10074: {{.*}} ldr x17, [x16, #40] +#DSO-NEXT: 10078: {{.*}} add x16, x16, #40 +#DSO-NEXT: 1007c: {{.*}} br x17 .globl _start _start: diff --git a/test/ELF/aarch64-copy.s b/test/ELF/aarch64-copy.s index 6e0af27a0c6b0..ffecf2f8a2837 100644 --- a/test/ELF/aarch64-copy.s +++ b/test/ELF/aarch64-copy.s @@ -22,7 +22,7 @@ _start: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x13000 +// CHECK-NEXT: Address: 0x40000 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: @@ -32,19 +32,19 @@ _start: // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.dyn { // CHECK-NEXT: Relocation { -// CHECK-NEXT: Offset: 0x13000 +// CHECK-NEXT: Offset: 0x40000 // CHECK-NEXT: Type: R_AARCH64_COPY // CHECK-NEXT: Symbol: x // CHECK-NEXT: Addend: 0x0 // CHECK-NEXT: } // CHECK-NEXT: Relocation { -// CHECK-NEXT: Offset: 0x13010 +// CHECK-NEXT: Offset: 0x40010 // CHECK-NEXT: Type: R_AARCH64_COPY // CHECK-NEXT: Symbol: y // CHECK-NEXT: Addend: 0x0 // CHECK-NEXT: } // CHECK-NEXT: Relocation { -// CHECK-NEXT: Offset: 0x13014 +// CHECK-NEXT: Offset: 0x40014 // CHECK-NEXT: Type: R_AARCH64_COPY // CHECK-NEXT: Symbol: z // CHECK-NEXT: Addend: 0x0 @@ -54,21 +54,21 @@ _start: // CHECK: Symbols [ // CHECK: Name: x -// CHECK-NEXT: Value: 0x13000 +// CHECK-NEXT: Value: 0x40000 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object // CHECK-NEXT: Other: // CHECK-NEXT: Section: .bss // CHECK: Name: y -// CHECK-NEXT: Value: 0x13010 +// CHECK-NEXT: Value: 0x40010 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object // CHECK-NEXT: Other: // CHECK-NEXT: Section: .bss // CHECK: Name: z -// CHECK-NEXT: Value: 0x13014 +// CHECK-NEXT: Value: 0x40014 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -78,16 +78,16 @@ _start: // CODE: Disassembly of section .text: // CODE-NEXT: _start: -// S(x) = 0x13000, A = 0, P = 0x11000 -// S + A - P = 0x2000 = 8208 -// CODE-NEXT: 11000: {{.*}} adr x1, #8192 -// S(y) = 0x13010, A = 0, P = 0x11004 -// Page(S + A) - Page(P) = 0x13000 - 0x11000 = 0x2000 = 8192 -// CODE-NEXT: 11004: {{.*}} adrp x2, #8192 -// S(y) = 0x13010, A = 0 +// S(x) = 0x40000, A = 0, P = 0x20000 +// S + A - P = 0x20000 = 131072 +// CODE-NEXT: 20000: {{.*}} adr x1, #131072 +// S(y) = 0x40010, A = 0, P = 0x20004 +// Page(S + A) - Page(P) = 0x40000 - 0x20000 = 0x20000 = 131072 +// CODE-NEXT: 20004: {{.*}} adrp x2, #131072 +// S(y) = 0x40010, A = 0 // (S + A) & 0xFFF = 0x10 = 16 -// CODE-NEXT: 11008: {{.*}} add x2, x2, #16 +// CODE-NEXT: 20008: {{.*}} add x2, x2, #16 // RODATA: Contents of section .rodata: -// S(z) = 0x13014 -// RODATA-NEXT: 101c8 14300100 +// S(z) = 0x40014 +// RODATA-NEXT: 101c8 14000400 diff --git a/test/ELF/aarch64-copy2.s b/test/ELF/aarch64-copy2.s index af99d8ec2aee1..6f72e21470aea 100644 --- a/test/ELF/aarch64-copy2.s +++ b/test/ELF/aarch64-copy2.s @@ -19,7 +19,7 @@ _start: // CHECK-NEXT: Section: Undefined // CHECK: Name: foo -// CHECK-NEXT: Value: 0x11030 +// CHECK-NEXT: Value: 0x20030 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Function diff --git a/test/ELF/aarch64-data-relocs.s b/test/ELF/aarch64-data-relocs.s index 30770836f7870..19e11bc3925c0 100644 --- a/test/ELF/aarch64-data-relocs.s +++ b/test/ELF/aarch64-data-relocs.s @@ -12,12 +12,12 @@ _start: // S = 0x100, A = 0x24 // S + A = 0x124 // CHECK: Contents of section .R_AARCH64_ABS64: -// CHECK-NEXT: 11000 24010000 00000000 +// CHECK-NEXT: 20000 24010000 00000000 .section .R_AARCH64_PREL64, "ax",@progbits .xword foo - . + 0x24 -// S = 0x100, A = 0x24, P = 0x11008 -// S + A - P = 0xfffffffffffef11c +// S = 0x100, A = 0x24, P = 0x20008 +// S + A - P = 0xfffffffffffe011c // CHECK: Contents of section .R_AARCH64_PREL64: -// CHECK-NEXT: 11008 1cf1feff ffffffff +// CHECK-NEXT: 20008 1c01feff ffffffff diff --git a/test/ELF/aarch64-fpic-abs16.s b/test/ELF/aarch64-fpic-abs16.s index e123f57447a58..539242a8d2179 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. +// CHECK: {{.*}}:(.data+0x0): relocation R_AARCH64_ABS16 cannot be used against shared object; recompile with -fPIC. .data .hword foo diff --git a/test/ELF/aarch64-fpic-add_abs_lo12_nc.s b/test/ELF/aarch64-fpic-add_abs_lo12_nc.s index 7e0b6b8330060..0ebd0fdde3a58 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 readonly segment +// CHECK: {{.*}}.o:(.text+0x0): can't create dynamic relocation R_AARCH64_ADD_ABS_LO12_NC against symbol 'dat' defined in {{.*}}.o add x0, x0, :lo12:dat .data diff --git a/test/ELF/aarch64-fpic-adr_prel_lo21.s b/test/ELF/aarch64-fpic-adr_prel_lo21.s index 501a724616e31..d01749600e718 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 readonly segment +// CHECK: {{.*}}.o:(.text+0x0): can't create dynamic relocation R_AARCH64_ADR_PREL_LO21 against symbol 'dat' defined in {{.*}}.o adr x0, dat .data diff --git a/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s b/test/ELF/aarch64-fpic-adr_prel_pg_hi21.s index 572ecffa6d71c..3da4b2ece5170 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 readonly segment +// CHECK: {{.*}}.o:(.text+0x0): can't create dynamic relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol 'dat' defined in {{.*}}.o adrp x0, dat .data diff --git a/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s b/test/ELF/aarch64-fpic-ldst32_abs_lo12_nc.s index 85772f10fcc78..8df582186b23d 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 readonly segment +// CHECK: {{.*}}.o:(.text+0x0): can't create dynamic relocation R_AARCH64_LDST32_ABS_LO12_NC against symbol 'dat' defined in {{.*}}.o ldr s4, [x0, :lo12:dat] .data diff --git a/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s b/test/ELF/aarch64-fpic-ldst64_abs_lo12_nc.s index d9f7b0c9ad1ba..fe80e654277fa 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 readonly segment +// CHECK: {{.*}}.o:(.text+0x0): can't create dynamic relocation R_AARCH64_LDST64_ABS_LO12_NC against symbol 'dat' defined in {{.*}}.o ldr x0, [x0, :lo12:dat] .data diff --git a/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s b/test/ELF/aarch64-fpic-ldst8_abs_lo12_nc.s index 20e1bba49d1eb..8442062bed97f 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 readonly segment +// CHECK: {{.*}}.o:(.text+0x0): can't create dynamic relocation R_AARCH64_LDST8_ABS_LO12_NC against symbol 'dat' defined in {{.*}}.o ldrsb x0, [x1, :lo12:dat] .data diff --git a/test/ELF/aarch64-fpic-prel16.s b/test/ELF/aarch64-fpic-prel16.s index 52e2402a4831b..3cb76cabd06ba 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: relocation R_AARCH64_PREL16 cannot be used against shared object; recompile with -fPIC. +// CHECK: {{.*}}:(.data+0x0): relocation R_AARCH64_PREL16 cannot be used against shared object; recompile with -fPIC. .data .hword foo - . diff --git a/test/ELF/aarch64-fpic-prel32.s b/test/ELF/aarch64-fpic-prel32.s index 72ba58f84d563..1c701e93cf845 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. +// CHECK: {{.*}}:(.data+0x0): relocation R_AARCH64_PREL32 cannot be used against shared object; recompile with -fPIC. .data .word foo - . diff --git a/test/ELF/aarch64-fpic-prel64.s b/test/ELF/aarch64-fpic-prel64.s index 53a4820962b6b..0f5f08a88eb33 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. +// CHECK: {{.*}}:(.data+0x0): relocation R_AARCH64_PREL64 cannot be used against shared object; recompile with -fPIC. .data .xword foo - . diff --git a/test/ELF/aarch64-gnu-ifunc-plt.s b/test/ELF/aarch64-gnu-ifunc-plt.s new file mode 100644 index 0000000000000..50e63f5257eb8 --- /dev/null +++ b/test/ELF/aarch64-gnu-ifunc-plt.s @@ -0,0 +1,85 @@ +// 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 +// RUN: ld.lld %t.so %t.o -o %tout +// 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 [ +// CHECK-NEXT: Section (4) .rela.plt { +// CHECK: 0x40018 R_AARCH64_JUMP_SLOT bar2 0x0 +// CHECK-NEXT: 0x40020 R_AARCH64_JUMP_SLOT zed2 0x0 +// CHECK-NEXT: 0x40028 R_AARCH64_IRELATIVE - 0x20000 +// CHECK-NEXT: 0x40030 R_AARCH64_IRELATIVE - 0x20004 +// CHECK-NEXT: } +// CHECK-NEXT: ] + +// Check that .got.plt entries point back to PLT header +// GOTPLT: Contents of section .got.plt: +// GOTPLT-NEXT: 40000 00000000 00000000 00000000 00000000 +// GOTPLT-NEXT: 40010 00000000 00000000 20000200 00000000 +// GOTPLT-NEXT: 40020 20000200 00000000 20000200 00000000 +// GOTPLT-NEXT: 40030 20000200 00000000 + +// Check that the PLTRELSZ tag includes the IRELATIVE relocations +// CHECK: DynamicSection [ +// CHECK: 0x0000000000000002 PLTRELSZ 96 (bytes) + +// Check that a PLT header is written and the ifunc entries appear last +// DISASM: Disassembly of section .text: +// DISASM-NEXT: foo: +// DISASM-NEXT: 20000: c0 03 5f d6 ret +// DISASM: bar: +// DISASM-NEXT: 20004: c0 03 5f d6 ret +// DISASM: _start: +// DISASM-NEXT: 20008: 16 00 00 94 bl #88 +// DISASM-NEXT: 2000c: 19 00 00 94 bl #100 +// DISASM-NEXT: 20010: 0c 00 00 94 bl #48 +// DISASM-NEXT: 20014: 0f 00 00 94 bl #60 +// DISASM-NEXT: Disassembly of section .plt: +// DISASM-NEXT: .plt: +// DISASM-NEXT: 20020: f0 7b bf a9 stp x16, x30, [sp, #-16]! +// DISASM-NEXT: 20024: 10 01 00 90 adrp x16, #131072 +// DISASM-NEXT: 20028: 11 0a 40 f9 ldr x17, [x16, #16] +// DISASM-NEXT: 2002c: 10 42 00 91 add x16, x16, #16 +// DISASM-NEXT: 20030: 20 02 1f d6 br x17 +// DISASM-NEXT: 20034: 1f 20 03 d5 nop +// DISASM-NEXT: 20038: 1f 20 03 d5 nop +// DISASM-NEXT: 2003c: 1f 20 03 d5 nop +// DISASM-NEXT: 20040: 10 01 00 90 adrp x16, #131072 +// DISASM-NEXT: 20044: 11 0e 40 f9 ldr x17, [x16, #24] +// DISASM-NEXT: 20048: 10 62 00 91 add x16, x16, #24 +// DISASM-NEXT: 2004c: 20 02 1f d6 br x17 +// DISASM-NEXT: 20050: 10 01 00 90 adrp x16, #131072 +// DISASM-NEXT: 20054: 11 12 40 f9 ldr x17, [x16, #32] +// DISASM-NEXT: 20058: 10 82 00 91 add x16, x16, #32 +// DISASM-NEXT: 2005c: 20 02 1f d6 br x17 +// DISASM-NEXT: 20060: 10 01 00 90 adrp x16, #131072 +// DISASM-NEXT: 20064: 11 16 40 f9 ldr x17, [x16, #40] +// DISASM-NEXT: 20068: 10 a2 00 91 add x16, x16, #40 +// DISASM-NEXT: 2006c: 20 02 1f d6 br x17 +// DISASM-NEXT: 20070: 10 01 00 90 adrp x16, #131072 +// DISASM-NEXT: 20074: 11 1a 40 f9 ldr x17, [x16, #48] +// DISASM-NEXT: 20078: 10 c2 00 91 add x16, x16, #48 +// DISASM-NEXT: 2007c: 20 02 1f d6 br x17 + +.text +.type foo STT_GNU_IFUNC +.globl foo +foo: + ret + +.type bar STT_GNU_IFUNC +.globl bar +bar: + ret + +.globl _start +_start: + bl foo + bl bar + bl bar2 + bl zed2 diff --git a/test/ELF/aarch64-gnu-ifunc.s b/test/ELF/aarch64-gnu-ifunc.s index 351d0ed0440a1..46f4a292d2ea1 100644 --- a/test/ELF/aarch64-gnu-ifunc.s +++ b/test/ELF/aarch64-gnu-ifunc.s @@ -15,15 +15,15 @@ // CHECK-NEXT: Address: [[RELA:.*]] // CHECK-NEXT: Offset: 0x158 // CHECK-NEXT: Size: 48 -// CHECK-NEXT: Link: 5 +// CHECK-NEXT: Link: 6 // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 8 // CHECK-NEXT: EntrySize: 24 // CHECK-NEXT: } // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.plt { -// CHECK-NEXT: 0x12018 R_AARCH64_IRELATIVE -// CHECK-NEXT: 0x12020 R_AARCH64_IRELATIVE +// CHECK-NEXT: 0x30000 R_AARCH64_IRELATIVE +// CHECK-NEXT: 0x30008 R_AARCH64_IRELATIVE // CHECK-NEXT: } // CHECK-NEXT: ] // CHECK: Symbols [ @@ -38,7 +38,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: $x.0 -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: 0x20000 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -69,7 +69,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x11008 +// CHECK-NEXT: Value: 0x20008 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None @@ -78,7 +78,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: bar -// CHECK-NEXT: Value: 0x11004 +// CHECK-NEXT: Value: 0x20004 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: GNU_IFunc @@ -87,7 +87,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: foo -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: 0x20000 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: GNU_IFunc @@ -98,34 +98,27 @@ // 344 = 0x158 // 392 = 0x188 -// DISASM: Disassembly of section .text: + +// DISASM: Disassembly of section .text: // DISASM-NEXT: foo: -// DISASM-NEXT: 11000: c0 03 5f d6 ret -// DISASM: bar: -// DISASM-NEXT: 11004: c0 03 5f d6 ret +// DISASM-NEXT: 20000: c0 03 5f d6 ret +// DISASM: bar: +// DISASM-NEXT: 20004: c0 03 5f d6 ret // DISASM: _start: -// DISASM-NEXT: 11008: 0e 00 00 94 bl #56 -// DISASM-NEXT: 1100c: 11 00 00 94 bl #68 -// DISASM-NEXT: 11010: 42 60 05 91 add x2, x2, #344 -// DISASM-NEXT: 11014: 42 20 06 91 add x2, x2, #392 +// DISASM-NEXT: 20008: 06 00 00 94 bl #24 +// DISASM-NEXT: 2000c: 09 00 00 94 bl #36 +// DISASM-NEXT: 20010: 42 60 05 91 add x2, x2, #344 +// DISASM-NEXT: 20014: 42 20 06 91 add x2, x2, #392 // DISASM-NEXT: Disassembly of section .plt: // DISASM-NEXT: .plt: -// DISASM-NEXT: 11020: f0 7b bf a9 stp x16, x30, [sp, #-16]! -// DISASM-NEXT: 11024: 10 00 00 b0 adrp x16, #4096 -// DISASM-NEXT: 11028: 11 0a 40 f9 ldr x17, [x16, #16] -// DISASM-NEXT: 1102c: 10 42 00 91 add x16, x16, #16 -// DISASM-NEXT: 11030: 20 02 1f d6 br x17 -// DISASM-NEXT: 11034: 1f 20 03 d5 nop -// DISASM-NEXT: 11038: 1f 20 03 d5 nop -// DISASM-NEXT: 1103c: 1f 20 03 d5 nop -// DISASM-NEXT: 11040: 10 00 00 b0 adrp x16, #4096 -// DISASM-NEXT: 11044: 11 0e 40 f9 ldr x17, [x16, #24] -// DISASM-NEXT: 11048: 10 62 00 91 add x16, x16, #24 -// DISASM-NEXT: 1104c: 20 02 1f d6 br x17 -// DISASM-NEXT: 11050: 10 00 00 b0 adrp x16, #4096 -// DISASM-NEXT: 11054: 11 12 40 f9 ldr x17, [x16, #32] -// DISASM-NEXT: 11058: 10 82 00 91 add x16, x16, #32 -// DISASM-NEXT: 1105c: 20 02 1f d6 br x17 +// DISASM-NEXT: 20020: 90 00 00 90 adrp x16, #65536 +// DISASM-NEXT: 20024: 11 02 40 f9 ldr x17, [x16] +// DISASM-NEXT: 20028: 10 02 00 91 add x16, x16, #0 +// DISASM-NEXT: 2002c: 20 02 1f d6 br x17 +// DISASM-NEXT: 20030: 90 00 00 90 adrp x16, #65536 +// DISASM-NEXT: 20034: 11 06 40 f9 ldr x17, [x16, #8] +// DISASM-NEXT: 20038: 10 22 00 91 add x16, x16, #8 +// DISASM-NEXT: 2003c: 20 02 1f d6 br x17 .text .type foo STT_GNU_IFUNC diff --git a/test/ELF/aarch64-got-reloc.s b/test/ELF/aarch64-got-reloc.s new file mode 100644 index 0000000000000..fec1ad6a1d222 --- /dev/null +++ b/test/ELF/aarch64-got-reloc.s @@ -0,0 +1,30 @@ +// REQUIRES: aarch64 +// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o +// RUN: ld.lld %t.o -o %t +// RUN: llvm-readobj -s --section-data %t | FileCheck %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: 0x30000 +// CHECK-NEXT: Offset: 0x20000 +// CHECK-NEXT: Size: 8 +// CHECK-NEXT: Link: 0 +// CHECK-NEXT: Info: 0 +// CHECK-NEXT: AddressAlignment: 8 +// CHECK-NEXT: EntrySize: 0 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 00000000 00000000 |........| +// CHECK-NEXT: ) + + .globl _start +_start: + adrp x8, :got:foo + ldr x8, [x8, :got_lo12:foo] + ldr w0, [x8] + ret + + .weak foo diff --git a/test/ELF/aarch64-prel16.s b/test/ELF/aarch64-prel16.s index 083cda9086087..4ae1f87e20810 100644 --- a/test/ELF/aarch64-prel16.s +++ b/test/ELF/aarch64-prel16.s @@ -14,7 +14,7 @@ _start: // the change of the address of the .data section. // You may found the correct address in the aarch64_abs16.s test, // if it is already fixed. Then, update addends accordingly. -// RUN: ld.lld %t.o %t256.o -o %t2 +// RUN: ld.lld -z max-page-size=4096 %t.o %t256.o -o %t2 // RUN: llvm-objdump -s -section=.data %t2 | FileCheck %s // CHECK: Contents of section .data: diff --git a/test/ELF/aarch64-prel32.s b/test/ELF/aarch64-prel32.s index c440b984eaa63..302f4521f46b1 100644 --- a/test/ELF/aarch64-prel32.s +++ b/test/ELF/aarch64-prel32.s @@ -14,7 +14,7 @@ _start: // the change of the address of the .data section. // You may found the correct address in the aarch64_abs32.s test, // if it is already fixed. Then, update addends accordingly. -// RUN: ld.lld %t.o %t256.o -o %t2 +// RUN: ld.lld -z max-page-size=4096 %t.o %t256.o -o %t2 // RUN: llvm-objdump -s -section=.data %t2 | FileCheck %s // CHECK: Contents of section .data: diff --git a/test/ELF/aarch64-relocs.s b/test/ELF/aarch64-relocs.s index 90541329587a8..9d02bd599b256 100644 --- a/test/ELF/aarch64-relocs.s +++ b/test/ELF/aarch64-relocs.s @@ -1,5 +1,6 @@ # RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t -# RUN: ld.lld %t -o %t2 +# 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 @@ -23,13 +24,13 @@ mystr: .asciz "blah" .size mystr, 4 -# S = 0x11012, A = 0x4, P = 0x11012 +# S = 0x20012, A = 0x4, P = 0x20012 # PAGE(S + A) = 0x11000 # PAGE(P) = 0x11000 # # CHECK: Disassembly of section .R_AARCH64_ADR_PREL_PG_H121: # CHECK-NEXT: $x.2: -# CHECK-NEXT: 11012: 01 00 00 90 adrp x1, #0 +# CHECK-NEXT: 20012: 01 00 00 90 adrp x1, #0 .section .R_AARCH64_ADD_ABS_LO12_NC,"ax",@progbits add x0, x0, :lo12:.L.str @@ -37,13 +38,13 @@ mystr: .asciz "blah" .size mystr, 4 -# S = 0x1101b, A = 0x4 +# S = 0x2001b, A = 0x4 # R = (S + A) & 0xFFF = 0x1f # R << 10 = 0x7c00 # # CHECK: Disassembly of section .R_AARCH64_ADD_ABS_LO12_NC: # CHECK-NEXT: $x.4: -# CHECK-NEXT: 1101b: 00 7c 00 91 add x0, x0, #31 +# CHECK-NEXT: 2001b: 00 7c 00 91 add x0, x0, #31 .section .R_AARCH64_LDST64_ABS_LO12_NC,"ax",@progbits ldr x28, [x27, :lo12:foo] @@ -51,12 +52,12 @@ foo: .asciz "foo" .size mystr, 3 -# S = 0x11024, A = 0x4 +# S = 0x20024, A = 0x4 # R = ((S + A) & 0xFFF) << 7 = 0x00001400 # 0x00001400 | 0xf940177c = 0xf940177c # CHECK: Disassembly of section .R_AARCH64_LDST64_ABS_LO12_NC: # CHECK-NEXT: $x.6: -# CHECK-NEXT: 11024: 7c 17 40 f9 ldr x28, [x27, #40] +# CHECK-NEXT: 20024: 7c 17 40 f9 ldr x28, [x27, #40] .section .SUB,"ax",@progbits nop @@ -65,33 +66,33 @@ sub: # CHECK: Disassembly of section .SUB: # CHECK-NEXT: $x.8: -# CHECK-NEXT: 1102c: 1f 20 03 d5 nop +# CHECK-NEXT: 2002c: 1f 20 03 d5 nop # CHECK: sub: -# CHECK-NEXT: 11030: 1f 20 03 d5 nop +# CHECK-NEXT: 20030: 1f 20 03 d5 nop .section .R_AARCH64_CALL26,"ax",@progbits call26: bl sub -# S = 0x1102c, A = 0x4, P = 0x11034 +# S = 0x2002c, A = 0x4, P = 0x20034 # R = S + A - P = -0x4 = 0xfffffffc # (R & 0x0ffffffc) >> 2 = 0x03ffffff # 0x94000000 | 0x03ffffff = 0x97ffffff # CHECK: Disassembly of section .R_AARCH64_CALL26: # CHECK-NEXT: call26: -# CHECK-NEXT: 11034: ff ff ff 97 bl #-4 +# CHECK-NEXT: 20034: ff ff ff 97 bl #-4 .section .R_AARCH64_JUMP26,"ax",@progbits jump26: b sub -# S = 0x1102c, A = 0x4, P = 0x11038 +# S = 0x2002c, A = 0x4, P = 0x20038 # R = S + A - P = -0x8 = 0xfffffff8 # (R & 0x0ffffffc) >> 2 = 0x03fffffe # 0x14000000 | 0x03fffffe = 0x17fffffe # CHECK: Disassembly of section .R_AARCH64_JUMP26: # CHECK-NEXT: jump26: -# CHECK-NEXT: 11038: fe ff ff 17 b #-8 +# CHECK-NEXT: 20038: fe ff ff 17 b #-8 .section .R_AARCH64_LDST32_ABS_LO12_NC,"ax",@progbits ldst32: @@ -100,12 +101,12 @@ foo32: .asciz "foo" .size mystr, 3 -# S = 0x1103c, A = 0x4 +# S = 0x2003c, A = 0x4 # R = ((S + A) & 0xFFC) << 8 = 0x00004000 # 0x00004000 | 0xbd4000a4 = 0xbd4040a4 # CHECK: Disassembly of section .R_AARCH64_LDST32_ABS_LO12_NC: # CHECK-NEXT: ldst32: -# CHECK-NEXT: 1103c: a4 40 40 bd ldr s4, [x5, #64] +# CHECK-NEXT: 2003c: a4 40 40 bd ldr s4, [x5, #64] .section .R_AARCH64_LDST8_ABS_LO12_NC,"ax",@progbits ldst8: @@ -114,12 +115,12 @@ foo8: .asciz "foo" .size mystr, 3 -# S = 0x11044, A = 0x4 +# S = 0x20044, A = 0x4 # R = ((S + A) & 0xFFF) << 10 = 0x00012000 # 0x00012000 | 0x398001ab = 0x398121ab # CHECK: Disassembly of section .R_AARCH64_LDST8_ABS_LO12_NC: # CHECK-NEXT: ldst8: -# CHECK-NEXT: 11044: ab 21 81 39 ldrsb x11, [x13, #72] +# CHECK-NEXT: 20044: ab 21 81 39 ldrsb x11, [x13, #72] .section .R_AARCH64_LDST128_ABS_LO12_NC,"ax",@progbits ldst128: @@ -128,25 +129,46 @@ foo128: .asciz "foo" .size mystr, 3 -# S = 0x1104c, A = 0x4 +# S = 0x2004c, A = 0x4 # R = ((S + A) & 0xFF8) << 6 = 0x00001400 # 0x00001400 | 0x3dc00274 = 0x3dc01674 # CHECK: Disassembly of section .R_AARCH64_LDST128_ABS_LO12_NC: # CHECK: ldst128: -# CHECK: 1104c: 74 16 c0 3d ldr q20, [x19, #80] +# CHECK: 2004c: 74 16 c0 3d ldr q20, [x19, #80] #foo128: -# 11050: 66 6f 6f 00 .word +# 20050: 66 6f 6f 00 .word .section .R_AARCH64_LDST16_ABS_LO12_NC,"ax",@progbits ldst16: ldr h17, [x19, :lo12:foo16] + ldrh w1, [x19, :lo12:foo16] + ldrh w2, [x19, :lo12:foo16 + 2] foo16: .asciz "foo" - .size mystr, 3 + .size mystr, 4 -# S = 0x11054, A = 0x4 +# S = 0x20054, A = 0x4 # R = ((S + A) & 0x0FFC) << 9 = 0xb000 # 0xb000 | 0x7d400271 = 0x7d40b271 # CHECK: Disassembly of section .R_AARCH64_LDST16_ABS_LO12_NC: # CHECK-NEXT: ldst16: -# CHECK-NEXT: 11054: 71 b2 40 7d ldr h17, [x19, #88] +# CHECK-NEXT: 20054: 71 c2 40 7d ldr h17, [x19, #96] +# CHECK-NEXT: 20058: 61 c2 40 79 ldrh w1, [x19, #96] +# CHECK-NEXT: 2005c: 62 c6 40 79 ldrh w2, [x19, #98] + +.section .R_AARCH64_MOVW_UABS,"ax",@progbits +movz1: + movk x12, #:abs_g0_nc:uabs_label + movk x13, #:abs_g1_nc:uabs_label + movk x14, #:abs_g2_nc:uabs_label + movz x15, #:abs_g3:uabs_label + movk x16, #:abs_g3:uabs_label + +## 4222124650659840 == (0xF << 48) +# CHECK: Disassembly of section .R_AARCH64_MOVW_UABS: +# CHECK-NEXT: movz1: +# CHECK-NEXT: 8c 01 80 f2 movk x12, #12 +# CHECK-NEXT: ad 01 a0 f2 movk x13, #13, lsl #16 +# CHECK-NEXT: ce 01 c0 f2 movk x14, #14, lsl #32 +# CHECK-NEXT: ef 01 e0 d2 mov x15, #4222124650659840 +# CHECK-NEXT: f0 01 e0 f2 movk x16, #15, lsl #48 diff --git a/test/ELF/aarch64-tls-gdie.s b/test/ELF/aarch64-tls-gdie.s index 709cc53a8c47e..c66ea6cfcadb1 100644 --- a/test/ELF/aarch64-tls-gdie.s +++ b/test/ELF/aarch64-tls-gdie.s @@ -21,14 +21,14 @@ _start: // SEC-NEXT: SHF_ALLOC // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x120B0 +// SEC-NEXT: Address: 0x300B0 -// page(0x120B0) - page(0x11004) = 4096 +// page(0x300B0) - page(0x20004) = 65536 // 0x0B0 = 176 // CHECK: _start: -// CHECK-NEXT: 11000: {{.*}} nop -// CHECK-NEXT: 11004: {{.*}} adrp x0, #4096 -// CHECK-NEXT: 11008: {{.*}} ldr x0, [x0, #176] -// CHECK-NEXT: 1100c: {{.*}} nop -// CHECK-NEXT: 11010: {{.*}} nop +// CHECK-NEXT: 20000: {{.*}} nop +// CHECK-NEXT: 20004: {{.*}} adrp x0, #65536 +// CHECK-NEXT: 20008: {{.*}} ldr x0, [x0, #176] +// CHECK-NEXT: 2000c: {{.*}} nop +// CHECK-NEXT: 20010: {{.*}} nop diff --git a/test/ELF/aarch64-tls-gdle.s b/test/ELF/aarch64-tls-gdle.s index dc0c02a31d1cb..a111cacefd290 100644 --- a/test/ELF/aarch64-tls-gdle.s +++ b/test/ELF/aarch64-tls-gdle.s @@ -12,10 +12,10 @@ # TCB size = 0x16 and foo is first element from TLS register. # CHECK: Disassembly of section .text: # CHECK: _start: -# CHECK: 11000: 00 00 a0 d2 movz x0, #0, lsl #16 -# CHECK: 11004: 00 02 80 f2 movk x0, #16 -# CHECK: 11008: 1f 20 03 d5 nop -# CHECK: 1100c: 1f 20 03 d5 nop +# CHECK: 20000: 00 00 a0 d2 movz x0, #0, lsl #16 +# CHECK: 20004: 00 02 80 f2 movk x0, #16 +# CHECK: 20008: 1f 20 03 d5 nop +# CHECK: 2000c: 1f 20 03 d5 nop .globl _start _start: diff --git a/test/ELF/aarch64-tls-ie.s b/test/ELF/aarch64-tls-ie.s index 0cec402b294a2..81ca326aff54f 100644 --- a/test/ELF/aarch64-tls-ie.s +++ b/test/ELF/aarch64-tls-ie.s @@ -15,8 +15,8 @@ #RELOC-NEXT: SHF_ALLOC #RELOC-NEXT: SHF_WRITE #RELOC-NEXT: ] -#RELOC-NEXT: Address: 0x120B0 -#RELOC-NEXT: Offset: 0x20B0 +#RELOC-NEXT: Address: 0x300B0 +#RELOC-NEXT: Offset: 0x200B0 #RELOC-NEXT: Size: 16 #RELOC-NEXT: Link: 0 #RELOC-NEXT: Info: 0 @@ -25,21 +25,21 @@ #RELOC-NEXT: } #RELOC: Relocations [ #RELOC-NEXT: Section ({{.*}}) .rela.dyn { -#RELOC-NEXT: 0x120B8 R_AARCH64_TLS_TPREL64 bar 0x0 -#RELOC-NEXT: 0x120B0 R_AARCH64_TLS_TPREL64 foo 0x0 +#RELOC-NEXT: 0x300B8 R_AARCH64_TLS_TPREL64 bar 0x0 +#RELOC-NEXT: 0x300B0 R_AARCH64_TLS_TPREL64 foo 0x0 #RELOC-NEXT: } #RELOC-NEXT:] -# Page(0x120B0) - Page(0x11000) = 0x1000 = 4096 -# 0x120B0 & 0xff8 = 0xB0 = 176 -# Page(0x120B8) - Page(0x11000) = 0x1000 = 4096 -# 0x120B8 & 0xff8 = 0xB8 = 184 +# Page(0x300B0) - Page(0x20000) = 0x10000 = 65536 +# 0x300B0 & 0xff8 = 0xB0 = 176 +# Page(0x300B8) - Page(0x20000) = 0x10000 = 65536 +# 0x300B8 & 0xff8 = 0xB8 = 184 #CHECK: Disassembly of section .text: #CHECK: _start: -#CHECK: 11000: 00 00 00 b0 adrp x0, #4096 -#CHECK: 11004: 00 58 40 f9 ldr x0, [x0, #176] -#CHECK: 11008: 00 00 00 b0 adrp x0, #4096 -#CHECK: 1100c: 00 5c 40 f9 ldr x0, [x0, #184] +#CHECK: 20000: 80 00 00 90 adrp x0, #65536 +#CHECK: 20004: 00 58 40 f9 ldr x0, [x0, #176] +#CHECK: 20008: 80 00 00 90 adrp x0, #65536 +#CHECK: 2000c: 00 5c 40 f9 ldr x0, [x0, #184] .globl _start _start: diff --git a/test/ELF/aarch64-tls-iele.s b/test/ELF/aarch64-tls-iele.s index 91efc092a2cfa..208b5cdd54462 100644 --- a/test/ELF/aarch64-tls-iele.s +++ b/test/ELF/aarch64-tls-iele.s @@ -12,10 +12,10 @@ # TCB size = 0x16 and foo is first element from TLS register. # CHECK: Disassembly of section .text: # CHECK: _start: -# CHECK-NEXT: 11000: 00 00 a0 d2 movz x0, #0, lsl #16 -# CHECK-NEXT: 11004: 80 02 80 f2 movk x0, #20 -# CHECK-NEXT: 11008: 00 00 a0 d2 movz x0, #0, lsl #16 -# CHECK-NEXT: 1100c: 00 02 80 f2 movk x0, #16 +# CHECK-NEXT: 20000: 00 00 a0 d2 movz x0, #0, lsl #16 +# CHECK-NEXT: 20004: 80 02 80 f2 movk x0, #20 +# CHECK-NEXT: 20008: 00 00 a0 d2 movz x0, #0, lsl #16 +# CHECK-NEXT: 2000c: 00 02 80 f2 movk x0, #16 .section .tdata .align 2 diff --git a/test/ELF/aarch64-tls-le.s b/test/ELF/aarch64-tls-le.s index 22bd0ef2dad7b..df943f7f091a0 100644 --- a/test/ELF/aarch64-tls-le.s +++ b/test/ELF/aarch64-tls-le.s @@ -17,9 +17,9 @@ _start: # TCB size = 0x16 and foo is first element from TLS register. #CHECK: Disassembly of section .text: #CHECK: _start: -#CHECK: 11000: 40 d0 3b d5 mrs x0, TPIDR_EL0 -#CHECK: 11004: 00 00 00 91 add x0, x0, #0 -#CHECK: 11008: 00 40 00 91 add x0, x0, #16 +#CHECK: 20000: 40 d0 3b d5 mrs x0, TPIDR_EL0 +#CHECK: 20004: 00 00 40 91 add x0, x0, #0, lsl #12 +#CHECK: 20008: 00 40 00 91 add x0, x0, #16 .type v1,@object .section .tbss,"awT",@nobits diff --git a/test/ELF/aarch64-tls-static.s b/test/ELF/aarch64-tls-static.s index c8508ee58b7f6..24306d5d7ee30 100644 --- a/test/ELF/aarch64-tls-static.s +++ b/test/ELF/aarch64-tls-static.s @@ -23,15 +23,15 @@ bar: // SEC-NEXT: SHF_ALLOC // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x2098 -// SEC-NEXT: Offset: 0x2098 +// SEC-NEXT: Address: 0x20098 +// SEC-NEXT: Offset: 0x20098 // SEC-NEXT: Size: 16 -// page(0x2098) - page(0x1000) = 4096 +// page(0x20098) - page(0x10000) = 65536 // 0x98 = 152 // CHECK: foo: -// CHECK-NEXT: 1000: {{.*}} adrp x0, #4096 -// CHECK-NEXT: 1004: {{.*}} ldr x1, [x0, #152] -// CHECK-NEXT: 1008: {{.*}} add x0, x0, #152 -// CHECK-NEXT: 100c: {{.*}} blr x1 +// CHECK-NEXT: 10000: {{.*}} adrp x0, #65536 +// CHECK-NEXT: 10004: {{.*}} ldr x1, [x0, #152] +// CHECK-NEXT: 10008: {{.*}} add x0, x0, #152 +// CHECK-NEXT: 1000c: {{.*}} blr x1 diff --git a/test/ELF/aarch64-tlsdesc.s b/test/ELF/aarch64-tlsdesc.s index f8c73aff243d8..09dfd04d8ac9c 100644 --- a/test/ELF/aarch64-tlsdesc.s +++ b/test/ELF/aarch64-tlsdesc.s @@ -4,21 +4,69 @@ // RUN: llvm-objdump -d %t.so | FileCheck %s // RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=REL %s + .text adrp x0, :tlsdesc:a ldr x1, [x0, :tlsdesc_lo12:a] add x0, x0, :tlsdesc_lo12:a .tlsdesccall a blr x1 -// CHECK: 1000: {{.*}} adrp x0, #4096 -// CHECK-NEXT: 1004: {{.*}} ldr x1, [x0, #144] -// CHECK-NEXT: 1008: {{.*}} add x0, x0, #144 -// CHECK-NEXT: 100c: {{.*}} blr x1 +// Create relocation against local TLS symbols where linker should +// create target specific dynamic TLSDESC relocation where addend is +// the symbol VMA in tls block. +// CHECK: 10000: {{.*}} adrp x0, #65536 +// CHECK-NEXT: 10004: {{.*}} ldr x1, [x0, #144] +// CHECK-NEXT: 10008: {{.*}} add x0, x0, #144 +// CHECK-NEXT: 1000c: {{.*}} blr x1 + + adrp x0, :tlsdesc:local1 + ldr x1, [x0, :tlsdesc_lo12:local1] + add x0, x0, :tlsdesc_lo12:local1 + .tlsdesccall a + blr x1 + +// CHECK: 10010: {{.*}} adrp x0, #65536 +// CHECK-NEXT: 10014: {{.*}} ldr x1, [x0, #160] +// CHECK-NEXT: 10018: {{.*}} add x0, x0, #160 +// CHECK-NEXT: 1001c: {{.*}} blr x1 + + adrp x0, :tlsdesc:local2 + ldr x1, [x0, :tlsdesc_lo12:local2] + add x0, x0, :tlsdesc_lo12:local2 + .tlsdesccall a + blr x1 + +// CHECK: 10020: {{.*}} adrp x0, #65536 +// CHECK-NEXT: 10024: {{.*}} ldr x1, [x0, #176] +// CHECK-NEXT: 10028: {{.*}} add x0, x0, #176 +// CHECK-NEXT: 1002c: {{.*}} blr x1 + + .section .tbss,"awT",@nobits + .type local1,@object + .p2align 2 +local1: + .word 0 + .size local1, 4 + + .type local2,@object + .p2align 3 +local2: + .xword 0 + .size local2, 8 + + +// 0x1000 + 4096 + 160 = 0x20A0 +// 0x1000 + 4096 + 176 = 0x20B0 // 0x1000 + 4096 + 144 = 0x2090 +// R_AARCH64_TLSDESC - 0x0 -> start of tls block +// R_AARCH64_TLSDESC - 0x8 -> align (sizeof (local1), 8) + // REL: Relocations [ // REL-NEXT: Section (4) .rela.dyn { -// REL-NEXT: 0x2090 R_AARCH64_TLSDESC a 0x0 +// REL-NEXT: 0x200A0 R_AARCH64_TLSDESC - 0x0 +// REL-NEXT: 0x200B0 R_AARCH64_TLSDESC - 0x8 +// REL-NEXT: 0x20090 R_AARCH64_TLSDESC a 0x0 // REL-NEXT: } // REL-NEXT: ] diff --git a/test/ELF/aarch64-tstbr14-reloc.s b/test/ELF/aarch64-tstbr14-reloc.s index 1dc1bdf3c09a9..6523a9c1cc9dd 100644 --- a/test/ELF/aarch64-tstbr14-reloc.s +++ b/test/ELF/aarch64-tstbr14-reloc.s @@ -7,25 +7,25 @@ # RUN: llvm-readobj -s -r %t3 | FileCheck -check-prefix=DSOREL %s # REQUIRES: aarch64 -# 0x1101c - 28 = 0x11000 -# 0x11020 - 16 = 0x11010 -# 0x11024 - 36 = 0x11000 -# 0x11028 - 24 = 0x11010 +# 0x1101c - 28 = 0x20000 +# 0x11020 - 16 = 0x20010 +# 0x11024 - 36 = 0x20000 +# 0x11028 - 24 = 0x20010 # CHECK: Disassembly of section .text: # CHECK-NEXT: _foo: -# CHECK-NEXT: 11000: {{.*}} nop -# CHECK-NEXT: 11004: {{.*}} nop -# CHECK-NEXT: 11008: {{.*}} nop -# CHECK-NEXT: 1100c: {{.*}} nop +# CHECK-NEXT: 20000: {{.*}} nop +# CHECK-NEXT: 20004: {{.*}} nop +# CHECK-NEXT: 20008: {{.*}} nop +# CHECK-NEXT: 2000c: {{.*}} nop # CHECK: _bar: -# CHECK-NEXT: 11010: {{.*}} nop -# CHECK-NEXT: 11014: {{.*}} nop -# CHECK-NEXT: 11018: {{.*}} nop +# CHECK-NEXT: 20010: {{.*}} nop +# CHECK-NEXT: 20014: {{.*}} nop +# CHECK-NEXT: 20018: {{.*}} nop # CHECK: _start: -# CHECK-NEXT: 1101c: {{.*}} tbnz w3, #15, #-28 -# CHECK-NEXT: 11020: {{.*}} tbnz w3, #15, #-16 -# CHECK-NEXT: 11024: {{.*}} tbz x6, #45, #-36 -# CHECK-NEXT: 11028: {{.*}} tbz x6, #45, #-24 +# CHECK-NEXT: 2001c: {{.*}} tbnz w3, #15, #-28 +# CHECK-NEXT: 20020: {{.*}} tbnz w3, #15, #-16 +# CHECK-NEXT: 20024: {{.*}} tbz x6, #45, #-36 +# CHECK-NEXT: 20028: {{.*}} tbz x6, #45, #-24 #DSOREL: Section { #DSOREL: Index: @@ -35,8 +35,8 @@ #DSOREL-NEXT: SHF_ALLOC #DSOREL-NEXT: SHF_WRITE #DSOREL-NEXT: ] -#DSOREL-NEXT: Address: 0x3000 -#DSOREL-NEXT: Offset: 0x3000 +#DSOREL-NEXT: Address: 0x30000 +#DSOREL-NEXT: Offset: 0x30000 #DSOREL-NEXT: Size: 40 #DSOREL-NEXT: Link: 0 #DSOREL-NEXT: Info: 0 @@ -45,48 +45,48 @@ #DSOREL-NEXT: } #DSOREL: Relocations [ #DSOREL-NEXT: Section ({{.*}}) .rela.plt { -#DSOREL-NEXT: 0x3018 R_AARCH64_JUMP_SLOT _foo -#DSOREL-NEXT: 0x3020 R_AARCH64_JUMP_SLOT _bar +#DSOREL-NEXT: 0x30018 R_AARCH64_JUMP_SLOT _foo +#DSOREL-NEXT: 0x30020 R_AARCH64_JUMP_SLOT _bar #DSOREL-NEXT: } #DSOREL-NEXT:] #DSO: Disassembly of section .text: #DSO-NEXT: _foo: -#DSO-NEXT: 1000: {{.*}} nop -#DSO-NEXT: 1004: {{.*}} nop -#DSO-NEXT: 1008: {{.*}} nop -#DSO-NEXT: 100c: {{.*}} nop +#DSO-NEXT: 10000: {{.*}} nop +#DSO-NEXT: 10004: {{.*}} nop +#DSO-NEXT: 10008: {{.*}} nop +#DSO-NEXT: 1000c: {{.*}} nop #DSO: _bar: -#DSO-NEXT: 1010: {{.*}} nop -#DSO-NEXT: 1014: {{.*}} nop -#DSO-NEXT: 1018: {{.*}} nop +#DSO-NEXT: 10010: {{.*}} nop +#DSO-NEXT: 10014: {{.*}} nop +#DSO-NEXT: 10018: {{.*}} nop #DSO: _start: -# 0x101c + 52 = 0x1050 = PLT[1] -# 0x1020 + 64 = 0x1060 = PLT[2] -# 0x1024 + 44 = 0x1050 = PLT[1] -# 0x1028 + 56 = 0x1060 = PLT[2] -#DSO-NEXT: 101c: {{.*}} tbnz w3, #15, #52 -#DSO-NEXT: 1020: {{.*}} tbnz w3, #15, #64 -#DSO-NEXT: 1024: {{.*}} tbz x6, #45, #44 -#DSO-NEXT: 1028: {{.*}} tbz x6, #45, #56 +# 0x1001c + 52 = 0x10050 = PLT[1] +# 0x10020 + 64 = 0x10060 = PLT[2] +# 0x10024 + 44 = 0x10050 = PLT[1] +# 0x10028 + 56 = 0x10060 = PLT[2] +#DSO-NEXT: 1001c: {{.*}} tbnz w3, #15, #52 +#DSO-NEXT: 10020: {{.*}} tbnz w3, #15, #64 +#DSO-NEXT: 10024: {{.*}} tbz x6, #45, #44 +#DSO-NEXT: 10028: {{.*}} tbz x6, #45, #56 #DSO-NEXT: Disassembly of section .plt: #DSO-NEXT: .plt: -#DSO-NEXT: 1030: {{.*}} stp x16, x30, [sp, #-16]! -#DSO-NEXT: 1034: {{.*}} adrp x16, #8192 -#DSO-NEXT: 1038: {{.*}} ldr x17, [x16, #16] -#DSO-NEXT: 103c: {{.*}} add x16, x16, #16 -#DSO-NEXT: 1040: {{.*}} br x17 -#DSO-NEXT: 1044: {{.*}} nop -#DSO-NEXT: 1048: {{.*}} nop -#DSO-NEXT: 104c: {{.*}} nop -#DSO-NEXT: 1050: {{.*}} adrp x16, #8192 -#DSO-NEXT: 1054: {{.*}} ldr x17, [x16, #24] -#DSO-NEXT: 1058: {{.*}} add x16, x16, #24 -#DSO-NEXT: 105c: {{.*}} br x17 -#DSO-NEXT: 1060: {{.*}} adrp x16, #8192 -#DSO-NEXT: 1064: {{.*}} ldr x17, [x16, #32] -#DSO-NEXT: 1068: {{.*}} add x16, x16, #32 -#DSO-NEXT: 106c: {{.*}} br x17 +#DSO-NEXT: 10030: {{.*}} stp x16, x30, [sp, #-16]! +#DSO-NEXT: 10034: {{.*}} adrp x16, #131072 +#DSO-NEXT: 10038: {{.*}} ldr x17, [x16, #16] +#DSO-NEXT: 1003c: {{.*}} add x16, x16, #16 +#DSO-NEXT: 10040: {{.*}} br x17 +#DSO-NEXT: 10044: {{.*}} nop +#DSO-NEXT: 10048: {{.*}} nop +#DSO-NEXT: 1004c: {{.*}} nop +#DSO-NEXT: 10050: {{.*}} adrp x16, #131072 +#DSO-NEXT: 10054: {{.*}} ldr x17, [x16, #24] +#DSO-NEXT: 10058: {{.*}} add x16, x16, #24 +#DSO-NEXT: 1005c: {{.*}} br x17 +#DSO-NEXT: 10060: {{.*}} adrp x16, #131072 +#DSO-NEXT: 10064: {{.*}} ldr x17, [x16, #32] +#DSO-NEXT: 10068: {{.*}} add x16, x16, #32 +#DSO-NEXT: 1006c: {{.*}} br x17 .globl _start _start: diff --git a/test/ELF/aarch64-undefined-weak.s b/test/ELF/aarch64-undefined-weak.s new file mode 100644 index 0000000000000..74fef669ed74f --- /dev/null +++ b/test/ELF/aarch64-undefined-weak.s @@ -0,0 +1,45 @@ +// 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 +// Symbols in relative are resolved to the place so S - P + A = A. + + .weak target + + .text + .global _start +_start: +// R_AARCH64_JUMP26 + b target +// R_AARCH64_CALL26 + bl target +// R_AARCH64_CONDBR19 + b.eq target +// R_AARCH64_TSTBR14 + cbz x1, target +// R_AARCH64_ADR_PREL_LO21 + adr x0, target +// R_AARCH64_ADR_PREL_PG_HI21 + adrp x0, target +// R_AARCH64_PREL32 + .word target - . +// R_AARCH64_PREL64 + .xword target - . +// R_AARCH64_PREL16 + .hword target - . + +// CHECK: Disassembly of section .text: +// 131076 = 0x20004 +// CHECK: 20000: 01 80 00 14 b #131076 +// CHECK-NEXT: 20004: 02 80 00 94 bl #131080 +// CHECK-NEXT: 20008: 60 00 10 54 b.eq #131084 +// CHECK-NEXT: 2000c: 81 00 10 b4 cbz x1, #131088 +// CHECK-NEXT: 20010: 00 00 00 10 adr x0, #0 +// CHECK-NEXT: 20014: 00 00 00 90 adrp x0, #0 +// CHECK: 20018: 00 00 00 00 .word 0x00000000 +// CHECK-NEXT: 2001c: 00 00 00 00 .word 0x00000000 +// CHECK-NEXT: 20020: 00 00 00 00 .word 0x00000000 +// CHECK-NEXT: 20024: 00 00 .short 0x0000 diff --git a/test/ELF/abs-conflict.s b/test/ELF/abs-conflict.s new file mode 100644 index 0000000000000..7837a6bae50a7 --- /dev/null +++ b/test/ELF/abs-conflict.s @@ -0,0 +1,16 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: ld.lld %t.o %t.o -o %t.so -shared +// RUN: llvm-readobj --dyn-symbols %t.so | FileCheck %s + +// CHECK: Name: foo +// CHECK-NEXT: Value: 0x123 + +.global foo +foo = 0x123 + +// RUN: echo ".global foo; foo = 0x124" > %t2.s +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t2.s -o %t2.o +// RUN: not ld.lld %t.o %t2.o -o %t.so -shared 2>&1 | FileCheck --check-prefix=DUP %s + +// DUP: duplicate symbol 'foo' diff --git a/test/ELF/abs-hidden.s b/test/ELF/abs-hidden.s index b93c2c692919a..5fad4cf6c40dd 100644 --- a/test/ELF/abs-hidden.s +++ b/test/ELF/abs-hidden.s @@ -25,7 +25,7 @@ // 0x2060 - (0x1000 + 8) = 1058 // CHECK-NEXT: ) -// CHECK: Name: .got (38) +// CHECK: Name: .got // CHECK-NEXT: Type: SHT_PROGBITS // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC diff --git a/test/ELF/allow-multiple-definition.s b/test/ELF/allow-multiple-definition.s index 89ea8c865822f..e4637e1a53678 100644 --- a/test/ELF/allow-multiple-definition.s +++ b/test/ELF/allow-multiple-definition.s @@ -15,10 +15,10 @@ # meet symbol should be used. # CHECK: _bar: -# CHECK-NEXT: 11000: b8 01 00 00 00 movl $1, %eax +# CHECK-NEXT: 201000: b8 01 00 00 00 movl $1, %eax # REVERT: _bar: -# REVERT-NEXT: 11000: b8 02 00 00 00 movl $2, %eax +# REVERT-NEXT: 201000: b8 02 00 00 00 movl $2, %eax .globl _bar .type _bar, @function diff --git a/test/ELF/amdgpu-entry.s b/test/ELF/amdgpu-entry.s deleted file mode 100644 index 2a47b1778de89..0000000000000 --- a/test/ELF/amdgpu-entry.s +++ /dev/null @@ -1,16 +0,0 @@ -# RUN: llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=kaveri %s -o %t.o -# RUN: not ld.lld -e kernel0 %t.o -o %t - -# REQUIRES: amdgpu - -.hsa_code_object_version 1,0 -.hsa_code_object_isa 7,0,0,"AMD","AMDGPU" - -.hsatext -.globl kernel0 -.align 256 -.amdgpu_hsa_kernel kernel0 -kernel0: - s_endpgm -.Lfunc_end0: - .size kernel0, .Lfunc_end0-kernel0 diff --git a/test/ELF/amdgpu-globals.s b/test/ELF/amdgpu-globals.s index 7f46b989b9558..f30c0ed40157a 100644 --- a/test/ELF/amdgpu-globals.s +++ b/test/ELF/amdgpu-globals.s @@ -1,5 +1,5 @@ # RUN: llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=kaveri %s -o %t.o -# RUN: lld -flavor gnu %t.o -o %t +# RUN: ld.lld %t.o -o %t # RUN: llvm-readobj -sections -symbols -program-headers %t | FileCheck %s # REQUIRES: amdgpu diff --git a/test/ELF/amdgpu-relocs.s b/test/ELF/amdgpu-relocs.s index 58c9582a84f16..965a812b14b94 100644 --- a/test/ELF/amdgpu-relocs.s +++ b/test/ELF/amdgpu-relocs.s @@ -1,33 +1,93 @@ # RUN: llvm-mc -filetype=obj -triple=amdgcn--amdhsa -mcpu=fiji %s -o %t.o # RUN: ld.lld -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 +.text kernel0: - s_mov_b32 s0, common_var@GOTPCREL+4 - s_mov_b32 s0, extern_var@GOTPCREL+4 - s_mov_b32 s0, local_var+4 - s_mov_b32 s0, global_var@GOTPCREL+4 - s_mov_b32 s0, weak_var@GOTPCREL+4 - s_mov_b32 s0, weakref_var@GOTPCREL+4 + s_mov_b32 s0, common_var0@GOTPCREL+4 + s_mov_b32 s0, common_var1@gotpcrel32@lo+4 + s_mov_b32 s0, common_var2@gotpcrel32@hi+4 + + s_mov_b32 s0, global_var0@GOTPCREL+4 + s_mov_b32 s0, global_var1@gotpcrel32@lo+4 + s_mov_b32 s0, global_var2@gotpcrel32@hi+4 + + s_mov_b32 s0, extern_var0@GOTPCREL+4 + s_mov_b32 s0, extern_var1@gotpcrel32@lo+4 + s_mov_b32 s0, extern_var2@gotpcrel32@hi+4 + + s_mov_b32 s0, weak_var0@GOTPCREL+4 + s_mov_b32 s0, weak_var1@gotpcrel32@lo+4 + s_mov_b32 s0, weak_var2@gotpcrel32@hi+4 + + s_mov_b32 s0, weakref_var0@GOTPCREL+4 + s_mov_b32 s0, weakref_var1@gotpcrel32@lo+4 + s_mov_b32 s0, weakref_var2@gotpcrel32@hi+4 + + s_mov_b32 s0, local_var0+4 + s_mov_b32 s0, local_var1@rel32@lo+4 + s_mov_b32 s0, local_var2@rel32@hi+4 + s_endpgm - .comm common_var,1024,4 - .globl global_var - .local local_var - .weak weak_var - .weakref weakref_var, weakref_alias_var + .comm common_var0,1024,4 + .comm common_var1,1024,4 + .comm common_var2,1024,4 + .globl global_var0 + .globl global_var1 + .globl global_var1 + .weak weak_var0 + .weak weak_var1 + .weak weak_var2 + .weakref weakref_var0, weakref_alias_var0 + .weakref weakref_var1, weakref_alias_var1 + .weakref weakref_var2, weakref_alias_var2 + .local local_var0 + .local local_var1 + .local local_var2 + +# R_AMDGPU_ABS32: +.section nonalloc, "w", @progbits + .long var0, common_var2+4 + .long var1, common_var1+8 + .long var2, common_var0+12 -# The relocation for local_var should be resolved by the linker. +# R_AMDGPU_ABS64: +.type ptr, @object +.data + .globl ptr + .p2align 3 +ptr: + .quad temp + .size ptr, 8 + +# The relocation for local_var{0, 1, 2} and var should be resolved by the +# linker. # CHECK: Relocations [ # CHECK: .rela.dyn { -# CHECK-NEXT: R_AMDGPU_ABS64 common_var 0x0 -# CHECK-NEXT: R_AMDGPU_ABS64 extern_var 0x0 -# CHECK-NEXT: R_AMDGPU_ABS64 global_var 0x0 -# CHECK-NEXT: R_AMDGPU_ABS64 weak_var 0x0 -# CHECK-NEXT: R_AMDGPU_ABS64 weakref_alias_var 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 common_var0 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 common_var1 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 common_var2 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 extern_var0 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 extern_var1 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 extern_var2 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 global_var0 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 global_var1 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 global_var2 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 temp 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 weak_var0 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 weak_var1 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 weak_var2 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 weakref_alias_var0 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 weakref_alias_var1 0x0 +# CHECK-NEXT: R_AMDGPU_ABS64 weakref_alias_var2 0x0 # CHECK-NEXT: } # CHECK-NEXT: ] + +# OBJDUMP: Contents of section nonalloc: +# OBJDUMP-NEXT: 0000 00000000 14380000 00000000 18340000 +# OBJDUMP-NEXT: 00000000 1c300000 diff --git a/test/ELF/arm-attributes.s b/test/ELF/arm-attributes.s new file mode 100644 index 0000000000000..14517e8fc7893 --- /dev/null +++ b/test/ELF/arm-attributes.s @@ -0,0 +1,183 @@ +// 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 + +// RUN: ld.lld %t1.o %t2.o -o %t +// RUN: llvm-readobj -arm-attributes %t | FileCheck %s +// RUN: ld.lld %t1.o %t2.o -shared -o %t2 +// 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 +// pass the first one through. + .text + .syntax unified + .eabi_attribute 67, "2.09" @ Tag_conformance + .cpu cortex-a8 + .eabi_attribute 6, 10 @ Tag_CPU_arch + .eabi_attribute 7, 65 @ Tag_CPU_arch_profile + .eabi_attribute 8, 1 @ Tag_ARM_ISA_use + .eabi_attribute 9, 2 @ Tag_THUMB_ISA_use + .fpu neon + .eabi_attribute 15, 1 @ Tag_ABI_PCS_RW_data + .eabi_attribute 16, 1 @ Tag_ABI_PCS_RO_data + .eabi_attribute 17, 2 @ Tag_ABI_PCS_GOT_use + .eabi_attribute 20, 1 @ Tag_ABI_FP_denormal + .eabi_attribute 21, 1 @ Tag_ABI_FP_exceptions + .eabi_attribute 23, 3 @ Tag_ABI_FP_number_model + .eabi_attribute 34, 1 @ Tag_CPU_unaligned_access + .eabi_attribute 24, 1 @ Tag_ABI_align_needed + .eabi_attribute 25, 1 @ Tag_ABI_align_preserved + .eabi_attribute 38, 1 @ Tag_ABI_FP_16bit_format + .eabi_attribute 18, 4 @ Tag_ABI_PCS_wchar_t + .eabi_attribute 26, 2 @ Tag_ABI_enum_size + .eabi_attribute 14, 0 @ Tag_ABI_PCS_R9_use + .eabi_attribute 68, 1 @ Tag_Virtualization_use + .globl _start + .p2align 2 + .type _start,%function +_start: + .globl func + bl func + bx lr + +// CHECK: BuildAttributes { +// CHECK-NEXT: FormatVersion: 0x41 +// CHECK-NEXT: Section 1 { +// CHECK-NEXT: SectionLength: 72 +// CHECK-NEXT: Vendor: aeabi +// CHECK-NEXT: Tag: Tag_File (0x1) +// CHECK-NEXT: Size: 62 +// CHECK-NEXT: FileAttributes { +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 67 +// CHECK-NEXT: TagName: conformance +// CHECK-NEXT: Value: 2.09 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 5 +// CHECK-NEXT: TagName: CPU_name +// CHECK-NEXT: Value: cortex-a8 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 6 +// CHECK-NEXT: Value: 10 +// CHECK-NEXT: TagName: CPU_arch +// CHECK-NEXT: Description: ARM v7 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 7 +// CHECK-NEXT: Value: 65 +// CHECK-NEXT: TagName: CPU_arch_profile +// CHECK-NEXT: Description: Application +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 8 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ARM_ISA_use +// CHECK-NEXT: Description: Permitted +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 9 +// CHECK-NEXT: Value: 2 +// CHECK-NEXT: TagName: THUMB_ISA_use +// CHECK-NEXT: Description: Thumb-2 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 10 +// CHECK-NEXT: Value: 3 +// CHECK-NEXT: TagName: FP_arch +// CHECK-NEXT: Description: VFPv3 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 12 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: Advanced_SIMD_arch +// CHECK-NEXT: Description: NEONv1 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 14 +// CHECK-NEXT: Value: 0 +// CHECK-NEXT: TagName: ABI_PCS_R9_use +// CHECK-NEXT: Description: v6 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 15 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_PCS_RW_data +// CHECK-NEXT: Description: PC-relative +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 16 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_PCS_RO_data +// CHECK-NEXT: Description: PC-relative +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 17 +// CHECK-NEXT: Value: 2 +// CHECK-NEXT: TagName: ABI_PCS_GOT_use +// CHECK-NEXT: Description: GOT-Indirect +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 18 +// CHECK-NEXT: Value: 4 +// CHECK-NEXT: TagName: ABI_PCS_wchar_t +// CHECK-NEXT: Description: 4-byte +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 20 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_FP_denormal +// CHECK-NEXT: Description: IEEE-754 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 21 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_FP_exceptions +// CHECK-NEXT: Description: IEEE-754 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 23 +// CHECK-NEXT: Value: 3 +// CHECK-NEXT: TagName: ABI_FP_number_model +// CHECK-NEXT: Description: IEEE-754 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 24 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_align_needed +// CHECK-NEXT: Description: 8-byte alignment +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 25 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_align_preserved +// CHECK-NEXT: Description: 8-byte data alignment +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 26 +// CHECK-NEXT: Value: 2 +// CHECK-NEXT: TagName: ABI_enum_size +// CHECK-NEXT: Description: Int32 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 34 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: CPU_unaligned_access +// CHECK-NEXT: Description: v6-style +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 38 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_FP_16bit_format +// CHECK-NEXT: Description: IEEE-754 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 68 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: Virtualization_use +// CHECK-NEXT: Description: TrustZone +// CHECK-NEXT: } diff --git a/test/ELF/arm-blx.s b/test/ELF/arm-blx.s index cccb1324fc8b0..159eee51c74c7 100644 --- a/test/ELF/arm-blx.s +++ b/test/ELF/arm-blx.s @@ -1,6 +1,7 @@ // 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 { \ +// RUN: . = 0xb4; \ // RUN: .callee1 : { *(.callee_low) } \ // RUN: .callee2 : { *(.callee_arm_low) } \ // RUN: .caller : { *(.text) } \ diff --git a/test/ELF/arm-branch.s b/test/ELF/arm-branch.s index 38266fabf852e..986863d3d80ce 100644 --- a/test/ELF/arm-branch.s +++ b/test/ELF/arm-branch.s @@ -1,6 +1,7 @@ // 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 { \ +// RUN: . = 0xb4; \ // RUN: .callee1 : { *(.callee_low) } \ // RUN: .caller : { *(.text) } \ // RUN: .callee2 : { *(.callee_high) } } " > %t.script diff --git a/test/ELF/arm-data-prel.s b/test/ELF/arm-data-prel.s index 590d8118ae6e8..a8c0c280b220d 100644 --- a/test/ELF/arm-data-prel.s +++ b/test/ELF/arm-data-prel.s @@ -1,8 +1,8 @@ // RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o %t.o // RUN: echo "SECTIONS { \ // RUN: .text : { *(.text) } \ -// RUN: .ARM.exidx : { *(.ARM.exidx) } \ -// RUN: .ARM.exidx.TEST1 : { *(.ARM.exidx.TEST1) } \ +// RUN: .prel.test : { *(.ARM.exidx) } \ +// RUN: .prel.test.TEST1 : { *(.ARM.exidx.TEST1) } \ // 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 @@ -47,7 +47,7 @@ __aeabi_unwind_cpp_pr0: // The expected value of the exception table is // Word0 0 in bit 31, -4 encoded in 31-bit signed offset // Word1 Inline table entry EHT Inline Personality Routine #0 -// CHECK: Name: .ARM.exidx +// CHECK: Name: .prel.test // CHECK: SectionData ( // CHECK: 0000: FCFFFF7F B0B0B080 // CHECK: ) @@ -57,7 +57,7 @@ __aeabi_unwind_cpp_pr0: // Word1 Inline table entry EHT Inline Personality Routine #0 // set vsp = r11 // pop r11, r14 -// CHECK: Name: .ARM.exidx.TEST1 +// CHECK: Name: .prel.test.TEST1 // CHECK: SectionData ( // CHECK: 0000: 08000000 80849B80 // CHECK: ) diff --git a/test/ELF/arm-eabi-version.s b/test/ELF/arm-eabi-version.s new file mode 100644 index 0000000000000..727b805fddd7e --- /dev/null +++ b/test/ELF/arm-eabi-version.s @@ -0,0 +1,14 @@ +// 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 +_start: + bx lr + +// CHECK: Flags [ +// CHECK-NEXT: 0x1000000 +// CHECK-NEXT: 0x4000000 +// CHECK-NEXT: ] diff --git a/test/ELF/arm-exidx-canunwind.s b/test/ELF/arm-exidx-canunwind.s new file mode 100644 index 0000000000000..e98ec0ec8978a --- /dev/null +++ b/test/ELF/arm-exidx-canunwind.s @@ -0,0 +1,99 @@ +// 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 + + .syntax unified + // Will produce an ARM.exidx entry with inline unwinding instructions + .section .text.func1, "ax",%progbits + .global func1 +func1: + .fnstart + bx lr + .save {r7, lr} + .setfp r7, sp, #0 + .fnend + + // Unwinding instructions for .text2 too large for an inline entry ARM.exidx + // entry. A separate .ARM.extab section is created to hold the unwind entries + // The .ARM.exidx table entry has a reference to the .ARM.extab section. + .section .text.func2, "ax",%progbits + .global func2 +func2: + .fnstart + bx lr + .personality __gxx_personality_v0 + .handlerdata + .long 0 + .section .text.func2 + .fnend + + // Dummy implementation of personality routines to satisfy reference from + // exception tables + .section .text.__gcc_personality_v0, "ax", %progbits + .global __gxx_personality_v0 +__gxx_personality_v0: + bx lr + + .section .text.__aeabi_unwind_cpp_pr0, "ax", %progbits + .global __aeabi_unwind_cpp_pr0 +__aeabi_unwind_cpp_pr0: + bx lr + + .text + .global _start +_start: + bl func1 + bl func2 + bx lr + +// CHECK: Disassembly of section .text: +// CHECK-NEXT: _start: +// CHECK-NEXT: 11000: 01 00 00 eb bl #4 <func1> +// CHECK-NEXT: 11004: 01 00 00 eb bl #4 <func2> +// CHECK-NEXT: 11008: 1e ff 2f e1 bx lr +// CHECK: func1: +// CHECK-NEXT: 1100c: 1e ff 2f e1 bx lr +// CHECK: func2: +// CHECK-NEXT: 11010: 1e ff 2f e1 bx lr +// CHECK: __gxx_personality_v0: +// CHECK-NEXT: 11014: 1e ff 2f e1 bx lr +// CHECK: __aeabi_unwind_cpp_pr0: +// CHECK-NEXT: 11018: 1e ff 2f e1 bx lr + +// CHECK-EXIDX: Contents of section .ARM.exidx: +// 100d4 + f38 = 1100c = func1 (inline unwinding data) +// 100dc + f34 = 11010 = func2 (100e0 + c = 100ec = .ARM.extab entry) +// CHECK-EXIDX-NEXT: 100d4 380f0000 08849780 340f0000 0c000000 +// 100e4 + f30 = 11014 = terminate = func2 + sizeof(func2) +// CHECK-EXIDX-NEXT: 100e4 300f0000 01000000 +// CHECK-EXIDX-NEXT: Contents of section .ARM.extab.text.func2: +// 100ec + f28 = 11014 = __gxx_personality_v0 +// CHECK-EXIDX-NEXT: 100ec 280f0000 b0b0b000 00000000 + +// CHECK-PT: Name: .ARM.exidx +// CHECK-PT-NEXT: Type: SHT_ARM_EXIDX (0x70000001) +// CHECK-PT-NEXT: Flags [ +// CHECK-PT-NEXT: SHF_ALLOC +// CHECK-PT-NEXT: SHF_LINK_ORDER +// CHECK-PT-NEXT: ] +// CHECK-PT-NEXT: Address: 0x100D4 +// CHECK-PT-NEXT: Offset: 0xD4 +// CHECK-PT-NEXT: Size: 24 + +// CHECK-PT: Type: PT_ARM_EXIDX (0x70000001) +// CHECK-PT-NEXT: Offset: 0xD4 +// CHECK-PT-NEXT: VirtualAddress: 0x100D4 +// CHECK-PT-NEXT: PhysicalAddress: 0x100D4 +// CHECK-PT-NEXT: FileSize: 24 +// CHECK-PT-NEXT: MemSize: 24 +// CHECK-PT-NEXT: Flags [ (0x4) +// CHECK-PT-NEXT: PF_R (0x4) +// CHECK-PT-NEXT: ] +// CHECK-PT-NEXT: Alignment: 4 +// CHECK-PT-NEXT: } diff --git a/test/ELF/arm-exidx-gc.s b/test/ELF/arm-exidx-gc.s new file mode 100644 index 0000000000000..b1a5be54aa2b0 --- /dev/null +++ b/test/ELF/arm-exidx-gc.s @@ -0,0 +1,125 @@ +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t +// RUN: ld.lld %t -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 +// section. +// A .ARM.exidx section may have a relocation to a .ARM.extab section, if the +// .ARM.exidx is live then the .ARM.extab section is live + + .syntax unified + .section .text.func1, "ax",%progbits + .global func1 +func1: + .fnstart + bx lr + .save {r7, lr} + .setfp r7, sp, #0 + .fnend + + .section .text.unusedfunc1, "ax",%progbits + .global unusedfunc1 +unusedfunc1: + .fnstart + bx lr + .cantunwind + .fnend + + // Unwinding instructions for .text2 too large for an inline entry ARM.exidx + // entry. A separate .ARM.extab section is created to hold the unwind entries + // The .ARM.exidx table entry has a reference to the .ARM.extab section. + .section .text.func2, "ax",%progbits + .global func2 +func2: + .fnstart + bx lr + .personality __gxx_personality_v0 + .handlerdata + .section .text.func2 + .fnend + + // An unused function with a reference to a .ARM.extab section. Both should + // be removed by gc. + .section .text.unusedfunc2, "ax",%progbits + .global unusedfunc2 +unusedfunc2: + .fnstart + bx lr + .personality __gxx_personality_v1 + .handlerdata + .section .text.unusedfunc2 + .fnend + + // Dummy implementation of personality routines to satisfy reference from + // exception tables + .section .text.__gcc_personality_v0, "ax", %progbits + .global __gxx_personality_v0 +__gxx_personality_v0: + .fnstart + bx lr + .cantunwind + .fnend + + .section .text.__gcc_personality_v1, "ax", %progbits + .global __gxx_personality_v1 +__gxx_personality_v1: + .fnstart + bx lr + .cantunwind + .fnend + + .section .text.__aeabi_unwind_cpp_pr0, "ax", %progbits + .global __aeabi_unwind_cpp_pr0 +__aeabi_unwind_cpp_pr0: + .fnstart + bx lr + .cantunwind + .fnend + +// Entry point for GC + .text + .global _start +_start: + bl func1 + bl func2 + bx lr + +// GC should have only removed unusedfunc1 and unusedfunc2 the personality +// routines are kept alive by references from live .ARM.exidx and .ARM.extab +// sections +// CHECK: Disassembly of section .text: +// CHECK-NEXT: _start: +// CHECK-NEXT: 11000: 01 00 00 eb bl #4 <func1> +// CHECK-NEXT: 11004: 01 00 00 eb bl #4 <func2> +// CHECK-NEXT: 11008: 1e ff 2f e1 bx lr +// CHECK: func1: +// CHECK-NEXT: 1100c: 1e ff 2f e1 bx lr +// CHECK: func2: +// CHECK-NEXT: 11010: 1e ff 2f e1 bx lr +// CHECK: __gxx_personality_v0: +// CHECK-NEXT: 11014: 1e ff 2f e1 bx lr +// CHECK: __aeabi_unwind_cpp_pr0: +// CHECK-NEXT: 11018: 1e ff 2f e1 bx lr + +// GC should have removed table entries for unusedfunc1, unusedfunc2 +// and __gxx_personality_v1 +// CHECK-NOT: unusedfunc1 +// CHECK-NOT: unusedfunc2 +// CHECK-NOT: __gxx_personality_v1 + +// CHECK-EXIDX-NOT: Contents of section .ARM.extab.text.unusedfunc2: +// CHECK-EXIDX: Contents of section .ARM.exidx: +// 100d4 + f38 = 1100c = func1 +// 100dc + f34 = 11010 = func2 (100e0 + 1c = 100fc = .ARM.extab.text.func2) +// CHECK-EXIDX-NEXT: 100d4 380f0000 08849780 340f0000 1c000000 +// 100e4 + f30 = 11014 = __gxx_personality_v0 +// 100ec + f2c = 11018 = __aeabi_unwind_cpp_pr0 +// CHECK-EXIDX-NEXT: 100e4 300f0000 01000000 2c0f0000 01000000 +// 100f4 + f28 = 1101c = __aeabi_unwind_cpp_pr0 + sizeof(__aeabi_unwind_cpp_pr0) +// CHECK-EXIDX-NEXT: 100f4 280f0000 01000000 +// CHECK-EXIDX-NEXT: Contents of section .ARM.extab.text.func2: +// 100fc + f18 = 11014 = __gxx_personality_v0 +// CHECK-EXIDX-NEXT: 100fc 180f0000 b0b0b000 diff --git a/test/ELF/arm-exidx-link.s b/test/ELF/arm-exidx-link.s new file mode 100644 index 0000000000000..50f981261d9de --- /dev/null +++ b/test/ELF/arm-exidx-link.s @@ -0,0 +1,25 @@ +// REQUIRES: arm +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-readobj -s %t.so | FileCheck %s + +// CHECK: Name: .ARM.exidx +// CHECK-NEXT: Type: SHT_ARM_EXIDX +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: SHF_LINK_ORDER +// CHECK-NEXT: ] +// CHECK-NEXT: Address: +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: +// CHECK-NEXT: Link: [[INDEX:.*]] + +// CHECK: Index: [[INDEX]] +// CHECK-NEXT: Name: .text + + + f: + .fnstart + bx lr + .cantunwind + .fnend diff --git a/test/ELF/arm-exidx-order.s b/test/ELF/arm-exidx-order.s new file mode 100644 index 0000000000000..951c71a4c33e1 --- /dev/null +++ b/test/ELF/arm-exidx-order.s @@ -0,0 +1,169 @@ +// 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 %t %tcantunwind -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 +// Use Linker script to place .ARM.exidx in between .text and orphan sections +// RUN: echo "SECTIONS { \ +// RUN: .text 0x11000 : { *(.text*) } \ +// RUN: .ARM.exidx : { *(.ARM.exidx) } } " > %t.script +// RUN: ld.lld --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 +// containing the function it describes. The linker must combine the .ARM.exidx +// InputSections in the same order that it has combined the executable section, +// such that the combined .ARM.exidx OutputSection can be used as a binary +// search table. + + .syntax unified + .section .text, "ax",%progbits + .globl _start +_start: + .fnstart + bx lr + .cantunwind + .fnend + + .section .text.f1, "ax", %progbits + .globl f1 +f1: + .fnstart + bx lr + .cantunwind + .fnend + + .section .text.f2, "ax", %progbits + .globl f2 +f2: + .fnstart + bx lr + .cantunwind + .fnend + .globl f3 +f3: + .fnstart + bx lr + .cantunwind + .fnend + +// Check default no linker script order. + +// CHECK: Disassembly of section .text: +// CHECK: _start: +// CHECK-NEXT: 11000: 1e ff 2f e1 bx lr +// CHECK: f1: +// CHECK-NEXT: 11004: 1e ff 2f e1 bx lr +// CHECK: f2: +// CHECK-NEXT: 11008: 1e ff 2f e1 bx lr +// CHECK: f3: +// CHECK-NEXT: 1100c: 1e ff 2f e1 bx lr +// CHECK: func4: +// CHECK-NEXT: 11010: 1e ff 2f e1 bx lr +// CHECK: func5: +// CHECK-NEXT: 11014: 1e ff 2f e1 bx lr +// CHECK: Disassembly of section .func1: +// CHECK-NEXT: func1: +// CHECK-NEXT: 11018: 1e ff 2f e1 bx lr +// CHECK: Disassembly of section .func2: +// CHECK-NEXT: func2: +// CHECK-NEXT: 1101c: 1e ff 2f e1 bx lr +// CHECK: Disassembly of section .func3: +// CHECK-NEXT: func3: +// CHECK-NEXT: 11020: 1e ff 2f e1 bx lr + +// Each .ARM.exidx section has two 4 byte fields +// Field 1 is the 31-bit offset to the function. The top bit is used to +// indicate whether Field 2 is a pointer or an inline table entry. +// Field 2 is either a pointer to a .ARM.extab section or an inline table +// In this example all Field 2 entries are inline can't unwind (0x1) +// We expect to see the entries in the same order as the functions + +// CHECK-EXIDX: Contents of section .ARM.exidx: +// 100d4 + f2c = 11000 = _start +// 100dc + f28 = 11004 = f1 +// CHECK-EXIDX-NEXT: 100d4 2c0f0000 01000000 280f0000 01000000 +// 100e4 + f24 = 11008 = f2 +// 100ec + f20 = 1100c = f3 +// CHECK-EXIDX-NEXT: 100e4 240f0000 01000000 200f0000 01000000 +// 100f4 + f1c = 11010 = func4 +// 100fc + f18 = 11014 = func5 +// CHECK-EXIDX-NEXT: 100f4 1c0f0000 01000000 180f0000 01000000 +// 10104 + f14 = 11018 = func1 +// 1010c + f10 = 1101c = func2 +// CHECK-EXIDX-NEXT: 10104 140f0000 01000000 100f0000 01000000 +// 10114 + f0c = 11020 = func3 +// CHECK-EXIDX-NEXT: 10114 0c0f0000 01000000 + +// Check that PT_ARM_EXIDX program header has been generated that describes +// the .ARM.exidx output section +// CHECK-PT: Name: .ARM.exidx +// CHECK-PT-NEXT: Type: SHT_ARM_EXIDX (0x70000001) +// CHECK-PT-NEXT: Flags [ +// CHECK-PT-NEXT: SHF_ALLOC +// CHECK-PT-NEXT: SHF_LINK_ORDER +// CHECK-PT-NEXT: ] +// CHECK-PT-NEXT: Address: 0x100D4 +// CHECK-PT-NEXT: Offset: 0xD4 +// CHECK-PT-NEXT: Size: 80 + +// CHECK-PT: Type: PT_ARM_EXIDX (0x70000001) +// CHECK-PT-NEXT: Offset: 0xD4 +// CHECK-PT-NEXT: VirtualAddress: 0x100D4 +// CHECK-PT-NEXT: PhysicalAddress: 0x100D4 +// CHECK-PT-NEXT: FileSize: 80 +// CHECK-PT-NEXT: MemSize: 80 +// CHECK-PT-NEXT: Flags [ (0x4) +// CHECK-PT-NEXT: PF_R (0x4) +// CHECK-PT-NEXT: ] +// CHECK-PT-NEXT: Alignment: 4 +// CHECK-PT-NEXT: } + + +// Check linker script order. The .ARM.exidx section will be inserted after +// the .text section but before the orphan sections + +// CHECK-SCRIPT: Disassembly of section .text: +// CHECK-SCRIPT-NEXT: func4: +// CHECK-SCRIPT-NEXT: 11000: 1e ff 2f e1 bx lr +// CHECK-SCRIPT: func5: +// CHECK-SCRIPT-NEXT: 11004: 1e ff 2f e1 bx lr +// CHECK-SCRIPT: _start: +// CHECK-SCRIPT-NEXT: 11008: 1e ff 2f e1 bx lr +// CHECK-SCRIPT: f1: +// CHECK-SCRIPT-NEXT: 1100c: 1e ff 2f e1 bx lr +// CHECK-SCRIPT: f2: +// CHECK-SCRIPT-NEXT: 11010: 1e ff 2f e1 bx lr +// CHECK-SCRIPT: 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: Disassembly of section .func2: +// CHECK-SCRIPT-NEXT: func2: +// CHECK-SCRIPT-NEXT: 1106c: 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 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 diff --git a/test/ELF/arm-exidx-output.s b/test/ELF/arm-exidx-output.s new file mode 100644 index 0000000000000..dca43a359934f --- /dev/null +++ b/test/ELF/arm-exidx-output.s @@ -0,0 +1,44 @@ +// 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 +// assembler creates the .ARM.exidx input sections with the .cantunwind +// directive + .syntax unified + .section .text, "ax",%progbits + .globl _start +_start: + .fnstart + bx lr + .cantunwind + .fnend + + .section .text.f1, "ax", %progbits + .globl f1 +f1: + .fnstart + bx lr + .cantunwind + .fnend + + .section .text.f2, "ax", %progbits + .globl f2 +f2: + .fnstart + bx lr + .cantunwind + .fnend + +// CHECK: Section { +// CHECK: Name: .ARM.exidx +// CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: SHF_LINK_ORDER +// CHECK-NEXT: ] + +// CHECK-NOT: Name: .ARM.exidx.text.f1 +// CHECK-NOT: Name: .ARM.exidx.text.f2 diff --git a/test/ELF/arm-exidx-relocatable.s b/test/ELF/arm-exidx-relocatable.s new file mode 100644 index 0000000000000..1b6ee3f23a4f7 --- /dev/null +++ b/test/ELF/arm-exidx-relocatable.s @@ -0,0 +1,132 @@ +// 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 +// containing the function it describes. To maintain this property in +// relocatable links we pass through the .ARM.exidx section, the section it +// it has a sh_link to, and the associated relocation sections uncombined. + + .syntax unified + .section .text, "ax",%progbits + .globl _start +_start: + .fnstart + bx lr + .cantunwind + .fnend + + .section .text.f1, "ax", %progbits + .globl f1 +f1: + .fnstart + bx lr + .cantunwind + .fnend + + .section .text.f2, "ax", %progbits + .globl f2 +f2: + .fnstart + bx lr + .cantunwind + .fnend + .globl f3 +f3: + .fnstart + bx lr + .cantunwind + .fnend + +// CHECK: Index: 1 +// CHECK-NEXT: Name: .text + +// CHECK: Name: .ARM.exidx +// CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) +// CHECK-NEXT: Flags [ (0x82) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: ] +// CHECK-NEXT: Address +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: 24 +// CHECK-NEXT: Link: 1 + + +// CHECK: Index: 4 +// CHECK-NEXT: Name: .text.f1 + +// CHECK: Name: .ARM.exidx.text.f1 +// CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) +// CHECK-NEXT: Flags [ (0x82) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: ] +// CHECK-NEXT: Address +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: 8 +// CHECK-NEXT: Link: 4 + + +// CHECK: Index: 7 +// CHECK-NEXT: Name: .text.f2 + +// CHECK: Name: .ARM.exidx.text.f2 +// CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) +// CHECK-NEXT: Flags [ (0x82) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: ] +// CHECK-NEXT: Address +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: 16 +// CHECK-NEXT: Link: 7 + + +// CHECK: Index: 10 +// CHECK-NEXT: Name: .func1 + +// CHECK: Name: .ARM.exidx.func1 +// CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) +// CHECK-NEXT: Flags [ (0x82) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: ] +// CHECK-NEXT: Address +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: 8 +// CHECK-NEXT: Link: 10 + + +// CHECK: Index: 13 +// CHECK-NEXT: Name: .func2 + +// CHECK: Name: .ARM.exidx.func2 +// CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) +// CHECK-NEXT: Flags [ (0x82) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: ] +// CHECK-NEXT: Address +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: 8 +// CHECK-NEXT: Link: 13 + + +// CHECK: Index: 16 +// CHECK-NEXT: Name: .func3 + +// CHECK: Name: .ARM.exidx.func3 +// CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) +// CHECK-NEXT: Flags [ (0x82) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: ] +// CHECK-NEXT: Address +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: 8 +// CHECK-NEXT: Link: 16 diff --git a/test/ELF/arm-exidx-sentinel-norelocatable.s b/test/ELF/arm-exidx-sentinel-norelocatable.s new file mode 100644 index 0000000000000..4a5b64d8cd185 --- /dev/null +++ b/test/ELF/arm-exidx-sentinel-norelocatable.s @@ -0,0 +1,17 @@ +// 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 + .syntax unified + .text +_start: + .fnstart + .cantunwind + bx lr + .fnend + +// Expect 1 table entry of size 8 +// CHECK: Name: .ARM.exidx +// CHECK: Size: 8 diff --git a/test/ELF/arm-exidx-sentinel-orphan.s b/test/ELF/arm-exidx-sentinel-orphan.s new file mode 100644 index 0000000000000..c054fe940db61 --- /dev/null +++ b/test/ELF/arm-exidx-sentinel-orphan.s @@ -0,0 +1,23 @@ +// 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 +// RUN: echo "SECTIONS { \ +// RUN: .text 0x11000 : { *(.text*) } \ +// RUN: } " > %t.script +// RUN: ld.lld --script %t.script %t -o %t2 +// RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s +// REQUIRES: arm + + .syntax unified + .text + .global _start +_start: + .fnstart + .cantunwind + bx lr + .fnend + +// CHECK: Contents of section .ARM.exidx: +// 11004 - 4 = 0x11000 = _start +// 1100c - 8 = 0x11004 = _start + sizeof(_start) +// CHECK-NEXT: 11004 fcffff7f 01000000 f8ffff7f 01000000 diff --git a/test/ELF/arm-exidx-shared.s b/test/ELF/arm-exidx-shared.s new file mode 100644 index 0000000000000..86b2d1fe00d82 --- /dev/null +++ b/test/ELF/arm-exidx-shared.s @@ -0,0 +1,45 @@ +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t +// RUN: ld.lld %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. +// Also check that the R_ARM_NONE no-op relocation can be used in a shared +// library. + .syntax unified +// Will produce an ARM.exidx entry with an R_ARM_NONE relocation to +// __aeabi_unwind_cpp_pr0 + .section .text.func1, "ax",%progbits + .global func1 +func1: + .fnstart + bx lr + .fnend + +// Will produce a R_ARM_PREL31 relocation with respect to the PLT entry of +// __gxx_personality_v0 + .section .text.func2, "ax",%progbits + .global func2 +func2: + .fnstart + bx lr + .personality __gxx_personality_v0 + .handlerdata + .long 0 + .section .text.func2 + .fnend + + .section .text.__aeabi_unwind_cpp_pr0, "ax", %progbits + .global __aeabi_unwind_cpp_pr0 +__aeabi_unwind_cpp_pr0: + bx lr + +// CHECK: Relocations [ +// CHECK-NEXT: Section (6) .rel.plt { +// CHECK-NEXT: 0x300C R_ARM_JUMP_SLOT __gxx_personality_v0 + +// CHECK-EXTAB: Contents of section .ARM.extab.text.func2: +// 014c + 0ed8 = 0x1024 = __gxx_personality_v0(PLT) +// CHECK-EXTAB-NEXT: 014c d80e0000 b0b0b000 00000000 diff --git a/test/ELF/arm-gnu-ifunc-plt.s b/test/ELF/arm-gnu-ifunc-plt.s new file mode 100644 index 0000000000000..30ef66a3b7758 --- /dev/null +++ b/test/ELF/arm-gnu-ifunc-plt.s @@ -0,0 +1,93 @@ +// 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 +// RUN: ld.lld %t.so %t.o -o %tout +// 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 [ +// CHECK-NEXT: Section (4) .rel.dyn { +// CHECK-NEXT: 0x12078 R_ARM_GLOB_DAT bar2 0x0 +// CHECK-NEXT: 0x1207C R_ARM_GLOB_DAT zed2 0x0 +// CHECK-NEXT: 0x12080 R_ARM_IRELATIVE - 0x0 +// CHECK-NEXT: 0x12084 R_ARM_IRELATIVE - 0x0 +// CHECK-NEXT: } +// CHECK-NEXT: Section (5) .rel.plt { +// CHECK-NEXT: 0x1300C R_ARM_JUMP_SLOT bar2 0x0 +// CHECK-NEXT: 0x13010 R_ARM_JUMP_SLOT zed2 0x0 +// CHECK-NEXT: } +// CHECK-NEXT: ] + +// Check that the GOT entries refer back to the ifunc resolver +// GOTPLT: Contents of section .got: +// GOTPLT-NEXT: 12078 00000000 00000000 00100100 04100100 +// GOTPLT-NEXT: Contents of section .got.plt: +// GOTPLT-NEXT: 13000 00000000 00000000 00000000 20100100 +// GOTPLT-NEXT: 13010 20100100 + +// DISASM: Disassembly of section .text: +// DISASM-NEXT: foo: +// DISASM-NEXT: 11000: 1e ff 2f e1 bx lr +// DISASM: bar: +// DISASM-NEXT: 11004: 1e ff 2f e1 bx lr +// DISASM: _start: +// DISASM-NEXT: 11008: 14 00 00 eb bl #80 +// DISASM-NEXT: 1100c: 17 00 00 eb bl #92 +// DISASM: 11010: 00 00 00 00 .word 0x00000000 +// DISASM-NEXT: 11014: 04 00 00 00 .word 0x00000004 +// DISASM: 11018: 05 00 00 eb bl #20 +// DISASM-NEXT: 1101c: 08 00 00 eb bl #32 +// DISASM-NEXT: Disassembly of section .plt: +// DISASM-NEXT: .plt: +// DISASM-NEXT: 11020: 04 e0 2d e5 str lr, [sp, #-4]! +// DISASM-NEXT: 11024: 04 e0 9f e5 ldr lr, [pc, #4] +// DISASM-NEXT: 11028: 0e e0 8f e0 add lr, pc, lr +// DISASM-NEXT: 1102c: 08 f0 be e5 ldr pc, [lr, #8]! +// DISASM-NEXT: 11030: d0 1f 00 00 +// DISASM-NEXT: 11034: 04 c0 9f e5 ldr r12, [pc, #4] +// DISASM-NEXT: 11038: 0f c0 8c e0 add r12, r12, pc +// DISASM-NEXT: 1103c: 00 f0 9c e5 ldr pc, [r12] +// DISASM-NEXT: 11040: cc 1f 00 00 +// DISASM-NEXT: 11044: 04 c0 9f e5 ldr r12, [pc, #4] +// DISASM-NEXT: 11048: 0f c0 8c e0 add r12, r12, pc +// DISASM-NEXT: 1104c: 00 f0 9c e5 ldr pc, [r12] +// DISASM-NEXT: 11050: c0 1f 00 00 +// Alignment to 16 byte boundary not strictly necessary on ARM, but harmless +// DISASM-NEXT: 11054: 00 00 00 00 andeq r0, r0, r0 +// DISASM-NEXT: 11058: 00 00 00 00 andeq r0, r0, r0 +// DISASM-NEXT: 1105c: 00 00 00 00 andeq r0, r0, r0 +// DISASM-NEXT: 11060: 04 c0 9f e5 ldr r12, [pc, #4] +// DISASM-NEXT: 11064: 0f c0 8c e0 add r12, r12, pc +// DISASM-NEXT: 11068: 00 f0 9c e5 ldr pc, [r12] +// DISASM-NEXT: 1106c: 14 10 00 00 +// DISASM-NEXT: 11070: 04 c0 9f e5 ldr r12, [pc, #4] +// DISASM-NEXT: 11074: 0f c0 8c e0 add r12, r12, pc +// DISASM-NEXT: 11078: 00 f0 9c e5 ldr pc, [r12] +// DISASM-NEXT: 1107c: 08 10 00 00 + + +.syntax unified +.text +.type foo STT_GNU_IFUNC +.globl foo +foo: + bx lr + +.type bar STT_GNU_IFUNC +.globl bar +bar: + bx lr + +.globl _start +_start: + bl foo + bl bar + // Create entries in the .got and .rel.dyn so that we don't just have + // IRELATIVE + .word bar2(got) + .word zed2(got) + bl bar2 + bl zed2 diff --git a/test/ELF/arm-gnu-ifunc.s b/test/ELF/arm-gnu-ifunc.s index c1e8a71835301..214a8824787c2 100644 --- a/test/ELF/arm-gnu-ifunc.s +++ b/test/ELF/arm-gnu-ifunc.s @@ -24,53 +24,65 @@ _start: movw r0,:lower16:__rel_iplt_end movt r0,:upper16:__rel_iplt_end -// CHECK: Sections [ -// CHECK: Section { -// CHECK: Index: 1 -// CHECK-NEXT: Name: .rel.plt -// CHECK-NEXT: Type: SHT_REL -// CHECK-NEXT: Flags [ -// CHECK-NEXT: SHF_ALLOC -// CHECK-NEXT: ] -// CHECK-NEXT: Address: [[REL:.*]] -// CHECK-NEXT: Offset: -// CHECK-NEXT: Size: 16 -// CHECK-NEXT: Link: -// CHECK-NEXT: Info: -// CHECK-NEXT: AddressAlignment: 4 -// CHECK-NEXT: EntrySize: 8 -// CHECK-NEXT: } -// CHECK: Relocations [ -// CHECK-NEXT: Section (1) .rel.plt { -// CHECK-NEXT: 0x1200C R_ARM_IRELATIVE -// CHECK-NEXT: 0x12010 R_ARM_IRELATIVE -// CHECK-NEXT: } -// CHECK-NEXT:] -// CHECK: Symbols [ -// CHECK: Symbol { -// CHECK: Name: __rel_iplt_end -// CHECK-NEXT: Value: 0x100E4 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: None -// CHECK-NEXT: Other [ -// CHECK-NEXT: STV_HIDDEN -// CHECK-NEXT: ] -// CHECK-NEXT: Section: .rel.plt -// CHECK-NEXT: } -// CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: __rel_iplt_start -// CHECK-NEXT: Value: 0x100D4 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Local -// CHECK-NEXT: Type: None -// CHECK-NEXT: Other [ -// CHECK-NEXT: STV_HIDDEN -// CHECK-NEXT: ] -// CHECK-NEXT: Section: .rel.plt -// CHECK-NEXT: } +// CHECK: Sections [ +// CHECK: Section { +// CHECK: Section { +// CHECK: Name: .rel.dyn +// CHECK-NEXT: Type: SHT_REL +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x100F4 +// CHECK-NEXT: Offset: 0xF4 +// CHECK-NEXT: Size: 16 +// CHECK: Name: .plt +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: SHF_EXECINSTR +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x11020 +// CHECK-NEXT: Offset: 0x1020 +// CHECK-NEXT: Size: 32 +// CHECK: Name: .got +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: SHF_WRITE +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x12000 +// CHECK-NEXT: Offset: 0x2000 +// CHECK-NEXT: Size: 8 +// CHECK: Relocations [ +// CHECK-NEXT: Section (1) .rel.dyn { +// CHECK-NEXT: 0x12000 R_ARM_IRELATIVE +// CHECK-NEXT: 0x12004 R_ARM_IRELATIVE +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK: Symbol { +// CHECK: Name: __rel_iplt_end (6) +// CHECK-NEXT: Value: 0x10104 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Local +// CHECK-NEXT: Type: None +// CHECK-NEXT: Other [ +// CHECK-NEXT: STV_HIDDEN +// CHECK-NEXT: ] +// CHECK-NEXT: Section: .rel.dyn +// CHECK-NEXT: } +// CHECK-NEXT: Symbol { +// CHECK-NEXT: Name: __rel_iplt_start +// CHECK-NEXT: Value: 0x100F4 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Local +// CHECK-NEXT: Type: None +// CHECK-NEXT: Other [ +// CHECK-NEXT: STV_HIDDEN +// CHECK-NEXT: ] +// CHECK-NEXT: Section: .rel.dyn +// CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: _start (6) +// CHECK-NEXT: Name: _start // CHECK-NEXT: Value: 0x11008 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global @@ -97,35 +109,29 @@ _start: // CHECK-NEXT: Section: .text // CHECK-NEXT: } -// DISASM: Disassembly of section .text: +// DISASM: Disassembly of section .text: // DISASM-NEXT: foo: -// DISASM-NEXT: 11000: 1e ff 2f e1 bx lr -// DISASM: bar: -// DISASM-NEXT: 11004: 1e ff 2f e1 bx lr -// DISASM: _start: -// DISASM-NEXT: 11008: 09 00 00 eb bl #36 -// DISASM-NEXT: 1100c: 0c 00 00 eb bl #48 -// DISASM-NEXT: 11010: d4 00 00 e3 movw r0, #212 -// DISASM-NEXT: 11014: 01 00 40 e3 movt r0, #1 -// r0 = 212 + 1 * 65536 = 100D4 = __rel_iplt_start -// DISASM-NEXT: 11018: e4 00 00 e3 movw r0, #228 -// DISASM-NEXT: 1101c: 01 00 40 e3 movt r0, #1 -// r1 = 228 + 1 * 65536 = 100E4 = __rel_iplt_end +// DISASM-NEXT: 11000: 1e ff 2f e1 bx lr +// DISASM: bar: +// DISASM-NEXT: 11004: 1e ff 2f e1 bx lr +// DISASM: _start: +// DISASM-NEXT: 11008: 04 00 00 eb bl #16 +// DISASM-NEXT: 1100c: 07 00 00 eb bl #28 +// 1 * 65536 + 244 = 0x100f4 __rel_iplt_start +// DISASM-NEXT: 11010: f4 00 00 e3 movw r0, #244 +// DISASM-NEXT: 11014: 01 00 40 e3 movt r0, #1 +// 1 * 65536 + 260 = 0x10104 __rel_iplt_end +// DISASM-NEXT: 11018: 04 01 00 e3 movw r0, #260 +// DISASM-NEXT: 1101c: 01 00 40 e3 movt r0, #1 // DISASM-NEXT: Disassembly of section .plt: // DISASM-NEXT: .plt: -// DISASM-NEXT: 11020: 04 e0 2d e5 str lr, [sp, #-4]! -// DISASM-NEXT: 11024: 04 e0 9f e5 ldr lr, [pc, #4] -// DISASM-NEXT: 11028: 0e e0 8f e0 add lr, pc, lr -// DISASM-NEXT: 1102c: 08 f0 be e5 ldr pc, [lr, #8]! -// 0x0fd0 + 0x11028 + 0x8 = 0x12000 -// DISASM-NEXT: 11030: d0 0f 00 00 -// DISASM-NEXT: 11034: 04 c0 9f e5 ldr r12, [pc, #4] -// DISASM-NEXT: 11038: 0f c0 8c e0 add r12, r12, pc -// DISASM-NEXT: 1103c: 00 f0 9c e5 ldr pc, [r12] -// 0x0fcc + 0x11038 + 0x8 = 0x1200C -// DISASM-NEXT: 11040: cc 0f 00 00 -// DISASM-NEXT: 11044: 04 c0 9f e5 ldr r12, [pc, #4] -// DISASM-NEXT: 11048: 0f c0 8c e0 add r12, r12, pc -// DISASM-NEXT: 1104c: 00 f0 9c e5 ldr pc, [r12] -// 0x0fc0 + 0x11048 + 0x8 = 0x12010 -// DISASM-NEXT: 11050: c0 0f 00 00 +// DISASM-NEXT: 11020: 04 c0 9f e5 ldr r12, [pc, #4] +// DISASM-NEXT: 11024: 0f c0 8c e0 add r12, r12, pc +// 11024 + 8 + fd4 = 0x12000 +// DISASM-NEXT: 11028: 00 f0 9c e5 ldr pc, [r12] +// DISASM-NEXT: 1102c: d4 0f 00 00 +// DISASM-NEXT: 11030: 04 c0 9f e5 ldr r12, [pc, #4] +// DISASM-NEXT: 11034: 0f c0 8c e0 add r12, r12, pc +// 11034 + 8 + fc8 = 0x12004 +// DISASM-NEXT: 11038: 00 f0 9c e5 ldr pc, [r12] +// DISASM-NEXT: 1103c: c8 0f 00 00 diff --git a/test/ELF/arm-got-relative.s b/test/ELF/arm-got-relative.s index 22ccb16a2a58d..db76711fe68e9 100644 --- a/test/ELF/arm-got-relative.s +++ b/test/ELF/arm-got-relative.s @@ -30,7 +30,7 @@ function: // CHECK: Dynamic Relocations { // CHECK-NEXT: 0x204C R_ARM_GLOB_DAT function 0x0 -// CHECK: Name: _GLOBAL_OFFSET_TABLE_ (16) +// CHECK: Name: _GLOBAL_OFFSET_TABLE_ // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: // CHECK-NEXT: Binding: Local diff --git a/test/ELF/arm-pie-relative.s b/test/ELF/arm-pie-relative.s new file mode 100644 index 0000000000000..223fcca08a2c1 --- /dev/null +++ b/test/ELF/arm-pie-relative.s @@ -0,0 +1,25 @@ +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t +// RUN: ld.lld %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 + .syntax unified + .text + .global _start +_start: + .word sym(GOT) + + .data + .global sym +sym: + .word 0 + +// CHECK: Relocations [ +// CHECK-NEXT: Section (4) .rel.dyn { +// CHECK-NEXT: 0x2058 R_ARM_RELATIVE + +// GOT: Contents of section .got: +// GOT-NEXT: 2058 00300000 diff --git a/test/ELF/arm-static-defines.s b/test/ELF/arm-static-defines.s new file mode 100644 index 0000000000000..0012841fb32cb --- /dev/null +++ b/test/ELF/arm-static-defines.s @@ -0,0 +1,44 @@ +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t +// RUN: ld.lld %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 + .syntax unified +.section .text + .global __tls_get_addr +__tls_get_addr: + bx lr + + .global _start + .global __exidx_start + .global __exidx_end +_start: + .fnstart + bx lr + .word __exidx_start + .word __exidx_end + .cantunwind + .fnend + +// CHECK: Name: __exidx_end +// CHECK-NEXT: Value: 0x100E4 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Local +// CHECK-NEXT: Type: None +// CHECK-NEXT: Other [ +// CHECK-NEXT: STV_HIDDEN +// CHECK-NEXT: ] +// CHECK-NEXT: Section: .ARM.exidx +// CHECK: Name: __exidx_start +// CHECK-NEXT: Value: 0x100D4 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Local +// CHECK-NEXT: Type: None +// CHECK-NEXT: Other [ +// CHECK-NEXT: STV_HIDDEN +// CHECK-NEXT: ] +// CHECK-NEXT: Section: .ARM.exidx +// CHECK: Symbol { +// CHECK-NEXT: Name: __tls_get_addr diff --git a/test/ELF/arm-target1.s b/test/ELF/arm-target1.s new file mode 100644 index 0000000000000..b62d6d663a856 --- /dev/null +++ b/test/ELF/arm-target1.s @@ -0,0 +1,32 @@ +// REQUIRES: arm +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o +// RUN: llvm-readobj -r %t.o | FileCheck %s --check-prefix=RELOC +// RUN: ld.lld -shared %t.o -o %t2.so --target1-rel +// RUN: llvm-objdump -t -d %t2.so | FileCheck %s \ +// RUN: --check-prefix=RELATIVE +// RUN: not ld.lld -shared %t.o -o %t3.so 2>&1 | FileCheck %s \ +// RUN: --check-prefix=ABS + +// RUN: ld.lld -shared %t.o -o %t2.so --target1-abs --target1-rel +// RUN: llvm-objdump -t -d %t2.so | FileCheck %s \ +// RUN: --check-prefix=RELATIVE +// RUN: not ld.lld -shared %t.o -o %t3.so --target1-rel --target1-abs 2>&1 \ +// RUN: | FileCheck %s --check-prefix=ABS + +// RELOC: Relocations [ +// RELOC: .rel.text { +// RELOC: 0x0 R_ARM_TARGET1 patatino 0x0 +// RELOC: } +// RELOC: ] + +.text + .word patatino(target1) + patatino: + +// RELATIVE: Disassembly of section .text: +// RELATIVE: $d.0: +// RELATIVE: 1000: 04 00 00 00 .word 0x00000004 +// RELATIVE: SYMBOL TABLE: +// RELATIVE: 00001004 .text 00000000 patatino + +// ABS: {{.*}}.o:(.text+0x0): can't create dynamic relocation R_ARM_TARGET1 against symbol 'patatino' defined in {{.*}}.o diff --git a/test/ELF/arm-target2.s b/test/ELF/arm-target2.s new file mode 100644 index 0000000000000..a678f7e08fdf1 --- /dev/null +++ b/test/ELF/arm-target2.s @@ -0,0 +1,60 @@ +// 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 +// RUN: ld.lld %t.o --target2=got-rel -o %t2 2>&1 +// RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t2 | FileCheck %s +// RUN: ld.lld %t.o --target2=abs -o %t3 2>&1 +// 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 +// is R_ARM_GOT_PREL. The other two options are primarily used for bare-metal, +// they can be selected with the --target2=abs or --target2=rel option. + .syntax unified + .text + .globl _start + .align 2 +_start: + .type function, %function + .fnstart + bx lr + .personality __gxx_personality_v0 + .handlerdata + .word _ZTIi(TARGET2) + .text + .fnend + .global __gxx_personality_v0 + .type function, %function +__gxx_personality_v0: + bx lr + + .rodata +_ZTIi: .word 0 + +// CHECK: Contents of section .ARM.extab: +// 1011c + 1ee4 = 12000 = .got +// CHECK-NEXT: 10114 f00e0000 b0b0b000 e41e0000 + +// CHECK-ABS: Contents of section .ARM.extab: +// 100f0 = .rodata +// CHECK-ABS-NEXT: 100d4 300f0000 b0b0b000 f0000100 + +// CHECK-REL: Contents of section .ARM.extab: +// 100dc + c = 100e8 = .rodata +// CHECK-REL-NEXT: 100d4 300f0000 b0b0b000 14000000 + +// CHECK: Contents of section .rodata: +// CHECK-NEXT: 10130 00000000 + +// CHECK-ABS: Contents of section .rodata: +// CHECK-ABS-NEXT: 100f0 00000000 + +// CHECK-REL: Contents of section .rodata: +// CHECK-REL-NEXT: 100f0 00000000 + +// CHECK: Contents of section .got: +// 10130 = _ZTIi +// CHECK-NEXT: 12000 30010100 diff --git a/test/ELF/arm-thumb-blx.s b/test/ELF/arm-thumb-blx.s index b581d1dd3acd1..d79bef1835e36 100644 --- a/test/ELF/arm-thumb-blx.s +++ b/test/ELF/arm-thumb-blx.s @@ -8,7 +8,7 @@ // RUN: .R_ARM_CALL24_callee4 : { *(.R_ARM_CALL24_callee_thumb_high) } } " > %t.script // 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 +// 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 diff --git a/test/ELF/arm-thumb-branch.s b/test/ELF/arm-thumb-branch.s index 94be9ecb6e53b..4dc0280b22f63 100644 --- a/test/ELF/arm-thumb-branch.s +++ b/test/ELF/arm-thumb-branch.s @@ -1,6 +1,7 @@ // 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 { \ +// RUN: . = 0xb4; \ // RUN: .callee1 : { *(.callee_low) } \ // RUN: .caller : { *(.text) } \ // RUN: .callee2 : { *(.callee_high) } } " > %t.script diff --git a/test/ELF/arm-thumb-interwork-thunk-range.s b/test/ELF/arm-thumb-interwork-thunk-range.s new file mode 100644 index 0000000000000..db674f4d5f7c9 --- /dev/null +++ b/test/ELF/arm-thumb-interwork-thunk-range.s @@ -0,0 +1,15 @@ +// 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 + +// Test that when the thunk is at a high address we don't get confused with it +// being out of range. + +.thumb +.global _start +_start: +b.w foo + +.arm +.weak foo +foo: diff --git a/test/ELF/arm-thumb-interwork-thunk.s b/test/ELF/arm-thumb-interwork-thunk.s index 6173df3c066be..3fd36b910cd12 100644 --- a/test/ELF/arm-thumb-interwork-thunk.s +++ b/test/ELF/arm-thumb-interwork-thunk.s @@ -1,12 +1,14 @@ // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: echo "SECTIONS { \ +// RUN: . = SIZEOF_HEADERS; \ // RUN: .R_ARM_JUMP24_callee_1 : { *(.R_ARM_JUMP24_callee_low) } \ // RUN: .R_ARM_THM_JUMP_callee_1 : { *(.R_ARM_THM_JUMP_callee_low)} \ // RUN: .text : { *(.text) } \ // RUN: .arm_caller : { *(.arm_caller) } \ // 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) } } " > %t.script +// RUN: .R_ARM_THM_JUMP_callee_2 : { *(.R_ARM_THM_JUMP_callee_high) } \ +// RUN: .got.plt 0x1894 : { } } " > %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 diff --git a/test/ELF/arm-thumb-narrow-branch-check.s b/test/ELF/arm-thumb-narrow-branch-check.s index b601b6d5dc267..82a7164f6df62 100644 --- a/test/ELF/arm-thumb-narrow-branch-check.s +++ b/test/ELF/arm-thumb-narrow-branch-check.s @@ -1,5 +1,6 @@ // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t // RUN: echo "SECTIONS { \ +// RUN: . = SIZEOF_HEADERS; \ // RUN: .R_ARM_PC11_1 : { *(.R_ARM_PC11_1) } \ // RUN: .caller : { *(.caller) } \ // RUN: .R_ARM_PC11_2 : { *(.R_ARM_PC11_2) } \ diff --git a/test/ELF/arm-thumb-no-undefined-thunk.s b/test/ELF/arm-thumb-no-undefined-thunk.s new file mode 100644 index 0000000000000..f668c8c278dee --- /dev/null +++ b/test/ELF/arm-thumb-no-undefined-thunk.s @@ -0,0 +1,24 @@ +// 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 + +.weak target + +.section .text.thumb, "ax", %progbits + .thumb + .global +_start: + bl target + b target + b.w target + +// CHECK: Disassembly of section .text: +// CHECK-NEXT: _start: +// 69636 = 0x11004 = next instruction +// CHECK: 11000: 11 f0 02 f8 bl #69636 +// CHECK-NEXT: 11004: 11 f0 04 b8 b.w #69640 +// CHECK-NEXT: 11008: 11 f0 06 b8 b.w #69644 diff --git a/test/ELF/arm-thumb-undefined-weak.s b/test/ELF/arm-thumb-undefined-weak.s new file mode 100644 index 0000000000000..087f8e71cb219 --- /dev/null +++ b/test/ELF/arm-thumb-undefined-weak.s @@ -0,0 +1,38 @@ +// 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 +// relocations are resolved to the place. + + .syntax unified + + .weak target + + .text + .global _start +_start: +// R_ARM_THM_JUMP19 + beq.w target +// R_ARM_THM_JUMP24 + b.w target +// R_ARM_THM_CALL + bl target +// R_ARM_THM_CALL with exchange + blx target +// R_ARM_THM_MOVT_PREL + movt r0, :upper16:target - . +// R_ARM_THM_MOVW_PREL_NC + movw r0, :lower16:target - . + +// CHECK: Disassembly of section .text: +// 69636 = 0x11004 +// CHECK: 11000: 11 f0 02 80 beq.w #69636 +// CHECK-NEXT: 11004: 11 f0 04 b8 b.w #69640 +// CHECK-NEXT: 11008: 11 f0 06 f8 bl #69644 +// blx is transformed into bl so we don't change state +// CHECK-NEXT: 1100c: 11 f0 08 f8 bl #69648 +// CHECK-NEXT: 11010: c0 f2 00 00 movt r0, #0 +// CHECK-NEXT: 11014: 40 f2 00 00 movw r0, #0 diff --git a/test/ELF/arm-tls-gd32.s b/test/ELF/arm-tls-gd32.s new file mode 100644 index 0000000000000..206b65d05af93 --- /dev/null +++ b/test/ELF/arm-tls-gd32.s @@ -0,0 +1,106 @@ +// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-readobj -s -dyn-relocations %t.so | FileCheck --check-prefix=SEC %s +// RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s +// 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 +// R_ARM_TLS_DTPOFF32. One of the variables is hidden which permits relaxation +// to local dynamic + + .text + .syntax unified + .globl func + .p2align 2 + .type func,%function +func: +.L0: + nop +.L1: + nop +.L2: + nop + + .p2align 2 +// Generate R_ARM_TLS_GD32 relocations +// Allocates a pair of GOT entries dynamically relocated by R_ARM_TLS_DTPMOD32 +// and R_ARM_TLS_DTPOFF32 respectively. The literal contains the offset of the +// first GOT entry from the place +.Lt0: .word x(TLSGD) + (. - .L0 - 8) +.Lt1: .word y(TLSGD) + (. - .L1 - 8) +.Lt2: .word z(TLSGD) + (. - .L2 - 8) + +// __thread int x = 10 +// __thread int y; +// __thread int z __attribute((visibility("hidden"))) + + .hidden z + .globl z + .globl y + .globl x + + .section .tbss,"awT",%nobits + .p2align 2 +.TLSSTART: + .type z, %object +z: + .space 4 + .type y, %object +y: + .space 4 + .section .tdata,"awT",%progbits + .p2align 2 + .type x, %object +x: + .word 10 + +// SEC: Name: .tdata +// SEC-NEXT: Type: SHT_PROGBITS +// SEC-NEXT: Flags [ +// SEC-NEXT: SHF_ALLOC +// SEC-NEXT: SHF_TLS +// SEC-NEXT: SHF_WRITE +// SEC-NEXT: ] +// SEC-NEXT: Address: 0x2000 +// SEC: Size: 4 +// SEC: Name: .tbss +// SEC-NEXT: Type: SHT_NOBITS +// SEC-NEXT: Flags [ +// SEC-NEXT: SHF_ALLOC +// SEC-NEXT: SHF_TLS +// SEC-NEXT: SHF_WRITE +// SEC-NEXT: ] +// SEC-NEXT: Address: 0x2004 +// SEC: Size: 8 + +// SEC: Name: .got +// SEC-NEXT: Type: SHT_PROGBITS +// SEC-NEXT: Flags [ +// SEC-NEXT: SHF_ALLOC +// SEC-NEXT: SHF_WRITE +// SEC-NEXT: ] +// SEC-NEXT: Address: 0x204C +// SEC: Size: 24 + +// SEC: Dynamic Relocations { +// SEC-NEXT: 0x205C R_ARM_TLS_DTPMOD32 - +// SEC-NEXT: 0x204C R_ARM_TLS_DTPMOD32 x +// SEC-NEXT: 0x2050 R_ARM_TLS_DTPOFF32 x +// SEC-NEXT: 0x2054 R_ARM_TLS_DTPMOD32 y +// SEC-NEXT: 0x2058 R_ARM_TLS_DTPOFF32 y + + +// CHECK: Disassembly +// CHECK-NEXT: func: +// CHECK-NEXT: 1000: 00 f0 20 e3 nop +// CHECK-NEXT: 1004: 00 f0 20 e3 nop +// CHECK-NEXT: 1008: 00 f0 20 e3 nop + +// (0x204c - 0x100c) + (0x100c - 0x1000 - 8) = 0x1044 +// CHECK: 100c: 44 10 00 00 +// (0x2054 - 0x1010) + (0x1010 - 0x1004 - 8) = 0x1048 +// CHECK-NEXT: 1010: 48 10 00 00 +// (0x205c - 0x1014) + (0x1014 - 0x1008 - 8) = 0x104c +// CHECK-NEXT: 1014: 4c 10 00 00 + diff --git a/test/ELF/arm-tls-ie32.s b/test/ELF/arm-tls-ie32.s new file mode 100644 index 0000000000000..48120fa682da4 --- /dev/null +++ b/test/ELF/arm-tls-ie32.s @@ -0,0 +1,96 @@ +// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-readobj -s -dyn-relocations %t.so | FileCheck --check-prefix=SEC %s +// RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s +// 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 +// of the R_ARM_TLS_TPOFF32 relocation. + + .syntax unified + .arm + .globl func + .type func,%function + .p2align 2 +func: +.L0: + nop +.L1: + nop +.L2: + nop + + .p2align 2 +// Generate R_ARM_TLS_IE32 static relocations +// Allocates a GOT entry dynamically relocated by R_ARM_TLS_TPOFF32 +// literal contains the offset of the GOT entry from the place +.Lt0: .word x(gottpoff) + (. - .L0 - 8) +.Lt1: .word y(gottpoff) + (. - .L1 - 8) +.Lt2: .word .TLSSTART(gottpoff) + (. - .L2 - 8) + +// __thread int x = 10 +// __thread int y; +// __thread int z __attribute((visibility("hidden"))) + .hidden z + .globl z + .globl y + .globl x + + .section .tbss,"awT",%nobits + .p2align 2 +.TLSSTART: + .type z, %object +z: + .space 4 + .type y, %object +y: + .space 4 + .section .tdata,"awT",%progbits + .p2align 2 + .type x, %object +x: + .word 10 + +// SEC: Name: .tdata +// SEC-NEXT: Type: SHT_PROGBITS +// SEC-NEXT: Flags [ +// SEC-NEXT: SHF_ALLOC +// SEC-NEXT: SHF_TLS +// SEC-NEXT: SHF_WRITE +// SEC: Size: 4 +// SEC: Name: .tbss +// SEC-NEXT: Type: SHT_NOBITS +// SEC-NEXT: Flags [ +// SEC-NEXT: SHF_ALLOC +// SEC-NEXT: SHF_TLS +// SEC-NEXT: SHF_WRITE +// SEC: Size: 8 + +// SEC: Name: .got +// SEC-NEXT: Type: SHT_PROGBITS +// SEC-NEXT: Flags [ +// SEC-NEXT: SHF_ALLOC +// SEC-NEXT: SHF_WRITE +// SEC-NEXT: ] +// SEC-NEXT: Address: 0x204C +// SEC: Size: 12 + + +// SEC: Dynamic Relocations { +// SEC: 0x2054 R_ARM_TLS_TPOFF32 +// SEC: 0x204C R_ARM_TLS_TPOFF32 x +// SEC: 0x2050 R_ARM_TLS_TPOFF32 y + +// CHECK: Disassembly of section .text: +// CHECK-NEXT: func: +// CHECK-NEXT: 1000: 00 f0 20 e3 nop +// CHECK-NEXT: 1004: 00 f0 20 e3 nop +// CHECK-NEXT: 1008: 00 f0 20 e3 nop + +// (0x204c - 0x100c) + (0x100c - 0x1000 - 8) = 0x1044 +// CHECK: 100c: 44 10 00 00 +// (0x2050 - 0x1010) + (0x1010 - 0x1004 - 8) = 0x1044 +// CHECK-NEXT: 1010: 44 10 00 00 +// (0x2054 - 0x1014) + (0x1014 - 0x1008 - 8) = 0x1044 +// CHECK-NEXT: 1014: 44 10 00 00 diff --git a/test/ELF/arm-tls-ldm32.s b/test/ELF/arm-tls-ldm32.s new file mode 100644 index 0000000000000..47e8791027075 --- /dev/null +++ b/test/ELF/arm-tls-ldm32.s @@ -0,0 +1,73 @@ +// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-readobj -s -dyn-relocations %t.so | FileCheck --check-prefix=SEC %s +// RUN: llvm-objdump -d -triple=armv7a-linux-gnueabi %t.so | FileCheck %s +// 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 +// The R_ARM_TLS_LDO is the offset of the variable within the TLS block. + .global __tls_get_addr + .text + .p2align 2 + .global _start + .syntax unified + .arm + .type _start, %function +_start: +.L0: + nop + + .word x(tlsldm) + (. - .L0 - 8) + .word x(tlsldo) + .word y(tlsldo) + + .section .tbss,"awT",%nobits + .p2align 2 + .type y, %object +y: + .space 4 + .section .tdata,"awT",%progbits + .p2align 2 + .type x, %object +x: + .word 10 + +// SEC: Name: .tdata +// SEC-NEXT: Type: SHT_PROGBITS +// SEC-NEXT: Flags [ +// SEC-NEXT: SHF_ALLOC +// SEC-NEXT: SHF_TLS +// SEC-NEXT: SHF_WRITE +// SEC-NEXT: ] +// SEC-NEXT: Address: 0x2000 +// SEC: Size: 4 +// SEC: Name: .tbss +// SEC-NEXT: Type: SHT_NOBITS (0x8) +// SEC-NEXT: Flags [ +// SEC-NEXT: SHF_ALLOC +// SEC-NEXT: SHF_TLS +// SEC-NEXT: SHF_WRITE +// SEC-NEXT: ] +// SEC-NEXT: Address: 0x2004 +// SEC: Size: 4 + +// SEC: Dynamic Relocations { +// SEC-NEXT: 0x204C R_ARM_TLS_DTPMOD32 - 0x0 + +// CHECK: Disassembly of section .text: +// CHECK-NEXT: _start: +// CHECK-NEXT: 1000: 00 f0 20 e3 nop + +// (0x204c - 0x1004) + (0x1004 - 0x1000 - 8) = 0x1044 +// CHECK: 1004: 44 10 00 00 +// CHECK-NEXT: 1008: 00 00 00 00 +// CHECK-NEXT: 100c: 04 00 00 00 + +// CHECK-EXE: Disassembly of section .text: +// CHECK-NEXT-EXE: _start: +// CHECK-NEXT-EXE: 11000: 00 f0 20 e3 nop + +// CHECK-EXE: 11004: fc 0f 00 00 +// CHECK-EXE: 11008: 00 00 00 00 +// CHECK-EXE: 1100c: 04 00 00 00 diff --git a/test/ELF/arm-tls-le32.s b/test/ELF/arm-tls-le32.s new file mode 100644 index 0000000000000..4d42a06b0fffb --- /dev/null +++ b/test/ELF/arm-tls-le32.s @@ -0,0 +1,77 @@ +// 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 +// in r9 + + .text + .syntax unified + .globl _start + .p2align 2 + .type _start,%function +_start: + .p2align 2 +// Generate R_ARM_TLS_LE32 relocations. These resolve statically to the offset +// of the variable from the thread pointer +.Lt0: .word x(TPOFF) +.Lt1: .word y(TPOFF) +.Lt2: .word z(TPOFF) + +// __thread int x = 10 +// __thread int y; +// __thread int z __attribute((visibility("hidden"))) + + .hidden z + .globl z + .globl y + .globl x + + .section .tbss,"awT",%nobits + .p2align 2 +.TLSSTART: + .type z, %object +z: + .space 4 + .type y, %object +y: + .space 4 + .section .tdata,"awT",%progbits + .p2align 2 + .type x, %object +x: + .word 10 + +// SEC: Name: .tdata +// SEC-NEXT: Type: SHT_PROGBITS +// SEC-NEXT: Flags [ +// SEC-NEXT: SHF_ALLOC +// SEC-NEXT: SHF_TLS +// SEC-NEXT: SHF_WRITE +// SEC-NEXT: ] +// SEC-NEXT: Address: 0x12000 +// SEC: Size: 4 +// SEC: Name: .tbss +// SEC-NEXT: Type: SHT_NOBITS +// SEC-NEXT: Flags [ +// SEC-NEXT: SHF_ALLOC +// SEC-NEXT: SHF_TLS +// SEC-NEXT: SHF_WRITE +// SEC-NEXT: ] +// SEC-NEXT: Address: 0x12004 +// SEC: Size: 8 + +// SEC: Dynamic Relocations { +// SEC-NEXT: } + +// CHECK: Disassembly of section .text: +// CHECK-NEXT: _start: +// offset of x from Thread pointer = (TcbSize + 0x0 = 0x8) +// CHECK-NEXT: 11000: 08 00 00 00 +// offset of z from Thread pointer = (TcbSize + 0x8 = 0x10) +// CHECK-NEXT: 11004: 10 00 00 00 +// offset of y from Thread pointer = (TcbSize + 0x4 = 0xc) +// CHECK-NEXT: 11008: 0c 00 00 00 diff --git a/test/ELF/arm-tls-norelax-gd-ie.s b/test/ELF/arm-tls-norelax-gd-ie.s new file mode 100644 index 0000000000000..3bd3db08ccf49 --- /dev/null +++ b/test/ELF/arm-tls-norelax-gd-ie.s @@ -0,0 +1,30 @@ +// 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 %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 +// possible. This would result in an assertion failure on ARM as the +// relaxation functions can't be implemented on ARM. Check that the sequence +// is handled as global dynamic + + .text + .syntax unified + .globl func + .p2align 2 + .type func,%function +func: +.L0: + .globl __tls_get_addr + bl __tls_get_addr + bx lr + .p2align 2 + .Lt0: .word y(TLSGD) + (. - .L0 - 8) + +// CHECK: Dynamic Relocations { +// CHECK-NEXT: 0x12078 R_ARM_TLS_DTPMOD32 y +// CHECK-NEXT: 0x1207C R_ARM_TLS_DTPOFF32 y +// CHECK-NEXT: 0x1300C R_ARM_JUMP_SLOT __tls_get_addr diff --git a/test/ELF/arm-tls-norelax-gd-le.s b/test/ELF/arm-tls-norelax-gd-le.s new file mode 100644 index 0000000000000..67952b1f8565f --- /dev/null +++ b/test/ELF/arm-tls-norelax-gd-le.s @@ -0,0 +1,37 @@ +// 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 %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 +// possible. This would result in an assertion failure on ARM as the +// relaxation functions can't be implemented on ARM. Check that the sequence +// is handled as global dynamic + + .text + .syntax unified + .globl func + .p2align 2 + .type func,%function +func: +.L0: + .globl __tls_get_addr + bl __tls_get_addr + bx lr + .p2align 2 + .Lt0: .word x(TLSGD) + (. - .L0 - 8) + + .globl x +.section .tbss,"awT",%nobits + .p2align 2 +x: + .space 4 + .type x, %object + +// CHECK: Contents of section .got: +// Module index is always 1 for executable +// CHECK-NEXT: 12060 01000000 00000000 + diff --git a/test/ELF/arm-tls-norelax-ie-le.s b/test/ELF/arm-tls-norelax-ie-le.s new file mode 100644 index 0000000000000..ecb68293829a1 --- /dev/null +++ b/test/ELF/arm-tls-norelax-ie-le.s @@ -0,0 +1,41 @@ +// 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 %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 +// failure on ARM as the relaxation functions can't be implemented on ARM. +// Check that the sequence is handled as initial exec + .text + .syntax unified + .globl func + .p2align 2 + .type func,%function +func: +.L0: + .globl __tls_get_addr + bl __tls_get_addr +.L1: + bx lr + .p2align 2 + .Lt0: .word x1(gottpoff) + (. - .L0 - 8) + .Lt1: .word x2(gottpoff) + (. - .L1 - 8) + + .globl x1 + .section .trw,"awT",%progbits + .p2align 2 +x1: + .word 0x1 + .globl x2 + .section .tbss,"awT",%nobits + .type x1, %object +x2: + .space 4 + .type x2, %object + +// CHECK: Contents of section .got +// x1 at offset 8 from TP, x2 at offset c from TP. Offsets include TCB size of 8 +// CHECK-NEXT: 12064 08000000 0c000000 diff --git a/test/ELF/arm-tls-norelax-ld-le.s b/test/ELF/arm-tls-norelax-ld-le.s new file mode 100644 index 0000000000000..380610ef394b1 --- /dev/null +++ b/test/ELF/arm-tls-norelax-ld-le.s @@ -0,0 +1,35 @@ +// 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 %t1.so %t.o -o %t +// RUN: llvm-objdump -s %t | FileCheck %s +// REQUIRES: arm + + .global __tls_get_addr + .text + .p2align 2 + .global _start + .syntax unified + .arm + .type _start, %function +_start: +.L0: + bl __tls_get_addr + + .word x(tlsldm) + (. - .L0 - 8) + .word x(tlsldo) + .word y(tlsldo) + + .section .tbss,"awT",%nobits + .p2align 2 + .type y, %object +y: + .space 4 + .section .tdata,"awT",%progbits + .p2align 2 + .type x, %object +x: + .word 10 + +// CHECK: Contents of section .got: +// CHECK-NEXT: 12064 01000000 00000000 diff --git a/test/ELF/arm-undefined-weak.s b/test/ELF/arm-undefined-weak.s new file mode 100644 index 0000000000000..df67b467e2635 --- /dev/null +++ b/test/ELF/arm-undefined-weak.s @@ -0,0 +1,39 @@ +// 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 +// Symbols in relative are resolved to the place so S - P + A = A. + + .syntax unified + + .weak target + + .text + .global _start +_start: +// R_ARM_JUMP24 + b target +// R_ARM_CALL + bl target +// R_ARM_CALL with exchange + blx target +// R_ARM_MOVT_PREL + movt r0, :upper16:target - . +// R_ARM_MOVW_PREL_NC + movw r0, :lower16:target - . +// R_ARM_REL32 + .word target - . + +// CHECK: Disassembly of section .text: +// 69636 = 0x11004 +// CHECK: 11000: 01 44 00 ea b #69636 +// CHECK-NEXT: 11004: 02 44 00 eb bl #69640 +// blx is transformed into bl so we don't change state +// CHECK-NEXT: 11008: 03 44 00 eb bl #69644 +// CHECK-NEXT: 1100c: 00 00 40 e3 movt r0, #0 +// CHECK-NEXT: 11010: 00 00 00 e3 movw r0, #0 +// CHECK: 11014: 00 00 00 00 .word 0x00000000 + diff --git a/test/ELF/arm-use-r-output.s b/test/ELF/arm-use-r-output.s new file mode 100644 index 0000000000000..918362466d3a6 --- /dev/null +++ b/test/ELF/arm-use-r-output.s @@ -0,0 +1,13 @@ +// 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 + +// We used to crash using the output of -r because of the relative order of +// SHF_LINK_ORDER sections. + +// That can be fixed by changing -r or making the regular link more flexible, +// so this is an end to end test. + + .fnstart + .fnend diff --git a/test/ELF/auxiliary.s b/test/ELF/auxiliary.s new file mode 100644 index 0000000000000..236d0a421d4fc --- /dev/null +++ b/test/ELF/auxiliary.s @@ -0,0 +1,12 @@ +# 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 + +# CHECK: DynamicSection [ +# CHECK-NEXT: Tag Type Name/Value +# CHECK-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [aaa] +# CHECK-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [bbb] + +# RUN: not ld.lld %t.o -f aaa --auxiliary bbb -o %t 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR %s +# ERR: -f may not be used without -shared diff --git a/test/ELF/avoid-empty-program-headers.s b/test/ELF/avoid-empty-program-headers.s index f7315677e1a31..271d1a3038508 100644 --- a/test/ELF/avoid-empty-program-headers.s +++ b/test/ELF/avoid-empty-program-headers.s @@ -16,8 +16,8 @@ _start: // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_PHDR (0x6) // CHECK-NEXT: Offset: 0x40 -// CHECK-NEXT: VirtualAddress: 0x10040 -// CHECK-NEXT: PhysicalAddress: 0x10040 +// CHECK-NEXT: VirtualAddress: 0x200040 +// CHECK-NEXT: PhysicalAddress: 0x200040 // CHECK-NEXT: FileSize: 280 // CHECK-NEXT: MemSize: 280 // CHECK-NEXT: Flags [ (0x4) @@ -28,8 +28,8 @@ _start: // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_LOAD (0x1) // CHECK-NEXT: Offset: 0x0 -// CHECK-NEXT: VirtualAddress: 0x10000 -// CHECK-NEXT: PhysicalAddress: 0x10000 +// CHECK-NEXT: VirtualAddress: 0x200000 +// CHECK-NEXT: PhysicalAddress: 0x200000 // CHECK-NEXT: FileSize: 344 // CHECK-NEXT: MemSize: 344 // CHECK-NEXT: Flags [ (0x4) @@ -40,8 +40,8 @@ _start: // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_LOAD (0x1) // CHECK-NEXT: Offset: 0x1000 -// CHECK-NEXT: VirtualAddress: 0x11000 -// CHECK-NEXT: PhysicalAddress: 0x11000 +// CHECK-NEXT: VirtualAddress: 0x201000 +// CHECK-NEXT: PhysicalAddress: 0x201000 // CHECK-NEXT: FileSize: 1 // CHECK-NEXT: MemSize: 1 // CHECK-NEXT: Flags [ (0x5) @@ -53,8 +53,8 @@ _start: // CHECK-NEXT: ProgramHeader { // CHECK-NEXT: Type: PT_TLS (0x7) // CHECK-NEXT: Offset: 0x1001 -// CHECK-NEXT: VirtualAddress: 0x11001 -// CHECK-NEXT: PhysicalAddress: 0x11001 +// CHECK-NEXT: VirtualAddress: 0x201001 +// CHECK-NEXT: PhysicalAddress: 0x201001 // CHECK-NEXT: FileSize: 0 // CHECK-NEXT: MemSize: 4 // CHECK-NEXT: Flags [ (0x4) diff --git a/test/ELF/bad-archive.s b/test/ELF/bad-archive.s new file mode 100644 index 0000000000000..39c8e160f95dc --- /dev/null +++ b/test/ELF/bad-archive.s @@ -0,0 +1,11 @@ +// REQUIRES: x86 + +// Check bad archive error reporting with --whole-archive +// and without it. +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +// RUN: not ld.lld %t.o %p/Inputs/bad-archive.a -o %t 2>&1 | FileCheck %s +// RUN: not ld.lld %t.o --whole-archive %p/Inputs/bad-archive.a -o %t 2>&1 | FileCheck %s +// CHECK: bad-archive.a: failed to parse archive + +.globl _start +_start: diff --git a/test/ELF/basic-aarch64.s b/test/ELF/basic-aarch64.s index 84105f0acdb70..b68a2f9942a7b 100644 --- a/test/ELF/basic-aarch64.s +++ b/test/ELF/basic-aarch64.s @@ -26,15 +26,15 @@ _start: # CHECK-NEXT: Version: 1 # CHECK-NEXT: Entry: [[ENTRY:0x[0-9A-F]+]] # CHECK-NEXT: ProgramHeaderOffset: 0x40 -# CHECK-NEXT: SectionHeaderOffset: 0x1088 +# CHECK-NEXT: SectionHeaderOffset: 0x10098 # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 64 # CHECK-NEXT: ProgramHeaderEntrySize: 56 # CHECK-NEXT: ProgramHeaderCount: 4 # CHECK-NEXT: SectionHeaderEntrySize: 64 -# CHECK-NEXT: SectionHeaderCount: 5 -# CHECK-NEXT: StringTableSectionIndex: 3 +# CHECK-NEXT: SectionHeaderCount: 6 +# CHECK-NEXT: StringTableSectionIndex: 4 # CHECK-NEXT: } # CHECK-NEXT: Sections [ # CHECK-NEXT: Section { @@ -59,8 +59,8 @@ _start: # CHECK-NEXT: SHF_ALLOC (0x2) # CHECK-NEXT: SHF_EXECINSTR (0x4) # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x11000 -# CHECK-NEXT: Offset: 0x1000 +# CHECK-NEXT: Address: 0x20000 +# CHECK-NEXT: Offset: 0x10000 # CHECK-NEXT: Size: 12 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -69,40 +69,56 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 2 +# CHECK-NEXT: Name: .comment +# 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: 0x1000C +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 1 +# CHECK-NEXT: EntrySize: 1 +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: 3 # CHECK-NEXT: Name: .symtab # CHECK-NEXT: Type: SHT_SYMTAB (0x2) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x1010 +# CHECK-NEXT: Offset: 0x10018 # CHECK-NEXT: Size: 72 -# CHECK-NEXT: Link: 4 +# CHECK-NEXT: Link: 5 # CHECK-NEXT: Info: 2 # CHECK-NEXT: AddressAlignment: 8 # CHECK-NEXT: EntrySize: 24 # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 3 +# CHECK-NEXT: Index: 4 # CHECK-NEXT: Name: .shstrtab # CHECK-NEXT: Type: SHT_STRTAB (0x3) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x1058 -# CHECK-NEXT: Size: 33 +# CHECK-NEXT: Offset: 0x10060 +# CHECK-NEXT: Size: 42 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 1 # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 4 -# CHECK-NEXT: Name: .strtab (25) +# CHECK-NEXT: Index: 5 +# CHECK-NEXT: Name: .strtab # CHECK-NEXT: Type: SHT_STRTAB (0x3) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x1079 +# CHECK-NEXT: Offset: 0x1008A # CHECK-NEXT: Size: 13 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -122,7 +138,7 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: Symbol { # CHECK-NEXT: Name: $x.0 -# CHECK-NEXT: Value: 0x11000 +# CHECK-NEXT: Value: 0x20000 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Local (0x0) # CHECK-NEXT: Type: None (0x0) @@ -162,20 +178,20 @@ _start: # CHECK-NEXT: Flags [ # CHECK-NEXT: PF_R # CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 4096 +# CHECK-NEXT: Alignment: 65536 # CHECK-NEXT: } # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD (0x1) # CHECK-NEXT: Offset: 0x1000 -# CHECK-NEXT: VirtualAddress: 0x11000 -# CHECK-NEXT: PhysicalAddress: 0x11000 +# CHECK-NEXT: VirtualAddress: 0x20000 +# CHECK-NEXT: PhysicalAddress: 0x20000 # 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: 4096 +# CHECK-NEXT: Alignment: 65536 # CHECK-NEXT: } # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_GNU_STACK diff --git a/test/ELF/basic-mips.s b/test/ELF/basic-mips.s index c598c7b5f2f75..dc640edae9f0c 100644 --- a/test/ELF/basic-mips.s +++ b/test/ELF/basic-mips.s @@ -27,18 +27,18 @@ __start: # CHECK-NEXT: Version: 1 # CHECK-NEXT: Entry: 0x20000 # CHECK-NEXT: ProgramHeaderOffset: 0x34 -# CHECK-NEXT: SectionHeaderOffset: 0x30088 +# CHECK-NEXT: SectionHeaderOffset: 0x30098 # CHECK-NEXT: Flags [ # CHECK-NEXT: EF_MIPS_ABI_O32 -# CHECK-NEXT: EF_MIPS_ARCH_32R2 +# CHECK-NEXT: EF_MIPS_ARCH_32 # CHECK-NEXT: EF_MIPS_CPIC # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 52 # CHECK-NEXT: ProgramHeaderEntrySize: 32 # CHECK-NEXT: ProgramHeaderCount: 6 # CHECK-NEXT: SectionHeaderEntrySize: 40 -# CHECK-NEXT: SectionHeaderCount: 10 -# CHECK-NEXT: StringTableSectionIndex: 8 +# CHECK-NEXT: SectionHeaderCount: 11 +# CHECK-NEXT: StringTableSectionIndex: 9 # CHECK-NEXT: } # CHECK-NEXT: Sections [ # CHECK-NEXT: Section { @@ -57,23 +57,23 @@ __start: # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 1 -# CHECK-NEXT: Name: .reginfo -# CHECK-NEXT: Type: SHT_MIPS_REGINFO (0x70000006) +# CHECK-NEXT: Name: .MIPS.abiflags +# CHECK-NEXT: Type: SHT_MIPS_ABIFLAGS (0x7000002A) # CHECK-NEXT: Flags [ (0x2) # CHECK-NEXT: SHF_ALLOC (0x2) # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x100F4 -# CHECK-NEXT: Offset: 0xF4 +# CHECK-NEXT: Address: 0x100F8 +# CHECK-NEXT: Offset: 0xF8 # CHECK-NEXT: Size: 24 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 -# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: AddressAlignment: 8 # CHECK-NEXT: EntrySize: 24 # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 2 -# CHECK-NEXT: Name: .MIPS.abiflags -# CHECK-NEXT: Type: SHT_MIPS_ABIFLAGS (0x7000002A) +# CHECK-NEXT: Name: .reginfo +# CHECK-NEXT: Type: SHT_MIPS_REGINFO (0x70000006) # CHECK-NEXT: Flags [ (0x2) # CHECK-NEXT: SHF_ALLOC (0x2) # CHECK-NEXT: ] @@ -82,12 +82,12 @@ __start: # CHECK-NEXT: Size: 24 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 -# CHECK-NEXT: AddressAlignment: 8 -# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 24 # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 3 -# CHECK-NEXT: Name: .text (25) +# CHECK-NEXT: Name: .text # CHECK-NEXT: Type: SHT_PROGBITS (0x1) # CHECK-NEXT: Flags [ (0x6) # CHECK-NEXT: SHF_ALLOC (0x2) @@ -103,7 +103,7 @@ __start: # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 4 -# CHECK-NEXT: Name: .got (31) +# CHECK-NEXT: Name: .got # CHECK-NEXT: Type: SHT_PROGBITS (0x1) # CHECK-NEXT: Flags [ (0x10000003) # CHECK-NEXT: SHF_ALLOC (0x2) @@ -152,40 +152,56 @@ __start: # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 7 +# CHECK-NEXT: Name: .comment +# 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: Size: 8 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 1 +# CHECK-NEXT: EntrySize: 1 +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: 8 # CHECK-NEXT: Name: .symtab # CHECK-NEXT: Type: SHT_SYMTAB (0x2) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x30000 +# CHECK-NEXT: Offset: 0x30008 # CHECK-NEXT: Size: 48 -# CHECK-NEXT: Link: 9 +# CHECK-NEXT: Link: 10 # CHECK-NEXT: Info: 1 # CHECK-NEXT: AddressAlignment: 4 # CHECK-NEXT: EntrySize: 16 # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 8 +# CHECK-NEXT: Index: 9 # CHECK-NEXT: Name: .shstrtab # CHECK-NEXT: Type: SHT_STRTAB (0x3) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x30030 -# CHECK-NEXT: Size: 73 +# CHECK-NEXT: Offset: 0x30038 +# CHECK-NEXT: Size: 82 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 1 # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 9 +# CHECK-NEXT: Index: 10 # CHECK-NEXT: Name: .strtab # CHECK-NEXT: Type: SHT_STRTAB (0x3) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x30079 +# CHECK-NEXT: Offset: 0x3008A # CHECK-NEXT: Size: 13 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -212,7 +228,7 @@ __start: # CHECK-NEXT: Other [ (0x2) # CHECK-NEXT: STV_HIDDEN (0x2) # CHECK-NEXT: ] -# CHECK-NEXT: Section: .got +# CHECK-NEXT: Section: Absolute # CHECK-NEXT: } # CHECK-NEXT: Symbol { # CHECK-NEXT: Name: __start diff --git a/test/ELF/basic-ppc.s b/test/ELF/basic-ppc.s index 83ace9a4983de..c0f28bd48c416 100644 --- a/test/ELF/basic-ppc.s +++ b/test/ELF/basic-ppc.s @@ -26,17 +26,17 @@ // CHECK-NEXT: Type: SharedObject (0x3) // CHECK-NEXT: Machine: EM_PPC (0x14) // CHECK-NEXT: Version: 1 -// CHECK-NEXT: Entry: 0x0 +// CHECK-NEXT: Entry: 0x1000 // CHECK-NEXT: ProgramHeaderOffset: 0x34 -// CHECK-NEXT: SectionHeaderOffset: 0x209C +// CHECK-NEXT: SectionHeaderOffset: 0x20AC // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: HeaderSize: 52 // CHECK-NEXT: ProgramHeaderEntrySize: 32 // CHECK-NEXT: ProgramHeaderCount: 7 // CHECK-NEXT: SectionHeaderEntrySize: 40 -// CHECK-NEXT: SectionHeaderCount: 9 -// CHECK-NEXT: StringTableSectionIndex: 7 +// CHECK-NEXT: SectionHeaderCount: 10 +// CHECK-NEXT: StringTableSectionIndex: 8 // CHECK-NEXT: } // CHECK-NEXT: Sections [ // CHECK-NEXT: Section { @@ -57,7 +57,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Section { // CHECK-NEXT: Index: 1 -// CHECK-NEXT: Name: .dynsym (1) +// CHECK-NEXT: Name: .dynsym // CHECK-NEXT: Type: SHT_DYNSYM (0xB) // CHECK-NEXT: Flags [ (0x2) // CHECK-NEXT: SHF_ALLOC (0x2) @@ -75,7 +75,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Section { // CHECK-NEXT: Index: 2 -// CHECK-NEXT: Name: .hash (9) +// CHECK-NEXT: Name: .hash // CHECK-NEXT: Type: SHT_HASH (0x5) // CHECK-NEXT: Flags [ (0x2) // CHECK-NEXT: SHF_ALLOC (0x2) @@ -93,7 +93,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Section { // CHECK-NEXT: Index: 3 -// CHECK-NEXT: Name: .dynstr (15) +// CHECK-NEXT: Name: .dynstr // CHECK-NEXT: Type: SHT_STRTAB (0x3) // CHECK-NEXT: Flags [ (0x2) // CHECK-NEXT: SHF_ALLOC (0x2) @@ -111,7 +111,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Section { // CHECK-NEXT: Index: 4 -// CHECK-NEXT: Name: .text (23) +// CHECK-NEXT: Name: .text // CHECK-NEXT: Type: SHT_PROGBITS (0x1) // CHECK-NEXT: Flags [ (0x6) // CHECK-NEXT: SHF_ALLOC (0x2) @@ -130,7 +130,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Section { // CHECK-NEXT: Index: 5 -// CHECK-NEXT: Name: .dynamic (29) +// CHECK-NEXT: Name: .dynamic // CHECK-NEXT: Type: SHT_DYNAMIC (0x6) // CHECK-NEXT: Flags [ (0x3) // CHECK-NEXT: SHF_ALLOC (0x2) @@ -151,14 +151,33 @@ // CHECK-NEXT: } // CHECK-NEXT: Section { // CHECK-NEXT: Index: 6 -// CHECK-NEXT: Name: .symtab (38) +// CHECK-NEXT: Name: .comment +// 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: 0x2030 +// 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 // CHECK-NEXT: Type: SHT_SYMTAB (0x2) // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x2030 +// CHECK-NEXT: Offset: 0x2038 // CHECK-NEXT: Size: 32 -// CHECK-NEXT: Link: 8 +// CHECK-NEXT: Link: 9 // CHECK-NEXT: Info: 1 // CHECK-NEXT: AddressAlignment: 4 // CHECK-NEXT: EntrySize: 16 @@ -168,14 +187,14 @@ // CHECK-NEXT: ) // CHECK-NEXT: } // CHECK-NEXT: Section { -// CHECK-NEXT: Index: 7 -// CHECK-NEXT: Name: .shstrtab (46) +// CHECK-NEXT: Index: 8 +// CHECK-NEXT: Name: .shstrtab // CHECK-NEXT: Type: SHT_STRTAB (0x3) // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x2050 -// CHECK-NEXT: Size: 64 +// CHECK-NEXT: Offset: 0x2058 +// CHECK-NEXT: Size: 73 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 1 @@ -183,18 +202,19 @@ // 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 63002E73 796D7461 62002E73 |namic..symtab..s| -// CHECK-NEXT: 0030: 68737472 74616200 2E737472 74616200 |hstrtab..strtab.| +// 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: 8 -// CHECK-NEXT: Name: .strtab (56) +// CHECK-NEXT: Index: 9 +// CHECK-NEXT: Name: .strtab // CHECK-NEXT: Type: SHT_STRTAB (0x3) // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x2090 +// CHECK-NEXT: Offset: 0x20A1 // CHECK-NEXT: Size: 1 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 diff --git a/test/ELF/basic.s b/test/ELF/basic.s index 28449331d3fab..e284f9bd40d28 100644 --- a/test/ELF/basic.s +++ b/test/ELF/basic.s @@ -27,15 +27,15 @@ _start: # CHECK-NEXT: Version: 1 # CHECK-NEXT: Entry: [[ENTRY:0x[0-9A-F]+]] # CHECK-NEXT: ProgramHeaderOffset: 0x40 -# CHECK-NEXT: SectionHeaderOffset: 0x1070 +# CHECK-NEXT: SectionHeaderOffset: 0x1080 # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 64 # CHECK-NEXT: ProgramHeaderEntrySize: 56 # CHECK-NEXT: ProgramHeaderCount: 4 # CHECK-NEXT: SectionHeaderEntrySize: 64 -# CHECK-NEXT: SectionHeaderCount: 5 -# CHECK-NEXT: StringTableSectionIndex: 3 +# CHECK-NEXT: SectionHeaderCount: 6 +# CHECK-NEXT: StringTableSectionIndex: 4 # CHECK-NEXT: } # CHECK-NEXT: Sections [ # CHECK-NEXT: Section { @@ -60,7 +60,7 @@ _start: # CHECK-NEXT: SHF_ALLOC (0x2) # CHECK-NEXT: SHF_EXECINSTR (0x4) # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x11000 +# CHECK-NEXT: Address: 0x201000 # CHECK-NEXT: Offset: 0x1000 # CHECK-NEXT: Size: 16 # CHECK-NEXT: Link: 0 @@ -70,40 +70,56 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 2 +# CHECK-NEXT: Name: .comment +# 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: 0x1010 +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 1 +# CHECK-NEXT: EntrySize: 1 +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: 3 # CHECK-NEXT: Name: .symtab # CHECK-NEXT: Type: SHT_SYMTAB (0x2) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x1010 +# CHECK-NEXT: Offset: 0x1018 # CHECK-NEXT: Size: 48 -# CHECK-NEXT: Link: 4 +# CHECK-NEXT: Link: 5 # CHECK-NEXT: Info: 1 # CHECK-NEXT: AddressAlignment: 8 # CHECK-NEXT: EntrySize: 24 # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 3 +# CHECK-NEXT: Index: 4 # CHECK-NEXT: Name: .shstrtab # CHECK-NEXT: Type: SHT_STRTAB (0x3) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x1040 -# CHECK-NEXT: Size: 33 +# CHECK-NEXT: Offset: 0x1048 +# CHECK-NEXT: Size: 42 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 1 # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 4 -# CHECK-NEXT: Name: .strtab (25) +# CHECK-NEXT: Index: 5 +# CHECK-NEXT: Name: .strtab # CHECK-NEXT: Type: SHT_STRTAB (0x3) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x1061 +# CHECK-NEXT: Offset: 0x1072 # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 @@ -135,8 +151,8 @@ _start: # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_PHDR (0x6) # CHECK-NEXT: Offset: 0x40 -# CHECK-NEXT: VirtualAddress: 0x10040 -# CHECK-NEXT: PhysicalAddress: 0x10040 +# CHECK-NEXT: VirtualAddress: 0x200040 +# CHECK-NEXT: PhysicalAddress: 0x200040 # CHECK-NEXT: FileSize: 224 # CHECK-NEXT: MemSize: 224 # CHECK-NEXT: Flags [ (0x4) @@ -147,8 +163,8 @@ _start: # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD (0x1) # CHECK-NEXT: Offset: 0x0 -# CHECK-NEXT: VirtualAddress: 0x10000 -# CHECK-NEXT: PhysicalAddress: 0x10000 +# CHECK-NEXT: VirtualAddress: 0x200000 +# CHECK-NEXT: PhysicalAddress: 0x200000 # CHECK-NEXT: FileSize: 288 # CHECK-NEXT: MemSize: 288 # CHECK-NEXT: Flags [ @@ -159,8 +175,8 @@ _start: # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_LOAD (0x1) # CHECK-NEXT: Offset: 0x1000 -# CHECK-NEXT: VirtualAddress: 0x11000 -# CHECK-NEXT: PhysicalAddress: 0x11000 +# CHECK-NEXT: VirtualAddress: 0x201000 +# CHECK-NEXT: PhysicalAddress: 0x201000 # CHECK-NEXT: FileSize: 16 # CHECK-NEXT: MemSize: 16 # CHECK-NEXT: Flags [ (0x5) @@ -207,24 +223,28 @@ _start: # RUN: not ld.lld -o %t2 2>&1 | \ # RUN: FileCheck --check-prefix=NO_INPUT %s -# NO_INPUT: no input files. +# NO_INPUT: ld.lld{{.*}}: no input files # RUN: not ld.lld %t.no.such.file -o %t2 2>&1 | \ # RUN: FileCheck --check-prefix=CANNOT_OPEN %s # CANNOT_OPEN: cannot open {{.*}}.no.such.file: {{[Nn]}}o such file or directory # RUN: not ld.lld %t -o 2>&1 | FileCheck --check-prefix=NO_O_VAL %s -# NO_O_VAL: missing arg value for "-o", expected 1 argument. +# NO_O_VAL: -o: missing argument # RUN: not ld.lld --foo 2>&1 | FileCheck --check-prefix=UNKNOWN %s # UNKNOWN: unknown argument: --foo # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: not ld.lld %t %t -o %t2 2>&1 | FileCheck --check-prefix=DUP %s -# DUP: duplicate symbol: _start in {{.*}} and {{.*}} +# DUP: {{.*}}:(.text+0x0): duplicate symbol '_start' +# DUP: {{.*}}:(.text+0x0): previous definition was here + +# RUN: not ld.lld %t -o %t -m wrong_emul_fbsd 2>&1 | FileCheck --check-prefix=UNKNOWN_EMUL %s +# UNKNOWN_EMUL: unknown emulation: wrong_emul_fbsd -# RUN: not ld.lld %t -o %t -m wrong_emul 2>&1 | FileCheck --check-prefix=UNKNOWN_EMUL %s -# UNKNOWN_EMUL: unknown emulation: wrong_emul +# RUN: not ld.lld %t --lto-partitions=0 2>&1 | FileCheck --check-prefix=NOTHREADS %s +# NOTHREADS: --lto-partitions: number of threads must be > 0 -# RUN: not ld.lld %t --lto-jobs=0 2>&1 | FileCheck --check-prefix=NOTHREADS %s -# NOTHREADS: number of threads must be > 0 +# RUN: not ld.lld %t --thinlto-jobs=0 2>&1 | FileCheck --check-prefix=NOTHREADSTHIN %s +# NOTHREADSTHIN: --thinlto-jobs: number of threads must be > 0 diff --git a/test/ELF/basic32.s b/test/ELF/basic32.s index 44ebe7a462250..e68ed73e637db 100644 --- a/test/ELF/basic32.s +++ b/test/ELF/basic32.s @@ -25,15 +25,15 @@ _start: # CHECK-NEXT: Version: 1 # CHECK-NEXT: Entry: 0x11000 # CHECK-NEXT: ProgramHeaderOffset: 0x34 -# CHECK-NEXT: SectionHeaderOffset: 0x1058 +# CHECK-NEXT: SectionHeaderOffset: 0x1068 # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 52 # CHECK-NEXT: ProgramHeaderEntrySize: 32 # CHECK-NEXT: ProgramHeaderCount: 4 # CHECK-NEXT: SectionHeaderEntrySize: 40 -# CHECK-NEXT: SectionHeaderCount: 5 -# CHECK-NEXT: StringTableSectionIndex: 3 +# CHECK-NEXT: SectionHeaderCount: 6 +# CHECK-NEXT: StringTableSectionIndex: 4 # CHECK-NEXT: } # CHECK-NEXT: Sections [ # CHECK-NEXT: Section { @@ -68,40 +68,56 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 2 +# CHECK-NEXT: Name: .comment +# 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: 0x100C +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 1 +# CHECK-NEXT: EntrySize: 1 +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: 3 # CHECK-NEXT: Name: .symtab # CHECK-NEXT: Type: SHT_SYMTAB # CHECK-NEXT: Flags [ # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x100C +# CHECK-NEXT: Offset: 0x1014 # CHECK-NEXT: Size: 32 -# CHECK-NEXT: Link: 4 +# CHECK-NEXT: Link: 5 # CHECK-NEXT: Info: 1 # CHECK-NEXT: AddressAlignment: 4 # CHECK-NEXT: EntrySize: 16 # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 3 +# CHECK-NEXT: Index: 4 # CHECK-NEXT: Name: .shstrtab # CHECK-NEXT: Type: SHT_STRTAB (0x3) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x102C -# CHECK-NEXT: Size: 33 +# CHECK-NEXT: Offset: 0x1034 +# CHECK-NEXT: Size: 42 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 1 # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 4 -# CHECK-NEXT: Name: .strtab (25) +# CHECK-NEXT: Index: 5 +# CHECK-NEXT: Name: .strtab # CHECK-NEXT: Type: SHT_STRTAB (0x3) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x104D +# CHECK-NEXT: Offset: 0x105E # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 diff --git a/test/ELF/basic64be.s b/test/ELF/basic64be.s index fb0bf7bfdb80a..1ad982f048673 100644 --- a/test/ELF/basic64be.s +++ b/test/ELF/basic64be.s @@ -38,15 +38,15 @@ _start: # CHECK-NEXT: Version: 1 # CHECK-NEXT: Entry: 0x10020040 # CHECK-NEXT: ProgramHeaderOffset: 0x40 -# CHECK-NEXT: SectionHeaderOffset: 0x200C8 +# CHECK-NEXT: SectionHeaderOffset: 0x200D8 # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: HeaderSize: 64 # CHECK-NEXT: ProgramHeaderEntrySize: 56 # CHECK-NEXT: ProgramHeaderCount: 6 # CHECK-NEXT: SectionHeaderEntrySize: 64 -# CHECK-NEXT: SectionHeaderCount: 9 -# CHECK-NEXT: StringTableSectionIndex: 7 +# CHECK-NEXT: SectionHeaderCount: 10 +# CHECK-NEXT: StringTableSectionIndex: 8 # CHECK-NEXT: } # CHECK-NEXT: Sections [ # CHECK-NEXT: Section { @@ -67,7 +67,7 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 1 -# CHECK-NEXT: Name: .text (1) +# CHECK-NEXT: Name: .text # CHECK-NEXT: Type: SHT_PROGBITS (0x1) # CHECK-NEXT: Flags [ (0x6) # CHECK-NEXT: SHF_ALLOC (0x2) @@ -163,14 +163,33 @@ _start: # CHECK-NEXT: } # CHECK-NEXT: Section { # CHECK-NEXT: Index: 6 +# CHECK-NEXT: Name: .comment +# 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: 0x20058 +# 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 # CHECK-NEXT: Type: SHT_SYMTAB (0x2) # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x20058 +# CHECK-NEXT: Offset: 0x20060 # CHECK-NEXT: Size: 48 -# CHECK-NEXT: Link: 8 +# CHECK-NEXT: Link: 9 # CHECK-NEXT: Info: 1 # CHECK-NEXT: AddressAlignment: 8 # CHECK-NEXT: EntrySize: 24 @@ -178,14 +197,14 @@ _start: # CHECK: ) # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 7 +# CHECK-NEXT: Index: 8 # CHECK-NEXT: Name: .shstrtab # CHECK-NEXT: Type: SHT_STRTAB # CHECK-NEXT: Flags [ # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x20088 -# CHECK-NEXT: Size: 54 +# CHECK-NEXT: Offset: 0x20090 +# CHECK-NEXT: Size: 63 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 1 @@ -194,13 +213,13 @@ _start: # CHECK: ) # CHECK-NEXT: } # CHECK-NEXT: Section { -# CHECK-NEXT: Index: 8 +# CHECK-NEXT: Index: 9 # CHECK-NEXT: Name: .strtab # CHECK-NEXT: Type: SHT_STRTAB # CHECK-NEXT: Flags [ (0x0) # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 -# CHECK-NEXT: Offset: 0x200BE +# CHECK-NEXT: Offset: 0x200CF # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 diff --git a/test/ELF/bss.s b/test/ELF/bss.s index d0b43ec5a2625..abd7f2e564d74 100644 --- a/test/ELF/bss.s +++ b/test/ELF/bss.s @@ -11,14 +11,24 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x11000 -// CHECK-NEXT: Offset: 0x1000 +// CHECK-NEXT: Address: +// CHECK-NEXT: Offset: 0x[[OFFSET:.*]] // CHECK-NEXT: Size: 4 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: // CHECK-NEXT: EntrySize: 0 // CHECK-NEXT: } +// CHECK-NEXT: Section { +// CHECK-NEXT: Index: +// CHECK-NEXT: Name: +// CHECK-NEXT: Type: +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_MERGE +// CHECK-NEXT: SHF_STRINGS +// CHECK-NEXT: ] +// CHECK-NEXT: Address: +// CHECK-NEXT: Offset: 0x[[OFFSET]] .global _start _start: diff --git a/test/ELF/bsymbolic-undef.s b/test/ELF/bsymbolic-undef.s index 6590bbcb50b7c..19bb3162fd95a 100644 --- a/test/ELF/bsymbolic-undef.s +++ b/test/ELF/bsymbolic-undef.s @@ -4,7 +4,7 @@ # CHECK: DynamicSymbols [ # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: @ (0) +# CHECK-NEXT: Name: @ # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Local (0x0) @@ -13,7 +13,7 @@ # CHECK-NEXT: Section: Undefined (0x0) # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: undef@ (1) +# CHECK-NEXT: Name: undef@ # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Global (0x1) diff --git a/test/ELF/bsymbolic.s b/test/ELF/bsymbolic.s index d713588d59528..5a089d55492d0 100644 --- a/test/ELF/bsymbolic.s +++ b/test/ELF/bsymbolic.s @@ -25,7 +25,7 @@ nop .globl do .type do,@function -do: +do: callq foo@PLT callq bar@PLT diff --git a/test/ELF/build-id.s b/test/ELF/build-id.s index f1eac42812b4e..51758d9eb24a7 100644 --- a/test/ELF/build-id.s +++ b/test/ELF/build-id.s @@ -1,16 +1,36 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: ld.lld --build-id %t -o %t2 + +# RUN: ld.lld --build-id %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 -# RUN: ld.lld --build-id=md5 %t -o %t2 + +# RUN: ld.lld --build-id=md5 %t -o %t2 -threads +# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=MD5 %s +# RUN: ld.lld --build-id=md5 %t -o %t2 -no-threads # RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=MD5 %s -# RUN: ld.lld --build-id=sha1 %t -o %t2 + +# RUN: ld.lld --build-id=sha1 %t -o %t2 -threads +# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SHA1 %s +# RUN: ld.lld --build-id=sha1 %t -o %t2 -no-threads +# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SHA1 %s + +# RUN: ld.lld --build-id=tree %t -o %t2 -threads # RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SHA1 %s +# RUN: ld.lld --build-id=tree %t -o %t2 -no-threads +# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SHA1 %s + +# RUN: ld.lld --build-id=uuid %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=UUID %s + # RUN: ld.lld --build-id=0x12345678 %t -o %t2 # RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=HEX %s + # RUN: ld.lld %t -o %t2 # RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=NONE %s + # RUN: ld.lld --build-id=md5 --build-id=none %t -o %t2 # RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=NONE %s @@ -21,15 +41,21 @@ _start: .section .note.test, "a", @note .quad 42 +# DEFAULT: Contents of section .note.test: # DEFAULT: Contents of section .note.gnu.build-id: # DEFAULT-NEXT: 04000000 08000000 03000000 474e5500 ............GNU. -# DEFAULT: Contents of section .note.test: +# DEFAULT-NEXT: d08dafb4 e6294b62 # MD5: Contents of section .note.gnu.build-id: # MD5-NEXT: 04000000 10000000 03000000 474e5500 ............GNU. +# MD5-NEXT: 37 # SHA1: Contents of section .note.gnu.build-id: # SHA1-NEXT: 04000000 14000000 03000000 474e5500 ............GNU. +# SHA1-NEXT: 7a4f4eaf 69ceb948 4a7d6e51 2225e87c + +# UUID: Contents of section .note.gnu.build-id: +# UUID-NEXT: 04000000 10000000 03000000 474e5500 ............GNU. # HEX: Contents of section .note.gnu.build-id: # HEX-NEXT: 04000000 04000000 03000000 474e5500 ............GNU. diff --git a/test/ELF/color-diagnostics.test b/test/ELF/color-diagnostics.test new file mode 100644 index 0000000000000..074bba29c54a9 --- /dev/null +++ b/test/ELF/color-diagnostics.test @@ -0,0 +1,18 @@ +# Windows command prompt doesn't support ANSI escape sequences. +# REQUIRES: shell + +# RUN: not ld.lld -xyz -color-diagnostics /nosuchfile 2>&1 \ +# RUN: | FileCheck -check-prefix=COLOR %s +# RUN: not ld.lld -xyz -color-diagnostics=always /nosuchfile 2>&1 \ +# RUN: | FileCheck -check-prefix=COLOR %s + +# COLOR: {{ld.lld: .\[0;1;31merror: .\[0munknown argument: -xyz}} +# COLOR: {{ld.lld: .\[0;1;31merror: .\[0mcannot open /nosuchfile}} + +# 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 +# RUN: not ld.lld -color-diagnostics=always -no-color-diagnostics \ +# RUN: /nosuchfile 2>&1 | FileCheck -check-prefix=NOCOLOR %s + +# NOCOLOR: ld.lld: error: cannot open /nosuchfile diff --git a/test/ELF/comdat.s b/test/ELF/comdat.s index d422ee8fba336..5b190b177ee0a 100644 --- a/test/ELF/comdat.s +++ b/test/ELF/comdat.s @@ -5,6 +5,15 @@ // 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 + .section .text2,"axG",@progbits,foo,comdat,unique,0 foo: nop diff --git a/test/ELF/comment-gc.s b/test/ELF/comment-gc.s new file mode 100644 index 0000000000000..8018ff89bbf9b --- /dev/null +++ b/test/ELF/comment-gc.s @@ -0,0 +1,15 @@ +# 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/comment-gc.s -o %t2.o +# RUN: ld.lld %t.o %t2.o -o %t1 --gc-sections -shared +# RUN: llvm-objdump -s %t1 | FileCheck %s + +# CHECK: Contents of section .comment: +# CHECK-NEXT: 0000 00666f6f 00626172 004c4c44 20312e30 .foo.bar.LLD 1.0 +# CHECK-NEXT: 0010 00 . + +.ident "foo" + +.globl _start +_start: + nop diff --git a/test/ELF/common.s b/test/ELF/common.s index f16f948fe64e3..c8011a0a5088f 100644 --- a/test/ELF/common.s +++ b/test/ELF/common.s @@ -10,7 +10,7 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x11000 +// CHECK-NEXT: Address: 0x201000 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 22 // CHECK-NEXT: Link: 0 @@ -18,7 +18,7 @@ // CHECK-NEXT: AddressAlignment: 16 // CHECK: Name: sym1 -// CHECK-NEXT: Value: 0x11004 +// CHECK-NEXT: Value: 0x201004 // CHECK-NEXT: Size: 8 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -26,7 +26,7 @@ // CHECK-NEXT: Section: .bss // CHECK: Name: sym2 -// CHECK-NEXT: Value: 0x1100C +// CHECK-NEXT: Value: 0x20100C // CHECK-NEXT: Size: 8 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -34,7 +34,7 @@ // CHECK-NEXT: Section: .bss // CHECK: Name: sym3 -// CHECK-NEXT: Value: 0x11014 +// CHECK-NEXT: Value: 0x201014 // CHECK-NEXT: Size: 2 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -42,7 +42,7 @@ // CHECK-NEXT: Section: .bss // CHECK: Name: sym4 -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: 0x201000 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object diff --git a/test/ELF/compressed-debug-input.s b/test/ELF/compressed-debug-input.s index 7339833dbb7f7..5104a102ba300 100644 --- a/test/ELF/compressed-debug-input.s +++ b/test/ELF/compressed-debug-input.s @@ -1,52 +1,73 @@ # REQUIRES: zlib # RUN: llvm-mc -compress-debug-sections=zlib -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: llvm-readobj -sections %t | FileCheck -check-prefix=COMPRESSED %s +# RUN: llvm-readobj -sections %t | FileCheck -check-prefix=ZLIB %s +# ZLIB: Section { +# ZLIB: Index: 2 +# ZLIB: Name: .debug_str +# ZLIB-NEXT: Type: SHT_PROGBITS +# ZLIB-NEXT: Flags [ +# ZLIB-NEXT: SHF_COMPRESSED (0x800) +# ZLIB-NEXT: SHF_MERGE (0x10) +# ZLIB-NEXT: SHF_STRINGS (0x20) +# ZLIB-NEXT: ] +# ZLIB-NEXT: Address: +# ZLIB-NEXT: Offset: +# ZLIB-NEXT: Size: +# ZLIB-NEXT: Link: +# ZLIB-NEXT: Info: +# ZLIB-NEXT: AddressAlignment: 1 +# ZLIB-NEXT: EntrySize: 1 +# ZLIB-NEXT: } -# COMPRESSED: Section { -# COMPRESSED: Index: 2 -# COMPRESSED: Name: .debug_str -# COMPRESSED-NEXT: Type: SHT_PROGBITS -# COMPRESSED-NEXT: Flags [ -# COMPRESSED-NEXT: SHF_COMPRESSED (0x800) -# COMPRESSED-NEXT: SHF_MERGE (0x10) -# COMPRESSED-NEXT: SHF_STRINGS (0x20) -# COMPRESSED-NEXT: ] -# COMPRESSED-NEXT: Address: -# COMPRESSED-NEXT: Offset: -# COMPRESSED-NEXT: Size: 66 -# COMPRESSED-NEXT: Link: -# COMPRESSED-NEXT: Info: -# COMPRESSED-NEXT: AddressAlignment: 1 -# COMPRESSED-NEXT: EntrySize: 1 -# COMPRESSED-NEXT: } +# RUN: llvm-mc -compress-debug-sections=zlib-gnu -filetype=obj -triple=x86_64-unknown-linux %s -o %t2 +# RUN: llvm-readobj -sections %t2 | FileCheck -check-prefix=GNU %s +# GNU: Section { +# GNU: Index: 2 +# GNU: Name: .zdebug_str +# GNU-NEXT: Type: SHT_PROGBITS +# GNU-NEXT: Flags [ +# GNU-NEXT: SHF_MERGE (0x10) +# GNU-NEXT: SHF_STRINGS (0x20) +# GNU-NEXT: ] +# GNU-NEXT: Address: +# GNU-NEXT: Offset: +# GNU-NEXT: Size: +# GNU-NEXT: Link: +# GNU-NEXT: Info: +# GNU-NEXT: AddressAlignment: 1 +# GNU-NEXT: EntrySize: 1 +# GNU-NEXT: } # RUN: ld.lld %t -o %t.so -shared -# RUN: llvm-readobj -sections -section-data %t.so | FileCheck -check-prefix=UNCOMPRESSED %s +# RUN: llvm-readobj -sections -section-data %t.so | FileCheck -check-prefix=DATA %s -# UNCOMPRESSED: Section { -# UNCOMPRESSED: Index: 6 -# UNCOMPRESSED: Name: .debug_str -# UNCOMPRESSED-NEXT: Type: SHT_PROGBITS -# UNCOMPRESSED-NEXT: Flags [ -# UNCOMPRESSED-NEXT: SHF_MERGE (0x10) -# UNCOMPRESSED-NEXT: SHF_STRINGS (0x20) -# UNCOMPRESSED-NEXT: ] -# UNCOMPRESSED-NEXT: Address: 0x0 -# UNCOMPRESSED-NEXT: Offset: 0x1060 -# UNCOMPRESSED-NEXT: Size: 69 -# UNCOMPRESSED-NEXT: Link: 0 -# UNCOMPRESSED-NEXT: Info: 0 -# UNCOMPRESSED-NEXT: AddressAlignment: 1 -# UNCOMPRESSED-NEXT: EntrySize: 1 -# UNCOMPRESSED-NEXT: SectionData ( -# UNCOMPRESSED-NEXT: 0000: 73686F72 7420756E 7369676E 65642069 |short unsigned i| -# UNCOMPRESSED-NEXT: 0010: 6E740075 6E736967 6E656420 696E7400 |nt.unsigned int.| -# UNCOMPRESSED-NEXT: 0020: 6C6F6E67 20756E73 69676E65 6420696E |long unsigned in| -# UNCOMPRESSED-NEXT: 0030: 74006368 61720075 6E736967 6E656420 |t.char.unsigned | -# UNCOMPRESSED-NEXT: 0040: 63686172 00 |char.| -# UNCOMPRESSED-NEXT: ) -# UNCOMPRESSED-NEXT: } +# RUN: ld.lld %t2 -o %t2.so -shared +# RUN: llvm-readobj -sections -section-data %t2.so | FileCheck -check-prefix=DATA %s + +# DATA: Section { +# DATA: Index: 6 +# DATA: Name: .debug_str +# DATA-NEXT: Type: SHT_PROGBITS +# DATA-NEXT: Flags [ +# DATA-NEXT: SHF_MERGE (0x10) +# DATA-NEXT: SHF_STRINGS (0x20) +# DATA-NEXT: ] +# DATA-NEXT: Address: 0x0 +# DATA-NEXT: Offset: 0x1060 +# DATA-NEXT: Size: 69 +# DATA-NEXT: Link: 0 +# DATA-NEXT: Info: 0 +# DATA-NEXT: AddressAlignment: 1 +# DATA-NEXT: EntrySize: 1 +# DATA-NEXT: SectionData ( +# DATA-NEXT: 0000: 73686F72 7420756E 7369676E 65642069 |short unsigned i| +# DATA-NEXT: 0010: 6E740075 6E736967 6E656420 696E7400 |nt.unsigned int.| +# DATA-NEXT: 0020: 6C6F6E67 20756E73 69676E65 6420696E |long unsigned in| +# DATA-NEXT: 0030: 74006368 61720075 6E736967 6E656420 |t.char.unsigned | +# DATA-NEXT: 0040: 63686172 00 |char.| +# DATA-NEXT: ) +# DATA-NEXT: } .section .debug_str,"MS",@progbits,1 .LASF2: diff --git a/test/ELF/conflict.s b/test/ELF/conflict.s index 7598eea3711c9..b9bb50515c5c9 100644 --- a/test/ELF/conflict.s +++ b/test/ELF/conflict.s @@ -1,22 +1,38 @@ -# REQUIRES: x86, shell +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o # RUN: not ld.lld %t1.o %t1.o -o %t2 2>&1 | FileCheck -check-prefix=DEMANGLE %s -# DEMANGLE: duplicate symbol: mul(double, double) in -# DEMANGLE: duplicate symbol: foo in +# DEMANGLE: {{.*}}:(.text+0x0): duplicate symbol 'mul(double, double)' +# DEMANGLE-NEXT: {{.*}}:(.text+0x0): previous definition was here +# DEMANGLE-NEXT: {{.*}}:(.text+0x0): duplicate symbol 'foo' +# DEMANGLE-NEXT: {{.*}}:(.text+0x0): previous definition was here # RUN: not ld.lld %t1.o %t1.o -o %t2 --no-demangle 2>&1 | \ # RUN: FileCheck -check-prefix=NO_DEMANGLE %s -# NO_DEMANGLE: duplicate symbol: _Z3muldd in -# NO_DEMANGLE: duplicate symbol: foo in +# NO_DEMANGLE: {{.*}}:(.text+0x0): duplicate symbol '_Z3muldd' +# NO_DEMANGLE-NEXT: {{.*}}:(.text+0x0): previous definition was here +# NO_DEMANGLE-NEXT: {{.*}}:(.text+0x0): duplicate symbol 'foo' +# NO_DEMANGLE-NEXT: {{.*}}:(.text+0x0): previous definition was here + +# RUN: not ld.lld %t1.o %t1.o -o %t2 --demangle --no-demangle 2>&1 | \ +# RUN: FileCheck -check-prefix=NO_DEMANGLE %s +# RUN: not ld.lld %t1.o %t1.o -o %t2 --no-demangle --demangle 2>&1 | \ +# RUN: FileCheck -check-prefix=DEMANGLE %s # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/conflict.s -o %t2.o # RUN: llvm-ar rcs %t3.a %t2.o # RUN: not ld.lld %t1.o %t3.a -u baz -o %t2 2>&1 | FileCheck -check-prefix=ARCHIVE %s -# ARCHIVE: duplicate symbol: foo in {{.*}}1.o and {{.*}}3.a({{.*}}2.o) +# ARCHIVE: {{.*}}3.a({{.*}}2.o):(.text+0x0): duplicate symbol 'foo' +# ARCHIVE-NEXT: {{.*}}1.o:(.text+0x0): previous definition was here + +# 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 + +# DBGINFO: conflict-debug.s:4: duplicate symbol 'zed' +# DBGINFO-NEXT: conflict-debug.s:4: previous definition was here .globl _Z3muldd, foo _Z3muldd: diff --git a/test/ELF/copy-errors.s b/test/ELF/copy-errors.s index 9d8b72ddb43bb..b0d56c9c6c641 100644 --- a/test/ELF/copy-errors.s +++ b/test/ELF/copy-errors.s @@ -9,7 +9,7 @@ _start: call bar -// CHECK: cannot preempt symbol +// CHECK: {{.*}}.o:(.text+0x1): cannot preempt symbol 'bar' defined in {{.*}}.so call zed -// CHECK: symbol is missing type +// CHECK: symbol 'zed' defined in {{.*}}.so is missing type diff --git a/test/ELF/copy-in-shared.s b/test/ELF/copy-in-shared.s index 4114d95fb1014..b8e57ce9e7034 100644 --- a/test/ELF/copy-in-shared.s +++ b/test/ELF/copy-in-shared.s @@ -7,4 +7,4 @@ .quad foo -// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment +// CHECK: {{.*}}.o:(.text+0x0): can't create dynamic relocation R_X86_64_64 against symbol 'foo' defined in {{.*}}.so diff --git a/test/ELF/copy-rel-corrupted.s b/test/ELF/copy-rel-corrupted.s index a3f72f71c1daa..3cdad7cf80372 100644 --- a/test/ELF/copy-rel-corrupted.s +++ b/test/ELF/copy-rel-corrupted.s @@ -3,7 +3,7 @@ // RUN: ld.lld %t2.o -o %t2.so -shared // RUN: not ld.lld %t.o %t2.so -o %t.exe 2>&1 | FileCheck %s -// CHECK: cannot create a copy relocation for x +// CHECK: error: cannot create a copy relocation for symbol x .global _start _start: diff --git a/test/ELF/copy-rel-pie-error.s b/test/ELF/copy-rel-pie-error.s index 1f427023baa58..7cb6700ef9f33 100644 --- a/test/ELF/copy-rel-pie-error.s +++ b/test/ELF/copy-rel-pie-error.s @@ -3,8 +3,8 @@ // 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 -// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment -// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment +// CHECK: {{.*}}.o:(.text+0x0): can't create dynamic relocation R_X86_64_64 against symbol 'bar' defined in {{.*}}.so +// CHECK: {{.*}}.o:(.text+0x8): can't create dynamic relocation R_X86_64_64 against symbol 'foo' defined in {{.*}}.so .global _start _start: diff --git a/test/ELF/debug-gc.s b/test/ELF/debug-gc.s new file mode 100644 index 0000000000000..8bcfde16a7b79 --- /dev/null +++ b/test/ELF/debug-gc.s @@ -0,0 +1,30 @@ +# 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 -s %t1 | FileCheck %s + +# CHECK: Contents of section .debug_str: +# CHECK-NEXT: 0000 41414100 42424200 43434300 AAA.BBB.CCC. +# CHECK: Contents of section .foo: +# CHECK-NEXT: 0000 2a000000 +# CHECK: Contents of section .debug_info: +# CHECK-NEXT: 0000 00000000 04000000 + +.globl _start +_start: + +.section .debug_str,"MS",@progbits,1 +.Linfo_string0: + .asciz "AAA" +.Linfo_string1: + .asciz "BBB" +.Linfo_string2: + .asciz "CCC" + +.section .foo,"M",@progbits,4 +.p2align 2 + .long 42 + +.section .debug_info,"",@progbits + .long .Linfo_string0 + .long .Linfo_string1 diff --git a/test/ELF/defined-tls_get_addr.s b/test/ELF/defined-tls_get_addr.s new file mode 100644 index 0000000000000..509c293cca1d8 --- /dev/null +++ b/test/ELF/defined-tls_get_addr.s @@ -0,0 +1,10 @@ +// RUN: llvm-mc %s -o %t.o -triple x86_64-pc-linux -filetype=obj +// RUN: ld.lld %t.o -o %t + +// Don't error if __tls_get_addr is defined. + +.global _start +.global __tls_get_addr +_start: +__tls_get_addr: +nop diff --git a/test/ELF/discard-locals.s b/test/ELF/discard-locals.s index 073e891c3143b..9deaccff11c71 100644 --- a/test/ELF/discard-locals.s +++ b/test/ELF/discard-locals.s @@ -40,7 +40,7 @@ _start: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None diff --git a/test/ELF/discard-none.s b/test/ELF/discard-none.s index e3a7a2032082b..89e06fd7b7e4b 100644 --- a/test/ELF/discard-none.s +++ b/test/ELF/discard-none.s @@ -36,7 +36,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: .Lmyothervar -// CHECK-NEXT: Value: 0x1000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -45,7 +45,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: .Lmyvar -// CHECK-NEXT: Value: 0x1000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None diff --git a/test/ELF/dont-export-hidden.s b/test/ELF/dont-export-hidden.s index 8819a6e99fdb1..8088c8d94d894 100644 --- a/test/ELF/dont-export-hidden.s +++ b/test/ELF/dont-export-hidden.s @@ -18,7 +18,7 @@ foo: // CHECK: DynamicSymbols [ // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: @ (0) +// CHECK-NEXT: Name: @ // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local diff --git a/test/ELF/driver.test b/test/ELF/driver.test index 95e2100b4abf7..80d19cb4d6a8e 100644 --- a/test/ELF/driver.test +++ b/test/ELF/driver.test @@ -19,6 +19,8 @@ # RUN: ld.lld --version 2>&1 | FileCheck -check-prefix=VERSION %s # VERSION: LLD +# RUN: not ld.lld -v 2>&1 | FileCheck -check-prefix=VERSION %s + ## Attempt to link DSO with -r # RUN: ld.lld -shared %t -o %t.so # RUN: not ld.lld -r %t.so %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR %s @@ -44,6 +46,14 @@ # 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 +## "--output=foo" is equivalent to "-o foo". +# RUN: not ld.lld %t --output=/no/such/file 2>&1 | FileCheck -check-prefix=ERR7 %s +# ERR7: failed to open /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: failed to open utput=/no/such/file + .globl _start _start: nop diff --git a/test/ELF/duplicate-internal.s b/test/ELF/duplicate-internal.s deleted file mode 100644 index d1ccf5322127d..0000000000000 --- a/test/ELF/duplicate-internal.s +++ /dev/null @@ -1,11 +0,0 @@ -# Should print an expected message in case of conflict with an internally generated symbol. - -# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o -# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s - -# CHECK: duplicate symbol: _gp in {{.*}} and (internal) - -# REQUIRES: mips - - .globl _gp -_gp = 0 diff --git a/test/ELF/dynamic-got-rela.s b/test/ELF/dynamic-got-rela.s new file mode 100644 index 0000000000000..0aeb6d477a26e --- /dev/null +++ b/test/ELF/dynamic-got-rela.s @@ -0,0 +1,34 @@ +// 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 + +// 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: ) + +// CHECK: Relocations [ +// CHECK-NEXT: Section ({{.*}}) .rela.dyn { +// CHECK-NEXT: 0x[[GOT]] R_X86_64_RELATIVE - 0x[[ADDEND:.*]] +// CHECK-NEXT: } +// CHECK-NEXT: ] + +// CHECK: Type: PT_DYNAMIC +// CHECK-NEXT: Offset: 0x[[ADDEND]] +// CHECK-NEXT: VirtualAddress: 0x[[ADDEND]] +// CHECK-NEXT: PhysicalAddress: 0x[[ADDEND]] + +cmpq $0, _DYNAMIC@GOTPCREL(%rip) diff --git a/test/ELF/dynamic-got.s b/test/ELF/dynamic-got.s new file mode 100644 index 0000000000000..c50c9022329ae --- /dev/null +++ b/test/ELF/dynamic-got.s @@ -0,0 +1,39 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t.o +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-readobj -s -l -section-data -r %t.so | FileCheck %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: +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: +// CHECK-NEXT: Link: +// CHECK-NEXT: Info: +// CHECK-NEXT: AddressAlignment: +// CHECK-NEXT: EntrySize: +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 00200000 | +// CHECK-NEXT: ) + +// CHECK: Relocations [ +// CHECK-NEXT: Section ({{.*}}) .rel.dyn { +// CHECK-NEXT: 0x2050 R_386_RELATIVE - 0x0 +// CHECK-NEXT: } +// CHECK-NEXT: ] + +// CHECK: Type: PT_DYNAMIC +// CHECK-NEXT: Offset: 0x2000 +// CHECK-NEXT: VirtualAddress: 0x2000 +// CHECK-NEXT: PhysicalAddress: 0x2000 + + calll .L0$pb +.L0$pb: + popl %eax +.Ltmp0: + addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %eax + movl _DYNAMIC@GOT(%eax), %eax diff --git a/test/ELF/dynamic-list-extern.s b/test/ELF/dynamic-list-extern.s new file mode 100644 index 0000000000000..dfeb31d4fc078 --- /dev/null +++ b/test/ELF/dynamic-list-extern.s @@ -0,0 +1,15 @@ +# REQUIRES: x86 + +# Test that we can parse multiple externs. + +# 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: ld.lld --dynamic-list %t.list %t.o -shared -o %t.so diff --git a/test/ELF/dynamic-list.s b/test/ELF/dynamic-list.s index 5e257b31d1f35..e2472e716b3f6 100644 --- a/test/ELF/dynamic-list.s +++ b/test/ELF/dynamic-list.s @@ -2,8 +2,6 @@ ## implemented in Python, and the Cygwin implementations of the Unix utilities. ## Avoid running these tests on Windows for now by requiring a real shell. -# REQUIRES: shell - # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o @@ -29,7 +27,7 @@ # CHECK: DynamicSymbols [ # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: @ (0) +# CHECK-NEXT: Name: @ # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Local @@ -38,15 +36,15 @@ # CHECK-NEXT: Section: Undefined # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: foo1@ (1) -# CHECK-NEXT: Value: 0x11000 +# CHECK-NEXT: Name: foo1@ +# CHECK-NEXT: Value: 0x201000 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Global (0x1) # CHECK-NEXT: Type: None (0x0) # CHECK-NEXT: Other: 0 # CHECK-NEXT: Section: .text (0x4) # CHECK-NEXT: } -# CHECK-NEXT: ] +# CHECK-NEXT: ] ## Now export all the foo1, foo2, and foo31 symbols @@ -56,7 +54,7 @@ # CHECK2: DynamicSymbols [ # CHECK2-NEXT: Symbol { -# CHECK2-NEXT: Name: @ (0) +# CHECK2-NEXT: Name: @ # CHECK2-NEXT: Value: 0x0 # CHECK2-NEXT: Size: 0 # CHECK2-NEXT: Binding: Local @@ -65,8 +63,8 @@ # CHECK2-NEXT: Section: Undefined # CHECK2-NEXT: } # CHECK2-NEXT: Symbol { -# CHECK2-NEXT: Name: foo1@ (1) -# CHECK2-NEXT: Value: 0x11000 +# CHECK2-NEXT: Name: foo1@ +# CHECK2-NEXT: Value: 0x201000 # CHECK2-NEXT: Size: 0 # CHECK2-NEXT: Binding: Global (0x1) # CHECK2-NEXT: Type: None (0x0) @@ -74,8 +72,8 @@ # CHECK2-NEXT: Section: .text (0x4) # CHECK2-NEXT: } # CHECK2-NEXT: Symbol { -# CHECK2-NEXT: Name: foo2@ (6) -# CHECK2-NEXT: Value: 0x11001 +# CHECK2-NEXT: Name: foo2@ +# CHECK2-NEXT: Value: 0x201001 # CHECK2-NEXT: Size: 0 # CHECK2-NEXT: Binding: Global (0x1) # CHECK2-NEXT: Type: None (0x0) @@ -83,15 +81,15 @@ # CHECK2-NEXT: Section: .text (0x4) # CHECK2-NEXT: } # CHECK2-NEXT: Symbol { -# CHECK2-NEXT: Name: foo31@ (11) -# CHECK2-NEXT: Value: 0x11002 +# CHECK2-NEXT: Name: foo31@ +# CHECK2-NEXT: Value: 0x201002 # CHECK2-NEXT: Size: 0 # CHECK2-NEXT: Binding: Global (0x1) # CHECK2-NEXT: Type: None (0x0) # CHECK2-NEXT: Other: 0 # CHECK2-NEXT: Section: .text (0x4) # CHECK2-NEXT: } -# CHECK2-NEXT: ] +# CHECK2-NEXT: ] .globl foo1 foo1: diff --git a/test/ELF/dynamic-reloc-in-ro.s b/test/ELF/dynamic-reloc-in-ro.s index 2ef36f695fb60..682dbdd8984e0 100644 --- a/test/ELF/dynamic-reloc-in-ro.s +++ b/test/ELF/dynamic-reloc-in-ro.s @@ -5,4 +5,4 @@ foo: .quad foo -// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment +// CHECK: {{.*}}.o:(.text+0x0): can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment defined in {{.*}}.o diff --git a/test/ELF/dynamic-reloc-index.s b/test/ELF/dynamic-reloc-index.s index 2d38c014a307f..ba3c5791beb0f 100644 --- a/test/ELF/dynamic-reloc-index.s +++ b/test/ELF/dynamic-reloc-index.s @@ -8,7 +8,7 @@ // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.plt { -// CHECK-NEXT: 0x13018 R_X86_64_JUMP_SLOT bar 0x0 +// CHECK-NEXT: 0x203018 R_X86_64_JUMP_SLOT bar 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] diff --git a/test/ELF/dynamic-reloc.s b/test/ELF/dynamic-reloc.s index 5e23ba93d5a95..07894cffc90dd 100644 --- a/test/ELF/dynamic-reloc.s +++ b/test/ELF/dynamic-reloc.s @@ -28,12 +28,12 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_EXECINSTR // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x11000 +// CHECK-NEXT: Address: 0x201000 // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.plt { // CHECK-NEXT: Relocation { -// CHECK-NEXT: Offset: 0x13018 +// CHECK-NEXT: Offset: 0x203018 // CHECK-NEXT: Type: R_X86_64_JUMP_SLOT // CHECK-NEXT: Symbol: bar // CHECK-NEXT: Addend: 0x0 @@ -44,6 +44,7 @@ // CHECK: DynamicSection [ // CHECK-NEXT: Tag Type Name/Value // CHECK-NEXT: 0x0000000000000001 NEEDED SharedLibrary ({{.*}}2.so) +// CHECK-NEXT: 0x0000000000000015 DEBUG 0x0 // CHECK-NEXT: 0x0000000000000017 JMPREL // CHECK-NEXT: 0x0000000000000002 PLTRELSZ 24 (bytes) // CHECK-NEXT: 0x0000000000000003 PLTGOT @@ -53,7 +54,6 @@ // CHECK-NEXT: 0x0000000000000005 STRTAB // CHECK-NEXT: 0x000000000000000A STRSZ // CHECK-NEXT: 0x0000000000000004 HASH -// CHECK-NEXT: 0x0000000000000015 DEBUG 0x0 // CHECK-NEXT: 0x0000000000000000 NULL 0x0 // CHECK-NEXT: ] diff --git a/test/ELF/dynamic.s b/test/ELF/dynamic.s index 2efd2990c52c4..0ed7abc146be2 100644 --- a/test/ELF/dynamic.s +++ b/test/ELF/dynamic.s @@ -34,8 +34,8 @@ # CHECK-NEXT: Section: .dynamic # CHECK-NEXT: } -# RUN: ld.lld %t.o -o %t.o -# RUN: llvm-readobj -sections -symbols %t.o | FileCheck -check-prefix=NODYN %s +# RUN: ld.lld %t.o -o %t2 +# RUN: llvm-readobj -sections -symbols %t2 | FileCheck -check-prefix=NODYN %s # NODYN: Symbols [ # NODYN-NOT: Name: _DYNAMIC # NODYN: ] diff --git a/test/ELF/edata-etext.s b/test/ELF/edata-etext.s index e0538d690d7c1..7723adf94e239 100644 --- a/test/ELF/edata-etext.s +++ b/test/ELF/edata-etext.s @@ -1,7 +1,7 @@ # 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 -sections -symbols %t | FileCheck %s +# RUN: llvm-objdump -t -section-headers %t | FileCheck %s ## This checks that: ## 1) Address of _etext is the first location after the last read-only loadable segment. @@ -10,101 +10,24 @@ ## 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. -# CHECK: Section { -# CHECK: Index: 1 -# CHECK: Name: .text -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: SHF_EXECINSTR -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x11000 -# CHECK-NEXT: Offset: 0x1000 -# CHECK-NEXT: Size: 1 -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: 0 -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: 2 -# CHECK-NEXT: Name: .data -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: SHF_WRITE -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x12000 -# CHECK-NEXT: Offset: 0x2000 -# CHECK-NEXT: Size: 2 -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: 3 -# CHECK-NEXT: Name: .bss -# CHECK-NEXT: Type: SHT_NOBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: SHF_WRITE -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x12004 -# CHECK-NEXT: Offset: 0x2002 -# CHECK-NEXT: Size: 6 -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK: Symbols [ -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: -# CHECK-NEXT: Value: 0x0 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Local -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Undefined -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: _start -# CHECK-NEXT: Value: 0x11000 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: .text -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: _edata -# CHECK-NEXT: Value: 0x12002 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Absolute -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: _end -# CHECK-NEXT: Value: 0x1200A -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Absolute -# CHECK-NEXT: } -# CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: _etext -# CHECK-NEXT: Value: 0x11001 -# CHECK-NEXT: Size: 0 -# CHECK-NEXT: Binding: Global -# CHECK-NEXT: Type: None -# CHECK-NEXT: Other: 0 -# CHECK-NEXT: Section: Absolute -# CHECK-NEXT: } -# CHECK-NEXT: ] +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .text 00000001 0000000000201000 TEXT DATA +# CHECK-NEXT: 2 .data 00000002 0000000000202000 DATA +# CHECK-NEXT: 3 .bss 00000006 0000000000202004 BSS +# CHECK: SYMBOL TABLE: +# CHECK-NEXT: 0000000000000000 *UND* 00000000 +# CHECK-NEXT: 0000000000202002 *ABS* 00000000 _edata +# CHECK-NEXT: 000000000020200a *ABS* 00000000 _end +# CHECK-NEXT: 0000000000201001 *ABS* 00000000 _etext +# CHECK-NEXT: 0000000000201000 .text 00000000 _start + +# RUN: ld.lld -r %t.o -o %t2 +# RUN: llvm-objdump -t %t2 | FileCheck %s --check-prefix=RELOCATABLE +# RELOCATABLE: 0000000000000000 *UND* 00000000 _edata +# RELOCATABLE-NEXT: 0000000000000000 *UND* 00000000 _end +# RELOCATABLE-NEXT: 0000000000000000 *UND* 00000000 _etext .global _start,_end,_etext,_edata .text diff --git a/test/ELF/eh-align-cie.s b/test/ELF/eh-align-cie.s index e85cbd27d4fdf..343dea5004f01 100644 --- a/test/ELF/eh-align-cie.s +++ b/test/ELF/eh-align-cie.s @@ -51,7 +51,7 @@ bar: // CHECK-NEXT: EntrySize: // CHECK-NEXT: SectionData ( // CHECK-NEXT: 0000: 1C000000 00000000 017A5052 00017810 -// CHECK-NEXT: 0010: 061B260E 00001B0C 07089001 00000000 -// CHECK-NEXT: 0020: 14000000 24000000 100E0000 00000000 +// CHECK-NEXT: 0010: 061BF60D 00001B0C 07089001 00000000 +// CHECK-NEXT: 0020: 14000000 24000000 E00D0000 00000000 // CHECK-NEXT: 0030: 00000000 00000000 // CHECK-NEXT: ) diff --git a/test/ELF/eh-frame-dyn-rel.s b/test/ELF/eh-frame-dyn-rel.s index 62d56951b2cf6..91baf597c7235 100644 --- a/test/ELF/eh-frame-dyn-rel.s +++ b/test/ELF/eh-frame-dyn-rel.s @@ -7,4 +7,4 @@ .cfi_personality 0x8c, foo .cfi_endproc -// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment +// CHECK: {{.*}}.o:(.eh_frame+0x12): can't create dynamic relocation R_X86_64_64 against symbol 'foo' defined in {{.*}}.o diff --git a/test/ELF/eh-frame-gc2.s b/test/ELF/eh-frame-gc2.s new file mode 100644 index 0000000000000..9cf0d0832d5b6 --- /dev/null +++ b/test/ELF/eh-frame-gc2.s @@ -0,0 +1,15 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o +// RUN: ld.lld --gc-sections %t.o -o %t +// RUN: llvm-readobj -s %t | FileCheck %s + +// Test that the we don't gc the personality function. +// CHECK: Name: .foobar + + .globl _start +_start: + .cfi_startproc + .cfi_personality 3, foobar + .cfi_endproc + .section .foobar,"ax" +foobar: diff --git a/test/ELF/eh-frame-hdr-abs-fde.s b/test/ELF/eh-frame-hdr-abs-fde.s index 37705d6ad8180..dd0836a0ab722 100644 --- a/test/ELF/eh-frame-hdr-abs-fde.s +++ b/test/ELF/eh-frame-hdr-abs-fde.s @@ -9,11 +9,11 @@ # REQUIRES: mips # CHECK: Contents of section .eh_frame_hdr: -# CHECK-NEXT: 10178 011b033b ffffffcc 00000001 0000fe88 -# ^-- 0x20000 - 0x10178 +# CHECK-NEXT: 10148 011b033b 00000010 00000001 0000feb8 +# ^-- 0x20000 - 0x10148 # .text - .eh_frame_hdr -# CHECK-NEXT: 10188 ffffffe8 -# CHECK-NEXT: Contents of section .text: +# CHECK-NEXT: 10158 0000002c +# CHECK: Contents of section .text: # CHECK-NEXT: 20000 00000000 # CHECK: Augmentation: "zLR" diff --git a/test/ELF/eh-frame-hdr-augmentation.s b/test/ELF/eh-frame-hdr-augmentation.s index 91e6a9cc1ccb8..618f5e1a9d7d3 100644 --- a/test/ELF/eh-frame-hdr-augmentation.s +++ b/test/ELF/eh-frame-hdr-augmentation.s @@ -18,7 +18,7 @@ // CHECK-NEXT: DW_CFA_nop: // CHECK-NEXT: DW_CFA_nop: -// CHECK: 00000020 00000014 00000024 FDE cie=00000024 pc=00000dd8...00000dd8 +// CHECK: 00000020 00000014 00000024 FDE cie=00000024 pc=00000d98...00000d98 // CHECK-NEXT: DW_CFA_nop: // CHECK-NEXT: DW_CFA_nop: // CHECK-NEXT: DW_CFA_nop: diff --git a/test/ELF/eh-frame-hdr-icf.s b/test/ELF/eh-frame-hdr-icf.s index 2e7b335fb46da..1b42285f5d320 100644 --- a/test/ELF/eh-frame-hdr-icf.s +++ b/test/ELF/eh-frame-hdr-icf.s @@ -5,10 +5,10 @@ # RUN: llvm-objdump -s %t2 | FileCheck %s # CHECK: Contents of section .eh_frame_hdr: -# CHECK-NEXT: 101a0 011b033b b4ffffff 01000000 600e0000 -# ^ FDE count -# CHECK-NEXT: 101b0 d0ffffff 00000000 00000000 -# ^ FDE for f2 +# CHECK-NEXT: 200158 011b033b 1c000000 01000000 a80e0000 +# ^ FDE count +# CHECK-NEXT: 200168 38000000 00000000 00000000 +# ^ FDE for f2 .globl _start, f1, f2 _start: diff --git a/test/ELF/eh-frame-hdr-no-out.s b/test/ELF/eh-frame-hdr-no-out.s deleted file mode 100644 index edbafad07247f..0000000000000 --- a/test/ELF/eh-frame-hdr-no-out.s +++ /dev/null @@ -1,6 +0,0 @@ -// REQUIRES: x86 -// RUN: not ld.lld --eh-frame-hdr %p/Inputs/invalid-cie-version2.elf -o %t >& %t.log -// RUN: FileCheck %s < %t.log - -// invalid-cie-version2.elf contains unsupported version of CIE = 2. -// CHECK: FDE version 1 or 3 expected, but got 2 diff --git a/test/ELF/eh-frame-hdr.s b/test/ELF/eh-frame-hdr.s index 16fb49ac8e9f5..35c14a4b65dd8 100644 --- a/test/ELF/eh-frame-hdr.s +++ b/test/ELF/eh-frame-hdr.s @@ -32,92 +32,91 @@ _start: //HDRDISASM: Disassembly of section foo: //HDRDISASM-NEXT: foo: -//HDRDISASM-NEXT: 11000: 90 nop +//HDRDISASM-NEXT: 201000: 90 nop //HDRDISASM-NEXT: Disassembly of section bar: //HDRDISASM-NEXT: bar: -//HDRDISASM-NEXT: 11001: 90 nop +//HDRDISASM-NEXT: 201001: 90 nop //HDRDISASM-NEXT: Disassembly of section dah: //HDRDISASM-NEXT: dah: -//HDRDISASM-NEXT: 11002: 90 nop +//HDRDISASM-NEXT: 201002: 90 nop -// HDR: Sections [ -// HDR: Section { -// HDR: Index: 1 -// HDR-NEXT: Name: .eh_frame +// HDR: Section { +// HDR: Index: +// HDR: Name: .eh_frame_hdr // HDR-NEXT: Type: SHT_PROGBITS // HDR-NEXT: Flags [ // HDR-NEXT: SHF_ALLOC // HDR-NEXT: ] -// HDR-NEXT: Address: 0x10158 +// HDR-NEXT: Address: 0x200158 // HDR-NEXT: Offset: 0x158 -// HDR-NEXT: Size: 96 +// HDR-NEXT: Size: 36 // HDR-NEXT: Link: 0 // HDR-NEXT: Info: 0 -// HDR-NEXT: AddressAlignment: 8 +// HDR-NEXT: AddressAlignment: 1 // HDR-NEXT: EntrySize: 0 // HDR-NEXT: SectionData ( -// HDR-NEXT: 0000: 14000000 00000000 017A5200 01781001 | -// HDR-NEXT: 0010: 1B0C0708 90010000 14000000 1C000000 | -// HDR-NEXT: 0020: 880E0000 01000000 00000000 00000000 | -// HDR-NEXT: 0030: 14000000 34000000 710E0000 01000000 | -// HDR-NEXT: 0040: 00000000 00000000 14000000 4C000000 | -// HDR-NEXT: 0050: 5A0E0000 01000000 00000000 00000000 | -// CIE: 14000000 00000000 017A5200 01781001 1B0C0708 90010000 -// FDE(1): 14000000 1C000000 880E0000 01000000 00000000 00000000 -// address of data (starts with 0x880E0000) = 0x10158 + 0x0020 = 0x10178 -// The starting address to which this FDE applies = 0xE88 + 0x10178 = 0x11000 -// The number of bytes after the start address to which this FDE applies = 0x01000000 = 1 -// FDE(2): 14000000 34000000 710E0000 01000000 00000000 00000000 -// address of data (starts with 0x710E0000) = 0x10158 + 0x0038 = 0x10190 -// The starting address to which this FDE applies = 0xE71 + 0x10190 = 0x11001 -// The number of bytes after the start address to which this FDE applies = 0x01000000 = 1 -// FDE(3): 14000000 4C000000 5A0E0000 01000000 00000000 00000000 -// address of data (starts with 0x5A0E0000) = 0x10158 + 0x0050 = 0x101A8 -// The starting address to which this FDE applies = 0xE5A + 0x101A8 = 0x11002 -// The number of bytes after the start address to which this FDE applies = 0x01000000 = 1 +// HDR-NEXT: 0000: 011B033B 24000000 03000000 A80E0000 +// HDR-NEXT: 0010: 40000000 A90E0000 58000000 AA0E0000 +// HDR-NEXT: 0020: 70000000 // HDR-NEXT: ) +// Header (always 4 bytes): 0x011B033B +// 24000000 = .eh_frame(0x200180) - .eh_frame_hdr(0x200158) - 4 +// 03000000 = 3 = the number of FDE pointers in the table. +// Entry(1): A80E0000 40000000 +// 480E0000 = 0x201000 - .eh_frame_hdr(0x200158) = 0xEA8 +// 40000000 = address of FDE(1) - .eh_frame_hdr(0x200158) = +// = .eh_frame(0x200180) + 24 - 0x200158 = 0x40 +// Entry(2): A90E0000 58000000 +// A90E0000 = 0x201001 - .eh_frame_hdr(0x200158) = 0xEA9 +// 58000000 = address of FDE(2) - .eh_frame_hdr(0x200158) = +// = .eh_frame(0x200180) + 24 + 24 - 0x200158 = 0x58 +// Entry(3): AA0E0000 70000000 +// AA0E0000 = 0x201002 - .eh_frame_hdr(0x200158) = 0xEAA +// 70000000 = address of FDE(3) - .eh_frame_hdr(0x200158) = +// = .eh_frame(0x200180) + 24 + 24 + 24 - 0x200158 = 0x70 // HDR-NEXT: } // HDR-NEXT: Section { -// HDR-NEXT: Index: 2 -// HDR-NEXT: Name: .eh_frame_hdr +// HDR-NEXT: Index: +// HDR-NEXT: Name: .eh_frame // HDR-NEXT: Type: SHT_PROGBITS // HDR-NEXT: Flags [ // HDR-NEXT: SHF_ALLOC // HDR-NEXT: ] -// HDR-NEXT: Address: 0x101B8 -// HDR-NEXT: Offset: 0x1B8 -// HDR-NEXT: Size: 36 +// HDR-NEXT: Address: 0x200180 +// HDR-NEXT: Offset: 0x180 +// HDR-NEXT: Size: 96 // HDR-NEXT: Link: 0 // HDR-NEXT: Info: 0 -// HDR-NEXT: AddressAlignment: 1 +// HDR-NEXT: AddressAlignment: 8 // HDR-NEXT: EntrySize: 0 // HDR-NEXT: SectionData ( -// HDR-NEXT: 0000: 011B033B 9CFFFFFF 03000000 480E0000 | -// HDR-NEXT: 0010: B8FFFFFF 490E0000 D0FFFFFF 4A0E0000 | -// HDR-NEXT: 0020: E8FFFFFF | -// Header (always 4 bytes): 0x011B033B -// 9CFFFFFF = .eh_frame(0x10158) - .eh_frame_hdr(0x101B8) - 4 -// 03000000 = 3 = the number of FDE pointers in the table. -// Entry(1): 480E0000 B8FFFFFF -// 480E0000 = 0x11000 - .eh_frame_hdr(0x101B8) = 0xE48 -// B8FFFFFF = address of FDE(1) - .eh_frame_hdr(0x101B8) = -// = .eh_frame(0x10158) + 24 - 0x101B8 = 0xFFFFFFB8 -// Entry(2): 490E0000 D0FFFFFF -// 490E0000 = 0x11001 - .eh_frame_hdr(0x101B8) = 0xE49 -// D0FFFFFF = address of FDE(2) - .eh_frame_hdr(0x101B8) = -// = .eh_frame(0x10158) + 24 + 24 - 0x101B8 = 0xFFFFFFD0 -// Entry(3): 4A0E0000 E8FFFFFF -// 4A0E0000 = 0x11002 - .eh_frame_hdr(0x101B8) = 0xE4A -// E8FFFFFF = address of FDE(2) - .eh_frame_hdr(0x101B8) = -// = .eh_frame(0x10158) + 24 + 24 - 0x101B8 = 0xFFFFFFE8 +// HDR-NEXT: 0000: 14000000 00000000 017A5200 01781001 +// HDR-NEXT: 0010: 1B0C0708 90010000 14000000 1C000000 +// HDR-NEXT: 0020: 600E0000 01000000 00000000 00000000 +// HDR-NEXT: 0030: 14000000 34000000 490E0000 01000000 +// HDR-NEXT: 0040: 00000000 00000000 14000000 4C000000 +// HDR-NEXT: 0050: 320E0000 01000000 00000000 00000000 // HDR-NEXT: ) +// CIE: 14000000 00000000 017A5200 01781001 1B0C0708 90010000 +// FDE(1): 14000000 1C000000 600E0000 01000000 00000000 00000000 +// address of data (starts with 0x600E0000) = 0x200180 + 0x0020 = 0x2001A0 +// The starting address to which this FDE applies = 0xE60 + 0x2001A0 = 0x201000 +// The number of bytes after the start address to which this FDE applies = 0x01000000 = 1 +// FDE(2): 14000000 34000000 490E0000 01000000 00000000 00000000 +// address of data (starts with 0x490E0000) = 0x200180 + 0x0038 = 0x2001B8 +// The starting address to which this FDE applies = 0xE49 + 0x2001B8 = 0x201001 +// The number of bytes after the start address to which this FDE applies = 0x01000000 = 1 +// FDE(3): 14000000 4C000000 320E0000 01000000 00000000 00000000 +// address of data (starts with 0x320E0000) = 0x200180 + 0x0050 = 0x2001D0 +// The starting address to which this FDE applies = 0xE5A + 0x2001D0 = 0x201002 +// The number of bytes after the start address to which this FDE applies = 0x01000000 = 1 // HDR-NEXT: } // HDR: ProgramHeaders [ // HDR: ProgramHeader { // HDR: Type: PT_GNU_EH_FRAME -// HDR-NEXT: Offset: 0x1B8 -// HDR-NEXT: VirtualAddress: 0x101B8 -// HDR-NEXT: PhysicalAddress: 0x101B8 +// HDR-NEXT: Offset: 0x158 +// HDR-NEXT: VirtualAddress: 0x200158 +// HDR-NEXT: PhysicalAddress: 0x200158 // HDR-NEXT: FileSize: 36 // HDR-NEXT: MemSize: 36 // HDR-NEXT: Flags [ diff --git a/test/ELF/eh-frame-marker.s b/test/ELF/eh-frame-marker.s index a5de2a7c3d408..30bac460ae254 100644 --- a/test/ELF/eh-frame-marker.s +++ b/test/ELF/eh-frame-marker.s @@ -1,6 +1,19 @@ // 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 // We used to crash on this. + +// CHECK: Name: .eh_frame_hdr +// CHECK: Name: .eh_frame +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: ] +// CHECK-NEXT: Address: [[ADDR:.*]] + +// CHECK: Name: foo +// CHECK-NEXT: Value: [[ADDR]] + .section .eh_frame foo: .long 0 diff --git a/test/ELF/eh-frame-merge.s b/test/ELF/eh-frame-merge.s index 2610d4d4d2de2..addbb3f857fed 100644 --- a/test/ELF/eh-frame-merge.s +++ b/test/ELF/eh-frame-merge.s @@ -35,10 +35,10 @@ // CHECK-NEXT: SectionData ( // CHECK-NEXT: 0000: 14000000 00000000 017A5200 01781001 | // CHECK-NEXT: 0010: 1B0C0708 90010000 14000000 1C000000 | -// CHECK-NEXT: 0020: 180E0000 01000000 00000000 00000000 | -// CHECK-NEXT: 0030: 14000000 34000000 020E0000 02000000 | +// CHECK-NEXT: 0020: E80D0000 01000000 00000000 00000000 | +// CHECK-NEXT: 0030: 14000000 34000000 D20D0000 02000000 | // CHECK-NEXT: 0040: 00000000 00000000 14000000 4C000000 | -// CHECK-NEXT: 0050: E90D0000 01000000 00000000 00000000 | +// CHECK-NEXT: 0050: B90D0000 01000000 00000000 00000000 | // CHECK-NEXT: ) // CHECK: Name: foo diff --git a/test/ELF/ehdr_start.s b/test/ELF/ehdr_start.s new file mode 100644 index 0000000000000..9172feca5e9cc --- /dev/null +++ b/test/ELF/ehdr_start.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-objdump -t %t | FileCheck %s +# CHECK: 0000000000200040 *ABS* 00000000 .hidden __ehdr_start + +.text +.global _start, __ehdr_start +_start: + .quad __ehdr_start + +# RUN: ld.lld -r %t.o -o %t.r +# RUN: llvm-objdump -t %t.r | FileCheck %s --check-prefix=RELOCATABLE + +# RELOCATABLE: 0000000000000000 *UND* 00000000 __ehdr_start diff --git a/test/ELF/ehframe-relocation.s b/test/ELF/ehframe-relocation.s index 8d5e14919e92e..0213b1bebf832 100644 --- a/test/ELF/ehframe-relocation.s +++ b/test/ELF/ehframe-relocation.s @@ -10,17 +10,17 @@ // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x10120 +// CHECK-NEXT: Address: 0x200120 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 48 // CHECK-NOT: .eh_frame -// 0x10120 = 65824 -// 0x10120 + 5 = 65829 +// 0x200120 = 2097440 +// 0x200120 + 5 = 2097445 // DISASM: Disassembly of section .text: // DISASM-NEXT: _start: -// DISASM-NEXT: 11000: {{.*}} movq 65824, %rax -// DISASM-NEXT: 11008: {{.*}} movq 65829, %rax +// DISASM-NEXT: 201000: {{.*}} movq 2097440, %rax +// DISASM-NEXT: 201008: {{.*}} movq 2097445, %rax .section .eh_frame,"ax",@unwind diff --git a/test/ELF/empty-pt-load.s b/test/ELF/empty-pt-load.s new file mode 100644 index 0000000000000..4074b63cb80f6 --- /dev/null +++ b/test/ELF/empty-pt-load.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.so -shared +// RUN: llvm-readobj -l --elf-output-style=GNU %t.so | FileCheck %s + +// Test that we don't create an empty executable PT_LOAD. + +// CHECK: PHDR {{.*}} R 0x8 +// CHECK-NEXT: LOAD {{.*}} R 0x1000 +// CHECK-NEXT: LOAD {{.*}} RW 0x1000 +// CHECK-NEXT: DYNAMIC {{.*}} RW 0x8 diff --git a/test/ELF/empty-ver.s b/test/ELF/empty-ver.s index f200d2876e090..3412f31347370 100644 --- a/test/ELF/empty-ver.s +++ b/test/ELF/empty-ver.s @@ -1,7 +1,25 @@ // 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 +// RUN: ld.lld %t.o -o t.so -shared -version-script %p/Inputs/empty-ver.ver +// RUN: llvm-readobj -s -section-data -version-info t.so | FileCheck %s + +// CHECK: Name: .dynstr +// CHECK-NEXT: Type: SHT_STRTAB +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: ] +// CHECK-NEXT: Address: +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: 14 +// CHECK-NEXT: Link: 0 +// CHECK-NEXT: Info: 0 +// CHECK-NEXT: AddressAlignment: 1 +// CHECK-NEXT: EntrySize: 0 +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 00666F6F 00742E73 6F007665 7200 |.foo.t.so.ver.| +// CHECK-NEXT: ) // CHECK: Version symbols { // CHECK-NEXT: Section Name: diff --git a/test/ELF/emulation.s b/test/ELF/emulation.s index 7cc764fc6c182..a54faeaa832a3 100644 --- a/test/ELF/emulation.s +++ b/test/ELF/emulation.s @@ -1,3 +1,37 @@ +# 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 +# RUN: ld.lld %tx64 -o %t3x64 +# RUN: llvm-readobj -file-headers %t3x64 | FileCheck --check-prefix=AMD64 %s +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.sysv +# RUN: ld.lld -m elf_amd64_fbsd %t.sysv -o %t.freebsd +# RUN: llvm-readobj -file-headers %t.freebsd | FileCheck --check-prefix=AMD64 %s +# AMD64: ElfHeader { +# AMD64-NEXT: Ident { +# AMD64-NEXT: Magic: (7F 45 4C 46) +# AMD64-NEXT: Class: 64-bit (0x2) +# AMD64-NEXT: DataEncoding: LittleEndian (0x1) +# AMD64-NEXT: FileVersion: 1 +# AMD64-NEXT: OS/ABI: FreeBSD (0x9) +# AMD64-NEXT: ABIVersion: 0 +# AMD64-NEXT: Unused: (00 00 00 00 00 00 00) +# AMD64-NEXT: } +# AMD64-NEXT: Type: Executable (0x2) +# AMD64-NEXT: Machine: EM_X86_64 (0x3E) +# AMD64-NEXT: Version: 1 +# AMD64-NEXT: Entry: +# AMD64-NEXT: ProgramHeaderOffset: 0x40 +# AMD64-NEXT: SectionHeaderOffset: +# AMD64-NEXT: Flags [ (0x0) +# AMD64-NEXT: ] +# AMD64-NEXT: HeaderSize: 64 +# AMD64-NEXT: ProgramHeaderEntrySize: 56 +# AMD64-NEXT: ProgramHeaderCount: +# AMD64-NEXT: SectionHeaderEntrySize: 64 +# AMD64-NEXT: SectionHeaderCount: +# AMD64-NEXT: StringTableSectionIndex: +# AMD64-NEXT: } + # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tx64 # RUN: ld.lld -m elf_x86_64 %tx64 -o %t2x64 # RUN: llvm-readobj -file-headers %t2x64 | FileCheck --check-prefix=X86-64 %s @@ -122,6 +156,37 @@ # X86FBSD-NEXT: StringTableSectionIndex: # X86FBSD-NEXT: } +# RUN: llvm-mc -filetype=obj -triple=i586-intel-elfiamcu %s -o %tiamcu +# RUN: ld.lld -m elf_iamcu %tiamcu -o %t2iamcu +# RUN: llvm-readobj -file-headers %t2iamcu | FileCheck --check-prefix=IAMCU %s +# RUN: ld.lld %tiamcu -o %t3iamcu +# RUN: llvm-readobj -file-headers %t3iamcu | FileCheck --check-prefix=IAMCU %s +# IAMCU: ElfHeader { +# IAMCU-NEXT: Ident { +# IAMCU-NEXT: Magic: (7F 45 4C 46) +# IAMCU-NEXT: Class: 32-bit (0x1) +# IAMCU-NEXT: DataEncoding: LittleEndian (0x1) +# IAMCU-NEXT: FileVersion: 1 +# IAMCU-NEXT: OS/ABI: SystemV (0x0) +# IAMCU-NEXT: ABIVersion: 0 +# IAMCU-NEXT: Unused: (00 00 00 00 00 00 00) +# IAMCU-NEXT: } +# IAMCU-NEXT: Type: Executable (0x2) +# IAMCU-NEXT: Machine: EM_IAMCU (0x6) +# IAMCU-NEXT: Version: 1 +# IAMCU-NEXT: Entry: +# IAMCU-NEXT: ProgramHeaderOffset: 0x34 +# IAMCU-NEXT: SectionHeaderOffset: +# IAMCU-NEXT: Flags [ (0x0) +# IAMCU-NEXT: ] +# IAMCU-NEXT: HeaderSize: 52 +# IAMCU-NEXT: ProgramHeaderEntrySize: 32 +# IAMCU-NEXT: ProgramHeaderCount: +# IAMCU-NEXT: SectionHeaderEntrySize: 40 +# IAMCU-NEXT: SectionHeaderCount: +# IAMCU-NEXT: StringTableSectionIndex: +# IAMCU-NEXT: } + # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %tppc64 # RUN: ld.lld -m elf64ppc %tppc64 -o %t2ppc64 # RUN: llvm-readobj -file-headers %t2ppc64 | FileCheck --check-prefix=PPC64 %s @@ -176,7 +241,7 @@ # MIPS-NEXT: SectionHeaderOffset: # MIPS-NEXT: Flags [ # MIPS-NEXT: EF_MIPS_ABI_O32 -# MIPS-NEXT: EF_MIPS_ARCH_32R2 +# MIPS-NEXT: EF_MIPS_ARCH_32 # MIPS-NEXT: EF_MIPS_CPIC # MIPS-NEXT: ] @@ -205,7 +270,7 @@ # MIPSEL-NEXT: SectionHeaderOffset: # MIPSEL-NEXT: Flags [ # MIPSEL-NEXT: EF_MIPS_ABI_O32 -# MIPSEL-NEXT: EF_MIPS_ARCH_32R2 +# MIPSEL-NEXT: EF_MIPS_ARCH_32 # MIPSEL-NEXT: EF_MIPS_CPIC # MIPSEL-NEXT: ] @@ -231,7 +296,7 @@ # MIPS64-NEXT: ProgramHeaderOffset: 0x40 # MIPS64-NEXT: SectionHeaderOffset: # MIPS64-NEXT: Flags [ -# MIPS64-NEXT: EF_MIPS_ARCH_64R2 +# MIPS64-NEXT: EF_MIPS_ARCH_64 # MIPS64-NEXT: EF_MIPS_CPIC # MIPS64-NEXT: EF_MIPS_PIC # MIPS64-NEXT: ] @@ -258,7 +323,7 @@ # MIPS64EL-NEXT: ProgramHeaderOffset: 0x40 # MIPS64EL-NEXT: SectionHeaderOffset: # MIPS64EL-NEXT: Flags [ -# MIPS64EL-NEXT: EF_MIPS_ARCH_64R2 +# MIPS64EL-NEXT: EF_MIPS_ARCH_64 # MIPS64EL-NEXT: EF_MIPS_CPIC # MIPS64EL-NEXT: EF_MIPS_PIC # MIPS64EL-NEXT: ] diff --git a/test/ELF/end-update.s b/test/ELF/end-update.s index 8654ef1e92eb8..afb137fd2d73a 100644 --- a/test/ELF/end-update.s +++ b/test/ELF/end-update.s @@ -12,13 +12,13 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x12000 +// CHECK-NEXT: Address: 0x202000 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 6 // CHECK: ] // CHECK: Symbols [ // CHECK: Name: end -// CHECK-NEXT: Value: 0x12006 +// CHECK-NEXT: Value: 0x202006 // CHECK: ] .global _start,end diff --git a/test/ELF/end.s b/test/ELF/end.s index 689157f820707..f40c5db8b5ffa 100644 --- a/test/ELF/end.s +++ b/test/ELF/end.s @@ -14,60 +14,18 @@ // DEFAULT-NEXT: SHF_ALLOC // DEFAULT-NEXT: SHF_WRITE // DEFAULT-NEXT: ] -// DEFAULT-NEXT: Address: 0x12002 +// DEFAULT-NEXT: Address: 0x202002 // DEFAULT-NEXT: Offset: // DEFAULT-NEXT: Size: 6 // DEFAULT: ] // DEFAULT: Symbols [ // DEFAULT: Name: _end -// DEFAULT-NEXT: Value: 0x12008 +// DEFAULT-NEXT: Value: 0x202008 // DEFAULT: ] -// If there is no .bss section, "_end" should point to the end of the .data section. -// RUN: echo "SECTIONS { \ -// RUN: /DISCARD/ : { *(.bss) } }" > %t.script -// RUN: ld.lld %t.o --script %t.script -o %t -// RUN: llvm-readobj -sections -symbols %t | FileCheck %s --check-prefix=NOBSS - -// NOBSS: Sections [ -// NOBSS: Name: .data -// NOBSS-NEXT: Type: -// NOBSS-NEXT: Flags [ -// NOBSS-NEXT: SHF_ALLOC -// NOBSS-NEXT: SHF_WRITE -// NOBSS-NEXT: ] -// NOBSS-NEXT: Address: 0x159 -// NOBSS-NEXT: Offset: -// NOBSS-NEXT: Size: 2 -// NOBSS: ] -// NOBSS: Symbols [ -// NOBSS: Name: _end -// NOBSS-NEXT: Value: 0x15B -// NOBSS: ] - -// If the layout of the sections is changed, "_end" should point to the end of allocated address space. -// RUN: echo "SECTIONS { \ -// RUN: .bss : { *(.bss) } \ -// RUN: .data : { *(.data) } \ -// RUN: .text : { *(.text) } }" > %t.script -// RUN: ld.lld %t.o --script %t.script -o %t -// RUN: llvm-readobj -sections -symbols %t | FileCheck %s --check-prefix=TEXTATEND - -// TEXTATEND: Sections [ -// TEXTATEND: Name: .text -// TEXTATEND-NEXT: Type: -// TEXTATEND-NEXT: Flags [ -// TEXTATEND-NEXT: SHF_ALLOC -// TEXTATEND-NEXT: SHF_EXECINSTR -// TEXTATEND-NEXT: ] -// TEXTATEND-NEXT: Address: 0x160 -// TEXTATEND-NEXT: Offset: -// TEXTATEND-NEXT: Size: 1 -// TEXTATEND: ] -// TEXTATEND: Symbols [ -// TEXTATEND: Name: _end -// TEXTATEND-NEXT: Value: 0x161 -// TEXTATEND: ] +// RUN: ld.lld -r %t.o -o %t2 +// RUN: llvm-objdump -t %t2 | FileCheck %s --check-prefix=RELOCATABLE +// RELOCATABLE: 0000000000000000 *UND* 00000000 _end .global _start,_end .text diff --git a/test/ELF/entry.s b/test/ELF/entry.s index 6175c7623a349..f288bcf6ae503 100644 --- a/test/ELF/entry.s +++ b/test/ELF/entry.s @@ -1,21 +1,53 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 -# RUN: not ld.lld %t1 -o %t2 + +# RUN: ld.lld -e foobar %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN1 %s +# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=TEXT %s + +# WARN1: warning: cannot find entry symbol foobar; defaulting to 0x201000 +# TEXT: Entry: 0x201000 + +# RUN: ld.lld %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN2 %s +# WARN2: warning: cannot find entry symbol _start; defaulting to 0x201000 + +# RUN: ld.lld -shared -e foobar %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN3 %s +# WARN3: warning: cannot find entry symbol foobar; defaulting to 0x1000 + +# RUN: ld.lld -shared --fatal-warnings -e entry %t1 -o %t2 +# RUN: ld.lld -shared --fatal-warnings %t1 -o %t2 + +# RUN: echo .data > %t.s +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux -n %t.s -o %t3 +# RUN: ld.lld %t3 -o %t4 2>&1 | FileCheck -check-prefix=WARN4 %s +# RUN: llvm-readobj -file-headers %t4 | FileCheck -check-prefix=NOENTRY %s + +# WARN4: cannot find entry symbol _start; not setting start address +# NOENTRY: Entry: 0x0 + +# RUN: ld.lld -v -r %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN5 %s +# WARN5-NOT: warning: cannot find entry symbol + # RUN: ld.lld %t1 -o %t2 -e entry # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=SYM %s -# RUN: ld.lld %t1 -shared -o %t2 -e entry +# SYM: Entry: 0x201008 + +# RUN: ld.lld %t1 --fatal-warnings -shared -o %t2 -e entry # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=DSO %s +# DSO: Entry: 0x1008 + # RUN: ld.lld %t1 -o %t2 --entry=4096 # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=DEC %s +# DEC: Entry: 0x1000 + # RUN: ld.lld %t1 -o %t2 --entry 0xcafe # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=HEX %s +# HEX: Entry: 0xCAFE + # RUN: ld.lld %t1 -o %t2 -e 0777 # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=OCT %s - -# SYM: Entry: 0x11000 -# DSO: Entry: 0x1000 -# DEC: Entry: 0x1000 -# HEX: Entry: 0xCAFE # OCT: Entry: 0x1FF .globl entry +.text + .quad 0 entry: + ret diff --git a/test/ELF/error-limit.test b/test/ELF/error-limit.test new file mode 100644 index 0000000000000..a82f2f2bfd729 --- /dev/null +++ b/test/ELF/error-limit.test @@ -0,0 +1,26 @@ +RUN: not ld.lld 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 \ +RUN: 21 22 2>&1 | FileCheck -check-prefix=DEFAULT %s + +DEFAULT: cannot open 01 +DEFAULT: cannot open 20 +DEFAULT-NEXT: too many errors emitted, stopping now (use -error-limit=0 to see all errors) +DEFAULT-NOT: cannot open 21 + +RUN: not ld.lld -error-limit=5 01 02 03 04 05 06 07 08 09 10 2>&1 \ +RUN: | FileCheck -check-prefix=LIMIT5 %s +RUN: not ld.lld -error-limit 5 01 02 03 04 05 06 07 08 09 10 2>&1 \ +RUN: | FileCheck -check-prefix=LIMIT5 %s + +LIMIT5: cannot open 01 +LIMIT5: cannot open 05 +LIMIT5-NEXT: too many errors emitted, stopping now (use -error-limit=0 to see all errors) +LIMIT5-NOT: cannot open 06 + +RUN: not ld.lld -error-limit=0 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 \ +RUN: 16 17 18 19 20 21 22 2>&1 | FileCheck -check-prefix=UNLIMITED %s + +UNLIMITED: cannot open 01 +UNLIMITED: cannot open 20 +UNLIMITED: cannot open 21 +UNLIMITED: cannot open 22 +UNLIMITED-NOT: too many errors emitted, stopping now (use -error-limit=0 to see all errors) diff --git a/test/ELF/exclude.s b/test/ELF/exclude.s new file mode 100644 index 0000000000000..8fe003747b148 --- /dev/null +++ b/test/ELF/exclude.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld -o %t1 %t +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s +# RUN: ld.lld -r -o %t1 %t +# RUN: llvm-objdump -section-headers %t1 | FileCheck --check-prefix=RELOCATABLE %s + +# CHECK-NOT: .aaa +# RELOCATABLE: .aaa + +.globl _start +_start: + jmp _start + +.section .aaa,"ae" + .quad .bbb + +.section .bbb,"a" + .quad 0 diff --git a/test/ELF/format-binary.test b/test/ELF/format-binary.test new file mode 100644 index 0000000000000..586f5f963dfad --- /dev/null +++ b/test/ELF/format-binary.test @@ -0,0 +1,56 @@ +# REQUIRES: x86 + +# RUN: echo -n "Fluffle Puff" > %t.binary +# RUN: ld.lld -m elf_x86_64 -r -b binary %t.binary -o %t.out +# RUN: llvm-readobj %t.out -sections -section-data -symbols | FileCheck %s + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -b binary %t.binary -b default %t.o -shared -o %t.out + +# RUN: not ld.lld -b foo > %t.log 2>&1 +# RUN: FileCheck -check-prefix=ERR %s < %t.log +# ERR: error: unknown -format value: foo (supported formats: elf, default, binary) + +# CHECK: Name: .data +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x0 +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 12 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 466C7566 666C6520 50756666 |Fluffle Puff| +# CHECK-NEXT: ) +# CHECK-NEXT: } + +# CHECK: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_test_tmp_binary_start +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Object +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .data +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_test_tmp_binary_end +# CHECK-NEXT: Value: 0xC +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Object +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .data +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_test_tmp_binary_size +# CHECK-NEXT: Value: 0xC +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Object +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } diff --git a/test/ELF/gc-debuginfo-tls.s b/test/ELF/gc-debuginfo-tls.s new file mode 100644 index 0000000000000..9884a578cca98 --- /dev/null +++ b/test/ELF/gc-debuginfo-tls.s @@ -0,0 +1,23 @@ +# 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 +# RUN: llvm-readobj -symbols %t1 | FileCheck %s --check-prefix=GC +# RUN: llvm-readobj -symbols %t2 | FileCheck %s --check-prefix=NOGC + +# NOGC: Symbol { +# NOGC: Name: .tbss +# NOGC: Value: 0x1000 +# NOGC: Size: 0 +# NOGC: Binding: Local +# NOGC: Type: TLS +# NOGC: Other: 0 +# NOGC: Section: .tbss +# NOGC: } + +# GC-NOT: tbss + +.section .tbss,"awT",@nobits +patatino: + .long 0 + .section .noalloc,"" + .quad patatino diff --git a/test/ELF/gc-sections-alloc.s b/test/ELF/gc-sections-alloc.s new file mode 100644 index 0000000000000..bffd1f9cdcab7 --- /dev/null +++ b/test/ELF/gc-sections-alloc.s @@ -0,0 +1,31 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld %t -o %t2 --gc-sections -shared +# RUN: llvm-readobj -sections -section-data %t2 | FileCheck %s + +# Non alloca section .bar should not keep section .foo alive. + +# CHECK-NOT: Name: .foo + +# CHECK: Name: .bar +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# 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: 00000000 00000000 | +# CHECK-NEXT: ) + + +.section .foo,"a" +.byte 0 + +.section .bar +.quad .foo diff --git a/test/ELF/gc-sections-implicit-addend.s b/test/ELF/gc-sections-implicit-addend.s new file mode 100644 index 0000000000000..1270affbcc0e8 --- /dev/null +++ b/test/ELF/gc-sections-implicit-addend.s @@ -0,0 +1,26 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=i386-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t --gc-sections +# RUN: llvm-readobj -s %t | FileCheck %s +# RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s + +# CHECK: Name: .foo +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: SHF_STRINGS +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x100B4 + +# 0x100B4 == 65716 +# DISASM: leal 65716, %eax + + .section .foo,"aMS",@progbits,1 + .byte 0 + + .text + .global _start +_start: + leal .foo, %eax diff --git a/test/ELF/gc-sections-keep-shared-start.s b/test/ELF/gc-sections-keep-shared-start.s new file mode 100644 index 0000000000000..23417ca01dc60 --- /dev/null +++ b/test/ELF/gc-sections-keep-shared-start.s @@ -0,0 +1,30 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld -shared --gc-sections -o %t1 %t +# RUN: llvm-readobj --elf-output-style=GNU --file-headers --symbols %t1 +# | FileCheck %s +# CHECK: Entry point address: 0x1000 +# CHECK: 0000000000001000 0 FUNC LOCAL HIDDEN 4 _start +# CHECK: 0000000000001006 0 FUNC LOCAL HIDDEN 4 internal +# CHECK: 0000000000001005 0 FUNC GLOBAL DEFAULT 4 foobar + +.section .text.start,"ax" +.globl _start +.type _start,%function +.hidden _start +_start: + jmp internal + +.section .text.foobar,"ax" +.globl foobar +.type foobar,%function +foobar: + ret + +.section .text.internal,"ax" +.globl internal +.hidden internal +.type internal,%function +internal: + ret diff --git a/test/ELF/gc-sections-lsda.s b/test/ELF/gc-sections-lsda.s index b5bed8f0c8161..1fc75c8e85b77 100644 --- a/test/ELF/gc-sections-lsda.s +++ b/test/ELF/gc-sections-lsda.s @@ -9,7 +9,7 @@ // RUN: llvm-readobj -s %t | FileCheck %s // CHECK: Name: .abc -// CHECK: Name: .foo (38) +// CHECK: Name: .foo .cfi_startproc .cfi_lsda 0x1b,zed diff --git a/test/ELF/gc-sections-non-alloc-to-merge.s b/test/ELF/gc-sections-non-alloc-to-merge.s new file mode 100644 index 0000000000000..37b0328d8455e --- /dev/null +++ b/test/ELF/gc-sections-non-alloc-to-merge.s @@ -0,0 +1,27 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t --gc-sections +# RUN: llvm-readobj -s --elf-output-style=GNU %t | FileCheck %s + +# CHECK: .merge1 PROGBITS {{[0-9a-z]*}} {{[0-9a-z]*}} 000004 + + .global _start +_start: + .quad .Lfoo + + .section .merge1,"aM",@progbits,4 + .p2align 2 +.Lfoo: + .long 1 +.Lbar: + .long 2 + + .section .merge2,"aM",@progbits,4 + .p2align 2 +.Lzed: + .long 1 + + .section bar + .quad .Lbar + .quad .Lzed diff --git a/test/ELF/gc-sections-shared.s b/test/ELF/gc-sections-shared.s index d52eae2177b2a..f1ac9cd345d45 100644 --- a/test/ELF/gc-sections-shared.s +++ b/test/ELF/gc-sections-shared.s @@ -8,13 +8,47 @@ # This test the property that we have a needed line for every undefined. # It would also be OK to drop bar2 and the need for the .so +# CHECK: DynamicSymbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar2 +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: Undefined +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: foo +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: ] -# CHECK: Name: bar -# CHECK: Name: bar2 -# CHECK: Name: foo # CHECK: NEEDED SharedLibrary ({{.*}}.so) - .section .text.foo, "ax" .globl foo foo: diff --git a/test/ELF/gc-sections-synthetic.s b/test/ELF/gc-sections-synthetic.s new file mode 100644 index 0000000000000..e47cc02cdde7f --- /dev/null +++ b/test/ELF/gc-sections-synthetic.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 + +# Linker-synthesized sections shouldn't be gc'ed. + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t1 +# RUN: ld.lld %t1 -shared -o %t.so +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2 +# RUN: ld.lld %t2 %t.so -build-id -dynamic-linker /foo/bar -o %t.out +# RUN: llvm-readobj -sections %t.out | FileCheck %s + +# CHECK: Name: .interp +# CHECK: Name: .note.gnu.build-id + +.globl _start +_start: + ret diff --git a/test/ELF/gc-sections.s b/test/ELF/gc-sections.s index 93f7dc67023f4..f100153ec3586 100644 --- a/test/ELF/gc-sections.s +++ b/test/ELF/gc-sections.s @@ -14,13 +14,13 @@ # NOGC: Name: .dtors # NOGC: Name: .init # NOGC: Name: .fini +# NOGC: Name: .debug_pubtypes +# NOGC: Name: .comment # NOGC: Name: a # NOGC: Name: b # NOGC: Name: c # NOGC: Name: x # NOGC: Name: y -# NOGC: Name: __preinit_array_start -# NOGC: Name: __preinit_array_end # NOGC: Name: d # GC1: Name: .eh_frame @@ -29,13 +29,13 @@ # GC1: Name: .dtors # GC1: Name: .init # GC1: Name: .fini +# GC1: Name: .debug_pubtypes +# GC1: Name: .comment # GC1: Name: a # GC1: Name: b # GC1: Name: c # GC1-NOT: Name: x # GC1-NOT: Name: y -# GC1: Name: __preinit_array_start -# GC1: Name: __preinit_array_end # GC1-NOT: Name: d # GC2: Name: .eh_frame @@ -44,13 +44,13 @@ # GC2: Name: .dtors # GC2: Name: .init # GC2: Name: .fini +# GC2: Name: .debug_pubtypes +# GC2: Name: .comment # GC2: Name: a # GC2: Name: b # GC2: Name: c # GC2-NOT: Name: x # GC2-NOT: Name: y -# GC2: Name: __preinit_array_start -# GC2: Name: __preinit_array_end # GC2: Name: d .globl _start, d @@ -100,3 +100,9 @@ y: .section .eh_frame,"a",@unwind .quad 0 + +.section .debug_pubtypes,"",@progbits + .quad 0 + +.section .comment,"MS",@progbits,8 + .quad 0 diff --git a/test/ELF/gdb-index.s b/test/ELF/gdb-index.s new file mode 100644 index 0000000000000..4ad5c13d31588 --- /dev/null +++ b/test/ELF/gdb-index.s @@ -0,0 +1,49 @@ +## gdb-index-a.elf and gdb-index-b.elf are a test.o and test2.o renamed, +## were generated in this way: +## test.cpp: +## int main() { return 0; } +## test2.cpp: +## int main2() { return 0; } +## Compiled with: +## gcc -gsplit-dwarf -c test.cpp test2.cpp +## gcc version 5.3.1 20160413 +## Info about gdb-index: https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html + +# REQUIRES: x86 +# RUN: ld.lld --gdb-index -e main %p/Inputs/gdb-index-a.elf %p/Inputs/gdb-index-b.elf -o %t +# RUN: llvm-dwarfdump -debug-dump=gdb_index %t | FileCheck %s +# RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=DISASM + +# DISASM: Disassembly of section .text: +# DISASM: main: +# DISASM-CHECK: 11000: 55 pushq %rbp +# DISASM-CHECK: 11001: 48 89 e5 movq %rsp, %rbp +# DISASM-CHECK: 11004: b8 00 00 00 00 movl $0, %eax +# DISASM-CHECK: 11009: 5d popq %rbp +# DISASM-CHECK: 1100a: c3 retq +# DISASM: _Z5main2v: +# DISASM-CHECK: 1100b: 55 pushq %rbp +# DISASM-CHECK: 1100c: 48 89 e5 movq %rsp, %rbp +# DISASM-CHECK: 1100f: b8 00 00 00 00 movl $0, %eax +# DISASM-CHECK: 11014: 5d popq %rbp +# DISASM-CHECK: 11015: c3 retq + +# 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 address = 0x201000, High address = 0x20100b, CU index = 0 +# CHECK-NEXT: Low address = 0x20100b, High address = 0x201016, CU index = 1 +# CHECK: Symbol table offset = 0x60, size = 1024, filled slots: +# CHECK-NEXT: 489: Name offset = 0x1d, CU vector offset = 0x0 +# CHECK-NEXT: String name: main, CU vector index: 0 +# CHECK-NEXT: 754: Name offset = 0x22, CU vector offset = 0x8 +# CHECK-NEXT: String name: int, CU vector index: 1 +# CHECK-NEXT: 956: Name offset = 0x26, 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 diff --git a/test/ELF/gnu-ifunc-gotpcrel.s b/test/ELF/gnu-ifunc-gotpcrel.s index 08aa0af37a1b6..2a5814a98bc23 100644 --- a/test/ELF/gnu-ifunc-gotpcrel.s +++ b/test/ELF/gnu-ifunc-gotpcrel.s @@ -6,7 +6,7 @@ # RUN: llvm-readobj -dyn-relocations %t | FileCheck %s # CHECK: Dynamic Relocations { -# CHECK-NEXT: 0x120B0 R_X86_64_GLOB_DAT foo 0x0 +# CHECK-NEXT: 0x2020B0 R_X86_64_GLOB_DAT foo 0x0 # CHECK-NEXT: } .globl _start diff --git a/test/ELF/gnu-ifunc-i386.s b/test/ELF/gnu-ifunc-i386.s index bc2d0f9610b3b..21f1313a9b051 100644 --- a/test/ELF/gnu-ifunc-i386.s +++ b/test/ELF/gnu-ifunc-i386.s @@ -15,15 +15,15 @@ // CHECK-NEXT: Address: [[RELA:.*]] // CHECK-NEXT: Offset: 0xD4 // CHECK-NEXT: Size: 16 -// CHECK-NEXT: Link: 5 +// CHECK-NEXT: Link: 6 // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 4 // CHECK-NEXT: EntrySize: 8 // CHECK-NEXT: } // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rel.plt { -// CHECK-NEXT: 0x1200C R_386_IRELATIVE -// CHECK-NEXT: 0x12010 R_386_IRELATIVE +// CHECK-NEXT: 0x12000 R_386_IRELATIVE +// CHECK-NEXT: 0x12004 R_386_IRELATIVE // CHECK-NEXT: } // CHECK-NEXT: ] @@ -88,30 +88,24 @@ // CHECK-NEXT: } // CHECK-NEXT:] -// DISASM: Disassembly of section .text: +// DISASM: Disassembly of section .text: // DISASM-NEXT: foo: -// DISASM-NEXT: 11000: c3 retl -// DISASM: bar: -// DISASM-NEXT: 11001: c3 retl +// DISASM-NEXT: 11000: c3 retl +// DISASM: bar: +// DISASM-NEXT: 11001: c3 retl // DISASM: _start: -// DISASM-NEXT: 11002: e8 29 00 00 00 calll 41 -// DISASM-NEXT: 11007: e8 34 00 00 00 calll 52 +// DISASM-NEXT: 11002: e8 19 00 00 00 calll 25 +// DISASM-NEXT: 11007: e8 24 00 00 00 calll 36 // DISASM-NEXT: 1100c: ba d4 00 01 00 movl $65748, %edx // DISASM-NEXT: 11011: ba e4 00 01 00 movl $65764, %edx // DISASM-NEXT: Disassembly of section .plt: // DISASM-NEXT: .plt: -// DISASM-NEXT: 11020: ff 35 04 20 01 00 pushl 73732 -// DISASM-NEXT: 11026: ff 25 08 20 01 00 jmpl *73736 -// DISASM-NEXT: 1102c: 90 nop -// DISASM-NEXT: 1102d: 90 nop -// DISASM-NEXT: 1102e: 90 nop -// DISASM-NEXT: 1102f: 90 nop -// DISASM-NEXT: 11030: ff 25 0c 20 01 00 jmpl *73740 -// DISASM-NEXT: 11036: 68 00 00 00 00 pushl $0 -// DISASM-NEXT: 1103b: e9 e0 ff ff ff jmp -32 <.plt> -// DISASM-NEXT: 11040: ff 25 10 20 01 00 jmpl *73744 -// DISASM-NEXT: 11046: 68 08 00 00 00 pushl $8 -// DISASM-NEXT: 1104b: e9 d0 ff ff ff jmp -48 <.plt> +// DISASM-NEXT: 11020: ff 25 00 20 01 00 jmpl *73728 +// DISASM-NEXT: 11026: 68 10 00 00 00 pushl $16 +// DISASM-NEXT: 1102b: e9 e0 ff ff ff jmp -32 <_start+0xE> +// DISASM-NEXT: 11030: ff 25 04 20 01 00 jmpl *73732 +// DISASM-NEXT: 11036: 68 18 00 00 00 pushl $24 +// DISASM-NEXT: 1103b: e9 d0 ff ff ff jmp -48 <_start+0xE> .text .type foo STT_GNU_IFUNC diff --git a/test/ELF/gnu-ifunc-plt-i386.s b/test/ELF/gnu-ifunc-plt-i386.s new file mode 100644 index 0000000000000..75ebc8dd76ef4 --- /dev/null +++ b/test/ELF/gnu-ifunc-plt-i386.s @@ -0,0 +1,76 @@ +// 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 +// RUN: ld.lld %t.so %t.o -o %tout +// 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 [ +// CHECK-NEXT: Section (4) .rel.plt { +// CHECK-NEXT: 0x1300C R_386_JUMP_SLOT bar2 +// CHECK-NEXT: 0x13010 R_386_JUMP_SLOT zed2 +// CHECK-NEXT: 0x13014 R_386_IRELATIVE +// CHECK-NEXT: 0x13018 R_386_IRELATIVE + +// Check that IRELATIVE .got.plt entries point to ifunc resolver and not +// back to the plt entry + 6. +// GOTPLT: Contents of section .got.plt: +// GOTPLT: 13000 00200100 00000000 00000000 36100100 +// GOTPLT-NEXT: 13010 46100100 00100100 01100100 + +// Check that the PLTRELSZ tag includes the IRELATIVE relocations +// CHECK: DynamicSection [ +// CHECK: 0x00000002 PLTRELSZ 32 (bytes) + +// Check that a PLT header is written and the ifunc entries appear last +// DISASM: Disassembly of section .text: +// DISASM-NEXT: foo: +// DISASM-NEXT: 11000: c3 retl +// DISASM: bar: +// DISASM-NEXT: 11001: c3 retl +// DISASM: _start: +// DISASM-NEXT: 11002: e8 49 00 00 00 calll 73 +// DISASM-NEXT: 11007: e8 54 00 00 00 calll 84 +// DISASM-NEXT: 1100c: e8 1f 00 00 00 calll 31 +// DISASM-NEXT: 11011: e8 2a 00 00 00 calll 42 +// DISASM-NEXT: Disassembly of section .plt: +// DISASM-NEXT: .plt: +// DISASM-NEXT: 11020: ff 35 04 30 01 00 pushl 77828 +// DISASM-NEXT: 11026: ff 25 08 30 01 00 jmpl *77832 +// DISASM-NEXT: 1102c: 90 nop +// DISASM-NEXT: 1102d: 90 nop +// DISASM-NEXT: 1102e: 90 nop +// DISASM-NEXT: 1102f: 90 nop +// DISASM-NEXT: 11030: ff 25 0c 30 01 00 jmpl *77836 +// DISASM-NEXT: 11036: 68 00 00 00 00 pushl $0 +// DISASM-NEXT: 1103b: e9 e0 ff ff ff jmp -32 <.plt> +// DISASM-NEXT: 11040: ff 25 10 30 01 00 jmpl *77840 +// DISASM-NEXT: 11046: 68 08 00 00 00 pushl $8 +// DISASM-NEXT: 1104b: e9 d0 ff ff ff jmp -48 <.plt> +// DISASM-NEXT: 11050: ff 25 14 30 01 00 jmpl *77844 +// DISASM-NEXT: 11056: 68 30 00 00 00 pushl $48 +// DISASM-NEXT: 1105b: e9 e0 ff ff ff jmp -32 <.plt+0x20> +// DISASM-NEXT: 11060: ff 25 18 30 01 00 jmpl *77848 +// DISASM-NEXT: 11066: 68 38 00 00 00 pushl $56 +// DISASM-NEXT: 1106b: e9 d0 ff ff ff jmp -48 <.plt+0x20> + +.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 + call bar2 + call zed2 diff --git a/test/ELF/gnu-ifunc-plt.s b/test/ELF/gnu-ifunc-plt.s new file mode 100644 index 0000000000000..c7bd6b67b1150 --- /dev/null +++ b/test/ELF/gnu-ifunc-plt.s @@ -0,0 +1,74 @@ +// 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 +// RUN: ld.lld %t.so %t.o -o %tout +// 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 [ +// CHECK-NEXT: Section (4) .rela.plt { +// CHECK-NEXT: 0x203018 R_X86_64_JUMP_SLOT bar2 0x0 +// CHECK-NEXT: 0x203020 R_X86_64_JUMP_SLOT zed2 0x0 +// CHECK-NEXT: 0x203028 R_X86_64_IRELATIVE - 0x201000 +// CHECK-NEXT: 0x203030 R_X86_64_IRELATIVE - 0x201001 + +// Check that .got.plt entries point back to PLT header +// GOTPLT: Contents of section .got.plt: +// GOTPLT-NEXT: 203000 00202000 00000000 00000000 00000000 . ............. +// GOTPLT-NEXT: 203010 00000000 00000000 36102000 00000000 ........6. ..... +// GOTPLT-NEXT: 203020 46102000 00000000 56102000 00000000 F. .....V. ..... +// GOTPLT-NEXT: 203030 66102000 00000000 + +// Check that the PLTRELSZ tag includes the IRELATIVE relocations +// CHECK: DynamicSection [ +// CHECK: 0x0000000000000002 PLTRELSZ 96 (bytes) + +// Check that a PLT header is written and the ifunc entries appear last +// DISASM: Disassembly of section .text: +// DISASM-NEXT: foo: +// DISASM-NEXT: 201000: c3 retq +// DISASM: bar: +// DISASM-NEXT: 201001: c3 retq +// DISASM: _start: +// DISASM-NEXT: 201002: e8 49 00 00 00 callq 73 +// DISASM-NEXT: 201007: e8 54 00 00 00 callq 84 +// DISASM-NEXT: 20100c: e8 1f 00 00 00 callq 31 +// DISASM-NEXT: 201011: e8 2a 00 00 00 callq 42 +// DISASM-NEXT: Disassembly of section .plt: +// DISASM-NEXT: .plt: +// DISASM-NEXT: 201020: ff 35 e2 1f 00 00 pushq 8162(%rip) +// DISASM-NEXT: 201026: ff 25 e4 1f 00 00 jmpq *8164(%rip) +// DISASM-NEXT: 20102c: 0f 1f 40 00 nopl (%rax) +// DISASM-NEXT: 201030: ff 25 e2 1f 00 00 jmpq *8162(%rip) +// DISASM-NEXT: 201036: 68 00 00 00 00 pushq $0 +// DISASM-NEXT: 20103b: e9 e0 ff ff ff jmp -32 <.plt> +// DISASM-NEXT: 201040: ff 25 da 1f 00 00 jmpq *8154(%rip) +// DISASM-NEXT: 201046: 68 01 00 00 00 pushq $1 +// DISASM-NEXT: 20104b: e9 d0 ff ff ff jmp -48 <.plt> +// DISASM-NEXT: 201050: ff 25 d2 1f 00 00 jmpq *8146(%rip) +// DISASM-NEXT: 201056: 68 00 00 00 00 pushq $0 +// DISASM-NEXT: 20105b: e9 e0 ff ff ff jmp -32 <.plt+0x20> +// DISASM-NEXT: 201060: ff 25 ca 1f 00 00 jmpq *8138(%rip) +// DISASM-NEXT: 201066: 68 01 00 00 00 pushq $1 +// DISASM-NEXT: 20106b: e9 d0 ff ff ff jmp -48 <.plt+0x20> + +.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 + call bar2 + call zed2 diff --git a/test/ELF/gnu-ifunc-shared.s b/test/ELF/gnu-ifunc-shared.s new file mode 100644 index 0000000000000..30142b6dfe598 --- /dev/null +++ b/test/ELF/gnu-ifunc-shared.s @@ -0,0 +1,66 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +// RUN: ld.lld --shared -o %t.so %t.o +// RUN: llvm-objdump -d %t.so | FileCheck %s --check-prefix=DISASM +// RUN: llvm-readobj -r %t.so | FileCheck %s + +// Check that an IRELATIVE relocation is used for a non-preemptible ifunc +// handler and a JUMP_SLOT is used for a preemptible ifunc +// DISASM: Disassembly of section .text: +// DISASM-NEXT: fct: +// DISASM-NEXT: 1000: c3 retq +// DISASM: fct2: +// DISASM-NEXT: 1001: c3 retq +// DISASM: f1: +// DISASM-NEXT: 1002: e8 49 00 00 00 callq 73 +// DISASM-NEXT: 1007: e8 24 00 00 00 callq 36 +// DISASM-NEXT: 100c: e8 2f 00 00 00 callq 47 +// DISASM-NEXT: 1011: c3 retq +// DISASM: f2: +// DISASM-NEXT: 1012: c3 retq +// DISASM-NEXT: Disassembly of section .plt: +// DISASM-NEXT: .plt: +// DISASM-NEXT: 1020: ff 35 e2 1f 00 00 pushq 8162(%rip) +// DISASM-NEXT: 1026: ff 25 e4 1f 00 00 jmpq *8164(%rip) +// DISASM-NEXT: 102c: 0f 1f 40 00 nopl (%rax) +// DISASM-NEXT: 1030: ff 25 e2 1f 00 00 jmpq *8162(%rip) +// DISASM-NEXT: 1036: 68 00 00 00 00 pushq $0 +// DISASM-NEXT: 103b: e9 e0 ff ff ff jmp -32 <.plt> +// DISASM-NEXT: 1040: ff 25 da 1f 00 00 jmpq *8154(%rip) +// DISASM-NEXT: 1046: 68 01 00 00 00 pushq $1 +// DISASM-NEXT: 104b: e9 d0 ff ff ff jmp -48 <.plt> +// DISASM-NEXT: 1050: ff 25 d2 1f 00 00 jmpq *8146(%rip) +// DISASM-NEXT: 1056: 68 00 00 00 00 pushq $0 +// DISASM-NEXT: 105b: e9 e0 ff ff ff jmp -32 <.plt+0x20> + +// CHECK: Relocations [ +// CHECK-NEXT: Section (4) .rela.plt { +// CHECK-NEXT: 0x3018 R_X86_64_JUMP_SLOT fct2 0x0 +// CHECK-NEXT: 0x3020 R_X86_64_JUMP_SLOT f2 0x0 +// CHECK-NEXT: 0x3028 R_X86_64_IRELATIVE - 0x1000 + + // Hidden expect IRELATIVE + .globl fct + .hidden fct + .type fct, STT_GNU_IFUNC +fct: + ret + + // Not hidden expect JUMP_SLOT + .globl fct2 + .type fct2, STT_GNU_IFUNC +fct2: + ret + + .globl f1 + .type f1, @function +f1: + call fct + call fct2 + call f2@PLT + ret + + .globl f2 + .type f2, @function +f2: + ret diff --git a/test/ELF/gnu-ifunc.s b/test/ELF/gnu-ifunc.s index 5336c89a563b8..f86f0300baaff 100644 --- a/test/ELF/gnu-ifunc.s +++ b/test/ELF/gnu-ifunc.s @@ -15,15 +15,15 @@ // CHECK-NEXT: Address: [[RELA:.*]] // CHECK-NEXT: Offset: 0x158 // CHECK-NEXT: Size: 48 -// CHECK-NEXT: Link: 5 +// CHECK-NEXT: Link: 6 // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 8 // CHECK-NEXT: EntrySize: 24 // CHECK-NEXT: } // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.plt { -// CHECK-NEXT: 0x12018 R_X86_64_IRELATIVE -// CHECK-NEXT: 0x12020 R_X86_64_IRELATIVE +// CHECK-NEXT: 0x202000 R_X86_64_IRELATIVE +// CHECK-NEXT: 0x202008 R_X86_64_IRELATIVE // CHECK-NEXT: } // CHECK-NEXT: ] // CHECK: Symbols [ @@ -38,7 +38,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: __rela_iplt_end -// CHECK-NEXT: Value: 0x10188 +// CHECK-NEXT: Value: 0x200188 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -60,7 +60,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x11002 +// CHECK-NEXT: Value: 0x201002 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None @@ -69,7 +69,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: bar -// CHECK-NEXT: Value: 0x11001 +// CHECK-NEXT: Value: 0x201001 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: GNU_IFunc @@ -78,7 +78,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: foo -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: 0x201000 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: GNU_IFunc @@ -87,28 +87,25 @@ // CHECK-NEXT: } // CHECK-NEXT: ] -// DISASM: Disassembly of section .text: +// DISASM: Disassembly of section .text: // DISASM-NEXT: foo: -// DISASM-NEXT: 11000: c3 retq +// DISASM-NEXT: 201000: {{.*}} retq // DISASM: bar: -// DISASM-NEXT: 11001: c3 retq +// DISASM-NEXT: 201001: {{.*}} retq // DISASM: _start: -// DISASM-NEXT: 11002: e8 29 00 00 00 callq 41 -// DISASM-NEXT: 11007: e8 34 00 00 00 callq 52 -// DISASM-NEXT: 1100c: ba 58 01 01 00 movl $65880, %edx -// DISASM-NEXT: 11011: ba 88 01 01 00 movl $65928, %edx -// DISASM-NEXT: 11016: ba 89 01 01 00 movl $65929, %edx +// DISASM-NEXT: 201002: {{.*}} callq 25 +// DISASM-NEXT: 201007: {{.*}} callq 36 +// DISASM-NEXT: 20100c: {{.*}} movl $2097496, %edx +// DISASM-NEXT: 201011: {{.*}} movl $2097544, %edx +// DISASM-NEXT: 201016: {{.*}} movl $2097545, %edx // DISASM-NEXT: Disassembly of section .plt: // DISASM-NEXT: .plt: -// DISASM-NEXT: 11020: ff 35 e2 0f 00 00 pushq 4066(%rip) -// DISASM-NEXT: 11026: ff 25 e4 0f 00 00 jmpq *4068(%rip) -// DISASM-NEXT: 1102c: 0f 1f 40 00 nopl (%rax) -// DISASM-NEXT: 11030: ff 25 e2 0f 00 00 jmpq *4066(%rip) -// DISASM-NEXT: 11036: 68 00 00 00 00 pushq $0 -// DISASM-NEXT: 1103b: e9 e0 ff ff ff jmp -32 -// DISASM-NEXT: 11040: ff 25 da 0f 00 00 jmpq *4058(%rip) -// DISASM-NEXT: 11046: 68 01 00 00 00 pushq $1 -// DISASM-NEXT: 1104b: e9 d0 ff ff ff jmp -48 +// DISASM-NEXT: 201020: {{.*}} jmpq *4058(%rip) +// DISASM-NEXT: 201026: {{.*}} pushq $0 +// DISASM-NEXT: 20102b: {{.*}} jmp -32 <_start+0xE> +// DISASM-NEXT: 201030: {{.*}} jmpq *4050(%rip) +// DISASM-NEXT: 201036: {{.*}} pushq $1 +// DISASM-NEXT: 20103b: {{.*}} jmp -48 <_start+0xE> .text .type foo STT_GNU_IFUNC diff --git a/test/ELF/got-aarch64.s b/test/ELF/got-aarch64.s index b4aa456b4e817..8f39d5a4804f0 100644 --- a/test/ELF/got-aarch64.s +++ b/test/ELF/got-aarch64.s @@ -10,7 +10,7 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x2090 +// CHECK-NEXT: Address: 0x20090 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 8 // CHECK-NEXT: Link: 0 @@ -19,16 +19,16 @@ // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x2090 R_AARCH64_GLOB_DAT dat 0x0 +// CHECK-NEXT: 0x20090 R_AARCH64_GLOB_DAT dat 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] -// Page(0x2098) - Page(0x1000) = 0x1000 = 4096 -// 0x2098 & 0xff8 = 0x98 = 152 +// Page(0x20098) - Page(0x10000) = 0x10000 = 65536 +// 0x20098 & 0xff8 = 0x98 = 152 // DISASM: main: -// DISASM-NEXT: 1000: {{.*}} adrp x0, #4096 -// DISASM-NEXT: 1004: {{.*}} ldr x0, [x0, #144] +// DISASM-NEXT: 10000: 80 00 00 90 adrp x0, #65536 +// DISASM-NEXT: 10004: 00 48 40 f9 ldr x0, [x0, #144] .global main,foo,dat .text diff --git a/test/ELF/got.s b/test/ELF/got.s index 600377ded2f7b..57c1baddfd0cc 100644 --- a/test/ELF/got.s +++ b/test/ELF/got.s @@ -12,7 +12,7 @@ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x120B0 +// CHECK-NEXT: Address: 0x2020B0 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 16 // CHECK-NEXT: Link: 0 @@ -21,22 +21,22 @@ // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x120B0 R_X86_64_GLOB_DAT bar 0x0 -// CHECK-NEXT: 0x120B8 R_X86_64_GLOB_DAT zed 0x0 +// CHECK-NEXT: 0x2020B0 R_X86_64_GLOB_DAT bar 0x0 +// CHECK-NEXT: 0x2020B8 R_X86_64_GLOB_DAT zed 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] // Unfortunately FileCheck can't do math, so we have to check for explicit // values: -// 0x120B0 - (0x11000 + 2) - 4 = 4266 -// 0x120B0 - (0x11006 + 2) - 4 = 4260 -// 0x120A8 - (0x1100c + 2) - 4 = 4262 +// 0x2020B0 - (0x201000 + 2) - 4 = 4266 +// 0x2020B0 - (0x201006 + 2) - 4 = 4260 +// 0x2020A8 - (0x20100c + 2) - 4 = 4262 // DISASM: _start: -// DISASM-NEXT: 11000: {{.*}} jmpq *4266(%rip) -// DISASM-NEXT: 11006: {{.*}} jmpq *4260(%rip) -// DISASM-NEXT: 1100c: {{.*}} jmpq *4262(%rip) +// DISASM-NEXT: 201000: {{.*}} jmpq *4266(%rip) +// DISASM-NEXT: 201006: {{.*}} jmpq *4260(%rip) +// DISASM-NEXT: 20100c: {{.*}} jmpq *4262(%rip) .global _start _start: diff --git a/test/ELF/gotpc-relax-nopic.s b/test/ELF/gotpc-relax-nopic.s index 278173557837a..3c7a4012a7d97 100644 --- a/test/ELF/gotpc-relax-nopic.s +++ b/test/ELF/gotpc-relax-nopic.s @@ -10,23 +10,23 @@ # SYMRELOC: Symbols [ # SYMRELOC: Symbol { # SYMRELOC: Name: bar -# SYMRELOC-NEXT: Value: 0x12000 +# SYMRELOC-NEXT: Value: 0x202000 -## 73728 = 0x12000 (bar) +## 2105344 = 0x202000 (bar) # DISASM: Disassembly of section .text: # DISASM-NEXT: _start: -# DISASM-NEXT: 11000: 48 81 d0 00 20 01 00 adcq $73728, %rax -# DISASM-NEXT: 11007: 48 81 c3 00 20 01 00 addq $73728, %rbx -# DISASM-NEXT: 1100e: 48 81 e1 00 20 01 00 andq $73728, %rcx -# DISASM-NEXT: 11015: 48 81 fa 00 20 01 00 cmpq $73728, %rdx -# DISASM-NEXT: 1101c: 48 81 cf 00 20 01 00 orq $73728, %rdi -# DISASM-NEXT: 11023: 48 81 de 00 20 01 00 sbbq $73728, %rsi -# DISASM-NEXT: 1102a: 48 81 ed 00 20 01 00 subq $73728, %rbp -# DISASM-NEXT: 11031: 49 81 f0 00 20 01 00 xorq $73728, %r8 -# DISASM-NEXT: 11038: 49 f7 c7 00 20 01 00 testq $73728, %r15 +# DISASM-NEXT: 201000: {{.*}} adcq $2105344, %rax +# DISASM-NEXT: 201007: {{.*}} addq $2105344, %rbx +# DISASM-NEXT: 20100e: {{.*}} andq $2105344, %rcx +# DISASM-NEXT: 201015: {{.*}} cmpq $2105344, %rdx +# DISASM-NEXT: 20101c: {{.*}} orq $2105344, %rdi +# DISASM-NEXT: 201023: {{.*}} sbbq $2105344, %rsi +# DISASM-NEXT: 20102a: {{.*}} subq $2105344, %rbp +# DISASM-NEXT: 201031: {{.*}} xorq $2105344, %r8 +# DISASM-NEXT: 201038: {{.*}} testq $2105344, %r15 # RUN: ld.lld -shared %t.o -o %t2 -# RUN: llvm-readobj -s %t2 | FileCheck --check-prefix=SEC-PIC %s +# RUN: llvm-readobj -s -r -d %t2 | FileCheck --check-prefix=SEC-PIC %s # RUN: llvm-objdump -d %t2 | FileCheck --check-prefix=DISASM-PIC %s # SEC-PIC: Section { # SEC-PIC: Index: @@ -36,29 +36,35 @@ # SEC-PIC-NEXT: SHF_ALLOC # SEC-PIC-NEXT: SHF_WRITE # SEC-PIC-NEXT: ] -# SEC-PIC-NEXT: Address: 0x2090 -# SEC-PIC-NEXT: Offset: 0x2090 +# SEC-PIC-NEXT: Address: 0x20A0 +# SEC-PIC-NEXT: Offset: 0x20A0 # SEC-PIC-NEXT: Size: 8 # SEC-PIC-NEXT: Link: # SEC-PIC-NEXT: Info: # SEC-PIC-NEXT: AddressAlignment: # SEC-PIC-NEXT: EntrySize: # SEC-PIC-NEXT: } +# SEC-PIC: Relocations [ +# SEC-PIC-NEXT: Section ({{.*}}) .rela.dyn { +# SEC-PIC-NEXT: 0x20A0 R_X86_64_RELATIVE - 0x3000 +# SEC-PIC-NEXT: } +# SEC-PIC-NEXT: ] +# SEC-PIC: 0x000000006FFFFFF9 RELACOUNT 1 ## Check that there was no relaxation performed. All values refer to got entry. -## Ex: 0x1000 + 4233 + 7 = 0x2090 -## 0x102a + 4191 + 7 = 0x2090 +## Ex: 0x1000 + 4249 + 7 = 0x20A0 +## 0x102a + 4207 + 7 = 0x20A0 # DISASM-PIC: Disassembly of section .text: # DISASM-PIC-NEXT: _start: -# DISASM-PIC-NEXT: 1000: 48 13 05 89 10 00 00 adcq 4233(%rip), %rax -# DISASM-PIC-NEXT: 1007: 48 03 1d 82 10 00 00 addq 4226(%rip), %rbx -# DISASM-PIC-NEXT: 100e: 48 23 0d 7b 10 00 00 andq 4219(%rip), %rcx -# DISASM-PIC-NEXT: 1015: 48 3b 15 74 10 00 00 cmpq 4212(%rip), %rdx -# DISASM-PIC-NEXT: 101c: 48 0b 3d 6d 10 00 00 orq 4205(%rip), %rdi -# DISASM-PIC-NEXT: 1023: 48 1b 35 66 10 00 00 sbbq 4198(%rip), %rsi -# DISASM-PIC-NEXT: 102a: 48 2b 2d 5f 10 00 00 subq 4191(%rip), %rbp -# DISASM-PIC-NEXT: 1031: 4c 33 05 58 10 00 00 xorq 4184(%rip), %r8 -# DISASM-PIC-NEXT: 1038: 4c 85 3d 51 10 00 00 testq 4177(%rip), %r15 +# DISASM-PIC-NEXT: 1000: {{.*}} adcq 4249(%rip), %rax +# DISASM-PIC-NEXT: 1007: {{.*}} addq 4242(%rip), %rbx +# DISASM-PIC-NEXT: 100e: {{.*}} andq 4235(%rip), %rcx +# DISASM-PIC-NEXT: 1015: {{.*}} cmpq 4228(%rip), %rdx +# DISASM-PIC-NEXT: 101c: {{.*}} orq 4221(%rip), %rdi +# DISASM-PIC-NEXT: 1023: {{.*}} sbbq 4214(%rip), %rsi +# DISASM-PIC-NEXT: 102a: {{.*}} subq 4207(%rip), %rbp +# DISASM-PIC-NEXT: 1031: {{.*}} xorq 4200(%rip), %r8 +# DISASM-PIC-NEXT: 1038: {{.*}} testq 4193(%rip), %r15 .data .type bar, @object diff --git a/test/ELF/gotpc-relax.s b/test/ELF/gotpc-relax.s index 422e10439d000..3d2f2ab578e83 100644 --- a/test/ELF/gotpc-relax.s +++ b/test/ELF/gotpc-relax.s @@ -8,17 +8,17 @@ # RELOC: Relocations [ # RELOC: ] -# 0x11003 + 7 - 10 = 0x11000 -# 0x1100a + 7 - 17 = 0x11000 -# 0x11011 + 7 - 23 = 0x11001 -# 0x11018 + 7 - 30 = 0x11001 +# 0x201003 + 7 - 10 = 0x201000 +# 0x20100a + 7 - 17 = 0x201000 +# 0x201011 + 7 - 23 = 0x201001 +# 0x201018 + 7 - 30 = 0x201001 # DISASM: Disassembly of section .text: # DISASM-NEXT: foo: -# DISASM-NEXT: 11000: 90 nop +# DISASM-NEXT: 201000: 90 nop # DISASM: hid: -# DISASM-NEXT: 11001: 90 nop +# DISASM-NEXT: 201001: 90 nop # DISASM: ifunc: -# DISASM-NEXT: 11002: c3 retq +# DISASM-NEXT: 201002: c3 retq # DISASM: _start: # DISASM-NEXT: leaq -10(%rip), %rax # DISASM-NEXT: leaq -17(%rip), %rax diff --git a/test/ELF/i386-gotoff-shared.s b/test/ELF/i386-gotoff-shared.s new file mode 100644 index 0000000000000..01242ad01c351 --- /dev/null +++ b/test/ELF/i386-gotoff-shared.s @@ -0,0 +1,23 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-readobj -s %t.so | FileCheck %s +// RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=DISASM %s + +bar: + movl bar@GOTOFF(%ebx), %eax + mov bar@GOT, %eax + +// CHECK: Name: .got +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: SHF_WRITE +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x2050 +// CHECK-NEXT: Offset: 0x2050 +// CHECK-NEXT: Size: 4 + +// 0x1000 - (0x2050 + 4) = -4180 + +// DISASM: 1000: {{.*}} movl -4180(%ebx), %eax diff --git a/test/ELF/i386-gotpc.s b/test/ELF/i386-gotpc.s index 14c2fcbec0644..8222effd66551 100644 --- a/test/ELF/i386-gotpc.s +++ b/test/ELF/i386-gotpc.s @@ -6,7 +6,7 @@ movl $_GLOBAL_OFFSET_TABLE_, %eax -// CHECK: Name: .got (38) +// CHECK: Name: .got // CHECK-NEXT: Type: SHT_PROGBITS // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC diff --git a/test/ELF/i386-pc16.test b/test/ELF/i386-pc16.test new file mode 100644 index 0000000000000..46c54ebb1510f --- /dev/null +++ b/test/ELF/i386-pc16.test @@ -0,0 +1,40 @@ +# REQUIRES: x86 + +# RUN: yaml2obj %s -o %t.o +# RUN: ld.lld %t.o -o %t.exe +# RUN: llvm-objdump -s -section=.text %t.exe 2>&1 | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 11000 56441111 52341111 + +!ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_386 +Sections: + - Type: SHT_PROGBITS + Name: .text + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x04 + Content: "1111111111111111" + - Type: SHT_REL + Name: .rel.text + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 0 + Symbol: _start + Type: R_386_16 + - Offset: 4 + Symbol: _start + Type: R_386_PC16 +Symbols: + Global: + - Name: _start + Type: STT_FUNC + Section: .text + Value: 0x12345 + Size: 4 diff --git a/test/ELF/i386-tls-got.s b/test/ELF/i386-tls-got.s new file mode 100644 index 0000000000000..56be4a138d9be --- /dev/null +++ b/test/ELF/i386-tls-got.s @@ -0,0 +1,7 @@ +# REQUIRES: x86 +# 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 + + addl foobar@INDNTPOFF, %eax diff --git a/test/ELF/i386-tls-ie-shared.s b/test/ELF/i386-tls-ie-shared.s index a2c25e2d2f81e..8becc3199f956 100644 --- a/test/ELF/i386-tls-ie-shared.s +++ b/test/ELF/i386-tls-ie-shared.s @@ -2,7 +2,7 @@ // RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %p/Inputs/tls-opt-iele-i686-nopic.s -o %tso.o // RUN: ld.lld -shared %tso.o -o %tso // RUN: ld.lld -shared %t.o %tso -o %t1 -// RUN: llvm-readobj -s -r %t1 | FileCheck --check-prefix=GOTRELSHARED %s +// RUN: llvm-readobj -s -r -d %t1 | FileCheck --check-prefix=GOTRELSHARED %s // RUN: llvm-objdump -d %t1 | FileCheck --check-prefix=DISASMSHARED %s // GOTRELSHARED: Section { @@ -13,8 +13,8 @@ // GOTRELSHARED-NEXT: SHF_ALLOC // GOTRELSHARED-NEXT: SHF_WRITE // GOTRELSHARED-NEXT: ] -// GOTRELSHARED-NEXT: Address: 0x1050 -// GOTRELSHARED-NEXT: Offset: 0x1050 +// GOTRELSHARED-NEXT: Address: 0x1058 +// GOTRELSHARED-NEXT: Offset: 0x1058 // GOTRELSHARED-NEXT: Size: 16 // GOTRELSHARED-NEXT: Link: 0 // GOTRELSHARED-NEXT: Info: 0 @@ -31,12 +31,13 @@ // GOTRELSHARED-NEXT: 0x202D R_386_RELATIVE - 0x0 // GOTRELSHARED-NEXT: 0x2036 R_386_RELATIVE - 0x0 // GOTRELSHARED-NEXT: 0x203F R_386_RELATIVE - 0x0 -// GOTRELSHARED-NEXT: 0x1050 R_386_TLS_TPOFF tlslocal0 0x0 -// GOTRELSHARED-NEXT: 0x1054 R_386_TLS_TPOFF tlslocal1 0x0 -// GOTRELSHARED-NEXT: 0x1058 R_386_TLS_TPOFF tlsshared0 0x0 -// GOTRELSHARED-NEXT: 0x105C R_386_TLS_TPOFF tlsshared1 0x0 +// GOTRELSHARED-NEXT: 0x1058 R_386_TLS_TPOFF tlslocal0 0x0 +// GOTRELSHARED-NEXT: 0x105C R_386_TLS_TPOFF tlslocal1 0x0 +// GOTRELSHARED-NEXT: 0x1060 R_386_TLS_TPOFF tlsshared0 0x0 +// GOTRELSHARED-NEXT: 0x1064 R_386_TLS_TPOFF tlsshared1 0x0 // GOTRELSHARED-NEXT: } // GOTRELSHARED-NEXT: ] +// GOTRELSHARED: 0x6FFFFFFA RELCOUNT 8 // DISASMSHARED: Disassembly of section test: // DISASMSHARED-NEXT: _start: @@ -44,22 +45,22 @@ // (.got)[1] = 0x2054 = 8276 // (.got)[2] = 0x2058 = 8280 // (.got)[3] = 0x205C = 8284 -// DISASMSHARED-NEXT: 2000: 8b 0d 50 10 00 00 movl 4176, %ecx -// DISASMSHARED-NEXT: 2006: 65 8b 01 movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 2009: a1 50 10 00 00 movl 4176, %eax -// DISASMSHARED-NEXT: 200e: 65 8b 00 movl %gs:(%eax), %eax -// DISASMSHARED-NEXT: 2011: 03 0d 50 10 00 00 addl 4176, %ecx -// DISASMSHARED-NEXT: 2017: 65 8b 01 movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 201a: 8b 0d 54 10 00 00 movl 4180, %ecx -// DISASMSHARED-NEXT: 2020: 65 8b 01 movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 2023: a1 54 10 00 00 movl 4180, %eax -// DISASMSHARED-NEXT: 2028: 65 8b 00 movl %gs:(%eax), %eax -// DISASMSHARED-NEXT: 202b: 03 0d 54 10 00 00 addl 4180, %ecx -// DISASMSHARED-NEXT: 2031: 65 8b 01 movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 2034: 8b 0d 58 10 00 00 movl 4184, %ecx -// DISASMSHARED-NEXT: 203a: 65 8b 01 movl %gs:(%ecx), %eax -// DISASMSHARED-NEXT: 203d: 03 0d 5c 10 00 00 addl 4188, %ecx -// DISASMSHARED-NEXT: 2043: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 2000: 8b 0d 58 10 00 00 movl 4184, %ecx +// DISASMSHARED-NEXT: 2006: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 2009: a1 58 10 00 00 movl 4184, %eax +// DISASMSHARED-NEXT: 200e: 65 8b 00 movl %gs:(%eax), %eax +// DISASMSHARED-NEXT: 2011: 03 0d 58 10 00 00 addl 4184, %ecx +// DISASMSHARED-NEXT: 2017: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 201a: 8b 0d 5c 10 00 00 movl 4188, %ecx +// DISASMSHARED-NEXT: 2020: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 2023: a1 5c 10 00 00 movl 4188, %eax +// DISASMSHARED-NEXT: 2028: 65 8b 00 movl %gs:(%eax), %eax +// DISASMSHARED-NEXT: 202b: 03 0d 5c 10 00 00 addl 4188, %ecx +// DISASMSHARED-NEXT: 2031: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 2034: 8b 0d 60 10 00 00 movl 4192, %ecx +// DISASMSHARED-NEXT: 203a: 65 8b 01 movl %gs:(%ecx), %eax +// DISASMSHARED-NEXT: 203d: 03 0d 64 10 00 00 addl 4196, %ecx +// DISASMSHARED-NEXT: 2043: 65 8b 01 movl %gs:(%ecx), %eax .type tlslocal0,@object .section .tbss,"awT",@nobits diff --git a/test/ELF/icf-non-mergeable.s b/test/ELF/icf-non-mergeable.s new file mode 100644 index 0000000000000..378c7b33696d2 --- /dev/null +++ b/test/ELF/icf-non-mergeable.s @@ -0,0 +1,28 @@ +// REQUIRES: x86 + +// This file contains two functions. They are themselves identical, +// but because they have reloactions against different data section, +// they are not mergeable. + +// 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/icf-non-mergeable.s -o %t2 + +// RUN: ld.lld %t1 %t2 -o %t3 --icf=all --verbose | FileCheck %s + +// CHECK-NOT: selected .text.f1 +// CHECK-NOT: removed .text.f2 + +.globl _start, f1, f2, d1, d2 +_start: + ret + +.section .text.f1, "ax" +f1: + movl $5, d1 + ret + +.section .text.f2, "ax" +f2: + movl $5, d2 + ret diff --git a/test/ELF/icf4.s b/test/ELF/icf4.s index ad16d48775d6d..08830c8e503c8 100644 --- a/test/ELF/icf4.s +++ b/test/ELF/icf4.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 %t --icf=all --verbose | FileCheck %s +# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s # CHECK-NOT: Selected .text.f1 # CHECK-NOT: Selected .text.f2 diff --git a/test/ELF/icf5.s b/test/ELF/icf5.s index cf466585c581d..952fe3601a4d9 100644 --- a/test/ELF/icf5.s +++ b/test/ELF/icf5.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 %t --icf=all --verbose | FileCheck %s +# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s # CHECK-NOT: Selected .text.f1 # CHECK-NOT: Selected .text.f2 diff --git a/test/ELF/icf7.s b/test/ELF/icf7.s index f1fca5b2f2d53..8504ca2ac610b 100644 --- a/test/ELF/icf7.s +++ b/test/ELF/icf7.s @@ -7,8 +7,8 @@ # CHECK: selected .text.f1 # CHECK: removed .text.f2 -# ALIGN: 0000000000011000 .text 00000000 _start -# ALIGN: 0000000000011100 .text 00000000 f1 +# ALIGN: 0000000000201000 .text 00000000 _start +# ALIGN: 0000000000201100 .text 00000000 f1 .globl _start, f1, f2 _start: diff --git a/test/ELF/image-base.s b/test/ELF/image-base.s index 0be5059dcad81..a6d160744b702 100644 --- a/test/ELF/image-base.s +++ b/test/ELF/image-base.s @@ -3,6 +3,10 @@ # RUN: ld.lld -image-base=0x1000000 %t -o %t1 # RUN: llvm-readobj -program-headers %t1 | FileCheck %s +# RUN: ld.lld -image-base=0x1000 -z max-page-size=0x2000 %t -o %t1 2>&1 | FileCheck --check-prefix=WARN %s +# WARN: warning: -image-base: address isn't multiple of page size: 0x1000 + + .global _start _start: nop diff --git a/test/ELF/incompatible-ar-first.s b/test/ELF/incompatible-ar-first.s index 8a8aaec220dd6..e076561d11ae5 100644 --- a/test/ELF/incompatible-ar-first.s +++ b/test/ELF/incompatible-ar-first.s @@ -6,6 +6,6 @@ // We used to crash when // * The first object seen by the symbol table is from an archive. // * -m was not used. -// CHECK: a.o is incompatible with {{.*}}b.o +// CHECK: .a({{.*}}a.o) is incompatible with {{.*}}b.o // REQUIRES: x86 diff --git a/test/ELF/incompatible.s b/test/ELF/incompatible.s index 82055b7a104a9..ce84606ad7e26 100644 --- a/test/ELF/incompatible.s +++ b/test/ELF/incompatible.s @@ -50,7 +50,7 @@ // 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 -// ARCHIVE: a.o is incompatible with {{.*}}b.o +// ARCHIVE: .a({{.*}}a.o) is incompatible with {{.*}}b.o .global _start _start: .data diff --git a/test/ELF/invalid-cie-length.s b/test/ELF/invalid-cie-length.s index e9ad3ca8ba824..e5ba27cf46169 100644 --- a/test/ELF/invalid-cie-length.s +++ b/test/ELF/invalid-cie-length.s @@ -6,4 +6,4 @@ .section .eh_frame .byte 0 -// CHECK: CIE/FDE too small +// CHECK: {{.*}}:(.eh_frame+0x0): CIE/FDE too small diff --git a/test/ELF/invalid-cie-length2.s b/test/ELF/invalid-cie-length2.s index 94a677eb8913a..4aea66952134b 100644 --- a/test/ELF/invalid-cie-length2.s +++ b/test/ELF/invalid-cie-length2.s @@ -6,4 +6,4 @@ .section .eh_frame .long 42 -// CHECK: CIE/FIE ends past the end of the section +// CHECK: {{.*}}:(.eh_frame+0x0): CIE/FDE ends past the end of the section diff --git a/test/ELF/invalid-cie-length3.s b/test/ELF/invalid-cie-length3.s index 665fc80a24b4b..ebd2690a9d981 100644 --- a/test/ELF/invalid-cie-length3.s +++ b/test/ELF/invalid-cie-length3.s @@ -6,4 +6,4 @@ .section .eh_frame .long 0xFFFFFFFC -// CHECK: CIE/FIE ends past the end of the section +// CHECK: {{.*}}:(.eh_frame+0x0): CIE/FDE ends past the end of the section diff --git a/test/ELF/invalid-cie-length4.s b/test/ELF/invalid-cie-length4.s index daa20d1968117..8c7cc00dfcaf8 100644 --- a/test/ELF/invalid-cie-length4.s +++ b/test/ELF/invalid-cie-length4.s @@ -7,4 +7,4 @@ .long 0xFFFFFFFF .byte 0 -// CHECK: CIE/FDE too large +// CHECK: {{.*}}:(.eh_frame+0x0): CIE/FDE too large diff --git a/test/ELF/invalid-dynamic-list.test b/test/ELF/invalid-dynamic-list.test index 0e7c820f563e4..f560ceed0f8bd 100644 --- a/test/ELF/invalid-dynamic-list.test +++ b/test/ELF/invalid-dynamic-list.test @@ -11,27 +11,27 @@ # RUN: echo foobar > %t1 # RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR1 %s -# ERR1: line 1: { expected, but got foobar +# ERR1: {{.*}}:1: { expected, but got foobar # RUN: echo "{ foobar;" > %t1 # RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR2 %s -# ERR2: line 1: unexpected EOF +# ERR2: {{.*}}:1: unexpected EOF ## Missing ';' before '}' # RUN: echo "{ foobar }" > %t1 # RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR3 %s -# ERR3: line 1: ; expected, but got } +# ERR3: {{.*}}:1: ; expected, but got } ## Missing final ';' # RUN: echo "{ foobar; }" > %t1 # RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR4 %s -# ERR4: line 1: unexpected EOF +# ERR4: {{.*}}:1: unexpected EOF ## Missing \" in foobar definition # RUN echo "{ \"foobar; };" > %t1 # RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR5 %s -# ERR5: line 1: unexpected EOF +# ERR5: {{.*}}:1: unexpected EOF # RUN: echo "{ extern \"BOGUS\" { test }; };" > %t1 # RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR6 %s -# ERR6: line 1: ; expected, but got BOGUS +# ERR6: {{.*}}:1: Unknown language diff --git a/test/ELF/invalid-elf.test b/test/ELF/invalid-elf.test deleted file mode 100644 index c3a97d37ffa97..0000000000000 --- a/test/ELF/invalid-elf.test +++ /dev/null @@ -1,35 +0,0 @@ -# RUN: llvm-mc %s -o %t -filetype=obj -triple x86_64-pc-linux - -# RUN: not ld.lld %t %p/Inputs/invalid-data-encoding.a -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=INVALID-DATA-ENC %s -# INVALID-DATA-ENC: invalid data encoding: test.o - -# RUN: not ld.lld %t %p/Inputs/invalid-file-class.a -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=INVALID-FILE-CLASS %s -# INVALID-FILE-CLASS: invalid file class: test.o - -# RUN: not ld.lld %p/Inputs/invalid-symtab-sh_info.elf -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=INVALID-SYMTAB-SHINFO %s -# INVALID-SYMTAB-SHINFO: invalid sh_info in symbol table - -# RUN: not ld.lld %p/Inputs/invalid-binding.elf -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=INVALID-BINDING %s -# INVALID-BINDING: unexpected binding - -# RUN: not ld.lld %p/Inputs/invalid-section-index.elf -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=INVALID-SECTION-INDEX-LLD %s -# INVALID-SECTION-INDEX-LLD: invalid section index - -# RUN: not ld.lld %p/Inputs/invalid-shstrndx.so -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=INVALID-SECTION-INDEX %s -# INVALID-SECTION-INDEX: Invalid section index - -# RUN: not ld.lld %p/Inputs/invalid-shentsize-zero.elf -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=INVALID-SHENTSIZE-ZERO %s -# INVALID-SHENTSIZE-ZERO: SHF_MERGE section size must be a multiple of sh_entsize - -# RUN: not ld.lld %p/Inputs/invalid-multiple-eh-relocs.elf -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=INVALID-EH-RELOCS %s -# INVALID-EH-RELOCS: multiple relocation sections to .eh_frame are not supported - -.long foo diff --git a/test/ELF/invalid-linkerscript.test b/test/ELF/invalid-linkerscript.test index e0881662b962b..3316becce1dca 100644 --- a/test/ELF/invalid-linkerscript.test +++ b/test/ELF/invalid-linkerscript.test @@ -15,7 +15,7 @@ # RUN: echo foobar > %t1 # RUN: not ld.lld %t1 no-such-file 2>&1 | FileCheck -check-prefix=ERR1 %s -# ERR1: unknown directive: foobar +# ERR1: unexpected EOF # ERR1: cannot open no-such-file: # RUN: echo "foo \"bar" > %t2 diff --git a/test/ELF/Inputs/invalid-binding.elf b/test/ELF/invalid/Inputs/binding.elf Binary files differindex 61b5af9b456c7..61b5af9b456c7 100644 --- a/test/ELF/Inputs/invalid-binding.elf +++ b/test/ELF/invalid/Inputs/binding.elf diff --git a/test/ELF/invalid/Inputs/broken-relaxation-x64.elf b/test/ELF/invalid/Inputs/broken-relaxation-x64.elf Binary files differnew file mode 100644 index 0000000000000..01a6af9a7fb53 --- /dev/null +++ b/test/ELF/invalid/Inputs/broken-relaxation-x64.elf diff --git a/test/ELF/Inputs/invalid-cie-version2.elf b/test/ELF/invalid/Inputs/cie-version2.elf Binary files differindex 87f8a5be76f4c..87f8a5be76f4c 100644 --- a/test/ELF/Inputs/invalid-cie-version2.elf +++ b/test/ELF/invalid/Inputs/cie-version2.elf diff --git a/test/ELF/invalid/Inputs/common-symbol-alignment.elf b/test/ELF/invalid/Inputs/common-symbol-alignment.elf Binary files differnew file mode 100644 index 0000000000000..9e7823b852b2c --- /dev/null +++ b/test/ELF/invalid/Inputs/common-symbol-alignment.elf diff --git a/test/ELF/invalid/Inputs/common-symbol-alignment2.elf b/test/ELF/invalid/Inputs/common-symbol-alignment2.elf Binary files differnew file mode 100644 index 0000000000000..21c2457cbea16 --- /dev/null +++ b/test/ELF/invalid/Inputs/common-symbol-alignment2.elf diff --git a/test/ELF/Inputs/invalid-data-encoding.a b/test/ELF/invalid/Inputs/data-encoding.a Binary files differindex ff2b37318c1e6..ff2b37318c1e6 100644 --- a/test/ELF/Inputs/invalid-data-encoding.a +++ b/test/ELF/invalid/Inputs/data-encoding.a diff --git a/test/ELF/invalid/Inputs/dynamic-section-sh_size.elf b/test/ELF/invalid/Inputs/dynamic-section-sh_size.elf Binary files differnew file mode 100644 index 0000000000000..ea35dba95179e --- /dev/null +++ b/test/ELF/invalid/Inputs/dynamic-section-sh_size.elf diff --git a/test/ELF/Inputs/invalid-file-class.a b/test/ELF/invalid/Inputs/file-class.a Binary files differindex f0ce607b4fdc8..f0ce607b4fdc8 100644 --- a/test/ELF/Inputs/invalid-file-class.a +++ b/test/ELF/invalid/Inputs/file-class.a diff --git a/test/ELF/invalid/Inputs/invalid-e_shnum.elf b/test/ELF/invalid/Inputs/invalid-e_shnum.elf Binary files differnew file mode 100644 index 0000000000000..0b46fbd8cec0c --- /dev/null +++ b/test/ELF/invalid/Inputs/invalid-e_shnum.elf diff --git a/test/ELF/invalid/Inputs/invalid-relocation-x64.elf b/test/ELF/invalid/Inputs/invalid-relocation-x64.elf Binary files differnew file mode 100644 index 0000000000000..25df2944614ea --- /dev/null +++ b/test/ELF/invalid/Inputs/invalid-relocation-x64.elf diff --git a/test/ELF/invalid/Inputs/mips-invalid-options-descriptor.elf b/test/ELF/invalid/Inputs/mips-invalid-options-descriptor.elf Binary files differnew file mode 100644 index 0000000000000..85feeebc61984 --- /dev/null +++ b/test/ELF/invalid/Inputs/mips-invalid-options-descriptor.elf diff --git a/test/ELF/Inputs/invalid-multiple-eh-relocs.elf b/test/ELF/invalid/Inputs/multiple-eh-relocs.elf Binary files differindex 62914596256a6..62914596256a6 100644 --- a/test/ELF/Inputs/invalid-multiple-eh-relocs.elf +++ b/test/ELF/invalid/Inputs/multiple-eh-relocs.elf diff --git a/test/ELF/invalid/Inputs/section-alignment-notpow2.elf b/test/ELF/invalid/Inputs/section-alignment-notpow2.elf Binary files differnew file mode 100644 index 0000000000000..59d4de7e73032 --- /dev/null +++ b/test/ELF/invalid/Inputs/section-alignment-notpow2.elf diff --git a/test/ELF/Inputs/invalid-section-index.elf b/test/ELF/invalid/Inputs/section-index.elf Binary files differindex ec5adcf3b0b8c..ec5adcf3b0b8c 100644 --- a/test/ELF/Inputs/invalid-section-index.elf +++ b/test/ELF/invalid/Inputs/section-index.elf diff --git a/test/ELF/invalid/Inputs/section-index2.elf b/test/ELF/invalid/Inputs/section-index2.elf Binary files differnew file mode 100644 index 0000000000000..5d842880b3755 --- /dev/null +++ b/test/ELF/invalid/Inputs/section-index2.elf diff --git a/test/ELF/Inputs/invalid-shentsize-zero.elf b/test/ELF/invalid/Inputs/shentsize-zero.elf Binary files differindex 5fa7df2456195..5fa7df2456195 100644 --- a/test/ELF/Inputs/invalid-shentsize-zero.elf +++ b/test/ELF/invalid/Inputs/shentsize-zero.elf diff --git a/test/ELF/invalid/Inputs/sht-group.elf b/test/ELF/invalid/Inputs/sht-group.elf Binary files differnew file mode 100644 index 0000000000000..5cb033628418d --- /dev/null +++ b/test/ELF/invalid/Inputs/sht-group.elf diff --git a/test/ELF/invalid/Inputs/symbol-index.elf b/test/ELF/invalid/Inputs/symbol-index.elf Binary files differnew file mode 100644 index 0000000000000..f31ffbf602c3b --- /dev/null +++ b/test/ELF/invalid/Inputs/symbol-index.elf diff --git a/test/ELF/invalid/Inputs/symbol-name-offset.elf b/test/ELF/invalid/Inputs/symbol-name-offset.elf Binary files differnew file mode 100644 index 0000000000000..8b8abde798731 --- /dev/null +++ b/test/ELF/invalid/Inputs/symbol-name-offset.elf diff --git a/test/ELF/Inputs/invalid-symtab-sh_info.elf b/test/ELF/invalid/Inputs/symtab-sh_info.elf Binary files differindex aa63d582d757c..aa63d582d757c 100644 --- a/test/ELF/Inputs/invalid-symtab-sh_info.elf +++ b/test/ELF/invalid/Inputs/symtab-sh_info.elf diff --git a/test/ELF/invalid/Inputs/symtab-sh_info2.elf b/test/ELF/invalid/Inputs/symtab-sh_info2.elf Binary files differnew file mode 100644 index 0000000000000..4fea12cf20333 --- /dev/null +++ b/test/ELF/invalid/Inputs/symtab-sh_info2.elf diff --git a/test/ELF/invalid/Inputs/symtab-sh_info3.elf b/test/ELF/invalid/Inputs/symtab-sh_info3.elf Binary files differnew file mode 100644 index 0000000000000..ca889fbca1aaa --- /dev/null +++ b/test/ELF/invalid/Inputs/symtab-sh_info3.elf diff --git a/test/ELF/invalid/Inputs/tls-symbol.elf b/test/ELF/invalid/Inputs/tls-symbol.elf Binary files differnew file mode 100644 index 0000000000000..78c759897ddcc --- /dev/null +++ b/test/ELF/invalid/Inputs/tls-symbol.elf diff --git a/test/ELF/invalid/Inputs/too-short.elf b/test/ELF/invalid/Inputs/too-short.elf Binary files differnew file mode 100644 index 0000000000000..077f392f1dc4d --- /dev/null +++ b/test/ELF/invalid/Inputs/too-short.elf diff --git a/test/ELF/invalid/broken-relaxation-x64.s b/test/ELF/invalid/broken-relaxation-x64.s new file mode 100644 index 0000000000000..10d4655847d52 --- /dev/null +++ b/test/ELF/invalid/broken-relaxation-x64.s @@ -0,0 +1,46 @@ +# REQUIRES: x86 + +# RUN: yaml2obj %s -o %t.o +# RUN: not ld.lld %t.o -o %t.exe 2>&1 | FileCheck --check-prefix=ERR %s +# ERR: R_X86_64_GOTTPOFF must be used in MOVQ or ADDQ instructions only +# ERR: R_X86_64_GOTTPOFF must be used in MOVQ or ADDQ instructions only + +## YAML below contains 2 relocations of type R_X86_64_GOTTPOFF, and a .text +## with fake content filled by 0xFF. That means instructions for relaxation are +## "broken", so they does not match any known valid relaxations. We also generate +## .tls section because we need it for correct proccessing of STT_TLS symbol. +!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: "FFFFFFFFFFFFFFFF" + - Type: SHT_PROGBITS + Name: .tls + Flags: [ SHF_ALLOC, SHF_TLS ] + - Type: SHT_REL + Name: .rel.text + Link: .symtab + Info: .text + AddressAlign: 0x04 + Relocations: + - Offset: 4 + Symbol: foo + Type: R_X86_64_GOTTPOFF + - Offset: 4 + Symbol: foo + Type: R_X86_64_GOTTPOFF +Symbols: + Global: + - Name: foo + Type: STT_TLS + Section: .text + Value: 0x12345 + Size: 4 diff --git a/test/ELF/invalid/common-symbol-alignment.s b/test/ELF/invalid/common-symbol-alignment.s new file mode 100644 index 0000000000000..2a654b11479be --- /dev/null +++ b/test/ELF/invalid/common-symbol-alignment.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 + +## common-symbol-alignment.elf contains common symbol with zero alignment. +# RUN: not ld.lld %S/Inputs/common-symbol-alignment.elf \ +# RUN: -o %t 2>&1 | FileCheck %s +# CHECK: common symbol 'bar' has invalid alignment: 0 + +## common-symbol-alignment2.elf contains common symbol alignment greater +## than UINT32_MAX. +# RUN: not ld.lld %S/Inputs/common-symbol-alignment2.elf \ +# RUN: -o %t 2>&1 | FileCheck %s --check-prefix=BIG +# BIG: common symbol 'bar' has invalid alignment: 271644049215 diff --git a/test/ELF/invalid/dynamic-section-size.s b/test/ELF/invalid/dynamic-section-size.s new file mode 100644 index 0000000000000..7d12904801e44 --- /dev/null +++ b/test/ELF/invalid/dynamic-section-size.s @@ -0,0 +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: FileCheck %s +# CHECK: getSectionContentsAsArray failed: Invalid data was encountered while parsing the file diff --git a/test/ELF/invalid/eh-frame-hdr-no-out.s b/test/ELF/invalid/eh-frame-hdr-no-out.s new file mode 100644 index 0000000000000..8379253d9fd06 --- /dev/null +++ b/test/ELF/invalid/eh-frame-hdr-no-out.s @@ -0,0 +1,6 @@ +// REQUIRES: x86 +// RUN: not ld.lld --eh-frame-hdr %p/Inputs/cie-version2.elf -o %t >& %t.log +// RUN: FileCheck %s < %t.log + +// cie-version2.elf contains unsupported version of CIE = 2. +// CHECK: FDE version 1 or 3 expected, but got 2 diff --git a/test/ELF/invalid/invalid-e_shnum.s b/test/ELF/invalid/invalid-e_shnum.s new file mode 100644 index 0000000000000..0c720ffa1713e --- /dev/null +++ b/test/ELF/invalid/invalid-e_shnum.s @@ -0,0 +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 diff --git a/test/ELF/invalid/invalid-elf.test b/test/ELF/invalid/invalid-elf.test new file mode 100644 index 0000000000000..e03450ed289c4 --- /dev/null +++ b/test/ELF/invalid/invalid-elf.test @@ -0,0 +1,31 @@ +# 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 | \ +# RUN: FileCheck --check-prefix=INVALID-DATA-ENC %s +# INVALID-DATA-ENC: test.o: invalid data encoding + +# RUN: not ld.lld %t %p/Inputs/file-class.a -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=INVALID-FILE-CLASS %s +# INVALID-FILE-CLASS: test.o: invalid file class + +# RUN: not ld.lld %p/Inputs/symtab-sh_info.elf -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=INVALID-SYMTAB-SHINFO %s +# INVALID-SYMTAB-SHINFO: invalid sh_info in symbol table + +# RUN: not ld.lld %p/Inputs/binding.elf -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=INVALID-BINDING %s +# INVALID-BINDING: unexpected binding + +# RUN: not ld.lld %p/Inputs/section-index.elf -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=INVALID-SECTION-INDEX-LLD %s +# INVALID-SECTION-INDEX-LLD: invalid section index + +## section-index2.elf has local symbol with incorrect section index. +# RUN: not ld.lld %p/Inputs/section-index2.elf -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=INVALID-SECTION-INDEX-LLD %s + +# RUN: not ld.lld %p/Inputs/multiple-eh-relocs.elf -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=INVALID-EH-RELOCS %s +# INVALID-EH-RELOCS: multiple relocation sections to one section are not supported + +.long foo diff --git a/test/ELF/invalid/invalid-relocation-x64.s b/test/ELF/invalid/invalid-relocation-x64.s new file mode 100644 index 0000000000000..1ad9afa4c649c --- /dev/null +++ b/test/ELF/invalid/invalid-relocation-x64.s @@ -0,0 +1,30 @@ +## invalid-relocation-x64.elf contains relocations with invalid relocation number. +## Next yaml code was used to create initial binary. After that it +## was modified with hex-editor to replace known relocations with fake ones, +## that have 0x98 and 0x98 numbers. +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_FREEBSD + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + Info: .text + Relocations: + - Offset: 0x0000000000000000 + Symbol: '' + Type: R_X86_64_NONE + - Offset: 0x0000000000000000 + Symbol: '' + Type: R_X86_64_NONE + +# RUN: not ld.lld %p/Inputs/invalid-relocation-x64.elf -o %t2 2>&1 | FileCheck %s +# CHECK: unrecognized reloc 152 +# CHECK: unrecognized reloc 153 diff --git a/test/ELF/merge-invalid-size.s b/test/ELF/invalid/merge-invalid-size.s index 2a99e14ad836b..1dbd7cf95b7de 100644 --- a/test/ELF/merge-invalid-size.s +++ b/test/ELF/invalid/merge-invalid-size.s @@ -3,5 +3,8 @@ // RUN: not ld.lld %t.o -o %t.so 2>&1 | FileCheck %s // CHECK: SHF_MERGE section size must be a multiple of sh_entsize - .section .foo,"aM",@progbits,4 - .short 42 +// Test that we accept a zero sh_entsize. +// RUN: ld.lld %p/Inputs/shentsize-zero.elf -o %t2 + +.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 new file mode 100644 index 0000000000000..b47bd9037cc5f --- /dev/null +++ b/test/ELF/invalid/mips-invalid-options-descriptor.s @@ -0,0 +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: FileCheck %s +# CHECK: error: invalid section offset diff --git a/test/ELF/invalid/section-alignment.test b/test/ELF/invalid/section-alignment.test new file mode 100644 index 0000000000000..48da12243ac8d --- /dev/null +++ b/test/ELF/invalid/section-alignment.test @@ -0,0 +1,19 @@ +# RUN: yaml2obj %s -o %t +# RUN: not ld.lld %t -o %tout 2>&1 | FileCheck %s + +## In current lld implementation, we do not accept sh_addralign +## larger than UINT32_MAX. +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x1000000000000000 + Content: "00000000" + +# CHECK: section sh_addralign is too large diff --git a/test/ELF/invalid/section-alignment2.s b/test/ELF/invalid/section-alignment2.s new file mode 100644 index 0000000000000..aaef9f8bff5d8 --- /dev/null +++ b/test/ELF/invalid/section-alignment2.s @@ -0,0 +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: 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 new file mode 100644 index 0000000000000..f28035f0dac9f --- /dev/null +++ b/test/ELF/invalid/sht-group.s @@ -0,0 +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 +# CHECK: invalid symbol index diff --git a/test/ELF/invalid/symbol-index.s b/test/ELF/invalid/symbol-index.s new file mode 100644 index 0000000000000..4ad1d6cb232cf --- /dev/null +++ b/test/ELF/invalid/symbol-index.s @@ -0,0 +1,10 @@ +## symbol-index.elf has incorrect type of .symtab section. +## There is no symbol bodies because of that and any symbol index becomes incorrect. +## Section Headers: +## [Nr] Name Type Address Off Size ES Flg Lk Inf Al +## [ 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: 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 new file mode 100644 index 0000000000000..8daee1a3fa78b --- /dev/null +++ b/test/ELF/invalid/symbol-name.s @@ -0,0 +1,7 @@ +# REQUIRES: x86 + +## 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 +# CHECK: invalid symbol name offset diff --git a/test/ELF/invalid/symtab-sh-info.s b/test/ELF/invalid/symtab-sh-info.s new file mode 100644 index 0000000000000..3522ae550c08a --- /dev/null +++ b/test/ELF/invalid/symtab-sh-info.s @@ -0,0 +1,9 @@ +## sh_info contains zero value. First entry in a symbol table is always completely zeroed, +## so sh_info should be at least 1 in a valid ELF. +# RUN: not ld.lld %p/Inputs/symtab-sh_info2.elf -o %t2 2>&1 | FileCheck %s +# CHECK: invalid sh_info in symbol table + +## sh_info contains invalid value saying non-local symbol is local. +# RUN: not ld.lld %p/Inputs/symtab-sh_info3.elf -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=INVALID-SYMTAB-SHINFO %s +# INVALID-SYMTAB-SHINFO: broken object: getLocalSymbols returns a non-local symbol diff --git a/test/ELF/invalid/symtab-symbols.test b/test/ELF/invalid/symtab-symbols.test new file mode 100644 index 0000000000000..953b2e32a4acd --- /dev/null +++ b/test/ELF/invalid/symtab-symbols.test @@ -0,0 +1,25 @@ +# RUN: yaml2obj %s -o %t +# RUN: ld.lld -shared %t -o %tout + +# GNU assembler 2.17.50 [FreeBSD] 2007-07-03 could generate +# broken objects. +# Verify that lld can handle STT_NOTYPE symbols associated +# with SHT_SYMTAB section. + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_FREEBSD + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: "00000000" +Symbols: + Local: + - Type: STT_NOTYPE + Section: .symtab diff --git a/test/ELF/invalid/tls-symbol.s b/test/ELF/invalid/tls-symbol.s new file mode 100644 index 0000000000000..7c65c6c9f2c7c --- /dev/null +++ b/test/ELF/invalid/tls-symbol.s @@ -0,0 +1,5 @@ +# REQUIRES: x86 + +## The test file contains a STT_TLS symbol but has no TLS section. +# RUN: not ld.lld %S/Inputs/tls-symbol.elf -o %t 2>&1 | FileCheck %s +# CHECK: has a STT_TLS symbol but doesn't have a PT_TLS section diff --git a/test/ELF/invalid/too-short.s b/test/ELF/invalid/too-short.s new file mode 100644 index 0000000000000..deaf8218d6e09 --- /dev/null +++ b/test/ELF/invalid/too-short.s @@ -0,0 +1,5 @@ +# 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/invalid/verdef-no-symtab.test b/test/ELF/invalid/verdef-no-symtab.test new file mode 100644 index 0000000000000..5b5c32e4ff5c3 --- /dev/null +++ b/test/ELF/invalid/verdef-no-symtab.test @@ -0,0 +1,26 @@ +# RUN: yaml2obj %s -o %t +# RUN: not ld.lld %t -o %tout 2>&1 | FileCheck %s + +## When we have SHT_GNU_versym section, it is should be associated +## with symbol table section. +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 +Sections: + - Name: .versym + Type: SHT_GNU_versym + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x1 + Content: "00000000" + + - Name: .verdef + Type: SHT_GNU_verdef + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x1 + Content: "00000000" + + +# CHECK: SHT_GNU_versym should be associated with symbol table diff --git a/test/ELF/libsearch.s b/test/ELF/libsearch.s index 782d755f73413..20783c5b6465e 100644 --- a/test/ELF/libsearch.s +++ b/test/ELF/libsearch.s @@ -3,6 +3,8 @@ // RUN: %p/Inputs/libsearch-dyn.s -o %tdyn.o // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ // RUN: %p/Inputs/libsearch-st.s -o %tst.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ +// RUN: %p/Inputs/use-bar.s -o %tbar.o // RUN: mkdir -p %t.dir // RUN: ld.lld -shared %tdyn.o -o %t.dir/libls.so // RUN: cp -f %t.dir/libls.so %t.dir/libls2.so @@ -13,12 +15,14 @@ // Should fail if no library specified // RUN: not ld.lld -l 2>&1 \ // RUN: | FileCheck --check-prefix=NOLIBRARY %s -// NOLIBRARY: missing arg value for "-l", expected 1 argument. +// NOLIBRARY: -l: missing argument +// Should link normally, because _bar is not used +// RUN: ld.lld -o %t3 %t.o // Should not link because of undefined symbol _bar -// RUN: not ld.lld -o %t3 %t.o 2>&1 \ +// RUN: not ld.lld -o %t3 %t.o %tbar.o 2>&1 \ // RUN: | FileCheck --check-prefix=UNDEFINED %s -// UNDEFINED: undefined symbol: _bar +// UNDEFINED: error: {{.*}}:(.bar+0x0): undefined symbol '_bar' // Should fail if cannot find specified library (without -L switch) // RUN: not ld.lld -o %t3 %t.o -lls 2>&1 \ @@ -85,5 +89,12 @@ // RUN: ld.lld -o %t3 %t.o -L%t.dir -Bstatic -call_shared -lls // RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=DYNAMIC %s +// -nostdlib +// RUN: echo 'SEARCH_DIR("'%t.dir'")' > %t.script +// RUN: ld.lld -o %t3 %t.o -script %t.script -lls +// RUN: not ld.lld -o %t3 %t.o -script %t.script -lls -nostdlib \ +// RUN: 2>&1 | FileCheck --check-prefix=NOSTDLIB %s +// NOSTDLIB: unable to find library -lls + .globl _start,_bar _start: diff --git a/test/ELF/linkerscript-align.s b/test/ELF/linkerscript-align.s deleted file mode 100644 index 5f6e6f7707666..0000000000000 --- a/test/ELF/linkerscript-align.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: . = 0x10000; \ -# RUN: .aaa : \ -# RUN: { \ -# RUN: *(.aaa) \ -# RUN: } \ -# RUN: . = ALIGN(4096); \ -# RUN: .bbb : \ -# RUN: { \ -# RUN: *(.bbb) \ -# RUN: } \ -# RUN: . = ALIGN(4096 * 4); \ -# RUN: .ccc : \ -# RUN: { \ -# RUN: *(.ccc) \ -# RUN: } \ -# 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 - -.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-diagnostic.s b/test/ELF/linkerscript-diagnostic.s deleted file mode 100644 index f42cbe82cf38f..0000000000000 --- a/test/ELF/linkerscript-diagnostic.s +++ /dev/null @@ -1,66 +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: line 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: line 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: line 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 > %t.log 2>&1 -# RUN: FileCheck -check-prefix=ERR6 %s < %t.log -# ERR6: line 1: -# ERR6-NEXT: UNKNOWN_TAG { -# RUN: grep '^^' %t.log - -## 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 > %t.log 2>&1 -# RUN: FileCheck -check-prefix=ERR7 %s < %t.log -# ERR7: line 4: : expected, but got .temp -# ERR7-NEXT: boom .temp : { *(.temp) } } -# RUN: grep '^ ^' %t.log diff --git a/test/ELF/linkerscript-locationcounter.s b/test/ELF/linkerscript-locationcounter.s deleted file mode 100644 index c6e8e7ef8ea86..0000000000000 --- a/test/ELF/linkerscript-locationcounter.s +++ /dev/null @@ -1,340 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "SECTIONS { \ -# RUN: . = 0xFFF0; \ -# RUN: . = . + 0x10; \ -# RUN: .plus : { *(.plus) } \ -# RUN: . = 0x11010 - 0x10; \ -# RUN: .minus : { *(.minus) } \ -# RUN: . = 0x24000 / 0x2; \ -# RUN: .div : { *(.div) } \ -# RUN: . = 0x11000 + 0x1000 * 0x2; \ -# RUN: .mul : { *(.mul) } \ -# RUN: . = 0x10000 + (0x1000 + 0x1000) * 0x2; \ -# RUN: .bracket : { *(.bracket) } \ -# RUN: . = 0x17000 & 0x15000; \ -# RUN: .and : { *(.and) } \ -# RUN: . = 0x1 ? 0x16000 : 0x999999; \ -# RUN: .ternary1 : { *(.ternary1) } \ -# RUN: . = 0x0 ? 0x999999 : 0x17000; \ -# RUN: .ternary2 : { *(.ternary2) } \ -# RUN: . = 0x0 < 0x1 ? 0x18000 : 0x999999; \ -# RUN: .less : { *(.less) } \ -# RUN: . = 0x1 <= 0x1 ? 0x19000 : 0x999999; \ -# RUN: .lesseq : { *(.lesseq) } \ -# RUN: . = 0x1 > 0x0 ? 0x20000 : 0x999999; \ -# RUN: .great : { *(.great) } \ -# RUN: . = 0x1 >= 0x1 ? 0x21000 : 0x999999; \ -# RUN: .greateq : { *(.greateq) } \ -# RUN: . = 0x1 == 0x1 ? 0x22000 : 0x999999; \ -# RUN: .eq : { *(.eq) } \ -# RUN: . = 0x2 != 0x1 ? 0x23000 : 0x999999; \ -# RUN: .neq : { *(.neq) } \ -# RUN: }" > %t.script -# RUN: ld.lld %t --script %t.script -o %t2 -# RUN: llvm-readobj -s %t2 | FileCheck %s - -# CHECK: Section { -# CHECK: Index: 1 -# CHECK: Name: .plus -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x10000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: 2 -# CHECK-NEXT: Name: .minus -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x11000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: 3 -# CHECK-NEXT: Name: .div -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x12000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: 4 -# CHECK-NEXT: Name: .mul -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x13000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: 5 -# CHECK-NEXT: Name: .bracket -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x14000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: -# CHECK-NEXT: Name: .and -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x15000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: -# CHECK-NEXT: Name: .ternary1 -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x16000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: -# CHECK-NEXT: Name: .ternary2 -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x17000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: -# CHECK-NEXT: Name: .less -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x18000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: -# CHECK-NEXT: Name: .lesseq -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x19000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: -# CHECK-NEXT: Name: .great -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x20000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: -# CHECK-NEXT: Name: .greateq -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x21000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: -# CHECK-NEXT: Name: .eq -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x22000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } -# CHECK-NEXT: Section { -# CHECK-NEXT: Index: -# CHECK-NEXT: Name: .neq -# CHECK-NEXT: Type: SHT_PROGBITS -# CHECK-NEXT: Flags [ -# CHECK-NEXT: SHF_ALLOC -# CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x23000 -# CHECK-NEXT: Offset: -# CHECK-NEXT: Size: -# CHECK-NEXT: Link: -# CHECK-NEXT: Info: -# CHECK-NEXT: AddressAlignment: -# CHECK-NEXT: EntrySize: -# CHECK-NEXT: } - -## Mailformed number error. -# RUN: echo "SECTIONS { \ -# RUN: . = 0x12Q41; \ -# RUN: }" > %t.script -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=NUMERR %s -# NUMERR: malformed number: 0x12Q41 - -## Missing closing bracket. -# RUN: echo "SECTIONS { \ -# RUN: . = 0x10000 + (0x1000 + 0x1000 * 0x2; \ -# RUN: }" > %t.script -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=BRACKETERR %s -# BRACKETERR: unexpected EOF - -## Missing opening bracket. -# RUN: echo "SECTIONS { \ -# RUN: . = 0x10000 + 0x1000 + 0x1000) * 0x2; \ -# RUN: }" > %t.script -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=BRACKETERR2 %s -# BRACKETERR2: stray token: ) - -## Empty expression. -# RUN: echo "SECTIONS { \ -# RUN: . = ; \ -# RUN: }" > %t.script -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=ERREXPR %s -# ERREXPR: error in location counter expression - -## Div by zero error. -# RUN: echo "SECTIONS { \ -# RUN: . = 0x10000 / 0x0; \ -# RUN: }" > %t.script -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=DIVZERO %s -# DIVZERO: division by zero - -## Broken ternary operator expression. -# RUN: echo "SECTIONS { \ -# RUN: . = 0x1 ? 0x2; \ -# RUN: }" > %t.script -# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=TERNERR %s -# TERNERR: unexpected EOF - -.globl _start -_start: -nop - -.section .plus, "a" -.quad 0 - -.section .minus, "a" -.quad 0 - -.section .div, "a" -.quad 0 - -.section .mul, "a" -.quad 0 - -.section .bracket, "a" -.quad 0 - -.section .and, "a" -.quad 0 - -.section .ternary1, "a" -.quad 0 - -.section .ternary2, "a" -.quad 0 - -.section .less, "a" -.quad 0 - -.section .lesseq, "a" -.quad 0 - -.section .great, "a" -.quad 0 - -.section .greateq, "a" -.quad 0 - -.section .eq, "a" -.quad 0 - -.section .neq, "a" -.quad 0 diff --git a/test/ELF/linkerscript-sections-padding.s b/test/ELF/linkerscript-sections-padding.s deleted file mode 100644 index 545739efe5a8d..0000000000000 --- a/test/ELF/linkerscript-sections-padding.s +++ /dev/null @@ -1,44 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -## Check that padding value works: -# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x112233445566778899 }" > %t.script -# RUN: ld.lld -o %t.out --script %t.script %t -# RUN: hexdump -C %t.out | FileCheck -check-prefix=YES %s -# YES: 00000120 66 22 33 44 55 66 77 88 99 11 22 33 44 55 66 77 - -## Confirming that address was correct: -# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x998877665544332211 }" > %t.script -# RUN: ld.lld -o %t.out --script %t.script %t -# RUN: hexdump -C %t.out | FileCheck -check-prefix=YES2 %s -# YES2: 00000120 66 88 77 66 55 44 33 22 11 99 88 77 66 55 44 - -## Default padding value is 0x00: -# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } }" > %t.script -# RUN: ld.lld -o %t.out --script %t.script %t -# RUN: hexdump -C %t.out | FileCheck -check-prefix=NO %s -# NO: 00000120 66 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 - -## Filler should be a hex value (1): -# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =99 }" > %t.script -# RUN: not ld.lld -o %t.out --script %t.script %t 2>&1 \ -# RUN: | FileCheck --check-prefix=ERR %s -# ERR: filler should be a hexadecimal value - -## Filler should be a hex value (2): -# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x99XX }" > %t.script -# RUN: not ld.lld -o %t.out --script %t.script %t 2>&1 \ -# RUN: | FileCheck --check-prefix=ERR2 %s -# ERR2: not a hexadecimal value: XX - -.section .mysec.1,"a" -.align 16 -.byte 0x66 - -.section .mysec.2,"a" -.align 16 -.byte 0x66 - -.globl _start -_start: - nop diff --git a/test/ELF/linkerscript.s b/test/ELF/linkerscript.s deleted file mode 100644 index 4ee7416a4b846..0000000000000 --- a/test/ELF/linkerscript.s +++ /dev/null @@ -1,120 +0,0 @@ -# There is some bad quoting interaction between lit's internal shell, which is -# implemented in Python, and the Cygwin implementations of the Unix utilities. -# Avoid running these tests on Windows for now by requiring a real shell. - -# REQUIRES: shell - -# REQUIRES: x86 -# RUN: mkdir -p %t.dir -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ -# RUN: %p/Inputs/libsearch-st.s -o %t2.o -# RUN: rm -f %t.dir/libxyz.a -# RUN: llvm-ar rcs %t.dir/libxyz.a %t2.o - -# RUN: echo "EXTERN( undef undef2 )" > %t.script -# RUN: ld.lld %t -o %t2 %t.script -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "GROUP(\"%t\")" > %t.script -# RUN: ld.lld -o %t2 %t.script -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "INPUT(\"%t\")" > %t.script -# RUN: ld.lld -o %t2 %t.script -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "GROUP(\"%t\" libxyz.a )" > %t.script -# RUN: not ld.lld -o %t2 %t.script -# RUN: ld.lld -o %t2 %t.script -L%t.dir -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "GROUP(\"%t\" =libxyz.a )" > %t.script -# RUN: not ld.lld -o %t2 %t.script -# RUN: ld.lld -o %t2 %t.script --sysroot=%t.dir -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "GROUP(\"%t\" -lxyz )" > %t.script -# RUN: not ld.lld -o %t2 %t.script -# RUN: ld.lld -o %t2 %t.script -L%t.dir -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "GROUP(\"%t\" libxyz.a )" > %t.script -# RUN: not ld.lld -o %t2 %t.script -# RUN: ld.lld -o %t2 %t.script -L%t.dir -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "GROUP(\"%t\" /libxyz.a )" > %t.script -# RUN: echo "GROUP(\"%t\" /libxyz.a )" > %t.dir/xyz.script -# RUN: not ld.lld -o %t2 %t.script -# RUN: not ld.lld -o %t2 %t.script --sysroot=%t.dir -# RUN: ld.lld -o %t2 %t.dir/xyz.script --sysroot=%t.dir -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "GROUP(\"%t.script2\")" > %t.script1 -# RUN: echo "GROUP(\"%t\")" > %t.script2 -# RUN: ld.lld -o %t2 %t.script1 -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "ENTRY(_label)" > %t.script -# RUN: ld.lld -o %t2 %t.script %t -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "ENTRY(_wrong_label)" > %t.script -# RUN: not ld.lld -o %t2 %t.script %t > %t.log 2>&1 -# RUN: FileCheck -check-prefix=ERR-ENTRY %s < %t.log - -# ERR-ENTRY: undefined symbol: _wrong_label - -# -e has precedence over linker script's ENTRY. -# RUN: echo "ENTRY(_label)" > %t.script -# RUN: ld.lld -e _start -o %t2 %t.script %t -# RUN: llvm-readobj -file-headers -symbols %t2 | \ -# RUN: FileCheck -check-prefix=ENTRY-OVERLOAD %s - -# ENTRY-OVERLOAD: Entry: [[ENTRY:0x[0-9A-F]+]] -# ENTRY-OVERLOAD: Name: _start -# ENTRY-OVERLOAD-NEXT: Value: [[ENTRY]] - -# RUN: echo "OUTPUT_FORMAT(elf64-x86-64) /*/*/ GROUP(\"%t\" )" > %t.script -# RUN: ld.lld -o %t2 %t.script -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: echo "GROUP(AS_NEEDED(\"%t\"))" > %t.script -# RUN: ld.lld -o %t2 %t.script -# RUN: llvm-readobj %t2 > /dev/null - -# RUN: rm -f %t.out -# RUN: echo "OUTPUT(\"%t.out\")" > %t.script -# RUN: ld.lld %t.script %t -# RUN: llvm-readobj %t.out > /dev/null - -# RUN: echo "SEARCH_DIR(/lib/foo/blah)" > %t.script -# RUN: ld.lld %t.script %t -# RUN: llvm-readobj %t.out > /dev/null - -# RUN: echo ";SEARCH_DIR(x);SEARCH_DIR(y);" > %t.script -# RUN: ld.lld %t.script %t -# RUN: llvm-readobj %t.out > /dev/null - -# RUN: echo ";" > %t.script -# RUN: ld.lld %t.script %t -# 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: llvm-readobj %t2 > /dev/null - -# RUN: echo "FOO(BAR)" > %t.script -# RUN: not ld.lld -o foo %t.script > %t.log 2>&1 -# RUN: FileCheck -check-prefix=ERR1 %s < %t.log - -# ERR1: unknown directive: FOO - -.globl _start, _label -_start: - mov $60, %rax - mov $42, %rdi -_label: - syscall diff --git a/test/ELF/linkerscript/Inputs/comdat-gc.s b/test/ELF/linkerscript/Inputs/comdat-gc.s new file mode 100644 index 0000000000000..da29d5b3830bf --- /dev/null +++ b/test/ELF/linkerscript/Inputs/comdat-gc.s @@ -0,0 +1,5 @@ +.file 1 "test/ELF/linkerscript/Inputs/comdat_gc.s" + +.section .text._Z3fooIiEvv,"axG",@progbits,_Z3fooIiEvv,comdat +.loc 1 5 + ret diff --git a/test/ELF/linkerscript/Inputs/exclude-multiple1.s b/test/ELF/linkerscript/Inputs/exclude-multiple1.s new file mode 100644 index 0000000000000..1e0f741df40f2 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/exclude-multiple1.s @@ -0,0 +1,8 @@ +.section .foo.1,"a" + .quad 4 + +.section .foo.2,"a" + .quad 5 + +.section .foo.3,"a" + .quad 6 diff --git a/test/ELF/linkerscript/Inputs/exclude-multiple2.s b/test/ELF/linkerscript/Inputs/exclude-multiple2.s new file mode 100644 index 0000000000000..60f790fa23560 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/exclude-multiple2.s @@ -0,0 +1,8 @@ +.section .foo.1,"a" + .quad 7 + +.section .foo.2,"a" + .quad 8 + +.section .foo.3,"a" + .quad 9 diff --git a/test/ELF/linkerscript/Inputs/filename-spec.s b/test/ELF/linkerscript/Inputs/filename-spec.s new file mode 100644 index 0000000000000..a688b4db4b606 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/filename-spec.s @@ -0,0 +1,2 @@ +.section .foo,"a" + .quad 0x11 diff --git a/test/ELF/linkerscript/Inputs/implicit-program-header.script b/test/ELF/linkerscript/Inputs/implicit-program-header.script new file mode 100644 index 0000000000000..27dbea84c4e4d --- /dev/null +++ b/test/ELF/linkerscript/Inputs/implicit-program-header.script @@ -0,0 +1,12 @@ +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/include.s b/test/ELF/linkerscript/Inputs/include.s new file mode 100644 index 0000000000000..a2f809b522f33 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/include.s @@ -0,0 +1,5 @@ +.section .text +.globl _potato +_potato: + nop + nop diff --git a/test/ELF/linkerscript/Inputs/keep.s b/test/ELF/linkerscript/Inputs/keep.s new file mode 100644 index 0000000000000..20fa41c1adff0 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/keep.s @@ -0,0 +1,2 @@ +.section .keep, "a" + .long 0x41414141 diff --git a/test/ELF/linkerscript/Inputs/libsearch-dyn.s b/test/ELF/linkerscript/Inputs/libsearch-dyn.s new file mode 100644 index 0000000000000..091b3b9b6eced --- /dev/null +++ b/test/ELF/linkerscript/Inputs/libsearch-dyn.s @@ -0,0 +1,3 @@ +.globl _bar,_dynamic +_bar: +_dynamic: diff --git a/test/ELF/linkerscript/Inputs/libsearch-st.s b/test/ELF/linkerscript/Inputs/libsearch-st.s new file mode 100644 index 0000000000000..6da62f79d52f2 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/libsearch-st.s @@ -0,0 +1,3 @@ +.globl _bar,_static +_bar: +_static: diff --git a/test/ELF/linkerscript/Inputs/merge-sections-reloc.s b/test/ELF/linkerscript/Inputs/merge-sections-reloc.s new file mode 100644 index 0000000000000..07e599b2820f2 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/merge-sections-reloc.s @@ -0,0 +1,3 @@ +.globl _start +_start: + .quad 0x11223344 diff --git a/test/ELF/linkerscript/Inputs/notinclude.s b/test/ELF/linkerscript/Inputs/notinclude.s new file mode 100644 index 0000000000000..46c0509b56cc0 --- /dev/null +++ b/test/ELF/linkerscript/Inputs/notinclude.s @@ -0,0 +1,4 @@ +.section .text +.globl tomato +tomato: + movl $1, %eax diff --git a/test/ELF/linkerscript/Inputs/segment-start.script b/test/ELF/linkerscript/Inputs/segment-start.script new file mode 100644 index 0000000000000..9f1a59360105d --- /dev/null +++ b/test/ELF/linkerscript/Inputs/segment-start.script @@ -0,0 +1,7 @@ +SECTIONS +{ + PROVIDE (foobar1 = SEGMENT_START("text-segment", 0x8001)); + PROVIDE (foobar2 = SEGMENT_START("data-segment", 0x8002)); + PROVIDE (foobar3 = SEGMENT_START("bss-segment", 0x8000 + (4 - 1))); + PROVIDE (foobar4 = SEGMENT_START("abc-segment", 0x8004)); +} diff --git a/test/ELF/linkerscript/Inputs/shared.s b/test/ELF/linkerscript/Inputs/shared.s new file mode 100644 index 0000000000000..c3c22fe4b4fbc --- /dev/null +++ b/test/ELF/linkerscript/Inputs/shared.s @@ -0,0 +1,10 @@ +.global bar +.type bar, @function +bar: + +.global bar2 +.type bar2, @function +bar2: + +.global zed +zed: diff --git a/test/ELF/linkerscript/Inputs/sort-nested.s b/test/ELF/linkerscript/Inputs/sort-nested.s new file mode 100644 index 0000000000000..c42fa9cd7ed8c --- /dev/null +++ b/test/ELF/linkerscript/Inputs/sort-nested.s @@ -0,0 +1,7 @@ +.section .aaa.1, "a" +.align 16 +.quad 0x11 + +.section .aaa.2, "a" +.align 4 +.quad 0x22 diff --git a/test/ELF/linkerscript/Inputs/sort.s b/test/ELF/linkerscript/Inputs/sort.s new file mode 100644 index 0000000000000..22e65ad19e1ec --- /dev/null +++ b/test/ELF/linkerscript/Inputs/sort.s @@ -0,0 +1,19 @@ +.section .aaa.5, "a" +.align 2 +.quad 0x55 + +.section .aaa.1, "a" +.align 32 +.quad 0x11 + +.section .aaa.3, "a" +.align 8 +.quad 0x33 + +.section .aaa.2, "a" +.align 16 +.quad 0x22 + +.section .aaa.4, "a" +.align 4 +.quad 0x44 diff --git a/test/ELF/linkerscript/absolute-expr.s b/test/ELF/linkerscript/absolute-expr.s new file mode 100644 index 0000000000000..a9a674b859f4b --- /dev/null +++ b/test/ELF/linkerscript/absolute-expr.s @@ -0,0 +1,82 @@ +# 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: llvm-readobj -t %t.so | FileCheck %s + +.global foo +foo = 0x123 + +# CHECK: Symbol { +# CHECK: Name: foo +# CHECK-NEXT: Value: 0x123 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute (0xFFF1) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar1 +# CHECK-NEXT: Value: 0x4 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar2 +# CHECK-NEXT: Value: 0x1000 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar3 +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar4 +# CHECK-NEXT: Value: 0x190 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar5 +# CHECK-NEXT: Value: 0x42 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar6 +# CHECK-NEXT: Value: 0x124 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute (0xFFF1) +# CHECK-NEXT: } diff --git a/test/ELF/linkerscript/absolute.s b/test/ELF/linkerscript/absolute.s new file mode 100644 index 0000000000000..e4b156e2f012e --- /dev/null +++ b/test/ELF/linkerscript/absolute.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { foo = ABSOLUTE(.) + 1; };" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: llvm-readobj --symbols %t | FileCheck %s + +# CHECK: Name: foo +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: +# CHECK-NEXT: Type: +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } + +.text +.globl _start +_start: diff --git a/test/ELF/linkerscript/addr.s b/test/ELF/linkerscript/addr.s new file mode 100644 index 0000000000000..2d3a7ab35767d --- /dev/null +++ b/test/ELF/linkerscript/addr.s @@ -0,0 +1,32 @@ +# 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/align-empty.s b/test/ELF/linkerscript/align-empty.s new file mode 100644 index 0000000000000..3ff71578410a0 --- /dev/null +++ b/test/ELF/linkerscript/align-empty.s @@ -0,0 +1,18 @@ +# 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.s b/test/ELF/linkerscript/align.s new file mode 100644 index 0000000000000..1e50fed3fa833 --- /dev/null +++ b/test/ELF/linkerscript/align.s @@ -0,0 +1,83 @@ +# 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 : \ +# RUN: { \ +# RUN: *(.aaa) \ +# RUN: } \ +# RUN: . = ALIGN(4096); \ +# RUN: .bbb : \ +# RUN: { \ +# RUN: *(.bbb) \ +# RUN: } \ +# RUN: . = ALIGN(4096 * 4); \ +# RUN: .ccc : \ +# RUN: { \ +# RUN: *(.ccc) \ +# RUN: } \ +# 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 : \ +# RUN: { \ +# RUN: *(.aaa) \ +# RUN: } \ +# RUN: . = ALIGN(., 4096); \ +# RUN: .bbb : \ +# RUN: { \ +# RUN: *(.bbb) \ +# RUN: } \ +# RUN: . = ALIGN(., 4096 * 4); \ +# RUN: .ccc : \ +# RUN: { \ +# RUN: *(.ccc) \ +# RUN: } \ +# 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 : \ +# RUN: { \ +# RUN: *(.aaa) \ +# RUN: } \ +# RUN: .bbb : ALIGN(4096) \ +# RUN: { \ +# RUN: *(.bbb) \ +# RUN: } \ +# RUN: .ccc : ALIGN(4096 * 4) \ +# RUN: { \ +# RUN: *(.ccc) \ +# RUN: } \ +# RUN: }" > %t2.script +# RUN: ld.lld -o %t2 --script %t2.script %t +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s + +.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/alignof.s b/test/ELF/linkerscript/alignof.s new file mode 100644 index 0000000000000..8880634df2430 --- /dev/null +++ b/test/ELF/linkerscript/alignof.s @@ -0,0 +1,41 @@ +# 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/alternate-sections.s b/test/ELF/linkerscript/alternate-sections.s new file mode 100644 index 0000000000000..6d3004af9a80c --- /dev/null +++ b/test/ELF/linkerscript/alternate-sections.s @@ -0,0 +1,34 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { abc : { *(foo) *(bar) *(zed) } }" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o -shared +# RUN: llvm-readobj -s -section-data %t | FileCheck %s + +# This test shows an oddity in lld. When a linker script alternates among +# different types of output section in the same command, the sections are +# reordered. +# In this test we go from regular, to merge and back to regular. The reason +# for the reordering is that we need two create two output sections and +# one cannot be in the middle of another. +# If this ever becomes a problem, some options would be: +# * Adding an extra layer in between input section and output sections (Chunk). +# With that this example would have 3 chunks, but only one output section. +# This would unfortunately complicate the non-script case too. +# * Just create three output sections. +# * If having three output sections causes problem, have linkerscript specific +# code to write the section table and section indexes. That way we could +# keep 3 sections internally but not expose that. + +# CHECK: Name: abc +# CHECK: 0000: 01000000 00000000 02000000 00000000 | +# CHECK: Name: abc +# CHECK: 0000: 61626331 323300 |abc123.| + + .section foo, "a" + .quad 1 + + .section bar,"aMS",@progbits,1 + .asciz "abc123" + + .section zed, "a" + .quad 2 diff --git a/test/ELF/linkerscript/arm-exidx-phdrs.s b/test/ELF/linkerscript/arm-exidx-phdrs.s new file mode 100644 index 0000000000000..971702f55d7b5 --- /dev/null +++ b/test/ELF/linkerscript/arm-exidx-phdrs.s @@ -0,0 +1,16 @@ +// 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/assert.s b/test/ELF/linkerscript/assert.s new file mode 100644 index 0000000000000..06eeaeec3b993 --- /dev/null +++ b/test/ELF/linkerscript/assert.s @@ -0,0 +1,43 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o + +# RUN: echo "SECTIONS { ASSERT(1, fail) }" > %t1.script +# RUN: ld.lld -shared -o %t1 --script %t1.script %t1.o +# RUN: llvm-readobj %t1 > /dev/null + +# RUN: echo "SECTIONS { ASSERT(ASSERT(42, fail) == 42, fail) }" > %t2.script +# RUN: ld.lld -shared -o %t2 --script %t2.script %t1.o +# RUN: llvm-readobj %t2 > /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: FileCheck %s -check-prefix=FAIL < %t.log +# FAIL: fail + +# RUN: echo "SECTIONS { . = ASSERT(0x1000, fail); }" > %t4.script +# RUN: ld.lld -shared -o %t4 --script %t4.script %t1.o +# RUN: llvm-readobj %t4 > /dev/null + +# RUN: echo "SECTIONS { .foo : { *(.foo) } }" > %t5.script +# RUN: echo "ASSERT(SIZEOF(.foo) == 8, fail);" >> %t5.script +# RUN: ld.lld -shared -o %t5 --script %t5.script %t1.o +# RUN: llvm-readobj %t5 > /dev/null + +## Even without SECTIONS block we still use section names +## in expressions +# RUN: echo "ASSERT(SIZEOF(.foo) == 8, fail);" > %t5.script +# RUN: ld.lld -shared -o %t5 --script %t5.script %t1.o +# RUN: llvm-readobj %t5 > /dev/null + +## Test assertions inside of output section decriptions. +# RUN: echo "SECTIONS { .foo : { *(.foo) ASSERT(SIZEOF(.foo) == 8, \"true\"); } }" > %t6.script +# RUN: ld.lld -shared -o %t6 --script %t6.script %t1.o +# RUN: llvm-readobj %t6 > /dev/null + +# 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 } + +.section .foo, "a" + .quad 0 diff --git a/test/ELF/linkerscript/at.s b/test/ELF/linkerscript/at.s new file mode 100644 index 0000000000000..a6b6198710ea2 --- /dev/null +++ b/test/ELF/linkerscript/at.s @@ -0,0 +1,119 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: . = 0x1000; \ +# RUN: .aaa : AT(0x2000) \ +# RUN: { \ +# RUN: *(.aaa) \ +# RUN: } \ +# RUN: .bbb : \ +# RUN: { \ +# RUN: *(.bbb) \ +# RUN: } \ +# RUN: .ccc : AT(0x3000) \ +# RUN: { \ +# RUN: *(.ccc) \ +# RUN: } \ +# RUN: .ddd : AT(0x4000) \ +# RUN: { \ +# RUN: *(.ddd) \ +# RUN: } \ +# 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_PHDR +# CHECK-NEXT: Offset: 0x40 +# CHECK-NEXT: VirtualAddress: 0x40 +# CHECK-NEXT: PhysicalAddress: 0x40 +# CHECK-NEXT: FileSize: +# CHECK-NEXT: MemSize: +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 8 +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x0 +# CHECK-NEXT: PhysicalAddress: 0x0 +# CHECK-NEXT: FileSize: +# CHECK-NEXT: MemSize: +# 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: 0x1000 +# CHECK-NEXT: VirtualAddress: 0x1000 +# CHECK-NEXT: PhysicalAddress: 0x2000 +# 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: 0x1010 +# CHECK-NEXT: VirtualAddress: 0x1010 +# CHECK-NEXT: PhysicalAddress: 0x3000 +# CHECK-NEXT: FileSize: 8 +# CHECK-NEXT: MemSize: 8 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_X +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 4096 +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x1018 +# CHECK-NEXT: VirtualAddress: 0x1018 +# CHECK-NEXT: PhysicalAddress: 0x4000 +# CHECK-NEXT: FileSize: 9 +# CHECK-NEXT: MemSize: 9 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_X +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 4096 +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_GNU_STACK +# CHECK-NEXT: Offset: +# CHECK-NEXT: VirtualAddress: 0x0 +# CHECK-NEXT: PhysicalAddress: 0x0 +# CHECK-NEXT: FileSize: +# CHECK-NEXT: MemSize: +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_W +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +.global _start +_start: + nop + +.section .aaa, "a" +.quad 0 + +.section .bbb, "a" +.quad 0 + +.section .ccc, "a" +.quad 0 + +.section .ddd, "a" +.quad 0 diff --git a/test/ELF/linkerscript/comdat-gc.s b/test/ELF/linkerscript/comdat-gc.s new file mode 100644 index 0000000000000..63dcf85c5a67f --- /dev/null +++ b/test/ELF/linkerscript/comdat-gc.s @@ -0,0 +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/comdat-gc.s -o %t1 +# RUN: echo "SECTIONS { .text : { *(.text*) } }" > %t.script +# RUN: ld.lld --gc-sections --script %t.script %t %t1 -o %t2 +# RUN: llvm-readobj -sections -symbols %t2 | FileCheck -check-prefix=GC1 %s + +# GC1: Name: .debug_line + +.file 1 "test/ELF/linkerscript/comdat_gc.s" +.section .text._Z3fooIiEvv,"axG",@progbits,_Z3fooIiEvv,comdat +.loc 1 14 + ret diff --git a/test/ELF/linkerscript/common.s b/test/ELF/linkerscript/common.s new file mode 100644 index 0000000000000..2e5972d523794 --- /dev/null +++ b/test/ELF/linkerscript/common.s @@ -0,0 +1,49 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { . = SIZEOF_HEADERS; .common : { *(COMMON) } }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-readobj -s -t %t1 | FileCheck %s + +# q2 alignment is greater than q1, so it should have smaller offset +# because of sorting +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .common +# CHECK-NEXT: Type: SHT_NOBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x200 +# CHECK-NEXT: Offset: 0x +# CHECK-NEXT: Size: 256 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 256 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: } +# CHECK: Symbol { +# CHECK: Name: q1 +# CHECK-NEXT: Value: 0x280 +# CHECK-NEXT: Size: 128 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Object +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .common +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: q2 +# CHECK-NEXT: Value: 0x200 +# CHECK-NEXT: Size: 128 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Object +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .common +# CHECK-NEXT: } + +.globl _start +_start: + jmp _start + +.comm q1,128,8 +.comm q2,128,256 diff --git a/test/ELF/linkerscript/data-commands.s b/test/ELF/linkerscript/data-commands.s new file mode 100644 index 0000000000000..ef154eda9f835 --- /dev/null +++ b/test/ELF/linkerscript/data-commands.s @@ -0,0 +1,81 @@ +# 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 + +.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-segment-relro.s b/test/ELF/linkerscript/data-segment-relro.s new file mode 100644 index 0000000000000..7f69319dde7ab --- /dev/null +++ b/test/ELF/linkerscript/data-segment-relro.s @@ -0,0 +1,70 @@ +# 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: . = 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 -z norelro %t1.o %t2.so --script %t.script -o %t +# RUN: llvm-readobj -s %t | FileCheck %s +# RUN: ld.lld -z relro %t1.o %t2.so --script %t.script -o %t2 +# RUN: llvm-readobj -s %t2 | FileCheck %s + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .got +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x10F0 +# CHECK-NEXT: Offset: 0x10F0 +# CHECK-NEXT: Size: +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: +# CHECK-NEXT: 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-NEXT: Offset: 0x2000 +# CHECK-NEXT: Size: +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# 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 new file mode 100644 index 0000000000000..b5f0b76e9e6bf --- /dev/null +++ b/test/ELF/linkerscript/define.s @@ -0,0 +1,25 @@ +# 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/diagnostic.s b/test/ELF/linkerscript/diagnostic.s new file mode 100644 index 0000000000000..bd1ebd01b5d28 --- /dev/null +++ b/test/ELF/linkerscript/diagnostic.s @@ -0,0 +1,106 @@ +# 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: +# ERR6-NEXT: error: {{.*}}.script:1: UNKNOWN_TAG { +# ERR6-NEXT: error: {{.*}}.script:1: ^ + +## 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: error: {{.*}}.script:4: boom .temp : { *(.temp) } } +# ERR7-NEXT: error: {{.*}}.script:4: ^ + +## 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: error: {{.*}}.script.inc:4: boom .temp : { *(.temp) } } +# ERR10-NEXT: error: {{.*}}.script.inc:4: ^ + +## 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-interp.s b/test/ELF/linkerscript/discard-interp.s new file mode 100644 index 0000000000000..261509e2e76b0 --- /dev/null +++ b/test/ELF/linkerscript/discard-interp.s @@ -0,0 +1,12 @@ +// 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-section.s b/test/ELF/linkerscript/discard-section.s new file mode 100644 index 0000000000000..a5af908068297 --- /dev/null +++ b/test/ELF/linkerscript/discard-section.s @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { /DISCARD/ : { *(.aaa*) } }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s + +# CHECK-NOT: .aaa + +.section .aaa,"a" +aab: + .quad 0 + +.section .zzz,"a" + .quad aab diff --git a/test/ELF/linkerscript/dot-is-not-abs.s b/test/ELF/linkerscript/dot-is-not-abs.s new file mode 100644 index 0000000000000..4532cd59f2a14 --- /dev/null +++ b/test/ELF/linkerscript/dot-is-not-abs.s @@ -0,0 +1,53 @@ +# 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: ld.lld -o %t1 --script %t1.script %t.o -shared +# RUN: llvm-readobj -t -s -section-data %t1 | FileCheck %s + +.hidden foo +.long foo - . + +.section .bar, "a" +.long 0 + +# The symbol foo is defined as a position in the file. This means that it is +# not absolute and it is possible to compute the distance from foo to some other +# position in the file. The symbol is not really in any output section, but +# ELF has no magic constant for not absolute, but not in any section. +# Fortunately the value of a symbol in a non relocatable file is a virtual +# address, so the section can be arbitrary. + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .text +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_EXECINSTR +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x0 +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 04000000 | +# CHECK-NEXT: ) +# CHECK-NEXT: } + +# CHECK: Symbol { +# CHECK: Name: foo +# CHECK-NEXT: Value: 0x4 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other [ +# CHECK-NEXT: STV_HIDDEN +# CHECK-NEXT: ] +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } diff --git a/test/ELF/linkerscript/double-bss.s b/test/ELF/linkerscript/double-bss.s new file mode 100644 index 0000000000000..c24332f5e5a6d --- /dev/null +++ b/test/ELF/linkerscript/double-bss.s @@ -0,0 +1,21 @@ +# 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/dynamic-sym.s b/test/ELF/linkerscript/dynamic-sym.s new file mode 100644 index 0000000000000..e3193b1a765d2 --- /dev/null +++ b/test/ELF/linkerscript/dynamic-sym.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "_DYNAMIC = 0x123;" > %t.script +# RUN: ld.lld -T %t.script %t.o -shared -o %t.so +# RUN: llvm-readobj -t %t.so | FileCheck %s + +# CHECK: Symbol { +# CHECK: Name: _DYNAMIC +# CHECK-NEXT: Value: 0x123 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other [ +# CHECK-NEXT: STV_HIDDEN +# CHECK-NEXT: ] +# CHECK-NEXT: Section: Absolute +# CHECK-NEXT: } diff --git a/test/ELF/linkerscript/dynamic.s b/test/ELF/linkerscript/dynamic.s new file mode 100644 index 0000000000000..ab65ab831f8f5 --- /dev/null +++ b/test/ELF/linkerscript/dynamic.s @@ -0,0 +1,28 @@ +# 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 { }" > %t.script +# RUN: ld.lld %t1.o %t2.so -o %t +# RUN: llvm-readobj -dynamic-table %t | FileCheck %s + +# CHECK: DynamicSection [ +# CHECK-NEXT: Tag Type Name/Value +# CHECK: 0x0000000000000021 PREINIT_ARRAYSZ 9 (bytes) +# CHECK: 0x000000000000001B INIT_ARRAYSZ 8 (bytes) +# CHECK: 0x000000000000001C FINI_ARRAYSZ 10 (bytes) + +.globl _start +_start: + +.section .init_array,"aw",@init_array + .quad 0 + +.section .preinit_array,"aw",@preinit_array + .quad 0 + .byte 0 + +.section .fini_array,"aw",@fini_array + .quad 0 + .short 0 diff --git a/test/ELF/linkerscript/edata-etext.s b/test/ELF/linkerscript/edata-etext.s new file mode 100644 index 0000000000000..fdf5ec1f5671b --- /dev/null +++ b/test/ELF/linkerscript/edata-etext.s @@ -0,0 +1,20 @@ +# 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 +# CHECK: error: {{.*}}:(.text+0x0): undefined symbol '_edata' +# CHECK: error: {{.*}}:(.text+0x8): undefined symbol '_etext' +# CHECK: error: {{.*}}:(.text+0x10): undefined symbol '_end' + +.global _start,_end,_etext,_edata +.text +_start: + .quad _edata + 0x1 + .quad _etext + 0x1 + .quad _end + 0x1 + +.data + .word 1 +.bss + .align 4 + .space 6 diff --git a/test/ELF/linkerscript/eh-frame-hdr.s b/test/ELF/linkerscript/eh-frame-hdr.s new file mode 100644 index 0000000000000..d1545be632a3a --- /dev/null +++ b/test/ELF/linkerscript/eh-frame-hdr.s @@ -0,0 +1,20 @@ +# 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: 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-NEXT: 30000000 + +.global _start +_start: + nop + +.section .dah,"ax",@progbits +.cfi_startproc + nop +.cfi_endproc diff --git a/test/ELF/linkerscript/ehdr_start.s b/test/ELF/linkerscript/ehdr_start.s new file mode 100644 index 0000000000000..0ae4a4dcfbc9e --- /dev/null +++ b/test/ELF/linkerscript/ehdr_start.s @@ -0,0 +1,11 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-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 +# CHECK: error: {{.*}}:(.text+0x0): undefined symbol '__ehdr_start' + +.text +.global _start, __ehdr_start +_start: + .quad __ehdr_start diff --git a/test/ELF/linkerscript/empty-load.s b/test/ELF/linkerscript/empty-load.s new file mode 100644 index 0000000000000..0a87d57274748 --- /dev/null +++ b/test/ELF/linkerscript/empty-load.s @@ -0,0 +1,22 @@ +# 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: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -private-headers %t1 | FileCheck %s + +## We expect 2 PT_LOAD segments +# CHECK: PHDR +# CHECK-NEXT: filesz {{0x[0-9a-f]+}} memsz {{0x[0-9a-f]+}} flags r-- +# CHECK-NEXT: LOAD +# CHECK-NEXT: filesz {{0x[0-9a-f]+}} memsz {{0x[0-9a-f]+}} flags rw- +# CHECK-NEXT: LOAD +# CHECK-NEXT: filesz {{0x[0-9a-f]+}} memsz {{0x[0-9a-f]+}} flags r-x +# CHECK-NEXT: STACK +# CHECK-NEXT: filesz + +.globl _start +_start: + jmp _start + +.section .rw, "aw" + .quad 0 diff --git a/test/ELF/linkerscript/empty-tls.s b/test/ELF/linkerscript/empty-tls.s new file mode 100644 index 0000000000000..919ccbffbe43a --- /dev/null +++ b/test/ELF/linkerscript/empty-tls.s @@ -0,0 +1,14 @@ +// 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/entry.s b/test/ELF/linkerscript/entry.s new file mode 100644 index 0000000000000..d75b1345a8aaa --- /dev/null +++ b/test/ELF/linkerscript/entry.s @@ -0,0 +1,42 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: echo "ENTRY(_label)" > %t.script +# RUN: ld.lld -o %t2 %t.script %t +# RUN: llvm-readobj %t2 > /dev/null + +# The entry symbol should not cause an undefined error. +# RUN: echo "ENTRY(_wrong_label)" > %t.script +# RUN: ld.lld -o %t2 %t.script %t +# RUN: ld.lld --entry=abc -o %t2 %t + +# -e has precedence over linker script's ENTRY. +# RUN: echo "ENTRY(_label)" > %t.script +# RUN: ld.lld -e _start -o %t2 %t.script %t +# RUN: llvm-readobj -file-headers -symbols %t2 | \ +# RUN: FileCheck -check-prefix=OVERLOAD %s + +# OVERLOAD: Entry: [[ENTRY:0x[0-9A-F]+]] +# OVERLOAD: Name: _start +# OVERLOAD-NEXT: Value: [[ENTRY]] + +# The entry symbol can be a linker-script-defined symbol. +# RUN: echo "ENTRY(foo); foo = 1;" > %t.script +# RUN: ld.lld -o %t2 %t.script %t +# RUN: llvm-readobj -file-headers -symbols %t2 | \ +# RUN: FileCheck -check-prefix=SCRIPT %s + +# SCRIPT: Entry: 0x1 + +# RUN: echo "ENTRY(no_such_symbol);" > %t.script +# RUN: ld.lld -o %t2 %t.script %t 2>&1 | \ +# RUN: FileCheck -check-prefix=MISSING %s + +# MISSING: warning: cannot find entry symbol no_such_symbol + +.globl _start, _label +_start: + ret +_label: + ret diff --git a/test/ELF/linkerscript/exclude-multiple.s b/test/ELF/linkerscript/exclude-multiple.s new file mode 100644 index 0000000000000..46ec18cfa1258 --- /dev/null +++ b/test/ELF/linkerscript/exclude-multiple.s @@ -0,0 +1,37 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tfile1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/exclude-multiple1.s -o %tfile2.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/exclude-multiple2.s -o %tfile3.o +# RUN: echo "SECTIONS { \ +# RUN: .foo : { *(.foo.1 EXCLUDE_FILE (*file1.o) .foo.2 EXCLUDE_FILE (*file2.o) .foo.3) } \ +# RUN: }" > %t1.script +# RUN: ld.lld -script %t1.script %tfile1.o %tfile2.o %tfile3.o -o %t1.o +# RUN: llvm-objdump -s %t1.o | FileCheck %s + +# CHECK: Contents of section .foo: +# CHECK-NEXT: 01000000 00000000 04000000 00000000 +# CHECK-NEXT: 07000000 00000000 05000000 00000000 +# CHECK-NEXT: 08000000 00000000 03000000 00000000 +# CHECK-NEXT: 09000000 00000000 +# CHECK-NEXT: Contents of section .foo.2: +# CHECK-NEXT: 02000000 00000000 +# CHECK-NEXT: Contents of section .foo.3: +# CHECK-NEXT: 06000000 00000000 + +# RUN: echo "SECTIONS { .foo : { *(EXCLUDE_FILE (*file1.o) EXCLUDE_FILE (*file2.o) .foo.3) } }" > %t2.script +# RUN: not ld.lld -script %t2.script %tfile1.o %tfile2.o %tfile3.o -o %t2.o 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ERR +# ERR: section pattern is expected + +# RUN: echo "SECTIONS { .foo : { *(EXCLUDE_FILE (*file1.o)) } }" > %t3.script +# RUN: not ld.lld -script %t3.script %tfile1.o %tfile2.o %tfile3.o -o %t2.o 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ERR + +.section .foo.1,"a" + .quad 1 + +.section .foo.2,"a" + .quad 2 + +.section .foo.3,"a" + .quad 3 diff --git a/test/ELF/linkerscript/excludefile.s b/test/ELF/linkerscript/excludefile.s new file mode 100644 index 0000000000000..8a154354dbc2d --- /dev/null +++ b/test/ELF/linkerscript/excludefile.s @@ -0,0 +1,46 @@ +# 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/include.s -o %t2 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ +# RUN: %p/Inputs/notinclude.s -o %t3.notinclude + +# RUN: echo "SECTIONS {} " > %t.script +# RUN: ld.lld -o %t --script %t.script %t1 %t2 %t3.notinclude +# RUN: llvm-objdump -d %t | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK: _start: +# CHECK-NEXT: : 48 c7 c0 3c 00 00 00 movq $60, %rax +# CHECK-NEXT: : 48 c7 c7 2a 00 00 00 movq $42, %rdi +# CHECK-NEXT: : 00 00 addb %al, (%rax) +# CHECK: _potato: +# CHECK-NEXT: : 90 nop +# CHECK-NEXT: : 90 nop +# CHECK-NEXT: : 00 00 addb %al, (%rax) +# CHECK: tomato: +# CHECK-NEXT: : b8 01 00 00 00 movl $1, %eax + +# RUN: echo "SECTIONS { .patatino : \ +# RUN: { KEEP(*(EXCLUDE_FILE(*notinclude) .text)) } }" \ +# RUN: > %t.script +# RUN: ld.lld -o %t4 --script %t.script %t1 %t2 %t3.notinclude +# RUN: llvm-objdump -d %t4 | FileCheck %s --check-prefix=EXCLUDE + +# EXCLUDE: Disassembly of section .patatino: +# EXCLUDE: _start: +# EXCLUDE-NEXT: : 48 c7 c0 3c 00 00 00 movq $60, %rax +# EXCLUDE-NEXT: : 48 c7 c7 2a 00 00 00 movq $42, %rdi +# EXCLUDE-NEXT: : 00 00 addb %al, (%rax) +# EXCLUDE: _potato: +# EXCLUDE-NEXT: : 90 nop +# EXCLUDE-NEXT: : 90 nop +# EXCLUDE: Disassembly of section .text: +# EXCLUDE: tomato: +# EXCLUDE-NEXT: : b8 01 00 00 00 movl $1, %eax + +.section .text +.globl _start +_start: + mov $60, %rax + mov $42, %rdi diff --git a/test/ELF/linkerscript/extend-pt-load.s b/test/ELF/linkerscript/extend-pt-load.s new file mode 100644 index 0000000000000..f9a77c8c12bf9 --- /dev/null +++ b/test/ELF/linkerscript/extend-pt-load.s @@ -0,0 +1,69 @@ +# 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 -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: . = ALIGN(0x1000); \ +# RUN: bar : { HIDDEN(bar_sym = .); } \ +# RUN: .data.rel.ro : { *(.data.rel.ro) } \ +# RUN: }" > %t.script +# RUN: ld.lld -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 PROGBITS 0000000000001000 001000 000000 00 AX +# CHECK2-NEXT: .data.rel.ro PROGBITS 0000000000001000 001000 000001 00 WA + +# CHECK2: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x001000 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 -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/filename-spec.s b/test/ELF/linkerscript/filename-spec.s new file mode 100644 index 0000000000000..d4bc495efb81c --- /dev/null +++ b/test/ELF/linkerscript/filename-spec.s @@ -0,0 +1,59 @@ +# 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 \ +# RUN: %p/Inputs/filename-spec.s -o %tsecond.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 : { \ +# 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: 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 : { \ +# RUN: *second.o(.foo) \ +# RUN: *first.o(.foo) } }" > %t4.script +# RUN: ld.lld -o %t4 --script %t4.script %tfirst.o %tsecond.o +# RUN: llvm-objdump -s %t4 | FileCheck --check-prefix=SECONDFIRST %s + +# 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 %T/filename-spec2.o + +# RUN: echo "SECTIONS { .foo : { \ +# RUN: filename-spec2.o(.foo) \ +# RUN: filename-spec1.o(.foo) } }" > %t5.script +# RUN: ld.lld -o %t5 --script %t5.script \ +# 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: ld.lld -o %t6 --script %t6.script \ +# RUN: %T/filename-spec1.o %T/filename-spec2.o +# RUN: llvm-objdump -s %t6 | FileCheck --check-prefix=FIRSTSECOND %s + +.global _start +_start: + nop + +.section .foo,"a" + .quad 1 diff --git a/test/ELF/linkerscript/fill.s b/test/ELF/linkerscript/fill.s new file mode 100644 index 0000000000000..57a19e0943d00 --- /dev/null +++ b/test/ELF/linkerscript/fill.s @@ -0,0 +1,30 @@ +# 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: *(.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: aa222222 22bb2222 22222222 2222 + +.text +.globl _start +_start: + +.section .aaa, "a" +.align 1 +.byte 0xAA + +.section .bbb, "a" +.align 1 +.byte 0xBB diff --git a/test/ELF/linkerscript/group.s b/test/ELF/linkerscript/group.s new file mode 100644 index 0000000000000..53a1c89ebfe34 --- /dev/null +++ b/test/ELF/linkerscript/group.s @@ -0,0 +1,56 @@ +# REQUIRES: x86 + +# RUN: mkdir -p %t.dir +# RUN: rm -f %t.dir/libxyz.a +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ +# RUN: %p/Inputs/libsearch-st.s -o %t2.o +# RUN: llvm-ar rcs %t.dir/libxyz.a %t2.o + +# RUN: echo "GROUP(\"%t\")" > %t.script +# RUN: ld.lld -o %t2 %t.script +# RUN: llvm-readobj %t2 > /dev/null + +# RUN: echo "INPUT(\"%t\")" > %t.script +# RUN: ld.lld -o %t2 %t.script +# RUN: llvm-readobj %t2 > /dev/null + +# RUN: echo "GROUP(\"%t\" libxyz.a )" > %t.script +# RUN: not ld.lld -o %t2 %t.script 2>/dev/null +# RUN: ld.lld -o %t2 %t.script -L%t.dir +# RUN: llvm-readobj %t2 > /dev/null + +# RUN: echo "GROUP(\"%t\" =libxyz.a )" > %t.script +# RUN: not ld.lld -o %t2 %t.script 2>/dev/null +# RUN: ld.lld -o %t2 %t.script --sysroot=%t.dir +# RUN: llvm-readobj %t2 > /dev/null + +# RUN: echo "GROUP(\"%t\" -lxyz )" > %t.script +# RUN: not ld.lld -o %t2 %t.script 2>/dev/null +# RUN: ld.lld -o %t2 %t.script -L%t.dir +# RUN: llvm-readobj %t2 > /dev/null + +# RUN: echo "GROUP(\"%t\" libxyz.a )" > %t.script +# RUN: not ld.lld -o %t2 %t.script 2>/dev/null +# RUN: ld.lld -o %t2 %t.script -L%t.dir +# RUN: llvm-readobj %t2 > /dev/null + +# RUN: echo "GROUP(\"%t\" /libxyz.a )" > %t.script +# RUN: echo "GROUP(\"%t\" /libxyz.a )" > %t.dir/xyz.script +# RUN: not ld.lld -o %t2 %t.script 2>/dev/null +# RUN: not ld.lld -o %t2 %t.script --sysroot=%t.dir 2>/dev/null +# RUN: ld.lld -o %t2 %t.dir/xyz.script --sysroot=%t.dir +# RUN: llvm-readobj %t2 > /dev/null + +# RUN: echo "GROUP(\"%t.script2\")" > %t.script1 +# RUN: echo "GROUP(\"%t\")" > %t.script2 +# RUN: ld.lld -o %t2 %t.script1 +# RUN: llvm-readobj %t2 > /dev/null + +# RUN: echo "GROUP(AS_NEEDED(\"%t\"))" > %t.script +# RUN: ld.lld -o %t2 %t.script +# RUN: llvm-readobj %t2 > /dev/null + +.globl _start +_start: + ret diff --git a/test/ELF/linkerscript/header-addr.s b/test/ELF/linkerscript/header-addr.s new file mode 100644 index 0000000000000..f37d319aaabee --- /dev/null +++ b/test/ELF/linkerscript/header-addr.s @@ -0,0 +1,47 @@ +# 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; \ +# RUN: .text : {*(.text)} :all \ +# RUN: }" > %t.script +# RUN: ld.lld -o %t.so --script %t.script %t.o -shared +# RUN: llvm-readobj -program-headers %t.so | FileCheck %s + +# CHECK: ProgramHeaders [ +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x40 +# CHECK-NEXT: VirtualAddress: 0x1040 +# CHECK-NEXT: PhysicalAddress: 0x1040 +# CHECK-NEXT: FileSize: 4176 +# CHECK-NEXT: MemSize: 4176 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: PF_W (0x2) +# CHECK-NEXT: PF_X (0x1) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 4096 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +# RUN: ld.lld -o %t2.so --script %t.script %t.o -shared -z max-page-size=0x2000 +# RUN: llvm-readobj -program-headers %t2.so \ +# RUN: | FileCheck --check-prefix=MAXPAGE %s + +# MAXPAGE: ProgramHeaders [ +# MAXPAGE-NEXT: ProgramHeader { +# MAXPAGE-NEXT: Type: PT_LOAD +# MAXPAGE-NEXT: Offset: 0x40 +# MAXPAGE-NEXT: VirtualAddress: 0x40 +# MAXPAGE-NEXT: PhysicalAddress: 0x40 +# MAXPAGE-NEXT: FileSize: 8272 +# MAXPAGE-NEXT: MemSize: 8272 +# MAXPAGE-NEXT: Flags [ +# MAXPAGE-NEXT: PF_R +# MAXPAGE-NEXT: PF_W +# MAXPAGE-NEXT: PF_X +# MAXPAGE-NEXT: ] +# MAXPAGE-NEXT: Alignment: 8192 +# MAXPAGE-NEXT: } +# MAXPAGE-NEXT: ] diff --git a/test/ELF/linkerscript/implicit-program-header.s b/test/ELF/linkerscript/implicit-program-header.s new file mode 100644 index 0000000000000..9598a6abebb04 --- /dev/null +++ b/test/ELF/linkerscript/implicit-program-header.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld -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/input-order.s b/test/ELF/linkerscript/input-order.s new file mode 100644 index 0000000000000..cb9ea354cdbfb --- /dev/null +++ b/test/ELF/linkerscript/input-order.s @@ -0,0 +1,38 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# This test case should place input sections in script order: +# .foo.1 .foo.2 .bar.1 .bar.2 +# RUN: echo "SECTIONS { . = 0x1000; .foo : {*(.foo.*) *(.bar.*) } }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -section=.foo -s %t1 | FileCheck --check-prefix=SCRIPT_ORDER %s +# SCRIPT_ORDER: Contents of section .foo: +# SCRIPT_ORDER-NEXT: 1000 00000000 00000000 ffffffff eeeeeeee + +# This test case should place input sections in native order: +# .bar.1 .foo.1 .bar.2 .foo.2 +# RUN: echo "SECTIONS { . = 0x1000; .foo : {*(.foo.* .bar.*)} }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -section=.foo -s %t1 | FileCheck --check-prefix=FILE_ORDER %s +# FILE_ORDER: Contents of section .foo: +# FILE_ORDER-NEXT: 1000 ffffffff 00000000 eeeeeeee 00000000 + +.global _start +_start: + nop + +.section .bar.1,"a" +bar1: + .long 0xFFFFFFFF + +.section .foo.1,"a" +foo1: + .long 0 + +.section .bar.2,"a" +bar2: + .long 0xEEEEEEEE + +.section .foo.2,"a" +foo2: + .long 0 diff --git a/test/ELF/linkerscript/input-sec-dup.s b/test/ELF/linkerscript/input-sec-dup.s new file mode 100644 index 0000000000000..fd889393c74c7 --- /dev/null +++ b/test/ELF/linkerscript/input-sec-dup.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: echo "SECTIONS {.foo : { *(.foo) *(.foo) } }" > %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 +# CHECK-NEXT: 0 00000000 +# CHECK-NEXT: 1 .foo 00000004 +# CHECK-NEXT: 2 .text 00000001 + +.global _start +_start: + nop + +.section .foo,"a" + .long 0 diff --git a/test/ELF/linkerscript/linkerscript.s b/test/ELF/linkerscript/linkerscript.s new file mode 100644 index 0000000000000..cac902af4270f --- /dev/null +++ b/test/ELF/linkerscript/linkerscript.s @@ -0,0 +1,54 @@ +# 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 \ +# RUN: %p/Inputs/libsearch-st.s -o %t2.o + +# RUN: echo "EXTERN( undef undef2 )" > %t.script +# RUN: ld.lld %t -o %t2 %t.script +# RUN: llvm-readobj %t2 > /dev/null + +# RUN: echo "OUTPUT_FORMAT(elf64-x86-64) /*/*/ GROUP(\"%t\" )" > %t.script +# RUN: ld.lld -o %t2 %t.script +# RUN: llvm-readobj %t2 > /dev/null + +# RUN: rm -f %t.out +# RUN: echo "OUTPUT(\"%t.out\")" > %t.script +# RUN: ld.lld %t.script %t +# RUN: llvm-readobj %t.out > /dev/null + +# RUN: echo "SEARCH_DIR(/lib/foo/blah)" > %t.script +# RUN: ld.lld %t.script %t +# RUN: llvm-readobj %t.out > /dev/null + +# RUN: echo ";SEARCH_DIR(x);SEARCH_DIR(y);" > %t.script +# RUN: ld.lld %t.script %t +# RUN: llvm-readobj %t.out > /dev/null + +# RUN: echo ";" > %t.script +# RUN: ld.lld %t.script %t +# 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: 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: FileCheck -check-prefix=INCLUDE_ERR %s < %t.log +# INCLUDE_ERR: error: {{.+}}.script:1: cannot open foo.script +# INCLUDE_ERR-NEXT: error: {{.+}}.script:1: 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: FileCheck -check-prefix=ERR1 %s < %t.log + +# ERR1: unknown directive: FOO + +.globl _start, _label +_start: + ret +_label: + ret diff --git a/test/ELF/linkerscript/loadaddr.s b/test/ELF/linkerscript/loadaddr.s new file mode 100644 index 0000000000000..33c5f21b52ba9 --- /dev/null +++ b/test/ELF/linkerscript/loadaddr.s @@ -0,0 +1,42 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: . = 0x1000; \ +# RUN: .aaa : AT(0x2000) { *(.aaa) } \ +# RUN: .bbb : { *(.bbb) } \ +# RUN: .ccc : AT(0x3000) { *(.ccc) } \ +# RUN: .ddd : AT(0x4000) { *(.ddd) } \ +# RUN: .text : { *(.text) } \ +# RUN: aaa_lma = LOADADDR(.aaa); \ +# RUN: bbb_lma = LOADADDR(.bbb); \ +# RUN: ccc_lma = LOADADDR(.ccc); \ +# RUN: ddd_lma = LOADADDR(.ddd); \ +# RUN: txt_lma = LOADADDR(.text); \ +# RUN: }" > %t.script +# RUN: ld.lld %t --script %t.script -o %t2 +# RUN: llvm-objdump -t %t2 | FileCheck %s +# RUN: echo "SECTIONS { v = LOADADDR(.zzz); }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | FileCheck --check-prefix=ERROR %s + +# CHECK: 0000000000002000 *ABS* 00000000 aaa_lma +# CHECK-NEXT: 0000000000002008 *ABS* 00000000 bbb_lma +# CHECK-NEXT: 0000000000003000 *ABS* 00000000 ccc_lma +# CHECK-NEXT: 0000000000004000 *ABS* 00000000 ddd_lma +# CHECK-NEXT: 0000000000004008 *ABS* 00000000 txt_lma +# ERROR: {{.*}}.script:1: undefined section .zzz + +.global _start +_start: + nop + +.section .aaa, "a" +.quad 0 + +.section .bbb, "a" +.quad 0 + +.section .ccc, "a" +.quad 0 + +.section .ddd, "a" +.quad 0 diff --git a/test/ELF/linkerscript/locationcounter.s b/test/ELF/linkerscript/locationcounter.s new file mode 100644 index 0000000000000..c57a17c5c9cbd --- /dev/null +++ b/test/ELF/linkerscript/locationcounter.s @@ -0,0 +1,189 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: . = 0xFFF0; \ +# RUN: . = . + 0x10; \ +# RUN: .plus : { *(.plus) } \ +# RUN: . = 0x11010 - 0x10; \ +# RUN: .minus : { *(.minus) } \ +# RUN: . = 0x24000 / 0x2; \ +# RUN: .div : { *(.div) } \ +# RUN: . = 0x11000 + 0x1000 * 0x2; \ +# RUN: .mul : { *(.mul) } \ +# RUN: . = 0x10000 + (0x1000 + 0x1000) * 0x2; \ +# RUN: .bracket : { *(.bracket) } \ +# RUN: . = 0x17000 & 0x15000; \ +# RUN: .and : { *(.and) } \ +# RUN: . = 0x1 ? 0x16000 : 0x999999; \ +# RUN: .ternary1 : { *(.ternary1) } \ +# RUN: . = 0x0 ? 0x999999 : 0x17000; \ +# RUN: .ternary2 : { *(.ternary2) } \ +# RUN: . = 0x0 < 0x1 ? 0x18000 : 0x999999; \ +# RUN: .less : { *(.less) } \ +# RUN: . = 0x1 <= 0x1 ? 0x19000 : 0x999999; \ +# RUN: .lesseq : { *(.lesseq) } \ +# RUN: . = 0x1 > 0x0 ? 0x20000 : 0x999999; \ +# RUN: .great : { *(.great) } \ +# RUN: . = 0x1 >= 0x1 ? 0x21000 : 0x999999; \ +# RUN: .greateq : { *(.greateq) } \ +# RUN: . = 0x1 == 0x1 ? 0x22000 : 0x999999; \ +# RUN: .eq : { *(.eq) } \ +# RUN: . = 0x2 != 0x1 ? 0x23000 : 0x999999; \ +# RUN: .neq : { *(.neq) } \ +# RUN: . = CONSTANT (MAXPAGESIZE) * 0x24; \ +# RUN: .maxpagesize : { *(.maxpagesize) } \ +# RUN: . = CONSTANT (COMMONPAGESIZE) * 0x25; \ +# RUN: .commonpagesize : { *(.commonpagesize) } \ +# RUN: . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); \ +# RUN: .datasegmentalign : { *(.datasegmentalign) } \ +# RUN: . = DATA_SEGMENT_END (.); \ +# RUN: . = 0x27000; \ +# RUN: . += 0x1000; \ +# RUN: .plusassign : { *(.plusassign) } \ +# RUN: . = ((. + 0x1fff) & ~(0x1000 + -1)); \ +# RUN: .unary : { *(.unary) } \ +# RUN: . = 0x30000 + (1 + 1 << 5); \ +# RUN: .shiftl : { *(.shiftl) } \ +# RUN: . = 0x30000 + (1 + 1023 >> 2); \ +# RUN: .shiftr : { *(.shiftr) } \ + +# RUN: }" > %t.script +# RUN: ld.lld %t --script %t.script -o %t2 +# RUN: llvm-objdump -section-headers %t2 | FileCheck %s + +# CHECK: .plus {{.*}} 0000000000010000 +# CHECK: .minus {{.*}} 0000000000011000 +# CHECK: .div {{.*}} 0000000000012000 +# CHECK: .mul {{.*}} 0000000000013000 +# CHECK: .bracket {{.*}} 0000000000014000 +# CHECK: .and {{.*}} 0000000000015000 +# CHECK: .ternary1 {{.*}} 0000000000016000 +# CHECK: .ternary2 {{.*}} 0000000000017000 +# CHECK: .less {{.*}} 0000000000018000 +# CHECK: .lesseq {{.*}} 0000000000019000 +# CHECK: .great {{.*}} 0000000000020000 +# CHECK: .greateq {{.*}} 0000000000021000 +# CHECK: .eq {{.*}} 0000000000022000 +# CHECK: .neq {{.*}} 0000000000023000 +# CHECK: .maxpagesize {{.*}} 0000000000024000 +# CHECK: .commonpagesize {{.*}} 0000000000025000 +# CHECK: .datasegmentalign {{.*}} 0000000000026000 +# CHECK: .plusassign {{.*}} 0000000000028000 +# CHECK: .unary {{.*}} 000000000002a000 +# CHECK: .shiftl {{.*}} 0000000000030040 +# CHECK: .shiftr {{.*}} 0000000000030100 + +## Mailformed number error. +# RUN: echo "SECTIONS { \ +# RUN: . = 0x12Q41; \ +# RUN: }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=NUMERR %s +# NUMERR: malformed number: 0x12Q41 + +## Missing closing bracket. +# RUN: echo "SECTIONS { \ +# RUN: . = 0x10000 + (0x1000 + 0x1000 * 0x2; \ +# RUN: }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=BRACKETERR %s +# BRACKETERR: ) expected, but got ; + +## Missing opening bracket. +# RUN: echo "SECTIONS { \ +# RUN: . = 0x10000 + 0x1000 + 0x1000) * 0x2; \ +# RUN: }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=BRACKETERR2 %s +# BRACKETERR2: ; expected, but got ) + +## Empty expression. +# RUN: echo "SECTIONS { \ +# RUN: . = ; \ +# RUN: }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=ERREXPR %s +# ERREXPR: malformed number: ; + +## Div by zero error. +# RUN: echo "SECTIONS { \ +# RUN: . = 0x10000 / 0x0; \ +# RUN: }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=DIVZERO %s +# DIVZERO: division by zero + +## Broken ternary operator expression. +# RUN: echo "SECTIONS { \ +# RUN: . = 0x1 ? 0x2; \ +# RUN: }" > %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 + +.section .plus, "a" +.quad 0 + +.section .minus, "a" +.quad 0 + +.section .div, "a" +.quad 0 + +.section .mul, "a" +.quad 0 + +.section .bracket, "a" +.quad 0 + +.section .and, "a" +.quad 0 + +.section .ternary1, "a" +.quad 0 + +.section .ternary2, "a" +.quad 0 + +.section .less, "a" +.quad 0 + +.section .lesseq, "a" +.quad 0 + +.section .great, "a" +.quad 0 + +.section .greateq, "a" +.quad 0 + +.section .eq, "a" +.quad 0 + +.section .neq, "a" +.quad 0 + +.section .maxpagesize, "a" +.quad 0 + +.section .commonpagesize, "a" +.quad 0 + +.section .datasegmentalign, "a" +.quad 0 + +.section .plusassign, "a" +.quad 0 + +.section .unary, "a" +.quad 0 + +.section .shiftl, "a" +.quad 0 + +.section .shiftr, "a" +.quad 0 diff --git a/test/ELF/linkerscript/locationcountererr.s b/test/ELF/linkerscript/locationcountererr.s new file mode 100644 index 0000000000000..7664d8d46917d --- /dev/null +++ b/test/ELF/linkerscript/locationcountererr.s @@ -0,0 +1,9 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { .text 0x2000 : {. = 0x10 ; *(.text) } }" > %t.script +# RUN: not ld.lld %t --script %t.script -o %t1 2>&1 | FileCheck %s +# CHECK: unable to move location counter backward for: .text + +.globl _start +_start: +nop diff --git a/test/ELF/linkerscript/merge-sections-reloc.s b/test/ELF/linkerscript/merge-sections-reloc.s new file mode 100644 index 0000000000000..6393415403504 --- /dev/null +++ b/test/ELF/linkerscript/merge-sections-reloc.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/merge-sections-reloc.s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o +# RUN: echo "SECTIONS {}" > %t.script +# RUN: ld.lld -o %t --script %t.script %t1.o %t2.o +# RUN: llvm-objdump -s %t | FileCheck %s + +## Check that sections content is not corrupted. +# CHECK: Contents of section .text: +# CHECK-NEXT: 44332211 00000000 44332211 00000000 +# CHECK-NEXT: f0ffffff ffffffff + +.globl _start +_foo: + .quad 0x11223344 + .quad _start - . diff --git a/test/ELF/linkerscript/merge-sections.s b/test/ELF/linkerscript/merge-sections.s new file mode 100644 index 0000000000000..7252fe576674c --- /dev/null +++ b/test/ELF/linkerscript/merge-sections.s @@ -0,0 +1,94 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: echo "SECTIONS { \ +# RUN: . = SIZEOF_HEADERS; \ +# RUN: .foo : { begin = .; *(.foo.*) end = .;} \ +# RUN: }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t -shared +# RUN: llvm-readobj -s -t %t1 | FileCheck %s + +# CHECK: Name: .foo +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: SHF_STRINGS +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x[[ADDR1:.*]] +# CHECK-NEXT: Offset: 0x[[ADDR1]] +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 1 +# CHECK-NEXT: EntrySize: 1 +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: +# CHECK-NEXT: Name: .foo +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x +# CHECK-NEXT: Offset: 0x +# CHECK-NEXT: Size: 1 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 1 +# CHECK-NEXT: EntrySize: 1 +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: +# CHECK-NEXT: Name: .foo +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x +# CHECK-NEXT: Offset: 0x +# CHECK-NEXT: Size: 2 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 2 +# CHECK-NEXT: EntrySize: 2 +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: +# CHECK-NEXT: Name: +# CHECK-NEXT: Type: +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_EXECINSTR +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x[[ADDR2:.*]] +# CHECK-NEXT: Offset: 0x[[ADDR2]] + + +# CHECK: Name: begin +# CHECK-NEXT: Value: 0x[[ADDR1]] + +# CHECK: Name: end +# CHECK-NEXT: Value: 0x[[ADDR2]] + +.section .foo.1a,"aMS",@progbits,1 +.asciz "foo" + +.section .foo.1b,"aMS",@progbits,1 +.asciz "foo" + +.section .foo.2a,"aM",@progbits,1 +.byte 42 + +.section .foo.2b,"aM",@progbits,1 +.byte 42 + +.section .foo.3a,"aM",@progbits,2 +.align 2 +.short 42 + +.section .foo.3b,"aM",@progbits,2 +.align 2 +.short 42 diff --git a/test/ELF/linkerscript/multi-sections-constraint.s b/test/ELF/linkerscript/multi-sections-constraint.s new file mode 100644 index 0000000000000..bfedd10fc2854 --- /dev/null +++ b/test/ELF/linkerscript/multi-sections-constraint.s @@ -0,0 +1,34 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.text) } \ +# RUN: . = 0x1000; .aaa : ONLY_IF_RO { *(.aaa.*) } \ +# RUN: . = 0x2000; .aaa : ONLY_IF_RW { *(.aaa.*) } } " > %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: .aaa 00000010 0000000000002000 DATA + + +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.text) } \ +# RUN: . = 0x1000; .aaa : ONLY_IF_RW { *(.aaa.*) } \ +# RUN: . = 0x2000; .aaa : ONLY_IF_RO { *(.aaa.*) } } " > %t2.script +# RUN: ld.lld -o %t2 --script %t2.script %t +# RUN: llvm-objdump -section-headers %t2 | FileCheck %s --check-prefix=REV + +# REV: Sections: +# REV-NEXT: Idx Name Size Address Type +# REV: .aaa 00000010 0000000000001000 DATA + +.global _start +_start: + nop + +.section .aaa.1, "aw" +.quad 1 + +.section .aaa.2, "aw" +.quad 1 diff --git a/test/ELF/linkerscript/multiple-tbss.s b/test/ELF/linkerscript/multiple-tbss.s new file mode 100644 index 0000000000000..6bbbca92c2399 --- /dev/null +++ b/test/ELF/linkerscript/multiple-tbss.s @@ -0,0 +1,45 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { }" > %t.script +# RUN: ld.lld -T %t.script %t.o -o %t +# RUN: llvm-readobj -l -s %t | FileCheck %s + +# CHECK: Name: .tbss +# CHECK-NEXT: Type: SHT_NOBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_TLS +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 8 +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: +# CHECK-NEXT: EntrySize: +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: +# CHECK-NEXT: Name: foo +# CHECK-NEXT: Type: SHT_NOBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_TLS +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 1 + +# CHECK: Type: PT_TLS +# CHECK-NEXT: Offset: +# CHECK-NEXT: VirtualAddress: +# CHECK-NEXT: PhysicalAddress: +# CHECK-NEXT: FileSize: 0 +# CHECK-NEXT: MemSize: 9 + +.section .tbss,"awT",@nobits +.quad 0 +.section foo,"awT",@nobits +.byte 0 diff --git a/test/ELF/linkerscript/no-pt-load.s b/test/ELF/linkerscript/no-pt-load.s new file mode 100644 index 0000000000000..c70402501391d --- /dev/null +++ b/test/ELF/linkerscript/no-pt-load.s @@ -0,0 +1,5 @@ +# 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-space.s b/test/ELF/linkerscript/no-space.s new file mode 100644 index 0000000000000..a96797269e43e --- /dev/null +++ b/test/ELF/linkerscript/no-space.s @@ -0,0 +1,26 @@ +# 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: ld.lld -o %t --script %t.script %t.o -shared +# RUN: llvm-readobj -elf-output-style=GNU -l %t | FileCheck %s + +# RUN: echo "SECTIONS {foo : {*(foo*)} }" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o -shared +# RUN: llvm-readobj -elf-output-style=GNU -l %t | FileCheck %s + +# There is not enough address space available for the header, so just start the PT_LOAD +# after it. + +# CHECK: Program Headers: +# CHECK-NEXT: Type Offset VirtAddr PhysAddr +# CHECK-NEXT: PHDR +# CHECK-NEXT: LOAD 0x001000 0x0000000000000000 0x0000000000000000 + +# CHECK: Section to Segment mapping: +# CHECK-NEXT: Segment Sections... +# CHECK-NEXT: 00 +# CHECK-NEXT: 01 foo .text .dynsym .hash .dynstr + +.section foo, "a" +.quad 0 diff --git a/test/ELF/linkerscript/non-alloc.s b/test/ELF/linkerscript/non-alloc.s new file mode 100644 index 0000000000000..2060129a80204 --- /dev/null +++ b/test/ELF/linkerscript/non-alloc.s @@ -0,0 +1,25 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t + +# RUN: echo "SECTIONS { .foo 0 : {*(foo)} }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t -shared +# RUN: llvm-readobj -elf-output-style=GNU -s -l %t1 | 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. + +# CHECK: Program Headers: +# CHECK-NEXT: Type +# CHECK-NEXT: PHDR +# CHECK-NEXT: LOAD {{.*}} R E +# CHECK-NEXT: LOAD {{.*}} RW + +# CHECK: Section to Segment mapping: +# CHECK-NEXT: Segment Sections... +# CHECK-NEXT: 00 +# CHECK-NEXT: 01 .text .dynsym .hash .dynstr +# CHECK-NEXT: 02 .dynamic + +nop +.section foo +.quad 0 diff --git a/test/ELF/linkerscript/numbers.s b/test/ELF/linkerscript/numbers.s new file mode 100644 index 0000000000000..653f94bd4e6ef --- /dev/null +++ b/test/ELF/linkerscript/numbers.s @@ -0,0 +1,72 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: . = 1000h; \ +# RUN: .hex1 : { *(.hex.1) } \ +# RUN: . = 1010H; \ +# RUN: .hex2 : { *(.hex.2) } \ +# RUN: . = 10k; \ +# RUN: .kilo1 : { *(.kilo.1) } \ +# RUN: . = 11K; \ +# RUN: .kilo2 : { *(.kilo.2) } \ +# RUN: . = 1m; \ +# RUN: .mega1 : { *(.mega.1) } \ +# RUN: . = 2M; \ +# RUN: .mega2 : { *(.mega.2) } \ +# RUN: }" > %t.script +# RUN: ld.lld %t --script %t.script -o %t2 +# RUN: llvm-objdump -section-headers %t2 | FileCheck %s + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address +# CHECK-NEXT: 0 00000000 0000000000000000 +# CHECK-NEXT: 1 .hex1 00000008 0000000000001000 +# CHECK-NEXT: 2 .hex2 00000008 0000000000001010 +# CHECK-NEXT: 3 .kilo1 00000008 0000000000002800 +# CHECK-NEXT: 4 .kilo2 00000008 0000000000002c00 +# CHECK-NEXT: 5 .mega1 00000008 0000000000100000 +# CHECK-NEXT: 6 .mega2 00000008 0000000000200000 + +## Mailformed number errors. +# RUN: echo "SECTIONS { \ +# RUN: . = 0x11h; \ +# RUN: }" > %t2.script +# RUN: not ld.lld %t --script %t2.script -o %t3 2>&1 | \ +# RUN: FileCheck --check-prefix=ERR1 %s +# ERR1: malformed number: 0x11h + +# RUN: echo "SECTIONS { \ +# RUN: . = 0x11k; \ +# RUN: }" > %t3.script +# RUN: not ld.lld %t --script %t3.script -o %t4 2>&1 | \ +# RUN: FileCheck --check-prefix=ERR2 %s +# ERR2: malformed number: 0x11k + +# RUN: echo "SECTIONS { \ +# RUN: . = 0x11m; \ +# RUN: }" > %t4.script +# RUN: not ld.lld %t --script %t4.script -o %t5 2>&1 | \ +# RUN: FileCheck --check-prefix=ERR3 %s +# ERR3: malformed number: 0x11m + +.globl _start +_start: +nop + +.section .hex.1, "a" +.quad 0 + +.section .kilo.1, "a" +.quad 0 + +.section .mega.1, "a" +.quad 0 + +.section .hex.2, "a" +.quad 0 + +.section .kilo.2, "a" +.quad 0 + +.section .mega.2, "a" +.quad 0 diff --git a/test/ELF/linkerscript/openbsd-bootdata.s b/test/ELF/linkerscript/openbsd-bootdata.s new file mode 100644 index 0000000000000..3e90574bb3a31 --- /dev/null +++ b/test/ELF/linkerscript/openbsd-bootdata.s @@ -0,0 +1,7 @@ +# 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-randomize.s b/test/ELF/linkerscript/openbsd-randomize.s new file mode 100644 index 0000000000000..bf885f423b022 --- /dev/null +++ b/test/ELF/linkerscript/openbsd-randomize.s @@ -0,0 +1,23 @@ +# 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; \ +# RUN: .text : { *(.text) } \ +# RUN: .openbsd.randomdata : { *(.openbsd.randomdata) } : rand }" > %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_RANDOMIZE (0x65A3DBE6) +# CHECK-NEXT: Offset: 0x74 +# CHECK-NEXT: VirtualAddress: 0x74 +# CHECK-NEXT: PhysicalAddress: 0x74 +# CHECK-NEXT: FileSize: 8 +# CHECK-NEXT: MemSize: 8 +# CHECK-NEXT: Flags [ (0x4) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 1 +# CHECK-NEXT: } + +.section .openbsd.randomdata, "a" +.quad 0 diff --git a/test/ELF/linkerscript/openbsd-wxneeded.s b/test/ELF/linkerscript/openbsd-wxneeded.s new file mode 100644 index 0000000000000..d371da9d86459 --- /dev/null +++ b/test/ELF/linkerscript/openbsd-wxneeded.s @@ -0,0 +1,17 @@ +# 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 +# RUN: llvm-readobj --program-headers %t | FileCheck %s + +# CHECK: ProgramHeader { +# CHECK: Type: PT_OPENBSD_WXNEEDED (0x65A3DBE7) +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x0 +# CHECK-NEXT: PhysicalAddress: 0x0 +# CHECK-NEXT: FileSize: 0 +# CHECK-NEXT: MemSize: 0 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 0 +# CHECK-NEXT: } diff --git a/test/ELF/linkerscript/orphan-align.s b/test/ELF/linkerscript/orphan-align.s new file mode 100644 index 0000000000000..edd637b928201 --- /dev/null +++ b/test/ELF/linkerscript/orphan-align.s @@ -0,0 +1,28 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { \ +# RUN: . = SIZEOF_HEADERS; \ +# RUN: .text : { *(.text) } \ +# RUN: . = ALIGN(0x1000); \ +# RUN: .data.rel.ro : { *(.data.rel.ro) } \ +# RUN: }" > %t.script +# RUN: ld.lld -o %t -T %t.script %t.o -shared +# RUN: llvm-readobj -l %t | FileCheck %s + + +# Test that the orphan section foo is placed before the ALIGN and so the second +# PT_LOAD is aligned. + + +# CHECK: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x0 + +# CHECK: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x1000 + +nop +.section .data.rel.ro, "aw" +.byte 0 + +.section foo, "ax" +nop diff --git a/test/ELF/linkerscript/orphan-first-cmd.s b/test/ELF/linkerscript/orphan-first-cmd.s new file mode 100644 index 0000000000000..3fb3b31b9a40d --- /dev/null +++ b/test/ELF/linkerscript/orphan-first-cmd.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: foo = 123; \ +# RUN: . = 0x1000; \ +# RUN: . = 0x2000; \ +# RUN: .bar : { . = . + 1; } \ +# 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 diff --git a/test/ELF/linkerscript/orphan.s b/test/ELF/linkerscript/orphan.s new file mode 100644 index 0000000000000..3daa6fbf63c9f --- /dev/null +++ b/test/ELF/linkerscript/orphan.s @@ -0,0 +1,36 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.text) } \ +# RUN: .rw1 : { *(.rw1) } \ +# RUN: .rw2 : { *(.rw2) } \ +# RUN: .rw3 : { *(.rw3) } \ +# RUN: }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s + +## .jcr is a relro section and should be placed before other RW sections. +## .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: 2 .jcr 00000008 0000000000000000 DATA +# CHECK-NEXT: 3 .rw1 00000008 0000000000000008 DATA +# CHECK-NEXT: 4 .rw2 00000008 0000000000000010 DATA +# CHECK-NEXT: 5 .rw3 00000008 0000000000000018 DATA +# CHECK-NEXT: 6 .bss 00000008 0000000000000020 BSS + +.section .rw1, "aw" + .quad 0 + +.section .rw2, "aw" + .quad 0 + +.section .rw3, "aw" + .quad 0 + +.section .jcr, "aw" + .quad 0 + +.section .bss, "aw",@nobits + .quad 0 diff --git a/test/ELF/linkerscript-orphans.s b/test/ELF/linkerscript/orphans.s index fa7d30bf7f7c5..0a8c7ab1129bc 100644 --- a/test/ELF/linkerscript-orphans.s +++ b/test/ELF/linkerscript/orphans.s @@ -14,8 +14,8 @@ # TEXTORPHAN: Sections: # TEXTORPHAN-NEXT: Idx Name # TEXTORPHAN-NEXT: 0 -# TEXTORPHAN-NEXT: 1 .writable -# TEXTORPHAN-NEXT: 2 .text +# TEXTORPHAN-NEXT: 1 .text +# TEXTORPHAN-NEXT: 2 .writable # WRITABLEORPHAN: Sections: # WRITABLEORPHAN-NEXT: Idx Name diff --git a/test/ELF/linkerscript-ouputformat.s b/test/ELF/linkerscript/ouputformat.s index 3c6cfdc8f9660..7d4402a557a0f 100644 --- a/test/ELF/linkerscript-ouputformat.s +++ b/test/ELF/linkerscript/ouputformat.s @@ -7,4 +7,3 @@ # RUN: echo "OUTPUT_FORMAT(x, y)" > %t.script # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %t1 # RUN: not ld.lld -shared -o %t2 %t1 %t.script -# RUN: llvm-readobj %t2 > /dev/null diff --git a/test/ELF/linkerscript-outputarch.s b/test/ELF/linkerscript/outputarch.s index 99089615cb17d..99089615cb17d 100644 --- a/test/ELF/linkerscript-outputarch.s +++ b/test/ELF/linkerscript/outputarch.s diff --git a/test/ELF/linkerscript/outsections-addr.s b/test/ELF/linkerscript/outsections-addr.s new file mode 100644 index 0000000000000..003b2771c3363 --- /dev/null +++ b/test/ELF/linkerscript/outsections-addr.s @@ -0,0 +1,122 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: .aaa 0x2000 : \ +# RUN: { \ +# RUN: *(.aaa) \ +# RUN: } \ +# RUN: .bbb 0x1 ? 0x3000 : 0x4000 : \ +# RUN: { \ +# RUN: *(.bbb) \ +# RUN: } \ +# RUN: .ccc ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) : \ +# RUN: { \ +# RUN: *(.ccc) \ +# RUN: } \ +# RUN: .ddd 0x5001 : \ +# RUN: { \ +# RUN: *(.ddd) \ +# RUN: } \ +# RUN: }" > %t.script +# RUN: ld.lld %t --script %t.script -o %tout +# RUN: llvm-readobj -s %tout | FileCheck %s + +## Check: +## 1) Simple constant as address. +## 2) That something that contains ":" character, like ternary +## operator works as expression. +## 3) That complex expressions work. +## 4) That section alignment still applied to explicitly specified address. + +#CHECK:Sections [ +#CHECK: Section { +#CHECK: Index: 0 +#CHECK: Name: +#CHECK: Type: SHT_NULL +#CHECK: Flags [ +#CHECK: ] +#CHECK: Address: 0x0 +#CHECK: Offset: 0x0 +#CHECK: Size: 0 +#CHECK: Link: 0 +#CHECK: Info: 0 +#CHECK: AddressAlignment: 0 +#CHECK: EntrySize: 0 +#CHECK: } +#CHECK: Section { +#CHECK: Index: 1 +#CHECK: Name: .aaa +#CHECK: Type: SHT_PROGBITS +#CHECK: Flags [ +#CHECK: SHF_ALLOC +#CHECK: ] +#CHECK: Address: 0x2000 +#CHECK: Offset: 0x1000 +#CHECK: Size: 8 +#CHECK: Link: 0 +#CHECK: Info: 0 +#CHECK: AddressAlignment: 1 +#CHECK: EntrySize: 0 +#CHECK: } +#CHECK: Section { +#CHECK: Index: 2 +#CHECK: Name: .bbb +#CHECK: Type: SHT_PROGBITS +#CHECK: Flags [ +#CHECK: SHF_ALLOC +#CHECK: ] +#CHECK: Address: 0x3000 +#CHECK: Offset: 0x2000 +#CHECK: Size: 8 +#CHECK: Link: 0 +#CHECK: Info: 0 +#CHECK: AddressAlignment: 1 +#CHECK: EntrySize: 0 +#CHECK: } +#CHECK: Section { +#CHECK: Index: 3 +#CHECK: Name: .ccc +#CHECK: Type: SHT_PROGBITS +#CHECK: Flags [ +#CHECK: SHF_ALLOC +#CHECK: ] +#CHECK: Address: 0x4008 +#CHECK: Offset: 0x3008 +#CHECK: Size: 8 +#CHECK: Link: 0 +#CHECK: Info: 0 +#CHECK: AddressAlignment: 1 +#CHECK: EntrySize: 0 +#CHECK: } +#CHECK: Section { +#CHECK: Index: 4 +#CHECK: Name: .ddd +#CHECK: Type: SHT_PROGBITS +#CHECK: Flags [ +#CHECK: SHF_ALLOC +#CHECK: ] +#CHECK: Address: 0x5010 +#CHECK: Offset: 0x4010 +#CHECK: Size: 8 +#CHECK: Link: 0 +#CHECK: Info: 0 +#CHECK: AddressAlignment: 16 +#CHECK: EntrySize: 0 +#CHECK: } + +.globl _start +_start: +nop + +.section .aaa, "a" +.quad 0 + +.section .bbb, "a" +.quad 0 + +.section .ccc, "a" +.quad 0 + +.section .ddd, "a" +.align 16 +.quad 0 diff --git a/test/ELF/linkerscript/page-size-align.s b/test/ELF/linkerscript/page-size-align.s new file mode 100644 index 0000000000000..771bb13a8e6d5 --- /dev/null +++ b/test/ELF/linkerscript/page-size-align.s @@ -0,0 +1,22 @@ +# 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.s b/test/ELF/linkerscript/page-size.s new file mode 100644 index 0000000000000..3d97816a68ee9 --- /dev/null +++ b/test/ELF/linkerscript/page-size.s @@ -0,0 +1,68 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: ld.lld -z max-page-size=0x4000 %t -o %t2 +# RUN: llvm-readobj -program-headers %t2 | FileCheck %s + +# CHECK: ProgramHeaders [ +# CHECK: ProgramHeader { +# CHECK: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x200000 +# CHECK-NEXT: PhysicalAddress: 0x200000 +# CHECK-NEXT: FileSize: 344 +# CHECK-NEXT: MemSize: 344 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 16384 +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x4000 +# CHECK-NEXT: VirtualAddress: 0x204000 +# CHECK-NEXT: PhysicalAddress: 0x204000 +# CHECK-NEXT: FileSize: 1 +# CHECK-NEXT: MemSize: 1 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_X +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 16384 +# CHECK-NEXT: } +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD +# CHECK-NEXT: Offset: 0x8000 +# CHECK-NEXT: VirtualAddress: 0x208000 +# CHECK-NEXT: PhysicalAddress: 0x208000 +# CHECK-NEXT: FileSize: 8 +# CHECK-NEXT: MemSize: 8 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_W +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 16384 +# CHECK-NEXT: } + +# RUN: echo "SECTIONS { \ +# RUN: symbol = CONSTANT(MAXPAGESIZE); \ +# RUN: }" > %t.script +# RUN: ld.lld -z max-page-size=0x4000 -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck -check-prefix CHECK-SCRIPT %s + +# CHECK-SCRIPT: 0000000000004000 *ABS* 00000000 symbol + +# RUN: not ld.lld -z max-page-size=0x1001 -o %t1 --script %t.script %t 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR1 %s +# ERR1: max-page-size: value isn't a power of 2 + +# RUN: not ld.lld -z max-page-size=-0x1000 -o %t1 --script %t.script %t 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR2 %s +# ERR2: invalid max-page-size: -0x1000 + +.global _start +_start: + nop + +.section .a, "aw" +.quad 0 diff --git a/test/ELF/linkerscript-phdr-check.s b/test/ELF/linkerscript/phdr-check.s index c7229ed3312c6..c7229ed3312c6 100644 --- a/test/ELF/linkerscript-phdr-check.s +++ b/test/ELF/linkerscript/phdr-check.s diff --git a/test/ELF/linkerscript/phdrs-flags.s b/test/ELF/linkerscript/phdrs-flags.s new file mode 100644 index 0000000000000..3cb6432db09ca --- /dev/null +++ b/test/ELF/linkerscript/phdrs-flags.s @@ -0,0 +1,58 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS FLAGS (1 | 1 + 0x1);} \ +# RUN: SECTIONS { \ +# RUN: . = 0x10000200; \ +# RUN: .text : {*(.text*)} :all \ +# RUN: .foo : {*(.foo.*)} :all \ +# RUN: .data : {*(.data.*)} :all}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-readobj -program-headers %t1 | FileCheck %s + +# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS FLAGS (0x1);} \ +# RUN: SECTIONS { \ +# RUN: . = 0x10000200; \ +# RUN: .text : {*(.text*)} :all \ +# RUN: .foo : {*(.foo.*)} \ +# RUN: .data : {*(.data.*)} }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-readobj -program-headers %t1 | FileCheck --check-prefix=DEFHDR %s + +# CHECK: ProgramHeaders [ +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD (0x1) +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x10000000 +# CHECK-NEXT: PhysicalAddress: 0x10000000 +# CHECK-NEXT: FileSize: 521 +# CHECK-NEXT: MemSize: 521 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_W (0x2) +# CHECK-NEXT: PF_X (0x1) +# CHECK-NEXT: ] + +# DEFHDR: ProgramHeaders [ +# DEFHDR-NEXT: ProgramHeader { +# DEFHDR-NEXT: Type: PT_LOAD (0x1) +# DEFHDR-NEXT: Offset: 0x0 +# DEFHDR-NEXT: VirtualAddress: 0x10000000 +# DEFHDR-NEXT: PhysicalAddress: 0x10000000 +# DEFHDR-NEXT: FileSize: 521 +# DEFHDR-NEXT: MemSize: 521 +# DEFHDR-NEXT: Flags [ (0x1) +# DEFHDR-NEXT: PF_X (0x1) +# DEFHDR-NEXT: ] +# DEFHDR-NEXT: Alignment: 4096 +# DEFHDR-NEXT: } + +.global _start +_start: + nop + +.section .foo.1,"a" +foo1: + .long 0 + +.section .foo.2,"aw" +foo2: + .long 0 diff --git a/test/ELF/linkerscript/phdrs.s b/test/ELF/linkerscript/phdrs.s new file mode 100644 index 0000000000000..a7476e8023411 --- /dev/null +++ b/test/ELF/linkerscript/phdrs.s @@ -0,0 +1,143 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS ;} \ +# RUN: SECTIONS { \ +# RUN: . = 0x10000200; \ +# RUN: .text : {*(.text*)} :all \ +# RUN: .foo : {*(.foo.*)} :all \ +# RUN: .data : {*(.data.*)} :all}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-readobj -program-headers %t1 | FileCheck %s + +## Check that program headers are not written, unless we explicitly tell +## lld to do this. +# RUN: echo "PHDRS {all PT_LOAD;} \ +# RUN: SECTIONS { \ +# RUN: . = 0x10000200; \ +# RUN: /DISCARD/ : {*(.text*)} \ +# RUN: .foo : {*(.foo.*)} :all \ +# RUN: }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-readobj -program-headers %t1 | FileCheck --check-prefix=NOPHDR %s + +## Check the AT(expr) +# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS AT(0x500 + 0x500) ;} \ +# RUN: SECTIONS { \ +# RUN: . = 0x10000200; \ +# RUN: .text : {*(.text*)} :all \ +# RUN: .foo : {*(.foo.*)} :all \ +# RUN: .data : {*(.data.*)} :all}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-readobj -program-headers %t1 | FileCheck --check-prefix=AT %s + +# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS ;} \ +# RUN: SECTIONS { \ +# RUN: . = 0x10000200; \ +# RUN: .text : {*(.text*)} :all \ +# RUN: .foo : {*(.foo.*)} \ +# RUN: .data : {*(.data.*)} }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-readobj -program-headers %t1 | FileCheck --check-prefix=DEFHDR %s + +## Check that error is reported when trying to use phdr which is not listed +## inside PHDRS {} block +## TODO: If script doesn't contain PHDRS {} block then default phdr is always +## created and error is not reported. +# RUN: echo "PHDRS { all PT_LOAD; } \ +# RUN: SECTIONS { .baz : {*(.foo.*)} :bar }" > %t.script +# RUN: not ld.lld -o %t1 --script %t.script %t 2>&1 | FileCheck --check-prefix=BADHDR %s + +# CHECK: ProgramHeaders [ +# CHECK-NEXT: ProgramHeader { +# CHECK-NEXT: Type: PT_LOAD (0x1) +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x10000000 +# CHECK-NEXT: PhysicalAddress: 0x10000000 +# CHECK-NEXT: FileSize: 521 +# CHECK-NEXT: MemSize: 521 +# CHECK-NEXT: Flags [ (0x7) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: PF_W (0x2) +# CHECK-NEXT: PF_X (0x1) +# CHECK-NEXT: ] + +# NOPHDR: ProgramHeaders [ +# NOPHDR-NEXT: ProgramHeader { +# NOPHDR-NEXT: Type: PT_LOAD (0x1) +# NOPHDR-NEXT: Offset: 0x200 +# NOPHDR-NEXT: VirtualAddress: 0x10000200 +# NOPHDR-NEXT: PhysicalAddress: 0x10000200 +# NOPHDR-NEXT: FileSize: 8 +# NOPHDR-NEXT: MemSize: 8 +# NOPHDR-NEXT: Flags [ (0x6) +# NOPHDR-NEXT: PF_R (0x4) +# NOPHDR-NEXT: PF_W (0x2) +# NOPHDR-NEXT: ] +# NOPHDR-NEXT: Alignment: 4096 +# NOPHDR-NEXT: } +# NOPHDR-NEXT: ] + +# AT: ProgramHeaders [ +# AT-NEXT: ProgramHeader { +# AT-NEXT: Type: PT_LOAD (0x1) +# AT-NEXT: Offset: 0x0 +# AT-NEXT: VirtualAddress: 0x10000000 +# AT-NEXT: PhysicalAddress: 0xA00 +# AT-NEXT: FileSize: 521 +# AT-NEXT: MemSize: 521 +# AT-NEXT: Flags [ (0x7) +# AT-NEXT: PF_R (0x4) +# AT-NEXT: PF_W (0x2) +# AT-NEXT: PF_X (0x1) +# AT-NEXT: ] + +## Check the numetic values for PHDRS. +# RUN: echo "PHDRS {text PT_LOAD FILEHDR PHDRS; foo 0x11223344; } \ +# RUN: SECTIONS { . = SIZEOF_HEADERS; .foo : { *(.*) } : text : foo}" > %t1.script +# RUN: ld.lld -o %t2 --script %t1.script %t +# RUN: llvm-readobj -program-headers %t2 | FileCheck --check-prefix=INT-PHDRS %s + +# INT-PHDRS: ProgramHeaders [ +# INT-PHDRS: ProgramHeader { +# INT-PHDRS: Type: (0x11223344) +# INT-PHDRS-NEXT: Offset: 0xB0 +# INT-PHDRS-NEXT: VirtualAddress: 0xB0 +# INT-PHDRS-NEXT: PhysicalAddress: 0xB0 +# INT-PHDRS-NEXT: FileSize: +# INT-PHDRS-NEXT: MemSize: +# INT-PHDRS-NEXT: Flags [ +# INT-PHDRS-NEXT: PF_R +# INT-PHDRS-NEXT: PF_W +# INT-PHDRS-NEXT: PF_X +# INT-PHDRS-NEXT: ] +# INT-PHDRS-NEXT: Alignment: +# INT-PHDRS-NEXT: } +# INT-PHDRS-NEXT: ] + +# DEFHDR: ProgramHeaders [ +# DEFHDR-NEXT: ProgramHeader { +# DEFHDR-NEXT: Type: PT_LOAD (0x1) +# DEFHDR-NEXT: Offset: 0x0 +# DEFHDR-NEXT: VirtualAddress: 0x10000000 +# DEFHDR-NEXT: PhysicalAddress: 0x10000000 +# DEFHDR-NEXT: FileSize: 521 +# DEFHDR-NEXT: MemSize: 521 +# DEFHDR-NEXT: Flags [ (0x7) +# DEFHDR-NEXT: PF_R (0x4) +# DEFHDR-NEXT: PF_W (0x2) +# DEFHDR-NEXT: PF_X (0x1) +# DEFHDR-NEXT: ] + +# BADHDR: {{.*}}.script:1: section header 'bar' is not listed in PHDRS + +.global _start +_start: + nop + +.section .foo.1,"a" +foo1: + .long 0 + +.section .foo.2,"aw" +foo2: + .long 0 diff --git a/test/ELF/linkerscript/repsection-symbol.s b/test/ELF/linkerscript/repsection-symbol.s new file mode 100644 index 0000000000000..6786ac47255ce --- /dev/null +++ b/test/ELF/linkerscript/repsection-symbol.s @@ -0,0 +1,28 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: echo "SECTIONS { \ +# RUN: . = SIZEOF_HEADERS; \ +# RUN: .text : { *(.text) } \ +# RUN: .foo : {foo1 = .; *(.foo.*) foo2 = .; *(.bar) foo3 = .;} \ +# RUN: }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t -shared +# RUN: llvm-readobj -t %t1 | FileCheck %s + +# CHECK: Name: foo1 +# CHECK-NEXT: Value: 0x288 + +# CHECK: Name: foo2 +# CHECK-NEXT: Value: 0x290 + +# CHECK: Name: foo3 +# CHECK-NEXT: Value: 0x294 + +.section .foo.1,"a" + .long 1 + +.section .foo.2,"aw" + .long 2 + + .section .bar,"aw" + .long 3 diff --git a/test/ELF/linkerscript-repsection-va.s b/test/ELF/linkerscript/repsection-va.s index 4feeaa0e1c383..8a50fc0998f9e 100644 --- a/test/ELF/linkerscript-repsection-va.s +++ b/test/ELF/linkerscript/repsection-va.s @@ -6,10 +6,10 @@ # 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 00000004 0000000000000158 DATA -# CHECK-NEXT: 2 .foo 00000004 000000000000015c DATA -# CHECK-NEXT: 3 .text 00000001 0000000000000160 TEXT DATA +# CHECK-NOT: .foo +# CHECK: .foo 00000008 {{.*}} DATA +# CHECK-NOT: .foo + .global _start _start: diff --git a/test/ELF/linkerscript/rosegment.s b/test/ELF/linkerscript/rosegment.s new file mode 100644 index 0000000000000..3201b8bda9fb8 --- /dev/null +++ b/test/ELF/linkerscript/rosegment.s @@ -0,0 +1,24 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -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: llvm-readobj -l %t1 | FileCheck %s + +# CHECK-NOT: Type: PT_LOAD + +# CHECK: Type: PT_LOAD +# CHECK: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_X +# CHECK-NEXT: ] + +# CHECK: Type: PT_LOAD +# CHECK: Flags [ +# CHECK-NEXT: PF_R +# CHECK-NEXT: PF_W +# CHECK-NEXT: ] + +# CHECK-NOT: Type: PT_LOAD diff --git a/test/ELF/linkerscript2.s b/test/ELF/linkerscript/searchdir.s index 6ecd9e7ea9756..9fc1a6a49a904 100644 --- a/test/ELF/linkerscript2.s +++ b/test/ELF/linkerscript/searchdir.s @@ -1,10 +1,5 @@ -# There is some bad quoting interaction between lit's internal shell, which is -# implemented in Python, and the Cygwin implementations of the Unix utilities. -# Avoid running these tests on Windows for now by requiring a real shell. - -# REQUIRES: shell - # REQUIRES: x86 + # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %t # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd \ # RUN: %p/Inputs/libsearch-dyn.s -o %tdyn.o diff --git a/test/ELF/linkerscript/sections-constraint.s b/test/ELF/linkerscript/sections-constraint.s new file mode 100644 index 0000000000000..4d95ec18336cc --- /dev/null +++ b/test/ELF/linkerscript/sections-constraint.s @@ -0,0 +1,46 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: .writable : ONLY_IF_RW { *(.writable) } \ +# RUN: .readable : ONLY_IF_RO { *(.readable) }}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -section-headers %t1 | \ +# RUN: FileCheck -check-prefix=BASE %s +# BASE: Sections: +# BASE-NEXT: Idx Name Size +# BASE-NEXT: 0 00000000 +# BASE: .writable 00000004 +# BASE: .readable 00000004 + +# RUN: echo "SECTIONS { \ +# RUN: .foo : ONLY_IF_RO { *(.foo.*) } \ +# RUN: .writable : ONLY_IF_RW { *(.writable) } \ +# RUN: .readable : ONLY_IF_RO { *(.readable) }}" > %t2.script +# RUN: ld.lld -o %t2 --script %t2.script %t +# RUN: llvm-objdump -section-headers %t2 | \ +# RUN: FileCheck -check-prefix=NO1 %s +# NO1: Sections: +# NO1-NEXT: Idx Name Size +# NO1-NEXT: 0 00000000 +# NO1: .writable 00000004 +# NO1: .foo.2 00000004 +# NO1: .readable 00000004 +# NO1: .foo.1 00000004 + +.global _start +_start: + nop + +.section .writable, "aw" +writable: + .long 1 + +.section .readable, "a" +readable: + .long 2 + +.section .foo.1, "awx" + .long 0 + +.section .foo.2, "aw" + .long 0 diff --git a/test/ELF/linkerscript/sections-constraint2.s b/test/ELF/linkerscript/sections-constraint2.s new file mode 100644 index 0000000000000..e726365582d8b --- /dev/null +++ b/test/ELF/linkerscript/sections-constraint2.s @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { zed : ONLY_IF_RO { *(foo) *(bar) } }" > %t.script +# RUN: ld.lld -T %t.script %t.o -o %t.so -shared +# RUN: llvm-readobj -s %t.so | FileCheck %s + +# CHECK: Sections [ +# CHECK-NOT: zed + +.section foo,"aw" +.quad 1 + +.section bar, "a" +.quad 2 diff --git a/test/ELF/linkerscript/sections-constraint3.s b/test/ELF/linkerscript/sections-constraint3.s new file mode 100644 index 0000000000000..259f11e91dd18 --- /dev/null +++ b/test/ELF/linkerscript/sections-constraint3.s @@ -0,0 +1,11 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "SECTIONS { zed : ONLY_IF_RO { abc = 1; *(foo) } }" > %t.script +# RUN: ld.lld -T %t.script %t.o -o %t.so -shared +# RUN: llvm-readobj -t %t.so | FileCheck %s + +# CHECK: Symbols [ +# CHECK-NOT: abc + +.section foo,"aw" +.quad 1 diff --git a/test/ELF/linkerscript/sections-constraint4.s b/test/ELF/linkerscript/sections-constraint4.s new file mode 100644 index 0000000000000..6c2d4c8e1ee43 --- /dev/null +++ b/test/ELF/linkerscript/sections-constraint4.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "SECTIONS { \ +# RUN: .foo : ONLY_IF_RO { *(.foo) } \ +# RUN: .bar : {bar1 = .; *(.bar) } }" > %t1.script +# RUN: ld.lld -o %t1 --script %t1.script %t +# RUN: llvm-readobj -t %t1 | FileCheck %s + +# CHECK: Name: bar1 + +.global _start +_start: + nop + +.section .bar, "aw" +bar: + .long 1 + +.section .foo, "aw" + .long 0 diff --git a/test/ELF/linkerscript/sections-constraint5.s b/test/ELF/linkerscript/sections-constraint5.s new file mode 100644 index 0000000000000..ea14aad5247ef --- /dev/null +++ b/test/ELF/linkerscript/sections-constraint5.s @@ -0,0 +1,32 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { \ +# RUN: bar : ONLY_IF_RO { sym1 = .; *(foo*) } \ +# RUN: bar : ONLY_IF_RW { sym2 = .; *(foo*) } \ +# RUN: }" > %t.script + +# RUN: ld.lld -o %t -T %t.script %t.o +# RUN: llvm-readobj -s -t %t | FileCheck %s + +# CHECK: Sections [ +# CHECK: Name: bar +# 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: 2 + +# CHECK: Symbols [ +# CHECK-NOT: sym1 +# CHECK: sym2 +# CHECK-NOT: sym1 + +.section foo1,"a" +.byte 0 + +.section foo2,"aw" +.byte 0 + diff --git a/test/ELF/linkerscript-sections-keep.s b/test/ELF/linkerscript/sections-keep.s index fae6383ca499b..feb0baca9c3d9 100644 --- a/test/ELF/linkerscript-sections-keep.s +++ b/test/ELF/linkerscript/sections-keep.s @@ -1,5 +1,6 @@ # 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 ## First check that section "keep" is garbage collected without using KEEP # RUN: echo "SECTIONS { \ @@ -10,10 +11,10 @@ # RUN: llvm-objdump -section-headers %t1 | \ # RUN: FileCheck -check-prefix=SECGC %s # SECGC: Sections: -# SECGC-NEXT: Idx Name Size Address Type -# SECGC-NEXT: 0 00000000 0000000000000000 -# SECGC-NEXT: 1 .text 00000007 0000000000000158 TEXT DATA -# SECGC-NEXT: 2 .temp 00000004 000000000000015f DATA +# SECGC-NEXT: Idx Name Size +# SECGC-NEXT: 0 00000000 +# SECGC-NEXT: 1 .text 00000007 +# SECGC-NEXT: 2 .temp 00000004 ## Now apply KEEP command to preserve the section. # RUN: echo "SECTIONS { \ @@ -24,48 +25,62 @@ # RUN: llvm-objdump -section-headers %t1 | \ # RUN: FileCheck -check-prefix=SECNOGC %s # SECNOGC: Sections: -# SECNOGC-NEXT: Idx Name Size Address Type -# SECNOGC-NEXT: 0 00000000 0000000000000000 -# SECNOGC-NEXT: 1 .text 00000007 0000000000000158 TEXT DATA -# SECNOGC-NEXT: 2 .keep 00000004 000000000000015f DATA -# SECNOGC-NEXT: 3 .temp 00000004 0000000000000163 DATA +# SECNOGC-NEXT: Idx Name Size +# SECNOGC-NEXT: 0 00000000 +# SECNOGC-NEXT: 1 .text 00000007 +# SECNOGC-NEXT: 2 .keep 00000004 +# SECNOGC-NEXT: 3 .temp 00000004 ## A section name matches two entries in the SECTIONS directive. The ## first one doesn't have KEEP, the second one does. If section that have ## KEEP is the first in order then section is NOT collected. # RUN: echo "SECTIONS { \ +# 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 # MIXED1: Sections: -# MIXED1-NEXT: Idx Name Size Address Type -# MIXED1-NEXT: 0 00000000 0000000000000000 -# MIXED1-NEXT: 1 .keep 00000004 0000000000000120 DATA -# MIXED1-NEXT: 2 .temp 00000004 0000000000000124 DATA -# MIXED1-NEXT: 3 .text 00000007 0000000000000128 TEXT DATA -# MIXED1-NEXT: 4 .symtab 00000060 0000000000000000 -# MIXED1-NEXT: 5 .shstrtab 0000002d 0000000000000000 -# MIXED1-NEXT: 6 .strtab 00000012 0000000000000000 +# 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: 4 .comment 00000008 0000000000000000 +# MIXED1-NEXT: 5 .symtab 00000060 0000000000000000 +# MIXED1-NEXT: 6 .shstrtab 00000036 0000000000000000 +# MIXED1-NEXT: 7 .strtab 00000012 0000000000000000 ## The same, but now section without KEEP is at first place. ## gold and bfd linkers disagree here. gold collects .keep while ## bfd keeps it. Our current behavior is compatible with bfd although ## we can choose either way. # RUN: echo "SECTIONS { \ +# 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 # MIXED2: Sections: -# MIXED2-NEXT: Idx Name Size Address Type -# MIXED2-NEXT: 0 00000000 0000000000000000 -# MIXED2-NEXT: 1 .nokeep 00000004 0000000000000120 DATA -# MIXED2-NEXT: 2 .temp 00000004 0000000000000124 DATA -# MIXED2-NEXT: 3 .text 00000007 0000000000000128 TEXT DATA -# MIXED2-NEXT: 4 .symtab 00000060 0000000000000000 -# MIXED2-NEXT: 5 .shstrtab 0000002f 0000000000000000 -# MIXED2-NEXT: 6 .strtab 00000012 0000000000000000 +# 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: 4 .comment 00000008 0000000000000000 +# MIXED2-NEXT: 5 .symtab 00000060 0000000000000000 +# MIXED2-NEXT: 6 .shstrtab 00000038 0000000000000000 +# MIXED2-NEXT: 7 .strtab 00000012 0000000000000000 + +# Check file pattern for kept sections. +# RUN: echo "SECTIONS { \ +# RUN: . = SIZEOF_HEADERS; \ +# RUN: .keep : { KEEP(*2.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 +# FILEMATCH: Contents of section .keep: +# FILEMATCH-NEXT: 00e8 41414141 AAAA .global _start _start: diff --git a/test/ELF/linkerscript/sections-padding.s b/test/ELF/linkerscript/sections-padding.s new file mode 100644 index 0000000000000..51d3a88fadf66 --- /dev/null +++ b/test/ELF/linkerscript/sections-padding.s @@ -0,0 +1,49 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +## Check that padding value works: +# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x1122 }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES %s +# YES: 66001122 00001122 00001122 00001122 + +## Confirming that address was correct: +# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x99887766 }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES2 %s +# YES2: 66887766 99887766 99887766 99887766 + +## Default padding value is 0x00: +# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=NO %s +# NO: 66000000 00000000 00000000 00000000 + +## Decimal value. +# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =777 }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=DEC %s +# DEC: 66000309 00000309 00000309 00000309 + +## Invalid hex value: +# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x99XX }" > %t.script +# RUN: not ld.lld -o %t.out --script %t.script %t 2>&1 \ +# RUN: | FileCheck --check-prefix=ERR2 %s +# ERR2: invalid filler expression: 0x99XX + +## Check case with space between '=' and expression: +# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } = 0x1122 }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES %s + +.section .mysec.1,"a" +.align 16 +.byte 0x66 + +.section .mysec.2,"a" +.align 16 +.byte 0x66 + +.globl _start +_start: + nop diff --git a/test/ELF/linkerscript/sections-sort.s b/test/ELF/linkerscript/sections-sort.s new file mode 100644 index 0000000000000..cf1fd3e578272 --- /dev/null +++ b/test/ELF/linkerscript/sections-sort.s @@ -0,0 +1,30 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.text) } \ +# RUN: foo : { *(foo) } \ +# RUN: } " > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o -shared +# RUN: llvm-objdump --section-headers %t | FileCheck %s + +# Test the section order. This is a case where at least with libstdc++'s +# stable_sort we used to get a different result. + +nop + +.section foo, "a" +.byte 0 + +# CHECK: Id +# 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: 6 .dynamic +# CHECK-NEXT: 7 .comment +# CHECK-NEXT: 8 .symtab +# CHECK-NEXT: 9 .shstrtab +# CHECK-NEXT: 10 .strtab diff --git a/test/ELF/linkerscript-sections.s b/test/ELF/linkerscript/sections.s index b68dac765a777..416e77346a59d 100644 --- a/test/ELF/linkerscript-sections.s +++ b/test/ELF/linkerscript/sections.s @@ -21,11 +21,13 @@ # SEC-DEFAULT: 3 other 00000003 {{[0-9a-f]*}} DATA # SEC-DEFAULT: 4 .bss 00000002 {{[0-9a-f]*}} BSS # SEC-DEFAULT: 5 .shstrtab 00000002 {{[0-9a-f]*}} -# SEC-DEFAULT: 6 .symtab 00000030 {{[0-9a-f]*}} -# SEC-DEFAULT: 7 .shstrtab 00000032 {{[0-9a-f]*}} -# SEC-DEFAULT: 8 .strtab 00000008 {{[0-9a-f]*}} +# SEC-DEFAULT: 6 .comment 00000008 {{[0-9a-f]*}} +# SEC-DEFAULT: 7 .symtab 00000030 {{[0-9a-f]*}} +# SEC-DEFAULT: 8 .shstrtab 0000003b {{[0-9a-f]*}} +# SEC-DEFAULT: 9 .strtab 00000008 {{[0-9a-f]*}} -# Sections are put in order specified in linker script. +# Sections are put in order specified in linker script, other than alloc +# sections going first. # RUN: echo "SECTIONS { \ # RUN: .bss : { *(.bss) } \ # RUN: other : { *(other) } \ @@ -42,7 +44,7 @@ # SEC-ORDER: 1 .bss 00000002 {{[0-9a-f]*}} BSS # SEC-ORDER: 2 other 00000003 {{[0-9a-f]*}} DATA # SEC-ORDER: 3 .shstrtab 00000002 {{[0-9a-f]*}} -# SEC-ORDER: 4 .shstrtab 00000032 {{[0-9a-f]*}} +# SEC-ORDER: 4 .shstrtab 0000003b {{[0-9a-f]*}} # SEC-ORDER: 5 .symtab 00000030 {{[0-9a-f]*}} # SEC-ORDER: 6 .strtab 00000008 {{[0-9a-f]*}} # SEC-ORDER: 7 .data 00000020 {{[0-9a-f]*}} DATA @@ -62,9 +64,10 @@ # SEC-SWAP-NAMES: 3 other 00000003 {{[0-9a-f]*}} DATA # SEC-SWAP-NAMES: 4 .bss 00000002 {{[0-9a-f]*}} BSS # SEC-SWAP-NAMES: 5 .shstrtab 00000002 {{[0-9a-f]*}} -# SEC-SWAP-NAMES: 6 .symtab 00000030 {{[0-9a-f]*}} -# SEC-SWAP-NAMES: 7 .shstrtab 00000032 {{[0-9a-f]*}} -# SEC-SWAP-NAMES: 8 .strtab 00000008 {{[0-9a-f]*}} +# SEC-SWAP-NAMES: 6 .comment 00000008 {{[0-9a-f]*}} +# SEC-SWAP-NAMES: 7 .symtab 00000030 {{[0-9a-f]*}} +# SEC-SWAP-NAMES: 8 .shstrtab 0000003b {{[0-9a-f]*}} +# SEC-SWAP-NAMES: 9 .strtab 00000008 {{[0-9a-f]*}} # .shstrtab from the input object file is discarded. # RUN: echo "SECTIONS { \ @@ -78,9 +81,10 @@ # SEC-DISCARD: 2 .data 00000020 {{[0-9a-f]*}} DATA # SEC-DISCARD: 3 other 00000003 {{[0-9a-f]*}} DATA # SEC-DISCARD: 4 .bss 00000002 {{[0-9a-f]*}} BSS -# SEC-DISCARD: 5 .symtab 00000030 {{[0-9a-f]*}} -# SEC-DISCARD: 6 .shstrtab 00000032 {{[0-9a-f]*}} -# SEC-DISCARD: 7 .strtab 00000008 {{[0-9a-f]*}} +# SEC-DISCARD: 5 .comment 00000008 {{[0-9a-f]*}} +# SEC-DISCARD: 6 .symtab 00000030 {{[0-9a-f]*}} +# SEC-DISCARD: 7 .shstrtab 0000003b {{[0-9a-f]*}} +# SEC-DISCARD: 8 .strtab 00000008 {{[0-9a-f]*}} # Multiple SECTIONS command specifying additional input section descriptions # for the same output section description - input sections are merged into @@ -99,9 +103,10 @@ # SEC-MULTI: 2 .data 00000023 {{[0-9a-f]*}} DATA # SEC-MULTI: 3 .bss 00000002 {{[0-9a-f]*}} BSS # SEC-MULTI: 4 .shstrtab 00000002 {{[0-9a-f]*}} -# SEC-MULTI: 5 .symtab 00000030 {{[0-9a-f]*}} -# SEC-MULTI: 6 .shstrtab 0000002c {{[0-9a-f]*}} -# SEC-MULTI: 7 .strtab 00000008 {{[0-9a-f]*}} +# SEC-MULTI: 5 .comment 00000008 {{[0-9a-f]*}} +# SEC-MULTI: 6 .symtab 00000030 {{[0-9a-f]*}} +# SEC-MULTI: 7 .shstrtab 00000035 {{[0-9a-f]*}} +# SEC-MULTI: 8 .strtab 00000008 {{[0-9a-f]*}} .globl _start _start: diff --git a/test/ELF/linkerscript/segment-start.s b/test/ELF/linkerscript/segment-start.s new file mode 100644 index 0000000000000..e46c398f63f95 --- /dev/null +++ b/test/ELF/linkerscript/segment-start.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 %S/Inputs/segment-start.script -shared -o %t.so +// RUN: llvm-readobj --dyn-symbols %t.so | FileCheck %s + +// CHECK: Name: foobar1 +// CHECK-NEXT: Value: 0x8001 + +// CHECK: Name: foobar2 +// CHECK-NEXT: Value: 0x8002 + +// CHECK: Name: foobar3 +// CHECK-NEXT: Value: 0x8003 + +// CHECK: Name: foobar4 +// CHECK-NEXT: Value: 0x8004 + +.data +.quad foobar1 +.quad foobar2 +.quad foobar3 +.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: | FileCheck --check-prefix=ERR %s +// ERR: {{.*}}.script:1: symbol not found: foo diff --git a/test/ELF/linkerscript/sizeof.s b/test/ELF/linkerscript/sizeof.s new file mode 100644 index 0000000000000..4618f79d3db6a --- /dev/null +++ b/test/ELF/linkerscript/sizeof.s @@ -0,0 +1,53 @@ +# 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 = SIZEOF(.aaa); \ +# RUN: _bbb = SIZEOF(.bbb); \ +# RUN: _ccc = SIZEOF(.ccc); \ +# RUN: }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t -section-headers %t1 | FileCheck %s +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size +# CHECK-NEXT: 0 00000000 +# CHECK-NEXT: 1 .aaa 00000008 +# CHECK-NEXT: 2 .bbb 00000010 +# CHECK-NEXT: 3 .ccc 00000018 +# CHECK: SYMBOL TABLE: +# CHECK-NEXT: 0000000000000000 *UND* 00000000 +# CHECK-NEXT: .text 00000000 _start +# CHECK-NEXT: 0000000000000008 *ABS* 00000000 _aaa +# CHECK-NEXT: 0000000000000010 *ABS* 00000000 _bbb +# CHECK-NEXT: 0000000000000018 *ABS* 00000000 _ccc + +## SIZEOF(.nonexistent_section) should return 0. +# RUN: echo "SECTIONS { \ +# RUN: .aaa : { *(.aaa) } \ +# RUN: .bbb : { *(.bbb) } \ +# RUN: .ccc : { *(.ccc) } \ +# RUN: _aaa = SIZEOF(.foo); \ +# RUN: }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t -section-headers %t1 | FileCheck -check-prefix=CHECK2 %s + +# CHECK2: 0000000000000000 *ABS* 00000000 _aaa + +.global _start +_start: + nop + +.section .aaa,"a" + .quad 0 + +.section .bbb,"a" + .quad 0 + .quad 0 + +.section .ccc,"a" + .quad 0 + .quad 0 + .quad 0 diff --git a/test/ELF/linkerscript/sizeofheaders.s b/test/ELF/linkerscript/sizeofheaders.s new file mode 100644 index 0000000000000..3cc70747280c9 --- /dev/null +++ b/test/ELF/linkerscript/sizeofheaders.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo " SECTIONS { \ +# RUN: . = SIZEOF_HEADERS; \ +# RUN: _size = SIZEOF_HEADERS; \ +# RUN: .text : {*(.text*)} \ +# RUN: }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck %s + +#CHECK: SYMBOL TABLE: +#CHECK-NEXT: 0000000000000000 *UND* 00000000 +#CHECK-NEXT: 00000000000000e8 .text 00000000 _start +#CHECK-NEXT: 00000000000000e8 *ABS* 00000000 _size + +.global _start +_start: + nop diff --git a/test/ELF/linkerscript/sort-constructors.s b/test/ELF/linkerscript/sort-constructors.s new file mode 100644 index 0000000000000..a0c23af6de798 --- /dev/null +++ b/test/ELF/linkerscript/sort-constructors.s @@ -0,0 +1,5 @@ +# 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-init.s b/test/ELF/linkerscript/sort-init.s new file mode 100644 index 0000000000000..894b8ae882b7a --- /dev/null +++ b/test/ELF/linkerscript/sort-init.s @@ -0,0 +1,24 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: echo "SECTIONS { .init_array : { *(SORT_BY_INIT_PRIORITY(.init_array.*)) } }" > %t1.script +# RUN: ld.lld --script %t1.script %t1.o -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck %s + +# CHECK: Contents of section .init_array: +# CHECK-NEXT: 03020000 00000000 010405 + +.globl _start +_start: + nop + +.section .init_array, "aw", @init_array + .align 8 + .byte 1 +.section .init_array.100, "aw", @init_array + .long 2 +.section .init_array.5, "aw", @init_array + .byte 3 +.section .init_array, "aw", @init_array + .byte 4 +.section .init_array, "aw", @init_array + .byte 5 diff --git a/test/ELF/linkerscript/sort-nested.s b/test/ELF/linkerscript/sort-nested.s new file mode 100644 index 0000000000000..fb1d1a3dd0708 --- /dev/null +++ b/test/ELF/linkerscript/sort-nested.s @@ -0,0 +1,50 @@ +# 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/sort-nested.s -o %t2.o + +## Check sorting first by alignment and then by name. +# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.aaa.*))) } }" > %t1.script +# RUN: ld.lld -o %t1 --script %t1.script %t1.o %t2.o +# RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=SORTED_AN %s +# SORTED_AN: Contents of section .aaa: +# SORTED_AN-NEXT: 01000000 00000000 00000000 00000000 +# SORTED_AN-NEXT: 11000000 00000000 00000000 00000000 +# SORTED_AN-NEXT: 55000000 00000000 22000000 00000000 +# SORTED_AN-NEXT: 02000000 00000000 + +## Check sorting first by name and then by alignment. +# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_NAME(SORT_BY_ALIGNMENT(.aaa.*))) } }" > %t2.script +# RUN: ld.lld -o %t2 --script %t2.script %t1.o %t2.o +# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SORTED_NA %s +# SORTED_NA: Contents of section .aaa: +# SORTED_NA: 01000000 00000000 00000000 00000000 +# SORTED_NA: 11000000 00000000 22000000 00000000 +# SORTED_NA: 02000000 00000000 00000000 00000000 +# SORTED_NA: 55000000 00000000 + +## If the section sorting command in linker script isn't nested, the +## command line option will make the section sorting command to be treated +## as nested sorting command. +# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_ALIGNMENT(.aaa.*)) } }" > %t3.script +# RUN: ld.lld --sort-section name -o %t3 --script %t3.script %t1.o %t2.o +# RUN: llvm-objdump -s %t3 | FileCheck -check-prefix=SORTED_AN %s +# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_NAME(.aaa.*)) } }" > %t4.script +# RUN: ld.lld --sort-section alignment -o %t4 --script %t4.script %t1.o %t2.o +# RUN: llvm-objdump -s %t4 | FileCheck -check-prefix=SORTED_NA %s + +.global _start +_start: + nop + +.section .aaa.1, "a" +.align 32 +.quad 1 + +.section .aaa.2, "a" +.align 2 +.quad 2 + +.section .aaa.5, "a" +.align 16 +.quad 0x55 diff --git a/test/ELF/linkerscript/sort-non-script.s b/test/ELF/linkerscript/sort-non-script.s new file mode 100644 index 0000000000000..75a2d450adccc --- /dev/null +++ b/test/ELF/linkerscript/sort-non-script.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t + +# RUN: echo "SECTIONS { foo : {*(foo)} }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t -shared +# RUN: llvm-readobj -elf-output-style=GNU -s %t1 | FileCheck %s + +# CHECK: .text {{.*}} AX +# CHECK-NEXT: .dynsym {{.*}} A +# CHECK-NEXT: .hash {{.*}} A +# CHECK-NEXT: .dynstr {{.*}} A +# CHECK-NEXT: .dynamic {{.*}} WA +# CHECK-NEXT: foo {{.*}} WA + +.section foo, "aw" +.byte 0 diff --git a/test/ELF/linkerscript/sort.s b/test/ELF/linkerscript/sort.s new file mode 100644 index 0000000000000..6390ced122892 --- /dev/null +++ b/test/ELF/linkerscript/sort.s @@ -0,0 +1,120 @@ +# 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/sort.s -o %t2.o + +# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t1.script +# RUN: ld.lld -o %t1 --script %t1.script %t2.o %t1.o +# RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=UNSORTED %s +# UNSORTED: Contents of section .aaa: +# UNSORTED-NEXT: 55000000 00000000 00000000 00000000 +# UNSORTED-NEXT: 00000000 00000000 00000000 00000000 +# UNSORTED-NEXT: 11000000 00000000 33000000 00000000 +# UNSORTED-NEXT: 22000000 00000000 44000000 00000000 +# UNSORTED-NEXT: 05000000 00000000 01000000 00000000 +# UNSORTED-NEXT: 03000000 00000000 02000000 00000000 +# UNSORTED-NEXT: 04000000 00000000 + +## Check that SORT works (sorted by name of section). +# RUN: echo "SECTIONS { .aaa : { *(SORT(.aaa.*)) } }" > %t2.script +# RUN: ld.lld -o %t2 --script %t2.script %t2.o %t1.o +# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SORTED_A %s +# SORTED_A: Contents of section .aaa: +# SORTED_A-NEXT: 11000000 00000000 01000000 00000000 +# SORTED_A-NEXT: 22000000 00000000 02000000 00000000 +# SORTED_A-NEXT: 33000000 00000000 03000000 00000000 +# SORTED_A-NEXT: 44000000 00000000 00000000 00000000 +# SORTED_A-NEXT: 04000000 00000000 55000000 00000000 +# SORTED_A-NEXT: 00000000 00000000 00000000 00000000 +# SORTED_A-NEXT: 05000000 00000000 + +## When we switch the order of files, check that sorting by +## section names is stable. +# RUN: echo "SECTIONS { .aaa : { *(SORT(.aaa.*)) } }" > %t3.script +# RUN: ld.lld -o %t3 --script %t3.script %t1.o %t2.o +# RUN: llvm-objdump -s %t3 | FileCheck -check-prefix=SORTED_B %s +# SORTED_B: Contents of section .aaa: +# SORTED_B-NEXT: 01000000 00000000 00000000 00000000 +# SORTED_B-NEXT: 00000000 00000000 00000000 00000000 +# SORTED_B-NEXT: 11000000 00000000 02000000 00000000 +# SORTED_B-NEXT: 22000000 00000000 03000000 00000000 +# SORTED_B-NEXT: 33000000 00000000 00000000 00000000 +# SORTED_B-NEXT: 04000000 00000000 44000000 00000000 +# SORTED_B-NEXT: 05000000 00000000 55000000 00000000 + +## Check that SORT surrounded with KEEP also works. +# RUN: echo "SECTIONS { .aaa : { KEEP (*(SORT(.aaa.*))) } }" > %t3.script +# RUN: ld.lld -o %t3 --script %t3.script %t2.o %t1.o +# RUN: llvm-objdump -s %t3 | FileCheck -check-prefix=SORTED_A %s + +## Check that SORT_BY_NAME works (SORT is alias). +# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_NAME(.aaa.*)) } }" > %t4.script +# RUN: ld.lld -o %t4 --script %t4.script %t2.o %t1.o +# RUN: llvm-objdump -s %t4 | FileCheck -check-prefix=SORTED_A %s + +## Check that sections ordered by alignment. +# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_ALIGNMENT(.aaa.*)) } }" > %t5.script +# RUN: ld.lld -o %t5 --script %t5.script %t1.o %t2.o +# RUN: llvm-objdump -s %t5 | FileCheck -check-prefix=SORTED_ALIGNMENT %s +# SORTED_ALIGNMENT: Contents of section .aaa: +# SORTED_ALIGNMENT-NEXT: 05000000 00000000 00000000 00000000 +# SORTED_ALIGNMENT-NEXT: 00000000 00000000 00000000 00000000 +# SORTED_ALIGNMENT-NEXT: 11000000 00000000 00000000 00000000 +# SORTED_ALIGNMENT-NEXT: 04000000 00000000 00000000 00000000 +# SORTED_ALIGNMENT-NEXT: 22000000 00000000 03000000 00000000 +# SORTED_ALIGNMENT-NEXT: 33000000 00000000 02000000 00000000 +# SORTED_ALIGNMENT-NEXT: 44000000 00000000 01000000 00000000 +# SORTED_ALIGNMENT-NEXT: 55000000 00000000 + +## SORT_NONE itself does not sort anything. +# RUN: echo "SECTIONS { .aaa : { *(SORT_NONE(.aaa.*)) } }" > %t6.script +# RUN: ld.lld -o %t7 --script %t6.script %t2.o %t1.o +# RUN: llvm-objdump -s %t7 | FileCheck -check-prefix=UNSORTED %s + +## Check --sort-section alignment option. +# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t7.script +# RUN: ld.lld --sort-section alignment -o %t8 --script %t7.script %t1.o %t2.o +# RUN: llvm-objdump -s %t8 | FileCheck -check-prefix=SORTED_ALIGNMENT %s + +## Check --sort-section= form. +# RUN: ld.lld --sort-section=alignment -o %t8_1 --script %t7.script %t1.o %t2.o +# RUN: llvm-objdump -s %t8_1 | FileCheck -check-prefix=SORTED_ALIGNMENT %s + +## Check --sort-section name option. +# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t8.script +# RUN: ld.lld --sort-section name -o %t9 --script %t8.script %t1.o %t2.o +# RUN: llvm-objdump -s %t9 | FileCheck -check-prefix=SORTED_B %s + +## SORT_NONE disables the --sort-section. +# RUN: echo "SECTIONS { .aaa : { *(SORT_NONE(.aaa.*)) } }" > %t9.script +# RUN: ld.lld --sort-section name -o %t10 --script %t9.script %t2.o %t1.o +# RUN: llvm-objdump -s %t10 | FileCheck -check-prefix=UNSORTED %s + +## SORT_NONE as a inner sort directive. +# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_NAME(SORT_NONE(.aaa.*))) } }" > %t10.script +# RUN: ld.lld -o %t11 --script %t10.script %t2.o %t1.o +# RUN: llvm-objdump -s %t11 | FileCheck -check-prefix=SORTED_A %s + +.global _start +_start: + nop + +.section .aaa.5, "a" +.align 32 +.quad 5 + +.section .aaa.1, "a" +.align 2 +.quad 1 + +.section .aaa.3, "a" +.align 8 +.quad 3 + +.section .aaa.2, "a" +.align 4 +.quad 2 + +.section .aaa.4, "a" +.align 16 +.quad 4 diff --git a/test/ELF/linkerscript/sort2.s b/test/ELF/linkerscript/sort2.s new file mode 100644 index 0000000000000..1d42093d5aa0b --- /dev/null +++ b/test/ELF/linkerscript/sort2.s @@ -0,0 +1,39 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tfile1.o + +# RUN: echo "SECTIONS { .abc : { *(SORT(.foo.*) .bar.*) } }" > %t1.script +# RUN: ld.lld -o %t1 --script %t1.script %tfile1.o +# RUN: llvm-objdump -s %t1 | FileCheck %s + +# CHECK: Contents of section .abc: +# CHECK: 01000000 00000000 02000000 00000000 +# CHECK: 03000000 00000000 04000000 00000000 +# CHECK: 06000000 00000000 05000000 00000000 + +# RUN: echo "SECTIONS { \ +# RUN: .abc : { *(SORT(.foo.* EXCLUDE_FILE (*file1.o) .bar.*) .bar.*) } \ +# RUN: }" > %t2.script +# RUN: ld.lld -o %t2 --script %t2.script %tfile1.o +# RUN: llvm-objdump -s %t2 | FileCheck %s + +.text +.globl _start +_start: + +.section .foo.2,"a" + .quad 2 + +.section .foo.3,"a" + .quad 3 + +.section .foo.1,"a" + .quad 1 + +.section .bar.4,"a" + .quad 4 + +.section .bar.6,"a" + .quad 6 + +.section .bar.5,"a" + .quad 5 diff --git a/test/ELF/linkerscript/start-end.s b/test/ELF/linkerscript/start-end.s new file mode 100644 index 0000000000000..b68606abc1811 --- /dev/null +++ b/test/ELF/linkerscript/start-end.s @@ -0,0 +1,16 @@ +# 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/subalign.s b/test/ELF/linkerscript/subalign.s new file mode 100644 index 0000000000000..8b441d440b0ef --- /dev/null +++ b/test/ELF/linkerscript/subalign.s @@ -0,0 +1,43 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o + +# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t1.script +# RUN: ld.lld -o %t1 --script %t1.script %t1.o +# RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=NOALIGN %s +# NOALIGN: Contents of section .aaa: +# NOALIGN-NEXT: 01000000 00000000 00000000 00000000 +# NOALIGN-NEXT: 00000000 00000000 00000000 00000000 +# NOALIGN-NEXT: 02000000 00000000 00000000 00000000 +# NOALIGN-NEXT: 00000000 00000000 00000000 00000000 +# NOALIGN-NEXT: 03000000 00000000 00000000 00000000 +# NOALIGN-NEXT: 00000000 00000000 00000000 00000000 +# NOALIGN-NEXT: 00000000 00000000 00000000 00000000 +# NOALIGN-NEXT: 00000000 00000000 00000000 00000000 +# NOALIGN-NEXT: 04000000 00000000 + +# RUN: echo "SECTIONS { .aaa : SUBALIGN(1) { *(.aaa.*) } }" > %t2.script +# RUN: ld.lld -o %t2 --script %t2.script %t1.o +# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SUBALIGN %s +# SUBALIGN: Contents of section .aaa: +# SUBALIGN: 01000000 00000000 02000000 00000000 +# SUBALIGN: 03000000 00000000 04000000 00000000 + +.global _start +_start: + nop + +.section .aaa.1, "a" +.align 16 +.quad 1 + +.section .aaa.2, "a" +.align 32 +.quad 2 + +.section .aaa.3, "a" +.align 64 +.quad 3 + +.section .aaa.4, "a" +.align 128 +.quad 4 diff --git a/test/ELF/linkerscript/symbol-assignexpr.s b/test/ELF/linkerscript/symbol-assignexpr.s new file mode 100644 index 0000000000000..b988abcdfe980 --- /dev/null +++ b/test/ELF/linkerscript/symbol-assignexpr.s @@ -0,0 +1,48 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: echo "SECTIONS { \ +# RUN: symbol = CONSTANT(MAXPAGESIZE); \ +# RUN: symbol2 = symbol + 0x1234; \ +# RUN: symbol3 = symbol2; \ +# RUN: symbol4 = symbol + -4; \ +# RUN: symbol5 = symbol - ~ 0xfffb; \ +# RUN: symbol6 = symbol - ~(0xfff0 + 0xb); \ +# RUN: symbol7 = symbol - ~ 0xfffb + 4; \ +# RUN: symbol8 = ~ 0xffff + 4; \ +# RUN: symbol9 = - 4; \ +# RUN: symbol10 = 0xfedcba9876543210; \ +# RUN: symbol11 = ((0x28000 + 0x1fff) & ~(0x1000 + -1)); \ +# RUN: }" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck %s + +# CHECK: SYMBOL TABLE: +# CHECK-NEXT: 0000000000000000 *UND* 00000000 +# CHECK-NEXT: .text 00000000 _start +# CHECK-NEXT: .text 00000000 foo +# CHECK-NEXT: 0000000000001000 *ABS* 00000000 symbol +# CHECK-NEXT: 0000000000002234 *ABS* 00000000 symbol2 +# CHECK-NEXT: 0000000000002234 *ABS* 00000000 symbol3 +# CHECK-NEXT: 0000000000000ffc *ABS* 00000000 symbol4 +# CHECK-NEXT: 0000000000010ffc *ABS* 00000000 symbol5 +# CHECK-NEXT: 0000000000010ffc *ABS* 00000000 symbol6 +# CHECK-NEXT: 0000000000011000 *ABS* 00000000 symbol7 +# CHECK-NEXT: ffffffffffff0004 *ABS* 00000000 symbol8 +# CHECK-NEXT: fffffffffffffffc *ABS* 00000000 symbol9 +# CHECK-NEXT: fedcba9876543210 *ABS* 00000000 symbol10 +# CHECK-NEXT: 0000000000029000 *ABS* 00000000 symbol11 + +# RUN: echo "SECTIONS { \ +# RUN: symbol2 = symbol; \ +# RUN: }" > %t2.script +# RUN: not ld.lld -o %t2 --script %t2.script %t 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR %s +# ERR: {{.*}}.script:1: symbol not found: symbol + +.global _start +_start: + nop + +.global foo +foo: diff --git a/test/ELF/linkerscript-symbols.s b/test/ELF/linkerscript/symbol-conflict.s index 1fcd4e8a84815..dcca7c13de6e6 100644 --- a/test/ELF/linkerscript-symbols.s +++ b/test/ELF/linkerscript/symbol-conflict.s @@ -1,10 +1,10 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "SECTIONS {.text : {*(.text.*)} text_end = .;}" > %t.script +# RUN: echo "SECTIONS { . = SIZEOF_HEADERS; .text : {*(.text.*)} end = .;}" > %t.script # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -t %t1 | FileCheck %s -# CHECK: 0000000000000121 *ABS* 00000000 text_end +# CHECK: 00000000000000e9 .text 00000000 end .global _start _start: diff --git a/test/ELF/linkerscript/symbol-only.s b/test/ELF/linkerscript/symbol-only.s new file mode 100644 index 0000000000000..76d54f01cdc75 --- /dev/null +++ b/test/ELF/linkerscript/symbol-only.s @@ -0,0 +1,21 @@ +# 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/symbolreferenced.s b/test/ELF/linkerscript/symbolreferenced.s new file mode 100644 index 0000000000000..c2925b179ad50 --- /dev/null +++ b/test/ELF/linkerscript/symbolreferenced.s @@ -0,0 +1,22 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# Provide new symbol. The value should be 1, like set in PROVIDE() +# RUN: echo "SECTIONS { PROVIDE(newsym = 1);}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE1 %s +# PROVIDE1: 0000000000000001 *ABS* 00000000 newsym + +# Provide new symbol (hidden). The value should be 1 +# RUN: echo "SECTIONS { PROVIDE_HIDDEN(newsym = 1);}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN1 %s +# HIDDEN1: 0000000000000001 *ABS* 00000000 .hidden newsym + +.global _start +_start: + nop + +.globl patatino +patatino: + movl newsym, %eax diff --git a/test/ELF/linkerscript/symbols-synthetic.s b/test/ELF/linkerscript/symbols-synthetic.s new file mode 100644 index 0000000000000..95cdae9a929ec --- /dev/null +++ b/test/ELF/linkerscript/symbols-synthetic.s @@ -0,0 +1,98 @@ +# 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/symbols.s b/test/ELF/linkerscript/symbols.s new file mode 100644 index 0000000000000..4656635171c88 --- /dev/null +++ b/test/ELF/linkerscript/symbols.s @@ -0,0 +1,84 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# Simple symbol assignment. Should raise conflict in case we +# have duplicates in any input section, but currently simply +# replaces the value. +# RUN: echo "SECTIONS {.text : {*(.text.*)} text_end = .;}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=SIMPLE %s +# SIMPLE: .text 00000000 text_end + +# The symbol is not referenced. Don't provide it. +# RUN: echo "SECTIONS { PROVIDE(newsym = 1);}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE1 %s +# PROVIDE1-NOT: 0000000000000001 *ABS* 00000000 newsym + +# The symbol is not referenced. Don't provide it. +# RUN: echo "SECTIONS { PROVIDE_HIDDEN(newsym = 1);}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN1 %s +# HIDDEN1-NOT: 0000000000000001 *ABS* 00000000 .hidden newsym + +# Provide existing symbol. The value should be 0, even though we +# have value of 1 in PROVIDE() +# RUN: echo "SECTIONS { PROVIDE(somesym = 1);}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE2 %s +# PROVIDE2: 0000000000000000 *ABS* 00000000 somesym + +# Provide existing symbol. The value should be 0, even though we +# have value of 1 in PROVIDE_HIDDEN(). Visibility should not change +# RUN: echo "SECTIONS { PROVIDE_HIDDEN(somesym = 1);}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN2 %s +# HIDDEN2: 0000000000000000 *ABS* 00000000 somesym + +# Hidden symbol assignment. +# RUN: echo "SECTIONS { HIDDEN(newsym = 1);}" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN3 %s +# HIDDEN3: 0000000000000001 *ABS* 00000000 .hidden newsym + +# The symbol is not referenced. Don't provide it. +# RUN: echo "PROVIDE(newsym = 1);" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE4 %s +# PROVIDE4-NOT: 0000000000000001 *ABS* 00000000 newsym + +# The symbol is not referenced. Don't provide it. +# RUN: echo "PROVIDE_HIDDEN(newsym = 1);" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN4 %s +# HIDDEN4-NOT: 0000000000000001 *ABS* 00000000 .hidden newsym + +# Provide existing symbol. The value should be 0, even though we +# have value of 1 in PROVIDE() +# RUN: echo "PROVIDE(somesym = 1);" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE5 %s +# PROVIDE5: 0000000000000000 *ABS* 00000000 somesym + +# Provide existing symbol. The value should be 0, even though we +# have value of 1 in PROVIDE_HIDDEN(). Visibility should not change +# RUN: echo "PROVIDE_HIDDEN(somesym = 1);" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN5 %s +# HIDDEN5: 0000000000000000 *ABS* 00000000 somesym + +# Simple symbol assignment. All three symbols should have the +# same value. +# RUN: echo "foo = 0x100; SECTIONS { bar = foo; } baz = bar;" > %t.script +# RUN: ld.lld -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=SIMPLE2 %s +# SIMPLE2: 0000000000000100 *ABS* 00000000 foo +# SIMPLE2: 0000000000000100 *ABS* 00000000 bar +# SIMPLE2: 0000000000000100 *ABS* 00000000 baz + +.global _start +_start: + nop + +.global somesym +somesym = 0 diff --git a/test/ELF/linkerscript/tbss.s b/test/ELF/linkerscript/tbss.s new file mode 100644 index 0000000000000..de8ed50cb4a4e --- /dev/null +++ b/test/ELF/linkerscript/tbss.s @@ -0,0 +1,42 @@ +# 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: foo : { *(foo) } \ +# RUN: bar : { *(bar) } \ +# RUN: }" > %t.script +# RUN: ld.lld -T %t.script %t.o -o %t +# RUN: llvm-readobj -s %t | FileCheck %s + +# test that a tbss section doesn't use address space. + +# CHECK: Name: foo +# CHECK-NEXT: Type: SHT_NOBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_TLS +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x[[ADDR:.*]] +# CHECK-NEXT: Offset: 0x[[ADDR]] +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 1 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: +# CHECK-NEXT: Name: bar +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x[[ADDR]] + + .section foo,"awT",@nobits + .long 0 + .section bar, "aw" + .long 0 diff --git a/test/ELF/linkerscript-symbol-conflict.s b/test/ELF/linkerscript/undef.s index 30186ed5cb870..85ad0767b5edd 100644 --- a/test/ELF/linkerscript-symbol-conflict.s +++ b/test/ELF/linkerscript/undef.s @@ -1,11 +1,11 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: echo "SECTIONS {.text : {*(.text.*)} end = .;}" > %t.script +# RUN: echo "SECTIONS { patatino = 0x1234; }" > %t.script # RUN: ld.lld -o %t1 --script %t.script %t # RUN: llvm-objdump -t %t1 | FileCheck %s -# CHECK: 0000000000000121 *ABS* 00000000 end +# CHECK: 0000000000001234 *ABS* 00000000 patatino .global _start _start: - nop + call patatino diff --git a/test/ELF/linkerscript-va.s b/test/ELF/linkerscript/va.s index 25d0bd2268c08..854ebcef01464 100644 --- a/test/ELF/linkerscript-va.s +++ b/test/ELF/linkerscript/va.s @@ -7,9 +7,9 @@ # CHECK: Sections: # CHECK-NEXT: Idx Name Size Address Type # CHECK-NEXT: 0 00000000 0000000000000000 -# CHECK-NEXT: 1 .foo 00000004 0000000000000120 DATA -# CHECK-NEXT: 2 .boo 00000004 0000000000000124 DATA -# CHECK-NEXT: 3 .text 00000001 0000000000000128 TEXT DATA +# CHECK-NEXT: 1 .text 00000001 0000000000000000 TEXT DATA +# CHECK-NEXT: 2 .foo 00000004 0000000000000001 DATA +# CHECK-NEXT: 3 .boo 00000004 0000000000000005 DATA .global _start _start: diff --git a/test/ELF/linkerscript/visibility.s b/test/ELF/linkerscript/visibility.s new file mode 100644 index 0000000000000..9d9fcf0c5cdc0 --- /dev/null +++ b/test/ELF/linkerscript/visibility.s @@ -0,0 +1,22 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o + +# RUN: echo "SECTIONS { foo = .; }" > %t1.script +# RUN: ld.lld -o %t1 --script %t1.script %t.o -shared +# RUN: llvm-readobj -t %t1 | FileCheck %s + +# CHECK: Symbol { +# CHECK: Name: foo +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: +# CHECK-NEXT: Other [ +# CHECK-NEXT: STV_HIDDEN +# CHECK-NEXT: ] +# CHECK-NEXT: Section: +# CHECK-NEXT: } + + .data + .hidden foo + .long foo diff --git a/test/ELF/linkerscript/wildcards.s b/test/ELF/linkerscript/wildcards.s new file mode 100644 index 0000000000000..4e9469e407737 --- /dev/null +++ b/test/ELF/linkerscript/wildcards.s @@ -0,0 +1,83 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +## Default case: abc and abx included in text. +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.abc .abx) } }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -section-headers %t.out | \ +# RUN: FileCheck -check-prefix=SEC-DEFAULT %s +# SEC-DEFAULT: Sections: +# SEC-DEFAULT-NEXT: Idx Name Size +# SEC-DEFAULT-NEXT: 0 00000000 +# SEC-DEFAULT-NEXT: 1 .text 00000008 +# SEC-DEFAULT-NEXT: 2 .abcd 00000004 +# SEC-DEFAULT-NEXT: 3 .ad 00000004 +# SEC-DEFAULT-NEXT: 4 .ag 00000004 +# SEC-DEFAULT-NEXT: 5 .comment 00000008 {{[0-9a-f]*}} +# SEC-DEFAULT-NEXT: 6 .symtab 00000030 +# SEC-DEFAULT-NEXT: 7 .shstrtab 00000038 +# SEC-DEFAULT-NEXT: 8 .strtab 00000008 + +## Now replace the symbol with '?' and check that results are the same. +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.abc .ab?) } }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -section-headers %t.out | \ +# RUN: FileCheck -check-prefix=SEC-DEFAULT %s + +## Now see how replacing '?' with '*' will consume whole abcd. +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.abc .ab*) } }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -section-headers %t.out | \ +# RUN: FileCheck -check-prefix=SEC-ALL %s +# SEC-ALL: Sections: +# SEC-ALL-NEXT: Idx Name Size +# SEC-ALL-NEXT: 0 00000000 +# SEC-ALL-NEXT: 1 .text 0000000c +# SEC-ALL-NEXT: 2 .ad 00000004 +# SEC-ALL-NEXT: 3 .ag 00000004 +# SEC-ALL-NEXT: 4 .comment 00000008 +# SEC-ALL-NEXT: 5 .symtab 00000030 +# SEC-ALL-NEXT: 6 .shstrtab 00000032 +# SEC-ALL-NEXT: 7 .strtab 00000008 + +## All sections started with .a are merged. +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.a*) } }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -section-headers %t.out | \ +# RUN: FileCheck -check-prefix=SEC-NO %s +# SEC-NO: Sections: +# SEC-NO-NEXT: Idx Name Size +# SEC-NO-NEXT: 0 00000000 +# SEC-NO-NEXT: 1 .text 00000014 +# SEC-NO-NEXT: 2 .comment 00000008 +# SEC-NO-NEXT: 3 .symtab 00000030 +# SEC-NO-NEXT: 4 .shstrtab 0000002a +# SEC-NO-NEXT: 5 .strtab 00000008 + +.text +.section .abc,"ax",@progbits +.long 0 + +.text +.section .abx,"ax",@progbits +.long 0 + +.text +.section .abcd,"ax",@progbits +.long 0 + +.text +.section .ad,"ax",@progbits +.long 0 + +.text +.section .ag,"ax",@progbits +.long 0 + + +.globl _start +_start: diff --git a/test/ELF/linkerscript/wildcards2.s b/test/ELF/linkerscript/wildcards2.s new file mode 100644 index 0000000000000..5e8d6a3d309a1 --- /dev/null +++ b/test/ELF/linkerscript/wildcards2.s @@ -0,0 +1,25 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +## Check that aabc is not included in text. +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.abc) } }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -section-headers %t.out | \ +# RUN: FileCheck %s +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size +# CHECK-NEXT: 0 00000000 +# CHECK-NEXT: 1 .text 00000004 +# CHECK-NEXT: 2 aabc 00000004 + +.text +.section .abc,"ax",@progbits +.long 0 + +.text +.section aabc,"ax",@progbits +.long 0 + +.globl _start +_start: diff --git a/test/ELF/local-dynamic.s b/test/ELF/local-dynamic.s index 436516a911904..797a1071311cd 100644 --- a/test/ELF/local-dynamic.s +++ b/test/ELF/local-dynamic.s @@ -16,7 +16,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: blah -// CHECK-NEXT: Value: 0x1000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -25,7 +25,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: foo -// CHECK-NEXT: Value: 0x1000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -34,7 +34,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: goo -// CHECK-NEXT: Value: 0x1000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -43,7 +43,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _DYNAMIC -// CHECK-NEXT: Value: 0x1000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -54,7 +54,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x1000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None @@ -75,7 +75,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start@ -// CHECK-NEXT: Value: 0x1000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None diff --git a/test/ELF/local-got-pie.s b/test/ELF/local-got-pie.s index e846bd4544459..417f9d002034e 100644 --- a/test/ELF/local-got-pie.s +++ b/test/ELF/local-got-pie.s @@ -1,6 +1,6 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o // RUN: ld.lld %t.o -o %t -pie -// RUN: llvm-readobj -s -r %t | FileCheck %s +// RUN: llvm-readobj -s -r -d %t | FileCheck %s // RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s .globl _start @@ -12,10 +12,10 @@ _start: foo: nop -// 0x20A0 - 1001 - 5 = 4250 +// 0x20B0 - 1001 - 5 = 4266 // DISASM: Disassembly of section .text: // DISASM-NEXT: _start: -// DISASM-NEXT: 1000: {{.*}} callq 4251 +// DISASM-NEXT: 1000: {{.*}} callq 4267 // DISASM: foo: // DISASM-NEXT: 1005: {{.*}} nop @@ -25,12 +25,13 @@ foo: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x20A0 +// CHECK-NEXT: Address: 0x20B0 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 8 // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x20A0 R_X86_64_RELATIVE - 0x1005 +// CHECK-NEXT: 0x20B0 R_X86_64_RELATIVE - 0x1005 // CHECK-NEXT: } // CHECK-NEXT: ] +// CHECK: 0x000000006FFFFFF9 RELACOUNT 1 diff --git a/test/ELF/local-got-shared.s b/test/ELF/local-got-shared.s index 08e6583f481fd..e4fd469975177 100644 --- a/test/ELF/local-got-shared.s +++ b/test/ELF/local-got-shared.s @@ -1,6 +1,6 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o // RUN: ld.lld %t.o -o %t -shared -// RUN: llvm-readobj -s -r %t | FileCheck %s +// RUN: llvm-readobj -s -r -d %t | FileCheck %s // RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s bar: @@ -11,9 +11,9 @@ bar: foo: nop -// 0x2090 - 0x1000 - 5 = 4235 +// 0x20A0 - 0x1000 - 5 = 4251 // DISASM: bar: -// DISASM-NEXT: 1000: {{.*}} callq 4235 +// DISASM-NEXT: 1000: {{.*}} callq 4251 // DISASM: foo: // DISASM-NEXT: 1005: {{.*}} nop @@ -24,12 +24,13 @@ foo: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x2090 +// CHECK-NEXT: Address: 0x20A0 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 8 // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x2090 R_X86_64_RELATIVE - 0x1005 +// CHECK-NEXT: 0x20A0 R_X86_64_RELATIVE - 0x1005 // CHECK-NEXT: } // CHECK-NEXT: ] +// CHECK: 0x000000006FFFFFF9 RELACOUNT 1 diff --git a/test/ELF/local-got.s b/test/ELF/local-got.s index 1a8fa0dfd2535..7e6ef9e0be7e8 100644 --- a/test/ELF/local-got.s +++ b/test/ELF/local-got.s @@ -14,14 +14,14 @@ _start: foo: nop -// 0x120B0 - 0x11000 - 5 = 4251 -// 0x120B8 - 0x11005 - 5 = 4254 +// 0x2020B0 - 0x201000 - 5 = 4251 +// 0x2020B8 - 0x201005 - 5 = 4254 // DISASM: _start: -// DISASM-NEXT: 11000: {{.*}} callq 4267 -// DISASM-NEXT: 11005: {{.*}} callq 4270 +// DISASM-NEXT: 201000: {{.*}} callq 4267 +// DISASM-NEXT: 201005: {{.*}} callq 4270 // DISASM: foo: -// DISASM-NEXT: 1100a: {{.*}} nop +// DISASM-NEXT: 20100a: {{.*}} nop // CHECK: Name: .got // CHECK-NEXT: Type: SHT_PROGBITS @@ -29,7 +29,7 @@ foo: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x120B0 +// CHECK-NEXT: Address: 0x2020B0 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 16 // CHECK-NEXT: Link: 0 @@ -37,12 +37,12 @@ foo: // CHECK-NEXT: AddressAlignment: 8 // CHECK-NEXT: EntrySize: 0 // CHECK-NEXT: SectionData ( -// 0x1200a in little endian -// CHECK-NEXT: 0000: 00000000 00000000 0A100100 00000000 +// 0x20200a in little endian +// CHECK-NEXT: 0000: 00000000 00000000 0A102000 00000000 // CHECK-NEXT: ) // CHECK: Relocations [ // CHECK-NEXT: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x120B0 R_X86_64_GLOB_DAT bar 0x0 +// CHECK-NEXT: 0x2020B0 R_X86_64_GLOB_DAT bar 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] diff --git a/test/ELF/local.s b/test/ELF/local.s index cc879e15c0db4..983d7ff7ba633 100644 --- a/test/ELF/local.s +++ b/test/ELF/local.s @@ -1,5 +1,5 @@ // Check that symbol table is correctly populated with local symbols. -// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +// 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 @@ -14,7 +14,7 @@ // CHECK-NEXT: Offset: // CHECK-NEXT: Size: // CHECK-NEXT: Link: -// CHECK-NEXT: Info: 5 +// CHECK-NEXT: Info: 6 // CHECK: Symbols [ // CHECK-NEXT: Symbol { @@ -27,8 +27,17 @@ // CHECK-NEXT: Section: Undefined // CHECK-NEXT: } // CHECK-NEXT: Symbol { +// CHECK-NEXT: Name: .Labs +// CHECK-NEXT: Value: +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Local +// CHECK-NEXT: Type: None +// CHECK-NEXT: Other: 0 +// CHECK-NEXT: Section: Absolute +// CHECK-NEXT: } +// CHECK-NEXT: Symbol { // CHECK-NEXT: Name: abs -// CHECK-NEXT: Value: 0x2A +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -37,7 +46,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: blah -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -46,7 +55,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: foo -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -55,7 +64,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: goo -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -64,7 +73,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None @@ -80,3 +89,4 @@ blah: foo: goo: abs = 42 +.Labs = 43 diff --git a/test/ELF/lto/Inputs/common3.ll b/test/ELF/lto/Inputs/common3.ll new file mode 100644 index 0000000000000..a4efc65915703 --- /dev/null +++ b/test/ELF/lto/Inputs/common3.ll @@ -0,0 +1,3 @@ +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/thin1.ll b/test/ELF/lto/Inputs/thin1.ll new file mode 100644 index 0000000000000..93029837714b7 --- /dev/null +++ b/test/ELF/lto/Inputs/thin1.ll @@ -0,0 +1,12 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-scei-ps4" + +define i32 @foo(i32 %goo) { +entry: + %goo.addr = alloca i32, align 4 + store i32 %goo, i32* %goo.addr, align 4 + %0 = load i32, i32* %goo.addr, align 4 + %1 = load i32, i32* %goo.addr, align 4 + %mul = mul nsw i32 %0, %1 + ret i32 %mul +} diff --git a/test/ELF/lto/Inputs/thin2.ll b/test/ELF/lto/Inputs/thin2.ll new file mode 100644 index 0000000000000..6cffbdcc53f26 --- /dev/null +++ b/test/ELF/lto/Inputs/thin2.ll @@ -0,0 +1,11 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-scei-ps4" + +define i32 @blah(i32 %meh) #0 { +entry: + %meh.addr = alloca i32, align 4 + store i32 %meh, i32* %meh.addr, align 4 + %0 = load i32, i32* %meh.addr, align 4 + %sub = sub nsw i32 %0, 48 + ret i32 %sub +} diff --git a/test/ELF/lto/Inputs/thinlto.ll b/test/ELF/lto/Inputs/thinlto.ll new file mode 100644 index 0000000000000..31c72ec4653a6 --- /dev/null +++ b/test/ELF/lto/Inputs/thinlto.ll @@ -0,0 +1,7 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @g() { +entry: + ret void +} diff --git a/test/ELF/lto/Inputs/unnamed-addr-drop.ll b/test/ELF/lto/Inputs/unnamed-addr-drop.ll new file mode 100644 index 0000000000000..b91bc8e5a891c --- /dev/null +++ b/test/ELF/lto/Inputs/unnamed-addr-drop.ll @@ -0,0 +1,4 @@ +target triple = "x86_64-unknown-linux-gnu" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +@foo = unnamed_addr constant i32 42 diff --git a/test/ELF/lto/archive-3.ll b/test/ELF/lto/archive-3.ll index 350c8929c9df8..0322e412539a6 100644 --- a/test/ELF/lto/archive-3.ll +++ b/test/ELF/lto/archive-3.ll @@ -3,12 +3,12 @@ ; RUN: llvm-as %s -o %t2.o ; RUN: ld.lld -m elf_x86_64 %t1.o %t2.o -o %t3 -save-temps -; RUN: llvm-dis %t3.lto.bc -o - | FileCheck %s +; 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: llvm-dis %t3.lto.bc -o - | FileCheck %s +; RUN: llvm-dis %t3.0.2.internalize.bc -o - | FileCheck %s ; CHECK: define internal void @foo() { diff --git a/test/ELF/lto/archive.ll b/test/ELF/lto/archive.ll index b3f69fb9920f1..b4d011fdb8886 100644 --- a/test/ELF/lto/archive.ll +++ b/test/ELF/lto/archive.ll @@ -8,7 +8,6 @@ ; RUN: ld.lld -m elf_x86_64 %t2.o --whole-archive %t.a -o %t3 -shared ; RUN: llvm-readobj -t %t3 | FileCheck %s - ; CHECK: Name: g ( ; CHECK-NEXT: Value: ; CHECK-NEXT: Size: diff --git a/test/ELF/lto/asmundef.ll b/test/ELF/lto/asmundef.ll index d76e418fce819..1c87cd01fad8c 100644 --- a/test/ELF/lto/asmundef.ll +++ b/test/ELF/lto/asmundef.ll @@ -1,7 +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-dis %t.lto.bc -o - | FileCheck %s +; 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" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/available-externally.ll b/test/ELF/lto/available-externally.ll index 74aa86002c9e9..181042b9d1e1c 100644 --- a/test/ELF/lto/available-externally.ll +++ b/test/ELF/lto/available-externally.ll @@ -1,7 +1,7 @@ ; 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: llvm-dis < %t.so.lto.bc | FileCheck %s +; 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" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/invalid-bitcode.ll b/test/ELF/lto/bitcode-nodatalayout.ll index eceffb10d8ad4..5c4883a42444e 100644 --- a/test/ELF/lto/invalid-bitcode.ll +++ b/test/ELF/lto/bitcode-nodatalayout.ll @@ -1,10 +1,11 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: not ld.lld -m elf_x86_64 %t.o 2>&1 | FileCheck %s +; RUN: not ld.lld -m elf_x86_64 %t.o -o %t 2>&1 | FileCheck %s -; CHECK: invalid bitcode file: +; CHECK: input module has no datalayout ; This bitcode file has no datalayout. +; Check that we error out producing a reasonable diagnostic. target triple = "x86_64-unknown-linux-gnu" define void @_start() { diff --git a/test/ELF/lto/combined-lto-object-name.ll b/test/ELF/lto/combined-lto-object-name.ll index f5b7e3ae40e68..f46efc4f7387c 100644 --- a/test/ELF/lto/combined-lto-object-name.ll +++ b/test/ELF/lto/combined-lto-object-name.ll @@ -11,4 +11,4 @@ define void @_start() { ret void } -; CHECK: undefined symbol: foo in {{.*}}combined-lto-object-name.ll.tmp.o +; CHECK: error: ld-temp.o:(function _start): undefined symbol 'foo' diff --git a/test/ELF/lto/common2.ll b/test/ELF/lto/common2.ll index 59a2676e4fc95..b44bbac4fda31 100644 --- a/test/ELF/lto/common2.ll +++ b/test/ELF/lto/common2.ll @@ -1,21 +1,24 @@ ; RUN: llvm-as %s -o %t1.o ; RUN: ld.lld -m elf_x86_64 %t1.o -o %t -shared -save-temps -; RUN: llvm-dis < %t.lto.bc | FileCheck %s +; RUN: llvm-dis < %t.0.2.internalize.bc | FileCheck %s ; RUN: llvm-readobj -t %t | FileCheck %s --check-prefix=SHARED target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @a = common global i8 0, align 8 +; CHECK-DAG: @a = common global i8 0, align 8 -; Shared library case, we ensure that the bitcode generated file -; has not the a symbol but is appears in the final shared library -; produced. -; CHECK-NOT: @a = common global i8 0, align 8 +@b = common hidden global i32 0, align 4 +define i32 @f() { + %t = load i32, i32* @b, align 4 + ret i32 %t +} +; CHECK-DAG: @b = internal global i32 0, align 4 ; SHARED: Symbol { ; SHARED: Name: a -; SHARED-NEXT: Value: 0x2000 +; SHARED-NEXT: Value: ; SHARED-NEXT: Size: 1 ; SHARED-NEXT: Binding: Global ; SHARED-NEXT: Type: Object diff --git a/test/ELF/lto/common3.ll b/test/ELF/lto/common3.ll new file mode 100644 index 0000000000000..6d40de547fcd6 --- /dev/null +++ b/test/ELF/lto/common3.ll @@ -0,0 +1,14 @@ +; 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: llvm-dis < %t.0.2.internalize.bc | FileCheck %s + +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 i32 0, align 8 +define i32 @f() { + %t = load i32, i32* @a, align 4 + ret i32 %t +} + +; CHECK: @a = internal global i64 0, align 8 diff --git a/test/ELF/lto/discard-value-names.ll b/test/ELF/lto/discard-value-names.ll index c6cd94fd2e183..c71dc386113dd 100644 --- a/test/ELF/lto/discard-value-names.ll +++ b/test/ELF/lto/discard-value-names.ll @@ -1,7 +1,7 @@ ; RUN: llvm-as %s -o %t.o ; RUN: ld.lld -m elf_x86_64 -shared -save-temps %t.o -o %t2.o -; RUN: llvm-dis < %t2.o.lto.bc | FileCheck %s +; RUN: llvm-dis < %t2.o.0.0.preopt.bc | FileCheck %s ; CHECK: @GlobalValueName ; CHECK: @foo(i32 %in) diff --git a/test/ELF/lto/drop-debug-info.ll b/test/ELF/lto/drop-debug-info.ll index 7a7ed5ea41d1c..27c0260080eb1 100644 --- a/test/ELF/lto/drop-debug-info.ll +++ b/test/ELF/lto/drop-debug-info.ll @@ -5,5 +5,5 @@ ; ; RUN: ld.lld -m elf_x86_64 -shared %p/Inputs/drop-debug-info.bc \ ; RUN: -disable-verify 2>&1 | FileCheck %s -; CHECK: warning: ignoring debug info with an invalid version (1) in {{.*}}drop-debug-info.bc +; 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 fd111c18bd131..1ff179666f0e6 100644 --- a/test/ELF/lto/drop-linkage.ll +++ b/test/ELF/lto/drop-linkage.ll @@ -5,7 +5,7 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" ; 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.lto.opt.bc -o - | FileCheck %s +; RUN: llvm-dis %t.so.0.4.opt.bc -o - | FileCheck %s define void @foo() { ret void diff --git a/test/ELF/lto/duplicated.ll b/test/ELF/lto/duplicated.ll index 6ef6772c5f207..903592c46067e 100644 --- a/test/ELF/lto/duplicated.ll +++ b/test/ELF/lto/duplicated.ll @@ -1,7 +1,7 @@ ; 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 -; CHECK: duplicate symbol: f in {{.*}}.o and {{.*}}.o +; CHECK: duplicate symbol 'f' in {{.*}}.o and {{.*}}.o 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/dynsym.ll b/test/ELF/lto/dynsym.ll index 5885960c7bc3a..b2b4157820b56 100644 --- a/test/ELF/lto/dynsym.ll +++ b/test/ELF/lto/dynsym.ll @@ -5,6 +5,11 @@ ; RUN: ld.lld -m elf_x86_64 %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: -o %t +; RUN: llvm-readobj -dyn-symbols %t | FileCheck %s + 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 396b9cb60f177..43c1837528f53 100644 --- a/test/ELF/lto/internalize-basic.ll +++ b/test/ELF/lto/internalize-basic.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o ; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -save-temps -; RUN: llvm-dis < %t2.lto.bc | FileCheck %s +; RUN: llvm-dis < %t2.0.2.internalize.bc | 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/internalize-exportdyn.ll b/test/ELF/lto/internalize-exportdyn.ll index bee9a1e6a1ee1..2034a2b3ab72b 100644 --- a/test/ELF/lto/internalize-exportdyn.ll +++ b/test/ELF/lto/internalize-exportdyn.ll @@ -2,7 +2,7 @@ ; 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: llvm-dis < %t2.lto.bc | FileCheck %s +; RUN: llvm-dis < %t2.0.2.internalize.bc | 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/internalize-llvmused.ll b/test/ELF/lto/internalize-llvmused.ll index 46c90a65ff726..253dcb26d0421 100644 --- a/test/ELF/lto/internalize-llvmused.ll +++ b/test/ELF/lto/internalize-llvmused.ll @@ -1,7 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o ; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -save-temps -; RUN: llvm-dis < %t2.lto.bc | FileCheck %s +; RUN: llvm-dis < %t2.0.2.internalize.bc | 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/internalize-undef.ll b/test/ELF/lto/internalize-undef.ll index 5d74c31eee8bb..f76528bda3b05 100644 --- a/test/ELF/lto/internalize-undef.ll +++ b/test/ELF/lto/internalize-undef.ll @@ -2,7 +2,7 @@ ; 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: llvm-dis < %t.lto.bc | FileCheck %s +; RUN: llvm-dis < %t.0.2.internalize.bc | FileCheck %s 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-version-script.ll b/test/ELF/lto/internalize-version-script.ll index c25328fb56e20..c577e43b50e43 100644 --- a/test/ELF/lto/internalize-version-script.ll +++ b/test/ELF/lto/internalize-version-script.ll @@ -2,7 +2,7 @@ ; 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: llvm-dis < %t2.lto.bc | FileCheck %s +; RUN: llvm-dis < %t2.0.2.internalize.bc | 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/irmover-error.ll b/test/ELF/lto/irmover-error.ll index aee411441c47e..8b9836d23ca41 100644 --- a/test/ELF/lto/irmover-error.ll +++ b/test/ELF/lto/irmover-error.ll @@ -2,7 +2,7 @@ ; 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 -; CHECK: failed to link module {{.*}}2.bc: linking module flags 'foo': IDs have conflicting values +; CHECK: linking module flags 'foo': IDs have conflicting values 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/linkonce-odr.ll b/test/ELF/lto/linkonce-odr.ll index 569e271545459..44233513d1fb8 100644 --- a/test/ELF/lto/linkonce-odr.ll +++ b/test/ELF/lto/linkonce-odr.ll @@ -2,7 +2,7 @@ ; RUN: llvm-as %p/Inputs/linkonce-odr.ll -o %t1.o ; RUN: llc -relocation-model=pic %s -o %t2.o -filetype=obj ; RUN: ld.lld %t1.o %t2.o -o %t.so -shared -save-temps -; RUN: llvm-dis %t.so.lto.opt.bc -o - | FileCheck %s +; 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" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/linkonce.ll b/test/ELF/lto/linkonce.ll index f980eff887b19..6dba6a3fded7c 100644 --- a/test/ELF/lto/linkonce.ll +++ b/test/ELF/lto/linkonce.ll @@ -2,7 +2,7 @@ ; RUN: llvm-as %p/Inputs/linkonce.ll -o %t1.o ; RUN: llc -relocation-model=pic %s -o %t2.o -filetype=obj ; RUN: ld.lld %t1.o %t2.o -o %t.so -shared -save-temps -; RUN: llvm-dis %t.so.lto.opt.bc -o - | FileCheck %s +; 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" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/ltopasses-basic.ll b/test/ELF/lto/ltopasses-basic.ll index 5bd5f4122fd03..0c4ad8b9f17c6 100644 --- a/test/ELF/lto/ltopasses-basic.ll +++ b/test/ELF/lto/ltopasses-basic.ll @@ -1,8 +1,7 @@ ; REQUIRES: x86 -; RUN: rm -f %t.so.lto.bc %t.so.lto.opt.bc %t.so.lto.o ; 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: llvm-dis %t.so.lto.opt.bc -o - | FileCheck %s +; 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" target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/lto/ltopasses-custom.ll b/test/ELF/lto/ltopasses-custom.ll index 3e982e079fb19..a48959a329913 100644 --- a/test/ELF/lto/ltopasses-custom.ll +++ b/test/ELF/lto/ltopasses-custom.ll @@ -3,8 +3,8 @@ ; RUN: ld.lld -m elf_x86_64 %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: llvm-dis %t.so.lto.opt.bc -o - | FileCheck %s -; RUN: llvm-dis %t2.so.lto.opt.bc -o - | FileCheck %s --check-prefix=ATOMIC +; 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 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @@ -28,3 +28,10 @@ define void @barrier() { ; RUN: --lto-newpm-passes=iamnotapass -shared 2>&1 | \ ; RUN: FileCheck %s --check-prefix=INVALID ; INVALID: unable to parse pass pipeline description: iamnotapass + +; Check that invalid AA pipelines are rejected gracefully. +; RUN: not ld.lld -m elf_x86_64 %t.o -o %t2.so \ +; RUN: --lto-newpm-passes=globaldce --lto-aa-pipeline=patatino \ +; RUN: -shared 2>&1 | \ +; RUN: FileCheck %s --check-prefix=INVALIDAA +; INVALIDAA: unable to parse AA pipeline description: patatino diff --git a/test/ELF/lto/metadata.ll b/test/ELF/lto/metadata.ll index 3e73de5aab473..2eaacaae27265 100644 --- a/test/ELF/lto/metadata.ll +++ b/test/ELF/lto/metadata.ll @@ -10,4 +10,6 @@ define weak void @foo(i32* %p) { ret void } -!0 = !{!"Simple C/C++ TBAA"} +!0 = !{!1, !1, i64 0} +!1 = !{!"int", !2} +!2 = !{!"Simple C/C++ TBAA"} diff --git a/test/ELF/lto/parallel-internalize.ll b/test/ELF/lto/parallel-internalize.ll index 58ed50eab894c..a7ee4b35877e0 100644 --- a/test/ELF/lto/parallel-internalize.ll +++ b/test/ELF/lto/parallel-internalize.ll @@ -1,6 +1,7 @@ ; REQUIRES: x86 ; RUN: llvm-as -o %t.bc %s -; RUN: ld.lld -m elf_x86_64 --lto-jobs=2 -save-temps -o %t %t.bc -e foo --lto-O0 +; RUN: ld.lld -m elf_x86_64 --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 %t0.lto.o | FileCheck --check-prefix=CHECK0 %s ; RUN: llvm-nm %t1.lto.o | FileCheck --check-prefix=CHECK1 %s @@ -16,8 +17,8 @@ ; CHECK-NEXT: Section: Undefined (0x0) ; CHECK-NEXT: } ; CHECK-NEXT: Symbol { -; CHECK-NEXT: Name: bar (5) -; CHECK-NEXT: Value: 0x11010 +; CHECK-NEXT: Name: bar +; CHECK-NEXT: Value: 0x201010 ; CHECK-NEXT: Size: 8 ; CHECK-NEXT: Binding: Local (0x0) ; CHECK-NEXT: Type: Function (0x2) @@ -27,8 +28,8 @@ ; CHECK-NEXT: Section: .text (0x2) ; CHECK-NEXT: } ; CHECK-NEXT: Symbol { -; CHECK-NEXT: Name: foo (1) -; CHECK-NEXT: Value: 0x11000 +; CHECK-NEXT: Name: foo +; CHECK-NEXT: Value: 0x201000 ; CHECK-NEXT: Size: 8 ; CHECK-NEXT: Binding: Global (0x1) ; CHECK-NEXT: Type: Function (0x2) diff --git a/test/ELF/lto/parallel.ll b/test/ELF/lto/parallel.ll index 8ea62ef3ae086..c5d7ca4e2cf1a 100644 --- a/test/ELF/lto/parallel.ll +++ b/test/ELF/lto/parallel.ll @@ -1,6 +1,6 @@ ; REQUIRES: x86 ; RUN: llvm-as -o %t.bc %s -; RUN: ld.lld -m elf_x86_64 --lto-jobs=2 -save-temps -o %t %t.bc -shared +; RUN: ld.lld -m elf_x86_64 --lto-partitions=2 -save-temps -o %t %t.bc -shared ; RUN: llvm-nm %t0.lto.o | FileCheck --check-prefix=CHECK0 %s ; RUN: llvm-nm %t1.lto.o | FileCheck --check-prefix=CHECK1 %s diff --git a/test/ELF/lto/save-temps.ll b/test/ELF/lto/save-temps.ll index 0b0f939c53f15..f7af99ed40af4 100644 --- a/test/ELF/lto/save-temps.ll +++ b/test/ELF/lto/save-temps.ll @@ -5,9 +5,9 @@ ; 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: llvm-nm a.out | FileCheck %s -; RUN: llvm-nm a.out.lto.bc | FileCheck %s +; RUN: llvm-nm a.out.0.0.preopt.bc | FileCheck %s ; RUN: llvm-nm a.out.lto.o | FileCheck %s -; RUN: llvm-dis a.out.lto.bc +; RUN: llvm-dis a.out.0.0.preopt.bc 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/shlib-undefined.ll b/test/ELF/lto/shlib-undefined.ll index db60de8e21b29..0250ed761927d 100644 --- a/test/ELF/lto/shlib-undefined.ll +++ b/test/ELF/lto/shlib-undefined.ll @@ -7,7 +7,7 @@ ; RUN: llvm-readobj -dyn-symbols %t | FileCheck %s ; CHECK: Name: __progname@ -; CHECK-NEXT: Value: 0x11010 +; CHECK-NEXT: Value: 0x201010 ; CHECK-NEXT: Size: 1 ; CHECK-NEXT: Binding: Global (0x1) ; CHECK-NEXT: Type: Function diff --git a/test/ELF/lto/thin-archivecollision.ll b/test/ELF/lto/thin-archivecollision.ll new file mode 100644 index 0000000000000..4e07187f36a0a --- /dev/null +++ b/test/ELF/lto/thin-archivecollision.ll @@ -0,0 +1,29 @@ +; RUN: opt -module-summary %s -o %t.o +; RUN: opt -module-summary %p/Inputs/thin1.ll -o %t.coll.o +; RUN: llvm-ar rcs %t1.a %t.coll.o +; RUN: opt -module-summary %p/Inputs/thin2.ll -o %t.coll.o +; RUN: llvm-ar rcsc %t2.a %t.coll.o + +; RUN: ld.lld %t.o %t1.a %t2.a -o %t +; RUN: llvm-nm %t | FileCheck %s + +; Check we handle this case correctly even in presence of --whole-archive. +; RUN: ld.lld %t.o --whole-archive %t1.a %t2.a -o %t +; RUN: llvm-nm %t | FileCheck %s + +; CHECK: T _start +; CHECK: T blah +; CHECK: T foo + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-scei-ps4" + +define i32 @_start() { +entry: + %call = call i32 @foo(i32 23) + %call1 = call i32 @blah(i32 37) + ret i32 0 +} + +declare i32 @foo(i32) #1 +declare i32 @blah(i32) #1 diff --git a/test/ELF/lto/thinlto.ll b/test/ELF/lto/thinlto.ll new file mode 100644 index 0000000000000..160c83a18abf8 --- /dev/null +++ b/test/ELF/lto/thinlto.ll @@ -0,0 +1,35 @@ +; Basic ThinLTO tests. +; RUN: opt -module-summary %s -o %t.o +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o + +; First force single-threaded mode +; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared %t.o %t2.o -o %t +; RUN: llvm-nm %t0.lto.o | FileCheck %s --check-prefix=NM1-SINGLE +; RUN: llvm-nm %t1.lto.o | FileCheck %s --check-prefix=NM2-SINGLE + +; NM1-SINGLE: T f +; NM2-SINGLE: T g + +; Next force multi-threaded mode +; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared %t.o %t2.o -o %t2 +; RUN: llvm-nm %t20.lto.o | FileCheck %s --check-prefix=NM1 +; RUN: llvm-nm %t21.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" + +declare void @g(...) + +define void @f() { +entry: + call void (...) @g() + ret void +} diff --git a/test/ELF/lto/timepasses.ll b/test/ELF/lto/timepasses.ll new file mode 100644 index 0000000000000..5c893e6619455 --- /dev/null +++ b/test/ELF/lto/timepasses.ll @@ -0,0 +1,15 @@ +; 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 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @patatino() { + ret void +} + +; 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/type-merge.ll b/test/ELF/lto/type-merge.ll index 98db53970b0c4..d6f196d7c3ba0 100644 --- a/test/ELF/lto/type-merge.ll +++ b/test/ELF/lto/type-merge.ll @@ -2,7 +2,7 @@ ; 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: llvm-dis < %t.lto.bc | FileCheck %s +; RUN: llvm-dis < %t.0.0.preopt.bc | FileCheck %s 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/type-merge2.ll b/test/ELF/lto/type-merge2.ll index f0931ddc9d5e5..45777a7e6a489 100644 --- a/test/ELF/lto/type-merge2.ll +++ b/test/ELF/lto/type-merge2.ll @@ -1,7 +1,7 @@ ; 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: llvm-dis %t.so.lto.bc -o - | FileCheck %s +; RUN: llvm-dis %t.so.0.0.preopt.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" diff --git a/test/ELF/lto/undefined-puts.ll b/test/ELF/lto/undefined-puts.ll index 54fb32cef4a27..07b2b4ef64145 100644 --- a/test/ELF/lto/undefined-puts.ll +++ b/test/ELF/lto/undefined-puts.ll @@ -20,7 +20,7 @@ declare i32 @printf(i8*, ...) ; Check that puts symbol is present in the dynamic symbol table and ; there's a relocation for it. ; CHECK: Dynamic Relocations { -; CHECK-NEXT: 0x13018 R_X86_64_JUMP_SLOT puts 0x0 +; CHECK-NEXT: 0x203018 R_X86_64_JUMP_SLOT puts 0x0 ; CHECK-NEXT: } ; CHECK: DynamicSymbols [ diff --git a/test/ELF/lto/unnamed-addr-comdat.ll b/test/ELF/lto/unnamed-addr-comdat.ll index c8c36de88d4cc..ed48f3ba5e04e 100644 --- a/test/ELF/lto/unnamed-addr-comdat.ll +++ b/test/ELF/lto/unnamed-addr-comdat.ll @@ -1,6 +1,6 @@ ; 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: llvm-dis %t.so.lto.bc -o - | FileCheck %s +; RUN: llvm-dis %t.so.0.2.internalize.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" diff --git a/test/ELF/lto/unnamed-addr-drop.ll b/test/ELF/lto/unnamed-addr-drop.ll new file mode 100644 index 0000000000000..9142537fe57d8 --- /dev/null +++ b/test/ELF/lto/unnamed-addr-drop.ll @@ -0,0 +1,12 @@ +; 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: llvm-dis %t.so.0.2.internalize.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" + +@foo = weak constant i32 41 + +; Check that unnamed_addr is dropped during the merge. +; CHECK: @foo = constant i32 42 diff --git a/test/ELF/lto/unnamed-addr-lib.ll b/test/ELF/lto/unnamed-addr-lib.ll index c1c31f84bc8eb..c2bc6016efd56 100644 --- a/test/ELF/lto/unnamed-addr-lib.ll +++ b/test/ELF/lto/unnamed-addr-lib.ll @@ -3,7 +3,7 @@ ; 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: llvm-dis %t.so.lto.bc -o - | FileCheck %s +; RUN: llvm-dis %t.so.0.2.internalize.bc -o - | FileCheck %s ; This documents a small limitation of lld's internalization logic. We decide ; that bar should be in the symbol table because if it is it will preempt the diff --git a/test/ELF/lto/unnamed-addr.ll b/test/ELF/lto/unnamed-addr.ll index a2c0105fd85f5..6a6dd73dad861 100644 --- a/test/ELF/lto/unnamed-addr.ll +++ b/test/ELF/lto/unnamed-addr.ll @@ -1,6 +1,6 @@ ; RUN: llvm-as %s -o %t.o ; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -save-temps -shared -; RUN: llvm-dis %t.so.lto.opt.bc -o - | FileCheck %s +; 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" diff --git a/test/ELF/lto/version-script.ll b/test/ELF/lto/version-script.ll index 11a7f073ab511..c43b443ff749b 100644 --- a/test/ELF/lto/version-script.ll +++ b/test/ELF/lto/version-script.ll @@ -2,7 +2,7 @@ ; 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: llvm-dis < %t2.lto.bc | FileCheck %s +; RUN: llvm-dis < %t2.0.0.preopt.bc | FileCheck %s ; RUN: llvm-readobj -V -dyn-symbols %t2 | FileCheck --check-prefix=DSO %s target triple = "x86_64-unknown-linux-gnu" diff --git a/test/ELF/merge-reloc.s b/test/ELF/merge-reloc.s new file mode 100644 index 0000000000000..2447e3e9444ff --- /dev/null +++ b/test/ELF/merge-reloc.s @@ -0,0 +1,92 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -r -o %t-rel +# RUN: llvm-readobj -s -section-data %t-rel | FileCheck %s + +# When linker generates a relocatable object it should keep "merge" +# sections as-is: do not merge content, do not join regular and +# "merge" sections, do not joint "merge" sections with different +# entry size. + +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .data +# 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: 12 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 4 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 42000000 42000000 42000000 +# CHECK-NEXT: ) +# CHECK-NEXT: } +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .data +# 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: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 8 +# CHECK-NEXT: EntrySize: 8 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 42000000 42000000 42000000 42000000 +# CHECK-NEXT: ) +# CHECK-NEXT: } +# CHECK: Section { +# CHECK: Index: +# CHECK: Name: .data +# 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: 16 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 1 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 42000000 42000000 42000000 42000000 +# CHECK-NEXT: ) +# CHECK-NEXT: } + + .section .data.1,"aM",@progbits,4 + .align 4 + .global foo +foo: + .long 0x42 + .long 0x42 + .long 0x42 + + .section .data.2,"aM",@progbits,8 + .align 8 + .global bar +bar: + .long 0x42 + .long 0x42 + .long 0x42 + .long 0x42 + + .data + .global gar +zed: + .long 0x42 + .long 0x42 + .long 0x42 + .long 0x42 diff --git a/test/ELF/merge-string-empty.s b/test/ELF/merge-string-empty.s new file mode 100644 index 0000000000000..0b82ce700a2c4 --- /dev/null +++ b/test/ELF/merge-string-empty.s @@ -0,0 +1,12 @@ +// 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 + +.globl _start, s +.section .rodata.str1.1,"aMS",@progbits,1 +s: +.text +_start: + .quad s diff --git a/test/ELF/merge-string-error.s b/test/ELF/merge-string-error.s index c5088acf63b62..78895cecca9ce 100644 --- a/test/ELF/merge-string-error.s +++ b/test/ELF/merge-string-error.s @@ -8,4 +8,4 @@ .data .long .rodata.str1.1 + 4 -// CHECK: entry is past the end of the section +// CHECK: merge-string-error.s.tmp.o:(.rodata.str1.1): entry is past the end of the section diff --git a/test/ELF/merge-string.s b/test/ELF/merge-string.s index 2ad8afa53d6ef..ffcafdea28a4a 100644 --- a/test/ELF/merge-string.s +++ b/test/ELF/merge-string.s @@ -61,8 +61,6 @@ zed: // NOMERGE-NEXT: Type: SHT_PROGBITS // NOMERGE-NEXT: Flags [ // NOMERGE-NEXT: SHF_ALLOC -// NOMERGE-NEXT: SHF_MERGE -// NOMERGE-NEXT: SHF_STRINGS // NOMERGE-NEXT: ] // NOMERGE-NEXT: Address: 0x1C8 // NOMERGE-NEXT: Offset: 0x1C8 diff --git a/test/ELF/merge.s b/test/ELF/merge.s index 5039ec2251c01..b84d33a3411e4 100644 --- a/test/ELF/merge.s +++ b/test/ELF/merge.s @@ -23,7 +23,7 @@ zed: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_MERGE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x10120 +// CHECK-NEXT: Address: 0x200120 // CHECK-NEXT: Offset: 0x120 // CHECK-NEXT: Size: 8 // CHECK-NEXT: Link: 0 @@ -35,13 +35,13 @@ zed: // CHECK-NEXT: ) -// Address of the constant 0x10 = 0x10120 = 65824 -// Address of the constant 0x42 = 0x10124 = 65828 +// Address of the constant 0x10 = 0x200120 = 2097440 +// Address of the constant 0x42 = 0x200124 = 2097444 // CHECK: Symbols [ // CHECK: Name: bar -// CHECK-NEXT: Value: 0x10124 +// CHECK-NEXT: Value: 0x200124 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Loca // CHECK-NEXT: Type: None @@ -49,7 +49,7 @@ zed: // CHECK-NEXT: Section: .mysec // CHECK: Name: zed -// CHECK-NEXT: Value: 0x10124 +// CHECK-NEXT: Value: 0x200124 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -57,7 +57,7 @@ zed: // CHECK-NEXT: Section: .mysec // CHECK: Name: foo -// CHECK-NEXT: Value: 0x10124 +// CHECK-NEXT: Value: 0x200124 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -75,37 +75,37 @@ _start: // DISASM-NEXT: _start: movl .mysec, %eax -// addr(0x10) = 65824 -// DISASM-NEXT: movl 65824, %eax +// addr(0x10) = 2097440 +// DISASM-NEXT: movl 2097440, %eax movl .mysec+7, %eax -// addr(0x42) + 3 = 65828 + 3 = 65831 -// DISASM-NEXT: movl 65831, %eax +// addr(0x42) + 3 = 2097444 + 3 = 2097447 +// DISASM-NEXT: movl 2097447, %eax movl .mysec+8, %eax -// addr(0x42) = 65828 -// DISASM-NEXT: movl 65828, %eax +// addr(0x42) = 2097444 +// DISASM-NEXT: movl 2097444, %eax movl bar+7, %eax -// addr(0x42) + 7 = 65828 + 7 = 65835 -// DISASM-NEXT: movl 65835, %eax +// addr(0x42) + 7 = 2097444 + 7 = 2097451 +// DISASM-NEXT: movl 2097451, %eax movl bar+8, %eax -// addr(0x42) + 8 = 65828 + 8 = 65836 -// DISASM-NEXT: movl 65836, %eax +// addr(0x42) + 8 = 2097444 + 8 = 2097452 +// DISASM-NEXT: movl 2097452, %eax movl foo, %eax -// addr(0x42) = 65828 -// DISASM-NEXT: movl 65828, %eax +// addr(0x42) = 2097444 +// DISASM-NEXT: movl 2097444, %eax movl foo+7, %eax -// addr(0x42) + 7 = = 65828 + 7 = 65835 -// DISASM-NEXT: movl 65835, %eax +// addr(0x42) + 7 = = 2097444 + 7 = 2097451 +// DISASM-NEXT: movl 2097451, %eax movl foo+8, %eax -// addr(0x42) + 8 = = 65828 + 8 = 65836 -// DISASM-NEXT: movl 65836, %eax +// addr(0x42) + 8 = = 2097444 + 8 = 2097452 +// DISASM-NEXT: movl 2097452, %eax // From the other file: movl .mysec, %eax -// addr(0x42) = 65828 -// DISASM-NEXT: movl 65828, %eax +// addr(0x42) = 2097444 +// DISASM-NEXT: movl 2097444, %eax diff --git a/test/ELF/mips-26-mask.s b/test/ELF/mips-26-mask.s new file mode 100644 index 0000000000000..4cf56cfe338c7 --- /dev/null +++ b/test/ELF/mips-26-mask.s @@ -0,0 +1,16 @@ +# 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 + + .text + .global __start +__start: + jal __start+0x8000000 diff --git a/test/ELF/mips-32.s b/test/ELF/mips-32.s index 7875c48d64d7f..8801bcf91f48b 100644 --- a/test/ELF/mips-32.s +++ b/test/ELF/mips-32.s @@ -52,10 +52,11 @@ v2: # REL-NEXT: } # REL-NEXT: ] -# REL: DynamicSection [ -# REL: Tag Type Name/Value -# REL: 0x00000012 RELSZ 16 (bytes) -# REL: 0x00000013 RELENT 8 (bytes) +# REL: DynamicSection [ +# REL: Tag Type Name/Value +# REL: 0x00000012 RELSZ 16 (bytes) +# REL: 0x00000013 RELENT 8 (bytes) +# REL-NOT: 0x6FFFFFFA RELCOUNT # REL: Primary GOT { # REL-NEXT: Canonical gp value: diff --git a/test/ELF/mips-64-disp.s b/test/ELF/mips-64-disp.s index 1c66ba4fb9a18..95568071a07f7 100644 --- a/test/ELF/mips-64-disp.s +++ b/test/ELF/mips-64-disp.s @@ -18,7 +18,7 @@ # CHECK-NEXT: 20010: 24 42 80 38 addiu $2, $2, -32712 # CHECK: 0000000000020014 .text 00000000 foo -# CHECK: 0000000000037ff0 .got 00000000 .hidden _gp +# CHECK: 0000000000037ff0 *ABS* 00000000 .hidden _gp # CHECK: 0000000000020000 .text 00000000 __start # CHECK: 0000000000000000 g F *UND* 00000000 foo1a diff --git a/test/ELF/mips-64-got.s b/test/ELF/mips-64-got.s index 52ce6fb4d3517..f489b4451b61f 100644 --- a/test/ELF/mips-64-got.s +++ b/test/ELF/mips-64-got.s @@ -14,12 +14,12 @@ # CHECK-NEXT: 20000: df 82 80 20 ld $2, -32736($gp) # CHECK-NEXT: 20004: 64 42 00 18 daddiu $2, $2, 24 -# CHECK-NEXT: 20008: 24 42 80 38 addiu $2, $2, -32712 -# CHECK-NEXT: 2000c: 24 42 80 28 addiu $2, $2, -32728 -# CHECK-NEXT: 20010: 24 42 80 30 addiu $2, $2, -32720 +# CHECK-NEXT: 20008: 24 42 80 40 addiu $2, $2, -32704 +# CHECK-NEXT: 2000c: 24 42 80 30 addiu $2, $2, -32720 +# CHECK-NEXT: 20010: 24 42 80 38 addiu $2, $2, -32712 # CHECK: 0000000000020018 .text 00000000 foo -# CHECK: 0000000000037ff0 .got 00000000 .hidden _gp +# CHECK: 0000000000037ff0 *ABS* 00000000 .hidden _gp # CHECK: 0000000000020000 .text 00000000 __start # CHECK: 0000000000020014 .text 00000000 bar @@ -50,18 +50,23 @@ # GOT-NEXT: Entry { # GOT-NEXT: Address: 0x30018 # GOT-NEXT: Access: -32728 -# GOT-NEXT: Initial: 0x20014 +# GOT-NEXT: Initial: 0x30000 # GOT-NEXT: } # GOT-NEXT: Entry { # GOT-NEXT: Address: 0x30020 # GOT-NEXT: Access: -32720 +# GOT-NEXT: Initial: 0x20014 +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x30028 +# GOT-NEXT: Access: -32712 # GOT-NEXT: Initial: 0x20018 # GOT-NEXT: } # GOT-NEXT: ] # GOT-NEXT: Global entries [ # GOT-NEXT: Entry { -# GOT-NEXT: Address: 0x30028 -# GOT-NEXT: Access: -32712 +# GOT-NEXT: Address: 0x30030 +# GOT-NEXT: Access: -32704 # GOT-NEXT: Initial: 0x0 # GOT-NEXT: Value: 0x0 # GOT-NEXT: Type: Function diff --git a/test/ELF/mips-64-gprel-so.s b/test/ELF/mips-64-gprel-so.s index 437238ef5f269..a390ec082b1b8 100644 --- a/test/ELF/mips-64-gprel-so.s +++ b/test/ELF/mips-64-gprel-so.s @@ -12,7 +12,7 @@ # CHECK-NEXT: 10004: 03 99 e0 2d daddu $gp, $gp, $25 # CHECK-NEXT: 10008: 67 9c 7f f0 daddiu $gp, $gp, 32752 -# CHECK: 0000000000027ff0 .got 00000000 .hidden _gp +# CHECK: 0000000000027ff0 *ABS* 00000000 .hidden _gp # CHECK: 0000000000010000 .text 00000000 foo .text diff --git a/test/ELF/mips-64-rels.s b/test/ELF/mips-64-rels.s index 7126afc1e5958..b9a3ee7384855 100644 --- a/test/ELF/mips-64-rels.s +++ b/test/ELF/mips-64-rels.s @@ -24,7 +24,7 @@ # ^-- 0x20004 - 0x37ff0 = 0xfffffffffffe8014 # CHECK: 0000000000020004 .text 00000000 loc -# CHECK: 0000000000037ff0 .got 00000000 .hidden _gp +# CHECK: 0000000000037ff0 *ABS* 00000000 .hidden _gp # CHECK: 0000000000020000 .text 00000000 __start # REL: Relocations [ diff --git a/test/ELF/mips-align-err.s b/test/ELF/mips-align-err.s index 28b192ac29f31..0c71ffba8cb96 100644 --- a/test/ELF/mips-align-err.s +++ b/test/ELF/mips-align-err.s @@ -4,7 +4,7 @@ # 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 -# CHECK: improper alignment for relocation R_MIPS_PC16 +# CHECK: {{.*}}:(.text+0x1): improper alignment for relocation R_MIPS_PC16 .globl __start __start: diff --git a/test/ELF/mips-call-hilo.s b/test/ELF/mips-call-hilo.s new file mode 100644 index 0000000000000..2504612f9e34c --- /dev/null +++ b/test/ELF/mips-call-hilo.s @@ -0,0 +1,62 @@ +# Check R_MIPS_CALL_HI16 / R_MIPS_CALL_LO16 relocations calculation. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -shared -o %t.so +# 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 +# CHECK-NEXT: 10004: 8c 42 80 20 lw $2, -32736($2) +# CHECK-NEXT: 10008: 3c 02 00 00 lui $2, 0 +# CHECK-NEXT: 1000c: 8c 42 80 18 lw $2, -32744($2) +# CHECK-NEXT: 10010: 3c 02 00 00 lui $2, 0 +# CHECK-NEXT: 10014: 8c 42 80 1c lw $2, -32740($2) + +# GOT: Relocations [ +# GOT-NEXT: ] + +# GOT: Primary GOT { +# GOT-NEXT: Canonical gp value: 0x27FF0 +# GOT: Local entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x20008 +# GOT-NEXT: Access: -32744 +# GOT-NEXT: Initial: 0x10018 +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x2000C +# GOT-NEXT: Access: -32740 +# GOT-NEXT: Initial: 0x1001C +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Global entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x20010 +# GOT-NEXT: Access: -32736 +# GOT-NEXT: Initial: 0x0 +# GOT-NEXT: Value: 0x0 +# GOT-NEXT: Type: None +# GOT-NEXT: Section: Undefined +# GOT-NEXT: Name: bar +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Number of TLS and multi-GOT entries: 0 +# GOT-NEXT: } + + .text + .global foo +foo: + lui $2, %call_hi(bar) + lw $2, %call_lo(bar)($2) + lui $2, %call_hi(loc1) + lw $2, %call_lo(loc1)($2) + lui $2, %call_hi(loc2) + lw $2, %call_lo(loc2)($2) +loc1: + nop +loc2: + nop diff --git a/test/ELF/mips-elf-flags-err.s b/test/ELF/mips-elf-flags-err.s new file mode 100644 index 0000000000000..eab8377b17e26 --- /dev/null +++ b/test/ELF/mips-elf-flags-err.s @@ -0,0 +1,87 @@ +# Check MIPS ELF ISA flag calculation if input files have different ISAs. + +# 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=mips32r2 %s -o %t2.o +# RUN: ld.lld %t1.o %t2.o -o %t.exe +# RUN: llvm-readobj -h %t.exe | FileCheck -check-prefix=R1R2 %s + +# Check that lld does not allow to link incompatible ISAs. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: -mcpu=mips3 %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=R3R32 %s + +# Check that lld does not allow to link incompatible ISAs. + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ +# RUN: -mcpu=mips64r6 %S/Inputs/mips-dynamic.s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ +# RUN: -mcpu=octeon %s -o %t2.o +# 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 \ +# RUN: -mcpu=mips64 %S/Inputs/mips-dynamic.s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ +# RUN: -mcpu=octeon %s -o %t2.o +# 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 +__start: + nop + +# R1R2: Flags [ +# R1R2-NEXT: EF_MIPS_ABI_O32 +# R1R2-NEXT: EF_MIPS_ARCH_32R2 +# R1R2-NEXT: EF_MIPS_CPIC +# R1R2-NEXT: ] + +# R3R32: target ISA 'mips3' is incompatible with 'mips32': {{.*}}mips-elf-flags-err.s.tmp2.o +# R6OCTEON: target ISA 'mips64r6' is incompatible with 'octeon': {{.*}}mips-elf-flags-err.s.tmp2.o +# 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-NEXT: EF_MIPS_PIC +# OCTEON-NEXT: ] + +# 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.s b/test/ELF/mips-elf-flags.s index 7817e58b53838..26dc42ded546a 100644 --- a/test/ELF/mips-elf-flags.s +++ b/test/ELF/mips-elf-flags.s @@ -1,10 +1,39 @@ # Check generation of MIPS specific ELF header flags. +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: %S/Inputs/mips-dynamic.s -o %t-so.o +# RUN: ld.lld %t-so.o -shared -o %t.so +# RUN: llvm-readobj -h -mips-abi-flags %t.so | FileCheck -check-prefix=SO %s + # 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 -h %t.so | FileCheck -check-prefix=SO %s # RUN: ld.lld %t.o -o %t.exe -# RUN: llvm-readobj -h %t.exe | FileCheck -check-prefix=EXE %s +# RUN: llvm-readobj -h -mips-abi-flags %t.exe | FileCheck -check-prefix=EXE %s + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: -mcpu=mips32r2 %s -o %t-r2.o +# RUN: ld.lld %t-r2.o -o %t-r2.exe +# RUN: llvm-readobj -h -mips-abi-flags %t-r2.exe \ +# RUN: | FileCheck -check-prefix=EXE-R2 %s + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: -mcpu=mips32r2 %s -o %t-r2.o +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: -mcpu=mips32r5 %S/Inputs/mips-dynamic.s -o %t-r5.o +# RUN: ld.lld %t-r2.o %t-r5.o -o %t-r5.exe +# RUN: llvm-readobj -h -mips-abi-flags %t-r5.exe \ +# RUN: | FileCheck -check-prefix=EXE-R5 %s + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: -mcpu=mips32r6 %s -o %t-r6.o +# RUN: ld.lld %t-r6.o -o %t-r6.exe +# RUN: llvm-readobj -h -mips-abi-flags %t-r6.exe \ +# RUN: | FileCheck -check-prefix=EXE-R6 %s + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ +# RUN: -mcpu=octeon %s -o %t.o +# RUN: ld.lld %t.o -o %t.exe +# RUN: llvm-readobj -h -mips-abi-flags %t.exe \ +# RUN: | FileCheck -check-prefix=OCTEON %s # REQUIRES: mips @@ -15,13 +44,129 @@ __start: # SO: Flags [ # SO-NEXT: EF_MIPS_ABI_O32 -# SO-NEXT: EF_MIPS_ARCH_32R2 +# SO-NEXT: EF_MIPS_ARCH_32 # SO-NEXT: EF_MIPS_CPIC # SO-NEXT: EF_MIPS_PIC # SO-NEXT: ] +# SO: MIPS ABI Flags { +# SO-NEXT: Version: 0 +# SO-NEXT: ISA: MIPS32 +# SO-NEXT: ISA Extension: None +# SO-NEXT: ASEs [ +# SO-NEXT: ] +# SO-NEXT: FP ABI: Hard float (double precision) +# SO-NEXT: GPR size: 32 +# SO-NEXT: CPR1 size: 32 +# SO-NEXT: CPR2 size: 0 +# SO-NEXT: Flags 1 [ +# SO-NEXT: ODDSPREG +# SO-NEXT: ] +# SO-NEXT: Flags 2: 0x0 +# SO-NEXT: } # EXE: Flags [ # EXE-NEXT: EF_MIPS_ABI_O32 -# EXE-NEXT: EF_MIPS_ARCH_32R2 +# EXE-NEXT: EF_MIPS_ARCH_32 # EXE-NEXT: EF_MIPS_CPIC # EXE-NEXT: ] +# EXE: MIPS ABI Flags { +# EXE-NEXT: Version: 0 +# EXE-NEXT: ISA: MIPS32 +# EXE-NEXT: ISA Extension: None +# EXE-NEXT: ASEs [ +# EXE-NEXT: ] +# EXE-NEXT: FP ABI: Hard float (double precision) +# EXE-NEXT: GPR size: 32 +# EXE-NEXT: CPR1 size: 32 +# EXE-NEXT: CPR2 size: 0 +# EXE-NEXT: Flags 1 [ +# EXE-NEXT: ODDSPREG +# EXE-NEXT: ] +# EXE-NEXT: Flags 2: 0x0 +# EXE-NEXT: } + +# EXE-R2: Flags [ +# EXE-R2-NEXT: EF_MIPS_ABI_O32 +# EXE-R2-NEXT: EF_MIPS_ARCH_32R2 +# EXE-R2-NEXT: EF_MIPS_CPIC +# EXE-R2-NEXT: ] +# EXE-R2: MIPS ABI Flags { +# EXE-R2-NEXT: Version: 0 +# EXE-R2-NEXT: ISA: MIPS32r2 +# EXE-R2-NEXT: ISA Extension: None +# EXE-R2-NEXT: ASEs [ +# EXE-R2-NEXT: ] +# EXE-R2-NEXT: FP ABI: Hard float (double precision) +# EXE-R2-NEXT: GPR size: 32 +# EXE-R2-NEXT: CPR1 size: 32 +# EXE-R2-NEXT: CPR2 size: 0 +# EXE-R2-NEXT: Flags 1 [ +# EXE-R2-NEXT: ODDSPREG +# EXE-R2-NEXT: ] +# EXE-R2-NEXT: Flags 2: 0x0 +# EXE-R2-NEXT: } + +# EXE-R5: Flags [ +# EXE-R5-NEXT: EF_MIPS_ABI_O32 +# EXE-R5-NEXT: EF_MIPS_ARCH_32R2 +# EXE-R5-NEXT: EF_MIPS_CPIC +# EXE-R5-NEXT: ] +# EXE-R5: MIPS ABI Flags { +# EXE-R5-NEXT: Version: 0 +# EXE-R5-NEXT: ISA: MIPS32r5 +# EXE-R5-NEXT: ISA Extension: None +# EXE-R5-NEXT: ASEs [ +# EXE-R5-NEXT: ] +# EXE-R5-NEXT: FP ABI: Hard float (double precision) +# EXE-R5-NEXT: GPR size: 32 +# EXE-R5-NEXT: CPR1 size: 32 +# EXE-R5-NEXT: CPR2 size: 0 +# EXE-R5-NEXT: Flags 1 [ +# EXE-R5-NEXT: ODDSPREG +# EXE-R5-NEXT: ] +# EXE-R5-NEXT: Flags 2: 0x0 +# EXE-R5-NEXT: } + +# EXE-R6: Flags [ +# EXE-R6-NEXT: EF_MIPS_ABI_O32 +# EXE-R6-NEXT: EF_MIPS_ARCH_32R6 +# EXE-R6-NEXT: EF_MIPS_CPIC +# EXE-R6-NEXT: EF_MIPS_NAN2008 +# EXE-R6-NEXT: ] +# EXE-R6: MIPS ABI Flags { +# EXE-R6-NEXT: Version: 0 +# EXE-R6-NEXT: ISA: MIPS32 +# EXE-R6-NEXT: ISA Extension: None +# EXE-R6-NEXT: ASEs [ +# EXE-R6-NEXT: ] +# EXE-R6-NEXT: FP ABI: Hard float (32-bit CPU, 64-bit FPU) +# EXE-R6-NEXT: GPR size: 32 +# EXE-R6-NEXT: CPR1 size: 64 +# EXE-R6-NEXT: CPR2 size: 0 +# EXE-R6-NEXT: Flags 1 [ +# EXE-R6-NEXT: ODDSPREG +# EXE-R6-NEXT: ] +# EXE-R6-NEXT: Flags 2: 0x0 +# EXE-R6-NEXT: } + +# OCTEON: Flags [ +# OCTEON-NEXT: EF_MIPS_ARCH_64R2 +# OCTEON-NEXT: EF_MIPS_CPIC +# OCTEON-NEXT: EF_MIPS_MACH_OCTEON +# OCTEON-NEXT: EF_MIPS_PIC +# OCTEON-NEXT: ] +# OCTEON: MIPS ABI Flags { +# OCTEON-NEXT: Version: 0 +# OCTEON-NEXT: ISA: MIPS64r2 +# OCTEON-NEXT: ISA Extension: Cavium Networks Octeon +# OCTEON-NEXT: ASEs [ +# OCTEON-NEXT: ] +# OCTEON-NEXT: FP ABI: Hard float (double precision) +# OCTEON-NEXT: GPR size: 64 +# OCTEON-NEXT: CPR1 size: 64 +# OCTEON-NEXT: CPR2 size: 0 +# OCTEON-NEXT: Flags 1 [ +# OCTEON-NEXT: ODDSPREG +# OCTEON-NEXT: ] +# OCTEON-NEXT: Flags 2: 0x0 +# OCTEON-NEXT: } diff --git a/test/ELF/mips-got-and-copy.s b/test/ELF/mips-got-and-copy.s index 453b8c957b56d..f42b39c6d51d8 100644 --- a/test/ELF/mips-got-and-copy.s +++ b/test/ELF/mips-got-and-copy.s @@ -37,7 +37,7 @@ # CHECK-NEXT: Value: 0x40014 # CHECK-NEXT: Type: Object (0x1) # CHECK-NEXT: Section: .bss (0xD) -# CHECK-NEXT: Name: data1@ (7) +# CHECK-NEXT: Name: data1@ # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: Number of TLS and multi-GOT entries: 0 diff --git a/test/ELF/mips-got-hilo.s b/test/ELF/mips-got-hilo.s new file mode 100644 index 0000000000000..7e6945fd2b62b --- /dev/null +++ b/test/ELF/mips-got-hilo.s @@ -0,0 +1,64 @@ +# Check R_MIPS_GOT_HI16 / R_MIPS_GOT_LO16 relocations calculation. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -shared -o %t.so +# 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 +# CHECK-NEXT: 10004: 8c 42 80 20 lw $2, -32736($2) +# CHECK-NEXT: 10008: 3c 02 00 00 lui $2, 0 +# CHECK-NEXT: 1000c: 8c 42 80 18 lw $2, -32744($2) +# CHECK-NEXT: 10010: 3c 02 00 00 lui $2, 0 +# CHECK-NEXT: 10014: 8c 42 80 1c lw $2, -32740($2) + +# GOT: Relocations [ +# GOT-NEXT: ] + +# GOT: Primary GOT { +# GOT-NEXT: Canonical gp value: 0x27FF0 +# GOT: Local entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x20008 +# GOT-NEXT: Access: -32744 +# GOT-NEXT: Initial: 0x30000 +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x2000C +# GOT-NEXT: Access: -32740 +# GOT-NEXT: Initial: 0x30004 +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Global entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x20010 +# GOT-NEXT: Access: -32736 +# GOT-NEXT: Initial: 0x0 +# GOT-NEXT: Value: 0x0 +# GOT-NEXT: Type: None +# GOT-NEXT: Section: Undefined +# GOT-NEXT: Name: bar +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Number of TLS and multi-GOT entries: 0 +# GOT-NEXT: } + + .text + .global foo +foo: + lui $2, %got_hi(bar) + lw $2, %got_lo(bar)($2) + lui $2, %got_hi(loc1) + lw $2, %got_lo(loc1)($2) + lui $2, %got_hi(loc2) + lw $2, %got_lo(loc2)($2) + + .data +loc1: + .word 0 +loc2: + .word 0 diff --git a/test/ELF/mips-got-page.s b/test/ELF/mips-got-page.s new file mode 100644 index 0000000000000..e2dc485ba661e --- /dev/null +++ b/test/ELF/mips-got-page.s @@ -0,0 +1,40 @@ +# 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. + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux -o %t.o %s +# 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 + +# CHECK: Name: foo +# CHECK-NEXT: Value: 0x27FFC +# ^ page-address = (0x27ffc + 0x8000) & ~0xffff = 0x20000 + +# CHECK: Local entries [ +# CHECK-NEXT: Entry { +# CHECK-NEXT: Address: +# CHECK-NEXT: Access: -32736 +# CHECK-NEXT: Initial: 0x20000 +# CHECK-NEXT: } +# CHECK-NEXT: Entry { +# CHECK-NEXT: Address: +# CHECK-NEXT: Access: -32728 +# CHECK-NEXT: Initial: 0x30000 +# CHECK-NEXT: } +# CHECK-NEXT: ] + + .text + ld $v0,%got_page(foo)($gp) + ld $v0,%got_page(bar)($gp) + + .rodata +foo: + .word 0 +bar: + .word 0 diff --git a/test/ELF/mips-got-redundant.s b/test/ELF/mips-got-redundant.s index 07c3c249f4fa9..115a49f357ddb 100644 --- a/test/ELF/mips-got-redundant.s +++ b/test/ELF/mips-got-redundant.s @@ -22,6 +22,12 @@ # CHECK-NEXT: Entry { # CHECK-NEXT: Address: 0x20010 # CHECK-NEXT: Access: -32736 +# CHECK-NEXT: Initial: 0x50000 +# ^-- redundant +# CHECK-NEXT: } +# CHECK-NEXT: Entry { +# CHECK-NEXT: Address: 0x20014 +# CHECK-NEXT: Access: -32732 # CHECK-NEXT: Initial: 0x40008 # ^-- glb1 # CHECK-NEXT: } diff --git a/test/ELF/mips-got-relocs.s b/test/ELF/mips-got-relocs.s index c44cf90b7be3b..19c0db49a440b 100644 --- a/test/ELF/mips-got-relocs.s +++ b/test/ELF/mips-got-relocs.s @@ -47,7 +47,7 @@ v1: # EXE_SYM: Sections: # EXE_SYM: .got 0000000c 0000000000030000 DATA # EXE_SYM: SYMBOL TABLE: -# EXE_SYM: 00037ff0 .got 00000000 .hidden _gp +# EXE_SYM: 00037ff0 *ABS* 00000000 .hidden _gp # ^-- .got + GP offset (0x7ff0) # EXE_SYM: 00040000 g .data 00000004 v1 @@ -71,7 +71,7 @@ v1: # DSO_SYM: Sections: # DSO_SYM: .got 0000000c 0000000000020000 DATA # DSO_SYM: SYMBOL TABLE: -# DSO_SYM: 00027ff0 .got 00000000 .hidden _gp +# DSO_SYM: 00027ff0 *ABS* 00000000 .hidden _gp # ^-- .got + GP offset (0x7ff0) # DSO_SYM: 00030000 g .data 00000004 v1 diff --git a/test/ELF/mips-got16.s b/test/ELF/mips-got16.s index ef80418ef0329..c4c14e46607c3 100644 --- a/test/ELF/mips-got16.s +++ b/test/ELF/mips-got16.s @@ -11,15 +11,15 @@ # CHECK-NEXT: __start: # CHECK-NEXT: 10000: 8f 88 80 18 lw $8, -32744($gp) # CHECK-NEXT: 10004: 21 08 00 2c addi $8, $8, 44 -# CHECK-NEXT: 10008: 8f 88 80 1c lw $8, -32740($gp) +# CHECK-NEXT: 10008: 8f 88 80 24 lw $8, -32732($gp) # CHECK-NEXT: 1000c: 21 08 90 00 addi $8, $8, -28672 -# CHECK-NEXT: 10010: 8f 88 80 20 lw $8, -32736($gp) +# CHECK-NEXT: 10010: 8f 88 80 28 lw $8, -32728($gp) # CHECK-NEXT: 10014: 21 08 90 04 addi $8, $8, -28668 -# CHECK-NEXT: 10018: 8f 88 80 20 lw $8, -32736($gp) +# CHECK-NEXT: 10018: 8f 88 80 28 lw $8, -32728($gp) # CHECK-NEXT: 1001c: 21 08 10 04 addi $8, $8, 4100 -# CHECK-NEXT: 10020: 8f 88 80 28 lw $8, -32728($gp) +# CHECK-NEXT: 10020: 8f 88 80 30 lw $8, -32720($gp) # CHECK-NEXT: 10024: 21 08 10 08 addi $8, $8, 4104 -# CHECK-NEXT: 10028: 8f 88 80 2c lw $8, -32724($gp) +# CHECK-NEXT: 10028: 8f 88 80 34 lw $8, -32716($gp) # # CHECK: SYMBOL TABLE: # CHECK: 00051008 .data 00000000 .hidden bar @@ -54,33 +54,45 @@ # GOT-NEXT: Entry { # GOT-NEXT: Address: 0x2000C # GOT-NEXT: Access: -32740 -# GOT-NEXT: Initial: 0x40000 -# ^-- (0x39000 + 0x8000) & ~0xffff +# GOT-NEXT: Initial: 0x20000 +# ^-- redundant unused entry # GOT-NEXT: } # GOT-NEXT: Entry { # GOT-NEXT: Address: 0x20010 # GOT-NEXT: Access: -32736 +# GOT-NEXT: Initial: 0x30000 +# ^-- redundant unused entry +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x20014 +# GOT-NEXT: Access: -32732 +# GOT-NEXT: Initial: 0x40000 +# ^-- (0x39000 + 0x8000) & ~0xffff +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x20018 +# GOT-NEXT: Access: -32728 # GOT-NEXT: Initial: 0x50000 # ^-- (0x39000 + 0x10004 + 0x8000) & ~0xffff # ^-- (0x39000 + 0x18004 + 0x8000) & ~0xffff # GOT-NEXT: } # GOT-NEXT: Entry { -# GOT-NEXT: Address: 0x20014 -# GOT-NEXT: Access: -32732 -# GOT-NEXT: Initial: 0x0 +# GOT-NEXT: Address: 0x2001C +# GOT-NEXT: Access: -32724 +# GOT-NEXT: Initial: 0x60000 # ^-- redundant unused entry # GOT-NEXT: } # GOT-NEXT: Entry { -# GOT-NEXT: Address: 0x20018 -# GOT-NEXT: Access: -327 +# GOT-NEXT: Address: 0x20020 +# GOT-NEXT: Access: -32720 # GOT-NEXT: Initial: 0x51008 # ^-- 'bar' address # GOT-NEXT: } # GOT-NEXT: ] # GOT-NEXT: Global entries [ # GOT-NEXT: Entry { -# GOT-NEXT: Address: 0x2001C -# GOT-NEXT: Access: -32724 +# GOT-NEXT: Address: 0x20024 +# GOT-NEXT: Access: -32716 # GOT-NEXT: Initial: 0x0 # GOT-NEXT: Value: 0x0 # GOT-NEXT: Type: None diff --git a/test/ELF/mips-gp-disp.s b/test/ELF/mips-gp-disp.s index 7a0fd6409d18b..62a2b1084530e 100644 --- a/test/ELF/mips-gp-disp.s +++ b/test/ELF/mips-gp-disp.s @@ -24,7 +24,7 @@ # DIS-NEXT: 10000: 3c 08 00 01 lui $8, 1 # DIS-NEXT: 10004: 21 08 7f f0 addi $8, $8, 32752 # ^-- 0x37ff0 & 0xffff -# DIS: 00027ff0 .got 00000000 .hidden _gp +# DIS: 00027ff0 *ABS* 00000000 .hidden _gp # REL: Relocations [ # REL-NEXT: ] diff --git a/test/ELF/mips-gp-ext.s b/test/ELF/mips-gp-ext.s new file mode 100644 index 0000000000000..b6c49e0fd422e --- /dev/null +++ b/test/ELF/mips-gp-ext.s @@ -0,0 +1,73 @@ +# Check that the linker use a value of _gp symbol defined +# in a linker script to calculate GOT relocations. + +# FIXME: This test is xfailed because it depends on D27276 patch +# that enables absolute symbols redefinition by a linker's script. +# XFAIL: * + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o + +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.text) } \ +# RUN: _gp = . + 0x100; \ +# RUN: .got : { *(.got) } }" > %t.rel.script +# RUN: ld.lld -shared -o %t.rel.so --script %t.rel.script %t.o +# RUN: llvm-objdump -s -t %t.rel.so | FileCheck --check-prefix=REL %s + +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.text) } \ +# RUN: _gp = 0x200; \ +# RUN: .got : { *(.got) } }" > %t.abs.script +# 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 .text: +# REL-NEXT: 0000 3c080000 2108010c 8f82ffe4 +# ^-- %hi(_gp_disp) +# ^-- %lo(_gp_disp) +# ^-- 8 - (0x10c - 0xe8) +# 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: 0100 fffffef4 +# ^-- 0-0x10c + +# REL: 00000000 .text 00000000 foo +# REL: 0000010c *ABS* 00000000 .hidden _gp_disp +# REL: 0000010c *ABS* 00000000 .hidden _gp + +# ABS: Contents of section .text: +# ABS-NEXT: 0000 3c080000 21080200 8f82fef0 +# ^-- %hi(_gp_disp) +# ^-- %lo(_gp_disp) +# ^-- 8 - (0x200 - 0xe8) +# 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: 0100 fffffe00 +# ^-- 0-0x200 + +# ABS: 00000000 .text 00000000 foo +# ABS: 00000200 *ABS* 00000000 .hidden _gp_disp +# ABS: 00000200 *ABS* 00000000 .hidden _gp + + .text +foo: + lui $t0, %hi(_gp_disp) + addi $t0, $t0, %lo(_gp_disp) + lw $v0, %call16(bar)($gp) + + .data + .gpword foo diff --git a/test/ELF/mips-gp-local.s b/test/ELF/mips-gp-local.s index 8bb3c236edf0e..b77dbb8367aec 100644 --- a/test/ELF/mips-gp-local.s +++ b/test/ELF/mips-gp-local.s @@ -11,7 +11,7 @@ # CHECK-NEXT: 20000: 3c 08 00 03 lui $8, 3 # CHECK-NEXT: 20004: 21 08 7f f0 addi $8, $8, 32752 -# CHECK: 00037ff0 .got 00000000 .hidden _gp +# CHECK: 00037ff0 *ABS* 00000000 .hidden _gp .text .globl __start diff --git a/test/ELF/mips-gp-lowest.s b/test/ELF/mips-gp-lowest.s new file mode 100644 index 0000000000000..b3d30aa359038 --- /dev/null +++ b/test/ELF/mips-gp-lowest.s @@ -0,0 +1,44 @@ +# Check that default _gp value is calculated relative +# to the GP-relative section with the lowest address. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { \ +# RUN: .sdata : { *(.sdata) } \ +# RUN: .got : { *(.got) } }" > %t.rel.script +# 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: + lui $gp, %call16(foo) + + .sdata + .word 0 + +# CHECK: Section { +# CHECK: Name: .sdata +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_MIPS_GPREL +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0xDD +# CHECK: } +# CHECK: Section { +# CHECK: Name: .got +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: SHF_MIPS_GPREL +# CHECK-NEXT: SHF_WRITE +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0xE4 +# CHECK: } + +# CHECK: Name: _gp (5) +# CHECK-NEXT: Value: 0x80CD +# ^-- 0xDD + 0x7ff0 diff --git a/test/ELF/mips-gprel32-relocs-gp0.s b/test/ELF/mips-gprel32-relocs-gp0.s new file mode 100644 index 0000000000000..e71f8856afeea --- /dev/null +++ b/test/ELF/mips-gprel32-relocs-gp0.s @@ -0,0 +1,48 @@ +# 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 +# RUN: llvm-readobj -mips-reginfo %t-rel.o | FileCheck --check-prefix=REL %s + +# RUN: ld.lld -shared -o %t.so %S/Inputs/mips-gp0-non-zero.o +# 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 + +# DUMP: Contents of section .rodata: +# DUMP: 0114 ffff0004 ffff0008 +# ^ 0x10004 + 0x7ff0 - 0x27ff0 +# ^ 0x10008 + 0x7ff0 - 0x27ff0 + +# DUMP: SYMBOL TABLE: +# DUMP: 00010008 .text 00000000 bar +# DUMP: 00010004 .text 00000000 foo +# DUMP: 00027ff0 *ABS* 00000000 .hidden _gp + +# ERR: error: {{.*}}mips-gp0-non-zero.o: unsupported non-zero ri_gp_value + + .text + .global __start +__start: + lw $t0,%call16(__start)($gp) +foo: + nop +bar: + nop + + .section .rodata, "a" +v: + .gpword foo + .gpword bar diff --git a/test/ELF/mips-gprel32-relocs-gp0.test b/test/ELF/mips-gprel32-relocs-gp0.test deleted file mode 100644 index 6cc837ef78898..0000000000000 --- a/test/ELF/mips-gprel32-relocs-gp0.test +++ /dev/null @@ -1,31 +0,0 @@ -# Check R_MIPS_GPREL32 relocation calculation if input file conatins -# non-zero GP0 value in the .reginfo section. -# FIXME: The only way to get an object file with non-zero GP0 value -# is to link multiple object files with GOT relocations using '-r' -# option. LLD does not calculate and generate GP0 correctly so we -# use a binary input in this test. The input object file is a result -# of linking two object files with R_MIPS_GPREL32 relocations. - -# RUN: ld.lld -shared -o %t.so %S/Inputs/mips-gprel32-gp0.o -# RUN: llvm-objdump -s %S/Inputs/mips-gprel32-gp0.o \ -# RUN: | FileCheck -check-prefix=OBJ %s -# RUN: llvm-objdump -s -t %t.so | FileCheck %s - -# OBJ: Contents of section .reginfo: -# OBJ-NEXT: 0000 00000001 00000000 00000000 00000000 -# OBJ-NEXT: 0010 00000000 00007fef -# ^-- GP0 value -# OBJ: Contents of section .rodata: -# OBJ-NEXT: 0000 ffff8011 ffff8011 -# ^-- foo addend -# ^-- bar addend - -# CHECK: Contents of section .rodata: -# CHECK: 012c fffe8010 fffe8020 -# ^ 0x10000 + 0xffff8011 + 0x7fef - 0x27ff0 -# ^ 0x10010 + 0xffff8011 + 0x7fef - 0x27ff0 - -# CHECK: SYMBOL TABLE: -# CHECK: 00010000 .text 00000000 foo -# CHECK: 00010010 .text 00000000 bar -# CHECK: 00027ff0 .got 00000000 .hidden _gp diff --git a/test/ELF/mips-gprel32-relocs.s b/test/ELF/mips-gprel32-relocs.s index fa1c5cfe99566..993596deedb74 100644 --- a/test/ELF/mips-gprel32-relocs.s +++ b/test/ELF/mips-gprel32-relocs.s @@ -28,4 +28,4 @@ v1: # CHECK: SYMBOL TABLE: # CHECK: 00010008 .text 00000000 bar # CHECK: 00010004 .text 00000000 foo -# CHECK: 00027ff0 .got 00000000 .hidden _gp +# CHECK: 00027ff0 *ABS* 00000000 .hidden _gp diff --git a/test/ELF/mips-higher-highest.s b/test/ELF/mips-higher-highest.s new file mode 100644 index 0000000000000..123b51a65addc --- /dev/null +++ b/test/ELF/mips-higher-highest.s @@ -0,0 +1,21 @@ +# Check R_MIPS_HIGHER / R_MIPS_HIGHEST relocations calculation. + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ +# RUN: %S/Inputs/mips-dynamic.s -o %t2.o +# 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) + daddiu $6, $6, %higher(_foo+0x300047FFF7FF7) + lui $7, %highest(_foo+0x300047FFF7FF8) + ld $7, %higher (_foo+0x300047FFF7FF8)($7) + +# CHECK: 20000: 3c 06 00 03 lui $6, 3 +# CHECK-NEXT: 20004: 64 c6 00 05 daddiu $6, $6, 5 +# CHECK-NEXT: 20008: 3c 07 00 03 lui $7, 3 +# CHECK-NEXT: 2000c: dc e7 00 05 ld $7, 5($7) diff --git a/test/ELF/mips-hilo-gp-disp.s b/test/ELF/mips-hilo-gp-disp.s index 37cf90d9728bb..16eab06e7b88c 100644 --- a/test/ELF/mips-hilo-gp-disp.s +++ b/test/ELF/mips-hilo-gp-disp.s @@ -34,7 +34,7 @@ bar: # EXE: SYMBOL TABLE: # EXE: 0002000c .text 00000000 bar -# EXE: 00037ff0 .got 00000000 .hidden _gp +# EXE: 00037ff0 *ABS* 00000000 .hidden _gp # EXE: 00020000 .text 00000000 __start # SO: Disassembly of section .text: @@ -51,5 +51,5 @@ bar: # SO: SYMBOL TABLE: # SO: 0001000c .text 00000000 bar -# SO: 00027ff0 .got 00000000 .hidden _gp +# SO: 00027ff0 *ABS* 00000000 .hidden _gp # SO: 00010000 .text 00000000 __start diff --git a/test/ELF/mips-merge-abiflags.s b/test/ELF/mips-merge-abiflags.s new file mode 100644 index 0000000000000..2e8b43bcc3b80 --- /dev/null +++ b/test/ELF/mips-merge-abiflags.s @@ -0,0 +1,63 @@ +# 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) + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-freebsd %s -o %t.o +# RUN: ld.lld %t.o %p/Inputs/mips-concatenated-abiflags.o -o %t.exe +# RUN: llvm-readobj -sections -mips-abi-flags %t.exe | FileCheck %s +# RUN: llvm-readobj -sections -mips-abi-flags \ +# RUN: %p/Inputs/mips-concatenated-abiflags.o | \ +# RUN: FileCheck --check-prefix=INPUT-OBJECT %s + +# REQUIRES: mips + .globl __start +__start: + nop + +# CHECK: Section { +# CHECK: Index: 1 +# CHECK-NEXT: Name: .MIPS.abiflags +# CHECK-NEXT: Type: SHT_MIPS_ABIFLAGS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_ALLOC +# CHECK-NEXT: ] +# CHECK-NEXT: Address: +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 24 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 8 +# CHECK-NEXT: EntrySize: 24 +# CHECK-NEXT: } + +# CHECK: MIPS ABI Flags { +# CHECK-NEXT: Version: 0 +# CHECK-NEXT: ISA: MIPS64 +# CHECK-NEXT: ISA Extension: None +# CHECK-NEXT: ASEs [ +# CHECK-NEXT: ] +# CHECK-NEXT: FP ABI: Hard float (double precision) +# CHECK-NEXT: GPR size: 64 +# CHECK-NEXT: CPR1 size: 64 +# CHECK-NEXT: CPR2 size: 0 +# CHECK-NEXT: Flags 1 [ +# CHECK-NEXT: ODDSPREG +# CHECK-NEXT: ] +# CHECK-NEXT: Flags 2: 0x0 +# CHECK-NEXT: } + +# INPUT-OBJECT: Section { +# INPUT-OBJECT: Index: 3 +# INPUT-OBJECT-NEXT: Name: .MIPS.abiflags +# INPUT-OBJECT-NEXT: Type: SHT_MIPS_ABIFLAGS +# INPUT-OBJECT-NEXT: Flags [ +# INPUT-OBJECT-NEXT: SHF_ALLOC +# INPUT-OBJECT-NEXT: ] +# INPUT-OBJECT-NEXT: Address: +# INPUT-OBJECT-NEXT: Offset: +# INPUT-OBJECT-NEXT: Size: 48 +# INPUT-OBJECT-NEXT: Link: 0 +# INPUT-OBJECT-NEXT: Info: 0 +# INPUT-OBJECT-NEXT: AddressAlignment: 8 +# INPUT-OBJECT-NEXT: EntrySize: 0 +# INPUT-OBJECT-NEXT: } +# INPUT-OBJECT: The .MIPS.abiflags section has a wrong size. diff --git a/test/ELF/mips-n32-emul.s b/test/ELF/mips-n32-emul.s new file mode 100644 index 0000000000000..d0d81cc1c95fa --- /dev/null +++ b/test/ELF/mips-n32-emul.s @@ -0,0 +1,14 @@ +# 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 + + .text + .global __start +__start: + nop + +# CHECK: error: {{.*}}mips-n32-emul.s.tmp.o is incompatible with elf32btsmipn32 diff --git a/test/ELF/mips-n32-rels.s b/test/ELF/mips-n32-rels.s new file mode 100644 index 0000000000000..4cf72887785e2 --- /dev/null +++ b/test/ELF/mips-n32-rels.s @@ -0,0 +1,71 @@ +# 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-objdump -t -d -s %t.exe | FileCheck %s +# RUN: llvm-readobj -h %t.exe | FileCheck -check-prefix=ELF %s + +# REQUIRES: mips + +# .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 + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: __start: +# CHECK-NEXT: 20000: 3c 1c 00 01 lui $gp, 1 +# ^-- 0x20000 - 0x37ff0 +# ^-- 0 - 0xfffe8010 +# ^-- %hi(0x17ff0) +# CHECK: loc: +# CHECK-NEXT: 20004: 67 9c 7f f0 daddiu $gp, $gp, 32752 +# ^-- 0x20000 - 0x37ff0 +# ^-- 0 - 0xfffe8010 +# ^-- %lo(0x17ff0) + +# CHECK: Contents of section .rodata: +# CHECK-NEXT: 100f4 00020004 +# ^-- loc + +# CHECK: 00020004 .text 00000000 loc +# CHECK: 00037ff0 *ABS* 00000000 .hidden _gp +# CHECK: 00020000 g F .text 00000000 __start + +# ELF: Format: ELF32-mips +# ELF-NEXT: Arch: mips +# ELF-NEXT: AddressSize: 32bit +# ELF-NEXT: LoadName: +# ELF-NEXT: ElfHeader { +# ELF-NEXT: Ident { +# ELF-NEXT: Magic: (7F 45 4C 46) +# ELF-NEXT: Class: 32-bit (0x1) +# ELF-NEXT: DataEncoding: BigEndian (0x2) +# ELF-NEXT: FileVersion: 1 +# ELF-NEXT: OS/ABI: SystemV (0x0) +# ELF-NEXT: ABIVersion: 0 +# ELF-NEXT: Unused: (00 00 00 00 00 00 00) +# ELF-NEXT: } +# ELF-NEXT: Type: Executable (0x2) +# ELF-NEXT: Machine: EM_MIPS (0x8) +# ELF-NEXT: Version: 1 +# ELF-NEXT: Entry: 0x20000 +# ELF-NEXT: ProgramHeaderOffset: +# ELF-NEXT: SectionHeaderOffset: +# ELF-NEXT: Flags [ +# ELF-NEXT: EF_MIPS_ABI2 +# ELF-NEXT: EF_MIPS_ARCH_64R2 +# ELF-NEXT: ] diff --git a/test/ELF/mips-no-objects.s b/test/ELF/mips-no-objects.s new file mode 100644 index 0000000000000..444477ea72064 --- /dev/null +++ b/test/ELF/mips-no-objects.s @@ -0,0 +1,5 @@ +# REQUIRES: mips +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -shared -o %t.so +# RUN: ld.lld %t.so -shared -o %t2.so +# RUN: llvm-readobj %t2.so > /dev/null 2>&1 diff --git a/test/ELF/mips-npic-call-pic.s b/test/ELF/mips-npic-call-pic.s index dbf053570bd9f..76c392e1f66c2 100644 --- a/test/ELF/mips-npic-call-pic.s +++ b/test/ELF/mips-npic-call-pic.s @@ -3,9 +3,14 @@ # non-PIC code calls PIC function. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: %p/Inputs/mips-fpic.s -o %t-fpic.o +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: %p/Inputs/mips-fnpic.s -o %t-fnpic.o +# RUN: ld.lld -r %t-fpic.o %t-fnpic.o -o %t-sto-pic.o +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ # RUN: %p/Inputs/mips-pic.s -o %t-pic.o # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t-npic.o -# RUN: ld.lld %t-npic.o %t-pic.o %p/Inputs/mips-sto-pic.o -o %t.exe +# RUN: ld.lld %t-npic.o %t-pic.o %t-sto-pic.o -o %t.exe # RUN: llvm-objdump -d %t.exe | FileCheck %s # CHECK: Disassembly of section .text: @@ -22,7 +27,7 @@ # CHECK-NEXT: 20018: 0c 00 80 19 jal 131172 <foo2+0x4> # ^-- .pic.foo2 # CHECK-NEXT: 2001c: 00 00 00 00 nop -# CHECK-NEXT: 20020: 0c 00 80 28 jal 131232 <fnpic+0x10> +# CHECK-NEXT: 20020: 0c 00 80 25 jal 131220 <fnpic+0x4> # ^-- .pic.fpic # CHECK-NEXT: 20024: 00 00 00 00 nop # CHECK-NEXT: 20028: 0c 00 80 24 jal 131216 <fnpic> @@ -56,25 +61,19 @@ # CHECK-NEXT: 20078: 00 00 00 00 nop # CHECK-NEXT: 2007c: 00 00 00 00 nop # -# CHECK: fpic: -# CHECK-NEXT: 20080: 00 00 00 00 nop -# CHECK-NEXT: 20084: 00 00 00 00 nop -# CHECK-NEXT: 20088: 00 00 00 00 nop -# CHECK-NEXT: 2008c: 00 00 00 00 nop +# CHECK: fpic: +# CHECK-NEXT: 20080: 00 00 00 00 nop # -# CHECK: fnpic: +# CHECK: fnpic: # CHECK-NEXT: 20090: 00 00 00 00 nop -# CHECK-NEXT: 20094: 00 00 00 00 nop -# CHECK-NEXT: 20098: 00 00 00 00 nop -# CHECK-NEXT: 2009c: 00 00 00 00 nop -# CHECK-NEXT: 200a0: 3c 19 00 02 lui $25, 2 -# CHECK-NEXT: 200a4: 08 00 80 20 j 131200 <fpic> -# CHECK-NEXT: 200a8: 27 39 00 80 addiu $25, $25, 128 +# CHECK-NEXT: 20094: 3c 19 00 02 lui $25, 2 +# CHECK-NEXT: 20098: 08 00 80 20 j 131200 <fpic> +# CHECK-NEXT: 2009c: 27 39 00 80 addiu $25, $25, 128 -# Make sure tha thunks are created properly no matter how +# Make sure the thunks are created properly no matter how # objects are laid out. # -# RUN: ld.lld %t-pic.o %t-npic.o %p/Inputs/mips-sto-pic.o -o %t.exe +# RUN: ld.lld %t-pic.o %t-npic.o %t-sto-pic.o -o %t.exe # RUN: llvm-objdump -d %t.exe | FileCheck -check-prefix=REVERSE %s # REVERSE: foo1a: @@ -112,26 +111,19 @@ # REVERSE-NEXT: 20064: 00 00 00 00 nop # REVERSE-NEXT: 20068: 0c 00 80 0d jal 131124 <foo2+0x4> # REVERSE-NEXT: 2006c: 00 00 00 00 nop -# REVERSE-NEXT: 20070: 0c 00 80 28 jal 131232 <fnpic+0x10> +# REVERSE-NEXT: 20070: 0c 00 80 25 jal 131220 <fnpic+0x4> # REVERSE-NEXT: 20074: 00 00 00 00 nop # REVERSE-NEXT: 20078: 0c 00 80 24 jal 131216 <fnpic> # REVERSE-NEXT: 2007c: 00 00 00 00 nop # -# REVERSE: fpic: +# REVERSE: fpic: # REVERSE-NEXT: 20080: 00 00 00 00 nop -# REVERSE-NEXT: 20084: 00 00 00 00 nop -# REVERSE-NEXT: 20088: 00 00 00 00 nop -# REVERSE-NEXT: 2008c: 00 00 00 00 nop # -# REVERSE: fnpic: +# REVERSE: fnpic: # REVERSE-NEXT: 20090: 00 00 00 00 nop -# REVERSE-NEXT: 20094: 00 00 00 00 nop -# REVERSE-NEXT: 20098: 00 00 00 00 nop -# REVERSE-NEXT: 2009c: 00 00 00 00 nop -# REVERSE-NEXT: 200a0: 3c 19 00 02 lui $25, 2 -# REVERSE-NEXT: 200a4: 08 00 80 20 j 131200 <fpic> -# REVERSE-NEXT: 200a8: 27 39 00 80 addiu $25, $25, 128 -# REVERSE-NEXT: 200ac: 00 00 00 00 nop +# REVERSE-NEXT: 20094: 3c 19 00 02 lui $25, 2 +# REVERSE-NEXT: 20098: 08 00 80 20 j 131200 <fpic> +# REVERSE-NEXT: 2009c: 27 39 00 80 addiu $25, $25, 128 .text .globl __start diff --git a/test/ELF/mips-options-r.test b/test/ELF/mips-options-r.test index c4144057e9ad9..40c61c0d2bac3 100644 --- a/test/ELF/mips-options-r.test +++ b/test/ELF/mips-options-r.test @@ -1,7 +1,6 @@ # Check that if input file contains .MIPS.options section and symbol # points to the section and the linker generates a relocatable output, -# LLD does not crash and write section symbols point to the output -# .MIPS.options section. +# LLD does not crash. # # PR 27878 # @@ -12,8 +11,8 @@ # % as -mabi=64 -mips64r2 t.s # RUN: ld.lld -r %p/Inputs/mips-options.o -o %t.o -# RUN: llvm-readobj -t %t.o | FileCheck %s +# RUN: llvm-readobj -s %t.o | FileCheck %s # REQUIRES: mips -# CHECK: Section: .MIPS.options +# CHECK: Name: .MIPS.options diff --git a/test/ELF/mips-options.s b/test/ELF/mips-options.s index 30381ae55af7f..f48ecad81d264 100644 --- a/test/ELF/mips-options.s +++ b/test/ELF/mips-options.s @@ -3,7 +3,10 @@ # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t1.o # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ # RUN: %S/Inputs/mips-dynamic.s -o %t2.o -# RUN: ld.lld %t1.o %t2.o -shared -o %t.so +# RUN: echo "SECTIONS { \ +# RUN: . = 0x100000000; \ +# RUN: .got : { *(.got) } }" > %t.rel.script +# RUN: ld.lld %t1.o %t2.o --script %t.rel.script -shared -o %t.so # RUN: llvm-readobj -symbols -mips-options %t.so | FileCheck %s # REQUIRES: mips @@ -11,15 +14,15 @@ .text .globl __start __start: - lw $t0,%call16(g1)($gp) + lui $gp, %hi(%neg(%gp_rel(g1))) # CHECK: Name: _gp -# CHECK-NEXT: Value: 0x[[GP:[0-9A-F]+]] +# CHECK-NEXT: Value: 0x100008250 # CHECK: MIPS Options { # CHECK-NEXT: ODK_REGINFO { -# CHECK-NEXT: GP: 0x[[GP]] -# CHECK-NEXT: General Mask: 0x10001001 +# CHECK-NEXT: GP: 0x100008250 +# CHECK-NEXT: General Mask: 0x10000001 # CHECK-NEXT: Co-Proc Mask0: 0x0 # CHECK-NEXT: Co-Proc Mask1: 0x0 # CHECK-NEXT: Co-Proc Mask2: 0x0 diff --git a/test/ELF/mips-plt-r6.s b/test/ELF/mips-plt-r6.s new file mode 100644 index 0000000000000..8685d6158f78d --- /dev/null +++ b/test/ELF/mips-plt-r6.s @@ -0,0 +1,38 @@ +# Check PLT entries generation in case of R6 ABI version. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: -mcpu=mips32r6 %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# 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 + +# 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 1c 00 04 aui $zero, $gp, 4 +# CHECK-NEXT: 20014: 8f 99 00 04 lw $25, 4($gp) +# CHECK-NEXT: 20018: 27 9c 00 04 addiu $gp, $gp, 4 +# 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 +# CHECK-NEXT: 2002c: 27 18 ff fe addiu $24, $24, -2 + +# CHECK-NEXT: 20030: 3c 0f 00 04 aui $zero, $15, 4 +# CHECK-NEXT: 20034: 8d f9 00 0c lw $25, 12($15) +# CHECK-NEXT: 20038: 03 20 00 09 jr $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-relocatable.s b/test/ELF/mips-relocatable.s new file mode 100644 index 0000000000000..168ddf736e1eb --- /dev/null +++ b/test/ELF/mips-relocatable.s @@ -0,0 +1,21 @@ +# 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: + lw $t0,%call16(__start)($gp) +foo: + nop + + .section .rodata, "a" +v: + .gpword foo + +# CHECK-NOT: Contents of section .got: +# CHECK-NOT: {{.*}} _gp diff --git a/test/ELF/mips-sto-pic-flag.s b/test/ELF/mips-sto-pic-flag.s new file mode 100644 index 0000000000000..4d79233464969 --- /dev/null +++ b/test/ELF/mips-sto-pic-flag.s @@ -0,0 +1,58 @@ +# 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. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t-npic.o +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: %p/Inputs/mips-pic.s -o %t-pic.o +# 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: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: foo1a +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Function +# CHECK-NEXT: Other [ +# CHECK-NEXT: STO_MIPS_PIC +# CHECK-NEXT: ] +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: foo1b +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Function +# CHECK-NEXT: Other [ +# CHECK-NEXT: STO_MIPS_PIC +# CHECK-NEXT: ] +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: foo2 +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: Function +# CHECK-NEXT: Other [ +# CHECK-NEXT: STO_MIPS_PIC +# CHECK-NEXT: ] +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } + + .text +main: + nop diff --git a/test/ELF/mips-tls-64.s b/test/ELF/mips-tls-64.s index 9c05e940b1c15..808fa4cbd1d70 100644 --- a/test/ELF/mips-tls-64.s +++ b/test/ELF/mips-tls-64.s @@ -1,86 +1,112 @@ # Check MIPS TLS 64-bit relocations handling. # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \ -# RUN: %p/Inputs/mips-dynamic.s -o %t.so.o +# RUN: %p/Inputs/mips-tls.s -o %t.so.o # RUN: ld.lld -shared %t.so.o -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 -s -t %t.exe | FileCheck -check-prefix=DIS %s # RUN: llvm-readobj -r -mips-plt-got %t.exe | FileCheck %s +# RUN: ld.lld -shared %t.o %t.so -o %t-out.so +# 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 28 addiu $2, $3, -32728 -# DIS-NEXT: 20004: 24 62 80 38 addiu $2, $3, -32712 -# DIS-NEXT: 20008: 8f 82 80 20 lw $2, -32736($gp) +# 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: Contents of section .got: -# DIS_NEXT: 30008 00000000 00000000 80000000 00000000 -# DIS_NEXT: 30018 00000000 00020000 00000000 00000000 -# DIS_NEXT: 30028 00000000 00000004 00000000 00000000 -# DIS_NEXT: 30038 00000000 00000000 00000000 00000004 +# DIS-NEXT: 30008 00000000 00000000 80000000 00000000 +# DIS-NEXT: 30018 00000000 00000000 00000000 00000000 +# DIS-NEXT: 30028 00000000 00000000 00000000 00000001 +# DIS-NEXT: 30038 00000000 00000000 00000000 00000001 +# DIS-NEXT: 30048 ffffffff ffff8004 ffffffff ffff9004 # DIS: 0000000000030000 l .tdata 00000000 .tdata # DIS: 0000000000030000 l .tdata 00000000 loc -# DIS: 0000000000000004 g .tdata 00000000 foo +# 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 - 0x0 -# CHECK-NEXT: 0x30028 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE - 0x0 -# CHECK-NEXT: 0x30030 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE - 0x0 -# CHECK-NEXT: 0x30040 R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE - 0x4 +# CHECK-NEXT: 0x30018 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# CHECK-NEXT: 0x30020 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# CHECK-NEXT: 0x30028 R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: Primary GOT { # CHECK-NEXT: Canonical gp value: 0x37FF8 # CHECK-NEXT: Reserved entries [ -# CHECK-NEXT: Entry { -# CHECK-NEXT: Address: 0x30008 -# CHECK-NEXT: Access: -32752 -# CHECK-NEXT: Initial: 0x0 -# CHECK-NEXT: Purpose: Lazy resolver -# CHECK-NEXT: } -# CHECK-NEXT: Entry { -# CHECK-NEXT: Address: 0x30010 -# CHECK-NEXT: Access: -32744 -# CHECK-NEXT: Initial: 0x80000000 -# CHECK-NEXT: Purpose: Module pointer (GNU extension) -# CHECK-NEXT: } -# CHECK-NEXT: ] +# CHECK: ] # CHECK-NEXT: Local entries [ # CHECK-NEXT: ] # CHECK-NEXT: Global entries [ -# CHECK-NEXT: Entry { -# CHECK-NEXT: Address: 0x30018 -# CHECK-NEXT: Access: -32736 -# CHECK-NEXT: Initial: 0x0 -# CHECK-NEXT: Value: 0x0 -# CHECK-NEXT: Type: Function -# CHECK-NEXT: Section: Undefined -# CHECK-NEXT: Name: foo0 -# CHECK-NEXT: } # CHECK-NEXT: ] -# CHECK-NEXT: Number of TLS and multi-GOT entries: 5 -# ^-- 0x30020 / -32728 - R_MIPS_TLS_GD - R_MIPS_TLS_DTPMOD32 foo -# ^-- 0x30028 / -32720 - R_MIPS_TLS_DTPREL32 foo -# ^-- 0x30030 / -32712 - R_MIPS_TLS_LDM - R_MIPS_TLS_DTPMOD32 loc -# ^-- 0x30038 / -32704 -# ^-- 0x30040 / -32696 - R_MIPS_TLS_GOTTPREL - R_MIPS_TLS_TPREL32 +# 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 + +# DIS-SO: Contents of section .got: +# DIS-SO-NEXT: 20008 00000000 00000000 80000000 00000000 +# DIS-SO-NEXT: 20018 00000000 00000000 00000000 00000000 +# DIS-SO-NEXT: 20028 00000000 00000000 00000000 00000000 +# DIS-SO-NEXT: 20038 00000000 00000000 00000000 00000000 +# DIS-SO-NEXT: 20048 00000000 00000000 00000000 00000000 + +# SO: Relocations [ +# SO-NEXT: Section (7) .rela.dyn { +# SO-NEXT: 0x20030 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE - 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: 0x20050 R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE bar 0x0 +# SO-NEXT: 0x20018 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# SO-NEXT: 0x20020 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# SO-NEXT: 0x20028 R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE foo 0x0 +# SO-NEXT: } +# SO-NEXT: ] +# SO-NEXT: Primary GOT { +# SO-NEXT: Canonical gp value: 0x27FF8 +# SO-NEXT: Reserved entries [ +# SO: ] +# SO-NEXT: Local entries [ +# SO-NEXT: ] +# SO-NEXT: Global entries [ +# SO-NEXT: ] +# SO-NEXT: Number of TLS and multi-GOT entries: 8 +# ^-- 0x20018 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD64 foo +# ^-- 0x20020 R_MIPS_TLS_DTPREL64 foo +# ^-- 0x20028 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL64 foo +# ^-- 0x20030 R_MIPS_TLS_LDM R_MIPS_TLS_DTPMOD64 loc +# ^-- 0x20038 0 loc +# ^-- 0x20040 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD64 bar +# ^-- 0x20048 R_MIPS_TLS_DTPREL64 bar +# ^-- 0x20050 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL64 bar .text .global __start __start: addiu $2, $3, %tlsgd(foo) # R_MIPS_TLS_GD - addiu $2, $3, %tlsldm(loc) # R_MIPS_TLS_LDM - lw $2, %got(foo0)($gp) addiu $2, $3, %gottprel(foo) # R_MIPS_TLS_GOTTPREL + addiu $2, $3, %tlsldm(loc) # R_MIPS_TLS_LDM + addiu $2, $3, %tlsgd(bar) # R_MIPS_TLS_GD + addiu $2, $3, %gottprel(bar) # R_MIPS_TLS_GOTTPREL .section .tdata,"awT",%progbits - .global foo + .global bar loc: .word 0 -foo: +bar: .word 0 diff --git a/test/ELF/mips-tls-static-64.s b/test/ELF/mips-tls-static-64.s new file mode 100644 index 0000000000000..e7baf67bb2954 --- /dev/null +++ b/test/ELF/mips-tls-static-64.s @@ -0,0 +1,37 @@ +# Check handling TLS related relocations and symbols when linking +# a 64-bit static executable. + +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t +# 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: 40000 00020004 ffffffff ffff8004 ffffffff +# CHECK-NEXT: 40010 ffff9004 +# +# CHECK: SYMBOL TABLE: +# CHECK: 0000000000020004 .text 00000000 __tls_get_addr +# CHECK: 0000000000000000 g .tdata 00000000 tls1 + + .text + .global __start +__start: + nop + + .global __tls_get_addr +__tls_get_addr: + nop + + .data +loc: + .word __tls_get_addr + .dtpreldword tls1+4 # R_MIPS_TLS_DTPREL64 + .tpreldword tls1+4 # R_MIPS_TLS_TPREL64 + + .section .tdata,"awT",%progbits + .global tls1 +tls1: + .word __tls_get_addr + .word 0 diff --git a/test/ELF/mips-tls-static.s b/test/ELF/mips-tls-static.s new file mode 100644 index 0000000000000..6f0fa559ae0dc --- /dev/null +++ b/test/ELF/mips-tls-static.s @@ -0,0 +1,42 @@ +# Check handling TLS related relocations and symbols when linking +# a static executable. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t +# RUN: ld.lld -static %t -o %t.exe +# RUN: llvm-objdump -s -t %t.exe | FileCheck %s + +# REQUIRES: mips + +# CHECK: Contents of section .got: +# CHECK-NEXT: 30008 00000000 80000000 00000001 ffff8000 +# CHECK-NEXT: 30018 00000001 00000000 ffff9000 +# CHECK: Contents of section .data: +# CHECK-NEXT: 40000 0002000c ffff8004 ffff9004 +# +# CHECK: SYMBOL TABLE: +# CHECK: 0002000c .text 00000000 __tls_get_addr +# CHECK: 00000000 g .tdata 00000000 tls1 + + .text + .global __start +__start: + addiu $2, $3, %tlsgd(tls1) # R_MIPS_TLS_GD + addiu $2, $3, %tlsldm(tls2) # R_MIPS_TLS_LDM + addiu $2, $3, %gottprel(tls1) # R_MIPS_TLS_GOTTPREL + + .global __tls_get_addr +__tls_get_addr: + nop + + .data +loc: + .word __tls_get_addr + .dtprelword tls1+4 # R_MIPS_TLS_DTPREL32 + .tprelword tls1+4 # R_MIPS_TLS_TPREL32 + + .section .tdata,"awT",%progbits + .global tls1 +tls1: + .word __tls_get_addr +tls2: + .word 0 diff --git a/test/ELF/mips-tls.s b/test/ELF/mips-tls.s index 9635558c2d955..fa02324fd850f 100644 --- a/test/ELF/mips-tls.s +++ b/test/ELF/mips-tls.s @@ -4,74 +4,105 @@ # RUN: %p/Inputs/mips-tls.s -o %t.so.o # RUN: ld.lld -shared %t.so.o -o %t.so # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o + # RUN: ld.lld %t.o %t.so -o %t.exe # RUN: llvm-objdump -d -s -t %t.exe | FileCheck -check-prefix=DIS %s # RUN: llvm-readobj -r -mips-plt-got %t.exe | FileCheck %s +# RUN: ld.lld -shared %t.o %t.so -o %t-out.so +# 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 1c addiu $2, $3, -32740 -# DIS-NEXT: 20004: 24 62 80 24 addiu $2, $3, -32732 -# DIS-NEXT: 20008: 8f 82 80 18 lw $2, -32744($gp) +# 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: Contents of section .got: -# DIS_NEXT: 30004 00000000 80000000 00020000 00000000 -# DIS_NEXT: 30014 00000000 00000000 00000000 00000000 +# DIS-NEXT: 30008 00000000 80000000 00000000 00000000 +# DIS-NEXT: 30018 00000000 00000001 00000000 00000001 +# DIS-NEXT: 30028 ffff8004 ffff9004 # DIS: 00030000 l .tdata 00000000 .tdata # DIS: 00030000 l .tdata 00000000 loc +# DIS: 00000004 g .tdata 00000000 bar # DIS: 00000000 g *UND* 00000000 foo # CHECK: Relocations [ # CHECK-NEXT: Section (7) .rel.dyn { -# CHECK-NEXT: 0x30018 R_MIPS_TLS_DTPMOD32 - 0x0 # CHECK-NEXT: 0x30010 R_MIPS_TLS_DTPMOD32 foo 0x0 # CHECK-NEXT: 0x30014 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: } # CHECK-NEXT: ] # CHECK-NEXT: Primary GOT { -# CHECK-NEXT: Canonical gp value: 0x37FF4 +# CHECK-NEXT: Canonical gp value: 0x37FF8 # CHECK-NEXT: Reserved entries [ -# CHECK-NEXT: Entry { -# CHECK-NEXT: Address: 0x30004 -# CHECK-NEXT: Access: -32752 -# CHECK-NEXT: Initial: 0x0 -# CHECK-NEXT: Purpose: Lazy resolver -# CHECK-NEXT: } -# CHECK-NEXT: Entry { -# CHECK-NEXT: Address: 0x30008 -# CHECK-NEXT: Access: -32748 -# CHECK-NEXT: Initial: 0x80000000 -# CHECK-NEXT: Purpose: Module pointer (GNU extension) -# CHECK-NEXT: } -# CHECK-NEXT: ] +# CHECK: ] # CHECK-NEXT: Local entries [ -# CHECK-NEXT: Entry { -# CHECK-NEXT: Address: 0x3000C -# CHECK-NEXT: Access: -32744 -# CHECK-NEXT: Initial: 0x20000 -# CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: Global entries [ # CHECK-NEXT: ] -# CHECK-NEXT: Number of TLS and multi-GOT entries: 5 -# ^-- 0x30010 / -32740 - R_MIPS_TLS_GD - R_MIPS_TLS_DTPMOD32 foo -# ^-- 0x30018 / -32736 - R_MIPS_TLS_DTPREL32 foo -# ^-- 0x3001C / -32732 - R_MIPS_TLS_LDM - R_MIPS_TLS_DTPMOD32 loc -# ^-- 0x30020 / -32728 -# ^-- 0x30024 / -32724 - R_MIPS_TLS_GOTTPREL - R_MIPS_TLS_TPREL32 +# CHECK-NEXT: Number of TLS and multi-GOT entries: 8 +# ^-- 0x30010 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD32 foo +# ^-- 0x30014 R_MIPS_TLS_DTPREL32 foo +# ^-- 0x30018 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL32 foo +# ^-- 0x3001C R_MIPS_TLS_LDM 1 loc +# ^-- 0x30020 0 loc +# ^-- 0x30024 R_MIPS_TLS_GD 1 bar +# ^-- 0x30028 VA - 0x8000 bar +# ^-- 0x3002C R_MIPS_TLS_GOTTPREL VA - 0x7000 bar + +# DIS-SO: Contents of section .got: +# DIS-SO-NEXT: 20008 00000000 80000000 00000000 00000000 +# DIS-SO-NEXT: 20018 00000000 00000000 00000000 00000000 +# DIS-SO-NEXT: 20028 00000000 00000000 + +# SO: Relocations [ +# SO-NEXT: Section (7) .rel.dyn { +# SO-NEXT: 0x2001C R_MIPS_TLS_DTPMOD32 - 0x0 +# SO-NEXT: 0x20024 R_MIPS_TLS_DTPMOD32 bar 0x0 +# SO-NEXT: 0x20028 R_MIPS_TLS_DTPREL32 bar 0x0 +# SO-NEXT: 0x2002C R_MIPS_TLS_TPREL32 bar 0x0 +# SO-NEXT: 0x20010 R_MIPS_TLS_DTPMOD32 foo 0x0 +# SO-NEXT: 0x20014 R_MIPS_TLS_DTPREL32 foo 0x0 +# SO-NEXT: 0x20018 R_MIPS_TLS_TPREL32 foo 0x0 +# SO-NEXT: } +# SO-NEXT: ] +# SO-NEXT: Primary GOT { +# SO-NEXT: Canonical gp value: 0x27FF8 +# SO-NEXT: Reserved entries [ +# SO: ] +# SO-NEXT: Local entries [ +# SO-NEXT: ] +# SO-NEXT: Global entries [ +# SO-NEXT: ] +# SO-NEXT: Number of TLS and multi-GOT entries: 8 +# ^-- 0x20010 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD32 foo +# ^-- 0x20014 R_MIPS_TLS_DTPREL32 foo +# ^-- 0x20018 R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL32 foo +# ^-- 0x2001C R_MIPS_TLS_LDM R_MIPS_TLS_DTPMOD32 loc +# ^-- 0x20020 0 loc +# ^-- 0x20024 R_MIPS_TLS_GD R_MIPS_TLS_DTPMOD32 bar +# ^-- 0x20028 R_MIPS_TLS_DTPREL32 bar +# ^-- 0x2002C R_MIPS_TLS_GOTTPREL R_MIPS_TLS_TPREL32 bar .text .global __start __start: addiu $2, $3, %tlsgd(foo) # R_MIPS_TLS_GD - addiu $2, $3, %tlsldm(loc) # R_MIPS_TLS_LDM - lw $2, %got(__start)($gp) addiu $2, $3, %gottprel(foo) # R_MIPS_TLS_GOTTPREL + addiu $2, $3, %tlsldm(loc) # R_MIPS_TLS_LDM + addiu $2, $3, %tlsgd(bar) # R_MIPS_TLS_GD + addiu $2, $3, %gottprel(bar) # R_MIPS_TLS_GOTTPREL .section .tdata,"awT",%progbits + .global bar loc: .word 0 +bar: + .word 0 diff --git a/test/ELF/mips-xgot-order.s b/test/ELF/mips-xgot-order.s new file mode 100644 index 0000000000000..d249715bafa55 --- /dev/null +++ b/test/ELF/mips-xgot-order.s @@ -0,0 +1,49 @@ +# Check that GOT entries accessed via 16-bit indexing are allocated +# in the beginning of the GOT. + +# 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 -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 +# CHECK-NEXT: 20004: 8c 42 80 24 lw $2, -32732($2) +# CHECK-NEXT: 20008: 3c 02 00 00 lui $2, 0 +# CHECK-NEXT: 2000c: 8c 42 80 28 lw $2, -32728($2) +# +# CHECK: bar: +# CHECK-NEXT: 20010: 8c 42 80 20 lw $2, -32736($2) +# CHECK-NEXT: 20014: 8c 42 80 18 lw $2, -32744($2) +# CHECK-NEXT: 20018: 20 42 00 00 addi $2, $2, 0 + +# CHECK: Contents of section .got: +# CHECK-NEXT: 30000 00000000 80000000 00040000 00050000 +# ^ %hi(loc) +# ^ redundant entry +# CHECK-NEXT: 30010 00020010 00020000 00040000 +# ^ %got(bar) +# ^ %got_hi/lo(start) +# ^ %got_hi/lo(loc) + +# CHECK: 00040000 .data 00000000 loc +# CHECK: 00020000 .text 00000000 __start +# CHECK: 00020010 .text 00000000 bar + + .text + .global __start, bar +__start: + lui $2, %got_hi(__start) + lw $2, %got_lo(__start)($2) + lui $2, %got_hi(loc) + lw $2, %got_lo(loc)($2) +bar: + lw $2, %got(bar)($2) + lw $2, %got(loc)($2) + addi $2, $2, %lo(loc) + + .data +loc: + .word 0 diff --git a/test/ELF/no-inhibit-exec.s b/test/ELF/no-inhibit-exec.s index 31638fd92cc92..d0970d93f21e5 100644 --- a/test/ELF/no-inhibit-exec.s +++ b/test/ELF/no-inhibit-exec.s @@ -6,7 +6,7 @@ # CHECK: Disassembly of section .text: # CHECK-NEXT: _start -# CHECK-NEXT: 11000: e8 fb ef fe ff callq -69637 +# CHECK-NEXT: 201000: {{.*}} callq -2101253 # next code will not link without noinhibit-exec flag # because of undefined symbol _bar diff --git a/test/ELF/no-merge.s b/test/ELF/no-merge.s new file mode 100644 index 0000000000000..5d8b8570ab492 --- /dev/null +++ b/test/ELF/no-merge.s @@ -0,0 +1,25 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { .data : {*(.data.*)} }" > %t0.script +# RUN: ld.lld %t.o -o %t0.out --script %t0.script +# RUN: llvm-objdump -s %t0.out | FileCheck %s --check-prefix=OPT +# OPT: Contents of section .data: +# OPT-NEXT: 0000 01 +# OPT-NEXT: Contents of section .data: +# OPT-NEXT: 0001 6100 +# OPT-NEXT: Contents of section .data: +# OPT-NEXT: 0003 03 + +# RUN: ld.lld -O0 %t.o -o %t1.out --script %t0.script +# RUN: llvm-objdump -s %t1.out | FileCheck %s --check-prefix=NOOPT +# NOOPT: Contents of section .data: +# NOOPT-NEXT: 0000 01610003 + +.section .data.aw,"aw",@progbits +.byte 1 + +.section .data.ams,"aMS",@progbits,1 +.asciz "a" + +.section .data.am,"aM",@progbits,1 +.byte 3 diff --git a/test/ELF/no-obj.s b/test/ELF/no-obj.s index 68e9979e3ede1..eea10a45d8795 100644 --- a/test/ELF/no-obj.s +++ b/test/ELF/no-obj.s @@ -2,7 +2,7 @@ // RUN: llvm-ar rcs %t.a %t.o // RUN: not ld.lld -o %t2 -u _start %t.a 2>&1 | FileCheck %s -// CHECK: -m or at least a .o file required +// CHECK: target emulation unknown: -m or at least one .o file required .global _start _start: diff --git a/test/ELF/non-abs-reloc.s b/test/ELF/non-abs-reloc.s new file mode 100644 index 0000000000000..ef9ba44661337 --- /dev/null +++ b/test/ELF/non-abs-reloc.s @@ -0,0 +1,11 @@ +// 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 reloc + +.globl _start +_start: + nop + +.section .dummy + .long foo@gotpcrel diff --git a/test/ELF/noplt-pie.s b/test/ELF/noplt-pie.s index 1eb84934184ed..81e4410ac2c2c 100644 --- a/test/ELF/noplt-pie.s +++ b/test/ELF/noplt-pie.s @@ -10,8 +10,8 @@ # CHECK: Relocations [ # CHECK-NEXT: Section ({{.*}}) .rela.dyn { -# CHECK-NEXT: 0x120B0 R_X86_64_GLOB_DAT bar 0x0 -# CHECK-NEXT: 0x120B8 R_X86_64_GLOB_DAT zed 0x0 +# CHECK-NEXT: 0x2020B0 R_X86_64_GLOB_DAT bar 0x0 +# CHECK-NEXT: 0x2020B8 R_X86_64_GLOB_DAT zed 0x0 # CHECK-NEXT: } # CHECK-NEXT: ] diff --git a/test/ELF/oformat-binary-ttext.s b/test/ELF/oformat-binary-ttext.s new file mode 100644 index 0000000000000..aced1a3be4cb6 --- /dev/null +++ b/test/ELF/oformat-binary-ttext.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: ld.lld -N -Ttext 0x100 -o %t.out %t --oformat binary +# RUN: od -t x1 -v %t.out | FileCheck %s --check-prefix=BIN + +# BIN: 0000000 90 00 00 00 00 00 00 00 +# BIN-NEXT: 0000010 +# BIN-NOT: 0000020 + +## The same but without OMAGIC. +# RUN: ld.lld -Ttext 0x100 -o %t.out %t --oformat binary +# RUN: od -t x1 -v %t.out | FileCheck %s --check-prefix=BIN + +.text +.globl _start +_start: + nop diff --git a/test/ELF/oformat-binary.s b/test/ELF/oformat-binary.s new file mode 100644 index 0000000000000..acd95c7cef362 --- /dev/null +++ b/test/ELF/oformat-binary.s @@ -0,0 +1,32 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: ld.lld -o %t.out %t --oformat binary +# RUN: od -t x1 -v %t.out | FileCheck %s +# CHECK: 000000 90 11 22 00 00 00 00 00 +# CHECK-NOT: 00000010 + +## Check case when linkerscript is used. +# RUN: echo "SECTIONS { . = 0x1000; }" > %t.script +# RUN: ld.lld -o %t2.out --script %t.script %t --oformat binary +# RUN: od -t x1 -v %t2.out | FileCheck %s + +# RUN: echo "SECTIONS { }" > %t.script +# 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: | FileCheck %s --check-prefix ERR +# ERR: unknown --oformat value: foo + +.text +.align 4 +.globl _start +_start: + nop + +.section .mysec.1,"ax" +.byte 0x11 + +.section .mysec.2,"ax" +.byte 0x22 diff --git a/test/ELF/openbsd-randomize.s b/test/ELF/openbsd-randomize.s new file mode 100644 index 0000000000000..794e87b281226 --- /dev/null +++ b/test/ELF/openbsd-randomize.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: ld.lld %t -o %t.out +# RUN: llvm-readobj --program-headers %t.out | FileCheck %s + +# CHECK: ProgramHeader { +# CHECK: Type: PT_OPENBSD_RANDOMIZE (0x65A3DBE6) +# CHECK-NEXT: Offset: +# CHECK-NEXT: VirtualAddress: +# CHECK-NEXT: PhysicalAddress: +# CHECK-NEXT: FileSize: 8 +# CHECK-NEXT: MemSize: 8 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 1 +# CHECK-NEXT: } + +.section .openbsd.randomdata, "a" +.quad 0 diff --git a/test/ELF/openbsd-wxneeded.s b/test/ELF/openbsd-wxneeded.s new file mode 100644 index 0000000000000..d209e4f019985 --- /dev/null +++ b/test/ELF/openbsd-wxneeded.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: ld.lld -z wxneeded %t -o %t.out +# RUN: llvm-readobj --program-headers %t.out | FileCheck %s + +# CHECK: ProgramHeader { +# CHECK: Type: PT_OPENBSD_WXNEEDED (0x65A3DBE7) +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x0 +# CHECK-NEXT: PhysicalAddress: 0x0 +# CHECK-NEXT: FileSize: 0 +# CHECK-NEXT: MemSize: 0 +# CHECK-NEXT: Flags [ +# CHECK-NEXT: PF_X +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 0 +# CHECK-NEXT: } diff --git a/test/ELF/phdr-align.s b/test/ELF/phdr-align.s index 58d537b46840a..354897eedd275 100644 --- a/test/ELF/phdr-align.s +++ b/test/ELF/phdr-align.s @@ -2,6 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: echo "SECTIONS { \ +# RUN: . = SIZEOF_HEADERS; \ # RUN: .bss : { *(.bss) } \ # RUN: .data : { *(.data) } \ # RUN: .text : { *(.text) } }" > %t.script diff --git a/test/ELF/pie.s b/test/ELF/pie.s index 4cf1743ee736e..5964db5c93993 100644 --- a/test/ELF/pie.s +++ b/test/ELF/pie.s @@ -1,5 +1,12 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o + +## Default is no PIE. +# RUN: ld.lld %t1.o -o %t +# RUN: llvm-readobj -file-headers -sections -program-headers -symbols -r %t \ +# RUN: | FileCheck %s --check-prefix=NOPIE + +## Check -pie. # RUN: ld.lld -pie %t1.o -o %t # RUN: llvm-readobj -file-headers -sections -program-headers -symbols -r %t | FileCheck %s @@ -18,20 +25,6 @@ # CHECK-NEXT: Unused: (00 00 00 00 00 00 00) # CHECK-NEXT: } # CHECK-NEXT: Type: SharedObject -# CHECK-NEXT: Machine: EM_X86_64 -# CHECK-NEXT: Version: 1 -# CHECK-NEXT: Entry: 0x1000 -# CHECK-NEXT: ProgramHeaderOffset: 0x40 -# CHECK-NEXT: SectionHeaderOffset: 0x1110 -# CHECK-NEXT: Flags [ -# CHECK-NEXT: ] -# CHECK-NEXT: HeaderSize: 64 -# CHECK-NEXT: ProgramHeaderEntrySize: 56 -# CHECK-NEXT: ProgramHeaderCount: 7 -# CHECK-NEXT: SectionHeaderEntrySize: 64 -# CHECK-NEXT: SectionHeaderCount: 9 -# CHECK-NEXT: StringTableSectionIndex: 7 -# CHECK-NEXT: } # CHECK: ProgramHeaders [ # CHECK-NEXT: ProgramHeader { @@ -39,8 +32,8 @@ # CHECK-NEXT: Offset: 0x40 # CHECK-NEXT: VirtualAddress: 0x40 # CHECK-NEXT: PhysicalAddress: 0x40 -# CHECK-NEXT: FileSize: 392 -# CHECK-NEXT: MemSize: 392 +# CHECK-NEXT: FileSize: +# CHECK-NEXT: MemSize: # CHECK-NEXT: Flags [ # CHECK-NEXT: PF_R # CHECK-NEXT: ] @@ -51,52 +44,13 @@ # CHECK-NEXT: Offset: 0x0 # CHECK-NEXT: VirtualAddress: 0x0 # CHECK-NEXT: PhysicalAddress: 0x0 -# CHECK-NEXT: FileSize: 497 -# CHECK-NEXT: MemSize: 497 -# CHECK-NEXT: Flags [ -# CHECK-NEXT: PF_R -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 4096 -# CHECK-NEXT: } -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_LOAD -# CHECK-NEXT: Offset: 0x1000 -# CHECK-NEXT: VirtualAddress: 0x1000 -# CHECK-NEXT: PhysicalAddress: 0x1000 -# CHECK-NEXT: FileSize: 0 -# CHECK-NEXT: MemSize: 0 -# CHECK-NEXT: Flags [ -# CHECK-NEXT: PF_R -# CHECK-NEXT: PF_X -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 4096 -# CHECK-NEXT: } -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_LOAD -# CHECK-NEXT: Offset: 0x1000 -# CHECK-NEXT: VirtualAddress: 0x1000 -# CHECK-NEXT: PhysicalAddress: 0x1000 -# CHECK-NEXT: FileSize: 112 -# CHECK-NEXT: MemSize: 112 -# CHECK-NEXT: Flags [ -# CHECK-NEXT: PF_R -# CHECK-NEXT: PF_W -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 4096 -# CHECK-NEXT: } -# CHECK-NEXT: ProgramHeader { -# CHECK-NEXT: Type: PT_DYNAMIC -# CHECK-NEXT: Offset: 0x1000 -# CHECK-NEXT: VirtualAddress: 0x1000 -# CHECK-NEXT: PhysicalAddress: 0x1000 -# CHECK-NEXT: FileSize: 112 -# CHECK-NEXT: MemSize: 112 -# CHECK-NEXT: Flags [ -# CHECK-NEXT: PF_R -# CHECK-NEXT: PF_W -# CHECK-NEXT: ] -# CHECK-NEXT: Alignment: 8 -# CHECK-NEXT: } + +# CHECK: Type: PT_DYNAMIC + +## Check -nopie +# RUN: ld.lld -nopie %t1.o -o %t2 +# RUN: llvm-readobj -file-headers -r %t2 | FileCheck %s --check-prefix=NOPIE +# NOPIE-NOT: Type: SharedObject .globl _start _start: diff --git a/test/ELF/plt-aarch64.s b/test/ELF/plt-aarch64.s index 3f124b0af49c3..9bc6f54743aa7 100644 --- a/test/ELF/plt-aarch64.s +++ b/test/ELF/plt-aarch64.s @@ -18,7 +18,7 @@ // CHECKDSO-NEXT: SHF_ALLOC // CHECKDSO-NEXT: SHF_EXECINSTR // CHECKDSO-NEXT: ] -// CHECKDSO-NEXT: Address: 0x1010 +// CHECKDSO-NEXT: Address: 0x10010 // CHECKDSO-NEXT: Offset: // CHECKDSO-NEXT: Size: 80 // CHECKDSO-NEXT: Link: @@ -31,7 +31,7 @@ // CHECKDSO-NEXT: SHF_ALLOC // CHECKDSO-NEXT: SHF_WRITE // CHECKDSO-NEXT: ] -// CHECKDSO-NEXT: Address: 0x3000 +// CHECKDSO-NEXT: Address: 0x30000 // CHECKDSO-NEXT: Offset: // CHECKDSO-NEXT: Size: 48 // CHECKDSO-NEXT: Link: @@ -41,72 +41,72 @@ // CHECKDSO: Relocations [ // CHECKDSO-NEXT: Section ({{.*}}) .rela.plt { -// &(.got.plt[3]) = 0x3000 + 3 * 8 = 0x3018 -// CHECKDSO-NEXT: 0x3018 R_AARCH64_JUMP_SLOT foo +// &(.got.plt[3]) = 0x30000 + 3 * 8 = 0x30018 +// CHECKDSO-NEXT: 0x30018 R_AARCH64_JUMP_SLOT foo -// &(.got.plt[4]) = 0x3000 + 4 * 8 = 0x3020 -// CHECKDSO-NEXT: 0x3020 R_AARCH64_JUMP_SLOT bar +// &(.got.plt[4]) = 0x30000 + 4 * 8 = 0x30020 +// CHECKDSO-NEXT: 0x30020 R_AARCH64_JUMP_SLOT bar -// &(.got.plt[5]) = 0x3000 + 5 * 8 = 0x3028 -// CHECKDSO-NEXT: 0x3028 R_AARCH64_JUMP_SLOT weak +// &(.got.plt[5]) = 0x30000 + 5 * 8 = 0x30028 +// CHECKDSO-NEXT: 0x30028 R_AARCH64_JUMP_SLOT weak // CHECKDSO-NEXT: } // CHECKDSO-NEXT: ] // DUMPDSO: Contents of section .got.plt: // .got.plt[0..2] = 0 (reserved) -// .got.plt[3..5] = .plt = 0x1010 -// DUMPDSO-NEXT: 3000 00000000 00000000 00000000 00000000 ................ -// DUMPDSO-NEXT: 3010 00000000 00000000 10100000 00000000 ................ -// DUMPDSO-NEXT: 3020 10100000 00000000 10100000 00000000 ................ +// .got.plt[3..5] = .plt = 0x10010 +// DUMPDSO-NEXT: 30000 00000000 00000000 00000000 00000000 ................ +// DUMPDSO-NEXT: 30010 00000000 00000000 10000100 00000000 ................ +// DUMPDSO-NEXT: 30020 10000100 00000000 10000100 00000000 ................ // DISASMDSO: _start: -// 0x1030 - 0x1000 = 0x30 = 48 -// DISASMDSO-NEXT: 1000: 0c 00 00 14 b #48 -// 0x1040 - 0x1004 = 0x3c = 60 -// DISASMDSO-NEXT: 1004: 0f 00 00 14 b #60 -// 0x1050 - 0x1008 = 0x48 = 72 -// DISASMDSO-NEXT: 1008: 12 00 00 14 b #72 +// 0x10030 - 0x10000 = 0x30 = 48 +// DISASMDSO-NEXT: 10000: 0c 00 00 14 b #48 +// 0x10040 - 0x10004 = 0x3c = 60 +// DISASMDSO-NEXT: 10004: 0f 00 00 14 b #60 +// 0x10050 - 0x10008 = 0x48 = 72 +// DISASMDSO-NEXT: 10008: 12 00 00 14 b #72 // DISASMDSO: foo: -// DISASMDSO-NEXT: 100c: 1f 20 03 d5 nop +// DISASMDSO-NEXT: 1000c: 1f 20 03 d5 nop // DISASMDSO: Disassembly of section .plt: // DISASMDSO-NEXT: .plt: -// DISASMDSO-NEXT: 1010: f0 7b bf a9 stp x16, x30, [sp, #-16]! +// DISASMDSO-NEXT: 10010: f0 7b bf a9 stp x16, x30, [sp, #-16]! // &(.got.plt[2]) = 0x3000 + 2 * 8 = 0x3010 -// Page(0x3010) - Page(0x1014) = 0x3000 - 0x1000 = 0x2000 = 8192 -// DISASMDSO-NEXT: 1014: 10 00 00 d0 adrp x16, #8192 +// Page(0x30010) - Page(0x10014) = 0x30000 - 0x10000 = 0x20000 = 131072 +// DISASMDSO-NEXT: 10014: 10 01 00 90 adrp x16, #131072 // 0x3010 & 0xFFF = 0x10 = 16 -// DISASMDSO-NEXT: 1018: 11 0a 40 f9 ldr x17, [x16, #16] -// DISASMDSO-NEXT: 101c: 10 42 00 91 add x16, x16, #16 -// DISASMDSO-NEXT: 1020: 20 02 1f d6 br x17 -// DISASMDSO-NEXT: 1024: 1f 20 03 d5 nop -// DISASMDSO-NEXT: 1028: 1f 20 03 d5 nop -// DISASMDSO-NEXT: 102c: 1f 20 03 d5 nop +// DISASMDSO-NEXT: 10018: 11 0a 40 f9 ldr x17, [x16, #16] +// DISASMDSO-NEXT: 1001c: 10 42 00 91 add x16, x16, #16 +// DISASMDSO-NEXT: 10020: 20 02 1f d6 br x17 +// DISASMDSO-NEXT: 10024: 1f 20 03 d5 nop +// DISASMDSO-NEXT: 10028: 1f 20 03 d5 nop +// DISASMDSO-NEXT: 1002c: 1f 20 03 d5 nop // foo@plt -// Page(0x3018) - Page(0x1030) = 0x3000 - 0x1000 = 0x2000 = 8192 -// DISASMDSO-NEXT: 1030: 10 00 00 d0 adrp x16, #8192 +// Page(0x30018) - Page(0x10030) = 0x30000 - 0x10000 = 0x20000 = 131072 +// DISASMDSO-NEXT: 10030: 10 01 00 90 adrp x16, #131072 // 0x3018 & 0xFFF = 0x18 = 24 -// DISASMDSO-NEXT: 1034: 11 0e 40 f9 ldr x17, [x16, #24] -// DISASMDSO-NEXT: 1038: 10 62 00 91 add x16, x16, #24 -// DISASMDSO-NEXT: 103c: 20 02 1f d6 br x17 +// DISASMDSO-NEXT: 10034: 11 0e 40 f9 ldr x17, [x16, #24] +// DISASMDSO-NEXT: 10038: 10 62 00 91 add x16, x16, #24 +// DISASMDSO-NEXT: 1003c: 20 02 1f d6 br x17 // bar@plt -// Page(0x3020) - Page(0x1040) = 0x3000 - 0x1000 = 0x2000 = 8192 -// DISASMDSO-NEXT: 1040: 10 00 00 d0 adrp x16, #8192 +// Page(0x30020) - Page(0x10040) = 0x30000 - 0x10000 = 0x20000 = 131072 +// DISASMDSO-NEXT: 10040: 10 01 00 90 adrp x16, #131072 // 0x3020 & 0xFFF = 0x20 = 32 -// DISASMDSO-NEXT: 1044: 11 12 40 f9 ldr x17, [x16, #32] -// DISASMDSO-NEXT: 1048: 10 82 00 91 add x16, x16, #32 -// DISASMDSO-NEXT: 104c: 20 02 1f d6 br x17 +// DISASMDSO-NEXT: 10044: 11 12 40 f9 ldr x17, [x16, #32] +// DISASMDSO-NEXT: 10048: 10 82 00 91 add x16, x16, #32 +// DISASMDSO-NEXT: 1004c: 20 02 1f d6 br x17 // weak@plt -// Page(0x3028) - Page(0x1050) = 0x3000 - 0x1000 = 0x2000 = 8192 -// DISASMDSO-NEXT: 1050: 10 00 00 d0 adrp x16, #8192 +// Page(0x30028) - Page(0x10050) = 0x30000 - 0x10000 = 0x20000 = 131072 +// DISASMDSO-NEXT: 10050: 10 01 00 90 adrp x16, #131072 // 0x3028 & 0xFFF = 0x28 = 40 -// DISASMDSO-NEXT: 1054: 11 16 40 f9 ldr x17, [x16, #40] -// DISASMDSO-NEXT: 1058: 10 a2 00 91 add x16, x16, #40 -// DISASMDSO-NEXT: 105c: 20 02 1f d6 br x17 +// DISASMDSO-NEXT: 10054: 11 16 40 f9 ldr x17, [x16, #40] +// DISASMDSO-NEXT: 10058: 10 a2 00 91 add x16, x16, #40 +// DISASMDSO-NEXT: 1005c: 20 02 1f d6 br x17 // CHECKEXE: Name: .plt // CHECKEXE-NEXT: Type: SHT_PROGBITS @@ -114,7 +114,7 @@ // CHECKEXE-NEXT: SHF_ALLOC // CHECKEXE-NEXT: SHF_EXECINSTR // CHECKEXE-NEXT: ] -// CHECKEXE-NEXT: Address: 0x11010 +// CHECKEXE-NEXT: Address: 0x20010 // CHECKEXE-NEXT: Offset: // CHECKEXE-NEXT: Size: 64 // CHECKEXE-NEXT: Link: @@ -127,7 +127,7 @@ // CHECKEXE-NEXT: SHF_ALLOC // CHECKEXE-NEXT: SHF_WRITE // CHECKEXE-NEXT: ] -// CHECKEXE-NEXT: Address: 0x13000 +// CHECKEXE-NEXT: Address: 0x40000 // CHECKEXE-NEXT: Offset: // CHECKEXE-NEXT: Size: 40 // CHECKEXE-NEXT: Link: @@ -138,60 +138,58 @@ // CHECKEXE-NEXT: Section ({{.*}}) .rela.plt { // &(.got.plt[3]) = 0x13000 + 3 * 8 = 0x13018 -// CHECKEXE-NEXT: 0x13018 R_AARCH64_JUMP_SLOT bar 0x0 +// CHECKEXE-NEXT: 0x40018 R_AARCH64_JUMP_SLOT bar 0x0 // &(.got.plt[4]) = 0x13000 + 4 * 8 = 0x13020 -// CHECKEXE-NEXT: 0x13020 R_AARCH64_JUMP_SLOT weak 0x0 +// CHECKEXE-NEXT: 0x40020 R_AARCH64_JUMP_SLOT weak 0x0 // CHECKEXE-NEXT: } // CHECKEXE-NEXT: ] // DUMPEXE: Contents of section .got.plt: // .got.plt[0..2] = 0 (reserved) -// .got.plt[3..4] = .plt = 0x11010 -// DUMPEXE-NEXT: 13000 00000000 00000000 00000000 00000000 ................ -// DUMPEXE-NEXT: 13010 00000000 00000000 10100100 00000000 ................ -// DUMPEXE-NEXT: 13020 10100100 00000000 ........ +// .got.plt[3..4] = .plt = 0x40010 +// DUMPEXE-NEXT: 40000 00000000 00000000 00000000 00000000 ................ +// DUMPEXE-NEXT: 40010 00000000 00000000 10000200 00000000 ................ +// DUMPEXE-NEXT: 40020 10000200 00000000 ........ // DISASMEXE: _start: -// 0x1100c - 0x11000 = 0xc = 12 -// DISASMEXE-NEXT: 11000: 03 00 00 14 b #12 -// 0x11030 - 0x11004 = 0x2c = 44 -// DISASMEXE-NEXT: 11004: 0b 00 00 14 b #44 -// 0x11040 - 0x11008 = 0x38 = 56 -// DISASMEXE-NEXT: 11008: 0e 00 00 14 b #56 +// 0x2000c - 0x20000 = 0xc = 12 +// DISASMEXE-NEXT: 20000: 03 00 00 14 b #12 +// 0x20030 - 0x20004 = 0x2c = 44 +// DISASMEXE-NEXT: 20004: 0b 00 00 14 b #44 +// 0x20040 - 0x20008 = 0x38 = 56 +// DISASMEXE-NEXT: 20008: 0e 00 00 14 b #56 // DISASMEXE: foo: -// DISASMEXE-NEXT: 1100c: 1f 20 03 d5 nop +// DISASMEXE-NEXT: 2000c: 1f 20 03 d5 nop // DISASMEXE: Disassembly of section .plt: // DISASMEXE-NEXT: .plt: -// DISASMEXE-NEXT: 11010: f0 7b bf a9 stp x16, x30, [sp, #-16]! -// &(.got.plt[2]) = 0x120B0 + 2 * 8 = 0x120C0 -// Page(0x13010) - Page(0x11014) = 0x13000 - 0x11000 = 0x1000 = 8192 -// DISASMEXE-NEXT: 11014: 10 00 00 d0 adrp x16, #8192 +// DISASMEXE-NEXT: 20010: f0 7b bf a9 stp x16, x30, [sp, #-16]! +// &(.got.plt[2]) = 0x300B0 + 2 * 8 = 0x300C0 +// Page(0x40010) - Page(0x20014) = 0x40000 - 0x20000 = 0x20000 = 131072 +// DISASMEXE-NEXT: 20014: 10 01 00 90 adrp x16, #131072 // 0x120c0 & 0xFFF = 0xC0 = 192 -// DISASMEXE-NEXT: 11018: 11 0a 40 f9 ldr x17, [x16, #16] -// DISASMEXE-NEXT: 1101c: 10 42 00 91 add x16, x16, #16 -// DISASMEXE-NEXT: 11020: 20 02 1f d6 br x17 -// DISASMEXE-NEXT: 11024: 1f 20 03 d5 nop -// DISASMEXE-NEXT: 11028: 1f 20 03 d5 nop -// DISASMEXE-NEXT: 1102c: 1f 20 03 d5 nop +// DISASMEXE-NEXT: 20018: 11 0a 40 f9 ldr x17, [x16, #16] +// DISASMEXE-NEXT: 2001c: 10 42 00 91 add x16, x16, #16 +// DISASMEXE-NEXT: 20020: 20 02 1f d6 br x17 +// DISASMEXE-NEXT: 20024: 1f 20 03 d5 nop +// DISASMEXE-NEXT: 20028: 1f 20 03 d5 nop +// DISASMEXE-NEXT: 2002c: 1f 20 03 d5 nop // bar@plt -// Page(0x13018) - Page(0x11030) = 0x12000 - 0x11000 = 0x1000 = 8192 -// DISASMEXE-NEXT: 11030: 10 00 00 d0 adrp x16, #8192 -// 0x120C8 & 0xFFF = 0xC8 = 200 -// DISASMEXE-NEXT: 11034: 11 0e 40 f9 ldr x17, [x16, #24] -// DISASMEXE-NEXT: 11038: 10 62 00 91 add x16, x16, #24 -// DISASMEXE-NEXT: 1103c: 20 02 1f d6 br x17 +// Page(0x40018) - Page(0x20030) = 0x40000 - 0x20000 = 0x20000 = 131072 +// DISASMEXE-NEXT: 20030: 10 01 00 90 adrp x16, #131072 +// DISASMEXE-NEXT: 20034: 11 0e 40 f9 ldr x17, [x16, #24] +// DISASMEXE-NEXT: 20038: 10 62 00 91 add x16, x16, #24 +// DISASMEXE-NEXT: 2003c: 20 02 1f d6 br x17 // weak@plt -// Page(0x13020) - Page(0x11040) = 0x12000 - 0x11000 = 0x1000 = 8192 -// DISASMEXE-NEXT: 11040: 10 00 00 d0 adrp x16, #8192 -// 0x120D0 & 0xFFF = 0xD0 = 208 -// DISASMEXE-NEXT: 11044: 11 12 40 f9 ldr x17, [x16, #32] -// DISASMEXE-NEXT: 11048: 10 82 00 91 add x16, x16, #32 -// DISASMEXE-NEXT: 1104c: 20 02 1f d6 br x17 +// Page(0x40020) - Page(0x20040) = 0x40000 - 0x20000 = 0x20000 = 131072 +// DISASMEXE-NEXT: 20040: 10 01 00 90 adrp x16, #131072 +// DISASMEXE-NEXT: 20044: 11 12 40 f9 ldr x17, [x16, #32] +// DISASMEXE-NEXT: 20048: 10 82 00 91 add x16, x16, #32 +// DISASMEXE-NEXT: 2004c: 20 02 1f d6 br x17 .global _start,foo,bar .weak weak diff --git a/test/ELF/plt.s b/test/ELF/plt.s index 60268a68195a9..0153e82786aee 100644 --- a/test/ELF/plt.s +++ b/test/ELF/plt.s @@ -37,7 +37,7 @@ // CHECK2-NEXT: SHF_ALLOC // CHECK2-NEXT: SHF_EXECINSTR // CHECK2-NEXT: ] -// CHECK2-NEXT: Address: 0x11020 +// CHECK2-NEXT: Address: 0x201020 // CHECK2-NEXT: Offset: // CHECK2-NEXT: Size: 48 // CHECK2-NEXT: Link: 0 @@ -46,8 +46,8 @@ // CHECK2: Relocations [ // CHECK2-NEXT: Section ({{.*}}) .rela.plt { -// CHECK2-NEXT: 0x13018 R_X86_64_JUMP_SLOT bar 0x0 -// CHECK2-NEXT: 0x13020 R_X86_64_JUMP_SLOT zed 0x0 +// CHECK2-NEXT: 0x203018 R_X86_64_JUMP_SLOT bar 0x0 +// CHECK2-NEXT: 0x203020 R_X86_64_JUMP_SLOT zed 0x0 // CHECK2-NEXT: } // CHECK2-NEXT: ] @@ -84,32 +84,32 @@ // DISASM-NEXT: 1056: 68 02 00 00 00 pushq $2 // DISASM-NEXT: 105b: e9 c0 ff ff ff jmp -64 <.plt> -// 0x11030 - (0x11000 + 1) - 4 = 43 -// 0x11030 - (0x11005 + 1) - 4 = 38 -// 0x11040 - (0x1100a + 1) - 4 = 49 -// 0x11000 - (0x1100f + 1) - 4 = -20 +// 0x201030 - (0x201000 + 1) - 4 = 43 +// 0x201030 - (0x201005 + 1) - 4 = 38 +// 0x201040 - (0x20100a + 1) - 4 = 49 +// 0x201000 - (0x20100f + 1) - 4 = -20 // DISASM2: _start: -// DISASM2-NEXT: 11000: e9 {{.*}} jmp 43 -// DISASM2-NEXT: 11005: e9 {{.*}} jmp 38 -// DISASM2-NEXT: 1100a: e9 {{.*}} jmp 49 -// DISASM2-NEXT: 1100f: e9 {{.*}} jmp -20 +// DISASM2-NEXT: 201000: e9 {{.*}} jmp 43 +// DISASM2-NEXT: 201005: e9 {{.*}} jmp 38 +// DISASM2-NEXT: 20100a: e9 {{.*}} jmp 49 +// DISASM2-NEXT: 20100f: e9 {{.*}} jmp -20 -// 0x13018 - 0x11036 = 4242 -// 0x13020 - 0x11046 = 4234 +// 0x203018 - 0x201036 = 4242 +// 0x203020 - 0x201046 = 4234 // DISASM2: Disassembly of section .plt: // DISASM2-NEXT: .plt: -// DISASM2-NEXT: 11020: ff 35 e2 1f 00 00 pushq 8162(%rip) -// DISASM2-NEXT: 11026: ff 25 e4 1f 00 00 jmpq *8164(%rip) -// DISASM2-NEXT: 1102c: 0f 1f 40 00 nopl (%rax) -// DISASM2-NEXT: 11030: ff 25 e2 1f 00 00 jmpq *8162(%rip) -// DISASM2-NEXT: 11036: 68 00 00 00 00 pushq $0 -// DISASM2-NEXT: 1103b: e9 e0 ff ff ff jmp -32 <.plt> -// DISASM2-NEXT: 11040: ff 25 da 1f 00 00 jmpq *8154(%rip) -// DISASM2-NEXT: 11046: 68 01 00 00 00 pushq $1 -// DISASM2-NEXT: 1104b: e9 d0 ff ff ff jmp -48 <.plt> -// DISASM2-NOT: 110C0 +// DISASM2-NEXT: 201020: ff 35 e2 1f 00 00 pushq 8162(%rip) +// DISASM2-NEXT: 201026: ff 25 e4 1f 00 00 jmpq *8164(%rip) +// DISASM2-NEXT: 20102c: 0f 1f 40 00 nopl (%rax) +// DISASM2-NEXT: 201030: ff 25 e2 1f 00 00 jmpq *8162(%rip) +// DISASM2-NEXT: 201036: 68 00 00 00 00 pushq $0 +// DISASM2-NEXT: 20103b: e9 e0 ff ff ff jmp -32 <.plt> +// DISASM2-NEXT: 201040: ff 25 da 1f 00 00 jmpq *8154(%rip) +// DISASM2-NEXT: 201046: 68 01 00 00 00 pushq $1 +// DISASM2-NEXT: 20104b: e9 d0 ff ff ff jmp -48 <.plt> +// DISASM2-NOT: 2010C0 .global _start _start: diff --git a/test/ELF/ppc-relocs.s b/test/ELF/ppc-relocs.s index a70cac1615e0d..78542dd64a4c1 100644 --- a/test/ELF/ppc-relocs.s +++ b/test/ELF/ppc-relocs.s @@ -28,3 +28,37 @@ mystr: # CHECK: 11008: 38 84 10 04 addi 4, 4, 4100 # CHECK: mystr: # CHECK: 1100c: 62 6c 61 68 ori 12, 19, 24936 + +.align 2 +.section .R_PPC_REL24,"ax",@progbits +.globl .FR_PPC_REL24 +.FR_PPC_REL24: + b .Lfoox +.section .R_PPC_REL24_2,"ax",@progbits +.Lfoox: + +# CHECK: Disassembly of section .R_PPC_REL24: +# CHECK: .FR_PPC_REL24: +# CHECK: 11014: 48 00 00 04 b .+4 + +.section .R_PPC_REL32,"ax",@progbits +.globl .FR_PPC_REL32 +.FR_PPC_REL32: + .long .Lfoox3 - . +.section .R_PPC_REL32_2,"ax",@progbits +.Lfoox3: + +# CHECK: Disassembly of section .R_PPC_REL32: +# CHECK: .FR_PPC_REL32: +# CHECK: 11018: 00 00 00 04 + +.section .R_PPC_ADDR32,"ax",@progbits +.globl .FR_PPC_ADDR32 +.FR_PPC_ADDR32: + .long .Lfoox2 +.section .R_PPC_ADDR32_2,"ax",@progbits +.Lfoox2: + +# CHECK: Disassembly of section .R_PPC_ADDR32: +# CHECK: .FR_PPC_ADDR32: +# CHECK: 1101c: 00 01 10 20 diff --git a/test/ELF/pre_init_fini_array.s b/test/ELF/pre_init_fini_array.s index 4ddcb6947e5b7..1192fd0dc851a 100644 --- a/test/ELF/pre_init_fini_array.s +++ b/test/ELF/pre_init_fini_array.s @@ -63,7 +63,7 @@ _start: // CHECK-NEXT: ] // CHECK: Name: __fini_array_end -// CHECK-NEXT: Value: 0x1201B +// CHECK-NEXT: Value: 0x20201B // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -85,7 +85,7 @@ _start: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: __init_array_end -// CHECK-NEXT: Value: 0x12008 +// CHECK-NEXT: Value: 0x202008 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -107,7 +107,7 @@ _start: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: __preinit_array_end -// CHECK-NEXT: Value: 0x12011 +// CHECK-NEXT: Value: 0x202011 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -137,16 +137,16 @@ _start: // CHECK: FINI_ARRAYSZ [[FINI_SIZE]] (bytes) -// 0x12008 - (0x11000 + 5) = 4099 -// 0x12011 - (0x11005 + 5) = 4103 -// 0x12000 - (0x1100a + 5) = 4081 -// 0x12008 - (0x1100f + 5) = 4084 -// 0x12011 - (0x11014 + 5) = 4088 -// 0x1201B - (0x11019 + 5) = 4093 +// 0x202008 - (0x201000 + 5) = 4099 +// 0x202011 - (0x201005 + 5) = 4103 +// 0x202000 - (0x20100a + 5) = 4081 +// 0x202008 - (0x20100f + 5) = 4084 +// 0x202011 - (0x201014 + 5) = 4088 +// 0x20201B - (0x201019 + 5) = 4093 // DISASM: _start: -// DISASM-NEXT: 11000: e8 {{.*}} callq 4099 -// DISASM-NEXT: 11005: e8 {{.*}} callq 4103 -// DISASM-NEXT: 1100a: e8 {{.*}} callq 4081 -// DISASM-NEXT: 1100f: e8 {{.*}} callq 4084 -// DISASM-NEXT: 11014: e8 {{.*}} callq 4088 -// DISASM-NEXT: 11019: e8 {{.*}} callq 4093 +// DISASM-NEXT: 201000: e8 {{.*}} callq 4099 +// DISASM-NEXT: 201005: e8 {{.*}} callq 4103 +// DISASM-NEXT: 20100a: e8 {{.*}} callq 4081 +// DISASM-NEXT: 20100f: e8 {{.*}} callq 4084 +// DISASM-NEXT: 201014: e8 {{.*}} callq 4088 +// DISASM-NEXT: 201019: e8 {{.*}} callq 4093 diff --git a/test/ELF/pre_init_fini_array_missing.s b/test/ELF/pre_init_fini_array_missing.s index 02b83240193ea..de976805d76cc 100644 --- a/test/ELF/pre_init_fini_array_missing.s +++ b/test/ELF/pre_init_fini_array_missing.s @@ -13,18 +13,18 @@ _start: call __fini_array_end // With no .init_array section the symbols resolve to 0 -// 0 - (0x11000 + 5) = -69637 -// 0 - (0x11005 + 5) = -69642 -// 0 - (0x1100a + 5) = -69647 -// 0 - (0x1100f + 5) = -69652 -// 0 - (0x11014 + 5) = -69657 -// 0 - (0x11019 + 5) = -69662 +// 0 - (0x201000 + 5) = -2101253 +// 0 - (0x201005 + 5) = -2101258 +// 0 - (0x20100a + 5) = -2101263 +// 0 - (0x20100f + 5) = -2101268 +// 0 - (0x201014 + 5) = -2101273 +// 0 - (0x201019 + 5) = -2101278 // CHECK: Disassembly of section .text: // CHECK-NEXT: _start: -// CHECK-NEXT: 11000: e8 fb ef fe ff callq -69637 -// CHECK-NEXT: 11005: e8 f6 ef fe ff callq -69642 -// CHECK-NEXT: 1100a: e8 f1 ef fe ff callq -69647 -// CHECK-NEXT: 1100f: e8 ec ef fe ff callq -69652 -// CHECK-NEXT: 11014: e8 e7 ef fe ff callq -69657 -// CHECK-NEXT: 11019: e8 e2 ef fe ff callq -69662 +// 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 diff --git a/test/ELF/program-header-layout.s b/test/ELF/program-header-layout.s index 8e32227ac741a..57759c946dace 100644 --- a/test/ELF/program-header-layout.s +++ b/test/ELF/program-header-layout.s @@ -35,8 +35,8 @@ _start: # CHECK-NEXT: ProgramHeader { # CHECK-NEXT: Type: PT_PHDR (0x6) # CHECK-NEXT: Offset: 0x40 -# CHECK-NEXT: VirtualAddress: 0x10040 -# CHECK-NEXT: PhysicalAddress: 0x10040 +# CHECK-NEXT: VirtualAddress: 0x200040 +# CHECK-NEXT: PhysicalAddress: 0x200040 # CHECK-NEXT: FileSize: 280 # CHECK-NEXT: MemSize: 280 # CHECK-NEXT: Flags [ (0x4) @@ -61,19 +61,6 @@ _start: # CHECK-NEXT: Offset: # CHECK-NEXT: VirtualAddress: # CHECK-NEXT: PhysicalAddress: -# CHECK-NEXT: FileSize: 0 -# CHECK-NEXT: MemSize: 0 -# 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: -# CHECK-NEXT: VirtualAddress: -# CHECK-NEXT: PhysicalAddress: # CHECK-NEXT: FileSize: 16 # CHECK-NEXT: MemSize: 16 # CHECK-NEXT: Flags [ diff --git a/test/ELF/relative-dynamic-reloc-ppc64.s b/test/ELF/relative-dynamic-reloc-ppc64.s index 81a7a7027bb8a..1df974b087c9b 100644 --- a/test/ELF/relative-dynamic-reloc-ppc64.s +++ b/test/ELF/relative-dynamic-reloc-ppc64.s @@ -28,7 +28,7 @@ // CHECK: DynamicSymbols [ // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: @ (0) +// CHECK-NEXT: Name: @ // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local diff --git a/test/ELF/relative-dynamic-reloc.s b/test/ELF/relative-dynamic-reloc.s index aac55669bb17a..947c86d890241 100644 --- a/test/ELF/relative-dynamic-reloc.s +++ b/test/ELF/relative-dynamic-reloc.s @@ -27,7 +27,7 @@ // CHECK: DynamicSymbols [ // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: @ (0) +// CHECK-NEXT: Name: @ // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local diff --git a/test/ELF/relocatable-comment.s b/test/ELF/relocatable-comment.s new file mode 100644 index 0000000000000..8ec22c2f43de2 --- /dev/null +++ b/test/ELF/relocatable-comment.s @@ -0,0 +1,27 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: ld.lld -r %t1.o -o %t +# RUN: llvm-readobj -s -section-data %t | FileCheck %s + +# CHECK: Name: .comment +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: Flags [ +# CHECK-NEXT: SHF_MERGE +# CHECK-NEXT: SHF_STRINGS +# CHECK-NEXT: ] +# CHECK-NEXT: Address: +# CHECK-NEXT: Offset: +# CHECK-NEXT: Size: 7 +# CHECK-NEXT: Link: +# CHECK-NEXT: Info: +# CHECK-NEXT: AddressAlignment: 1 +# CHECK-NEXT: EntrySize: 1 +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 666F6F62 617200 |foobar.| +# CHECK-NEXT: ) + + +# We used to crash creating a merge and non merge .comment sections. + + .section .comment,"MS",@progbits,1 + .asciz "foobar" diff --git a/test/ELF/relocatable-local-sym.s b/test/ELF/relocatable-local-sym.s new file mode 100644 index 0000000000000..b894d6b9900c1 --- /dev/null +++ b/test/ELF/relocatable-local-sym.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: ld.lld -r %t1.o -o %t2.o +# RUN: llvm-readobj -r %t2.o | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: Section ({{.*}}) .rela.text { +# CHECK-NEXT: 0x3 R_X86_64_PC32 .Lstr 0xFFFFFFFFFFFFFFFC +# CHECK-NEXT: } +# CHECK-NEXT: ] + + leaq .Lstr(%rip), %rdi + + .section .rodata.str1.1,"aMS",@progbits,1 + .Lstr: + .asciz "abc\n" diff --git a/test/ELF/relocatable-sections.s b/test/ELF/relocatable-sections.s new file mode 100644 index 0000000000000..d6a922fba4827 --- /dev/null +++ b/test/ELF/relocatable-sections.s @@ -0,0 +1,30 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: ld.lld -r %t1.o -o %t +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +# CHECK: .text +# CHECK-NEXT: .rela.text +# CHECK: .text._init +# CHECK-NEXT: .rela.text._init +# CHECK: .text._fini +# CHECK-NEXT: .rela.text._fini + +.globl _start +_start: + call foo + nop + +.section .xxx,"a" + .quad 0 + +.section .text._init,"ax" + .quad .xxx +foo: + call bar + nop + + +.section .text._fini,"ax" + .quad .xxx +bar: + nop diff --git a/test/ELF/relocatable-symbols.s b/test/ELF/relocatable-symbols.s index 75ed17ec5f6ff..79608e7b74f04 100644 --- a/test/ELF/relocatable-symbols.s +++ b/test/ELF/relocatable-symbols.s @@ -2,6 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: ld.lld -r %t -o %tout # RUN: llvm-objdump -d %tout | FileCheck -check-prefix=DISASM %s +# RUN: llvm-readobj -r %t | FileCheck -check-prefix=RELOC %s # RUN: llvm-readobj -symbols -r %tout | FileCheck -check-prefix=SYMBOL %s # DISASM: _start: @@ -28,20 +29,37 @@ # DISASM-NEXT: 1: 90 nop # DISASM-NEXT: 2: 90 nop +# RELOC: Relocations [ +# RELOC-NEXT: Section ({{.*}}) .rela.text { +# RELOC-NEXT: 0x1 R_X86_64_PC32 __start_foo 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0x6 R_X86_64_PC32 __stop_foo 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0xB R_X86_64_PC32 __start_bar 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0x10 R_X86_64_PC32 __stop_bar 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0x15 R_X86_64_PC32 __start_doo 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0x1A R_X86_64_PC32 __stop_doo 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0x1F R_X86_64_PC32 __preinit_array_start 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0x24 R_X86_64_PC32 __preinit_array_end 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0x29 R_X86_64_PC32 __init_array_start 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0x2E R_X86_64_PC32 __init_array_end 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0x33 R_X86_64_PC32 __fini_array_start 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: 0x38 R_X86_64_PC32 __fini_array_end 0xFFFFFFFFFFFFFFFC +# RELOC-NEXT: } +# RELOC-NEXT: ] + # SYMBOL: Relocations [ # SYMBOL-NEXT: Section ({{.*}}) .rela.text { -# SYMBOL-NEXT: 0x1 R_X86_64_PC32 __start_foo 0x0 -# SYMBOL-NEXT: 0x6 R_X86_64_PC32 __stop_foo 0x0 -# SYMBOL-NEXT: 0xB R_X86_64_PC32 __start_bar 0x0 -# SYMBOL-NEXT: 0x10 R_X86_64_PC32 __stop_bar 0x0 -# SYMBOL-NEXT: 0x15 R_X86_64_PC32 __start_doo 0x0 -# SYMBOL-NEXT: 0x1A R_X86_64_PC32 __stop_doo 0x0 -# SYMBOL-NEXT: 0x1F R_X86_64_PC32 __preinit_array_start 0x0 -# SYMBOL-NEXT: 0x24 R_X86_64_PC32 __preinit_array_end 0x0 -# SYMBOL-NEXT: 0x29 R_X86_64_PC32 __init_array_start 0x0 -# SYMBOL-NEXT: 0x2E R_X86_64_PC32 __init_array_end 0x0 -# SYMBOL-NEXT: 0x33 R_X86_64_PC32 __fini_array_start 0x0 -# SYMBOL-NEXT: 0x38 R_X86_64_PC32 __fini_array_end 0x0 +# SYMBOL-NEXT: 0x1 R_X86_64_PC32 __start_foo 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0x6 R_X86_64_PC32 __stop_foo 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0xB R_X86_64_PC32 __start_bar 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0x10 R_X86_64_PC32 __stop_bar 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0x15 R_X86_64_PC32 __start_doo 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0x1A R_X86_64_PC32 __stop_doo 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0x1F R_X86_64_PC32 __preinit_array_start 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0x24 R_X86_64_PC32 __preinit_array_end 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0x29 R_X86_64_PC32 __init_array_start 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0x2E R_X86_64_PC32 __init_array_end 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0x33 R_X86_64_PC32 __fini_array_start 0xFFFFFFFFFFFFFFFC +# SYMBOL-NEXT: 0x38 R_X86_64_PC32 __fini_array_end 0xFFFFFFFFFFFFFFFC # SYMBOL-NEXT: } # SYMBOL-NEXT: ] # SYMBOL: Symbol { diff --git a/test/ELF/relocatable-tls.s b/test/ELF/relocatable-tls.s new file mode 100644 index 0000000000000..88d38c2ae4b4a --- /dev/null +++ b/test/ELF/relocatable-tls.s @@ -0,0 +1,15 @@ +# 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: %S/Inputs/relocatable-tls.s -o %t2.o + +# RUN: ld.lld -r %t2.o -o %t3.r +# RUN: llvm-objdump -t %t3.r | FileCheck --check-prefix=RELOCATABLE %s +# RELOCATABLE: SYMBOL TABLE: +# RELOCATABLE: 0000000000000000 *UND* 00000000 __tls_get_addr + +# RUN: ld.lld -shared %t2.o %t3.r -o %t4.out +# RUN: llvm-objdump -t %t4.out | FileCheck --check-prefix=DSO %s +# DSO: SYMBOL TABLE: +# DSO: 0000000000000000 *UND* 00000000 __tls_get_addr + +callq __tls_get_addr@PLT diff --git a/test/ELF/relocatable-visibility.s b/test/ELF/relocatable-visibility.s new file mode 100644 index 0000000000000..7cc7da3097bb1 --- /dev/null +++ b/test/ELF/relocatable-visibility.s @@ -0,0 +1,19 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld -r %t.o -o %t1 +# RUN: llvm-readobj -t %t1 | FileCheck --check-prefix=RELOCATABLE %s + +# RELOCATABLE: Name: foo +# RELOCATABLE-NEXT: Value: 0x0 +# RELOCATABLE-NEXT: Size: 0 +# RELOCATABLE-NEXT: Binding: Global +# RELOCATABLE-NEXT: Type: None +# RELOCATABLE-NEXT: Other [ +# RELOCATABLE-NEXT: STV_HIDDEN +# RELOCATABLE-NEXT: ] +# RELOCATABLE-NEXT: Section: Undefined + +.global _start +_start: + callq foo + .hidden foo diff --git a/test/ELF/relocatable.s b/test/ELF/relocatable.s index 032cb6336c08e..14e9d605892eb 100644 --- a/test/ELF/relocatable.s +++ b/test/ELF/relocatable.s @@ -42,7 +42,7 @@ # CHECK-NEXT: } # CHECK: Relocations [ -# CHECK-NEXT: Section (3) .rela.text { +# CHECK-NEXT: Section ({{.*}}) .rela.text { # CHECK-NEXT: 0x3 R_X86_64_32S x 0x0 # CHECK-NEXT: 0xE R_X86_64_32S y 0x0 # CHECK-NEXT: 0x23 R_X86_64_32S xx 0x0 @@ -79,17 +79,17 @@ # CHECKEXE-NEXT: Type: Executable # CHECKEXE-NEXT: Machine: EM_X86_64 # CHECKEXE-NEXT: Version: 1 -# CHECKEXE-NEXT: Entry: 0x11000 +# CHECKEXE-NEXT: Entry: 0x201000 # CHECKEXE-NEXT: ProgramHeaderOffset: 0x40 -# CHECKEXE-NEXT: SectionHeaderOffset: 0x11E8 +# CHECKEXE-NEXT: SectionHeaderOffset: 0x11F8 # CHECKEXE-NEXT: Flags [ # CHECKEXE-NEXT: ] # CHECKEXE-NEXT: HeaderSize: 64 # CHECKEXE-NEXT: ProgramHeaderEntrySize: 56 # CHECKEXE-NEXT: ProgramHeaderCount: 5 # CHECKEXE-NEXT: SectionHeaderEntrySize: 64 -# CHECKEXE-NEXT: SectionHeaderCount: 6 -# CHECKEXE-NEXT: StringTableSectionIndex: 4 +# CHECKEXE-NEXT: SectionHeaderCount: 7 +# CHECKEXE-NEXT: StringTableSectionIndex: 5 # CHECKEXE-NEXT: } .text diff --git a/test/ELF/relocation-common.s b/test/ELF/relocation-common.s index d5d379a355aac..28276bfe07507 100644 --- a/test/ELF/relocation-common.s +++ b/test/ELF/relocation-common.s @@ -10,5 +10,5 @@ _start: .global sym1 .comm sym1,4,4 -// CHECK: 11000: {{.*}} movl $1, 4086(%rip) -// CHECK: 0000000000012000 g .bss 00000004 sym1 +// CHECK: 201000: {{.*}} movl $1, 4086(%rip) +// CHECK: 0000000000202000 g .bss 00000004 sym1 diff --git a/test/ELF/relocation-copy-flags.s b/test/ELF/relocation-copy-flags.s index 50b4b15267e69..069866865c278 100644 --- a/test/ELF/relocation-copy-flags.s +++ b/test/ELF/relocation-copy-flags.s @@ -22,7 +22,7 @@ _start: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_EXECINSTR // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x11000 +// CHECK-NEXT: Address: 0x201000 // CHECK-NEXT: Offset: 0x1000 // CHECK-NEXT: Size: 8 // CHECK-NEXT: Link: 0 @@ -30,7 +30,7 @@ _start: // CHECK-NEXT: AddressAlignment: 4 // CHECK-NEXT: EntrySize: 0 // CHECK-NEXT: SectionData ( -// CHECK-NEXT: 0000: 10300100 +// CHECK-NEXT: 0000: 10302000 // CHECK-NEXT: ) // CHECK: Name: bar @@ -39,7 +39,7 @@ _start: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x13000 +// CHECK-NEXT: Address: 0x203000 // CHECK-NEXT: Offset: 0x3000 // CHECK-NEXT: Size: 8 // CHECK-NEXT: Link: 0 @@ -67,7 +67,7 @@ _start: // CHECK: Relocations [ // CHECK-NEXT: Section (4) .rela.dyn { -// CHECK-NEXT: 0x13010 R_X86_64_COPY x 0x0 -// CHECK-NEXT: 0x13000 R_X86_64_64 z 0x0 +// CHECK-NEXT: 0x203010 R_X86_64_COPY x 0x0 +// CHECK-NEXT: 0x203000 R_X86_64_64 z 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] diff --git a/test/ELF/relocation-copy.s b/test/ELF/relocation-copy.s index 9d13241f54963..9a3254fb25491 100644 --- a/test/ELF/relocation-copy.s +++ b/test/ELF/relocation-copy.s @@ -22,7 +22,7 @@ movl $z, %edx // CHECK-NEXT: SHF_ALLOC (0x2) // CHECK-NEXT: SHF_WRITE (0x1) // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x13000 +// CHECK-NEXT: Address: 0x203000 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 0 @@ -53,15 +53,15 @@ movl $z, %edx // CHECK-NEXT: } // CHECK-NEXT: ] -// 77824 = 0x13000 +// 2109440 = 0x203000 // 16 is alignment here -// 77840 = 0x13000 + 16 -// 77844 = 0x13000 + 16 + 4 +// 2109456 = 0x203000 + 16 +// 2109460 = 0x203000 + 16 + 4 // CODE: Disassembly of section .text: // CODE-NEXT: _start: -// CODE-NEXT: 11000: c7 04 25 00 30 01 00 05 00 00 00 movl $5, 77824 -// CODE-NEXT: 1100b: c7 04 25 10 30 01 00 07 00 00 00 movl $7, 77840 -// CODE-NEXT: 11016: c7 04 25 14 30 01 00 09 00 00 00 movl $9, 77844 -// CODE-NEXT: 11021: ba 00 30 01 00 movl $77824, %edx -// CODE-NEXT: 11026: ba 10 30 01 00 movl $77840, %edx -// CODE-NEXT: 1102b: ba 14 30 01 00 movl $77844, %edx +// CODE-NEXT: 201000: {{.*}} movl $5, 2109440 +// CODE-NEXT: 20100b: {{.*}} movl $7, 2109456 +// CODE-NEXT: 201016: {{.*}} movl $9, 2109460 +// CODE-NEXT: 201021: {{.*}} movl $2109440, %edx +// CODE-NEXT: 201026: {{.*}} movl $2109456, %edx +// CODE-NEXT: 20102b: {{.*}} movl $2109460, %edx diff --git a/test/ELF/relocation-dtrace.test b/test/ELF/relocation-dtrace.test new file mode 100644 index 0000000000000..ef2cc4956ca65 --- /dev/null +++ b/test/ELF/relocation-dtrace.test @@ -0,0 +1,24 @@ +# RUN: yaml2obj %s -o %t.o +# RUN: ld.lld -shared %t.o -o %t.so + +# Test that we can handle R_X86_64_NONE as produced by dtrace. + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_FREEBSD + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + Info: .text + Relocations: + - Offset: 0x0000000000000000 + Symbol: '' + Type: R_X86_64_NONE diff --git a/test/ELF/relocation-i686.s b/test/ELF/relocation-i686.s index 96d7606011270..262f697184bbb 100644 --- a/test/ELF/relocation-i686.s +++ b/test/ELF/relocation-i686.s @@ -56,16 +56,18 @@ movl bar@GOT, %eax // ADDR-NEXT: SHF_WRITE // ADDR-NEXT: ] // ADDR-NEXT: Address: 0x12078 +// ADDR-NEXT: Offset: +// ADDR-NEXT: Size: 8 .section .R_386_GOTPC,"ax",@progbits R_386_GOTPC: movl $_GLOBAL_OFFSET_TABLE_, %eax -// 0x12050 - 0x11014 = 4156 +// 0x12078 + 8 - 0x11014 = 4204 // CHECK: Disassembly of section .R_386_GOTPC: // CHECK-NEXT: R_386_GOTPC: -// CHECK-NEXT: 11014: {{.*}} movl $4196, %eax +// CHECK-NEXT: 11014: {{.*}} movl $4204, %eax .section .dynamic_reloc, "ax",@progbits call bar diff --git a/test/ELF/relocation-local.s b/test/ELF/relocation-local.s index 26e89fc12f8da..8173dac0522fd 100644 --- a/test/ELF/relocation-local.s +++ b/test/ELF/relocation-local.s @@ -20,7 +20,7 @@ R_X86_64_32: // constants in hex. // CHECK: Disassembly of section .text2: // CHECK-NEXT: R_X86_64_32: -// CHECK-NEXT: 11009: {{.*}} movl $69641, %edx +// CHECK-NEXT: 201009: {{.*}} movl $2101257, %edx .section .R_X86_64_32S,"ax",@progbits R_X86_64_32S: @@ -28,11 +28,11 @@ R_X86_64_32S: // CHECK: Disassembly of section .R_X86_64_32S: // CHECK-NEXT: R_X86_64_32S: -// CHECK-NEXT: {{.*}}: {{.*}} movq -978935, %rdx +// CHECK-NEXT: {{.*}}: {{.*}} movq 1052681, %rdx .section .R_X86_64_64,"a",@progbits R_X86_64_64: .quad R_X86_64_64 // CHECK: Contents of section .R_X86_64_64: -// CHECK-NEXT: 10120 20010100 00000000 +// CHECK-NEXT: 200120 20012000 00000000 diff --git a/test/ELF/relocation-past-merge-end.s b/test/ELF/relocation-past-merge-end.s index 993b071f62d27..d08bde7b9f6c4 100644 --- a/test/ELF/relocation-past-merge-end.s +++ b/test/ELF/relocation-past-merge-end.s @@ -1,8 +1,9 @@ // 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 -// CHECK: entry is past the end of the section +// CHECK: relocation-past-merge-end.s.tmp.o:(.foo): entry is past the end of the section - .data - .long .foo + 1 - .section .foo,"aM",@progbits,4 +.data +.long .foo + 10 +.section .foo,"aM",@progbits,4 +.quad 0 diff --git a/test/ELF/relocation-relative-absolute.s b/test/ELF/relocation-relative-absolute.s index 5253191331cc1..e1636c734a881 100644 --- a/test/ELF/relocation-relative-absolute.s +++ b/test/ELF/relocation-relative-absolute.s @@ -1,12 +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 %t -pie 2>&1 | FileCheck %s +# 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 .globl _start _start: -# CHECK: relocation R_X86_64_PLT32 cannot refer to absolute symbol answer -call answer@PLT +# CHECK: {{.*}}input1.o:(.text+0x1): relocation R_X86_64_PLT32 cannot refer to absolute symbol 'answer' defined in {{.*}}input2.o -.globl answer -answer = 42 +call answer@PLT diff --git a/test/ELF/relocation-size-shared.s b/test/ELF/relocation-size-shared.s index d6274e9ae12eb..7b700ad74401f 100644 --- a/test/ELF/relocation-size-shared.s +++ b/test/ELF/relocation-size-shared.s @@ -7,48 +7,48 @@ // RELOCSHARED: Relocations [ // RELOCSHARED-NEXT: Section ({{.*}}) .rela.dyn { -// RELOCSHARED-NEXT: 0x13018 R_X86_64_SIZE64 fooshared 0xFFFFFFFFFFFFFFFF -// RELOCSHARED-NEXT: 0x13020 R_X86_64_SIZE64 fooshared 0x0 -// RELOCSHARED-NEXT: 0x13028 R_X86_64_SIZE64 fooshared 0x1 -// RELOCSHARED-NEXT: 0x13048 R_X86_64_SIZE32 fooshared 0xFFFFFFFFFFFFFFFF -// RELOCSHARED-NEXT: 0x1304F R_X86_64_SIZE32 fooshared 0x0 -// RELOCSHARED-NEXT: 0x13056 R_X86_64_SIZE32 fooshared 0x1 +// RELOCSHARED-NEXT: 0x203018 R_X86_64_SIZE64 fooshared 0xFFFFFFFFFFFFFFFF +// RELOCSHARED-NEXT: 0x203020 R_X86_64_SIZE64 fooshared 0x0 +// RELOCSHARED-NEXT: 0x203028 R_X86_64_SIZE64 fooshared 0x1 +// RELOCSHARED-NEXT: 0x203048 R_X86_64_SIZE32 fooshared 0xFFFFFFFFFFFFFFFF +// RELOCSHARED-NEXT: 0x20304F R_X86_64_SIZE32 fooshared 0x0 +// RELOCSHARED-NEXT: 0x203056 R_X86_64_SIZE32 fooshared 0x1 // RELOCSHARED-NEXT: } // RELOCSHARED-NEXT:] // DISASM: Disassembly of section test // DISASM: _data: -// DISASM-NEXT: 13000: 19 00 -// DISASM-NEXT: 13002: 00 00 -// DISASM-NEXT: 13004: 00 00 -// DISASM-NEXT: 13006: 00 00 -// DISASM-NEXT: 13008: 1a 00 -// DISASM-NEXT: 1300a: 00 00 -// DISASM-NEXT: 1300c: 00 00 -// DISASM-NEXT: 1300e: 00 00 -// DISASM-NEXT: 13010: 1b 00 -// DISASM-NEXT: 13012: 00 00 -// DISASM-NEXT: 13014: 00 00 -// DISASM-NEXT: 13016: 00 00 -// DISASM-NEXT: 13018: 00 00 -// DISASM-NEXT: 1301a: 00 00 -// DISASM-NEXT: 1301c: 00 00 -// DISASM-NEXT: 1301e: 00 00 -// DISASM-NEXT: 13020: 00 00 -// DISASM-NEXT: 13022: 00 00 -// DISASM-NEXT: 13024: 00 00 -// DISASM-NEXT: 13026: 00 00 -// DISASM-NEXT: 13028: 00 00 -// DISASM-NEXT: 1302a: 00 00 -// DISASM-NEXT: 1302c: 00 00 -// DISASM-NEXT: 1302e: 00 00 +// DISASM-NEXT: 203000: 19 00 +// DISASM-NEXT: 203002: 00 00 +// DISASM-NEXT: 203004: 00 00 +// DISASM-NEXT: 203006: 00 00 +// DISASM-NEXT: 203008: 1a 00 +// DISASM-NEXT: 20300a: 00 00 +// DISASM-NEXT: 20300c: 00 00 +// DISASM-NEXT: 20300e: 00 00 +// DISASM-NEXT: 203010: 1b 00 +// DISASM-NEXT: 203012: 00 00 +// DISASM-NEXT: 203014: 00 00 +// DISASM-NEXT: 203016: 00 00 +// DISASM-NEXT: 203018: 00 00 +// DISASM-NEXT: 20301a: 00 00 +// DISASM-NEXT: 20301c: 00 00 +// DISASM-NEXT: 20301e: 00 00 +// DISASM-NEXT: 203020: 00 00 +// DISASM-NEXT: 203022: 00 00 +// DISASM-NEXT: 203024: 00 00 +// DISASM-NEXT: 203026: 00 00 +// DISASM-NEXT: 203028: 00 00 +// DISASM-NEXT: 20302a: 00 00 +// DISASM-NEXT: 20302c: 00 00 +// DISASM-NEXT: 20302e: 00 00 // DISASM: _start: -// DISASM-NEXT: 13030: 8b 04 25 19 00 00 00 movl 25, %eax -// DISASM-NEXT: 13037: 8b 04 25 1a 00 00 00 movl 26, %eax -// DISASM-NEXT: 1303e: 8b 04 25 1b 00 00 00 movl 27, %eax -// DISASM-NEXT: 13045: 8b 04 25 00 00 00 00 movl 0, %eax -// DISASM-NEXT: 1304c: 8b 04 25 00 00 00 00 movl 0, %eax -// DISASM-NEXT: 13053: 8b 04 25 00 00 00 00 movl 0, %eax +// DISASM-NEXT: 203030: 8b 04 25 19 00 00 00 movl 25, %eax +// DISASM-NEXT: 203037: 8b 04 25 1a 00 00 00 movl 26, %eax +// DISASM-NEXT: 20303e: 8b 04 25 1b 00 00 00 movl 27, %eax +// DISASM-NEXT: 203045: 8b 04 25 00 00 00 00 movl 0, %eax +// DISASM-NEXT: 20304c: 8b 04 25 00 00 00 00 movl 0, %eax +// DISASM-NEXT: 203053: 8b 04 25 00 00 00 00 movl 0, %eax .data .global foo diff --git a/test/ELF/relocation-size.s b/test/ELF/relocation-size.s index 58604dbcb4e43..2256be67df060 100644 --- a/test/ELF/relocation-size.s +++ b/test/ELF/relocation-size.s @@ -11,37 +11,37 @@ // DISASM: Disassembly of section test: // DISASM-NEXT: _data: -// DISASM-NEXT: 12000: 19 00 -// DISASM-NEXT: 12002: 00 00 -// DISASM-NEXT: 12004: 00 00 -// DISASM-NEXT: 12006: 00 00 -// DISASM-NEXT: 12008: 1a 00 -// DISASM-NEXT: 1200a: 00 00 -// DISASM-NEXT: 1200c: 00 00 -// DISASM-NEXT: 1200e: 00 00 -// DISASM-NEXT: 12010: 1b 00 -// DISASM-NEXT: 12012: 00 00 -// DISASM-NEXT: 12014: 00 00 -// DISASM-NEXT: 12016: 00 00 -// DISASM-NEXT: 12018: 19 00 -// DISASM-NEXT: 1201a: 00 00 -// DISASM-NEXT: 1201c: 00 00 -// DISASM-NEXT: 1201e: 00 00 -// DISASM-NEXT: 12020: 1a 00 -// DISASM-NEXT: 12022: 00 00 -// DISASM-NEXT: 12024: 00 00 -// DISASM-NEXT: 12026: 00 00 -// DISASM-NEXT: 12028: 1b 00 -// DISASM-NEXT: 1202a: 00 00 -// DISASM-NEXT: 1202c: 00 00 -// DISASM-NEXT: 1202e: 00 00 +// DISASM-NEXT: 202000: 19 00 +// DISASM-NEXT: 202002: 00 00 +// DISASM-NEXT: 202004: 00 00 +// DISASM-NEXT: 202006: 00 00 +// DISASM-NEXT: 202008: 1a 00 +// DISASM-NEXT: 20200a: 00 00 +// DISASM-NEXT: 20200c: 00 00 +// DISASM-NEXT: 20200e: 00 00 +// DISASM-NEXT: 202010: 1b 00 +// DISASM-NEXT: 202012: 00 00 +// DISASM-NEXT: 202014: 00 00 +// DISASM-NEXT: 202016: 00 00 +// DISASM-NEXT: 202018: 19 00 +// DISASM-NEXT: 20201a: 00 00 +// DISASM-NEXT: 20201c: 00 00 +// DISASM-NEXT: 20201e: 00 00 +// DISASM-NEXT: 202020: 1a 00 +// DISASM-NEXT: 202022: 00 00 +// DISASM-NEXT: 202024: 00 00 +// DISASM-NEXT: 202026: 00 00 +// DISASM-NEXT: 202028: 1b 00 +// DISASM-NEXT: 20202a: 00 00 +// DISASM-NEXT: 20202c: 00 00 +// DISASM-NEXT: 20202e: 00 00 // DISASM: _start: -// DISASM-NEXT: 12030: 8b 04 25 19 00 00 00 movl 25, %eax -// DISASM-NEXT: 12037: 8b 04 25 1a 00 00 00 movl 26, %eax -// DISASM-NEXT: 1203e: 8b 04 25 1b 00 00 00 movl 27, %eax -// DISASM-NEXT: 12045: 8b 04 25 19 00 00 00 movl 25, %eax -// DISASM-NEXT: 1204c: 8b 04 25 1a 00 00 00 movl 26, %eax -// DISASM-NEXT: 12053: 8b 04 25 1b 00 00 00 movl 27, %eax +// DISASM-NEXT: 202030: 8b 04 25 19 00 00 00 movl 25, %eax +// DISASM-NEXT: 202037: 8b 04 25 1a 00 00 00 movl 26, %eax +// DISASM-NEXT: 20203e: 8b 04 25 1b 00 00 00 movl 27, %eax +// DISASM-NEXT: 202045: 8b 04 25 19 00 00 00 movl 25, %eax +// DISASM-NEXT: 20204c: 8b 04 25 1a 00 00 00 movl 26, %eax +// DISASM-NEXT: 202053: 8b 04 25 1b 00 00 00 movl 27, %eax // RELOCSHARED: Relocations [ // RELOCSHARED-NEXT: Section ({{.*}}) .rela.dyn { diff --git a/test/ELF/relocation-undefined-weak.s b/test/ELF/relocation-undefined-weak.s index f1cb706329a47..6aa84ec483f41 100644 --- a/test/ELF/relocation-undefined-weak.s +++ b/test/ELF/relocation-undefined-weak.s @@ -18,10 +18,10 @@ _start: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_EXECINSTR // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x11000 +// CHECK-NEXT: Address: 0x201000 // Unfortunately FileCheck can't do math, so we have to check for explicit // values: -// R_86_64_PC32 = 0 + (-8 - (0x11000 + 2)) = -69642 +// R_86_64_PC32 = 0 + (-8 - (0x201000 + 2)) = -2101258 -// DISASM: movl $1, -69642(%rip) +// DISASM: movl $1, -2101258(%rip) diff --git a/test/ELF/relocation.s b/test/ELF/relocation.s index 11832683d9bed..452d1bedba5a7 100644 --- a/test/ELF/relocation.s +++ b/test/ELF/relocation.s @@ -12,7 +12,7 @@ // SEC-NEXT: SHF_ALLOC // SEC-NEXT: SHF_EXECINSTR // SEC-NEXT: ] -// SEC-NEXT: Address: 0x11030 +// SEC-NEXT: Address: 0x201030 // SEC-NEXT: Offset: 0x1030 // SEC-NEXT: Size: 48 @@ -22,7 +22,7 @@ // SEC-NEXT: SHF_ALLOC // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x120F0 +// SEC-NEXT: Address: 0x2020F0 // SEC-NEXT: Offset: // SEC-NEXT: Size: 8 // SEC-NEXT: Link: 0 @@ -37,7 +37,7 @@ // SEC-NEXT: SHF_ALLOC // SEC-NEXT: SHF_WRITE // SEC-NEXT: ] -// SEC-NEXT: Address: 0x13000 +// SEC-NEXT: Address: 0x203000 // SEC-NEXT: Offset: 0x3000 // SEC-NEXT: Size: 40 // SEC-NEXT: Link: 0 @@ -59,11 +59,11 @@ lulz: // CHECK: Disassembly of section .text: // CHECK-NEXT: _start: -// CHECK-NEXT: 11000: e8 04 00 00 00 callq 4 -// CHECK-NEXT: 11005: +// CHECK-NEXT: 201000: e8 04 00 00 00 callq 4 +// CHECK-NEXT: 201005: // CHECK: lulz: -// CHECK-NEXT: 11009: 90 nop +// CHECK-NEXT: 201009: 90 nop .section .text2,"ax",@progbits @@ -75,7 +75,7 @@ R_X86_64_32: // constants in hex. // CHECK: Disassembly of section .text2: // CHECK-NEXT: R_X86_64_32: -// CHECK-NEXT: 1100a: {{.*}} movl $69642, %edx +// CHECK-NEXT: 20100a: {{.*}} movl $2101258, %edx .section .R_X86_64_32S,"ax",@progbits .global R_X86_64_32S @@ -84,7 +84,7 @@ R_X86_64_32S: // CHECK: Disassembly of section .R_X86_64_32S: // CHECK-NEXT: R_X86_64_32S: -// CHECK-NEXT: {{.*}}: {{.*}} movq -978935, %rdx +// CHECK-NEXT: {{.*}}: {{.*}} movq 1052681, %rdx .section .R_X86_64_PC32,"ax",@progbits .global R_X86_64_PC32 @@ -92,20 +92,20 @@ R_X86_64_PC32: call bar movl $bar, %eax //16 is a size of PLT[0] -// 0x11030 + 16 - (0x11017 + 5) = 20 +// 0x201030 + 16 - (0x201017 + 5) = 20 // CHECK: Disassembly of section .R_X86_64_PC32: // CHECK-NEXT: R_X86_64_PC32: -// CHECK-NEXT: 11017: {{.*}} callq 36 -// CHECK-NEXT: 1101c: {{.*}} movl $69696, %eax +// CHECK-NEXT: 201017: {{.*}} callq 36 +// CHECK-NEXT: 20101c: {{.*}} movl $2101312, %eax .section .R_X86_64_32S_2,"ax",@progbits .global R_X86_64_32S_2 R_X86_64_32S_2: mov bar2, %eax -// plt is at 0x11030. The second plt entry is at 0x11050 == 69712 +// plt is at 0x201030. The second plt entry is at 0x201050 == 69712 // CHECK: Disassembly of section .R_X86_64_32S_2: // CHECK-NEXT: R_X86_64_32S_2: -// CHECK-NEXT: 11021: {{.*}} movl 69712, %eax +// CHECK-NEXT: 201021: {{.*}} movl 2101328, %eax .section .R_X86_64_64,"a",@progbits .global R_X86_64_64 @@ -113,17 +113,17 @@ R_X86_64_64: .quad R_X86_64_64 // CHECK: Contents of section .R_X86_64_64: -// CHECK-NEXT: 101c8 c8010100 00000000 +// CHECK-NEXT: 2001c8 c8012000 00000000 .section .R_X86_64_GOTPCREL,"a",@progbits .global R_X86_64_GOTPCREL R_X86_64_GOTPCREL: .long zed@gotpcrel -// 0x120F8 - 0x101D8 = 7952 +// 0x2020F8 - 0x2001D8 = 7952 // 7952 = 0x101f0000 in little endian // CHECK: Contents of section .R_X86_64_GOTPCREL -// CHECK-NEXT: 101d0 201f0000 +// CHECK-NEXT: 2001d0 201f0000 .section .R_X86_64_GOT32,"a",@progbits .global R_X86_64_GOT32 @@ -132,3 +132,11 @@ R_X86_64_GOT32: // CHECK: Contents of section .R_X86_64_GOT32: // CHECK-NEXT: f8ffffff + + +// CHECK: Contents of section .R_X86_64_GOT64: +// CHECK-NEXT: f8ffffff ffffffff +.section .R_X86_64_GOT64,"a",@progbits +.global R_X86_64_GOT64 +R_X86_64_GOT64: + .quad zed@got diff --git a/test/ELF/relro-omagic.s b/test/ELF/relro-omagic.s new file mode 100644 index 0000000000000..35a92db2f07a7 --- /dev/null +++ b/test/ELF/relro-omagic.s @@ -0,0 +1,34 @@ +# 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 -N %t.o %t2.so -o %t +# RUN: llvm-objdump -section-headers %t | FileCheck --check-prefix=NORELRO %s +# RUN: llvm-readobj --program-headers %t | FileCheck --check-prefix=NOPHDRS %s + +# NORELRO: Sections: +# NORELRO-NEXT: Idx Name Size Address Type +# NORELRO-NEXT: 0 00000000 0000000000000000 +# NORELRO-NEXT: 1 .dynsym 00000048 0000000000200120 +# NORELRO-NEXT: 2 .hash 00000020 0000000000200168 +# 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: 8 .data 00000008 0000000000200210 DATA +# NORELRO-NEXT: 9 .foo 00000004 0000000000200218 DATA +# NORELRO-NEXT: 10 .dynamic 000000f0 0000000000200220 +# NORELRO-NEXT: 11 .got 00000008 0000000000200310 DATA +# NORELRO-NEXT: 12 .got.plt 00000020 0000000000200318 DATA + +# NOPHDRS: ProgramHeaders [ +# NOPHDRS-NOT: PT_GNU_RELRO + +.long bar +jmp *bar2@GOTPCREL(%rip) + +.section .data,"aw" +.quad 0 + +.section .foo,"aw" +.zero 4 diff --git a/test/ELF/relro.s b/test/ELF/relro.s index d355487400019..b21e514303ab8 100644 --- a/test/ELF/relro.s +++ b/test/ELF/relro.s @@ -2,232 +2,28 @@ // 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: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data %t | FileCheck --check-prefix=FULLRELRO %s +// 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: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data %t | FileCheck --check-prefix=PARTRELRO %s +// 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 --program-headers --dynamic-table -t -s -dyn-symbols -section-data %t | FileCheck --check-prefix=NORELRO %s +// RUN: llvm-readobj -l --elf-output-style=GNU %t | FileCheck --check-prefix=NORELRO %s // REQUIRES: x86 -// FULLRELRO: Section { -// FULLRELRO: Index: 9 -// FULLRELRO-NEXT: Name: .got -// FULLRELRO-NEXT: Type: SHT_PROGBITS -// FULLRELRO-NEXT: Flags [ -// FULLRELRO-NEXT: SHF_ALLOC -// FULLRELRO-NEXT: SHF_WRITE -// FULLRELRO-NEXT: ] -// FULLRELRO-NEXT: Address: 0x12110 -// FULLRELRO-NEXT: Offset: 0x2110 -// FULLRELRO-NEXT: Size: 8 -// FULLRELRO-NEXT: Link: 0 -// FULLRELRO-NEXT: Info: 0 -// FULLRELRO-NEXT: AddressAlignment: 8 -// FULLRELRO-NEXT: EntrySize: 0 -// FULLRELRO-NEXT: SectionData ( -// FULLRELRO-NEXT: 0000: 00000000 00000000 -// FULLRELRO-NEXT: ) -// FULLRELRO-NEXT: } -// FULLRELRO-NEXT: Section { -// FULLRELRO-NEXT: Index: 10 -// FULLRELRO-NEXT: Name: .got.plt -// FULLRELRO-NEXT: Type: SHT_PROGBITS -// FULLRELRO-NEXT: Flags [ -// FULLRELRO-NEXT: SHF_ALLOC -// FULLRELRO-NEXT: SHF_WRITE -// FULLRELRO-NEXT: ] -// FULLRELRO-NEXT: Address: 0x12118 -// FULLRELRO-NEXT: Offset: 0x2118 -// FULLRELRO-NEXT: Size: 32 -// FULLRELRO-NEXT: Link: 0 -// FULLRELRO-NEXT: Info: 0 -// FULLRELRO-NEXT: AddressAlignment: 8 -// FULLRELRO-NEXT: EntrySize: 0 -// FULLRELRO-NEXT: SectionData ( -// FULLRELRO-NEXT: 0000: -// FULLRELRO-NEXT: 0010: -// FULLRELRO-NEXT: ) -// FULLRELRO-NEXT: } -// FULLRELRO-NEXT: Section { -// FULLRELRO-NEXT: Index: 11 -// FULLRELRO-NEXT: Name: .data -// FULLRELRO-NEXT: Type: SHT_PROGBITS -// FULLRELRO-NEXT: Flags [ -// FULLRELRO-NEXT: SHF_ALLOC -// FULLRELRO-NEXT: SHF_WRITE -// FULLRELRO-NEXT: ] -// FULLRELRO-NEXT: Address: 0x13000 -// FULLRELRO-NEXT: Offset: 0x3000 -// FULLRELRO-NEXT: Size: 12 -// FULLRELRO-NEXT: Link: 0 -// FULLRELRO-NEXT: Info: 0 -// FULLRELRO-NEXT: AddressAlignment: -// FULLRELRO-NEXT: EntrySize: 0 -// FULLRELRO-NEXT: SectionData ( -// FULLRELRO-NEXT: 0000: -// FULLRELRO-NEXT: ) -// FULLRELRO-NEXT: } -// FULLRELRO-NEXT: Section { -// FULLRELRO-NEXT: Index: 12 -// FULLRELRO-NEXT: Name: .foo -// FULLRELRO-NEXT: Type: SHT_PROGBITS -// FULLRELRO-NEXT: Flags [ -// FULLRELRO-NEXT: SHF_ALLOC -// FULLRELRO-NEXT: SHF_WRITE -// FULLRELRO-NEXT: ] -// FULLRELRO-NEXT: Address: 0x1300C -// FULLRELRO-NEXT: Offset: 0x300C -// FULLRELRO-NEXT: Size: 0 -// FULLRELRO-NEXT: Link: 0 -// FULLRELRO-NEXT: Info: 0 -// FULLRELRO-NEXT: AddressAlignment: -// FULLRELRO-NEXT: EntrySize: 0 -// FULLRELRO-NEXT: SectionData ( -// FULLRELRO-NEXT: ) -// FULLRELRO-NEXT: } -// 308 - sizeof(.data)(12) = 296 -// FULLRELRO: ProgramHeaders [ -// FULLRELRO: Type: PT_LOAD -// FULLRELRO: Offset: 0x2000 -// FULLRELRO-NEXT: VirtualAddress: [[RWADDR:.*]] -// FULLRELRO-NEXT: PhysicalAddress: -// FULLRELRO-NEXT: FileSize: 4108 -// FULLRELRO-NEXT: MemSize: 4108 -// FULLRELRO-NEXT: Flags [ -// FULLRELRO-NEXT: PF_R -// FULLRELRO-NEXT: PF_W -// FULLRELRO-NEXT: ] -// FULLRELRO-NEXT: Alignment: 4096 -// FULLRELRO-NEXT:} -// FULLRELRO: Type: PT_GNU_RELRO -// FULLRELRO-NEXT: Offset: 0x -// FULLRELRO-NEXT: VirtualAddress: [[RWADDR]] -// FULLRELRO-NEXT: PhysicalAddress: -// FULLRELRO-NEXT: FileSize: 312 -// FULLRELRO-NEXT: MemSize: 312 -// FULLRELRO-NEXT: Flags [ -// FULLRELRO-NEXT: PF_R -// FULLRELRO-NEXT: ] -// FULLRELRO-NEXT: Alignment: 1 -// FULLRELRO-NEXT:} +// CHECK: Program Headers: +// CHECK-NEXT: Type +// CHECK-NEXT: PHDR +// CHECK-NEXT: LOAD +// CHECK-NEXT: LOAD +// CHECK-NEXT: LOAD +// CHECK-NEXT: DYNAMIC +// CHECK-NEXT: GNU_RELRO +// CHECK: Section to Segment mapping: -// PARTRELRO: Section { -// PARTRELRO: Index: 9 -// PARTRELRO-NEXT: Name: .got -// PARTRELRO-NEXT: Type: SHT_PROGBITS -// PARTRELRO-NEXT: Flags [ -// PARTRELRO-NEXT: SHF_ALLOC -// PARTRELRO-NEXT: SHF_WRITE -// PARTRELRO-NEXT: ] -// PARTRELRO-NEXT: Address: 0x120F0 -// PARTRELRO-NEXT: Offset: 0x20F0 -// PARTRELRO-NEXT: Size: 8 -// PARTRELRO-NEXT: Link: 0 -// PARTRELRO-NEXT: Info: 0 -// PARTRELRO-NEXT: AddressAlignment: 8 -// PARTRELRO-NEXT: EntrySize: 0 -// PARTRELRO-NEXT: SectionData ( -// PARTRELRO-NEXT: 0000: -// PARTRELRO-NEXT: ) -// PARTRELRO-NEXT: } -// PARTRELRO-NEXT: Section { -// PARTRELRO-NEXT: Index: 10 -// PARTRELRO-NEXT: Name: .data -// PARTRELRO-NEXT: Type: SHT_PROGBITS -// PARTRELRO-NEXT: Flags [ -// PARTRELRO-NEXT: SHF_ALLOC -// PARTRELRO-NEXT: SHF_WRITE -// PARTRELRO-NEXT: ] -// PARTRELRO-NEXT: Address: 0x13000 -// PARTRELRO-NEXT: Offset: 0x3000 -// PARTRELRO-NEXT: Size: 12 -// PARTRELRO-NEXT: Link: 0 -// PARTRELRO-NEXT: Info: 0 -// PARTRELRO-NEXT: AddressAlignment: 1 -// PARTRELRO-NEXT: EntrySize: 0 -// PARTRELRO-NEXT: SectionData ( -// PARTRELRO-NEXT: 0000: -// PARTRELRO-NEXT: ) -// PARTRELRO-NEXT: } -// PARTRELRO-NEXT: Section { -// PARTRELRO-NEXT: Index: 11 -// PARTRELRO-NEXT: Name: .foo -// PARTRELRO-NEXT: Type: SHT_PROGBITS -// PARTRELRO-NEXT: Flags [ -// PARTRELRO-NEXT: SHF_ALLOC -// PARTRELRO-NEXT: SHF_WRITE -// PARTRELRO-NEXT: ] -// PARTRELRO-NEXT: Address: 0x1300C -// PARTRELRO-NEXT: Offset: 0x300C -// PARTRELRO-NEXT: Size: 0 -// PARTRELRO-NEXT: Link: 0 -// PARTRELRO-NEXT: Info: 0 -// PARTRELRO-NEXT: AddressAlignment: 1 -// PARTRELRO-NEXT: EntrySize: 0 -// PARTRELRO-NEXT: SectionData ( -// PARTRELRO-NEXT: ) -// PARTRELRO-NEXT: } -// PARTRELRO-NEXT: Section { -// PARTRELRO-NEXT: Index: 12 -// PARTRELRO-NEXT: Name: .got.plt -// PARTRELRO-NEXT: Type: SHT_PROGBITS -// PARTRELRO-NEXT: Flags [ -// PARTRELRO-NEXT: SHF_ALLOC -// PARTRELRO-NEXT: SHF_WRITE -// PARTRELRO-NEXT: ] -// PARTRELRO-NEXT: Address: 0x13010 -// PARTRELRO-NEXT: Offset: 0x3010 -// PARTRELRO-NEXT: Size: 32 -// PARTRELRO-NEXT: Link: 0 -// PARTRELRO-NEXT: Info: 0 -// PARTRELRO-NEXT: AddressAlignment: 8 -// PARTRELRO-NEXT: EntrySize: 0 -// PARTRELRO-NEXT: SectionData ( -// PARTRELRO-NEXT: 0000: -// PARTRELRO-NEXT: 0010: -// PARTRELRO-NEXT: ) -// PARTRELRO-NEXT: } -// PARTRELRO-NEXT: Section { -// PARTRELRO-NEXT: Index: 13 -// PARTRELRO-NEXT: Name: .bss -// PARTRELRO-NEXT: Type: SHT_NOBITS -// PARTRELRO-NEXT: Flags [ -// PARTRELRO-NEXT: SHF_ALLOC -// PARTRELRO-NEXT: SHF_WRITE -// PARTRELRO-NEXT: ] -// PARTRELRO-NEXT: Address: 0x13030 -// PARTRELRO-NEXT: Offset: 0x3030 -// PARTRELRO-NEXT: Size: 0 -// PARTRELRO-NEXT: Link: 0 -// PARTRELRO-NEXT: Info: 0 -// PARTRELRO-NEXT: AddressAlignment: 1 -// PARTRELRO-NEXT: EntrySize: 0 -// PARTRELRO-NEXT: } -// PARTRELRO: ProgramHeader { -// PARTRELRO: Type: PT_LOAD -// PARTRELRO: Offset: 0x2000 -// PARTRELRO-NEXT: VirtualAddress: [[RWADDR:.*]] -// PARTRELRO-NEXT: PhysicalAddress: -// PARTRELRO-NEXT: FileSize: 4144 -// PARTRELRO-NEXT: MemSize: 4144 -// PARTRELRO-NEXT: Flags [ -// PARTRELRO-NEXT: PF_R (0x4) -// PARTRELRO-NEXT: PF_W (0x2) -// PARTRELRO-NEXT: ] -// PARTRELRO-NEXT: Alignment: 4096 -// PARTRELRO: Type: PT_GNU_RELRO -// PARTRELRO-NEXT: Offset: 0x2000 -// PARTRELRO-NEXT: VirtualAddress: [[RWADDR]] -// PARTRELRO-NEXT: PhysicalAddress: -// PARTRELRO-NEXT: FileSize: 248 -// PARTRELRO-NEXT: MemSize: 248 -// PARTRELRO-NEXT: Flags [ -// PARTRELRO-NEXT: PF_R -// PARTRELRO-NEXT: ] -// PARTRELRO-NEXT: Alignment: 1 +// FULLRELRO: 05 .openbsd.randomdata .dynamic .got .got.plt {{$}} +// PARTRELRO: 05 .openbsd.randomdata .dynamic .got {{$}} -// NORELRO: ProgramHeaders [ -// NORELRO-NOT: PT_GNU_RELRO + +// NORELRO-NOT: GNU_RELRO .global _start _start: @@ -240,3 +36,6 @@ _start: .zero 4 .section .foo,"aw" .section .bss,"",@nobits + +.section .openbsd.randomdata, "aw" +.quad 0 diff --git a/test/ELF/reproduce-backslash.s b/test/ELF/reproduce-backslash.s new file mode 100644 index 0000000000000..849c8f8fb3ddb --- /dev/null +++ b/test/ELF/reproduce-backslash.s @@ -0,0 +1,9 @@ +# REQUIRES: x86, cpio, shell + +# 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 +# RUN: cpio -it < repro.cpio | FileCheck %s + +# CHECK: repro/{{.*}}/foo\.o diff --git a/test/ELF/reproduce-windows.s b/test/ELF/reproduce-windows.s index 464b27098694c..4825a8a95e786 100644 --- a/test/ELF/reproduce-windows.s +++ b/test/ELF/reproduce-windows.s @@ -1,12 +1,12 @@ -# REQUIRES: x86 +# REQUIRES: x86, cpio # Test that a repro archive always uses / instead of \. # RUN: rm -rf %t.dir # RUN: mkdir -p %t.dir/build # RUN: llvm-mc %s -o %t.dir/build/foo.o -filetype=obj -triple=x86_64-pc-linux # RUN: cd %t.dir -# RUN: not ld.lld build/foo.o --reproduce repro -# RUN: cpio -t < repro.cpio | FileCheck %s +# RUN: ld.lld build/foo.o --reproduce repro +# RUN: cpio -it < repro.cpio | FileCheck %s # CHECK: repro/response.txt # CHECK: repro/{{.*}}/build/foo.o diff --git a/test/ELF/reproduce-windows2.s b/test/ELF/reproduce-windows2.s new file mode 100644 index 0000000000000..d428288a36404 --- /dev/null +++ b/test/ELF/reproduce-windows2.s @@ -0,0 +1,11 @@ +# REQUIRES: system-windows, x86, cpio + +# Test that a response.txt file always uses / instead of \. +# RUN: rm -rf %t.dir +# RUN: mkdir -p %t.dir/build +# RUN: llvm-mc %s -o %t.dir/build/foo.o -filetype=obj -triple=x86_64-pc-linux +# RUN: cd %t.dir +# RUN: ld.lld build/foo.o --reproduce repro +# RUN: echo "*response.txt" > list.txt +# RUN: cpio -i --to-stdout --pattern-file=list.txt < repro.cpio | FileCheck %s +# CHECK: {{.*}}/build/foo.o diff --git a/test/ELF/reproduce.s b/test/ELF/reproduce.s index 9d256c12d827a..471a0f82da443 100644 --- a/test/ELF/reproduce.s +++ b/test/ELF/reproduce.s @@ -1,4 +1,4 @@ -# REQUIRES: x86 +# REQUIRES: x86, cpio # Extracting the cpio archive can get over the path limit on windows. # REQUIRES: shell @@ -30,12 +30,12 @@ # RUN: diff %t.dir/build2/foo.o repro/%:t.dir/build2/foo.o # RUN: echo "{ local: *; };" > ver -# RUN: echo > dyn +# RUN: echo "{};" > dyn # RUN: echo > file # RUN: echo > file2 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o 'foo bar' # RUN: ld.lld --reproduce repro2 'foo bar' -L"foo bar" -Lfile -Tfile2 \ -# RUN: --dynamic-list dyn -rpath file --script file --version-script ver \ +# RUN: --dynamic-list dyn -rpath file --script=file --version-script ver \ # RUN: --dynamic-linker "some unusual/path" -soname 'foo bar' -soname='foo bar' # RUN: cpio -id < repro2.cpio # RUN: FileCheck %s --check-prefix=RSP2 < repro2/response.txt @@ -51,7 +51,7 @@ # RSP2-NEXT: -soname="foo bar" # RSP2-NEXT: -soname="foo bar" -# RUN: cpio -t < repro2.cpio | FileCheck %s +# RUN: cpio -it < repro2.cpio | FileCheck %s # CHECK: repro2/response.txt # CHECK-NEXT: repro2/version.txt # CHECK-NEXT: repro2/{{.*}}/dyn diff --git a/test/ELF/resolution.s b/test/ELF/resolution.s index 5596212b3bace..4a42d941eab6c 100644 --- a/test/ELF/resolution.s +++ b/test/ELF/resolution.s @@ -19,15 +19,6 @@ // CHECK-NEXT: Section: Undefined (0x0) // CHECK-NEXT: } // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Binding: Global -// CHECK-NEXT: Type: None -// CHECK-NEXT: Other: 0 -// CHECK-NEXT: Section: .text -// CHECK-NEXT: } -// CHECK-NEXT: Symbol { // CHECK-NEXT: Name: CommonStrong_with_CommonStrong // CHECK-NEXT: Value: // CHECK-NEXT: Size: 63 @@ -315,6 +306,15 @@ // CHECK-NEXT: Other: 0 // CHECK-NEXT: Section: Undefined // CHECK-NEXT: } +// CHECK-NEXT: Symbol { +// CHECK-NEXT: Name: _start +// CHECK-NEXT: Value: 0x201000 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Global (0x1) +// CHECK-NEXT: Type: None (0x0) +// CHECK-NEXT: Other: 0 +// CHECK-NEXT: Section: .text (0x1) +// CHECK-NEXT: } // CHECK-NEXT: ] .globl _start diff --git a/test/ELF/retain-symbols-file.s b/test/ELF/retain-symbols-file.s new file mode 100644 index 0000000000000..b146bd797b5c0 --- /dev/null +++ b/test/ELF/retain-symbols-file.s @@ -0,0 +1,44 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: echo "bar" > %t_retain.txt +# RUN: echo "foo" >> %t_retain.txt +# RUN: ld.lld -shared --retain-symbols-file=%t_retain.txt %t -o %t2 +# RUN: llvm-readobj -s -sd -t %t2 | FileCheck %s + +## Check separate form. +# RUN: ld.lld -shared --retain-symbols-file %t_retain.txt %t -o %t2 +# RUN: llvm-readobj -s -sd -t %t2 | FileCheck %s + +# CHECK: Symbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: (0) +# CHECK: Symbol { +# CHECK-NEXT: Name: bar +# CHECK: Symbol { +# CHECK-NEXT: Name: foo +# CHECK-NOT: Symbol + +.text +.globl _start +_start: +call zed@PLT +call und@PLT + +.globl foo +.type foo,@function +foo: +retq + +.globl bar +.type bar,@function +bar: +retq + +.globl zed +.type zed,@function +zed: +retq + +.type loc,@function +loc: +retq diff --git a/test/ELF/section-name.s b/test/ELF/section-name.s index f470c48c6a37d..53f0e536f3d6d 100644 --- a/test/ELF/section-name.s +++ b/test/ELF/section-name.s @@ -1,6 +1,6 @@ # 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 +# RUN: llvm-objdump --section-headers %tout | FileCheck %s # REQUIRES: x86 .global _start @@ -8,36 +8,52 @@ _start: .section .text.a,"ax" +.byte 0 .section .text.,"ax" +.byte 0 .section .rodata.a,"a" +.byte 0 .section .rodata,"a" +.byte 0 .section .data.a,"aw" +.byte 0 .section .data,"aw" +.byte 0 .section .bss.a,"",@nobits +.byte 0 .section .bss,"",@nobits +.byte 0 .section .foo.a,"aw" +.byte 0 .section .foo,"aw" +.byte 0 .section .data.rel.ro,"aw",%progbits +.byte 0 .section .data.rel.ro.a,"aw",%progbits +.byte 0 .section .data.rel.ro.local,"aw",%progbits +.byte 0 .section .data.rel.ro.local.a,"aw",%progbits +.byte 0 .section .tbss.foo,"aGwT",@nobits,foo,comdat +.byte 0 .section .gcc_except_table.foo,"aG",@progbits,foo,comdat +.byte 0 .section .tdata.foo,"aGwT",@progbits,foo,comdat +.byte 0 -// CHECK-NOT: Name: .rodata.a -// CHECK: Name: .rodata -// CHECK: Name: .gcc_except_table ({{.*}}) -// CHECK-NOT: Name: .text.a -// CHECK: Name: .text -// CHECK: Name: .tdata ({{.*}}) -// CHECK: Name: .tbss ({{.*}}) -// CHECK-NOT: Name: .data.rel.ro.a -// CHECK-NOT: Name: .data.rel.ro.local.a -// CHECK: Name: .data.rel.ro -// CHECK-NOT: Name: .data.a -// CHECK: Name: .data -// CHECK: Name: .foo.a -// CHECK: Name: .foo -// CHECK-NOT: Name: .bss.a -// CHECK: Name: .bss +// CHECK: 1 .rodata 00000002 +// CHECK: 2 .gcc_except_table 00000001 +// CHECK: 3 .text 00000002 +// CHECK: 4 .tdata 00000001 +// CHECK: 5 .tbss 00000001 +// CHECK: 6 .data.rel.ro 00000004 +// CHECK: 7 .data 00000002 +// CHECK: 8 .foo.a 00000001 +// CHECK: 9 .foo 00000001 +// CHECK: 10 .bss 00000001 +// CHECK: 11 .bss 00000001 +// CHECK: 12 .comment 00000008 +// CHECK: 13 .symtab 00000060 +// CHECK: 14 .shstrtab 00000075 +// CHECK: 15 .strtab 0000001d diff --git a/test/ELF/section-symbols.test b/test/ELF/section-symbols.test new file mode 100644 index 0000000000000..2ef77a828b654 --- /dev/null +++ b/test/ELF/section-symbols.test @@ -0,0 +1,35 @@ +# RUN: yaml2obj %s -o %t +# RUN: ld.lld -shared %t -o %tout + +# Verify that lld can handle STT_SECTION symbols associated +# with SHT_REL[A]/SHT_SYMTAB/SHT_STRTAB sections. + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_FREEBSD + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: "00000000" + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + AddressAlign: 0x0000000000000008 + Info: .text + Relocations: +Symbols: + Local: + - Type: STT_SECTION + Section: .rela.text + - Type: STT_SECTION + Section: .shstrtab + - Type: STT_SECTION + Section: .symtab + - Type: STT_SECTION + Section: .strtab diff --git a/test/ELF/sectionstart.s b/test/ELF/sectionstart.s new file mode 100644 index 0000000000000..23574c14748a0 --- /dev/null +++ b/test/ELF/sectionstart.s @@ -0,0 +1,67 @@ +# 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: 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: 2 .data 00000004 0000000000110000 DATA +# CHECK-NEXT: 3 .bss 00000004 0000000000200000 BSS + +## The same, but dropped "0x" prefix. +# RUN: ld.lld %t.o --section-start .text=100000 \ +# RUN: --section-start .data=110000 --section-start .bss=0x200000 -o %t1 +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s + +## Use -Ttext, -Tdata, -Tbss as replacement for --section-start: +# RUN: ld.lld %t.o -Ttext=0x100000 -Tdata=0x110000 -Tbss=0x200000 -o %t4 +# RUN: llvm-objdump -section-headers %t4 | FileCheck %s + +## Check Ttext-segment X and Ttext-segment=X forms. +# RUN: ld.lld %t.o -Ttext-segment=0x100000 -Tdata=0x110000 -Tbss=0x200000 -o %t4 +# RUN: llvm-objdump -section-headers %t4 | FileCheck %s +# RUN: ld.lld %t.o -Ttext-segment 0x100000 -Tdata=0x110000 -Tbss=0x200000 -o %t4 +# RUN: llvm-objdump -section-headers %t4 | FileCheck %s + +## The same, but dropped "0x" prefix. +# RUN: ld.lld %t.o -Ttext=100000 -Tdata=110000 -Tbss=200000 -o %t5 +# RUN: llvm-objdump -section-headers %t5 | FileCheck %s + +## Check form without assignment: +# RUN: ld.lld %t.o -Ttext 0x100000 -Tdata 0x110000 -Tbss 0x200000 -o %t4 +# RUN: llvm-objdump -section-headers %t4 | FileCheck %s + +## Errors: +# RUN: not ld.lld %t.o --section-start .text100000 -o %t2 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: | FileCheck -check-prefix=ERR2 %s +# ERR2: invalid argument: --section-start .text=1Q0000 + +# RUN: not ld.lld %t.o -Ttext=1w0000 -o %t6 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR3 %s +# ERR3: invalid argument: --Ttext 1w0000 + +# RUN: not ld.lld %t.o -Tbss=1w0000 -o %t6 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR4 %s +# ERR4: invalid argument: --Tbss 1w0000 + +# RUN: not ld.lld %t.o -Tdata=1w0000 -o %t6 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR5 %s +# ERR5: invalid argument: --Tdata 1w0000 + +.text +.globl _start +_start: + nop + +.data +.long 0 + +.bss +.zero 4 diff --git a/test/ELF/segments.s b/test/ELF/segments.s new file mode 100644 index 0000000000000..9307ba39fe467 --- /dev/null +++ b/test/ELF/segments.s @@ -0,0 +1,108 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld %t -o %t1 +# RUN: llvm-readobj --program-headers %t1 | FileCheck --check-prefix=ROSEGMENT %s + +# ROSEGMENT: ProgramHeader { +# ROSEGMENT: Type: PT_LOAD +# ROSEGMENT-NEXT: Offset: 0x0 +# ROSEGMENT-NEXT: VirtualAddress: +# ROSEGMENT-NEXT: PhysicalAddress: +# ROSEGMENT-NEXT: FileSize: +# ROSEGMENT-NEXT: MemSize: +# ROSEGMENT-NEXT: Flags [ +# ROSEGMENT-NEXT: PF_R +# ROSEGMENT-NEXT: ] +# ROSEGMENT-NEXT: Alignment: 4096 +# ROSEGMENT-NEXT: } +# ROSEGMENT-NEXT: ProgramHeader { +# ROSEGMENT-NEXT: Type: PT_LOAD +# ROSEGMENT-NEXT: Offset: 0x1000 +# ROSEGMENT-NEXT: VirtualAddress: +# ROSEGMENT-NEXT: PhysicalAddress: +# ROSEGMENT-NEXT: FileSize: +# ROSEGMENT-NEXT: MemSize: +# ROSEGMENT-NEXT: Flags [ +# ROSEGMENT-NEXT: PF_R +# ROSEGMENT-NEXT: PF_X +# ROSEGMENT-NEXT: ] +# ROSEGMENT-NEXT: Alignment: 4096 +# ROSEGMENT-NEXT: } +# ROSEGMENT-NEXT: ProgramHeader { +# ROSEGMENT-NEXT: Type: PT_LOAD +# ROSEGMENT-NEXT: Offset: 0x2000 +# ROSEGMENT-NEXT: VirtualAddress: +# ROSEGMENT-NEXT: PhysicalAddress: +# ROSEGMENT-NEXT: FileSize: 1 +# ROSEGMENT-NEXT: MemSize: 1 +# ROSEGMENT-NEXT: Flags [ +# ROSEGMENT-NEXT: PF_R +# ROSEGMENT-NEXT: PF_W +# ROSEGMENT-NEXT: ] +# ROSEGMENT-NEXT: Alignment: 4096 +# ROSEGMENT-NEXT: } + +# RUN: ld.lld -no-rosegment %t -o %t2 +# RUN: llvm-readobj --program-headers %t2 | FileCheck --check-prefix=NOROSEGMENT %s + +# NOROSEGMENT: ProgramHeader { +# NOROSEGMENT: Type: PT_LOAD +# NOROSEGMENT-NEXT: Offset: 0x0 +# NOROSEGMENT-NEXT: VirtualAddress: +# NOROSEGMENT-NEXT: PhysicalAddress: +# NOROSEGMENT-NEXT: FileSize: +# NOROSEGMENT-NEXT: MemSize: +# NOROSEGMENT-NEXT: Flags [ +# NOROSEGMENT-NEXT: PF_R +# NOROSEGMENT-NEXT: PF_X +# NOROSEGMENT-NEXT: ] +# NOROSEGMENT-NEXT: Alignment: 4096 +# NOROSEGMENT-NEXT: } +# NOROSEGMENT-NEXT: ProgramHeader { +# NOROSEGMENT-NEXT: Type: PT_LOAD +# NOROSEGMENT-NEXT: Offset: 0x1000 +# NOROSEGMENT-NEXT: VirtualAddress: +# NOROSEGMENT-NEXT: PhysicalAddress: +# NOROSEGMENT-NEXT: FileSize: +# NOROSEGMENT-NEXT: MemSize: +# NOROSEGMENT-NEXT: Flags [ +# NOROSEGMENT-NEXT: PF_R +# NOROSEGMENT-NEXT: PF_W +# NOROSEGMENT-NEXT: ] +# NOROSEGMENT-NEXT: Alignment: 4096 +# NOROSEGMENT-NEXT: } +# NOROSEGMENT-NEXT: ProgramHeader { +# NOROSEGMENT-NEXT: Type: PT_GNU_STACK + +# RUN: ld.lld -N %t -o %t3 +# RUN: llvm-readobj --program-headers %t3 | FileCheck --check-prefix=OMAGIC %s + +# OMAGIC: ProgramHeader { +# OMAGIC: Type: PT_LOAD +# OMAGIC-NEXT: Offset: 0x0 +# OMAGIC-NEXT: VirtualAddress: +# OMAGIC-NEXT: PhysicalAddress: +# OMAGIC-NEXT: FileSize: +# OMAGIC-NEXT: MemSize: +# OMAGIC-NEXT: Flags [ +# OMAGIC-NEXT: PF_R +# OMAGIC-NEXT: PF_W +# OMAGIC-NEXT: PF_X +# OMAGIC-NEXT: ] +# OMAGIC-NEXT: Alignment: 4096 +# OMAGIC-NEXT: } +# OMAGIC-NEXT: ProgramHeader { +# OMAGIC-NEXT: Type: PT_GNU_STACK + +.global _start +_start: + nop + +.section .ro,"a" +nop + +.section .rw,"aw" +nop + +.section .rx,"ax" +nop diff --git a/test/ELF/shared-be.s b/test/ELF/shared-be.s index 12eb3131050a2..c969793d9d21b 100644 --- a/test/ELF/shared-be.s +++ b/test/ELF/shared-be.s @@ -22,11 +22,11 @@ // CHECK-NEXT: Tag Type Name/Value // CHECK-NEXT: 0x000000000000001D RUNPATH foo:bar // CHECK-NEXT: 0x0000000000000001 NEEDED SharedLibrary ({{.*}}2.so) +// CHECK-NEXT: 0x0000000000000015 DEBUG 0x0 // CHECK-NEXT: 0x0000000000000007 RELA [[RELADDR]] // CHECK-NEXT: 0x0000000000000008 RELASZ [[RELSIZE]] (bytes) // CHECK-NEXT: 0x0000000000000009 RELAENT [[RELENT]] (bytes) -// CHECK: 0x0000000000000015 DEBUG 0x0 -// CHECK-NEXT: 0x0000000000000000 NULL 0x0 +// CHECK: 0x0000000000000000 NULL 0x0 // CHECK-NEXT: ] .global _start diff --git a/test/ELF/shared.s b/test/ELF/shared.s index 086cc73451250..350ef5c602d00 100644 --- a/test/ELF/shared.s +++ b/test/ELF/shared.s @@ -14,7 +14,7 @@ // SO-NEXT: Flags [ // SO-NEXT: ] // SO-NEXT: Address: -// SO-NEXT: Offset: 0x1030 +// SO-NEXT: Offset: 0x1038 // SO-NEXT: Size: // SO-NEXT: Link: // SO-NEXT: Info: @@ -184,7 +184,7 @@ // CHECK: DynamicSymbols [ // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: @ (0) +// CHECK-NEXT: Name: @ // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local @@ -223,7 +223,7 @@ // DONT_EXPORT: DynamicSymbols [ // DONT_EXPORT-NEXT: Symbol { -// DONT_EXPORT-NEXT: Name: @ (0) +// DONT_EXPORT-NEXT: Name: @ // DONT_EXPORT-NEXT: Value: 0x0 // DONT_EXPORT-NEXT: Size: 0 // DONT_EXPORT-NEXT: Binding: Local (0x0) @@ -255,6 +255,7 @@ // CHECK-NEXT: Tag Type Name/Value // CHECK-NEXT: 0x0000001D RUNPATH foo:bar // CHECK-NEXT: 0x00000001 NEEDED SharedLibrary ({{.*}}2.so) +// CHECK-NEXT: 0x00000015 DEBUG 0x0 // CHECK-NEXT: 0x00000011 REL [[RELADDR]] // CHECK-NEXT: 0x00000012 RELSZ [[RELSIZE]] (bytes) // CHECK-NEXT: 0x00000013 RELENT [[RELENT]] (bytes) @@ -263,7 +264,6 @@ // CHECK-NEXT: 0x00000005 STRTAB [[DYNSTRADDR]] // CHECK-NEXT: 0x0000000A STRSZ // CHECK-NEXT: 0x00000004 HASH [[HASHADDR]] -// CHECK-NEXT: 0x00000015 DEBUG 0x0 // CHECK-NEXT: 0x00000000 NULL 0x0 // CHECK-NEXT: ] diff --git a/test/ELF/shf-info-link.test b/test/ELF/shf-info-link.test new file mode 100644 index 0000000000000..ea15655ec89f7 --- /dev/null +++ b/test/ELF/shf-info-link.test @@ -0,0 +1,32 @@ +# RUN: yaml2obj %s -o %t.o +# RUN: yaml2obj %S/Inputs/shf-info-link.test -o %t2.o +# RUN: ld.lld %t.o %t2.o -o %t3.o -r +# RUN: llvm-readobj -s %t3.o | FileCheck %s + +# CHECK-NOT: Name: .rela.text +# CHECK: Name: .rela.text +# CHECK-NOT: Name: .rela.text + + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + - Name: .rela.text + Type: SHT_RELA + Flags: [ SHF_INFO_LINK ] + Link: .symtab + Info: .text + Relocations: + - Offset: 0x0000000000000000 + Symbol: foo + Type: R_X86_64_64 +Symbols: + Global: + - Name: foo diff --git a/test/ELF/sort-norosegment.s b/test/ELF/sort-norosegment.s new file mode 100644 index 0000000000000..3026bb2dbf3ca --- /dev/null +++ b/test/ELF/sort-norosegment.s @@ -0,0 +1,15 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t + +# RUN: ld.lld -no-rosegment -o %t1 %t -shared +# RUN: llvm-readobj -elf-output-style=GNU -s %t1 | FileCheck %s + +# CHECK: .text {{.*}} AX +# CHECK-NEXT: .dynsym {{.*}} A +# CHECK-NEXT: .hash {{.*}} A +# CHECK-NEXT: .dynstr {{.*}} A +# CHECK-NEXT: .dynamic {{.*}} WA +# CHECK-NEXT: foo {{.*}} WA + +.section foo, "aw" +.byte 0 diff --git a/test/ELF/startstop-gccollect.s b/test/ELF/startstop-gccollect.s index b0cd41337e345..589ccafafcca0 100644 --- a/test/ELF/startstop-gccollect.s +++ b/test/ELF/startstop-gccollect.s @@ -12,13 +12,13 @@ # RUN: llvm-objdump -d %tout | FileCheck -check-prefix=DISASM %s # DISASM: _start: -# DISASM-NEXT: 11000: 90 nop +# DISASM-NEXT: 201000: 90 nop # DISASM-NEXT: Disassembly of section foo: # DISASM-NEXT: foo: -# DISASM-NEXT: 11001: 90 nop +# DISASM-NEXT: 201001: 90 nop # DISASM-NEXT: Disassembly of section bar: # DISASM-NEXT: bar: -# DISASM-NEXT: 11002: 90 nop +# DISASM-NEXT: 201002: 90 nop .global _start .text diff --git a/test/ELF/startstop-shared.s b/test/ELF/startstop-shared.s index 77411f3f25c97..80ccf3df0aad8 100644 --- a/test/ELF/startstop-shared.s +++ b/test/ELF/startstop-shared.s @@ -6,21 +6,23 @@ .data .quad __start_foo .section foo,"aw" -// By default the symbol is hidden. -// CHECK: R_X86_64_RELATIVE - 0x[[ADDR1:.*]] .hidden __start_bar .quad __start_bar .section bar,"a" -// References do not affect the visibility. -// CHECK: R_X86_64_RELATIVE - 0x[[ADDR2:.*]] + +// Test that we are able to hide the symbol. +// CHECK: R_X86_64_RELATIVE - 0x[[ADDR:.*]] + +// By default the symbol is visible and we need a dynamic reloc. +// CHECK: R_X86_64_64 __start_foo 0x0 // CHECK: Name: __start_bar -// CHECK-NEXT: Value: 0x[[ADDR2]] +// CHECK-NEXT: Value: 0x[[ADDR]] // CHECK-NEXT: Size: // CHECK-NEXT: Binding: Local // CHECK: Name: __start_foo -// CHECK-NEXT: Value: 0x[[ADDR1]] +// CHECK-NEXT: Value: // CHECK-NEXT: Size: -// CHECK-NEXT: Binding: Local +// CHECK-NEXT: Binding: Global diff --git a/test/ELF/startstop-shared2.s b/test/ELF/startstop-shared2.s new file mode 100644 index 0000000000000..b8bd8abe90d42 --- /dev/null +++ b/test/ELF/startstop-shared2.s @@ -0,0 +1,14 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/startstop-shared2.s -o %t.o +// RUN: ld.lld -o %t.so %t.o -shared +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o +// RUN: ld.lld -o %t %t2.o %t.so +// RUN: llvm-objdump -s -h %t | FileCheck %s + +// CHECK: foo 00000000 0000000000201008 + +// CHECK: Contents of section .text: +// CHECK-NEXT: 201000 08102000 00000000 + +.quad __start_foo +.section foo,"ax" diff --git a/test/ELF/startstop.s b/test/ELF/startstop.s index a7b2e43e6a5fa..326196dafa680 100644 --- a/test/ELF/startstop.s +++ b/test/ELF/startstop.s @@ -22,30 +22,46 @@ // SYMBOL: Relocations [ // SYMBOL-NEXT: Section ({{.*}}) .rela.dyn { -// SYMBOL-NEXT: 0x3000 R_X86_64_RELATIVE - 0x3020 -// SYMBOL-NEXT: 0x3008 R_X86_64_RELATIVE - 0x3021 -// SYMBOL-NEXT: 0x3010 R_X86_64_RELATIVE - 0x3010 -// SYMBOL-NEXT: 0x3018 R_X86_64_RELATIVE - 0x3011 +// SYMBOL-NEXT: 0x3010 R_X86_64_64 __stop_zed1 0x0 +// SYMBOL-NEXT: 0x3018 R_X86_64_64 __stop_zed1 0x1 +// SYMBOL-NEXT: 0x3000 R_X86_64_64 __stop_zed2 0x0 +// SYMBOL-NEXT: 0x3008 R_X86_64_64 __stop_zed2 0x1 // SYMBOL-NEXT: } // SYMBOL-NEXT: ] // SYMBOL: Symbol { // SYMBOL: Name: __start_bar // SYMBOL: Value: 0x1012 +// SYMBOL: STV_HIDDEN // SYMBOL: Section: bar // SYMBOL: } // SYMBOL-NOT: Section: __stop_bar // SYMBOL: Symbol { // SYMBOL: Name: __start_foo // SYMBOL: Value: 0x100F +// SYMBOL: STV_HIDDEN // SYMBOL: Section: foo // SYMBOL: } // SYMBOL: Symbol { // SYMBOL: Name: __stop_foo // SYMBOL: Value: 0x1012 +// STMBOL: STV_HIDDEN // SYMBOL: Section: foo // SYMBOL: } +// SYMBOL: Symbol { +// SYMBOL: Name: __stop_zed1 +// SYMBOL: Value: 0x3010 +// STMBOL: Other: 0 +// SYMBOL: Section: zed1 +// SYMBOL: } +// SYMBOL: Symbol { +// SYMBOL: Name: __stop_zed2 +// SYMBOL: Value: 0x3020 +// STMBOL: Other: 0 +// SYMBOL: Section: zed2 +// SYMBOL: } + .hidden __start_foo .hidden __stop_foo .hidden __start_bar diff --git a/test/ELF/string-gc.s b/test/ELF/string-gc.s index e7f86a1c60772..3157a79a65cd0 100644 --- a/test/ELF/string-gc.s +++ b/test/ELF/string-gc.s @@ -14,7 +14,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: s3 -// CHECK-NEXT: Value: 0x10125 +// CHECK-NEXT: Value: 0x200125 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local (0x0) // CHECK-NEXT: Type: Object (0x1) @@ -23,7 +23,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: s1 -// CHECK-NEXT: Value: 0x10120 +// CHECK-NEXT: Value: 0x200120 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local (0x0) // CHECK-NEXT: Type: Object (0x1) @@ -34,7 +34,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: 0x201000 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global (0x1) // CHECK-NEXT: Type: Function (0x2) diff --git a/test/ELF/string-table.s b/test/ELF/string-table.s index 892c348f6fd01..c783445f8e315 100644 --- a/test/ELF/string-table.s +++ b/test/ELF/string-table.s @@ -19,7 +19,7 @@ _start: // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x10120 +// CHECK-NEXT: Address: 0x200120 // CHECK: Name: foobar // CHECK-NEXT: Type: SHT_PROGBITS @@ -59,8 +59,9 @@ _start: // CHECK-NEXT: EntrySize: 0 // CHECK-NEXT: SectionData ( // CHECK-NEXT: 0000: 00626172 002E7465 78740066 6F6F6261 |.bar..text.fooba| -// CHECK-NEXT: 0010: 72002E73 796D7461 62002E73 68737472 |r..symtab..shstr| -// CHECK-NEXT: 0020: 74616200 2E737472 74616200 |tab..strtab.| +// CHECK-NEXT: 0010: 72002E63 6F6D6D65 6E74002E 73796D74 |r..comment..symt| +// CHECK-NEXT: 0020: 6162002E 73687374 72746162 002E7374 |ab..shstrtab..st| +// CHECK-NEXT: 0030: 72746162 00 |rtab.| // CHECK-NEXT: ) // CHECK-NEXT:} // CHECK: Name: .strtab diff --git a/test/ELF/symbol-ordering-file.s b/test/ELF/symbol-ordering-file.s new file mode 100644 index 0000000000000..5a88b8c0827f9 --- /dev/null +++ b/test/ELF/symbol-ordering-file.s @@ -0,0 +1,44 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t.out +# RUN: llvm-objdump -s %t.out| FileCheck %s --check-prefix=BEFORE + +# BEFORE: Contents of section .foo: +# BEFORE-NEXT: 201000 11223344 5566 + +# RUN: echo "_foo4 " > %t_order.txt +# RUN: echo " _foo3" >> %t_order.txt +# RUN: echo "_foo5" >> %t_order.txt +# RUN: echo "_foo2" >> %t_order.txt +# RUN: echo " " >> %t_order.txt +# RUN: echo "_foo4" >> %t_order.txt +# RUN: echo "_bar1" >> %t_order.txt +# RUN: echo "_foo1" >> %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 + +# AFTER: Contents of section .foo: +# AFTER-NEXT: 201000 44335566 2211 + +.section .foo,"ax",@progbits,unique,1 +_foo1: + .byte 0x11 + +.section .foo,"ax",@progbits,unique,2 +_foo2: + .byte 0x22 + +.section .foo,"ax",@progbits,unique,3 +_foo3: + .byte 0x33 + +.section .foo,"ax",@progbits,unique,4 +_foo4: + .byte 0x44 + +.section .foo,"ax",@progbits,unique,5 +_foo5: + .byte 0x55 +_bar1: + .byte 0x66 diff --git a/test/ELF/symbol-override.s b/test/ELF/symbol-override.s index 487885b75b362..8b62d8749aa04 100644 --- a/test/ELF/symbol-override.s +++ b/test/ELF/symbol-override.s @@ -25,7 +25,7 @@ // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: foo -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: 0x201000 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Function @@ -37,7 +37,7 @@ .text .globl foo .type foo,@function -foo: +foo: nop .text diff --git a/test/ELF/symbols.s b/test/ELF/symbols.s index a6c838cf0b74e..54dfcbd087cdb 100644 --- a/test/ELF/symbols.s +++ b/test/ELF/symbols.s @@ -50,7 +50,7 @@ internal: // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x10158 +// CHECK-NEXT: Address: 0x200158 // CHECK: Name: .text // CHECK-NEXT: Type: SHT_PROGBITS @@ -58,7 +58,7 @@ internal: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_EXECINSTR // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x1100 +// CHECK-NEXT: Address: 0x201000 // CHECK: Name: .bss // CHECK-NEXT: Type: SHT_NOBITS @@ -66,7 +66,7 @@ internal: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x12000 +// CHECK-NEXT: Address: 0x202000 // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 4 @@ -82,7 +82,7 @@ internal: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: hidden -// CHECK-NEXT: Value: 0x10160 +// CHECK-NEXT: Value: 0x200160 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -93,7 +93,7 @@ internal: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: internal -// CHECK-NEXT: Value: 0x10160 +// CHECK-NEXT: Value: 0x200160 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local // CHECK-NEXT: Type: None @@ -104,7 +104,7 @@ internal: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: _start -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: 0x201000 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global (0x1) // CHECK-NEXT: Type: Function @@ -131,7 +131,7 @@ internal: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: common -// CHECK-NEXT: Value: 0x12000 +// CHECK-NEXT: Value: 0x202000 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Object @@ -140,7 +140,7 @@ internal: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: foo -// CHECK-NEXT: Value: 0x11000 +// CHECK-NEXT: Value: 0x201000 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Weak (0x2) // CHECK-NEXT: Type: Object @@ -149,7 +149,7 @@ internal: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: protected -// CHECK-NEXT: Value: 0x10160 +// CHECK-NEXT: Value: 0x200160 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None @@ -160,7 +160,7 @@ internal: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: zed -// CHECK-NEXT: Value: 0x10158 +// CHECK-NEXT: Value: 0x200158 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global (0x1) // CHECK-NEXT: Type: None @@ -169,7 +169,7 @@ internal: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: zed2 -// CHECK-NEXT: Value: 0x1015C +// CHECK-NEXT: Value: 0x20015C // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None @@ -178,7 +178,7 @@ internal: // CHECK-NEXT: } // CHECK-NEXT: Symbol { // CHECK-NEXT: Name: zed3 -// CHECK-NEXT: Value: 0x10160 +// CHECK-NEXT: Value: 0x200160 // CHECK-NEXT: Size: 4 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: None diff --git a/test/ELF/synthetic-got.s b/test/ELF/synthetic-got.s new file mode 100644 index 0000000000000..c84d27827aef7 --- /dev/null +++ b/test/ELF/synthetic-got.s @@ -0,0 +1,32 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "SECTIONS { }" > %t0.script +# RUN: ld.lld -shared %t.o -o %t0.out --script %t0.script +# RUN: llvm-objdump -section-headers %t0.out | FileCheck %s --check-prefix=GOT +# RUN: llvm-objdump -s -section=.got -section=.got.plt %t0.out \ +# RUN: | FileCheck %s --check-prefix=GOTDATA + +# GOT: Sections: +# GOT: 9 .got 00000008 00000000000001b0 DATA +# GOT-NEXT: 10 .got.plt 00000020 00000000000001b8 DATA +# GOTDATA: Contents of section .got: +# GOTDATA-NEXT: 01b0 00000000 00000000 +# GOTDATA-NEXT: Contents of section .got.plt: +# GOTDATA-NEXT: 01b8 e0000000 00000000 00000000 00000000 +# GOTDATA-NEXT: 01c8 00000000 00000000 d6000000 00000000 + +# RUN: echo "SECTIONS { .mygot : { *(.got) *(.got.plt) } }" > %t1.script +# RUN: ld.lld -shared %t.o -o %t1.out --script %t1.script +# RUN: llvm-objdump -section-headers %t1.out | FileCheck %s --check-prefix=MYGOT +# RUN: llvm-objdump -s -section=.mygot %t1.out | FileCheck %s --check-prefix=MYGOTDATA + +# MYGOT: Sections: +# MYGOT: 9 .mygot 00000028 00000000000001b0 DATA +# MYGOT-NOT: .got +# MYGOT-NOT: .got.plt +# MYGOTDATA: 01b0 00000000 00000000 e0000000 00000000 +# MYGOTDATA-NEXT: 01c0 00000000 00000000 00000000 00000000 +# MYGOTDATA-NEXT: 01d0 d6000000 00000000 + +mov bar@gotpcrel(%rip), %rax +call foo@plt diff --git a/test/ELF/sysroot.s b/test/ELF/sysroot.s index 38fd8cdde402a..0b7b17260e58b 100644 --- a/test/ELF/sysroot.s +++ b/test/ELF/sysroot.s @@ -9,7 +9,7 @@ // Should not link because of undefined symbol _bar // RUN: not ld.lld -o %t/r %t/m.o 2>&1 \ // RUN: | FileCheck --check-prefix=UNDEFINED %s -// UNDEFINED: undefined symbol: _bar +// UNDEFINED: error: {{.*}}:(.text+0x1): undefined symbol '_bar' // We need to be sure that there is no suitable library in the /lib directory // RUN: not ld.lld -o %t/r %t/m.o -L/lib -l:libls.a 2>&1 \ @@ -34,3 +34,4 @@ .globl _start,_bar _start: + call _bar diff --git a/test/ELF/tls-got.s b/test/ELF/tls-got.s index f36d94e40cb1d..450dd634d7a97 100644 --- a/test/ELF/tls-got.s +++ b/test/ELF/tls-got.s @@ -24,23 +24,23 @@ // CHECK: Relocations [ // CHECK-NEXT: Section (4) .rela.dyn { -// CHECK-NEXT: 0x120B8 R_X86_64_TPOFF64 tls0 0x0 +// CHECK-NEXT: 0x2020B8 R_X86_64_TPOFF64 tls0 0x0 // CHECK-NEXT: [[ADDR]] R_X86_64_TPOFF64 tls1 0x0 // CHECK-NEXT: } // CHECK-NEXT: ] -//0x11000 + 4249 + 7 = 0x120B0 -//0x1100A + 4247 + 7 = 0x120B8 -//0x11014 + 4237 + 7 = 0x120B8 +//0x201000 + 4249 + 7 = 0x2020B0 +//0x20100A + 4247 + 7 = 0x2020B8 +//0x201014 + 4237 + 7 = 0x2020B8 //DISASM: Disassembly of section .text: //DISASM-NEXT: main: -//DISASM-NEXT: 11000: 48 8b 05 a9 10 00 00 movq 4265(%rip), %rax -//DISASM-NEXT: 11007: 64 8b 00 movl %fs:(%rax), %eax -//DISASM-NEXT: 1100a: 48 8b 05 a7 10 00 00 movq 4263(%rip), %rax -//DISASM-NEXT: 11011: 64 8b 00 movl %fs:(%rax), %eax -//DISASM-NEXT: 11014: 48 8b 05 9d 10 00 00 movq 4253(%rip), %rax -//DISASM-NEXT: 1101b: 64 8b 00 movl %fs:(%rax), %eax -//DISASM-NEXT: 1101e: c3 retq +//DISASM-NEXT: 201000: 48 8b 05 a9 10 00 00 movq 4265(%rip), %rax +//DISASM-NEXT: 201007: 64 8b 00 movl %fs:(%rax), %eax +//DISASM-NEXT: 20100a: 48 8b 05 a7 10 00 00 movq 4263(%rip), %rax +//DISASM-NEXT: 201011: 64 8b 00 movl %fs:(%rax), %eax +//DISASM-NEXT: 201014: 48 8b 05 9d 10 00 00 movq 4253(%rip), %rax +//DISASM-NEXT: 20101b: 64 8b 00 movl %fs:(%rax), %eax +//DISASM-NEXT: 20101e: c3 retq .section .tdata,"awT",@progbits diff --git a/test/ELF/tls-mismatch.s b/test/ELF/tls-mismatch.s index fb70229e1a52c..aee1f73dedce5 100644 --- a/test/ELF/tls-mismatch.s +++ b/test/ELF/tls-mismatch.s @@ -2,7 +2,7 @@ // 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 -// CHECK: TLS attribute mismatch for symbol: tlsvar +// CHECK: TLS attribute mismatch for symbol 'tlsvar' .globl _start,tlsvar _start: diff --git a/test/ELF/tls-offset.s b/test/ELF/tls-offset.s index 8f5a46d988daa..1734f7fb9e9c2 100644 --- a/test/ELF/tls-offset.s +++ b/test/ELF/tls-offset.s @@ -30,7 +30,7 @@ _start: // CHECK-NEXT: SHF_TLS // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x12000 +// CHECK-NEXT: Address: 0x202000 // CHECK-NEXT: Offset: 0x2000 // CHECK-NEXT: Size: 4 @@ -41,7 +41,7 @@ _start: // CHECK-NEXT: SHF_TLS // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x12010 +// CHECK-NEXT: Address: 0x202010 // CHECK-NEXT: Offset: 0x2004 // CHECK-NEXT: Size: 16 @@ -51,6 +51,6 @@ _start: // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x12004 +// CHECK-NEXT: Address: 0x202004 // CHECK-NEXT: Offset: 0x2004 // CHECK-NEXT: Size: 4 diff --git a/test/ELF/tls-opt-gdie.s b/test/ELF/tls-opt-gdie.s index 6ed370e3f0b22..c423a3e0f2468 100644 --- a/test/ELF/tls-opt-gdie.s +++ b/test/ELF/tls-opt-gdie.s @@ -13,7 +13,7 @@ //RELOC-NEXT: SHF_ALLOC //RELOC-NEXT: SHF_WRITE //RELOC-NEXT: ] -//RELOC-NEXT: Address: 0x120B0 +//RELOC-NEXT: Address: 0x2020B0 //RELOC-NEXT: Offset: 0x20B0 //RELOC-NEXT: Size: 16 //RELOC-NEXT: Link: 0 @@ -23,19 +23,19 @@ //RELOC-NEXT: } //RELOC: Relocations [ //RELOC-NEXT: Section (4) .rela.dyn { -//RELOC-NEXT: 0x120B0 R_X86_64_TPOFF64 tlsshared0 0x0 -//RELOC-NEXT: 0x120B8 R_X86_64_TPOFF64 tlsshared1 0x0 +//RELOC-NEXT: 0x2020B0 R_X86_64_TPOFF64 tlsshared0 0x0 +//RELOC-NEXT: 0x2020B8 R_X86_64_TPOFF64 tlsshared1 0x0 //RELOC-NEXT: } //RELOC-NEXT: ] -//0x11009 + (4256 + 7) = 0x120B0 -//0x11019 + (4248 + 7) = 0x120B8 +//0x201009 + (4256 + 7) = 0x2020B0 +//0x201019 + (4248 + 7) = 0x2020B8 // DISASM: Disassembly of section .text: // DISASM-NEXT: _start: -// DISASM-NEXT: 11000: {{.*}} movq %fs:0, %rax -// DISASM-NEXT: 11009: {{.*}} addq 4256(%rip), %rax -// DISASM-NEXT: 11010: {{.*}} movq %fs:0, %rax -// DISASM-NEXT: 11019: {{.*}} addq 4248(%rip), %rax +// DISASM-NEXT: 201000: {{.*}} movq %fs:0, %rax +// DISASM-NEXT: 201009: {{.*}} addq 4256(%rip), %rax +// DISASM-NEXT: 201010: {{.*}} movq %fs:0, %rax +// DISASM-NEXT: 201019: {{.*}} addq 4248(%rip), %rax .section .text .globl _start diff --git a/test/ELF/tls-opt-local.s b/test/ELF/tls-opt-local.s index d2904ac6fba00..633c22b0611c9 100644 --- a/test/ELF/tls-opt-local.s +++ b/test/ELF/tls-opt-local.s @@ -8,18 +8,18 @@ // DISASM: Disassembly of section .text: // DISASM-NEXT: _start: -// DISASM-NEXT: 11000: 48 c7 c0 f8 ff ff ff movq $-8, %rax -// DISASM-NEXT: 11007: 49 c7 c7 f8 ff ff ff movq $-8, %r15 -// DISASM-NEXT: 1100e: 48 8d 80 f8 ff ff ff leaq -8(%rax), %rax -// DISASM-NEXT: 11015: 4d 8d bf f8 ff ff ff leaq -8(%r15), %r15 -// DISASM-NEXT: 1101c: 48 81 c4 f8 ff ff ff addq $-8, %rsp -// DISASM-NEXT: 11023: 49 81 c4 f8 ff ff ff addq $-8, %r12 -// DISASM-NEXT: 1102a: 48 c7 c0 fc ff ff ff movq $-4, %rax -// DISASM-NEXT: 11031: 49 c7 c7 fc ff ff ff movq $-4, %r15 -// DISASM-NEXT: 11038: 48 8d 80 fc ff ff ff leaq -4(%rax), %rax -// DISASM-NEXT: 1103f: 4d 8d bf fc ff ff ff leaq -4(%r15), %r15 -// DISASM-NEXT: 11046: 48 81 c4 fc ff ff ff addq $-4, %rsp -// DISASM-NEXT: 1104d: 49 81 c4 fc ff ff ff addq $-4, %r12 +// DISASM-NEXT: 201000: 48 c7 c0 f8 ff ff ff movq $-8, %rax +// DISASM-NEXT: 201007: 49 c7 c7 f8 ff ff ff movq $-8, %r15 +// DISASM-NEXT: 20100e: 48 8d 80 f8 ff ff ff leaq -8(%rax), %rax +// DISASM-NEXT: 201015: 4d 8d bf f8 ff ff ff leaq -8(%r15), %r15 +// DISASM-NEXT: 20101c: 48 81 c4 f8 ff ff ff addq $-8, %rsp +// DISASM-NEXT: 201023: 49 81 c4 f8 ff ff ff addq $-8, %r12 +// DISASM-NEXT: 20102a: 48 c7 c0 fc ff ff ff movq $-4, %rax +// DISASM-NEXT: 201031: 49 c7 c7 fc ff ff ff movq $-4, %r15 +// DISASM-NEXT: 201038: 48 8d 80 fc ff ff ff leaq -4(%rax), %rax +// DISASM-NEXT: 20103f: 4d 8d bf fc ff ff ff leaq -4(%r15), %r15 +// DISASM-NEXT: 201046: 48 81 c4 fc ff ff ff addq $-4, %rsp +// DISASM-NEXT: 20104d: 49 81 c4 fc ff ff ff addq $-4, %r12 .section .tbss,"awT",@nobits diff --git a/test/ELF/tls-opt.s b/test/ELF/tls-opt.s index 52468f16b09de..6835e06f3402d 100644 --- a/test/ELF/tls-opt.s +++ b/test/ELF/tls-opt.s @@ -7,36 +7,36 @@ // NORELOC-NEXT: ] // DISASM: _start: -// DISASM-NEXT: 11000: 48 c7 c0 f8 ff ff ff movq $-8, %rax -// DISASM-NEXT: 11007: 49 c7 c7 f8 ff ff ff movq $-8, %r15 -// DISASM-NEXT: 1100e: 48 8d 80 f8 ff ff ff leaq -8(%rax), %rax -// DISASM-NEXT: 11015: 4d 8d bf f8 ff ff ff leaq -8(%r15), %r15 -// DISASM-NEXT: 1101c: 48 81 c4 f8 ff ff ff addq $-8, %rsp -// DISASM-NEXT: 11023: 49 81 c4 f8 ff ff ff addq $-8, %r12 -// DISASM-NEXT: 1102a: 48 c7 c0 fc ff ff ff movq $-4, %rax -// DISASM-NEXT: 11031: 49 c7 c7 fc ff ff ff movq $-4, %r15 -// DISASM-NEXT: 11038: 48 8d 80 fc ff ff ff leaq -4(%rax), %rax -// DISASM-NEXT: 1103f: 4d 8d bf fc ff ff ff leaq -4(%r15), %r15 -// DISASM-NEXT: 11046: 48 81 c4 fc ff ff ff addq $-4, %rsp -// DISASM-NEXT: 1104d: 49 81 c4 fc ff ff ff addq $-4, %r12 +// DISASM-NEXT: 201000: 48 c7 c0 f8 ff ff ff movq $-8, %rax +// DISASM-NEXT: 201007: 49 c7 c7 f8 ff ff ff movq $-8, %r15 +// DISASM-NEXT: 20100e: 48 8d 80 f8 ff ff ff leaq -8(%rax), %rax +// DISASM-NEXT: 201015: 4d 8d bf f8 ff ff ff leaq -8(%r15), %r15 +// DISASM-NEXT: 20101c: 48 81 c4 f8 ff ff ff addq $-8, %rsp +// DISASM-NEXT: 201023: 49 81 c4 f8 ff ff ff addq $-8, %r12 +// DISASM-NEXT: 20102a: 48 c7 c0 fc ff ff ff movq $-4, %rax +// DISASM-NEXT: 201031: 49 c7 c7 fc ff ff ff movq $-4, %r15 +// DISASM-NEXT: 201038: 48 8d 80 fc ff ff ff leaq -4(%rax), %rax +// DISASM-NEXT: 20103f: 4d 8d bf fc ff ff ff leaq -4(%r15), %r15 +// DISASM-NEXT: 201046: 48 81 c4 fc ff ff ff addq $-4, %rsp +// DISASM-NEXT: 20104d: 49 81 c4 fc ff ff ff addq $-4, %r12 // LD to LE: -// DISASM-NEXT: 11054: 66 66 66 64 48 8b 04 25 00 00 00 00 movq %fs:0, %rax -// DISASM-NEXT: 11060: 48 8d 88 f8 ff ff ff leaq -8(%rax), %rcx -// DISASM-NEXT: 11067: 66 66 66 64 48 8b 04 25 00 00 00 00 movq %fs:0, %rax -// DISASM-NEXT: 11073: 48 8d 88 fc ff ff ff leaq -4(%rax), %rcx +// DISASM-NEXT: 201054: 66 66 66 64 48 8b 04 25 00 00 00 00 movq %fs:0, %rax +// DISASM-NEXT: 201060: 48 8d 88 f8 ff ff ff leaq -8(%rax), %rcx +// DISASM-NEXT: 201067: 66 66 66 64 48 8b 04 25 00 00 00 00 movq %fs:0, %rax +// DISASM-NEXT: 201073: 48 8d 88 fc ff ff ff leaq -4(%rax), %rcx // GD to LE: -// DISASM-NEXT: 1107a: 64 48 8b 04 25 00 00 00 00 movq %fs:0, %rax -// DISASM-NEXT: 11083: 48 8d 80 f8 ff ff ff leaq -8(%rax), %rax -// DISASM-NEXT: 1108a: 64 48 8b 04 25 00 00 00 00 movq %fs:0, %rax -// DISASM-NEXT: 11093: 48 8d 80 fc ff ff ff leaq -4(%rax), %rax +// DISASM-NEXT: 20107a: 64 48 8b 04 25 00 00 00 00 movq %fs:0, %rax +// DISASM-NEXT: 201083: 48 8d 80 f8 ff ff ff leaq -8(%rax), %rax +// DISASM-NEXT: 20108a: 64 48 8b 04 25 00 00 00 00 movq %fs:0, %rax +// DISASM-NEXT: 201093: 48 8d 80 fc ff ff ff leaq -4(%rax), %rax // LD to LE: // DISASM: _DTPOFF64_1: -// DISASM-NEXT: 1109a: f8 clc +// DISASM-NEXT: 20109a: f8 clc // DISASM: _DTPOFF64_2: -// DISASM-NEXT: 110a3: fc cld +// DISASM-NEXT: 2010a3: fc cld .type tls0,@object .section .tbss,"awT",@nobits @@ -88,7 +88,7 @@ _start: .word 0x6666 rex64 call __tls_get_addr@plt - + // LD to LE _DTPOFF64_1: .quad tls0@DTPOFF diff --git a/test/ELF/tls-relocatable.s b/test/ELF/tls-relocatable.s new file mode 100644 index 0000000000000..2743861c1de0a --- /dev/null +++ b/test/ELF/tls-relocatable.s @@ -0,0 +1,21 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %s -o %t.o +// RUN: ld.lld %t.o -r -o %tr.o +// RUN: ld.lld %tr.o -shared -o %t1 +// RUN: llvm-readobj -t %t1 | FileCheck %s + +// CHECK: Symbol { +// CHECK: Name: tls0 +// CHECK-NEXT: Value: 0x0 +// CHECK-NEXT: Size: 0 +// CHECK-NEXT: Binding: Global +// CHECK-NEXT: Type: TLS +// CHECK-NEXT: Other: 0 +// CHECK-NEXT: Section: .tdata +// CHECK-NEXT: } + +.type tls0,@object +.section .tdata,"awT",@progbits +.globl tls0 +tls0: + .long 0 diff --git a/test/ELF/tls-static.s b/test/ELF/tls-static.s index 4c515abb1252a..b098b68b03f17 100644 --- a/test/ELF/tls-static.s +++ b/test/ELF/tls-static.s @@ -10,4 +10,4 @@ _start: call __tls_get_addr -// CHECK: undefined symbol: __tls_get_addr +// CHECK: error: {{.*}}:(.text+0x1): undefined symbol '__tls_get_addr' diff --git a/test/ELF/tls-weak-undef.s b/test/ELF/tls-weak-undef.s new file mode 100644 index 0000000000000..7aa6ef13a2af4 --- /dev/null +++ b/test/ELF/tls-weak-undef.s @@ -0,0 +1,16 @@ +// 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-mc -filetype=obj -triple=x86_64-pc-linux \ +// RUN: %p/Inputs/tls-in-archive.s -o %t1.o +// RUN: llvm-ar cru %t.a %t1.o +// RUN: ld.lld %t.o %t.a -o %t + +// Check that lld doesn't crash because we don't reference +// the TLS phdr when it's not created. + .globl _start +_start: + movq foo@gottpoff(%rip), %rax + .section .tbss,"awT",@nobits + .weak foo diff --git a/test/ELF/tls.s b/test/ELF/tls.s index 525890b087e25..a5b95597518bd 100644 --- a/test/ELF/tls.s +++ b/test/ELF/tls.s @@ -90,9 +90,9 @@ d: // CHECK-NEXT: SHF_WRITE // CHECK-NEXT: ] -// 0x1200C = TBSS_ADDR + 4 +// 0x20200C = TBSS_ADDR + 4 -// CHECK-NEXT: Address: 0x1200C +// CHECK-NEXT: Address: 0x20200C // CHECK-NEXT: Offset: // CHECK-NEXT: Size: 4 // CHECK-NEXT: Link: @@ -164,7 +164,7 @@ d: // DIS: Disassembly of section .text: // DIS-NEXT: _start: -// DIS-NEXT: 11000: {{.+}} movl %fs:-8, %eax -// DIS-NEXT: 11008: {{.+}} movl %fs:-16, %eax -// DIS-NEXT: 11010: {{.+}} movl %fs:-4, %eax -// DIS-NEXT: 11018: {{.+}} movl %fs:-12, %eax +// DIS-NEXT: 201000: {{.+}} movl %fs:-8, %eax +// DIS-NEXT: 201008: {{.+}} movl %fs:-16, %eax +// DIS-NEXT: 201010: {{.+}} movl %fs:-4, %eax +// DIS-NEXT: 201018: {{.+}} movl %fs:-12, %eax diff --git a/test/ELF/ttext-tdata-tbss.s b/test/ELF/ttext-tdata-tbss.s new file mode 100644 index 0000000000000..c31c56e75692b --- /dev/null +++ b/test/ELF/ttext-tdata-tbss.s @@ -0,0 +1,63 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +## Show what regular output gives to us. +# RUN: ld.lld %t.o -o %t1 +# RUN: llvm-readobj --elf-output-style=GNU -l -s %t1 | FileCheck %s +# CHECK: .rodata PROGBITS 0000000000200158 000158 000008 +# CHECK-NEXT: .text PROGBITS 0000000000201000 001000 000001 +# CHECK-NEXT: .aw PROGBITS 0000000000202000 002000 000008 +# CHECK-NEXT: .data PROGBITS 0000000000202008 002008 000008 +# CHECK-NEXT: .bss NOBITS 0000000000202010 002010 000008 +# CHECK: PHDR +# CHECK-NEXT: LOAD 0x000000 0x0000000000200000 + +## With .text at 0 there is no space to allocate the headers. +# RUN: ld.lld -Ttext 0x0 -Tdata 0x4000 -Tbss 0x8000 %t.o -o %t2 +# RUN: llvm-readobj --elf-output-style=GNU -l -s %t2 | FileCheck %s --check-prefix=USER1 +# USER1: .text PROGBITS 0000000000000000 001000 000001 +# USER1-NEXT: .data PROGBITS 0000000000004000 002000 000008 +# USER1-NEXT: .bss NOBITS 0000000000008000 002008 000008 +# USER1-NEXT: .rodata PROGBITS 0000000000009000 003000 000008 +# USER1-NEXT: .aw PROGBITS 000000000000a000 004000 000008 +# USER1: PHDR +# USER1-NEXT: LOAD 0x001000 0x0000000000000000 + +## With .text at 0x1000 there is space to allocate the headers. +# RUN: ld.lld -Ttext 0x1000 -Tdata 0x4000 -Tbss 0x8000 %t.o -o %t3 +# RUN: llvm-readobj --elf-output-style=GNU -l -s %t3 | FileCheck %s --check-prefix=USER2 +# USER2: .text PROGBITS 0000000000001000 001000 000001 +# USER2-NEXT: .data PROGBITS 0000000000004000 002000 000008 +# USER2-NEXT: .bss NOBITS 0000000000008000 002008 000008 +# USER2-NEXT: .rodata PROGBITS 0000000000009000 003000 000008 +# USER2-NEXT: .aw PROGBITS 000000000000a000 004000 000008 +# USER2: PHDR +# USER2-NEXT: LOAD 0x000000 0x0000000000000000 + +## With .text well above 200000 we don't need to change the image base +# RUN: ld.lld -Ttext 0x201000 %t.o -o %t4 +# RUN: llvm-readobj --elf-output-style=GNU -l -s %t4 | FileCheck %s --check-prefix=USER3 +# USER3: .text PROGBITS 0000000000201000 001000 000001 +# USER3-NEX: .rodata PROGBITS 0000000000202000 002000 000008 +# USER3-NEX: .aw PROGBITS 0000000000203000 003000 000008 +# USER3-NEX: .data PROGBITS 0000000000203008 003008 000008 +# USER3-NEX: .bss NOBITS 0000000000203010 003010 000008 +# USER3: PHDR +# USER3-NEXT: LOAD 0x000000 0x0000000000200000 + +.text +.globl _start +_start: + nop + +.section .rodata,"a" + .quad 0 + +.section .aw,"aw" + .quad 0 + +.section .data,"aw" + .quad 0 + +.section .bss,"",@nobits + .quad 0 diff --git a/test/ELF/undef-shared.s b/test/ELF/undef-shared.s index ed91035714434..3f01ec25f511f 100644 --- a/test/ELF/undef-shared.s +++ b/test/ELF/undef-shared.s @@ -1,14 +1,19 @@ # 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: undefined symbol: hidden in {{.*}} +# CHECK: error: {{.*}}:(.data+0x0): undefined symbol 'hidden' .global hidden .hidden hidden -# CHECK: undefined symbol: internal in {{.*}} +# CHECK: error: {{.*}}:(.data+0x8): undefined symbol 'internal' .global internal .internal internal -# CHECK: undefined symbol: protected in {{.*}} +# CHECK: error: {{.*}}:(.data+0x10): undefined symbol 'protected' .global protected .protected protected + +.section .data, "a" + .quad hidden + .quad internal + .quad protected diff --git a/test/ELF/undef-start.s b/test/ELF/undef-start.s index bf1d89853f592..590d0a80096b8 100644 --- a/test/ELF/undef-start.s +++ b/test/ELF/undef-start.s @@ -1,4 +1,3 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s -# CHECK: undefined symbol: _start +# RUN: ld.lld %t -o %t2 2>&1 # REQUIRES: x86 diff --git a/test/ELF/undef-version-script.s b/test/ELF/undef-version-script.s index 9f0a5a49e72eb..5297283287478 100644 --- a/test/ELF/undef-version-script.s +++ b/test/ELF/undef-version-script.s @@ -8,7 +8,7 @@ # CHECK: DynamicSymbols [ # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: @ (0) +# CHECK-NEXT: Name: @ # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Local (0x0) @@ -17,7 +17,7 @@ # CHECK-NEXT: Section: Undefined (0x0) # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: bar@ (1) +# CHECK-NEXT: Name: bar@ # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Weak (0x2) @@ -26,7 +26,7 @@ # CHECK-NEXT: Section: Undefined (0x0) # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: foo@ (5) +# CHECK-NEXT: Name: foo@ # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Global (0x1) diff --git a/test/ELF/undef-with-plt-addr.s b/test/ELF/undef-with-plt-addr.s index 792d85f3da61b..e30cd90d380f1 100644 --- a/test/ELF/undef-with-plt-addr.s +++ b/test/ELF/undef-with-plt-addr.s @@ -19,13 +19,13 @@ movabsq $set_data, %rax // CHECK-NEXT: SHF_ALLOC // CHECK-NEXT: SHF_EXECINSTR // CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x11010 +// CHECK-NEXT: Address: 0x201010 // CHECK: Section ({{.*}}) .rela.dyn { -// CHECK-NEXT: 0x13000 R_X86_64_64 foo 0x0 +// CHECK-NEXT: 0x203000 R_X86_64_64 foo 0x0 // CHECK-NEXT: } // CHECK-NEXT: Section ({{.*}}) .rela.plt { -// CHECK-NEXT: 0x13020 R_X86_64_JUMP_SLOT set_data 0x0 +// CHECK-NEXT: 0x203020 R_X86_64_JUMP_SLOT set_data 0x0 // CHECK-NEXT: } // CHECK: Name: foo @@ -37,7 +37,7 @@ movabsq $set_data, %rax // CHECK-NEXT: Section: Undefined // CHECK: Name: set_data -// CHECK-NEXT: Value: 0x11020 +// CHECK-NEXT: Value: 0x201020 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Global // CHECK-NEXT: Type: Function diff --git a/test/ELF/undef.s b/test/ELF/undef.s index c8211c73866fa..5fcd75f948b02 100644 --- a/test/ELF/undef.s +++ b/test/ELF/undef.s @@ -1,15 +1,27 @@ # 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.s -o %t2.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/undef-debug.s -o %t3.o # RUN: llvm-ar rc %t2.a %t2.o -# RUN: not ld.lld %t.o %t2.a -o %t.exe 2>&1 | FileCheck %s -# RUN: not ld.lld -pie %t.o %t2.a -o %t.exe 2>&1 | FileCheck %s -# CHECK: undefined symbol: bar in {{.*}} -# CHECK: undefined symbol: foo in {{.*}} -# CHECK: undefined symbol: zed2 in {{.*}}2.a({{.*}}.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 +# CHECK: error: undef.s:(.text+0x1): undefined symbol 'foo' +# CHECK: error: undef.s:(.text+0x6): undefined symbol 'bar' +# CHECK: error: undef.s:(.text+0x10): undefined symbol 'foo(int)' +# CHECK: error: {{.*}}2.a({{.*}}.o):(.text+0x0): undefined symbol 'zed2' +# CHECK: error: dir/undef-debug.s:3: undefined symbol 'zed3' +# CHECK: error: dir/undef-debug.s:7: undefined symbol 'zed4' +# CHECK: error: dir/undef-debug.s:11: undefined symbol 'zed5' + +# 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: undef.s:(.text+0x10): undefined symbol '_Z3fooi' + +.file "undef.s" .globl _start _start: call foo call bar call zed1 + call _Z3fooi diff --git a/test/ELF/undefined-opt.s b/test/ELF/undefined-opt.s index ddd34f49b748b..d8b793d7bab45 100644 --- a/test/ELF/undefined-opt.s +++ b/test/ELF/undefined-opt.s @@ -31,6 +31,8 @@ # Use the option couple of times, both short and long forms # RUN: ld.lld -o %t3 %t.o %tar.a -u bar --undefined=abs # RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TWO-UNDEFINED %s +# RUN: ld.lld -o %t3 %t.o %tar.a -u bar --undefined abs +# RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TWO-UNDEFINED %s # TWO-UNDEFINED: Symbols [ # TWO-UNDEFINED: Name: abs # TWO-UNDEFINED: Name: big diff --git a/test/ELF/unresolved-symbols.s b/test/ELF/unresolved-symbols.s index 2fa59cb0ffd75..3c33b92457863 100644 --- a/test/ELF/unresolved-symbols.s +++ b/test/ELF/unresolved-symbols.s @@ -6,7 +6,7 @@ ## Check that %t2.o contains undefined symbol undef. # RUN: not ld.lld %t1.o %t2.o -o %t 2>&1 | \ # RUN: FileCheck -check-prefix=UNDCHECK %s -# UNDCHECK: undefined symbol: undef in {{.*}}2.o +# UNDCHECK: error: {{.*}}2.o:(.text+0x1): undefined symbol 'undef' ## Error out if unknown option value was set. # RUN: not ld.lld %t1.o %t2.o -o %t --unresolved-symbols=xxx 2>&1 | \ @@ -19,7 +19,7 @@ # 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: FileCheck -check-prefix=ERRUND %s -# ERRUND: undefined symbol: undef +# ERRUND: error: {{.*}}:(.text+0x1): undefined symbol 'undef' ## Also ignore all should not produce error for symbols from DSOs. # RUN: ld.lld %t1.o %t.so -o %t1_3 --unresolved-symbols=ignore-all # RUN: llvm-readobj %t1_3 > /dev/null 2>&1 diff --git a/test/ELF/verdef-defaultver.s b/test/ELF/verdef-defaultver.s index 4d847344f996a..c37c90a66d92c 100644 --- a/test/ELF/verdef-defaultver.s +++ b/test/ELF/verdef-defaultver.s @@ -1,12 +1,8 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/verdef-defaultver.s -o %t1 -# RUN: echo "LIBSAMPLE_1.0{ \ -# RUN: global: a; \ -# RUN: local: *; }; \ -# RUN: LIBSAMPLE_2.0{ \ -# RUN: global: b; c; \ -# RUN: }LIBSAMPLE_1.0;" > %t.script +# RUN: echo "V1 { global: a; local: *; };" > %t.script +# RUN: echo "V2 { global: b; c; } V1;" >> %t.script # RUN: ld.lld -shared -soname shared %t1 --version-script %t.script -o %t.so # RUN: llvm-readobj -V -dyn-symbols %t.so | FileCheck --check-prefix=DSO %s @@ -21,7 +17,7 @@ # DSO-NEXT: Section: Undefined # DSO-NEXT: } # DSO-NEXT: Symbol { -# DSO-NEXT: Name: a@@LIBSAMPLE_1.0 +# DSO-NEXT: Name: a@@V1 # DSO-NEXT: Value: 0x1000 # DSO-NEXT: Size: 0 # DSO-NEXT: Binding: Global @@ -30,7 +26,7 @@ # DSO-NEXT: Section: .text # DSO-NEXT: } # DSO-NEXT: Symbol { -# DSO-NEXT: Name: b@@LIBSAMPLE_2.0 +# DSO-NEXT: Name: b@@V2 # DSO-NEXT: Value: 0x1002 # DSO-NEXT: Size: 0 # DSO-NEXT: Binding: Global @@ -39,7 +35,7 @@ # DSO-NEXT: Section: .text # DSO-NEXT: } # DSO-NEXT: Symbol { -# DSO-NEXT: Name: b@LIBSAMPLE_1.0 +# DSO-NEXT: Name: b@V1 # DSO-NEXT: Value: 0x1001 # DSO-NEXT: Size: 0 # DSO-NEXT: Binding: Global @@ -48,7 +44,7 @@ # DSO-NEXT: Section: .text # DSO-NEXT: } # DSO-NEXT: Symbol { -# DSO-NEXT: Name: c@@LIBSAMPLE_2.0 +# DSO-NEXT: Name: c@@V2 # DSO-NEXT: Value: 0x1003 # DSO-NEXT: Size: 0 # DSO-NEXT: Binding: Global @@ -69,19 +65,19 @@ # DSO-NEXT: } # DSO-NEXT: Symbol { # DSO-NEXT: Version: 2 -# DSO-NEXT: Name: a@@LIBSAMPLE_1.0 +# DSO-NEXT: Name: a@@V1 # DSO-NEXT: } # DSO-NEXT: Symbol { # DSO-NEXT: Version: 3 -# DSO-NEXT: Name: b@@LIBSAMPLE_2.0 +# DSO-NEXT: Name: b@@V2 # DSO-NEXT: } # DSO-NEXT: Symbol { # DSO-NEXT: Version: 2 -# DSO-NEXT: Name: b@LIBSAMPLE_1.0 +# DSO-NEXT: Name: b@V1 # DSO-NEXT: } # DSO-NEXT: Symbol { # DSO-NEXT: Version: 3 -# DSO-NEXT: Name: c@@LIBSAMPLE_2.0 +# DSO-NEXT: Name: c@@V2 # DSO-NEXT: } # DSO-NEXT: ] # DSO-NEXT: } @@ -97,15 +93,15 @@ # DSO-NEXT: Version: 1 # DSO-NEXT: Flags: 0x0 # DSO-NEXT: Index: 2 -# DSO-NEXT: Hash: 98457184 -# DSO-NEXT: Name: LIBSAMPLE_1.0 +# DSO-NEXT: Hash: 1425 +# DSO-NEXT: Name: V1 # DSO-NEXT: } # DSO-NEXT: Definition { # DSO-NEXT: Version: 1 # DSO-NEXT: Flags: 0x0 # DSO-NEXT: Index: 3 -# DSO-NEXT: Hash: 98456416 -# DSO-NEXT: Name: LIBSAMPLE_2.0 +# DSO-NEXT: Hash: 1426 +# DSO-NEXT: Name: V2 # DSO-NEXT: } # DSO-NEXT: } @@ -125,8 +121,8 @@ # EXE-NEXT: Section: Undefined # EXE-NEXT: } # EXE-NEXT: Symbol { -# EXE-NEXT: Name: a@LIBSAMPLE_1.0 -# EXE-NEXT: Value: 0x11020 +# EXE-NEXT: Name: a@V1 +# EXE-NEXT: Value: 0x201020 # EXE-NEXT: Size: 0 # EXE-NEXT: Binding: Global # EXE-NEXT: Type: Function @@ -134,8 +130,8 @@ # EXE-NEXT: Section: Undefined # EXE-NEXT: } # EXE-NEXT: Symbol { -# EXE-NEXT: Name: b@LIBSAMPLE_2.0 -# EXE-NEXT: Value: 0x11030 +# EXE-NEXT: Name: b@V2 +# EXE-NEXT: Value: 0x201030 # EXE-NEXT: Size: 0 # EXE-NEXT: Binding: Global # EXE-NEXT: Type: Function @@ -143,8 +139,8 @@ # EXE-NEXT: Section: Undefined # EXE-NEXT: } # EXE-NEXT: Symbol { -# EXE-NEXT: Name: c@LIBSAMPLE_2.0 -# EXE-NEXT: Value: 0x11040 +# EXE-NEXT: Name: c@V2 +# EXE-NEXT: Value: 0x201040 # EXE-NEXT: Size: 0 # EXE-NEXT: Binding: Global # EXE-NEXT: Type: Function @@ -154,7 +150,7 @@ # EXE-NEXT: ] # EXE-NEXT: Version symbols { # EXE-NEXT: Section Name: .gnu.version -# EXE-NEXT: Address: 0x10228 +# EXE-NEXT: Address: 0x200228 # EXE-NEXT: Offset: 0x228 # EXE-NEXT: Link: 1 # EXE-NEXT: Symbols [ @@ -164,15 +160,15 @@ # EXE-NEXT: } # EXE-NEXT: Symbol { # EXE-NEXT: Version: 2 -# EXE-NEXT: Name: a@LIBSAMPLE_1.0 +# EXE-NEXT: Name: a@V1 # EXE-NEXT: } # EXE-NEXT: Symbol { # EXE-NEXT: Version: 3 -# EXE-NEXT: Name: b@LIBSAMPLE_2.0 +# EXE-NEXT: Name: b@V2 # EXE-NEXT: } # EXE-NEXT: Symbol { # EXE-NEXT: Version: 3 -# EXE-NEXT: Name: c@LIBSAMPLE_2.0 +# EXE-NEXT: Name: c@V2 # EXE-NEXT: } # EXE-NEXT: ] # EXE-NEXT: } @@ -184,16 +180,16 @@ # EXE-NEXT: Count: 2 # EXE-NEXT: FileName: shared # EXE-NEXT: Entry { -# EXE-NEXT: Hash: 98457184 +# EXE-NEXT: Hash: 1425 # EXE-NEXT: Flags: 0x0 # EXE-NEXT: Index: 2 -# EXE-NEXT: Name: LIBSAMPLE_1.0 +# EXE-NEXT: Name: V1 # EXE-NEXT: } # EXE-NEXT: Entry { -# EXE-NEXT: Hash: 98456416 +# EXE-NEXT: Hash: 1426 # EXE-NEXT: Flags: 0x0 # EXE-NEXT: Index: 3 -# EXE-NEXT: Name: LIBSAMPLE_2.0 +# EXE-NEXT: Name: V2 # EXE-NEXT: } # EXE-NEXT: } # EXE-NEXT: } diff --git a/test/ELF/verdef-dependency.s b/test/ELF/verdef-dependency.s index 92627ddc5c0ff..3f126856b10fd 100644 --- a/test/ELF/verdef-dependency.s +++ b/test/ELF/verdef-dependency.s @@ -1,14 +1,8 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "LIBSAMPLE_1.0{ \ -# RUN: global: a; \ -# RUN: local: *; }; \ -# RUN: LIBSAMPLE_2.0{ \ -# RUN: global: b; \ -# RUN: local: *; }LIBSAMPLE_1.0; \ -# RUN: LIBSAMPLE_3.0{ \ -# RUN: global: c; \ -# RUN: }LIBSAMPLE_2.0;" > %t.script +# RUN: echo "LIBSAMPLE_1.0 { global: a; local: *; };" > %t.script +# RUN: echo "LIBSAMPLE_2.0 { global: b; local: *; } LIBSAMPLE_1.0;" >> %t.script +# RUN: echo "LIBSAMPLE_3.0 { global: c; } LIBSAMPLE_2.0;" >> %t.script # RUN: ld.lld --version-script %t.script -shared -soname shared %t.o -o %t.so # RUN: llvm-readobj -V -dyn-symbols %t.so | FileCheck --check-prefix=DSO %s diff --git a/test/ELF/verdef.s b/test/ELF/verdef.s index 9463de0c0a0cf..7fd60a95d1df5 100644 --- a/test/ELF/verdef.s +++ b/test/ELF/verdef.s @@ -1,14 +1,8 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "LIBSAMPLE_1.0{ \ -# RUN: global: a; \ -# RUN: local: *; }; \ -# RUN: LIBSAMPLE_2.0{ \ -# RUN: global: b; \ -# RUN: local: *; }; \ -# RUN: LIBSAMPLE_3.0{ \ -# RUN: global: c; \ -# RUN: local: *; };" > %t.script +# RUN: echo "LIBSAMPLE_1.0 { global: a; local: *; };" > %t.script +# RUN: echo "LIBSAMPLE_2.0 { global: b; local: *; };" >> %t.script +# RUN: echo "LIBSAMPLE_3.0 { global: c; local: *; };" >> %t.script # RUN: ld.lld --version-script %t.script -shared -soname shared %t.o -o %t.so # RUN: llvm-readobj -V -dyn-symbols %t.so | FileCheck --check-prefix=DSO %s @@ -76,7 +70,7 @@ # MAIN: Version symbols { # MAIN-NEXT: Section Name: .gnu.version -# MAIN-NEXT: Address: 0x10228 +# MAIN-NEXT: Address: 0x200228 # MAIN-NEXT: Offset: 0x228 # MAIN-NEXT: Link: 1 # MAIN-NEXT: Symbols [ @@ -101,6 +95,14 @@ # MAIN-NEXT: SHT_GNU_verdef { # MAIN-NEXT: } +# RUN: echo "VERSION {" > %t.script +# RUN: echo "LIBSAMPLE_1.0 { global: a; local: *; };" >> %t.script +# RUN: echo "LIBSAMPLE_2.0 { global: b; local: *; };" >> %t.script +# RUN: echo "LIBSAMPLE_3.0 { global: c; local: *; };" >> %t.script +# RUN: echo "}" >> %t.script +# RUN: ld.lld --script %t.script -shared -soname shared %t.o -o %t2.so +# RUN: llvm-readobj -V -dyn-symbols %t2.so | FileCheck --check-prefix=DSO %s + .globl a .type a,@function a: diff --git a/test/ELF/verneed-local.s b/test/ELF/verneed-local.s index a50f670ed7bd4..94336fddad48d 100644 --- a/test/ELF/verneed-local.s +++ b/test/ELF/verneed-local.s @@ -2,7 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: not ld.lld %t.o %S/Inputs/verneed1.so -o %t 2>&1 | FileCheck %s -# CHECK: undefined symbol: f3 in +# CHECK: error: {{.*}}:(.text+0x1): undefined symbol 'f3' .globl _start _start: call f3 diff --git a/test/ELF/verneed.s b/test/ELF/verneed.s index e9d7c53ba3342..d0d0067250aa1 100644 --- a/test/ELF/verneed.s +++ b/test/ELF/verneed.s @@ -5,12 +5,12 @@ # CHECK: Section { # CHECK: Index: 1 -# CHECK-NEXT: Name: .dynsym (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: 0x101C8 +# CHECK-NEXT: Address: 0x2001C8 # CHECK-NEXT: Offset: 0x1C8 # CHECK-NEXT: Size: 96 # CHECK-NEXT: Link: 5 @@ -19,12 +19,12 @@ # CHECK-NEXT: EntrySize: 24 # CHECK: Section { # CHECK-NEXT: Index: 2 -# CHECK-NEXT: Name: .gnu.version (9) +# 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: 0x10228 +# CHECK-NEXT: Address: 0x200228 # CHECK-NEXT: Offset: 0x228 # CHECK-NEXT: Size: 8 # CHECK-NEXT: Link: 1 @@ -33,12 +33,12 @@ # CHECK-NEXT: EntrySize: 2 # CHECK: Section { # CHECK-NEXT: Index: 3 -# CHECK-NEXT: Name: .gnu.version_r (22) +# 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: 0x10230 +# CHECK-NEXT: Address: 0x200230 # CHECK-NEXT: Offset: 0x230 # CHECK-NEXT: Size: 80 # CHECK-NEXT: Link: 5 @@ -52,7 +52,7 @@ # CHECK-NEXT: Flags [ (0x2) # CHECK-NEXT: SHF_ALLOC (0x2) # CHECK-NEXT: ] -# CHECK-NEXT: Address: 0x102A8 +# CHECK-NEXT: Address: 0x2002A8 # CHECK-NEXT: Offset: 0x2A8 # CHECK-NEXT: Size: 47 # CHECK-NEXT: Link: 0 @@ -60,15 +60,15 @@ # CHECK-NEXT: AddressAlignment: 1 # CHECK-NEXT: EntrySize: 0 # CHECK-NEXT: SectionData ( -# CHECK-NEXT: 0000: 00663100 7665726E 65656431 2E736F2E |.f1.verneed1.so.| -# CHECK-NEXT: 0010: 30007633 00663200 76320067 31007665 |0.v3.f2.v2.g1.ve| -# CHECK-NEXT: 0020: 726E6565 64322E73 6F2E3000 763100 |rneed2.so.0.v1.| +# 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 { -# CHECK-NEXT: Name: @ (0) +# CHECK-NEXT: Name: @ # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Local (0x0) @@ -77,7 +77,7 @@ # CHECK-NEXT: Section: Undefined (0x0) # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: f1@v3 (1) +# CHECK-NEXT: Name: f1@v3 # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Global (0x1) @@ -86,7 +86,7 @@ # CHECK-NEXT: Section: Undefined (0x0) # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: f2@v2 (21) +# CHECK-NEXT: Name: f2@v2 # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Global (0x1) @@ -95,7 +95,7 @@ # CHECK-NEXT: Section: Undefined (0x0) # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: g1@v1 (27) +# CHECK-NEXT: Name: g1@v1 # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Global (0x1) @@ -105,13 +105,13 @@ # CHECK-NEXT: } # CHECK-NEXT: ] -# CHECK: 0x000000006FFFFFF0 VERSYM 0x10228 -# CHECK-NEXT: 0x000000006FFFFFFE VERNEED 0x10230 +# CHECK: 0x000000006FFFFFF0 VERSYM 0x200228 +# CHECK-NEXT: 0x000000006FFFFFFE VERNEED 0x200230 # CHECK-NEXT: 0x000000006FFFFFFF VERNEEDNUM 2 # CHECK: Version symbols { # CHECK-NEXT: Section Name: .gnu.version -# CHECK-NEXT: Address: 0x10228 +# CHECK-NEXT: Address: 0x200228 # CHECK-NEXT: Offset: 0x228 # CHECK-NEXT: Link: 1 # CHECK-NEXT: Symbols [ diff --git a/test/ELF/version-script-complex-wildcards.s b/test/ELF/version-script-complex-wildcards.s new file mode 100644 index 0000000000000..61e1069e2eac2 --- /dev/null +++ b/test/ELF/version-script-complex-wildcards.s @@ -0,0 +1,62 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "FOO { global: extern \"C++\" { ab[c]*; }; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -V %t.so | FileCheck %s --check-prefix=ABC +# ABC: Name: _Z3abbi@ +# ABC: Name: _Z3abci@@FOO + +# RUN: echo "FOO { global: extern \"C++\" { ab[b]*; }; };" > %t1.script +# RUN: ld.lld --version-script %t1.script -shared %t.o -o %t1.so +# RUN: llvm-readobj -V %t1.so | FileCheck %s --check-prefix=ABB +# ABB: Name: _Z3abbi@@FOO +# ABB: Name: _Z3abci@ + +# RUN: echo "FOO { global: extern \"C++\" { ab[a-b]*; }; };" > %t2.script +# RUN: ld.lld --version-script %t2.script -shared %t.o -o %t2.so +# RUN: llvm-readobj -V %t2.so | FileCheck %s --check-prefix=ABB + +# RUN: echo "FOO { global: extern \"C++\" { ab[a-c]*; }; };" > %t3.script +# RUN: ld.lld --version-script %t3.script -shared %t.o -o %t3.so +# RUN: llvm-readobj -V %t3.so | FileCheck %s --check-prefix=ABBABC +# ABBABC: Name: _Z3abbi@@FOO +# ABBABC: Name: _Z3abci@@FOO + +# RUN: echo "FOO { global: extern \"C++\" { ab[a-bc-d]*; }; };" > %t4.script +# RUN: ld.lld --version-script %t4.script -shared %t.o -o %t4.so +# RUN: llvm-readobj -V %t4.so | FileCheck %s --check-prefix=ABBABC + +# RUN: echo "FOO { global: extern \"C++\" { ab[a-bd-e]*; }; };" > %t5.script +# RUN: ld.lld --version-script %t5.script -shared %t.o -o %t5.so +# RUN: llvm-readobj -V %t5.so | FileCheck %s --check-prefix=ABB + +# RUN: echo "FOO { global: extern \"C++\" { ab[^a-c]*; }; };" > %t6.script +# RUN: ld.lld --version-script %t6.script -shared %t.o -o %t6.so +# RUN: llvm-readobj -V %t6.so | FileCheck %s --check-prefix=NO +# NO: Name: _Z3abbi@ +# NO: Name: _Z3abci@ + +# RUN: echo "FOO { global: extern \"C++\" { ab[^c-z]*; }; };" > %t7.script +# RUN: ld.lld --version-script %t7.script -shared %t.o -o %t7.so +# RUN: llvm-readobj -V %t7.so | FileCheck %s --check-prefix=ABB + +# RUN: echo "FOO { global: extern \"C++\" { a[x-za-b][a-c]*; }; };" > %t8.script +# RUN: ld.lld --version-script %t8.script -shared %t.o -o %t8.so +# 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: | FileCheck %s --check-prefix=ERROR +# ERROR: invalid glob pattern: a[ + +.text +.globl _Z3abci +.type _Z3abci,@function +_Z3abci: +retq + +.globl _Z3abbi +.type _Z3abbi,@function +_Z3abbi: +retq diff --git a/test/ELF/version-script-err.s b/test/ELF/version-script-err.s index 15b69e98505b4..ea3f664ea6ce5 100644 --- a/test/ELF/version-script-err.s +++ b/test/ELF/version-script-err.s @@ -7,4 +7,5 @@ // RUN: echo "\"" > %terr1.script // RUN: not ld.lld --version-script %terr1.script -shared %t.o -o %t.so 2>&1 | \ // RUN: FileCheck -check-prefix=ERR1 %s -// ERR1: unclosed quote +// ERR1: {{.*}}:1: unclosed quote +// ERR1-NEXT: {{.*}}: unexpected EOF diff --git a/test/ELF/version-script-extern-exact.s b/test/ELF/version-script-extern-exact.s new file mode 100644 index 0000000000000..1ac2f6395ab6c --- /dev/null +++ b/test/ELF/version-script-extern-exact.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++\" { \"aaa*\"; }; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -V -dyn-symbols %t.so | FileCheck %s + +# CHECK: Symbol { +# CHECK: Name: _Z3aaaPf@ +# CHECK: Symbol { +# CHECK: Name: _Z3aaaPi@ + +.text +.globl _Z3aaaPi +.type _Z3aaaPi,@function +_Z3aaaPi: +retq + +.globl _Z3aaaPf +.type _Z3aaaPf,@function +_Z3aaaPf: +retq diff --git a/test/ELF/version-script-extern-wildcards-anon.s b/test/ELF/version-script-extern-wildcards-anon.s new file mode 100644 index 0000000000000..790d985e2b0cc --- /dev/null +++ b/test/ELF/version-script-extern-wildcards-anon.s @@ -0,0 +1,62 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo '{ \ +# RUN: global: \ +# RUN: _Z3bari; \ +# RUN: extern "C++" { \ +# RUN: "foo(int)"; \ +# RUN: z*; \ +# RUN: }; \ +# RUN: local: *; \ +# RUN: }; ' > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck %s + +# CHECK: DynamicSymbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: _Z3bari +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: _Z3fooi +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: _Z3zedi +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: +# CHECK-NEXT: Other: +# CHECK-NEXT: Section: +# CHECK-NEXT: } +# CHECK-NEXT: ] + +.global _Z3fooi +_Z3fooi: +.global _Z3bari +_Z3bari: +.global _Z3zedi +_Z3zedi: +.global _Z3bazi +_Z3bazi: diff --git a/test/ELF/version-script-extern-wildcards.s b/test/ELF/version-script-extern-wildcards.s new file mode 100644 index 0000000000000..472fc1f7833e3 --- /dev/null +++ b/test/ELF/version-script-extern-wildcards.s @@ -0,0 +1,29 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "FOO { global: extern \"C++\" { foo*; }; };" > %t.script +# RUN: echo "BAR { global: extern \"C++\" { zed*; bar; }; };" >> %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -V -dyn-symbols %t.so | FileCheck %s + +# CHECK: Version symbols { +# CHECK: Symbols [ +# CHECK: Name: _Z3bari@ +# CHECK: Name: _Z3fooi@@FOO +# CHECK: Name: _Z3zedi@@BAR + +.text +.globl _Z3fooi +.type _Z3fooi,@function +_Z3fooi: +retq + +.globl _Z3bari +.type _Z3bari,@function +_Z3bari: +retq + +.globl _Z3zedi +.type _Z3zedi,@function +_Z3zedi: +retq diff --git a/test/ELF/version-script-extern.s b/test/ELF/version-script-extern.s index 439653487bc05..2b89839c369a6 100644 --- a/test/ELF/version-script-extern.s +++ b/test/ELF/version-script-extern.s @@ -1,19 +1,12 @@ -# REQUIRES: shell +# REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -# RUN: echo "LIBSAMPLE_1.0 { \ -# RUN: global: \ -# RUN: extern "C++" { \ -# RUN: \"foo(int)\"; \ -# RUN: \"zed(int)\"; \ -# RUN: }; \ -# RUN: }; \ -# RUN: LIBSAMPLE_2.0 { \ -# RUN: global: \ -# RUN: extern "C++" { \ -# RUN: \"bar(int)\"; \ -# RUN: }; \ -# RUN: }; " > %t.script +# RUN: echo "LIBSAMPLE_1.0 { global:" > %t.script +# RUN: echo ' extern "C++" { "foo(int)"; "zed(int)"; "abc::abc()"; };' >> %t.script +# RUN: echo "};" >> %t.script +# RUN: echo "LIBSAMPLE_2.0 { global:" >> %t.script +# RUN: echo ' extern "C" { _Z3bari; };' >> %t.script +# RUN: echo "};" >> %t.script # RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so # RUN: llvm-readobj -V -dyn-symbols %t.so | FileCheck --check-prefix=DSO %s @@ -54,11 +47,29 @@ # DSO-NEXT: Other: 0 # DSO-NEXT: Section: .text (0x6) # DSO-NEXT: } +# DSO-NEXT: Symbol { +# DSO-NEXT: Name: _ZN3abcC1Ev@@LIBSAMPLE_1.0 +# DSO-NEXT: Value: 0x1003 +# DSO-NEXT: Size: 0 +# DSO-NEXT: Binding: Global (0x1) +# DSO-NEXT: Type: Function (0x2) +# DSO-NEXT: Other: 0 +# DSO-NEXT: Section: .text (0x6) +# DSO-NEXT: } +# DSO-NEXT: Symbol { +# DSO-NEXT: Name: _ZN3abcC2Ev@@LIBSAMPLE_1.0 +# DSO-NEXT: Value: 0x1004 +# DSO-NEXT: Size: 0 +# DSO-NEXT: Binding: Global (0x1) +# DSO-NEXT: Type: Function (0x2) +# DSO-NEXT: Other: 0 +# DSO-NEXT: Section: .text (0x6) +# DSO-NEXT: } # DSO-NEXT: ] # DSO-NEXT: Version symbols { # DSO-NEXT: Section Name: .gnu.version -# DSO-NEXT: Address: 0x228 -# DSO-NEXT: Offset: 0x228 +# DSO-NEXT: Address: 0x258 +# DSO-NEXT: Offset: 0x258 # DSO-NEXT: Link: 1 # DSO-NEXT: Symbols [ # DSO-NEXT: Symbol { @@ -77,6 +88,14 @@ # DSO-NEXT: Version: 2 # DSO-NEXT: Name: _Z3zedi@@LIBSAMPLE_1.0 # DSO-NEXT: } +# DSO-NEXT: Symbol { +# DSO-NEXT: Version: 2 +# DSO-NEXT: Name: _ZN3abcC1Ev@@LIBSAMPLE_1.0 +# DSO-NEXT: } +# DSO-NEXT: Symbol { +# DSO-NEXT: Version: 2 +# DSO-NEXT: Name: _ZN3abcC2Ev@@LIBSAMPLE_1.0 +# DSO-NEXT: } # DSO-NEXT: ] # DSO-NEXT: } @@ -95,3 +114,13 @@ retq .type _Z3zedi,@function _Z3zedi: retq + +.globl _ZN3abcC1Ev +.type _ZN3abcC1Ev,@function +_ZN3abcC1Ev: +retq + +.globl _ZN3abcC2Ev +.type _ZN3abcC2Ev,@function +_ZN3abcC2Ev: +retq diff --git a/test/ELF/version-script-glob.s b/test/ELF/version-script-glob.s new file mode 100644 index 0000000000000..330c068ba91de --- /dev/null +++ b/test/ELF/version-script-glob.s @@ -0,0 +1,45 @@ +# REQUIRES: x86 + +# RUN: echo "{ global: foo*; bar*; local: *; };" > %t.script +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld -shared --version-script %t.script %t.o -o %t.so +# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck %s + + .globl foo1 +foo1: + + .globl bar1 +bar1: + + .globl zed1 +zed1: + +# CHECK: DynamicSymbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: bar1 +# CHECK-NEXT: Value: 0x1000 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: foo1 +# CHECK-NEXT: Value: 0x1000 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Global +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text +# CHECK-NEXT: } +# CHECK-NEXT: ] diff --git a/test/ELF/version-script-locals-extern.s b/test/ELF/version-script-locals-extern.s new file mode 100644 index 0000000000000..12e8771b8eff8 --- /dev/null +++ b/test/ELF/version-script-locals-extern.s @@ -0,0 +1,45 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "FOO { local: 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-prefix=ABB +# ABB: Symbols [ +# ABB-NEXT: Symbol { +# ABB-NEXT: Version: 0 +# ABB-NEXT: Name: @ +# ABB-NEXT: } +# ABB-NEXT: Symbol { +# ABB-NEXT: Version: 1 +# ABB-NEXT: Name: _Z3abci@ +# ABB-NEXT: } +# ABB-NEXT: ] + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "FOO { local: extern \"C++\" { abb*; }; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -V %t.so | FileCheck %s --check-prefix=ABB + +# RUN: echo "FOO { local: extern \"C++\" { abc*; }; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -V %t.so | FileCheck %s --check-prefix=ABC +# ABC: Symbols [ +# ABC-NEXT: Symbol { +# ABC-NEXT: Version: 0 +# ABC-NEXT: Name: @ +# ABC-NEXT: } +# ABC-NEXT: Symbol { +# ABC-NEXT: Version: 1 +# ABC-NEXT: Name: _Z3abbi@ +# ABC-NEXT: } +# ABC-NEXT: ] + +.globl _Z3abbi +.type _Z3abbi,@function +_Z3abbi: +retq + +.globl _Z3abci +.type _Z3abci,@function +_Z3abci: +retq diff --git a/test/ELF/version-script-locals.s b/test/ELF/version-script-locals.s new file mode 100644 index 0000000000000..80110c396ecc3 --- /dev/null +++ b/test/ELF/version-script-locals.s @@ -0,0 +1,45 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +# RUN: echo "VERSION_1.0 { local: foo1; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck --check-prefix=EXACT %s +# EXACT: DynamicSymbols [ +# EXACT: _start +# EXACT-NOT: foo1 +# EXACT: foo2 +# EXACT: foo3 + +# RUN: echo "VERSION_1.0 { local: foo*; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck --check-prefix=WC %s +# WC: DynamicSymbols [ +# WC: _start +# WC-NOT: foo1 +# WC-NOT: foo2 +# WC-NOT: foo3 + +# RUN: echo "VERSION_1.0 { global: *; local: foo*; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck --check-prefix=MIX %s +# MIX: DynamicSymbols [ +# MIX: _start@@VERSION_1.0 +# MIX-NOT: foo1 +# MIX-NOT: foo2 +# MIX-NOT: foo3 + +.globl foo1 +foo1: + ret + +.globl foo2 +foo2: + ret + +.globl foo3 +foo3: + ret + +.globl _start +_start: + ret diff --git a/test/ELF/version-script-missing.s b/test/ELF/version-script-missing.s new file mode 100644 index 0000000000000..ad4786e70cc54 --- /dev/null +++ b/test/ELF/version-script-missing.s @@ -0,0 +1,7 @@ +# REQUIRES: x86 + +# We used to crash if a symbol in a version script was not in the symbol table. + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: echo "{ foobar; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so diff --git a/test/ELF/version-script-no-warn.s b/test/ELF/version-script-no-warn.s new file mode 100644 index 0000000000000..6a897159d2d00 --- /dev/null +++ b/test/ELF/version-script-no-warn.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %t2.o +# RUN: ld.lld -shared %t2.o -soname shared -o %t2.so + +# RUN: echo "foo { global: bar; local: *; };" > %t.script +# RUN: ld.lld --fatal-warnings --shared --version-script %t.script %t.o %t2.so + +.global bar +bar: + nop diff --git a/test/ELF/version-script-noundef.s b/test/ELF/version-script-noundef.s index 4a251d6172da8..247752cac8443 100644 --- a/test/ELF/version-script-noundef.s +++ b/test/ELF/version-script-noundef.s @@ -1,19 +1,20 @@ # REQUIRES: x86 -# RUN: echo "VERSION_1.0{ \ -# RUN: global: bar; \ -# RUN: };" > %t.script +# RUN: echo "VERSION_1.0 { global: bar; };" > %t.script # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o # 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 +# ERR1: version script assignment of 'VERSION_1.0' to symbol 'bar' failed: symbol not defined -# RUN: echo "VERSION_1.0{ \ -# RUN: global: und; \ -# RUN: };" > %t2.script +# RUN: echo "VERSION_1.0 { global: und; };" > %t2.script # RUN: not ld.lld --version-script %t2.script -shared --no-undefined-version \ # RUN: %t.o -o %t.so 2>&1 | FileCheck -check-prefix=ERR2 %s -# ERR2: version script assignment of VERSION_1.0 to symbol und failed: symbol not defined +# ERR2: version script assignment of 'VERSION_1.0' to symbol 'und' failed: symbol not defined + +# RUN: echo "VERSION_1.0 { local: und; };" > %t3.script +# RUN: not ld.lld --version-script %t3.script -shared --no-undefined-version \ +# RUN: %t.o -o %t.so 2>&1 | FileCheck -check-prefix=ERR3 %s +# ERR3: version script assignment of 'local' to symbol 'und' failed: symbol not defined .text .globl foo diff --git a/test/ELF/version-script.s b/test/ELF/version-script.s index ba9c95a96fc31..7453981ab9ccf 100644 --- a/test/ELF/version-script.s +++ b/test/ELF/version-script.s @@ -14,55 +14,36 @@ # RUN: ld.lld --version-script %t3.script -shared %t.o %t2.so -o %t3.so # RUN: llvm-readobj -dyn-symbols %t3.so | FileCheck --check-prefix=DSO2 %s -# --version-script filters --dynamic-list. -# RUN: echo "{ foo1; foo2; };" > %t.list -# RUN: ld.lld --version-script %t.script --dynamic-list %t.list %t.o %t2.so -o %t -# RUN: llvm-readobj -dyn-symbols %t | FileCheck --check-prefix=EXE %s - -# RUN: echo "VERSION_1.0{ \ -# RUN: global: foo1; \ -# RUN: local: *; }; \ -# RUN: VERSION_2.0{ \ -# RUN: global: foo3; \ -# RUN: local: *; }; " > %t4.script +# RUN: echo "VERSION_1.0 { global: foo1; local: *; };" > %t4.script +# RUN: echo "VERSION_2.0 { global: foo3; local: *; };" >> %t4.script # RUN: ld.lld --version-script %t4.script -shared %t.o %t2.so -o %t4.so # RUN: llvm-readobj -dyn-symbols %t4.so | FileCheck --check-prefix=VERDSO %s -# RUN: echo "VERSION_1.0{ \ -# RUN: global: foo1; \ -# RUN: local: *; }; \ -# RUN: { \ -# RUN: global: foo3; \ -# RUN: local: *; }; " > %t5.script +# RUN: echo "VERSION_1.0 { global: foo1; local: *; };" > %t5.script +# RUN: echo "{ global: foo3; local: *; };" >> %t5.script # RUN: not ld.lld --version-script %t5.script -shared %t.o %t2.so -o %t5.so 2>&1 | \ -# RUN: FileCheck -check-prefix=ERR %s -# ERR: anonymous version definition is used in combination with other version definitions +# RUN: FileCheck -check-prefix=ERR1 %s +# ERR1: anonymous version definition is used in combination with other version definitions -# RUN: echo "{ \ -# RUN: global: foo1; \ -# RUN: local: *; }; \ -# RUN: VERSION_2.0 { \ -# RUN: global: foo3; \ -# RUN: local: *; }; " > %t5.script +# RUN: echo "{ global: foo1; local: *; };" > %t5.script +# RUN: echo "VERSION_2.0 { global: foo3; local: *; };" >> %t5.script # RUN: not ld.lld --version-script %t5.script -shared %t.o %t2.so -o %t5.so 2>&1 | \ -# RUN: FileCheck -check-prefix=ERR %s +# RUN: FileCheck -check-prefix=ERR2 %s +# ERR2: EOF expected, but got VERSION_2.0 -# RUN: echo "VERSION_1.0{ \ -# RUN: global: foo1; \ -# RUN: local: *; }; \ -# RUN: VERSION_2.0 { \ -# RUN: global: foo1; \ -# RUN: local: *; }; " > %t6.script +# 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 +# WARN2: 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 # RUN: llvm-readobj %t2 > /dev/null # DSO: DynamicSymbols [ # DSO-NEXT: Symbol { -# DSO-NEXT: Name: @ (0) +# DSO-NEXT: Name: @ # DSO-NEXT: Value: 0x0 # DSO-NEXT: Size: 0 # DSO-NEXT: Binding: Local (0x0) @@ -71,7 +52,7 @@ # DSO-NEXT: Section: Undefined (0x0) # DSO-NEXT: } # DSO-NEXT: Symbol { -# DSO-NEXT: Name: bar@ (1) +# DSO-NEXT: Name: bar@ # DSO-NEXT: Value: 0x0 # DSO-NEXT: Size: 0 # DSO-NEXT: Binding: Global (0x1) @@ -80,7 +61,7 @@ # DSO-NEXT: Section: Undefined (0x0) # DSO-NEXT: } # DSO-NEXT: Symbol { -# DSO-NEXT: Name: foo1@ (5) +# DSO-NEXT: Name: foo1@ # DSO-NEXT: Value: 0x1000 # DSO-NEXT: Size: 0 # DSO-NEXT: Binding: Global (0x1) @@ -89,7 +70,7 @@ # DSO-NEXT: Section: .text # DSO-NEXT: } # DSO-NEXT: Symbol { -# DSO-NEXT: Name: foo3@ (10) +# DSO-NEXT: Name: foo3@ # DSO-NEXT: Value: 0x1007 # DSO-NEXT: Size: 0 # DSO-NEXT: Binding: Global (0x1) @@ -101,7 +82,7 @@ # DSO2: DynamicSymbols [ # DSO2-NEXT: Symbol { -# DSO2-NEXT: Name: @ (0) +# DSO2-NEXT: Name: @ # DSO2-NEXT: Value: 0x0 # DSO2-NEXT: Size: 0 # DSO2-NEXT: Binding: Local (0x0) @@ -110,7 +91,7 @@ # DSO2-NEXT: Section: Undefined (0x0) # DSO2-NEXT: } # DSO2-NEXT: Symbol { -# DSO2-NEXT: Name: bar@ (1) +# DSO2-NEXT: Name: bar@ # DSO2-NEXT: Value: 0x0 # DSO2-NEXT: Size: 0 # DSO2-NEXT: Binding: Global (0x1) @@ -120,36 +101,6 @@ # DSO2-NEXT: } # DSO2-NEXT: ] -# EXE: DynamicSymbols [ -# EXE-NEXT: Symbol { -# EXE-NEXT: Name: @ (0) -# EXE-NEXT: Value: 0x0 -# EXE-NEXT: Size: 0 -# EXE-NEXT: Binding: Local (0x0) -# EXE-NEXT: Type: None (0x0) -# EXE-NEXT: Other: 0 -# EXE-NEXT: Section: Undefined (0x0) -# EXE-NEXT: } -# EXE-NEXT: Symbol { -# EXE-NEXT: Name: bar@ (1) -# EXE-NEXT: Value: 0x0 -# EXE-NEXT: Size: 0 -# EXE-NEXT: Binding: Global (0x1) -# EXE-NEXT: Type: Function (0x2) -# EXE-NEXT: Other: 0 -# EXE-NEXT: Section: Undefined (0x0) -# EXE-NEXT: } -# EXE-NEXT: Symbol { -# EXE-NEXT: Name: foo1@ (5) -# EXE-NEXT: Value: 0x11000 -# EXE-NEXT: Size: 0 -# EXE-NEXT: Binding: Global (0x1) -# EXE-NEXT: Type: None (0x0) -# EXE-NEXT: Other: 0 -# EXE-NEXT: Section: .text -# EXE-NEXT: } -# EXE-NEXT: ] - # VERDSO: DynamicSymbols [ # VERDSO-NEXT: Symbol { # VERDSO-NEXT: Name: @ diff --git a/test/ELF/version-symbol-error.s b/test/ELF/version-symbol-error.s new file mode 100644 index 0000000000000..fb83b359485b5 --- /dev/null +++ b/test/ELF/version-symbol-error.s @@ -0,0 +1,12 @@ +// 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: | FileCheck %s + +// CHECK: .o: symbol foo@V2 has undefined version V2 + +.globl foo@V2 +.text +foo@V2: + ret diff --git a/test/ELF/version-wildcard.test b/test/ELF/version-wildcard.test index 80cb9cadf159f..ac0b7edc6c519 100644 --- a/test/ELF/version-wildcard.test +++ b/test/ELF/version-wildcard.test @@ -1,9 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "VERSION_1.0{ \ -# RUN: global: foo*; \ -# RUN: local: *; };" > %t.script +# RUN: echo "VERSION_1.0 { global: foo*; local: *; };" > %t.script # RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so # RUN: llvm-readobj -dyn-symbols %t.so | FileCheck %s @@ -47,12 +45,8 @@ # CHECK-NEXT: ] # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "VERSION_1.0{ \ -# RUN: global: foo2; \ -# RUN: local: *; }; \ -# RUN: VERSION_2.0{ \ -# RUN: global: foo*; \ -# RUN: }; " > %t2.script +# RUN: echo "VERSION_1.0 { global: foo2; local: *; };" > %t2.script +# RUN: echo "VERSION_2.0 { global: foo*; };" >> %t2.script # RUN: ld.lld --version-script %t2.script -shared %t.o -o %t2.so # RUN: llvm-readobj -dyn-symbols %t2.so | FileCheck --check-prefix=MIX %s diff --git a/test/ELF/visibility.s b/test/ELF/visibility.s index 2043894d3d3d1..7af29c957b52f 100644 --- a/test/ELF/visibility.s +++ b/test/ELF/visibility.s @@ -82,7 +82,7 @@ // CHECK: DynamicSymbols [ // CHECK-NEXT: Symbol { -// CHECK-NEXT: Name: @ (0) +// CHECK-NEXT: Name: @ // CHECK-NEXT: Value: 0x0 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Local diff --git a/test/ELF/weak-undef-shared.s b/test/ELF/weak-undef-shared.s index 862a08632e26b..668a05b658a18 100644 --- a/test/ELF/weak-undef-shared.s +++ b/test/ELF/weak-undef-shared.s @@ -6,7 +6,7 @@ // RUN: llvm-readobj -t %t.exe | FileCheck %s // CHECK: Name: bar -// CHECK-NEXT: Value: 0x11020 +// CHECK-NEXT: Value: 0x201020 // CHECK-NEXT: Size: 0 // CHECK-NEXT: Binding: Weak // CHECK-NEXT: Type: Function diff --git a/test/ELF/weak-undef.s b/test/ELF/weak-undef.s index 02555535927e2..b6340339ebac5 100644 --- a/test/ELF/weak-undef.s +++ b/test/ELF/weak-undef.s @@ -5,7 +5,7 @@ # CHECK: DynamicSymbols [ # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: @ (0) +# CHECK-NEXT: Name: @ # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 # CHECK-NEXT: Binding: Local (0x0) diff --git a/test/ELF/wildcards.s b/test/ELF/wildcards.s deleted file mode 100644 index 2fe0f881bf46c..0000000000000 --- a/test/ELF/wildcards.s +++ /dev/null @@ -1,80 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -## Default case: abc and abx included in text. -# RUN: echo "SECTIONS { \ -# RUN: .text : { *(.abc .abx) } }" > %t.script -# RUN: ld.lld -o %t.out --script %t.script %t -# RUN: llvm-objdump -section-headers %t.out | \ -# RUN: FileCheck -check-prefix=SEC-DEFAULT %s -# SEC-DEFAULT: Sections: -# SEC-DEFAULT-NEXT: Idx Name Size Address Type -# SEC-DEFAULT-NEXT: 0 00000000 0000000000000000 -# SEC-DEFAULT-NEXT: 1 .text 00000008 0000000000000120 TEXT DATA -# SEC-DEFAULT-NEXT: 2 .abcd 00000004 0000000000000128 TEXT DATA -# SEC-DEFAULT-NEXT: 3 .ad 00000004 000000000000012c TEXT DATA -# SEC-DEFAULT-NEXT: 4 .ag 00000004 0000000000000130 TEXT DATA -# SEC-DEFAULT-NEXT: 5 .symtab 00000030 0000000000000000 -# SEC-DEFAULT-NEXT: 6 .shstrtab 0000002f 0000000000000000 -# SEC-DEFAULT-NEXT: 7 .strtab 00000008 0000000000000000 - -## Now replace the symbol with '?' and check that results are the same. -# RUN: echo "SECTIONS { \ -# RUN: .text : { *(.abc .ab?) } }" > %t.script -# RUN: ld.lld -o %t.out --script %t.script %t -# RUN: llvm-objdump -section-headers %t.out | \ -# RUN: FileCheck -check-prefix=SEC-DEFAULT %s - -## Now see how replacing '?' with '*' will consume whole abcd. -# RUN: echo "SECTIONS { \ -# RUN: .text : { *(.abc .ab*) } }" > %t.script -# RUN: ld.lld -o %t.out --script %t.script %t -# RUN: llvm-objdump -section-headers %t.out | \ -# RUN: FileCheck -check-prefix=SEC-ALL %s -# SEC-ALL: Sections: -# SEC-ALL-NEXT: Idx Name Size Address Type -# SEC-ALL-NEXT: 0 00000000 0000000000000000 -# SEC-ALL-NEXT: 1 .text 0000000c 0000000000000120 TEXT DATA -# SEC-ALL-NEXT: 2 .ad 00000004 000000000000012c TEXT DATA -# SEC-ALL-NEXT: 3 .ag 00000004 0000000000000130 TEXT DATA -# SEC-ALL-NEXT: 4 .symtab 00000030 0000000000000000 -# SEC-ALL-NEXT: 5 .shstrtab 00000029 0000000000000000 -# SEC-ALL-NEXT: 6 .strtab 00000008 0000000000000000 - -## All sections started with .a are merged. -# RUN: echo "SECTIONS { \ -# RUN: .text : { *(.a*) } }" > %t.script -# RUN: ld.lld -o %t.out --script %t.script %t -# RUN: llvm-objdump -section-headers %t.out | \ -# RUN: FileCheck -check-prefix=SEC-NO %s -# SEC-NO: Sections: -# SEC-NO-NEXT: Idx Name Size Address Type -# SEC-NO-NEXT: 0 00000000 0000000000000000 -# SEC-NO-NEXT: 1 .text 00000014 0000000000000120 TEXT DATA -# SEC-NO-NEXT: 2 .symtab 00000030 0000000000000000 -# SEC-NO-NEXT: 3 .shstrtab 00000021 0000000000000000 -# SEC-NO-NEXT: 4 .strtab 00000008 0000000000000000 - -.text -.section .abc,"ax",@progbits -.long 0 - -.text -.section .abx,"ax",@progbits -.long 0 - -.text -.section .abcd,"ax",@progbits -.long 0 - -.text -.section .ad,"ax",@progbits -.long 0 - -.text -.section .ag,"ax",@progbits -.long 0 - - -.globl _start -_start: diff --git a/test/ELF/writable-merge.s b/test/ELF/writable-merge.s index 431cb6282d91c..3006fa387fb51 100644 --- a/test/ELF/writable-merge.s +++ b/test/ELF/writable-merge.s @@ -4,3 +4,4 @@ // CHECK: writable SHF_MERGE section is not supported .section .foo,"awM",@progbits,4 +.quad 0 diff --git a/test/ELF/x86-64-dyn-rel-error.s b/test/ELF/x86-64-dyn-rel-error.s index c814fbeb1d9a5..354fcc09e8a8e 100644 --- a/test/ELF/x86-64-dyn-rel-error.s +++ b/test/ELF/x86-64-dyn-rel-error.s @@ -9,4 +9,4 @@ _start: .data .long bar -// CHECK: R_X86_64_32 cannot be used against shared object; recompile with -fPIC. +// CHECK: {{.*}}:(.data+0x0): relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC. diff --git a/test/ELF/x86-64-dyn-rel-error2.s b/test/ELF/x86-64-dyn-rel-error2.s index c1d3da3ae2ae8..88a180da6274e 100644 --- a/test/ELF/x86-64-dyn-rel-error2.s +++ b/test/ELF/x86-64-dyn-rel-error2.s @@ -9,4 +9,4 @@ _start: .data .long bar - . -// CHECK: R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC. +// CHECK: {{.*}}:(.data+0x0): relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC. diff --git a/test/ELF/x86-64-relax-got-abs.s b/test/ELF/x86-64-relax-got-abs.s new file mode 100644 index 0000000000000..c4291202f0351 --- /dev/null +++ b/test/ELF/x86-64-relax-got-abs.s @@ -0,0 +1,16 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -relax-relocations -triple=x86_64-pc-linux %s \ +// RUN: -o %t.o +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-objdump -d %t.so | FileCheck %s + +// We used to fail trying to relax this into a pc relocation to an absolute +// value. + +// CHECK: movq 4185(%rip), %rax + + movq bar@GOTPCREL(%rip), %rax + .data + .global bar + .hidden bar + bar = 42 diff --git a/test/ELF/x86-64-reloc-32-fpic.s b/test/ELF/x86-64-reloc-32-fpic.s index 0a0f1a09fda83..5726d36e9ad70 100644 --- a/test/ELF/x86-64-reloc-32-fpic.s +++ b/test/ELF/x86-64-reloc-32-fpic.s @@ -1,7 +1,7 @@ # 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 -# CHECK: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC. +# CHECK: {{.*}}:(.data+0x0): relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC. .data .long _shared diff --git a/test/ELF/x86-64-reloc-error.s b/test/ELF/x86-64-reloc-error.s index 9b7e17de793bd..ece1bd45aa4fa 100644 --- a/test/ELF/x86-64-reloc-error.s +++ b/test/ELF/x86-64-reloc-error.s @@ -6,5 +6,5 @@ movl $big, %edx movq $foo - 0x1000000000000, %rdx -# CHECK: R_X86_64_32 out of range -# CHECK: R_X86_64_32S out of range +# CHECK: {{.*}}:(.text+0x1): relocation R_X86_64_32 out of range +# CHECK: {{.*}}:(.text+0x8): relocation R_X86_64_32S out of range diff --git a/test/ELF/x86-64-reloc-pc32-fpic.s b/test/ELF/x86-64-reloc-pc32-fpic.s index ed9121583c183..3c9f3e0bdb389 100644 --- a/test/ELF/x86-64-reloc-pc32-fpic.s +++ b/test/ELF/x86-64-reloc-pc32-fpic.s @@ -1,7 +1,7 @@ # 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 -# CHECK: relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC. +# CHECK: {{.*}}:(.data+0x1): relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC. .data call _shared diff --git a/test/ELF/x86-64-reloc-range.s b/test/ELF/x86-64-reloc-range.s index 8319eaafa0ce0..08f604ee6a30c 100644 --- a/test/ELF/x86-64-reloc-range.s +++ b/test/ELF/x86-64-reloc-range.s @@ -1,7 +1,7 @@ // 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 -// CHECK: relocation R_X86_64_PC32 out of range +// CHECK: {{.*}}:(.text+0x3): relocation R_X86_64_PC32 out of range // CHECK-NOT: relocation lea foo(%rip), %rax diff --git a/test/ELF/zdefs.s b/test/ELF/zdefs.s index 410da1812db96..420f602c41ae7 100644 --- a/test/ELF/zdefs.s +++ b/test/ELF/zdefs.s @@ -2,6 +2,6 @@ # RUN: ld.lld -shared %t.o -o %t1.so # RUN: not ld.lld -z defs -shared %t.o -o %t1.so 2>&1 | FileCheck -check-prefix=ERR %s -# ERR: undefined symbol: foo +# ERR: error: {{.*}}:(.text+0x1): undefined symbol 'foo' callq foo@PLT diff --git a/test/ELF/zstack-size.s b/test/ELF/zstack-size.s new file mode 100644 index 0000000000000..36fbd03766ce2 --- /dev/null +++ b/test/ELF/zstack-size.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld -z stack-size=0x1000 %t -o %t1 +# RUN: llvm-readobj -program-headers %t1 | FileCheck %s + +.global _start +_start: + nop + +# CHECK: Type: PT_GNU_STACK (0x6474E551) +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: VirtualAddress: 0x0 +# CHECK-NEXT: PhysicalAddress: 0x0 +# CHECK-NEXT: FileSize: 0 +# CHECK-NEXT: MemSize: 4096 +# CHECK-NEXT: Flags [ (0x6) +# CHECK-NEXT: PF_R (0x4) +# CHECK-NEXT: PF_W (0x2) +# CHECK-NEXT: ] +# CHECK-NEXT: Alignment: 0 |