Skip to content

Conversation

@vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented Oct 16, 2025

To simplify implementation of #160135

To keep the logic of figuring out what should be in TLS to one place.
The rest of the code should just reset it and rely on GetFakeStackFast()/GetFakeStackFastAlways().

@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

Changes

This reverts commit 6d7fedd1e4b0f305fd2bf179140e7a82f9bf72d0.


Full diff: https://github.com/llvm/llvm-project/pull/163674.diff

4 Files Affected:

  • (modified) compiler-rt/lib/asan/asan_fake_stack.cpp (+4-2)
  • (modified) compiler-rt/lib/asan/asan_fake_stack.h (+1-1)
  • (modified) compiler-rt/lib/asan/asan_thread.cpp (+3-3)
  • (modified) compiler-rt/lib/asan/asan_thread.h (+1-1)
diff --git a/compiler-rt/lib/asan/asan_fake_stack.cpp b/compiler-rt/lib/asan/asan_fake_stack.cpp
index d243b5739a309..d3fa953f31005 100644
--- a/compiler-rt/lib/asan/asan_fake_stack.cpp
+++ b/compiler-rt/lib/asan/asan_fake_stack.cpp
@@ -217,10 +217,12 @@ void FakeStack::ForEachFakeFrame(RangeIteratorCallback callback, void* arg) {
 static THREADLOCAL FakeStack* fake_stack_tls;
 
 static FakeStack* GetTLSFakeStack() { return fake_stack_tls; }
-void SetTLSFakeStack(FakeStack* fs) { fake_stack_tls = fs; }
+static void SetTLSFakeStack(FakeStack* fs) { fake_stack_tls = fs; }
+void ResetTLSFakeStack() { fake_stack_tls = nullptr; }
 #else
 static FakeStack* GetTLSFakeStack() { return nullptr; }
-void SetTLSFakeStack(FakeStack* fs) {}
+static void SetTLSFakeStack(FakeStack*) {}
+void ResetTLSFakeStack() {}
 #endif  // (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA
 
 static FakeStack* GetFakeStack() {
diff --git a/compiler-rt/lib/asan/asan_fake_stack.h b/compiler-rt/lib/asan/asan_fake_stack.h
index 7dedb29809d22..593c1373c8ff1 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 ResetTLSFakeStack();
 
 }  // namespace __asan
 
diff --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp
index 2627ae1289012..0ed58bbe2a73a 100644
--- a/compiler-rt/lib/asan/asan_thread.cpp
+++ b/compiler-rt/lib/asan/asan_thread.cpp
@@ -163,7 +163,7 @@ void AsanThread::StartSwitchFiber(FakeStack **fake_stack_save, uptr bottom,
   if (fake_stack_save)
     *fake_stack_save = fake_stack_;
   fake_stack_ = nullptr;
-  SetTLSFakeStack(nullptr);
+  ResetTLSFakeStack();
   // if fake_stack_save is null, the fiber will die, delete the fakestack
   if (!fake_stack_save && current_fake_stack)
     current_fake_stack->Destroy(this->tid());
@@ -177,8 +177,8 @@ void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save, uptr *bottom_old,
   }
 
   if (fake_stack_save) {
-    SetTLSFakeStack(fake_stack_save);
     fake_stack_ = fake_stack_save;
+    ResetTLSFakeStack();
   }
 
   if (bottom_old)
@@ -242,7 +242,7 @@ FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
         Max(stack_size_log, static_cast<uptr>(flags()->min_uar_stack_size_log));
     fake_stack_ = FakeStack::Create(stack_size_log);
     DCHECK_EQ(GetCurrentThread(), this);
-    SetTLSFakeStack(fake_stack_);
+    ResetTLSFakeStack();
     return fake_stack_;
   }
   return nullptr;
diff --git a/compiler-rt/lib/asan/asan_thread.h b/compiler-rt/lib/asan/asan_thread.h
index 12f0cc7a62dae..19b7f342e1712 100644
--- a/compiler-rt/lib/asan/asan_thread.h
+++ b/compiler-rt/lib/asan/asan_thread.h
@@ -104,7 +104,7 @@ class AsanThread {
     if (!fake_stack_) return;
     FakeStack *t = fake_stack_;
     fake_stack_ = nullptr;
-    SetTLSFakeStack(nullptr);
+    ResetTLSFakeStack();
     t->Destroy(tid);
   }
 

@vitalybuka vitalybuka changed the title Revert "undoreset" [asan] Hide SetTLSFakeStack as static function of cpp Oct 16, 2025
Copy link
Contributor

@fmayer fmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"of cpp" is not necessary in commit message

@vitalybuka vitalybuka changed the title [asan] Hide SetTLSFakeStack as static function of cpp [asan] Hide SetTLSFakeStack and replaces uses with ResetTLSFakeStack Oct 16, 2025
@vitalybuka vitalybuka changed the base branch from users/vitalybuka/spr/main.revert-undoreset to main October 16, 2025 01:34
Created using spr 1.3.6
@vitalybuka vitalybuka merged commit f7f6f6d into main Oct 16, 2025
8 of 9 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/revert-undoreset branch October 16, 2025 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants