lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* glibc test for __tls_get_addr optimization. */ |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | #include "../../elf/tls-macros.h" |
| 5 | #include "dl-tls.h" |
| 6 | |
| 7 | /* common 'int' variable in TLS. */ |
| 8 | COMMON_INT_DEF(foo); |
| 9 | |
| 10 | |
| 11 | #define TEST_FUNCTION do_test () |
| 12 | static int |
| 13 | do_test (void) |
| 14 | { |
| 15 | int result = 0; |
| 16 | |
| 17 | /* Get variable using general dynamic model. */ |
| 18 | int *ap = TLS_GD (foo); |
| 19 | if (*ap != 0) |
| 20 | { |
| 21 | printf ("foo = %d\n", *ap); |
| 22 | result = 1; |
| 23 | } |
| 24 | |
| 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 |
| 37 | |
| 38 | if (tls_arg->ti_module != 0) |
| 39 | { |
| 40 | printf ("tls_index not optimized, binutils too old?\n"); |
| 41 | result = 1; |
| 42 | } |
| 43 | else if (tls_arg->ti_offset + thread_pointer != (unsigned long) ap) |
| 44 | { |
| 45 | printf ("tls_index->ti_offset wrong value\n"); |
| 46 | result = 1; |
| 47 | } |
| 48 | |
| 49 | return result; |
| 50 | } |
| 51 | |
| 52 | #include "../../test-skeleton.c" |