Bug 1553363 - Generalize the *_impl goop for allocation functions in mozglue. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 29 May 2019 22:49:42 +0000
changeset 476149 e9cddb23f947853bffeb1cac51cbcadcc3e294e8
parent 476148 b33cfaa24138bd3bd1e167f1736fb6ba0b20d473
child 476150 ea9f5104395dd9af914a27302630210639865378
push id36086
push usershindli@mozilla.com
push dateThu, 30 May 2019 03:47:55 +0000
treeherdermozilla-central@73c98da145a7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1553363
milestone69.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 1553363 - Generalize the *_impl goop for allocation functions in mozglue. r=froydnj The current situation is suboptimal, where we have the same goop repeated in multiple files, and where things kinda sorta work out fine thanks to the linker for files that would have been forbidden, except when the linker doesn't do its job, which apparently happen on mingwclang builds. This change only really covers C++ code using operator new/delete, and not things that would be using malloc/free, because it's easier. malloc/free is left for a followup. Differential Revision: https://phabricator.services.mozilla.com/D32119
ipc/mscom/mozglue/moz.build
memory/mozalloc/moz.build
memory/mozalloc/mozalloc.cpp
memory/mozalloc/mozalloc.h
memory/mozalloc/winheap.cpp
modules/zlib/src/moz.build
mozglue/build/Authenticode.cpp
mozglue/build/UntrustedDllsHandler.cpp
mozglue/build/WindowsDllBlocklist.cpp
mozglue/build/moz.build
mozglue/linker/moz.build
mozglue/misc/interceptor/moz.build
mozglue/misc/moz.build
--- a/ipc/mscom/mozglue/moz.build
+++ b/ipc/mscom/mozglue/moz.build
@@ -1,21 +1,19 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-Library('mscom-mozglue')
+FINAL_LIBRARY = 'mozglue'
 
 EXPORTS.mozilla.mscom += [
     'ProcessRuntimeShared.h',
 ]
 
 LOCAL_INCLUDES += [
     '/mozglue/build',
 ]
 
-DEFINES['IMPL_MFBT'] = True
-
 UNIFIED_SOURCES += [
     'ProcessRuntimeShared.cpp',
 ]
--- a/memory/mozalloc/moz.build
+++ b/memory/mozalloc/moz.build
@@ -40,16 +40,14 @@ if CONFIG['CPU_ARCH'] == 'arm' and CONFI
 
 FINAL_LIBRARY = 'mozglue'
 
 # The strndup declaration in string.h is in an ifdef __USE_GNU section
 DEFINES['_GNU_SOURCE'] = True
 
 DisableStlWrapping()
 
-DEFINES['IMPL_MFBT'] = True
-
 LOCAL_INCLUDES += [
     '!/xpcom',
     '/memory/build',
 ]
 
 DIST_INSTALL = True
--- a/memory/mozalloc/mozalloc.cpp
+++ b/memory/mozalloc/mozalloc.cpp
@@ -2,45 +2,24 @@
  * vim: sw=2 ts=4 et :
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <stddef.h>  // for size_t
 
-#if defined(MOZ_MEMORY)
-// mozalloc.cpp is part of the same library as mozmemory, thus MOZ_MEMORY_IMPL
-// is needed.
-#  define MOZ_MEMORY_IMPL
-#  include "mozmemory_wrap.h"
-
-#  if defined(XP_DARWIN)
-#    include <malloc/malloc.h>  // for malloc_size
-#  endif
+#if defined(MALLOC_H)
+#  include MALLOC_H  // for memalign, malloc_size, malloc_us
+#endif               // if defined(MALLOC_H)
 
-// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
-// it needs to use _impl suffixes. However, with libmozglue growing, this is
-// becoming cumbersome, so we will likely use a malloc.h wrapper of some sort
-// and allow the use of the functions without a _impl suffix.
-#  define MALLOC_DECL(name, return_type, ...) \
-    MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
-#  define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
-#  include "malloc_decls.h"
-
-MOZ_MEMORY_API char* strdup_impl(const char*);
-MOZ_MEMORY_API char* strndup_impl(const char*, size_t);
-
-#else
+#if !defined(MOZ_MEMORY)
 // When jemalloc is disabled, or when building the static runtime variant,
 // we need not to use the suffixes.
 
-#  if defined(MALLOC_H)
-#    include MALLOC_H  // for memalign, malloc_size, malloc_us
-#  endif               // if defined(MALLOC_H)
 #  include <stdlib.h>  // for malloc, free
 #  if defined(XP_UNIX)
 #    include <unistd.h>
 #  endif  // if defined(XP_UNIX)
 
 #  define malloc_impl malloc
 #  define calloc_impl calloc
 #  define realloc_impl realloc
