ld.so slight difference Linux and FreeBSD ports/127946

Kostik Belousov kostikbel at gmail.com
Mon Jun 15 21:08:46 UTC 2009


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-openoffice/attachments/20090615/349573ce/attachment.pgp


More information about the freebsd-openoffice mailing list