Date: Wed, 6 Nov 2013 18:13:52 -0500 From: Mark Johnston <markj@freebsd.org> To: Konstantin Belousov <kostikbel@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: dl_iterate_phdr() omits ld-elf.so Message-ID: <20131106231352.GB86666@charmander.sandvine.com> In-Reply-To: <20131106171301.GG59496@kib.kiev.ua> References: <20131106052010.GB2826@raichu> <20131106171301.GG59496@kib.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
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? -Mark
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20131106231352.GB86666>