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

Chris Apple via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 13:04:46 PDT 2024


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

Intermittently on my mac I was getting the same nullptr crash in dlsym.

We need to make sure rtsan gets initialized on mac between when the binary starts running, and the first intercepted function is called. Until that point we should use the DlsymAllocator.

>From 06321b5d8d19ff1b13ec6dbe51f411919e2d97c5 Mon Sep 17 00:00:00 2001
From: Chris Apple <cja-private at pm.me>
Date: Tue, 23 Jul 2024 13:00:02 -0700
Subject: [PATCH] Make sure rtsan gets initialized on mac

---
 compiler-rt/lib/rtsan/rtsan_interceptors.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors.cpp
index 4d5423ec629d2..833062c3de41e 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors.cpp
@@ -39,7 +39,6 @@
 
 using namespace __sanitizer;
 
-using __rtsan::rtsan_init_is_running;
 using __rtsan::rtsan_initialized;
 
 namespace {
@@ -49,6 +48,9 @@ struct DlsymAlloc : public DlSymAllocator<DlsymAlloc> {
 } // namespace
 
 void ExpectNotRealtime(const char *intercepted_function_name) {
+  if (!rtsan_initialized)
+    __rtsan_init();
+
   __rtsan::GetContextForThisThread().ExpectNotRealtime(
       intercepted_function_name);
 }



More information about the llvm-commits mailing list