6 #include <gnu/lib-names.h>
11 void *handle = dlopen ("modstatic2-nonexistent.so", RTLD_LAZY);
13 printf ("nonexistent: %s\n", dlerror ());
17 handle = dlopen ("modstatic2.so", RTLD_LAZY);
20 printf ("%s\n", dlerror ());
24 int (*test) (FILE *, int);
25 test = dlsym (handle, "test");
28 printf ("%s\n", dlerror ());
33 int res = dladdr (test, &info);
36 puts ("dladdr returned 0");
41 if (strstr (info.dli_fname, "modstatic2.so") == NULL
42 || strcmp (info.dli_sname, "test") != 0)
44 printf ("fname %s sname %s\n", info.dli_fname, info.dli_sname);
47 if (info.dli_saddr != (void *) test)
49 printf ("saddr %p != test %p\n", info.dli_saddr, test);
56 res = dladdr1 (test, &info, &symp, RTLD_DL_SYMENT);
59 puts ("dladdr1 returned 0");
64 if (strstr (info.dli_fname, "modstatic2.so") == NULL
65 || strcmp (info.dli_sname, "test") != 0)
67 printf ("fname %s sname %s\n", info.dli_fname, info.dli_sname);
70 if (info.dli_saddr != (void *) test)
72 printf ("saddr %p != test %p\n", info.dli_saddr, test);
78 puts ("sym == NULL\n");
81 if (ELF32_ST_BIND (sym->st_info) != STB_GLOBAL
82 || ELF32_ST_VISIBILITY (sym->st_other) != STV_DEFAULT)
84 printf ("bind %d visibility %d\n",
85 (int) ELF32_ST_BIND (sym->st_info),
86 (int) ELF32_ST_VISIBILITY (sym->st_other));
92 res = dlinfo (handle, RTLD_DI_LMID, &lmid);
95 printf ("dlinfo returned %d %s\n", res, dlerror ());
98 else if (lmid != LM_ID_BASE)
100 printf ("lmid %d != %d\n", (int) lmid, (int) LM_ID_BASE);
104 res = test (stdout, 2);
107 printf ("Got %i, expected 4\n", res);
111 void *handle2 = dlopen (LIBDL_SO, RTLD_LAZY);
114 printf ("libdl.so: %s\n", dlerror ());
119 if (dlvsym (handle2, "_dlfcn_hook", "GLIBC_PRIVATE") == NULL)
121 printf ("dlvsym: %s\n", dlerror ());
126 void *(*dlsymfn) (void *, const char *);
127 dlsymfn = dlsym (handle2, "dlsym");
130 printf ("dlsym \"dlsym\": %s\n", dlerror ());
133 void *test2 = dlsymfn (handle, "test");
136 printf ("%s\n", dlerror ());
139 else if (test2 != (void *) test)
141 printf ("test %p != test2 %p\n", test, test2);
148 handle = dlmopen (LM_ID_BASE, "modstatic2.so", RTLD_LAZY);
151 printf ("%s\n", dlerror ());
156 handle = dlmopen (LM_ID_NEWLM, "modstatic2.so", RTLD_LAZY);
158 printf ("LM_ID_NEWLM: %s\n", dlerror ());
161 puts ("LM_ID_NEWLM unexpectedly succeeded");