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