mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-23 23:21:46 +00:00
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
This commit is contained in:
parent
513b5ca6b5
commit
cdb3d057a1
2 changed files with 7 additions and 5 deletions
|
@ -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 symbol *find_symbol_by_name(struct elf *elf, const char *name)
|
||||||
{
|
{
|
||||||
struct section *sec;
|
|
||||||
struct symbol *sym;
|
struct symbol *sym;
|
||||||
|
|
||||||
list_for_each_entry(sec, &elf->sections, list)
|
hash_for_each_possible(elf->symbol_name_hash, sym, name_hash, str_hash(name))
|
||||||
list_for_each_entry(sym, &sec->symbol_list, list)
|
if (!strcmp(sym->name, name))
|
||||||
if (!strcmp(sym->name, name))
|
return sym;
|
||||||
return sym;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -386,6 +384,7 @@ static int read_symbols(struct elf *elf)
|
||||||
entry = &sym->sec->symbol_list;
|
entry = &sym->sec->symbol_list;
|
||||||
list_add(&sym->list, entry);
|
list_add(&sym->list, entry);
|
||||||
hash_add(elf->symbol_hash, &sym->hash, sym->idx);
|
hash_add(elf->symbol_hash, &sym->hash, sym->idx);
|
||||||
|
hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stats)
|
if (stats)
|
||||||
|
@ -524,6 +523,7 @@ struct elf *elf_read(const char *name, int flags)
|
||||||
memset(elf, 0, sizeof(*elf));
|
memset(elf, 0, sizeof(*elf));
|
||||||
|
|
||||||
hash_init(elf->symbol_hash);
|
hash_init(elf->symbol_hash);
|
||||||
|
hash_init(elf->symbol_name_hash);
|
||||||
hash_init(elf->section_hash);
|
hash_init(elf->section_hash);
|
||||||
hash_init(elf->section_name_hash);
|
hash_init(elf->section_name_hash);
|
||||||
INIT_LIST_HEAD(&elf->sections);
|
INIT_LIST_HEAD(&elf->sections);
|
||||||
|
|
|
@ -47,6 +47,7 @@ struct symbol {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
struct rb_node node;
|
struct rb_node node;
|
||||||
struct hlist_node hash;
|
struct hlist_node hash;
|
||||||
|
struct hlist_node name_hash;
|
||||||
GElf_Sym sym;
|
GElf_Sym sym;
|
||||||
struct section *sec;
|
struct section *sec;
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -77,6 +78,7 @@ struct elf {
|
||||||
char *name;
|
char *name;
|
||||||
struct list_head sections;
|
struct list_head sections;
|
||||||
DECLARE_HASHTABLE(symbol_hash, 20);
|
DECLARE_HASHTABLE(symbol_hash, 20);
|
||||||
|
DECLARE_HASHTABLE(symbol_name_hash, 20);
|
||||||
DECLARE_HASHTABLE(section_hash, 16);
|
DECLARE_HASHTABLE(section_hash, 16);
|
||||||
DECLARE_HASHTABLE(section_name_hash, 16);
|
DECLARE_HASHTABLE(section_name_hash, 16);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue