[llvm] Fix tsan race in PerfJITEventListener.cpp (PR #106800)

Eugene Zhulenev via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 30 14:27:35 PDT 2024


https://github.com/ezhulenev updated https://github.com/llvm/llvm-project/pull/106800

>From 4904b7396988bd7fd9319e26eaa5cdfa7ce98f60 Mon Sep 17 00:00:00 2001
From: Eugene Zhulenev <ezhulenev at google.com>
Date: Fri, 30 Aug 2024 14:17:27 -0700
Subject: [PATCH 1/2] Fix tsan race in PerfJITEventListener.cpp

---
 .../ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp    | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp b/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp
index e2b5ce49ba2ec1..b7b07cc41129e5 100644
--- a/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp
+++ b/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp
@@ -60,6 +60,10 @@ class PerfJITEventListener : public JITEventListener {
 public:
   PerfJITEventListener();
   ~PerfJITEventListener() {
+    // Lock a mutex to correctly synchronize with prior calls to
+    // `notifyObjectLoaded` and `notifyFreeingObject` that happened on other
+    // threads to prevent tsan from complaining.
+    std::lock_guard<sys::Mutex> Guard(Mutex);	  
     if (MarkerAddr)
       CloseMarker();
   }

>From cde2173c5066b233a3098a77232ffbf92c58d7c8 Mon Sep 17 00:00:00 2001
From: Eugene Zhulenev <ezhulenev at google.com>
Date: Fri, 30 Aug 2024 14:27:27 -0700
Subject: [PATCH 2/2] Update PerfJITEventListener.cpp

---
 llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp b/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp
index b7b07cc41129e5..cf9ed7dbff1536 100644
--- a/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp
+++ b/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp
@@ -63,7 +63,7 @@ class PerfJITEventListener : public JITEventListener {
     // Lock a mutex to correctly synchronize with prior calls to
     // `notifyObjectLoaded` and `notifyFreeingObject` that happened on other
     // threads to prevent tsan from complaining.
-    std::lock_guard<sys::Mutex> Guard(Mutex);	  
+    std::lock_guard<sys::Mutex> Guard(Mutex);
     if (MarkerAddr)
       CloseMarker();
   }



More information about the llvm-commits mailing list