diff options
11 files changed, 47 insertions, 10 deletions
diff --git a/compiler-rt/lib/lsan/lsan.cc b/compiler-rt/lib/lsan/lsan.cc index 6c4767d6125..a51a63ba8c0 100644 --- a/compiler-rt/lib/lsan/lsan.cc +++ b/compiler-rt/lib/lsan/lsan.cc @@ -65,6 +65,18 @@ static void InitializeFlags() { 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 @@ extern "C" void __lsan_init() { InitTlsSize(); InitializeInterceptors(); InitializeThreadRegistry(); + InstallDeadlySignalHandlers(LsanOnDeadlySignal); u32 tid = ThreadCreate(0, 0, true); CHECK_EQ(tid, 0); ThreadStart(tid, GetTid()); diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cc b/compiler-rt/lib/lsan/lsan_interceptors.cc index 259c138eca2..a7c0f72f63c 100644 --- a/compiler-rt/lib/lsan/lsan_interceptors.cc +++ b/compiler-rt/lib/lsan/lsan_interceptors.cc @@ -401,9 +401,14 @@ INTERCEPTOR(void, _exit, int status) { 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; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 4a6b58d3911..0c5ea0999b1 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -318,15 +318,24 @@ void SetSoftRssLimitExceededCallback(void (*Callback)(bool exceeded)); 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(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc index b10eaeb96ed..cce544dd8f3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc @@ -254,6 +254,18 @@ void ReportDeadlySignal(const SignalContext &sig, u32 tid, 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) { diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc b/compiler-rt/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc index e76f0b1afcc..7f0a190277b 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc +++ b/compiler-rt/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 diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/assert.cc b/compiler-rt/test/sanitizer_common/TestCases/Linux/assert.cc index 51a9163f4c5..af0853e6b65 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/assert.cc +++ b/compiler-rt/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 <assert.h> #include <stdio.h> #include <sanitizer/asan_interface.h> diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/ill.cc b/compiler-rt/test/sanitizer_common/TestCases/Linux/ill.cc index 030da337616..7d39abefa26 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/ill.cc +++ b/compiler-rt/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 // diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc index ad94d13d2e4..86ad40bcbff 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc +++ b/compiler-rt/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 diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc index b5e45c30701..4cb075807a2 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc +++ b/compiler-rt/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__) diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/fpe.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/fpe.cc index 44d53274bc4..46fe4f4391e 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/fpe.cc +++ b/compiler-rt/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 // diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc index f619b2205b8..cdccf97bdfa 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc +++ b/compiler-rt/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 |