objtool: Create reloc sections implicitly
authorPeter Zijlstra <peterz@infradead.org>
Fri, 26 Mar 2021 15:12:08 +0000 (16:12 +0100)
committerIngo Molnar <mingo@kernel.org>
Fri, 2 Apr 2021 10:44:37 +0000 (12:44 +0200)
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
tools/objtool/check.c
tools/objtool/elf.c
tools/objtool/include/objtool/elf.h
tools/objtool/orc_gen.c

index 61fe29ae4cd466b80c100cedd3cb345bd23758f0..600fa67153d318e1d0446be04f471d52a8d4bba5 100644 (file)
@@ -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) {
 
@@ -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) {
 
index 0ab52ac3f861040b46e9089a933a3b1c90514c40..7b65ae3beea4a56b39a1c03d6d4f28ce5a8df776 100644 (file)
@@ -447,11 +447,18 @@ err:
        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");
@@ -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)
 {
index 825ad326201dc49161081548bba1ede024b6b215..463f329f1c6653381908042105bf00bb26d7ca11 100644 (file)
@@ -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);
index 1b57be6508f40d992057c8144b2106ff26acfc4c..dc9b7dd314b05fbc0780e5699931476cdfdbe6c6 100644 (file)
@@ -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) {