From owner-freebsd-hackers@FreeBSD.ORG Wed Jul 6 05:47:56 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5B65416A41C for ; Wed, 6 Jul 2005 05:47:56 +0000 (GMT) (envelope-from vd@datamax.bg) Received: from jengal.datamax.bg (jengal.datamax.bg [82.103.104.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id C239043D48 for ; Wed, 6 Jul 2005 05:47:55 +0000 (GMT) (envelope-from vd@datamax.bg) Received: from sinanica.bg.datamax (sinanica.bg.datamax [192.168.10.1]) by jengal.datamax.bg (Postfix) with QMQP id AE7A787CA; Wed, 6 Jul 2005 08:47:53 +0300 (EEST) Received: (nullmailer pid 19676 invoked by uid 1004); Wed, 06 Jul 2005 05:47:53 -0000 Date: Wed, 6 Jul 2005 08:47:53 +0300 From: Vasil Dimov To: Tom Schutter Message-ID: <20050706054753.GA69973@sinanica.bg.datamax> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="8t9RHnE3ZwKMSgU+" Content-Disposition: inline In-Reply-To: X-OS: FreeBSD 5.4-STABLE User-Agent: Mutt/1.5.9i Cc: freebsd-hackers@freebsd.org Subject: Re: linking libjava.so RPATH problem X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: vd@datamax.bg List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jul 2005 05:47:56 -0000 --8t9RHnE3ZwKMSgU+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jul 05, 2005 at 03:55:26PM -0600, Tom Schutter wrote: > I am having problems linking in the Java JVM libraries (libjava.so, > libverify.so, libjvm.so) into my executable. >=20 > With these options added to my gcc command: > -L/usr/local/jdk1.4.2/jre/lib/i386 -ljava -lverify > -L/usr/local/jdk1.4.2/jre/lib/i386/server -ljvm >=20 > It links ok, but when I try to run it I get: > $ ./testme > /libexec/ld-elf.so.1: Shared object "libjava.so" not found, required by > "testme" >=20 > At this point ldd tells me: > $ ldd testme > testme: > libm.so.3 =3D3D> /lib/libm.so.3 (0x2807c000) > libjava.so =3D3D> not found (0x0) > libverify.so =3D3D> not found (0x0) > libjvm.so =3D3D> not found (0x0) > libpthread.so.1 =3D3D> /usr/lib/libpthread.so.1 (0x28097000) > libc.so.5 =3D3D> /lib/libc.so.5 (0x280bb000) >=20 > Using -Xlinker -rpath -Xlinker PATH_TO_JRE_DIR, I can tell my executable = to > look in the JRE dir for libjvm.so. I have verified that RPATH has been s= et > in the executable using objdump: > $ objdump -x testme | grep RPATH > RPATH /usr/local/jdk1.4.2/jre/lib/i386:/usr/local/jdk1.4.2/jre/lib= /i386/server >=20 > But when I run the executable, it cannot find libjvm.so: > $ ./testme > /libexec/ld-elf.so.1: Shared object "libjvm.so" not found, required by > "libjava.so" >=20 > At this point ldd tells me: > $ ldd ./testme > ./testme: > libm.so.3 =3D3D> /lib/libm.so.3 (0x2807c000) > libjava.so =3D3D> /usr/local/jdk1.4.2/jre/lib/i386/libjava.so (0x2= 8097000) > libverify.so =3D3D> /usr/local/jdk1.4.2/jre/lib/i386/libverify.so > (0x280b5000) > libjvm.so =3D3D> > /usr/local/jdk1.4.2/jre/lib/i386/server/libjvm.so (0x280ca000) > libpthread.so.1 =3D3D> /usr/lib/libpthread.so.1 (0x28702000) > libc.so.5 =3D3D> /lib/libc.so.5 (0x28726000) > libjvm.so =3D3D> not found (0x0) > libverify.so =3D3D> not found (0x0) > libjvm.so =3D3D> not found (0x0) > libstdc++.so.4 =3D3D> /usr/lib/libstdc++.so.4 (0x28800000) >=20 > Note that at this point on Linux, testme runs ok. >=20 > If I set LD_LIBRARY_PATH, the libraries are found (no output is correct): > $ LD_LIBRARY_PATH=3D3D/usr/local/jdk1.4.2/jre/lib/i386:/usr/local/jdk1.4.= 2/jre/lib/i386/server > ./testme > $ >=20 > My questions are: >=20 > 1) Why is the RPATH in the executable being ignored? Here are my suggestions: It is not being ignored, as you see: libjava.so, libverify.so and libjvm.so were found in /usr/local/jdk1.4.2/jre/lib/i386/ > 2) When I add the -rpath, I get two copies of a libjvm.so reference in te= stme, > one that resolves correctly, and one that doesn't. Why? What happens is that libjava.so "depends" on libjvm.so and libverify.so itself: % ldd /usr/local/jdk1.4.2/jre/lib/i386/libjava.so /usr/local/jdk1.4.2/jre/lib/i386/libjava.so: libjvm.so =3D> not found (0x0) libverify.so =3D> not found (0x0) and libverify.so "depends" on libjvm.so itself: % ldd /usr/local/jdk1.4.2/jre/lib/i386/libverify.so /usr/local/jdk1.4.2/jre/lib/i386/libverify.so: libjvm.so =3D> not found (0x0) So, after finding libjava.so, libverify.so and libjvm.so, required by "testme" executable (thanks to its RPATH) the linker sees that libjava.so itself depends on libjvm.so and libverify.so and: 1. does not notice that they are already found/loaded 2. does not use the rpath in "testme" 3. starts looking for them in the standard path and does not find them > 3) What is the correct way of linking in libjvm.so? In my point of view the libjava.so and libverify.so shared objects are incorrect in the way that they depend on some shared objects, that are not located in the standard path *AND* libjava.so and libverify.so do not have RPATH in themselves. 1. Recompile libjava.so and libverify.so without -L... -l..., it is not needed anyway. OR 2. Recompile libjava.so and libverify.so with -L... -l..., but also add -rpath OR 3. Use ldconfig -m (see ldconfig_paths in rc.conf(5)) OR 4. Use LD_LIBRARY_PATH > Thanks, > --=20 > Tom Schutter --8t9RHnE3ZwKMSgU+ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- iD8DBQFCy3CJFw6SP/bBpCARAtyGAJ9K6OFpelWLTpuK0NMC2bu23k7vXwCfb/lK K+gwOShoPSA0Mh61KH37lx8= =OEYJ -----END PGP SIGNATURE----- --8t9RHnE3ZwKMSgU+--