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 |
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 (format: "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 | # ifdef __PCREL__ |
26 | asm ("paddi %0,0,foo@got@tlsgd@pcrel,1" : "=b" (tls_arg)); |
27 | # else |
28 | asm ("addi %0,2,foo@got@tlsgd" : "=b" (tls_arg)); |
29 | # endif |
30 | #else |
31 | register unsigned long thread_pointer __asm__ ("r2" ); |
32 | asm ("bcl 20,31,1f\n1:\t" |
33 | "mflr %0\n\t" |
34 | "addis %0,%0,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t" |
35 | "addi %0,%0,_GLOBAL_OFFSET_TABLE_-1b@l\n\t" |
36 | "addi %0,%0,foo@got@tlsgd" : "=b" (tls_arg)); |
37 | #endif |
38 | |
39 | if (tls_arg->ti_module != 0) |
40 | { |
41 | printf (format: "tls_index not optimized, binutils too old?\n" ); |
42 | result = 1; |
43 | } |
44 | else if (tls_arg->ti_offset + thread_pointer != (unsigned long) ap) |
45 | { |
46 | printf (format: "tls_index->ti_offset wrong value\n" ); |
47 | result = 1; |
48 | } |
49 | |
50 | return result; |
51 | } |
52 | |