[asan] Move AsanCheckDynamicRTPrereqs check under flag
authorMaxim Ostapenko <chefmax7@gmail.com>
Fri, 31 Mar 2017 06:36:37 +0000 (06:36 +0000)
committerMaxim Ostapenko <chefmax7@gmail.com>
Fri, 31 Mar 2017 06:36:37 +0000 (06:36 +0000)
The patch addresses https://github.com/google/sanitizers/issues/786. Currently AsanCheckDynamicRTPrereqs prevents
dynamic ASan runtime from running in some important environments e.g. cowbuilder and fakeroot that may also work with interposition.
Let's allow users to switch off the check given that they know what they do.

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

llvm-svn: 299188

compiler-rt/lib/asan/asan_flags.inc
compiler-rt/lib/asan/asan_linux.cc
compiler-rt/test/asan/TestCases/Linux/asan_dlopen_test.cc

index 65a1d17..f2216c2 100644 (file)
@@ -158,3 +158,6 @@ ASAN_FLAG(bool, allocator_frees_and_returns_null_on_realloc_zero, true,
           "realloc(p, 0) is equivalent to free(p) by default (Same as the "
           "POSIX standard). If set to false, realloc(p, 0) will return a "
           "pointer to an allocated space which can not be used.")
+ASAN_FLAG(bool, verify_asan_link_order, true,
+          "Check position of ASan runtime in library list (needs to be disabled"
+          " when other library has to be preloaded system-wide)")
index 6d150de..50ef84c 100644 (file)
@@ -111,7 +111,7 @@ static void ReportIncompatibleRT() {
 }
 
 void AsanCheckDynamicRTPrereqs() {
-  if (!ASAN_DYNAMIC)
+  if (!ASAN_DYNAMIC || !flags()->verify_asan_link_order)
     return;
 
   // Ensure that dynamic RT is the first DSO in the list
index f1e31b0..5081b77 100644 (file)
@@ -2,6 +2,8 @@
 //
 // RUN: %clangxx %s -DRT=\"%shared_libasan\" -o %t -ldl
 // RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=verify_asan_link_order=true not %run %t 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=verify_asan_link_order=false %run %t 2>&1
 // REQUIRES: asan-dynamic-runtime
 // XFAIL: android