From owner-svn-src-all@FreeBSD.ORG Fri Apr 3 19:17:24 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9E734106566B; Fri, 3 Apr 2009 19:17:24 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8BC3C8FC1F; Fri, 3 Apr 2009 19:17:24 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n33JHO0s030714; Fri, 3 Apr 2009 19:17:24 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n33JHOMr030710; Fri, 3 Apr 2009 19:17:24 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <200904031917.n33JHOMr030710@svn.freebsd.org> From: Konstantin Belousov Date: Fri, 3 Apr 2009 19:17:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r190673 - in head: lib/libc/gen libexec/rtld-elf X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Apr 2009 19:17:25 -0000 Author: kib Date: Fri Apr 3 19:17:23 2009 New Revision: 190673 URL: http://svn.freebsd.org/changeset/base/190673 Log: Allow the NULL, RTLD_SELF and RTLD_NEXT handles to work with dlfunc(3). dlfunc() called dlsym() to do the work, and dlsym() determines the dso that originating the call by the return address. Due to this, dlfunc() operated as if the caller is always the libc. To fix this, move the dlfunc() to rtld, where it can call the internal implementation of dlsym, and still correctly fetch return address. Provide usual weak stub for the symbol from libc for static binaries. dlfunc is put to FBSD_1.0 symver namespace in the ld.so export to override dlfunc@FBSD_1.0 weak symbol, exported by libc. Reported, analyzed and tested by: Tijl Coosemans PR: standards/133339 Reviewed by: kan Deleted: head/lib/libc/gen/dlfunc.c Modified: head/lib/libc/gen/Makefile.inc head/lib/libc/gen/dlfcn.c head/libexec/rtld-elf/Symbol.map head/libexec/rtld-elf/rtld.c Modified: head/lib/libc/gen/Makefile.inc ============================================================================== --- head/lib/libc/gen/Makefile.inc Fri Apr 3 18:00:19 2009 (r190672) +++ head/lib/libc/gen/Makefile.inc Fri Apr 3 19:17:23 2009 (r190673) @@ -9,7 +9,7 @@ SRCS+= __getosreldate.c __xuname.c \ alarm.c arc4random.c assert.c basename.c check_utility_compat.c \ clock.c closedir.c confstr.c \ crypt.c ctermid.c daemon.c devname.c dirname.c disklabel.c \ - dlfcn.c dlfunc.c drand48.c erand48.c err.c errlst.c errno.c \ + dlfcn.c drand48.c erand48.c err.c errlst.c errno.c \ exec.c fdevname.c feature_present.c fmtcheck.c fmtmsg.c fnmatch.c \ fpclassify.c frexp.c fstab.c ftok.c fts.c fts-compat.c ftw.c \ getbootfile.c getbsize.c \ Modified: head/lib/libc/gen/dlfcn.c ============================================================================== --- head/lib/libc/gen/dlfcn.c Fri Apr 3 18:00:19 2009 (r190672) +++ head/lib/libc/gen/dlfcn.c Fri Apr 3 19:17:23 2009 (r190673) @@ -105,6 +105,14 @@ dlsym(void * __restrict handle, const ch return NULL; } +#pragma weak dlfunc +dlfunc_t +dlfunc(void * __restrict handle, const char * __restrict name) +{ + _rtld_error(sorry); + return NULL; +} + #pragma weak dlvsym void * dlvsym(void * __restrict handle, const char * __restrict name, Modified: head/libexec/rtld-elf/Symbol.map ============================================================================== --- head/libexec/rtld-elf/Symbol.map Fri Apr 3 18:00:19 2009 (r190672) +++ head/libexec/rtld-elf/Symbol.map Fri Apr 3 19:17:23 2009 (r190673) @@ -8,6 +8,7 @@ FBSD_1.0 { dlerror; dlopen; dlsym; + dlfunc; dlvsym; dladdr; dllockinit; Modified: head/libexec/rtld-elf/rtld.c ============================================================================== --- head/libexec/rtld-elf/rtld.c Fri Apr 3 18:00:19 2009 (r190672) +++ head/libexec/rtld-elf/rtld.c Fri Apr 3 19:17:23 2009 (r190673) @@ -200,6 +200,7 @@ static func_ptr_type exports[] = { (func_ptr_type) &dlerror, (func_ptr_type) &dlopen, (func_ptr_type) &dlsym, + (func_ptr_type) &dlfunc, (func_ptr_type) &dlvsym, (func_ptr_type) &dladdr, (func_ptr_type) &dllockinit, @@ -2170,6 +2171,19 @@ dlsym(void *handle, const char *name) SYMLOOK_DLSYM); } +dlfunc_t +dlfunc(void *handle, const char *name) +{ + union { + void *d; + dlfunc_t f; + } rv; + + rv.d = do_dlsym(handle, name, __builtin_return_address(0), NULL, + SYMLOOK_DLSYM); + return (rv.f); +} + void * dlvsym(void *handle, const char *name, const char *version) {