Revert "Bionic loader is no longer hijacking libdl.so"

This reverts commit c12acef96b.

Breaks the Mips build.

Bug: 27106625
Change-Id: I27edb7114065c36e1b618e387530d58189cdb184
This commit is contained in:
Andreas Gampe 2016-12-06 02:10:13 +00:00
parent c12acef96b
commit dcb846cb49
9 changed files with 118 additions and 287 deletions

View file

@ -57,55 +57,6 @@ 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,
},

View file

@ -1 +0,0 @@

View file

@ -20,148 +20,54 @@
#include <stdbool.h>
#include <android/dlext.h>
// These functions are exported by the loader
// TODO(dimitry): replace these with reference to libc.so
// These are stubs for functions that are actually defined
// in the dynamic linker and hijacked at runtime.
__attribute__((__weak__, visibility("default")))
void* __loader_dlopen(const char* filename, int flags, const void* caller_addr);
void* dlopen(const char* filename __unused, int flag __unused) { return 0; }
__attribute__((__weak__, visibility("default")))
void* __loader_dlerror();
char* dlerror(void) { return 0; }
__attribute__((__weak__, visibility("default")))
void* __loader_dlsym(void* handle, const char* symbol, const void* caller_addr);
void* dlsym(void* handle __unused, const char* symbol __unused) { return 0; }
__attribute__((__weak__, visibility("default")))
void* __loader_dlvsym(void* handle,
const char* symbol,
const char* version,
const void* caller_addr);
void* dlvsym(void* handle __unused, const char* symbol __unused, const char* version __unused) {
return 0;
}
__attribute__((__weak__, visibility("default")))
int __loader_dladdr(const void* addr, Dl_info* info);
int dladdr(const void* addr __unused, Dl_info* info __unused) { return 0; }
__attribute__((__weak__, visibility("default")))
int __loader_dlclose(void* handle);
int dlclose(void* handle __unused) { return 0; }
#if defined(__arm__)
__attribute__((__weak__, visibility("default")))
_Unwind_Ptr __loader_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc __unused, int* pcount __unused) { return 0; }
#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);
int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data) __unused,
void* data __unused) {
return 0;
}
char* dlerror() {
return __loader_dlerror();
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_dlopen_ext(const char* filename __unused, int flag __unused,
const android_dlextinfo* extinfo __unused) {
return 0;
}
void* dlsym(void* handle, const char* symbol) {
const void* caller_addr = __builtin_return_address(0);
return __loader_dlsym(handle, symbol, caller_addr);
void android_set_application_target_sdk_version(uint32_t target __unused) { }
uint32_t android_get_application_target_sdk_version() { return 0; }
bool android_init_namespaces(const char* public_ns_sonames __unused,
const char* anon_ns_library_path __unused) {
return false;
}
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 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, 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), void* data) {
return __loader_dl_iterate_phdr(cb, data);
}
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, 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) {
__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,
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,
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);
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;
}
void android_dlwarning(void* obj, void (*f)(void*, const char*)) { f(obj, 0); }

View file

