Bug 489975 Trunk comm-central static builds broken: unresolved external symbol _malloc_usable_size. r=gozer
authorMark Banner <bugzilla@standard8.plus.com>
Mon, 04 May 2009 19:11:46 +0100
changeset 2547 91b50be6114a98499f8c39445e7cb027151b70fb
parent 2546 d19ebdd62dbfb0fa446a3da18883132a3c924465
child 2548 db857c5e58e8625e6f3afb4ee8503b6e5e3715ab
push idunknown
push userunknown
push dateunknown
reviewersgozer
bugs489975
Bug 489975 Trunk comm-central static builds broken: unresolved external symbol _malloc_usable_size. r=gozer
config/autoconf.mk.in
config/config.mk
configure.in
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -554,24 +554,35 @@ MOZ_MILESTONE_RELEASE = @MOZ_MILESTONE_R
 # Win32 options
 MOZ_BROWSE_INFO	= @MOZ_BROWSE_INFO@
 MOZ_TOOLS_DIR	= @MOZ_TOOLS_DIR@
 MOZ_DEBUG_SYMBOLS = @MOZ_DEBUG_SYMBOLS@
 MOZ_QUANTIFY	= @MOZ_QUANTIFY@
 MSMANIFEST_TOOL = @MSMANIFEST_TOOL@
 WIN32_REDIST_DIR = @WIN32_REDIST_DIR@
 WIN32_CRT_SRC_DIR = @WIN32_CRT_SRC_DIR@
+ifdef MOZILLA_1_9_1_BRANCH
 WIN32_CUSTOM_CRT_DIR = @WIN32_CUSTOM_CRT_DIR@
-# These are for custom CRT building
+else
+MOZ_MEMORY_LDFLAGS = @MOZ_MEMORY_LDFLAGS@
+endif
+
+# This is for custom CRT building
 ifdef MOZ_MEMORY
+ifdef MOZILLA_1_9_1_BRANCH
 ifneq (,$(WIN32_CRT_SRC_DIR)$(WIN32_CUSTOM_CRT_DIR))
 export LIB = @MOZ_LIB@
 export PATH = @MOZ_PATH@
 DLLFLAGS = @DLLFLAGS@
 endif
+else
+ifdef WIN32_CRT_SRC_DIR
+DLLFLAGS = @DLLFLAGS@
+endif
+endif
 endif
 
 # Codesighs tools option, enables win32 mapfiles.
 MOZ_MAPINFO	= @MOZ_MAPINFO@
 
 MOZ_THUNDERBIRD = @MOZ_THUNDERBIRD@
 MOZ_STATIC_MAIL_BUILD = @MOZ_STATIC_MAIL_BUILD@
 MOZ_INCOMPLETE_EXTERNAL_LINKAGE = @MOZ_INCOMPLETE_EXTERNAL_LINKAGE@
--- a/config/config.mk
+++ b/config/config.mk
@@ -245,16 +245,26 @@ OS_LDFLAGS += $(_DEBUG_LDFLAGS)
 ifeq ($(OS_ARCH)_$(GNU_CC),WINNT_)
 ifdef MOZ_DEBUG
 ifneq (,$(MOZ_BROWSE_INFO)$(MOZ_BSCFILE))
 OS_CFLAGS += -FR
 OS_CXXFLAGS += -FR
 endif
 else # ! 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.
+ifndef MOZILLA_1_9_1_BRANCH
+ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_)
+# Disable default CRT libs and add the right lib path for the linker
+OS_LDFLAGS += $(MOZ_MEMORY_LDFLAGS)
+endif
+endif
+
 # MOZ_DEBUG_SYMBOLS generates debug symbols in separate PDB files.
 # Used for generating an optimized build with debugging symbols.
 # Used in the Windows nightlies to generate symbols for crash reporting.
 ifdef MOZ_DEBUG_SYMBOLS
 OS_CXXFLAGS += -Zi -UDEBUG -DNDEBUG
 OS_CFLAGS += -Zi -UDEBUG -DNDEBUG
 OS_LDFLAGS += -DEBUG -OPT:REF -OPT:nowin98
 endif
--- a/configure.in
+++ b/configure.in
@@ -5922,71 +5922,98 @@ if test "$MOZ_MEMORY"; then
   netbsd*)
     AC_DEFINE(MOZ_MEMORY_BSD)
     ;;
   solaris*)
     AC_DEFINE(MOZ_MEMORY_SOLARIS)
     ;;
   msvc*|mks*|cygwin*|mingw*)
     AC_DEFINE(MOZ_MEMORY_WINDOWS)
