Deprecate readdir_r, readdir64_r [BZ #19056]
[glibc.git] / elf / tst-tls6.c
blob9e6235f1d34782da8ef46c1c536b142c8b7bae8e
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 modname[] = "tst-tlsmod2.so";
13 int result = 0;
14 int *foop;
15 int *foop2;
16 int (*fp) (int, int *);
17 void *h;
18 int i;
19 int modid = -1;
21 for (i = 0; i < 10; ++i)
23 h = dlopen (modname, RTLD_LAZY);
24 if (h == NULL)
26 printf ("cannot open '%s': %s\n", modname, dlerror ());
27 exit (1);
30 /* Dirty test code here: we peek into a private data structure.
31 We make sure that the module gets assigned the same ID every
32 time. The value of the first round is used. */
33 if (modid == -1)
34 modid = ((struct link_map *) h)->l_tls_modid;
35 else if (((struct link_map *) h)->l_tls_modid != modid)
37 printf ("round %d: modid now %zd, initially %d\n",
38 i, ((struct link_map *) h)->l_tls_modid, modid);
39 result = 1;
42 foop = dlsym (h, "foo");
43 if (foop == NULL)
45 printf ("cannot get symbol 'foo': %s\n", dlerror ());
46 exit (1);
49 *foop = 42 + i;
51 fp = dlsym (h, "in_dso");
52 if (fp == NULL)
54 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
55 exit (1);
58 result |= fp (42 + i, foop);
60 foop2 = dlsym (h, "foo");
61 if (foop2 == NULL)
63 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
64 exit (1);
67 if (foop != foop2)
69 puts ("address of 'foo' different the second time");
70 result = 1;
72 else if (*foop != 16)
74 puts ("foo != 16");
75 result = 1;
78 dlclose (h);
81 return result;
85 #include "../test-skeleton.c"