Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 05 Jun 2022 16:26:37 +0800
From:      "Michael Yan Ka Chiu" <nyan@myuji.xyz>
To:        freebsd-hackers@FreeBSD.org
Subject:   Help needed to get Rust dtrace USDT working on/with FreeBSD linker
Message-ID:  <f5c27ce0-0dc7-467f-b293-857c74125648@www.fastmail.com>

next in thread | raw e-mail | index | archive | help
--85fc6e84595f46b0831dedca9d529307
Content-Type: text/plain;charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi everyone,

I=E2=80=99m working on a PR to get the Rust Usdt crate working on FreeBS=
D. This crate
basically allow adding DTrace probes to rust sources by compiling the pr=
obe during
macro invocation and embed to a custom section (set_dtrace_probe) using =
inline=20
assembly.

The problem I am encountering is that the linker will optimize the compi=
led probes
out in the custom section, the only workaround I have found is to 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 will not th=
row the probes=20
away; however the same workaround does not work on FreeBSD.

I wonder if there're any tricks similar to the Illumos fix, by putting s=
ome inline asm there
to trick the linker and not throw out the probes.

Thanks In advance,
Michael

References:
The PR: https://github.com/oxidecomputer/usdt/pull/63
The illumos fix: https://github.com/oxidecomputer/usdt/blob/eac0fe5f03c3=
fbf23468ead5cb140f62d51ac3f3/usdt-impl/src/record.rs#L251

=20

--85fc6e84595f46b0831dedca9d529307
Content-Type: text/html;charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html><html><head><title></title><style type=3D"text/css">p.Mso=
Normal,p.MsoNoSpacing{margin:0}
p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>Hi everyon=
e,<br></div><div><br></div><div>I=E2=80=99m working on a PR to get the R=
ust Usdt crate working on FreeBSD. This crate<br></div><div>basically al=
low adding DTrace probes to rust sources by compiling the probe during<b=
r></div><div>macro invocation and embed to a custom section (set_dtrace_=
probe) using inline <br></div><div>assembly.<br></div><div><br></div><di=
v>The problem I am encountering is that the linker will optimize the com=
piled probes<br></div><div>out in the custom section, the only workaroun=
d I have found is to force the linker to<br></div><div>link all the dead=
 code by invoking `-C link-dead-code=3Dyes`. On Illumos, the workaround<=
br></div><div>is to reference another section such that the Illumos link=
er will not throw the probes <br></div><div>away; however the same worka=
round does not work on FreeBSD.<br></div><div><br></div><div>I wonder if=
 there're any tricks similar to the Illumos fix, by putting some inline =
asm there<br></div><div>to trick the linker and not throw out the probes=
.<br><br>Thanks In advance,</div><div>Michael</div><div> <br></div><div>=
<div>References:<br></div><div><div>The PR: <a href=3D"https://github.co=
m/oxidecomputer/usdt/pull/63">https://github.com/oxidecomputer/usdt/pull=
/63</a><br></div><div>The illumos fix:&nbsp;<a href=3D"https://github.co=
m/oxidecomputer/usdt/blob/eac0fe5f03c3fbf23468ead5cb140f62d51ac3f3/usdt-=
impl/src/record.rs#L251">https://github.com/oxidecomputer/usdt/blob/eac0=
fe5f03c3fbf23468ead5cb140f62d51ac3f3/usdt-impl/src/record.rs#L251</a><br=
></div><div><br></div></div><div>&nbsp;<br></div></div><div><br></div></=
body></html>
--85fc6e84595f46b0831dedca9d529307--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?f5c27ce0-0dc7-467f-b293-857c74125648>