@@ -59,16 +38,21 @@ MOZ_MEMORY_API char* strndup_impl(const 
 #include <sys/types.h>
 
 #include "mozilla/Assertions.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/Likely.h"
 #include "mozilla/mozalloc.h"
 #include "mozilla/mozalloc_oom.h"  // for mozalloc_handle_oom
 
+#if defined(MOZ_MEMORY)
+MOZ_MEMORY_API char* strdup_impl(const char*);
+MOZ_MEMORY_API char* strndup_impl(const char*, size_t);
+#endif
+
 void* moz_xmalloc(size_t size) {
   void* ptr = malloc_impl(size);
   if (MOZ_UNLIKELY(!ptr && size)) {
     mozalloc_handle_oom(size);
     return moz_xmalloc(size);
   }
   return ptr;
 }
--- a/memory/mozalloc/mozalloc.h
+++ b/memory/mozalloc/mozalloc.h
@@ -3,16 +3,29 @@
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_mozalloc_h
 #define mozilla_mozalloc_h
 
+#if defined(MOZ_MEMORY) && defined(IMPL_MFBT)
+#  define MOZ_MEMORY_IMPL
+#  include "mozmemory_wrap.h"
+#  define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
+// See mozmemory_wrap.h for more details. Files that are part of libmozglue,
+// need to use _impl suffixes, which is becoming cumbersome. We'll have to use
+// something like a malloc.h wrapper and allow the use of the functions without
+// a _impl suffix. In the meanwhile, this is enough to get by for C++ code.
+#  define MALLOC_DECL(name, return_type, ...) \
+    MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
+#  include "malloc_decls.h"
+#endif
+
 /*
  * https://bugzilla.mozilla.org/show_bug.cgi?id=427099
  */
 
 #if defined(__cplusplus)
 #  include <new>
 // Since libstdc++ 6, including the C headers (e.g. stdlib.h) instead of the
 // corresponding C++ header (e.g. cstdlib) can cause confusion in C++ code
--- a/memory/mozalloc/winheap.cpp
+++ b/memory/mozalloc/winheap.cpp
@@ -1,40 +1,24 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * vim: sw=2 ts=4 et :
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "mozilla/Types.h"
+#include "mozilla/mozalloc.h"
 #include <windows.h>
 
-#if defined(MOZ_MEMORY)
-// mozalloc.cpp is part of the same library as mozmemory, thus MOZ_MEMORY_IMPL
-// is needed.
-#  define MOZ_MEMORY_IMPL
-#  include "mozmemory_wrap.h"
-
-// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
-// it needs to use _impl suffixes. However, with libmozglue growing, this is
-// becoming cumbersome, so we will likely use a malloc.h wrapper of some sort
-// and allow the use of the functions without a _impl suffix.
-#  define MALLOC_DECL(name, return_type, ...) \
-    MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
-#  define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
-#  include "malloc_decls.h"
-#else
-
+#if !defined(MOZ_MEMORY)
 #  include <malloc.h>
 #  define malloc_impl malloc
 #  define calloc_impl calloc
 #  define realloc_impl realloc
 #  define free_impl free
-
 #endif
 
 // Warning: C4273: 'HeapAlloc': inconsistent dll linkage
 // The Windows headers define HeapAlloc as dllimport, but we define it as
 // dllexport, which is a voluntary inconsistency.
 #pragma warning(disable : 4273)
 
 MFBT_API
--- a/modules/zlib/src/moz.build
+++ b/modules/zlib/src/moz.build
@@ -7,17 +7,16 @@
 EXPORTS += [
     'mozzconf.h',
     'zconf.h',
     'zlib.h',
 ]
 
 if CONFIG['ZLIB_IN_MOZGLUE']:
     FINAL_LIBRARY = 'mozglue'
-    DEFINES['IMPL_MFBT'] = True
 else:
     # The final library is in config/external/zlib
     FINAL_LIBRARY = 'zlib'
     HostLibrary('hostzlib')
 
 # These files can't be unified because zlib's headers don't use include guards.
 SOURCES += [
     'adler32.c',
--- a/mozglue/build/Authenticode.cpp
+++ b/mozglue/build/Authenticode.cpp
@@ -1,26 +1,14 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifdef MOZ_MEMORY
-#  define MOZ_MEMORY_IMPL
-#  include "mozmemory_wrap.h"
-#  define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
-// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
-// it needs to use _impl suffixes.
-#  define MALLOC_DECL(name, return_type, ...) \
-    MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
-#  include "malloc_decls.h"
-#  include "mozilla/mozalloc.h"
-#endif
-
 // We need Windows 8 functions and structures to be able to verify SHA-256.
 #if defined(_WIN32_WINNT)
 #  undef _WIN32_WINNT
 #  define _WIN32_WINNT _WIN32_WINNT_WIN8
 #endif  // defined(_WIN32_WINNT)
 #if defined(NTDDI_VERSION)
 #  undef NTDDI_VERSION
 #  define NTDDI_VERSION NTDDI_WIN8
--- a/mozglue/build/UntrustedDllsHandler.cpp
+++ b/mozglue/build/UntrustedDllsHandler.cpp
@@ -1,26 +1,14 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifdef MOZ_MEMORY
-#  define MOZ_MEMORY_IMPL
-#  include "mozmemory_wrap.h"
-#  define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
-// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
-// it needs to use _impl suffixes.
-#  define MALLOC_DECL(name, return_type, ...) \
-    MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
-#  include "malloc_decls.h"
-#  include "mozilla/mozalloc.h"
-#endif
-
 #include "UntrustedDllsHandler.h"
 
 #include <windows.h>
 
 #include "mozilla/Atomics.h"
 #include "mozilla/mozalloc.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/StaticPtr.h"
--- a/mozglue/build/WindowsDllBlocklist.cpp
+++ b/mozglue/build/WindowsDllBlocklist.cpp
@@ -1,25 +1,13 @@
 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifdef MOZ_MEMORY
-#  define MOZ_MEMORY_IMPL
-#  include "mozmemory_wrap.h"
-#  define MALLOC_FUNCS MALLOC_FUNCS_MALLOC
-// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
-// it needs to use _impl suffixes.
-#  define MALLOC_DECL(name, return_type, ...) \
-    MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
-#  include "malloc_decls.h"
-#  include "mozilla/mozalloc.h"
-#endif
-
 #include <windows.h>
 #include <winternl.h>
 
 #pragma warning(push)
 #pragma warning(disable : 4275 4530)  // See msvc-stl-wrapper.template.h
 #include <map>
 #pragma warning(pop)
 
--- a/mozglue/build/moz.build
+++ b/mozglue/build/moz.build
@@ -73,23 +73,16 @@ if CONFIG['MOZ_WIDGET_TOOLKIT']:
         EXPORTS.mozilla += [
             'Authenticode.h',
             'WindowsDllBlocklistCommon.h',
             'WindowsDllBlocklistDefs.h',
         ]
         EXPORTS.mozilla.glue += [
             'WindowsDllServices.h',
         ]
-        USE_LIBS += [
-            'mscom-mozglue',
-        ]
-        if CONFIG['CPU_ARCH'] == 'aarch64':
-            USE_LIBS += [
-                'interceptor',
-            ]
 
     EXPORTS.mozilla += [
         'arm.h',
         'mips.h',
         'SSE.h',
         'WindowsDllBlocklist.h',
     ]
 
@@ -112,17 +105,17 @@ if CONFIG['MOZ_WIDGET_TOOLKIT']:
         USE_LIBS += [
             'zlib',
         ]
 
 USE_LIBS += [
     'mfbt',
 ]
 
-DEFINES['IMPL_MFBT'] = True
+LIBRARY_DEFINES['IMPL_MFBT'] = True
 LIBRARY_DEFINES['MOZ_HAS_MOZGLUE'] = True
 
 if CONFIG['OS_TARGET'] == 'Darwin':
     # On OSX 10.10.3, a dead lock happens in some cases involving dynamic
     # symbol resolution for symbols that jemalloc itself uses. While it
     # might be possible to find a way to avoid all such symbol resolutions,
     # it's currently not possible because at the very least there's a call
     # to pthread_self from tsd_init_check_recursion, which is necessary
--- a/mozglue/linker/moz.build
+++ b/mozglue/linker/moz.build
@@ -12,18 +12,16 @@ SOURCES += [
     'XZStream.cpp',
     'Zip.cpp',
 ]
 
 Library('linker')
 
 FINAL_LIBRARY = 'mozglue'
 
-DEFINES['IMPL_MFBT'] = True
-
 TEST_DIRS += ['tests']
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
 
 DEFINES['XZ_USE_CRC64'] = 1
 
 USE_LIBS += [
--- a/mozglue/misc/interceptor/moz.build
+++ b/mozglue/misc/interceptor/moz.build
@@ -11,16 +11,14 @@ EXPORTS.mozilla.interceptor += [
     'PatcherDetour.h',
     'PatcherNopSpace.h',
     'TargetFunction.h',
     'Trampoline.h',
     'VMSharingPolicies.h',
 ]
 
 if CONFIG['CPU_ARCH'] == 'aarch64':
-    Library('interceptor')
-
-    DEFINES['IMPL_MFBT'] = True
+    FINAL_LIBRARY = 'mozglue'
 
     UNIFIED_SOURCES += [
         'Arm64.cpp',
     ]
 
--- a/mozglue/misc/moz.build
+++ b/mozglue/misc/moz.build
@@ -29,18 +29,16 @@ SOURCES += [
     'AutoProfilerLabel.cpp',
     'Printf.cpp',
     'StackWalk.cpp',
     'TimeStamp.cpp',
 ]
 
 OS_LIBS += CONFIG['REALTIME_LIBS']
 
-DEFINES['IMPL_MFBT'] = True
-
 if CONFIG['OS_ARCH'] == 'WINNT':
     DIRS += [
         'interceptor',
     ]
     EXPORTS += [
         'nsWindowsDllInterceptor.h',
     ]
     EXPORTS.mozilla += [