-    dnl XXX: should test for vc8sp1 here, otherwise patching the crt src
-    dnl will fail miserably
-    if test "$_CC_SUITE" -lt "8"; then
-        AC_MSG_ERROR([Building jemalloc requires Visual C++ 2005 or better])
-    fi
-    if test -z "$WIN32_CRT_SRC_DIR" -a -z "$WIN32_CUSTOM_CRT_DIR"; then
-      if test -z "$VCINSTALLDIR" -o ! -d "$VCINSTALLDIR"; then
-        AC_MSG_ERROR([When building jemalloc, either set WIN32_CRT_SRC_DIR to the path to the Visual C++ CRT source (usually VCINSTALLDIR\crt\src), or set WIN32_CUSTOM_CRT_DIR to the path to a folder containing a pre-built CRT DLL.])
+    dnl This is sort of awful. Will revisit if we add support for more versions
+    if test "$CC_VERSION" != "14.00.50727.762"; then
+        AC_MSG_ERROR([Building jemalloc requires exactly Visual C++ 2005 SP1 currently.])
+    fi
+    if test "$MOZILLA_1_9_1_BRANCH" = "1"; then
+      if test -z "$WIN32_CRT_SRC_DIR" -a -z "$WIN32_CUSTOM_CRT_DIR"; then
+        if test -z "$VCINSTALLDIR" -o ! -d "$VCINSTALLDIR"; then
+          AC_MSG_ERROR([When building jemalloc, either set WIN32_CRT_SRC_DIR to the path to the Visual C++ CRT source (usually VCINSTALLDIR\crt\src), or set WIN32 _CUSTOM_CRT_DIR to the path to a folder containing a pre-built CRT DLL.])
+        else
+          WIN32_CRT_SRC_DIR="$VCINSTALLDIR\crt\src"
+        fi
+      fi
+      if test -z "$WIN32_CRT_SRC_DIR"; then
+        # pre-built dll
+        WIN32_CUSTOM_CRT_DIR=`cd "$WIN32_CUSTOM_CRT_DIR" && pwd`
+        _WIN_UNIX_CRT_PATH="$WIN32_CUSTOM_CRT_DIR"
       else
-        WIN32_CRT_SRC_DIR="$VCINSTALLDIR\crt\src"
+        # CRT source directory
+        WIN32_CRT_SRC_DIR=`cd "$WIN32_CRT_SRC_DIR" && pwd`
+        _CRT_BASE_DIR=`basename "$WIN32_CRT_SRC_DIR"`
+        _WIN_UNIX_CRT_PATH="$_objdir/mozilla/memory/jemalloc/$_CRT_BASE_DIR/build/intel"
       fi
-    fi
-    if test -z "$WIN32_CRT_SRC_DIR"; then
-      # pre-built dll
-      WIN32_CUSTOM_CRT_DIR=`cd "$WIN32_CUSTOM_CRT_DIR" && pwd`
-      _WIN_UNIX_CRT_PATH="$WIN32_CUSTOM_CRT_DIR"
+      dnl need win32 paths in LIB, hence this python abuse.  extra brackets
+      dnl are to avoid m4
+      _WIN_CRT_PATH=[`$PYTHON -c 'import sys, os.path; print os.path.normpath(sys.argv[1])' "$_WIN_UNIX_CRT_PATH"`]
+      MOZ_LIB="$_WIN_CRT_PATH;$LIB"
+      dnl Needs to be in PATH too, since our tools will wind up linked against it.
+      dnl This needs to be unix style.
+      MOZ_PATH="$PATH:$_WIN_UNIX_CRT_PATH"
+      dnl Statically link the C++ stdlib.  We only use this for Breakpad anyway.
+      AC_DEFINE(_STATIC_CPPLIB)
+      dnl Don't generate a manifest, since we're linking to a custom CRT.
+      LDFLAGS="$LDFLAGS -MANIFEST:NO"
+      dnl Also pass this to NSPR/NSS
+      DLLFLAGS="$DLLFLAGS -MANIFEST:NO"
     else
