]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/test/tls/tst-tls8.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / test / tls / tst-tls8.c
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #include <tls.h>
6 #include <link.h>
7 #ifdef __UCLIBC__
8 #include "dl-elf.h"
9 #include "dl-hash.h"
10 #endif
11
12
13 #define TEST_FUNCTION do_test ()
14 static int
15 do_test (void)
16 {
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;
29
30   for (i = 0; i < 10; ++i)
31     {
32       h1 = dlopen (modname1, RTLD_LAZY);
33       if (h1 == NULL)
34         {
35           printf ("cannot open '%s': %s\n", modname1, dlerror ());
36           exit (1);
37         }
38
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 link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid;
45       else if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
46         != (size_t) modid1)
47         {
48           printf ("round %d: modid now %zd, initially %zd\n",
49                   i,
50                   ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
51                   modid1);
52           result = 1;
53         }
54 #else
55       if (modid1 == (size_t) -1)
56         modid1 = ((struct link_map *) h1)->l_tls_modid;
57       else if (((struct link_map *) h1)->l_tls_modid != modid1)
58         {
59           printf ("round %d: modid now %zd, initially %zd\n",
60                   i, ((struct link_map *) h1)->l_tls_modid, modid1);
61           result = 1;
62         }
63 #endif
64
65       fp1 = dlsym (h1, "in_dso2");
66       if (fp1 == NULL)
67         {
68           printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
69           exit (1);
70         }
71
72       result |= fp1 ();
73
74
75
76       h2 = dlopen (modname2, RTLD_LAZY);
77       if (h2 == NULL)
78         {
79           printf ("cannot open '%s': %s\n", modname2, dlerror ());
80           exit (1);
81         }
82
83       /* Dirty test code here: we peek into a private data structure.
84          We make sure that the module gets assigned the same ID every
85          time.  The value of the first round is used.  */
86 #ifdef __UCLIBC__
87       if (modid2 == (size_t) -1)
88         modid2 = ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid;
89       else if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
90         != (size_t) modid2)
91         {
92           printf ("round %d: modid now %zd, initially %zd\n",
93                   i,
94                   ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
95                   modid2);
96           result = 1;
97         }
98 #else
99       if (modid2 == (size_t) -1)
100         modid2 = ((struct link_map *) h1)->l_tls_modid;
101       else if (((struct link_map *) h1)->l_tls_modid != modid2)
102         {
103           printf ("round %d: modid now %zd, initially %zd\n",
104                   i, ((struct link_map *) h1)->l_tls_modid, modid2);
105           result = 1;
106         }
107 #endif
108
109       bazp = dlsym (h2, "baz");
110       if (bazp == NULL)
111         {
112           printf ("cannot get symbol 'baz' in %s\n", modname2);
113           exit (1);
114         }
115
116       *bazp = 42 + i;
117
118       fp2 = dlsym (h2, "in_dso");
119       if (fp2 == NULL)
120         {
121           printf ("cannot get symbol 'in_dso' in %s\n", modname2);
122           exit (1);
123         }
124
125       result |= fp2 (42 + i, bazp);
126
127       dlclose (h1);
128       dlclose (h2);
129
130
131       h1 = dlopen (modname1, RTLD_LAZY);
132       if (h1 == NULL)
133         {
134           printf ("cannot open '%s': %s\n", modname1, dlerror ());
135           exit (1);
136         }
137
138       /* Dirty test code here: we peek into a private data structure.
139          We make sure that the module gets assigned the same ID every
140          time.  The value of the first round is used.  */
141 #ifdef __UCLIBC__
142       if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
143         != modid1)
144         {
145           printf ("round %d: modid now %zd, initially %zd\n",
146                   i,
147                   ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
148                   modid1);
149           result = 1;
150         }
151 #else
152       if (((struct link_map *) h1)->l_tls_modid != modid1)
153         {
154           printf ("round %d: modid now %zd, initially %zd\n",
155                   i, ((struct link_map *) h1)->l_tls_modid, modid1);
156           result = 1;
157         }
158 #endif
159
160       fp1 = dlsym (h1, "in_dso2");
161       if (fp1 == NULL)
162         {
163           printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
164           exit (1);
165         }
166
167       result |= fp1 ();
168
169
170
171       h2 = dlopen (modname2, RTLD_LAZY);
172       if (h2 == NULL)
173         {
174           printf ("cannot open '%s': %s\n", modname2, dlerror ());
175           exit (1);
176         }
177
178       /* Dirty test code here: we peek into a private data structure.
179          We make sure that the module gets assigned the same ID every
180          time.  The value of the first round is used.  */
181 #ifdef __UCLIBC__
182       if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
183         != modid2)
184         {
185           printf ("round %d: modid now %zd, initially %zd\n",
186                   i,
187                   ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
188                   modid2);
189           result = 1;
190         }
191 #else
192       if (((struct link_map *) h1)->l_tls_modid != modid2)
193         {
194           printf ("round %d: modid now %zd, initially %zd\n",
195                   i, ((struct link_map *) h1)->l_tls_modid, modid2);
196           result = 1;
197         }
198 #endif
199
200       bazp = dlsym (h2, "baz");
201       if (bazp == NULL)
202         {
203           printf ("cannot get symbol 'baz' in %s\n", modname2);
204           exit (1);
205         }
206
207       *bazp = 62 + i;
208
209       fp2 = dlsym (h2, "in_dso");
210       if (fp2 == NULL)
211         {
212           printf ("cannot get symbol 'in_dso' in %s\n", modname2);
213           exit (1);
214         }
215
216       result |= fp2 (62 + i, bazp);
217
218       /* This time the dlclose calls are in reverse order.  */
219       dlclose (h2);
220       dlclose (h1);
221     }
222
223   return result;
224 #else
225   return 0;
226 #endif
227 }
228
229
230 #include "../test-skeleton.c"