From nobody@FreeBSD.org  Wed Dec 21 10:31:47 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9699716A425
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 21 Dec 2005 10:31:47 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6C8AF43D83
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 21 Dec 2005 10:31:40 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id jBLAVevD081770
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 21 Dec 2005 10:31:40 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id jBLAVdww081768;
	Wed, 21 Dec 2005 10:31:39 GMT
	(envelope-from nobody)
Message-Id: <200512211031.jBLAVdww081768@www.freebsd.org>
Date: Wed, 21 Dec 2005 10:31:39 GMT
From: Konstantin Oznobikhin <bork@rsu.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: dlfunc can not be defined in libc
X-Send-Pr-Version: www-2.3

>Number:         90736
>Category:       bin
>Synopsis:       [libc] dlfunc can not be defined in libc
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 21 10:40:03 GMT 2005
>Closed-Date:    Sat Apr 04 19:49:02 UTC 2009
>Last-Modified:  Sat Apr 04 19:49:02 UTC 2009
>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:
State-Changed-From-To: open->closed  
State-Changed-By: brucec 
State-Changed-When: Sat Apr 4 19:48:30 UTC 2009 
State-Changed-Why:  
Duplicate of standards/133339. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=90736 
>Unformatted:
