2 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
3 # RUN: echo '.tbss; .globl c; c: .zero 4' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
4 # RUN: ld.lld -shared -soname=t1.so %t1.o -o %t1.so
6 # RUN: ld.lld -shared %t.o %t1.o -o %t.so
7 # RUN: llvm-readobj -r -x .got %t.so | FileCheck --check-prefix=GD-RELA %s
8 # RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t.so | FileCheck --check-prefix=GD %s
10 # RUN: ld.lld -shared %t.o %t1.o -o %t-rel.so -z rel
11 # RUN: llvm-readobj -r -x .got %t-rel.so | FileCheck --check-prefix=GD-REL %s
13 # RUN: ld.lld %t.o %t1.o -o %t
14 # RUN: llvm-readelf -r %t | FileCheck --check-prefix=NOREL %s
15 # RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s
17 # RUN: ld.lld %t.o %t1.so -o %t
18 # RUN: llvm-readobj -r %t | FileCheck --check-prefix=IE-REL %s
19 # RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t | FileCheck --check-prefix=IE %s
21 # GD-RELA: .rela.dyn {
22 # GD-RELA-NEXT: 0x23E0 R_X86_64_TLSDESC - 0xB
23 # GD-RELA-NEXT: 0x23C0 R_X86_64_TLSDESC a 0x0
24 # GD-RELA-NEXT: 0x23D0 R_X86_64_TLSDESC c 0x0
26 # GD-RELA: Hex dump of section '.got':
27 # GD-RELA-NEXT: 0x000023c0 00000000 00000000 00000000 00000000
28 # GD-RELA-NEXT: 0x000023d0 00000000 00000000 00000000 00000000
29 # GD-RELA-NEXT: 0x000023e0 00000000 00000000 00000000 00000000
32 # GD-REL-NEXT: 0x23C8 R_X86_64_TLSDESC -
33 # GD-REL-NEXT: 0x23A8 R_X86_64_TLSDESC a
34 # GD-REL-NEXT: 0x23B8 R_X86_64_TLSDESC c
36 # GD-REL: Hex dump of section '.got':
37 # GD-REL-NEXT: 0x000023a8 00000000 00000000 00000000 00000000
38 # GD-REL-NEXT: 0x000023b8 00000000 00000000 00000000 00000000
39 # GD-REL-NEXT: 0x000023c8 00000000 00000000 0b000000 00000000
41 ## &.rela.dyn[a]-pc = 0x23C0-0x12e7 = 4313
42 # GD: leaq 4313(%rip), %rax
43 # GD-NEXT: 12e7: callq *(%rax)
44 # GD-NEXT: movl %fs:(%rax), %eax
46 ## &.rela.dyn[b]-pc = 0x23E0-0x12f3 = 4333
47 # GD-NEXT: leaq 4333(%rip), %rcx
48 # GD-NEXT: 12f3: movq %rcx, %rax
49 # GD-NEXT: callq *(%rax)
50 # GD-NEXT: movl %fs:(%rax), %eax
52 ## &.rela.dyn[c]-pc = 0x23D0-0x1302 = 4302
53 # GD-NEXT: leaq 4302(%rip), %r15
54 # GD-NEXT: 1302: movq %r15, %rax
55 # GD-NEXT: callq *(%rax)
56 # GD-NEXT: movl %fs:(%rax), %eax
58 ## &.rela.dyn[c]-pc = 0x23D0-0x1312 = 4286
59 # GD-NEXT: leaq 4286(%rip), %r16
60 # GD-NEXT: 1312: movq %r16, %rax
61 # GD-NEXT: callq *(%rax)
62 # GD-NEXT: movl %fs:(%rax), %eax
64 # NOREL: no relocations
66 ## tpoff(a) = st_value(a) - tls_size = -8
69 # LE-NEXT: movl %fs:(%rax), %eax
70 ## tpoff(b) = st_value(b) - tls_size = -5
72 # LE-NEXT: movq %rcx, %rax
74 # LE-NEXT: movl %fs:(%rax), %eax
75 ## tpoff(c) = st_value(c) - tls_size = -4
77 # LE-NEXT: movq %r15, %rax
79 # LE-NEXT: movl %fs:(%rax), %eax
80 ## tpoff(c) = st_value(c) - tls_size = -4
82 # LE-NEXT: movq %r16, %rax
84 # LE-NEXT: movl %fs:(%rax), %eax
87 # IE-REL-NEXT: 0x202388 R_X86_64_TPOFF64 c 0x0
90 ## a is relaxed to use LE.
93 # IE-NEXT: movl %fs:(%rax), %eax
94 # IE-NEXT: movq $-1, %rcx
95 # IE-NEXT: movq %rcx, %rax
97 # IE-NEXT: movl %fs:(%rax), %eax
98 ## &.rela.dyn[c]-pc = 0x202388 - 0x2012aa = 4318
99 # IE-NEXT: movq 4318(%rip), %r15
100 # IE-NEXT: 2012aa: movq %r15, %rax
102 # IE-NEXT: movl %fs:(%rax), %eax
103 ## &.rela.dyn[c]-pc = 0x202388 - 0x2012ba = 4302
104 # IE-NEXT: movq 4302(%rip), %r16
105 # IE-NEXT: 2012ba: movq %r16, %rax
107 # IE-NEXT: movl %fs:(%rax), %eax
109 leaq
a@tlsdesc
(%rip
), %rax
110 call
*a@tlscall
(%rax
)
111 movl
%fs:(%rax
), %eax
113 ## leaq/call may not be adjacent: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5665
114 ## Test non-RAX registers as well.
115 leaq
b@tlsdesc
(%rip
), %rcx
117 call
*b@tlscall
(%rax
)
118 movl
%fs:(%rax
), %eax
120 leaq c@tlsdesc
(%rip
), %r15
122 call
*c@tlscall
(%rax
)
123 movl
%fs:(%rax
), %eax
125 leaq c@tlsdesc
(%rip
), %r16
127 call
*c@tlscall
(%rax
)
128 movl
%fs:(%rax
), %eax