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 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return elf symbol value or error */
|
/* return elf symbol value, signal error if 'err' is nonzero */
|
||||||
void *tcc_get_symbol(TCCState *s, const char *name)
|
static void *get_elf_sym_addr(TCCState *s, const char *name, int err)
|
||||||
{
|
{
|
||||||
int sym_index;
|
int sym_index;
|
||||||
ElfW(Sym) *sym;
|
ElfW(Sym) *sym;
|
||||||
|
|
||||||
sym_index = find_elf_sym(symtab_section, name);
|
sym_index = find_elf_sym(symtab_section, name);
|
||||||
if (!sym_index)
|
|
||||||
return NULL;
|
|
||||||
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
|
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 (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 *tcc_get_symbol_err(TCCState *s, const char *name)
|
||||||
{
|
{
|
||||||
void *sym;
|
return get_elf_sym_addr(s, name, 1);
|
||||||
sym = tcc_get_symbol(s, name);
|
|
||||||
if (!sym)
|
|
||||||
error("%s not defined", name);
|
|
||||||
return sym;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add an elf symbol : check if it is already defined and patch
|
/* add an elf symbol : check if it is already defined and patch
|
||||||
|
Loading…
Reference in New Issue
Block a user