[compiler-rt] f161e84 - Revert "[lsan] On Fuchsia, don't use atexit hook for leak checks"

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 12:11:07 PDT 2020


Author: Nikita Popov
Date: 2020-09-23T21:10:56+02:00
New Revision: f161e84c10b6eb2255345ebfaaa2bbadb4b0fe2a

URL: https://github.com/llvm/llvm-project/commit/f161e84c10b6eb2255345ebfaaa2bbadb4b0fe2a
DIFF: https://github.com/llvm/llvm-project/commit/f161e84c10b6eb2255345ebfaaa2bbadb4b0fe2a.diff

LOG: Revert "[lsan] On Fuchsia, don't use atexit hook for leak checks"

This reverts commit 0caad9fe441d5ee562e96d8b30b5574b492a933a.
This reverts commit c96d0cceb684fa176b51d7df5f4f8370e2c983f4.

Causes linker errors which were not fixed by the subsequent commit
either:

/home/nikic/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:503: error: undefined reference to '__asan::InstallAtExitCheckLeaks()'

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_fuchsia.cpp
    compiler-rt/lib/asan/asan_internal.h
    compiler-rt/lib/asan/asan_posix.cpp
    compiler-rt/lib/asan/asan_rtl.cpp
    compiler-rt/lib/asan/asan_win.cpp
    compiler-rt/lib/lsan/lsan.cpp
    compiler-rt/lib/lsan/lsan.h
    compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
    compiler-rt/lib/lsan/lsan_fuchsia.cpp
    compiler-rt/lib/lsan/lsan_posix.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_fuchsia.cpp b/compiler-rt/lib/asan/asan_fuchsia.cpp
index edab8d39d7d7..ec15abfa0fe8 100644
--- a/compiler-rt/lib/asan/asan_fuchsia.cpp
+++ b/compiler-rt/lib/asan/asan_fuchsia.cpp
@@ -14,16 +14,15 @@
 #include "sanitizer_common/sanitizer_fuchsia.h"
 #if SANITIZER_FUCHSIA
 
-#include <limits.h>
-#include <zircon/sanitizer.h>
-#include <zircon/syscalls.h>
-#include <zircon/threads.h>
-
 #include "asan_interceptors.h"
 #include "asan_internal.h"
 #include "asan_stack.h"
 #include "asan_thread.h"
