diff options
| -rw-r--r-- | compiler-rt/lib/msan/msan.cc | 6 | ||||
| -rw-r--r-- | compiler-rt/lib/msan/msan.h | 3 | ||||
| -rw-r--r-- | compiler-rt/lib/msan/msan_linux.cc | 13 | ||||
| -rw-r--r-- | compiler-rt/lib/msan/msan_report.cc | 8 |
4 files changed, 29 insertions, 1 deletions
diff --git a/compiler-rt/lib/msan/msan.cc b/compiler-rt/lib/msan/msan.cc index 2e615ca20ac..670213f011c 100644 --- a/compiler-rt/lib/msan/msan.cc +++ b/compiler-rt/lib/msan/msan.cc @@ -90,6 +90,8 @@ Flags *flags() { int msan_inited = 0; bool msan_init_is_running; +int msan_report_count = 0; + // Array of stack origins. // FIXME: make it resizable. static const uptr kNumStackOriginDescrs = 1024 * 1024; @@ -163,6 +165,8 @@ void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin) { return; } + ++msan_report_count; + StackTrace stack; GetStackTrace(&stack, kStackTraceMax, pc, bp); @@ -177,7 +181,6 @@ void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin) { } } - } // namespace __msan // Interface. @@ -202,6 +205,7 @@ void __msan_init() { if (msan_inited) return; msan_init_is_running = 1; + InstallAtExitHandler(); SetDieCallback(MsanDie); InitializeInterceptors(); diff --git a/compiler-rt/lib/msan/msan.h b/compiler-rt/lib/msan/msan.h index 6c481995aba..99d9a90d2dc 100644 --- a/compiler-rt/lib/msan/msan.h +++ b/compiler-rt/lib/msan/msan.h @@ -32,6 +32,7 @@ const int kMsanRetvalTlsSizeInWords = 100; namespace __msan { extern int msan_inited; extern bool msan_init_is_running; +extern int msan_report_count; bool ProtectRange(uptr beg, uptr end); bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins); @@ -42,6 +43,7 @@ void *MsanReallocate(StackTrace *stack, void *oldp, uptr size, uptr alignment, bool zeroise); void MsanDeallocate(void *ptr); void InstallTrapHandler(); +void InstallAtExitHandler(); void ReplaceOperatorsNewAndDelete(); void MsanDie(); @@ -52,6 +54,7 @@ void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp); void ReportUMR(StackTrace *stack, u32 origin); void ReportExpectedUMRNotFound(StackTrace *stack); +void ReportAtExitStatistics(); #define GET_MALLOC_STACK_TRACE \ StackTrace stack; \ diff --git a/compiler-rt/lib/msan/msan_linux.cc b/compiler-rt/lib/msan/msan_linux.cc index b51f6363310..02382055d2a 100644 --- a/compiler-rt/lib/msan/msan_linux.cc +++ b/compiler-rt/lib/msan/msan_linux.cc @@ -91,6 +91,19 @@ void InstallTrapHandler() { void MsanDie() { _exit(flags()->exit_code); } + +static void MsanAtExit(void) { + if (msan_report_count > 0) { + ReportAtExitStatistics(); + if (flags()->exit_code) + _exit(flags()->exit_code); + } +} + +void InstallAtExitHandler() { + atexit(MsanAtExit); +} + } #endif // __linux__ diff --git a/compiler-rt/lib/msan/msan_report.cc b/compiler-rt/lib/msan/msan_report.cc index 27d20d3d8e3..87210899973 100644 --- a/compiler-rt/lib/msan/msan_report.cc +++ b/compiler-rt/lib/msan/msan_report.cc @@ -89,4 +89,12 @@ void ReportExpectedUMRNotFound(StackTrace *stack) { StackTrace::PrintStack(stack->trace, stack->size, true, "", 0); } +void ReportAtExitStatistics() { + Decorator d; + Printf("%s", d.Warning()); + Printf("MemorySanitizer: %d warnings reported.\n", msan_report_count); + Printf("%s", d.End()); +} + + } // namespace msan |

