2.5-18.1
[glibc.git] / elf / tst-tls-dlinfo.c
blobe97b5081fdc5b3df0ae8223a702c28eabc471506
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 #include <tls.h>
8 #define TEST_FUNCTION do_test ()
9 static int
10 do_test (void)
12 #ifdef USE_TLS
13 static const char modname[] = "tst-tlsmod2.so";
14 int result = 0;
15 int *foop;
16 int (*fp) (int, int *);
17 void *h;
19 h = dlopen (modname, RTLD_LAZY);
20 if (h == NULL)
22 printf ("cannot open '%s': %s\n", modname, dlerror ());
23 exit (1);
26 fp = dlsym (h, "in_dso");
27 if (fp == NULL)
29 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
30 exit (1);
33 size_t modid = -1;
34 if (dlinfo (h, RTLD_DI_TLS_MODID, &modid))
36 printf ("dlinfo RTLD_DI_TLS_MODID failed: %s\n", dlerror ());
37 result = 1;
39 else
40 printf ("dlinfo says TLS module ID %Zu\n", modid);
42 void *block;
43 if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
45 printf ("dlinfo RTLD_DI_TLS_DATA failed: %s\n", dlerror ());
46 result = 1;
48 else if (block != NULL)
50 printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be unallocated\n",
51 block);
52 result = 1;
55 result |= fp (0, NULL);
57 foop = dlsym (h, "foo");
58 if (foop == NULL)
60 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
61 exit (1);
63 if (*foop != 16)
65 puts ("foo != 16");
66 result = 1;
69 /* Now the module's TLS block has been used and should appear. */
70 if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
72 printf ("dlinfo RTLD_DI_TLS_DATA failed the second time: %s\n",
73 dlerror ());
74 result = 1;
76 else if (block != foop)
78 printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be %p\n",
79 block, foop);
80 result = 1;
83 dlclose (h);
85 return result;
86 #else
87 return 0;
88 #endif
92 #include "../test-skeleton.c"