Skip to content

Commit 65fb11a

Browse files
author
Peter Zijlstra
committed
objtool: Optimize find_symbol_by_index()
The symbol index is object wide, not per section, so it makes no sense to have the symbol_hash be part of the section object. By moving it to the elf object we avoid the linear sections iteration. This reduces the runtime of objtool on vmlinux.o from over 3 hours (I gave up) to a few minutes. The defconfig vmlinux.o has around 20k sections. 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.261852348@infradead.org
1 parent 36cc552 commit 65fb11a

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

‎tools/objtool/elf.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ static struct section *find_section_by_index(struct elf *elf,
4646

4747
static struct symbol *find_symbol_by_index(struct elf *elf, unsigned int idx)
4848
{
49-
struct section *sec;
5049
struct symbol *sym;
5150

52-
list_for_each_entry(sec, &elf->sections, list)
53-
hash_for_each_possible(sec->symbol_hash, sym, hash, idx)
54-
if (sym->idx == idx)
55-
return sym;
51+
hash_for_each_possible(elf->symbol_hash, sym, hash, idx)
52+
if (sym->idx == idx)
53+
return sym;
5654

5755
return NULL;
5856
}
@@ -166,7 +164,6 @@ static int read_sections(struct elf *elf)
166164
INIT_LIST_HEAD(&sec->symbol_list);
167165
INIT_LIST_HEAD(&sec->rela_list);
168166
hash_init(sec->rela_hash);
169-
hash_init(sec->symbol_hash);
170167

171168
list_add_tail(&sec->list, &elf->sections);
172169

@@ -299,7 +296,7 @@ static int read_symbols(struct elf *elf)
299296
}
300297
sym->alias = alias;
301298
list_add(&sym->list, entry);
302-
hash_add(sym->sec->symbol_hash, &sym->hash, sym->idx);
299+
hash_add(elf->symbol_hash, &sym->hash, sym->idx);
303300
}
304301

305302
/* Create parent/child links for any cold subfunctions */
@@ -425,6 +422,7 @@ struct elf *elf_read(const char *name, int flags)
425422
}
426423
memset(elf, 0, sizeof(*elf));
427424

425+
hash_init(elf->symbol_hash);
428426
INIT_LIST_HEAD(&elf->sections);
429427

430428
elf->fd = open(name, flags);
@@ -486,7 +484,6 @@ struct section *elf_create_section(struct elf *elf, const char *name,
486484
INIT_LIST_HEAD(&sec->symbol_list);
487485
INIT_LIST_HEAD(&sec->rela_list);
488486
hash_init(sec->rela_hash);
489-
hash_init(sec->symbol_hash);
490487

491488
list_add_tail(&sec->list, &elf->sections);
492489

‎tools/objtool/elf.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct section {
2727
struct list_head list;
2828
GElf_Shdr sh;
2929
struct list_head symbol_list;
30-
DECLARE_HASHTABLE(symbol_hash, 8);
3130
struct list_head rela_list;
3231
DECLARE_HASHTABLE(rela_hash, 16);
3332
struct section *base, *rela;
@@ -71,7 +70,7 @@ struct elf {
7170
int fd;
7271
char *name;
7372
struct list_head sections;
74-
DECLARE_HASHTABLE(rela_hash, 16);
73+
DECLARE_HASHTABLE(symbol_hash, 20);
7574
};
7675

7776

0 commit comments

Comments
 (0)