6 #include <gnu/lib-names.h>
7 #include <first-versions.h>
12 void *handle
= dlopen ("modstatic2-nonexistent.so", RTLD_LAZY
);
14 printf ("nonexistent: %s\n", dlerror ());
18 handle
= dlopen ("modstatic2.so", RTLD_LAZY
);
21 printf ("%s\n", dlerror ());
25 int (*test
) (FILE *, int);
26 test
= dlsym (handle
, "test");
29 printf ("%s\n", dlerror ());
34 int res
= dladdr (test
, &info
);
37 puts ("dladdr returned 0");
42 if (strstr (info
.dli_fname
, "modstatic2.so") == NULL
43 || strcmp (info
.dli_sname
, "test") != 0)
45 printf ("fname %s sname %s\n", info
.dli_fname
, info
.dli_sname
);
48 if (info
.dli_saddr
!= (void *) test
)
50 printf ("saddr %p != test %p\n", info
.dli_saddr
, test
);
57 res
= dladdr1 (test
, &info
, &symp
, RTLD_DL_SYMENT
);
60 puts ("dladdr1 returned 0");
65 if (strstr (info
.dli_fname
, "modstatic2.so") == NULL
66 || strcmp (info
.dli_sname
, "test") != 0)
68 printf ("fname %s sname %s\n", info
.dli_fname
, info
.dli_sname
);
71 if (info
.dli_saddr
!= (void *) test
)
73 printf ("saddr %p != test %p\n", info
.dli_saddr
, test
);
79 puts ("sym == NULL\n");
82 if (ELF32_ST_BIND (sym
->st_info
) != STB_GLOBAL
83 || ELF32_ST_VISIBILITY (sym
->st_other
) != STV_DEFAULT
)
85 printf ("bind %d visibility %d\n",
86 (int) ELF32_ST_BIND (sym
->st_info
),
87 (int) ELF32_ST_VISIBILITY (sym
->st_other
));
93 res
= dlinfo (handle
, RTLD_DI_LMID
, &lmid
);
96 printf ("dlinfo returned %d %s\n", res
, dlerror ());
99 else if (lmid
!= LM_ID_BASE
)
101 printf ("lmid %d != %d\n", (int) lmid
, (int) LM_ID_BASE
);
105 res
= test (stdout
, 2);
108 printf ("Got %i, expected 4\n", res
);
112 void *handle2
= dlopen (LIBDL_SO
, RTLD_LAZY
);
115 printf ("libdl.so: %s\n", dlerror ());
119 /* _exit is very unlikely to receive a second symbol version. */
120 void *exit_ptr
= dlvsym (handle2
, "_exit", FIRST_VERSION_libc__exit_STRING
);
121 if (exit_ptr
== NULL
)
123 printf ("dlvsym: %s\n", dlerror ());
126 if (exit_ptr
!= dlsym (handle2
, "_exit"))
128 printf ("dlvsym for _exit does not match dlsym\n");
132 void *(*dlsymfn
) (void *, const char *);
133 dlsymfn
= dlsym (handle2
, "dlsym");
136 printf ("dlsym \"dlsym\": %s\n", dlerror ());
139 void *test2
= dlsymfn (handle
, "test");
142 printf ("%s\n", dlerror ());
145 else if (test2
!= (void *) test
)
147 printf ("test %p != test2 %p\n", test
, test2
);
154 handle
= dlmopen (LM_ID_BASE
, "modstatic2.so", RTLD_LAZY
);
157 printf ("%s\n", dlerror ());
162 handle
= dlmopen (LM_ID_NEWLM
, "modstatic2.so", RTLD_LAZY
);
164 printf ("LM_ID_NEWLM: %s\n", dlerror ());
167 puts ("LM_ID_NEWLM unexpectedly succeeded");
174 #define TEST_FUNCTION do_test ()
175 #include "../test-skeleton.c"