On Tue, Nov 26, 2024 at 09:22:22PM +0800, Tiezhu Yang wrote:
OK, if I understand your comment correctly, this should be an
arch-specific function defined in
tools/objtool/arch/*/include/arch/elf.h, otherwise it also needs to
check ehdr.e_machine
in tools/objtool/include/objtool/elf.h.
There are only macro definitions in
tools/objtool/arch/*/include/arch/elf.h,
so I think it is better to add reloc_size() in
tools/objtool/include/objtool/elf.h,
like this:
static inline unsigned int reloc_size(struct elf *elf, struct reloc *reloc)
{
if (elf->ehdr.e_machine == EM_X86_64) {
switch (reloc_type(reloc)) {
case R_X86_64_32:
case R_X86_64_PC32:
return 4;
case R_X86_64_64:
case R_X86_64_PC64:
return 8;
default:
ERROR("unknown X86_64 reloc type");
}
} else if (elf->ehdr.e_machine == EM_LOONGARCH) {
switch (reloc_type(reloc)) {
case R_LARCH_32:
case R_LARCH_32_PCREL:
return 4;
case R_LARCH_64:
case R_LARCH_64_PCREL:
return 8;
default:
ERROR("unknown LoongArch reloc type");
}
} else {
return 8;
}
}
How about tools/objtool/arch/loongarch/decode.c? Then we don't need to
check e_machine.