NPTL/arc: notify kernel of the TP value
[uClibc.git] / test / tls / tst-tls8.c
blob140de438ef68ec111ad506f27518f89b5da59b7a
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 #include <tls.h>
6 #include <link.h>
7 #ifdef __UCLIBC__
8 #include "dl-elf.h"
9 #include "dl-hash.h"
10 #endif
13 #define TEST_FUNCTION do_test ()
14 static int
15 do_test (void)
17 #ifdef USE_TLS
18 static const char modname1[] = "tst-tlsmod3.so";
19 static const char modname2[] = "tst-tlsmod4.so";
20 int result = 0;
21 int (*fp1) (void);
22 int (*fp2) (int, int *);
23 void *h1;
24 void *h2;
25 int i;
26 size_t modid1 = (size_t) -1;
27 size_t modid2 = (size_t) -1;
28 int *bazp;
30 for (i = 0; i < 10; ++i)
32 h1 = dlopen (modname1, RTLD_LAZY);
33 if (h1 == NULL)
35 printf ("cannot open '%s': %s\n", modname1, dlerror ());
36 exit (1);
39 /* Dirty test code here: we peek into a private data structure.
40 We make sure that the module gets assigned the same ID every
41 time. The value of the first round is used. */
42 #ifdef __UCLIBC__
43 if (modid1 == (size_t) -1)
44 modid1 = ((struct dyn_elf *) h1)->dyn->l_tls_modid;
45 else if (((struct dyn_elf *)h1)->dyn->l_tls_modid != (size_t) modid1)
47 printf ("round %d: modid now %zd, initially %zd\n",
49 ((struct dyn_elf *)h1)->dyn->l_tls_modid,
50 modid1);
51 result = 1;
53 #else
54 if (modid1 == (size_t) -1)
55 modid1 = ((struct link_map *) h1)->l_tls_modid;
56 else if (((struct link_map *) h1)->l_tls_modid != modid1)
58 printf ("round %d: modid now %zd, initially %zd\n",
59 i, ((struct link_map *) h1)->l_tls_modid, modid1);
60 result = 1;
62 #endif
64 fp1 = dlsym (h1, "in_dso2");
65 if (fp1 == NULL)
67 printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
68 exit (1);
71 result |= fp1 ();
75 h2 = dlopen (modname2, RTLD_LAZY);
76 if (h2 == NULL)
78 printf ("cannot open '%s': %s\n", modname2, dlerror ());
79 exit (1);
82 /* Dirty test code here: we peek into a private data structure.
83 We make sure that the module gets assigned the same ID every
84 time. The value of the first round is used. */
85 #ifdef __UCLIBC__
86 if (modid2 == (size_t) -1)
87 modid2 = ((struct dyn_elf *)h2)->dyn->l_tls_modid;
88 else if (((struct dyn_elf *)h2)->dyn->l_tls_modid
89 != (size_t) modid2)
91 printf ("round %d: modid now %zd, initially %zd\n",
93 ((struct dyn_elf *)h2)->dyn->l_tls_modid,
94 modid2);
95 result = 1;
97 #else
98 if (modid2 == (size_t) -1)
99 modid2 = ((struct link_map *) h2)->l_tls_modid;
100 else if (((struct link_map *) h2)->l_tls_modid != modid2)
102 printf ("round %d: modid now %zd, initially %zd\n",
103 i, ((struct link_map *) h2)->l_tls_modid, modid2);
104 result = 1;
106 #endif
108 bazp = dlsym (h2, "baz");
109 if (bazp == NULL)
111 printf ("cannot get symbol 'baz' in %s\n", modname2);
112 exit (1);
115 *bazp = 42 + i;
117 fp2 = dlsym (h2, "in_dso");
118 if (fp2 == NULL)
120 printf ("cannot get symbol 'in_dso' in %s\n", modname2);
121 exit (1);
124 result |= fp2 (42 + i, bazp);
126 dlclose (h1);
127 dlclose (h2);
130 h1 = dlopen (modname1, RTLD_LAZY);
131 if (h1 == NULL)
133 printf ("cannot open '%s': %s\n", modname1, dlerror ());
134 exit (1);
137 /* Dirty test code here: we peek into a private data structure.
138 We make sure that the module gets assigned the same ID every
139 time. The value of the first round is used. */
140 #ifdef __UCLIBC__
141 if (((struct dyn_elf *)h1)->dyn->l_tls_modid
142 != modid1)
144 printf ("round %d: modid now %zd, initially %zd\n",
146 ((struct dyn_elf *)h1)->dyn->l_tls_modid,
147 modid1);
148 result = 1;
150 #else
151 if (((struct link_map *) h1)->l_tls_modid != modid1)
153 printf ("round %d: modid now %zd, initially %zd\n",
154 i, ((struct link_map *) h1)->l_tls_modid, modid1);
155 result = 1;
157 #endif
159 fp1 = dlsym (h1, "in_dso2");
160 if (fp1 == NULL)
162 printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
163 exit (1);
166 result |= fp1 ();
170 h2 = dlopen (modname2, RTLD_LAZY);
171 if (h2 == NULL)
173 printf ("cannot open '%s': %s\n", modname2, dlerror ());
174 exit (1);
177 /* Dirty test code here: we peek into a private data structure.
178 We make sure that the module gets assigned the same ID every
179 time. The value of the first round is used. */
180 #ifdef __UCLIBC__
181 if (((struct dyn_elf *)h2)->dyn->l_tls_modid
182 != modid2)
184 printf ("round %d: modid now %zd, initially %zd\n",
186 ((struct dyn_elf *)h2)->dyn->l_tls_modid,
187 modid2);
188 result = 1;
190 #else
191 if (((struct link_map *) h2)->l_tls_modid != modid2)
193 printf ("round %d: modid now %zd, initially %zd\n",
194 i, ((struct link_map *) h2)->l_tls_modid, modid2);
195 result = 1;
197 #endif
199 bazp = dlsym (h2, "baz");
200 if (bazp == NULL)
202 printf ("cannot get symbol 'baz' in %s\n", modname2);
203 exit (1);
206 *bazp = 62 + i;
208 fp2 = dlsym (h2, "in_dso");
209 if (fp2 == NULL)
211 printf ("cannot get symbol 'in_dso' in %s\n", modname2);
212 exit (1);
215 result |= fp2 (62 + i, bazp);
217 /* This time the dlclose calls are in reverse order. */
218 dlclose (h2);
219 dlclose (h1);
222 return result;
223 #else
224 return 0;
225 #endif
229 #include "../test-skeleton.c"