1// RUN: %clang -c -o %t %s
2// RUN: %llvm_jitlink %t
3//
4// Test that basic ELF TLS work by adding together TLSs with values
5// 0, 1, and -1, and returning the result (0 for success). This setup
6// tests both zero-initialized (.tbss) and non-zero-initialized
7// (.tdata) sections.
8
9 .text
10 .file "tlstest.cpp"
11 .globl main # -- Begin function main
12 .p2align 4, 0x90
13 .type main,@function
14main: # @main
15# %bb.0: # %entry
16 pushq %rbp
17 movq %rsp, %rbp
18 subq $32, %rsp
19 movl $0, -4(%rbp)
20 movl %edi, -8(%rbp)
21 movq %rsi, -16(%rbp)
22 data16
23 leaq x@TLSGD(%rip), %rdi
24 data16
25 data16
26 rex64
27 callq __tls_get_addr@PLT
28 movl (%rax), %eax
29 movl %eax, -24(%rbp) # 4-byte Spill
30 data16
31 leaq y@TLSGD(%rip), %rdi
32 data16
33 data16
34 rex64
35 callq __tls_get_addr@PLT
36 movq %rax, %rcx
37 movl -24(%rbp), %eax # 4-byte Reload
38 movl (%rcx), %ecx
39 addl %ecx, %eax
40 movl %eax, -20(%rbp) # 4-byte Spill
41 data16
42 leaq z@TLSGD(%rip), %rdi
43 data16
44 data16
45 rex64
46 callq __tls_get_addr@PLT
47 movq %rax, %rcx
48 movl -20(%rbp), %eax # 4-byte Reload
49 movl (%rcx), %ecx
50 addl %ecx, %eax
51 addq $32, %rsp
52 popq %rbp
53 retq
54.Lfunc_end0:
55 .size main, .Lfunc_end0-main
56 # -- End function
57 .type x,@object # @x
58 .section .tbss,"awT",@nobits
59 .globl x
60 .p2align 2
61x:
62 .long 0 # 0x0
63 .size x, 4
64
65 .type y,@object # @y
66 .section .tdata,"awT",@progbits
67 .globl y
68 .p2align 2
69y:
70 .long 1 # 0x1
71 .size y, 4
72
73 .type z,@object # @z
74 .globl z
75 .p2align 2
76z:
77 .long 4294967295 # 0xffffffff
78 .size z, 4
79
80 .section ".note.GNU-stack","",@progbits
81 .addrsig
82

source code of compiler-rt/test/orc/TestCases/FreeBSD/x86-64/trivial-tls.S