manual: Document getcontext uc_stack value on Linux [BZ #759]
[glibc.git] / elf / tst-tls-dlinfo.c
blob7d2b42e2ab4d83defbaf3e57e86ff1d9f370820b
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
6 static int
7 do_test (void)
9 static const char modname[] = "tst-tlsmod2.so";
10 int result = 0;
11 int *foop;
12 int (*fp) (int, int *);
13 void *h;
15 h = dlopen (modname, RTLD_LAZY);
16 if (h == NULL)
18 printf ("cannot open '%s': %s\n", modname, dlerror ());
19 exit (1);
22 fp = dlsym (h, "in_dso");
23 if (fp == NULL)
25 printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
26 exit (1);
29 size_t modid = -1;
30 if (dlinfo (h, RTLD_DI_TLS_MODID, &modid))
32 printf ("dlinfo RTLD_DI_TLS_MODID failed: %s\n", dlerror ());
33 result = 1;
35 else
36 printf ("dlinfo says TLS module ID %Zu\n", modid);
38 void *block;
39 if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
41 printf ("dlinfo RTLD_DI_TLS_DATA failed: %s\n", dlerror ());
42 result = 1;
44 else if (block != NULL)
46 printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be unallocated\n",
47 block);
48 result = 1;
51 result |= fp (0, NULL);
53 foop = dlsym (h, "foo");
54 if (foop == NULL)
56 printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
57 exit (1);
59 if (*foop != 16)
61 puts ("foo != 16");
62 result = 1;
65 /* Now the module's TLS block has been used and should appear. */
66 if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
68 printf ("dlinfo RTLD_DI_TLS_DATA failed the second time: %s\n",
69 dlerror ());
70 result = 1;
72 else if (block != foop)
74 printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be %p\n",
75 block, foop);
76 result = 1;
79 dlclose (h);
81 return result;
85 #include <support/test-driver.c>