.
[glibc/history.git] / elf / tst-tls2.c
blob417489968ec9db2e2f93b017c1b4da68259c26f9
1 /* glibc test for TLS in ld.so. */
2 #include <stdio.h>
4 #include <tls.h>
6 #ifdef USE_TLS
7 # include "tls-macros.h"
10 /* Two 'int' variables in TLS. */
11 VAR_INT_DEF(foo);
12 VAR_INT_DEF(bar);
13 #endif
16 #define TEST_FUNCTION do_test ()
17 static int
18 do_test (void)
20 #ifdef USE_TLS
21 int result = 0;
22 int *ap, *bp;
25 /* Set the variable using the local exec model. */
26 puts ("set bar to 1 (LE)");
27 ap = TLS_LE (bar);
28 *ap = 1;
31 /* Get variables using initial exec model. */
32 fputs ("get sum of foo and bar (IE)", stdout);
33 ap = TLS_IE (foo);
34 bp = TLS_IE (bar);
35 printf (" = %d\n", *ap + *bp);
36 result |= *ap + *bp != 1;
37 if (*ap != 0)
39 printf ("foo = %d\n", *ap);
40 result = 1;
42 if (*bp != 1)
44 printf ("bar = %d\n", *bp);
45 result = 1;
49 /* Get variables using local dynamic model. */
50 fputs ("get sum of foo and bar (LD)", stdout);
51 ap = TLS_LD (foo);
52 bp = TLS_LD (bar);
53 printf (" = %d\n", *ap + *bp);
54 result |= *ap + *bp != 1;
55 if (*ap != 0)
57 printf ("foo = %d\n", *ap);
58 result = 1;
60 if (*bp != 1)
62 printf ("bar = %d\n", *bp);
63 result = 1;
67 /* Get variables using generic dynamic model. */
68 fputs ("get sum of foo and bar (GD)", stdout);
69 ap = TLS_GD (foo);
70 bp = TLS_GD (bar);
71 printf (" = %d\n", *ap + *bp);
72 result |= *ap + *bp != 1;
73 if (*ap != 0)
75 printf ("foo = %d\n", *ap);
76 result = 1;
78 if (*bp != 1)
80 printf ("bar = %d\n", *bp);
81 result = 1;
84 return result;
85 #else
86 return 0;
87 #endif
91 #include "../test-skeleton.c"