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

--VjP/dwTbBl6I9PQk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Jun 15, 2009 at 05:46:54AM +0900, Maho NAKATA wrote:
> Hi Konstantin,
>=20
> Your patch rocks! tested on FBSD7/i386 and it works!
>=20
> * Small test program works.
> * also PR 127946 and Issue 22253 went away.
> =20
> 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;
=20
-    for (obj =3D obj_list;  obj !=3D NULL;  obj =3D obj->next)
-	if (obj =3D=3D (Obj_Entry *) handle)
-	    break;
+    if (handle =3D=3D RTLD_HANDLE_FROM_NULL)
+	obj =3D obj_main;
+    else {
+	for (obj =3D obj_list;  obj !=3D NULL;  obj =3D obj->next)
+	    if (obj =3D=3D (Obj_Entry *) handle)
+		break;
+    }
=20
     if (obj =3D=3D NULL || obj->refcount =3D=3D 0 || obj->dl_refcount =3D=
=3D 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 =3D=3D NULL)
+	obj =3D RTLD_HANDLE_FROM_NULL;
     return obj;
 trace:
     trace_loaded_objects(obj);
@@ -2069,7 +2075,7 @@ do_dlsym(void *handle, const char *name, void *retadd=
r, const Ver_Entry *ve,
     const Obj_Entry *obj, *defobj;
     const Elf_Sym *def, *symp;
     unsigned long hash;
-    int lockstate;
+    int lockstate, search_global;
=20
     hash =3D elf_hash(name);
     def =3D NULL;
@@ -2079,6 +2085,7 @@ do_dlsym(void *handle, const char *name, void *retadd=
r, const Ver_Entry *ve,
     lockstate =3D rlock_acquire(rtld_bind_lock);
     if (handle =3D=3D NULL || handle =3D=3D RTLD_NEXT ||
 	handle =3D=3D RTLD_DEFAULT || handle =3D=3D RTLD_SELF) {
+	search_global =3D true;
=20
 	if ((obj =3D obj_from_addr(retaddr)) =3D=3D NULL) {
 	    _rtld_error("Cannot determine caller's shared object");
@@ -2120,6 +2127,7 @@ do_dlsym(void *handle, const char *name, void *retadd=
r, const Ver_Entry *ve,
 	    def =3D symlook_default(name, hash, obj, &defobj, ve, flags);
 	}
     } else {
+	search_global =3D (handle =3D=3D RTLD_HANDLE_FROM_NULL);
 	if ((obj =3D dlcheck(handle)) =3D=3D NULL) {
 	    rlock_release(rtld_bind_lock, lockstate);
 	    return NULL;
@@ -2141,6 +2149,11 @@ do_dlsym(void *handle, const char *name, void *retad=
dr, const Ver_Entry *ve,
 				 &donelist);
 	}
     }
+    if (def =3D=3D NULL && search_global) {
+	donelist_init(&donelist);
+	def =3D symlook_list(name, hash, &list_global, &defobj, ve, flags,
+			   &donelist);
+    }
=20
     if (def !=3D 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. */
=20
+/* 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.

--VjP/dwTbBl6I9PQk
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)

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

--VjP/dwTbBl6I9PQk--



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