Re: [PATCH] perf capstone: Fix build with Capstone versions before 6
From: Namhyung Kim
Date: Mon Jul 13 2026 - 16:54:04 EST
On Mon, Jul 13, 2026 at 07:21:33PM +0100, Leo Yan wrote:
> Hi Namhyung,
>
> On Mon, Jul 13, 2026 at 10:39:57AM -0700, Namhyung Kim wrote:
> > On Mon, Jul 13, 2026 at 12:08:35PM +0100, Leo Yan wrote:
> > > The commit 12c4737f55f2 ("perf capstone: Determine architecture from
> > > e_machine") added a RISC-V mapping for Capstone disassembly.
> > >
> > > However, the RISC-V arch and mode definitions are only available from
> > > Capstone 6.0.0. Older Capstone headers do not define CS_ARCH_RISCV,
> > > CS_MODE_RISCV64 or CS_MODE_RISCV32, so perf fails to build.
> > >
> > > Guard the RISC-V mapping with a Capstone major version check. Also use
> > > CS_MODE_RISCV_C instead of CS_MODE_RISCVC, which is the mode name used
> > > by Capstone 6.
> >
> > Please see
> >
> > https://lore.kernel.org/r/20260706234836.815254-1-namhyung@xxxxxxxxxx
>
> I am a bit concerned that defining the macros directly in perf is a good
> idea, since the Capstone library doesn't actually support the arch/insn
> and the macros merely work around the build.
Yep, the goal is to avoid build errors. Actually it'll fail at runtime
and fallback to other libraries when it tries to use on RISC-V. But I
think it should continue to support old capstones on supported archs.
>
> Perhaps checking the Capstone version would be a safer approach?
I'm not sure. IIUC RISC-V support was added to v5.0 and CS_MODE_RISCV_C
was changed before v6.0 is out. Do you build capstone from source or
use a packaged version?
>
> I have no knowledge for capstone, I will leave this to you to decide which
> is better. I tested your patch, which works well at my side.
Thanks for the test!
Namhyung