1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #include <dlfcn.h>
21: #include <stdio.h>
22: #include <stdlib.h>
23: #include <error.h>
24:
25: #define TEST_FUNCTION do_test ()
26:
27: static int
28: do_test (void)
29: {
30: int status = 0;
31:
32: void *handle = dlopen ("glreflib3.so", RTLD_NOW);
33: if (handle == NULL)
34: error (EXIT_FAILURE, 0, "cannot load: glreflib1.so: %s", dlerror ());
35:
36: #define TRY(req, arg) \
37: if (dlinfo (handle, req, arg) != 0) \
38: { \
39: printf ("dlinfo failed for %s: %s\n", #req, dlerror ()); \
40: status = 1; \
41: } \
42: else
43:
44: struct link_map *l;
45: TRY (RTLD_DI_LINKMAP, &l)
46: {
47: if (l != handle)
48: {
49: printf ("bogus link_map? %p != %p\n", l, handle);
50: status = 1;
51: }
52: }
53:
54: char origin[8192];
55: TRY (RTLD_DI_ORIGIN, origin)
56: {
57: printf ("origin: %s\n", origin);
58: }
59:
60: Dl_serinfo counts;
61: TRY (RTLD_DI_SERINFOSIZE, &counts)
62: {
63: Dl_serinfo *buf = alloca (counts.dls_size);
64: buf->dls_cnt = counts.dls_cnt;
65: buf->dls_size = counts.dls_size;
66: printf ("%u library directories\n", buf->dls_cnt);
67: TRY (RTLD_DI_SERINFO, buf)
68: {
69: if (counts.dls_cnt != buf->dls_cnt)
70: {
71: printf ("??? became %u library directories\n", buf->dls_cnt);
72: status = 1;
73: }
74: for (unsigned int i = 0; i < buf->dls_cnt; ++i)
75: printf ("\t%#02x\t%s\n",
76: buf->dls_serpath[i].dls_flags,
77: buf->dls_serpath[i].dls_name);
78: }
79: }
80:
81: unsigned long int lmid = 0xdeadbeefUL;
82: if (dlinfo (handle, RTLD_DI_LMID, &lmid) != 0)
83: printf ("dlinfo refuses RTLD_DI_LMID: %s\n", dlerror ());
84: else
85: {
86: printf ("dlinfo RTLD_DI_LMID worked? %#lx\n", lmid);
87: status = lmid == 0xdeadbeefUL;
88: }
89:
90: #undef TRY
91: dlclose (handle);
92:
93: return status;
94: }
95:
96: #include "../test-skeleton.c"