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을 참조하십시오.