From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12411 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: BUG: $ORIGIN does not seem to work Date: Sat, 27 Jan 2018 12:07:22 +0100 Message-ID: <20180127110722.GI4418@port70.net> References: <17b31628-04b5-3181-4623-046ffc4c0cab@petroprogram.com> <20180126142137.GH4418@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1517051139 24513 195.159.176.226 (27 Jan 2018 11:05:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 27 Jan 2018 11:05:39 +0000 (UTC) User-Agent: Mutt/1.9.1 (2017-09-22) Cc: musl@lists.openwall.com To: Stefan =?iso-8859-1?Q?Fr=F6berg?= Original-X-From: musl-return-12427-gllmg-musl=m.gmane.org@lists.openwall.com Sat Jan 27 12:05:34 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1efOIf-00066Y-Pn for gllmg-musl@m.gmane.org; Sat, 27 Jan 2018 12:05:33 +0100 Original-Received: (qmail 23677 invoked by uid 550); 27 Jan 2018 11:07:34 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 23659 invoked from network); 27 Jan 2018 11:07:34 -0000 Mail-Followup-To: Stefan =?iso-8859-1?Q?Fr=F6berg?= , musl@lists.openwall.com Content-Disposition: inline In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:12411 Archived-At: * Stefan Fr=F6berg [2018-01-27 01:50:21 += 0200]: > My ldd is just symbolic link inside musl chroot environment, to > /lib/ld-musl-x86_64.so.1 > and it's symbolic link to /lib/libc.so >=20 > Here is readelf output of that test program > readelf -d x >=20 > Dynamic section at offset 0xe10 contains 24 entries: > =A0 Tag=A0=A0=A0=A0=A0=A0=A0 Type=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Name/Value > =A00x0000000000000001 (NEEDED)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Shared= library: [libcrypto.so.1.1] ^^^^^^^^^^^^^^^^ this looks like the wrong library version if you had straced the ldd output you would have seen that musl tries to open lib/libcrypto.so.1.1, but you probably only have lib/libcrypto.so.1.0.0 based on the glibc ldd output below. at link time you need to make sure ld picks up the right libcrypto. > =A00x0000000000000001 (NEEDED)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Shared= library: [libc.so] > =A00x000000000000000f (RPATH)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Libr= ary rpath: [$ORIGIN/lib] > =A00x000000000000000c (INIT)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x= 598 > =A00x000000000000000d (FINI)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x= 812 > =A00x000000006ffffef5 (GNU_HASH)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x220 > =A00x0000000000000005 (STRTAB)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x390 > =A00x0000000000000006 (SYMTAB)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x258 > =A00x000000000000000a (STRSZ)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 241 = (bytes) > =A00x000000000000000b (SYMENT)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 24 (by= tes) > =A00x0000000000000015 (DEBUG)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x0 > =A00x0000000000000003 (PLTGOT)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x2010= 00 > =A00x0000000000000002 (PLTRELSZ)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 48 (bytes) > =A00x0000000000000014 (PLTREL)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 RELA > =A00x0000000000000017 (JMPREL)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x568 > =A00x0000000000000007 (RELA)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x= 4c0 > =A00x0000000000000008 (RELASZ)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 168 (b= ytes) > =A00x0000000000000009 (RELAENT)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 24 (byte= s) > =A00x000000006ffffffb (FLAGS_1)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Flags: P= IE > =A00x000000006ffffffe (VERNEED)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x4a0 > =A00x000000006fffffff (VERNEEDNUM)=A0=A0=A0=A0=A0=A0=A0=A0 1 > =A00x000000006ffffff0 (VERSYM)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x482 > =A00x000000006ffffff9 (RELACOUNT)=A0=A0=A0=A0=A0=A0=A0=A0=A0 2 > =A00x0000000000000000 (NULL)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 0x0 >=20 > So the $ORIGIN/lib is there but for some reason ldd won't show it??? >=20 > Best Regards > Stefan Fr=F6berg >=20 > Szabolcs Nagy kirjoitti 26.01.2018 klo 16:21: > > * Stefan Fr=F6berg [2018-01-26 15:39:= 23 +0200]: > >> On glibc the following: > >> > >> gcc=A0 -o x -Wl,-rpath=3D'$ORIGIN/lib' x.c -L ./lib -lcrypto > >> > >> or > >> > >> gcc=A0 -o x -Wl,-rpath,'$ORIGIN/lib' x.c -L ./lib -lcrypto > >> > >> Gives me binary with relative library path > >> > >> ldd x > >> =A0=A0=A0 linux-vdso.so.1 (0x00007ffcb6bee000) > >> *=A0=A0=A0 libcrypto.so.1.0.0 =3D> /home/wizard/kal-el/lib/libcrypto.s= o.1.0.0 > >> (0x00007f0bc3593000)** > >> *=A0=A0=A0 libc.so.6 =3D> /lib64/libc.so.6 (0x00007f0bc31e2000) > >> =A0=A0=A0 libdl.so.2 =3D> /lib64/libdl.so.2 (0x00007f0bc2fde000) > >> =A0=A0=A0 libz.so.1 =3D> /lib64/libz.so.1 (0x00007f0bc2dc7000) > >> =A0=A0=A0 /lib64/ld-linux-x86-64.so.2 (0x00007f0bc39d2000) > >> > >> cp -rap kal-el/* batman/ > >> ldd x > >> =A0=A0=A0 linux-vdso.so.1 (0x00007ffdbf0b6000) > >> *=A0=A0=A0 libcrypto.so.1.0.0 =3D> /home/wizard/batman/lib/libcrypto.s= o.1.0.0 > >> (0x00007fb682149000)** > >> *=A0=A0=A0 libc.so.6 =3D> /lib64/libc.so.6 (0x00007fb681d98000) > >> =A0=A0=A0 libdl.so.2 =3D> /lib64/libdl.so.2 (0x00007fb681b94000) > >> =A0=A0=A0 libz.so.1 =3D> /lib64/libz.so.1 (0x00007fb68197d000) > >> =A0=A0=A0 /lib64/ld-linux-x86-64.so.2 (0x00007fb682588000) > >> > >> > >> But trying the same with musl does not seem to work? > >> ldd x > >> /lib/ld-musl-x86_64.so.1 (0x7f07372e2000) > >> =A0=A0=A0 libc.so =3D> /lib/ld-musl-x86_64.so.1 (0x7f07372e2000) > >> > >> and if i remove the -L ./lib from the command it uses system library > >> gcc=A0 -o x -Wl,-rpath,'$ORIGIN/lib'=A0 x.c=A0=A0 -lcrypto > >> ldd xx > >> =A0=A0=A0 /lib/ld-musl-x86_64.so.1 (0x7fdd8618d000) > >> =A0=A0=A0 libcrypto.so.1.1 =3D> /usr/lib/libcrypto.so.1.1 (0x7fdd85ed7= 000) > >> =A0=A0=A0 libc.so =3D> /lib/ld-musl-x86_64.so.1 (0x7fdd8618d000) > >> > >> > > $ORIGIN in rpath works fine in musl > > > > you are doing something wrong > > > > but it's hard to tell what: your ldd command is looking at > > the wrong binary, we don't know what ldd you are using (e.g. > > use ld-*-musl.so.1 --list foo to make this explicit), it's > > not clear if the binary has $ORIGIN set up correctly since > > you showed a gcc command line instead of readelf -d of the > > generated executable, we don't know what paths have the > > library and what paths the ldso tried (you can check this > > by strace). > > > > (there are some differences between musl and glibc: > > e.g. glibc expands $ORIGIN in dlopen too while musl does > > not, however in your case musl should work)