mirror of https://github.com/dynup/kpatch
Make lookup_symbol() accept struct symbol as an argument
At the moment lookup_symbol() takes symbol name as an argument which might not be enough in some cases (e.g. for objectfiles built from multiple source files). Make it accept full symbol structure. Signed-off-by: Artem Savkov <asavkov@redhat.com>
This commit is contained in:
parent
a132000868
commit
db442d1405
|
@ -2280,7 +2280,7 @@ static bool should_keep_jump_label(struct lookup_table *lookup,
|
|||
* jump label init.
|
||||
*/
|
||||
|
||||
if (lookup_symbol(lookup, key->sym->name, &symbol) &&
|
||||
if (lookup_symbol(lookup, key->sym, &symbol) &&
|
||||
strcmp(symbol.objname, "vmlinux")) {
|
||||
|
||||
/* The static key lives in a module -- not supported */
|
||||
|
@ -2935,7 +2935,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
|||
sym->parent)
|
||||
continue;
|
||||
|
||||
if (!lookup_symbol(table, sym->name, &symbol))
|
||||
if (!lookup_symbol(table, sym, &symbol))
|
||||
ERROR("can't find symbol '%s' in symbol table", sym->name);
|
||||
|
||||
if (sym->bind == STB_LOCAL && symbol.global)
|
||||
|
@ -3096,7 +3096,7 @@ static bool need_dynrela(struct lookup_table *table, const struct rela *rela)
|
|||
!strchr(toc_rela(rela)->sym->name, '.');
|
||||
}
|
||||
|
||||
if (!lookup_symbol(table, rela->sym->name, &symbol)) {
|
||||
if (!lookup_symbol(table, rela->sym, &symbol)) {
|
||||
/*
|
||||
* Assume the symbol lives in another .o in the patch module.
|
||||
* A normal rela should work.
|
||||
|
@ -3282,7 +3282,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
|||
ERROR("unsupported dynrela reference to symbol '%s' in module-specific special section '%s'",
|
||||
rela->sym->name, sec->base->name);
|
||||
|
||||
if (!lookup_symbol(table, rela->sym->name, &symbol))
|
||||
if (!lookup_symbol(table, rela->sym, &symbol))
|
||||
ERROR("can't find symbol '%s' in symbol table",
|
||||
rela->sym->name);
|
||||
|
||||
|
|
|
@ -407,7 +407,8 @@ void lookup_close(struct lookup_table *table)
|
|||
free(table);
|
||||
}
|
||||
|
||||
static bool lookup_local_symbol(struct lookup_table *table, char *name,
|
||||
static bool lookup_local_symbol(struct lookup_table *table,
|
||||
struct symbol *lookup_sym,
|
||||
struct lookup_result *result)
|
||||
{
|
||||
struct object_symbol *sym;
|
||||
|
@ -419,7 +420,8 @@ static bool lookup_local_symbol(struct lookup_table *table, char *name,
|
|||
|
||||
memset(result, 0, sizeof(*result));
|
||||
for_each_obj_symbol(i, sym, table) {
|
||||
if (sym->bind == STB_LOCAL && !strcmp(sym->name, name))
|
||||
if (sym->bind == STB_LOCAL && !strcmp(sym->name,
|
||||
lookup_sym->name))
|
||||
sympos++;
|
||||
|
||||
if (table->local_syms == sym) {
|
||||
|
@ -433,10 +435,12 @@ static bool lookup_local_symbol(struct lookup_table *table, char *name,
|
|||
if (sym->type == STT_FILE)
|
||||
break;
|
||||
|
||||
if (sym->bind == STB_LOCAL && !strcmp(sym->name, name)) {
|
||||
if (sym->bind == STB_LOCAL && !strcmp(sym->name,
|
||||
lookup_sym->name)) {
|
||||
|
||||
if (result->objname)
|
||||
ERROR("duplicate local symbol found for %s", name);
|
||||
ERROR("duplicate local symbol found for %s",
|
||||
lookup_sym->name);
|
||||
|
||||
result->objname = table->objname;
|
||||
result->addr = sym->addr;
|
||||
|
@ -511,14 +515,14 @@ static bool lookup_global_symbol(struct lookup_table *table, char *name,
|
|||
return !!result->objname;
|
||||
}
|
||||
|
||||
bool lookup_symbol(struct lookup_table *table, char *name,
|
||||
bool lookup_symbol(struct lookup_table *table, struct symbol *sym,
|
||||
struct lookup_result *result)
|
||||
{
|
||||
if (lookup_local_symbol(table, name, result))
|
||||
if (lookup_local_symbol(table, sym, result))
|
||||
return true;
|
||||
|
||||
if (lookup_global_symbol(table, name, result))
|
||||
if (lookup_global_symbol(table, sym->name, result))
|
||||
return true;
|
||||
|
||||
return lookup_exported_symbol(table, name, result);
|
||||
return lookup_exported_symbol(table, sym->name, result);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _LOOKUP_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "kpatch-elf.h"
|
||||
|
||||
struct lookup_table;
|
||||
|
||||
|
@ -22,7 +23,7 @@ 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_symbol(struct lookup_table *table, char *name,
|
||||
bool lookup_symbol(struct lookup_table *table, struct symbol *sym,
|
||||
struct lookup_result *result);
|
||||
|
||||
#endif /* _LOOKUP_H_ */
|
||||
|
|
Loading…
Reference in New Issue