[PATCH] [asan] LSan hooks in asan_rtl

Sergey Matveev earthdok at google.com
Tue May 21 04:31:06 PDT 2013


    - removed some \#ifs and changed flag name

Hi kcc, glider,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D831?vs=2042&id=2047#toc

Files:
  lib/asan/asan_flags.h
  lib/asan/asan_rtl.cc

Index: lib/asan/asan_flags.h
===================================================================
--- lib/asan/asan_flags.h
+++ lib/asan/asan_flags.h
@@ -108,6 +108,8 @@
   // If true, assume that dynamic initializers can never access globals from
   // other modules, even if the latter are already initialized.
   bool strict_init_order;
+  // Invoke LeakSanitizer at process exit.
+  bool detect_leaks;
 };
 
 extern Flags asan_flags_dont_use_directly;
Index: lib/asan/asan_rtl.cc
===================================================================
--- lib/asan/asan_rtl.cc
+++ lib/asan/asan_rtl.cc
@@ -24,6 +24,7 @@
 #include "sanitizer_common/sanitizer_flags.h"
 #include "sanitizer_common/sanitizer_libc.h"
 #include "sanitizer_common/sanitizer_symbolizer.h"
+#include "lsan/lsan_common.h"
 
 namespace __asan {
 
@@ -124,6 +125,7 @@
   ParseFlag(str, &f->use_stack_depot, "use_stack_depot");
   ParseFlag(str, &f->strict_memcmp, "strict_memcmp");
   ParseFlag(str, &f->strict_init_order, "strict_init_order");
+  ParseFlag(str, &f->detect_leaks, "detect_leaks");
 }
 
 void InitializeFlags(Flags *f, const char *env) {
@@ -171,6 +173,7 @@
   f->use_stack_depot = true;
   f->strict_memcmp = true;
   f->strict_init_order = false;
+  f->detect_leaks = false;
 
   // Override from compile definition.
   ParseFlagsFromString(f, MaybeUseAsanDefaultOptionsCompileDefiniton());
@@ -184,6 +187,20 @@
 
   // Override from command line.
   ParseFlagsFromString(f, env);
+
+#if !CAN_SANITIZE_LEAKS
+  if (f->detect_leaks) {
+    Report("%s: detect_leaks is not supported on this platform.\n",
+           SanitizerToolName);
+    f->detect_leaks = false;
+  }
+#endif
+
+  if (f->detect_leaks && !f->use_stack_depot) {
+    Report("%s: detect_leaks is ignored (requires use_stack_depot).\n",
+           SanitizerToolName);
+    f->detect_leaks = false;
+  }
 }
 
 // -------------------------- Globals --------------------- {{{1
@@ -448,6 +465,10 @@
     Atexit(asan_atexit);
   }
 
+  if (flags()->detect_leaks) {
+    Atexit(__lsan::DoLeakCheck);
+  }
+
   // interceptors
   InitializeAsanInterceptors();
 
@@ -527,6 +548,8 @@
   main_thread->ThreadStart(internal_getpid());
   force_interface_symbols();  // no-op.
 
+  __lsan::InitCommonLsan();
+
   InitializeAllocator();
 
   if (flags()->verbosity) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D831.2.patch
Type: text/x-patch
Size: 2309 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130521/380fa77c/attachment.bin>


More information about the llvm-commits mailing list