Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jun 2009 00:08:31 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Maho NAKATA <chat95@mac.com>
Cc:        kan@freebsd.org, openoffice@freebsd.org
Subject:   Re: ld.so slight difference Linux and FreeBSD ports/127946
Message-ID:  <20090615210831.GT23592@deviant.kiev.zoral.com.ua>
In-Reply-To: <20090615.054654.71139727.chat95@mac.com>
References:  <1244902235.49065.33.camel@localhost> <20090614.081457.193757375.chat95@mac.com> <20090614094141.GF23592@deviant.kiev.zoral.com.ua> <20090615.054654.71139727.chat95@mac.com>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Mon, Jun 15, 2009 at 05:46:54AM +0900, Maho NAKATA wrote:
> Hi Konstantin,
> 
> Your patch rocks! tested on FBSD7/i386 and it works!
> 
> * Small test program works.
> * also PR 127946 and Issue 22253 went away.
>  
> Is your patch can be commit to FBSD8 or MFC'ed to 7?

After discussion with Alexander, who pointed out that handles
returned from dlopen done over non-NULL name shall not search
in the namespace of objects opened with RTLD_GLOBAL flag,
I modified the patch.

Would be nice if you could retest the change below.

diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 40ed6ed..54acb8a 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -1048,9 +1048,13 @@ dlcheck(void *handle)
 {
     Obj_Entry *obj;
 
-    for (obj = obj_list;  obj != NULL;  obj = obj->next)
-	if (obj == (Obj_Entry *) handle)
-	    break;
+    if (handle == RTLD_HANDLE_FROM_NULL)
+	obj = obj_main;
+    else {
+	for (obj = obj_list;  obj != NULL;  obj = obj->next)
+	    if (obj == (Obj_Entry *) handle)
+		break;
+    }
 
     if (obj == NULL || obj->refcount == 0 || obj->dl_refcount == 0) {
 	_rtld_error("Invalid shared object handle %p", handle);
@@ -2054,6 +2058,8 @@ dlopen(const char *name, int mode)
     objlist_call_init(&initlist, &lockstate);
     objlist_clear(&initlist);
     wlock_release(rtld_bind_lock, lockstate);
+    if (name == NULL)
+	obj = RTLD_HANDLE_FROM_NULL;
     return obj;
 trace:
     trace_loaded_objects(obj);
@@ -2069,7 +2075,7 @@ do_dlsym(void *handle, const char *name, void *retaddr, const Ver_Entry *ve,
     const Obj_Entry *obj, *defobj;
     const Elf_Sym *def, *symp;
     unsigned long hash;
-    int lockstate;
+    int lockstate, search_global;
 
     hash = elf_hash(name);
     def = NULL;
@@ -2079,6 +2085,7 @@ do_dlsym(void *handle, const char *name, void *retaddr, const Ver_Entry *ve,
     lockstate = rlock_acquire(rtld_bind_lock);
     if (handle == NULL || handle == RTLD_NEXT ||
 	handle == RTLD_DEFAULT || handle == RTLD_SELF) {
+	search_global = true;
 
 	if ((obj = obj_from_addr(retaddr)) == NULL) {
 	    _rtld_error("Cannot determine caller's shared object");
@@ -2120,6 +2127,7 @@ do_dlsym(void *handle, const char *name, void *retaddr, const Ver_Entry *ve,
 	    def = symlook_default(name, hash, obj, &defobj, ve, flags);
 	}
     } else {
+	search_global = (handle == RTLD_HANDLE_FROM_NULL);
 	if ((obj = dlcheck(handle)) == NULL) {
 	    rlock_release(rtld_bind_lock, lockstate);
 	    return NULL;
@@ -2141,6 +2149,11 @@ do_dlsym(void *handle, const char *name, void *retaddr, const Ver_Entry *ve,
 				 &donelist);
 	}
     }
+    if (def == NULL && search_global) {
+	donelist_init(&donelist);
+	def = symlook_list(name, hash, &list_global, &defobj, ve, flags,
+			   &donelist);
+    }
 
     if (def != NULL) {
 	rlock_release(rtld_bind_lock, lockstate);
diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h
index 2b3b897..b16e57e 100644
--- a/libexec/rtld-elf/rtld.h
+++ b/libexec/rtld-elf/rtld.h
@@ -238,6 +238,9 @@ typedef struct Struct_Obj_Entry {
 #define SYMLOOK_DLSYM	0x02	/* Return newes versioned symbol. Used by
 				   dlsym. */
 
+/* Handle returned by dlopen(NULL, flags). */
+#define	RTLD_HANDLE_FROM_NULL	((void *) -100)
+
 /*
  * Symbol cache entry used during relocation to avoid multiple lookups
  * of the same symbol.

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)

iEYEARECAAYFAko2uE8ACgkQC3+MBN1Mb4g1AwCfWqH7yVULv1FeF/Ge3+i/IDXT
3h0An1iAiW5aAP8ZB0Pk+/0umWdabXz6
=QGQx
-----END PGP SIGNATURE-----

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090615210831.GT23592>