[compiler-rt] [TySan] add internal interface support (PR #192413)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 02:10:52 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Matthew Nagy (gbMattN)

<details>
<summary>Changes</summary>

Partial reland of https://github.com/llvm/llvm-project/pull/183310
Trying to avoid the parts that blow up mac ci until I can fix that issue.

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


1 Files Affected:

- (modified) compiler-rt/lib/tysan/tysan.cpp (+28-1) 


``````````diff
diff --git a/compiler-rt/lib/tysan/tysan.cpp b/compiler-rt/lib/tysan/tysan.cpp
index 7c1cf193d3cb6..55410930d9966 100644
--- a/compiler-rt/lib/tysan/tysan.cpp
+++ b/compiler-rt/lib/tysan/tysan.cpp
@@ -15,6 +15,7 @@
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_flag_parser.h"
 #include "sanitizer_common/sanitizer_flags.h"
+#include "sanitizer_common/sanitizer_interface_internal.h"
 #include "sanitizer_common/sanitizer_libc.h"
 #include "sanitizer_common/sanitizer_report_decorator.h"
 #include "sanitizer_common/sanitizer_stacktrace.h"
@@ -40,6 +41,30 @@ tysan_copy_types(const void *daddr, const void *saddr, uptr size) {
     internal_memmove(shadow_for(daddr), shadow_for(saddr), size * sizeof(uptr));
 }
 
+static void getStackTrace(bool fullStacktrace, uptr pc, uptr bp,
+                          BufferedStackTrace *ST) {
+  uptr top = 0;
+  uptr bottom = 0;
+  if (fullStacktrace)
+    GetThreadStackTopAndBottom(false, &top, &bottom);
+  bool request_fast = StackTrace::WillUseFastUnwind(true);
+  ST->Unwind(kStackTraceMax, pc, bp, 0, top, bottom, request_fast);
+}
+
+namespace __tysan {
+void OnStackUnwind(const SignalContext &sig, const void *,
+                   BufferedStackTrace *stack) {
+  getStackTrace(true, StackTrace::GetNextInstructionPc(sig.pc), sig.bp, stack);
+}
+} // namespace __tysan
+
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_print_stack_trace() {
+  GET_CURRENT_PC_BP;
+  UNINITIALIZED BufferedStackTrace stack;
+  getStackTrace(true, pc, bp, &stack);
+  stack.Print();
+}
+
 static const char *getDisplayName(const char *Name) {
   if (Name[0] == '\0')
     return "<anonymous type>";
@@ -248,7 +273,7 @@ static void reportError(void *Addr, int Size, tysan_type_descriptor *TD,
 
     bool request_fast = StackTrace::WillUseFastUnwind(true);
     BufferedStackTrace ST;
-    ST.Unwind(kStackTraceMax, pc, bp, 0, top, bottom, request_fast);
+    getStackTrace(flags().print_stacktrace, pc, bp, &ST);
     ST.Print();
   } else {
     Printf("\n");
@@ -464,6 +489,8 @@ static void InitializeFlags() {
     ReportUnrecognizedFlags();
   if (common_flags()->help)
     parser.PrintFlagDescriptions();
+
+  __sanitizer_set_report_path(common_flags()->log_path);
 }
 
 static void TySanInitializePlatformEarly() {

``````````

</details>


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


More information about the llvm-commits mailing list