Bug 1598196 - Support disabling the linker on Android in the code. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 21 Nov 2019 14:57:24 +0000
changeset 503746 dbf6218a04ddfa90c8d2348489c8c4798a96888c
parent 503745 8596a38b5dabbd56202cf97d8d8c0541e0c621d0
child 503747 92923aba79d4847a10e79377d8315b4e66e9ba0b
push id36847
push userncsoregi@mozilla.com
push dateTue, 26 Nov 2019 09:34:48 +0000
treeherdermozilla-central@7bc0df30a8a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1598196
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
mozglue/android/APKOpen.cpp
mozglue/android/NSSBridge.cpp
mozglue/android/SQLiteBridge.cpp
mozglue/baseprofiler/core/shared-libraries-linux.cc
mozglue/linker/ElfLoader.cpp
mozglue/linker/Linker.h
mozglue/linker/Logging.cpp
mozglue/linker/Logging.h
mozglue/linker/moz.build
mozglue/misc/StackWalk.cpp
mozglue/misc/moz.build
mozglue/moz.build
old-configure.in
tools/profiler/core/shared-libraries-linux.cc
xpcom/glue/standalone/nsXPCOMGlue.cpp
--- a/mozglue/android/APKOpen.cpp
+++ b/mozglue/android/APKOpen.cpp
@@ -26,17 +26,17 @@
 #include "APKOpen.h"
 #include <sys/time.h>
 #include <sys/syscall.h>
 #include <sys/resource.h>
 #include <sys/prctl.h>
 #include "sqlite3.h"
 #include "SQLiteBridge.h"
 #include "NSSBridge.h"
-#include "ElfLoader.h"
+#include "Linker.h"
 #include "application.ini.h"
 
 #include "mozilla/arm.h"
 #include "mozilla/Bootstrap.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/UniquePtr.h"
 #include "XREChildData.h"
@@ -94,17 +94,17 @@ void JNI_Throw(JNIEnv* jenv, const char*
 }
 
 namespace {
 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.
   }
 
   Dl_info info = {};
   if ((sigact.sa_flags & SA_SIGINFO) &&
       __wrap_dladdr(reinterpret_cast<void*>(sigact.sa_sigaction), &info) &&
       info.dli_fname && strstr(info.dli_fname, "libxul.so")) {
     return;  // Existing signal handler is in libxul (i.e. we have crash
@@ -368,19 +368,23 @@ Java_org_mozilla_gecko_mozglue_GeckoLoad
   char** argv = CreateArgvFromObjectArray(jenv, jargs, &argc);
 
   if (ipcFd < 0) {
     if (gBootstrap == nullptr) {
       FreeArgv(argv, argc);
       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});
     gBootstrap->XRE_SetProcessType(argv[argc - 1]);
 
     XREChildData childData;
     gBootstrap->XRE_InitChildProcess(argc - 1, argv, &childData);
   }
--- a/mozglue/android/NSSBridge.cpp
+++ b/mozglue/android/NSSBridge.cpp
@@ -6,17 +6,17 @@
 #include "dlfcn.h"
 #include "NSSBridge.h"
 #include "APKOpen.h"
 #ifdef ANDROID
 #  include <jni.h>
 #  include <android/log.h>
 #endif
 
-#include "ElfLoader.h"
+#include "Linker.h"
 
 #ifdef DEBUG
 #  define LOG(x...) __android_log_print(ANDROID_LOG_INFO, "GeckoJNI", x)
 #else
 #  define LOG(x...)
 #endif
 
 static bool initialized = false;
--- a/mozglue/android/SQLiteBridge.cpp
+++ b/mozglue/android/SQLiteBridge.cpp
@@ -1,19 +1,20 @@
 /* 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 <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
 #  define LOG(x...) __android_log_print(ANDROID_LOG_INFO, "GeckoJNI", x)
 #else
 #  define LOG(x...)
 #endif
 
--- a/mozglue/baseprofiler/core/shared-libraries-linux.cc
+++ b/mozglue/baseprofiler/core/shared-libraries-linux.cc
@@ -30,17 +30,17 @@
 #  include <features.h>
 #  include <sys/mman.h>
 #  include <sys/stat.h>
 #  include <sys/types.h>
 #  include <vector>
 
 #  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
 #    error "Unexpected configuration"
 #  endif
 
 #  if defined(GP_OS_android)
 extern "C" MOZ_EXPORT __attribute__((weak)) int dl_iterate_phdr(
--- a/mozglue/linker/ElfLoader.cpp
+++ b/mozglue/linker/ElfLoader.cpp
@@ -1317,10 +1317,8 @@ int SEGVHandler::__wrap_sigaction(int si
   /* Use system sigaction() function for all but SIGSEGV signals. */
   if (!that.registeredHandler || (signum != SIGSEGV))
     return sys_sigaction(signum, act, oldact);
 
   if (oldact) *oldact = that.action;
   if (act) that.action = *act;
   return 0;
 }
