1// REQUIRES: arm
2// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=armv7a-linux-gnueabi
3// RUN: ld.lld %t.o -o %t.so -shared
4// RUN: llvm-readobj -S --dyn-relocations %t.so | FileCheck --check-prefix=SEC %s
5// RUN: llvm-objdump -d --triple=armv7a-linux-gnueabi %t.so | FileCheck %s
6
7/// Test the handling of the global-dynamic TLS model. Dynamic Loader finds
8/// module index R_ARM_TLS_DTPMOD32 and the offset within the module
9/// R_ARM_TLS_DTPOFF32. One of the variables is hidden which permits relaxation
10/// to local dynamic
11
12 .text
13 .syntax unified
14 .globl  func
15 .p2align        2
16 .type   func,%function
17func:
18.L0:
19 nop
20.L1:
21 nop
22.L2:
23 nop
24
25 .p2align        2
26/// Generate R_ARM_TLS_GD32 relocations
27/// Allocates a pair of GOT entries dynamically relocated by R_ARM_TLS_DTPMOD32
28/// and R_ARM_TLS_DTPOFF32 respectively. The literal contains the offset of the
29/// first GOT entry from the place
30.Lt0: .word   x(TLSGD) + (. - .L0 - 8)
31.Lt1: .word   y(TLSGD) + (. - .L1 - 8)
32.Lt2: .word   z(TLSGD) + (. - .L2 - 8)
33
34/// __thread int x = 10
35/// __thread int y;
36/// __thread int z __attribute((visibility("hidden")))
37
38 .hidden z
39 .globl  z
40 .globl  y
41 .globl  x
42
43 .section       .tbss,"awT",%nobits
44 .p2align  2
45.TLSSTART:
46 .type  z, %object
47z:
48 .space 4
49 .type  y, %object
50y:
51 .space 4
52 .section       .tdata,"awT",%progbits
53 .p2align 2
54 .type  x, %object
55x:
56 .word  10
57
58// SEC:      Name: .tdata
59// SEC-NEXT: Type: SHT_PROGBITS
60// SEC-NEXT: Flags [
61// SEC-NEXT:   SHF_ALLOC
62// SEC-NEXT:   SHF_TLS
63// SEC-NEXT:   SHF_WRITE
64// SEC-NEXT:  ]
65// SEC-NEXT: Address: 0x20210
66// SEC:      Size: 4
67// SEC:      Name: .tbss
68// SEC-NEXT: Type: SHT_NOBITS
69// SEC-NEXT: Flags [
70// SEC-NEXT:   SHF_ALLOC
71// SEC-NEXT:   SHF_TLS
72// SEC-NEXT:   SHF_WRITE
73// SEC-NEXT: ]
74// SEC-NEXT: Address: 0x20214
75// SEC:      Size: 8
76
77// SEC:      Name: .got
78// SEC-NEXT: Type: SHT_PROGBITS
79// SEC-NEXT: Flags [
80// SEC-NEXT:   SHF_ALLOC
81// SEC-NEXT:   SHF_WRITE
82// SEC-NEXT: ]
83// SEC-NEXT: Address: 0x20264
84// SEC:      Size: 24
85
86// SEC: Dynamic Relocations {
87// SEC-NEXT: 0x20274 R_ARM_TLS_DTPMOD32 -
88// SEC-NEXT: 0x20264 R_ARM_TLS_DTPMOD32 x
89// SEC-NEXT: 0x20268 R_ARM_TLS_DTPOFF32 x
90// SEC-NEXT: 0x2026C R_ARM_TLS_DTPMOD32 y
91// SEC-NEXT: 0x20270 R_ARM_TLS_DTPOFF32 y
92
93
94// CHECK-LABEL: 000101f8 <func>:
95// CHECK-NEXT:    101f8:      00 f0 20 e3     nop
96// CHECK-NEXT:    101fc:      00 f0 20 e3     nop
97// CHECK-NEXT:    10200:      00 f0 20 e3     nop
98
99/// (0x20264 - 0x1204) + (0x10204 - 0x101f8 - 8) = 0x1f064
100// CHECK:         10204: 64 00 01 00
101/// (0x2026c - 0x10204) + (0x10204 - 0x101fc - 8) = 0x10068
102// CHECK-NEXT:    10208: 68 00 01 00
103/// (0x20274 - 0x10204) + (0x10204 - 0x10200 - 8) = 0x1006c
104// CHECK-NEXT:    1020c: 6c 00 01 00
105
106