[compiler-rt] r186821 - [lsan] Make __lsan_do_leak_check() honor the detect_leaks flag.
Sergey Matveev
earthdok at google.com
Mon Jul 22 05:38:17 PDT 2013
Author: smatveev
Date: Mon Jul 22 07:38:17 2013
New Revision: 186821
URL: http://llvm.org/viewvc/llvm-project?rev=186821&view=rev
Log:
[lsan] Make __lsan_do_leak_check() honor the detect_leaks flag.
Also move detect_leaks to common flags.
Modified:
compiler-rt/trunk/lib/asan/asan_flags.h
compiler-rt/trunk/lib/asan/asan_rtl.cc
compiler-rt/trunk/lib/lsan/lsan.cc
compiler-rt/trunk/lib/lsan/lsan_common.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
Modified: compiler-rt/trunk/lib/asan/asan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_flags.h?rev=186821&r1=186820&r2=186821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_flags.h (original)
+++ compiler-rt/trunk/lib/asan/asan_flags.h Mon Jul 22 07:38:17 2013
@@ -106,8 +106,6 @@ struct Flags {
// 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;
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=186821&r1=186820&r2=186821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon Jul 22 07:38:17 2013
@@ -124,7 +124,6 @@ static void ParseFlagsFromString(Flags *
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) {
@@ -137,6 +136,7 @@ void InitializeFlags(Flags *f, const cha
cf->strip_path_prefix = "";
cf->handle_ioctl = false;
cf->log_path = 0;
+ cf->detect_leaks = false;
internal_memset(f, 0, sizeof(*f));
f->quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 26 : 1UL << 28;
@@ -173,7 +173,6 @@ void InitializeFlags(Flags *f, const cha
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());
@@ -189,17 +188,17 @@ void InitializeFlags(Flags *f, const cha
ParseFlagsFromString(f, env);
#if !CAN_SANITIZE_LEAKS
- if (f->detect_leaks) {
+ if (cf->detect_leaks) {
Report("%s: detect_leaks is not supported on this platform.\n",
SanitizerToolName);
- f->detect_leaks = false;
+ cf->detect_leaks = false;
}
#endif
- if (f->detect_leaks && !f->use_stack_depot) {
+ if (cf->detect_leaks && !f->use_stack_depot) {
Report("%s: detect_leaks is ignored (requires use_stack_depot).\n",
SanitizerToolName);
- f->detect_leaks = false;
+ cf->detect_leaks = false;
}
}
@@ -557,7 +556,7 @@ void __asan_init() {
#if CAN_SANITIZE_LEAKS
__lsan::InitCommonLsan();
- if (flags()->detect_leaks) {
+ if (common_flags()->detect_leaks) {
Atexit(__lsan::DoLeakCheck);
}
#endif // CAN_SANITIZE_LEAKS
Modified: compiler-rt/trunk/lib/lsan/lsan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan.cc?rev=186821&r1=186820&r2=186821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan.cc Mon Jul 22 07:38:17 2013
@@ -30,6 +30,7 @@ static void InitializeCommonFlags() {
cf->strip_path_prefix = "";
cf->fast_unwind_on_malloc = true;
cf->malloc_context_size = 30;
+ cf->detect_leaks = true;
ParseCommonFlagsFromString(GetEnv("LSAN_OPTIONS"));
}
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=186821&r1=186820&r2=186821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Mon Jul 22 07:38:17 2013
@@ -550,8 +550,9 @@ void __lsan_enable() {
SANITIZER_INTERFACE_ATTRIBUTE
void __lsan_do_leak_check() {
#if CAN_SANITIZE_LEAKS
- __lsan::DoLeakCheck();
-#endif
+ if (common_flags()->detect_leaks)
+ __lsan::DoLeakCheck();
+#endif // CAN_SANITIZE_LEAKS
}
#if !SANITIZER_SUPPORTS_WEAK_HOOKS
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc?rev=186821&r1=186820&r2=186821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Mon Jul 22 07:38:17 2013
@@ -29,6 +29,7 @@ void ParseCommonFlagsFromString(const ch
ParseFlag(str, &f->symbolize, "symbolize");
ParseFlag(str, &f->handle_ioctl, "handle_ioctl");
ParseFlag(str, &f->log_path, "log_path");
+ ParseFlag(str, &f->detect_leaks, "detect_leaks");
}
static bool GetFlagValue(const char *env, const char *name,
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h?rev=186821&r1=186820&r2=186821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h Mon Jul 22 07:38:17 2013
@@ -39,6 +39,8 @@ struct CommonFlags {
int malloc_context_size;
// Write logs to "log_path.pid" instead of stderr.
const char *log_path;
+ // Enable memory leak detection.
+ bool detect_leaks;
};
extern CommonFlags common_flags_dont_use_directly;
More information about the llvm-commits
mailing list