Skip to content

Commit d0c5c4c

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
objtool: Create reloc sections implicitly
Have elf_add_reloc() create the relocation section implicitly. Suggested-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent ef47cc0 commit d0c5c4c

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

tools/objtool/check.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,6 @@ static int create_static_call_sections(struct objtool_file *file)
459459
if (!sec)
460460
return -1;
461461

462-
if (!elf_create_reloc_section(file->elf, sec, SHT_RELA))
463-
return -1;
464-
465462
idx = 0;
466463
list_for_each_entry(insn, &file->static_call_list, static_call_node) {
467464

@@ -547,9 +544,6 @@ static int create_mcount_loc_sections(struct objtool_file *file)
547544
if (!sec)
548545
return -1;
549546

550-
if (!elf_create_reloc_section(file->elf, sec, SHT_RELA))
551-
return -1;
552-
553547
idx = 0;
554548
list_for_each_entry(insn, &file->mcount_loc_list, mcount_loc_node) {
555549

tools/objtool/elf.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,18 @@ static int read_symbols(struct elf *elf)
447447
return -1;
448448
}
449449

450+
static struct section *elf_create_reloc_section(struct elf *elf,
451+
struct section *base,
452+
int reltype);
453+
450454
int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
451455
unsigned int type, struct symbol *sym, int addend)
452456
{
453457
struct reloc *reloc;
454458

459+
if (!sec->reloc && !elf_create_reloc_section(elf, sec, SHT_RELA))
460+
return -1;
461+
455462
reloc = malloc(sizeof(*reloc));
456463
if (!reloc) {
457464
perror("malloc");
@@ -829,7 +836,7 @@ static struct section *elf_create_rela_reloc_section(struct elf *elf, struct sec
829836
return sec;
830837
}
831838

832-
struct section *elf_create_reloc_section(struct elf *elf,
839+
static struct section *elf_create_reloc_section(struct elf *elf,
833840
struct section *base,
834841
int reltype)
835842
{

tools/objtool/include/objtool/elf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ static inline u32 reloc_hash(struct reloc *reloc)
122122

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

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

tools/objtool/orc_gen.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ int orc_create(struct objtool_file *file)
225225
sec = elf_create_section(file->elf, ".orc_unwind_ip", 0, sizeof(int), nr);
226226
if (!sec)
227227
return -1;
228-
if (!elf_create_reloc_section(file->elf, sec, SHT_RELA))
229-
return -1;
230228

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

0 commit comments

Comments
 (0)