mirror of
https://github.com/frida/tinycc
synced 2024-11-24 16:49:44 +03:00
fix "symbol not defined" if symbol has offset 0
This commit is contained in:
parent
d923e652f2
commit
1026ca5888
25
tccelf.c
25
tccelf.c
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user