From nobody Tue Jun 07 00:52:40 2022 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C772E1BE4513 for ; Tue, 7 Jun 2022 00:53:23 +0000 (UTC) (envelope-from nyan@myuji.xyz) Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4LHBg40xzyz4gn5 for ; Tue, 7 Jun 2022 00:53:19 +0000 (UTC) (envelope-from nyan@myuji.xyz) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 9E2EE5C0174; Mon, 6 Jun 2022 20:53:13 -0400 (EDT) Received: from imap45 ([10.202.2.95]) by compute4.internal (MEProxy); Mon, 06 Jun 2022 20:53:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=myuji.xyz; h=cc :cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1654563193; x=1654649593; bh=IZnhLyOZuP m/AZth2QTYlblLeQgW86ivAyCSxZYY9K8=; b=IkIqgx10n7YQm30fzq1uVZVe5C PAUcRqVUR7mBSGzrnoM+8gqIFkdutT0EXRqOOdK2Js8uxZw7SMXMzrd+BhT6V73j XeJfOxCf5JwlczC6k8B9YtMbp+WjVAhMoc/4176cJYO2A/IKigtL4RNn8ZPGVUWb /AXMhzvofG/wXLR9C2s7O6iiMSYHQyEIiN8H0mSH7CzFbbJqe7NyWSNVRA1EHIbD BUtLlFD5+tpYKXqSYdGOg5YkB1eQFLlzwJlWBcosprp6ekkcBWjZvtsuFJ7SJZav dOmZUNmCqJRcZH3DXxRNMG1eEaai6DbrY9vNCgwI4AkJliUOYw5qZbb5bvSQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1654563193; x=1654649593; bh=IZnhLyOZuPm/AZth2QTYlblLeQgW 86ivAyCSxZYY9K8=; b=SISlPVfB+lxJbk6XXA+QfaN+HF5YmbNVqwVHRHYnk216 8WUAX1DRjUd/Inc5reCxCKI1B5rWuXKlyFnpCTDOgMoiEV0hQURntLD0MkHdkaz7 rgpEeWwC2qKiE42FeFZ3S74EIuJFAF8TcVTtjBSZVOl3LBRBxpsq8WMbzK8NBx5m DW5iRUjcaOeHA7s9Du1GpW9ubuNUO5nwRRPL90oeyNiAFW8GXHV1Hp0vYr2fgnoF B3MQoJDOHtCk2seZOxZF+XJHjiXRh5c32d89SJ6lGG+yvdM/uQXHM+UVBXjyIoE9 HnYBk0QQc+iLfeB6LtdCqY/Nk0khWJG1MOyNNjnBPQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedruddtgedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfeehmdenucfjughrpefofg ggkfgjfhffhffvvefutgesrgdtreerreerjeenucfhrhhomhepfdfoihgthhgrvghlucgj rghnucfmrgcuvehhihhufdcuoehnhigrnhesmhihuhhjihdrgiihiieqnecuggftrfgrth htvghrnhepuddtkedtgedtueejtdelhffhiedtuddtkeelgefguedvtdfghfevffeiuedu ffejnecuffhomhgrihhnpehgihhthhhusgdrtghomhdprhgvtghorhgurdhrshenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehnhigrnhesmhih uhhjihdrgiihii X-ME-Proxy: Feedback-ID: i9dd946d0:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 5058C2720072; Mon, 6 Jun 2022 20:53:13 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-592-g7095c13f5a-fm-20220603.004-g7095c13f List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org Mime-Version: 1.0 Message-Id: <717e9669-425a-4aae-9178-99d031d606f2@www.fastmail.com> In-Reply-To: References: <51c74c5b-731a-445f-be96-0baf6cd0ebe2@www.fastmail.com> Date: Tue, 07 Jun 2022 08:52:40 +0800 From: "Michael Yan Ka Chiu" To: "Konstantin Belousov" Cc: freebsd-hackers@freebsd.org Subject: Re: Help needed to get Rust dtrace USDT working on/with FreeBSD linker Content-Type: multipart/alternative; boundary=852b2e739d824269a0a618ba8ae1a5db X-Rspamd-Queue-Id: 4LHBg40xzyz4gn5 X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=myuji.xyz header.s=fm2 header.b=IkIqgx10; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=SISlPVfB; dmarc=none; spf=pass (mx1.freebsd.org: domain of nyan@myuji.xyz designates 66.111.4.26 as permitted sender) smtp.mailfrom=nyan@myuji.xyz X-Spamd-Result: default: False [-3.59 / 15.00]; XM_UA_NO_VERSION(0.01)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; R_SPF_ALLOW(-0.20)[+ip4:66.111.4.26]; RWL_MAILSPIKE_GOOD(0.00)[66.111.4.26:from]; RCVD_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[myuji.xyz:+,messagingengine.com:+]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_SHORT(-1.00)[-0.996]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:19151, ipnet:66.111.4.0/24, country:US]; RCVD_IN_DNSWL_LOW(-0.10)[66.111.4.26:from]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; R_DKIM_ALLOW(-0.20)[myuji.xyz:s=fm2,messagingengine.com:s=fm2]; FREEFALL_USER(0.00)[nyan]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DMARC_NA(0.00)[myuji.xyz]; DWL_DNSWL_LOW(-1.00)[messagingengine.com:dkim]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MLMMJ_DEST(0.00)[freebsd-hackers]; MID_RHS_WWW(0.50)[] X-ThisMailContainsUnwantedMimeParts: N --852b2e739d824269a0a618ba8ae1a5db Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Jun 7, 2022, at 3:40 AM, Konstantin Belousov wrote: > On Mon, Jun 06, 2022 at 03:44:32AM +0800, Michael Yan Ka Chiu wrote: > > On Mon, Jun 6, 2022, at 3:01 AM, Konstantin Belousov wrote: > > > On Sun, Jun 05, 2022 at 04:26:37PM +0800, Michael Yan Ka Chiu wrot= e: > > > > Hi everyone, > > > >=20 > > > > I=E2=80=99m working on a PR to get the Rust Usdt crate working o= n FreeBSD. This crate > > > > basically allow adding DTrace probes to rust sources by compilin= g the probe during > > > > macro invocation and embed to a custom section (set_dtrace_probe= ) using inline=20 > > > > assembly. > > > >=20 > > > > The problem I am encountering is that the linker will optimize t= he compiled probes > > > > out in the custom section, the only workaround I have found is t= o force the linker to > > > > link all the dead code by invoking `-C link-dead-code=3Dyes`. On= Illumos, the workaround > > > > is to reference another section such that the Illumos linker wil= l not throw the probes=20 > > > > away; however the same workaround does not work on FreeBSD. > > > >=20 > > > > I wonder if there're any tricks similar to the Illumos fix, by p= utting some inline asm there > > > > to trick the linker and not throw out the probes. > > > >=20 > > > > Thanks In advance, > > > > Michael > > > >=20 > > > > References: > > > > The PR: https://github.com/oxidecomputer/usdt/pull/63 > > > > The illumos fix: https://github.com/oxidecomputer/usdt/blob/eac0= fe5f03c3fbf23468ead5cb140f62d51ac3f3/usdt-impl/src/record.rs#L251 > > > >=20 > > > > =20 > > >=20 > > > GNU as seems to gain support for the "R" flag for sections, which = should > > > prevent them from linker GC. Not sure if llvm toolchain has this,= it > > > requires both as and lld to recognize the flag. > > >=20 > > > Anyway, try it? See GNU as documentation for the .section directi= ve, > > > ELF type flags. > >=20 > > Thanks! This seems to solve a big part of the issue. > >=20 > > If i pass =E2=80=9Ccargo:rustc-link-arg=3D-Xlinker=E2=80=9D and =E2=80= =9Ccargo:rustc-link-arg=3D=E2=80=94no-gc-sections=E2=80=9D it does preve= nt the linker from removing the probes. > >=20 > > I am still looking for solutions that does not involve explicit invo= lvement of the flags by the crate consumer, and maybe something not turn= ing gc off entirely but this is a great progress. >=20 > Did you tried the "R" section flag, as I noted above? Yes sir, I am using the =E2=80=9CR=E2=80=9D flag and it works amazingly = well. Sorry I misread your email the first time. --852b2e739d824269a0a618ba8ae1a5db Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable

