misc/90736: dlfunc can not be defined in libc
bork at rsu.ru
Wed Dec 21 02:40:10 PST 2005
>Synopsis: dlfunc can not be defined in libc
>Arrival-Date: Wed Dec 21 10:40:03 GMT 2005
>Originator: Konstantin Oznobikhin
Computer Center of Rostov State University
FreeBSD rocky.cc.rsu.ru 5.4-STABLE FreeBSD 5.4-STABLE #0: Tue Jul 26 17:57:13 UTC 2005 root at rocky.cc.rsu.ru:/usr/obj/usr/src/sys/rocky.athlon-xp_5 i386
The dlfunc(3) is placed in the libc to provide a C standard compliant way of getting functions addresses from shared libraries. It's implemented as a simple wrapper for the dlsym(3) (see src/lib/libc/gen/dlfunc.c). This leads to wrong determination of the calling module handle in the dlsym, which becomes libc.so instead of the module which called dlfunc. This makes impossible to correctly use NULL, RTLD_SELF and RTLD_NEXT values for handle when using dlfunc.
compile the following with "-Xliker --export-dynamic" option to gcc and run.
printf("here we are!\n");
typedef void (*foo_ptr_t)(void);
f = (foo_ptr_t)dlsym(NULL, "foo"); // search for foo in the executable from which the call is being made.
f(); // this one works
f = (foo_ptr_t)dlfunc(NULL, "foo"); // actually searches the libc for foo
f(); // this one crashes! (f is NULL now)
One of the solutions would be to implement dlfunc in the linker itself as it done for dlopen, dlsym and other dl* functions.
More information about the freebsd-bugs