Skip to content

[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

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions compiler-rt/lib/rtsan/rtsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ static InitializationState GetInitializationState() {
atomic_load(&rtsan_initialized, memory_order_acquire));
}

static auto PrintDiagnosticsAndDieAction(DiagnosticsInfo info) {
static auto OnViolationAction(DiagnosticsInfo info) {
return [info]() {
__rtsan::PrintDiagnostics(info);
Die();
if (flags().halt_on_error)
Die();
};
}

Expand Down Expand Up @@ -105,20 +106,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(),
OnViolationAction({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(),
OnViolationAction({DiagnosticsInfoType::BlockingCall,
func_name, pc, bp}));
}

} // extern "C"
3 changes: 1 addition & 2 deletions compiler-rt/lib/rtsan/rtsan_flags.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Copy link
Contributor Author

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

26 changes: 26 additions & 0 deletions compiler-rt/test/rtsan/halt_on_error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %clangxx -fsanitize=realtime %s -o %t
// RUN: %env_rtsan_opts="halt_on_error=true" not %run %t 2>&1 | FileCheck %s
// RUN: %env_rtsan_opts="halt_on_error=false" %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-HALT,CHECK
// 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-NO-HALT: ==ERROR: RealtimeSanitizer
// CHECK-NO-HALT-NEXT: {{.*`free`.*}}
}
Loading