= On Tue, Jun 7, 2022, at 3:40 AM, Konstantin Belousov wrote:
On Mon, Jun 06, 2022 at= 03:44:32AM +0800, Michael Yan Ka Chiu wrote:
> On Mon,= Jun 6, 2022, at 3:01 AM, Konstantin Belousov wrote:
> = > On Sun, Jun 05, 2022 at 04:26:37PM +0800, Michael Yan Ka Chiu wrote= :
> > > Hi everyone,
> > >=  
> > > I=E2=80=99m working on a PR to get t= he Rust Usdt crate working on FreeBSD. This crate
> >= ; > basically allow adding DTrace probes to rust sources by compiling= the probe during
> > > macro invocation and embe= d to a custom section (set_dtrace_probe) using inline 
> > > assembly.
> > > 
<= div>> > > The problem I am encountering is that the linker will= optimize the compiled probes
> > > out in the cu= stom section, the only workaround I have found is to force the linker to=
> > > link all the dead code by invoking `-C lin= k-dead-code=3Dyes`. On Illumos, the workaround
> > &= gt; is to reference another section such that the Illumos linker will no= t throw the probes 
> > > away; however the = same workaround does not work on FreeBSD.
> > >&n= bsp;
> > > I wonder if there're any tricks simila= r to the Illumos fix, by putting some inline asm there
>= ; > > to trick the linker and not throw out the probes.
<= div>> > > 
> > > Thanks In advance,=
> > > Michael
> > > =
> > > References:
> = > > 
> > >  
&= gt; > 
> > GNU as seems to gain support for = the "R" flag for sections, which should
> > prevent = them from linker GC.  Not sure if llvm toolchain has this, it
> > requires both as and lld to recognize the flag.
> > 
> > Anyway, try it?  S= ee GNU as documentation for the .section directive,
> &= gt; ELF type flags.

> Thanks! = This seems to solve a big part of the issue.
> If i pass =E2=80=9Ccargo:rustc-link-arg=3D-Xlinker=E2=80= =9D and =E2=80=9Ccargo:rustc-link-arg=3D=E2=80=94no-gc-sections=E2=80=9D= it does prevent the linker from removing the probes.
>=  
> I am still looking for solutions that does not= involve explicit involvement of the flags by the crate consumer, and ma= ybe something not turning gc off entirely but this is a great progress.<= br>

Did you tried the "R" section flag, as I no= ted above?

Yes sir, I am using= the =E2=80=9CR=E2=80=9D flag and it works amazingly well. Sorry I misre= ad your email the first time.
--852b2e739d824269a0a618ba8ae1a5db--