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

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 00:38:38 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())
----------------
vitalybuka wrote:

Actually I don't believe we care about partially initialized asan for `__asan_handle_no_return`.
I think `__asan_handle_no_return` should bailout aggressively.

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


More information about the llvm-commits mailing list