lookup: fix discarded symbol handling for all kernel versions

Fix discarded symbol handling for all kernel versions.

Fixes #765.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
This commit is contained in:
Josh Poimboeuf 2018-03-21 12:47:58 -05:00
parent d2fba54b42
commit b811940173

View File

@ -56,7 +56,6 @@ struct lookup_table {
struct object_symbol *obj_syms; struct object_symbol *obj_syms;
struct export_symbol *exp_syms; struct export_symbol *exp_syms;
struct object_symbol *local_syms; struct object_symbol *local_syms;
int vmlinux;
}; };
#define for_each_obj_symbol(ndx, iter, table) \ #define for_each_obj_symbol(ndx, iter, table) \
@ -68,13 +67,20 @@ struct lookup_table {
#define for_each_exp_symbol(ndx, iter, table) \ #define for_each_exp_symbol(ndx, iter, table) \
for (ndx = 0, iter = table->exp_syms; ndx < table->exp_nr; ndx++, iter++) for (ndx = 0, iter = table->exp_syms; ndx < table->exp_nr; ndx++, iter++)
static int discarded_sym(struct lookup_table *table, static int maybe_discarded_sym(const char *name)
struct sym_compare_type *sym)
{ {
if (table->vmlinux && sym->name && if (!name)
(!strncmp(sym->name, "__exitcall_", 11) || return 0;
!strncmp(sym->name, "__brk_reservation_fn_", 21) ||
!strncmp(sym->name, "__func_stack_frame_non_standard_", 32))) /*
* Sometimes these symbols are discarded during linking, and sometimes
* they're not, depending on whether the parent object is vmlinux or a
* module, and also depending on the kernel version. For simplicity,
* we just always skip them when comparing object symbol tables.
*/
if (!strncmp(name, "__exitcall_", 11) ||
!strncmp(name, "__brk_reservation_fn_", 21) ||
!strncmp(name, "__func_stack_frame_non_standard_", 32))
return 1; return 1;
return 0; return 0;
@ -114,7 +120,7 @@ static int locals_match(struct lookup_table *table, int idx,
* Symbols which get discarded at link time are missing from * Symbols which get discarded at link time are missing from
* the lookup table, so skip them. * the lookup table, so skip them.
*/ */
if (discarded_sym(table, child)) if (maybe_discarded_sym(child->name))
continue; continue;
found = 0; found = 0;
@ -126,6 +132,8 @@ static int locals_match(struct lookup_table *table, int idx,
continue; continue;
if (sym->type != STT_FUNC && sym->type != STT_OBJECT) if (sym->type != STT_FUNC && sym->type != STT_OBJECT)
continue; continue;
if (maybe_discarded_sym(sym->name))
continue;
if (!strcmp(child->name, sym->name)) { if (!strcmp(child->name, sym->name)) {
found = 1; found = 1;
@ -316,8 +324,6 @@ struct lookup_table *lookup_open(char *obj_path, char *symvers_path,
ERROR("malloc table"); ERROR("malloc table");
memset(table, 0, sizeof(*table)); memset(table, 0, sizeof(*table));
table->vmlinux = !strncmp(basename(obj_path), "vmlinux", 7);
obj_read(table, obj_path); obj_read(table, obj_path);
symvers_read(table, symvers_path); symvers_read(table, symvers_path);
find_local_syms(table, hint, locals); find_local_syms(table, hint, locals);