From b1d0510804b6986b122556f7c11e14003b4a2985 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Thu, 21 Nov 2019 14:57:24 +0000 Subject: [PATCH] Bug 1598196 - Support disabling the linker on Android in the code. r=froydnj For now, there is no flag to actually allow it, but this is the code-side changes to allow the linker being disabled. Differential Revision: https://phabricator.services.mozilla.com/D54074 --HG-- extra : moz-landing-system : lando --- mozglue/android/APKOpen.cpp | 8 +++++-- mozglue/android/NSSBridge.cpp | 2 +- mozglue/android/SQLiteBridge.cpp | 3 ++- .../core/shared-libraries-linux.cc | 2 +- mozglue/linker/ElfLoader.cpp | 2 -- mozglue/linker/Linker.h | 24 +++++++++++++++++++ mozglue/linker/Logging.cpp | 7 ++++++ mozglue/linker/Logging.h | 1 + mozglue/linker/moz.build | 17 +++++++++---- mozglue/misc/StackWalk.cpp | 2 +- mozglue/misc/moz.build | 2 +- mozglue/moz.build | 2 +- old-configure.in | 2 +- tools/profiler/core/shared-libraries-linux.cc | 2 +- xpcom/glue/standalone/nsXPCOMGlue.cpp | 8 +++---- 15 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 mozglue/linker/Linker.h create mode 100644 mozglue/linker/Logging.cpp diff --git a/mozglue/android/APKOpen.cpp b/mozglue/android/APKOpen.cpp index 1ab1d2acf9c0..b0d43a355c1e 100644 --- a/mozglue/android/APKOpen.cpp +++ b/mozglue/android/APKOpen.cpp @@ -31,7 +31,7 @@ #include "sqlite3.h" #include "SQLiteBridge.h" #include "NSSBridge.h" -#include "ElfLoader.h" +#include "Linker.h" #include "application.ini.h" #include "mozilla/arm.h" @@ -99,7 +99,7 @@ JavaVM* sJavaVM; void abortThroughJava(const char* msg) { struct sigaction sigact = {}; - if (SEGVHandler::__wrap_sigaction(SIGSEGV, nullptr, &sigact)) { + if (__wrap_sigaction(SIGSEGV, nullptr, &sigact)) { return; // sigaction call failed. } @@ -373,9 +373,13 @@ Java_org_mozilla_gecko_mozglue_GeckoLoader_nativeRun(JNIEnv* jenv, jclass jc, return; } +#ifdef MOZ_LINKER ElfLoader::Singleton.ExpectShutdown(false); +#endif gBootstrap->GeckoStart(jenv, argv, argc, sAppData); +#ifdef MOZ_LINKER ElfLoader::Singleton.ExpectShutdown(true); +#endif } else { gBootstrap->XRE_SetAndroidChildFds( jenv, {prefsFd, prefMapFd, ipcFd, crashFd, crashAnnotationFd}); diff --git a/mozglue/android/NSSBridge.cpp b/mozglue/android/NSSBridge.cpp index 98ab1d3fdb97..e54fbbf2bf32 100644 --- a/mozglue/android/NSSBridge.cpp +++ b/mozglue/android/NSSBridge.cpp @@ -11,7 +11,7 @@ # include #endif -#include "ElfLoader.h" +#include "Linker.h" #ifdef DEBUG # define LOG(x...) __android_log_print(ANDROID_LOG_INFO, "GeckoJNI", x) diff --git a/mozglue/android/SQLiteBridge.cpp b/mozglue/android/SQLiteBridge.cpp index cf78e45b351a..1f53f94dfbf4 100644 --- a/mozglue/android/SQLiteBridge.cpp +++ b/mozglue/android/SQLiteBridge.cpp @@ -4,11 +4,12 @@ #include #include +#include #include #include #include "dlfcn.h" #include "APKOpen.h" -#include "ElfLoader.h" +#include "Linker.h" #include "SQLiteBridge.h" #ifdef DEBUG diff --git a/mozglue/baseprofiler/core/shared-libraries-linux.cc b/mozglue/baseprofiler/core/shared-libraries-linux.cc index 14022fb592de..e0279bd6720a 100644 --- a/mozglue/baseprofiler/core/shared-libraries-linux.cc +++ b/mozglue/baseprofiler/core/shared-libraries-linux.cc @@ -35,7 +35,7 @@ # if defined(MOZ_LINKER) # include "AutoObjectMapper.h" -# include "ElfLoader.h" // dl_phdr_info +# include "Linker.h" // dl_phdr_info # elif defined(GP_OS_linux) || defined(GP_OS_android) # include // dl_phdr_info # else diff --git a/mozglue/linker/ElfLoader.cpp b/mozglue/linker/ElfLoader.cpp index 67f3f6debfe3..9d43d095e532 100644 --- a/mozglue/linker/ElfLoader.cpp +++ b/mozglue/linker/ElfLoader.cpp @@ -1322,5 +1322,3 @@ int SEGVHandler::__wrap_sigaction(int signum, const struct sigaction* act, if (act) that.action = *act; return 0; } - -Logging Logging::Singleton; diff --git a/mozglue/linker/Linker.h b/mozglue/linker/Linker.h new file mode 100644 index 000000000000..77ddb06ecc07 --- /dev/null +++ b/mozglue/linker/Linker.h @@ -0,0 +1,24 @@ +/* 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 Linker_h +#define Linker_h + +#ifdef MOZ_LINKER +# include "ElfLoader.h" +# define __wrap_sigaction SEGVHandler::__wrap_sigaction +#else +# include +# include +# include +# define __wrap_sigaction sigaction +# define __wrap_dlopen dlopen +# define __wrap_dlerror dlerror +# define __wrap_dlsym dlsym +# define __wrap_dlclose dlclose +# define __wrap_dladdr dladdr +# define __wrap_dl_iterate_phdr dl_iterate_phdr +#endif + +#endif diff --git a/mozglue/linker/Logging.cpp b/mozglue/linker/Logging.cpp new file mode 100644 index 000000000000..e61c7835d24a --- /dev/null +++ b/mozglue/linker/Logging.cpp @@ -0,0 +1,7 @@ +/* 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 "Logging.h" + +Logging Logging::Singleton; diff --git a/mozglue/linker/Logging.h b/mozglue/linker/Logging.h index 54e16ff091c1..1e66ea41de31 100644 --- a/mozglue/linker/Logging.h +++ b/mozglue/linker/Logging.h @@ -5,6 +5,7 @@ #ifndef Logging_h #define Logging_h +#include #include "mozilla/Likely.h" #include "mozilla/MacroArgs.h" diff --git a/mozglue/linker/moz.build b/mozglue/linker/moz.build index 91b8bf07f81e..847d3399c712 100644 --- a/mozglue/linker/moz.build +++ b/mozglue/linker/moz.build @@ -4,12 +4,19 @@ # 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 CONFIG['MOZ_LINKER']: + SOURCES += [ + 'BaseElf.cpp', + 'CustomElf.cpp', + 'ElfLoader.cpp', + 'Mappable.cpp', + 'XZStream.cpp', + ] + +# When the linker is disabled, we still need Zip for mozglue/android. +# Logging is a required dependency. SOURCES += [ - 'BaseElf.cpp', - 'CustomElf.cpp', - 'ElfLoader.cpp', - 'Mappable.cpp', - 'XZStream.cpp', + 'Logging.cpp', 'Zip.cpp', ] diff --git a/mozglue/misc/StackWalk.cpp b/mozglue/misc/StackWalk.cpp index 2a42defec7d2..f443baa22013 100644 --- a/mozglue/misc/StackWalk.cpp +++ b/mozglue/misc/StackWalk.cpp @@ -15,7 +15,7 @@ #include #if defined(ANDROID) && defined(MOZ_LINKER) -# include "ElfLoader.h" +# include "Linker.h" # include #endif diff --git a/mozglue/misc/moz.build b/mozglue/misc/moz.build index c047e9ad9b8b..247682cc0384 100644 --- a/mozglue/misc/moz.build +++ b/mozglue/misc/moz.build @@ -82,7 +82,7 @@ else: 'Mutex_posix.cpp', ] -if CONFIG['MOZ_LINKER']: +if CONFIG['MOZ_LINKER'] or CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android': LOCAL_INCLUDES += [ '/mozglue/linker', ] diff --git a/mozglue/moz.build b/mozglue/moz.build index abf2d169c240..e990195da8f0 100644 --- a/mozglue/moz.build +++ b/mozglue/moz.build @@ -7,7 +7,7 @@ with Files("**"): BUG_COMPONENT = ("Core", "mozglue") -if CONFIG['MOZ_LINKER']: +if CONFIG['MOZ_LINKER'] or CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android': DIRS += ['linker'] if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android': diff --git a/old-configure.in b/old-configure.in index 16b9211de4fd..c20ef7bc67ab 100644 --- a/old-configure.in +++ b/old-configure.in @@ -2556,7 +2556,7 @@ dnl ======================================================== MOZ_ARG_HEADER(Static build options) if test -z "$MOZ_SYSTEM_ZLIB"; then -if test -n "$JS_SHARED_LIBRARY" -o -n "$MOZ_LINKER"; then +if test -n "$JS_SHARED_LIBRARY" -o -n "$MOZ_LINKER" -o "$MOZ_WIDGET_TOOLKIT" = android; then ZLIB_IN_MOZGLUE=1 AC_DEFINE(ZLIB_IN_MOZGLUE) fi diff --git a/tools/profiler/core/shared-libraries-linux.cc b/tools/profiler/core/shared-libraries-linux.cc index 6fe3d009dc61..7c0f3dbf19b8 100644 --- a/tools/profiler/core/shared-libraries-linux.cc +++ b/tools/profiler/core/shared-libraries-linux.cc @@ -30,7 +30,7 @@ #if defined(MOZ_LINKER) # include "AutoObjectMapper.h" -# include "ElfLoader.h" // dl_phdr_info +# include "Linker.h" // dl_phdr_info #elif defined(GP_OS_linux) || defined(GP_OS_android) # include // dl_phdr_info #else diff --git a/xpcom/glue/standalone/nsXPCOMGlue.cpp b/xpcom/glue/standalone/nsXPCOMGlue.cpp index 07ee0bb686fb..44f26fdd99a6 100644 --- a/xpcom/glue/standalone/nsXPCOMGlue.cpp +++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp @@ -99,7 +99,7 @@ static NSFuncPtr GetSymbol(LibHandleType aLibHandle, const char* aSymbol) { return (NSFuncPtr)dlsym(aLibHandle, aSymbol); } -# ifndef MOZ_LINKER +# if !defined(MOZ_LINKER) && !defined(__ANDROID__) static void CloseLibHandle(LibHandleType aLibHandle) { dlclose(aLibHandle); } # endif #endif @@ -125,7 +125,7 @@ static void AppendDependentLib(LibHandleType aLibHandle) { static bool ReadDependentCB(pathstr_t aDependentLib, LibLoadingStrategy aLibLoadingStrategy) { -#ifndef MOZ_LINKER +#if !defined(MOZ_LINKER) && !defined(__ANDROID__) // Don't bother doing a ReadAhead if we're not in the parent process. // What we need from the library should already be in the system file // cache. @@ -173,7 +173,7 @@ struct ScopedCloseFileTraits { }; typedef Scoped ScopedCloseFile; -#ifndef MOZ_LINKER +#if !defined(MOZ_LINKER) && !defined(__ANDROID__) static void XPCOMGlueUnload() { while (sTop) { CloseLibHandle(sTop->libHandle); @@ -206,7 +206,7 @@ static const char* ns_strrpbrk(const char* string, const char* strCharSet) { static nsresult XPCOMGlueLoad(const char* aXPCOMFile, LibLoadingStrategy aLibLoadingStrategy) { -#ifdef MOZ_LINKER +#if defined(MOZ_LINKER) || defined(__ANDROID__) if (!ReadDependentCB(aXPCOMFile, aLibLoadingStrategy)) { return NS_ERROR_FAILURE; }