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