-#include "lsan/lsan_common.h"
+
+#include <limits.h>
+#include <zircon/sanitizer.h>
+#include <zircon/syscalls.h>
+#include <zircon/threads.h>
 
 namespace __asan {
 
@@ -32,8 +31,7 @@ namespace __asan {
 // AsanInitInternal->InitializeHighMemEnd (asan_rtl.cpp).
 // Just do some additional sanity checks here.
 void InitializeShadowMemory() {
-  if (Verbosity())
-    PrintAddressSpaceLayout();
+  if (Verbosity()) PrintAddressSpaceLayout();
 
   // Make sure SHADOW_OFFSET doesn't use __asan_shadow_memory_dynamic_address.
   __asan_shadow_memory_dynamic_address = kDefaultShadowSentinel;
@@ -150,8 +148,7 @@ static void *BeforeThreadCreateHook(uptr user_id, bool detached,
                                     uptr stack_size) {
   EnsureMainThreadIDIsCorrect();
   // Strict init-order checking is thread-hostile.
-  if (flags()->strict_init_order)
-    StopInitOrderChecking();
+  if (flags()->strict_init_order) StopInitOrderChecking();
 
   GET_STACK_TRACE_THREAD;
   u32 parent_tid = GetCurrentTidOrInvalid();
@@ -205,18 +202,8 @@ void FlushUnneededASanShadowMemory(uptr p, uptr size) {
   __sanitizer_fill_shadow(p, size, 0, 0);
 }
 
-// On Fuchsia, leak detection is done by a special hook after atexit hooks.
-// So this doesn't install any atexit hook like on other platforms.
-void InstallAtExitCheckLeaks() {}
-
 }  // namespace __asan
 
-namespace __lsan {
-
-bool UseExitcodeOnLeak() { return __asan::flags()->halt_on_error; }
-
-}  // namespace __lsan
-
 // These are declared (in extern "C") by <zircon/sanitizer.h>.
 // The system runtime will call our definitions directly.
 

diff  --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h
index 861b70f716af..cfb54927c6cf 100644
--- a/compiler-rt/lib/asan/asan_internal.h
+++ b/compiler-rt/lib/asan/asan_internal.h
@@ -123,8 +123,6 @@ void *AsanDlSymNext(const char *sym);
 // `dlopen()` specific initialization inside this function.
 bool HandleDlopenInit();
 
-void InstallAtExitCheckLeaks();
-
 // Add convenient macro for interface functions that may be represented as
 // weak hooks.
 #define ASAN_MALLOC_HOOK(ptr, size)                                   \

diff  --git a/compiler-rt/lib/asan/asan_posix.cpp b/compiler-rt/lib/asan/asan_posix.cpp
index c69ecbf55584..d7f19d846544 100644
--- a/compiler-rt/lib/asan/asan_posix.cpp
+++ b/compiler-rt/lib/asan/asan_posix.cpp
@@ -140,18 +140,6 @@ void PlatformTSDDtor(void *tsd) {
   AsanThread::TSDDtor(tsd);
 }
 #endif
-
-#if CAN_SANITIZE_LEAKS
-void InstallAtExitCheckLeaks() {
-  if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) {
-    if (flags()->halt_on_error)
-      Atexit(__lsan::DoLeakCheck);
-    else
-      Atexit(__lsan::DoRecoverableLeakCheckVoid);
-  }
-}
-#endif
-
 }  // namespace __asan
 
 #endif  // SANITIZER_POSIX

diff  --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp
index 09270e9b43b1..115733cdaa48 100644
--- a/compiler-rt/lib/asan/asan_rtl.cpp
+++ b/compiler-rt/lib/asan/asan_rtl.cpp
@@ -498,10 +498,15 @@ static void AsanInitInternal() {
   force_interface_symbols();  // no-op.
   SanitizerInitializeUnwinder();
 
-#if CAN_SANITIZE_LEAKS
-  __lsan::InitCommonLsan();
-  InstallAtExitCheckLeaks();
-#endif
+  if (CAN_SANITIZE_LEAKS) {
+    __lsan::InitCommonLsan();
+    if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) {
+      if (flags()->halt_on_error)
+        Atexit(__lsan::DoLeakCheck);
+      else
+        Atexit(__lsan::DoRecoverableLeakCheckVoid);
+    }
+  }
 
 #if CAN_SANITIZE_UB
   __ubsan::InitAsPlugin();

diff  --git a/compiler-rt/lib/asan/asan_win.cpp b/compiler-rt/lib/asan/asan_win.cpp
index 89e41e4685f6..8044ae16ff9b 100644
--- a/compiler-rt/lib/asan/asan_win.cpp
+++ b/compiler-rt/lib/asan/asan_win.cpp
@@ -1,5 +1,4 @@
-//===-- asan_win.cpp
-//------------------------------------------------------===//>
+//===-- asan_win.cpp ------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -15,9 +14,10 @@
 #include "sanitizer_common/sanitizer_platform.h"
 #if SANITIZER_WINDOWS
 #define WIN32_LEAN_AND_MEAN
-#include <stdlib.h>
 #include <windows.h>
 
+#include <stdlib.h>
+
 #include "asan_interceptors.h"
 #include "asan_internal.h"
 #include "asan_mapping.h"
@@ -49,8 +49,8 @@ uptr __asan_get_shadow_memory_dynamic_address() {
 static LPTOP_LEVEL_EXCEPTION_FILTER default_seh_handler;
 static LPTOP_LEVEL_EXCEPTION_FILTER user_seh_handler;
 
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE long __asan_unhandled_exception_filter(
-    EXCEPTION_POINTERS *info) {
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE
+long __asan_unhandled_exception_filter(EXCEPTION_POINTERS *info) {
   EXCEPTION_RECORD *exception_record = info->ExceptionRecord;
   CONTEXT *context = info->ContextRecord;
 
@@ -187,8 +187,6 @@ void InitializePlatformInterceptors() {
   }
 }
 
-void InstallAtExitCheckLeaks() {}
-
 void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {
   UNIMPLEMENTED();
 }

diff  --git a/compiler-rt/lib/lsan/lsan.cpp b/compiler-rt/lib/lsan/lsan.cpp
index 1d3ad84b3617..c8cc045783d4 100644
--- a/compiler-rt/lib/lsan/lsan.cpp
+++ b/compiler-rt/lib/lsan/lsan.cpp
@@ -103,7 +103,9 @@ extern "C" void __lsan_init() {
   InitializeThreadRegistry();
   InstallDeadlySignalHandlers(LsanOnDeadlySignal);
   InitializeMainThread();
-  InstallAtExitCheckLeaks();
+
+  if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
+    Atexit(DoLeakCheck);
 
   InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
 

diff  --git a/compiler-rt/lib/lsan/lsan.h b/compiler-rt/lib/lsan/lsan.h
index da70d6d55e13..1e82ad72f005 100644
--- a/compiler-rt/lib/lsan/lsan.h
+++ b/compiler-rt/lib/lsan/lsan.h
@@ -39,7 +39,6 @@ namespace __lsan {
 void InitializeInterceptors();
 void ReplaceSystemMalloc();
 void LsanOnDeadlySignal(int signo, void *siginfo, void *context);
-void InstallAtExitCheckLeaks();
 
 #define ENSURE_LSAN_INITED do {   \
   CHECK(!lsan_init_is_running);   \

diff  --git a/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
index a245093728a3..caedbf155969 100644
--- a/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
+++ b/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
@@ -51,16 +51,7 @@ void ProcessPlatformSpecificAllocations(Frontier *frontier) {}
 // behavior and causes rare race conditions.
 void HandleLeaks() {}
 
-// This is defined 
diff erently in asan_fuchsia.cpp and lsan_fuchsia.cpp.
-bool UseExitcodeOnLeak();
-
 int ExitHook(int status) {
-  if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) {
-    if (UseExitcodeOnLeak())
-      DoLeakCheck();
-    else
-      DoRecoverableLeakCheckVoid();
-  }
   return status == 0 && HasReportedLeaks() ? common_flags()->exitcode : status;
 }
 

diff  --git a/compiler-rt/lib/lsan/lsan_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_fuchsia.cpp
index 5b9b0e2ad1e9..40e65c6fb729 100644
--- a/compiler-rt/lib/lsan/lsan_fuchsia.cpp
+++ b/compiler-rt/lib/lsan/lsan_fuchsia.cpp
@@ -76,13 +76,6 @@ void GetAllThreadAllocatorCachesLocked(InternalMmapVector<uptr> *caches) {
       caches);
 }
 
-// On Fuchsia, leak detection is done by a special hook after atexit hooks.
-// So this doesn't install any atexit hook like on other platforms.
-void InstallAtExitCheckLeaks() {}
-
-// ASan defines this to check its `halt_on_error` flag.
-bool UseExitcodeOnLeak() { return true; }
-
 }  // namespace __lsan
 
 // These are declared (in extern "C") by <zircon/sanitizer.h>.

diff  --git a/compiler-rt/lib/lsan/lsan_posix.cpp b/compiler-rt/lib/lsan/lsan_posix.cpp
index 4407f1cc7142..8e05915dd1b9 100644
--- a/compiler-rt/lib/lsan/lsan_posix.cpp
+++ b/compiler-rt/lib/lsan/lsan_posix.cpp
@@ -91,11 +91,6 @@ void LsanOnDeadlySignal(int signo, void *siginfo, void *context) {
                      nullptr);
 }
 
-void InstallAtExitCheckLeaks() {
-  if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
-    Atexit(DoLeakCheck);
-}
-
 }  // namespace __lsan
 
 #endif  // SANITIZER_POSIX


        


More information about the llvm-commits mailing list