For intercepts in libc and the dynamic linker (ld.so or dyld), split
the Linux and Darwin definitions so they are in completely separate
ifdefs -- iow, remove any definitions that are common to both.  This
gives some duplication, but the upside is that it is now possible to
edit the Darwin intercepts without fear of breaking the Linux ones.
This will be important when it comes to supporting OSX 10.7.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12009 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c
index 38553ec..f75bc7c 100644
--- a/coregrind/m_replacemalloc/vg_replace_malloc.c
+++ b/coregrind/m_replacemalloc/vg_replace_malloc.c
@@ -70,7 +70,7 @@
 #include "pub_core_redir.h"         // for VG_REPLACE_FUNCTION_*
 #include "pub_core_replacemalloc.h"
 
-/* Assignment of behavioural equivalence class tags: 1NNN is intended
+/* Assignment of behavioural equivalence class tags: 1NNNP is intended
    to be reserved for the Valgrind core.  Current usage:
 
    10010 ALLOC_or_NULL
@@ -126,7 +126,8 @@
 }
 
 /* Same problem with getpagesize. */
-static inline int my_getpagesize ( void ) {
+static inline int my_getpagesize ( void )
+{
 #  if defined(VGPV_arm_linux_android)
    return 4096; /* kludge - link failure on Android, for some reason */
 #  else
@@ -257,81 +258,139 @@
 //     (from_so, from_fn,  v's replacement)
 
 // malloc
-ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, malloc,      malloc);
-ALLOC_or_NULL(VG_Z_LIBC_SONAME,      malloc,      malloc);
-#if defined(VGO_darwin)
-ZONEALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc_zone_malloc, malloc);
+#if defined(VGO_linux)
+ ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, malloc,      malloc);
+ ALLOC_or_NULL(VG_Z_LIBC_SONAME,      malloc,      malloc);
+
+#elif defined(VGO_darwin)
+ ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, malloc,      malloc);
+ ALLOC_or_NULL(VG_Z_LIBC_SONAME,      malloc,      malloc);
+ ZONEALLOC_or_NULL(VG_Z_LIBC_SONAME, malloc_zone_malloc, malloc);
+
 #endif
 
 
 /*---------------------- new ----------------------*/
 
-// operator new(unsigned int), not mangled (for gcc 2.96)
-ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME,  builtin_new,    __builtin_new);
-ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       builtin_new,    __builtin_new);
+#if defined(VGO_linux)
+ // operator new(unsigned int), not mangled (for gcc 2.96)
+ ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME,  builtin_new,    __builtin_new);
+ ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       builtin_new,    __builtin_new);
+ ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME,  __builtin_new,  __builtin_new);
+ ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       __builtin_new,  __builtin_new);
+ // operator new(unsigned int), GNU mangling
+ #if VG_WORDSIZE == 4
+  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj,          __builtin_new);
+  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znwj,          __builtin_new);
+ #endif
+ // operator new(unsigned long), GNU mangling
+ #if VG_WORDSIZE == 8
+  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm,          __builtin_new);
+  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znwm,          __builtin_new);
+ #endif
 
-ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME,  __builtin_new,  __builtin_new);
-ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       __builtin_new,  __builtin_new);
+#elif defined(VGO_darwin)
+ // operator new(unsigned int), GNU mangling
+ #if VG_WORDSIZE == 4
+  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj,          __builtin_new);
+  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znwj,          __builtin_new);
+ #endif
+ // operator new(unsigned long), GNU mangling
+ #if 1 // FIXME: is this right?
+  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm,          __builtin_new);
+  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znwm,          __builtin_new);
+ #endif
 
-// operator new(unsigned int), GNU mangling
-#if VG_WORDSIZE == 4
- ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwj,          __builtin_new);
- ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znwj,          __builtin_new);
-#endif
-
-// operator new(unsigned long), GNU mangling
-#if VG_WORDSIZE == 8 || defined(VGO_darwin)
- ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znwm,          __builtin_new);
- ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znwm,          __builtin_new);
 #endif
 
 
 /*---------------------- new nothrow ----------------------*/
 
-// operator new(unsigned, std::nothrow_t const&), GNU mangling
-#if VG_WORDSIZE == 4
- ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t,  __builtin_new);
- ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnwjRKSt9nothrow_t,  __builtin_new);
-#endif
+#if defined(VGO_linux)
+ // operator new(unsigned, std::nothrow_t const&), GNU mangling
+ #if VG_WORDSIZE == 4
+  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t,  __builtin_new);
+  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnwjRKSt9nothrow_t,  __builtin_new);
+ #endif
+ // operator new(unsigned long, std::nothrow_t const&), GNU mangling
+ #if VG_WORDSIZE == 8
+  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t,  __builtin_new);
+  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnwmRKSt9nothrow_t,  __builtin_new);
+ #endif
 
-// operator new(unsigned long, std::nothrow_t const&), GNU mangling
-#if VG_WORDSIZE == 8 || defined(VGO_darwin)
- ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t,  __builtin_new);
- ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnwmRKSt9nothrow_t,  __builtin_new);
+#elif defined(VGO_darwin)
+ // operator new(unsigned, std::nothrow_t const&), GNU mangling
+ #if VG_WORDSIZE == 4
+  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwjRKSt9nothrow_t,  __builtin_new);
+  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnwjRKSt9nothrow_t,  __builtin_new);
+ #endif
+ // operator new(unsigned long, std::nothrow_t const&), GNU mangling
+ #if 1 // FIXME: is this right?
+  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnwmRKSt9nothrow_t,  __builtin_new);
+  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnwmRKSt9nothrow_t,  __builtin_new);
+ #endif
+
 #endif
 
 
 /*---------------------- new [] ----------------------*/
 
-// operator new[](unsigned int), not mangled (for gcc 2.96)
-ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME,  __builtin_vec_new, __builtin_vec_new );
-ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       __builtin_vec_new, __builtin_vec_new );
+#if defined(VGO_linux)
+ // operator new[](unsigned int), not mangled (for gcc 2.96)
+ ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME,  __builtin_vec_new, __builtin_vec_new );
+ ALLOC_or_BOMB(VG_Z_LIBC_SONAME,       __builtin_vec_new, __builtin_vec_new );
+ // operator new[](unsigned int), GNU mangling
+ #if VG_WORDSIZE == 4
+  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj,             __builtin_vec_new );
+  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znaj,             __builtin_vec_new );
+ #endif
+ // operator new[](unsigned long), GNU mangling
+ #if VG_WORDSIZE == 8
+  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam,             __builtin_vec_new );
+  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znam,             __builtin_vec_new );
+ #endif
 
-// operator new[](unsigned int), GNU mangling
-#if VG_WORDSIZE == 4
- ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj,             __builtin_vec_new );
- ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znaj,             __builtin_vec_new );
-#endif
+#elif defined(VGO_darwin)
+ // operator new[](unsigned int), GNU mangling
+ #if VG_WORDSIZE == 4
+  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znaj,             __builtin_vec_new );
+  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znaj,             __builtin_vec_new );
+ #endif
+ // operator new[](unsigned long), GNU mangling
+ #if 1 // FIXME: is this right?
+  ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam,             __builtin_vec_new );
+  ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znam,             __builtin_vec_new );
+ #endif
 
-// operator new[](unsigned long), GNU mangling
-#if VG_WORDSIZE == 8 || defined(VGO_darwin)
- ALLOC_or_BOMB(VG_Z_LIBSTDCXX_SONAME, _Znam,             __builtin_vec_new );
- ALLOC_or_BOMB(VG_Z_LIBC_SONAME,      _Znam,             __builtin_vec_new );
 #endif
 
 
 /*---------------------- new [] nothrow ----------------------*/
 
-// operator new[](unsigned, std::nothrow_t const&), GNU mangling
-#if VG_WORDSIZE == 4
- ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
- ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnajRKSt9nothrow_t, __builtin_vec_new );
-#endif
+#if defined(VGO_linux)
+ // operator new[](unsigned, std::nothrow_t const&), GNU mangling
+ #if VG_WORDSIZE == 4
+  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
+  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnajRKSt9nothrow_t, __builtin_vec_new );
+ #endif
+ // operator new[](unsigned long, std::nothrow_t const&), GNU mangling
+ #if VG_WORDSIZE == 8
+  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
+  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnamRKSt9nothrow_t, __builtin_vec_new );
+ #endif
 
