[compiler-rt] r313966 - [asan/lsan] Make LSan compliant with recovery mode when running on top of ASan

Maxim Ostapenko via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 00:11:43 PDT 2017


Author: chefmax
Date: Fri Sep 22 00:11:43 2017
New Revision: 313966

URL: http://llvm.org/viewvc/llvm-project?rev=313966&view=rev
Log:
[asan/lsan] Make LSan compliant with recovery mode when running on top of ASan

Don't overwrite exit code in LSan when running on top of ASan in recovery mode
to avoid breakage of users code due to found leaks.

Patch by Slava Barinov.

Differential Revision: https://reviews.llvm.org/D38026

Added:
    compiler-rt/trunk/test/asan/TestCases/recoverable-lsan.cc
Modified:
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/lib/lsan/lsan_common.cc
    compiler-rt/trunk/lib/lsan/lsan_common.h

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=313966&r1=313965&r2=313966&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Fri Sep 22 00:11:43 2017
@@ -459,7 +459,10 @@ static void AsanInitInternal() {
   if (CAN_SANITIZE_LEAKS) {
     __lsan::InitCommonLsan();
     if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) {
-      Atexit(__lsan::DoLeakCheck);
+      if (flags()->halt_on_error)
+        Atexit(__lsan::DoLeakCheck);
+      else
+        Atexit(__lsan::DoRecoverableLeakCheckVoid);
     }
   }
 

Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=313966&r1=313965&r2=313966&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Fri Sep 22 00:11:43 2017
@@ -593,6 +593,8 @@ static int DoRecoverableLeakCheck() {
   return have_leaks ? 1 : 0;
 }
 
+void DoRecoverableLeakCheckVoid() { DoRecoverableLeakCheck(); }
+
 static Suppression *GetSuppressionForAddr(uptr addr) {
   Suppression *s = nullptr;
 
@@ -755,6 +757,7 @@ uptr LeakReport::UnsuppressedLeakCount()
 namespace __lsan {
 void InitCommonLsan() { }
 void DoLeakCheck() { }
+void DoRecoverableLeakCheckVoid() { }
 void DisableInThisThread() { }
 void EnableInThisThread() { }
 }

Modified: compiler-rt/trunk/lib/lsan/lsan_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.h?rev=313966&r1=313965&r2=313966&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.h (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.h Fri Sep 22 00:11:43 2017
@@ -145,6 +145,7 @@ enum IgnoreObjectResult {
 // Functions called from the parent tool.
 void InitCommonLsan();
 void DoLeakCheck();
+void DoRecoverableLeakCheckVoid();
 void DisableCounterUnderflow();
 bool DisabledInThisThread();
 

Added: compiler-rt/trunk/test/asan/TestCases/recoverable-lsan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/recoverable-lsan.cc?rev=313966&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/recoverable-lsan.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/recoverable-lsan.cc Fri Sep 22 00:11:43 2017
@@ -0,0 +1,21 @@
+// Ensure that output is the same but exit code depends on halt_on_error value
+// RUN: %clangxx_asan %s -o %t
+// RUN: %env_asan_opts="halt_on_error=0" %run %t 2>&1 | FileCheck %s
+// RUN: %env_asan_opts="halt_on_error=1" not %run %t 2>&1 | FileCheck %s
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+
+int f() {
+  volatile int *a = (int *)malloc(20);
+  a[0] = 1;
+  return a[0];
+}
+
+int main() {
+  f();
+  f();
+}
+
+// CHECK: LeakSanitizer: detected memory leaks
+// CHECK: SUMMARY: AddressSanitizer: 20 byte(s) leaked




More information about the llvm-commits mailing list