Bug 1481633 Resolve kPStaticModules undefined symbols in MinGW Clang r=glandium
authorTom Ritter <tom@mozilla.com>
Tue, 11 Sep 2018 03:20:06 +0000
changeset 435604 c73d63442c8daccada03c850df06bc52e631545d
parent 435603 8d4bac2ca4dace70a1388b0791aaa4774ef73513
child 435605 fddf77dc2f9d02172eaed2e04289b22df4168864
push id69061
push userapavel@mozilla.com
push dateTue, 11 Sep 2018 03:54:44 +0000
treeherderautoland@c73d63442c8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1481633
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1481633 Resolve kPStaticModules undefined symbols in MinGW Clang r=glandium clang can handle MSVC-like codepaths generally, so we want to use those when building with clang for Windows. So we switch _MSC_VER over to _WIN32 to pick up those codepaths when compiling for Windows with clang. Additionally, we relax the ordering of sections for the same scenario. Note that we do need to tell clang to use -fms-extensions with the MSVC code, we do that in the mingw clang build job patch. Differential Revision: https://phabricator.services.mozilla.com/D3526
python/mozbuild/mozbuild/action/check_binary.py
xpcom/components/Module.h
xpcom/components/nsComponentManager.cpp
--- a/python/mozbuild/mozbuild/action/check_binary.py
+++ b/python/mozbuild/mozbuild/action/check_binary.py
@@ -217,18 +217,21 @@ def check_nsmodules(target, binary):
         for addr, size, sym in symbols:
             print('%x %d %s' % (addr, size, sym))
 
     symbols = sorted(symbols)
     next_addr = None
     # MSVC linker, when doing incremental linking, adds padding when
     # merging sections. Allow there to be more space between the NSModule
     # symbols, as long as they are in the right order.
-    if buildconfig.substs.get('_MSC_VER') and \
-            buildconfig.substs.get('DEVELOPER_OPTIONS'):
+    test_msvc = (buildconfig.substs.get('_MSC_VER') and \
+        buildconfig.substs.get('DEVELOPER_OPTIONS'))
+    test_clang = (buildconfig.substs.get('CC_TYPE') == 'clang' and \
+        buildconfig.substs.get('OS_ARCH') == 'WINNT')
+    if test_msvc or test_clang:
         sym_cmp = lambda guessed, actual: guessed <= actual
     else:
         sym_cmp = lambda guessed, actual: guessed == actual
 
     for addr, size, sym in symbols:
         if next_addr is not None and not sym_cmp(next_addr, addr):
             print_symbols(symbols)
             raise RuntimeError('NSModules are not adjacent')
--- a/xpcom/components/Module.h
+++ b/xpcom/components/Module.h
@@ -128,17 +128,17 @@ struct Module
    */
   ProcessSelector selector;
 };
 
 } // namespace mozilla
 
 #if defined(MOZILLA_INTERNAL_API)
 #  define NSMODULE_NAME(_name) _name##_NSModule
-#  if defined(_MSC_VER)
+#  if defined(_MSC_VER) || (defined(__clang__) && defined(__MINGW32__))
 #    pragma section(".kPStaticModules$M", read)
 #    pragma comment(linker, "/merge:.kPStaticModules=.rdata")
 #    define NSMODULE_SECTION __declspec(allocate(".kPStaticModules$M"), dllexport)
 #  elif defined(__GNUC__)
 #    if defined(__ELF__)
 #      define NSMODULE_SECTION __attribute__((section("kPStaticModules"), visibility("default")))
 #    elif defined(__MACH__)
 #      define NSMODULE_SECTION __attribute__((section("__DATA, .kPStaticModules"), visibility("default")))
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -275,17 +275,17 @@ static nsTArray<const mozilla::Module*>*
  * On Windows, the __start_kPStaticModules symbol points to an empty pointer
  * preceding the first NSModule pointer. On other platforms, it points to the
  * first NSModule pointer.
  */
 
 // Dummy class to define a range-iterator for the static modules.
 class AllStaticModules {};
 
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) || (defined(__clang__) && defined(__MINGW32__))
 
 #  pragma section(".kPStaticModules$A", read)
 NSMODULE_ASAN_BLACKLIST __declspec(allocate(".kPStaticModules$A"), dllexport)
 extern mozilla::Module const* const __start_kPStaticModules = nullptr;
 
 mozilla::Module const* const* begin(AllStaticModules& _) {
     return &__start_kPStaticModules + 1;
 }