-// operator new[](unsigned long, std::nothrow_t const&), GNU mangling
-#if VG_WORDSIZE == 8 || defined(VGO_darwin)
- ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
- ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnamRKSt9nothrow_t, __builtin_vec_new );
+#elif defined(VGO_darwin)
+ // operator new[](unsigned, std::nothrow_t const&), GNU mangling
+ #if VG_WORDSIZE == 4
+  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnajRKSt9nothrow_t, __builtin_vec_new );
+  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnajRKSt9nothrow_t, __builtin_vec_new );
+ #endif
+ // operator new[](unsigned long, std::nothrow_t const&), GNU mangling
+ #if 1 // FIXME: is this right?
+  ALLOC_or_NULL(VG_Z_LIBSTDCXX_SONAME, _ZnamRKSt9nothrow_t, __builtin_vec_new );
+  ALLOC_or_NULL(VG_Z_LIBC_SONAME,      _ZnamRKSt9nothrow_t, __builtin_vec_new );
+ #endif
+
 #endif
 
 
@@ -365,52 +424,99 @@
    }
 
 // free
-FREE(VG_Z_LIBSTDCXX_SONAME,  free,                 free );
-FREE(VG_Z_LIBC_SONAME,       free,                 free );
-#if defined(VGO_darwin)
-ZONEFREE(VG_Z_LIBC_SONAME,   malloc_zone_free,     free );
+#if defined(VGO_linux)
+ FREE(VG_Z_LIBSTDCXX_SONAME,  free,                 free );
+ FREE(VG_Z_LIBC_SONAME,       free,                 free );
+
+#elif defined(VGO_darwin)
+ FREE(VG_Z_LIBSTDCXX_SONAME,  free,                 free );
+ FREE(VG_Z_LIBC_SONAME,       free,                 free );
+ ZONEFREE(VG_Z_LIBC_SONAME,   malloc_zone_free,     free );
+
 #endif
 
 
 /*---------------------- cfree ----------------------*/
 
 // cfree
-FREE(VG_Z_LIBSTDCXX_SONAME,  cfree,                free );
-FREE(VG_Z_LIBC_SONAME,       cfree,                free );
+#if defined(VGO_linux)
+ FREE(VG_Z_LIBSTDCXX_SONAME,  cfree,                free );
+ FREE(VG_Z_LIBC_SONAME,       cfree,                free );
+
+#elif defined(VGO_darwin)
+ FREE(VG_Z_LIBSTDCXX_SONAME,  cfree,                free );
+ FREE(VG_Z_LIBC_SONAME,       cfree,                free );
+
+#endif
 
 
 /*---------------------- delete ----------------------*/
-// operator delete(void*), not mangled (for gcc 2.96)
-FREE(VG_Z_LIBSTDCXX_SONAME,   __builtin_delete,     __builtin_delete );
-FREE(VG_Z_LIBC_SONAME,        __builtin_delete,     __builtin_delete );
 
-// operator delete(void*), GNU mangling
-FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdlPv,               __builtin_delete );
-FREE(VG_Z_LIBC_SONAME,       _ZdlPv,               __builtin_delete );
+#if defined(VGO_linux)
+ // operator delete(void*), not mangled (for gcc 2.96)
+ FREE(VG_Z_LIBSTDCXX_SONAME,   __builtin_delete,     __builtin_delete );
+ FREE(VG_Z_LIBC_SONAME,        __builtin_delete,     __builtin_delete );
+ // operator delete(void*), GNU mangling
+ FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdlPv,               __builtin_delete );
+ FREE(VG_Z_LIBC_SONAME,       _ZdlPv,               __builtin_delete );
+
+#elif defined(VGO_darwin)
+ // operator delete(void*), GNU mangling
+ FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdlPv,               __builtin_delete );
+ FREE(VG_Z_LIBC_SONAME,       _ZdlPv,               __builtin_delete );
+
+#endif
 
 
 /*---------------------- delete nothrow ----------------------*/
 
-// operator delete(void*, std::nothrow_t const&), GNU mangling
-FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t,  __builtin_delete );
-FREE(VG_Z_LIBC_SONAME,      _ZdlPvRKSt9nothrow_t,  __builtin_delete );
+#if defined(VGO_linux)
+ // operator delete(void*, std::nothrow_t const&), GNU mangling
+ FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t,  __builtin_delete );
+ FREE(VG_Z_LIBC_SONAME,      _ZdlPvRKSt9nothrow_t,  __builtin_delete );
+
+#elif defined(VGO_darwin)
+ // operator delete(void*, std::nothrow_t const&), GNU mangling
+ FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvRKSt9nothrow_t,  __builtin_delete );
+ FREE(VG_Z_LIBC_SONAME,      _ZdlPvRKSt9nothrow_t,  __builtin_delete );
+
+#endif
 
 
 /*---------------------- delete [] ----------------------*/
-// operator delete[](void*), not mangled (for gcc 2.96)
-FREE(VG_Z_LIBSTDCXX_SONAME,   __builtin_vec_delete, __builtin_vec_delete );
-FREE(VG_Z_LIBC_SONAME,        __builtin_vec_delete, __builtin_vec_delete );
 
-// operator delete[](void*), GNU mangling
-FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdaPv,               __builtin_vec_delete );
-FREE(VG_Z_LIBC_SONAME,       _ZdaPv,               __builtin_vec_delete );
+#if defined(VGO_linux)
+ // operator delete[](void*), not mangled (for gcc 2.96)
+ FREE(VG_Z_LIBSTDCXX_SONAME,   __builtin_vec_delete, __builtin_vec_delete );
+ FREE(VG_Z_LIBC_SONAME,        __builtin_vec_delete, __builtin_vec_delete );
+ // operator delete[](void*), GNU mangling
+ FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdaPv,               __builtin_vec_delete );
+ FREE(VG_Z_LIBC_SONAME,       _ZdaPv,               __builtin_vec_delete );
+
+#elif defined(VGO_darwin)
+ // operator delete[](void*), not mangled (for gcc 2.96)
+ FREE(VG_Z_LIBSTDCXX_SONAME,   __builtin_vec_delete, __builtin_vec_delete );
+ FREE(VG_Z_LIBC_SONAME,        __builtin_vec_delete, __builtin_vec_delete );
+ // operator delete[](void*), GNU mangling
+ FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdaPv,               __builtin_vec_delete );
+ FREE(VG_Z_LIBC_SONAME,       _ZdaPv,               __builtin_vec_delete );
+
+#endif
 
 
 /*---------------------- delete [] nothrow ----------------------*/
 
-// operator delete[](void*, std::nothrow_t const&), GNU mangling
-FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
-FREE(VG_Z_LIBC_SONAME,       _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
+#if defined(VGO_linux)
+ // operator delete[](void*, std::nothrow_t const&), GNU mangling
+ FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
+ FREE(VG_Z_LIBC_SONAME,       _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
+
+#elif defined(VGO_darwin)
+ // operator delete[](void*, std::nothrow_t const&), GNU mangling
+ FREE(VG_Z_LIBSTDCXX_SONAME,  _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
+ FREE(VG_Z_LIBC_SONAME,       _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
+
+#endif
 
 
 /*---------------------- calloc ----------------------*/
@@ -459,9 +565,13 @@
       return v; \
    }
 
-CALLOC(VG_Z_LIBC_SONAME, calloc);
-#if defined(VGO_darwin)
-ZONECALLOC(VG_Z_LIBC_SONAME, malloc_zone_calloc);
+#if defined(VGO_linux)
+ CALLOC(VG_Z_LIBC_SONAME, calloc);
+
+#elif defined(VGO_darwin)
+ CALLOC(VG_Z_LIBC_SONAME, calloc);
+ ZONECALLOC(VG_Z_LIBC_SONAME, malloc_zone_calloc);
+
 #endif
 
 
@@ -521,9 +631,13 @@
       return v; \
    }
 
-REALLOC(VG_Z_LIBC_SONAME, realloc);
-#if defined(VGO_darwin)
-ZONEREALLOC(VG_Z_LIBC_SONAME, malloc_zone_realloc);
+#if defined(VGO_linux)
+ REALLOC(VG_Z_LIBC_SONAME, realloc);
+
+#elif defined(VGO_darwin)
+ REALLOC(VG_Z_LIBC_SONAME, realloc);
+ ZONEREALLOC(VG_Z_LIBC_SONAME, malloc_zone_realloc);
+
 #endif
 
 
@@ -579,9 +693,13 @@
       return v; \
    }
 
-MEMALIGN(VG_Z_LIBC_SONAME, memalign);
-#if defined(VGO_darwin)
-ZONEMEMALIGN(VG_Z_LIBC_SONAME, malloc_zone_memalign);
+#if defined(VGO_linux)
+ MEMALIGN(VG_Z_LIBC_SONAME, memalign);
+
+#elif defined(VGO_darwin)
+ MEMALIGN(VG_Z_LIBC_SONAME, memalign);
+ ZONEMEMALIGN(VG_Z_LIBC_SONAME, malloc_zone_memalign);
+
 #endif
 
 
@@ -613,9 +731,13 @@
                 ((SizeT)pszB, size); \
    }
 
