[compiler-rt] [TySan] add internal interface support (PR #192413)
Matthew Nagy via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 02:10:15 PDT 2026
https://github.com/gbMattN created https://github.com/llvm/llvm-project/pull/192413
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.
>From 10cff4f4cd13787113b4f9699919c36ed8143e1a Mon Sep 17 00:00:00 2001
From: gbMattN <matthew.nagy at sony.com>
Date: Thu, 16 Apr 2026 10:08:12 +0100
Subject: [PATCH] [TySan] add internal interface support
---
compiler-rt/lib/tysan/tysan.cpp | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
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() {
More information about the llvm-commits
mailing list