[compiler-rt] [rtsan] Make sure rtsan gets initialized on mac (PR #100188)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 15:40:08 PDT 2024


================
@@ -12,23 +12,43 @@
 #include <rtsan/rtsan_context.h>
 #include <rtsan/rtsan_interceptors.h>
 
+#include "sanitizer_common/sanitizer_atomic.h"
+
 using namespace __rtsan;
+using namespace __sanitizer;
+
+static atomic_uint8_t rtsan_initialized{0};
+static atomic_uint8_t rtsan_init_is_running{0};
+
+static void SetInitIsRunning(bool is_running) {
+  atomic_store(&rtsan_init_is_running, is_running, memory_order_release);
+}
+
+static bool IsInitRunning() {
+  return atomic_load(&rtsan_init_is_running, memory_order_acquire) == 1;
+}
 
-bool __rtsan::rtsan_initialized;
-bool __rtsan::rtsan_init_is_running;
+static void SetInitialized() {
+  atomic_store(&rtsan_initialized, 1, memory_order_release);
+}
 
 extern "C" {
 
 SANITIZER_INTERFACE_ATTRIBUTE void __rtsan_init() {
-  CHECK(!rtsan_init_is_running);
-  if (rtsan_initialized)
+  CHECK(!IsInitRunning());
+  if (__rtsan_is_initialized())
----------------
vitalybuka wrote:

why don't you call a static one here?

https://github.com/llvm/llvm-project/pull/100188


More information about the llvm-commits mailing list