-VALLOC(VG_Z_LIBC_SONAME, valloc);
-#if defined(VGO_darwin)
-ZONEVALLOC(VG_Z_LIBC_SONAME, malloc_zone_valloc);
+#if defined(VGO_linux)
+ VALLOC(VG_Z_LIBC_SONAME, valloc);
+
+#elif defined(VGO_darwin)
+ VALLOC(VG_Z_LIBC_SONAME, valloc);
+ ZONEVALLOC(VG_Z_LIBC_SONAME, malloc_zone_valloc);
+
 #endif
 
 
@@ -633,7 +755,13 @@
       return 1; \
    }
 
-MALLOPT(VG_Z_LIBC_SONAME, mallopt);
+#if defined(VGO_linux)
+ MALLOPT(VG_Z_LIBC_SONAME, mallopt);
+
+#elif defined(VGO_darwin)
+ MALLOPT(VG_Z_LIBC_SONAME, mallopt);
+
+#endif
 
 
 /*---------------------- malloc_trim ----------------------*/
@@ -669,7 +797,13 @@
       return 0; \
    }
 
-MALLOC_TRIM(VG_Z_LIBC_SONAME, malloc_trim);
+#if defined(VGO_linux)
+ MALLOC_TRIM(VG_Z_LIBC_SONAME, malloc_trim);
+
+#elif defined(VGO_darwin)
+ MALLOC_TRIM(VG_Z_LIBC_SONAME, malloc_trim);
+
+#endif
 
 
 /*---------------------- posix_memalign ----------------------*/
@@ -700,7 +834,13 @@
       return VKI_ENOMEM; \
    }
 
-POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
+#if defined(VGO_linux)
+ POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
+
+#elif defined(VGO_darwin)
+ POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
+
+#endif
 
 
 /*---------------------- malloc_usable_size ----------------------*/
@@ -723,8 +863,15 @@
       return pszB; \
    }
 
-MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_usable_size);
-MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_size);
+#if defined(VGO_linux)
+ MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_usable_size);
+ MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_size);
+
+#elif defined(VGO_darwin)
+ MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_usable_size);
+ MALLOC_USABLE_SIZE(VG_Z_LIBC_SONAME, malloc_size);
+
+#endif
 
 
 /*---------------------- (unimplemented) ----------------------*/
@@ -746,9 +893,18 @@
       panic(#fnname); \
    }
 
-PANIC(VG_Z_LIBC_SONAME, pvalloc);
-PANIC(VG_Z_LIBC_SONAME, malloc_get_state);
-PANIC(VG_Z_LIBC_SONAME, malloc_set_state);
+#if defined(VGO_linux)
+ PANIC(VG_Z_LIBC_SONAME, pvalloc);
+ PANIC(VG_Z_LIBC_SONAME, malloc_get_state);
+ PANIC(VG_Z_LIBC_SONAME, malloc_set_state);
+
+#elif defined(VGO_darwin)
+ PANIC(VG_Z_LIBC_SONAME, pvalloc);
+ PANIC(VG_Z_LIBC_SONAME, malloc_get_state);
+ PANIC(VG_Z_LIBC_SONAME, malloc_set_state);
+
+#endif
+
 
 #define MALLOC_STATS(soname, fnname) \
    \
@@ -758,7 +914,13 @@
       /* Valgrind's malloc_stats implementation does nothing. */ \
    } 
 
-MALLOC_STATS(VG_Z_LIBC_SONAME, malloc_stats);
+#if defined(VGO_linux)
+ MALLOC_STATS(VG_Z_LIBC_SONAME, malloc_stats);
+
+#elif defined(VGO_darwin)
+ MALLOC_STATS(VG_Z_LIBC_SONAME, malloc_stats);
+
+#endif
 
 
 /*---------------------- mallinfo ----------------------*/
@@ -778,7 +940,13 @@
       return mi; \
    }
 
-MALLINFO(VG_Z_LIBC_SONAME, mallinfo);
+#if defined(VGO_linux)
+ MALLINFO(VG_Z_LIBC_SONAME, mallinfo);
+
+#elif defined(VGO_darwin)
+ MALLINFO(VG_Z_LIBC_SONAME, mallinfo);
+
+#endif
 
 
 #if defined(VGO_darwin)
@@ -812,10 +980,8 @@
       return &vg_default_zone; \
    }
 
-#if defined(VGO_darwin)
 DEFAULT_ZONE(VG_Z_LIBC_SONAME, malloc_zone_from_ptr);
 DEFAULT_ZONE(VG_Z_LIBC_SONAME, malloc_default_zone);
-#endif
 
 // GrP fixme bypass libc's use of zone->introspect->check
 #define ZONE_CHECK(soname, fnname) \
@@ -826,11 +992,9 @@
       return 1; \
    }
 
-#if defined(VGO_darwin)
 ZONE_CHECK(VG_Z_LIBC_SONAME, malloc_zone_check);    
-#endif
 
-#endif
+#endif /* defined(VGO_darwin) */
 
 
 /* All the code in here is unused until this function is called */
diff --git a/drd/drd_strmem_intercepts.c b/drd/drd_strmem_intercepts.c
index 70beee5..5d3e0d3 100644
--- a/drd/drd_strmem_intercepts.c
+++ b/drd/drd_strmem_intercepts.c
@@ -48,7 +48,11 @@
       return i;                                                         \
    }
 
-STRNLEN(VG_Z_LIBC_SONAME, strnlen)
+#if defined(VGO_linux)
+ STRNLEN(VG_Z_LIBC_SONAME, strnlen)
+#elif defined(VGO_darwin)
+ STRNLEN(VG_Z_LIBC_SONAME, strnlen)
+#endif
 
 
 // Note that this replacement often doesn't get used because gcc inlines
@@ -64,10 +68,12 @@
       return i;                                                         \
    }
 
-STRLEN(VG_Z_LIBC_SONAME,          strlen)
 #if defined(VGO_linux)
-STRLEN(VG_Z_LD_LINUX_SO_2,        strlen)
-STRLEN(VG_Z_LD_LINUX_X86_64_SO_2, strlen)
+ STRLEN(VG_Z_LIBC_SONAME,          strlen)
+ STRLEN(VG_Z_LD_LINUX_SO_2,        strlen)
+ STRLEN(VG_Z_LD_LINUX_X86_64_SO_2, strlen)
+#elif defined(VGO_darwin)
+ STRLEN(VG_Z_LIBC_SONAME,          strlen)
 #endif
 
 /*--------------------------------------------------------------------*/
diff --git a/helgrind/hg_intercepts.c b/helgrind/hg_intercepts.c
index 241df23..3267416 100644
--- a/helgrind/hg_intercepts.c
+++ b/helgrind/hg_intercepts.c
@@ -1,7 +1,7 @@
 
 /*--------------------------------------------------------------------*/
 /*--- pthread intercepts for thread checking.                      ---*/
