Date: Wed, 21 Dec 2005 10:31:39 GMT From: Konstantin Oznobikhin <bork@rsu.ru> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/90736: dlfunc can not be defined in libc Message-ID: <200512211031.jBLAVdww081768@www.freebsd.org> Resent-Message-ID: <200512211040.jBLAe43t088472@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 90736
>Category: misc
>Synopsis: dlfunc can not be defined in libc
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Dec 21 10:40:03 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Konstantin Oznobikhin
>Release: 5.4-STABLE
>Organization:
Computer Center of Rostov State University
>Environment:
FreeBSD rocky.cc.rsu.ru 5.4-STABLE FreeBSD 5.4-STABLE #0: Tue Jul 26 17:57:13 UTC 2005 root@rocky.cc.rsu.ru:/usr/obj/usr/src/sys/rocky.athlon-xp_5 i386
>Description:
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.
>How-To-Repeat:
compile the following with "-Xliker --export-dynamic" option to gcc and run.
#include <dlfcn.h>
#include <stdio.h>
void
foo(void)
{
printf("here we are!\n");
}
typedef void (*foo_ptr_t)(void);
int
main(void)
{
foo_ptr_t f;
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)
}
>Fix:
One of the solutions would be to implement dlfunc in the linker itself as it done for dlopen, dlsym and other dl* functions.
>Release-Note:
>Audit-Trail:
>Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200512211031.jBLAVdww081768>
