[lsan] Invoke leak detection with atexit().
Keeps it consistent between ASan and LSan.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182399 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index 595b722..28779b9 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -465,12 +465,6 @@
Atexit(asan_atexit);
}
-#if CAN_SANITIZE_LEAKS
- if (flags()->detect_leaks) {
- Atexit(__lsan::DoLeakCheck);
- }
-#endif
-
// interceptors
InitializeAsanInterceptors();
@@ -550,12 +544,15 @@
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/lib/lsan/lsan.cc b/lib/lsan/lsan.cc
index 84466a1..278492b 100644
--- a/lib/lsan/lsan.cc
+++ b/lib/lsan/lsan.cc
@@ -56,6 +56,11 @@
external_symbolizer[0]) {
InitializeExternalSymbolizer(external_symbolizer);
}
+
+#if CAN_SANITIZE_LEAKS
+ __lsan::InitCommonLsan();
+ Atexit(__lsan::DoLeakCheck);
+#endif
}
} // namespace __lsan
diff --git a/lib/lsan/lsan_allocator.cc b/lib/lsan/lsan_allocator.cc
index b131d38..cde18c9 100644
--- a/lib/lsan/lsan_allocator.cc
+++ b/lib/lsan/lsan_allocator.cc
@@ -180,6 +180,7 @@
allocator.ForEachChunk(callback);
}
+#if CAN_SANITIZE_LEAKS
template void ForEachChunk<ProcessPlatformSpecificAllocationsCb>(
ProcessPlatformSpecificAllocationsCb const &callback);
template void ForEachChunk<PrintLeakedCb>(PrintLeakedCb const &callback);
@@ -188,5 +189,5 @@
MarkIndirectlyLeakedCb const &callback);
template void ForEachChunk<ReportLeakedCb>(ReportLeakedCb const &callback);
template void ForEachChunk<ClearTagCb>(ClearTagCb const &callback);
-
+#endif
} // namespace __lsan
diff --git a/lib/lsan/tests/lsan_testlib.cc b/lib/lsan/tests/lsan_testlib.cc
index 142f187..363cc14 100644
--- a/lib/lsan/tests/lsan_testlib.cc
+++ b/lib/lsan/tests/lsan_testlib.cc
@@ -17,15 +17,9 @@
-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();
-}