[asan] Make ReplaceSystemMalloc optional on Android.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 6 Jun 2014 10:57:21 +0000 (10:57 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 6 Jun 2014 10:57:21 +0000 (10:57 +0000)
Don't fail if __libc_malloc_dispatch is missing; continue running
with normal linux interceptors instead.

llvm-svn: 210322

compiler-rt/lib/asan/asan_internal.h
compiler-rt/lib/asan/asan_linux.cc
compiler-rt/lib/asan/asan_malloc_linux.cc

index 650a4d1..9d7d1d9 100644 (file)
@@ -98,6 +98,8 @@ void AppendToErrorMessageBuffer(const char *buffer);
 
 void ParseExtraActivationFlags();
 
+void *AsanDlSymNext(const char *sym);
+
 // Platform-specific options.
 #if SANITIZER_MAC
 bool PlatformHasDifferentMemcpyAndMemmove();
index 3dc8fe5..b3c45ee 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/mman.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
+#include <dlfcn.h>
 #include <fcntl.h>
 #include <pthread.h>
 #include <stdio.h>
@@ -42,7 +43,6 @@
 extern "C" void* _DYNAMIC;
 #else
 #include <sys/ucontext.h>
-#include <dlfcn.h>
 #include <link.h>
 #endif
 
@@ -243,6 +243,10 @@ void ReadContextStack(void *context, uptr *stack, uptr *ssize) {
 }
 #endif
 
+void *AsanDlSymNext(const char *sym) {
+  return dlsym(RTLD_NEXT, sym);
+}
+
 }  // namespace __asan
 
 #endif  // SANITIZER_FREEBSD || SANITIZER_LINUX
index 52fd4b1..4d60bfc 100644 (file)
@@ -42,21 +42,23 @@ const MallocDebug asan_malloc_dispatch ALIGNED(32) = {
   WRAP(malloc), WRAP(free), WRAP(calloc), WRAP(realloc), WRAP(memalign)
 };
 
-extern "C" const MallocDebug* __libc_malloc_dispatch;
-
 namespace __asan {
 void ReplaceSystemMalloc() {
-  __libc_malloc_dispatch = &asan_malloc_dispatch;
+  const MallocDebug** __libc_malloc_dispatch_p;
+  __libc_malloc_dispatch_p =
+      (const MallocDebug **)AsanDlSymNext("__libc_malloc_dispatch");
+  if (__libc_malloc_dispatch_p)
+    *__libc_malloc_dispatch_p = &asan_malloc_dispatch;
 }
 }  // namespace __asan
 
-#else  // ANDROID
+#else  // SANITIZER_ANDROID
 
 namespace __asan {
 void ReplaceSystemMalloc() {
 }
 }  // namespace __asan
-#endif  // ANDROID
+#endif  // SANITIZER_ANDROID
 
 // ---------------------- Replacement functions ---------------- {{{1
 using namespace __asan;  // NOLINT