diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 595b722e74fc..28779b916836 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -465,12 +465,6 @@ void __asan_init() { Atexit(asan_atexit); } -#if CAN_SANITIZE_LEAKS - if (flags()->detect_leaks) { - Atexit(__lsan::DoLeakCheck); - } -#endif - // interceptors InitializeAsanInterceptors(); @@ -550,12 +544,15 @@ void __asan_init() { main_thread->ThreadStart(internal_getpid()); force_interface_symbols(); // no-op. + InitializeAllocator(); + #if CAN_SANITIZE_LEAKS __lsan::InitCommonLsan(); + if (flags()->detect_leaks) { + Atexit(__lsan::DoLeakCheck); + } #endif - InitializeAllocator(); - if (flags()->verbosity) { Report("AddressSanitizer Init done\n"); } diff --git a/compiler-rt/lib/lsan/lsan.cc b/compiler-rt/lib/lsan/lsan.cc index 84466a1e231a..278492b52656 100644 --- a/compiler-rt/lib/lsan/lsan.cc +++ b/compiler-rt/lib/lsan/lsan.cc @@ -56,6 +56,11 @@ void Init() { external_symbolizer[0]) { InitializeExternalSymbolizer(external_symbolizer); } + +#if CAN_SANITIZE_LEAKS + __lsan::InitCommonLsan(); + Atexit(__lsan::DoLeakCheck); +#endif } } // namespace __lsan diff --git a/compiler-rt/lib/lsan/lsan_allocator.cc b/compiler-rt/lib/lsan/lsan_allocator.cc index b131d386572a..cde18c965c9e 100644 --- a/compiler-rt/lib/lsan/lsan_allocator.cc +++ b/compiler-rt/lib/lsan/lsan_allocator.cc @@ -180,6 +180,7 @@ void ForEachChunk(Callable const &callback) { allocator.ForEachChunk(callback); } +#if CAN_SANITIZE_LEAKS template void ForEachChunk( ProcessPlatformSpecificAllocationsCb const &callback); template void ForEachChunk(PrintLeakedCb const &callback); @@ -188,5 +189,5 @@ template void ForEachChunk( MarkIndirectlyLeakedCb const &callback); template void ForEachChunk(ReportLeakedCb const &callback); template void ForEachChunk(ClearTagCb const &callback); - +#endif } // namespace __lsan diff --git a/compiler-rt/lib/lsan/tests/lsan_testlib.cc b/compiler-rt/lib/lsan/tests/lsan_testlib.cc index 142f187c19ed..363cc14f1941 100644 --- a/compiler-rt/lib/lsan/tests/lsan_testlib.cc +++ b/compiler-rt/lib/lsan/tests/lsan_testlib.cc @@ -17,15 +17,9 @@ clang++ ../sanitizer_common/sanitizer_*.cc ../interception/interception_*.cc \ -o lsan.so LD_PRELOAD=./lsan.so /your/app */ -#include "lsan_common.h" #include "lsan.h" __attribute__((constructor)) void constructor() { __lsan::Init(); } - -__attribute__((destructor)) -void destructor() { - __lsan::DoLeakCheck(); -}