Skip to content

Commit

Permalink
objtool: Improve reloc hash size guestimate
Browse files Browse the repository at this point in the history
Nathan reported that LLVM ThinLTO builds have a performance regression
with commit 25cf0d8 ("objtool: Rewrite hashtable sizing"). Sami
was quick to note that this is due to their use of -ffunction-sections.

As a result the .text section is small and basing the number of relocs
off of that no longer works. Instead have read_sections() compute the
sum of all SHF_EXECINSTR sections and use that.

Fixes: 25cf0d8 ("objtool: Rewrite hashtable sizing")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Debugged-by: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lkml.kernel.org/r/YMJpGLuGNsGtA5JJ@hirez.programming.kicks-ass.net
  • Loading branch information
Peter Zijlstra committed Jun 14, 2021
1 parent c199f64 commit d33b903
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
11 changes: 4 additions & 7 deletions tools/objtool/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ static int read_sections(struct elf *elf)
}
sec->len = sec->sh.sh_size;

if (sec->sh.sh_flags & SHF_EXECINSTR)
elf->text_size += sec->len;

list_add_tail(&sec->list, &elf->sections);
elf_hash_add(section, &sec->hash, sec->idx);
elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name));
Expand Down Expand Up @@ -581,13 +584,7 @@ static int read_relocs(struct elf *elf)
unsigned int symndx;
unsigned long nr_reloc, max_reloc = 0, tot_reloc = 0;

sec = find_section_by_name(elf, ".text");
if (!sec) {
WARN("no .text");
return -1;
}

if (!elf_alloc_hash(reloc, sec->len / 16))
if (!elf_alloc_hash(reloc, elf->text_size / 16))
return -1;

list_for_each_entry(sec, &elf->sections, list) {
Expand Down
1 change: 1 addition & 0 deletions tools/objtool/include/objtool/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct elf {
int fd;
bool changed;
char *name;
unsigned int text_size;
struct list_head sections;

int symbol_bits;
Expand Down

0 comments on commit d33b903

Please sign in to comment.