dl_iterate_phdr() omits ld-elf.so

Konstantin Belousov kostikbel at gmail.com
Wed Nov 6 17:13:08 UTC 2013


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 ?
-------------- 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/20131106/d69b8460/attachment.sig>


More information about the freebsd-hackers mailing list