Index: compiler-rt/trunk/lib/lsan/lsan.cc =================================================================== --- compiler-rt/trunk/lib/lsan/lsan.cc +++ compiler-rt/trunk/lib/lsan/lsan.cc @@ -65,6 +65,18 @@ if (common_flags()->help) parser.PrintFlagDescriptions(); } +static void OnStackUnwind(const SignalContext &sig, const void *, + BufferedStackTrace *stack) { + GetStackTraceWithPcBpAndContext(stack, kStackTraceMax, sig.pc, sig.bp, + sig.context, + common_flags()->fast_unwind_on_fatal); +} + +void LsanOnDeadlySignal(int signo, void *siginfo, void *context) { + HandleDeadlySignal(siginfo, context, GetCurrentThread(), &OnStackUnwind, + nullptr); +} + extern "C" void __lsan_init() { CHECK(!lsan_init_is_running); if (lsan_inited) @@ -80,6 +92,7 @@ InitTlsSize(); InitializeInterceptors(); InitializeThreadRegistry(); + InstallDeadlySignalHandlers(LsanOnDeadlySignal); u32 tid = ThreadCreate(0, 0, true); CHECK_EQ(tid, 0); ThreadStart(tid, GetTid()); Index: compiler-rt/trunk/lib/lsan/lsan_interceptors.cc =================================================================== --- compiler-rt/trunk/lib/lsan/lsan_interceptors.cc +++ compiler-rt/trunk/lib/lsan/lsan_interceptors.cc @@ -401,9 +401,14 @@ REAL(_exit)(status); } +#define COMMON_INTERCEPT_FUNCTION(name) INTERCEPT_FUNCTION(name) +#include "sanitizer_common/sanitizer_signal_interceptors.inc" + namespace __lsan { void InitializeInterceptors() { + InitializeSignalInterceptors(); + INTERCEPT_FUNCTION(malloc); INTERCEPT_FUNCTION(free); LSAN_MAYBE_INTERCEPT_CFREE; Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h @@ -318,15 +318,24 @@ typedef void (*SignalHandlerType)(int, void *, void *); HandleSignalMode GetHandleSignalMode(int signum); void InstallDeadlySignalHandlers(SignalHandlerType handler); + // Signal reporting. -void StartReportDeadlySignal(); // Each sanitizer uses slightly different implementation of stack unwinding. typedef void (*UnwindSignalStackCallbackType)(const SignalContext &sig, const void *callback_context, BufferedStackTrace *stack); +// Print deadly signal report and die. +void HandleDeadlySignal(void *siginfo, void *context, u32 tid, + UnwindSignalStackCallbackType unwind, + const void *unwind_context); + +// Part of HandleDeadlySignal, exposed for asan. +void StartReportDeadlySignal(); +// Part of HandleDeadlySignal, exposed for asan. void ReportDeadlySignal(const SignalContext &sig, u32 tid, UnwindSignalStackCallbackType unwind, const void *unwind_context); + // Alternative signal stack (POSIX-only). void SetAlternateSignalStack(); void UnsetAlternateSignalStack(); Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc @@ -254,6 +254,18 @@ else ReportDeadlySignalImpl(sig, tid, unwind, unwind_context); } + +void HandleDeadlySignal(void *siginfo, void *context, u32 tid, + UnwindSignalStackCallbackType unwind, + const void *unwind_context) { + StartReportDeadlySignal(); + ScopedErrorReportLock rl; + SignalContext sig(siginfo, context); + ReportDeadlySignal(sig, tid, unwind, unwind_context); + Report("ABORTING\n"); + Die(); +} + #endif // !SANITIZER_FUCHSIA && !SANITIZER_GO void WriteToSyslog(const char *msg) { Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc @@ -18,7 +18,6 @@ // clang-format on // Remove when fixed: https://github.com/google/sanitizers/issues/637 -// XFAIL: lsan // XFAIL: msan // XFAIL: tsan // XFAIL: ubsan Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc @@ -7,11 +7,11 @@ // RUN: %env_tool_opts=handle_abort=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s // clang-format on -// FIXME: implement in other sanitizers, not just asan. +// FIXME: implement in other sanitizers. // XFAIL: msan -// XFAIL: lsan // XFAIL: tsan // XFAIL: ubsan + #include #include #include Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ill.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ill.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ill.cc @@ -7,9 +7,8 @@ // RUN: %env_tool_opts=handle_sigill=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s // clang-format on -// FIXME: implement in other sanitizers, not just asan. +// FIXME: implement in other sanitizers. // XFAIL: msan -// XFAIL: lsan // XFAIL: tsan // XFAIL: ubsan // Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc @@ -9,7 +9,6 @@ // REQUIRES: stable-runtime // FIXME: implement SEGV handler in other sanitizers, not just asan. // XFAIL: msan -// XFAIL: lsan // XFAIL: tsan // XFAIL: ubsan Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc @@ -8,7 +8,10 @@ // clang-format on // REQUIRES: x86-target-arch -// XFAIL: lsan, msan, tsan, ubsan +// FIXME: implement in other sanitizers. +// XFAIL: msan +// XFAIL: tsan +// XFAIL: ubsan int main() { #if defined(__x86_64__) Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fpe.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fpe.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/fpe.cc @@ -5,7 +5,6 @@ // RUN: %env_tool_opts=handle_sigfpe=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s // FIXME: implement in other sanitizers, not just asan. // XFAIL: msan -// XFAIL: lsan // XFAIL: tsan // XFAIL: ubsan // Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc =================================================================== --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc @@ -8,7 +8,6 @@ // XFAIL: android && i386-target-arch && asan // FIXME: implement SEGV handler in other sanitizers, not just asan. // XFAIL: msan -// XFAIL: lsan // XFAIL: tsan // XFAIL: ubsan