From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 6 22:14:00 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 634A7B5D for ; Wed, 6 Nov 2013 22:14:00 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-ie0-x230.google.com (mail-ie0-x230.google.com [IPv6:2607:f8b0:4001:c03::230]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 33BB62301 for ; Wed, 6 Nov 2013 22:14:00 +0000 (UTC) Received: by mail-ie0-f176.google.com with SMTP id u16so252787iet.21 for ; Wed, 06 Nov 2013 14:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=sjwPYaD1GOtrev8HTqaJyPwOYubcgzz1tDt/2gFNbWQ=; b=qDcTH0vOkawRiKDbboIspE2GXuUWZ0z0E8Vu9NHYizbMx55x3CkmtcFPFZL8evFH2r R01nzf6gFnPkTfKv9W/MxQ03PkQmGK/cGbT87RSYLMothYkcygG98gHBWP1aZIGyKl6D mWkkp7vLrIp6u/BHJdaRqVo6/c87lyg6//sS9b0m2TKxAbGeT00NMWdkTR7RWpl891It rSpoEY6pgagnMVMU73leMqz6i+Bd84PpPJYAROZUkU7kjZmj+57f2ljU3zpAJryt78be ZNeA132hsUlLDe6/gCZU+Xh4qCg13PA4z6G8zmyRc9QLlNvX/n6DZIux5Eq0zmRwMWBu 9Ykg== X-Received: by 10.42.128.207 with SMTP id n15mr3536647ics.7.1383776039538; Wed, 06 Nov 2013 14:13:59 -0800 (PST) Received: from charmander.sandvine.com ([64.7.137.182]) by mx.google.com with ESMTPSA id x5sm455908iga.6.2013.11.06.14.13.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Nov 2013 14:13:59 -0800 (PST) Sender: Mark Johnston Date: Wed, 6 Nov 2013 18:13:52 -0500 From: Mark Johnston To: Konstantin Belousov Subject: Re: dl_iterate_phdr() omits ld-elf.so Message-ID: <20131106231352.GB86666@charmander.sandvine.com> References: <20131106052010.GB2826@raichu> <20131106171301.GG59496@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20131106171301.GG59496@kib.kiev.ua> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Nov 2013 22:14:00 -0000 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 /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