1 /* shared library to test for __tls_get_addr optimization. */
2 #include <stdio.h>
3
4 #include "dl-tls.h"
5
6 __thread int foo __attribute__ ((tls_model("global-dynamic")));
7
8
9 int
tls_get_addr_opt_test(void)10 tls_get_addr_opt_test (void)
11 {
12 int result = 0;
13
14 /* Get variable using general dynamic model. */
15 int *ap = &foo;
16 if (*ap != 0)
17 {
18 printf ("foo = %d\n", *ap);
19 result = 1;
20 }
21
22 tls_index *tls_arg;
23 #ifdef __powerpc64__
24 register unsigned long thread_pointer __asm__ ("r13");
25 asm ("addi %0,2,foo@got@tlsgd" : "=r" (tls_arg));
26 #else
27 register unsigned long thread_pointer __asm__ ("r2");
28 asm ("bcl 20,31,1f\n1:\t"
29 "mflr %0\n\t"
30 "addis %0,%0,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t"
31 "addi %0,%0,_GLOBAL_OFFSET_TABLE_-1b@l\n\t"
32 "addi %0,%0,foo@got@tlsgd" : "=b" (tls_arg));
33 #endif
34
35 if (tls_arg->ti_module != 0)
36 {
37 printf ("tls_index not optimized, binutils too old?\n");
38 result = 1;
39 }
40 else if (tls_arg->ti_offset + thread_pointer != (unsigned long) ap)
41 {
42 printf ("tls_index->ti_offset wrong value\n");
43 result = 1;
44 }
45
46 return result;
47 }
48