OSDN Git Service

Bionic loader is no longer hijacking libdl.so
authorDimitry Ivanov <dimitry@google.com>
Wed, 23 Nov 2016 00:55:25 +0000 (16:55 -0800)
committerDimitry Ivanov <dimitry@google.com>
Fri, 9 Dec 2016 22:53:59 +0000 (14:53 -0800)
Do not hijack libdl.so methods but make libdl proxy calls to
loader instead. This will be replaces by calls to libc.so
once loader functionality is migrated.

Also add a lock to dl_unwind_find_exidx function call.

Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Bug: http://b/27106625
Change-Id: Ic33a7109a86f4262798d63a35f4c61d15b0068bb

libdl/Android.bp
libdl/ld_android.c [new file with mode: 0644]
libdl/libdl.c
linker/Android.bp
linker/dlfcn.cpp
linker/linker.cpp
linker/linker.h
linker/linker_main.cpp
linker/linker_soinfo.h

index 9db3a94..e9b79d7 100644 (file)
@@ -57,6 +57,55 @@ cc_library {
     allow_undefined_symbols: true,
     system_shared_libs: [],
 
+    // This is placeholder library the actual implementation is (currently)
+    // provided by the linker.
+    shared_libs: [ "ld-android" ],
+
+    sanitize: {
+        never: true,
+    },
+}
+
+cc_library {
+    // NOTE: --exclude-libs=libgcc.a makes sure that any symbols libdl.so pulls from
+    // libgcc.a are made static to ld-android.so.  This in turn ensures that libraries that
+    // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
+    // to provide those symbols, but will instead pull them from libgcc.a.  Specifically,
+    // we use this property to make sure libc.so has its own copy of the code from
+    // libgcc.a it uses.
+    //
+    // DO NOT REMOVE --exclude-libs!
+
+    ldflags: ["-Wl,--exclude-libs=libgcc.a"],
+
+    // for x86, exclude libgcc_eh.a for the same reasons as above
+    arch: {
+        x86: {
+            ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
+        },
+        x86_64: {
+            ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
+        },
+    },
+    srcs: ["ld_android.c"],
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Wunused",
+        "-Werror",
+    ],
+    stl: "none",
+
+    name: "ld-android",
+
+    // NOTE: libdl needs __aeabi_unwind_cpp_pr0 from libgcc.a but libgcc.a needs a
+    // few symbols from libc. Using --no-undefined here results in having to link
+    // against libc creating a circular dependency which is removed and we end up
+    // with missing symbols. Since this library is just a bunch of stubs, we set
+    // LOCAL_ALLOW_UNDEFINED_SYMBOLS to remove --no-undefined from the linker flags.
+    allow_undefined_symbols: true,
+    system_shared_libs: [],
+
     sanitize: {
         never: true,
     },
diff --git a/libdl/ld_android.c b/libdl/ld_android.c
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
index 4cc4dea..8329468 100644 (file)
 #include <stdbool.h>
 #include <android/dlext.h>
 
-// These are stubs for functions that are actually defined
-// in the dynamic linker and hijacked at runtime.
+// These functions are exported by the loader
+// TODO(dimitry): replace these with reference to libc.so
 
-void* dlopen(const char* filename __unused, int flag __unused) { return 0; }
+__attribute__((__weak__, visibility("default")))
+void* __loader_dlopen(const char* filename, int flags, const void* caller_addr);
 
-char* dlerror(void) { return 0; }
+__attribute__((__weak__, visibility("default")))
+void* __loader_dlerror();
 
-void* dlsym(void* handle __unused, const char* symbol __unused) { return 0; }
+__attribute__((__weak__, visibility("default")))
+void* __loader_dlsym(void* handle, const char* symbol, const void* caller_addr);
 
