[PATCH] D39991: [sanitizer] Add 'strip_env' flag to enable/disable removing sanitizer dylib from DYLD_INSERT_LIBRARIES

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 13:43:16 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT319365: [sanitizer] Add 'strip_env' flag to enable/disable removing sanitizer dylib… (authored by kuba.brecka).

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D39991

Files:
  lib/sanitizer_common/sanitizer_flags.inc
  lib/sanitizer_common/sanitizer_mac.cc
  test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cc


Index: lib/sanitizer_common/sanitizer_mac.cc
===================================================================
--- lib/sanitizer_common/sanitizer_mac.cc
+++ lib/sanitizer_common/sanitizer_mac.cc
@@ -741,6 +741,9 @@
   if (!lib_is_in_env)
     return;
 
+  if (!common_flags()->strip_env)
+    return;
+
   // DYLD_INSERT_LIBRARIES is set and contains the runtime library. Let's remove
   // the dylib from the environment variable, because interceptors are installed
   // and we don't want our children to inherit the variable.
Index: lib/sanitizer_common/sanitizer_flags.inc
===================================================================
--- lib/sanitizer_common/sanitizer_flags.inc
+++ lib/sanitizer_common/sanitizer_flags.inc
@@ -62,6 +62,9 @@
 COMMON_FLAG(
     int, verbosity, 0,
     "Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output).")
+COMMON_FLAG(bool, strip_env, 1,
+            "Whether to remove the sanitizer from DYLD_INSERT_LIBRARIES to "
+            "avoid passing it to children. Default is true.")
 COMMON_FLAG(bool, detect_leaks, !SANITIZER_MAC, "Enable memory leak detection.")
 COMMON_FLAG(
     bool, leak_check_at_exit, true,
Index: test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cc
===================================================================
--- test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cc
+++ test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cc
@@ -21,6 +21,11 @@
 // RUN:   %run ./a.out 2>&1 ) | FileCheck %s || exit 1
 
 // RUN: ( cd %t && \
+// RUN:   %env_asan_opts=strip_env=0 \
+// RUN:   DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
+// RUN:   %run ./a.out 2>&1 ) | FileCheck %s --check-prefix=CHECK-KEEP || exit 1
+
+// RUN: ( cd %t && \
 // RUN:   DYLD_INSERT_LIBRARIES=%t/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
 // RUN:   %run ./a.out 2>&1 ) | FileCheck %s || exit 1
 
@@ -32,6 +37,7 @@
   const char kEnvName[] = "DYLD_INSERT_LIBRARIES";
   printf("%s=%s\n", kEnvName, getenv(kEnvName));
   // CHECK: {{DYLD_INSERT_LIBRARIES=dummy-so.dylib}}
+  // CHECK-KEEP: {{DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib}}
   return 0;
 }
 #else  // SHARED_LIB


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39991.124809.patch
Type: text/x-patch
Size: 2219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171129/3ba6016c/attachment.bin>


More information about the llvm-commits mailing list