From ee10afb48a9c4669374b72eda092032361fb4586 Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Sat, 3 Sep 2011 04:35:21 +0100 Subject: [PATCH] Backout e5815c156b6c (bug 683096), 9ca928d8095c (merge), a286edb8ca4b (bug 683875), 61dc35b8f63f (bug 683171), b0741ae44def (bug 683875), 8e01bc314326 + e2697c06468f (bug 677501), 805e28e85577 (bug 680440) for Win opt orange and purple galore, on a CLOSED TREE --- Makefile.in | 6 +- browser/app/Makefile.in | 2 + browser/installer/package-manifest.in | 7 +- browser/installer/removed-files.in | 2 +- build/win32/Makefile.in | 2 - build/win32/crashinjectdll/Makefile.in | 2 - build/win32/vmwarerecordinghelper/Makefile.in | 2 - config/autoconf.mk.in | 8 +- config/config.mk | 19 +- config/rules.mk | 24 ++- configure.in | 34 +--- ipc/app/Makefile.in | 4 + js/src/Makefile.in | 6 + js/src/config/autoconf.mk.in | 3 +- js/src/config/config.mk | 19 +- js/src/config/rules.mk | 24 ++- js/src/configure.in | 5 +- memory/Makefile.in | 1 - memory/jemalloc/Makefile.in | 110 ++++++++++- memory/{mozutils => jemalloc}/fixcrt.py | 0 .../mozutils.def.in => jemalloc/jemalloc.def} | 4 +- memory/mozalloc/Makefile.in | 6 + memory/mozutils/Makefile.in | 175 ------------------ memory/mozutils/dummy.cpp | 2 - mobile/app/Makefile.in | 2 + mobile/installer/package-manifest.in | 4 +- other-licenses/android/Makefile.in | 15 +- toolkit/library/libxul-rules.mk | 6 + toolkit/mozapps/installer/packager.mk | 2 +- xpcom/idl-parser/typelib.py | 4 +- xpcom/typelib/xpidl/Makefile.in | 5 + xulrunner/app/Makefile.in | 2 + xulrunner/stub/Makefile.in | 2 + 33 files changed, 238 insertions(+), 271 deletions(-) rename memory/{mozutils => jemalloc}/fixcrt.py (100%) rename memory/{mozutils/mozutils.def.in => jemalloc/jemalloc.def} (97%) delete mode 100644 memory/mozutils/Makefile.in delete mode 100644 memory/mozutils/dummy.cpp diff --git a/Makefile.in b/Makefile.in index 573b2f2baa1e..ee1da71bde92 100644 --- a/Makefile.in +++ b/Makefile.in @@ -65,11 +65,15 @@ tier_base_dirs = \ $(NULL) ifndef LIBXUL_SDK +ifdef MOZ_MEMORY +tier_base_dirs += memory/jemalloc +endif + ifeq ($(OS_TARGET),Android) tier_base_dirs += other-licenses/android endif -tier_base_dirs += memory +tier_base_dirs += memory/mozalloc endif ifdef COMPILE_ENVIRONMENT diff --git a/browser/app/Makefile.in b/browser/app/Makefile.in index e40172f9e245..9a39a45e48a2 100644 --- a/browser/app/Makefile.in +++ b/browser/app/Makefile.in @@ -85,6 +85,8 @@ ifdef MOZ_APP_PROFILE DEFINES += -DMOZ_APP_PROFILE="$(MOZ_APP_PROFILE)" endif +LIBS += $(JEMALLOC_LIBS) + ifdef LIBXUL_SDK include $(topsrcdir)/config/rules.mk else diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index d5d239d93f21..be25880912ed 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -45,7 +45,9 @@ @BINPATH@/@DLL_PREFIX@xpcom@DLL_SUFFIX@ @BINPATH@/@DLL_PREFIX@nspr4@DLL_SUFFIX@ @BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@ -@BINPATH@/@DLL_PREFIX@mozutils@DLL_SUFFIX@ +#ifdef MOZ_MEMORY_DARWIN +@BINPATH@/@DLL_PREFIX@jemalloc@DLL_SUFFIX@ +#endif #ifdef XP_MACOSX @BINPATH@/XUL #else @@ -58,6 +60,9 @@ @BINPATH@/@MOZ_CHILD_PROCESS_NAME@ #endif #ifdef XP_WIN32 +#ifdef MOZ_MEMORY +@BINPATH@/jemalloc.dll +#endif #if _MSC_VER == 1400 @BINPATH@/Microsoft.VC80.CRT.manifest @BINPATH@/msvcm80.dll diff --git a/browser/installer/removed-files.in b/browser/installer/removed-files.in index dde9c503893b..746627754a92 100644 --- a/browser/installer/removed-files.in +++ b/browser/installer/removed-files.in @@ -9,7 +9,6 @@ @DLL_PREFIX@xpcom_compat@DLL_SUFFIX@ @DLL_PREFIX@xpistub@DLL_SUFFIX@ @DLL_PREFIX@zlib@DLL_SUFFIX@ -@DLL_PREFIX@jemalloc@DLL_SUFFIX@ #ifdef MOZ_STATIC_JS @DLL_PREFIX@mozjs@DLL_SUFFIX@ #endif @@ -1259,6 +1258,7 @@ xpicleanup@BIN_SUFFIX@ dictionaries/PL.dic icons/mozicon16.xpm icons/mozicon50.xpm + libjemalloc.so plugins/libnullplugin.so readme.txt #endif diff --git a/build/win32/Makefile.in b/build/win32/Makefile.in index e65bfcb77f4b..7f6688b5cb86 100644 --- a/build/win32/Makefile.in +++ b/build/win32/Makefile.in @@ -62,8 +62,6 @@ CPPSRCS = crashinject.cpp endif # ENABLE_TESTS -MOZ_UTILS_LDFLAGS = - include $(topsrcdir)/config/rules.mk ifdef WIN32_REDIST_DIR diff --git a/build/win32/crashinjectdll/Makefile.in b/build/win32/crashinjectdll/Makefile.in index a7cd0ab962b1..14ffaac4e4a0 100644 --- a/build/win32/crashinjectdll/Makefile.in +++ b/build/win32/crashinjectdll/Makefile.in @@ -50,6 +50,4 @@ USE_STATIC_LIBS = 1 CPPSRCS = crashinjectdll.cpp -MOZ_UTILS_LDFLAGS = - include $(topsrcdir)/config/rules.mk diff --git a/build/win32/vmwarerecordinghelper/Makefile.in b/build/win32/vmwarerecordinghelper/Makefile.in index 7c0e459dd709..01457deac0b4 100644 --- a/build/win32/vmwarerecordinghelper/Makefile.in +++ b/build/win32/vmwarerecordinghelper/Makefile.in @@ -51,6 +51,4 @@ USE_STATIC_LIBS = 1 CPPSRCS = $(LIBRARY_NAME).cpp -MOZ_UTILS_LDFLAGS = - include $(topsrcdir)/config/rules.mk diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in index e86645621c42..ea68d9fcc3f0 100644 --- a/config/autoconf.mk.in +++ b/config/autoconf.mk.in @@ -197,6 +197,7 @@ RM = rm -f MOZ_UI_LOCALE = @MOZ_UI_LOCALE@ MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS = @MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS@ +MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS = @MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS@ MOZ_COMPONENT_NSPR_LIBS=@MOZ_COMPONENT_NSPR_LIBS@ MOZ_FIX_LINK_PATHS=@MOZ_FIX_LINK_PATHS@ @@ -627,12 +628,13 @@ MOZ_TOOLS_DIR = @MOZ_TOOLS_DIR@ MOZ_QUANTIFY = @MOZ_QUANTIFY@ MSMANIFEST_TOOL = @MSMANIFEST_TOOL@ WIN32_REDIST_DIR = @WIN32_REDIST_DIR@ -MOZ_UTILS_LDFLAGS = @MOZ_UTILS_LDFLAGS@ -MOZ_UTILS_PROGRAM_LDFLAGS = @MOZ_UTILS_PROGRAM_LDFLAGS@ +MOZ_MEMORY_LDFLAGS = @MOZ_MEMORY_LDFLAGS@ WIN32_CRT_LIBS = @WIN32_CRT_LIBS@ -# This is used to pass jemalloc flags to NSS +# This is for custom CRT building +ifdef MOZ_MEMORY DLLFLAGS = @DLLFLAGS@ +endif # Codesighs tools option, enables win32 mapfiles. MOZ_MAPINFO = @MOZ_MAPINFO@ diff --git a/config/config.mk b/config/config.mk index 162cdaec2a7d..54c03ed8e989 100644 --- a/config/config.mk +++ b/config/config.mk @@ -149,6 +149,17 @@ FINAL_LINK_COMP_NAMES = $(DEPTH)/config/final-link-comp-names MOZ_UNICHARUTIL_LIBS = $(LIBXUL_DIST)/lib/$(LIB_PREFIX)unicharutil_s.$(LIB_SUFFIX) MOZ_WIDGET_SUPPORT_LIBS = $(DIST)/lib/$(LIB_PREFIX)widgetsupport_s.$(LIB_SUFFIX) +ifdef MOZ_MEMORY +ifneq ($(OS_ARCH),WINNT) +JEMALLOC_LIBS = $(MKSHLIB_FORCE_ALL) $(call EXPAND_MOZLIBNAME,jemalloc) $(MKSHLIB_UNFORCE_ALL) +# If we are linking jemalloc into a program, we want the jemalloc symbols +# to be exported +ifneq (,$(SIMPLE_PROGRAMS)$(PROGRAM)) +JEMALLOC_LIBS += $(MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS) +endif +endif +endif + CC := $(CC_WRAPPER) $(CC) CXX := $(CXX_WRAPPER) $(CXX) MKDIR ?= mkdir @@ -236,17 +247,13 @@ endif # MOZ_DEBUG # We don't build a static CRT when building a custom CRT, # it appears to be broken. So don't link to jemalloc if # the Makefile wants static CRT linking. -ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_1) +ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_) # Disable default CRT libs and add the right lib path for the linker -MOZ_UTILS_LDFLAGS= +OS_LDFLAGS += $(MOZ_MEMORY_LDFLAGS) endif endif # WINNT && !GNU_CC -ifndef MOZ_UTILS_PROGRAM_LDFLAGS -MOZ_UTILS_PROGRAM_LDFLAGS=$(MOZ_UTILS_LDFLAGS) -endif - # # Build using PIC by default # diff --git a/config/rules.mk b/config/rules.mk index 33339b221f8e..726368514ecf 100644 --- a/config/rules.mk +++ b/config/rules.mk @@ -250,12 +250,12 @@ endif # ENABLE_TESTS ifndef LIBRARY ifdef STATIC_LIBRARY_NAME -REAL_LIBRARY := $(LIB_PREFIX)$(STATIC_LIBRARY_NAME).$(LIB_SUFFIX) +_LIBRARY := $(LIB_PREFIX)$(STATIC_LIBRARY_NAME).$(LIB_SUFFIX) # Only build actual library if it is installed in DIST/lib or SDK ifeq (,$(SDK_LIBRARY)$(DIST_INSTALL)$(NO_EXPAND_LIBS)) -LIBRARY := $(REAL_LIBRARY).$(LIBS_DESC_SUFFIX) +LIBRARY := $(_LIBRARY).$(LIBS_DESC_SUFFIX) else -LIBRARY := $(REAL_LIBRARY) $(REAL_LIBRARY).$(LIBS_DESC_SUFFIX) +LIBRARY := $(_LIBRARY) $(_LIBRARY).$(LIBS_DESC_SUFFIX) endif endif # STATIC_LIBRARY_NAME endif # LIBRARY @@ -875,7 +875,7 @@ alltags: $(PROGRAM): $(PROGOBJS) $(LIBS_DEPS) $(EXTRA_DEPS) $(EXE_DEF_FILE) $(RESFILE) $(GLOBAL_DEPS) @$(RM) $@.manifest ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH)) - $(EXPAND_LD) -NOLOGO -OUT:$@ -PDB:$(LINK_PDBFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(PROGOBJS) $(RESFILE) $(LIBS) $(EXTRA_LIBS) $(OS_LIBS) + $(EXPAND_LD) -NOLOGO -OUT:$@ -PDB:$(LINK_PDBFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(PROGOBJS) $(RESFILE) $(LIBS) $(EXTRA_LIBS) $(OS_LIBS) ifdef MSMANIFEST_TOOL @if test -f $@.manifest; then \ if test -f "$(srcdir)/$@.manifest"; then \ @@ -897,10 +897,10 @@ ifdef MOZ_PROFILE_GENERATE endif else # !WINNT || GNU_CC ifeq ($(CPP_PROG_LINK),1) - $(EXPAND_CCC) -o $@ $(CXXFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(WRAP_LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(EXE_DEF_FILE) + $(EXPAND_CCC) -o $@ $(CXXFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(EXE_DEF_FILE) @$(call CHECK_STDCXX,$@) else # ! CPP_PROG_LINK - $(EXPAND_CC) -o $@ $(CFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(EXE_DEF_FILE) + $(EXPAND_CC) -o $@ $(CFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(EXE_DEF_FILE) endif # CPP_PROG_LINK endif # WINNT && !GNU_CC @@ -946,7 +946,7 @@ endif # $(SIMPLE_PROGRAMS): %$(BIN_SUFFIX): %.$(OBJ_SUFFIX) $(LIBS_DEPS) $(EXTRA_DEPS) $(GLOBAL_DEPS) ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH)) - $(EXPAND_LD) -nologo -out:$@ -pdb:$(LINK_PDBFILE) $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(LIBS) $(EXTRA_LIBS) $(OS_LIBS) + $(EXPAND_LD) -nologo -out:$@ -pdb:$(LINK_PDBFILE) $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(LIBS) $(EXTRA_LIBS) $(OS_LIBS) ifdef MSMANIFEST_TOOL @if test -f $@.manifest; then \ mt.exe -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \ @@ -955,10 +955,10 @@ ifdef MSMANIFEST_TOOL endif # MSVC with manifest tool else ifeq ($(CPP_PROG_LINK),1) - $(EXPAND_CCC) $(CXXFLAGS) -o $@ $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) + $(EXPAND_CCC) $(CXXFLAGS) -o $@ $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) @$(call CHECK_STDCXX,$@) else - $(EXPAND_CC) $(CFLAGS) $(OUTOPTION)$@ $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) + $(EXPAND_CC) $(CFLAGS) $(OUTOPTION)$@ $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) endif # CPP_PROG_LINK endif # WINNT && !GNU_CC @@ -1016,8 +1016,6 @@ $(filter %.$(LIB_SUFFIX),$(LIBRARY)): $(OBJS) $(LOBJS) $(SHARED_LIBRARY_LIBS_DEP $(RANLIB) $@ $(filter-out %.$(LIB_SUFFIX),$(LIBRARY)): $(filter %.$(LIB_SUFFIX),$(LIBRARY)) $(OBJS) $(LOBJS) $(SHARED_LIBRARY_LIBS_DEPS) $(EXTRA_DEPS) $(GLOBAL_DEPS) -# When we only build a library descriptor, blow out any existing library - $(if $(filter %.$(LIB_SUFFIX),$(LIBRARY)),,$(RM) $(REAL_LIBRARY) $(EXPORT_LIBRARY:%=%/$(REAL_LIBRARY))) $(EXPAND_LIBS_GEN) $(OBJS) $(LOBJS) $(SHARED_LIBRARY_LIBS) > $@ ifeq ($(OS_ARCH),WINNT) @@ -1071,10 +1069,10 @@ ifdef DTRACE_LIB_DEPENDENT ifndef XP_MACOSX dtrace -G -C -s $(MOZILLA_DTRACE_SRC) -o $(DTRACE_PROBE_OBJ) $(shell $(EXPAND_LIBS) $(MOZILLA_PROBE_LIBS)) endif - $(EXPAND_MKSHLIB) $(SHLIB_LDSTARTFILE) $(OBJS) $(LOBJS) $(SUB_SHLOBJS) $(DTRACE_PROBE_OBJ) $(MOZILLA_PROBE_LIBS) $(RESFILE) $(LDFLAGS) $(MOZ_UTILS_LDFLAGS) $(WRAP_LDFLAGS) $(SHARED_LIBRARY_LIBS) $(EXTRA_DSO_LDOPTS) $(OS_LIBS) $(EXTRA_LIBS) $(DEF_FILE) $(SHLIB_LDENDFILE) + $(EXPAND_MKSHLIB) $(SHLIB_LDSTARTFILE) $(OBJS) $(LOBJS) $(SUB_SHLOBJS) $(DTRACE_PROBE_OBJ) $(MOZILLA_PROBE_LIBS) $(RESFILE) $(LDFLAGS) $(WRAP_LDFLAGS) $(SHARED_LIBRARY_LIBS) $(EXTRA_DSO_LDOPTS) $(OS_LIBS) $(EXTRA_LIBS) $(DEF_FILE) $(SHLIB_LDENDFILE) @$(RM) $(DTRACE_PROBE_OBJ) else # ! DTRACE_LIB_DEPENDENT - $(EXPAND_MKSHLIB) $(SHLIB_LDSTARTFILE) $(OBJS) $(LOBJS) $(SUB_SHLOBJS) $(RESFILE) $(LDFLAGS) $(MOZ_UTILS_LDFLAGS) $(WRAP_LDFLAGS) $(SHARED_LIBRARY_LIBS) $(EXTRA_DSO_LDOPTS) $(OS_LIBS) $(EXTRA_LIBS) $(DEF_FILE) $(SHLIB_LDENDFILE) + $(EXPAND_MKSHLIB) $(SHLIB_LDSTARTFILE) $(OBJS) $(LOBJS) $(SUB_SHLOBJS) $(RESFILE) $(LDFLAGS) $(WRAP_LDFLAGS) $(SHARED_LIBRARY_LIBS) $(EXTRA_DSO_LDOPTS) $(OS_LIBS) $(EXTRA_LIBS) $(DEF_FILE) $(SHLIB_LDENDFILE) endif # DTRACE_LIB_DEPENDENT @$(call CHECK_STDCXX,$@) diff --git a/configure.in b/configure.in index 1f5e367aff1b..cc0305262a09 100644 --- a/configure.in +++ b/configure.in @@ -2723,6 +2723,7 @@ dnl ======================================================== case "$target" in *-linux*|*-kfreebsd*-gnu|*-gnu*) MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-Wl,--version-script -Wl,$(BUILD_TOOLS)/gnu-ld-scripts/components-version-script' + MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS='-rdynamic -Wl,--version-script -Wl,$(BUILD_TOOLS)/gnu-ld-scripts/jemalloc-standalone-linkage-version-script' ;; *-solaris*) if test -z "$GNU_CC"; then @@ -7083,21 +7084,6 @@ if test "$NS_TRACE_MALLOC"; then MOZ_MEMORY= fi -if test "${OS_TARGET}" = "Android"; then - dnl On Android, we use WRAP_LDFLAGS to link everything to mozutils - : -elif test "${OS_TARGET}" = "WINNT" -o "${OS_TARGET}" = "Darwin" -o "${OS_TARGET}" = "OS2"; then - dnl On Windows, OSX and OS2, we want to link all our binaries against mozutils - MOZ_UTILS_LDFLAGS='$(call EXPAND_LIBNAME_PATH,mozutils,$(LIBXUL_DIST)/lib)' -else - dnl On other Unix systems, we only want to link executables against mozutils - MOZ_UTILS_PROGRAM_LDFLAGS='$(MKSHLIB_FORCE_ALL) $(call EXPAND_LIBNAME_PATH,mozutils,$(LIBXUL_DIST)/lib) $(MKSHLIB_UNFORCE_ALL)' - if test -n "$GNU_CC"; then - dnl And we need mozutils symbols to be exported. - MOZ_UTILS_PROGRAM_LDFLAGS="$MOZ_UTILS_PROGRAM_LDFLAGS -rdynamic" - fi -fi - if test -z "$MOZ_MEMORY"; then case "${target}" in *-mingw*) @@ -7147,7 +7133,6 @@ else AC_DEFINE(MOZ_MEMORY_LINUX) AC_DEFINE(MOZ_MEMORY_ANDROID) _WRAP_MALLOC=1 - MOZ_UTILS_LDFLAGS= ;; *-*linux*) AC_DEFINE(MOZ_MEMORY_LINUX) @@ -7169,12 +7154,14 @@ else WIN32_CRTDLL_FULLPATH=`lib -nologo -list $WIN32_CRT_LIBS | grep crtdll\\.obj` lib -NOLOGO -OUT:crtdll.obj $WIN32_CRT_LIBS -EXTRACT:$WIN32_CRTDLL_FULLPATH if grep -q '__imp__\{0,1\}free' crtdll.obj; then - MOZ_UTILS_LDFLAGS='-LIBPATH:$(DIST)/lib -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcrtd -NODEFAULTLIB:msvcprt -NODEFAULTLIB:msvcprtd -DEFAULTLIB:mozcrt' + MOZ_MEMORY_LDFLAGS='-LIBPATH:$(DIST)/lib -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcrtd -NODEFAULTLIB:msvcprt -NODEFAULTLIB:msvcprtd -DEFAULTLIB:mozcrt' + else + MOZ_MEMORY_LDFLAGS='$(DIST)/../memory/jemalloc/jemalloc.lib' fi rm crtdll.obj dnl Also pass this to NSPR/NSS - DLLFLAGS="$DLLFLAGS $MOZ_UTILS_LDFLAGS" + DLLFLAGS="$DLLFLAGS $MOZ_MEMORY_LDFLAGS" export DLLFLAGS ;; *) @@ -7190,8 +7177,7 @@ else AC_DEFINE(HAVE_JEMALLOC_MEMALIGN) fi # MOZ_MEMORY AC_SUBST(MOZ_MEMORY) -AC_SUBST(MOZ_UTILS_LDFLAGS) -AC_SUBST(MOZ_UTILS_PROGRAM_LDFLAGS) +AC_SUBST(MOZ_MEMORY_LDFLAGS) AC_SUBST(WIN32_CRT_LIBS) dnl Need to set this for make because NSS doesn't have configure AC_SUBST(DLLFLAGS) @@ -8606,6 +8592,7 @@ AC_SUBST(USE_ELF_DYNSTR_GC) AC_SUBST(USE_ELF_HACK) AC_SUBST(INCREMENTAL_LINKER) AC_SUBST(MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS) +AC_SUBST(MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS) AC_SUBST(MOZ_COMPONENT_NSPR_LIBS) AC_SUBST(MOZ_FIX_LINK_PATHS) @@ -9179,11 +9166,8 @@ ac_configure_args="$ac_configure_args --prefix=$dist" ac_configure_args="$ac_configure_args --with-sync-build-files=$_topsrcdir" if test "$MOZ_MEMORY"; then ac_configure_args="$ac_configure_args --enable-jemalloc" - if test -n "$MOZ_UTILS_LDFLAGS"; then - export MOZ_UTILS_LDFLAGS - fi - if test -n "$MOZ_UTILS_PROGRAM_LDFLAGS"; then - export MOZ_UTILS_PROGRAM_LDFLAGS + if test -n "$MOZ_MEMORY_LDFLAGS"; then + export MOZ_MEMORY_LDFLAGS fi fi export MOZ_APP_NAME diff --git a/ipc/app/Makefile.in b/ipc/app/Makefile.in index c7ac94bdf0c2..bc1833b39bb6 100644 --- a/ipc/app/Makefile.in +++ b/ipc/app/Makefile.in @@ -90,6 +90,10 @@ OS_LIBS += $(call EXPAND_LIBNAME,comctl32 comdlg32 uuid shell32 ole32 oleaut32 v OS_LIBS += $(call EXPAND_LIBNAME,usp10 msimg32) endif +ifneq (Android,$(OS_TARGET)) +LIBS += $(JEMALLOC_LIBS) +endif + include $(topsrcdir)/config/rules.mk ifeq ($(OS_ARCH),WINNT) diff --git a/js/src/Makefile.in b/js/src/Makefile.in index 01ee687e43bc..3c022ffed535 100644 --- a/js/src/Makefile.in +++ b/js/src/Makefile.in @@ -828,6 +828,12 @@ EXTRA_LIBS += -lposix4 -ldl -lnsl -lsocket endif endif +ifdef MOZ_MEMORY +ifeq ($(OS_ARCH),Darwin) +LDFLAGS += -ljemalloc +endif +endif + ifdef SOLARIS_SUNPRO_CXX ifeq ($(TARGET_CPU),sparc) # Sun Studio SPARC doesn't work well with gcc inline asm, use lock_SunOS_sparc*.il diff --git a/js/src/config/autoconf.mk.in b/js/src/config/autoconf.mk.in index 6eb14b482455..a719c93c3e1f 100644 --- a/js/src/config/autoconf.mk.in +++ b/js/src/config/autoconf.mk.in @@ -319,8 +319,7 @@ MOZ_BROWSE_INFO = @MOZ_BROWSE_INFO@ MOZ_TOOLS_DIR = @MOZ_TOOLS_DIR@ MOZ_QUANTIFY = @MOZ_QUANTIFY@ MSMANIFEST_TOOL = @MSMANIFEST_TOOL@ -MOZ_UTILS_LDFLAGS = @MOZ_UTILS_LDFLAGS@ -MOZ_UTILS_PROGRAM_LDFLAGS = @MOZ_UTILS_PROGRAM_LDFLAGS@ +MOZ_MEMORY_LDFLAGS = @MOZ_MEMORY_LDFLAGS@ # Codesighs tools option, enables win32 mapfiles. MOZ_MAPINFO = @MOZ_MAPINFO@ diff --git a/js/src/config/config.mk b/js/src/config/config.mk index 162cdaec2a7d..54c03ed8e989 100644 --- a/js/src/config/config.mk +++ b/js/src/config/config.mk @@ -149,6 +149,17 @@ FINAL_LINK_COMP_NAMES = $(DEPTH)/config/final-link-comp-names MOZ_UNICHARUTIL_LIBS = $(LIBXUL_DIST)/lib/$(LIB_PREFIX)unicharutil_s.$(LIB_SUFFIX) MOZ_WIDGET_SUPPORT_LIBS = $(DIST)/lib/$(LIB_PREFIX)widgetsupport_s.$(LIB_SUFFIX) +ifdef MOZ_MEMORY +ifneq ($(OS_ARCH),WINNT) +JEMALLOC_LIBS = $(MKSHLIB_FORCE_ALL) $(call EXPAND_MOZLIBNAME,jemalloc) $(MKSHLIB_UNFORCE_ALL) +# If we are linking jemalloc into a program, we want the jemalloc symbols +# to be exported +ifneq (,$(SIMPLE_PROGRAMS)$(PROGRAM)) +JEMALLOC_LIBS += $(MOZ_JEMALLOC_STANDALONE_GLUE_LDOPTS) +endif +endif +endif + CC := $(CC_WRAPPER) $(CC) CXX := $(CXX_WRAPPER) $(CXX) MKDIR ?= mkdir @@ -236,17 +247,13 @@ endif # MOZ_DEBUG # We don't build a static CRT when building a custom CRT, # it appears to be broken. So don't link to jemalloc if # the Makefile wants static CRT linking. -ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_1) +ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_) # Disable default CRT libs and add the right lib path for the linker -MOZ_UTILS_LDFLAGS= +OS_LDFLAGS += $(MOZ_MEMORY_LDFLAGS) endif endif # WINNT && !GNU_CC -ifndef MOZ_UTILS_PROGRAM_LDFLAGS -MOZ_UTILS_PROGRAM_LDFLAGS=$(MOZ_UTILS_LDFLAGS) -endif - # # Build using PIC by default # diff --git a/js/src/config/rules.mk b/js/src/config/rules.mk index 33339b221f8e..726368514ecf 100644 --- a/js/src/config/rules.mk +++ b/js/src/config/rules.mk @@ -250,12 +250,12 @@ endif # ENABLE_TESTS ifndef LIBRARY ifdef STATIC_LIBRARY_NAME -REAL_LIBRARY := $(LIB_PREFIX)$(STATIC_LIBRARY_NAME).$(LIB_SUFFIX) +_LIBRARY := $(LIB_PREFIX)$(STATIC_LIBRARY_NAME).$(LIB_SUFFIX) # Only build actual library if it is installed in DIST/lib or SDK ifeq (,$(SDK_LIBRARY)$(DIST_INSTALL)$(NO_EXPAND_LIBS)) -LIBRARY := $(REAL_LIBRARY).$(LIBS_DESC_SUFFIX) +LIBRARY := $(_LIBRARY).$(LIBS_DESC_SUFFIX) else -LIBRARY := $(REAL_LIBRARY) $(REAL_LIBRARY).$(LIBS_DESC_SUFFIX) +LIBRARY := $(_LIBRARY) $(_LIBRARY).$(LIBS_DESC_SUFFIX) endif endif # STATIC_LIBRARY_NAME endif # LIBRARY @@ -875,7 +875,7 @@ alltags: $(PROGRAM): $(PROGOBJS) $(LIBS_DEPS) $(EXTRA_DEPS) $(EXE_DEF_FILE) $(RESFILE) $(GLOBAL_DEPS) @$(RM) $@.manifest ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH)) - $(EXPAND_LD) -NOLOGO -OUT:$@ -PDB:$(LINK_PDBFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(PROGOBJS) $(RESFILE) $(LIBS) $(EXTRA_LIBS) $(OS_LIBS) + $(EXPAND_LD) -NOLOGO -OUT:$@ -PDB:$(LINK_PDBFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(PROGOBJS) $(RESFILE) $(LIBS) $(EXTRA_LIBS) $(OS_LIBS) ifdef MSMANIFEST_TOOL @if test -f $@.manifest; then \ if test -f "$(srcdir)/$@.manifest"; then \ @@ -897,10 +897,10 @@ ifdef MOZ_PROFILE_GENERATE endif else # !WINNT || GNU_CC ifeq ($(CPP_PROG_LINK),1) - $(EXPAND_CCC) -o $@ $(CXXFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(WRAP_LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(EXE_DEF_FILE) + $(EXPAND_CCC) -o $@ $(CXXFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(EXE_DEF_FILE) @$(call CHECK_STDCXX,$@) else # ! CPP_PROG_LINK - $(EXPAND_CC) -o $@ $(CFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(EXE_DEF_FILE) + $(EXPAND_CC) -o $@ $(CFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(EXE_DEF_FILE) endif # CPP_PROG_LINK endif # WINNT && !GNU_CC @@ -946,7 +946,7 @@ endif # $(SIMPLE_PROGRAMS): %$(BIN_SUFFIX): %.$(OBJ_SUFFIX) $(LIBS_DEPS) $(EXTRA_DEPS) $(GLOBAL_DEPS) ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH)) - $(EXPAND_LD) -nologo -out:$@ -pdb:$(LINK_PDBFILE) $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(LIBS) $(EXTRA_LIBS) $(OS_LIBS) + $(EXPAND_LD) -nologo -out:$@ -pdb:$(LINK_PDBFILE) $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(LIBS) $(EXTRA_LIBS) $(OS_LIBS) ifdef MSMANIFEST_TOOL @if test -f $@.manifest; then \ mt.exe -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \ @@ -955,10 +955,10 @@ ifdef MSMANIFEST_TOOL endif # MSVC with manifest tool else ifeq ($(CPP_PROG_LINK),1) - $(EXPAND_CCC) $(CXXFLAGS) -o $@ $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) + $(EXPAND_CCC) $(CXXFLAGS) -o $@ $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) @$(call CHECK_STDCXX,$@) else - $(EXPAND_CC) $(CFLAGS) $(OUTOPTION)$@ $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_UTILS_PROGRAM_LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) + $(EXPAND_CC) $(CFLAGS) $(OUTOPTION)$@ $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(WRAP_LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) endif # CPP_PROG_LINK endif # WINNT && !GNU_CC @@ -1016,8 +1016,6 @@ $(filter %.$(LIB_SUFFIX),$(LIBRARY)): $(OBJS) $(LOBJS) $(SHARED_LIBRARY_LIBS_DEP $(RANLIB) $@ $(filter-out %.$(LIB_SUFFIX),$(LIBRARY)): $(filter %.$(LIB_SUFFIX),$(LIBRARY)) $(OBJS) $(LOBJS) $(SHARED_LIBRARY_LIBS_DEPS) $(EXTRA_DEPS) $(GLOBAL_DEPS) -# When we only build a library descriptor, blow out any existing library - $(if $(filter %.$(LIB_SUFFIX),$(LIBRARY)),,$(RM) $(REAL_LIBRARY) $(EXPORT_LIBRARY:%=%/$(REAL_LIBRARY))) $(EXPAND_LIBS_GEN) $(OBJS) $(LOBJS) $(SHARED_LIBRARY_LIBS) > $@ ifeq ($(OS_ARCH),WINNT) @@ -1071,10 +1069,10 @@ ifdef DTRACE_LIB_DEPENDENT ifndef XP_MACOSX dtrace -G -C -s $(MOZILLA_DTRACE_SRC) -o $(DTRACE_PROBE_OBJ) $(shell $(EXPAND_LIBS) $(MOZILLA_PROBE_LIBS)) endif - $(EXPAND_MKSHLIB) $(SHLIB_LDSTARTFILE) $(OBJS) $(LOBJS) $(SUB_SHLOBJS) $(DTRACE_PROBE_OBJ) $(MOZILLA_PROBE_LIBS) $(RESFILE) $(LDFLAGS) $(MOZ_UTILS_LDFLAGS) $(WRAP_LDFLAGS) $(SHARED_LIBRARY_LIBS) $(EXTRA_DSO_LDOPTS) $(OS_LIBS) $(EXTRA_LIBS) $(DEF_FILE) $(SHLIB_LDENDFILE) + $(EXPAND_MKSHLIB) $(SHLIB_LDSTARTFILE) $(OBJS) $(LOBJS) $(SUB_SHLOBJS) $(DTRACE_PROBE_OBJ) $(MOZILLA_PROBE_LIBS) $(RESFILE) $(LDFLAGS) $(WRAP_LDFLAGS) $(SHARED_LIBRARY_LIBS) $(EXTRA_DSO_LDOPTS) $(OS_LIBS) $(EXTRA_LIBS) $(DEF_FILE) $(SHLIB_LDENDFILE) @$(RM) $(DTRACE_PROBE_OBJ) else # ! DTRACE_LIB_DEPENDENT - $(EXPAND_MKSHLIB) $(SHLIB_LDSTARTFILE) $(OBJS) $(LOBJS) $(SUB_SHLOBJS) $(RESFILE) $(LDFLAGS) $(MOZ_UTILS_LDFLAGS) $(WRAP_LDFLAGS) $(SHARED_LIBRARY_LIBS) $(EXTRA_DSO_LDOPTS) $(OS_LIBS) $(EXTRA_LIBS) $(DEF_FILE) $(SHLIB_LDENDFILE) + $(EXPAND_MKSHLIB) $(SHLIB_LDSTARTFILE) $(OBJS) $(LOBJS) $(SUB_SHLOBJS) $(RESFILE) $(LDFLAGS) $(WRAP_LDFLAGS) $(SHARED_LIBRARY_LIBS) $(EXTRA_DSO_LDOPTS) $(OS_LIBS) $(EXTRA_LIBS) $(DEF_FILE) $(SHLIB_LDENDFILE) endif # DTRACE_LIB_DEPENDENT @$(call CHECK_STDCXX,$@) diff --git a/js/src/configure.in b/js/src/configure.in index 06c1484a09ba..cd6d63436c7b 100644 --- a/js/src/configure.in +++ b/js/src/configure.in @@ -4543,7 +4543,7 @@ if test "$MOZ_MEMORY"; then ;; *-mingw*) AC_DEFINE(MOZ_MEMORY_WINDOWS) - # the interesting bits will get passed down in MOZ_UTILS_LDFLAGS + # the interesting bits will get passed down in MOZ_MEMORY_LDFLAGS ;; *) AC_MSG_ERROR([--enable-jemalloc not supported on ${target}]) @@ -4558,8 +4558,7 @@ if test "$MOZ_MEMORY"; then fi fi AC_SUBST(MOZ_MEMORY) -AC_SUBST(MOZ_UTILS_LDFLAGS) -AC_SUBST(MOZ_UTILS_PROGRAM_LDFLAGS) +AC_SUBST(MOZ_MEMORY_LDFLAGS) dnl ======================================================== dnl = Use malloc wrapper lib diff --git a/memory/Makefile.in b/memory/Makefile.in index c61e5cf78346..408d49f6f515 100644 --- a/memory/Makefile.in +++ b/memory/Makefile.in @@ -47,7 +47,6 @@ ifdef MOZ_MEMORY DIRS += jemalloc endif -DIRS += mozutils DIRS += mozalloc include $(topsrcdir)/config/rules.mk diff --git a/memory/jemalloc/Makefile.in b/memory/jemalloc/Makefile.in index 4c572c56c4e2..a61deb0f53c3 100644 --- a/memory/jemalloc/Makefile.in +++ b/memory/jemalloc/Makefile.in @@ -52,7 +52,18 @@ VISIBILITY_FLAGS= CSRCS = jemalloc.c EXPORTS = jemalloc.h jemalloc_types.h LIBRARY_NAME = jemalloc -FORCE_STATIC_LIB= 1 + +ifeq (WINNT,$(OS_TARGET)) +FORCE_SHARED_LIB = 1 + +MOZ_MEMORY_LDFLAGS = # Don't link against ourselves + +DEFFILE = $(srcdir)/jemalloc.def + +LDFLAGS += -ENTRY:DllMain + +NO_INSTALL_IMPORT_LIBRARY = 1 +else # Not Windows ifeq ($(OS_ARCH),SunOS) ifndef GNU_CC @@ -60,10 +71,105 @@ MODULE_OPTIMIZE_FLAGS = -xO5 endif endif -ifeq (Linux,$(OS_TARGET)) +# Build jemalloc as a shared lib. This is mandatory for Darwin, since a library +# init function is used on that platform. +ifeq ($(OS_ARCH),Darwin) +FORCE_SHARED_LIB= 1 +else +# On Android, we're going to link jemalloc into mozutils, and that only works +# properly if we only build a fakelib, which won't happen if we DIST_INSTALL +ifneq ($(OS_TARGET),Android) +DIST_INSTALL = 1 +endif +FORCE_STATIC_LIB= 1 +endif + #XXX: PGO on Linux causes problems here # See bug 419470 NO_PROFILE_GUIDED_OPTIMIZE = 1 endif include $(topsrcdir)/config/rules.mk + +ifeq (Darwin,$(OS_TARGET)) +LDFLAGS += -init _jemalloc_darwin_init +endif + +ifeq (WINNT,$(OS_TARGET)) +# Roll our own custom logic here for the import library + +############################################################################### +# +# Linking Mozilla itself to jemalloc is not particularly difficult. To do this +# we avoid linking directly to the Microsoft-provided CRT import libraries. +# Instead, we link to our own import library which we generate here. To +# replace the CRT's malloc/free/other memory management symbols we export +# our own versions out of jemalloc.dll. We then take the import library that +# the compiler generates for jemalloc.dll and combine it with the MS CRT import +# libraries. We put our library on the command line first, and the CRT symbols +# are discarded in favor of our versions! +# +# Unfortunately that was too easy. The CRT import library is not a standard +# import library that contains a list of symbols and whatnot. It also includes +# object files that are linked into generated programs. One of these, +# crtdll.obj is (as one might expect) linked into all DLLs that link against +# the CRT. This file does things like run static C++ constructors when the +# DLL is attached, call DllMain, etc. +# +# In the CRT source all malloc/free calls are made to malloc_crt and free_crt. +# In debug builds these are both defined to malloc_dbg and free_dbg. In opt +# builds malloc_crt is an actual function, implemented and exposed from the +# CRT. free_crt is, however, defined to be just plain old free. This works +# fine inside the CRT where malloc_crt and free operate on the same heap. +# Outside the CRT malloc_crt is in the CRT's heap, but free is in jemalloc's +# heap. This causes much pain at shutdown :-( +# +# The obvious solution here is to override malloc_crt too. Unfortunately, +# that doesn't work because the CRT expects to be able to call msize on this +# piece of memory deep inside the CRT, which will fail because it'll call the +# CRT's msize on a pointer in jemalloc's heap. +# +# Our solution to this is quite devious. We take apart the CRT's import lib +# and remove the problematic object file. We then poke at the object file's +# symbol table and replace '__imp__free' (which means grab free from some +# other DLL) with '__imp__frex'. Then we define our own dummy no-op function +# in jemalloc.dll and export it as frex. Then we put the CRT import lib +# back together with the patched crtdll.obj, glue it to the end of jemalloc's +# import library and link the rest of Mozilla to that. +# +# The result? A binary that uses jemalloc, doesn't crash, and leaks a tiny +# amount of memory (32 words per DLL in the 2010 CRT) at shutdown. +# +############################################################################### + +libs:: mozcrt.lib + $(INSTALL) $(IFLAGS2) mozcrt.lib $(DIST)/lib + +# And finally combine that with the jemalloc import library to get an import +# library that has our malloc/free/etc and the CRT's everything else +mozcrt.lib: $(IMPORT_LIBRARY) msvc_modified.lib + lib -OUT:$@ $^ + +# Put the fixed object file back in +msvc_modified.lib: msvc_removed.lib crtdll_fixed.obj + lib -OUT:$@ $^ + +# Fix the object file +crtdll_fixed.obj: crtdll.obj + $(PYTHON) $(srcdir)/fixcrt.py + +# Find the path of crtdll.obj +CRTDLL_FULLPATH=$(subst \,\\,$(shell lib -list msvc_combined.lib | grep crtdll\\.obj)) + +# Remove the broken object file, only after we have extracted it +msvc_removed.lib: msvc_combined.lib crtdll.obj + lib -OUT:$@ msvc_combined.lib -REMOVE:$(CRTDLL_FULLPATH) + +# Extract the broken object file out of the combined library +crtdll.obj: msvc_combined.lib + lib -OUT:$@ $^ -EXTRACT:$(CRTDLL_FULLPATH) + +# Grab both CRT libraries and combine them into one library to simplify things +msvc_combined.lib: + lib -OUT:$@ $(WIN32_CRT_LIBS) +endif diff --git a/memory/mozutils/fixcrt.py b/memory/jemalloc/fixcrt.py similarity index 100% rename from memory/mozutils/fixcrt.py rename to memory/jemalloc/fixcrt.py diff --git a/memory/mozutils/mozutils.def.in b/memory/jemalloc/jemalloc.def similarity index 97% rename from memory/mozutils/mozutils.def.in rename to memory/jemalloc/jemalloc.def index 92c71f7e2534..9193d2df289d 100644 --- a/memory/mozutils/mozutils.def.in +++ b/memory/jemalloc/jemalloc.def @@ -33,10 +33,9 @@ ; ; ***** END LICENSE BLOCK ***** -LIBRARY mozutils.dll +LIBRARY jemalloc.dll EXPORTS -#ifdef MOZ_MEMORY ; symbols that are actually useful malloc=je_malloc valloc=je_valloc @@ -54,4 +53,3 @@ EXPORTS jemalloc_stats ; A hack to work around the CRT (see giant comment in Makefile.in) frex=je_dumb_free_thunk -#endif diff --git a/memory/mozalloc/Makefile.in b/memory/mozalloc/Makefile.in index 3f8fb942b1ec..a59ad0d957ae 100644 --- a/memory/mozalloc/Makefile.in +++ b/memory/mozalloc/Makefile.in @@ -54,6 +54,12 @@ LIBRARY_NAME = mozalloc FORCE_SHARED_LIB= 1 DIST_INSTALL = 1 +ifdef MOZ_MEMORY +ifeq ($(OS_ARCH),Darwin) +EXTRA_DSO_LDOPTS += -L$(DIST)/lib -ljemalloc +endif +endif + ifeq (,$(filter-out OS2,$(OS_ARCH))) # The strndup declaration in string.h is in an ifdef __USE_GNU section DEFINES += -D_GNU_SOURCE diff --git a/memory/mozutils/Makefile.in b/memory/mozutils/Makefile.in deleted file mode 100644 index 30a09c3368b6..000000000000 --- a/memory/mozutils/Makefile.in +++ /dev/null @@ -1,175 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Mozilla Foundation -# Portions created by the Initial Developer are Copyright (C) 2008 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Ted Mielczarek -# -# Alternatively, the contents of this file may be used under the terms of -# either of the GNU General Public License Version 2 or later (the "GPL"), -# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = mozutils -LIBRARY_NAME = mozutils -DIST_INSTALL = 1 - -ifdef MOZ_MEMORY -SHARED_LIBRARY_LIBS = $(call EXPAND_LIBNAME_PATH,jemalloc,../jemalloc) -else -# Temporary, until bug 662814 lands -VISIBILITY_FLAGS = -CPPSRCS = dummy.cpp -endif - -# Build mozutils as a shared lib on Windows, OSX and Android. -ifneq (,$(filter WINNT Darwin Android,$(OS_TARGET))) -FORCE_SHARED_LIB = 1 -else -FORCE_STATIC_LIB = 1 -endif - -MOZ_UTILS_LDFLAGS = # Don't link against ourselves - -ifeq (WINNT,$(OS_TARGET)) -DEFFILE = mozutils.def - -mozutils.def: mozutils.def.in - $(PYTHON) $(topsrcdir)/config/Preprocessor.py $(ACDEFINES) $< > $@ - -GARBAGE += mozutils.def - -LDFLAGS += -ENTRY:DllMain - -ifneq (,$(filter -DEFAULTLIB:mozcrt,$(MOZ_UTILS_LDFLAGS))) -# Don't install the import library if we use mozcrt -NO_INSTALL_IMPORT_LIBRARY = 1 -endif -endif - -ifeq (Android, $(OS_TARGET)) -# Add Android linker -EXTRA_DSO_LDOPTS += $(ZLIB_LIBS) -SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,android,$(DEPTH)/other-licenses/android) -WRAP_LDFLAGS = -endif - -include $(topsrcdir)/config/rules.mk - -ifdef MOZ_MEMORY -ifeq (Darwin,$(OS_TARGET)) -LDFLAGS += -init _jemalloc_darwin_init -endif - -ifeq (WINNT,$(OS_TARGET)) -# Roll our own custom logic here for the import library - -############################################################################### -# -# Linking Mozilla itself to jemalloc is not particularly difficult. To do this -# we avoid linking directly to the Microsoft-provided CRT import libraries. -# Instead, we link to our own import library which we generate here. To -# replace the CRT's malloc/free/other memory management symbols we export -# our own versions out of jemalloc.dll. We then take the import library that -# the compiler generates for jemalloc.dll and combine it with the MS CRT import -# libraries. We put our library on the command line first, and the CRT symbols -# are discarded in favor of our versions! -# -# Unfortunately that was too easy. The CRT import library is not a standard -# import library that contains a list of symbols and whatnot. It also includes -# object files that are linked into generated programs. One of these, -# crtdll.obj is (as one might expect) linked into all DLLs that link against -# the CRT. This file does things like run static C++ constructors when the -# DLL is attached, call DllMain, etc. -# -# In the CRT source all malloc/free calls are made to malloc_crt and free_crt. -# In debug builds these are both defined to malloc_dbg and free_dbg. In opt -# builds malloc_crt is an actual function, implemented and exposed from the -# CRT. free_crt is, however, defined to be just plain old free. This works -# fine inside the CRT where malloc_crt and free operate on the same heap. -# Outside the CRT malloc_crt is in the CRT's heap, but free is in jemalloc's -# heap. This causes much pain at shutdown :-( -# -# The obvious solution here is to override malloc_crt too. Unfortunately, -# that doesn't work because the CRT expects to be able to call msize on this -# piece of memory deep inside the CRT, which will fail because it'll call the -# CRT's msize on a pointer in jemalloc's heap. -# -# Our solution to this is quite devious. We take apart the CRT's import lib -# and remove the problematic object file. We then poke at the object file's -# symbol table and replace '__imp__free' (which means grab free from some -# other DLL) with '__imp__frex'. Then we define our own dummy no-op function -# in jemalloc.dll and export it as frex. Then we put the CRT import lib -# back together with the patched crtdll.obj, glue it to the end of jemalloc's -# import library and link the rest of Mozilla to that. -# -# The result? A binary that uses jemalloc, doesn't crash, and leaks a tiny -# amount of memory (32 words per DLL in the 2010 CRT) at shutdown. -# -############################################################################### - -libs:: mozcrt.lib - $(INSTALL) $(IFLAGS2) mozcrt.lib $(DIST)/lib - -# And finally combine that with the jemalloc import library to get an import -# library that has our malloc/free/etc and the CRT's everything else -mozcrt.lib: $(IMPORT_LIBRARY) msvc_modified.lib - lib -OUT:$@ $^ - -# Put the fixed object file back in -msvc_modified.lib: msvc_removed.lib crtdll_fixed.obj - lib -OUT:$@ $^ - -# Fix the object file -crtdll_fixed.obj: crtdll.obj - $(PYTHON) $(srcdir)/fixcrt.py - -# Find the path of crtdll.obj -CRTDLL_FULLPATH=$(subst \,\\,$(shell lib -list msvc_combined.lib | grep crtdll\\.obj)) - -# Remove the broken object file, only after we have extracted it -msvc_removed.lib: msvc_combined.lib crtdll.obj - lib -OUT:$@ msvc_combined.lib -REMOVE:$(CRTDLL_FULLPATH) - -# Extract the broken object file out of the combined library -crtdll.obj: msvc_combined.lib - lib -OUT:$@ $^ -EXTRACT:$(CRTDLL_FULLPATH) - -# Grab both CRT libraries and combine them into one library to simplify things -msvc_combined.lib: - lib -OUT:$@ $(WIN32_CRT_LIBS) -endif -endif # MOZ_MEMORY diff --git a/memory/mozutils/dummy.cpp b/memory/mozutils/dummy.cpp deleted file mode 100644 index b7196600f307..000000000000 --- a/memory/mozutils/dummy.cpp +++ /dev/null @@ -1,2 +0,0 @@ -void _dummy(void) { -} diff --git a/mobile/app/Makefile.in b/mobile/app/Makefile.in index 4f466df38990..4c2c272a2116 100644 --- a/mobile/app/Makefile.in +++ b/mobile/app/Makefile.in @@ -60,6 +60,8 @@ LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build DEFINES += -DXPCOM_GLUE STL_FLAGS= +LIBS += $(JEMALLOC_LIBS) + LIBS += \ $(EXTRA_DSO_LIBS) \ $(XPCOM_STANDALONE_GLUE_LDOPTS) \ diff --git a/mobile/installer/package-manifest.in b/mobile/installer/package-manifest.in index a9c8c9382078..464d14220d4c 100644 --- a/mobile/installer/package-manifest.in +++ b/mobile/installer/package-manifest.in @@ -47,7 +47,6 @@ @BINPATH@/@DLL_PREFIX@xpcom@DLL_SUFFIX@ @BINPATH@/@DLL_PREFIX@nspr4@DLL_SUFFIX@ @BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@ -@BINPATH@/@DLL_PREFIX@mozutils@DLL_SUFFIX@ #ifdef XP_MACOSX @BINPATH@/XUL #else @@ -59,6 +58,9 @@ @BINPATH@/@MOZ_CHILD_PROCESS_NAME@ #endif #ifdef XP_WIN32 +#ifdef MOZ_MEMORY +@BINPATH@/jemalloc.dll +#endif #if _MSC_VER == 1400 @BINPATH@/Microsoft.VC80.CRT.manifest @BINPATH@/msvcm80.dll diff --git a/other-licenses/android/Makefile.in b/other-licenses/android/Makefile.in index 181d401e5fe2..5e1fd3e22386 100644 --- a/other-licenses/android/Makefile.in +++ b/other-licenses/android/Makefile.in @@ -42,9 +42,10 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -MODULE = android -LIBRARY_NAME = android -FORCE_STATIC_LIB = 1 +MODULE = mozutils +LIBRARY_NAME = mozutils +FORCE_SHARED_LIB = 1 +DIST_INSTALL = 1 DEFINES += \ -DLINKER_DEBUG=0 \ @@ -71,4 +72,12 @@ CSRCS = \ EXPORTS = APKOpen.h +EXTRA_DSO_LDOPTS += $(ZLIB_LIBS) + +ifdef MOZ_MEMORY +SHARED_LIBRARY_LIBS = $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/jemalloc) +endif + +WRAP_LDFLAGS = + include $(topsrcdir)/config/rules.mk diff --git a/toolkit/library/libxul-rules.mk b/toolkit/library/libxul-rules.mk index e4517595f0c0..5335d970862b 100644 --- a/toolkit/library/libxul-rules.mk +++ b/toolkit/library/libxul-rules.mk @@ -45,6 +45,12 @@ LOCAL_INCLUDES += \ OS_LIBS += $(LIBICONV) +ifdef MOZ_MEMORY +ifeq ($(OS_ARCH),Darwin) +EXTRA_DSO_LDOPTS += -L$(DIST)/lib -ljemalloc +endif +endif + DEFINES += \ -D_IMPL_NS_COM \ -D_IMPL_NS_STRINGAPI \ diff --git a/toolkit/mozapps/installer/packager.mk b/toolkit/mozapps/installer/packager.mk index 46c8a9c9411a..bcbbf6e14939 100644 --- a/toolkit/mozapps/installer/packager.mk +++ b/toolkit/mozapps/installer/packager.mk @@ -420,7 +420,7 @@ GENERATE_CACHE = \ rm startupCache.zip && \ $(ZIP) -r9m omni.jar jsloader/resource/$(PRECOMPILE_RESOURCE) else -GENERATE_CACHE = true +GENERATE_CACHE = endif endif diff --git a/xpcom/idl-parser/typelib.py b/xpcom/idl-parser/typelib.py index 2a97230e8c43..054097a67169 100644 --- a/xpcom/idl-parser/typelib.py +++ b/xpcom/idl-parser/typelib.py @@ -94,9 +94,7 @@ def build_interface(iface, ifaces): reference=False) if isinstance(type, xpidl.Array): - # NB: For an Array we pass down the iid_is to get the type of T. - # This allows Arrays of InterfaceIs types to work. - return xpt.ArrayType(get_type(type.type, calltype, iid_is), size_is, + return xpt.ArrayType(get_type(type.type, calltype), size_is, #XXXkhuey length_is duplicates size_is (bug 677788), size_is) diff --git a/xpcom/typelib/xpidl/Makefile.in b/xpcom/typelib/xpidl/Makefile.in index a5fe8f59f4a3..90d6b2c97a20 100644 --- a/xpcom/typelib/xpidl/Makefile.in +++ b/xpcom/typelib/xpidl/Makefile.in @@ -111,6 +111,11 @@ include $(topsrcdir)/config/rules.mk CFLAGS += $(LIBIDL_CFLAGS) +# Do not link to jemalloc +ifeq ($(OS_ARCH),SunOS) +SOLARIS_JEMALLOC_LDFLAGS = +endif + # Compile directly against the static lib, so we can use xpidl during the build # without the shared library path being set. ifneq (,$(filter WINNT OS2,$(OS_ARCH))) diff --git a/xulrunner/app/Makefile.in b/xulrunner/app/Makefile.in index d8e4184bb484..10ebe166dfef 100644 --- a/xulrunner/app/Makefile.in +++ b/xulrunner/app/Makefile.in @@ -130,6 +130,8 @@ endif RCFLAGS += -DXULRUNNER_ICO=\"$(DIST)/branding/xulrunner.ico\" -DDOCUMENT_ICO=\"$(DIST)/branding/document.ico\" endif +LIBS += $(JEMALLOC_LIBS) + include $(topsrcdir)/config/rules.mk DEFINES += -DXULRUNNER_ICO=\"$(DIST)/branding/xulrunner.ico\" -DDOCUMENT_ICO=\"$(DIST)/branding/document.ico\" diff --git a/xulrunner/stub/Makefile.in b/xulrunner/stub/Makefile.in index 5ca03f5acd26..37ac92efbc43 100644 --- a/xulrunner/stub/Makefile.in +++ b/xulrunner/stub/Makefile.in @@ -97,6 +97,8 @@ ifdef _MSC_VER WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup endif +LIBS += $(JEMALLOC_LIBS) + include $(topsrcdir)/config/rules.mk ifeq ($(OS_ARCH),WINNT)