Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Oct 2008 19:29:05 -0400
From:      Alexander Kabaev <kabaev@gmail.com>
To:        Maxim Sobolev <sobomax@FreeBSD.org>
Cc:        Alexander Kabaev <kan@FreeBSD.org>, "current@freebsd.org" <current@FreeBSD.org>
Subject:   Re: dlsym(RTLD_NEXT) and weak symbols
Message-ID:  <20081008192905.0b75b0a6@kan.dnsalias.net>
In-Reply-To: <48ED3545.6030609@FreeBSD.org>
References:  <48ED27EA.9020407@FreeBSD.org> <48ED3545.6030609@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--Sig_/iKWPDK2+MyrwaEDHj5BqloR
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

On Wed, 08 Oct 2008 15:33:41 -0700
Maxim Sobolev <sobomax@FreeBSD.org> wrote:
>=20
> The following patch fixes the issue for me:
>
<SKIP>

I do not think your patch is completely correct. How about this one
instead:=20

=3D=3D=3D rtld.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- rtld.c	(revision 183657)
+++ rtld.c	(local)
@@ -1925,7 +1925,7 @@
 {
     DoneList donelist;
     const Obj_Entry *obj, *defobj;
-    const Elf_Sym *def;
+    const Elf_Sym *def, *symp;
     unsigned long hash;
     int lockstate;
=20
@@ -1951,11 +1951,28 @@
 	    if (handle =3D=3D RTLD_NEXT)
 		obj =3D obj->next;
 	    for (; obj !=3D NULL; obj =3D obj->next) {
-		if ((def =3D symlook_obj(name, hash, obj, ve, flags)) !=3D NULL) {
-		    defobj =3D obj;
-		    break;
+	    	if ((symp =3D symlook_obj(name, hash, obj, ve, flags)) !=3D NULL) {
+		    if (def =3D=3D NULL || ELF_ST_BIND(symp->st_info) !=3D STB_WEAK) {
+			def =3D symp;
+			defobj =3D obj;
+			if (ELF_ST_BIND(def->st_info) !=3D 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 =3D=3D NULL || ELF_ST_BIND(def->st_info) =3D=3D STB_WEAK) {
+		symp =3D symlook_obj(name, hash, &obj_rtld, ve, flags);
+		if (symp !=3D NULL && is_exported(symp)) {
+		    def =3D symp;
+		    defobj =3D &obj_rtld;
+		}
+	    }
 	} else {
 	    assert(handle =3D=3D RTLD_DEFAULT);
 	    def =3D symlook_default(name, hash, obj, &defobj, ve, flags);

--Sig_/iKWPDK2+MyrwaEDHj5BqloR
Content-Type: application/pgp-signature; name=signature.asc
Content-Disposition: attachment; filename=signature.asc

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

iD8DBQFI7UJBQ6z1jMm+XZYRAimTAJ4sud5blRPU3p56/6DOBLj042J4NgCfRefv
qN8RLZfeIQ7PznnKigTBvm4=
=h2Bm
-----END PGP SIGNATURE-----

--Sig_/iKWPDK2+MyrwaEDHj5BqloR--



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