mozglue/build/Makefile.in

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mozglue/build/Makefile.in	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,178 @@
     1.4 +#
     1.5 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +
     1.9 +DIST_INSTALL = 1
    1.10 +
    1.11 +# For FORCE_SHARED_LIB
    1.12 +include $(topsrcdir)/config/config.mk
    1.13 +
    1.14 +ifneq (1_1,$(MOZ_MEMORY)_$(or $(MOZ_NATIVE_JEMALLOC),$(FORCE_SHARED_LIB)))
    1.15 +
    1.16 +ifneq (,$(filter WINNT,$(OS_ARCH)))
    1.17 +SDK_LIBRARY = $(IMPORT_LIBRARY)
    1.18 +else
    1.19 +ifdef FORCE_SHARED_LIB
    1.20 +SDK_LIBRARY = $(SHARED_LIBRARY)
    1.21 +else
    1.22 +SDK_LIBRARY = $(REAL_LIBRARY)
    1.23 +endif
    1.24 +endif
    1.25 +
    1.26 +endif
    1.27 + 
    1.28 +MOZ_GLUE_LDFLAGS = # Don't link against ourselves
    1.29 +
    1.30 +SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,mfbt,$(DEPTH)/mfbt)
    1.31 +
    1.32 +ifneq (,$(ZLIB_IN_MOZGLUE)$(MOZ_LINKER))
    1.33 +ifdef MOZ_NATIVE_ZLIB
    1.34 +EXTRA_DSO_LDOPTS += $(MOZ_ZLIB_LIBS)
    1.35 +else
    1.36 +SHARED_LIBRARY_LIBS += $(MOZ_ZLIB_LIBS)
    1.37 +endif
    1.38 +endif
    1.39 +
    1.40 +ifeq (WINNT,$(OS_TARGET))
    1.41 +mozglue.def: mozglue.def.in
    1.42 +	$(call py_action,preprocessor,$(if $(MOZ_REPLACE_MALLOC),-DMOZ_REPLACE_MALLOC) $(ACDEFINES) $< -o $@)
    1.43 +
    1.44 +GARBAGE += mozglue.def
    1.45 +
    1.46 +ifneq (,$(filter -DEFAULTLIB:mozcrt,$(MOZ_GLUE_LDFLAGS)))
    1.47 +# Don't install the import library if we use mozcrt
    1.48 +NO_INSTALL_IMPORT_LIBRARY = 1
    1.49 +endif
    1.50 +
    1.51 +
    1.52 +EXTRA_DSO_LDOPTS += \
    1.53 +	$(call EXPAND_LIBNAME,version) \
    1.54 +	$(NULL)
    1.55 +
    1.56 +endif
    1.57 +
    1.58 +ifeq (Darwin_1,$(OS_TARGET)_$(MOZ_REPLACE_MALLOC))
    1.59 +EXTRA_DSO_LDOPTS += \
    1.60 +  -Wl,-U,_replace_init \
    1.61 +  -Wl,-U,_replace_malloc \
    1.62 +  -Wl,-U,_replace_posix_memalign \
    1.63 +  -Wl,-U,_replace_aligned_alloc \
    1.64 +  -Wl,-U,_replace_calloc \
    1.65 +  -Wl,-U,_replace_realloc \
    1.66 +  -Wl,-U,_replace_free \
    1.67 +  -Wl,-U,_replace_memalign \
    1.68 +  -Wl,-U,_replace_valloc \
    1.69 +  -Wl,-U,_replace_malloc_usable_size \
    1.70 +  -Wl,-U,_replace_malloc_good_size \
    1.71 +  -Wl,-U,_replace_jemalloc_stats \
    1.72 +  -Wl,-U,_replace_jemalloc_purge_freed_pages \
    1.73 +  -Wl,-U,_replace_jemalloc_free_dirty_pages \
    1.74 +  $(NULL)
    1.75 +
    1.76 +ifneq ($(MOZ_REPLACE_MALLOC_LINKAGE),compiler support)
    1.77 +EXTRA_DSO_LDOPTS += -flat_namespace
    1.78 +endif
    1.79 +ifeq ($(MOZ_REPLACE_MALLOC_LINKAGE),dummy library)
    1.80 +EXTRA_DSO_LDOPTS += -Wl,-weak_library,$(DEPTH)/memory/replace/dummy/$(DLL_PREFIX)replace_malloc$(DLL_SUFFIX)
    1.81 +endif
    1.82 +endif
    1.83 +
    1.84 +ifeq (android, $(MOZ_WIDGET_TOOLKIT))
    1.85 +# To properly wrap jemalloc's pthread_atfork call.
    1.86 +EXTRA_DSO_LDOPTS += -Wl,--wrap=pthread_atfork
    1.87 +endif
    1.88 +
    1.89 +ifdef MOZ_LINKER
    1.90 +ifeq (arm, $(TARGET_CPU))
    1.91 +EXTRA_DSO_LDOPTS += -Wl,-version-script,$(srcdir)/arm-eabi-filter
    1.92 +endif
    1.93 +
    1.94 +endif
    1.95 +
    1.96 +ifeq (Android, $(OS_TARGET))
    1.97 +WRAP_LDFLAGS := $(filter -Wl%,$(WRAP_LDFLAGS))
    1.98 +endif
    1.99 +
   1.100 +include $(topsrcdir)/config/rules.mk
   1.101 +
   1.102 +ifdef MOZ_MEMORY
   1.103 +ifeq (WINNT,$(OS_TARGET))
   1.104 +# Roll our own custom logic here for the import library
   1.105 +
   1.106 +###############################################################################
   1.107 +#
   1.108 +# Linking Mozilla itself to jemalloc is not particularly difficult.  To do this
   1.109 +# we avoid linking directly to the Microsoft-provided CRT import libraries.
   1.110 +# Instead, we link to our own import library which we generate here.  To
   1.111 +# replace the CRT's malloc/free/other memory management symbols we export
   1.112 +# our own versions out of jemalloc.dll.  We then take the import library that
   1.113 +# the compiler generates for jemalloc.dll and combine it with the MS CRT import
   1.114 +# libraries.  We put our library on the command line first, and the CRT symbols
   1.115 +# are discarded in favor of our versions!
   1.116 +#
   1.117 +# Unfortunately that was too easy.  The CRT import library is not a standard
   1.118 +# import library that contains a list of symbols and whatnot.  It also includes
   1.119 +# object files that are linked into generated programs.  One of these,
   1.120 +# crtdll.obj is (as one might expect) linked into all DLLs that link against
   1.121 +# the CRT.  This file does things like run static C++ constructors when the
   1.122 +# DLL is attached, call DllMain, etc.
   1.123 +#
   1.124 +# In the CRT source all malloc/free calls are made to malloc_crt and free_crt.
   1.125 +# In debug builds these are both defined to malloc_dbg and free_dbg.  In opt
   1.126 +# builds malloc_crt is an actual function, implemented and exposed from the
   1.127 +# CRT.  free_crt is, however, defined to be just plain old free.  This works
   1.128 +# fine inside the CRT where malloc_crt and free operate on the same heap.
   1.129 +# Outside the CRT malloc_crt is in the CRT's heap, but free is in jemalloc's
   1.130 +# heap.  This causes much pain at shutdown :-(
   1.131 +#
   1.132 +# The obvious solution here is to override malloc_crt too.  Unfortunately,
   1.133 +# that doesn't work because the CRT expects to be able to call msize on this
   1.134 +# piece of memory deep inside the CRT, which will fail because it'll call the
   1.135 +# CRT's msize on a pointer in jemalloc's heap.
   1.136 +#
   1.137 +# Our solution to this is quite devious.  We take apart the CRT's import lib
   1.138 +# and remove the problematic object file.  We then poke at the object file's
   1.139 +# symbol table and replace '__imp__free' (which means grab free from some
   1.140 +# other DLL) with '__imp__frex'.  Then we define our own dummy no-op function
   1.141 +# in jemalloc.dll and export it as frex.  Then we put the CRT import lib
   1.142 +# back together with the patched crtdll.obj, glue it to the end of jemalloc's
   1.143 +# import library and link the rest of Mozilla to that.
   1.144 +#
   1.145 +# The result?  A binary that uses jemalloc, doesn't crash, and leaks a tiny
   1.146 +# amount of memory (32 words per DLL in the 2010 CRT) at shutdown.
   1.147 +#
   1.148 +###############################################################################
   1.149 +
   1.150 +libs:: mozcrt.lib
   1.151 +	$(INSTALL) $(IFLAGS2) mozcrt.lib $(DIST)/lib
   1.152 +
   1.153 +# And finally combine that with the jemalloc import library to get an import
   1.154 +# library that has our malloc/free/etc and the CRT's everything else
   1.155 +mozcrt.lib: $(IMPORT_LIBRARY) msvc_modified.lib
   1.156 +	lib -OUT:$@ $^
   1.157 +
   1.158 +# Put the fixed object file back in
   1.159 +msvc_modified.lib: msvc_removed.lib crtdll_fixed.obj
   1.160 +	lib -OUT:$@ $^
   1.161 +
   1.162 +# Fix the object file
   1.163 +crtdll_fixed.obj: crtdll.obj
   1.164 +	$(PYTHON) $(srcdir)/fixcrt.py
   1.165 +
   1.166 +# Find the path of crtdll.obj
   1.167 +CRTDLL_FULLPATH=$(subst \,\\,$(shell lib -list msvc_combined.lib | grep crtdll\\.obj))
   1.168 +
   1.169 +# Remove the broken object file, only after we have extracted it
   1.170 +msvc_removed.lib: msvc_combined.lib crtdll.obj
   1.171 +	lib -OUT:$@ msvc_combined.lib -REMOVE:$(CRTDLL_FULLPATH)
   1.172 +
   1.173 +# Extract the broken object file out of the combined library
   1.174 +crtdll.obj: msvc_combined.lib
   1.175 +	lib -OUT:$@ $^ -EXTRACT:$(CRTDLL_FULLPATH)
   1.176 +
   1.177 +# Grab both CRT libraries and combine them into one library to simplify things
   1.178 +msvc_combined.lib:
   1.179 +	lib -OUT:$@ $(WIN32_CRT_LIBS)
   1.180 +endif
   1.181 +endif # MOZ_MEMORY

mercurial