On Fri, May 09, 2025 at 01:17:16PM -0700, Josh Poimboeuf wrote:
> diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
> index cdf385e54c69..ae4f83fcbadf 100644
> --- a/tools/objtool/arch/x86/decode.c
> +++ b/tools/objtool/arch/x86/decode.c
> @@ -95,6 +95,46 @@ s64 arch_insn_adjusted_addend(struct instruction *insn,
> struct reloc *reloc)
> return phys_to_virt(addend);
> }
>
> +static void scan_for_insn(struct section *sec, unsigned long offset,
> + unsigned long *insn_off, unsigned int *insn_len)
> +{
> + unsigned long o = 0;
> + struct insn insn;
> +
> + while (1) {
> +
> + insn_decode(&insn, sec->data->d_buf + o, sec_size(sec) - o,
> + INSN_MODE_64);
> +
> + if (o + insn.length > offset) {
> + *insn_off = o;
> + *insn_len = insn.length;
> + return;
> + }
> +
> + o += insn.length;
> + }
> +}
> +
> +u64 arch_adjusted_addend(struct reloc *reloc)
> +{
> + unsigned int type = reloc_type(reloc);
> + s64 addend = reloc_addend(reloc);
> + unsigned long insn_off;
> + unsigned int insn_len;
> +
> + if (type == R_X86_64_PLT32)
> + return addend + 4;
> +
> + if (type != R_X86_64_PC32 || !is_text_sec(reloc->sec->base))
> + return addend;
> +
> + scan_for_insn(reloc->sec->base, reloc_offset(reloc),
> + &insn_off, &insn_len);
> +
> + return addend + insn_off + insn_len - reloc_offset(reloc);
> +}
This looks like a rather expensive proposition; it will have to decode
the section nr_reloc times.
Does it not make more sense to fully decode the section like 'normal' ?