Commit 3a647607 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

objtool: Rework the elf_rebuild_reloc_section() logic

Instead of manually calling elf_rebuild_reloc_section() on sections
we've called elf_add_reloc() on, have elf_write() DTRT.

This makes it easier to add random relocations in places without
carefully tracking when we're done and need to flush what section.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Reviewed-by: default avatarMiroslav Benes <mbenes@suse.cz>
Link: https://lkml.kernel.org/r/20210326151259.754213408@infradead.org
parent a958c4fe
...@@ -542,9 +542,6 @@ static int create_static_call_sections(struct objtool_file *file) ...@@ -542,9 +542,6 @@ static int create_static_call_sections(struct objtool_file *file)
idx++; idx++;
} }
if (elf_rebuild_reloc_section(file->elf, reloc_sec))
return -1;
return 0; return 0;
} }
...@@ -614,9 +611,6 @@ static int create_mcount_loc_sections(struct objtool_file *file) ...@@ -614,9 +611,6 @@ static int create_mcount_loc_sections(struct objtool_file *file)
idx++; idx++;
} }
if (elf_rebuild_reloc_section(file->elf, reloc_sec))
return -1;
return 0; return 0;
} }
......
...@@ -479,6 +479,8 @@ void elf_add_reloc(struct elf *elf, struct reloc *reloc) ...@@ -479,6 +479,8 @@ void elf_add_reloc(struct elf *elf, struct reloc *reloc)
list_add_tail(&reloc->list, &sec->reloc_list); list_add_tail(&reloc->list, &sec->reloc_list);
elf_hash_add(elf->reloc_hash, &reloc->hash, reloc_hash(reloc)); elf_hash_add(elf->reloc_hash, &reloc->hash, reloc_hash(reloc));
sec->changed = true;
} }
static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx)
...@@ -558,7 +560,9 @@ static int read_relocs(struct elf *elf) ...@@ -558,7 +560,9 @@ static int read_relocs(struct elf *elf)
return -1; return -1;
} }
elf_add_reloc(elf, reloc); list_add_tail(&reloc->list, &sec->reloc_list);
elf_hash_add(elf->reloc_hash, &reloc->hash, reloc_hash(reloc));
nr_reloc++; nr_reloc++;
} }
max_reloc = max(max_reloc, nr_reloc); max_reloc = max(max_reloc, nr_reloc);
...@@ -873,14 +877,11 @@ static int elf_rebuild_rela_reloc_section(struct section *sec, int nr) ...@@ -873,14 +877,11 @@ static int elf_rebuild_rela_reloc_section(struct section *sec, int nr)
return 0; return 0;
} }
int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) static int elf_rebuild_reloc_section(struct elf *elf, struct section *sec)
{ {
struct reloc *reloc; struct reloc *reloc;
int nr; int nr;
sec->changed = true;
elf->changed = true;
nr = 0; nr = 0;
list_for_each_entry(reloc, &sec->reloc_list, list) list_for_each_entry(reloc, &sec->reloc_list, list)
nr++; nr++;
...@@ -944,9 +945,15 @@ int elf_write(struct elf *elf) ...@@ -944,9 +945,15 @@ int elf_write(struct elf *elf)
struct section *sec; struct section *sec;
Elf_Scn *s; Elf_Scn *s;
/* Update section headers for changed sections: */ /* Update changed relocation sections and section headers: */
list_for_each_entry(sec, &elf->sections, list) { list_for_each_entry(sec, &elf->sections, list) {
if (sec->changed) { if (sec->changed) {
if (sec->base &&
elf_rebuild_reloc_section(elf, sec)) {
WARN("elf_rebuild_reloc_section");
return -1;
}
s = elf_getscn(elf->elf, sec->idx); s = elf_getscn(elf->elf, sec->idx);
if (!s) { if (!s) {
WARN_ELF("elf_getscn"); WARN_ELF("elf_getscn");
...@@ -958,6 +965,7 @@ int elf_write(struct elf *elf) ...@@ -958,6 +965,7 @@ int elf_write(struct elf *elf)
} }
sec->changed = false; sec->changed = false;
elf->changed = true;
} }
} }
......
...@@ -142,7 +142,6 @@ struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *se ...@@ -142,7 +142,6 @@ struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *se
struct symbol *find_func_containing(struct section *sec, unsigned long offset); struct symbol *find_func_containing(struct section *sec, unsigned long offset);
void insn_to_reloc_sym_addend(struct section *sec, unsigned long offset, void insn_to_reloc_sym_addend(struct section *sec, unsigned long offset,
struct reloc *reloc); struct reloc *reloc);
int elf_rebuild_reloc_section(struct elf *elf, struct section *sec);
#define for_each_sec(file, sec) \ #define for_each_sec(file, sec) \
list_for_each_entry(sec, &file->elf->sections, list) list_for_each_entry(sec, &file->elf->sections, list)
......
...@@ -254,8 +254,5 @@ int orc_create(struct objtool_file *file) ...@@ -254,8 +254,5 @@ int orc_create(struct objtool_file *file)
return -1; return -1;
} }
if (elf_rebuild_reloc_section(file->elf, ip_rsec))
return -1;
return 0; return 0;
} }
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