[compiler-rt] [TySan] add internal interface support (PR #192413)
Matthew Nagy via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 02:24:25 PDT 2026
https://github.com/gbMattN updated https://github.com/llvm/llvm-project/pull/192413
>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 1/2] [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() {
>From c697da2cea959731380480adf3cc50581aa704de Mon Sep 17 00:00:00 2001
From: gbMattN <matthew.nagy at sony.com>
Date: Thu, 16 Apr 2026 10:24:13 +0100
Subject: [PATCH 2/2] remove unused code
---
compiler-rt/lib/tysan/tysan.cpp | 6 ------
1 file changed, 6 deletions(-)
diff --git a/compiler-rt/lib/tysan/tysan.cpp b/compiler-rt/lib/tysan/tysan.cpp
index 55410930d9966..c0171bbb2c375 100644
--- a/compiler-rt/lib/tysan/tysan.cpp
+++ b/compiler-rt/lib/tysan/tysan.cpp
@@ -266,12 +266,6 @@ static void reportError(void *Addr, int Size, tysan_type_descriptor *TD,
Printf("\n");
if (pc) {
- uptr top = 0;
- uptr bottom = 0;
- if (flags().print_stacktrace)
- GetThreadStackTopAndBottom(false, &top, &bottom);
-
- bool request_fast = StackTrace::WillUseFastUnwind(true);
BufferedStackTrace ST;
getStackTrace(flags().print_stacktrace, pc, bp, &ST);
ST.Print();
More information about the llvm-commits
mailing list