1 /* glibc test for TLS in ld.so.  */
2 #include <stdio.h>
3 
4 
5 __thread int foo, bar __attribute__ ((tls_model("initial-exec")));
6 __thread int baz __attribute__ ((tls_model("local-exec")));
7 extern __thread int foo_gd __attribute__ ((alias("foo"), tls_model("global-dynamic")));
8 extern __thread int bar_gd __attribute__ ((alias("bar"), tls_model("global-dynamic")));
9 extern __thread int baz_ld __attribute__ ((alias("baz"), tls_model("local-dynamic")));
10 
11 
12 extern int in_dso (void);
13 
14 
15 static int
do_test(void)16 do_test (void)
17 {
18   int result = 0;
19   int *ap, *bp, *cp;
20 
21 
22   /* Set the variable using the local exec model.  */
23   puts ("set baz to 3 (LE)");
24   baz = 3;
25 
26 
27   /* Get variables using initial exec model.  */
28   puts ("set variables foo and bar (IE)");
29   foo = 1;
30   bar = 2;
31 
32 
33   /* Get variables using local dynamic model.  */
34   fputs ("get sum of foo, bar (GD) and baz (LD)", stdout);
35   ap = &foo_gd;
36   bp = &bar_gd;
37   cp = &baz_ld;
38   printf (" = %d\n", *ap + *bp + *cp);
39   result |= *ap + *bp + *cp != 6;
40   if (*ap != 1)
41     {
42       printf ("foo = %d\n", *ap);
43       result = 1;
44     }
45   if (*bp != 2)
46     {
47       printf ("bar = %d\n", *bp);
48       result = 1;
49     }
50   if (*cp != 3)
51     {
52       printf ("baz = %d\n", *cp);
53       result = 1;
54     }
55 
56 
57   result |= in_dso ();
58 
59   return result;
60 }
61 
62 
63 #include <support/test-driver.c>
64