Date: Mon, 15 Jun 2020 22:31:40 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: John Baldwin <jhb@freebsd.org> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r362152 - head/usr.bin/ldd Message-ID: <20200615193140.GB45690@kib.kiev.ua> In-Reply-To: <d50cf8d5-0d99-7cb3-3d7e-4981345c7ee3@FreeBSD.org> References: <202006131821.05DILVnR053798@repo.freebsd.org> <d50cf8d5-0d99-7cb3-3d7e-4981345c7ee3@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jun 15, 2020 at 11:45:31AM -0700, John Baldwin wrote: > On 6/13/20 11:21 AM, Konstantin Belousov wrote: > > Author: kib > > Date: Sat Jun 13 18:21:31 2020 > > New Revision: 362152 > > URL: https://svnweb.freebsd.org/changeset/base/362152 > > > > Log: > > Fix ldd for PIE binaries after rtld stopped accepting binaries for dlopen. > > > > ldd proclaims ET_DYN objects as shared libraries and tries to > > dlopen(RTLD_TRACE) them to get dependencies. Since PIE binaries are > > ET_DYN | DF_1_PIE, refusal to dlopen such binaries breaks ldd. > > > > Fix it by reading and parsing dynamic segment looking for DF_FLAG_1 > > and taking DF_1_PIE into account when deciding between binary and > > library. > > Hmmm, I have an alternate patch for this that instead depends on the > present of PT_INTERP (since we already look at program headers) to > determine PIE vs not-PIE. >From my understanding of some discussions on the ABI list PT_INTERP is not the characteristic property of the binary. Instead it is ET_EXEC | (ET_DYN && DF_1_PIE), i.e. this is the reason why the flag was added. > This has the advantage of working for older > binaries since DF_1_PIE is relatively recent. (I had also changed it to > use libelf to reduce code duplication for the 32-bit compat stuff, but > it was pending on getting the branding sorted out since it still doesn't > fully work for RISC-V and aarch64 shared libraries until they are > branded as the patches also look at notes sections to check for the > FreeBSD ABI note tag to decide if a shared library is a FreeBSD one that > can be passed to dlopen()). Initially I considered to just reenable dlopening ET_DYN && DF_1_PIE for tracing. After your note about old binaries without DF_1_PIE, I think it is even better idea. I do not have an opinion on use of libelf in ldd. It is fine, perhaps, since I do not think about ldd as anything fundamental, just a convenience wrapper around rtld. So one more dependency for ldd is not that critical.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200615193140.GB45690>