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

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 14:21:36 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Alexander Shaposhnikov (alexander-shaposhnikov)

<details>
<summary>Changes</summary>

Implement __sanitizer::BufferedStackTrace::UnwindImpl following msan.

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


1 Files Affected:

- (modified) compiler-rt/lib/nsan/nsan.cpp (+13-6) 


``````````diff
diff --git a/compiler-rt/lib/nsan/nsan.cpp b/compiler-rt/lib/nsan/nsan.cpp
index 4be9c673bd4e00..c2e7690e12ab10 100644
--- a/compiler-rt/lib/nsan/nsan.cpp
+++ b/compiler-rt/lib/nsan/nsan.cpp
@@ -195,12 +195,19 @@ template <typename T> T max(T a, T b) { return a < b ? b : a; }
 
 } // end anonymous namespace
 
-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);
+void __sanitizer::BufferedStackTrace::UnwindImpl(
+    uptr pc, uptr bp, void *context, bool request_fast, u32 max_depth) {
+  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() {

``````````

</details>


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


More information about the llvm-commits mailing list