]> git.ipfire.org Git - thirdparty/glibc.git/blob - elf/tst-tls2.c
[BZ #2510, BZ #2830, BZ #3137, BZ #3313, BZ #3426, BZ #3465, BZ #3480, BZ #3483,...
[thirdparty/glibc.git] / elf / tst-tls2.c
1 /* glibc test for TLS in ld.so. */
2 #include <stdio.h>
3
4 #include <tls.h>
5
6 #include "tls-macros.h"
7
8
9 /* Two 'int' variables in TLS. */
10 VAR_INT_DEF(foo);
11 VAR_INT_DEF(bar);
12
13
14 #define TEST_FUNCTION do_test ()
15 static int
16 do_test (void)
17 {
18 int result = 0;
19 int *ap, *bp;
20
21
22 /* Set the variable using the local exec model. */
23 puts ("set bar to 1 (LE)");
24 ap = TLS_LE (bar);
25 *ap = 1;
26
27
28 /* Get variables using initial exec model. */
29 fputs ("get sum of foo and bar (IE)", stdout);
30 ap = TLS_IE (foo);
31 bp = TLS_IE (bar);
32 printf (" = %d\n", *ap + *bp);
33 result |= *ap + *bp != 1;
34 if (*ap != 0)
35 {
36 printf ("foo = %d\n", *ap);
37 result = 1;
38 }
39 if (*bp != 1)
40 {
41 printf ("bar = %d\n", *bp);
42 result = 1;
43 }
44
45
46 /* Get variables using local dynamic model. */
47 fputs ("get sum of foo and bar (LD)", stdout);
48 ap = TLS_LD (foo);
49 bp = TLS_LD (bar);
50 printf (" = %d\n", *ap + *bp);
51 result |= *ap + *bp != 1;
52 if (*ap != 0)
53 {
54 printf ("foo = %d\n", *ap);
55 result = 1;
56 }
57 if (*bp != 1)
58 {
59 printf ("bar = %d\n", *bp);
60 result = 1;
61 }
62
63
64 /* Get variables using generic dynamic model. */
65 fputs ("get sum of foo and bar (GD)", stdout);
66 ap = TLS_GD (foo);
67 bp = TLS_GD (bar);
68 printf (" = %d\n", *ap + *bp);
69 result |= *ap + *bp != 1;
70 if (*ap != 0)
71 {
72 printf ("foo = %d\n", *ap);
73 result = 1;
74 }
75 if (*bp != 1)
76 {
77 printf ("bar = %d\n", *bp);
78 result = 1;
79 }
80
81 return result;
82 }
83
84
85 #include "../test-skeleton.c"