Update.
[glibc.git] / elf / tst-tls2.c
blob1810ffa1e3505e892f807cb6465ac82fbb49c64c
1 /* glibc test for TLS in ld.so. */
2 #include <stdio.h>
4 #include <tls.h>
5 #include "tls-macros.h"
8 /* Two 'int' variables in TLS. */
9 VAR_INT_DEF(foo);
10 VAR_INT_DEF(bar);
13 int
14 main (void)
16 #ifdef USE_TLS
17 int result = 0;
18 int *ap, *bp;
21 /* Set the variable using the local exec model. */
22 puts ("set bar to 1 (LE)");
23 ap = TLS_LE (bar);
24 *ap = 1;
27 /* Get variables using initial exec model. */
28 fputs ("get sum of foo and bar (IE)", stdout);
29 ap = TLS_IE (foo);
30 bp = TLS_IE (bar);
31 printf (" = %d\n", *ap + *bp);
32 result |= *ap + *bp != 1;
33 if (*ap != 0)
35 printf ("foo = %d\n", *ap);
36 result = 1;
38 if (*bp != 1)
40 printf ("bar = %d\n", *bp);
41 result = 1;
45 /* Get variables using local dynamic model. */
46 fputs ("get sum of foo and bar (LD)", stdout);
47 ap = TLS_LD (foo);
48 bp = TLS_LD (bar);
49 printf (" = %d\n", *ap + *bp);
50 result |= *ap + *bp != 1;
51 if (*ap != 0)
53 printf ("foo = %d\n", *ap);
54 result = 1;
56 if (*bp != 1)
58 printf ("bar = %d\n", *bp);
59 result = 1;
63 /* Get variables using generic dynamic model. */
64 fputs ("get sum of foo and bar (GD)", stdout);
65 ap = TLS_GD (foo);
66 bp = TLS_GD (bar);
67 printf (" = %d\n", *ap + *bp);
68 result |= *ap + *bp != 1;
69 if (*ap != 0)
71 printf ("foo = %d\n", *ap);
72 result = 1;
74 if (*bp != 1)
76 printf ("bar = %d\n", *bp);
77 result = 1;
80 return result;
81 #else
82 return 0;
83 #endif