Page MenuHomeFreeBSD

use ld(1) to do DOF probe relocation
ClosedPublic

Authored by markj on Sep 10 2014, 1:20 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 15, 3:31 AM
Unknown Object (File)
Mon, Apr 13, 1:37 AM
Unknown Object (File)
Sun, Apr 5, 1:32 AM
Unknown Object (File)
Nov 14 2025, 9:38 AM
Unknown Object (File)
Nov 7 2025, 8:14 AM
Unknown Object (File)
Nov 7 2025, 8:14 AM
Unknown Object (File)
Nov 7 2025, 3:15 AM
Unknown Object (File)
Sep 20 2025, 11:16 AM
Subscribers

Details

Reviewers
rpaulo
Group Reviewers
DTrace
Summary

There's a comment in drti.c that indicates that ld(1) needs to be able to parse SUNW_dof in order to do probe address relocations. As far as I can determine, this isn't the case: our ld(1) handles relocations in .SUNW_dof just fine. Indeed, if we add a .rela.SUNW_dof section containing relocations for each probe, everything just works (modulo some bug fixes/tweaks). Any relocations that can't be done at link time are handled by rtld.

At the moment, we use drti.o to do these relocations at runtime. There are many problems with this:

  • it has a performance impact,
  • it doesn't work with stripped executables (since it relies on symtab lookups), and to some extent with stripped shared libraries,
  • it doesn't work with probes associated with local symbols (dtrace emits mangled global symbols to handle this, but the drti code doesn't know about them)
  • other problems that I ran into but never figured out.

This change removes the relocation code from drti.o and fixes a number of bugs. With this change, I'm able to instrument the tcl DTrace probes without running into the "WARNING: number of probes fixed does not match the number of defined probes" message on startup.

Test Plan

tcl DTrace works (tested 8.4, 8.5, 8.6). You need this patch to enable DTrace for the corresponding ports: http://people.freebsd.org/~markj/patches/tcl_dtrace_provider.diff

Made sure that USDT probes in PHP and Postgres still work properly, and tested a number of toy examples (probes in shared libraries and dynamically-linked executables). Probes in static libraries currently don't work - looks like ld(1) outright removes the SUNW_dof section when linking.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

markj retitled this revision from to use ld(1) to do DOF probe relocation.
markj updated this object.
markj edited the test plan for this revision. (Show Details)
markj added a reviewer: DTrace.
cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c
717

The SUNW_dof section needs to be writable; otherwise ld(1) refuses to process relocations in .rela.SUNW_dof.

1822

Some differences to account for the fact that we write to a separate tmpfile instead of using fdescfs.

1848

This line was just plain wrong.

rpaulo added a reviewer: rpaulo.
rpaulo added a subscriber: rpaulo.

Thanks for proving that I'm an idiot. :-)

Please MFC this. One thing that never worked for me was 32-bit USDT binaries on amd64. The ld(1) invocation in dt_link.c complains about the input format.

This revision is now accepted and ready to land.Sep 10 2014, 1:27 AM