-
-Logging Logging::Singleton;
new file mode 100644
--- /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 <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
new file mode 100644
--- /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;
--- a/mozglue/linker/Logging.h
+++ b/mozglue/linker/Logging.h
@@ -1,15 +1,16 @@
 /* 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 Logging_h
 #define Logging_h
 
+#include <cstdlib>
 #include "mozilla/Likely.h"
 #include "mozilla/MacroArgs.h"
 
 #ifdef ANDROID
 #  include <android/log.h>
 #  define LOG(...) \
     __android_log_print(ANDROID_LOG_INFO, "GeckoLinker", __VA_ARGS__)
 #  define WARN(...) \
--- a/mozglue/linker/moz.build
+++ b/mozglue/linker/moz.build
@@ -1,20 +1,27 @@
 # -*- Mode: python; 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/.
 
+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',
 ]
 
 Library('linker')
 
 FINAL_LIBRARY = 'mozglue'
 
 TEST_DIRS += ['tests']
--- a/mozglue/misc/StackWalk.cpp
+++ b/mozglue/misc/StackWalk.cpp
@@ -10,17 +10,17 @@
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/StackWalk.h"
 
 #include <string.h>
 
 #if defined(ANDROID) && defined(MOZ_LINKER)
-#  include "ElfLoader.h"
+#  include "Linker.h"
 #  include <android/log.h>
 #endif
 
 using namespace mozilla;
 
 // for _Unwind_Backtrace from libcxxrt or libunwind
 // cxxabi.h from libcxxrt implicitly includes unwind.h first
 #if defined(HAVE__UNWIND_BACKTRACE) && !defined(_GNU_SOURCE)
--- a/mozglue/misc/moz.build
+++ b/mozglue/misc/moz.build
@@ -77,17 +77,17 @@ if CONFIG['OS_ARCH'] == 'WINNT':
         'Mutex_windows.cpp',
     ]
 else:
     SOURCES += [
         'ConditionVariable_posix.cpp',
         'Mutex_posix.cpp',
     ]
 
-if CONFIG['MOZ_LINKER']:
+if CONFIG['MOZ_LINKER'] or CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     LOCAL_INCLUDES += [
         '/mozglue/linker',
     ]
 
 SOURCES += [
     'decimal/Decimal.cpp',
 ]
 
--- a/mozglue/moz.build
+++ b/mozglue/moz.build
@@ -2,17 +2,17 @@
 # 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/.
 
 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':
     DIRS += ['android']
 
 if CONFIG['OS_TARGET'] == 'WINNT':
     DIRS += ['dllservices']
 
--- a/old-configure.in
+++ b/old-configure.in
@@ -2551,17 +2551,17 @@ fi # COMPILE_ENVIRONMENT
 dnl ========================================================
 dnl =
 dnl = Static Build Options
 dnl =
 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
 fi
 
 AC_SUBST(ZLIB_IN_MOZGLUE)
 
 dnl ========================================================
--- a/tools/profiler/core/shared-libraries-linux.cc
+++ b/tools/profiler/core/shared-libraries-linux.cc
@@ -25,17 +25,17 @@
 #include "common/linux/file_id.h"
 #include <algorithm>
 #include <dlfcn.h>
 #include <features.h>
 #include <sys/types.h>
 
 #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
 #  error "Unexpected configuration"
 #endif
 
 #if defined(GP_OS_android)
 extern "C" MOZ_EXPORT __attribute__((weak)) int dl_iterate_phdr(
--- a/xpcom/glue/standalone/nsXPCOMGlue.cpp
+++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp
@@ -94,17 +94,17 @@ static LibHandleType GetLibHandle(pathst
   }
   return libHandle;
 }
 
 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
 
 struct DependentLib {
   LibHandleType libHandle;
   DependentLib* next;
 };
@@ -120,17 +120,17 @@ static void AppendDependentLib(LibHandle
   d->next = sTop;
   d->libHandle = aLibHandle;
 
   sTop = d;
 }
 
 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.
   if (aLibLoadingStrategy == LibLoadingStrategy::ReadAhead) {
     ReadAheadLib(aDependentLib);
   }
 #endif
   LibHandleType libHandle = GetLibHandle(aDependentLib);
@@ -168,17 +168,17 @@ struct ScopedCloseFileTraits {
   static void release(type aFile) {
     if (aFile) {
       fclose(aFile);
     }
   }
 };
 typedef Scoped<ScopedCloseFileTraits> ScopedCloseFile;
 
-#ifndef MOZ_LINKER
+#if !defined(MOZ_LINKER) && !defined(__ANDROID__)
 static void XPCOMGlueUnload() {
   while (sTop) {
     CloseLibHandle(sTop->libHandle);
 
     DependentLib* temp = sTop;
     sTop = sTop->next;
 
     delete temp;
@@ -201,17 +201,17 @@ static const char* ns_strrpbrk(const cha
   }
 
   return found;
 }
 #endif
 
 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;
   }
 #else
   char xpcomDir[MAXPATHLEN];
 #  ifdef XP_WIN
   const char* lastSlash = ns_strrpbrk(aXPCOMFile, "/\\");
 #  elif XP_MACOSX