exclude UNDEF global syms from lookup_global_symbol

Don't return a result for an UNDEF symbol

Signed-off-by: Seth Jennings <sjenning@redhat.com>
This commit is contained in:
Seth Jennings 2014-06-02 16:30:47 -05:00
parent 870b6fb95b
commit 6b7013daa1
1 changed files with 9 additions and 3 deletions

View File

@ -41,7 +41,7 @@ struct symbol {
unsigned long value;
unsigned long size;
char *name;
int type, bind;
int type, bind, skip;
};
struct lookup_table {
@ -108,6 +108,7 @@ struct lookup_table *lookup_open(char *path)
table->syms = malloc(len * sizeof(struct symbol));
if (!table->syms)
ERROR("malloc table.syms");
memset(table->syms, 0, len * sizeof(struct symbol));
table->nr = len;
table->fd = fd;
table->elf = elf;
@ -116,6 +117,11 @@ struct lookup_table *lookup_open(char *path)
if (!gelf_getsym(data, i, &sym))
ERROR("gelf_getsym");
if (sym.st_shndx == SHN_UNDEF) {
mysym->skip = 1;
continue;
}
name = elf_strptr(elf, sh.sh_link, sym.st_name);
if(!name)
ERROR("elf_strptr sym");
@ -179,7 +185,7 @@ int lookup_global_symbol(struct lookup_table *table, char *name,
memset(result, 0, sizeof(*result));
for_each_symbol(i, sym, table)
if (sym->bind == STB_GLOBAL &&
if (!sym->skip && sym->bind == STB_GLOBAL &&
!strcmp(sym->name, name)) {
result->value = sym->value;
result->size = sym->size;
@ -198,7 +204,7 @@ int lookup_is_exported_symbol(struct lookup_table *table, char *name)
strncat(export, name, 254);
for_each_symbol(i, sym, table)
if (!strcmp(sym->name, export))
if (!sym->skip && !strcmp(sym->name, export))
return 1;
return 0;