6 #include <gnu/lib-names.h>
7 #include <first-versions.h>
9 int test (FILE *out
, int a
);
12 test (FILE *out
, int a
)
14 fputs ("in modstatic2.c (test)\n", out
);
16 void *handle
= dlopen ("modstatic2-nonexistent.so", RTLD_LAZY
);
18 fprintf (out
, "nonexistent: %s\n", dlerror ());
22 handle
= dlopen ("modstatic2.so", RTLD_LAZY
);
25 fprintf (out
, "%s\n", dlerror ());
29 int (*test2
) (FILE *, int);
30 test2
= dlsym (handle
, "test");
33 fprintf (out
, "%s\n", dlerror ());
38 fprintf (out
, "test %p != test2 %p\n", test
, test2
);
43 int res
= dladdr (test2
, &info
);
46 fputs ("dladdr returned 0\n", out
);
51 if (strstr (info
.dli_fname
, "modstatic2.so") == NULL
52 || strcmp (info
.dli_sname
, "test") != 0)
54 fprintf (out
, "fname %s sname %s\n", info
.dli_fname
, info
.dli_sname
);
57 if (info
.dli_saddr
!= (void *) test2
)
59 fprintf (out
, "saddr %p != test %p\n", info
.dli_saddr
, test2
);
66 res
= dladdr1 (test2
, &info
, &symp
, RTLD_DL_SYMENT
);
69 fputs ("dladdr1 returned 0\n", out
);
74 if (strstr (info
.dli_fname
, "modstatic2.so") == NULL
75 || strcmp (info
.dli_sname
, "test") != 0)
77 fprintf (out
, "fname %s sname %s\n", info
.dli_fname
, info
.dli_sname
);
80 if (info
.dli_saddr
!= (void *) test2
)
82 fprintf (out
, "saddr %p != test %p\n", info
.dli_saddr
, test2
);
88 fputs ("sym == NULL\n", out
);
91 if (ELF32_ST_BIND (sym
->st_info
) != STB_GLOBAL
92 || ELF32_ST_VISIBILITY (sym
->st_other
) != STV_DEFAULT
)
94 fprintf (out
, "bind %d visibility %d\n",
95 (int) ELF32_ST_BIND (sym
->st_info
),
96 (int) ELF32_ST_VISIBILITY (sym
->st_other
));
102 res
= dlinfo (handle
, RTLD_DI_LMID
, &lmid
);
105 fprintf (out
, "dlinfo returned %d %s\n", res
, dlerror ());
108 else if (lmid
!= LM_ID_BASE
)
110 fprintf (out
, "lmid %d != %d\n", (int) lmid
, (int) LM_ID_BASE
);
114 void *handle2
= dlopen (LIBDL_SO
, RTLD_LAZY
);
117 fprintf (out
, "libdl.so: %s\n", dlerror ());
121 /* _exit is very unlikely to receive a second symbol version. */
122 void *exit_ptr
= dlvsym (handle2
, "_exit", FIRST_VERSION_libc__exit_STRING
);
123 if (exit_ptr
== NULL
)
125 fprintf (out
, "dlvsym: %s\n", dlerror ());
128 if (exit_ptr
!= dlsym (handle2
, "_exit"))
130 fprintf (out
, "dlvsym for _exit does not match dlsym\n");
134 void *(*dlsymfn
) (void *, const char *);
135 dlsymfn
= dlsym (handle2
, "dlsym");
138 fprintf (out
, "dlsym \"dlsym\": %s\n", dlerror ());
141 void *test3
= dlsymfn (handle
, "test");
144 fprintf (out
, "%s\n", dlerror ());
147 else if (test3
!= (void *) test2
)
149 fprintf (out
, "test2 %p != test3 %p\n", test2
, test3
);
156 handle
= dlmopen (LM_ID_BASE
, "modstatic2.so", RTLD_LAZY
);
159 fprintf (out
, "%s\n", dlerror ());
164 handle
= dlmopen (LM_ID_NEWLM
, "modstatic2.so", RTLD_LAZY
);
166 fprintf (out
, "LM_ID_NEWLM: %s\n", dlerror ());
169 fputs ("LM_ID_NEWLM unexpectedly succeeded\n", out
);
173 handle
= dlopen ("modstatic.so", RTLD_LAZY
);
176 fprintf (out
, "%s\n", dlerror ());
181 test4
= dlsym (handle
, "test");
184 fprintf (out
, "%s\n", dlerror ());
191 fprintf (out
, "modstatic.so (test) returned %d\n", res
);
195 res
= dladdr1 (test4
, &info
, &symp
, RTLD_DL_SYMENT
);
198 fputs ("dladdr1 returned 0\n", out
);
203 if (strstr (info
.dli_fname
, "modstatic.so") == NULL
204 || strcmp (info
.dli_sname
, "test") != 0)
206 fprintf (out
, "fname %s sname %s\n", info
.dli_fname
, info
.dli_sname
);
209 if (info
.dli_saddr
!= (void *) test4
)
211 fprintf (out
, "saddr %p != test %p\n", info
.dli_saddr
, test4
);
217 fputs ("sym == NULL\n", out
);
220 if (ELF32_ST_BIND (sym
->st_info
) != STB_GLOBAL
221 || ELF32_ST_VISIBILITY (sym
->st_other
) != STV_DEFAULT
)
223 fprintf (out
, "bind %d visibility %d\n",
224 (int) ELF32_ST_BIND (sym
->st_info
),
225 (int) ELF32_ST_VISIBILITY (sym
->st_other
));
232 fputs ("leaving modstatic2.c (test)\n", out
);