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