Skip to content

[rtsan] Add statistics for suppression count #112718

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 1 commit into from
Oct 17, 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
9 changes: 7 additions & 2 deletions compiler-rt/lib/rtsan/rtsan_assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "rtsan/rtsan.h"
#include "rtsan/rtsan_context.h"
#include "rtsan/rtsan_diagnostics.h"
#include "rtsan/rtsan_stats.h"
#include "rtsan/rtsan_suppressions.h"

#include "sanitizer_common/sanitizer_stacktrace.h"
Expand All @@ -28,8 +29,10 @@ void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
if (context.InRealtimeContext() && !context.IsBypassed()) {
ScopedBypass sb{context};

if (IsFunctionSuppressed(info.func_name))
if (IsFunctionSuppressed(info.func_name)) {
IncrementSuppressedCount();
return;
}

__sanitizer::BufferedStackTrace stack;

Expand All @@ -38,8 +41,10 @@ void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
stack.Unwind(info.pc, info.bp, nullptr,
__sanitizer::common_flags()->fast_unwind_on_fatal);

if (IsStackTraceSuppressed(stack))
if (IsStackTraceSuppressed(stack)) {
IncrementSuppressedCount();
return;
}

OnViolation(stack, info);
}
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct Flags {
Type Name{DefaultValue};
#include "rtsan_flags.inc"
#undef RTSAN_FLAG

bool ContainsSuppresionFile() { return suppressions[0] != '\0'; }
};

extern Flags flags_data;
Expand Down
13 changes: 13 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "rtsan/rtsan_stats.h"
#include "rtsan/rtsan_flags.h"

#include "sanitizer_common/sanitizer_atomic.h"
#include "sanitizer_common/sanitizer_common.h"
Expand All @@ -20,6 +21,7 @@ using namespace __rtsan;

static atomic_uint32_t rtsan_total_error_count{0};
static atomic_uint32_t rtsan_unique_error_count{0};
static atomic_uint32_t rtsan_suppressed_count{0};

void __rtsan::IncrementTotalErrorCount() {
atomic_fetch_add(&rtsan_total_error_count, 1, memory_order_relaxed);
Expand All @@ -37,9 +39,20 @@ static u32 GetUniqueErrorCount() {
return atomic_load(&rtsan_unique_error_count, memory_order_relaxed);
}

void __rtsan::IncrementSuppressedCount() {
atomic_fetch_add(&rtsan_suppressed_count, 1, memory_order_relaxed);
}

static u32 GetSuppressedCount() {
return atomic_load(&rtsan_suppressed_count, memory_order_relaxed);
}

void __rtsan::PrintStatisticsSummary() {
ScopedErrorReportLock l;
Printf("RealtimeSanitizer exit stats:\n");
Printf(" Total error count: %u\n", GetTotalErrorCount());
Printf(" Unique error count: %u\n", GetUniqueErrorCount());

if (flags().ContainsSuppresionFile())
Printf(" Suppression count: %u\n", GetSuppressedCount());
}
1 change: 1 addition & 0 deletions compiler-rt/lib/rtsan/rtsan_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace __rtsan {

void IncrementTotalErrorCount();
void IncrementUniqueErrorCount();
void IncrementSuppressedCount();

void PrintStatisticsSummary();

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/rtsan/rtsan_suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void __rtsan::InitializeSuppressions() {
CHECK_EQ(nullptr, suppression_ctx);

// We will use suppression_ctx == nullptr as an early out
if (flags().suppressions[0] == '\0')
if (!flags().ContainsSuppresionFile())
return;

suppression_ctx = new (suppression_placeholder)
Expand Down
11 changes: 11 additions & 0 deletions compiler-rt/test/rtsan/exit_stats.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %clangxx -fsanitize=realtime %s -o %t
// RUN: %env_rtsan_opts="halt_on_error=false,print_stats_on_exit=true" %run %t 2>&1 | FileCheck %s
// RUN: %env_rtsan_opts="halt_on_error=true,print_stats_on_exit=true" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HALT
// RUN: %env_rtsan_opts="suppressions=%s.supp,print_stats_on_exit=true" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUPPRESSIONS

// UNSUPPORTED: ios

Expand All @@ -23,7 +24,17 @@ int main() {
// CHECK: RealtimeSanitizer exit stats:
// CHECK-NEXT: Total error count: 10
// CHECK-NEXT: Unique error count: 1
// CHECK-NOT: Suppression count

// CHECK-HALT: RealtimeSanitizer exit stats:
// CHECK-HALT-NEXT: Total error count: 1
// CHECK-HALT-NEXT: Unique error count: 1
// CHECK-HALT-NOT: Suppression count

// We pass in intentionally_non_existant_function in the suppressions file
// This is just to ensure we only get the "Suppression count" metric if this
// file is passed at runtime, otherwise that statistic is omitted
// CHECK-SUPPRESSIONS: RealtimeSanitizer exit stats:
// CHECK-SUPPRESSIONS-NEXT: Total error count: 1
// CHECK-SUPPRESSIONS-NEXT: Unique error count: 1
// CHECK-SUPPRESSIONS-NEXT: Suppression count: 0
1 change: 1 addition & 0 deletions compiler-rt/test/rtsan/exit_stats.cpp.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function-name-matches:intentionally_non_existant_function
5 changes: 4 additions & 1 deletion compiler-rt/test/rtsan/stack_suppressions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %clangxx -fsanitize=realtime %s -o %t
// RUN: %env_rtsan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOSUPPRESSIONS
// RUN: %env_rtsan_opts=suppressions='%s.supp' not %run %t 2>&1 | FileCheck %s
// RUN: %env_rtsan_opts=suppressions='%s.supp':print_stats_on_exit=true not %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: ios

// Intent: Ensure that suppressions work as intended
Expand Down Expand Up @@ -61,6 +61,9 @@ int main() {
// CHECK-NOT: free
// CHECK-NOT: BlockFunc

// CHECK: RealtimeSanitizer exit stats:
// CHECK: Suppression count: 7

// CHECK-NOSUPPRESSIONS: malloc
// CHECK-NOSUPPRESSIONS: vector
// CHECK-NOSUPPRESSIONS: free
Expand Down
Loading