[PATCH] Introduce a common mutex to prevent mixing reports from different sanitizers.
Alexey Samsonov
samsonov at google.com
Thu Apr 4 05:21:39 PDT 2013
Restore report mutex in TSan.
Hi rsmith, dvyukov, kcc,
http://llvm-reviews.chandlerc.com/D618
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D618?vs=1494&id=1504#toc
Files:
lib/asan/asan_report.cc
lib/tsan/rtl/tsan_rtl.cc
lib/tsan/rtl/tsan_rtl_report.cc
lib/sanitizer_common/sanitizer_printf.cc
lib/sanitizer_common/sanitizer_common.h
lib/msan/msan_report.cc
lib/ubsan/ubsan_diag.cc
Index: lib/asan/asan_report.cc
===================================================================
--- lib/asan/asan_report.cc
+++ lib/asan/asan_report.cc
@@ -458,10 +458,12 @@
internal__exit(flags()->exitcode);
}
ASAN_ON_ERROR();
- // Make sure the registry is locked while we're printing an error report.
- // We can lock the registry only here to avoid self-deadlock in case of
+ // Make sure the registry and sanitizer report mutexes are locked while
+ // we're printing an error report.
+ // We can lock them only here to avoid self-deadlock in case of
// recursive reports.
asanThreadRegistry().Lock();
+ CommonSanitizerReportMutex.Lock();
reporting_thread_tid = GetCurrentTidOrInvalid();
Printf("===================================================="
"=============\n");
Index: lib/tsan/rtl/tsan_rtl.cc
===================================================================
--- lib/tsan/rtl/tsan_rtl.cc
+++ lib/tsan/rtl/tsan_rtl.cc
@@ -152,6 +152,7 @@
memory_order_relaxed);
if (last != 0 && last + flags()->flush_symbolizer_ms * kMs2Ns < now) {
Lock l(&ctx->report_mtx);
+ SpinMutexLock l2(&CommonSanitizerReportMutex);
SymbolizeFlush();
atomic_store(&ctx->last_symbolize_time_ns, 0, memory_order_relaxed);
}
@@ -253,6 +254,8 @@
// Wait for pending reports.
ctx->report_mtx.Lock();
+ CommonSanitizerReportMutex.Lock();
+ CommonSanitizerReportMutex.Unlock();
ctx->report_mtx.Unlock();
#ifndef TSAN_GO
Index: lib/tsan/rtl/tsan_rtl_report.cc
===================================================================
--- lib/tsan/rtl/tsan_rtl_report.cc
+++ lib/tsan/rtl/tsan_rtl_report.cc
@@ -130,9 +130,11 @@
rep_ = new(mem) ReportDesc;
rep_->typ = typ;
ctx_->report_mtx.Lock();
+ CommonSanitizerReportMutex.Lock();
}
ScopedReport::~ScopedReport() {
+ CommonSanitizerReportMutex.Unlock();
ctx_->report_mtx.Unlock();
DestroyAndFree(rep_);
}
Index: lib/sanitizer_common/sanitizer_printf.cc
===================================================================
--- lib/sanitizer_common/sanitizer_printf.cc
+++ lib/sanitizer_common/sanitizer_printf.cc
@@ -23,6 +23,8 @@
namespace __sanitizer {
+StaticSpinMutex CommonSanitizerReportMutex;
+
static int AppendChar(char **buff, const char *buff_end, char c) {
if (*buff < buff_end) {
**buff = c;
Index: lib/sanitizer_common/sanitizer_common.h
===================================================================
--- lib/sanitizer_common/sanitizer_common.h
+++ lib/sanitizer_common/sanitizer_common.h
@@ -18,6 +18,7 @@
#include "sanitizer_internal_defs.h"
#include "sanitizer_libc.h"
+#include "sanitizer_mutex.h"
namespace __sanitizer {
struct StackTrace;
@@ -109,6 +110,8 @@
void Printf(const char *format, ...);
void Report(const char *format, ...);
void SetPrintfAndReportCallback(void (*callback)(const char *));
+// Can be used to prevent mixing error reports from different sanitizers.
+extern StaticSpinMutex CommonSanitizerReportMutex;
fd_t OpenFile(const char *filename, bool write);
// Opens the file 'file_name" and reads up to 'max_len' bytes.
Index: lib/msan/msan_report.cc
===================================================================
--- lib/msan/msan_report.cc
+++ lib/msan/msan_report.cc
@@ -21,8 +21,6 @@
using namespace __sanitizer;
-static StaticSpinMutex report_mu;
-
namespace __msan {
static bool PrintsToTtyCached() {
@@ -89,7 +87,7 @@
void ReportUMR(StackTrace *stack, u32 origin) {
if (!__msan::flags()->report_umrs) return;
- GenericScopedLock<StaticSpinMutex> lock(&report_mu);
+ SpinMutexLock l(&CommonSanitizerReportMutex);
Decorator d;
Printf("%s", d.Warning());
@@ -103,13 +101,15 @@
}
void ReportExpectedUMRNotFound(StackTrace *stack) {
- GenericScopedLock<StaticSpinMutex> lock(&report_mu);
+ SpinMutexLock l(&CommonSanitizerReportMutex);
Printf(" WARNING: Expected use of uninitialized value not found\n");
PrintStack(stack->trace, stack->size);
}
void ReportAtExitStatistics() {
+ SpinMutexLock l(&CommonSanitizerReportMutex);
+
Decorator d;
Printf("%s", d.Warning());
Printf("MemorySanitizer: %d warnings reported.\n", msan_report_count);
Index: lib/ubsan/ubsan_diag.cc
===================================================================
--- lib/ubsan/ubsan_diag.cc
+++ lib/ubsan/ubsan_diag.cc
@@ -31,7 +31,7 @@
if (!SymbolizeCode(Loc, &Info, 1) || !Info.module || !*Info.module)
return Location(Loc);
- if (!Info.function)
+ if (!Info.file)
return ModuleLocation(Info.module, Info.module_offset);
return SourceLocation(Info.file, Info.line, Info.column);
@@ -237,6 +237,7 @@
Diag::~Diag() {
__sanitizer::AnsiColorDecorator Decor(PrintsToTty());
+ SpinMutexLock l(&CommonSanitizerReportMutex);
Printf(Decor.Bold());
renderLocation(Loc);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D618.2.patch
Type: text/x-patch
Size: 4918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130404/335959b3/attachment.bin>
More information about the llvm-commits
mailing list