Bug 1543555 - Stop using our linker to resolve libc/libm symbols when not strictly necessary. r=froydnj a=pascalc
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 12 Apr 2019 02:12:31 +0000
changeset 526193 904db16056b425afb588f34fa480cec86d618335
parent 526192 d667a13de4174df377f65a2f457c3b9eaa1f1ffd
child 526194 cd1e0b429eff6abc69f7aa0b547e06b8afaa17a4
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, pascalc
bugs1543555
milestone67.0
Bug 1543555 - Stop using our linker to resolve libc/libm symbols when not strictly necessary. r=froydnj a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D27019
mozglue/linker/ElfLoader.cpp
--- a/mozglue/linker/ElfLoader.cpp
+++ b/mozglue/linker/ElfLoader.cpp
@@ -589,21 +589,26 @@ void ElfLoader::Init() {
   Dl_info info;
   /* On Android < 4.1 can't reenter dl* functions. So when the library
    * containing this code is dlopen()ed, it can't call dladdr from a
    * static initializer. */
   if (dladdr(_DYNAMIC, &info) != 0) {
     self_elf = LoadedElf::Create(info.dli_fname, info.dli_fbase);
   }
 #if defined(ANDROID)
-  if (dladdr(FunctionPtr(syscall), &info) != 0) {
-    libc = LoadedElf::Create(info.dli_fname, info.dli_fbase);
-  }
-  if (dladdr(FunctionPtr<int (*)(double)>(isnan), &info) != 0) {
-    libm = LoadedElf::Create(info.dli_fname, info.dli_fbase);
+  // On Android < 5.0, resolving weak symbols via dlsym doesn't work.
+  // The weak symbols Gecko uses are in either libc or libm, so we
+  // wrap those such that this linker does symbol resolution for them.
+  if (GetAndroidSDKVersion() < 21) {
+    if (dladdr(FunctionPtr(syscall), &info) != 0) {
+      libc = LoadedElf::Create(info.dli_fname, info.dli_fbase);
+    }
+    if (dladdr(FunctionPtr<int (*)(double)>(isnan), &info) != 0) {
+      libm = LoadedElf::Create(info.dli_fname, info.dli_fbase);
+    }
   }
 #endif
 }
 
 ElfLoader::~ElfLoader() {
   LibHandleList list;
 
   if (!Singleton.IsShutdownExpected()) {