Bug 758010 - Wrap operator new/delete on Android. r=khuey
authorMike Hommey <mh+mozilla@glandium.org>
Sat, 26 May 2012 10:21:33 +0200
changeset 95072 ef0180b53eae5695f05a8a8542d4dbcd4629ada3
parent 95071 93018b4bf4da0594bf368748b21ce1ea1446f4df
child 95084 823f773dd7ebf51c6da4405b32a2679ac981f7c0
push id22778
push usermh@glandium.org
push dateMon, 28 May 2012 06:19:10 +0000
treeherdermozilla-central@ef0180b53eae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs758010
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 758010 - Wrap operator new/delete on Android. r=khuey
configure.in
js/src/configure.in
memory/build/extraMallocFuncs.c
--- a/configure.in
+++ b/configure.in
@@ -7290,16 +7290,20 @@ MOZ_ARG_ENABLE_BOOL(wrap-malloc,
     _WRAP_MALLOC= )
 
 if test -n "$_WRAP_MALLOC"; then
     if test -n "$GNU_CC"; then
         WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=malloc,--wrap=calloc,--wrap=valloc,--wrap=free,--wrap=realloc,--wrap=memalign"
         WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=__builtin_new,--wrap=__builtin_vec_new,--wrap=__builtin_delete,--wrap=__builtin_vec_delete"
         WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=strdup,--wrap=strndup"
         WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=posix_memalign,--wrap=malloc_usable_size"
+        dnl Wrap operator new and operator delete on Android.
+        if test "$OS_TARGET" = "Android"; then
+            WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=_Znwj,--wrap=_Znaj,--wrap=_ZdlPv,--wrap=_ZdaPv"
+        fi
     else
         AC_MSG_ERROR([--enable-wrap-malloc is not supported for non-GNU toolchains])
     fi
 fi
 
 dnl ========================================================
 dnl = Location of malloc wrapper lib
 dnl ========================================================
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -4053,16 +4053,20 @@ MOZ_ARG_ENABLE_BOOL(wrap-malloc,
     _WRAP_MALLOC= )
 
 if test -n "$_WRAP_MALLOC"; then
     if test "$GNU_CC"; then
         WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=malloc,--wrap=calloc,--wrap=valloc,--wrap=free,--wrap=realloc,--wrap=memalign"
         WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=__builtin_new,--wrap=__builtin_vec_new,--wrap=__builtin_delete,--wrap=__builtin_vec_delete"
         WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=strdup,--wrap=strndup"
         WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=posix_memalign,--wrap=malloc_usable_size"
+        dnl Wrap operator new and operator delete on Android.
+        if test "$OS_TARGET" = "Android"; then
+            WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=_Znwj,--wrap=_Znaj,--wrap=_ZdlPv,--wrap=_ZdaPv"
+        fi
     else
         AC_MSG_ERROR([--enable-wrap-malloc is not supported for non-GNU toolchains])
     fi
 fi
 
 dnl ========================================================
 dnl = Location of malloc wrapper lib
 dnl ========================================================
--- a/memory/build/extraMallocFuncs.c
+++ b/memory/build/extraMallocFuncs.c
@@ -2,16 +2,42 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <string.h>
 #include "mozilla/Types.h"
 
 #ifdef ANDROID
 #define wrap(a) __wrap_ ## a
+
+/* operator new wrapper implementation */
+static void *
+new(unsigned int size)
+{
+  return malloc(size);
+}
+/* operator new(unsigned int) */
+MOZ_EXPORT_API(void *)
+wrap(_Znwj)(unsigned int) __attribute__((alias("new")));
+/* operator new[](unsigned int) */
+MOZ_EXPORT_API(void *)
+wrap(_Znaj)(unsigned int) __attribute__((alias("new")));
+
+/* operator delete wrapper implementation */
+static void
+delete(void *ptr)
+{
+  free(ptr);
+}
+/* operator delete(void*) */
+MOZ_EXPORT_API(void)
+wrap(_ZdlPv)(void *ptr) __attribute__((alias("delete")));
+/* operator delete[](void*) */
+MOZ_EXPORT_API(void)
+wrap(_ZdaPv)(void *ptr) __attribute__((alias("delete")));
 #endif
 
 #if defined(XP_WIN) || defined(XP_MACOSX)
 #define wrap(a) je_ ## a
 #endif
 
 #ifdef wrap
 void *wrap(malloc)(size_t);