[compiler-rt] r319366 - [XRay][compiler-rt][Darwin] Use dynamic initialisation as an alternative

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 14:06:12 PST 2017


Author: dberris
Date: Wed Nov 29 14:06:12 2017
New Revision: 319366

URL: http://llvm.org/viewvc/llvm-project?rev=319366&view=rev
Log:
[XRay][compiler-rt][Darwin] Use dynamic initialisation as an alternative

Summary:
In cases where we can't use the .preinit_array section (as in Darwin for
example) we instead use dynamic initialisation. We know that this
alternative approach will race with the initializers of other objects at
global scope, but this is strictly better than nothing.

Reviewers: kubamracek, nglevin

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D40599

Modified:
    compiler-rt/trunk/lib/xray/xray_init.cc

Modified: compiler-rt/trunk/lib/xray/xray_init.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_init.cc?rev=319366&r1=319365&r2=319366&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/xray_init.cc (original)
+++ compiler-rt/trunk/lib/xray/xray_init.cc Wed Nov 29 14:06:12 2017
@@ -88,8 +88,15 @@ void __xray_init() XRAY_NEVER_INSTRUMENT
 #endif
 }
 
-// Only add the preinit array initialization if the sanitizers can.
 #if !defined(XRAY_NO_PREINIT) && SANITIZER_CAN_USE_PREINIT_ARRAY
+// Only add the preinit array initialization if the sanitizers can.
 __attribute__((section(".preinit_array"),
                used)) void (*__local_xray_preinit)(void) = __xray_init;
+#else
+// If we cannot use the .preinit_array section, we should instead use dynamic
+// initialisation.
+static bool UNUSED __local_xray_dyninit = [] {
+  __xray_init();
+  return true;
+}();
 #endif




More information about the llvm-commits mailing list