This is an archive of the discontinued LLVM Phabricator instance.

[XRay] [compiler-rt] [DSO] introduce a context for patching/unpatching
Needs RevisionPublic

Authored by pelikan on Oct 17 2017, 1:08 AM.

Details

Reviewers
dberris
Summary

For the upcoming DSO support, we want to reuse code between the "static"
version of XRay, already within the main binary and possibly initialized
at startup, and the "dynamic" part bundled with .so libraries which will
need to communicate with it. Wherever patching/unpatching happens needs
to be clearly defined for the patching code to recognize which memory is
it actually operating on.

This diff introduces an "always visible" pointer (*DSOContext), which is
local for each DSO, only visible within its own "copy" of XRay. Whoever
initializes that context (xray_init.cc in the main binary or xray_dso.cc
in a DSO during dlopen(3)) will populate that pointer. The advantage of
having a pointer instead of scattered functions and variables is:

  • we have something to identify a DSO (it will have a numeric ID soon)
  • it is easier to add per-DSO behaviour later, and control it globally
  • it is clearer for the reader which C++ code is intended to be shared

When this is in, it is easy to take xray_interface{.cc,_internal.h} and
build a DSO version of the XRay runtime with it.

Event Timeline

pelikan created this revision.Oct 17 2017, 1:08 AM
dberris requested changes to this revision.Nov 1 2017, 10:48 PM
dberris added subscribers: kcc, eugenis.

@pelikan and I are discussing this offline, pulling in @eugenis and @kcc -- we're prepping to get an RFC onto the mailing list(s) on how we might proceed with our options before continuing on this.

This revision now requires changes to proceed.Nov 1 2017, 10:48 PM