objtool: Get rid of reloc->type
authorJosh Poimboeuf <jpoimboe@kernel.org>
Tue, 30 May 2023 17:21:07 +0000 (10:21 -0700)
committerJosh Poimboeuf <jpoimboe@kernel.org>
Wed, 7 Jun 2023 17:03:22 +0000 (10:03 -0700)
Get the type from the embedded GElf_Rel[a] struct.

Link: https://lore.kernel.org/r/d1c1f8da31e4f052a2478aea585fcf355cacc53a.1685464332.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
tools/objtool/arch/x86/decode.c
tools/objtool/arch/x86/special.c
tools/objtool/check.c
tools/objtool/elf.c
tools/objtool/include/objtool/elf.h

index 9ef024fd648c1b39e039fc2ffb62a2aa8c344756..ffb12e83b2382e0ec97fb8a522dccac9fe5c8850 100644 (file)
@@ -84,7 +84,7 @@ bool arch_pc_relative_reloc(struct reloc *reloc)
         * All relocation types where P (the address of the target)
         * is included in the computation.
         */
-       switch (reloc->type) {
+       switch (reloc_type(reloc)) {
        case R_X86_64_PC8:
        case R_X86_64_PC16:
        case R_X86_64_PC32:
index 7c97b739127994febfded845e40d8b5dd1180b23..1a54a249cb504ef9c02de78c1325dd7b4d780706 100644 (file)
@@ -108,7 +108,7 @@ struct reloc *arch_find_switch_table(struct objtool_file *file,
        table_offset = text_reloc->addend;
        table_sec = text_reloc->sym->sec;
 
-       if (text_reloc->type == R_X86_64_PC32)
+       if (reloc_type(text_reloc) == R_X86_64_PC32)
                table_offset += 4;
 
        /*
@@ -138,7 +138,7 @@ struct reloc *arch_find_switch_table(struct objtool_file *file,
         * indicates a rare GCC quirk/bug which can leave dead
         * code behind.
         */
-       if (text_reloc->type == R_X86_64_PC32)
+       if (reloc_type(text_reloc) == R_X86_64_PC32)
                file->ignore_unreachables = true;
 
        return rodata_reloc;
index e06ffad5a93c26a73157feaa4df4d61eadd5a77c..04b4152be206dde92d97bb916f027fa4be1aa35e 100644 (file)
@@ -958,7 +958,7 @@ static int create_mcount_loc_sections(struct objtool_file *file)
                if (!reloc)
                        return -1;
 
-               reloc->type = addr_size == 8 ? R_ABS64 : R_ABS32;
+               set_reloc_type(reloc, addr_size == 8 ? R_ABS64 : R_ABS32);
 
                idx++;
        }
@@ -1354,7 +1354,7 @@ static void annotate_call_site(struct objtool_file *file,
         */
        if (opts.hack_noinstr && insn->sec->noinstr && sym->profiling_func) {
                if (reloc) {
-                       reloc->type = R_NONE;
+                       set_reloc_type(reloc, R_NONE);
                        elf_write_reloc(file->elf, reloc);
                }
 
@@ -1383,7 +1383,7 @@ static void annotate_call_site(struct objtool_file *file,
                        WARN_INSN(insn, "tail call to __fentry__ !?!?");
                if (opts.mnop) {
                        if (reloc) {
-                               reloc->type = R_NONE;
+                               set_reloc_type(reloc, R_NONE);
                                elf_write_reloc(file->elf, reloc);
                        }
 
@@ -1865,7 +1865,7 @@ static int handle_jump_alt(struct objtool_file *file,
                struct reloc *reloc = insn_reloc(file, orig_insn);
 
                if (reloc) {
-                       reloc->type = R_NONE;
+                       set_reloc_type(reloc, R_NONE);
                        elf_write_reloc(file->elf, reloc);
                }
                elf_write_insn(file->elf, orig_insn->sec,
@@ -4277,7 +4277,8 @@ static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn
                        continue;
 
                off = reloc->sym->offset;
-               if (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32)
+               if (reloc_type(reloc) == R_X86_64_PC32 ||
+                   reloc_type(reloc) == R_X86_64_PLT32)
                        off += arch_dest_reloc_offset(reloc->addend);
                else
                        off += reloc->addend;
index 2b45460225d18f2b50e8f7710e90f57edd86c275..be9d24dcdf56b86026b8f7db7802cc192561a41a 100644 (file)
@@ -541,6 +541,7 @@ static int elf_update_sym_relocs(struct elf *elf, struct symbol *sym)
        struct reloc *reloc;
 
        list_for_each_entry(reloc, &sym->reloc_list, sym_reloc_entry) {
+               reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc_type(reloc));
                if (elf_write_reloc(elf, reloc))
                        return -1;
        }
@@ -831,11 +832,11 @@ static struct reloc *elf_init_reloc(struct elf *elf, struct section *rsec,
        }
 
        reloc->sec = rsec;
-       reloc->type = type;
        reloc->sym = sym;
        reloc->addend = addend;
 
        reloc->rel.r_offset = offset;
+       reloc->rel.r_info = GELF_R_INFO(sym->idx, type);
 
        if (elf_write_reloc(elf, reloc))
                return NULL;
@@ -910,7 +911,6 @@ static int read_reloc(struct section *rsec, int i, struct reloc *reloc)
                return -1;
        }
 
-       reloc->type = GELF_R_TYPE(reloc->rel.r_info);
        reloc->addend = rela ? reloc->rela.r_addend : 0;
 
        return 0;
@@ -1231,8 +1231,6 @@ int elf_write_reloc(struct elf *elf, struct reloc *reloc)
        struct section *rsec = reloc->sec;
        int ret;
 
-       reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type);
-
        if (rsec->sh.sh_type == SHT_RELA) {
                reloc->rela.r_addend = reloc->addend;
                ret = gelf_update_rela(rsec->data, reloc_idx(reloc), &reloc->rela);
index 2070860a099e26ddadfe488628b6604faed3d9c0..41d2149f8bb8a3b59c516f2beabdc34d794d9a69 100644 (file)
@@ -76,7 +76,6 @@ struct reloc {
        struct symbol *sym;
        struct list_head sym_reloc_entry;
        s64 addend;
-       unsigned int type;
        bool jump_table_start;
 };
 
@@ -208,6 +207,16 @@ static inline unsigned long reloc_offset(struct reloc *reloc)
        return reloc->rel.r_offset;
 }
 
+static inline unsigned int reloc_type(struct reloc *reloc)
+{
+       return GELF_R_TYPE(reloc->rel.r_info);
+}
+
+static inline void set_reloc_type(struct reloc *reloc, int type)
+{
+       reloc->rel.r_info = GELF_R_INFO(GELF_R_SYM(reloc->rel.r_info), type);
+}
+
 #define for_each_sec(file, sec)                                                \
        list_for_each_entry(sec, &file->elf->sections, list)