[compiler-rt] r352150 - [hwasan] Implement print_module_map flag.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 24 18:05:25 PST 2019


Author: eugenis
Date: Thu Jan 24 18:05:25 2019
New Revision: 352150

URL: http://llvm.org/viewvc/llvm-project?rev=352150&view=rev
Log:
[hwasan] Implement print_module_map flag.

Reviewers: kcc, pcc

Subscribers: kubamracek, llvm-commits

Differential Revision: https://reviews.llvm.org/D57130

Added:
    compiler-rt/trunk/test/hwasan/TestCases/print-module-map.c
Modified:
    compiler-rt/trunk/lib/hwasan/hwasan_linux.cc
    compiler-rt/trunk/lib/hwasan/hwasan_report.cc

Modified: compiler-rt/trunk/lib/hwasan/hwasan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_linux.cc?rev=352150&r1=352149&r2=352150&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_linux.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_linux.cc Thu Jan 24 18:05:25 2019
@@ -218,6 +218,8 @@ bool MemIsApp(uptr p) {
 }
 
 static void HwasanAtExit(void) {
+  if (common_flags()->print_module_map)
+    DumpProcessMap();
   if (flags()->print_stats && (flags()->atexit || hwasan_report_count > 0))
     ReportStats();
   if (hwasan_report_count > 0) {
@@ -376,8 +378,6 @@ static void HandleTagMismatch(AccessInfo
   GetStackTrace(stack, kStackTraceMax, pc, frame, uc,
                 common_flags()->fast_unwind_on_fatal);
 
-  ++hwasan_report_count;
-
   bool fatal = flags()->halt_on_error || !ai.recover;
   ReportTagMismatch(stack, ai.addr, ai.size, ai.is_store, fatal);
 }

Modified: compiler-rt/trunk/lib/hwasan/hwasan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_report.cc?rev=352150&r1=352149&r2=352150&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_report.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_report.cc Thu Jan 24 18:05:25 2019
@@ -34,15 +34,21 @@ class ScopedReport {
   ScopedReport(bool fatal = false) : error_message_(1), fatal(fatal) {
     BlockingMutexLock lock(&error_message_lock_);
     error_message_ptr_ = fatal ? &error_message_ : nullptr;
+    ++hwasan_report_count;
   }
 
   ~ScopedReport() {
-    BlockingMutexLock lock(&error_message_lock_);
-    if (fatal) {
-      SetAbortMessage(error_message_.data());
-      Die();
+    {
+      BlockingMutexLock lock(&error_message_lock_);
+      if (fatal)
+        SetAbortMessage(error_message_.data());
+      error_message_ptr_ = nullptr;
     }
-    error_message_ptr_ = nullptr;
+    if (common_flags()->print_module_map >= 2 ||
+        (fatal && common_flags()->print_module_map))
+      DumpProcessMap();
+    if (fatal)
+      Die();
   }
 
   static void MaybeAppendToErrorMessage(const char *msg) {

Added: compiler-rt/trunk/test/hwasan/TestCases/print-module-map.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/hwasan/TestCases/print-module-map.c?rev=352150&view=auto
==============================================================================
--- compiler-rt/trunk/test/hwasan/TestCases/print-module-map.c (added)
+++ compiler-rt/trunk/test/hwasan/TestCases/print-module-map.c Thu Jan 24 18:05:25 2019
@@ -0,0 +1,32 @@
+// RUN: %clang_hwasan %s -o %t && %env_hwasan_opts=print_module_map=1 %run %t 2>&1 | FileCheck %s --check-prefixes=EXIT,NOMORE
+// RUN: %clang_hwasan %s -DBUG -o %t && %env_hwasan_opts=print_module_map=1 not %run %t 2>&1 | FileCheck %s --check-prefixes=EXIT,NOMORE
+// RUN: %clang_hwasan %s -DBUG -fsanitize-recover=hwaddress -o %t && %env_hwasan_opts=print_module_map=1,halt_on_error=0 not %run %t 2>&1 | FileCheck %s --check-prefixes=EXIT,NOMORE
+// RUN: %clang_hwasan %s -DBUG -fsanitize-recover=hwaddress -o %t && %env_hwasan_opts=print_module_map=2,halt_on_error=0 not %run %t 2>&1 | FileCheck %s --check-prefixes=BUG1,BUG2,EXIT,NOMORE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sanitizer/hwasan_interface.h>
+
+int main() {
+  __hwasan_enable_allocator_tagging();
+#ifdef BUG
+  char * volatile x = (char*)malloc(40);
+  free(x);
+  free(x);
+  free(x);
+#endif
+  __hwasan_disable_allocator_tagging();
+  // BUG1: Process memory map follows:
+  // BUG1: print-module-map
+  // BUG1: End of process memory map.
+
+  // BUG2: Process memory map follows:
+  // BUG2: print-module-map
+  // BUG2: End of process memory map.
+
+  // EXIT: Process memory map follows:
+  // EXIT: print-module-map
+  // EXIT: End of process memory map.
+
+  // NOMORE-NOT: Process memory map follows:
+}




More information about the llvm-commits mailing list