Commit 78239025 authored by Fangrui Song's avatar Fangrui Song
Browse files

[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
parent 11512e74
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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)

lld/test/ELF/ppc64-gd-to-ie.s

deleted100644 → 0
+0 −100
Original line number Diff line number Diff line
# 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
+0 −112
Original line number Diff line number Diff line
// 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
+0 −102
Original line number Diff line number Diff line
// 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
+34 −25
Original line number Diff line number Diff line
// 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
Loading