-/*---                                              tc_intercepts.c ---*/
+/*---                                              hg_intercepts.c ---*/
 /*--------------------------------------------------------------------*/
 
 /*
@@ -2285,13 +2285,16 @@
    }
 
 // Apparently index() is the same thing as strchr()
-STRCHR(VG_Z_LIBC_SONAME,          strchr)
-STRCHR(VG_Z_LIBC_SONAME,          index)
 #if defined(VGO_linux)
-STRCHR(VG_Z_LD_LINUX_SO_2,        strchr)
-STRCHR(VG_Z_LD_LINUX_SO_2,        index)
-STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, strchr)
-STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, index)
+ STRCHR(VG_Z_LIBC_SONAME,          strchr)
+ STRCHR(VG_Z_LIBC_SONAME,          index)
+ STRCHR(VG_Z_LD_LINUX_SO_2,        strchr)
+ STRCHR(VG_Z_LD_LINUX_SO_2,        index)
+ STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, strchr)
+ STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, index)
+#elif defined(VGO_darwin)
+ STRCHR(VG_Z_LIBC_SONAME,          strchr)
+ STRCHR(VG_Z_LIBC_SONAME,          index)
 #endif
 
 
@@ -2308,10 +2311,12 @@
       return i; \
    }
 
-STRLEN(VG_Z_LIBC_SONAME,          strlen)
 #if defined(VGO_linux)
-STRLEN(VG_Z_LD_LINUX_SO_2,        strlen)
-STRLEN(VG_Z_LD_LINUX_X86_64_SO_2, strlen)
+ STRLEN(VG_Z_LIBC_SONAME,          strlen)
+ STRLEN(VG_Z_LD_LINUX_SO_2,        strlen)
+ STRLEN(VG_Z_LD_LINUX_X86_64_SO_2, strlen)
+#elif defined(VGO_darwin)
+ STRLEN(VG_Z_LIBC_SONAME,          strlen)
 #endif
 
 
@@ -2327,7 +2332,11 @@
       return (char*)dst_orig; \
    }
 
-STRCPY(VG_Z_LIBC_SONAME, strcpy)
+#if defined(VGO_linux)
+ STRCPY(VG_Z_LIBC_SONAME, strcpy)
+#elif defined(VGO_darwin)
+ STRCPY(VG_Z_LIBC_SONAME, strcpy)
+#endif
 
 
 #define STRCMP(soname, fnname) \
@@ -2350,10 +2359,12 @@
       return 0; \
    }
 
-STRCMP(VG_Z_LIBC_SONAME,          strcmp)
 #if defined(VGO_linux)
-STRCMP(VG_Z_LD_LINUX_X86_64_SO_2, strcmp)
-STRCMP(VG_Z_LD64_SO_1,            strcmp)
+ STRCMP(VG_Z_LIBC_SONAME,          strcmp)
+ STRCMP(VG_Z_LD_LINUX_X86_64_SO_2, strcmp)
+ STRCMP(VG_Z_LD64_SO_1,            strcmp)
+#elif defined(VGO_darwin)
+ STRCMP(VG_Z_LIBC_SONAME,          strcmp)
 #endif
 
 
@@ -2399,22 +2410,24 @@
       return dst; \
    }
 
-MEMCPY(VG_Z_LIBC_SONAME,    memcpy)
 #if defined(VGO_linux)
-MEMCPY(VG_Z_LD_SO_1,        memcpy) /* ld.so.1 */
-MEMCPY(VG_Z_LD64_SO_1,      memcpy) /* ld64.so.1 */
-#endif
-/* icc9 blats these around all over the place.  Not only in the main
-   executable but various .so's.  They are highly tuned and read
-   memory beyond the source boundary (although work correctly and
-   never go across page boundaries), so give errors when run natively,
-   at least for misaligned source arg.  Just intercepting in the exe
-   only until we understand more about the problem.  See
-   http://bugs.kde.org/show_bug.cgi?id=139776
+ MEMCPY(VG_Z_LIBC_SONAME,    memcpy)
+ MEMCPY(VG_Z_LD_SO_1,        memcpy) /* ld.so.1 */
+ MEMCPY(VG_Z_LD64_SO_1,      memcpy) /* ld64.so.1 */
+ /* icc9 blats these around all over the place.  Not only in the main
+    executable but various .so's.  They are highly tuned and read
+    memory beyond the source boundary (although work correctly and
+    never go across page boundaries), so give errors when run
+    natively, at least for misaligned source arg.  Just intercepting
+    in the exe only until we understand more about the problem.  See
+    http://bugs.kde.org/show_bug.cgi?id=139776
  */
-MEMCPY(NONE, _intel_fast_memcpy)
+ MEMCPY(NONE, _intel_fast_memcpy)
+#elif defined(VGO_darwin)
+ MEMCPY(VG_Z_LIBC_SONAME,    memcpy)
+#endif
 
 
 /*--------------------------------------------------------------------*/
-/*--- end                                          tc_intercepts.c ---*/
+/*--- end                                          hg_intercepts.c ---*/
 /*--------------------------------------------------------------------*/
diff --git a/memcheck/mc_replace_strmem.c b/memcheck/mc_replace_strmem.c
index 7e680f9..46e426d 100644
--- a/memcheck/mc_replace_strmem.c
+++ b/memcheck/mc_replace_strmem.c
@@ -154,6 +154,8 @@
                   s, src, dst, len, 0)
 
 
+/*---------------------- strrchr ----------------------*/
+
 #define STRRCHR(soname, fnname) \
    char* VG_REPLACE_FUNCTION_EZU(20010,soname,fnname)( const char* s, int c ); \
    char* VG_REPLACE_FUNCTION_EZU(20010,soname,fnname)( const char* s, int c ) \
@@ -169,17 +171,21 @@
    }
 
 // Apparently rindex() is the same thing as strrchr()
-STRRCHR(VG_Z_LIBC_SONAME,   strrchr)
-STRRCHR(VG_Z_LIBC_SONAME,   rindex)
 #if defined(VGO_linux)
-STRRCHR(VG_Z_LIBC_SONAME,   __GI_strrchr)
-STRRCHR(VG_Z_LD_LINUX_SO_2, rindex)
+ STRRCHR(VG_Z_LIBC_SONAME,   strrchr)
+ STRRCHR(VG_Z_LIBC_SONAME,   rindex)
+ STRRCHR(VG_Z_LIBC_SONAME,   __GI_strrchr)
+ STRRCHR(VG_Z_LD_LINUX_SO_2, rindex)
 #elif defined(VGO_darwin)
-STRRCHR(VG_Z_DYLD,          strrchr)
-STRRCHR(VG_Z_DYLD,          rindex)
+ STRRCHR(VG_Z_LIBC_SONAME,   strrchr)
+ STRRCHR(VG_Z_LIBC_SONAME,   rindex)
+ STRRCHR(VG_Z_DYLD,          strrchr)
+ STRRCHR(VG_Z_DYLD,          rindex)
 #endif
    
 
+/*---------------------- strchr ----------------------*/
+
 #define STRCHR(soname, fnname) \
    char* VG_REPLACE_FUNCTION_EZU(20020,soname,fnname) ( const char* s, int c ); \
    char* VG_REPLACE_FUNCTION_EZU(20020,soname,fnname) ( const char* s, int c ) \
@@ -194,22 +200,26 @@
    }
 
 // Apparently index() is the same thing as strchr()
-STRCHR(VG_Z_LIBC_SONAME,          strchr)
-STRCHR(VG_Z_LIBC_SONAME,          index)
 #if defined(VGO_linux)
-STRCHR(VG_Z_LIBC_SONAME,          __GI_strchr)
-#if !defined(VGP_x86_linux)
- STRCHR(VG_Z_LD_LINUX_SO_2,        strchr)
- STRCHR(VG_Z_LD_LINUX_SO_2,        index)
- STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, strchr)
- STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, index)
-#endif
+ STRCHR(VG_Z_LIBC_SONAME,          strchr)
+ STRCHR(VG_Z_LIBC_SONAME,          index)
+ STRCHR(VG_Z_LIBC_SONAME,          __GI_strchr)
+# if !defined(VGP_x86_linux)
+  STRCHR(VG_Z_LD_LINUX_SO_2,        strchr)
+  STRCHR(VG_Z_LD_LINUX_SO_2,        index)
+  STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, strchr)
+  STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, index)
+# endif
 #elif defined(VGO_darwin)
