[clang] [compiler-rt] Rtsan fbsd (PR #125389)

Chris Apple via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 5 12:54:12 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:

This does not do the same thing as the other version. This construct needs to be thread local, otherwise a multi threaded binary will not be able to track its state properly.

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


More information about the cfe-commits mailing list