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