Updated to fedora-glibc-20080612T1619
[glibc.git] / elf / tst-tls-dlinfo.c
blob26c2811178f9c2fd6cd8278f58c06dd4e9b7fde6
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 static const char modname[] = "tst-tlsmod2.so";
13 int result = 0;
14 int *foop;
15 int (*fp) (int, int *);
16 void *h;
18 h = dlopen (modname, RTLD_LAZY);
19 if (h == NULL)
21 printf ("cannot open '%s': %s\n", modname, dlerror ());
22 exit (1);
25 fp = dlsym (h, "in_dso");
26 if (fp == NULL)
28 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
29 exit (1);
32 size_t modid = -1;
33 if (dlinfo (h, RTLD_DI_TLS_MODID, &modid))
35 printf ("dlinfo RTLD_DI_TLS_MODID failed: %s\n", dlerror ());
36 result = 1;
38 else
39 printf ("dlinfo says TLS module ID %Zu\n", modid);
41 void *block;
42 if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
44 printf ("dlinfo RTLD_DI_TLS_DATA failed: %s\n", dlerror ());
45 result = 1;
47 else if (block != NULL)
49 printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be unallocated\n",
50 block);
51 result = 1;
54 result |= fp (0, NULL);
56 foop = dlsym (h, "foo");
57 if (foop == NULL)
59 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
60 exit (1);
62 if (*foop != 16)
64 puts ("foo != 16");
65 result = 1;
68 /* Now the module's TLS block has been used and should appear. */
69 if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
71 printf ("dlinfo RTLD_DI_TLS_DATA failed the second time: %s\n",
72 dlerror ());
73 result = 1;
75 else if (block != foop)
77 printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be %p\n",
78 block, foop);
79 result = 1;
82 dlclose (h);
84 return result;
88 #include "../test-skeleton.c"