Skip to content

Commit

Permalink
Bug 1541792 - Replace linker magic with manual component registration…
Browse files Browse the repository at this point in the history
…. r=froydnj

Before bug 938437, we had a rather large and error-prone
nsStaticXULComponents.cpp used to register all modules. That was
replaced with clever use of the linker, which allowed to avoid the mess
that maintaining that file was.

Fast forward to now, where after bug 1524687 and other work that
preceded it, we have a much smaller number of remaining static xpcom
components, registered via this linker hack, and don't expect to add
any new ones. The list should eventually go down to zero.

Within that context, it seems to be the right time to get rid of the
magic, and with it the problems it causes on its own.

Some of those components could probably be trivially be converted to
static registration via .conf files, but I didn't want to deal with the
possible need to increase the number of dummy modules in XPCOMInit.cpp.
They can still be converted as a followup.

Differential Revision: https://phabricator.services.mozilla.com/D26076

--HG--
extra : moz-landing-system : lando
  • Loading branch information
glandium committed Apr 5, 2019
1 parent e4a2cb3 commit 071a2fe
Show file tree
Hide file tree
Showing 29 changed files with 108 additions and 307 deletions.
4 changes: 1 addition & 3 deletions dom/media/webspeech/synth/android/AndroidSpeechModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static const mozilla::Module::CategoryEntry kCategories[] = {
ANDROIDSPEECHSERVICE_CONTRACTID},
{nullptr}};

