bug 361343 - make profiledbuild work on windows. r=bsmedberg
--- a/Makefile.in
+++ b/Makefile.in
@@ -204,8 +204,18 @@ deliver: splitsymbols rebase signnss
endif # WINNT
ifneq (,$(wildcard $(DIST)/bin/application.ini))
BUILDID = $(shell $(PYTHON) $(srcdir)/config/printconfigsetting.py $(DIST)/bin/application.ini App BuildID)
else
BUILDID = $(shell $(PYTHON) $(srcdir)/config/printconfigsetting.py $(DIST)/bin/platform.ini Build BuildID)
endif
+
+#XXX: this is a hack, since we don't want to clobber for MSVC
+# PGO support, but we can't do this test in client.mk
+ifneq ($(OS_ARCH)_$(GNU_CC), WINNT_)
+maybe_clobber_profiledbuild: clobber_all
+else
+maybe_clobber_profiledbuild:
+endif
+
+.PHONY: maybe_clobber_profiledbuild
new file mode 100755
--- /dev/null
+++ b/build/win32/pgomerge.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+# Usage: pgomerge.py <binary basename> <dist/bin>
+# Gathers .pgc files from dist/bin and merges them into
+# $PWD/$basename.pgd using pgomgr, then deletes them.
+# No errors if any of these files don't exist.
+
+import sys, os, os.path, subprocess
+if not sys.platform == "win32":
+ raise Exception("This script was only meant for Windows.")
+
+def MergePGOFiles(basename, pgddir, pgcdir):
+ """Merge pgc files produced from an instrumented binary
+ into the pgd file for the second pass of profile-guided optimization
+ with MSVC. |basename| is the name of the DLL or EXE without the
+ extension. |pgddir| is the path that contains <basename>.pgd
+ (should be the objdir it was built in). |pgcdir| is the path
+ containing basename!N.pgc files, which is probably dist/bin.
+ Calls pgomgr to merge each pgc file into the pgd, then deletes
+ the pgc files."""
+ if not os.path.isdir(pgddir) or not os.path.isdir(pgcdir):
+ return
+ pgdfile = os.path.abspath(os.path.join(pgddir, basename + ".pgd"))
+ if not os.path.isfile(pgdfile):
+ return
+ for file in os.listdir(pgcdir):
+ if file.startswith(basename) and file.endswith(".pgc"):
+ try:
+ pgcfile = os.path.normpath(os.path.join(pgcdir, file))
+ subprocess.call(['pgomgr', '-merge',
+ pgcfile,
+ pgdfile])
+ os.remove(pgcfile)
+ except OSError:
+ pass
+
+if __name__ == '__main__':
+ if len(sys.argv) != 3:
+ print >>sys.stderr, "Usage: pgomerge.py <binary basename> <dist/bin>"
+ sys.exit(1)
+ MergePGOFiles(sys.argv[1], os.getcwd(), sys.argv[2])
--- a/client.mk
+++ b/client.mk
@@ -1092,19 +1092,18 @@ build:: $(OBJDIR)/Makefile $(OBJDIR)/co
# mk_add_options PROFILE_GEN_SCRIPT=/path/to/profile-script
#
# The profile script should exercise the functionality to be included
# in the profile feedback.
profiledbuild:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
$(MOZ_MAKE) MOZ_PROFILE_GENERATE=1
OBJDIR=${OBJDIR} $(PROFILE_GEN_SCRIPT)
- $(MOZ_MAKE) clobber_all
+ $(MOZ_MAKE) maybe_clobber_profiledbuild
$(MOZ_MAKE) MOZ_PROFILE_USE=1
- find $(OBJDIR) -name "*.da" -exec rm {} \;
####################################
# Other targets
# Pass these target onto the real build system
install export libs clean realclean distclean alldep:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
$(MOZ_MAKE) $@
--- a/config/config.mk
+++ b/config/config.mk
@@ -351,33 +351,47 @@ DSO_CFLAGS=
ifeq ($(OS_ARCH)_$(HAVE_GCC3_ABI),Darwin_1)
DSO_PIC_CFLAGS=-mdynamic-no-pic
else
DSO_PIC_CFLAGS=
endif
endif
# Enable profile-based feedback
+ifndef NO_PROFILE_GUIDED_OPTIMIZE
ifdef MOZ_PROFILE_GENERATE
# No sense in profiling tools
ifndef INTERNAL_TOOLS
OS_CFLAGS += $(PROFILE_GEN_CFLAGS)
OS_CXXFLAGS += $(PROFILE_GEN_CFLAGS)
-endif # INTERNAL_TOOLS
+OS_LDFLAGS += $(PROFILE_GEN_LDFLAGS)
+ifeq (WINNT,$(OS_ARCH))
+AR_FLAGS += -LTCG
+endif
+else
+# We don't want to link internal tools with profiling,
+# but gcc needs to because xpidl will wind up linking with
+# libs that have been built with PROFILE_GEN_CFLAGS.
+ifdef GNU_CC
OS_LDFLAGS += $(PROFILE_GEN_LDFLAGS)
endif
+endif # INTERNAL_TOOLS
+endif # MOZ_PROFILE_GENERATE
-# We always use the profile-use flags, even in cases where we didn't use the
-# profile-generate flags. It's harmless, and it saves us from having to
-# answer the question "Would these objects have been built using
-# the profile-generate flags?" which is not trivial.
ifdef MOZ_PROFILE_USE
+ifndef INTERNAL_TOOLS
OS_CFLAGS += $(PROFILE_USE_CFLAGS)
OS_CXXFLAGS += $(PROFILE_USE_CFLAGS)
+OS_LDFLAGS += $(PROFILE_USE_LDFLAGS)
+ifeq (WINNT,$(OS_ARCH))
+AR_FLAGS += -LTCG
endif
+endif # INTERNAL_TOOLS
+endif # MOZ_PROFILE_USE
+endif # NO_PROFILE_GUIDED_OPTIMIZE
# Does the makefile specifies the internal XPCOM API linkage?
ifneq (,$(MOZILLA_INTERNAL_API)$(LIBXUL_LIBRARY))
DEFINES += -DMOZILLA_INTERNAL_API
endif
# Force XPCOM/widget/gfx methods to be _declspec(dllexport) when we're
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -779,16 +779,47 @@ else
$(INSTALL) $(IFLAGS1) $(JAVA_LIBRARY) $(FINAL_TARGET)
endif
endif # JAVA_LIBRARY
endif # !NO_DIST_INSTALL
+$(LOOP_OVER_DIRS)
##############################################
+ifndef NO_PROFILE_GUIDED_OPTIMIZE
+ifneq (,$(MOZ_PROFILE_GENERATE)$(MOZ_PROFILE_USE))
+ifeq ($(OS_ARCH)_$(GNU_CC)$(INTERNAL_TOOLS), WINNT_)
+# Force re-linking when building with PGO, since
+# the MSVC linker does all the work. We force re-link
+# in both stages so you can do depend builds with PGO.
+ifdef SHARED_LIBRARY
+$(SHARED_LIBRARY): FORCE
+BINARY_BASENAME = $(SHARED_LIBRARY:$(DLL_SUFFIX)=)
+endif
+ifdef PROGRAM
+$(PROGRAM): FORCE
+BINARY_BASENAME = $(PROGRAM:$(BIN_SUFFIX)=)
+endif
+
+ifdef MOZ_PROFILE_USE
+# In the second pass, we need to merge the pgc files into the pgd file.
+# The compiler would do this for us automatically if they were in the right
+# place, but they're in dist/bin.
+ifdef BINARY_BASENAME
+export::
+ $(PYTHON) $(topsrcdir)/build/win32/pgomerge.py \
+ $(BINARY_BASENAME) $(DIST)/bin
+endif
+endif # MOZ_PROFILE_USE
+endif # WINNT_
+endif # MOZ_PROFILE_GENERATE || MOZ_PROFILE_USE
+endif # NO_PROFILE_GUIDED_OPTIMIZE
+
+##############################################
+
checkout:
$(MAKE) -C $(topsrcdir) -f client.mk checkout
run_viewer: $(FINAL_TARGET)/viewer
cd $(FINAL_TARGET); \
MOZILLA_FIVE_HOME=`pwd` \
LD_LIBRARY_PATH=".:$(LIBS_PATH):$$LD_LIBRARY_PATH" \
viewer
--- a/configure.in
+++ b/configure.in
@@ -1915,16 +1915,22 @@ case "$target" in
MOZ_FIX_LINK_PATHS=
DYNAMIC_XPCOM_LIBS='$(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xpcom_core.lib'
XPCOM_FROZEN_LDOPTS='$(LIBXUL_DIST)/lib/xpcom.lib'
LIBXUL_LIBS='$(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xul.lib'
MOZ_COMPONENT_NSPR_LIBS='$(NSPR_LIBS)'
MOZ_XPCOM_OBSOLETE_LIBS='$(LIBXUL_DIST)/lib/xpcom_compat.lib'
if test $_MSC_VER -ge 1400; then
LDFLAGS="$LDFLAGS -NXCOMPAT -SAFESEH"
+ # For profile-guided optimization
+ PROFILE_GEN_CFLAGS="-GL"
+ PROFILE_GEN_LDFLAGS="-LTCG:PGINSTRUMENT"
+ PROFILE_USE_CFLAGS="-GL"
+ #XXX: should be -LTCG:PGOPTIMIZE, but that fails on libxul
+ PROFILE_USE_LDFLAGS="-LTCG:PGUPDATE"
fi
fi
MOZ_JPEG_LIBS='$(call EXPAND_LIBNAME_PATH,jpeg$(MOZ_BITS)$(VERSION_NUMBER),$(DEPTH)/jpeg)'
MOZ_PNG_LIBS='$(call EXPAND_LIBNAME_PATH,png,$(DEPTH)/modules/libimg/png)'
AC_DEFINE(HAVE_SNPRINTF)
AC_DEFINE(_WINDOWS)
AC_DEFINE(_WIN32)
AC_DEFINE(WIN32)
@@ -6509,16 +6515,19 @@ if test "$_IGNORE_LONG_LONG_WARNINGS"; t
AC_TRY_COMPILE([], [return(0);],
[ _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} ${_COMPILER_PREFIX}-Wno-long-long"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} ${_COMPILER_PREFIX}-Wno-long-long"
result="yes" ], result="no")
AC_MSG_RESULT([$result])
CFLAGS="$_SAVE_CFLAGS"
fi
+dnl ========================================================
+dnl Profile guided optimization
+dnl ========================================================
dnl Test for profiling options
dnl Under gcc 3.3, use -fprofile-arcs/-fbranch-probabilities
dnl Under gcc 3.4+, use -fprofile-generate/-fprofile-use
_SAVE_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fprofile-generate"
AC_MSG_CHECKING([whether C compiler supports -fprofile-generate])