-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[rtsan] Introduce halt_on_error flag #109832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CC Review @davidtrevelyan |
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Chris Apple (cjappl) ChangesThis is what we were previously calling "continue mode" Allow a runtime option to either
Follow up reviews will allow for de-duplication so users do not drown in info. Full diff: https://github.com/llvm/llvm-project/pull/109832.diff 3 Files Affected:
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`.*}}
+}
|
@@ -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.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference for this default is to remain true, but I'm open for discussion on the matter.
You can grep for this flag name and see the defaults for the other sanitizers, each takes their own approach
fd18816
to
087c47f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
Thanks for the reviews @fmayer , we really appreciate having more eyes on this thing |
This is what we were previously calling "continue mode"
Allow a runtime option to either
Follow up reviews will allow for de-duplication so users do not drown in info.