-STRCHR(VG_Z_DYLD,                 strchr)
-STRCHR(VG_Z_DYLD,                 index)
+ STRCHR(VG_Z_LIBC_SONAME,          strchr)
+ STRCHR(VG_Z_LIBC_SONAME,          index)
+ STRCHR(VG_Z_DYLD,                 strchr)
+ STRCHR(VG_Z_DYLD,                 index)
 #endif
 
 
+/*---------------------- strcat ----------------------*/
+
 #define STRCAT(soname, fnname) \
    char* VG_REPLACE_FUNCTION_EZU(20030,soname,fnname) \
             ( char* dst, const char* src ); \
@@ -233,11 +243,16 @@
       return dst_orig; \
    }
 
-STRCAT(VG_Z_LIBC_SONAME, strcat)
 #if defined(VGO_linux)
-STRCAT(VG_Z_LIBC_SONAME, __GI_strcat)
+ STRCAT(VG_Z_LIBC_SONAME, strcat)
+ STRCAT(VG_Z_LIBC_SONAME, __GI_strcat)
+#elif defined(VGO_darwin)
+ STRCAT(VG_Z_LIBC_SONAME, strcat)
 #endif
 
+
+/*---------------------- strncat ----------------------*/
+
 #define STRNCAT(soname, fnname) \
    char* VG_REPLACE_FUNCTION_EZU(20040,soname,fnname) \
             ( char* dst, const char* src, SizeT n ); \
@@ -263,12 +278,16 @@
       return dst_orig; \
    }
 
-STRNCAT(VG_Z_LIBC_SONAME, strncat)
-#if defined(VGO_darwin)
-STRNCAT(VG_Z_DYLD,        strncat)
+#if defined(VGO_linux)
+ STRNCAT(VG_Z_LIBC_SONAME, strncat)
+#elif defined(VGO_darwin)
+ STRNCAT(VG_Z_LIBC_SONAME, strncat)
+ STRNCAT(VG_Z_DYLD,        strncat)
 #endif
 
 
+/*---------------------- strlcat ----------------------*/
+
 /* Append src to dst. n is the size of dst's buffer. dst is guaranteed 
    to be nul-terminated after the copy, unless n <= strlen(dst_orig). 
    Returns min(n, strlen(dst_orig)) + strlen(src_orig). 
@@ -305,12 +324,15 @@
       return m; \
    }
 
-#if defined(VGO_darwin)
-STRLCAT(VG_Z_LIBC_SONAME, strlcat)
-STRLCAT(VG_Z_DYLD,        strlcat)
+#if defined(VGO_linux)
+#elif defined(VGO_darwin)
+ STRLCAT(VG_Z_LIBC_SONAME, strlcat)
+ STRLCAT(VG_Z_DYLD,        strlcat)
 #endif
 
 
+/*---------------------- strnlen ----------------------*/
+
 #define STRNLEN(soname, fnname) \
    SizeT VG_REPLACE_FUNCTION_EZU(20060,soname,fnname) \
             ( const char* str, SizeT n ); \
@@ -322,16 +344,21 @@
       return i; \
    }
 
-STRNLEN(VG_Z_LIBC_SONAME, strnlen)
 #if defined(VGO_linux)
-STRNLEN(VG_Z_LIBC_SONAME, __GI_strnlen)
+ STRNLEN(VG_Z_LIBC_SONAME, strnlen)
+ STRNLEN(VG_Z_LIBC_SONAME, __GI_strnlen)
+#elif defined(VGO_darwin)
+ STRNLEN(VG_Z_LIBC_SONAME, strnlen)
 #endif
    
 
+/*---------------------- strlen ----------------------*/
+
 // Note that this replacement often doesn't get used because gcc inlines
 // calls to strlen() with its own built-in version.  This can be very
-// confusing if you aren't expecting it.  Other small functions in this file
-// may also be inline by gcc.
+// confusing if you aren't expecting it.  Other small functions in
+// this file may also be inline by gcc.
+
 #define STRLEN(soname, fnname) \
    SizeT VG_REPLACE_FUNCTION_EZU(20070,soname,fnname) \
       ( const char* str ); \
@@ -343,12 +370,16 @@
       return i; \
    }
 
-STRLEN(VG_Z_LIBC_SONAME,          strlen)
 #if defined(VGO_linux)
-STRLEN(VG_Z_LIBC_SONAME,          __GI_strlen)
+ STRLEN(VG_Z_LIBC_SONAME,          strlen)
+ STRLEN(VG_Z_LIBC_SONAME,          __GI_strlen)
+#elif defined(VGO_darwin)
+ STRLEN(VG_Z_LIBC_SONAME,          strlen)
 #endif
 
 
+/*---------------------- strcpy ----------------------*/
+
 #define STRCPY(soname, fnname) \
    char* VG_REPLACE_FUNCTION_EZU(20080,soname,fnname) \
       ( char* dst, const char* src ); \
@@ -372,14 +403,17 @@
       return dst_orig; \
    }
 
-STRCPY(VG_Z_LIBC_SONAME, strcpy)
 #if defined(VGO_linux)
-STRCPY(VG_Z_LIBC_SONAME, __GI_strcpy)
+ STRCPY(VG_Z_LIBC_SONAME, strcpy)
+ STRCPY(VG_Z_LIBC_SONAME, __GI_strcpy)
 #elif defined(VGO_darwin)
-STRCPY(VG_Z_DYLD,        strcpy)
+ STRCPY(VG_Z_LIBC_SONAME, strcpy)
+ STRCPY(VG_Z_DYLD,        strcpy)
 #endif
 
 
+/*---------------------- strncpy ----------------------*/
+
 #define STRNCPY(soname, fnname) \
    char* VG_REPLACE_FUNCTION_EZU(20090,soname,fnname) \
             ( char* dst, const char* src, SizeT n ); \
@@ -396,18 +430,21 @@
       if (is_overlap(dst_orig, src_orig, n, (m < n) ? m+1 : n)) \
          RECORD_OVERLAP_ERROR("strncpy", dst, src, n); \
       while (m++ < n) *dst++ = 0;         /* must pad remainder with nulls */ \
- \
+      \
       return dst_orig; \
    }
 
-STRNCPY(VG_Z_LIBC_SONAME, strncpy)
 #if defined(VGO_linux)
-STRNCPY(VG_Z_LIBC_SONAME, __GI_strncpy)
+ STRNCPY(VG_Z_LIBC_SONAME, strncpy)
+ STRNCPY(VG_Z_LIBC_SONAME, __GI_strncpy)
 #elif defined(VGO_darwin)
-STRNCPY(VG_Z_DYLD,        strncpy)
+ STRNCPY(VG_Z_LIBC_SONAME, strncpy)
+ STRNCPY(VG_Z_DYLD,        strncpy)
 #endif
 
 
+/*---------------------- strlcpy ----------------------*/
+
 /* Copy up to n-1 bytes from src to dst. Then nul-terminate dst if n > 0. 
    Returns strlen(src). Does not zero-fill the remainder of dst. */
 #define STRLCPY(soname, fnname) \
@@ -433,12 +470,15 @@
       return src - src_orig; \
    }
 
-#if defined(VGO_darwin)
-STRLCPY(VG_Z_LIBC_SONAME, strlcpy)
-STRLCPY(VG_Z_DYLD,        strlcpy)
+#if defined(VGO_linux)
+#elif defined(VGO_darwin)
+ STRLCPY(VG_Z_LIBC_SONAME, strlcpy)
+ STRLCPY(VG_Z_DYLD,        strlcpy)
 #endif
 
 
+/*---------------------- strncmp ----------------------*/
+
 #define STRNCMP(soname, fnname) \
    int VG_REPLACE_FUNCTION_EZU(20110,soname,fnname) \
           ( const char* s1, const char* s2, SizeT nmax ); \
@@ -459,14 +499,17 @@
       } \
    }
 
