fix "symbol not defined" if symbol has offset 0

This commit is contained in:
grischka 2009-07-10 16:29:10 +01:00
parent d923e652f2
commit 1026ca5888

View File

@ -168,25 +168,32 @@ static int find_elf_sym(Section *s, const char *name)
return 0;
}
/* return elf symbol value or error */
void *tcc_get_symbol(TCCState *s, const char *name)
/* return elf symbol value, signal error if 'err' is nonzero */
static void *get_elf_sym_addr(TCCState *s, const char *name, int err)
{
int sym_index;
ElfW(Sym) *sym;
sym_index = find_elf_sym(symtab_section, name);
if (!sym_index)
return NULL;
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
if (!sym_index || sym->st_shndx == SHN_UNDEF) {
if (err)
error("%s not defined", name);
return NULL;
}
return (void*)(uplong)sym->st_value;
}
/* return elf symbol value */
void *tcc_get_symbol(TCCState *s, const char *name)
{
return get_elf_sym_addr(s, name, 0);
}
/* return elf symbol value or error */
void *tcc_get_symbol_err(TCCState *s, const char *name)
{
void *sym;
sym = tcc_get_symbol(s, name);
if (!sym)
error("%s not defined", name);
return sym;
return get_elf_sym_addr(s, name, 1);
}
/* add an elf symbol : check if it is already defined and patch