From 3064cf3c6081a1e3f5b9102b9ae7c92e7842e7dd Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Fri, 1 Nov 2019 15:03:14 -0500 Subject: [PATCH] lookup: add 'objname' to lookup table and lookup results This will be needed for the upcoming dynrela refactoring. Signed-off-by: Josh Poimboeuf --- kpatch-build/create-diff-object.c | 7 ++++--- kpatch-build/lookup.c | 15 +++++++++++---- kpatch-build/lookup.h | 6 ++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index 104bc0d..acfaec1 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -3605,10 +3605,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); diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c index 82d6b22..ce7549a 100644 --- a/kpatch-build/lookup.c +++ b/kpatch-build/lookup.c @@ -57,6 +57,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) \ @@ -167,13 +168,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 '_' */ @@ -359,8 +362,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; @@ -369,6 +373,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); @@ -429,6 +434,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; @@ -445,6 +451,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 */ diff --git a/kpatch-build/lookup.h b/kpatch-build/lookup.h index bb367a3..59f7f1e 100644 --- a/kpatch-build/lookup.h +++ b/kpatch-build/lookup.h @@ -6,6 +6,7 @@ struct lookup_table; struct lookup_result { + char *objname; unsigned long addr; unsigned long size; unsigned long sympos; @@ -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);