-STRNCMP(VG_Z_LIBC_SONAME, strncmp)
 #if defined(VGO_linux)
-STRNCMP(VG_Z_LIBC_SONAME, __GI_strncmp)
+ STRNCMP(VG_Z_LIBC_SONAME, strncmp)
+ STRNCMP(VG_Z_LIBC_SONAME, __GI_strncmp)
 #elif defined(VGO_darwin)
-STRNCMP(VG_Z_DYLD,        strncmp)
+ STRNCMP(VG_Z_LIBC_SONAME, strncmp)
+ STRNCMP(VG_Z_DYLD,        strncmp)
 #endif
 
 
+/*---------------------- strcasecmp ----------------------*/
+
 #define STRCASECMP(soname, fnname) \
    int VG_REPLACE_FUNCTION_EZU(20120,soname,fnname) \
           ( const char* s1, const char* s2 ); \
@@ -488,14 +531,18 @@
       return 0; \
    }
 
-#if !defined(VGPV_arm_linux_android)
-STRCASECMP(VG_Z_LIBC_SONAME, strcasecmp)
-#endif
-#if defined(VGO_linux) && !defined(VGPV_arm_linux_android)
-STRCASECMP(VG_Z_LIBC_SONAME, __GI_strcasecmp)
+#if defined(VGO_linux)
+# if !defined(VGPV_arm_linux_android)
+  STRCASECMP(VG_Z_LIBC_SONAME, strcasecmp)
+  STRCASECMP(VG_Z_LIBC_SONAME, __GI_strcasecmp)
+# endif
+#elif defined(VGO_darwin)
+ STRCASECMP(VG_Z_LIBC_SONAME, strcasecmp)
 #endif
 
 
+/*---------------------- strncasecmp ----------------------*/
+
 #define STRNCASECMP(soname, fnname) \
    int VG_REPLACE_FUNCTION_EZU(20130,soname,fnname) \
           ( const char* s1, const char* s2, SizeT nmax ); \
@@ -519,23 +566,26 @@
       } \
    }
 
-#if !defined(VGPV_arm_linux_android)
-STRNCASECMP(VG_Z_LIBC_SONAME, strncasecmp)
-#endif
-#if defined(VGO_linux) && !defined(VGPV_arm_linux_android)
-STRNCASECMP(VG_Z_LIBC_SONAME, __GI_strncasecmp)
+#if defined(VGO_linux)
+# if !defined(VGPV_arm_linux_android)
+  STRNCASECMP(VG_Z_LIBC_SONAME, strncasecmp)
+  STRNCASECMP(VG_Z_LIBC_SONAME, __GI_strncasecmp)
+# endif
 #elif defined(VGO_darwin)
-STRNCASECMP(VG_Z_DYLD,        strncasecmp)
+ STRNCASECMP(VG_Z_LIBC_SONAME, strncasecmp)
+ STRNCASECMP(VG_Z_DYLD,        strncasecmp)
 #endif
 
 
+/*---------------------- strcasecmp_l ----------------------*/
+
 #define STRCASECMP_L(soname, fnname) \
    int VG_REPLACE_FUNCTION_EZU(20140,soname,fnname) \
           ( const char* s1, const char* s2, void* locale ); \
    int VG_REPLACE_FUNCTION_EZU(20140,soname,fnname) \
           ( const char* s1, const char* s2, void* locale ) \
    { \
-      extern int tolower_l(int, void*) __attribute__((weak));    \
+      extern int tolower_l(int, void*) __attribute__((weak)); \
       register unsigned char c1; \
       register unsigned char c2; \
       while (True) { \
@@ -550,13 +600,17 @@
       return 0; \
    }
 
-STRCASECMP_L(VG_Z_LIBC_SONAME, strcasecmp_l)
 #if defined(VGO_linux)
-STRCASECMP_L(VG_Z_LIBC_SONAME, __GI_strcasecmp_l)
-STRCASECMP_L(VG_Z_LIBC_SONAME, __GI___strcasecmp_l)
+ STRCASECMP_L(VG_Z_LIBC_SONAME, strcasecmp_l)
+ STRCASECMP_L(VG_Z_LIBC_SONAME, __GI_strcasecmp_l)
+ STRCASECMP_L(VG_Z_LIBC_SONAME, __GI___strcasecmp_l)
+#elif defined(VGO_darwin)
+ STRCASECMP_L(VG_Z_LIBC_SONAME, strcasecmp_l)
 #endif
 
 
+/*---------------------- strncasecmp_l ----------------------*/
+
 #define STRNCASECMP_L(soname, fnname) \
    int VG_REPLACE_FUNCTION_EZU(20150,soname,fnname) \
           ( const char* s1, const char* s2, SizeT nmax, void* locale ); \
@@ -580,14 +634,17 @@
       } \
    }
 
-STRNCASECMP_L(VG_Z_LIBC_SONAME, strncasecmp_l)
 #if defined(VGO_linux)
-STRNCASECMP_L(VG_Z_LIBC_SONAME, __GI_strncasecmp_l)
+ STRNCASECMP_L(VG_Z_LIBC_SONAME, strncasecmp_l)
+ STRNCASECMP_L(VG_Z_LIBC_SONAME, __GI_strncasecmp_l)
 #elif defined(VGO_darwin)
-STRNCASECMP_L(VG_Z_DYLD,        strncasecmp_l)
+ STRNCASECMP_L(VG_Z_LIBC_SONAME, strncasecmp_l)
+ STRNCASECMP_L(VG_Z_DYLD,        strncasecmp_l)
 #endif
 
 
+/*---------------------- strcmp ----------------------*/
+
 #define STRCMP(soname, fnname) \
    int VG_REPLACE_FUNCTION_EZU(20160,soname,fnname) \
           ( const char* s1, const char* s2 ); \
@@ -608,14 +665,18 @@
       return 0; \
    }
 
-STRCMP(VG_Z_LIBC_SONAME,          strcmp)
 #if defined(VGO_linux)
-STRCMP(VG_Z_LIBC_SONAME,          __GI_strcmp)
-STRCMP(VG_Z_LD_LINUX_X86_64_SO_2, strcmp)
-STRCMP(VG_Z_LD64_SO_1,            strcmp)
+ STRCMP(VG_Z_LIBC_SONAME,          strcmp)
+ STRCMP(VG_Z_LIBC_SONAME,          __GI_strcmp)
+ STRCMP(VG_Z_LD_LINUX_X86_64_SO_2, strcmp)
+ STRCMP(VG_Z_LD64_SO_1,            strcmp)
+#elif defined(VGO_darwin)
+ STRCMP(VG_Z_LIBC_SONAME,          strcmp)
 #endif
 
 
+/*---------------------- memchr ----------------------*/
+
 #define MEMCHR(soname, fnname) \
    void* VG_REPLACE_FUNCTION_EZU(20170,soname,fnname) \
             (const void *s, int c, SizeT n); \
@@ -630,12 +691,16 @@
       return NULL; \
    }
 
-MEMCHR(VG_Z_LIBC_SONAME, memchr)
-#if defined(VGO_darwin)
-MEMCHR(VG_Z_DYLD,        memchr)
+#if defined(VGO_linux)
+ MEMCHR(VG_Z_LIBC_SONAME, memchr)
+#elif defined(VGO_darwin)
+ MEMCHR(VG_Z_LIBC_SONAME, memchr)
+ MEMCHR(VG_Z_DYLD,        memchr)
 #endif
 
 
+/*---------------------- memcpy ----------------------*/
+
 #define MEMMOVE_OR_MEMCPY(becTag, soname, fnname, do_ol_check)  \
    void* VG_REPLACE_FUNCTION_EZZ(becTag,soname,fnname) \
             ( void *dst, const void *src, SizeT len ); \
@@ -716,28 +781,30 @@
    MEMMOVE_OR_MEMCPY(20180, soname, fnname, 1)
 
 #if defined(VGO_linux)
