Use C11-like atomics instead of plain memory accesses in x86 lock elision.
[glibc.git] / elf / tst-tls8.c
blob4bf3e3ffb582dcdb92d1263d4772d028555cd528
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 #include <link.h>
8 #define TEST_FUNCTION do_test ()
9 static int
10 do_test (void)
12 static const char modname1[] = "$ORIGIN/tst-tlsmod3.so";
13 static const char modname2[] = "$ORIGIN/tst-tlsmod4.so";
14 int result = 0;
15 int (*fp1) (void);
16 int (*fp2) (int, int *);
17 void *h1;
18 void *h2;
19 int i;
20 size_t modid1 = (size_t) -1;
21 size_t modid2 = (size_t) -1;
22 int *bazp;
24 for (i = 0; i < 10; ++i)
26 h1 = dlopen (modname1, RTLD_LAZY);
27 if (h1 == NULL)
29 printf ("cannot open '%s': %s\n", modname1, dlerror ());
30 exit (1);
33 /* Dirty test code here: we peek into a private data structure.
34 We make sure that the module gets assigned the same ID every
35 time. The value of the first round is used. */
36 if (modid1 == (size_t) -1)
37 modid1 = ((struct link_map *) h1)->l_tls_modid;
38 else if (((struct link_map *) h1)->l_tls_modid != modid1)
40 printf ("round %d: modid now %zd, initially %zd\n",
41 i, ((struct link_map *) h1)->l_tls_modid, modid1);
42 result = 1;
45 fp1 = dlsym (h1, "in_dso2");
46 if (fp1 == NULL)
48 printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
49 exit (1);
52 result |= fp1 ();
56 h2 = dlopen (modname2, RTLD_LAZY);
57 if (h2 == NULL)
59 printf ("cannot open '%s': %s\n", modname2, dlerror ());
60 exit (1);
63 /* Dirty test code here: we peek into a private data structure.
64 We make sure that the module gets assigned the same ID every
65 time. The value of the first round is used. */
66 if (modid2 == (size_t) -1)
67 modid2 = ((struct link_map *) h1)->l_tls_modid;
68 else if (((struct link_map *) h1)->l_tls_modid != modid2)
70 printf ("round %d: modid now %zd, initially %zd\n",
71 i, ((struct link_map *) h1)->l_tls_modid, modid2);
72 result = 1;
75 bazp = dlsym (h2, "baz");
76 if (bazp == NULL)
78 printf ("cannot get symbol 'baz' in %s\n", modname2);
79 exit (1);
82 *bazp = 42 + i;
84 fp2 = dlsym (h2, "in_dso");
85 if (fp2 == NULL)
87 printf ("cannot get symbol 'in_dso' in %s\n", modname2);
88 exit (1);
91 result |= fp2 (42 + i, bazp);
93 dlclose (h1);
94 dlclose (h2);
97 h1 = dlopen (modname1, RTLD_LAZY);
98 if (h1 == NULL)
100 printf ("cannot open '%s': %s\n", modname1, dlerror ());
101 exit (1);
104 /* Dirty test code here: we peek into a private data structure.
105 We make sure that the module gets assigned the same ID every
106 time. The value of the first round is used. */
107 if (((struct link_map *) h1)->l_tls_modid != modid1)
109 printf ("round %d: modid now %zd, initially %zd\n",
110 i, ((struct link_map *) h1)->l_tls_modid, modid1);
111 result = 1;
114 fp1 = dlsym (h1, "in_dso2");
115 if (fp1 == NULL)
117 printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
118 exit (1);
121 result |= fp1 ();
125 h2 = dlopen (modname2, RTLD_LAZY);
126 if (h2 == NULL)
128 printf ("cannot open '%s': %s\n", modname2, dlerror ());
129 exit (1);
132 /* Dirty test code here: we peek into a private data structure.
133 We make sure that the module gets assigned the same ID every
134 time. The value of the first round is used. */
135 if (((struct link_map *) h1)->l_tls_modid != modid2)
137 printf ("round %d: modid now %zd, initially %zd\n",
138 i, ((struct link_map *) h1)->l_tls_modid, modid2);
139 result = 1;
142 bazp = dlsym (h2, "baz");
143 if (bazp == NULL)
145 printf ("cannot get symbol 'baz' in %s\n", modname2);
146 exit (1);
149 *bazp = 62 + i;
151 fp2 = dlsym (h2, "in_dso");
152 if (fp2 == NULL)
154 printf ("cannot get symbol 'in_dso' in %s\n", modname2);
155 exit (1);
158 result |= fp2 (62 + i, bazp);
160 /* This time the dlclose calls are in reverse order. */
161 dlclose (h2);
162 dlclose (h1);
165 return result;
169 #include "../test-skeleton.c"