-      # CRT source directory
-      WIN32_CRT_SRC_DIR=`cd "$WIN32_CRT_SRC_DIR" && pwd`
-      _CRT_BASE_DIR=`basename "$WIN32_CRT_SRC_DIR"`
-      _WIN_UNIX_CRT_PATH="$_objdir/mozilla/memory/jemalloc/$_CRT_BASE_DIR/build/intel"
-    fi
-    dnl need win32 paths in LIB, hence this python abuse.  extra brackets
-    dnl are to avoid m4
-    _WIN_CRT_PATH=[`$PYTHON -c 'import sys, os.path; print os.path.normpath(sys.argv[1])' "$_WIN_UNIX_CRT_PATH"`]
-    MOZ_LIB="$_WIN_CRT_PATH;$LIB"
-    dnl Needs to be in PATH too, since our tools will wind up linked against it.
-    dnl This needs to be unix style.
-    MOZ_PATH="$PATH:$_WIN_UNIX_CRT_PATH"
-    dnl Statically link the C++ stdlib.  We only use this for Breakpad anyway.
-    AC_DEFINE(_STATIC_CPPLIB)
-    dnl Don't generate a manifest, since we're linking to a custom CRT.
-    LDFLAGS="$LDFLAGS -MANIFEST:NO"
-    dnl Also pass this to NSPR/NSS
-    DLLFLAGS="$DLLFLAGS -MANIFEST:NO"
+      dnl trunk set-up.
+      if test -z "$WIN32_CRT_SRC_DIR"; then
+        if test -z "$VCINSTALLDIR" -o ! -d "$VCINSTALLDIR"; then
+          AC_MSG_ERROR([When building jemalloc, set WIN32_CRT_SRC_DIR to the path to the Visual C++ CRT source (usually VCINSTALLDIR\crt\src, but VCINSTALLDIR is not set, so I can't autodetect it for you).])
+        else
+          WIN32_CRT_SRC_DIR="$VCINSTALLDIR\crt\src"
+        fi
+      fi
+
+      if test ! -d "$WIN32_CRT_SRC_DIR"; then
+        AC_MSG_ERROR([Invalid Win32 CRT source directory: ${WIN32_CRT_SRC_DIR}])
+      fi
+      WIN32_CRT_SRC_DIR=`cd "$WIN32_CRT_SRC_DIR" && pwd -W`
+      _objdir_win=`pwd -W`
+      WIN32_CUSTOM_CRT_DIR="$_objdir_win/mozilla/memory/jemalloc/crtsrc/build/intel"
+      dnl Statically link the C++ stdlib.  We only use this for Breakpad anyway.
+      AC_DEFINE(_STATIC_CPPLIB)
+
+      MOZ_MEMORY_LDFLAGS="-MANIFEST:NO -LIBPATH:\"$WIN32_CUSTOM_CRT_DIR\" -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcrtd -DEFAULTLIB:mozcrt19"
+      dnl Also pass this to NSPR/NSS
+      DLLFLAGS="$DLLFLAGS $MOZ_MEMORY_LDFLAGS"
+    fi
     export DLLFLAGS
     ;;
   *)
     AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
     ;;
   esac
 
   AC_ARG_WITH([valgrind],
     [  --with-valgrind         Enable valgrind integration hooks],
     [enable_valgrind="yes"], [enable_valgrind="no"])
   AC_CHECK_HEADER([valgrind/valgrind.h], [], [enable_valgrind="no"])
   if test "x$enable_valgrind" = "xyes" ; then
     AC_DEFINE(MOZ_VALGRIND)
   fi
 fi
 AC_SUBST(MOZ_MEMORY)
-AC_SUBST(WIN32_CRT_SRC_DIR)
+dnl only applies to !MOZILLA_1_9_1_BRANCH
+AC_SUBST(MOZ_MEMORY_LDFLAGS)
+dnl these apply to MOZILLA_1_9_1_BRANCH
 AC_SUBST(WIN32_CUSTOM_CRT_DIR)
 AC_SUBST(MOZ_LIB)
 AC_SUBST(MOZ_PATH)
+dnl end apply to MOZILLA_1_9_1_BRANCH
+AC_SUBST(WIN32_CRT_SRC_DIR)
 dnl Need to set this for make because NSS doesn't have configure
 AC_SUBST(DLLFLAGS)
 
 dnl ========================================================
 dnl = Use malloc wrapper lib
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(wrap-malloc,
 [  --enable-wrap-malloc    Wrap malloc calls (gnu linker only)],