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