Skip to content

Commit

Permalink
objtool: Create reloc sections implicitly
Browse files Browse the repository at this point in the history
Have elf_add_reloc() create the relocation section implicitly.

Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Link: https://lkml.kernel.org/r/20210326151259.880174448@infradead.org
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Apr 2, 2021
1 parent ef47cc0 commit d0c5c4c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 0 additions & 6 deletions tools/objtool/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,6 @@ static int create_static_call_sections(struct objtool_file *file)
if (!sec)
return -1;

if (!elf_create_reloc_section(file->elf, sec, SHT_RELA))
return -1;

idx = 0;
list_for_each_entry(insn, &file->static_call_list, static_call_node) {

Expand Down Expand Up @@ -547,9 +544,6 @@ static int create_mcount_loc_sections(struct objtool_file *file)
if (!sec)
return -1;

if (!elf_create_reloc_section(file->elf, sec, SHT_RELA))
return -1;

idx = 0;
list_for_each_entry(insn, &file->mcount_loc_list, mcount_loc_node) {

Expand Down
9 changes: 8 additions & 1 deletion tools/objtool/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,18 @@ static int read_symbols(struct elf *elf)
return -1;
}

static struct section *elf_create_reloc_section(struct elf *elf,
struct section *base,
int reltype);

int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
unsigned int type, struct symbol *sym, int addend)
{
struct reloc *reloc;

if (!sec->reloc && !elf_create_reloc_section(elf, sec, SHT_RELA))
return -1;

reloc = malloc(sizeof(*reloc));
if (!reloc) {
perror("malloc");
Expand Down Expand Up @@ -829,7 +836,7 @@ static struct section *elf_create_rela_reloc_section(struct elf *elf, struct sec
return sec;
}

struct section *elf_create_reloc_section(struct elf *elf,
static struct section *elf_create_reloc_section(struct elf *elf,
struct section *base,
int reltype)
{
Expand Down
1 change: 0 additions & 1 deletion tools/objtool/include/objtool/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ static inline u32 reloc_hash(struct reloc *reloc)

struct elf *elf_open_read(const char *name, int flags);
struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr);
struct section *elf_create_reloc_section(struct elf *elf, struct section *base, int reltype);

int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
unsigned int type, struct symbol *sym, int addend);
Expand Down
2 changes: 0 additions & 2 deletions tools/objtool/orc_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ int orc_create(struct objtool_file *file)
sec = elf_create_section(file->elf, ".orc_unwind_ip", 0, sizeof(int), nr);
if (!sec)
return -1;
if (!elf_create_reloc_section(file->elf, sec, SHT_RELA))
return -1;

/* Write ORC entries to sections: */
list_for_each_entry(entry, &orc_list, list) {
Expand Down

0 comments on commit d0c5c4c

Please sign in to comment.