-/* For older memcpy we have to use memmove-like semantics and skip the
-   overlap check; sigh; see #275284. */
-MEMMOVE(VG_Z_LIBC_SONAME, memcpyZAGLIBCZu2Zd2Zd5) /* memcpy@GLIBC_2.2.5 */
-MEMCPY(VG_Z_LIBC_SONAME,  memcpyZAZAGLIBCZu2Zd14) /* memcpy@@GLIBC_2.14 */
-MEMCPY(VG_Z_LIBC_SONAME,  memcpy) /* fallback case */
-MEMCPY(VG_Z_LD_SO_1,      memcpy) /* ld.so.1 */
-MEMCPY(VG_Z_LD64_SO_1,    memcpy) /* ld64.so.1 */
+ /* For older memcpy we have to use memmove-like semantics and skip
+    the overlap check; sigh; see #275284. */
+ MEMMOVE(VG_Z_LIBC_SONAME, memcpyZAGLIBCZu2Zd2Zd5) /* memcpy@GLIBC_2.2.5 */
+ MEMCPY(VG_Z_LIBC_SONAME,  memcpyZAZAGLIBCZu2Zd14) /* memcpy@@GLIBC_2.14 */
+ MEMCPY(VG_Z_LIBC_SONAME,  memcpy) /* fallback case */
+ MEMCPY(VG_Z_LD_SO_1,      memcpy) /* ld.so.1 */
+ MEMCPY(VG_Z_LD64_SO_1,    memcpy) /* ld64.so.1 */
 #elif defined(VGO_darwin)
-MEMCPY(VG_Z_LIBC_SONAME,  memcpy)
-MEMCPY(VG_Z_DYLD,         memcpy)
-#endif
-/* icc9 blats these around all over the place.  Not only in the main
-   executable but various .so's.  They are highly tuned and read
-   memory beyond the source boundary (although work correctly and
-   never go across page boundaries), so give errors when run natively,
-   at least for misaligned source arg.  Just intercepting in the exe
-   only until we understand more about the problem.  See
-   http://bugs.kde.org/show_bug.cgi?id=139776
+ MEMCPY(VG_Z_LIBC_SONAME,  memcpy)
+ MEMCPY(VG_Z_DYLD,         memcpy)
+ /* icc9 blats these around all over the place.  Not only in the main
+    executable but various .so's.  They are highly tuned and read
+    memory beyond the source boundary (although work correctly and
+    never go across page boundaries), so give errors when run
+    natively, at least for misaligned source arg.  Just intercepting
+    in the exe only until we understand more about the problem.  See
+    http://bugs.kde.org/show_bug.cgi?id=139776
  */
-MEMCPY(NONE, ZuintelZufastZumemcpy)
+ MEMCPY(NONE, ZuintelZufastZumemcpy)
+#endif
 
 
+/*---------------------- memcmp ----------------------*/
+
 #define MEMCMP(soname, fnname) \
    int VG_REPLACE_FUNCTION_EZU(20190,soname,fnname)       \
           ( const void *s1V, const void *s2V, SizeT n ); \
@@ -763,16 +830,20 @@
       return 0; \
    }
 
-MEMCMP(VG_Z_LIBC_SONAME, memcmp)
-MEMCMP(VG_Z_LIBC_SONAME, bcmp)
 #if defined(VGO_linux)
-MEMCMP(VG_Z_LD_SO_1,     bcmp)
+ MEMCMP(VG_Z_LIBC_SONAME, memcmp)
+ MEMCMP(VG_Z_LIBC_SONAME, bcmp)
+ MEMCMP(VG_Z_LD_SO_1,     bcmp)
 #elif defined(VGO_darwin)
-MEMCMP(VG_Z_DYLD,        memcmp)
-MEMCMP(VG_Z_DYLD,        bcmp)
+ MEMCMP(VG_Z_LIBC_SONAME, memcmp)
+ MEMCMP(VG_Z_LIBC_SONAME, bcmp)
+ MEMCMP(VG_Z_DYLD,        memcmp)
+ MEMCMP(VG_Z_DYLD,        bcmp)
 #endif
 
 
+/*---------------------- stpcpy ----------------------*/
+
 /* Copy SRC to DEST, returning the address of the terminating '\0' in
    DEST. (minor variant of strcpy) */
 #define STPCPY(soname, fnname) \
@@ -798,16 +869,21 @@
       return dst; \
    }
 
-STPCPY(VG_Z_LIBC_SONAME,          stpcpy)
 #if defined(VGO_linux)
-STPCPY(VG_Z_LIBC_SONAME,          __GI_stpcpy)
-STPCPY(VG_Z_LD_LINUX_SO_2,        stpcpy)
-STPCPY(VG_Z_LD_LINUX_X86_64_SO_2, stpcpy)
+ STPCPY(VG_Z_LIBC_SONAME,          stpcpy)
+ STPCPY(VG_Z_LIBC_SONAME,          __GI_stpcpy)
+ STPCPY(VG_Z_LD_LINUX_SO_2,        stpcpy)
+ STPCPY(VG_Z_LD_LINUX_X86_64_SO_2, stpcpy)
 #elif defined(VGO_darwin)
-STPCPY(VG_Z_DYLD,                 stpcpy)
+ STPCPY(VG_Z_LIBC_SONAME,          stpcpy)
+ STPCPY(VG_Z_DYLD,                 stpcpy)
 #endif
 
 
+/*---------------------- memset ----------------------*/
+
+/* Why are we bothering to intercept this?  It seems entirely
+   pointless. */
 #define MEMSET(soname, fnname) \
    void* VG_REPLACE_FUNCTION_EZU(20210,soname,fnname) \
             (void *s, Int c, SizeT n); \
@@ -827,19 +903,27 @@
       return s; \
    }
 
-MEMSET(VG_Z_LIBC_SONAME, memset)
-#if defined(VGO_darwin)
-MEMSET(VG_Z_DYLD,        memset)
+#if defined(VGO_linux)
+ MEMSET(VG_Z_LIBC_SONAME, memset)
+#elif defined(VGO_darwin)
+ MEMSET(VG_Z_LIBC_SONAME, memset)
+ MEMSET(VG_Z_DYLD,        memset)
 #endif
 
 
+/*---------------------- memmove ----------------------*/
+
 /* memmove -- use the MEMMOVE defn above. */
-MEMMOVE(VG_Z_LIBC_SONAME, memmove)
-#if defined(VGO_darwin)
-MEMMOVE(VG_Z_DYLD,        memmove)
+#if defined(VGO_linux)
+ MEMMOVE(VG_Z_LIBC_SONAME, memmove)
+#elif defined(VGO_darwin)
+ MEMMOVE(VG_Z_LIBC_SONAME, memmove)
+ MEMMOVE(VG_Z_DYLD,        memmove)
 #endif
 
 
+/*---------------------- bcopy ----------------------*/
+
 #define BCOPY(soname, fnname) \
    void VG_REPLACE_FUNCTION_EZU(20230,soname,fnname) \
             (const void *srcV, void *dstV, SizeT n); \
@@ -860,12 +944,15 @@
       } \
    }
 
-#if defined(VGO_darwin)
-BCOPY(VG_Z_LIBC_SONAME, bcopy)
-BCOPY(VG_Z_DYLD,        bcopy)
+#if defined(VGO_linux)
+#elif defined(VGO_darwin)
+ BCOPY(VG_Z_LIBC_SONAME, bcopy)
+ BCOPY(VG_Z_DYLD,        bcopy)
 #endif
 
 
+/*-------------------- memmove_chk --------------------*/
+
 /* glibc 2.5 variant of memmove which checks the dest is big enough.
    There is no specific part of glibc that this is copied from. */
 #define GLIBC25___MEMMOVE_CHK(soname, fnname) \
@@ -898,9 +985,14 @@
      return NULL; \
    }
 
-GLIBC25___MEMMOVE_CHK(VG_Z_LIBC_SONAME, __memmove_chk)
+#if defined(VGO_linux)
+ GLIBC25___MEMMOVE_CHK(VG_Z_LIBC_SONAME, __memmove_chk)
+#elif defined(VGO_darwin)
+#endif
 
 
+/*-------------------- strchrnul --------------------*/
+
 /* Find the first occurrence of C in S or the final NUL byte.  */
 #define GLIBC232_STRCHRNUL(soname, fnname) \
    char* VG_REPLACE_FUNCTION_EZU(20250,soname,fnname) \