static const mozilla::Module kModule = {
extern const mozilla::Module kSpeechSynthModule = {
mozilla::Module::kVersion,
kCIDs,
kContracts,
Expand All @@ -47,5 +47,3 @@ static const mozilla::Module kModule = {
nullptr,
nullptr,
};

NSMODULE_DEFN(androidspeechsynth) = &kModule;
17 changes: 8 additions & 9 deletions dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ static void UnloadOSXSpeechSynthesizerModule() {
OSXSpeechSynthesizerService::Shutdown();
}

static const mozilla::Module kModule = {mozilla::Module::kVersion,
kCIDs,
kContracts,
kCategories,
nullptr,
nullptr,
UnloadOSXSpeechSynthesizerModule};

NSMODULE_DEFN(osxsynth) = &kModule;
extern const mozilla::Module kSpeechSynthModule = {
mozilla::Module::kVersion,
kCIDs,
kContracts,
kCategories,
nullptr,
nullptr,
UnloadOSXSpeechSynthesizerModule};
4 changes: 1 addition & 3 deletions dom/media/webspeech/synth/windows/SapiModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ static const mozilla::Module::CategoryEntry kCategories[] = {

static void UnloadSapiModule() { SapiService::Shutdown(); }

static const mozilla::Module kModule = {
extern const mozilla::Module kSpeechSynthModule = {
mozilla::Module::kVersion, kCIDs, kContracts, kCategories, nullptr, nullptr,
UnloadSapiModule};

NSMODULE_DEFN(synthsapi) = &kModule;
4 changes: 1 addition & 3 deletions dom/power/PowerManagerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static const mozilla::Module::ContractIDEntry kPowerManagerContracts[] = {

// We mark the power module as being available in the GPU process because the
// appshell depends on the power manager service.
static const mozilla::Module kPowerManagerModule = {
extern const mozilla::Module kPowerManagerModule = {
mozilla::Module::kVersion,
kPowerManagerCIDs,
kPowerManagerContracts,
Expand All @@ -182,5 +182,3 @@ static const mozilla::Module kPowerManagerModule = {
nullptr,
nullptr,
mozilla::Module::ALLOW_IN_GPU_AND_SOCKET_PROCESS};

NSMODULE_DEFN(nsPowerManagerModule) = &kPowerManagerModule;
4 changes: 1 addition & 3 deletions layout/build/nsLayoutModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,10 @@ void nsLayoutModuleDtor() {
xpcModuleDtor();
}

static const mozilla::Module kLayoutModule = {mozilla::Module::kVersion,
extern const mozilla::Module kLayoutModule = {mozilla::Module::kVersion,
nullptr,
nullptr,
kLayoutCategories,
nullptr,
nullptr,
nullptr};

NSMODULE_DEFN(nsLayoutModule) = &kLayoutModule;
4 changes: 1 addition & 3 deletions layout/tools/layout-debug/src/nsDebugFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ static const mozilla::Module::CategoryEntry kLayoutDebugCategories[] = {
"@mozilla.org/commandlinehandler/general-startup;1?type=layoutdebug"},
{nullptr}};

static const mozilla::Module kLayoutDebugModule = {
extern const mozilla::Module kLayoutDebugModule = {
mozilla::Module::kVersion, kLayoutDebugCIDs, kLayoutDebugContracts,
kLayoutDebugCategories};

NSMODULE_DEFN(nsLayoutDebugModule) = &kLayoutDebugModule;
4 changes: 1 addition & 3 deletions mobile/android/components/build/nsBrowserModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,5 @@ static const mozilla::Module::ContractIDEntry kBrowserContracts[] = {
#endif
{nullptr}};

static const mozilla::Module kBrowserModule = {mozilla::Module::kVersion,
extern const mozilla::Module kBrowserModule = {mozilla::Module::kVersion,
kBrowserCIDs, kBrowserContracts};

NSMODULE_DEFN(nsBrowserCompsModule) = &kBrowserModule;
4 changes: 1 addition & 3 deletions netwerk/build/nsNetModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void nsNetShutdown() {
gDataSniffers = nullptr;
}

static const mozilla::Module kNeckoModule = {
extern const mozilla::Module kNeckoModule = {
mozilla::Module::kVersion,
nullptr,
nullptr,
Expand All @@ -358,5 +358,3 @@ static const mozilla::Module kNeckoModule = {
nullptr,
nullptr,
mozilla::Module::ALLOW_IN_SOCKET_PROCESS};

NSMODULE_DEFN(necko) = &kNeckoModule;
16 changes: 7 additions & 9 deletions parser/htmlparser/nsParserModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ static nsresult Initialize() {

static void Shutdown() { nsHTMLTags::ReleaseTable(); }

static mozilla::Module kParserModule = {mozilla::Module::kVersion,
kParserCIDs,
nullptr,
nullptr,
nullptr,
Initialize,
Shutdown};

NSMODULE_DEFN(nsParserModule) = &kParserModule;
extern const mozilla::Module kParserModule = {mozilla::Module::kVersion,
kParserCIDs,
nullptr,
nullptr,
nullptr,
Initialize,
Shutdown};
69 changes: 0 additions & 69 deletions python/mozbuild/mozbuild/action/check_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,73 +214,6 @@ def is_libxul(binary):
return 'xul' in basename


def check_nsmodules(target, binary):
if target is HOST or not is_libxul(binary):
raise Skip()
symbols = []
for sym in iter_symbols(binary):
if sym['addr'] == 0:
continue
name = sym['name']
# NSModules symbols end with _NSModule or _NSModuleE when C++-mangled.
if name.endswith(('_NSModule', '_NSModuleE')):
# We don't have a valid size in the symbol list for macho and coff.
# Use our guesstimate.
size = sym['size'] or GUESSED_NSMODULE_SIZE
symbols.append((sym['addr'], size, name))
elif name in ('__start_kPStaticModules', '__stop_kPStaticModules'):
# For coff, these symbols have a size.
if get_type(binary) not in (ELF, MACHO):
size = GUESSED_NSMODULE_SIZE
else:
size = 0
symbols.append((sym['addr'], size, name))
if not symbols:
raise RuntimeError('Could not find NSModules')

def print_symbols(symbols):
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.
test_msvc = (buildconfig.substs.get('CC_TYPE') == 'clang-cl' 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')
next_addr = addr + size

# The mac linker doesn't emit the start/stop symbols in the symbol table.
# We'll just assume it did the job correctly.
if get_type(binary) == MACHO:
return

first = symbols[0][2]
last = symbols[-1][2]
# On some platforms, there are extra underscores on symbol names.
if first.lstrip('_') != 'start_kPStaticModules' or \
last.lstrip('_') != 'stop_kPStaticModules':
print_symbols(symbols)
syms = set(sym for add, size, sym in symbols)
if 'start_kPStaticModules' not in syms:
raise RuntimeError('Could not find start_kPStaticModules symbol')
if 'stop_kPStaticModules' not in syms:
raise RuntimeError('Could not find stop_kPStaticModules symbol')
raise RuntimeError('NSModules are not ordered appropriately')


def check_pt_load(target, binary):
if target is HOST or get_type(binary) != ELF or not is_libxul(binary):
raise Skip()
Expand Down Expand Up @@ -371,8 +304,6 @@ def checks(target, binary):
checks.append(check_pt_load)
checks.append(check_mozglue_order)

checks.append(check_nsmodules)

retcode = 0
basename = os.path.basename(binary)
for c in checks:
Expand Down
4 changes: 1 addition & 3 deletions security/manager/ssl/LocalCertService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,7 @@ static const Module::CIDEntry kLocalCertServiceCIDs[] = {
static const Module::ContractIDEntry kLocalCertServiceContracts[] = {
{LOCALCERTSERVICE_CONTRACTID, &kLOCALCERTSERVICE_CID}, {nullptr}};

static const Module kLocalCertServiceModule = {
extern const Module kLocalCertServiceModule = {
Module::kVersion, kLocalCertServiceCIDs, kLocalCertServiceContracts};

NSMODULE_DEFN(LocalCertServiceModule) = &kLocalCertServiceModule;

} // namespace mozilla
4 changes: 1 addition & 3 deletions toolkit/components/kvstore/nsKeyValueModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ const mozilla::Module::CIDEntry kKeyValueCIDs[] = {
const mozilla::Module::ContractIDEntry kKeyValueContracts[] = {
{NS_KEY_VALUE_SERVICE_CONTRACTID, &kNS_KEY_VALUE_SERVICE_CID}, {nullptr}};

const mozilla::Module kKeyValueModule = {
extern const mozilla::Module kKeyValueModule = {
mozilla::Module::kVersion, kKeyValueCIDs, kKeyValueContracts, nullptr};

NSMODULE_DEFN(nsKeyValueModule) = &kKeyValueModule;
7 changes: 0 additions & 7 deletions toolkit/library/StaticXULComponents.ld

This file was deleted.

11 changes: 0 additions & 11 deletions toolkit/library/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ def Libxul(name, output_category=None):
# and config/version.mk would lift the $(srcdir)
RCINCLUDE = '$(DEPTH)/toolkit/library/xulrunner.rc'

# BFD ld doesn't create multiple PT_LOADs as usual when an unknown section
# exists. Using an implicit linker script to make it fold that section in
# .data.rel.ro makes it create multiple PT_LOADs. That implicit linker
# script however makes gold misbehave, first because it doesn't like that
# the linker script is given after crtbegin.o, and even past that, replaces
# the default section rules with those from the script instead of
# supplementing them. Which leads to a lib with a huge load of sections.
if CONFIG['OS_TARGET'] not in ('OpenBSD', 'WINNT') and \
CONFIG['LINKER_KIND'] == 'bfd':
LDFLAGS += [TOPSRCDIR + '/toolkit/library/StaticXULComponents.ld']

Libxul_defines()

if CONFIG['MOZ_NEEDS_LIBATOMIC']:
Expand Down
4 changes: 1 addition & 3 deletions toolkit/system/androidproxy/nsAndroidSystemProxySettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,5 @@ static const mozilla::Module::ContractIDEntry kSysProxyContracts[] = {
{NS_SYSTEMPROXYSETTINGS_CONTRACTID, &kNS_ANDROIDSYSTEMPROXYSERVICE_CID},
{nullptr}};

static const mozilla::Module kSysProxyModule = {
extern const mozilla::Module kSysProxyModule = {
mozilla::Module::kVersion, kSysProxyCIDs, kSysProxyContracts};

NSMODULE_DEFN(nsAndroidProxyModule) = &kSysProxyModule;
6 changes: 2 additions & 4 deletions toolkit/system/osxproxy/nsOSXSystemProxySettings.mm
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,5 @@ static void ProxyHasChangedWrapper(SCDynamicStoreRef aStore, CFArrayRef aChanged
static const mozilla::Module::ContractIDEntry kOSXSysProxyContracts[] = {
{NS_SYSTEMPROXYSETTINGS_CONTRACTID, &kNS_OSXSYSTEMPROXYSERVICE_CID}, {NULL}};

static const mozilla::Module kOSXSysProxyModule = {mozilla::Module::kVersion, kOSXSysProxyCIDs,
kOSXSysProxyContracts};

NSMODULE_DEFN(nsOSXProxyModule) = &kOSXSysProxyModule;
extern const mozilla::Module kSysProxyModule = {mozilla::Module::kVersion, kOSXSysProxyCIDs,
kOSXSysProxyContracts};
4 changes: 1 addition & 3 deletions toolkit/system/windowsDHCPClient/nsWindowsDHCPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ static const mozilla::Module::CIDEntry kSysDHCPClientCIDs[] = {
static const mozilla::Module::ContractIDEntry kSysDHCPClientContracts[] = {
{NS_DHCPCLIENT_CONTRACTID, &kNS_WINDOWSDHCPCLIENTSERVICE_CID}, {nullptr}};

static const mozilla::Module kSysDHCPClientModule = {
extern const mozilla::Module kSysDHCPClientModule = {
mozilla::Module::kVersion, kSysDHCPClientCIDs, kSysDHCPClientContracts};

NSMODULE_DEFN(nsDHCPClientModule) = &kSysDHCPClientModule;

} // namespace windowsDHCPClient
} // namespace system
} // namespace toolkit
Expand Down
4 changes: 1 addition & 3 deletions toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,5 @@ static const mozilla::Module::ContractIDEntry kSysProxyContracts[] = {
{NS_SYSTEMPROXYSETTINGS_CONTRACTID, &kNS_WINDOWSSYSTEMPROXYSERVICE_CID},
{nullptr}};

static const mozilla::Module kSysProxyModule = {
extern const mozilla::Module kSysProxyModule = {
mozilla::Module::kVersion, kSysProxyCIDs, kSysProxyContracts};

NSMODULE_DEFN(nsWindowsProxyModule) = &kSysProxyModule;
4 changes: 1 addition & 3 deletions toolkit/xre/nsAppRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,11 +1283,9 @@ static const mozilla::Module::ContractIDEntry kXREContracts[] = {
{NS_PROFILESERVICE_CONTRACTID, &kProfileServiceCID},
{nullptr}};

static const mozilla::Module kXREModule = {mozilla::Module::kVersion, kXRECIDs,
extern const mozilla::Module kXREModule = {mozilla::Module::kVersion, kXRECIDs,
kXREContracts};

NSMODULE_DEFN(Apprunner) = &kXREModule;

nsresult ScopedXPCOMStartup::Initialize() {
NS_ASSERTION(gDirServiceProvider, "Should not get here!");

Expand Down
4 changes: 1 addition & 3 deletions toolkit/xre/nsEmbeddingModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,5 @@ static const mozilla::Module::ContractIDEntry kEmbeddingContracts[] = {
#endif
{nullptr}};

static const mozilla::Module kEmbeddingModule = {
extern const mozilla::Module kEmbeddingModule = {
mozilla::Module::kVersion, kEmbeddingCIDs, kEmbeddingContracts};

NSMODULE_DEFN(embedcomponents) = &kEmbeddingModule;
4 changes: 1 addition & 3 deletions tools/code-coverage/nsCodeCoverageFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ static const mozilla::Module::CIDEntry kCodeCoverageCIDs[] = {
static const mozilla::Module::ContractIDEntry kCodeCoverageContracts[] = {
{"@mozilla.org/tools/code-coverage;1", &kNS_CODECOVERAGE_CID}, {nullptr}};

static const mozilla::Module kCodeCoverageModule = {
extern const mozilla::Module kCodeCoverageModule = {
mozilla::Module::kVersion, kCodeCoverageCIDs, kCodeCoverageContracts};

NSMODULE_DEFN(nsCodeCoverageModule) = &kCodeCoverageModule;
4 changes: 1 addition & 3 deletions widget/android/nsWidgetFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ static void nsWidgetAndroidModuleDtor() {
nsAppShellShutdown();
}

static const mozilla::Module kWidgetModule = {mozilla::Module::kVersion,
extern const mozilla::Module kWidgetModule = {mozilla::Module::kVersion,
kWidgetCIDs,
kWidgetContracts,
nullptr,
nullptr,
nsAppShellInit,
nsWidgetAndroidModuleDtor};

NSMODULE_DEFN(nsWidgetAndroidModule) = &kWidgetModule;
4 changes: 1 addition & 3 deletions widget/cocoa/nsWidgetFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,11 @@ static void nsWidgetCocoaModuleDtor() {
nsAppShellShutdown();
}

static const mozilla::Module kWidgetModule = {mozilla::Module::kVersion,
extern const mozilla::Module kWidgetModule = {mozilla::Module::kVersion,
kWidgetCIDs,
kWidgetContracts,
NULL,
NULL,
nsAppShellInit,
nsWidgetCocoaModuleDtor,
mozilla::Module::ALLOW_IN_GPU_VR_AND_SOCKET_PROCESS};

NSMODULE_DEFN(nsWidgetMacModule) = &kWidgetModule;
6 changes: 2 additions & 4 deletions widget/nsContentProcessWidgetFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,5 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
Module::CONTENT_PROCESS_ONLY},
{nullptr}};

static const mozilla::Module kWidgetModule = {mozilla::Module::kVersion,
kWidgetCIDs, kWidgetContracts};

NSMODULE_DEFN(nsContentProcessWidgetModule) = &kWidgetModule;
extern const mozilla::Module kContentProcessWidgetModule = {
mozilla::Module::kVersion, kWidgetCIDs, kWidgetContracts};
4 changes: 1 addition & 3 deletions widget/uikit/nsWidgetFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ static void nsWidgetUIKitModuleDtor() {
nsAppShellShutdown();
}

static const mozilla::Module kWidgetModule = {
extern const mozilla::Module kWidgetModule = {
mozilla::Module::kVersion, kWidgetCIDs, kWidgetContracts, nullptr, nullptr, nsAppShellInit,
nsWidgetUIKitModuleDtor};

NSMODULE_DEFN(nsWidgetUIKitModule) = &kWidgetModule;
Loading

0 comments on commit 071a2fe

Please sign in to comment.