[compiler-rt] 082efba - [asan] Make GetFakeStackFast()/GetFakeStackFastAlways() lazily init fake_stack_tls (#163481)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 15 18:31:21 PDT 2025


Author: Vitaly Buka
Date: 2025-10-16T01:31:17Z
New Revision: 082efbaac1b706bcdae624243465268ca23d1655

URL: https://github.com/llvm/llvm-project/commit/082efbaac1b706bcdae624243465268ca23d1655
DIFF: https://github.com/llvm/llvm-project/commit/082efbaac1b706bcdae624243465268ca23d1655.diff

LOG: [asan] Make GetFakeStackFast()/GetFakeStackFastAlways() lazily init fake_stack_tls (#163481)

To simplify implementation of #160135

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_fake_stack.cpp
    compiler-rt/lib/asan/asan_fake_stack.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_fake_stack.cpp b/compiler-rt/lib/asan/asan_fake_stack.cpp
index 5034ea2a0e459..d243b5739a309 100644
--- a/compiler-rt/lib/asan/asan_fake_stack.cpp
+++ b/compiler-rt/lib/asan/asan_fake_stack.cpp
@@ -231,17 +231,25 @@ static FakeStack* GetFakeStack() {
 }
 
 static FakeStack* GetFakeStackFast() {
-  if (FakeStack* fs = GetTLSFakeStack())
+  FakeStack* fs = GetTLSFakeStack();
+  if (LIKELY(fs))
     return fs;
   if (!__asan_option_detect_stack_use_after_return)
     return nullptr;
-  return GetFakeStack();
+  fs = GetFakeStack();
+  if (LIKELY(fs))
+    SetTLSFakeStack(fs);
+  return fs;
 }
 
 static FakeStack* GetFakeStackFastAlways() {
-  if (FakeStack* fs = GetTLSFakeStack())
+  FakeStack* fs = GetTLSFakeStack();
+  if (LIKELY(fs))
     return fs;
-  return GetFakeStack();
+  fs = GetFakeStack();
+  if (LIKELY(fs))
+    SetTLSFakeStack(fs);
+  return fs;
 }
 
 static ALWAYS_INLINE uptr OnMalloc(uptr class_id, uptr size) {

diff  --git a/compiler-rt/lib/asan/asan_fake_stack.h b/compiler-rt/lib/asan/asan_fake_stack.h
index ec772c3299f00..7dedb29809d22 100644
--- a/compiler-rt/lib/asan/asan_fake_stack.h
+++ b/compiler-rt/lib/asan/asan_fake_stack.h
@@ -195,7 +195,7 @@ class FakeStack {
   void *true_start;
 };
 
-void SetTLSFakeStack(FakeStack *fs);
+void SetTLSFakeStack(FakeStack* fs);
 
 }  // namespace __asan
 


        


More information about the llvm-commits mailing list