lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | |
| 3 | #include "tls-macros.h" |
| 4 | |
| 5 | |
| 6 | /* One define int variable, two externs. */ |
| 7 | COMMON_INT_DEF(foo); |
| 8 | VAR_INT_DEF(bar); |
| 9 | VAR_INT_DECL(baz); |
| 10 | |
| 11 | extern int in_dso (void); |
| 12 | |
| 13 | int |
| 14 | in_dso (void) |
| 15 | { |
| 16 | int result = 0; |
| 17 | int *ap, *bp, *cp; |
| 18 | |
| 19 | /* Get variables using initial exec model. */ |
| 20 | fputs ("get sum of foo and bar (IE)", stdout); |
| 21 | asm ("" ::: "memory"); |
| 22 | ap = TLS_IE (foo); |
| 23 | bp = TLS_IE (bar); |
| 24 | printf (" = %d\n", *ap + *bp); |
| 25 | result |= *ap + *bp != 3; |
| 26 | if (*ap != 1) |
| 27 | { |
| 28 | printf ("foo = %d\n", *ap); |
| 29 | result = 1; |
| 30 | } |
| 31 | if (*bp != 2) |
| 32 | { |
| 33 | printf ("bar = %d\n", *bp); |
| 34 | result = 1; |
| 35 | } |
| 36 | |
| 37 | |
| 38 | /* Get variables using generic dynamic model. */ |
| 39 | fputs ("get sum of foo and bar and baz (GD)", stdout); |
| 40 | ap = TLS_GD (foo); |
| 41 | bp = TLS_GD (bar); |
| 42 | cp = TLS_GD (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 | return result; |
| 62 | } |