6 #include <gnu/lib-names.h>
8 int test (FILE *out, int a);
11 test (FILE *out, int a)
13 fputs ("in modstatic2.c (test)\n", out);
15 void *handle = dlopen ("modstatic2-nonexistent.so", RTLD_LAZY);
17 fprintf (out, "nonexistent: %s\n", dlerror ());
21 handle = dlopen ("modstatic2.so", RTLD_LAZY);
24 fprintf (out, "%s\n", dlerror ());
28 int (*test2) (FILE *, int);
29 test2 = dlsym (handle, "test");
32 fprintf (out, "%s\n", dlerror ());
37 fprintf (out, "test %p != test2 %p\n", test, test2);
42 int res = dladdr (test2, &info);
45 fputs ("dladdr returned 0\n", out);
50 if (strstr (info.dli_fname, "modstatic2.so") == NULL
51 || strcmp (info.dli_sname, "test") != 0)
53 fprintf (out, "fname %s sname %s\n", info.dli_fname, info.dli_sname);
56 if (info.dli_saddr != (void *) test2)
58 fprintf (out, "saddr %p != test %p\n", info.dli_saddr, test2);
65 res = dladdr1 (test2, &info, &symp, RTLD_DL_SYMENT);
68 fputs ("dladdr1 returned 0\n", out);
73 if (strstr (info.dli_fname, "modstatic2.so") == NULL
74 || strcmp (info.dli_sname, "test") != 0)
76 fprintf (out, "fname %s sname %s\n", info.dli_fname, info.dli_sname);
79 if (info.dli_saddr != (void *) test2)
81 fprintf (out, "saddr %p != test %p\n", info.dli_saddr, test2);
87 fputs ("sym == NULL\n", out);
90 if (ELF32_ST_BIND (sym->st_info) != STB_GLOBAL
91 || ELF32_ST_VISIBILITY (sym->st_other) != STV_DEFAULT)
93 fprintf (out, "bind %d visibility %d\n",
94 (int) ELF32_ST_BIND (sym->st_info),
95 (int) ELF32_ST_VISIBILITY (sym->st_other));
101 res = dlinfo (handle, RTLD_DI_LMID, &lmid);
104 fprintf (out, "dlinfo returned %d %s\n", res, dlerror ());
107 else if (lmid != LM_ID_BASE)
109 fprintf (out, "lmid %d != %d\n", (int) lmid, (int) LM_ID_BASE);
113 void *handle2 = dlopen (LIBDL_SO, RTLD_LAZY);
116 fprintf (out, "libdl.so: %s\n", dlerror ());
121 if (dlvsym (handle2, "_dlfcn_hook", "GLIBC_PRIVATE") == NULL)
123 fprintf (out, "dlvsym: %s\n", dlerror ());
128 void *(*dlsymfn) (void *, const char *);
129 dlsymfn = dlsym (handle2, "dlsym");
132 fprintf (out, "dlsym \"dlsym\": %s\n", dlerror ());
135 void *test3 = dlsymfn (handle, "test");
138 fprintf (out, "%s\n", dlerror ());
141 else if (test3 != (void *) test2)
143 fprintf (out, "test2 %p != test3 %p\n", test2, test3);
150 handle = dlmopen (LM_ID_BASE, "modstatic2.so", RTLD_LAZY);
153 fprintf (out, "%s\n", dlerror ());
158 handle = dlmopen (LM_ID_NEWLM, "modstatic2.so", RTLD_LAZY);
160 fprintf (out, "LM_ID_NEWLM: %s\n", dlerror ());
163 fputs ("LM_ID_NEWLM unexpectedly succeeded\n", out);
167 handle = dlopen ("modstatic.so", RTLD_LAZY);
170 fprintf (out, "%s\n", dlerror ());
175 test4 = dlsym (handle, "test");
178 fprintf (out, "%s\n", dlerror ());
185 fprintf (out, "modstatic.so (test) returned %d\n", res);
189 res = dladdr1 (test4, &info, &symp, RTLD_DL_SYMENT);
192 fputs ("dladdr1 returned 0\n", out);
197 if (strstr (info.dli_fname, "modstatic.so") == NULL
198 || strcmp (info.dli_sname, "test") != 0)
200 fprintf (out, "fname %s sname %s\n", info.dli_fname, info.dli_sname);
203 if (info.dli_saddr != (void *) test4)
205 fprintf (out, "saddr %p != test %p\n", info.dli_saddr, test4);
211 fputs ("sym == NULL\n", out);
214 if (ELF32_ST_BIND (sym->st_info) != STB_GLOBAL
215 || ELF32_ST_VISIBILITY (sym->st_other) != STV_DEFAULT)
217 fprintf (out, "bind %d visibility %d\n",
218 (int) ELF32_ST_BIND (sym->st_info),
219 (int) ELF32_ST_VISIBILITY (sym->st_other));
226 fputs ("leaving modstatic2.c (test)\n", out);