Update.
[glibc.git] / elf / tst-tls1.c
blob4d0913890c1a982dde50843764319e4c5246b9ae
1 /* glibc test for TLS in ld.so. */
2 #include <stdio.h>
4 #include <tls.h>
7 /* XXX Until gcc gets told how to define and use thread-local
8 variables we will have to resort to use asms. */
9 //asm (".tls_common foo,4,4");
10 asm (".section \".tdata\", \"awT\", @progbits\n\t"
11 ".align 4\n\t"
12 ".globl foo\n"
13 "foo:\t.long 0\n\t"
14 ".globl bar\n"
15 "bar:\t.long 0\n\t"
16 ".previous");
19 int
20 main (void)
22 #ifdef USE_TLS
23 int result = 0;
24 int a, b;
26 /* XXX Each architecture must have its own asm for now. */
27 # ifdef __i386__
28 /* Set the variable using the local exec model. */
29 puts ("set bar to 1 (LE)");
30 asm ("movl %gs:0,%eax\n\t"
31 "subl $bar@tpoff,%eax\n\t"
32 "movl $1,(%eax)");
34 #if 0
35 // XXX Doesn't work yet; no runtime relocations.
36 fputs ("get sum of foo and bar (IE)", stdout);
37 asm ("call 1f\n\t"
38 ".subsection 1\n"
39 "1:\tmovl (%%esp), %%ebx\n\t"
40 "ret\n\t"
41 ".previous\n\t"
42 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t"
43 "movl %%gs:0,%%eax\n\t"
44 "movl %%eax,%%edx\n\t"
45 "addl foo@gottpoff(%%ebx),%%eax\n\t"
46 "addl bar@gottpoff(%%ebx),%%eax\n\t"
47 "movl (%%eax), %0\n\t"
48 "addl (%%edx), %0"
49 : "=a" (a), "=&b" (b));
50 printf (" = %d\n", a);
51 result |= a != 1;
52 #endif
54 fputs ("get sum of foo and bar (GD)", stdout);
55 asm ("call 1f\n\t"
56 ".subsection 1\n"
57 "1:\tmovl (%%esp), %%ebx\n\t"
58 "ret\n\t"
59 ".previous\n\t"
60 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t"
61 "leal foo@tlsgd(%%ebx),%%eax\n\t"
62 "call ___tls_get_addr@plt\n\t"
63 "nop\n\t"
64 "movl (%%eax), %%edx\n\t"
65 "leal bar@tlsgd(%%ebx),%%eax\n\t"
66 "call ___tls_get_addr@plt\n\t"
67 "nop\n\t"
68 "addl (%%eax), %%edx\n\t"
69 : "=&a" (a), "=d" (b));
70 printf (" = %d\n", b);
71 result |= b != 1;
73 # else
74 # error "No support for this architecture so far."
75 # endif
77 return result;
78 #else
79 return 0;
80 #endif