xref: /llvm-project/lld/test/ELF/i386-tls-opt.s (revision 8dc73662ab5f7c992f9d7778de7c3611c1d5367e)
1// REQUIRES: x86
2// RUN: llvm-mc -filetype=obj -triple=i686 %s -o %t.o
3// RUN: ld.lld %t.o -o %t1
4// RUN: llvm-readobj -r %t1 | FileCheck --check-prefix=NORELOC %s
5// RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t1 | FileCheck --check-prefix=DISASM %s
6
7// NORELOC:      Relocations [
8// NORELOC-NEXT: ]
9
10// DISASM:      Disassembly of section .text:
11// DISASM-EMPTY:
12// DISASM-NEXT: <_start>:
13// LD -> LE:
14// DISASM-NEXT:   movl %gs:0, %eax
15// DISASM-NEXT:   nop
16// DISASM-NEXT:   leal (%esi,%eiz), %esi
17// DISASM-NEXT:   leal -8(%eax), %edx
18// DISASM-NEXT:   movl %gs:0, %eax
19// DISASM-NEXT:   nop
20// DISASM-NEXT:   leal (%esi,%eiz), %esi
21// DISASM-NEXT:   leal -4(%eax), %edx
22// DISASM-NEXT:   movl %gs:0, %eax
23// DISASM-NEXT:   leal (%esi), %esi
24// DISASM-NEXT:   movl -4(%eax), %edx
25// IE -> LE:
26// 4294967288 == 0xFFFFFFF8
27// 4294967292 == 0xFFFFFFFC
28// DISASM-NEXT:   movl %gs:0, %eax
29// DISASM-NEXT:   movl $4294967288, %eax
30// DISASM-NEXT:   movl %gs:0, %eax
31// DISASM-NEXT:   movl $4294967292, %eax
32// DISASM-NEXT:   movl %gs:0, %eax
33// DISASM-NEXT:   leal -8(%eax), %eax
34// DISASM-NEXT:   movl %gs:0, %eax
35// DISASM-NEXT:   leal -4(%eax), %eax
36.type tls0,@object
37.section .tbss,"awT",@nobits
38.globl tls0
39.align 4
40tls0:
41 .long 0
42 .size tls0, 4
43
44.type  tls1,@object
45.globl tls1
46.align 4
47tls1:
48 .long 0
49 .size tls1, 4
50
51.section .text
52.globl ___tls_get_addr
53.type ___tls_get_addr,@function
54___tls_get_addr:
55
56.section .text
57.globl _start
58_start:
59//LD -> LE:
60leal tls0@tlsldm(%ebx),%eax
61call ___tls_get_addr@plt
62leal tls0@dtpoff(%eax),%edx
63leal tls1@tlsldm(%ebx),%eax
64call ___tls_get_addr@plt
65leal tls1@dtpoff(%eax),%edx
66// -fno-plt LD -> LE
67leal tls1@tlsldm(%edx),%eax
68call *___tls_get_addr@GOT(%edx)
69movl tls1@dtpoff(%eax), %edx
70//IE -> LE:
71movl %gs:0,%eax
72movl tls0@gotntpoff(%ebx),%eax
73movl %gs:0,%eax
74movl tls1@gotntpoff(%ebx),%eax
75movl %gs:0,%eax
76addl tls0@gotntpoff(%ebx),%eax
77movl %gs:0,%eax
78addl tls1@gotntpoff(%ebx),%eax
79