[llvm-commits] [compiler-rt] r145821 - in /compiler-rt/trunk/lib/asan: asan_interceptors.h asan_rtl.cc

Kostya Serebryany kcc at google.com
Mon Dec 5 09:56:33 PST 2011


Author: kcc
Date: Mon Dec  5 11:56:32 2011
New Revision: 145821

URL: http://llvm.org/viewvc/llvm-project?rev=145821&view=rev
Log:
[asan] don't require __cxa_throw to be present in the process. This is the last dependency on libstdc++

Modified:
    compiler-rt/trunk/lib/asan/asan_interceptors.h
    compiler-rt/trunk/lib/asan/asan_rtl.cc

Modified: compiler-rt/trunk/lib/asan/asan_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.h?rev=145821&r1=145820&r2=145821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.h (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.h Mon Dec  5 11:56:32 2011
@@ -37,18 +37,33 @@
 #include "mach_override/mach_override.h"
 #define WRAP(x) wrap_##x
 #define WRAPPER_NAME(x) "wrap_"#x
+
 #define OVERRIDE_FUNCTION(oldfunc, newfunc)                             \
   CHECK(0 == mach_override_ptr((void*)(oldfunc),                        \
                                (void*)(newfunc),                        \
                                (void**)&real_##oldfunc));               \
   CHECK(real_##oldfunc != NULL);
+
+#define OVERRIDE_FUNCTION_IF_EXISTS(oldfunc, newfunc)                   \
+  do { mach_override_ptr((void*)(oldfunc),                              \
+                         (void*)(newfunc),                              \
+                         (void**)&real_##oldfunc); } while (0)
+
 #define INTERCEPT_FUNCTION(func)                                        \
   OVERRIDE_FUNCTION(func, WRAP(func))
-#else
+
+#define INTERCEPT_FUNCTION_IF_EXISTS(func)                              \
+  OVERRIDE_FUNCTION_IF_EXISTS(func, WRAP(func))
+
+#else  // __linux__
 #define WRAP(x) x
 #define WRAPPER_NAME(x) #x
+
 #define INTERCEPT_FUNCTION(func)                                        \
   CHECK((real_##func = (func##_f)dlsym(RTLD_NEXT, #func)));
+
+#define INTERCEPT_FUNCTION_IF_EXISTS(func)                              \
+  do { real_##func = (func##_f)dlsym(RTLD_NEXT, #func); } while (0)
 #endif
 
 #ifdef __APPLE__

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=145821&r1=145820&r2=145821&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon Dec  5 11:56:32 2011
@@ -507,6 +507,7 @@
 
 #if ASAN_HAS_EXCEPTIONS
 extern "C" void WRAP(__cxa_throw)(void *a, void *b, void *c) {
+  CHECK(&real___cxa_throw);
   UnpoisonStackFromHereToTop();
   real___cxa_throw(a, b, c);
 }
@@ -690,7 +691,7 @@
   INTERCEPT_FUNCTION(signal);
   INTERCEPT_FUNCTION(longjmp);
   INTERCEPT_FUNCTION(_longjmp);
-  INTERCEPT_FUNCTION(__cxa_throw);
+  INTERCEPT_FUNCTION_IF_EXISTS(__cxa_throw);
   INTERCEPT_FUNCTION(pthread_create);
 #ifdef __APPLE__
   INTERCEPT_FUNCTION(dispatch_async_f);





More information about the llvm-commits mailing list