From d2fcac0ee269d1860c774a5ecf65296ce9417c84 Mon Sep 17 00:00:00 2001 From: kib Date: Fri, 3 Apr 2009 19:17:23 +0000 Subject: 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 --- libexec/rtld-elf/Symbol.map | 1 + libexec/rtld-elf/rtld.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) (limited to 'libexec') diff --git a/libexec/rtld-elf/Symbol.map b/libexec/rtld-elf/Symbol.map index 20f8d60..ce1e3e5 100644 --- a/libexec/rtld-elf/Symbol.map +++ b/libexec/rtld-elf/Symbol.map @@ -8,6 +8,7 @@ FBSD_1.0 { dlerror; dlopen; dlsym; + dlfunc; dlvsym; dladdr; dllockinit; diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 07529b3..40ed6ed 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -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) { -- cgit v1.1