-void* dlvsym(void* handle __unused, const char* symbol __unused, const char* version __unused) {
-  return 0;
+__attribute__((__weak__, visibility("default")))
+void* __loader_dlvsym(void* handle,
+                      const char* symbol,
+                      const char* version,
+                      const void* caller_addr);
+
+__attribute__((__weak__, visibility("default")))
+int __loader_dladdr(const void* addr, Dl_info* info);
+
+__attribute__((__weak__, visibility("default")))
+int __loader_dlclose(void* handle);
+
+#if defined(__arm__)
+__attribute__((__weak__, visibility("default")))
+_Unwind_Ptr __loader_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
+#endif
+
+__attribute__((__weak__, visibility("default")))
+int __loader_dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data),
+                             void* data);
+
+__attribute__((__weak__, visibility("default")))
+void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size);
+
+__attribute__((__weak__, visibility("default")))
+void __loader_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
+
+__attribute__((__weak__, visibility("default")))
+void* __loader_android_dlopen_ext(const char* filename,
+                                  int flag,
+                                  const android_dlextinfo* extinfo,
+                                  const void* caller_addr);
+
+__attribute__((__weak__, visibility("default")))
+void __loader_android_set_application_target_sdk_version(uint32_t target);
+
+__attribute__((__weak__, visibility("default")))
+uint32_t __loader_android_get_application_target_sdk_version();
+
+__attribute__((__weak__, visibility("default")))
+bool __loader_android_init_namespaces(const char* public_ns_sonames,
+                                      const char* anon_ns_library_path);
+
+__attribute__((__weak__, visibility("default")))
+struct android_namespace_t* __loader_android_create_namespace(
+                                const char* name,
+                                const char* ld_library_path,
+                                const char* default_library_path,
+                                uint64_t type,
+                                const char* permitted_when_isolated_path,
+                                struct android_namespace_t* parent,
+                                const void* caller_addr);
+
+// Proxy calls to bionic loader
+void* dlopen(const char* filename, int flag) {
+  const void* caller_addr = __builtin_return_address(0);
+  return __loader_dlopen(filename, flag, caller_addr);
+}
+
+char* dlerror() {
+  return __loader_dlerror();
+}
+
+void* dlsym(void* handle, const char* symbol) {
+  const void* caller_addr = __builtin_return_address(0);
+  return __loader_dlsym(handle, symbol, caller_addr);
 }
 
-int dladdr(const void* addr __unused, Dl_info* info __unused) { return 0; }
+void* dlvsym(void* handle, const char* symbol, const char* version) {
+  const void* caller_addr = __builtin_return_address(0);
+  return __loader_dlvsym(handle, symbol, version, caller_addr);
+}
 
-int dlclose(void* handle __unused) { return 0; }
+int dladdr(const void* addr, Dl_info* info) {
+  return __loader_dladdr(addr, info);
+}
+
+int dlclose(void* handle) {
+  return __loader_dlclose(handle);
+}
 
 #if defined(__arm__)
-_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc __unused, int* pcount __unused) { return 0; }
+_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
+  return __loader_dl_unwind_find_exidx(pc, pcount);
+}
 #endif
 
-int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data) __unused,
-                    void* data __unused) {
-  return 0;
+int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data), void* data) {
+  return __loader_dl_iterate_phdr(cb, data);
 }
 
-void android_get_LD_LIBRARY_PATH(char* buffer __unused, size_t buffer_size __unused) { }
-void android_update_LD_LIBRARY_PATH(const char* ld_library_path __unused) { }
+void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
+  __loader_android_get_LD_LIBRARY_PATH(buffer, buffer_size);
+}
+
+void android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
+  __loader_android_update_LD_LIBRARY_PATH(ld_library_path);
+}
 
-void* android_dlopen_ext(const char* filename __unused, int flag __unused,
-                         const android_dlextinfo* extinfo __unused) {
-  return 0;
+void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo) {
+  const void* caller_addr = __builtin_return_address(0);
+  return __loader_android_dlopen_ext(filename, flag, extinfo, caller_addr);
 }
 
-void android_set_application_target_sdk_version(uint32_t target __unused) { }
-uint32_t android_get_application_target_sdk_version() { return 0; }
+void android_set_application_target_sdk_version(uint32_t target) {
+  __loader_android_set_application_target_sdk_version(target);
+}
+uint32_t android_get_application_target_sdk_version() {
+  return __loader_android_get_application_target_sdk_version();
+}
 
