我想你是在談論Android N.下面的一切都是基於這個假設。
這些符號不是來自任何共享庫,它們在鏈接器中實現,並通過源代碼中的手工製作soinfo
導出。
static ElfW(Sym) g_libdl_symtab[] = {
// Total length of libdl_info.strtab, including trailing 0.
// This is actually the STH_UNDEF entry. Technically, it's
// 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),
#if defined(__arm__)
ELFW(SYM_INITIALIZER)(290, &dl_unwind_find_exidx, 1),
#endif
};
// This is used by the dynamic linker. Every process gets these symbols for free.
soinfo* get_libdl_info() {
if (__libdl_info == nullptr) {
__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;
__libdl_info->nbucket_ = sizeof(g_libdl_buckets)/sizeof(unsigned);
__libdl_info->nchain_ = sizeof(g_libdl_chains)/sizeof(unsigned);
__libdl_info->bucket_ = g_libdl_buckets;
__libdl_info->chain_ = g_libdl_chains;
__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->target_sdk_version_ = __ANDROID_API__;
__libdl_info->generate_handle();
#if defined(__work_around_b_24465209__)
strlcpy(__libdl_info->old_name_, __libdl_info->soname_, sizeof(__libdl_info->old_name_));
#endif
}
查詢https://android.googlesource.com/platform/bionic/+/android-7.0.0_r1/linker/dlfcn.cpp瞭解更多詳情。