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
This commit is contained in:
Mike Hommey 2019-11-21 14:57:24 +00:00
parent 83bfe6cee0
commit b1d0510804
15 changed files with 63 additions and 21 deletions

View File

@ -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});

View File

@ -11,7 +11,7 @@
# include <android/log.h>
#endif
#include "ElfLoader.h"
#include "Linker.h"
#ifdef DEBUG
# define LOG(x...) __android_log_print(ANDROID_LOG_INFO, "GeckoJNI", x)

View File

@ -4,11 +4,12 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <jni.h>
#include <android/log.h>
#include "dlfcn.h"
#include "APKOpen.h"
#include "ElfLoader.h"
#include "Linker.h"
#include "SQLiteBridge.h"
#ifdef DEBUG

View File

@ -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 <link.h> // dl_phdr_info
# else

View File

@ -1322,5 +1322,3 @@ int SEGVHandler::__wrap_sigaction(int signum, const struct sigaction* act,
if (act) that.action = *act;
return 0;
}
Logging Logging::Singleton;

24
mozglue/linker/Linker.h Normal file
View File

@ -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 <dlfcn.h>
# include <link.h>
# include <signal.h>
# 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

View File

@ -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;

View File

@ -5,6 +5,7 @@
#ifndef Logging_h
#define Logging_h
#include <cstdlib>
#include "mozilla/Likely.h"
#include "mozilla/MacroArgs.h"

View File

@ -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',
]

View File

@ -15,7 +15,7 @@
#include <string.h>
#if defined(ANDROID) && defined(MOZ_LINKER)
# include "ElfLoader.h"
# include "Linker.h"
# include <android/log.h>
#endif

View File

@ -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',
]

View File

@ -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':

View File

@ -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

View File

@ -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 <link.h> // dl_phdr_info
#else

View File

@ -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<ScopedCloseFileTraits> 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;
}