[PATCH] D40599: [XRay][compiler-rt][Darwin] Use dynamic initialisation as an alternative

Dean Michael Berris via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 04:24:12 PST 2017


dberris created this revision.

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.


https://reviews.llvm.org/D40599

Files:
  compiler-rt/lib/xray/xray_init.cc


Index: compiler-rt/lib/xray/xray_init.cc
===================================================================
--- compiler-rt/lib/xray/xray_init.cc
+++ compiler-rt/lib/xray/xray_init.cc
@@ -88,8 +88,15 @@
 #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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40599.124719.patch
Type: text/x-patch
Size: 739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171129/8ae58ca9/attachment.bin>


More information about the llvm-commits mailing list