Bug 868814 - Fold mozalloc library into mozglue. r=njn
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 27 Feb 2015 14:00:15 +0900
changeset 249342 beed1c584a2264aab11aa41484083ba49ba4c0ab
parent 249341 5ddbdbc00f3c53f6b0e049d9c890ad4840e3c527
child 249343 56f1a3605429c9b4f8a6e54d720eb3f6aa499829
push id972
push userbcampen@mozilla.com
push dateTue, 10 Mar 2015 19:43:03 +0000
reviewersnjn
bugs868814
milestone39.0a1
Bug 868814 - Fold mozalloc library into mozglue. r=njn
b2g/installer/package-manifest.in
browser/installer/package-manifest.in
build/gecko_templates.mozbuild
ipc/app/moz.build
layout/media/moz.build
memory/mozalloc/moz.build
memory/mozalloc/mozalloc.cpp
memory/mozalloc/mozalloc.h
memory/mozalloc/mozalloc_abort.cpp
memory/mozalloc/mozalloc_abort.h
memory/mozalloc/mozalloc_oom.cpp
memory/mozalloc/mozalloc_oom.h
memory/mozalloc/msvc_raise_wrappers.cpp
memory/mozalloc/msvc_raise_wrappers.h
memory/mozalloc/msvc_throw_wrapper.cpp
memory/mozalloc/staticruntime/moz.build
mobile/android/installer/package-manifest.in
security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
testing/mochitest/ssltunnel/moz.build
toolkit/library/moz.build
toolkit/mozapps/installer/upload-files.mk
xpcom/glue/moz.build
xpcom/glue/nomozalloc/Makefile.in
xpcom/glue/nomozalloc/moz.build
xulrunner/installer/Makefile.in
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -64,17 +64,16 @@
 #ifndef MOZ_STATIC_JS
 @BINPATH@/@DLL_PREFIX@mozjs@DLL_SUFFIX@
 #endif
 #ifndef MOZ_FOLD_LIBS
 @BINPATH@/@DLL_PREFIX@plc4@DLL_SUFFIX@
 @BINPATH@/@DLL_PREFIX@plds4@DLL_SUFFIX@
 @BINPATH@/@DLL_PREFIX@nspr4@DLL_SUFFIX@
 #endif
-@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
 #ifdef MOZ_DMD
 @BINPATH@/@DLL_PREFIX@dmd@DLL_SUFFIX@
 #endif
 #ifdef XP_MACOSX
 @BINPATH@/XUL
 #else
 @BINPATH@/@DLL_PREFIX@xul@DLL_SUFFIX@
 #endif
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -62,17 +62,16 @@
 @RESPATH@/updater.ini
 #endif
 
 [xpcom]
 @RESPATH@/dependentlibs.list
 #ifdef GKMEDIAS_SHARED_LIBRARY
 @BINPATH@/@DLL_PREFIX@gkmedias@DLL_SUFFIX@
 #endif
-@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
 #ifdef MOZ_SHARED_MOZGLUE
 @BINPATH@/@DLL_PREFIX@mozglue@DLL_SUFFIX@
 #endif
 #ifndef MOZ_STATIC_JS
 @BINPATH@/@DLL_PREFIX@mozjs@DLL_SUFFIX@
 #endif
 #ifdef MOZ_DMD
 @BINPATH@/@DLL_PREFIX@dmd@DLL_SUFFIX@
