[compiler-rt] [rtsan] Introduce halt_on_error flag (PR #109832)
Chris Apple via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 24 10:07:19 PDT 2024
https://github.com/cjappl created https://github.com/llvm/llvm-project/pull/109832
This is what we were previously calling "continue mode"
Allow a runtime option to either
1. Die (halt_on_error=false) -- default behavior
2. Continue
Follow up reviews will allow for de-duplication so users do not drown in info.
>From fd1881632fd8c07e82440955929c89f2be76dedf Mon Sep 17 00:00:00 2001
From: Chris Apple <cja-private at pm.me>
Date: Fri, 16 Aug 2024 10:44:45 -0700
Subject: [PATCH] [rtsan] Introduce halt_on_error flag
---
compiler-rt/lib/rtsan/rtsan.cpp | 19 +++++++++---------
compiler-rt/lib/rtsan/rtsan_flags.inc | 3 +--
compiler-rt/test/rtsan/halt_on_error.cpp | 25 ++++++++++++++++++++++++
3 files changed, 35 insertions(+), 12 deletions(-)
create mode 100644 compiler-rt/test/rtsan/halt_on_error.cpp
diff --git a/compiler-rt/lib/rtsan/rtsan.cpp b/compiler-rt/lib/rtsan/rtsan.cpp
index e6d2481b2c2a3d..5a2318633a9bc7 100644
--- a/compiler-rt/lib/rtsan/rtsan.cpp
+++ b/compiler-rt/lib/rtsan/rtsan.cpp
@@ -43,10 +43,11 @@ static InitializationState GetInitializationState() {
atomic_load(&rtsan_initialized, memory_order_acquire));
}
-static auto PrintDiagnosticsAndDieAction(DiagnosticsInfo info) {
+static auto DefaultErrorAction(DiagnosticsInfo info) {
return [info]() {
__rtsan::PrintDiagnostics(info);
- Die();
+ if (flags().halt_on_error)
+ Die();
};
}
@@ -104,20 +105,18 @@ __rtsan_notify_intercepted_call(const char *func_name) {
__rtsan_ensure_initialized();
GET_CALLER_PC_BP;
- ExpectNotRealtime(
- GetContextForThisThread(),
- PrintDiagnosticsAndDieAction(
- {DiagnosticsInfoType::InterceptedCall, func_name, pc, bp}));
+ ExpectNotRealtime(GetContextForThisThread(),
+ DefaultErrorAction({DiagnosticsInfoType::InterceptedCall,
+ func_name, pc, bp}));
}
SANITIZER_INTERFACE_ATTRIBUTE void
__rtsan_notify_blocking_call(const char *func_name) {
__rtsan_ensure_initialized();
GET_CALLER_PC_BP;
- ExpectNotRealtime(
- GetContextForThisThread(),
- PrintDiagnosticsAndDieAction(
- {DiagnosticsInfoType::BlockingCall, func_name, pc, bp}));
+ ExpectNotRealtime(GetContextForThisThread(),
+ DefaultErrorAction({DiagnosticsInfoType::BlockingCall,
+ func_name, pc, bp}));
}
} // extern "C"
diff --git a/compiler-rt/lib/rtsan/rtsan_flags.inc b/compiler-rt/lib/rtsan/rtsan_flags.inc
index 93b0294313672f..25d62cf0a60fb0 100644
--- a/compiler-rt/lib/rtsan/rtsan_flags.inc
+++ b/compiler-rt/lib/rtsan/rtsan_flags.inc
@@ -16,5 +16,4 @@
// RTSAN_FLAG(Type, Name, DefaultValue, Description)
// See COMMON_FLAG in sanitizer_flags.inc for more details.
-// Example flag, until we get a real one
-// RTSAN_FLAG(bool, halt_on_error, true, "If true, halt the program on error")
+RTSAN_FLAG(bool, halt_on_error, true, "Exit after first reported error.")
diff --git a/compiler-rt/test/rtsan/halt_on_error.cpp b/compiler-rt/test/rtsan/halt_on_error.cpp
new file mode 100644
index 00000000000000..1d1d90e93f3f44
--- /dev/null
+++ b/compiler-rt/test/rtsan/halt_on_error.cpp
@@ -0,0 +1,25 @@
+// RUN: %clangxx -fsanitize=realtime %s -o %t
+// RUN: env RTSAN_OPTIONS="halt_on_error=false" %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: ios
+
+// Intent: Ensure that halt_on_error does not exit on the first violation.
+
+#include <stdlib.h>
+
+void *MallocViolation() { return malloc(10); }
+
+void FreeViolation(void *Ptr) { free(Ptr); }
+
+void process() [[clang::nonblocking]] {
+ void *Ptr = MallocViolation();
+ FreeViolation(Ptr);
+}
+
+int main() {
+ process();
+ return 0;
+ // CHECK: ==ERROR: RealtimeSanitizer
+ // CHECK-NEXT: {{.*`malloc`.*}}
+ // CHECK: ==ERROR: RealtimeSanitizer
+ // CHECK-NEXT: {{.*`free`.*}}
+}
More information about the llvm-commits
mailing list