Bug 1471132 - Avoid ASAN padding between NSModules. r?froydnj
--- a/python/mozbuild/mozbuild/action/check_binary.py
+++ b/python/mozbuild/mozbuild/action/check_binary.py
@@ -35,19 +35,17 @@ TARGET = {
'MOZ_LIBSTDCXX_VERSION':
buildconfig.substs.get('MOZ_LIBSTDCXX_TARGET_VERSION'),
'platform': buildconfig.substs['OS_TARGET'],
'readelf': '{}readelf'.format(
buildconfig.substs.get('TOOLCHAIN_PREFIX', '')),
'nm': '{}nm'.format(buildconfig.substs.get('TOOLCHAIN_PREFIX', '')),
}
-if buildconfig.substs.get('MOZ_ASAN'):
- GUESSED_NSMODULE_SIZE = 64
-elif buildconfig.substs.get('HAVE_64BIT_BUILD'):
+if buildconfig.substs.get('HAVE_64BIT_BUILD'):
GUESSED_NSMODULE_SIZE = 8
else:
GUESSED_NSMODULE_SIZE = 4
get_type = memoize(get_type)
--- a/xpcom/components/Module.h
+++ b/xpcom/components/Module.h
@@ -6,16 +6,17 @@
#ifndef mozilla_Module_h
#define mozilla_Module_h
#include "nscore.h"
#include "nsID.h"
#include "nsIFactory.h"
#include "nsCOMPtr.h" // for already_AddRefed
+#include "mozilla/Attributes.h"
namespace mozilla {
/**
* A module implements one or more XPCOM components. This structure is used
* for both binary and script modules, but the registration members
* (cids/contractids/categoryentries) are unused for modules which are loaded
* via a module loader.
@@ -143,15 +144,20 @@ struct Module
# define NSMODULE_SECTION __attribute__((section("__DATA, .kPStaticModules"), visibility("default")))
# elif defined (_WIN32)
# define NSMODULE_SECTION __attribute__((section(".kPStaticModules"), dllexport))
# endif
# endif
# if !defined(NSMODULE_SECTION)
# error Do not know how to define sections.
# endif
-# define NSMODULE_DEFN(_name) extern NSMODULE_SECTION mozilla::Module const *const NSMODULE_NAME(_name)
+# if defined(MOZ_HAVE_ASAN_BLACKLIST)
+# define NSMODULE_ASAN_BLACKLIST __attribute__((no_sanitize_address))
+# else
+# define NSMODULE_ASAN_BLACKLIST
+# endif
+# define NSMODULE_DEFN(_name) extern NSMODULE_SECTION NSMODULE_ASAN_BLACKLIST mozilla::Module const *const NSMODULE_NAME(_name)
#else
# define NSMODULE_NAME(_name) NSModule
# define NSMODULE_DEFN(_name) extern "C" NS_EXPORT mozilla::Module const *const NSModule
#endif
#endif // mozilla_Module_h
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -245,36 +245,28 @@ nsComponentManagerImpl::nsComponentManag
{
}
nsTArray<const mozilla::Module*>* nsComponentManagerImpl::sStaticModules;
NSMODULE_DEFN(start_kPStaticModules);
NSMODULE_DEFN(end_kPStaticModules);
-/* The content between start_kPStaticModules and end_kPStaticModules is gathered
- * by the linker from various objects containing symbols in a specific section.
- * ASAN considers (rightfully) the use of this content as a global buffer
- * overflow. But this is a deliberate and well-considered choice, with no proper
- * way to make ASAN happy. */
-MOZ_ASAN_BLACKLIST
/* static */ void
nsComponentManagerImpl::InitializeStaticModules()
{
if (sStaticModules) {
return;
}
sStaticModules = new nsTArray<const mozilla::Module*>;
for (const mozilla::Module * const* staticModules =
&NSMODULE_NAME(start_kPStaticModules) + 1;
staticModules < &NSMODULE_NAME(end_kPStaticModules); ++staticModules)
- if (*staticModules) { // ASAN adds padding
- sStaticModules->AppendElement(*staticModules);
- }
+ sStaticModules->AppendElement(*staticModules);
}
nsTArray<nsComponentManagerImpl::ComponentLocation>*
nsComponentManagerImpl::sModuleLocations;
/* static */ void
nsComponentManagerImpl::InitializeModuleLocations()
{