1 | #include <stdio.h> |
2 | |
3 | |
4 | __thread int foo, bar __attribute__ ((tls_model("global-dynamic" ))); |
5 | extern __thread int baz __attribute__ ((tls_model("global-dynamic" ))); |
6 | extern __thread int foo_ie asm ("foo" ) __attribute__ ((tls_model("initial-exec" ))); |
7 | extern __thread int bar_ie asm ("bar" ) __attribute__ ((tls_model("initial-exec" ))); |
8 | extern __thread int baz_ie asm ("baz" ) __attribute__ ((tls_model("initial-exec" ))); |
9 | |
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 (s: "get sum of foo and bar (IE)" , stdout); |
21 | asm ("" ::: "memory" ); |
22 | ap = &foo_ie; |
23 | bp = &bar_ie; |
24 | printf (format: " = %d\n" , *ap + *bp); |
25 | result |= *ap + *bp != 3; |
26 | if (*ap != 1) |
27 | { |
28 | printf (format: "foo = %d\n" , *ap); |
29 | result = 1; |
30 | } |
31 | if (*bp != 2) |
32 | { |
33 | printf (format: "bar = %d\n" , *bp); |
34 | result = 1; |
35 | } |
36 | |
37 | |
38 | /* Get variables using generic dynamic model or TLSDESC. */ |
39 | fputs (s: "get sum of foo and bar and baz (GD or TLSDESC)" , stdout); |
40 | ap = &foo; |
41 | bp = &bar; |
42 | cp = &baz; |
43 | printf (format: " = %d\n" , *ap + *bp + *cp); |
44 | result |= *ap + *bp + *cp != 6; |
45 | if (*ap != 1) |
46 | { |
47 | printf (format: "foo = %d\n" , *ap); |
48 | result = 1; |
49 | } |
50 | if (*bp != 2) |
51 | { |
52 | printf (format: "bar = %d\n" , *bp); |
53 | result = 1; |
54 | } |
55 | if (*cp != 3) |
56 | { |
57 | printf (format: "baz = %d\n" , *cp); |
58 | result = 1; |
59 | } |
60 | |
61 | return result; |
62 | } |
63 | |