Commit 19526717 authored by Peter Zijlstra's avatar Peter Zijlstra

objtool: Optimize elf_dirty_reloc_sym()

When moving a symbol in the symtab its index changes and any reloc
referring that symtol-table-index will need to be rewritten too.

In order to facilitate this, objtool simply marks the whole reloc
section 'changed' which will cause the whole section to be
re-generated.

However, finding the relocs that use any given symbol is implemented
rather crudely -- a fully iteration of all sections and their relocs.
Given that some builds have over 20k sections (kallsyms etc..)
iterating all that for *each* symbol moved takes a bit of time.

Instead have each symbol keep a list of relocs that reference it.

This *vastly* improves build times for certain configs.
Reported-by: default avatarBorislav Petkov <bp@alien8.de>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/Y2LlRA7x+8UsE1xf@hirez.programming.kicks-ass.net
parent 0c3e806e
...@@ -356,6 +356,7 @@ static void elf_add_symbol(struct elf *elf, struct symbol *sym) ...@@ -356,6 +356,7 @@ static void elf_add_symbol(struct elf *elf, struct symbol *sym)
struct rb_node *pnode; struct rb_node *pnode;
struct symbol *iter; struct symbol *iter;
INIT_LIST_HEAD(&sym->reloc_list);
INIT_LIST_HEAD(&sym->pv_target); INIT_LIST_HEAD(&sym->pv_target);
sym->alias = sym; sym->alias = sym;
...@@ -557,6 +558,7 @@ int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, ...@@ -557,6 +558,7 @@ int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
reloc->sym = sym; reloc->sym = sym;
reloc->addend = addend; reloc->addend = addend;
list_add_tail(&reloc->sym_reloc_entry, &sym->reloc_list);
list_add_tail(&reloc->list, &sec->reloc->reloc_list); list_add_tail(&reloc->list, &sec->reloc->reloc_list);
elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc));
...@@ -573,21 +575,10 @@ int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, ...@@ -573,21 +575,10 @@ int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
*/ */
static void elf_dirty_reloc_sym(struct elf *elf, struct symbol *sym) static void elf_dirty_reloc_sym(struct elf *elf, struct symbol *sym)
{ {
struct section *sec;
list_for_each_entry(sec, &elf->sections, list) {
struct reloc *reloc; struct reloc *reloc;
if (sec->changed) list_for_each_entry(reloc, &sym->reloc_list, sym_reloc_entry)
continue; reloc->sec->changed = true;
list_for_each_entry(reloc, &sec->reloc_list, list) {
if (reloc->sym == sym) {
sec->changed = true;
break;
}
}
}
} }
/* /*
...@@ -902,11 +893,12 @@ static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsi ...@@ -902,11 +893,12 @@ static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsi
static int read_relocs(struct elf *elf) static int read_relocs(struct elf *elf)
{ {
unsigned long nr_reloc, max_reloc = 0, tot_reloc = 0;
struct section *sec; struct section *sec;
struct reloc *reloc; struct reloc *reloc;
int i;
unsigned int symndx; unsigned int symndx;
unsigned long nr_reloc, max_reloc = 0, tot_reloc = 0; struct symbol *sym;
int i;
if (!elf_alloc_hash(reloc, elf->text_size / 16)) if (!elf_alloc_hash(reloc, elf->text_size / 16))
return -1; return -1;
...@@ -947,13 +939,14 @@ static int read_relocs(struct elf *elf) ...@@ -947,13 +939,14 @@ static int read_relocs(struct elf *elf)
reloc->sec = sec; reloc->sec = sec;
reloc->idx = i; reloc->idx = i;
reloc->sym = find_symbol_by_index(elf, symndx); reloc->sym = sym = find_symbol_by_index(elf, symndx);
if (!reloc->sym) { if (!reloc->sym) {
WARN("can't find reloc entry symbol %d for %s", WARN("can't find reloc entry symbol %d for %s",
symndx, sec->name); symndx, sec->name);
return -1; return -1;
} }
list_add_tail(&reloc->sym_reloc_entry, &sym->reloc_list);
list_add_tail(&reloc->list, &sec->reloc_list); list_add_tail(&reloc->list, &sec->reloc_list);
elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc));
......
...@@ -62,6 +62,7 @@ struct symbol { ...@@ -62,6 +62,7 @@ struct symbol {
u8 fentry : 1; u8 fentry : 1;
u8 profiling_func : 1; u8 profiling_func : 1;
struct list_head pv_target; struct list_head pv_target;
struct list_head reloc_list;
}; };
struct reloc { struct reloc {
...@@ -73,6 +74,7 @@ struct reloc { ...@@ -73,6 +74,7 @@ struct reloc {
}; };
struct section *sec; struct section *sec;
struct symbol *sym; struct symbol *sym;
struct list_head sym_reloc_entry;
unsigned long offset; unsigned long offset;
unsigned int type; unsigned int type;
s64 addend; s64 addend;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment