Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <yangtiezhu@loongson.cn>
Link: https://lore.kernel.org/r/20250211115016.26913-3-yangtiezhu@loongson.cn
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

authored by

Tiezhu Yang and committed by
Josh Poimboeuf
091bf313 ab6ce22b

+41 -1
+11
tools/objtool/arch/loongarch/decode.c
··· 363 363 state->cfa.base = CFI_SP; 364 364 state->cfa.offset = 0; 365 365 } 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 + }
+14
tools/objtool/arch/powerpc/decode.c
··· 106 106 state->regs[CFI_RA].base = CFI_CFA; 107 107 state->regs[CFI_RA].offset = 0; 108 108 } 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 + }
+13
tools/objtool/arch/x86/decode.c
··· 852 852 return !strcmp(sym->name, "retbleed_return_thunk") || 853 853 !strcmp(sym->name, "srso_safe_ret"); 854 854 } 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 + }
+1 -1
tools/objtool/check.c
··· 1969 1969 break; 1970 1970 1971 1971 /* 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)) 1973 1973 break; 1974 1974 1975 1975 sym_offset = reloc->sym->offset + reloc_addend(reloc);
+2
tools/objtool/include/objtool/arch.h
··· 97 97 98 98 bool arch_pc_relative_reloc(struct reloc *reloc); 99 99 100 + unsigned int arch_reloc_size(struct reloc *reloc); 101 + 100 102 #endif /* _ARCH_H */