lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* glibc test for TLS in ld.so. */ |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | #include "tls-macros.h" |
| 5 | |
| 6 | |
| 7 | /* One define int variable, two externs. */ |
| 8 | COMMON_INT_DECL(foo); |
| 9 | VAR_INT_DECL(bar); |
| 10 | VAR_INT_DEF(baz); |
| 11 | |
| 12 | |
| 13 | extern int in_dso (void); |
| 14 | |
| 15 | |
| 16 | #define TEST_FUNCTION do_test () |
| 17 | static int |
| 18 | do_test (void) |
| 19 | { |
| 20 | int result = 0; |
| 21 | int *ap, *bp, *cp; |
| 22 | |
| 23 | |
| 24 | /* Set the variable using the local exec model. */ |
| 25 | puts ("set baz to 3 (LE)"); |
| 26 | ap = TLS_LE (baz); |
| 27 | *ap = 3; |
| 28 | |
| 29 | |
| 30 | /* Get variables using initial exec model. */ |
| 31 | puts ("set variables foo and bar (IE)"); |
| 32 | ap = TLS_IE (foo); |
| 33 | *ap = 1; |
| 34 | bp = TLS_IE (bar); |
| 35 | *bp = 2; |
| 36 | |
| 37 | |
| 38 | /* Get variables using local dynamic model. */ |
| 39 | fputs ("get sum of foo, bar (GD) and baz (LD)", stdout); |
| 40 | ap = TLS_GD (foo); |
| 41 | bp = TLS_GD (bar); |
| 42 | cp = TLS_LD (baz); |
| 43 | printf (" = %d\n", *ap + *bp + *cp); |
| 44 | result |= *ap + *bp + *cp != 6; |
| 45 | if (*ap != 1) |
| 46 | { |
| 47 | printf ("foo = %d\n", *ap); |
| 48 | result = 1; |
| 49 | } |
| 50 | if (*bp != 2) |
| 51 | { |
| 52 | printf ("bar = %d\n", *bp); |
| 53 | result = 1; |
| 54 | } |
| 55 | if (*cp != 3) |
| 56 | { |
| 57 | printf ("baz = %d\n", *cp); |
| 58 | result = 1; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | result |= in_dso (); |
| 63 | |
| 64 | return result; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | #include "../test-skeleton.c" |