Skip to content

Commit

Permalink
lookup: add 'objname' to lookup table and lookup results
Browse files Browse the repository at this point in the history
This will be needed for the upcoming dynrela refactoring.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
  • Loading branch information
jpoimboe committed Nov 1, 2019
1 parent 1c14167 commit 9eef74d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 4 additions & 3 deletions kpatch-build/create-diff-object.c
Expand Up @@ -3448,10 +3448,11 @@ int main(int argc, char *argv[])
kpatch_elf_teardown(kelf_patched);

/* create symbol lookup table */
lookup = lookup_open(parent_symtab, mod_symvers, hint, base_locals);
for (sym_comp = base_locals; sym_comp && sym_comp->name; sym_comp++) {
lookup = lookup_open(parent_symtab, parent_name, mod_symvers, hint,
base_locals);

for (sym_comp = base_locals; sym_comp && sym_comp->name; sym_comp++)
free(sym_comp->name);
}
free(base_locals);
free(hint);

Expand Down
15 changes: 11 additions & 4 deletions kpatch-build/lookup.c
Expand Up @@ -56,6 +56,7 @@ struct lookup_table {
struct object_symbol *obj_syms;
struct export_symbol *exp_syms;
struct object_symbol *local_syms;
char *objname;
};

#define for_each_obj_symbol(ndx, iter, table) \
Expand Down Expand Up @@ -166,13 +167,15 @@ static void find_local_syms(struct lookup_table *table, char *hint,
if (!locals_match(table, i, child_locals))
continue;
if (table->local_syms)
ERROR("find_local_syms for %s: found_dup", hint);
ERROR("found duplicate matches for %s local symbols in %s symbol table",
hint, table->objname);

table->local_syms = sym;
}

if (!table->local_syms)
ERROR("find_local_syms for %s: couldn't find in vmlinux symbol table", hint);
ERROR("couldn't find matching %s local symbols in %s symbol table",
hint, table->objname);
}

/* Strip the path and replace '-' with '_' */
Expand Down Expand Up @@ -347,8 +350,9 @@ static void symvers_read(struct lookup_table *table, char *path)
fclose(file);
}

struct lookup_table *lookup_open(char *symtab_path, char *symvers_path,
char *hint, struct sym_compare_type *locals)
struct lookup_table *lookup_open(char *symtab_path, char *objname,
char *symvers_path, char *hint,
struct sym_compare_type *locals)
{
struct lookup_table *table;

Expand All @@ -357,6 +361,7 @@ struct lookup_table *lookup_open(char *symtab_path, char *symvers_path,
ERROR("malloc table");
memset(table, 0, sizeof(*table));

table->objname = objname;
symtab_read(table, symtab_path);
symvers_read(table, symvers_path);
find_local_syms(table, hint, locals);
Expand Down Expand Up @@ -417,6 +422,7 @@ bool lookup_local_symbol(struct lookup_table *table, char *name,
if (!match)
return false;

result->objname = table->objname;
result->sympos = sympos;
result->addr = sym->addr;
result->size = sym->size;
Expand All @@ -433,6 +439,7 @@ bool lookup_global_symbol(struct lookup_table *table, char *name,
for_each_obj_symbol(i, sym, table) {
if ((sym->bind == STB_GLOBAL || sym->bind == STB_WEAK) &&
!strcmp(sym->name, name)) {
result->objname = table->objname;
result->addr = sym->addr;
result->size = sym->size;
result->sympos = 0; /* always 0 for global symbols */
Expand Down
6 changes: 4 additions & 2 deletions kpatch-build/lookup.h
Expand Up @@ -6,6 +6,7 @@
struct lookup_table;

struct lookup_result {
char *objname;
unsigned long addr;
unsigned long size;
unsigned long sympos;
Expand All @@ -16,8 +17,9 @@ struct sym_compare_type {
int type;
};

struct lookup_table *lookup_open(char *symtab_path, char *symvers_path,
char *hint, struct sym_compare_type *locals);
struct lookup_table *lookup_open(char *symtab_path, char *objname,
char *symvers_path, char *hint,
struct sym_compare_type *locals);
void lookup_close(struct lookup_table *table);
bool lookup_local_symbol(struct lookup_table *table, char *name,
struct lookup_result *result);
Expand Down

0 comments on commit 9eef74d

Please sign in to comment.