@@ -917,9 +1009,14 @@
       } \
    }
 
-GLIBC232_STRCHRNUL(VG_Z_LIBC_SONAME, strchrnul)
+#if defined(VGO_linux)
+ GLIBC232_STRCHRNUL(VG_Z_LIBC_SONAME, strchrnul)
+#elif defined(VGO_darwin)
+#endif
 
 
+/*---------------------- rawmemchr ----------------------*/
+
 /* Find the first occurrence of C in S.  */
 #define GLIBC232_RAWMEMCHR(soname, fnname) \
    char* VG_REPLACE_FUNCTION_EZU(20260,soname,fnname) \
@@ -935,11 +1032,15 @@
       } \
    }
 
-GLIBC232_RAWMEMCHR(VG_Z_LIBC_SONAME, rawmemchr)
 #if defined (VGO_linux)
-GLIBC232_RAWMEMCHR(VG_Z_LIBC_SONAME, __GI___rawmemchr)
+ GLIBC232_RAWMEMCHR(VG_Z_LIBC_SONAME, rawmemchr)
+ GLIBC232_RAWMEMCHR(VG_Z_LIBC_SONAME, __GI___rawmemchr)
+#elif defined(VGO_darwin)
 #endif
 
+
+/*---------------------- strcpy_chk ----------------------*/
+
 /* glibc variant of strcpy that checks the dest is big enough.
    Copied from glibc-2.5/debug/test-strcpy_chk.c. */
 #define GLIBC25___STRCPY_CHK(soname,fnname) \
@@ -964,9 +1065,14 @@
      return NULL; \
    }
 
-GLIBC25___STRCPY_CHK(VG_Z_LIBC_SONAME, __strcpy_chk)
+#if defined(VGO_linux)
+ GLIBC25___STRCPY_CHK(VG_Z_LIBC_SONAME, __strcpy_chk)
+#elif defined(VGO_darwin)
+#endif
 
 
+/*---------------------- stpcpy_chk ----------------------*/
+
 /* glibc variant of stpcpy that checks the dest is big enough.
    Copied from glibc-2.5/debug/test-stpcpy_chk.c. */
 #define GLIBC25___STPCPY_CHK(soname,fnname) \
@@ -990,9 +1096,14 @@
      return NULL; \
    }
 
-GLIBC25___STPCPY_CHK(VG_Z_LIBC_SONAME, __stpcpy_chk)
+#if defined(VGO_linux)
+ GLIBC25___STPCPY_CHK(VG_Z_LIBC_SONAME, __stpcpy_chk)
+#elif defined(VGO_darwin)
+#endif
 
 
+/*---------------------- mempcpy ----------------------*/
+
 /* mempcpy */
 #define GLIBC25_MEMPCPY(soname, fnname) \
    void* VG_REPLACE_FUNCTION_EZU(20290,soname,fnname) \
@@ -1026,12 +1137,16 @@
       return (void*)( ((char*)dst) + len_saved ); \
    }
 
-GLIBC25_MEMPCPY(VG_Z_LIBC_SONAME, mempcpy)
 #if defined(VGO_linux)
-GLIBC25_MEMPCPY(VG_Z_LD_SO_1,     mempcpy) /* ld.so.1 */
+ GLIBC25_MEMPCPY(VG_Z_LIBC_SONAME, mempcpy)
+ GLIBC25_MEMPCPY(VG_Z_LD_SO_1,     mempcpy) /* ld.so.1 */
+#elif defined(VGO_darwin)
+ GLIBC25_MEMPCPY(VG_Z_LIBC_SONAME, mempcpy)
 #endif
 
 
+/*-------------------- memcpy_chk --------------------*/
+
 #define GLIBC26___MEMCPY_CHK(soname, fnname) \
    void* VG_REPLACE_FUNCTION_EZU(20300,soname,fnname) \
             (void* dst, const void* src, SizeT len, SizeT dstlen ); \
@@ -1072,9 +1187,14 @@
      return NULL; \
    }
 
-GLIBC26___MEMCPY_CHK(VG_Z_LIBC_SONAME, __memcpy_chk)
+#if defined(VGO_linux)
+ GLIBC26___MEMCPY_CHK(VG_Z_LIBC_SONAME, __memcpy_chk)
+#elif defined(VGO_darwin)
+#endif
 
 
+/*---------------------- strstr ----------------------*/
+
 #define STRSTR(soname, fnname) \
    void* VG_REPLACE_FUNCTION_EZU(20310,soname,fnname) \
          (void* haystack, void* needle); \
@@ -1113,10 +1233,13 @@
    }
 
 #if defined(VGO_linux)
-STRSTR(VG_Z_LIBC_SONAME,          strstr)
+ STRSTR(VG_Z_LIBC_SONAME,          strstr)
+#elif defined(VGO_darwin)
 #endif
 
 
+/*---------------------- strpbrk ----------------------*/
+
 #define STRPBRK(soname, fnname) \
    void* VG_REPLACE_FUNCTION_EZU(20320,soname,fnname) \
          (void* sV, void* acceptV); \
@@ -1150,10 +1273,13 @@
    }
 
 #if defined(VGO_linux)
-STRPBRK(VG_Z_LIBC_SONAME,          strpbrk)
+ STRPBRK(VG_Z_LIBC_SONAME,          strpbrk)
+#elif defined(VGO_darwin)
 #endif
 
 
+/*---------------------- strcspn ----------------------*/
+
 #define STRCSPN(soname, fnname) \
    SizeT VG_REPLACE_FUNCTION_EZU(20330,soname,fnname) \
          (void* sV, void* rejectV); \
@@ -1188,10 +1314,13 @@
    }
 
 #if defined(VGO_linux)
-STRCSPN(VG_Z_LIBC_SONAME,          strcspn)
+ STRCSPN(VG_Z_LIBC_SONAME,          strcspn)
+#elif defined(VGO_darwin)
 #endif
 
 
+/*---------------------- strspn ----------------------*/
+
 #define STRSPN(soname, fnname) \
    SizeT VG_REPLACE_FUNCTION_EZU(20340,soname,fnname) \
          (void* sV, void* acceptV); \
@@ -1227,7 +1356,8 @@
    }
 
 #if defined(VGO_linux)
-STRSPN(VG_Z_LIBC_SONAME,          strspn)
+ STRSPN(VG_Z_LIBC_SONAME,          strspn)
+#elif defined(VGO_darwin)
 #endif
 
 
@@ -1241,7 +1371,8 @@
    versions of each function exist (as above), use the _EZU variants
    to assign equivalance class tags. */
 
-/* putenv */
+/*---------------------- putenv ----------------------*/
+
 int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, putenv) (char* string);
 int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, putenv) (char* string)
 {
@@ -1253,12 +1384,14 @@
        traces when hitting undefined memory. */
     if (p)
         while (*p++)
-            ;
+            __asm__ __volatile__("" ::: "memory");
     CALL_FN_W_W(result, fn, string);
     return result;
 }
 
-/* unsetenv */
+
+/*---------------------- unsetenv ----------------------*/
+
 int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, unsetenv) (const char* name);
 int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, unsetenv) (const char* name)
 {
@@ -1270,11 +1403,14 @@
        traces when hitting undefined memory. */
     if (p)
         while (*p++)
-            ;
+            __asm__ __volatile__("" ::: "memory");
     CALL_FN_W_W(result, fn, name);
     return result;
 }
 
+
+/*---------------------- setenv ----------------------*/
+
 /* setenv */
 int VG_WRAP_FUNCTION_ZU(VG_Z_LIBC_SONAME, setenv)
     (const char* name, const char* value, int overwrite);
@@ -1289,10 +1425,10 @@
        traces when hitting undefined memory. */
     if (name)
         for (p = name; *p; p++)
-            ;
+            __asm__ __volatile__("" ::: "memory");
     if (value)
         for (p = value; *p; p++)
-            ;
+            __asm__ __volatile__("" ::: "memory");
     VALGRIND_CHECK_VALUE_IS_DEFINED (overwrite);
     CALL_FN_W_WWW(result, fn, name, value, overwrite);
     return result;