summaryrefslogtreecommitdiff
path: root/tools/objtool/elf.c
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2020-03-12 12:17:38 +0300
committerPeter Zijlstra <peterz@infradead.org>2020-03-25 20:28:30 +0300
commitcdb3d057a17d56363a831e486ea39e4c389a6cf9 (patch)
tree87c68d4378ff885e3efaba3cbad947f100c1c071 /tools/objtool/elf.c
parent513b5ca6b5fbeb766999fb1a4bc9a55c9fb7c9ca (diff)
downloadlinux-cdb3d057a17d56363a831e486ea39e4c389a6cf9.tar.xz
objtool: Optimize find_symbol_by_name()
Perf showed that find_symbol_by_name() takes time; add a symbol name hash. This shaves another second off of objtool on vmlinux.o runtime, down to 15 seconds. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Miroslav Benes <mbenes@suse.cz> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Link: https://lkml.kernel.org/r/20200324160924.676865656@infradead.org
Diffstat (limited to 'tools/objtool/elf.c')
-rw-r--r--tools/objtool/elf.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 07db4df18588..43abae763b3b 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -203,13 +203,11 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset)
struct symbol *find_symbol_by_name(struct elf *elf, const char *name)
{
- struct section *sec;
struct symbol *sym;
- list_for_each_entry(sec, &elf->sections, list)
- list_for_each_entry(sym, &sec->symbol_list, list)
- if (!strcmp(sym->name, name))
- return sym;
+ hash_for_each_possible(elf->symbol_name_hash, sym, name_hash, str_hash(name))
+ if (!strcmp(sym->name, name))
+ return sym;
return NULL;
}
@@ -386,6 +384,7 @@ static int read_symbols(struct elf *elf)
entry = &sym->sec->symbol_list;
list_add(&sym->list, entry);
hash_add(elf->symbol_hash, &sym->hash, sym->idx);
+ hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name));
}
if (stats)
@@ -524,6 +523,7 @@ struct elf *elf_read(const char *name, int flags)
memset(elf, 0, sizeof(*elf));
hash_init(elf->symbol_hash);
+ hash_init(elf->symbol_name_hash);
hash_init(elf->section_hash);
hash_init(elf->section_name_hash);
INIT_LIST_HEAD(&elf->sections);