|
From: <sv...@va...> - 2006-10-17 01:50:34
|
Author: sewardj
Date: 2006-10-17 02:50:31 +0100 (Tue, 17 Oct 2006)
New Revision: 6280
Log:
Merge r6146:
Generally tidy up, and add bindings for both gcc and xlc's C/C++
libraries on AIX.
Modified:
trunk/coregrind/m_replacemalloc/vg_replace_malloc.c
Modified: trunk/coregrind/m_replacemalloc/vg_replace_malloc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_replacemalloc/vg_replace_malloc.c 2006-10-17 01:49:=
50 UTC (rev 6279)
+++ trunk/coregrind/m_replacemalloc/vg_replace_malloc.c 2006-10-17 01:50:=
31 UTC (rev 6280)
@@ -50,14 +50,40 @@
// VALGRIND_NON_SIMD_CALL[12]
#include "pub_core_debuginfo.h" // needed for pub_core_redir.h :(
#include "pub_core_mallocfree.h" // for VG_MIN_MALLOC_SZB, VG_AR_CLIE=
NT
-#include "pub_core_redir.h" // for VG_REDIRECT_FUNCTION_*
+#include "pub_core_redir.h" // for VG_REPLACE_FUNCTION_*
#include "pub_core_replacemalloc.h"
=20
-/* Some handy Z-encoded names */
-#define m_libstc_plus_plus_star libstdcZpZpZa // libstdc++*
-#define m_libc_dot_so_star libcZdsoZa // libc.so*
-//#define m_libpgc_dot_so libpgcZdso // libpgc.so
+/* --------- Some handy Z-encoded names. --------- */
=20
+/* --- Soname of the standard C library. --- */
+
+#if defined(VGO_linux)
+# define m_libc_soname libcZdsoZa // libc.so*
+#elif defined(VGP_ppc32_aix5)
+ /* AIX has both /usr/lib/libc.a and /usr/lib/libc_r.a. */
+# define m_libc_soname libcZaZdaZLshrZdoZR // libc*.a(shr.o)
+#elif defined(VGP_ppc64_aix5)
+# define m_libc_soname libcZaZdaZLshrZu64ZdoZR // libc*.a(shr_64.o=
)
+#else
+# error "Unknown platform"
+#endif
+
+/* --- Soname of the GNU C++ library. --- */
+
+#define m_libstdcxx_soname libstdcZpZpZa // libstdc++*
+
+/* --- Soname of XLC's C++ library. --- */
+
+/* AIX: xlC's C++ runtime library is called libC.a, and the
+ interesting symbols appear to be in ansicore_32.o or ansicore_64.o
+ respectively. */
+#if defined(VGP_ppc32_aix5)
+# define m_libC_dot_a libCZdaZLansicoreZu32ZdoZR // libC.a(ansicore_=
32.o)
+#elif defined(VGP_ppc64_aix5)
+# define m_libC_dot_a libCZdaZLansicoreZu64ZdoZR // libC.a(ansicore_=
64.o)
+#endif
+
+
/* 2 Apr 05: the Portland Group compiler, which uses cfront/ARM style
mangling, could be supported properly by the redirects in this
module. Except we can't because it doesn't put its allocation
@@ -65,10 +91,38 @@
compilation unit holding main(), which makes them impossible to
intercept directly. Fortunately those fns seem to route everything
through to malloc/free.
+
+ mid-06: could be improved, since we can now intercept in the main
+ executable too.
*/
=20
extern void _exit(int);
=20
+/* Apparently it is necessary to make ourselves free of any dependency
+ on memcpy() on ppc32-aix5; else programs linked with -brtl fail.
+ memcpy() is used by gcc for a struct assignment in mallinfo()
+ below. Add the following conservative implementation (memmove,
+ really). */
+#if defined(VGO_aix5)
+__attribute__((weak))
+void *memcpy(void *destV, const void *srcV, unsigned long n)
+{
+ unsigned char* src =3D (unsigned char*)srcV;
+ unsigned char* dest =3D (unsigned char*)destV;
+ unsigned long i;
+ if (dest < src) {
+ for (i =3D 0; i < n; i++)
+ dest[i] =3D src[i];
+ }
+ if (dest > src) {
+ for (i =3D n; i > 0; i--)
+ dest[i-1] =3D src[i-1];
+ }
+ return dest;
+}
+#endif
+
+
/*------------------------------------------------------------*/
/*--- Replacing malloc() et al ---*/
/*------------------------------------------------------------*/
@@ -98,6 +152,9 @@
replacing.
*/
=20
+
+/*---------------------- malloc ----------------------*/
+
/* Generate a replacement for 'fnname' in object 'soname', which calls
'vg_replacement' to allocate memory. If that fails, return NULL.
*/
@@ -146,74 +203,103 @@
// (from_so, from_fn, v's replacement)
=20
// malloc
-ALLOC_or_NULL(m_libstc_plus_plus_star, malloc, malloc);
-ALLOC_or_NULL(m_libc_dot_so_star, malloc, malloc);
-//ALLOC_or_NULL(m_libpgc_dot_so, malloc, malloc);
+ALLOC_or_NULL(m_libstdcxx_soname, malloc, malloc);
+ALLOC_or_NULL(m_libc_soname, malloc, malloc);
=20
=20
+/*---------------------- new ----------------------*/
+
// operator new(unsigned int), not mangled (for gcc 2.96)
-ALLOC_or_BOMB(m_libstc_plus_plus_star, builtin_new, __builtin_new);
-ALLOC_or_BOMB(m_libc_dot_so_star, builtin_new, __builtin_new);
+ALLOC_or_BOMB(m_libcstdcxx_soname, builtin_new, __builtin_new);
+ALLOC_or_BOMB(m_libc_soname, builtin_new, __builtin_new);
=20
-ALLOC_or_BOMB(m_libstc_plus_plus_star, __builtin_new, __builtin_new);
-ALLOC_or_BOMB(m_libc_dot_so_star, __builtin_new, __builtin_new);
+ALLOC_or_BOMB(m_libcstdcxx_soname, __builtin_new, __builtin_new);
+ALLOC_or_BOMB(m_libc_soname, __builtin_new, __builtin_new);
=20
-// operator new(unsigned int), GNU mangling, 32-bit platforms
-// operator new(unsigned long), GNU mangling, 64-bit platforms
+// operator new(unsigned int), GNU mangling
#if VG_WORDSIZE =3D=3D 4
- ALLOC_or_BOMB(m_libstc_plus_plus_star, _Znwj, __builtin_new);
- ALLOC_or_BOMB(m_libc_dot_so_star, _Znwj, __builtin_new);
+ ALLOC_or_BOMB(m_libstdcxx_soname, _Znwj, __builtin_new);
+ ALLOC_or_BOMB(m_libc_soname, _Znwj, __builtin_new);
#endif
-#if VG_WORDSIZE =3D=3D 8
- ALLOC_or_BOMB(m_libstc_plus_plus_star, _Znwm, __builtin_new);
- ALLOC_or_BOMB(m_libc_dot_so_star, _Znwm, __builtin_new);
+
+// operator new(unsigned long), GNU mangling
+#if VG_WORDSIZE =3D=3D 8 || defined(VGP_ppc32_aix5)
+ ALLOC_or_BOMB(m_libstdcxx_soname, _Znwm, __builtin_new);
+ ALLOC_or_BOMB(m_libc_soname, _Znwm, __builtin_new);
#endif
=20
+// operator new(unsigned long), ARM/cfront mangling
+#if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
+ ALLOC_or_BOMB(m_libC_dot_a, __nw__FUl, __builtin_new);
+#endif
=20
-// operator new(unsigned int), ARM/cfront mangling
-//ALLOC_or_BOMB(m_libpgc_dot_so, __nw__FUi, __builtin_new);
=20
+/*---------------------- new nothrow ----------------------*/
=20
-// operator new(unsigned, std::nothrow_t const&), GNU mangling, 32-bit
-// operator new(unsigned long, std::nothrow_t const&), GNU mangling, 64-=
bit
+// operator new(unsigned, std::nothrow_t const&), GNU mangling
#if VG_WORDSIZE =3D=3D 4
- ALLOC_or_NULL(m_libstc_plus_plus_star, _ZnwjRKSt9nothrow_t, __builtin_=
new);
- ALLOC_or_NULL(m_libc_dot_so_star, _ZnwjRKSt9nothrow_t, __builtin_=
new);
+ ALLOC_or_NULL(m_libstdcxx_soname, _ZnwjRKSt9nothrow_t, __builtin_new);
+ ALLOC_or_NULL(m_libc_soname, _ZnwjRKSt9nothrow_t, __builtin_new);
#endif
-#if VG_WORDSIZE =3D=3D 8
- ALLOC_or_NULL(m_libstc_plus_plus_star, _ZnwmRKSt9nothrow_t, __builtin_=
new);
- ALLOC_or_NULL(m_libc_dot_so_star, _ZnwmRKSt9nothrow_t, __builtin_=
new);
+
+// operator new(unsigned long, std::nothrow_t const&), GNU mangling
+#if VG_WORDSIZE =3D=3D 8 || defined(VGP_ppc32_aix5) || defined(VGP_ppc64=
_aix5)
+ ALLOC_or_NULL(m_libstdcxx_soname, _ZnwmRKSt9nothrow_t, __builtin_new);
+ ALLOC_or_NULL(m_libc_soname, _ZnwmRKSt9nothrow_t, __builtin_new);
#endif
=20
+// operator new(unsigned long, std::nothrow_t const&), ARM/cfront mangli=
ng
+#if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
+ ALLOC_or_NULL(m_libC_dot_a, __nw__FUlRCQ2_3std9nothrow_t, __builtin_=
new);
+#endif
=20
+
+/*---------------------- new [] ----------------------*/
+
// operator new[](unsigned int), not mangled (for gcc 2.96)
-ALLOC_or_BOMB(m_libstc_plus_plus_star, __builtin_vec_new, __builtin_vec_=
new );
-ALLOC_or_BOMB(m_libc_dot_so_star, __builtin_vec_new, __builtin_vec_=
new );
+ALLOC_or_BOMB(m_libcstdcxx_soname, __builtin_vec_new, __builtin_vec_new =
);
+ALLOC_or_BOMB(m_libc_soname, __builtin_vec_new, __builtin_vec_new =
);
=20
-// operator new[](unsigned int), GNU mangling, 32-bit platforms
-// operator new[](unsigned long), GNU mangling, 64-bit platforms
+// operator new[](unsigned int), GNU mangling
#if VG_WORDSIZE =3D=3D 4
- ALLOC_or_BOMB(m_libstc_plus_plus_star, _Znaj, __builtin_vec=
_new );
- ALLOC_or_BOMB(m_libc_dot_so_star, _Znaj, __builtin_vec=
_new );
+ ALLOC_or_BOMB(m_libstdcxx_soname, _Znaj, __builtin_vec_new =
);
+ ALLOC_or_BOMB(m_libc_soname, _Znaj, __builtin_vec_new =
);
#endif
-#if VG_WORDSIZE =3D=3D 8
- ALLOC_or_BOMB(m_libstc_plus_plus_star, _Znam, __builtin_vec=
_new );
- ALLOC_or_BOMB(m_libc_dot_so_star, _Znam, __builtin_vec_=
new );
+
+// operator new[](unsigned long), GNU mangling
+#if VG_WORDSIZE =3D=3D 8 || defined(VGP_ppc32_aix5) || defined(VGP_ppc64=
_aix5)
+ ALLOC_or_BOMB(m_libstdcxx_soname, _Znam, __builtin_vec_new =
);
+ ALLOC_or_BOMB(m_libc_soname, _Znam, __builtin_vec_new =
);
#endif
=20
+// operator new[](unsigned long), ARM/cfront mangling
+#if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
+ ALLOC_or_BOMB(m_libC_dot_a, __vn__FUl, __builtin_vec_new)=
;
+#endif
=20
-// operator new[](unsigned, std::nothrow_t const&), GNU mangling, 32-bit
-// operator new[](unsigned long, std::nothrow_t const&), GNU mangling, 6=
4-bit
+
+/*---------------------- new [] nothrow ----------------------*/
+
+// operator new[](unsigned, std::nothrow_t const&), GNU mangling
#if VG_WORDSIZE =3D=3D 4
- ALLOC_or_NULL(m_libstc_plus_plus_star, _ZnajRKSt9nothrow_t, __builtin_v=
ec_new );
- ALLOC_or_NULL(m_libc_dot_so_star, _ZnajRKSt9nothrow_t, __builtin_v=
ec_new );
+ ALLOC_or_NULL(m_libstdcxx_soname, _ZnajRKSt9nothrow_t, __builtin_vec_ne=
w );
+ ALLOC_or_NULL(m_libc_soname, _ZnajRKSt9nothrow_t, __builtin_vec_ne=
w );
#endif
-#if VG_WORDSIZE =3D=3D 8
- ALLOC_or_NULL(m_libstc_plus_plus_star, _ZnamRKSt9nothrow_t, __builtin_v=
ec_new );
- ALLOC_or_NULL(m_libc_dot_so_star, _ZnamRKSt9nothrow_t, __builtin_v=
ec_new );
+
+// operator new[](unsigned long, std::nothrow_t const&), GNU mangling
+#if VG_WORDSIZE =3D=3D 8 || defined(VGP_ppc32_aix5) || defined(VGP_ppc64=
_aix5)
+ ALLOC_or_NULL(m_libstdcxx_soname, _ZnamRKSt9nothrow_t, __builtin_vec_ne=
w );
+ ALLOC_or_NULL(m_libc_soname, _ZnamRKSt9nothrow_t, __builtin_vec_ne=
w );
#endif
=20
+// operator new [](unsigned long, std::nothrow_t const&), ARM/cfront man=
gling
+#if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
+ ALLOC_or_BOMB(m_libC_dot_a, __vn__FUlRCQ2_3std9nothrow_t, __builtin_v=
ec_new );
+#endif
=20
+
+/*---------------------- free ----------------------*/
+
/* Generate a replacement for 'fnname' in object 'soname', which calls
'vg_replacement' to free previously allocated memory.
*/
@@ -230,38 +316,63 @@
}
=20
// free
-FREE(m_libstc_plus_plus_star, free, free );
-FREE(m_libc_dot_so_star, free, free );
+FREE(m_libstdcxx_soname, free, free );
+FREE(m_libc_soname, free, free );
=20
+
+/*---------------------- cfree ----------------------*/
+
// cfree
-FREE(m_libstc_plus_plus_star, cfree, free );
-FREE(m_libc_dot_so_star, cfree, free );
+FREE(m_libstdcxx_soname, cfree, free );
+FREE(m_libc_soname, cfree, free );
=20
+
+/*---------------------- delete ----------------------*/
// operator delete(void*), not mangled (for gcc 2.96)
-FREE(m_libstc_plus_plus_star, __builtin_delete, __builtin_delete );
-FREE(m_libc_dot_so_star, __builtin_delete, __builtin_delete );
+FREE(m_libcstdcxx_soname, __builtin_delete, __builtin_delete );
+FREE(m_libc_soname, __builtin_delete, __builtin_delete );
=20
// operator delete(void*), GNU mangling
-FREE(m_libstc_plus_plus_star, _ZdlPv, __builtin_delete );
-FREE(m_libc_dot_so_star, _ZdlPv, __builtin_delete );
+FREE(m_libstdcxx_soname, _ZdlPv, __builtin_delete );
+FREE(m_libc_soname, _ZdlPv, __builtin_delete );
=20
+// operator delete(void*), ARM/cfront mangling
+#if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
+FREE(m_libC_dot_a, __dl__FPv, __builtin_delete );
+#endif
+
+
+/*---------------------- delete nothrow ----------------------*/
+
// operator delete(void*, std::nothrow_t const&), GNU mangling
-FREE(m_libstc_plus_plus_star, _ZdlPvRKSt9nothrow_t, __builtin_delete );
-FREE(m_libc_dot_so_star, _ZdlPvRKSt9nothrow_t, __builtin_delete );
+FREE(m_libstdcxx_soname, _ZdlPvRKSt9nothrow_t, __builtin_delete );
+FREE(m_libc_soname, _ZdlPvRKSt9nothrow_t, __builtin_delete );
=20
+
+/*---------------------- delete [] ----------------------*/
// operator delete[](void*), not mangled (for gcc 2.96)
-FREE(m_libstc_plus_plus_star, __builtin_vec_delete, __builtin_vec_delet=
e );
-FREE(m_libc_dot_so_star, __builtin_vec_delete, __builtin_vec_delet=
e );
+FREE(m_libcstdcxx_soname, __builtin_vec_delete, __builtin_vec_delete );
+FREE(m_libc_soname, __builtin_vec_delete, __builtin_vec_delete );
=20
// operator delete[](void*), GNU mangling
-FREE(m_libstc_plus_plus_star, _ZdaPv, __builtin_vec_delet=
e );
-FREE(m_libc_dot_so_star, _ZdaPv, __builtin_vec_delet=
e );
+FREE(m_libstdcxx_soname, _ZdaPv, __builtin_vec_delete );
+FREE(m_libc_soname, _ZdaPv, __builtin_vec_delete );
=20
+// operator delete[](void*), ARM/cfront mangling
+#if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
+FREE(m_libC_dot_a, __vd__FPv, __builtin_vec_delete );
+#endif
+
+
+/*---------------------- delete [] nothrow ----------------------*/
+
// operator delete[](void*, std::nothrow_t const&), GNU mangling
-FREE(m_libstc_plus_plus_star, _ZdaPvRKSt9nothrow_t, __builtin_vec_delet=
e );
-FREE(m_libc_dot_so_star, _ZdaPvRKSt9nothrow_t, __builtin_vec_delet=
e );
+FREE(m_libstdcxx_soname, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
+FREE(m_libc_soname, _ZdaPvRKSt9nothrow_t, __builtin_vec_delete );
=20
=20
+/*---------------------- calloc ----------------------*/
+
#define CALLOC(soname, fnname) \
\
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT nmemb, SizeT size=
); \
@@ -277,9 +388,11 @@
return v; \
}
=20
-CALLOC(m_libc_dot_so_star, calloc);
+CALLOC(m_libc_soname, calloc);
=20
=20
+/*---------------------- realloc ----------------------*/
+
#define REALLOC(soname, fnname) \
\
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( void* ptrV, SizeT new_s=
ize );\
@@ -293,9 +406,9 @@
if (ptrV =3D=3D NULL) \
/* We need to call a malloc-like function; so let's use \
one which we know exists. */ \
- return VG_REPLACE_FUNCTION_ZU(libcZdsoZa,malloc) (new_size); \
+ return VG_REPLACE_FUNCTION_ZU(m_libc_soname,malloc) (new_size);=
\
if (new_size <=3D 0) { \
- VG_REPLACE_FUNCTION_ZU(libcZdsoZa,free)(ptrV); \
+ VG_REPLACE_FUNCTION_ZU(m_libc_soname,free)(ptrV); \
MALLOC_TRACE(" =3D 0"); \
return NULL; \
} \
@@ -304,9 +417,11 @@
return v; \
}
=20
-REALLOC(m_libc_dot_so_star, realloc);
+REALLOC(m_libc_soname, realloc);
=20
=20
+/*---------------------- memalign ----------------------*/
+
#define MEMALIGN(soname, fnname) \
\
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT alignment, SizeT =
n ); \
@@ -330,20 +445,24 @@
return v; \
}
=20
-MEMALIGN(m_libc_dot_so_star, memalign);
+MEMALIGN(m_libc_soname, memalign);
=20
=20
+/*---------------------- valloc ----------------------*/
+
#define VALLOC(soname, fnname) \
\
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT size ); \
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) ( SizeT size ) \
{ \
- return VG_REPLACE_FUNCTION_ZU(libcZdsoZa,memalign)(VKI_PAGE_SIZE, =
size); \
+ return VG_REPLACE_FUNCTION_ZU(m_libc_soname,memalign)(VKI_PAGE_SIZ=
E, size); \
}
=20
-VALLOC(m_libc_dot_so_star, valloc);
+VALLOC(m_libc_soname, valloc);
=20
=20
+/*---------------------- mallopt ----------------------*/
+
/* Various compatibility wrapper functions, for glibc and libstdc++. */
=20
#define MALLOPT(soname, fnname) \
@@ -356,9 +475,10 @@
return 1; \
}
=20
-MALLOPT(m_libc_dot_so_star, mallopt);
+MALLOPT(m_libc_soname, mallopt);
=20
=20
+/*---------------------- malloc_trim ----------------------*/
// Documentation says:
// malloc_trim(size_t pad);
//=20
@@ -391,9 +511,11 @@
return 0; \
}
=20
-MALLOC_TRIM(m_libc_dot_so_star, malloc_trim);
+MALLOC_TRIM(m_libc_soname, malloc_trim);
=20
=20
+/*---------------------- posix_memalign ----------------------*/
+
#define POSIX_MEMALIGN(soname, fnname) \
\
int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void **memptr, \
@@ -409,7 +531,7 @@
|| (alignment & (alignment - 1)) !=3D 0) \
return VKI_EINVAL; \
\
- mem =3D VG_REPLACE_FUNCTION_ZU(libcZdsoZa,memalign)(alignment, siz=
e); \
+ mem =3D VG_REPLACE_FUNCTION_ZU(m_libc_soname,memalign)(alignment, =
size); \
\
if (mem !=3D NULL) { \
*memptr =3D mem; \
@@ -419,9 +541,11 @@
return VKI_ENOMEM; \
}
=20
-POSIX_MEMALIGN(m_libc_dot_so_star, posix_memalign);
+POSIX_MEMALIGN(m_libc_soname, posix_memalign);
=20
=20
+/*---------------------- malloc_usable_size ----------------------*/
+
#define MALLOC_USABLE_SIZE(soname, fnname) \
\
int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void* p ); \
@@ -441,9 +565,11 @@
return pszB; \
}
=20
-MALLOC_USABLE_SIZE(m_libc_dot_so_star, malloc_usable_size);
+MALLOC_USABLE_SIZE(m_libc_soname, malloc_usable_size);
=20
=20
+/*---------------------- (unimplemented) ----------------------*/
+
/* Bomb out if we get any of these. */
=20
static void panic(const char *str)
@@ -461,11 +587,14 @@
panic(#fnname); \
}
=20
-PANIC(m_libc_dot_so_star, pvalloc);
-PANIC(m_libc_dot_so_star, malloc_stats);
-PANIC(m_libc_dot_so_star, malloc_get_state);
-PANIC(m_libc_dot_so_star, malloc_set_state);
+PANIC(m_libc_soname, pvalloc);
+PANIC(m_libc_soname, malloc_stats);
+PANIC(m_libc_soname, malloc_get_state);
+PANIC(m_libc_soname, malloc_set_state);
=20
+
+/*---------------------- mallinfo ----------------------*/
+
// mi must be static; if it is auto then Memcheck thinks it is
// uninitialised when used by the caller of this function, because Memch=
eck
// doesn't know that the call to mallinfo fills in mi.
@@ -481,7 +610,7 @@
return mi; \
}
=20
-MALLINFO(m_libc_dot_so_star, mallinfo);
+MALLINFO(m_libc_soname, mallinfo);
=20
=20
/* All the code in here is unused until this function is called */
|