ports/www/libxul/files/patch-bug788955
Florian Smeets 96b39667d3 Update to 17.0.6 (this should also fix the build on head after the
clang 3.3 merge)

PR:             ports/179034 [1]
Submitted by:   Jan Beich <jbeich@tormail.org>,
                Nikolai Lifanov <lifanov@mail.lifanov.com> [1]
2013-06-04 15:47:49 +00:00

299 lines
9 KiB
Text

diff --git Makefile.in Makefile.in
index e341462..f75bd55 100644
--- Makefile.in
+++ Makefile.in
@@ -48,8 +48,10 @@ endif
ifdef MOZ_MEMORY
tier_base_dirs += memory/mozjemalloc
ifdef MOZ_JEMALLOC
+ifndef MOZ_NATIVE_JEMALLOC
tier_base_dirs += memory/jemalloc
endif
+endif
tier_base_dirs += memory/build
endif
ifndef MOZ_NATIVE_ZLIB
diff --git allmakefiles.sh allmakefiles.sh
index 6a9be4b..d2e49e3 100755
--- allmakefiles.sh
+++ allmakefiles.sh
@@ -59,7 +59,7 @@ if [ ! "$LIBXUL_SDK" ]; then
mozglue/Makefile
mozglue/build/Makefile
"
- if [ "$MOZ_JEMALLOC" ]; then
+ if [ "$MOZ_JEMALLOC" -a -z "$MOZ_NATIVE_JEMALLOC" ]; then
add_makefiles "
memory/jemalloc/Makefile
"
diff --git configure.in configure.in
index bb05782..2f32516 100644
--- configure.in
+++ configure.in
@@ -3711,21 +3711,22 @@ fi
dnl Check for the existence of various allocation headers/functions
+MALLOC_HEADERS="malloc.h malloc_np.h malloc/malloc.h sys/malloc.h"
MALLOC_H=
-MOZ_CHECK_HEADER(malloc.h, [MALLOC_H=malloc.h])
-if test "$MALLOC_H" = ""; then
- MOZ_CHECK_HEADER(malloc/malloc.h, [MALLOC_H=malloc/malloc.h])
- if test "$MALLOC_H" = ""; then
- MOZ_CHECK_HEADER(sys/malloc.h, [MALLOC_H=sys/malloc.h])
+
+for file in $MALLOC_HEADERS; do
+ MOZ_CHECK_HEADER($file, [MALLOC_H=$file])
+ if test "$MALLOC_H" != ""; then
+ AC_DEFINE_UNQUOTED(MALLOC_H, <$MALLOC_H>)
+ break
fi
-fi
-if test "$MALLOC_H" != ""; then
- AC_DEFINE_UNQUOTED(MALLOC_H, <$MALLOC_H>)
-fi
+done
MOZ_ALLOCATING_FUNCS="strndup posix_memalign memalign valloc"
AC_CHECK_FUNCS(strndup posix_memalign memalign valloc)
+AC_CHECK_FUNCS(malloc_usable_size)
+
dnl See if compiler supports some gcc-style attributes
AC_CACHE_CHECK(for __attribute__((always_inline)),
@@ -6939,6 +6940,18 @@ else
fi
if test -z "$MOZ_MEMORY"; then
+ if test -n "$MOZ_JEMALLOC"; then
+ MOZ_NATIVE_JEMALLOC=1
+ AC_CHECK_FUNCS(mallctl nallocm,,
+ [MOZ_NATIVE_JEMALLOC=
+ break])
+ if test -n "$MOZ_NATIVE_JEMALLOC"; then
+ MOZ_MEMORY=1
+ AC_DEFINE(MOZ_MEMORY)
+ AC_DEFINE(MOZ_JEMALLOC)
+ AC_DEFINE(MOZ_NATIVE_JEMALLOC)
+ fi
+ fi
case "${target}" in
*-mingw*)
if test -z "$WIN32_REDIST_DIR" -a -z "$MOZ_DEBUG"; then
@@ -7033,6 +7046,7 @@ else
fi # MOZ_MEMORY
AC_SUBST(MOZ_MEMORY)
AC_SUBST(MOZ_JEMALLOC)
+AC_SUBST(MOZ_NATIVE_JEMALLOC)
AC_SUBST(MOZ_GLUE_LDFLAGS)
AC_SUBST(MOZ_GLUE_PROGRAM_LDFLAGS)
AC_SUBST(WIN32_CRT_LIBS)
@@ -8820,10 +8834,22 @@ fi
# Run jemalloc configure script
-if test "$MOZ_JEMALLOC" -a "$MOZ_MEMORY"; then
+if test -z "$MOZ_NATIVE_JEMALLOC" -a "$MOZ_JEMALLOC" -a "$MOZ_MEMORY" ; then
ac_configure_args="$_SUBDIR_CONFIG_ARGS --build=$build --host=$target --enable-stats --with-jemalloc-prefix=je_"
- if test "$OS_ARCH" = "Linux"; then
- MANGLE="malloc calloc valloc free realloc memalign posix_memalign malloc_usable_size"
+ case "$OS_ARCH" in
+ Linux|DragonFly|FreeBSD|NetBSD|OpenBSD)
+ MANGLE="malloc calloc valloc free realloc posix_memalign"
+ case "$OS_ARCH" in
+ Linux)
+ MANGLE="$MANGLE memalign malloc_usable_size"
+ ;;
+ FreeBSD)
+ MANGLE="$MANGLE malloc_usable_size"
+ ;;
+ esac
+ ;;
+ esac
+ if test -n "$MANGLE"; then
MANGLED=
JEMALLOC_WRAPPER=
if test -n "$_WRAP_MALLOC"; then
diff --git memory/build/Makefile.in memory/build/Makefile.in
index dca0f48..af93ee0 100644
--- memory/build/Makefile.in
+++ memory/build/Makefile.in
@@ -22,7 +22,9 @@ CSRCS = extraMallocFuncs.c
ifdef MOZ_JEMALLOC
CSRCS += mozjemalloc_compat.c
+ifndef MOZ_NATIVE_JEMALLOC
SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/jemalloc)
+endif
else
SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/mozjemalloc)
endif
diff --git memory/build/extraMallocFuncs.c memory/build/extraMallocFuncs.c
index 9d87629..03c8320 100644
--- memory/build/extraMallocFuncs.c
+++ memory/build/extraMallocFuncs.c
@@ -94,8 +94,16 @@ wrap(wcsdup)(const wchar_t *src)
#endif
#ifdef MOZ_JEMALLOC
+
+#undef wrap
+#if defined(MOZ_NATIVE_JEMALLOC)
+#define wrap(a) a
+#else
+#define wrap(a) je_ ## a
+#endif
+
/* Override some jemalloc defaults */
-const char *je_malloc_conf = "narenas:1,lg_chunk:20";
+MOZ_EXPORT_DATA(const char *) wrap(malloc_conf) = "narenas:1,lg_chunk:20";
#ifdef ANDROID
#include <android/log.h>
diff --git memory/build/mozjemalloc_compat.c memory/build/mozjemalloc_compat.c
index 10a845a..94ad96e 100644
--- memory/build/mozjemalloc_compat.c
+++ memory/build/mozjemalloc_compat.c
@@ -5,14 +5,21 @@
#include "mozilla/Types.h"
#include "jemalloc_types.h"
-extern int je_mallctl(const char*, void*, size_t*, void*, size_t);
+#if defined(MOZ_NATIVE_JEMALLOC)
+#define wrap(a) a
+#else
+#define wrap(a) je_ ## a
+#endif
-MOZ_EXPORT_API (void)
+extern MOZ_IMPORT_API(int)
+wrap(mallctl)(const char*, void*, size_t*, void*, size_t);
+
+MOZ_EXPORT_API(void)
jemalloc_stats(jemalloc_stats_t *stats)
{
size_t size = sizeof(stats->mapped);
- je_mallctl("stats.mapped", &stats->mapped, &size, NULL, 0);
- je_mallctl("stats.allocated", &stats->allocated, &size, NULL, 0);
+ wrap(mallctl)("stats.mapped", &stats->mapped, &size, NULL, 0);
+ wrap(mallctl)("stats.allocated", &stats->allocated, &size, NULL, 0);
stats->committed = -1;
stats->dirty = -1;
}
diff --git memory/jemalloc/src/src/mutex.c memory/jemalloc/src/src/mutex.c
index 37a843e..55e18c2 100644
--- memory/jemalloc/src/src/mutex.c
+++ memory/jemalloc/src/src/mutex.c
@@ -64,7 +64,7 @@ pthread_create(pthread_t *__restrict thread,
/******************************************************************************/
#ifdef JEMALLOC_MUTEX_INIT_CB
-int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
+JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
void *(calloc_cb)(size_t, size_t));
#endif
diff --git memory/mozalloc/mozalloc.cpp memory/mozalloc/mozalloc.cpp
index 5b61050b..5b3399a 100644
--- memory/mozalloc/mozalloc.cpp
+++ memory/mozalloc/mozalloc.cpp
@@ -12,16 +12,13 @@
#include <sys/types.h>
#if defined(MALLOC_H)
-# include MALLOC_H // for memalign, valloc where available
+# include MALLOC_H // for memalign, valloc, malloc_size, malloc_usable_size
#endif // if defined(MALLOC_H)
#include <stddef.h> // for size_t
#include <stdlib.h> // for malloc, free
#if defined(XP_UNIX)
# include <unistd.h> // for valloc on *BSD
#endif //if defined(XP_UNIX)
-#if defined(__FreeBSD__)
-# include <malloc_np.h> // for malloc_usable_size
-#endif // if defined(__FreeBSD__)
#if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec))
# define MOZALLOC_EXPORT __declspec(dllexport)
@@ -213,8 +210,7 @@ moz_malloc_usable_size(void *ptr)
#if defined(XP_MACOSX)
return malloc_size(ptr);
-#elif defined(MOZ_MEMORY) || (defined(XP_LINUX) && !defined(ANDROID)) || defined(__FreeBSD__)
- // Android bionic libc doesn't have malloc_usable_size.
+#elif defined(HAVE_MALLOC_USABLE_SIZE) || defined(MOZ_MEMORY)
return malloc_usable_size(ptr);
#elif defined(XP_WIN)
return _msize(ptr);
diff --git memory/mozjemalloc/jemalloc.h memory/mozjemalloc/jemalloc.h
index f0e0878..2486e83 100644
--- memory/mozjemalloc/jemalloc.h
+++ memory/mozjemalloc/jemalloc.h
@@ -37,22 +37,29 @@
#endif
#include "jemalloc_types.h"
+#if defined(MOZ_NATIVE_JEMALLOC)
+#define wrap(a) a
+#else
+#define wrap(a) je_ ## a
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
-#if defined(MOZ_MEMORY_LINUX)
+#if defined(MOZ_NATIVE_JEMALLOC) \
+ || defined(MOZ_MEMORY_LINUX) || defined(MOZ_MEMORY_BSD)
__attribute__((weak))
#endif
void jemalloc_stats(jemalloc_stats_t *stats);
/* Computes the usable size in advance. */
#if !defined(MOZ_MEMORY_DARWIN)
-#if defined(MOZ_MEMORY_LINUX)
+#if defined(MOZ_MEMORY_LINUX) || defined(MOZ_MEMORY_BSD)
__attribute__((weak))
#endif
#if defined(MOZ_JEMALLOC)
-int je_nallocm(size_t *rsize, size_t size, int flags);
+MOZ_IMPORT_API(int) wrap(nallocm)(size_t *rsize, size_t size, int flags);
#else
size_t je_malloc_good_size(size_t size);
#endif
@@ -62,11 +69,11 @@ static inline size_t je_malloc_usable_size_in_advance(size_t size) {
#if defined(MOZ_MEMORY_DARWIN)
return malloc_good_size(size);
#elif defined(MOZ_JEMALLOC)
- if (je_nallocm) {
+ if (wrap(nallocm)) {
size_t ret;
if (size == 0)
size = 1;
- if (!je_nallocm(&ret, size, 0))
+ if (!wrap(nallocm)(&ret, size, 0))
return ret;
}
return size;
@@ -113,4 +120,6 @@ void jemalloc_purge_freed_pages();
} /* extern "C" */
#endif
+#undef wrap
+
#endif /* _JEMALLOC_H_ */
diff --git mozglue/build/Makefile.in mozglue/build/Makefile.in
index c333647..15ba505 100644
--- mozglue/build/Makefile.in
+++ mozglue/build/Makefile.in
@@ -23,7 +23,7 @@ FORCE_STATIC_LIB = 1
endif
# Keep jemalloc separated when mozglue is statically linked
-ifeq (1_1,$(MOZ_MEMORY)_$(FORCE_SHARED_LIB))
+ifeq (1_1,$(MOZ_MEMORY)_$(or $(MOZ_NATIVE_JEMALLOC),$(FORCE_SHARED_LIB)))
SHARED_LIBRARY_LIBS = $(call EXPAND_LIBNAME_PATH,memory,$(DEPTH)/memory/build)
else
# Temporary, until bug 662814 lands