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

source code of glibc/elf/tst-tls1.c