[compiler-rt] r245770 - [Sanitizer] Dump coverage if we're killing the program with __sanitizer::Die().

Alexey Samsonov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 17:28:12 PDT 2015


Author: samsonov
Date: Fri Aug 21 19:28:12 2015
New Revision: 245770

URL: http://llvm.org/viewvc/llvm-project?rev=245770&view=rev
Log:
[Sanitizer] Dump coverage if we're killing the program with __sanitizer::Die().

Previously we had to call __sanitizer_cov_dump() from tool-specific
callbacks - instead, let sanitizer_common library handle this in a single place.

Modified:
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/lib/lsan/lsan_common.cc
    compiler-rt/trunk/lib/msan/msan.cc
    compiler-rt/trunk/lib/msan/msan.h
    compiler-rt/trunk/lib/msan/msan_linux.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=245770&r1=245769&r2=245770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Fri Aug 21 19:28:12 2015
@@ -56,8 +56,6 @@ static void AsanDie() {
       UnmapOrDie((void*)kLowShadowBeg, kHighShadowEnd - kLowShadowBeg);
     }
   }
-  if (common_flags()->coverage)
-    __sanitizer_cov_dump();
   if (flags()->abort_on_error)
     Abort();
 }

Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=245770&r1=245769&r2=245770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Fri Aug 21 19:28:12 2015
@@ -445,8 +445,6 @@ void DoLeakCheck() {
     return;
   }
   if (common_flags()->exitcode) {
-    if (common_flags()->coverage)
-      __sanitizer_cov_dump();
     Die();
   }
 }

Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=245770&r1=245769&r2=245770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Fri Aug 21 19:28:12 2015
@@ -375,7 +375,6 @@ void __msan_init() {
   msan_init_is_running = 1;
   SanitizerToolName = "MemorySanitizer";
 
-  SetDieCallback(MsanDie);
   InitTlsSize();
 
   CacheBinaryName();

Modified: compiler-rt/trunk/lib/msan/msan.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.h?rev=245770&r1=245769&r2=245770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.h (original)
+++ compiler-rt/trunk/lib/msan/msan.h Fri Aug 21 19:28:12 2015
@@ -167,7 +167,6 @@ struct SymbolizerScope {
   ~SymbolizerScope() { ExitSymbolizer(); }
 };
 
-void MsanDie();
 void PrintWarning(uptr pc, uptr bp);
 void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin);
 

Modified: compiler-rt/trunk/lib/msan/msan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_linux.cc?rev=245770&r1=245769&r2=245770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_linux.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_linux.cc Fri Aug 21 19:28:12 2015
@@ -151,11 +151,6 @@ bool InitShadow(bool init_origins) {
   return true;
 }
 
-void MsanDie() {
-  if (common_flags()->coverage)
-    __sanitizer_cov_dump();
-}
-
 static void MsanAtExit(void) {
   if (flags()->print_stats && (flags()->atexit || msan_report_count > 0))
     ReportStats();

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=245770&r1=245769&r2=245770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Fri Aug 21 19:28:12 2015
@@ -118,6 +118,12 @@ DieCallbackType GetDieCallback() {
 }
 
 void NORETURN Die() {
+#if !SANITIZER_GO
+  // Dump coverage before invoking user callback, in case it calls abort() or
+  // _exit() itself.
+  if (common_flags()->coverage)
+    DumpCoverage();
+#endif  // !SANITIZER_GO
   if (UserDieCallback)
     UserDieCallback();
   if (InternalDieCallback)

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=245770&r1=245769&r2=245770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Fri Aug 21 19:28:12 2015
@@ -283,6 +283,7 @@ void PrepareForSandboxing(__sanitizer_sa
 void CovPrepareForSandboxing(__sanitizer_sandbox_arguments *args);
 void SetSandboxingCallback(void (*f)());
 
+void DumpCoverage();
 void CoverageUpdateMapping();
 void CovBeforeFork();
 void CovAfterFork(int child_pid);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc?rev=245770&r1=245769&r2=245770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_nolibc.cc Fri Aug 21 19:28:12 2015
@@ -20,4 +20,5 @@ namespace __sanitizer {
 void WriteToSyslog(const char *buffer) {}
 #endif
 
-}
+void DumpCoverage() {}
+}  // namespace __sanitizer

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc?rev=245770&r1=245769&r2=245770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc Fri Aug 21 19:28:12 2015
@@ -824,6 +824,8 @@ fd_t MaybeOpenCovFile(const char *name)
   return CovOpenFile(&path, true /* packed */, name);
 }
 
+void DumpCoverage() { coverage_data.DumpAll(); }
+
 void CovBeforeFork() {
   coverage_data.BeforeFork();
 }
@@ -877,7 +879,7 @@ SANITIZER_INTERFACE_ATTRIBUTE void __san
   coverage_data.Init();
 }
 SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_cov_dump() {
-  coverage_data.DumpAll();
+  DumpCoverage();
 }
 SANITIZER_INTERFACE_ATTRIBUTE void
 __sanitizer_cov_module_init(s32 *guards, uptr npcs, u8 *counters,




More information about the llvm-commits mailing list