[compiler-rt] [sanitizer-common][rtsan] Fix log and stack printing for rtsan (PR #215707)

Chris Apple via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 18:54:02 PDT 2026


https://github.com/cjappl created https://github.com/llvm/llvm-project/pull/215707

Fixes:
* sanitizer_common/TestCases/suffix-log-path_test.c
* sanitizer_common/TestCases/print-stack-trace.cpp


These two tests have some overlap, which is why they are fixed in the same commit. Functionally, this means:
* RTSan now exports the common `__sanitizer_print_stack_trace` API, from what I understand from the comment on the master version of this, this is for debuggers to call
* RTSan can now report out to a log file using the common utilities

>From 4ed894b68d1b2b5fae216db2f56b11c47692d8ba Mon Sep 17 00:00:00 2001
From: Chris Apple <cja-private at pm.me>
Date: Fri, 31 Jul 2026 14:48:17 -0700
Subject: [PATCH] [sanitizer-common][rtsan] Fix log and stack printing for
 rtsan

Fixes:
* sanitizer_common/TestCases/suffix-log-path_test.c
* sanitizer_common/TestCases/print-stack-trace.cpp
---
 compiler-rt/lib/rtsan/rtsan.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/compiler-rt/lib/rtsan/rtsan.cpp b/compiler-rt/lib/rtsan/rtsan.cpp
index 73340b34f6d4b..dc9b792bf256f 100644
--- a/compiler-rt/lib/rtsan/rtsan.cpp
+++ b/compiler-rt/lib/rtsan/rtsan.cpp
@@ -18,6 +18,7 @@
 
 #include "sanitizer_common/sanitizer_atomic.h"
 #include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_interface_internal.h"
 #include "sanitizer_common/sanitizer_mutex.h"
 #include "sanitizer_common/sanitizer_stackdepot.h"
 
@@ -82,7 +83,9 @@ SANITIZER_INTERFACE_ATTRIBUTE void __rtsan_init() {
   SetInitializationState(InitializationState::Initializing);
 
   SanitizerToolName = "RealtimeSanitizer";
+  CacheBinaryName();
   InitializeFlags();
+  __sanitizer_set_report_path(common_flags()->log_path);
 
   InitializePlatformEarly();
 
@@ -151,4 +154,12 @@ __rtsan_notify_blocking_call(const char *func_name) {
                     OnViolation);
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE
+void __sanitizer_print_stack_trace() {
+  GET_CURRENT_PC_BP;
+  UNINITIALIZED BufferedStackTrace stack;
+  stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal);
+  stack.Print();
+}
+
 } // extern "C"



More information about the llvm-commits mailing list