[llvm-commits] [compiler-rt] r147303 - in /compiler-rt/trunk/lib/asan: asan_interceptors.h mach_override/README.txt mach_override/mach_override.c mach_override/mach_override.h

Kostya Serebryany kcc at google.com
Tue Dec 27 17:08:15 PST 2011


Author: kcc
Date: Tue Dec 27 19:08:14 2011
New Revision: 147303

URL: http://llvm.org/viewvc/llvm-project?rev=147303&view=rev
Log:
The code instrumented with ASan may have its own instance of the
mach_override library.
In this case chances are that functions from it will be called from
mach_override_ptr() during ASan initialization.
This may lead to crashes (if those functions are instrumented) or
incorrect behavior (if the implementations differ).

The attached patch renames mach_override_ptr() into
__asan_mach_override_ptr() and makes the rest of the mach_override
internals hidden.
The corresponding AddressSanitizer bug is
http://code.google.com/p/address-sanitizer/issues/detail?id=22

Patch by glider at google.com


Modified:
    compiler-rt/trunk/lib/asan/asan_interceptors.h
    compiler-rt/trunk/lib/asan/mach_override/README.txt
    compiler-rt/trunk/lib/asan/mach_override/mach_override.c
    compiler-rt/trunk/lib/asan/mach_override/mach_override.h

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=147303&r1=147302&r2=147303&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.h (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.h Tue Dec 27 19:08:14 2011
@@ -39,15 +39,15 @@
 #define WRAPPER_NAME(x) "wrap_"#x
 
 #define OVERRIDE_FUNCTION(oldfunc, newfunc)                             \
-  CHECK(0 == mach_override_ptr((void*)(oldfunc),                        \
-                               (void*)(newfunc),                        \
-                               (void**)&real_##oldfunc));               \
+  CHECK(0 == __asan_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)
+  do { __asan_mach_override_ptr((void*)(oldfunc),                              \
+                                (void*)(newfunc),                              \
+                                (void**)&real_##oldfunc); } while (0)
 
 #define INTERCEPT_FUNCTION(func)                                        \
   OVERRIDE_FUNCTION(func, WRAP(func))

Modified: compiler-rt/trunk/lib/asan/mach_override/README.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/mach_override/README.txt?rev=147303&r1=147302&r2=147303&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/mach_override/README.txt (original)
+++ compiler-rt/trunk/lib/asan/mach_override/README.txt Tue Dec 27 19:08:14 2011
@@ -4,4 +4,6 @@
 -- The files are guarded with #ifdef __APPLE__
 -- some opcodes are added in order to parse the library functions on Lion
 -- fixupInstructions() is extended to relocate relative calls, not only jumps
+-- mach_override_ptr is renamed to __asan_mach_override_ptr and
+ other functions are marked as hidden.
 

Modified: compiler-rt/trunk/lib/asan/mach_override/mach_override.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/mach_override/mach_override.c?rev=147303&r1=147302&r2=147303&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/mach_override/mach_override.c (original)
+++ compiler-rt/trunk/lib/asan/mach_override/mach_override.c Tue Dec 27 19:08:14 2011
@@ -108,18 +108,18 @@
 allocateBranchIsland(
 		BranchIsland	**island,
 		int				allocateHigh,
-		void *originalFunctionAddress);
+		void *originalFunctionAddress) __attribute__((visibility("hidden")));
 
 	mach_error_t
 freeBranchIsland(
-		BranchIsland	*island );
+		BranchIsland	*island ) __attribute__((visibility("hidden")));
 
 #if defined(__ppc__) || defined(__POWERPC__)
 	mach_error_t
 setBranchIslandTarget(
 		BranchIsland	*island,
 		const void		*branchTo,
-		long			instruction );
+		long			instruction ) __attribute__((visibility("hidden")));
 #endif 
 
 #if defined(__i386__) || defined(__x86_64__)
@@ -127,11 +127,11 @@
 setBranchIslandTarget_i386(
 						   BranchIsland	*island,
 						   const void		*branchTo,
-						   char*			instructions );
+						   char*			instructions ) __attribute__((visibility("hidden")));
 void 
 atomic_mov64(
 		uint64_t *targetAddress,
-		uint64_t value );
+		uint64_t value ) __attribute__((visibility("hidden")));
 
 	static Boolean 
 eatKnownInstructions( 
@@ -140,7 +140,7 @@
 	int				*howManyEaten, 
 	char			*originalInstructions,
 	int				*originalInstructionCount, 
-	uint8_t			*originalInstructionSizes );
+	uint8_t			*originalInstructionSizes ) __attribute__((visibility("hidden")));
 
 	static void
 fixupInstructions(
@@ -148,7 +148,7 @@
     void		*escapeIsland,
     void		*instructionsToFix,
 	int			instructionCount,
-	uint8_t		*instructionSizes );
+	uint8_t		*instructionSizes ) __attribute__((visibility("hidden")));
 #endif
 
 /*******************************************************************************
@@ -176,7 +176,7 @@
 #endif
 
     mach_error_t
-mach_override_ptr(
+__asan_mach_override_ptr(
 	void *originalFunctionAddress,
     const void *overrideFunctionAddress,
     void **originalFunctionReentryIsland )

Modified: compiler-rt/trunk/lib/asan/mach_override/mach_override.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/mach_override/mach_override.h?rev=147303&r1=147302&r2=147303&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/mach_override/mach_override.h (original)
+++ compiler-rt/trunk/lib/asan/mach_override/mach_override.h Tue Dec 27 19:08:14 2011
@@ -77,8 +77,10 @@
 
 	************************************************************************************/
 
+// We're prefixing mach_override_ptr() with "__asan_" to avoid name conflicts with other
+// mach_override_ptr() implementations that may appear in the client program.
     mach_error_t
-mach_override_ptr(
+__asan_mach_override_ptr(
 	void *originalFunctionAddress,
     const void *overrideFunctionAddress,
     void **originalFunctionReentryIsland );





More information about the llvm-commits mailing list