From owner-freebsd-dtrace@FreeBSD.ORG Fri Jan 30 06:14:02 2015 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 00560A65 for ; Fri, 30 Jan 2015 06:14:01 +0000 (UTC) Received: from mail-pa0-x22b.google.com (mail-pa0-x22b.google.com [IPv6:2607:f8b0:400e:c03::22b]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C33127F3 for ; Fri, 30 Jan 2015 06:14:01 +0000 (UTC) Received: by mail-pa0-f43.google.com with SMTP id eu11so48450089pac.2 for ; Thu, 29 Jan 2015 22:14:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=K1zyLU2KjJPeLL/v8znRtdFizz5iapklAGr8x8JZmdc=; b=yTXz5IYFl9rwu9/u9nHFR8S41rY4eyN8D63UTe0ckKszGjG70NgHdU9q/041yupWw8 /FEqLZsv9XisqR+G3ow9PRD+UcvsVNjpLEMvHMiFgXTyJLS1CR3zF13Cce9zr0KciKhx S1qrUCRVYg7aXoN91Zykp6NKOJHSKbviUZhL31x6xybORBZRsglDMpni8PQEh7MjBhgb e1SBx2pNFvAkyBSL6wYx9cR7BrPCLRPf35Q8DkRyE7GS6ds0DSwDjGptTw6QIhQHgJuN i1D3SB/yFdN6femlE3Y0M3ep5LGjrXJLKatZ+KoGTO3hDhf/NkBZlB2H17zXxyd4wNVl 0kdg== X-Received: by 10.66.66.68 with SMTP id d4mr6687146pat.44.1422598441401; Thu, 29 Jan 2015 22:14:01 -0800 (PST) Received: from raichu (216-243-33-197.users.condointernet.net. [216.243.33.197]) by mx.google.com with ESMTPSA id or4sm9683857pab.30.2015.01.29.22.13.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jan 2015 22:14:00 -0800 (PST) Sender: Mark Johnston Date: Thu, 29 Jan 2015 22:13:55 -0800 From: Mark Johnston To: freebsd-dtrace@freebsd.org Subject: removing USDT's libelf dependency Message-ID: <20150130061355.GA14037@raichu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: freebsd-dtrace@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "A discussion list for developers working on DTrace in FreeBSD." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jan 2015 06:14:02 -0000 Hello, At the moment, any FreeBSD program containing USDT probes needs to be linked with libelf. This is so that drti.o can find the address of the DOF section within the executable or library. With this, it can extract the DOF and load it into the kernel prior to beginning execution. This requirement is an annoyance since it's specific to FreeBSD and many upstream projects which support DTrace aren't aware of it, so some patching is necessary to get their probes working on FreeBSD. It also increases the startup cost of programs containing USDT probes, which can be significant for e.g. sh(1) or libc/libthr (plockstat). Solaris exploits a feature of its linker to solve this problem - the dtrace -G step emits an object file containing a symbol called __SUNW_dof; the linker knows to fill in the value of this symbol with the address of the DOF section, so drti.o begins execution with the DOF section already available. It turns out that GNU ld implements a similar feature, albeit in a more restrictive manner: a symbol named __start_ will have its value filled in with the address of the section named . The catch is that has to be a valid C identifier, and the DOF section is conventionally named ".SUNW_dof", which of course doesn't quite work. I propose using "SUNW_dof" instead so that we can make use of this linker feature and eliminate the libelf dependency. DOF sections have their own ELF section type (SHT_SUNW_dof), so anything that might want to find a DOF section should already be searching for that rather than the conventional name. Depending on this linker feature is also arguably a portability concern given that lld is on the horizon, but we depend on it already anyway - this feature is used in FreeBSD's linker set implementation (which in turn is used by our SDT code :). So I don't think this would introduce a new problem. Any thoughts? Thanks, -Mark From owner-freebsd-dtrace@FreeBSD.ORG Fri Jan 30 10:36:39 2015 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 81D439F7; Fri, 30 Jan 2015 10:36:39 +0000 (UTC) Received: from vps.hungerhost.com (vps.hungerhost.com [216.38.53.176]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5C05D5EE; Fri, 30 Jan 2015 10:36:39 +0000 (UTC) Received: from [81.168.91.50] (port=53407 helo=[172.16.19.1]) by vps.hungerhost.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82) (envelope-from ) id 1YH8wB-0001Bl-PP; Fri, 30 Jan 2015 05:36:32 -0500 From: "George Neville-Neil" To: "Mark Johnston" Subject: Re: removing USDT's libelf dependency Date: Fri, 30 Jan 2015 10:36:19 +0000 Message-ID: In-Reply-To: <20150130061355.GA14037@raichu> References: <20150130061355.GA14037@raichu> MIME-Version: 1.0 X-Mailer: MailMate (1.8r5035) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vps.hungerhost.com X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - neville-neil.com X-Get-Message-Sender-Via: vps.hungerhost.com: authenticated_id: gnn@neville-neil.com Cc: freebsd-dtrace@freebsd.org X-BeenThere: freebsd-dtrace@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "A discussion list for developers working on DTrace in FreeBSD." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jan 2015 10:36:39 -0000 On 30 Jan 2015, at 6:13, Mark Johnston wrote: > Hello, > > At the moment, any FreeBSD program containing USDT probes needs to be > linked with libelf. This is so that drti.o can find the address of the > DOF section within the executable or library. With this, it can extract > the DOF and load it into the kernel prior to beginning execution. > > This requirement is an annoyance since it's specific to FreeBSD and > many upstream projects which support DTrace aren't aware of it, so some > patching is necessary to get their probes working on FreeBSD. It also > increases the startup cost of programs containing USDT probes, which can > be significant for e.g. sh(1) or libc/libthr (plockstat). > > Solaris exploits a feature of its linker to solve this problem - the > dtrace -G step emits an object file containing a symbol called > __SUNW_dof; the linker knows to fill in the value of this symbol with > the address of the DOF section, so drti.o begins execution with the DOF > section already available. > > It turns out that GNU ld implements a similar feature, albeit in a more > restrictive manner: a symbol named __start_ will have its value > filled in with the address of the section named . The catch is that > has to be a valid C identifier, and the DOF section is > conventionally named ".SUNW_dof", which of course doesn't quite work. I > propose using "SUNW_dof" instead so that we can make use of this linker > feature and eliminate the libelf dependency. > > DOF sections have their own ELF section type (SHT_SUNW_dof), so > anything that might want to find a DOF section should already be > searching for that rather than the conventional name. Depending on this > linker feature is also arguably a portability concern given that lld is > on the horizon, but we depend on it already anyway - this feature is > used in FreeBSD's linker set implementation (which in turn is used by > our SDT code :). So I don't think this would introduce a new problem. > > Any thoughts? > Do it. I can't see a problem thus far. Best, George From owner-freebsd-dtrace@FreeBSD.ORG Fri Jan 30 15:15:31 2015 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 41CADF2E; Fri, 30 Jan 2015 15:15:31 +0000 (UTC) Received: from mail-qg0-x234.google.com (mail-qg0-x234.google.com [IPv6:2607:f8b0:400d:c04::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F09EF926; Fri, 30 Jan 2015 15:15:30 +0000 (UTC) Received: by mail-qg0-f52.google.com with SMTP id z107so38540851qgd.11; Fri, 30 Jan 2015 07:15:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=kVL0vvEVrqXwfE1k4spDvWI9vZI6BtxuKdSty/F90NA=; b=OEKRqKXaQOABCVKvlQUzkZAayobqVeSKka0LX7T2ur9JUJ3BknkEghHSG5hSU4FIKt ZMPHqIDZeul12ufgGUvb4CJyKxOn+VDsYzEMJGMydOIrgwPiR2Smf2sTsFZjZvHbHwW6 FgF+dWXOJYovz+wJ01cadszhFdh4uBfho+TQs1kH3uuPk+TALPdODD5brwLfzgREJitl GR1xrqx7lRjjV3fZZOBvmAcoA2q1EIAnFGYNL7xCaWQdupqgk+EngTwJRsZ+wkgZazOj g7oa4NxvREeh9/ns6N9necslPcCSGL0AcVqwgJJiYWh+Wsou0iJmtMgdOH+ekbfb2s8p wKeQ== X-Received: by 10.224.30.145 with SMTP id u17mr13202732qac.46.1422630930156; Fri, 30 Jan 2015 07:15:30 -0800 (PST) MIME-Version: 1.0 Sender: carpeddiem@gmail.com Received: by 10.140.39.209 with HTTP; Fri, 30 Jan 2015 07:15:09 -0800 (PST) In-Reply-To: <20150130061355.GA14037@raichu> References: <20150130061355.GA14037@raichu> From: Ed Maste Date: Fri, 30 Jan 2015 10:15:09 -0500 X-Google-Sender-Auth: lcW8pfKmHUBiKj5zfCpasIJo16w Message-ID: Subject: Re: removing USDT's libelf dependency To: Mark Johnston Content-Type: text/plain; charset=UTF-8 Cc: freebsd-dtrace@freebsd.org X-BeenThere: freebsd-dtrace@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "A discussion list for developers working on DTrace in FreeBSD." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jan 2015 15:15:31 -0000 On 30 January 2015 at 01:13, Mark Johnston wrote: > > It turns out that GNU ld implements a similar feature, albeit in a more > restrictive manner: a symbol named __start_ will have its value > filled in with the address of the section named . The catch is that > has to be a valid C identifier, and the DOF section is > conventionally named ".SUNW_dof", which of course doesn't quite work. I > propose using "SUNW_dof" instead so that we can make use of this linker > feature and eliminate the libelf dependency. > > DOF sections have their own ELF section type (SHT_SUNW_dof), so > anything that might want to find a DOF section should already be > searching for that rather than the conventional name. Depending on this > linker feature is also arguably a portability concern given that lld is > on the horizon, but we depend on it already anyway - this feature is > used in FreeBSD's linker set implementation (which in turn is used by > our SDT code :). So I don't think this would introduce a new problem. I'm not worried about issues with lld here - we can make it meet our requirements. I am a little worried that there will be code floating around that does strcmp(foo, ".SUNW_dof") though. A quick search turned up some examples. Most are copies of drti.c but I did find one case in some markjdb Github repo :-) Even if we don't end up changing .SUNW_dof I think we should convert these cases to use the section type instead of name. We could give GNU ld 2.17.50 and lld knowledge of .SUNW_dof and __SUNW_dof. This looks like it would be straightforward, but at the cost of carrying around different FreeBSD-specific changes. I think our best approach will be to find an approach that upstream linker projects (GNU ld, gold, lld) are willing to support. But, until or unless that happens I'd much rather we switch to SUNW_dof than require linking against libelf. From owner-freebsd-dtrace@FreeBSD.ORG Fri Jan 30 22:10:31 2015 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CEDBC681; Fri, 30 Jan 2015 22:10:31 +0000 (UTC) Received: from mail-pa0-x22c.google.com (mail-pa0-x22c.google.com [IPv6:2607:f8b0:400e:c03::22c]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 95F77EA7; Fri, 30 Jan 2015 22:10:31 +0000 (UTC) Received: by mail-pa0-f44.google.com with SMTP id rd3so57216623pab.3; Fri, 30 Jan 2015 14:10:31 -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=AhS7PjxOgNlEORIrKxDDzFi99ea/mfNMlz76Ew/DkOo=; b=qGS1oGQ/36SuJSsvyF31EbM8tMbuzHpjl1TlmY31++VIRVL7QD/NNYckTYB7Ex+k8r qZx9Ac3QpwCbE74uwQkrJw3ScMaidJ+fDLBVq5F79NSmY/20vsNnHoYiL5RLU6fWS3Wh dBffSQcEXsU12kx9j2qONAITJMdoNZSAJruo/2L2xnJGXMrzQyV9qX171uDJycBwmYRt ghjlXIF1qDsemqB5VxDKDAr+faTLYVQeWP6kft7+Z+sdgMJY2dIaGAMU4jsJHKYIvsIq t31T5O29lKODgmua0rQRxPBQD+XTVKcg/P3wj/alJFt+FfyLxt0UFnq8XzB3GYl5A+WA UEvw== X-Received: by 10.66.194.102 with SMTP id hv6mr12171267pac.138.1422655830897; Fri, 30 Jan 2015 14:10:30 -0800 (PST) Received: from charmander.picturesperfect.net (c-67-182-131-225.hsd1.wa.comcast.net. [67.182.131.225]) by mx.google.com with ESMTPSA id mw3sm11766372pdb.30.2015.01.30.14.10.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jan 2015 14:10:29 -0800 (PST) Sender: Mark Johnston Date: Fri, 30 Jan 2015 14:10:24 -0800 From: Mark Johnston To: Ed Maste Subject: Re: removing USDT's libelf dependency Message-ID: <20150130221024.GA2731@charmander.picturesperfect.net> References: <20150130061355.GA14037@raichu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Cc: freebsd-dtrace@freebsd.org X-BeenThere: freebsd-dtrace@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "A discussion list for developers working on DTrace in FreeBSD." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jan 2015 22:10:32 -0000 On Fri, Jan 30, 2015 at 10:15:09AM -0500, Ed Maste wrote: > On 30 January 2015 at 01:13, Mark Johnston wrote: > > > > It turns out that GNU ld implements a similar feature, albeit in a more > > restrictive manner: a symbol named __start_ will have its value > > filled in with the address of the section named . The catch is that > > has to be a valid C identifier, and the DOF section is > > conventionally named ".SUNW_dof", which of course doesn't quite work. I > > propose using "SUNW_dof" instead so that we can make use of this linker > > feature and eliminate the libelf dependency. > > > > DOF sections have their own ELF section type (SHT_SUNW_dof), so > > anything that might want to find a DOF section should already be > > searching for that rather than the conventional name. Depending on this > > linker feature is also arguably a portability concern given that lld is > > on the horizon, but we depend on it already anyway - this feature is > > used in FreeBSD's linker set implementation (which in turn is used by > > our SDT code :). So I don't think this would introduce a new problem. > > I'm not worried about issues with lld here - we can make it meet our > requirements. I am a little worried that there will be code floating > around that does strcmp(foo, ".SUNW_dof") though. A quick search > turned up some examples. Most are copies of drti.c but I did find one > case in some markjdb Github repo :-) Heh, oops. > Even if we don't end up changing > .SUNW_dof I think we should convert these cases to use the section > type instead of name. I agree. In the case of drti.c, we look for both the section type and name. There isn't much else out there that looks for a DOF section. > > We could give GNU ld 2.17.50 and lld knowledge of .SUNW_dof and > __SUNW_dof. This looks like it would be straightforward, but at the > cost of carrying around different FreeBSD-specific changes. > > I think our best approach will be to find an approach that upstream > linker projects (GNU ld, gold, lld) are willing to support. But, until > or unless that happens I'd much rather we switch to SUNW_dof than > require linking against libelf. Ok. It looks like gold also supports the __start_ feature from GNU ld; there's a thread about handling the case where starts with a period here: http://comments.gmane.org/gmane.comp.gnu.binutils/61852, though it didn't really go anywhere. lld doesn't support the feature AFAICS. For now I'd rather just change the section name. -Mark