dl_iterate_phdr() omits ld-elf.so

Konstantin Belousov kostikbel at gmail.com
Thu Nov 7 06:12:40 UTC 2013


On Wed, Nov 06, 2013 at 06:13:52PM -0500, Mark Johnston wrote:
> On Wed, Nov 06, 2013 at 07:13:01PM +0200, Konstantin Belousov wrote:
> > On Wed, Nov 06, 2013 at 12:20:10AM -0500, Mark Johnston wrote:
> > > Hello,
> > > 
> > > While experimenting with dl_iterate_phdr(3), I noticed that it doesn't
> > > include the runtime linker itself in the list of objects. This is
> > > inconsistent with related interfaces such as <pid>/map in procfs, and
> > > kinfo_getvmmap(3), so it seems incorrect to me that rtld is excluded
> > > from the list of callback arguments.
> > > 
> > > Is there a reason for this behaviour? If not, does anyone have thoughts
> > > on the diff below which fixes this?
> > > 
> > > Thanks,
> > > -Mark
> > > 
> > > diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
> > > index fa6dc2a..b55effa 100644
> > > --- a/libexec/rtld-elf/rtld.c
> > > +++ b/libexec/rtld-elf/rtld.c
> > > @@ -3269,6 +3269,11 @@ dl_iterate_phdr(__dl_iterate_hdr_callback callback, void *param)
> > >  		break;
> > >  
> > >      }
> > > +    if (error == 0) {
> > > +	rtld_fill_dl_phdr_info(&obj_rtld, &phdr_info);
> > > +	error = callback(&phdr_info, sizeof(phdr_info), param);
> > > +    }
> > > +
> > >      lock_release(rtld_bind_lock, &bind_lockstate);
> > >      lock_release(rtld_phdr_lock, &phdr_lockstate);
> > 
> > I cannot make a case where this patch would be problematic, but rtld is
> > very special object in the process address space indeed. The patch is
> > needed exactly because rtld is not included into the list of the loaded
> > objects, and more, symbol resolution from rtld is a special case. Doing
> > dlopen() on rtld path would probably break things in funny way.
> > 
> > Still, I think the patch is worth committing, but be prepared to handle
> > the broken cases, which could come out in quite indirect ways.
> > 
> > BTW, why do you need this ?
> 
> I was just trying to find a portable way to figure out the address at
> which a given object was located, and noticed the omission because the
> runtime linker is included in the list on Linux. It seemed like a bug to
> me just based on what dl_iterate_phdr(3) is supposed to do: invoke a
> callback for each loaded ELF object, which includes rtld even though
> it's special.
> 
> So I don't really need this change. In this case, do you still think
> it's worth committing? Or should I just leave it alone?

It seems to make the function more logical.  As I said, I think that the
patch is worth committing.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20131107/66029ccc/attachment.sig>


More information about the freebsd-hackers mailing list