[compiler-rt] r326105 - [MSan] Print current stack on CHECK violation
Alex Shlyapnikov via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 10:27:24 PST 2018
Author: alekseyshl
Date: Mon Feb 26 10:27:24 2018
New Revision: 326105
URL: http://llvm.org/viewvc/llvm-project?rev=326105&view=rev
Log:
[MSan] Print current stack on CHECK violation
Summary:
Print current stack on CHECK violation to aid debugging and
match other sanitizers functionality.
Reviewers: eugenis
Subscribers: delcypher, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43692
Added:
compiler-rt/trunk/test/msan/check-handler.cc
Modified:
compiler-rt/trunk/lib/msan/msan.cc
compiler-rt/trunk/lib/msan/msan.h
Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=326105&r1=326104&r2=326105&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Mon Feb 26 10:27:24 2018
@@ -379,6 +379,14 @@ static void MsanOnDeadlySignal(int signo
HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr);
}
+static void MsanCheckFailed(const char *file, int line, const char *cond,
+ u64 v1, u64 v2) {
+ Report("MemorySanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n", file,
+ line, cond, (uptr)v1, (uptr)v2);
+ PRINT_CURRENT_STACK_CHECK();
+ Die();
+}
+
void __msan_init() {
CHECK(!msan_init_is_running);
if (msan_inited) return;
@@ -391,6 +399,9 @@ void __msan_init() {
CacheBinaryName();
InitializeFlags();
+ // Install tool-specific callbacks in sanitizer_common.
+ SetCheckFailedCallback(MsanCheckFailed);
+
__sanitizer_set_report_path(common_flags()->log_path);
InitializeInterceptors();
Modified: compiler-rt/trunk/lib/msan/msan.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.h?rev=326105&r1=326104&r2=326105&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.h (original)
+++ compiler-rt/trunk/lib/msan/msan.h Mon Feb 26 10:27:24 2018
@@ -356,14 +356,23 @@ const int STACK_TRACE_TAG_POISON = Stack
common_flags()->fast_unwind_on_malloc); \
}
+#define GET_STORE_STACK_TRACE \
+ GET_STORE_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
+
#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp) \
BufferedStackTrace stack; \
if (msan_inited) \
GetStackTrace(&stack, kStackTraceMax, pc, bp, nullptr, \
common_flags()->fast_unwind_on_fatal)
-#define GET_STORE_STACK_TRACE \
- GET_STORE_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
+#define GET_FATAL_STACK_TRACE_HERE \
+ GET_FATAL_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
+
+#define PRINT_CURRENT_STACK_CHECK() \
+ { \
+ GET_FATAL_STACK_TRACE_HERE; \
+ stack.Print(); \
+ }
class ScopedThreadLocalStateBackup {
public:
Added: compiler-rt/trunk/test/msan/check-handler.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/check-handler.cc?rev=326105&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/check-handler.cc (added)
+++ compiler-rt/trunk/test/msan/check-handler.cc Mon Feb 26 10:27:24 2018
@@ -0,0 +1,16 @@
+// RUN: %clangxx_msan -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// Verify that CHECK handler prints a stack on CHECK fail.
+
+#include <stdlib.h>
+
+int main(void) {
+ // Allocate chunk from the secondary allocator to trigger CHECK(IsALigned())
+ // in its free() path.
+ void *p = malloc(8 << 20);
+ free(reinterpret_cast<char*>(p) + 1);
+ // CHECK: MemorySanitizer: bad pointer
+ // CHECK: MemorySanitizer CHECK failed
+ // CHECK: #0
+ return 0;
+}
More information about the llvm-commits
mailing list