(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / elf / tst-tls8.c
blobdd896c4937ef2d0deda257c8280eaec35d082eab
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 #include <link.h>
6 #include <tls.h>
9 #define TEST_FUNCTION do_test ()
10 static int
11 do_test (void)
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 size_t modid1 = (size_t) -1;
23 size_t modid2 = (size_t) -1;
24 int *bazp;
26 for (i = 0; i < 10; ++i)
28 h1 = dlopen (modname1, RTLD_LAZY);
29 if (h1 == NULL)
31 printf ("cannot open '%s': %s\n", modname1, dlerror ());
32 exit (1);
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 == (size_t) -1)
39 modid1 = ((struct link_map *) h1)->l_tls_modid;
40 else if (((struct link_map *) h1)->l_tls_modid != modid1)
42 printf ("round %d: modid now %zd, initially %zd\n",
43 i, ((struct link_map *) h1)->l_tls_modid, modid1);
44 result = 1;
47 fp1 = dlsym (h1, "in_dso2");
48 if (fp1 == NULL)
50 printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
51 exit (1);
54 result |= fp1 ();
58 h2 = dlopen (modname2, RTLD_LAZY);
59 if (h2 == NULL)
61 printf ("cannot open '%s': %s\n", modname2, dlerror ());
62 exit (1);
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 == (size_t) -1)
69 modid2 = ((struct link_map *) h1)->l_tls_modid;
70 else if (((struct link_map *) h1)->l_tls_modid != modid2)
72 printf ("round %d: modid now %zd, initially %zd\n",
73 i, ((struct link_map *) h1)->l_tls_modid, modid2);
74 result = 1;
77 bazp = dlsym (h2, "baz");
78 if (bazp == NULL)
80 printf ("cannot get symbol 'baz' in %s\n", modname2);
81 exit (1);
84 *bazp = 42 + i;
86 fp2 = dlsym (h2, "in_dso");
87 if (fp2 == NULL)
89 printf ("cannot get symbol 'in_dso' in %s\n", modname2);
90 exit (1);
93 result |= fp2 (42 + i, bazp);
95 dlclose (h1);
96 dlclose (h2);
99 h1 = dlopen (modname1, RTLD_LAZY);
100 if (h1 == NULL)
102 printf ("cannot open '%s': %s\n", modname1, dlerror ());
103 exit (1);
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)
111 printf ("round %d: modid now %zd, initially %zd\n",
112 i, ((struct link_map *) h1)->l_tls_modid, modid1);
113 result = 1;
116 fp1 = dlsym (h1, "in_dso2");
117 if (fp1 == NULL)
119 printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
120 exit (1);
123 result |= fp1 ();
127 h2 = dlopen (modname2, RTLD_LAZY);
128 if (h2 == NULL)
130 printf ("cannot open '%s': %s\n", modname2, dlerror ());
131 exit (1);
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)
139 printf ("round %d: modid now %zd, initially %zd\n",
140 i, ((struct link_map *) h1)->l_tls_modid, modid2);
141 result = 1;
144 bazp = dlsym (h2, "baz");
145 if (bazp == NULL)
147 printf ("cannot get symbol 'baz' in %s\n", modname2);
148 exit (1);
151 *bazp = 62 + i;
153 fp2 = dlsym (h2, "in_dso");
154 if (fp2 == NULL)
156 printf ("cannot get symbol 'in_dso' in %s\n", modname2);
157 exit (1);
160 result |= fp2 (62 + i, bazp);
162 /* This time the dlclose calls are in reverse order. */
163 dlclose (h2);
164 dlclose (h1);
167 return result;
168 #else
169 return 0;
170 #endif
174 #include "../test-skeleton.c"