Skip to content

Commit d33b903

Browse files
author
Peter Zijlstra
committed
objtool: Improve reloc hash size guestimate
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
1 parent c199f64 commit d33b903

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

tools/objtool/elf.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ static int read_sections(struct elf *elf)
288288
}
289289
sec->len = sec->sh.sh_size;
290290

291+
if (sec->sh.sh_flags & SHF_EXECINSTR)
292+
elf->text_size += sec->len;
293+
291294
list_add_tail(&sec->list, &elf->sections);
292295
elf_hash_add(section, &sec->hash, sec->idx);
293296
elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name));
@@ -581,13 +584,7 @@ static int read_relocs(struct elf *elf)
581584
unsigned int symndx;
582585
unsigned long nr_reloc, max_reloc = 0, tot_reloc = 0;
583586

584-
sec = find_section_by_name(elf, ".text");
585-
if (!sec) {
586-
WARN("no .text");
587-
return -1;
588-
}
589-
590-
if (!elf_alloc_hash(reloc, sec->len / 16))
587+
if (!elf_alloc_hash(reloc, elf->text_size / 16))
591588
return -1;
592589

593590
list_for_each_entry(sec, &elf->sections, list) {

tools/objtool/include/objtool/elf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct elf {
8383
int fd;
8484
bool changed;
8585
char *name;
86+
unsigned int text_size;
8687
struct list_head sections;
8788

8889
int symbol_bits;

0 commit comments

Comments
 (0)