OSDN Git Service

h8300: O_DIRECT and O_DIRECTIRY swapping.
[uclinux-h8/uclibc-ng.git] / 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 dyn_elf *) h1)->dyn->l_tls_modid;
45       else if (((struct dyn_elf *)h1)->dyn->l_tls_modid != (size_t) modid1)
46         {
47           printf ("round %d: modid now %zd, initially %zd\n",
48                   i,
49                   ((struct dyn_elf *)h1)->dyn->l_tls_modid,
50                   modid1);
51           result = 1;
52         }
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)
57         {
58           printf ("round %d: modid now %zd, initially %zd\n",
59                   i, ((struct link_map *) h1)->l_tls_modid, modid1);
60           result = 1;
61         }
62 #endif
63
64       fp1 = dlsym (h1, "in_dso2");
65       if (fp1 == NULL)
66         {
67           printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
68           exit (1);
69         }
70
71       result |= fp1 ();
72
73
74
75       h2 = dlopen (modname2, RTLD_LAZY);
76       if (h2 == NULL)
77         {
78           printf ("cannot open '%s': %s\n", modname2, dlerror ());
79           exit (1);
80         }
81
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)
90         {
91           printf ("round %d: modid now %zd, initially %zd\n",
92                   i,
93                   ((struct dyn_elf *)h2)->dyn->l_tls_modid,
94                   modid2);
95           result = 1;
96         }
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)
101         {
102           printf ("round %d: modid now %zd, initially %zd\n",
103                   i, ((struct link_map *) h2)->l_tls_modid, modid2);
104           result = 1;
105         }
106 #endif
107
108       bazp = dlsym (h2, "baz");
109       if (bazp == NULL)
110         {
111           printf ("cannot get symbol 'baz' in %s\n", modname2);
112           exit (1);
113         }
114
115       *bazp = 42 + i;
116
117       fp2 = dlsym (h2, "in_dso");
118       if (fp2 == NULL)
119         {
120           printf ("cannot get symbol 'in_dso' in %s\n", modname2);
121           exit (1);
122         }
123
124       result |= fp2 (42 + i, bazp);
125
126       dlclose (h1);
127       dlclose (h2);
128
129
130       h1 = dlopen (modname1, RTLD_LAZY);
131       if (h1 == NULL)
132         {
133           printf ("cannot open '%s': %s\n", modname1, dlerror ());
134           exit (1);
135         }
136
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)
143         {
144           printf ("round %d: modid now %zd, initially %zd\n",
145                   i,
146                   ((struct dyn_elf *)h1)->dyn->l_tls_modid,
147                   modid1);
148           result = 1;
149         }
150 #else
151       if (((struct link_map *) h1)->l_tls_modid != modid1)
152         {
153           printf ("round %d: modid now %zd, initially %zd\n",
154                   i, ((struct link_map *) h1)->l_tls_modid, modid1);
155           result = 1;
156         }
157 #endif
158
159       fp1 = dlsym (h1, "in_dso2");
160       if (fp1 == NULL)
161         {
162           printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
163           exit (1);
164         }
165
166       result |= fp1 ();
167
168
169
170       h2 = dlopen (modname2, RTLD_LAZY);
171       if (h2 == NULL)
172         {
173           printf ("cannot open '%s': %s\n", modname2, dlerror ());
174           exit (1);
175         }
176
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)
183         {
184           printf ("round %d: modid now %zd, initially %zd\n",
185                   i,
186                   ((struct dyn_elf *)h2)->dyn->l_tls_modid,
187                   modid2);
188           result = 1;
189         }
190 #else
191       if (((struct link_map *) h2)->l_tls_modid != modid2)
192         {
193           printf ("round %d: modid now %zd, initially %zd\n",
194                   i, ((struct link_map *) h2)->l_tls_modid, modid2);
195           result = 1;
196         }
197 #endif
198
199       bazp = dlsym (h2, "baz");
200       if (bazp == NULL)
201         {
202           printf ("cannot get symbol 'baz' in %s\n", modname2);
203           exit (1);
204         }
205
206       *bazp = 62 + i;
207
208       fp2 = dlsym (h2, "in_dso");
209       if (fp2 == NULL)
210         {
211           printf ("cannot get symbol 'in_dso' in %s\n", modname2);
212           exit (1);
213         }
214
215       result |= fp2 (62 + i, bazp);
216
217       /* This time the dlclose calls are in reverse order.  */
218       dlclose (h2);
219       dlclose (h1);
220     }
221
222   return result;
223 #else
224   return 0;
225 #endif
226 }
227
228
229 #include "../test-skeleton.c"