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 ());
120 if (dlvsym (handle2, "_dlfcn_hook", "GLIBC_PRIVATE") == NULL)
122 fprintf (out, "dlvsym: %s\n", dlerror ());
126 void *(*dlsymfn) (void *, const char *);
127 dlsymfn = dlsym (handle2, "dlsym");
130 fprintf (out, "dlsym \"dlsym\": %s\n", dlerror ());
133 void *test3 = dlsymfn (handle, "test");
136 fprintf (out, "%s\n", dlerror ());
139 else if (test3 != (void *) test2)
141 fprintf (out, "test2 %p != test3 %p\n", test2, test3);
148 handle = dlmopen (LM_ID_BASE, "modstatic2.so", RTLD_LAZY);
151 fprintf (out, "%s\n", dlerror ());
156 handle = dlmopen (LM_ID_NEWLM, "modstatic2.so", RTLD_LAZY);
158 fprintf (out, "LM_ID_NEWLM: %s\n", dlerror ());
161 fputs ("LM_ID_NEWLM unexpectedly succeeded\n", out);
165 handle = dlopen ("modstatic.so", RTLD_LAZY);
168 fprintf (out, "%s\n", dlerror ());
173 test4 = dlsym (handle, "test");
176 fprintf (out, "%s\n", dlerror ());
183 fprintf (out, "modstatic.so (test) returned %d\n", res);
187 res = dladdr1 (test4, &info, &symp, RTLD_DL_SYMENT);
190 fputs ("dladdr1 returned 0\n", out);
195 if (strstr (info.dli_fname, "modstatic.so") == NULL
196 || strcmp (info.dli_sname, "test") != 0)
198 fprintf (out, "fname %s sname %s\n", info.dli_fname, info.dli_sname);
201 if (info.dli_saddr != (void *) test4)
203 fprintf (out, "saddr %p != test %p\n", info.dli_saddr, test4);
209 fputs ("sym == NULL\n", out);
212 if (ELF32_ST_BIND (sym->st_info) != STB_GLOBAL
213 || ELF32_ST_VISIBILITY (sym->st_other) != STV_DEFAULT)
215 fprintf (out, "bind %d visibility %d\n",
216 (int) ELF32_ST_BIND (sym->st_info),
217 (int) ELF32_ST_VISIBILITY (sym->st_other));
224 fputs ("leaving modstatic2.c (test)\n", out);