@ -1,5 +1,6 @@
cc_library_static {
name: "liblinker_malloc",
clang: true,
defaults: ["linux_bionic_supported"],
srcs: [
@ -12,7 +13,9 @@ cc_library_static {
}
cc_binary {
clang: true,
defaults: ["linux_bionic_supported"],
srcs: [
"dlfcn.cpp",
"linker.cpp",
@ -96,6 +99,8 @@ cc_binary {
"-Werror",
],
conlyflags: ["-std=gnu99"],
cppflags: ["-Wold-style-cast"],
// we don't want crtbegin.o (because we have begin.o), so unset it

View file

@ -52,25 +52,23 @@ 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,
const void* caller_addr) {
static void* dlopen_ext(const char* filename, int flags,
const android_dlextinfo* extinfo, void* caller_addr) {
ScopedPthreadMutexLocker locker(&g_dl_mutex);
g_linker_logger.ResetState();
void* result = do_dlopen(filename, flags, extinfo, caller_addr);
@ -81,18 +79,17 @@ static void* dlopen_ext(const char* filename,
return result;
}
void* __android_dlopen_ext(const char* filename,
int flags,
const android_dlextinfo* extinfo,
const void* caller_addr) {
void* android_dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo) {
void* caller_addr = __builtin_return_address(0);
return dlopen_ext(filename, flags, extinfo, caller_addr);
}
void* __dlopen(const char* filename, int flags, const void* caller_addr) {
void* dlopen(const char* filename, int flags) {
void* caller_addr = __builtin_return_address(0);
return dlopen_ext(filename, flags, nullptr, caller_addr);
}
void* dlsym_impl(void* handle, const char* symbol, const char* version, const void* caller_addr) {
void* dlsym_impl(void* handle, const char* symbol, const char* version, void* caller_addr) {
ScopedPthreadMutexLocker locker(&g_dl_mutex);
g_linker_logger.ResetState();
void* result;
@ -104,20 +101,22 @@ void* dlsym_impl(void* handle, const char* symbol, const char* version, const vo
return result;
}
void* __dlsym(void* handle, const char* symbol, const void* caller_addr) {
void* dlsym(void* handle, const char* symbol) {
void* caller_addr = __builtin_return_address(0);
return dlsym_impl(handle, symbol, nullptr, caller_addr);
}
void* __dlvsym(void* handle, const char* symbol, const char* version, const void* caller_addr) {
void* dlvsym(void* handle, const char* symbol, const char* version) {
void* caller_addr = __builtin_return_address(0);
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) {
@ -126,34 +125,27 @@ int __dlclose(void* handle) {
return result;
}
int __dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void* data) {
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);
}
#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) {
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);
@ -164,13 +156,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,
const void* caller_addr) {
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);
ScopedPthreadMutexLocker locker(&g_dl_mutex);
android_namespace_t* result = create_namespace(caller_addr,
@ -208,28 +200,18 @@ android_namespace_t* __android_create_namespace(const char* name,
}
static const char ANDROID_LIBDL_STRTAB[] =
// 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"
// 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"
#if defined(__arm__)
// 425
"__loader_dl_unwind_find_exidx\0"
// 290
"dl_unwind_find_exidx\0"
#endif
;
@ -239,23 +221,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)( 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),
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),
#if defined(__arm__)
ELFW(SYM_INITIALIZER)(425, &__dl_unwind_find_exidx, 1),
ELFW(SYM_INITIALIZER)(290, &dl_unwind_find_exidx, 1),
#endif
};
@ -281,9 +263,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(const char* linker_path) {
soinfo* get_libdl_info() {
if (__libdl_info == nullptr) {
__libdl_info = new (__libdl_info_buf) soinfo(&g_default_namespace, linker_path, nullptr, 0, 0);
__libdl_info = new (__libdl_info_buf) soinfo(&g_default_namespace, "libdl.so", nullptr, 0, RTLD_GLOBAL);
__libdl_info->flags_ |= FLAG_LINKED;
__libdl_info->strtab_ = ANDROID_LIBDL_STRTAB;
__libdl_info->symtab_ = g_libdl_symtab;
@ -294,7 +276,7 @@ soinfo* get_libdl_info(const char* linker_path) {
__libdl_info->ref_count_ = 1;
__libdl_info->strtab_size_ = sizeof(ANDROID_LIBDL_STRTAB);
__libdl_info->local_group_root_ = __libdl_info;
__libdl_info->soname_ = "ld-android.so";
__libdl_info->soname_ = "libdl.so";
__libdl_info->target_sdk_version_ = __ANDROID_API__;
__libdl_info->generate_handle();
#if defined(__work_around_b_24465209__)

View file

@ -324,7 +324,9 @@ 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().
_Unwind_Ptr do_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
//
// This function is exposed via dlfcn.cpp and libdl.so.
_Unwind_Ptr 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) {
@ -1728,9 +1730,8 @@ 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,
const void* caller_addr) {
void* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo,
void* caller_addr) {
soinfo* const caller = find_containing_library(caller_addr);
android_namespace_t* ns = get_caller_namespace(caller);
@ -1854,11 +1855,8 @@ 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,
const void* caller_addr,
void** symbol) {
bool do_dlsym(void* handle, const char* sym_name, const char* sym_ver,
void* caller_addr, void** symbol) {
#if !defined(__LP64__)
if (handle == nullptr) {
DL_ERR("dlsym failed: library handle is null");

View file

@ -101,27 +101,17 @@ enum RelocationKind {
void count_relocation(RelocationKind kind);
soinfo* get_libdl_info(const char* linker_path);
soinfo* get_libdl_info();
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,
const void* caller_addr);
void* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo, 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);
#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);
bool do_dlsym(void* handle, const char* sym_name, const char* sym_ver,
void* caller_addr, void** symbol);
int do_dladdr(const void* addr, Dl_info* info);

View file

@ -160,11 +160,16 @@ 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, char* linker_path) {
static void init_linker_info_for_gdb(ElfW(Addr) linker_base) {
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 = linker_path;
linker_link_map_for_gdb.l_name = kLinkerPath;
/*
* Set the dynamic field in the link map otherwise gdb will complain with
@ -196,12 +201,6 @@ 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
@ -283,7 +282,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, kLinkerPath);
init_linker_info_for_gdb(linker_base);
// Extract information passed from the kernel.
si->phdr = reinterpret_cast<ElfW(Phdr)*>(args.getauxval(AT_PHDR));
@ -525,8 +524,9 @@ 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().
sonext = solist = get_libdl_info(kLinkerPath);
g_default_namespace.add_soinfo(solist);
solist = get_libdl_info();
sonext = get_libdl_info();
g_default_namespace.add_soinfo(get_libdl_info());
// We have successfully fixed our own relocations. It's safe to run
// the main part of the linker now.

View file

@ -336,7 +336,7 @@ struct soinfo {
android_namespace_list_t secondary_namespaces_;
uintptr_t handle_;
friend soinfo* get_libdl_info(const char* linker_path);
friend soinfo* get_libdl_info();
};
// This function is used by dlvsym() to calculate hash of sym_ver