From: Fangrui Song Date: Thu, 18 Jul 2019 10:43:07 +0000 (+0000) Subject: [ELF][PPC] Refactor some ppc64 tests X-Git-Tag: llvmorg-10-init~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=782390258b5cfcde078b71513f21fd05fc59cb34;p=platform%2Fupstream%2Fllvm.git [ELF][PPC] Refactor some ppc64 tests Merge ppc64-dynamic-relocations.s into ppc64-plt-stub.s Add ppc64-tls-ie.s: covers ppc64-initial-exec-tls.s and ppc64-tls-ie-le.s Add ppc64-tls-gd.s: covers ppc64-general-dynamic-tls.s, ppc64-gd-to-ie.s, ppc64-tls-gd-le.s, and ppc64-tls-gd-le-small.s llvm-svn: 366424 --- diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp index 96b8291..70d284c 100644 --- a/lld/ELF/Arch/PPC64.cpp +++ b/lld/ELF/Arch/PPC64.cpp @@ -946,6 +946,7 @@ void PPC64::relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const { // addis rT, r2, sym@got@tprel@ha. relocateOne(loc, R_PPC64_GOT_TPREL16_HA, val); return; + case R_PPC64_GOT_TLSGD16: case R_PPC64_GOT_TLSGD16_LO: { // Relax from addi r3, rA, sym@got@tlsgd@l to // ld r3, sym@got@tprel@l(rA) diff --git a/lld/test/ELF/ppc64-gd-to-ie.s b/lld/test/ELF/ppc64-gd-to-ie.s deleted file mode 100644 index a11024a..0000000 --- a/lld/test/ELF/ppc64-gd-to-ie.s +++ /dev/null @@ -1,100 +0,0 @@ -# REQUIRES: ppc - -# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o -# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-tls.s -o %t2.o -# RUN: ld.lld -shared %t2.o -o %t3.so -# RUN: ld.lld %t.o %t3.so -o %t -# RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=CheckGot %s -# RUN: llvm-objdump -d %t | FileCheck --check-prefix=Dis %s -# RUN: llvm-readelf -r %t | FileCheck --check-prefix=OutputRelocs %s - -# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o -# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-tls.s -o %t2.o -# RUN: ld.lld -shared %t2.o -o %t3.so -# RUN: ld.lld %t.o %t3.so -o %t -# RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=CheckGot %s -# RUN: llvm-objdump -d %t | FileCheck --check-prefix=Dis %s -# RUN: llvm-readelf -r %t | FileCheck --check-prefix=OutputRelocs %s - - .text - .abiversion 2 - .globl _start - .p2align 4 - .type _start,@function -_start: -.Lfunc_gep0: - addis 2, 12, .TOC.-.Lfunc_gep0@ha - addi 2, 2, .TOC.-.Lfunc_gep0@l -.Lfunc_lep0: - .localentry _start, .Lfunc_lep0-.Lfunc_gep0 - mflr 0 - std 0, 16(1) - stdu 1, -32(1) - addis 3, 2, a@got@tlsgd@ha - addi 3, 3, a@got@tlsgd@l - bl __tls_get_addr(a@tlsgd) - nop - lwa 3, 0(3) - addi 1, 1, 32 - ld 0, 16(1) - mtlr 0 - blr - - - .globl other_reg - .p2align 4 - .type other_reg,@function -other_reg: -.Lfunc_gep1: - addis 2, 12, .TOC.-.Lfunc_gep1@ha - addi 2, 2, .TOC.-.Lfunc_gep1@l -.Lfunc_lep1: - .localentry other_reg, .Lfunc_lep1-.Lfunc_gep1 - mflr 0 - std 0, 16(1) - stdu 1, -32(1) - addis 5, 2, a@got@tlsgd@ha - addi 3, 5, a@got@tlsgd@l - bl __tls_get_addr(a@tlsgd) - nop - lwa 4, 0(3) - addis 30, 2, b@got@tlsgd@ha - addi 3, 30, b@got@tlsgd@l - bl __tls_get_addr(b@tlsgd) - nop - lwa 3, 0(3) - add 3, 4, 3 - addi 1, 1, 32 - ld 0, 16(1) - mtlr 0 - blr - - -# CheckGot: .got 00000018 00000000100200c0 DATA -# .got is at 0x100200c0 so the toc-base is 100280c0. -# `a` is at .got[1], we expect the offsets to be: -# Ha(a) = ((0x100200c8 - 0x100280c0) + 0x8000) >> 16 = 0 -# Lo(a) = (0x100200c8 - 0x100280c0) = -32760 - -# Dis-LABEL: _start -# Dis: addis 3, 2, 0 -# Dis-NEXT: ld 3, -32760(3) -# Dis-NEXT: nop -# Dis-NEXT: add 3, 3, 13 - -# Dis-LABEL: other_reg -# Dis: addis 5, 2, 0 -# Dis-NEXT: ld 3, -32760(5) -# Dis-NEXT: nop -# Dis-NEXT: add 3, 3, 13 -# Dis: addis 30, 2, 0 -# Dis: ld 3, -32752(30) -# Dis-NEXT: nop -# Dis-NEXT: add 3, 3, 13 - -# Verify that the only dynamic relocations we emit are TPREL ones rather then -# the DTPMOD64/DTPREL64 pair for general-dynamic. -# OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 2 entries: -# OutputRelocs-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend -# OutputRelocs-NEXT: {{[0-9a-f]+}} {{[0-9a-f]+}} R_PPC64_TPREL64 {{[0-9a-f]+}} a + 0 -# OutputRelocs-NEXT: {{[0-9a-f]+}} {{[0-9a-f]+}} R_PPC64_TPREL64 {{[0-9a-f]+}} b + 0 diff --git a/lld/test/ELF/ppc64-general-dynamic-tls.s b/lld/test/ELF/ppc64-general-dynamic-tls.s deleted file mode 100644 index 8ae25a9..0000000 --- a/lld/test/ELF/ppc64-general-dynamic-tls.s +++ /dev/null @@ -1,112 +0,0 @@ -// REQUIRES: ppc - -// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o -// RUN: ld.lld -shared %t.o -o %t.so -// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s -// RUN: llvm-readelf -r %t.so | FileCheck --check-prefix=OutputRelocs %s -// RUN: llvm-objdump --section-headers %t.so | FileCheck --check-prefix=CheckGot %s -// RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=Dis %s - -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o -// RUN: ld.lld -shared %t.o -o %t.so -// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s -// RUN: llvm-readelf -r %t.so | FileCheck --check-prefix=OutputRelocs %s -// RUN: llvm-objdump --section-headers %t.so | FileCheck --check-prefix=CheckGot %s -// RUN: llvm-objdump -d %t.so | FileCheck --check-prefix=Dis %s - - .text - .abiversion 2 - .globl test - .p2align 4 - .type test,@function -test: -.Lfunc_gep0: - addis 2, 12, .TOC.-.Lfunc_gep0@ha - addi 2, 2, .TOC.-.Lfunc_gep0@l -.Lfunc_lep0: - .localentry test, .Lfunc_lep0-.Lfunc_gep0 - mflr 0 - std 31, -8(1) - std 0, 16(1) - stdu 1, -48(1) - mr 31, 1 - std 30, 32(31) - addis 3, 2, i@got@tlsgd@ha - addi 3, 3, i@got@tlsgd@l - bl __tls_get_addr(i@tlsgd) - nop - lwz 30, 0(3) - extsw 3, 30 - ld 30, 32(31) - addi 1, 1, 48 - ld 0, 16(1) - ld 31, -8(1) - mtlr 0 - blr - - -test_hi: -.Lfunc_gep1: - addis 2, 12, .TOC.-.Lfunc_gep1@ha - addi 2, 2, .TOC.-.Lfunc_gep1@l -.Lfunc_lep1: - .localentry test2, .Lfunc_lep1-.Lfunc_gep1 - addis 3, 0, j@got@tlsgd@h - blr - -test_16: -.Lfunc_gep2: - addis 2, 12, .TOC.-.Lfunc_gep2@ha - addi 2, 2, .TOC.-.Lfunc_gep2@l -.Lfunc_lep2: - .localentry test16, .Lfunc_lep2-.Lfunc_gep2 - addi 3, 0, k@got@tlsgd - blr - -// Verify that the input has every general-dynamic tls relocation type. -// InputRelocs: Relocation section '.rela.text' -// InputRelocs: R_PPC64_GOT_TLSGD16_HA {{0+}} i + 0 -// InputRelocs: R_PPC64_GOT_TLSGD16_LO {{0+}} i + 0 -// InputRelocs: R_PPC64_TLSGD {{0+}} i + 0 -// InputRelocs: R_PPC64_GOT_TLSGD16_HI {{0+}} j + 0 -// InputRelocs: R_PPC64_GOT_TLSGD16 {{0+}} k + 0 - -// There is 2 got entries for each tls variable that is accessed with the -// general-dynamic model. The entries can be though of as a structure to be -// filled in by the dynamic linker: -// typedef struct { -// unsigned long int ti_module; --> R_PPC64_DTPMOD64 -// unsigned long int ti_offset; --> R_PPC64_DTPREL64 -//} tls_index; -// OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 6 entries: -// OutputRelocs: R_PPC64_DTPMOD64 {{0+}} i + 0 -// OutputRelocs: R_PPC64_DTPREL64 {{0+}} i + 0 -// OutputRelocs: R_PPC64_DTPMOD64 {{0+}} j + 0 -// OutputRelocs: R_PPC64_DTPREL64 {{0+}} j + 0 -// OutputRelocs: R_PPC64_DTPMOD64 {{0+}} k + 0 -// OutputRelocs: R_PPC64_DTPREL64 {{0+}} k + 0 - -// Check that the got has 7 entires. (1 for the TOC and 3 structures of -// 2 entries for the tls variables). Also verify the address so we can check -// the offsets we calculated for each relocation type. -// CheckGot: got 00000038 00000000000200f0 - -// got starts at 0x200f0, so .TOC. will be 0x280f0. - -// We are building the address of the first tls_index in the got which starts at -// 0x200f8 (got[1]). -// #ha(i@got@tlsgd) --> (0x200f8 - 0x280f0 + 0x8000) >> 16 = 0 -// #lo(i@got@tlsgd) --> (0x200f8 - 0x280f0) & 0xFFFF = -7ff8 = -32760 -// Dis: test: -// Dis: addis 3, 2, 0 -// Dis: addi 3, 3, -32760 - -// Second tls_index starts at got[3]. -// #hi(j@got@tlsgd) --> (0x20108 - 0x280f0) >> 16 = -1 -// Dis: test_hi: -// Dis: lis 3, -1 - -// Third tls index is at got[5]. -// k@got@tlsgd --> (0x20118 - 0x280f0) = -0x7fd8 = -32728 -// Dis: test_16: -// Dis: li 3, -32728 diff --git a/lld/test/ELF/ppc64-initial-exec-tls.s b/lld/test/ELF/ppc64-initial-exec-tls.s deleted file mode 100644 index 9cdd3e4..0000000 --- a/lld/test/ELF/ppc64-initial-exec-tls.s +++ /dev/null @@ -1,102 +0,0 @@ -// REQUIRES: ppc - -// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o -// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-tls.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so -// RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.so -o %t -// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s -// RUN: llvm-readelf -r %t | FileCheck --check-prefix=OutputRelocs %s -// RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=CheckGot %s -// RUN: llvm-objdump -d %t | FileCheck --check-prefix=Dis %s - -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-tls.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so -// RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.so -o %t -// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s -// RUN: llvm-readelf -r %t | FileCheck --check-prefix=OutputRelocs %s -// RUN: llvm-objdump --section-headers %t | FileCheck --check-prefix=CheckGot %s -// RUN: llvm-objdump -d %t | FileCheck --check-prefix=Dis %s - - .text - .abiversion 2 - .file "intial_exec.c" - .globl test_initial_exec # -- Begin function test_initial_exec - .p2align 4 - .type test_initial_exec,@function -test_initial_exec: # @test_initial_exec -.Lfunc_begin0: -.Lfunc_gep0: - addis 2, 12, .TOC.-.Lfunc_gep0@ha - addi 2, 2, .TOC.-.Lfunc_gep0@l -.Lfunc_lep0: - .localentry test_initial_exec, .Lfunc_lep0-.Lfunc_gep0 -# %bb.0: # %entry - li 3, 0 - stw 3, -12(1) - addis 3, 2, a@got@tprel@ha - ld 3, a@got@tprel@l(3) - lwzx 4, 3, a@tls - extsw 3, 4 - blr - - -test_hi: -.Lfunc_gep1: - addis 2, 12, .TOC.-.Lfunc_gep1@ha - addi 2, 2, .TOC.-.Lfunc_gep1@l -.Lfunc_lep1: - .localentry test2, .Lfunc_lep1-.Lfunc_gep1 - addis 3, 0, b@got@tprel@h - blr - -test_ds: -.Lfunc_gep2: - addis 2, 12, .TOC.-.Lfunc_gep2@ha - addi 2, 2, .TOC.-.Lfunc_gep2@l -.Lfunc_lep2: - .localentry test16, .Lfunc_lep2-.Lfunc_gep2 - addi 3, 0, c@got@tprel - blr - -// Verify that the input has every initial-exec tls relocation type. -// InputRelocs: Relocation section '.rela.text' -// InputRelocs: R_PPC64_GOT_TPREL16_HA {{0+}} a + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_LO_DS {{0+}} a + 0 -// InputRelocs: R_PPC64_TLS {{0+}} a + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_HI {{0+}} b + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_DS {{0+}} c + 0 - -// There is a got entry for each tls variable that is accessed with the -// initial-exec model to be filled in by the dynamic linker. -// OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 3 entries: -// OutputRelocs: R_PPC64_TPREL64 {{0+}} a + 0 -// OutputRelocs: R_PPC64_TPREL64 {{0+}} b + 0 -// OutputRelocs: R_PPC64_TPREL64 {{0+}} c + 0 - -// Check that the got has 4 entires. (1 for the TOC and 3 entries for TLS -// variables). Also verify the address so we can check -// the offsets we calculated for each relocation type. -// CheckGot: got 00000020 00000000100200c0 - -// GOT stats at 0x100200c0, so TOC will be 0x100280c0 - -// We are building the address of the first TLS got entry which contains the -// offset of the tls variable relative to the thread pointer. -// 0x100200c8 (got[1]). -// #ha(a@got@tprel) --> (0x100200c8 - 0x100280c0 + 0x8000) >> 16 = 0 -// #lo(a@got@tprel)) --> (0x100200c8 - 0x100280c0) & 0xFFFF = -7ff8 = -32760 -// Dis: test_initial_exec: -// Dis: addis 3, 2, 0 -// Dis: ld 3, -32760(3) -// Dis: lwzx 4, 3, 13 - -// Second TLS got entry starts at got[2] 0x100200d0 -// #hi(b@got@tprel) --> (0x100200d0 - 0x100280c0) >> 16 = -1 -// Dis: test_hi: -// Dis: lis 3, -1 - -// Third TLS got entry starts at got[3] 0x100200d8. -// c@got@tprel--> (0x100200d8. - 0x100280c0) = -0x7fe8 = 32744 -// Dis: test_ds: -// Dis: li 3, -32744 diff --git a/lld/test/ELF/ppc64-plt-stub.s b/lld/test/ELF/ppc64-plt-stub.s index b2de161..44ea40d 100644 --- a/lld/test/ELF/ppc64-plt-stub.s +++ b/lld/test/ELF/ppc64-plt-stub.s @@ -1,28 +1,37 @@ -// REQUIRES: ppc - -// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o -// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/shared-ppc64.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so -// RUN: ld.lld %t.o %t2.so -o %t -// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s - -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/shared-ppc64.s -o %t2.o -// RUN: ld.lld -shared %t2.o -o %t2.so -// RUN: ld.lld %t.o %t2.so -o %t -// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s - -// CHECK: Disassembly of section .text: -// CHECK-EMPTY: -// CHECK-NEXT: _start: -// CHECK: 10010008: bl .+16 - -// CHECK-LABEL: 0000000010010018 __plt_foo: -// CHECK-NEXT: std 2, 24(1) -// CHECK-NEXT: addis 12, 2, 0 -// CHECK-NEXT: ld 12, 32560(12) -// CHECK-NEXT: mtctr 12 -// CHECK-NEXT: bctr +# REQUIRES: ppc + +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/shared-ppc64.s -o %t2.o +# RUN: ld.lld -shared %t2.o -soname=t2.so -o %t2.so +# RUN: ld.lld %t.o %t2.so -o %t +# RUN: llvm-readelf -S -d %t | FileCheck --check-prefix=SEC %s +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s + +# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/shared-ppc64.s -o %t2.o +# RUN: ld.lld -shared %t2.o -soname=t2.so -o %t2.so +# RUN: ld.lld %t.o %t2.so -o %t +# RUN: llvm-readelf -S -d %t | FileCheck --check-prefix=SEC %s +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s + +## DT_PLTGOT points to .plt +# SEC: .plt NOBITS 0000000010030000 030000 000018 +# SEC: 0x0000000000000003 (PLTGOT) 0x10030000 + +## .plt[0] holds the address of _dl_runtime_resolve. +## .plt[1] holds the link map. +## The JMP_SLOT relocation is stored at .plt[2] +# RELOC: 0x10030010 R_PPC64_JMP_SLOT foo 0x0 + +# CHECK: _start: +# CHECK: 10010008: bl .+16 + +# CHECK-LABEL: 0000000010010018 __plt_foo: +# CHECK-NEXT: std 2, 24(1) +# CHECK-NEXT: addis 12, 2, 0 +# CHECK-NEXT: ld 12, 32560(12) +# CHECK-NEXT: mtctr 12 +# CHECK-NEXT: bctr .text diff --git a/lld/test/ELF/ppc64-tls-gd-le-small.s b/lld/test/ELF/ppc64-tls-gd-le-small.s deleted file mode 100644 index 4d80f0a..0000000 --- a/lld/test/ELF/ppc64-tls-gd-le-small.s +++ /dev/null @@ -1,61 +0,0 @@ -# REQUIRES: ppc - -# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o -# RUN: llvm-objdump -d --no-show-raw-insn -r %t.o | FileCheck --check-prefix=CHECK-INPUT %s -# RUN: ld.lld --defsym __tls_get_addr=0x10001000 %t.o -o %t -# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=CHECK-DIS %s -# RUN: llvm-readelf -relocations %t | FileCheck --check-prefix=DYN-RELOCS %s - -# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o -# RUN: llvm-objdump -d --no-show-raw-insn -r %t.o | FileCheck --check-prefix=CHECK-INPUT %s -# RUN: ld.lld --defsym __tls_get_addr=0x10001000 %t.o -o %t -# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=CHECK-DIS %s -# RUN: llvm-readelf -relocations %t | FileCheck --check-prefix=DYN-RELOCS %s - -# Test checks the relaxation of a 'small' general-dynamic tls access into a -# local-exec tls access. - - .text - .abiversion 2 - - .global test - .p2align 4 - .type test, @function - -test: -.Lgep: - addis 2, 12, .TOC.-.Lgep@ha - addi 2, 2, .TOC.-.Lgep@l - .localentry test, .-test - mflr 0 - std 0, 16(1) - stdu 1, -32(1) - addi 3, 2, a@got@tlsgd - bl __tls_get_addr(a@tlsgd) - nop - lwz 3, 0(3) - addi 1, 1, 32 - ld 0, 16(1) - mtlr 0 - blr - - .type a, @object - .section .tdata,"awT",@progbits - .global a - .p2align 2 -a: - .long 55 - .size a, 4 - -# CHECK-INPUT: addi 3, 2, 0 -# CHECK-INPUT-NEXT: R_PPC64_GOT_TLSGD16 a -# CHECK-INPUT-NEXT: bl .+0 -# CHECK-INPUT-NEXT: R_PPC64_TLSGD a -# CHECK-INPUT-NEXT: R_PPC64_REL24 __tls_get_addr - -# CHECK-DIS: addis 3, 13, 0 -# CHECK-DIS-NEXT: nop -# CHECK-DIS-NEXT: addi 3, 3, -28672 -# CHECK-DIS-NEXT: lwz 3, 0(3) - -# DYN-RELOCS: There are no relocations in this file diff --git a/lld/test/ELF/ppc64-tls-gd-le.s b/lld/test/ELF/ppc64-tls-gd-le.s deleted file mode 100644 index 78bffb2..0000000 --- a/lld/test/ELF/ppc64-tls-gd-le.s +++ /dev/null @@ -1,79 +0,0 @@ -// REQUIRES: ppc - -// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o -// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s -// RUN: ld.lld %t.o -o %t -// RUN: llvm-objdump -d %t | FileCheck --check-prefix=Dis %s -// RUN: llvm-readelf -r %t | FileCheck --check-prefix=OutputRelocs %s - -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o -// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s -// RUN: ld.lld %t.o -o %t -// RUN: llvm-objdump -d %t | FileCheck --check-prefix=Dis %s -// RUN: llvm-readelf -r %t | FileCheck --check-prefix=OutputRelocs %s - - .text - .abiversion 2 - .globl _start # -- Begin function _start - .p2align 4 - .type _start,@function -_start: # @_start -.Lfunc_begin0: -.Lfunc_gep0: - addis 2, 12, .TOC.-.Lfunc_gep0@ha - addi 2, 2, .TOC.-.Lfunc_gep0@l -.Lfunc_lep0: - .localentry _start, .Lfunc_lep0-.Lfunc_gep0 -# %bb.0: # %entry - mflr 0 - std 31, -8(1) - std 0, 16(1) - stdu 1, -64(1) - mr 31, 1 - std 30, 48(31) # 8-byte Folded Spill - li 3, 0 - stw 3, 44(31) - addis 3, 2, a@got@tlsgd@ha - addi 3, 3, a@got@tlsgd@l - bl __tls_get_addr(a@tlsgd) - nop - lwz 30, 0(3) - extsw 3, 30 - ld 30, 48(31) # 8-byte Folded Reload - addi 1, 1, 64 - ld 0, 16(1) - ld 31, -8(1) - mtlr 0 - blr - .long 0 - .quad 0 -.Lfunc_end0: - .size _start, .Lfunc_end0-.Lfunc_begin0 - - # -- End function - .type a,@object # @a - .section .tdata,"awT",@progbits - .globl a - .p2align 2 -a: - .long 55 # 0x37 - .size a, 4 - -// Verify that the input has general-dynamic tls relocation types -// InputRelocs: Relocation section '.rela.text' -// InputRelocs: R_PPC64_GOT_TLSGD16_HA {{0+}} a + 0 -// InputRelocs: R_PPC64_GOT_TLSGD16_LO {{0+}} a + 0 -// InputRelocs: R_PPC64_TLSGD {{0+}} a + 0 - -// Verify that the general-dynamic sequence is relaxed to local exec. -// #ha(a@tprel) --> (0 - 0x7000 + 0x8000) >> 16 = 0 -// #lo(a@tprel)) --> (0 - 0x7000) & 0xFFFF = -0x7000 = -28672 -// Dis: _start: -// Dis: nop -// Dis: addis 3, 13, 0 -// Dis: nop -// Dis: addi 3, 3, -28672 - -// Verify that no general-dynamic relocations exist for the dynamic linker. -// OutputRelocs-NOT: R_PPC64_DTPMOD64 -// OutputRelocs-NOT: R_PPC64_DTPREL64 diff --git a/lld/test/ELF/ppc64-tls-gd.s b/lld/test/ELF/ppc64-tls-gd.s new file mode 100644 index 0000000..5b9c9ed --- /dev/null +++ b/lld/test/ELF/ppc64-tls-gd.s @@ -0,0 +1,102 @@ +# REQUIRES: ppc +# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o +# RUN: echo '.tbss; .globl b, c; b: .zero 4; c:' | llvm-mc -filetype=obj -triple=powerpc64le - -o %t1.o +# RUN: ld.lld -shared -soname=t1.so %t1.o -o %t1.so + +# RUN: ld.lld -shared %t.o %t1.o -o %t.so +# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=GD-REL %s +# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=GD %s + +# RUN: ld.lld %t.o %t1.o -o %t +# RUN: llvm-readelf -r %t | FileCheck --check-prefix=NOREL %s +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s + +# RUN: ld.lld %t.o %t1.so -o %t +# RUN: llvm-readobj -r %t | FileCheck --check-prefix=IE-REL %s +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=IE %s + +# GD-REL: .rela.dyn { +# GD-REL-NEXT: 0x200F0 R_PPC64_DTPMOD64 a 0x0 +# GD-REL-NEXT: 0x200F8 R_PPC64_DTPREL64 a 0x0 +# GD-REL-NEXT: 0x20100 R_PPC64_DTPMOD64 b 0x0 +# GD-REL-NEXT: 0x20108 R_PPC64_DTPREL64 b 0x0 +# GD-REL-NEXT: 0x20110 R_PPC64_DTPMOD64 c 0x0 +# GD-REL-NEXT: 0x20118 R_PPC64_DTPREL64 c 0x0 +# GD-REL-NEXT: } + +## &DTPMOD(a) - .TOC. = &.got[0] - (.got+0x8000) = -32768 +# GD: addis 3, 2, 0 +# GD-NEXT: addi 3, 3, -32768 +# GD-NEXT: bl .+40 +# GD-NEXT: ld 2, 24(1) + +## &DTPMOD(b) - .TOC. = &.got[2] - (.got+0x8000) = -32752 +# GD-NEXT: addis 3, 2, 0 +# GD-NEXT: addi 3, 3, -32752 +# GD-NEXT: bl .+24 +# GD-NEXT: ld 2, 24(1) + +## &DTPMOD(b) - .TOC. = &.got[4] - (.got+0x8000) = -32736 +# GD-NEXT: li 3, -32736 +# GD-NEXT: bl .+12 +# GD-NEXT: ld 2, 24(1) + +# NOREL: no relocations + +## a@tprel = st_value(a)-0x7000 = -28664 +# LE: nop +# LE-NEXT: addis 3, 13, 0 +# LE-NEXT: nop +# LE-NEXT: addi 3, 3, -28664 +## b@tprel = st_value(b)-0x7000 = -28660 +# LE: nop +# LE-NEXT: addis 3, 13, 0 +# LE-NEXT: nop +# LE-NEXT: addi 3, 3, -28660 +## c@tprel = st_value(c)-0x7000 = -28656 +# LE-NEXT: addis 3, 13, 0 +# LE-NEXT: nop +# LE-NEXT: addi 3, 3, -28656 + +# IE-REL: .rela.dyn { +# IE-REL-NEXT: 0x100200C0 R_PPC64_TPREL64 b 0x0 +# IE-REL-NEXT: 0x100200C8 R_PPC64_TPREL64 c 0x0 +# IE-REL-NEXT: } + +## a is relaxed to use LE. +## a@tprel = st_value(a)-0x7000 = -28664 +# IE: nop +# IE-NEXT: addis 3, 13, 0 +# IE-NEXT: nop +# IE-NEXT: addi 3, 3, -28664 +## &DTPMOD(b) - .TOC. = &.got[0] - (.got+0x8000) = -32768 +# IE-NEXT: addis 3, 2, 0 +# IE-NEXT: ld 3, -32768(3) +# IE-NEXT: nop +# IE-NEXT: add 3, 3, 13 +## &DTPMOD(c) - .TOC. = &.got[1] - (.got+0x8000) = -32760 +## r0 is wrong. R_PPC64_GOT_TLS16 cannot be relaxed to IE but the behavior is +## consistent with ld.bfd +# IE-NEXT: ld 3, -32760(0) +# IE-NEXT: nop +# IE-NEXT: add 3, 3, 13 + +addis 3, 2, a@got@tlsgd@ha +addi 3, 3, a@got@tlsgd@l +bl __tls_get_addr(a@tlsgd) +nop + +addis 3, 2, b@got@tlsgd@ha +addi 3, 3, b@got@tlsgd@l +bl __tls_get_addr(b@tlsgd) +nop + +addi 3, 0, c@got@tlsgd +bl __tls_get_addr(c@tlsgd) +nop + +.section .tbss +.globl a +.zero 8 +a: +.zero 4 diff --git a/lld/test/ELF/ppc64-tls-ie-le.s b/lld/test/ELF/ppc64-tls-ie-le.s deleted file mode 100644 index c989310..0000000 --- a/lld/test/ELF/ppc64-tls-ie-le.s +++ /dev/null @@ -1,140 +0,0 @@ -// REQUIRES: ppc - -// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o -// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-tls-ie-le.s -o %t2.o -// RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.o -o %t -// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s -// RUN: llvm-readelf -r %t | FileCheck --check-prefix=OutputRelocs %s -// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=Dis %s - -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o -// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-tls-ie-le.s -o %t2.o -// RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.o -o %t -// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s -// RUN: llvm-readelf -r %t | FileCheck --check-prefix=OutputRelocs %s -// RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=Dis %s - - .text - .abiversion 2 -test1: # @test1 - addis 3, 2, c@got@tprel@ha - ld 3, c@got@tprel@l(3) - lbzx 3, 3, c@tls - blr -test2: # @test2 - addis 3, 2, s@got@tprel@ha - ld 3, s@got@tprel@l(3) - lhzx 3, 3, s@tls - blr -test3: # @test3 - addis 3, 2, i@got@tprel@ha - ld 3, i@got@tprel@l(3) - lwzx 3, 3, i@tls - blr -test4: # @test4 - addis 3, 2, l@got@tprel@ha - ld 3, l@got@tprel@l(3) - ldx 3, 3, l@tls - blr -test5: # @test5 - addis 4, 2, c@got@tprel@ha - ld 4, c@got@tprel@l(4) - stbx 3, 4, c@tls - blr -test6: # @test6 - addis 4, 2, s@got@tprel@ha - ld 4, s@got@tprel@l(4) - sthx 3, 4, s@tls - blr -test7: # @test7 - addis 4, 2, i@got@tprel@ha - ld 4, i@got@tprel@l(4) - stwx 3, 4, i@tls - blr -test8: # @test8 - addis 4, 2, l@got@tprel@ha - ld 4, l@got@tprel@l(4) - stdx 3, 4, l@tls - blr -test9: # @test9 - addis 3, 2, i@got@tprel@ha - ld 3, i@got@tprel@l(3) - add 3, 3, i@tls - blr -test_ds: # @test_ds - ld 4, l@got@tprel(2) - stdx 3, 4, l@tls - blr - - -// Verify that the input has initial-exec tls relocation types. -// InputRelocs: Relocation section '.rela.text' -// InputRelocs: R_PPC64_GOT_TPREL16_HA {{0+}} c + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_LO_DS {{0+}} c + 0 -// InputRelocs: R_PPC64_TLS {{0+}} c + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_HA {{0+}} s + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_LO_DS {{0+}} s + 0 -// InputRelocs: R_PPC64_TLS {{0+}} s + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_HA {{0+}} i + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_LO_DS {{0+}} i + 0 -// InputRelocs: R_PPC64_TLS {{0+}} i + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_HA {{0+}} l + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_LO_DS {{0+}} l + 0 -// InputRelocs: R_PPC64_TLS {{0+}} l + 0 -// InputRelocs: R_PPC64_GOT_TPREL16_DS {{0+}} l + 0 -// InputRelocs: R_PPC64_TLS {{0+}} l + 0 - -// Verify that no initial-exec relocations exist for the dynamic linker. -// OutputRelocs-NOT: R_PPC64_TPREL64 {{0+}} c + 0 -// OutputRelocs-NPT: R_PPC64_TPREL64 {{0+}} s + 0 -// OutputRelocs-NOT: R_PPC64_TPREL64 {{0+}} i + 0 -// OutputRelocs-NOT: R_PPC64_TPREL64 {{0+}} l + 0 - -// Dis: test1: -// Dis: nop -// Dis: addis 3, 13, 0 -// Dis: lbz 3, -28672(3) - -// Dis: test2: -// Dis: nop -// Dis: addis 3, 13, 0 -// Dis: lhz 3, -28670(3) - -// Dis: test3: -// Dis: nop -// Dis: addis 3, 13, 0 -// Dis: lwz 3, -28668(3) - -// Dis: test4: -// Dis: nop -// Dis: addis 3, 13, 0 -// Dis: ld 3, -28664(3) - -// Dis: test5: -// Dis: nop -// Dis: addis 4, 13, 0 -// Dis: stb 3, -28672(4) - -// Dis: test6: -// Dis: nop -// Dis: addis 4, 13, 0 -// Dis: sth 3, -28670(4) - -// Dis: test7: -// Dis: nop -// Dis: addis 4, 13, 0 -// Dis: stw 3, -28668(4) - -// Dis: test8: -// Dis: nop -// Dis: addis 4, 13, 0 -// Dis: std 3, -28664(4) - -// Dis: test9: -// Dis: nop -// Dis: addis 3, 13, 0 -// Dis: addi 3, 3, -28668 - -// Dis: test_ds: -// Dis: addis 4, 13, 0 -// Dis: std 3, -28664(4) diff --git a/lld/test/ELF/ppc64-tls-ie.s b/lld/test/ELF/ppc64-tls-ie.s new file mode 100644 index 0000000..aa55090 --- /dev/null +++ b/lld/test/ELF/ppc64-tls-ie.s @@ -0,0 +1,171 @@ +# REQUIRES: ppc + +# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o +# RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=INPUT-REL %s +## IE +# RUN: ld.lld -shared %t.o -o %t.so +# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=IE-REL %s +# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=IE %s +## IE -> LE +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readelf -r %t | FileCheck --check-prefix=NOREL %s +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s + +# RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t.o +# RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=INPUT-REL %s +## IE +# RUN: ld.lld -shared %t.o -o %t.so +# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=IE-REL %s +# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=IE %s +## IE -> LE +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readelf -r %t | FileCheck --check-prefix=NOREL %s +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s + +# IE-REL: .rela.dyn { +# IE-REL-NEXT: 0x200B0 R_PPC64_TPREL64 c 0x0 +# IE-REL-NEXT: 0x200C0 R_PPC64_TPREL64 i 0x0 +# IE-REL-NEXT: 0x200C8 R_PPC64_TPREL64 l 0x0 +# IE-REL-NEXT: 0x200B8 R_PPC64_TPREL64 s 0x0 +# IE-REL-NEXT: } + +# INPUT-REL: R_PPC64_GOT_TPREL16_HA c 0x0 +# INPUT-REL: R_PPC64_GOT_TPREL16_LO_DS c 0x0 +# INPUT-REL: R_PPC64_TLS c 0x0 +## &.got[0] - .TOC. = -32768 +# IE-LABEL: test1: +# IE-NEXT: addis 3, 2, 0 +# IE-NEXT: ld 3, -32768(3) +# IE-NEXT: lbzx 3, 3, 13 +# LE-LABEL: test1: +# LE-NEXT: nop +# LE-NEXT: addis 3, 13, 0 +# LE-NEXT: lbz 3, -28672(3) +test1: + addis 3, 2, c@got@tprel@ha + ld 3, c@got@tprel@l(3) + lbzx 3, 3, c@tls + +# INPUT-REL: R_PPC64_GOT_TPREL16_HA s 0x0 +# INPUT-REL: R_PPC64_GOT_TPREL16_LO_DS s 0x0 +# INPUT-REL: R_PPC64_TLS s 0x0 +## &.got[1] - .TOC. = -32760 +# IE-LABEL: test2: +# IE-NEXT: addis 3, 2, 0 +# IE-NEXT: ld 3, -32760(3) +# IE-NEXT: lhzx 3, 3, 13 +# LE-LABEL: test2: +# LE-NEXT: nop +# LE-NEXT: addis 3, 13, 0 +# LE-NEXT: lhz 3, -28670(3) +test2: + addis 3, 2, s@got@tprel@ha + ld 3, s@got@tprel@l(3) + lhzx 3, 3, s@tls + +# INPUT-REL: R_PPC64_GOT_TPREL16_HA i 0x0 +# INPUT-REL: R_PPC64_GOT_TPREL16_LO_DS i 0x0 +# INPUT-REL: R_PPC64_TLS i 0x0 +## &.got[2] - .TOC. = -32752 +# IE-LABEL: test3: +# IE-NEXT: addis 3, 2, 0 +# IE-NEXT: ld 3, -32752(3) +# IE-NEXT: lwzx 3, 3, 13 +# LE-LABEL: test3: +# LE-NEXT: nop +# LE-NEXT: addis 3, 13, 0 +# LE-NEXT: lwz 3, -28668(3) +test3: + addis 3, 2, i@got@tprel@ha + ld 3, i@got@tprel@l(3) + lwzx 3, 3, i@tls + +# INPUT-REL: R_PPC64_GOT_TPREL16_HA l 0x0 +# INPUT-REL: R_PPC64_GOT_TPREL16_LO_DS l 0x0 +# INPUT-REL: R_PPC64_TLS l 0x0 +## &.got[3] - .TOC. = -32744 +# IE-LABEL: test4: +# IE-NEXT: addis 3, 2, 0 +# IE-NEXT: ld 3, -32744(3) +# IE-NEXT: ldx 3, 3, 13 +# LE-LABEL: test4: +# LE-NEXT: nop +# LE-NEXT: addis 3, 13, 0 +# LE-NEXT: ld 3, -28664(3) +test4: + addis 3, 2, l@got@tprel@ha + ld 3, l@got@tprel@l(3) + ldx 3, 3, l@tls + +# LE-LABEL: test5: +# LE-NEXT: nop +# LE-NEXT: addis 4, 13, 0 +# LE-NEXT: stb 3, -28672(4) +test5: + addis 4, 2, c@got@tprel@ha + ld 4, c@got@tprel@l(4) + stbx 3, 4, c@tls + + +# LE-LABEL: test6: +# LE-NEXT: nop +# LE-NEXT: addis 4, 13, 0 +# LE-NEXT: sth 3, -28670(4) +test6: + addis 4, 2, s@got@tprel@ha + ld 4, s@got@tprel@l(4) + sthx 3, 4, s@tls + + +# LE-LABEL: test7: +# LE-NEXT: nop +# LE-NEXT: addis 4, 13, 0 +# LE-NEXT: stw 3, -28668(4) +test7: + addis 4, 2, i@got@tprel@ha + ld 4, i@got@tprel@l(4) + stwx 3, 4, i@tls + +# LE-LABEL: test8: +# LE-NEXT: nop +# LE-NEXT: addis 4, 13, 0 +# LE-NEXT: std 3, -28664(4) +test8: + addis 4, 2, l@got@tprel@ha + ld 4, l@got@tprel@l(4) + stdx 3, 4, l@tls + +# LE-LABEL: test9: +# LE-NEXT: nop +# LE-NEXT: addis 3, 13, 0 +# LE-NEXT: addi 3, 3, -28668 +test9: + addis 3, 2, i@got@tprel@ha + ld 3, i@got@tprel@l(3) + add 3, 3, i@tls + +# LE-LABEL: test_ds: +# LE-NEXT: addis 4, 13, 0 +# LE-NEXT: std 3, -28664(4) +test_ds: + ld 4, l@got@tprel(2) + stdx 3, 4, l@tls + +# NOREL: There are no relocations in this file. + +.section .tdata,"awT",@progbits +.globl c, s, i, l +c: +.byte 97 + +.p2align 1 +s: +.short 55 + +.p2align 2 +i: +.long 55 + +.p2align 3 +l: +.quad 55