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 523195 904db16056b4
parent 523194 d667a13de417
child 523196 cd1e0b429eff
push id11098
push userapavel@mozilla.com
push dateTue, 16 Apr 2019 13:54:52 +0000
treeherdermozilla-beta@75a92a484e17 [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()) {