* commit '6b69b753d7c9820fb4fd7f88a047931c645834c8': Fix linker crashes during unknown symbol lookup
This commit is contained in:
commit
2a60b264eb
@ -73,6 +73,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static bool soinfo_link_image(soinfo* si);
|
static bool soinfo_link_image(soinfo* si);
|
||||||
|
static Elf_Addr get_elf_exec_load_bias(const Elf_Ehdr* elf);
|
||||||
|
|
||||||
// We can't use malloc(3) in the dynamic linker. We use a linked list of anonymous
|
// We can't use malloc(3) in the dynamic linker. We use a linked list of anonymous
|
||||||
// maps, each a single page in size. The pages are broken up into as many struct soinfo
|
// maps, each a single page in size. The pages are broken up into as many struct soinfo
|
||||||
@ -186,7 +187,7 @@ static pthread_mutex_t gDebugMutex = PTHREAD_MUTEX_INITIALIZER;
|
|||||||
static void insert_soinfo_into_debug_map(soinfo * info) {
|
static void insert_soinfo_into_debug_map(soinfo * info) {
|
||||||
// Copy the necessary fields into the debug structure.
|
// Copy the necessary fields into the debug structure.
|
||||||
link_map_t* map = &(info->link_map);
|
link_map_t* map = &(info->link_map);
|
||||||
map->l_addr = info->base;
|
map->l_addr = info->load_bias;
|
||||||
map->l_name = (char*) info->name;
|
map->l_name = (char*) info->name;
|
||||||
map->l_ld = (uintptr_t)info->dynamic;
|
map->l_ld = (uintptr_t)info->dynamic;
|
||||||
|
|
||||||
@ -1751,15 +1752,16 @@ static void add_vdso(KernelArgumentBlock& args UNUSED) {
|
|||||||
Elf_Ehdr* ehdr_vdso = reinterpret_cast<Elf_Ehdr*>(args.getauxval(AT_SYSINFO_EHDR));
|
Elf_Ehdr* ehdr_vdso = reinterpret_cast<Elf_Ehdr*>(args.getauxval(AT_SYSINFO_EHDR));
|
||||||
|
|
||||||
soinfo* si = soinfo_alloc("[vdso]");
|
soinfo* si = soinfo_alloc("[vdso]");
|
||||||
|
|
||||||
si->phdr = reinterpret_cast<Elf_Phdr*>(reinterpret_cast<char*>(ehdr_vdso) + ehdr_vdso->e_phoff);
|
si->phdr = reinterpret_cast<Elf_Phdr*>(reinterpret_cast<char*>(ehdr_vdso) + ehdr_vdso->e_phoff);
|
||||||
si->phnum = ehdr_vdso->e_phnum;
|
si->phnum = ehdr_vdso->e_phnum;
|
||||||
si->link_map.l_name = si->name;
|
si->base = reinterpret_cast<Elf_Addr>(ehdr_vdso);
|
||||||
for (size_t i = 0; i < si->phnum; ++i) {
|
si->size = phdr_table_get_load_size(si->phdr, si->phnum);
|
||||||
if (si->phdr[i].p_type == PT_LOAD) {
|
si->flags = 0;
|
||||||
si->link_map.l_addr = reinterpret_cast<Elf_Addr>(ehdr_vdso) - si->phdr[i].p_vaddr;
|
si->load_bias = get_elf_exec_load_bias(ehdr_vdso);
|
||||||
break;
|
|
||||||
}
|
soinfo_link_image(si);
|
||||||
}
|
insert_soinfo_into_debug_map(si);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,3 +222,15 @@ TEST(dlfcn, dlopen_bad_flags) {
|
|||||||
ASSERT_TRUE(handle != NULL);
|
ASSERT_TRUE(handle != NULL);
|
||||||
ASSERT_SUBSTR(NULL, dlerror());
|
ASSERT_SUBSTR(NULL, dlerror());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(dlfcn, rtld_default_unknown_symbol) {
|
||||||
|
void* self = RTLD_DEFAULT;
|
||||||
|
void* addr = dlsym(self, "ANY_UNKNOWN_SYMBOL_NAME");
|
||||||
|
ASSERT_TRUE(addr == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(dlfcn, rtld_default_known_symbol) {
|
||||||
|
void* self = RTLD_DEFAULT;
|
||||||
|
void* addr = dlsym(self, "fopen");
|
||||||
|
ASSERT_TRUE(addr != NULL);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user