]> git.ipfire.org Git - thirdparty/glibc.git/blob - elf/tst-tls8.c
* sysdeps/generic/ldsodefs.h (struct rtld_global): Move all [USE_TLS]
[thirdparty/glibc.git] / elf / tst-tls8.c
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #include <link.h>
6 #include <tls.h>
7
8
9 #define TEST_FUNCTION do_test ()
10 static int
11 do_test (void)
12 {
13 #ifdef USE_TLS
14 static const char modname1[] = "tst-tlsmod3.so";
15 static const char modname2[] = "tst-tlsmod4.so";
16 int result = 0;
17 int (*fp1) (void);
18 int (*fp2) (int, int *);
19 void *h1;
20 void *h2;
21 int i;
22 int modid1 = -1;
23 int modid2 = -1;
24 int *bazp;
25
26 for (i = 0; i < 10; ++i)
27 {
28 h1 = dlopen (modname1, RTLD_LAZY);
29 if (h1 == NULL)
30 {
31 printf ("cannot open '%s': %s\n", modname1, dlerror ());
32 exit (1);
33 }
34
35 /* Dirty test code here: we peek into a private data structure.
36 We make sure that the module gets assigned the same ID every
37 time. The value of the first round is used. */
38 if (modid1 == -1)
39 modid1 = ((struct link_map *) h1)->l_tls_modid;
40 else if (((struct link_map *) h1)->l_tls_modid != modid1)
41 {
42 printf ("round %d: modid now %zd, initially %d\n",
43 i, ((struct link_map *) h1)->l_tls_modid, modid1);
44 result = 1;
45 }
46
47 fp1 = dlsym (h1, "in_dso2");
48 if (fp1 == NULL)
49 {
50 printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
51 exit (1);
52 }
53
54 result |= fp1 ();
55
56
57
58 h2 = dlopen (modname2, RTLD_LAZY);
59 if (h2 == NULL)
60 {
61 printf ("cannot open '%s': %s\n", modname2, dlerror ());
62 exit (1);
63 }
64
65 /* Dirty test code here: we peek into a private data structure.
66 We make sure that the module gets assigned the same ID every
67 time. The value of the first round is used. */
68 if (modid2 == -1)
69 modid2 = ((struct link_map *) h1)->l_tls_modid;
70 else if (((struct link_map *) h1)->l_tls_modid != modid2)
71 {
72 printf ("round %d: modid now %zd, initially %d\n",
73 i, ((struct link_map *) h1)->l_tls_modid, modid2);
74 result = 1;
75 }
76
77 bazp = dlsym (h2, "baz");
78 if (bazp == NULL)
79 {
80 printf ("cannot get symbol 'baz' in %s\n", modname2);
81 exit (1);
82 }
83
84 *bazp = 42 + i;
85
86 fp2 = dlsym (h2, "in_dso");
87 if (fp2 == NULL)
88 {
89 printf ("cannot get symbol 'in_dso' in %s\n", modname2);
90 exit (1);
91 }
92
93 result |= fp2 (42 + i, bazp);
94
95 dlclose (h1);
96 dlclose (h2);
97
98
99 h1 = dlopen (modname1, RTLD_LAZY);
100 if (h1 == NULL)
101 {
102 printf ("cannot open '%s': %s\n", modname1, dlerror ());
103 exit (1);
104 }
105
106 /* Dirty test code here: we peek into a private data structure.
107 We make sure that the module gets assigned the same ID every
108 time. The value of the first round is used. */
109 if (((struct link_map *) h1)->l_tls_modid != modid1)
110 {
111 printf ("round %d: modid now %zd, initially %d\n",
112 i, ((struct link_map *) h1)->l_tls_modid, modid1);
113 result = 1;
114 }
115
116 fp1 = dlsym (h1, "in_dso2");
117 if (fp1 == NULL)
118 {
119 printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
120 exit (1);
121 }
122
123 result |= fp1 ();
124
125
126
127 h2 = dlopen (modname2, RTLD_LAZY);
128 if (h2 == NULL)
129 {
130 printf ("cannot open '%s': %s\n", modname2, dlerror ());
131 exit (1);
132 }
133
134 /* Dirty test code here: we peek into a private data structure.
135 We make sure that the module gets assigned the same ID every
136 time. The value of the first round is used. */
137 if (((struct link_map *) h1)->l_tls_modid != modid2)
138 {
139 printf ("round %d: modid now %zd, initially %d\n",
140 i, ((struct link_map *) h1)->l_tls_modid, modid2);
141 result = 1;
142 }
143
144 bazp = dlsym (h2, "baz");
145 if (bazp == NULL)
146 {
147 printf ("cannot get symbol 'baz' in %s\n", modname2);
148 exit (1);
149 }
150
151 *bazp = 62 + i;
152
153 fp2 = dlsym (h2, "in_dso");
154 if (fp2 == NULL)
155 {
156 printf ("cannot get symbol 'in_dso' in %s\n", modname2);
157 exit (1);
158 }
159
160 result |= fp2 (62 + i, bazp);
161
162 /* This time the dlclose calls are in reverse order. */
163 dlclose (h2);
164 dlclose (h1);
165 }
166
167 return result;
168 #else
169 return 0;
170 #endif
171 }
172
173
174 #include "../test-skeleton.c"