-bool android_init_namespaces(const char* public_ns_sonames __unused,
-                             const char* anon_ns_library_path __unused) {
-  return false;
+bool android_init_namespaces(const char* public_ns_sonames,
+                             const char* anon_ns_library_path) {
+  return __loader_android_init_namespaces(public_ns_sonames, anon_ns_library_path);
 }
 
-struct android_namespace_t* android_create_namespace(const char* name __unused,
-                                                     const char* ld_library_path __unused,
-                                                     const char* default_library_path __unused,
-                                                     uint64_t type __unused,
-                                                     const char* permitted_when_isolated_path __unused) {
-  return 0;
+struct android_namespace_t* android_create_namespace(const char* name,
+                                                     const char* ld_library_path,
+                                                     const char* default_library_path,
+                                                     uint64_t type,
+                                                     const char* permitted_when_isolated_path,
+                                                     struct android_namespace_t* parent) {
+  const void* caller_addr = __builtin_return_address(0);
+  return __loader_android_create_namespace(name,
+                                           ld_library_path,
+                                           default_library_path,
+                                           type,
+                                           permitted_when_isolated_path,
+                                           parent,
+                                           caller_addr);
 }
 
 void android_dlwarning(void* obj, void (*f)(void*, const char*)) { f(obj, 0); }
index 239e54b..a3b9cb2 100644 (file)
@@ -1,6 +1,5 @@
 cc_library_static {
     name: "liblinker_malloc",
-    clang: true,
     defaults: ["linux_bionic_supported"],
 
     srcs: [
@@ -13,9 +12,7 @@ cc_library_static {
 }
 
 cc_binary {
-    clang: true,
     defaults: ["linux_bionic_supported"],
-
     srcs: [
         "dlfcn.cpp",
         "linker.cpp",
@@ -99,8 +96,6 @@ cc_binary {
         "-Werror",
     ],
 
-    conlyflags: ["-std=gnu99"],
-
     cppflags: ["-Wold-style-cast"],
 
     // we are going to link libc++_static manually because
index 3ac61d7..feb36cf 100644 (file)
@@ -52,23 +52,25 @@ static void __bionic_format_dlerror(const char* msg, const char* detail) {
   __bionic_set_dlerror(buffer);
 }
 
-char* dlerror() {
+char* __dlerror() {
   char* old_value = __bionic_set_dlerror(nullptr);
   return old_value;
 }
 
-void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
+void __android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   do_android_get_LD_LIBRARY_PATH(buffer, buffer_size);
 }
 
-void android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
+void __android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   do_android_update_LD_LIBRARY_PATH(ld_library_path);
 }
 
-static void* dlopen_ext(const char* filename, int flags,
-                        const android_dlextinfo* extinfo, void* caller_addr) {
+static void* dlopen_ext(const char* filename,
+                        int flags,
+                        const android_dlextinfo* extinfo,
+                        const void* caller_addr) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   g_linker_logger.ResetState();
   void* result = do_dlopen(filename, flags, extinfo, caller_addr);
@@ -79,17 +81,18 @@ static void* dlopen_ext(const char* filename, int flags,
   return result;
 }
 
-void* android_dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo) {
-  void* caller_addr = __builtin_return_address(0);
+void* __android_dlopen_ext(const char* filename,
+                           int flags,
+                           const android_dlextinfo* extinfo,
+                           const void* caller_addr) {
   return dlopen_ext(filename, flags, extinfo, caller_addr);
 }
 
-void* dlopen(const char* filename, int flags) {
-  void* caller_addr = __builtin_return_address(0);
+void* __dlopen(const char* filename, int flags, const void* caller_addr) {
   return dlopen_ext(filename, flags, nullptr, caller_addr);
 }
 
-void* dlsym_impl(void* handle, const char* symbol, const char* version, void* caller_addr) {
+void* dlsym_impl(void* handle, const char* symbol, const char* version, const void* caller_addr) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   g_linker_logger.ResetState();
   void* result;
@@ -101,22 +104,20 @@ void* dlsym_impl(void* handle, const char* symbol, const char* version, void* ca
   return result;
 }
 
-void* dlsym(void* handle, const char* symbol) {
-  void* caller_addr = __builtin_return_address(0);
+void* __dlsym(void* handle, const char* symbol, const void* caller_addr) {
   return dlsym_impl(handle, symbol, nullptr, caller_addr);
 }
 
-void* dlvsym(void* handle, const char* symbol, const char* version) {
-  void* caller_addr = __builtin_return_address(0);
+void* __dlvsym(void* handle, const char* symbol, const char* version, const void* caller_addr) {
   return dlsym_impl(handle, symbol, version, caller_addr);
 }
 
-int dladdr(const void* addr, Dl_info* info) {
+int __dladdr(const void* addr, Dl_info* info) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   return do_dladdr(addr, info);
 }
 
-int dlclose(void* handle) {
+int __dlclose(void* handle) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   int result = do_dlclose(handle);
   if (result != 0) {
@@ -125,27 +126,35 @@ int dlclose(void* handle) {
   return result;
 }
 
+// This function is needed by libgcc.a (this is why there is no prefix for this one)
 int dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void* data) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   return do_dl_iterate_phdr(cb, data);
 }
 
-void android_set_application_target_sdk_version(uint32_t target) {
+#if defined(__arm__)
+_Unwind_Ptr __dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
+  ScopedPthreadMutexLocker locker(&g_dl_mutex);
+  return do_dl_unwind_find_exidx(pc, pcount);
+}
+#endif
+
+void __android_set_application_target_sdk_version(uint32_t target) {
   // lock to avoid modification in the middle of dlopen.
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   set_application_target_sdk_version(target);
 }
 
-uint32_t android_get_application_target_sdk_version() {
+uint32_t __android_get_application_target_sdk_version() {
   return get_application_target_sdk_version();
 }
 
-void android_dlwarning(void* obj, void (*f)(void*, const char*)) {
+void __android_dlwarning(void* obj, void (*f)(void*, const char*)) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   get_dlwarning(obj, f);
 }
 
-bool android_init_namespaces(const char* public_ns_sonames,
+bool __android_init_namespaces(const char* public_ns_sonames,
                              const char* anon_ns_library_path) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
   bool success = init_namespaces(public_ns_sonames, anon_ns_library_path);
@@ -156,13 +165,13 @@ bool android_init_namespaces(const char* public_ns_sonames,
   return success;
 }
 
-android_namespace_t* android_create_namespace(const char* name,
-                                              const char* ld_library_path,
-                                              const char* default_library_path,
-                                              uint64_t type,
-                                              const char* permitted_when_isolated_path,
-                                              android_namespace_t* parent_namespace) {
-  void* caller_addr = __builtin_return_address(0);
+android_namespace_t* __android_create_namespace(const char* name,
+                                                const char* ld_library_path,
+                                                const char* default_library_path,
+                                                uint64_t type,
+                                                const char* permitted_when_isolated_path,
+                                                android_namespace_t* parent_namespace,
+                                                const void* caller_addr) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
 
   android_namespace_t* result = create_namespace(caller_addr,
@@ -200,18 +209,28 @@ android_namespace_t* android_create_namespace(const char* name,
     }
 
 static const char ANDROID_LIBDL_STRTAB[] =
-  // 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667777777777888888888899999 99999
-  // 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890123456789012345678901234 56789
-    "dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0android_get_LD_LIBRARY_PATH\0dl_it"
-  // 00000000001 1111111112222222222 3333333333444444444455555555556666666666777 777777788888888889999999999
-  // 01234567890 1234567890123456789 0123456789012345678901234567890123456789012 345678901234567890123456789
-    "erate_phdr\0android_dlopen_ext\0android_set_application_target_sdk_version\0android_get_application_tar"
-  // 0000000000111111 111122222222223333333333 4444444444555555555566666 6666677 777777778888888888
-  // 0123456789012345 678901234567890123456789 0123456789012345678901234 5678901 234567890123456789
-    "get_sdk_version\0android_init_namespaces\0android_create_namespace\0dlvsym\0android_dlwarning\0"
+  // 0000000000111111 11112222222222333 333333344444444 44555555555566666 6666677777777778 8888888889999999999
+  // 0123456789012345 67890123456789012 345678901234567 89012345678901234 5678901234567890 1234567890123456789
+    "__loader_dlopen\0__loader_dlclose\0__loader_dlsym\0__loader_dlerror\0__loader_dladdr\0__loader_android_up"
+  // 1*
+  // 000000000011111111112 2222222223333333333444444444455555555 5566666666667777777777888 88888889999999999
+  // 012345678901234567890 1234567890123456789012345678901234567 8901234567890123456789012 34567890123456789
+    "date_LD_LIBRARY_PATH\0__loader_android_get_LD_LIBRARY_PATH\0__loader_dl_iterate_phdr\0__loader_android_"
+  // 2*
+  // 00000000001 1111111112222222222333333333344444444445555555555666 6666666777777777788888888889999999999
+  // 01234567890 1234567890123456789012345678901234567890123456789012 3456789012345678901234567890123456789
+    "dlopen_ext\0__loader_android_set_application_target_sdk_version\0__loader_android_get_application_targ"
+  // 3*
+  // 000000000011111 111112222222222333333333344444444 4455555555556666666666777777777788 888888889999999 999
+  // 012345678901234 567890123456789012345678901234567 8901234567890123456789012345678901 234567890123456 789
+    "et_sdk_version\0__loader_android_init_namespaces\0__loader_android_create_namespace\0__loader_dlvsym\0__"
+  // 4*
+  // 0000000000111111111122222 2222233333333334444444 4445555555555666666666677777777778 8888888889999999 999
+  // 0123456789012345678901234 5678901234567890123456 7890123456789012345678901234567890 1234567890123456 789
+    "loader_android_dlwarning\0"
 #if defined(__arm__)
-  // 290
-    "dl_unwind_find_exidx\0"
+  // 425
+    "__loader_dl_unwind_find_exidx\0"
 #endif
     ;
 
@@ -221,23 +240,23 @@ static ElfW(Sym) g_libdl_symtab[] = {
   // supposed to have st_name == 0, but instead, it points to an index
   // in the strtab with a \0 to make iterating through the symtab easier.
   ELFW(SYM_INITIALIZER)(sizeof(ANDROID_LIBDL_STRTAB) - 1, nullptr, 0),
-  ELFW(SYM_INITIALIZER)(  0, &dlopen, 1),
-  ELFW(SYM_INITIALIZER)(  7, &dlclose, 1),
-  ELFW(SYM_INITIALIZER)( 15, &dlsym, 1),
-  ELFW(SYM_INITIALIZER)( 21, &dlerror, 1),
-  ELFW(SYM_INITIALIZER)( 29, &dladdr, 1),
-  ELFW(SYM_INITIALIZER)( 36, &android_update_LD_LIBRARY_PATH, 1),
-  ELFW(SYM_INITIALIZER)( 67, &android_get_LD_LIBRARY_PATH, 1),
-  ELFW(SYM_INITIALIZER)( 95, &dl_iterate_phdr, 1),
-  ELFW(SYM_INITIALIZER)(111, &android_dlopen_ext, 1),
-  ELFW(SYM_INITIALIZER)(130, &android_set_application_target_sdk_version, 1),
-  ELFW(SYM_INITIALIZER)(173, &android_get_application_target_sdk_version, 1),
-  ELFW(SYM_INITIALIZER)(216, &android_init_namespaces, 1),
-  ELFW(SYM_INITIALIZER)(240, &android_create_namespace, 1),
-  ELFW(SYM_INITIALIZER)(265, &dlvsym, 1),
-  ELFW(SYM_INITIALIZER)(272, &android_dlwarning, 1),
+  ELFW(SYM_INITIALIZER)(  0, &__dlopen, 1),
+  ELFW(SYM_INITIALIZER)( 16, &__dlclose, 1),
+  ELFW(SYM_INITIALIZER)( 33, &__dlsym, 1),
+  ELFW(SYM_INITIALIZER)( 48, &__dlerror, 1),
+  ELFW(SYM_INITIALIZER)( 65, &__dladdr, 1),
+  ELFW(SYM_INITIALIZER)( 81, &__android_update_LD_LIBRARY_PATH, 1),
+  ELFW(SYM_INITIALIZER)(121, &__android_get_LD_LIBRARY_PATH, 1),
+  ELFW(SYM_INITIALIZER)(158, &dl_iterate_phdr, 1),
+  ELFW(SYM_INITIALIZER)(183, &__android_dlopen_ext, 1),
+  ELFW(SYM_INITIALIZER)(211, &__android_set_application_target_sdk_version, 1),
+  ELFW(SYM_INITIALIZER)(263, &__android_get_application_target_sdk_version, 1),
+  ELFW(SYM_INITIALIZER)(315, &__android_init_namespaces, 1),
+  ELFW(SYM_INITIALIZER)(348, &__android_create_namespace, 1),
+  ELFW(SYM_INITIALIZER)(382, &__dlvsym, 1),
+  ELFW(SYM_INITIALIZER)(397, &__android_dlwarning, 1),
 #if defined(__arm__)
-  ELFW(SYM_INITIALIZER)(290, &dl_unwind_find_exidx, 1),
+  ELFW(SYM_INITIALIZER)(425, &__dl_unwind_find_exidx, 1),
 #endif
 };
 
@@ -263,9 +282,9 @@ static uint8_t __libdl_info_buf[sizeof(soinfo)] __attribute__((aligned(8)));
 static soinfo* __libdl_info = nullptr;
 
 // This is used by the dynamic linker. Every process gets these symbols for free.
-soinfo* get_libdl_info() {
+soinfo* get_libdl_info(const char* linker_path) {
   if (__libdl_info == nullptr) {
-    __libdl_info = new (__libdl_info_buf) soinfo(&g_default_namespace, "libdl.so", nullptr, 0, RTLD_GLOBAL);
+    __libdl_info = new (__libdl_info_buf) soinfo(&g_default_namespace, linker_path, nullptr, 0, 0);
     __libdl_info->flags_ |= FLAG_LINKED;
     __libdl_info->strtab_ = ANDROID_LIBDL_STRTAB;
     __libdl_info->symtab_ = g_libdl_symtab;
@@ -276,7 +295,7 @@ soinfo* get_libdl_info() {
     __libdl_info->ref_count_ = 1;
     __libdl_info->strtab_size_ = sizeof(ANDROID_LIBDL_STRTAB);
     __libdl_info->local_group_root_ = __libdl_info;
-    __libdl_info->soname_ = "libdl.so";
+    __libdl_info->soname_ = "ld-android.so";
     __libdl_info->target_sdk_version_ = __ANDROID_API__;
     __libdl_info->generate_handle();
 #if defined(__work_around_b_24465209__)
index be4b584..d3ab8d8 100644 (file)
@@ -324,9 +324,7 @@ static bool realpath_fd(int fd, std::string* realpath) {
 // in that section (via *pcount).
 //
 // Intended to be called by libc's __gnu_Unwind_Find_exidx().
-//
-// This function is exposed via dlfcn.cpp and libdl.so.
-_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
+_Unwind_Ptr do_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
   uintptr_t addr = reinterpret_cast<uintptr_t>(pc);
 
   for (soinfo* si = solist_get_head(); si != 0; si = si->next) {
@@ -1730,8 +1728,9 @@ static std::string android_dlextinfo_to_string(const android_dlextinfo* info) {
                                         info->library_namespace : nullptr);
 }
 
-void* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo,
-                  void* caller_addr) {
+void* do_dlopen(const char* name, int flags,
+                const android_dlextinfo* extinfo,
+                const void* caller_addr) {
   soinfo* const caller = find_containing_library(caller_addr);
   android_namespace_t* ns = get_caller_namespace(caller);
 
@@ -1858,8 +1857,11 @@ static soinfo* soinfo_from_handle(void* handle) {
   return static_cast<soinfo*>(handle);
 }
 
-bool do_dlsym(void* handle, const char* sym_name, const char* sym_ver,
-              void* caller_addr, void** symbol) {
+bool do_dlsym(void* handle,
+              const char* sym_name,
+              const char* sym_ver,
+              const void* caller_addr,
+              void** symbol) {
 #if !defined(__LP64__)
   if (handle == nullptr) {
     DL_ERR("dlsym failed: library handle is null");
index 4787471..c65d503 100644 (file)
@@ -101,17 +101,27 @@ enum RelocationKind {
 
 void count_relocation(RelocationKind kind);
 
-soinfo* get_libdl_info();
+soinfo* get_libdl_info(const char* linker_path);
 
 void do_android_get_LD_LIBRARY_PATH(char*, size_t);
 void do_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
-void* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo, void* caller_addr);
+void* do_dlopen(const char* name,
+                int flags,
+                const android_dlextinfo* extinfo,
+                const void* caller_addr);
+
 int do_dlclose(void* handle);
 
 int do_dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void* data);
 
-bool do_dlsym(void* handle, const char* sym_name, const char* sym_ver,
-              void* caller_addr, void** symbol);
+#if defined(__arm__)
+_Unwind_Ptr do_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
+#endif
+
+bool do_dlsym(void* handle, const char* sym_name,
+              const char* sym_ver,
+              const void* caller_addr,
+              void** symbol);
 
 int do_dladdr(const void* addr, Dl_info* info);
 
index a8cc814..13edfe1 100644 (file)
@@ -160,16 +160,11 @@ static void add_vdso(KernelArgumentBlock& args __unused) {
  * relocate the offset of our exported 'rtld_db_dlactivity' symbol.
  * Note that the linker shouldn't be on the soinfo list.
  */
-static void init_linker_info_for_gdb(ElfW(Addr) linker_base) {
+static void init_linker_info_for_gdb(ElfW(Addr) linker_base, char* linker_path) {
   static link_map linker_link_map_for_gdb;
-#if defined(__LP64__)
-  static char kLinkerPath[] = "/system/bin/linker64";
-#else
-  static char kLinkerPath[] = "/system/bin/linker";
-#endif
 
   linker_link_map_for_gdb.l_addr = linker_base;
-  linker_link_map_for_gdb.l_name = kLinkerPath;
+  linker_link_map_for_gdb.l_name = linker_path;
 
   /*
    * Set the dynamic field in the link map otherwise gdb will complain with
@@ -201,6 +196,12 @@ static const char* get_executable_path() {
   return executable_path.c_str();
 }
 
+#if defined(__LP64__)
+static char kLinkerPath[] = "/system/bin/linker64";
+#else
+static char kLinkerPath[] = "/system/bin/linker";
+#endif
+
 /*
  * This code is called after the linker has linked itself and
  * fixed it's own GOT. It is safe to make references to externs
@@ -282,7 +283,7 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
   map->l_addr = 0;
   map->l_name = const_cast<char*>(executable_path);
   insert_link_map_into_debug_map(map);
-  init_linker_info_for_gdb(linker_base);
+  init_linker_info_for_gdb(linker_base, kLinkerPath);
 
   // Extract information passed from the kernel.
   si->phdr = reinterpret_cast<ElfW(Phdr)*>(args.getauxval(AT_PHDR));
@@ -524,9 +525,8 @@ extern "C" ElfW(Addr) __linker_init(void* raw_args) {
   // Initialize static variables. Note that in order to
   // get correct libdl_info we need to call constructors
   // before get_libdl_info().
-  solist = get_libdl_info();
-  sonext = get_libdl_info();
-  g_default_namespace.add_soinfo(get_libdl_info());
+  sonext = solist = get_libdl_info(kLinkerPath);
+  g_default_namespace.add_soinfo(solist);
 
   // We have successfully fixed our own relocations. It's safe to run
   // the main part of the linker now.
index a0fe9e2..7ef5da2 100644 (file)
@@ -336,7 +336,7 @@ struct soinfo {
   android_namespace_list_t secondary_namespaces_;
   uintptr_t handle_;
 
-  friend soinfo* get_libdl_info();
+  friend soinfo* get_libdl_info(const char* linker_path);
 };
 
 // This function is used by dlvsym() to calculate hash of sym_ver