[compiler-rt] r210322 - [asan] Make ReplaceSystemMalloc optional on Android.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Fri Jun 6 03:57:21 PDT 2014


Author: eugenis
Date: Fri Jun  6 05:57:21 2014
New Revision: 210322

URL: http://llvm.org/viewvc/llvm-project?rev=210322&view=rev
Log:
[asan] Make ReplaceSystemMalloc optional on Android.

Don't fail if __libc_malloc_dispatch is missing; continue running
with normal linux interceptors instead.

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

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=210322&r1=210321&r2=210322&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Fri Jun  6 05:57:21 2014
@@ -98,6 +98,8 @@ void AppendToErrorMessageBuffer(const ch
 
 void ParseExtraActivationFlags();
 
+void *AsanDlSymNext(const char *sym);
+
 // Platform-specific options.
 #if SANITIZER_MAC
 bool PlatformHasDifferentMemcpyAndMemmove();

Modified: compiler-rt/trunk/lib/asan/asan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_linux.cc?rev=210322&r1=210321&r2=210322&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_linux.cc Fri Jun  6 05:57:21 2014
@@ -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, upt
 }
 #endif
 
+void *AsanDlSymNext(const char *sym) {
+  return dlsym(RTLD_NEXT, sym);
+}
+
 }  // namespace __asan
 
 #endif  // SANITIZER_FREEBSD || SANITIZER_LINUX

Modified: compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_linux.cc?rev=210322&r1=210321&r2=210322&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_linux.cc Fri Jun  6 05:57:21 2014
@@ -42,21 +42,23 @@ const MallocDebug asan_malloc_dispatch A
   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





More information about the llvm-commits mailing list