Bug 944800 - Move the information about delay loaded DLLs into moz.build; r=gps
☠☠ backed out by 6a25e4cef8da ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 04 Feb 2014 13:57:34 -0500
changeset 167175 b54e8c328c327943fe5662e9e84bf748a1f97564
parent 167174 06e99d1896ce003326d24eebd7854104748d8f3a
child 167176 1c9290033b333a3765ef16c45bf752fea0ba326f
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersgps
bugs944800
milestone30.0a1
Bug 944800 - Move the information about delay loaded DLLs into moz.build; r=gps
config/config.mk
config/rules.mk
python/mozbuild/mozbuild/frontend/emitter.py
python/mozbuild/mozbuild/frontend/sandbox_symbols.py
python/mozbuild/mozbuild/test/backend/data/variable_passthru/moz.build
python/mozbuild/mozbuild/test/backend/test_recursivemake.py
python/mozbuild/mozbuild/test/frontend/data/variable-passthru/moz.build
python/mozbuild/mozbuild/test/frontend/test_emitter.py
toolkit/library/Makefile.in
toolkit/library/moz.build
toolkit/mozapps/update/updater/Makefile.in
toolkit/mozapps/update/updater/moz.build
--- a/config/config.mk
+++ b/config/config.mk
@@ -410,16 +410,19 @@ OS_CFLAGS += $(if $(filter $(notdir $<),
 OS_CXXFLAGS += $(if $(filter $(notdir $<),$(notdir $(NO_PROFILE_GUIDED_OPTIMIZE))),,$(PROFILE_USE_CFLAGS))
 OS_LDFLAGS += $(PROFILE_USE_LDFLAGS)
 ifeq (WINNT,$(OS_ARCH))
 AR_FLAGS += -LTCG
 endif
 endif # MOZ_PROFILE_USE
 endif # NO_PROFILE_GUIDED_OPTIMIZE
 
+ifdef _MSC_VER
+OS_LDFLAGS += $(DELAYLOAD_LDFLAGS)
+endif # _MSC_VER
 
 # 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
 # building libxul libraries
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -525,16 +525,22 @@ endif
 #
 # GNU doesn't have path length limitation
 #
 
 ifeq ($(OS_ARCH),GNU)
 OS_CPPFLAGS += -DPATH_MAX=1024 -DMAXPATHLEN=1024
 endif
 
+ifeq ($(OS_ARCH),WINNT)
+ifdef USE_DELAYIMP
+OS_LIBS += $(call EXPAND_LIBNAME,delayimp)
+endif
+endif
+
 #
 # MINGW32
 #
 ifeq ($(OS_ARCH),WINNT)
 ifdef GNU_CC
 ifndef IS_COMPONENT
 DSO_LDOPTS += -Wl,--out-implib -Wl,$(IMPORT_LIBRARY)
 endif
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -241,16 +241,20 @@ class TreeMetadataEmitter(LoggingMixin):
         for v in varlist:
             if v in sandbox and sandbox[v]:
                 passthru.variables[v] = sandbox[v]
 
         # NO_VISIBILITY_FLAGS is slightly different
         if sandbox['NO_VISIBILITY_FLAGS']:
             passthru.variables['VISIBILITY_FLAGS'] = ''
 
+        if sandbox['DELAYLOAD_DLLS']:
+            passthru.variables['DELAYLOAD_LDFLAGS'] = [('-DELAYLOAD:%s' % dll) for dll in sandbox['DELAYLOAD_DLLS']]
+            passthru.variables['USE_DELAYIMP'] = True
+
         varmap = dict(
             SOURCES={
                 '.s': 'ASFILES',
                 '.asm': 'ASFILES',
                 '.c': 'CSRCS',
                 '.m': 'CMSRCS',
                 '.mm': 'CMMSRCS',
                 '.cc': 'CPPSRCS',
--- a/python/mozbuild/mozbuild/frontend/sandbox_symbols.py
+++ b/python/mozbuild/mozbuild/frontend/sandbox_symbols.py
@@ -144,16 +144,23 @@ VARIABLES = {
 
            DEFINES.update({
                'NS_NO_XPCOM': True,
                'MOZ_EXTENSIONS_DB_SCHEMA': 15,
                'DLL_SUFFIX': '".so"',
            })
         """, None),
 
+    'DELAYLOAD_DLLS': (list, list,
+        """Delay-loaded DLLs.
+
+        This variable contains a list of DLL files which the module being linked
+        should load lazily.  This only has an effect when building with MSVC.
+        """, 'binaries'),
+
     'DIRS': (list, list,
         """Child directories to descend into looking for build frontend files.
 
         This works similarly to the ``DIRS`` variable in make files. Each str
         value in the list is the name of a child directory. When this file is
         done parsing, the build reader will descend into each listed directory
         and read the frontend file there. If there is no frontend file, an error
         is raised.
--- a/python/mozbuild/mozbuild/test/backend/data/variable_passthru/moz.build
+++ b/python/mozbuild/mozbuild/test/backend/data/variable_passthru/moz.build
@@ -28,8 +28,11 @@ SOURCES += ['bar.c', 'foo.c']
 SOURCES += ['bar.mm', 'foo.mm']
 
 SOURCES += ['baz.S', 'foo.S']
 
 FAIL_ON_WARNINGS = True
 LIBXUL_LIBRARY = True
 MSVC_ENABLE_PGO = True
 NO_VISIBILITY_FLAGS = True
+
+if CONFIG['_MSC_VER']:
+    DELAYLOAD_DLLS = ['foo.dll', 'bar.dll']
--- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
+++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
@@ -316,16 +316,19 @@ class TestRecursiveMakeBackend(BackendTe
             ],
             'SSRCS': [
                 'SSRCS += baz.S',
                 'SSRCS += foo.S',
             ],
             'VISIBILITY_FLAGS': [
                 'VISIBILITY_FLAGS :=',
             ],
+            'DELAYLOAD_DLLS': [
+                'EXTRA_DSO_LDOPTS :=',
+            ],
         }
 
         for var, val in expected.items():
             # print("test_variable_passthru[%s]" % (var))
             found = [str for str in lines if str.startswith(var)]
             self.assertEqual(found, val)
 
     def test_exports(self):
--- a/python/mozbuild/mozbuild/test/frontend/data/variable-passthru/moz.build
+++ b/python/mozbuild/mozbuild/test/frontend/data/variable-passthru/moz.build
@@ -34,8 +34,11 @@ LIBXUL_LIBRARY = True
 MSVC_ENABLE_PGO = True
 
 NO_DIST_INSTALL = True
 
 FORCE_SHARED_LIB = True
 EXPORT_LIBRARY = True
 IS_COMPONENT = True
 NO_VISIBILITY_FLAGS = True
+
+if CONFIG['_MSC_VER']:
+    DELAYLOAD_DLLS = ['foo.dll', 'bar.dll']
--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
@@ -164,16 +164,17 @@ class TestEmitterBasic(unittest.TestCase
             LIBS=['fans.lib', 'tans.lib'],
             LIBXUL_LIBRARY=True,
             MSVC_ENABLE_PGO=True,
             NO_DIST_INSTALL=True,
             OS_LIBS=['foo.so', '-l123', 'aaa.a'],
             SDK_LIBRARY=['fans.sdk', 'tans.sdk'],
             SSRCS=['bans.S', 'fans.S'],
             VISIBILITY_FLAGS='',
+            DELAYLOAD_DLLS=['foo.dll', 'bar.dll'],
         )
 
         variables = objs[0].variables
         maxDiff = self.maxDiff
         self.maxDiff = None
         self.assertEqual(wanted, variables)
         self.maxDiff = maxDiff
 
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -293,48 +293,16 @@ endif
 ifeq ($(OS_ARCH),WINNT)
 OS_LIBS += $(call EXPAND_LIBNAME,shell32 ole32 version winspool comdlg32 imm32 msimg32 shlwapi psapi ws2_32 dbghelp rasapi32 rasdlg iphlpapi uxtheme setupapi secur32 sensorsapi portabledeviceguids windowscodecs wininet wbemuuid)
 ifdef ACCESSIBILITY
 OS_LIBS += $(call EXPAND_LIBNAME,oleacc)
 endif
 ifdef MOZ_METRO
 OS_LIBS += $(call EXPAND_LIBNAME,uiautomationcore runtimeobject)
 endif
-ifdef _MSC_VER
-OS_LIBS += $(call EXPAND_LIBNAME,delayimp)
-EXTRA_DSO_LDOPTS += \
-  -DELAYLOAD:psapi.dll \
-  -DELAYLOAD:dbghelp.dll \
-  -DELAYLOAD:rasapi32.dll \
-  -DELAYLOAD:rasdlg.dll \
-  -DELAYLOAD:comdlg32.dll \
-  -DELAYLOAD:winspool.drv \
-  -DELAYLOAD:secur32.dll \
-  -DELAYLOAD:wininet.dll \
-  $(NULL)
-
-# See nsDllMain for an explanation
-ifdef MOZ_METRO
-ifdef MOZ_DEBUG
-EXTRA_DSO_LDOPTS += -DELAYLOAD:VCCORLIB$(CRTDLLVERSION)D.DLL
-else
-EXTRA_DSO_LDOPTS += -DELAYLOAD:VCCORLIB$(CRTDLLVERSION).DLL
-endif
-EXTRA_DSO_LDOPTS += -DELAYLOAD:API-MS-WIN-CORE-WINRT-L$(CRTEXPDLLVERSION).DLL
-EXTRA_DSO_LDOPTS += -DELAYLOAD:API-MS-WIN-CORE-WINRT-STRING-L$(CRTEXPDLLVERSION).DLL
-EXTRA_DSO_LDOPTS += -DELAYLOAD:uiautomationcore.dll
-endif
-
-ifdef ACCESSIBILITY
-EXTRA_DSO_LDOPTS += -DELAYLOAD:oleacc.dll
-endif
-ifdef MOZ_WEBRTC
-EXTRA_DSO_LDOPTS += -DELAYLOAD:msdmo.dll
-endif
-endif
 ifdef MOZ_GAMEPAD
 ifndef GNU_CC
 DXSDK := $(subst \,/,$(MOZ_DIRECTX_SDK_PATH))/Lib/$(MOZ_DIRECTX_SDK_CPU_SUFFIX)
 OS_LIBS += \
   '$(DXSDK)/dxguid.lib' \
   '$(DXSDK)/dinput8.lib' \
   $(NULL)
 else
--- a/toolkit/library/moz.build
+++ b/toolkit/library/moz.build
@@ -15,8 +15,36 @@ if CONFIG['OS_ARCH'] == 'WINNT':
         'nsDllMain.cpp',
     ]
 
 FAIL_ON_WARNINGS = True
 
 MSVC_ENABLE_PGO = True
 
 FORCE_SHARED_LIB = True
+
+DELAYLOAD_DLLS += [
+    'comdlg32.dll',
+    'dbghelp.dll',
+    'psapi.dll',
+    'rasapi32.dll',
+    'rasdlg.dll',
+    'secur32.dll',
+    'wininet.dll',
+    'winspool.dll'
+]
+
+if CONFIG['MOZ_METRO']:
+    if CONFIG['MOZ_DEBUG']:
+        DELAYLOAD_DLLS += ['VCCORLIB' + CONFIG['CRTDLLVERSION'] + 'D.DLL']
+    else:
+        DELAYLOAD_DLLS += ['VCCORLIB' + CONFIG['CRTDLLVERSION'] + '.DLL']
+    DELAYLOAD_DLLS += [
+        'API-MS-WIN-CORE-WINRT-L' + CONFIG['CRTDLLVERSION'] + '.DLL',
+        'API-MS-WIN-CORE-WINRT-STRING-L' + CONFIG['CRTDLLVERSION'] + '.DLL',
+        'uiautomationcore.dll'
+    ]
+
+if CONFIG['ACCESSIBILITY']:
+    DELAYLOAD_DLLS += ['oleacc.dll']
+
+if CONFIG['MOZ_WEBRTC']:
+    DELAYLOAD_DLLS += ['msdmo.dll']
--- a/toolkit/mozapps/update/updater/Makefile.in
+++ b/toolkit/mozapps/update/updater/Makefile.in
@@ -59,17 +59,16 @@ else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef _MSC_VER
 WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup
-WIN32_EXE_LDFLAGS += -DELAYLOAD:wsock32.dll -DELAYLOAD:crypt32.dll -DELAYLOAD:userenv.dll
 endif
 
 ifdef MOZ_WIDGET_GTK
 libs:: updater.png
 	$(NSINSTALL) -D $(DIST)/bin/icons
 	$(INSTALL) $(IFLAGS1) $^ $(DIST)/bin/icons
 endif
 
--- a/toolkit/mozapps/update/updater/moz.build
+++ b/toolkit/mozapps/update/updater/moz.build
@@ -47,8 +47,14 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'coco
     SOURCES += [
         'launchchild_osx.mm',
         'progressui_osx.mm',
     ]
 
 DEFINES['NS_NO_XPCOM'] = True
 for var in ('MAR_CHANNEL_ID', 'MOZ_APP_VERSION'):
     DEFINES[var] = '"%s"' % CONFIG[var]
+
+DELAYLOAD_DLLS += [
+    'crypt32.dll',
+    'userenv.dll',
+    'wsock32.dll',
+]