svn commit: r362152 - head/usr.bin/ldd

Konstantin Belousov kostikbel at gmail.com
Mon Jun 15 19:31:50 UTC 2020


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.


More information about the svn-src-all mailing list