[PATCH 3/3] perf script: Provide weak stubs for instruction decoding

Ian Rogers irogers at google.com
Wed May 13 09:20:11 PDT 2026


On Wed, May 13, 2026 at 8:50 AM Li Guan <guanli.oerv at isrc.iscas.ac.cn> wrote:
>
> When cross-compiling perf for architectures that do not yet implement
> hardware-specific instruction decoding (such as RISC-V and ARM64),
> the linker fails with undefined references to `dump_insn` and
> `arch_is_uncond_branch` in builtin-script.c.
>
> Provide global __weak stubs for these functions to ensure successful
> linking across all architectures. Architectures that support these
> features will automatically override these weak symbols.

No don't. Weak symbols are the devil's work (they are outside of the C
specification) and a time bomb set to explode during an LTO build. As
mentioned earlier, these functions should use perf_env's e_machine and
arch arguments so they can work in cross-platform settings. I believe
you've broken your build in interesting ways, but this isn't the fix.

Thanks,
Ian

> Signed-off-by: Li Guan <guanli.oerv at isrc.iscas.ac.cn>
> ---
>  tools/perf/builtin-script.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index c8ac9f01a3..80a8f0e80b 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -4608,3 +4608,25 @@ int cmd_script(int argc, const char **argv)
>  out:
>         return err;
>  }
> +
> +/*
> + * Provide weak stubs for architectures that have not yet implemented
> + * instruction decoding. This prevents linker errors (undefined
> + * references) on non-x86 architectures (like ARM64, RISC-V) when
> + * building perf script.
> + */
> +const char * __weak dump_insn(struct perf_insn *x __maybe_unused,
> +                             u64 ip __maybe_unused,
> +                             u8 *inbuf __maybe_unused,
> +                             int inlen __maybe_unused,
> +                             int *lenp __maybe_unused)
> +{
> +       return NULL;
> +}
> +
> +int __weak arch_is_uncond_branch(const unsigned char *buf __maybe_unused,
> +                                size_t len __maybe_unused,
> +                                int x86_64 __maybe_unused)
> +{
> +       return 0;
> +}
> --
> 2.54.0
>



More information about the linux-riscv mailing list