This is an archive of the discontinued LLVM Phabricator instance.

[XRay][compiler-rt] Allow for building the XRay runtime without PREINIT initialization.
ClosedPublic

Authored by dberris on Jul 31 2017, 3:32 AM.

Details

Summary

Define a build-time configuration option for the XRay runtime to
determine whether the archive will add an entry to the .preinit_array
section of the binary. We also allow for initializing the XRay data
structures with an explicit call to __xray_init(). This allows us to
give users the capability to initialize the XRay data structures on
demand.

This can allow us to start porting XRay to platforms where
.preinit_array isn't a supported section. It also allows us to limit
the effects of XRay in the initialization sequence for applications that
are sensitive to this kind of interference (i.e. large binaries) or
those that want to package XRay control in libraries.

Future changes should allow us to build two different library archives
for the XRay runtime, and allow clang users to determine which version
to link.

Diff Detail

Repository
rL LLVM

Event Timeline

dberris created this revision.Jul 31 2017, 3:32 AM
kpw added inline comments.Aug 1 2017, 12:30 PM
include/xray/xray_interface.h
109–113 ↗(On Diff #108894)

Are callers expected to synchronize before calling __xray_init()? Is it even legal to call this function more than once? This should be documented in the header.

lib/xray/xray_init.cc
50–52 ↗(On Diff #108894)

Is it safe for initializeFlags() to be called twice? Called by different callers at the same time? Depending on what you expect of callers invoking __xray_init, these things can happen.

I suggest that we add an atomic_uint8_t XRayFlagsInitialized above and check that within a XrayFlagInitMutex, then it will be safe for callers to make multiple unsynchronized invocations of __xray_init().

I will also suggest early return if this atomic_load is true. As written, this just wraps the initializeFlags() call. XRayInstrMap is still reloaded even if XRayInitialized is true.

dberris updated this revision to Diff 109273.Aug 1 2017, 10:39 PM
dberris marked 2 inline comments as done.
  • fixup: synchronize better
include/xray/xray_interface.h
109–113 ↗(On Diff #108894)

Good point. Updated doc and implementation to allow for multiple calls (and documenting the semantics of that).

lib/xray/xray_init.cc
50–52 ↗(On Diff #108894)

Good point! Done, PTAL.

kpw accepted this revision.Aug 2 2017, 10:19 AM
This revision is now accepted and ready to land.Aug 2 2017, 10:19 AM
This revision was automatically updated to reflect the committed changes.