On Fri, May 09, 2025 at 01:16:42PM -0700, Josh Poimboeuf wrote:
> On x86, arch_dest_reloc_offset() hardcodes the addend adjustment to
> four, but the actual adjustment depends on the relocation type.  Fix
> that.

> +s64 arch_insn_adjusted_addend(struct instruction *insn, struct reloc *reloc)
>  {
> -     return addend + 4;
> +     s64 addend = reloc_addend(reloc);
> +
> +     switch (reloc_type(reloc)) {
> +     case R_X86_64_PC32:
> +     case R_X86_64_PLT32:
> +             addend += insn->offset + insn->len - reloc_offset(reloc);
> +             break;
> +     default:
> +             break;
> +     }
> +
> +     return addend;
>  }

Should this not be something like:

s64 arch_insn_adjusted_addend(struct instruction *insn, struct reloc *reloc)
{
        s64 addend = reloc_addend(reloc);

        if (arch_pc_relative_reloc(reloc))
                addend += insn->offset + insn->len - reloc_offset(reloc);

        return addend;
}

instead?

AFAIU arch_pc_relative_reloc() is the exact same set of relocations.

Reply via email to