]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/ELF/ppc64-general-dynamic-tls.s
Vendor import of lld trunk r338150:
[FreeBSD/FreeBSD.git] / test / ELF / ppc64-general-dynamic-tls.s
1 // REQUIRES: ppc
2
3 // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
4 // RUN: ld.lld -shared %t.o -o %t.so
5 // RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s
6 // RUN: llvm-readelf -relocations --wide %t.so | FileCheck --check-prefix=OutputRelocs %s
7 // RUN: llvm-objdump --section-headers %t.so | FileCheck --check-prefix=CheckGot %s
8 // RUN: llvm-objdump -D %t.so | FileCheck --check-prefix=Dis %s
9
10 // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
11 // RUN: ld.lld -shared %t.o -o %t.so
12 // RUN: llvm-readelf -relocations --wide %t.o | FileCheck --check-prefix=InputRelocs %s
13 // RUN: llvm-readelf -relocations --wide %t.so | FileCheck --check-prefix=OutputRelocs %s
14 // RUN: llvm-objdump --section-headers %t.so | FileCheck --check-prefix=CheckGot %s
15 // RUN: llvm-objdump -D %t.so | FileCheck --check-prefix=Dis %s
16
17         .text
18         .abiversion 2
19         .globl  test
20         .p2align        4
21         .type   test,@function
22 test:
23 .Lfunc_gep0:
24         addis 2, 12, .TOC.-.Lfunc_gep0@ha
25         addi 2, 2, .TOC.-.Lfunc_gep0@l
26 .Lfunc_lep0:
27         .localentry     test, .Lfunc_lep0-.Lfunc_gep0
28         mflr 0
29         std 31, -8(1)
30         std 0, 16(1)
31         stdu 1, -48(1)
32         mr 31, 1
33         std 30, 32(31)
34         addis 3, 2, i@got@tlsgd@ha
35         addi 3, 3, i@got@tlsgd@l
36         bl __tls_get_addr(i@tlsgd)
37         nop
38         lwz 30, 0(3)
39         extsw 3, 30
40         ld 30, 32(31)
41         addi 1, 1, 48
42         ld 0, 16(1)
43         ld 31, -8(1)
44         mtlr 0
45         blr
46
47
48 test_hi:
49 .Lfunc_gep1:
50   addis 2, 12, .TOC.-.Lfunc_gep1@ha
51   addi  2, 2,  .TOC.-.Lfunc_gep1@l
52 .Lfunc_lep1:
53   .localentry test2, .Lfunc_lep1-.Lfunc_gep1
54   addis 3, 0, j@got@tlsgd@h
55   blr
56
57 test_16:
58 .Lfunc_gep2:
59   addis 2, 12, .TOC.-.Lfunc_gep2@ha
60   addi 2, 2, .TOC.-.Lfunc_gep2@l
61 .Lfunc_lep2:
62   .localentry test16, .Lfunc_lep2-.Lfunc_gep2
63   addi 3, 0, k@got@tlsgd
64   blr
65
66 // Verify that the input has every general-dynamic tls relocation type.
67 // InputRelocs:  Relocation section '.rela.text'
68 // InputRelocs: R_PPC64_GOT_TLSGD16_HA  {{0+}}  i + 0
69 // InputRelocs: R_PPC64_GOT_TLSGD16_LO  {{0+}}  i + 0
70 // InputRelocs: R_PPC64_TLSGD           {{0+}}  i + 0
71 // InputRelocs: R_PPC64_GOT_TLSGD16_HI  {{0+}}  j + 0
72 // InputRelocs: R_PPC64_GOT_TLSGD16     {{0+}}  k + 0
73
74 // There is 2 got entries for each tls variable that is accessed with the
75 // general-dynamic model.  The entries can be though of as a structure to be
76 // filled in by the dynamic linker:
77 // typedef struct {
78 //  unsigned long int ti_module; --> R_PPC64_DTPMOD64
79 //  unsigned long int ti_offset; --> R_PPC64_DTPREL64
80 //} tls_index;
81 // OutputRelocs: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 6 entries:
82 // OutputRelocs: R_PPC64_DTPMOD64  {{0+}}  i + 0
83 // OutputRelocs: R_PPC64_DTPREL64  {{0+}}  i + 0
84 // OutputRelocs: R_PPC64_DTPMOD64  {{0+}}  j + 0
85 // OutputRelocs: R_PPC64_DTPREL64  {{0+}}  j + 0
86 // OutputRelocs: R_PPC64_DTPMOD64  {{0+}}  k + 0
87 // OutputRelocs: R_PPC64_DTPREL64  {{0+}}  k + 0
88
89 // Check that the got has 7 entires. (1 for the TOC and 3 structures of
90 // 2 entries for the tls variables). Also verify the address so we can check
91 // the offsets we calculated for each relocation type.
92 // CheckGot: got          00000038 00000000000200f0
93
94 // got starts at 0x200f0, so .TOC. will be 0x280f0.
95
96 // We are building the address of the first tls_index in the got which starts at
97 // 0x200f8 (got[1]).
98 // #ha(i@got@tlsgd) --> (0x200f8 - 0x280f0 + 0x8000) >> 16 = 0
99 // #lo(i@got@tlsgd) --> (0x200f8 - 0x280f0) & 0xFFFF =  -7ff8 = -32760
100 // Dis:  test:
101 // Dis:    addis 3, 2, 0
102 // Dis:    addi 3, 3, -32760
103
104 // Second tls_index starts at got[3].
105 // #hi(j@got@tlsgd) --> (0x20108 - 0x280f0) >> 16 = -1
106 // Dis: test_hi:
107 // Dis:   lis 3, -1
108
109 // Third tls index is at got[5].
110 // k@got@tlsgd --> (0x20118 -  0x280f0) = -0x7fd8 = -32728
111 // Dis: test_16:
112 // Dis:   li 3, -32728