1# REQUIRES: x86_64-linux 2# RUN: rm -rf %t && mkdir -p %t 3# RUN: split-file %s %t 4# RUN: llvm-mc -triple=x86_64-unknown-linux -filetype=obj -o %t/test_runner.o %t/test_runner.s 5# RUN: llvm-mc -triple=x86_64-unknown-linux -filetype=obj -o %t/external_tls.o %t/external_tls.s 6# RUN: llvm-rtdyld -triple=x86_64-unknown-linux -execute %t/test_runner.o %t/external_tls.o 7 8#--- test_runner.s 9 10_main: 11 12 push %rbx 13 # load the address of the GOT in rbx for the large code model tests 14 lea _GLOBAL_OFFSET_TABLE_(%rip), %rbx 15 16# Test Local Exec TLS Model 17 mov %fs:tls_foo@tpoff, %eax 18 cmp $0x12, %eax 19 je 1f 20 mov $1, %eax 21 jmp 2f 221: 23 24 mov %fs:tls_bar@tpoff, %eax 25 cmp $0x34, %eax 26 je 1f 27 mov $2, %eax 28 jmp 2f 291: 30 31# Test Initial Exec TLS Model 32 mov tls_foo@gottpoff(%rip), %rax 33 mov %fs:(%rax), %eax 34 cmp $0x12, %eax 35 je 1f 36 mov $3, %eax 37 jmp 2f 381: 39 40 mov tls_bar@gottpoff(%rip), %rax 41 mov %fs:(%rax), %eax 42 cmp $0x34, %eax 43 je 1f 44 mov $4, %eax 45 jmp 2f 461: 47 48# Test Local Dynamic TLS Model (small code model) 49 lea tls_foo@tlsld(%rip), %rdi 50 call __tls_get_addr@plt 51 mov tls_foo@dtpoff(%rax), %eax 52 cmp $0x12, %eax 53 je 1f 54 mov $5, %eax 55 jmp 2f 561: 57 58 lea tls_bar@tlsld(%rip), %rdi 59 call __tls_get_addr@plt 60 mov tls_bar@dtpoff(%rax), %eax 61 cmp $0x34, %eax 62 je 1f 63 mov $6, %eax 64 jmp 2f 651: 66 67# Test Local Dynamic TLS Model (large code model) 68 lea tls_foo@tlsld(%rip), %rdi 69 movabs $__tls_get_addr@pltoff, %rax 70 add %rbx, %rax 71 call *%rax 72 mov tls_foo@dtpoff(%rax), %eax 73 cmp $0x12, %eax 74 je 1f 75 mov $7, %eax 76 jmp 2f 771: 78 79 lea tls_bar@tlsld(%rip), %rdi 80 movabs $__tls_get_addr@pltoff, %rax 81 add %rbx, %rax 82 call *%rax 83 mov tls_bar@dtpoff(%rax), %eax 84 cmp $0x34, %eax 85 je 1f 86 mov $8, %eax 87 jmp 2f 881: 89 90# Test Global Dynamic TLS Model (small code model) 91 .byte 0x66 92 leaq tls_foo@tlsgd(%rip), %rdi 93 .byte 0x66, 0x66, 0x48 94 call __tls_get_addr@plt 95 mov (%rax), %eax 96 cmp $0x12, %eax 97 je 1f 98 mov $9, %eax 99 jmp 2f 1001: 101 102 .byte 0x66 103 leaq tls_bar@tlsgd(%rip), %rdi 104 .byte 0x66, 0x66, 0x48 105 call __tls_get_addr@plt 106 mov (%rax), %eax 107 cmp $0x34, %eax 108 je 1f 109 mov $10, %eax 110 jmp 2f 1111: 112 113# Test Global Dynamic TLS Model (large code model) 114 lea tls_foo@tlsgd(%rip), %rdi 115 movabs $__tls_get_addr@pltoff, %rax 116 add %rbx, %rax 117 call *%rax 118 mov (%rax), %eax 119 cmp $0x12, %eax 120 je 1f 121 mov $11, %eax 122 jmp 2f 1231: 124 125 lea tls_bar@tlsgd(%rip), %rdi 126 movabs $__tls_get_addr@pltoff, %rax 127 add %rbx, %rax 128 call *%rax 129 mov (%rax), %eax 130 cmp $0x34, %eax 131 je 1f 132 mov $12, %eax 133 jmp 2f 1341: 135 136# External TLS variable, Local Exec TLS Model (small code model) 137 mov %fs:external_tls_var@tpoff, %eax 138 cmp $0x56, %eax 139 je 1f 140 mov $12, %eax 141 jmp 2f 1421: 143 144# External TLS variable, Global Dynamic TLS Model (small code model) 145 .byte 0x66 146 leaq external_tls_var@tlsgd(%rip), %rdi 147 .byte 0x66, 0x66, 0x48 148 call __tls_get_addr@plt 149 mov (%rax), %eax 150 cmp $0x56, %eax 151 je 1f 152 mov $13, %eax 153 jmp 2f 1541: 155 156 157# Return 0 if all tests are successful 158 xor %eax, %eax 159 1602: 161 pop %rbx 162 ret 163 164 165 .section .tdata, "awT", @progbits 166 167 .global tls_foo 168 .type tls_foo, @object 169 .size tls_foo, 4 170 .align 4 171tls_foo: 172 .long 0x12 173 174 .global tls_bar 175 .type tls_bar, @object 176 .size tls_bar, 4 177 .align 4 178tls_bar: 179 .long 0x34 180 181#--- external_tls.s 182 183 .section .tdata, "awT", @progbits 184 185 .global external_tls_var 186 .type external_tls_var, @object 187 .size external_tls_var, 4 188 .align 4 189external_tls_var: 190 .long 0x56 191