Re: [PATCH v4 04/10] objtool: Handle PC relative relocation type

From: Josh Poimboeuf
Date: Tue Nov 26 2024 - 19:58:16 EST


On Tue, Nov 26, 2024 at 09:24:59PM +0800, Tiezhu Yang wrote:
> On 11/26/2024 07:00 PM, Tiezhu Yang wrote:
> > > Maybe there should be an arch-specific function arch_adjusted_addend().
>
> Add adjust_offset() in
> tools/objtool/include/objtool/elf.h,
> like this:
>
> static inline unsigned long adjust_offset(struct elf *elf, struct reloc
> *reloc,
> unsigned long offset)
> {
> if (elf->ehdr.e_machine == EM_LOONGARCH && reloc_type(reloc) ==
> R_LARCH_32_PCREL)
> offset = reloc->sym->offset + reloc_addend(reloc) -
> (reloc_offset(reloc) - reloc_offset(table));
>
> return offset;
> }
>
> then call it in check.c, like this:
>
> offset = reloc->sym->offset + reloc_addend(reloc);
> offset = adjust_offset(file->elf, reloc, offset);
>
> What do you think?

Similar to reloc_size() I'm thinking this should also be in
arch-specific decode.c.

--
Josh