[compiler-rt] [compiler-rt][nsan] Update UnwindImpl (PR #107313)

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 14:28:02 PDT 2024


https://github.com/alexander-shaposhnikov updated https://github.com/llvm/llvm-project/pull/107313

>From eecdb010946b2943960882c337a4ff70ade6a175 Mon Sep 17 00:00:00 2001
From: Alexander Shaposhnikov <ashaposhnikov at google.com>
Date: Wed, 4 Sep 2024 21:13:47 +0000
Subject: [PATCH] [compiler-rt][nsan] Update
 __sanitizer::BufferedStackTrace::UnwindImpl following msan's example

---
 compiler-rt/lib/nsan/nsan.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/nsan/nsan.cpp b/compiler-rt/lib/nsan/nsan.cpp
index 4be9c673bd4e00..0cc1b69c71f7bc 100644
--- a/compiler-rt/lib/nsan/nsan.cpp
+++ b/compiler-rt/lib/nsan/nsan.cpp
@@ -199,8 +199,17 @@ void __sanitizer::BufferedStackTrace::UnwindImpl(uptr pc, uptr bp,
                                                  void *context,
                                                  bool request_fast,
                                                  u32 max_depth) {
-  using namespace __nsan;
-  return Unwind(max_depth, pc, bp, context, 0, 0, false);
+  using namespace __msan;
+  NsanThread *t = GetCurrentThread();
+  if (!t || !StackTrace::WillUseFastUnwind(request_fast)) {
+    // Block reports from our interceptors during _Unwind_Backtrace.
+    return Unwind(max_depth, pc, bp, context, t ? t->stack_top() : 0,
+                  t ? t->stack_bottom() : 0, false);
+  }
+  if (StackTrace::WillUseFastUnwind(request_fast))
+    Unwind(max_depth, pc, bp, nullptr, t->stack_top(), t->stack_bottom(), true);
+  else
+    Unwind(max_depth, pc, 0, context, 0, 0, false);
 }
 
 extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_print_accumulated_stats() {



More information about the llvm-commits mailing list