powerpc __tls_get_addr call optimization
[glibc.git] / sysdeps / powerpc / tst-tlsopt-powerpc.c
blobc9a14cbfdc79476b673a3411435970ad779d98c6
1 /* glibc test for __tls_get_addr optimization. */
2 #include <stdio.h>
4 #include "../../elf/tls-macros.h"
5 #include "dl-tls.h"
7 /* common 'int' variable in TLS. */
8 COMMON_INT_DEF(foo);
11 #define TEST_FUNCTION do_test ()
12 static int
13 do_test (void)
15 int result = 0;
17 /* Get variable using general dynamic model. */
18 int *ap = TLS_GD (foo);
19 if (*ap != 0)
21 printf ("foo = %d\n", *ap);
22 result = 1;
25 tls_index *tls_arg;
26 #ifdef __powerpc64__
27 register unsigned long thread_pointer __asm__ ("r13");
28 asm ("addi %0,2,foo@got@tlsgd" : "=r" (tls_arg));
29 #else
30 register unsigned long thread_pointer __asm__ ("r2");
31 asm ("bcl 20,31,1f\n1:\t"
32 "mflr %0\n\t"
33 "addis %0,%0,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t"
34 "addi %0,%0,_GLOBAL_OFFSET_TABLE_-1b@l\n\t"
35 "addi %0,%0,foo@got@tlsgd" : "=b" (tls_arg));
36 #endif
38 if (tls_arg->ti_module != 0)
40 printf ("tls_index not optimized, binutils too old?\n");
41 result = 1;
43 else if (tls_arg->ti_offset + thread_pointer != (unsigned long) ap)
45 printf ("tls_index->ti_offset wrong value\n");
46 result = 1;
49 return result;
52 #include "../../test-skeleton.c"