[PATCH] D80967: add debug code to chase down a rare crash in asan/lsan https://github.com/google/sanitizers/issues/1193

Kostya Serebryany via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 19:30:26 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e6c3e3e7b5e: add debug code to chase down a rare crash in asan/lsan https://github. (authored by kcc).

Changed prior to commit:
  https://reviews.llvm.org/D80967?vs=267773&id=267778#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80967/new/

https://reviews.llvm.org/D80967

Files:
  compiler-rt/lib/asan/asan_allocator.cpp
  compiler-rt/lib/lsan/lsan_common.cpp


Index: compiler-rt/lib/lsan/lsan_common.cpp
===================================================================
--- compiler-rt/lib/lsan/lsan_common.cpp
+++ compiler-rt/lib/lsan/lsan_common.cpp
@@ -25,6 +25,8 @@
 #include "sanitizer_common/sanitizer_thread_registry.h"
 #include "sanitizer_common/sanitizer_tls_get_addr.h"
 
+extern "C" const char *__lsan_current_stage = "unknown";
+
 #if CAN_SANITIZE_LEAKS
 namespace __lsan {
 
@@ -34,6 +36,7 @@
 
 Flags lsan_flags;
 
+
 void DisableCounterUnderflow() {
   if (common_flags()->detect_leaks) {
     Report("Unmatched call to __lsan_enable().\n");
@@ -363,6 +366,7 @@
 // ForEachChunk callback. If the chunk is marked as leaked, marks all chunks
 // which are reachable from it as indirectly leaked.
 static void MarkIndirectlyLeakedCb(uptr chunk, void *arg) {
+  __lsan_current_stage = "MarkIndirectlyLeakedCb";
   chunk = GetUserBegin(chunk);
   LsanMetadata m(chunk);
   if (m.allocated() && m.tag() != kReachable) {
@@ -375,6 +379,7 @@
 // frontier.
 static void CollectIgnoredCb(uptr chunk, void *arg) {
   CHECK(arg);
+  __lsan_current_stage = "CollectIgnoredCb";
   chunk = GetUserBegin(chunk);
   LsanMetadata m(chunk);
   if (m.allocated() && m.tag() == kIgnored) {
@@ -404,6 +409,7 @@
 static void MarkInvalidPCCb(uptr chunk, void *arg) {
   CHECK(arg);
   InvalidPCParam *param = reinterpret_cast<InvalidPCParam *>(arg);
+  __lsan_current_stage = "MarkInvalidPCCb";
   chunk = GetUserBegin(chunk);
   LsanMetadata m(chunk);
   if (m.allocated() && m.tag() != kReachable && m.tag() != kIgnored) {
@@ -479,6 +485,7 @@
 // ForEachChunk callback. Resets the tags to pre-leak-check state.
 static void ResetTagsCb(uptr chunk, void *arg) {
   (void)arg;
+  __lsan_current_stage = "ResetTagsCb";
   chunk = GetUserBegin(chunk);
   LsanMetadata m(chunk);
   if (m.allocated() && m.tag() != kIgnored)
@@ -495,6 +502,7 @@
 static void CollectLeaksCb(uptr chunk, void *arg) {
   CHECK(arg);
   LeakReport *leak_report = reinterpret_cast<LeakReport *>(arg);
+  __lsan_current_stage = "CollectLeaksCb";
   chunk = GetUserBegin(chunk);
   LsanMetadata m(chunk);
   if (!m.allocated()) return;
Index: compiler-rt/lib/asan/asan_allocator.cpp
===================================================================
--- compiler-rt/lib/asan/asan_allocator.cpp
+++ compiler-rt/lib/asan/asan_allocator.cpp
@@ -1037,8 +1037,19 @@
   return 0;
 }
 
+// Debug code. Delete once issue #1193 is chased down.
+extern "C" SANITIZER_WEAK_ATTRIBUTE const char *__lsan_current_stage;
+
 uptr GetUserBegin(uptr chunk) {
   __asan::AsanChunk *m = __asan::instance.GetAsanChunkByAddrFastLocked(chunk);
+  if (!m)
+    Printf(
+        "ASAN is about to crash with a CHECK failure.\n"
+        "The ASAN developers are trying to chaise down this bug,\n"
+        "so if you've encountered this bug please let us know.\n"
+        "See also: https://github.com/google/sanitizers/issues/1193\n"
+        "chunk: %p caller %p __lsan_current_stage %s\n",
+        chunk, GET_CALLER_PC(), __lsan_current_stage);
   CHECK(m);
   return m->Beg();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80967.267778.patch
Type: text/x-patch
Size: 3068 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200602/35fbdd1e/attachment.bin>


More information about the llvm-commits mailing list