* commit '2a60b264ebf85bdec2ef741651815781b145d868': Fix linker crashes during unknown symbol lookup
This commit is contained in:
commit
040fe7a832
@ -73,6 +73,7 @@
|
||||
*/
|
||||
|
||||
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
|
||||
// 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) {
|
||||
// Copy the necessary fields into the debug structure.
|
||||
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_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));
|
||||
|
||||
soinfo* si = soinfo_alloc("[vdso]");
|
||||
|
||||
si->phdr = reinterpret_cast<Elf_Phdr*>(reinterpret_cast<char*>(ehdr_vdso) + ehdr_vdso->e_phoff);
|
||||
si->phnum = ehdr_vdso->e_phnum;
|
||||
si->link_map.l_name = si->name;
|
||||
for (size_t i = 0; i < si->phnum; ++i) {
|
||||
if (si->phdr[i].p_type == PT_LOAD) {
|
||||
si->link_map.l_addr = reinterpret_cast<Elf_Addr>(ehdr_vdso) - si->phdr[i].p_vaddr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
si->base = reinterpret_cast<Elf_Addr>(ehdr_vdso);
|
||||
si->size = phdr_table_get_load_size(si->phdr, si->phnum);
|
||||
si->flags = 0;
|
||||
si->load_bias = get_elf_exec_load_bias(ehdr_vdso);
|
||||
|
||||
soinfo_link_image(si);
|
||||
insert_soinfo_into_debug_map(si);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -222,3 +222,15 @@ TEST(dlfcn, dlopen_bad_flags) {
|
||||
ASSERT_TRUE(handle != NULL);
|
||||
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