[compiler-rt] [asan] Switch initialization to "double-checked locking" (PR #74387)

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 4 23:15:06 PST 2023


================
@@ -515,22 +511,27 @@ static void AsanInitInternal() {
   VReport(1, "AddressSanitizer Init done\n");
 
   WaitForDebugger(flags()->sleep_after_init, "after init");
+
+  return true;
 }
 
 // Initialize as requested from some part of ASan runtime library (interceptors,
 // allocator, etc).
 void AsanInitFromRtl() {
-  CHECK(!AsanInitIsRunning());
-  if (UNLIKELY(!AsanInited()))
-    AsanInitInternal();
+  if (LIKELY(AsanInited()))
+    return;
+  SpinMutexLock lock(&asan_inited_mutex);
+  AsanInitInternal();
 }
 
 bool TryAsanInitFromRtl() {
-  if (UNLIKELY(AsanInitIsRunning()))
+  if (LIKELY(AsanInited()))
+    return true;
+  if (!asan_inited_mutex.TryLock())
----------------
dvyukov wrote:

This also seems to introduce a change in the behavior. Currently __asan_handle_no_return returns early only while AsanInitIsRunning, but the mutex lock duration covers whole AsanInitInternal.
Is this intentional?

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


More information about the llvm-commits mailing list