lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* glibc test for TLS in ld.so. */ |
| 2 | #undef _LIBC |
| 3 | #include <stdio.h> |
| 4 | |
| 5 | #include <tls.h> |
| 6 | |
| 7 | #ifdef USE_TLS |
| 8 | # include "tls-macros.h" |
| 9 | |
| 10 | |
| 11 | /* Two common 'int' variables in TLS. */ |
| 12 | COMMON_INT_DEF(foo); |
| 13 | COMMON_INT_DEF(bar); |
| 14 | #endif |
| 15 | |
| 16 | |
| 17 | #define TEST_FUNCTION do_test () |
| 18 | static int |
| 19 | do_test (void) |
| 20 | { |
| 21 | #ifdef USE_TLS |
| 22 | int result = 0; |
| 23 | int *ap, *bp; |
| 24 | |
| 25 | |
| 26 | /* Set the variable using the local exec model. */ |
| 27 | puts ("set bar to 1 (LE)"); |
| 28 | ap = TLS_LE (bar); |
| 29 | *ap = 1; |
| 30 | |
| 31 | |
| 32 | /* Get variables using initial exec model. */ |
| 33 | fputs ("get sum of foo and bar (IE)", stdout); |
| 34 | ap = TLS_IE (foo); |
| 35 | bp = TLS_IE (bar); |
| 36 | printf (" = %d\n", *ap + *bp); |
| 37 | result |= *ap + *bp != 1; |
| 38 | if (*ap != 0) |
| 39 | { |
| 40 | printf ("foo = %d\n", *ap); |
| 41 | result = 1; |
| 42 | } |
| 43 | if (*bp != 1) |
| 44 | { |
| 45 | printf ("bar = %d\n", *bp); |
| 46 | result = 1; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /* Get variables using local dynamic model. */ |
| 51 | fputs ("get sum of foo and bar (LD)", stdout); |
| 52 | ap = TLS_LD (foo); |
| 53 | bp = TLS_LD (bar); |
| 54 | printf (" = %d\n", *ap + *bp); |
| 55 | result |= *ap + *bp != 1; |
| 56 | if (*ap != 0) |
| 57 | { |
| 58 | printf ("foo = %d\n", *ap); |
| 59 | result = 1; |
| 60 | } |
| 61 | if (*bp != 1) |
| 62 | { |
| 63 | printf ("bar = %d\n", *bp); |
| 64 | result = 1; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /* Get variables using generic dynamic model. */ |
| 69 | fputs ("get sum of foo and bar (GD)", stdout); |
| 70 | ap = TLS_GD (foo); |
| 71 | bp = TLS_GD (bar); |
| 72 | printf (" = %d\n", *ap + *bp); |
| 73 | result |= *ap + *bp != 1; |
| 74 | if (*ap != 0) |
| 75 | { |
| 76 | printf ("foo = %d\n", *ap); |
| 77 | result = 1; |
| 78 | } |
| 79 | if (*bp != 1) |
| 80 | { |
| 81 | printf ("bar = %d\n", *bp); |
| 82 | result = 1; |
| 83 | } |
| 84 | |
| 85 | return result; |
| 86 | #else |
| 87 | return 0; |
| 88 | #endif |
| 89 | } |
| 90 | |
| 91 | |
| 92 | #include "../test-skeleton.c" |