[PATCH] Add the way to disable LSan at link time.

Alexey Samsonov samsonov at google.com
Wed Jun 26 04:46:49 PDT 2013


Hi earthdok,

http://llvm-reviews.chandlerc.com/D1044

Files:
  lib/lsan/lsan_common.cc
  lib/lsan/lit_tests/TestCases/link_turned_off.cc
  lib/lsan/lsan_common.h
  include/sanitizer/lsan_interface.h

Index: lib/lsan/lsan_common.cc
===================================================================
--- lib/lsan/lsan_common.cc
+++ lib/lsan/lsan_common.cc
@@ -314,6 +314,8 @@
   static bool already_done;
   CHECK(!already_done);
   already_done = true;
+  if (&__lsan_is_turned_off && __lsan_is_turned_off())
+    return;
 
   DoLeakCheckParam param;
   param.success = false;
@@ -442,4 +444,11 @@
   __lsan::disable_counter--;
 #endif
 }
+
+#if !SANITIZER_SUPPORTS_WEAK_HOOKS
+SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
+int __lsan_is_turned_off() {
+  return 0;
+}
+#endif
 }  // extern "C"
Index: lib/lsan/lit_tests/TestCases/link_turned_off.cc
===================================================================
--- /dev/null
+++ lib/lsan/lit_tests/TestCases/link_turned_off.cc
@@ -0,0 +1,16 @@
+// Test for disabling LSan at link-time.
+// RUN: %clangxx_lsan %s -o %t && %t
+
+#include <sanitizer/lsan_interface.h>
+
+extern "C" {
+int __lsan_is_turned_off() {
+  return 1;
+}
+}
+
+int main() {
+  volatile int *x = new int;
+  *x = 42;
+  return 0;
+}
Index: lib/lsan/lsan_common.h
===================================================================
--- lib/lsan/lsan_common.h
+++ lib/lsan/lsan_common.h
@@ -154,4 +154,9 @@
 
 }  // namespace __lsan
 
+extern "C" {
+int __lsan_is_turned_off() SANITIZER_WEAK_ATTRIBUTE
+    SANITIZER_INTERFACE_ATTRIBUTE;
+}  // extern "C"
+
 #endif  // LSAN_COMMON_H
Index: include/sanitizer/lsan_interface.h
===================================================================
--- include/sanitizer/lsan_interface.h
+++ include/sanitizer/lsan_interface.h
@@ -25,6 +25,10 @@
   void __lsan_enable();
   // The heap object into which p points will be treated as a non-leak.
   void __lsan_ignore_object(const void *p);
+  // The user may optionally provide this function to disallow the leak checking
+  // for the program it is linked into. Note: this function may be called late,
+  // after all the global destructors.
+  int __lsan_is_turned_off();
 #ifdef __cplusplus
 }  // extern "C"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1044.1.patch
Type: text/x-patch
Size: 2044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130626/257cad3b/attachment.bin>


More information about the llvm-commits mailing list