[clang] [compiler-rt] [rtsan] Enable RealtimeSanitizer for FreeBSD (PR #125389)

Chris Apple via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 5 18:55:04 PST 2025


================
@@ -43,6 +44,21 @@ static __rtsan::Context &GetContextForThisThreadImpl() {
 
   return *current_thread_context;
 }
+#else
+
+// On FreeBSD, pthread api cannot be used as calloc is called under the hood
+// at library initialization time.
+static __thread Context *ctx = nullptr;
+
+static __rtsan::Context &GetContextForThisThreadImpl() {
+  if (ctx == nullptr) {
+    ctx = static_cast<Context *>(MmapOrDie(sizeof(Context), "RtsanContext"));
+    new (ctx) Context();
----------------
cjappl wrote:

My suspicion is that one of the interceptors is getting called by pthread, which tries to set up the context, which calls pthread, which calls the interceptor, which tries to set up the context............

I recommend figuring out which of those interceptors this is and checking if we can do an early out like this dlsym init early out:

https://github.com/llvm/llvm-project/blob/e223485c9b38a5579991b8cebb6a200153eee245/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp#L776-L782

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


More information about the cfe-commits mailing list