1// REQUIRES: ppc
2
3// RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
4// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s
5// RUN: ld.lld  %t.o -o %t
6// RUN: llvm-objdump -d %t | FileCheck --check-prefix=Dis %s
7// RUN: llvm-readelf -r %t | FileCheck --check-prefix=OutputRelocs %s
8
9// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
10// RUN: llvm-readelf -r %t.o | FileCheck --check-prefix=InputRelocs %s
11// RUN: ld.lld  %t.o -o %t
12// RUN: llvm-objdump -d %t | FileCheck --check-prefix=Dis %s
13// RUN: llvm-readelf -r %t | FileCheck --check-prefix=OutputRelocs %s
14
15	.text
16	.abiversion 2
17	.globl	_start                    # -- Begin function _start
18	.p2align	4
19	.type	_start,@function
20_start:                                   # @_start
21.Lfunc_begin0:
22.Lfunc_gep0:
23	addis 2, 12, .TOC.-.Lfunc_gep0@ha
24	addi 2, 2, .TOC.-.Lfunc_gep0@l
25.Lfunc_lep0:
26	.localentry	_start, .Lfunc_lep0-.Lfunc_gep0
27# %bb.0:                                # %entry
28	mflr 0
29	std 31, -8(1)
30	std 0, 16(1)
31	stdu 1, -64(1)
32	mr 31, 1
33	std 30, 48(31)                  # 8-byte Folded Spill
34	li 3, 0
35	stw 3, 44(31)
36	addis 3, 2, a@got@tlsgd@ha
37	addi 3, 3, a@got@tlsgd@l
38	bl __tls_get_addr(a@tlsgd)
39	nop
40	lwz 30, 0(3)
41	extsw 3, 30
42	ld 30, 48(31)                   # 8-byte Folded Reload
43	addi 1, 1, 64
44	ld 0, 16(1)
45	ld 31, -8(1)
46	mtlr 0
47	blr
48	.long	0
49	.quad	0
50.Lfunc_end0:
51	.size	_start, .Lfunc_end0-.Lfunc_begin0
52
53.globl __tls_get_addr
54.type __tls_get_addr,@function
55__tls_get_addr:
56
57                                        # -- End function
58	.type	a,@object               # @a
59	.section	.tdata,"awT",@progbits
60	.globl	a
61	.p2align	2
62a:
63	.long	55                      # 0x37
64	.size	a, 4
65
66// Verify that the input has general-dynamic tls relocation types
67// InputRelocs:  Relocation section '.rela.text'
68// InputRelocs: R_PPC64_GOT_TLSGD16_HA  {{0+}}  a + 0
69// InputRelocs: R_PPC64_GOT_TLSGD16_LO  {{0+}}  a + 0
70// InputRelocs: R_PPC64_TLSGD           {{0+}}  a + 0
71
72// Verify that the general-dynamic sequence is  relaxed to local exec.
73// #ha(a@tprel) --> (0 - 0x7000 + 0x8000) >> 16 = 0
74// #lo(a@tprel)) --> (0 - 0x7000) &  0xFFFF =  -0x7000 = -28672
75// Dis: _start:
76// Dis: nop
77// Dis: addis 3, 13, 0
78// Dis: nop
79// Dis: addi 3, 3, -28672
80
81// Verify that no general-dynamic relocations exist for the dynamic linker.
82// OutputRelocs-NOT: R_PPC64_DTPMOD64
83// OutputRelocs-NOT: R_PPC64_DTPREL64
84