Help needed to get Rust dtrace USDT working on/with FreeBSD linker

From: Michael Yan Ka Chiu <nyan_at_myuji.xyz>
Date: Sun, 05 Jun 2022 08:26:37 UTC
Hi everyone,

I’m working on a PR to get the Rust Usdt crate working on FreeBSD. This crate
basically allow adding DTrace probes to rust sources by compiling the probe during
macro invocation and embed to a custom section (set_dtrace_probe) using inline 
assembly.

The problem I am encountering is that the linker will optimize the compiled 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=yes`. On Illumos, the workaround
is to reference another section such that the Illumos linker will not throw the probes 
away; however the same workaround does not work on FreeBSD.

I wonder if there're any tricks similar to the Illumos fix, by putting some 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/eac0fe5f03c3fbf23468ead5cb140f62d51ac3f3/usdt-impl/src/record.rs#L251