--- a/build/gecko_templates.mozbuild
+++ b/build/gecko_templates.mozbuild
@@ -27,22 +27,25 @@ def GeckoBinary(linkage='dependent', msv
     '''
     if msvcrt == 'dynamic' or CONFIG['OS_ARCH'] != 'WINNT':
         xpcomglue = 'xpcomglue'
     elif msvcrt == 'static':
         USE_STATIC_LIBS = True
         xpcomglue = 'xpcomglue_staticruntime'
         if not CONFIG['GNU_CC']:
             mozglue = None
+            if linkage == 'dependent':
+                USE_LIBS += [
+                    'mozalloc_staticruntime',
+                ]
     else:
         error('msvcrt must be "dynamic" or "static"')
 
     if linkage == 'dependent':
         USE_LIBS += [
-            'mozalloc',
             'nspr',
             '%s_s' % xpcomglue,
             'xul',
         ]
     elif linkage == 'standalone':
         DEFINES['XPCOM_GLUE'] = True
 
         USE_LIBS += [
--- a/ipc/app/moz.build
+++ b/ipc/app/moz.build
@@ -10,23 +10,26 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'andr
         'MozillaRuntimeMainAndroid.cpp',
     ]
 else:
     kwargs = {
         'linkage': None,
     }
     if CONFIG['MOZ_SANDBOX'] and CONFIG['OS_ARCH'] == 'WINNT':
         kwargs['msvcrt'] = 'static'
+        if not CONFIG['GNU_CC']:
+            USE_LIBS += [
+                'mozalloc_staticruntime',
+            ]
     GeckoProgram(CONFIG['MOZ_CHILD_PROCESS_NAME'], **kwargs)
 
     SOURCES += [
         'MozillaRuntimeMain.cpp',
     ]
     USE_LIBS += [
-        'mozalloc',
         'nspr',
         'xul',
     ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 LOCAL_INCLUDES += [
     '/toolkit/xre',
@@ -46,17 +49,16 @@ if CONFIG['MOZ_SANDBOX'] and CONFIG['OS_
         '/security',
         '/security/sandbox/chromium',
     ]
     USE_LIBS += [
         'rlz',
         'sandbox_staticruntime_s',
     ]
     DELAYLOAD_DLLS += [
-        'mozalloc.dll',
         'nss3.dll',
         'xul.dll'
     ]
     DEFINES['HASH_NODE_ID_WITH_DEVICE_ID'] = 1;
     SOURCES += [
         'sha256.c',
     ]
 
--- a/layout/media/moz.build
+++ b/layout/media/moz.build
@@ -5,17 +5,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 with Files('**'):
     BUG_COMPONENT = ('Core', 'Video/Audio')
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     GeckoSharedLibrary('gkmedias', linkage=None)
     USE_LIBS += [
-        'mozalloc',
         'nspr',
     ]
 else:
     Library('gkmedias')
 
 
 if CONFIG['MOZ_WEBRTC']:
     DIRS += ['webrtc']
--- a/memory/mozalloc/moz.build
+++ b/memory/mozalloc/moz.build
@@ -33,23 +33,24 @@ if CONFIG['WRAP_STL_INCLUDES']:
             ]
 
 UNIFIED_SOURCES += [
     'mozalloc.cpp',
     'mozalloc_abort.cpp',
     'mozalloc_oom.cpp',
 ]
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
-    Library('mozalloc')
-else:
-    GeckoSharedLibrary('mozalloc', linkage=None)
-    SDK_LIBRARY = True
+FINAL_LIBRARY = 'mozglue'
 
 # The strndup declaration in string.h is in an ifdef __USE_GNU section
 DEFINES['_GNU_SOURCE'] = True
 
 GENERATED_INCLUDES += ['/xpcom']
 
 DISABLE_STL_WRAPPING = True
 
 if CONFIG['CLANG_CXX'] or CONFIG['_MSC_VER']:
     FAIL_ON_WARNINGS = True
+
+DEFINES['IMPL_MFBT'] = True
+
+if CONFIG['_MSC_VER']:
+    DIRS += ['staticruntime']
--- a/memory/mozalloc/mozalloc.cpp
+++ b/memory/mozalloc/mozalloc.cpp
@@ -1,154 +1,187 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: sw=4 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
+
+// Building with USE_STATIC_LIBS = True sets -MT instead of -MD. -MT sets _MT,
+// while -MD sets _MT and _DLL.
+#if defined(_MT) && !defined(_DLL)
+#define MOZ_STATIC_RUNTIME
+#endif
+
+#if defined(MOZ_MEMORY) && !defined(MOZ_STATIC_RUNTIME)
+// mozalloc.cpp is part of the same library as mozmemory, thus MOZ_MEMORY_IMPL
+// is needed.
+#define MOZ_MEMORY_IMPL
+#include "mozmemory.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, ...) \
+  extern "C" MOZ_MEMORY_API return_type name ## _impl(__VA_ARGS__);
+#define MALLOC_FUNS MALLOC_FUNCS_MALLOC
+#include "malloc_decls.h"
+
+extern "C" MOZ_MEMORY_API char *strdup_impl(const char *);
+extern "C" MOZ_MEMORY_API char *strndup_impl(const char *, size_t);
+
+#else
+// 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, valloc, malloc_size, malloc_us
+#endif // if defined(MALLOC_H)
+#include <stdlib.h>             // for malloc, free
+#if defined(XP_UNIX)
+#  include <unistd.h>           // for valloc on *BSD
+#endif //if defined(XP_UNIX)
+
+#define malloc_impl malloc
+#define posix_memalign_impl posix_memalign
+#define calloc_impl calloc
+#define realloc_impl realloc
+#define free_impl free
+#define memalign_impl memalign
+#define valloc_impl valloc
+#define malloc_usable_size_impl malloc_usable_size
+#define strdup_impl strdup
+#define strndup_impl strndup
+
+#endif
+
 #include <errno.h>
 #include <new>                  // for std::bad_alloc
 #include <string.h>
 
 #include <sys/types.h>
 
-#if defined(MALLOC_H)
-#  include MALLOC_H             // for memalign, valloc, malloc_size, malloc_usable_size
-#endif // if defined(MALLOC_H)
-#include <stddef.h>             // for size_t
-#include <stdlib.h>             // for malloc, free
-#if defined(XP_UNIX)
-#  include <unistd.h>           // for valloc on *BSD
-#endif //if defined(XP_UNIX)
-
-#if defined(XP_WIN)
-#  define MOZALLOC_EXPORT __declspec(dllexport)
-#endif
-
 #include "mozilla/mozalloc.h"
 #include "mozilla/mozalloc_oom.h"  // for mozalloc_handle_oom
 
-/* Windows doesn't have malloc_usable_size, but jemalloc has */
-#if defined(MOZ_MEMORY_WINDOWS)
-extern "C" size_t malloc_usable_size(const void *ptr);
-#endif
-
 #ifdef __GNUC__
 #define LIKELY(x)    (__builtin_expect(!!(x), 1))
 #define UNLIKELY(x)  (__builtin_expect(!!(x), 0))
 #else
 #define LIKELY(x)    (x)
 #define UNLIKELY(x)  (x)
 #endif
 
 void
 moz_free(void* ptr)
 {
-    free(ptr);
+    free_impl(ptr);
 }
 
 void*
 moz_xmalloc(size_t size)
 {
-    void* ptr = malloc(size);
+    void* ptr = malloc_impl(size);
     if (UNLIKELY(!ptr && size)) {
         mozalloc_handle_oom(size);
         return moz_xmalloc(size);
     }
     return ptr;
 }
 void*
 moz_malloc(size_t size)
 {
-    return malloc(size);
+    return malloc_impl(size);
 }
 
 void*
 moz_xcalloc(size_t nmemb, size_t size)
 {
-    void* ptr = calloc(nmemb, size);
+    void* ptr = calloc_impl(nmemb, size);
     if (UNLIKELY(!ptr && nmemb && size)) {
         mozalloc_handle_oom(size);
         return moz_xcalloc(nmemb, size);
     }
     return ptr;
 }
 void*
 moz_calloc(size_t nmemb, size_t size)
 {
-    return calloc(nmemb, size);
+    return calloc_impl(nmemb, size);
 }
 
 void*
 moz_xrealloc(void* ptr, size_t size)
 {
-    void* newptr = realloc(ptr, size);
+    void* newptr = realloc_impl(ptr, size);
     if (UNLIKELY(!newptr && size)) {
         mozalloc_handle_oom(size);
         return moz_xrealloc(ptr, size);
     }
     return newptr;
 }
 void*
 moz_realloc(void* ptr, size_t size)
 {
-    return realloc(ptr, size);
+    return realloc_impl(ptr, size);
 }
 
 char*
 moz_xstrdup(const char* str)
 {
-    char* dup = strdup(str);
+    char* dup = strdup_impl(str);
     if (UNLIKELY(!dup)) {
         mozalloc_handle_oom(0);
         return moz_xstrdup(str);
     }
     return dup;
 }
 char*
 moz_strdup(const char* str)
 {
-    return strdup(str);
+    return strdup_impl(str);
 }
 
 #if defined(HAVE_STRNDUP)
 char*
 moz_xstrndup(const char* str, size_t strsize)
 {
-    char* dup = strndup(str, strsize);
+    char* dup = strndup_impl(str, strsize);
     if (UNLIKELY(!dup)) {
         mozalloc_handle_oom(strsize);
         return moz_xstrndup(str, strsize);
     }
     return dup;
 }
 char*
 moz_strndup(const char* str, size_t strsize)
 {
-    return strndup(str, strsize);
+    return strndup_impl(str, strsize);
 }
 #endif  // if defined(HAVE_STRNDUP)
 
 #if defined(HAVE_POSIX_MEMALIGN)
 int
 moz_xposix_memalign(void **ptr, size_t alignment, size_t size)
 {
-    int err = posix_memalign(ptr, alignment, size);
+    int err = posix_memalign_impl(ptr, alignment, size);
     if (UNLIKELY(err && ENOMEM == err)) {
         mozalloc_handle_oom(size);
         return moz_xposix_memalign(ptr, alignment, size);
     }
     // else: (0 == err) or (EINVAL == err)
     return err;
 }
 int
 moz_posix_memalign(void **ptr, size_t alignment, size_t size)
 {
-    int code = posix_memalign(ptr, alignment, size);
+    int code = posix_memalign_impl(ptr, alignment, size);
     if (code)
         return code;
 
 #if defined(XP_MACOSX)
     // Workaround faulty OSX posix_memalign, which provides memory with the
     // incorrect alignment sometimes, but returns 0 as if nothing was wrong.
     size_t mask = alignment - 1;
     if (((size_t)(*ptr) & mask) != 0) {
@@ -162,62 +195,64 @@ moz_posix_memalign(void **ptr, size_t al
 
 }
 #endif // if defined(HAVE_POSIX_MEMALIGN)
 
 #if defined(HAVE_MEMALIGN)
 void*
 moz_xmemalign(size_t boundary, size_t size)
 {
-    void* ptr = memalign(boundary, size);
+    void* ptr = memalign_impl(boundary, size);
     if (UNLIKELY(!ptr && EINVAL != errno)) {
         mozalloc_handle_oom(size);
         return moz_xmemalign(boundary, size);
     }
     // non-NULL ptr or errno == EINVAL
     return ptr;
 }
 void*
 moz_memalign(size_t boundary, size_t size)
 {
-    return memalign(boundary, size);
+    return memalign_impl(boundary, size);
 }
 #endif // if defined(HAVE_MEMALIGN)
 
 #if defined(HAVE_VALLOC)
 void*
 moz_xvalloc(size_t size)
 {
-    void* ptr = valloc(size);
+    void* ptr = valloc_impl(size);
     if (UNLIKELY(!ptr)) {
         mozalloc_handle_oom(size);
         return moz_xvalloc(size);
     }
     return ptr;
 }
 void*
 moz_valloc(size_t size)
 {
-    return valloc(size);
+    return valloc_impl(size);
 }
 #endif // if defined(HAVE_VALLOC)
 
+#if !(defined(_MT) && !defined(_DLL))
 size_t
 moz_malloc_usable_size(void *ptr)
 {
     if (!ptr)
         return 0;
 
 #if defined(XP_MACOSX)
     return malloc_size(ptr);
 #elif defined(HAVE_MALLOC_USABLE_SIZE) || defined(MOZ_MEMORY)
-    return malloc_usable_size(ptr);
+    return malloc_usable_size_impl(ptr);
 #elif defined(XP_WIN)
     return _msize(ptr);
 #else
     return 0;
 #endif
 }
 
 size_t moz_malloc_size_of(const void *ptr)
 {
     return moz_malloc_usable_size((void *)ptr);
 }
+#endif
--- a/memory/mozalloc/mozalloc.h
+++ b/memory/mozalloc/mozalloc.h
@@ -19,33 +19,20 @@
 #endif
 #include "xpcom-config.h"
 
 #if defined(__cplusplus)
 #include "mozilla/fallible.h"
 #include "mozilla/TemplateLib.h"
 #endif
 #include "mozilla/Attributes.h"
+#include "mozilla/Types.h"
 
 #define MOZALLOC_HAVE_XMALLOC
 
-#if defined(MOZALLOC_EXPORT)
-/* do nothing: it's been defined to __declspec(dllexport) by
- * mozalloc*.cpp on platforms where that's required. */
-#elif defined(XP_WIN)
-#  define MOZALLOC_EXPORT __declspec(dllimport)
-#elif defined(HAVE_VISIBILITY_ATTRIBUTE)
-/* Make sure symbols are still exported even if we're wrapped in a
- * |visibility push(hidden)| blanket. */
-#  define MOZALLOC_EXPORT __attribute__ ((visibility ("default")))
-#else
-#  define MOZALLOC_EXPORT
-#endif
-
-
 #if defined(MOZ_ALWAYS_INLINE_EVEN_DEBUG)
 #  define MOZALLOC_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG
 #elif defined(HAVE_FORCEINLINE)
 #  define MOZALLOC_INLINE __forceinline
 #else
 #  define MOZALLOC_INLINE inline
 #endif
 
@@ -70,83 +57,83 @@ extern "C" {
  * NULL pointers if memory is exhausted: their return value must be
  * checked.
  *
  * All these allocation functions are *guaranteed* to return a pointer
  * to memory allocated in such a way that that memory can be freed by
  * passing that pointer to |moz_free()|.
  */
 
-MOZALLOC_EXPORT
+MFBT_API
 void moz_free(void* ptr);
 
-MOZALLOC_EXPORT void* moz_xmalloc(size_t size)
+MFBT_API void* moz_xmalloc(size_t size)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
-MOZALLOC_EXPORT
+MFBT_API
 void* moz_malloc(size_t size)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
 
-MOZALLOC_EXPORT void* moz_xcalloc(size_t nmemb, size_t size)
+MFBT_API void* moz_xcalloc(size_t nmemb, size_t size)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
-MOZALLOC_EXPORT void* moz_calloc(size_t nmemb, size_t size)
+MFBT_API void* moz_calloc(size_t nmemb, size_t size)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
 
-MOZALLOC_EXPORT void* moz_xrealloc(void* ptr, size_t size)
+MFBT_API void* moz_xrealloc(void* ptr, size_t size)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
-MOZALLOC_EXPORT void* moz_realloc(void* ptr, size_t size)
+MFBT_API void* moz_realloc(void* ptr, size_t size)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
 
-MOZALLOC_EXPORT char* moz_xstrdup(const char* str)
+MFBT_API char* moz_xstrdup(const char* str)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
-MOZALLOC_EXPORT char* moz_strdup(const char* str)
+MFBT_API char* moz_strdup(const char* str)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
-MOZALLOC_EXPORT size_t moz_malloc_usable_size(void *ptr);
+MFBT_API size_t moz_malloc_usable_size(void *ptr);
 
-MOZALLOC_EXPORT size_t moz_malloc_size_of(const void *ptr);
+MFBT_API size_t moz_malloc_size_of(const void *ptr);
 
 #if defined(HAVE_STRNDUP)
-MOZALLOC_EXPORT char* moz_xstrndup(const char* str, size_t strsize)
+MFBT_API char* moz_xstrndup(const char* str, size_t strsize)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
-MOZALLOC_EXPORT char* moz_strndup(const char* str, size_t strsize)
+MFBT_API char* moz_strndup(const char* str, size_t strsize)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 #endif /* if defined(HAVE_STRNDUP) */
 
 
 #if defined(HAVE_POSIX_MEMALIGN)
-MOZALLOC_EXPORT int moz_xposix_memalign(void **ptr, size_t alignment, size_t size)
+MFBT_API int moz_xposix_memalign(void **ptr, size_t alignment, size_t size)
     NS_WARN_UNUSED_RESULT;
 
-MOZALLOC_EXPORT int moz_posix_memalign(void **ptr, size_t alignment, size_t size)
+MFBT_API int moz_posix_memalign(void **ptr, size_t alignment, size_t size)
     NS_WARN_UNUSED_RESULT;
 #endif /* if defined(HAVE_POSIX_MEMALIGN) */
 
 
 #if defined(HAVE_MEMALIGN)
-MOZALLOC_EXPORT void* moz_xmemalign(size_t boundary, size_t size)
+MFBT_API void* moz_xmemalign(size_t boundary, size_t size)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
-MOZALLOC_EXPORT void* moz_memalign(size_t boundary, size_t size)
+MFBT_API void* moz_memalign(size_t boundary, size_t size)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 #endif /* if defined(HAVE_MEMALIGN) */
 
 
 #if defined(HAVE_VALLOC)
-MOZALLOC_EXPORT void* moz_xvalloc(size_t size)
+MFBT_API void* moz_xvalloc(size_t size)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 
-MOZALLOC_EXPORT void* moz_valloc(size_t size)
+MFBT_API void* moz_valloc(size_t size)
     NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
 #endif /* if defined(HAVE_VALLOC) */
 
 
 #ifdef __cplusplus
 } /* extern "C" */
 #endif /* ifdef __cplusplus */
 
@@ -171,17 +158,17 @@ MOZALLOC_EXPORT void* moz_valloc(size_t 
  * throw that exception.  This declaration is consistent with the rule
  * that |::operator new() throw(std::bad_alloc)| will never return NULL.
  */
 
 /* NB: This is defined just to silence vacuous warnings about symbol
  * visibility on OS X/gcc. These symbols are force-inline and not
  * exported. */
 #if defined(XP_MACOSX)
-#  define MOZALLOC_EXPORT_NEW MOZALLOC_EXPORT
+#  define MOZALLOC_EXPORT_NEW MFBT_API
 #else
 #  define MOZALLOC_EXPORT_NEW
 #endif
 
 #if defined(ANDROID)
 /*
  * It's important to always specify 'throw()' in GCC because it's used to tell
  * GCC that 'new' may return null. That makes GCC null-check the result before
--- a/memory/mozalloc/mozalloc_abort.cpp
+++ b/memory/mozalloc/mozalloc_abort.cpp
@@ -1,19 +1,15 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: sw=4 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/. */
 
-#if defined(XP_WIN)
-#  define MOZALLOC_EXPORT __declspec(dllexport)
-#endif
-
 #include "mozilla/mozalloc_abort.h"
 
 #ifdef ANDROID
 # include <android/log.h>
 #endif
 #ifdef MOZ_WIDGET_ANDROID
 # include "APKOpen.h"
 # include "dlfcn.h"
--- a/memory/mozalloc/mozalloc_abort.h
+++ b/memory/mozalloc/mozalloc_abort.h
@@ -4,37 +4,25 @@
 /* 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_abort_h
 #define mozilla_mozalloc_abort_h
 
 #include "mozilla/Attributes.h"
-
-#if defined(MOZALLOC_EXPORT)
-// do nothing: it's been defined to __declspec(dllexport) by
-// mozalloc*.cpp on platforms where that's required
-#elif defined(XP_WIN)
-#  define MOZALLOC_EXPORT __declspec(dllimport)
-#elif defined(HAVE_VISIBILITY_ATTRIBUTE)
-/* Make sure symbols are still exported even if we're wrapped in a
- * |visibility push(hidden)| blanket. */
-#  define MOZALLOC_EXPORT __attribute__ ((visibility ("default")))
-#else
-#  define MOZALLOC_EXPORT
-#endif
+#include "mozilla/Types.h"
 
 /**
  * Terminate this process in such a way that breakpad is triggered, if
  * at all possible.
  *
  * Note: MOZ_NORETURN seems to break crash stacks on ARM, so we don't
  * use that annotation there.
  */
-MOZALLOC_EXPORT
+MFBT_API
 #if !defined(__arm__)
   MOZ_NORETURN
 #endif
   void mozalloc_abort(const char* const msg);
 
 
 #endif  /* ifndef mozilla_mozalloc_abort_h */
--- a/memory/mozalloc/mozalloc_oom.cpp
+++ b/memory/mozalloc/mozalloc_oom.cpp
@@ -1,19 +1,15 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: sw=4 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/. */
 
-#if defined(XP_WIN)
-#  define MOZALLOC_EXPORT __declspec(dllexport)
-#endif
-
 #include "mozilla/mozalloc_abort.h"
 #include "mozilla/mozalloc_oom.h"
 #include "mozilla/Assertions.h"
 
 static mozalloc_oom_abort_handler gAbortHandler;
 
 #define OOM_MSG_LEADER "out of memory: 0x"
 #define OOM_MSG_DIGITS "0000000000000000" // large enough for 2^64
--- a/memory/mozalloc/mozalloc_oom.h
+++ b/memory/mozalloc/mozalloc_oom.h
@@ -5,44 +5,27 @@
  * 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_oom_h
 #define mozilla_mozalloc_oom_h
 
 #include "mozalloc.h"
 
-#if defined(MOZALLOC_EXPORT)
-// do nothing: it's been defined to __declspec(dllexport) by
-// mozalloc*.cpp on platforms where that's required
-#elif defined(XP_WIN)
-#  define MOZALLOC_EXPORT __declspec(dllimport)
-#elif defined(HAVE_VISIBILITY_ATTRIBUTE)
-/* Make sure symbols are still exported even if we're wrapped in a
- * |visibility push(hidden)| blanket. */
-#  define MOZALLOC_EXPORT __attribute__ ((visibility ("default")))
-#else
-#  define MOZALLOC_EXPORT
-#endif
-
-
 /**
- * Called when memory is critically low.  Returns iff it was able to 
+ * Called when memory is critically low.  Returns iff it was able to
  * remedy the critical memory situation; if not, it will abort().
- * 
- * We have to re-#define MOZALLOC_EXPORT because this header can be
- * used indepedently of mozalloc.h.
  */
-MOZALLOC_EXPORT void mozalloc_handle_oom(size_t requestedSize);
+MFBT_API void mozalloc_handle_oom(size_t requestedSize);
 
 /**
  * Called by embedders (specifically Mozilla breakpad) which wants to be
  * notified of an intentional abort, to annotate any crash report with
  * the size of the allocation on which we aborted.
  */
 typedef void (*mozalloc_oom_abort_handler)(size_t size);
-MOZALLOC_EXPORT void mozalloc_set_oom_abort_handler(mozalloc_oom_abort_handler handler);
+MFBT_API void mozalloc_set_oom_abort_handler(mozalloc_oom_abort_handler handler);
 
 /* TODO: functions to query system memory usage and register
  * critical-memory handlers. */
 
 
 #endif /* ifndef mozilla_mozalloc_oom_h */
--- a/memory/mozalloc/msvc_raise_wrappers.cpp
+++ b/memory/mozalloc/msvc_raise_wrappers.cpp
@@ -2,20 +2,16 @@
  * vim: sw=4 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 <stdio.h>
 
-#if defined(XP_WIN)
-#  define MOZALLOC_EXPORT __declspec(dllexport)
-#endif
-
 #include "mozalloc_abort.h"
 
 #define MOZALLOC_DONT_WRAP_RAISE_FUNCTIONS
 #include "mozilla/throw_msvc.h"
 
 __declspec(noreturn) static void abort_from_exception(const char* const which,
                                                       const char* const what);
 static void
--- a/memory/mozalloc/msvc_raise_wrappers.h
+++ b/memory/mozalloc/msvc_raise_wrappers.h
@@ -18,21 +18,21 @@
 #include "mozilla/mozalloc_abort.h"
 
 namespace std {
 
 // NB: user code is not supposed to touch the std:: namespace.  We're
 // doing this after careful review because we want to define our own
 // exception throwing semantics.  Don't try this at home!
 
-MOZALLOC_EXPORT __declspec(noreturn) void moz_Xinvalid_argument(const char*);
-MOZALLOC_EXPORT __declspec(noreturn) void moz_Xlength_error(const char*);
-MOZALLOC_EXPORT __declspec(noreturn) void moz_Xout_of_range(const char*);
-MOZALLOC_EXPORT __declspec(noreturn) void moz_Xoverflow_error(const char*);
-MOZALLOC_EXPORT __declspec(noreturn) void moz_Xruntime_error(const char*);
+MFBT_API __declspec(noreturn) void moz_Xinvalid_argument(const char*);
+MFBT_API __declspec(noreturn) void moz_Xlength_error(const char*);
+MFBT_API __declspec(noreturn) void moz_Xout_of_range(const char*);
+MFBT_API __declspec(noreturn) void moz_Xoverflow_error(const char*);
+MFBT_API __declspec(noreturn) void moz_Xruntime_error(const char*);
 
 } // namespace std
 
 #ifndef MOZALLOC_DONT_WRAP_RAISE_FUNCTIONS
 
 #  define _Xinvalid_argument  moz_Xinvalid_argument
 #  define _Xlength_error      moz_Xlength_error
 #  define _Xout_of_range      moz_Xout_of_range
--- a/memory/mozalloc/msvc_throw_wrapper.cpp
+++ b/memory/mozalloc/msvc_throw_wrapper.cpp
@@ -2,20 +2,16 @@
  * vim: sw=4 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 <exception>
 
-#if defined(XP_WIN)
-#  define MOZALLOC_EXPORT __declspec(dllexport)
-#endif
-
 #include "mozilla/mozalloc_abort.h"
 
 namespace std {
 
 // NB: user code is not supposed to touch the std:: namespace.  We're
 // doing this after careful review because we want to define our own
 // exception throwing semantics.  Don't try this at home!
 
copy from memory/mozalloc/moz.build
copy to memory/mozalloc/staticruntime/moz.build
--- a/memory/mozalloc/moz.build
+++ b/memory/mozalloc/staticruntime/moz.build
@@ -1,55 +1,38 @@
 # -*- Mode: python; c-basic-offset: 4; 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/.
+
 NO_VISIBILITY_FLAGS = True
 
-EXPORTS.mozilla += [
-    'mozalloc.h',
-    'mozalloc_abort.h',
-    'mozalloc_oom.h',
-]
-
 if CONFIG['MOZ_MSVC_STL_WRAP_RAISE'] or CONFIG['MOZ_MSVC_STL_WRAP_Throw']:
     build_msvc_wrappers = 1
 else:
     build_msvc_wrappers = 0
 
 if CONFIG['WRAP_STL_INCLUDES']:
-    if CONFIG['GNU_CXX']:
-        EXPORTS.mozilla += ['throw_gcc.h']
-    elif CONFIG['_MSC_VER']:
-        DEFINES['_HAS_EXCEPTIONS'] = 0
-        if build_msvc_wrappers:
-            EXPORTS.mozilla += [
-                'msvc_raise_wrappers.h',
-                'msvc_throw_wrapper.h',
-                'throw_msvc.h',
-            ]
-            SOURCES += [
-                'msvc_raise_wrappers.cpp',
-                'msvc_throw_wrapper.cpp',
-            ]
+    DEFINES['_HAS_EXCEPTIONS'] = 0
+    if build_msvc_wrappers:
+        SOURCES += [
+            '../msvc_raise_wrappers.cpp',
+            '../msvc_throw_wrapper.cpp',
+        ]
 
 UNIFIED_SOURCES += [
-    'mozalloc.cpp',
-    'mozalloc_abort.cpp',
-    'mozalloc_oom.cpp',
+    '../mozalloc.cpp',
+    '../mozalloc_abort.cpp',
+    '../mozalloc_oom.cpp',
 ]
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
-    Library('mozalloc')
-else:
-    GeckoSharedLibrary('mozalloc', linkage=None)
-    SDK_LIBRARY = True
-
-# The strndup declaration in string.h is in an ifdef __USE_GNU section
-DEFINES['_GNU_SOURCE'] = True
-
 GENERATED_INCLUDES += ['/xpcom']
 
 DISABLE_STL_WRAPPING = True
 
-if CONFIG['CLANG_CXX'] or CONFIG['_MSC_VER']:
-    FAIL_ON_WARNINGS = True
+FAIL_ON_WARNINGS = True
+
+DEFINES['IMPL_MFBT'] = True
+
+USE_STATIC_LIBS = True
+
+Library('mozalloc_staticruntime')
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -37,17 +37,16 @@
 #ifdef MOZ_DMD
 @BINPATH@/@DLL_PREFIX@dmd@DLL_SUFFIX@
 #endif
 #ifndef MOZ_FOLD_LIBS
 @BINPATH@/@DLL_PREFIX@plc4@DLL_SUFFIX@
 @BINPATH@/@DLL_PREFIX@plds4@DLL_SUFFIX@
 @BINPATH@/@DLL_PREFIX@nspr4@DLL_SUFFIX@
 #endif
-@BINPATH@/@DLL_PREFIX@mozalloc@DLL_SUFFIX@
 @BINPATH@/@DLL_PREFIX@omxplugin@DLL_SUFFIX@
 @BINPATH@/@DLL_PREFIX@omxplugingb@DLL_SUFFIX@
 @BINPATH@/@DLL_PREFIX@omxplugingb235@DLL_SUFFIX@
 @BINPATH@/@DLL_PREFIX@omxpluginhc@DLL_SUFFIX@
 @BINPATH@/@DLL_PREFIX@omxpluginkk@DLL_SUFFIX@
 @BINPATH@/@DLL_PREFIX@xul@DLL_SUFFIX@
 
 @BINPATH@/@DLL_PREFIX@nssckbi@DLL_SUFFIX@
--- a/security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
+++ b/security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
@@ -13,17 +13,16 @@ GeckoSimplePrograms([
     'OCSPStaplingServer',
 ], linkage=None)
 
 LOCAL_INCLUDES += [
     '../lib',
 ]
 
 USE_LIBS += [
-    'mozalloc',
     'mozillapkix',
     'nspr',
     'nss',
     'pkixtestutil',
     'tlsserver',
 ]
 
 CXXFLAGS += CONFIG['TK_CFLAGS']
--- a/testing/mochitest/ssltunnel/moz.build
+++ b/testing/mochitest/ssltunnel/moz.build
@@ -6,16 +6,15 @@
 
 GeckoProgram('ssltunnel', linkage=None)
 
 SOURCES += [
     'ssltunnel.cpp',
 ]
 
 USE_LIBS += [
-    'mozalloc',
     'nspr',
     'nss',
 ]
 
 # This isn't XPCOM code, but it wants to use STL, so disable the STL
 # wrappers
 DISABLE_STL_WRAPPING = True
--- a/toolkit/library/moz.build
+++ b/toolkit/library/moz.build
@@ -108,17 +108,16 @@ USE_LIBS += [
 
 if CONFIG['MOZ_SANDBOX'] and CONFIG['OS_ARCH'] == 'WINNT':
     USE_LIBS += [
         'sandboxbroker',
     ]
 
 USE_LIBS += [
     'gkmedias',
-    'mozalloc',
     'nspr',
     'nss',
     'sqlite',
     'zlib',
 ]
 
 if CONFIG['USE_ICU']:
     USE_LIBS += [
--- a/toolkit/mozapps/installer/upload-files.mk
+++ b/toolkit/mozapps/installer/upload-files.mk
@@ -265,17 +265,16 @@ endif #Create an RPM file
 ifeq ($(MOZ_PKG_FORMAT),APK)
 
 JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
 include $(MOZILLA_DIR)/config/android-common.mk
 
 DIST_FILES =
 
 # Place the files in the order they are going to be opened by the linker
-DIST_FILES += libmozalloc.so
 ifndef MOZ_FOLD_LIBS
 DIST_FILES += \
   libnspr4.so \
   libplc4.so \
   libplds4.so \
   libmozsqlite3.so \
   libnssutil3.so \
   $(NULL)
--- a/xpcom/glue/moz.build
+++ b/xpcom/glue/moz.build
@@ -1,15 +1,15 @@
 # -*- Mode: python; c-basic-offset: 4; 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/.
 
-DIRS += ['standalone', 'nomozalloc']
+DIRS += ['standalone']
 
 # On win we build two glue libs - glue linked to crt dlls here and in staticruntime we build
 # a statically linked glue lib.
 if CONFIG['OS_ARCH'] == 'WINNT':
     DIRS += ['staticruntime']
 
 EXPORTS += [
     'MainThreadUtils.h',
deleted file mode 100644
--- a/xpcom/glue/nomozalloc/Makefile.in
+++ /dev/null
@@ -1,8 +0,0 @@
-# vim:set ts=8 sw=8 sts=8 noet:
-# 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/.
-
-DIST_INSTALL	= 1
-# Force to build a static library only
-NO_EXPAND_LIBS = 1
deleted file mode 100644
--- a/xpcom/glue/nomozalloc/moz.build
+++ /dev/null
@@ -1,49 +0,0 @@
-# -*- Mode: python; c-basic-offset: 4; 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/.
-
-include('../objs.mozbuild')
-
-UNIFIED_SOURCES += xpcom_gluens_src_cppsrcs
-UNIFIED_SOURCES += xpcom_glue_src_cppsrcs
-
-UNIFIED_SOURCES += [
-    '../GenericModule.cpp',
-    '../nsStringAPI.cpp',
-]
-
-Library('xpcomglue_s_nomozalloc')
-
-SDK_LIBRARY = True
-
-# we don't want the shared lib, but we want to force the creation of a static lib.
-FORCE_STATIC_LIB = True
-
-if CONFIG['_MSC_VER']:
-    DEFINES['_USE_ANSI_CPP'] = True
-    # Don't include directives about which CRT to use
-    CFLAGS += ['-Zl']
-    CXXFLAGS += ['-Zl']
-
-DEFINES['MOZ_NO_MOZALLOC'] = True
-
-LOCAL_INCLUDES += [
-    '../../build',
-]
-
-# Pretend we're statically linking the CRT, even though we might not be: this
-# avoids "msvcrp" and assembly dependencies from creeping into the directives
-# for this library on Windows.
-USE_STATIC_LIBS = True
-
-# Don't use STL wrappers here (i.e. wrapped <new>); they require mozalloc
-DISABLE_STL_WRAPPING = True
-
-FAIL_ON_WARNINGS = True
-
-# Include fallible for third party code using the xpcom glue
-USE_LIBS += [
-    'fallible',
-]
--- a/xulrunner/installer/Makefile.in
+++ b/xulrunner/installer/Makefile.in
@@ -51,17 +51,17 @@ NSPR_VERSION=$(shell $(NSPR_CONFIG) --ve
 else
 pkg_config_files += mozilla-nspr.pc
 NSPR_NAME=mozilla-nspr
 FULL_NSPR_CFLAGS=-I\$${includedir}
 FULL_NSPR_LIBS=$(subst $(prefix),\$${sdkdir},$(shell $(DEPTH)/nsprpub/config/nspr-config --libs))
 NSPR_VERSION=$(shell $(DEPTH)/nsprpub/config/nspr-config --version)
 endif
 
-MOZ_XUL_LINK = -lxpcomglue_s -lxul -lmozalloc
+MOZ_XUL_LINK = -lxpcomglue_s -lxul
 ifdef JS_SHARED_LIBRARY
 MOZ_JS_LINK = -lmozjs
 else
 MOZ_JS_LINK = $(MOZ_XUL_LINK)
 endif
 
 $(warning FULL_NSPR_CFLAGS=$(FULL_NSPR_CFLAGS))