Mention IFUNC enhancements to testsuite in NEWS.
[platform/upstream/glibc.git] / elf / tst-tls-dlinfo.c
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #include <tls.h>
6
7
8 #define TEST_FUNCTION do_test ()
9 static int
10 do_test (void)
11 {
12   static const char modname[] = "tst-tlsmod2.so";
13   int result = 0;
14   int *foop;
15   int (*fp) (int, int *);
16   void *h;
17
18   h = dlopen (modname, RTLD_LAZY);
19   if (h == NULL)
20     {
21       printf ("cannot open '%s': %s\n", modname, dlerror ());
22       exit (1);
23     }
24
25   fp = dlsym (h, "in_dso");
26   if (fp == NULL)
27     {
28       printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
29       exit (1);
30     }
31
32   size_t modid = -1;
33   if (dlinfo (h, RTLD_DI_TLS_MODID, &modid))
34     {
35       printf ("dlinfo RTLD_DI_TLS_MODID failed: %s\n", dlerror ());
36       result = 1;
37     }
38   else
39     printf ("dlinfo says TLS module ID %Zu\n", modid);
40
41   void *block;
42   if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
43     {
44       printf ("dlinfo RTLD_DI_TLS_DATA failed: %s\n", dlerror ());
45       result = 1;
46     }
47   else if (block != NULL)
48     {
49       printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be unallocated\n",
50               block);
51       result = 1;
52     }
53
54   result |= fp (0, NULL);
55
56   foop = dlsym (h, "foo");
57   if (foop == NULL)
58     {
59       printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
60       exit (1);
61     }
62   if (*foop != 16)
63     {
64       puts ("foo != 16");
65       result = 1;
66     }
67
68   /* Now the module's TLS block has been used and should appear.  */
69   if (dlinfo (h, RTLD_DI_TLS_DATA, &block))
70     {
71       printf ("dlinfo RTLD_DI_TLS_DATA failed the second time: %s\n",
72               dlerror ());
73       result = 1;
74     }
75   else if (block != foop)
76     {
77       printf ("dlinfo RTLD_DI_TLS_DATA says %p but should be %p\n",
78               block, foop);
79       result = 1;
80     }
81
82   dlclose (h);
83
84   return result;
85 }
86
87
88 #include "../test-skeleton.c"