Code simplification in relocate_syms

master
Thomas Preud'homme 2016-11-12 23:16:09 +08:00
parent 25927df3b7
commit c4bec037be
1 changed files with 4 additions and 7 deletions

View File

@ -665,11 +665,9 @@ ST_FUNC void relocate_syms(TCCState *s1, int do_resolve)
/* Use ld.so to resolve symbol for us (for tcc -run) */ /* Use ld.so to resolve symbol for us (for tcc -run) */
if (do_resolve) { if (do_resolve) {
#if defined TCC_IS_NATIVE && !defined TCC_TARGET_PE #if defined TCC_IS_NATIVE && !defined TCC_TARGET_PE
void *addr; void *addr = dlsym(RTLD_DEFAULT, name);
name = (char *) symtab_section->link->data + sym->st_name;
addr = dlsym(RTLD_DEFAULT, name);
if (addr) { if (addr) {
sym->st_value = (addr_t)addr; sym->st_value = (addr_t) addr;
#ifdef DEBUG_RELOC #ifdef DEBUG_RELOC
printf ("relocate_sym: %s -> 0x%lx\n", name, sym->st_value); printf ("relocate_sym: %s -> 0x%lx\n", name, sym->st_value);
#endif #endif
@ -686,11 +684,10 @@ ST_FUNC void relocate_syms(TCCState *s1, int do_resolve)
/* only weak symbols are accepted to be undefined. Their /* only weak symbols are accepted to be undefined. Their
value is zero */ value is zero */
sym_bind = ELFW(ST_BIND)(sym->st_info); sym_bind = ELFW(ST_BIND)(sym->st_info);
if (sym_bind == STB_WEAK) { if (sym_bind == STB_WEAK)
sym->st_value = 0; sym->st_value = 0;
} else { else
tcc_error_noabort("undefined symbol '%s'", name); tcc_error_noabort("undefined symbol '%s'", name);
}
} else if (sh_num < SHN_LORESERVE) { } else if (sh_num < SHN_LORESERVE) {
/* add section base */ /* add section base */
sym->st_value += s1->sections[sym->st_shndx]->sh_addr; sym->st_value += s1->sections[sym->st_shndx]->sh_addr;