From owner-svn-src-all@FreeBSD.ORG Fri Oct 10 00:16:33 2008 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 16B1D1065690; Fri, 10 Oct 2008 00:16:33 +0000 (UTC) (envelope-from kan@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 044B28FC22; Fri, 10 Oct 2008 00:16:33 +0000 (UTC) (envelope-from kan@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 m9A0GWjQ074922; Fri, 10 Oct 2008 00:16:32 GMT (envelope-from kan@svn.freebsd.org) Received: (from kan@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9A0GWoo074921; Fri, 10 Oct 2008 00:16:32 GMT (envelope-from kan@svn.freebsd.org) Message-Id: <200810100016.m9A0GWoo074921@svn.freebsd.org> From: Alexander Kabaev Date: Fri, 10 Oct 2008 00:16:32 +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: r183737 - head/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, 10 Oct 2008 00:16:33 -0000 Author: kan Date: Fri Oct 10 00:16:32 2008 New Revision: 183737 URL: http://svn.freebsd.org/changeset/base/183737 Log: Allow strong symbols to override weak ones for lookups done through dlsym with RTLD_NEXT/RTLD_SELF handles. Allow symbols from ld-elf.so to be located this way too. Based on report and original patch from sobomax@. Modified: head/libexec/rtld-elf/rtld.c Modified: head/libexec/rtld-elf/rtld.c ============================================================================== --- head/libexec/rtld-elf/rtld.c Thu Oct 9 22:01:27 2008 (r183736) +++ head/libexec/rtld-elf/rtld.c Fri Oct 10 00:16:32 2008 (r183737) @@ -1925,7 +1925,7 @@ do_dlsym(void *handle, const char *name, { DoneList donelist; const Obj_Entry *obj, *defobj; - const Elf_Sym *def; + const Elf_Sym *def, *symp; unsigned long hash; int lockstate; @@ -1951,9 +1951,26 @@ do_dlsym(void *handle, const char *name, if (handle == RTLD_NEXT) obj = obj->next; for (; obj != NULL; obj = obj->next) { - if ((def = symlook_obj(name, hash, obj, ve, flags)) != NULL) { - defobj = obj; - break; + if ((symp = symlook_obj(name, hash, obj, ve, flags)) != NULL) { + if (def == NULL || ELF_ST_BIND(symp->st_info) != STB_WEAK) { + def = symp; + defobj = obj; + if (ELF_ST_BIND(def->st_info) != STB_WEAK) + break; + } + } + } + /* + * Search the dynamic linker itself, and possibly resolve the + * symbol from there. This is how the application links to + * dynamic linker services such as dlopen. Only the values listed + * in the "exports" array can be resolved from the dynamic linker. + */ + if (def == NULL || ELF_ST_BIND(def->st_info) == STB_WEAK) { + symp = symlook_obj(name, hash, &obj_rtld, ve, flags); + if (symp != NULL && is_exported(symp)) { + def = symp; + defobj = &obj_rtld; } } } else {