Skip to content

Commit 091bf31

Browse files
seehearfeeljpoimboe
authored andcommitted
objtool: Handle different entry size of rodata
In the most cases, the entry size of rodata is 8 bytes because the relocation type is 64 bit. There are also 32 bit relocation types, the entry size of rodata should be 4 bytes in this case. Add an arch-specific function arch_reloc_size() to assign the entry size of rodata for x86, powerpc and LoongArch. Signed-off-by: Tiezhu Yang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Huacai Chen <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]>
1 parent ab6ce22 commit 091bf31

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

tools/objtool/arch/loongarch/decode.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,14 @@ void arch_initial_func_cfi_state(struct cfi_init_state *state)
363363
state->cfa.base = CFI_SP;
364364
state->cfa.offset = 0;
365365
}
366+
367+
unsigned int arch_reloc_size(struct reloc *reloc)
368+
{
369+
switch (reloc_type(reloc)) {
370+
case R_LARCH_32:
371+
case R_LARCH_32_PCREL:
372+
return 4;
373+
default:
374+
return 8;
375+
}
376+
}

tools/objtool/arch/powerpc/decode.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,17 @@ void arch_initial_func_cfi_state(struct cfi_init_state *state)
106106
state->regs[CFI_RA].base = CFI_CFA;
107107
state->regs[CFI_RA].offset = 0;
108108
}
109+
110+
unsigned int arch_reloc_size(struct reloc *reloc)
111+
{
112+
switch (reloc_type(reloc)) {
113+
case R_PPC_REL32:
114+
case R_PPC_ADDR32:
115+
case R_PPC_UADDR32:
116+
case R_PPC_PLT32:
117+
case R_PPC_PLTREL32:
118+
return 4;
119+
default:
120+
return 8;
121+
}
122+
}

tools/objtool/arch/x86/decode.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,3 +852,16 @@ bool arch_is_embedded_insn(struct symbol *sym)
852852
return !strcmp(sym->name, "retbleed_return_thunk") ||
853853
!strcmp(sym->name, "srso_safe_ret");
854854
}
855+
856+
unsigned int arch_reloc_size(struct reloc *reloc)
857+
{
858+
switch (reloc_type(reloc)) {
859+
case R_X86_64_32:
860+
case R_X86_64_32S:
861+
case R_X86_64_PC32:
862+
case R_X86_64_PLT32:
863+
return 4;
864+
default:
865+
return 8;
866+
}
867+
}

tools/objtool/check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
19691969
break;
19701970

19711971
/* Make sure the table entries are consecutive: */
1972-
if (prev_offset && reloc_offset(reloc) != prev_offset + 8)
1972+
if (prev_offset && reloc_offset(reloc) != prev_offset + arch_reloc_size(reloc))
19731973
break;
19741974

19751975
sym_offset = reloc->sym->offset + reloc_addend(reloc);

tools/objtool/include/objtool/arch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,6 @@ int arch_rewrite_retpolines(struct objtool_file *file);
9797

9898
bool arch_pc_relative_reloc(struct reloc *reloc);
9999

100+
unsigned int arch_reloc_size(struct reloc *reloc);
101+
100102
#endif /* _ARCH_H */

0 commit comments

Comments
 (0)