* [PATCH] perf build: Fix compiler errors with old capstone
@ 2026-07-01 18:28 Namhyung Kim
2026-07-01 18:49 ` Ian Rogers
0 siblings, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2026-07-01 18:28 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark, Peter Zijlstra,
Ingo Molnar, LKML, linux-perf-users
It seems RISCV was added in capstone version 5. Unfortunately they are
enum constants so cannot check with #ifdef but anyway we can define the
symbols. Let's do it using the version number to avoid build errors.
It'll fail at runtime though.
util/capstone.c: In function 'e_machine_to_capstone':
util/capstone.c:186:25: error: 'CS_ARCH_RISCV' undeclared (first use in this function);
did you mean 'CS_ARCH_SYSZ'?
186 | *arch = CS_ARCH_RISCV;
| ^~~~~~~~~~~~~
| CS_ARCH_SYSZ
util/capstone.c:186:25: note: each undeclared identifier is reported only once for each function it appears in
util/capstone.c:187:34: error: 'CS_MODE_RISCV64' undeclared (first use in this function);
did you mean 'CS_MODE_MIPS64'?
187 | *mode |= (is64 ? CS_MODE_RISCV64 : CS_MODE_RISCV32) | CS_MODE_RISCVC;
| ^~~~~~~~~~~~~~~
| CS_MODE_MIPS64
Also note that capstone renamed CS_MODE_RISCVC to CS_MODE_RISCV_C which
would cause a different build failure on latest versions. It's reported
in https://github.com/capstone-engine/capstone/issues/2977 so I think
they will add compatibility layer to prevent the error.
Fixes: 12c4737f55f2 ("perf capstone: Determine architecture from e_machine")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/capstone.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c
index 5ad537fea4360e31..dd7cd97d0a38056e 100644
--- a/tools/perf/util/capstone.c
+++ b/tools/perf/util/capstone.c
@@ -24,6 +24,13 @@
#include "symbol.h"
#include "thread.h"
+#if CS_VERSION_MAJOR < 5
+#define CS_ARCH_RISCV CS_ARCH_MAX
+#define CS_MODE_RISCV32 1
+#define CS_MODE_RISCV64 2
+#define CS_MODE_RISCVC 4
+#endif
+
#ifdef LIBCAPSTONE_DLOPEN
static void *perf_cs_dll_handle(void)
{
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] perf build: Fix compiler errors with old capstone
2026-07-01 18:28 [PATCH] perf build: Fix compiler errors with old capstone Namhyung Kim
@ 2026-07-01 18:49 ` Ian Rogers
2026-07-01 19:30 ` Namhyung Kim
0 siblings, 1 reply; 4+ messages in thread
From: Ian Rogers @ 2026-07-01 18:49 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
On Wed, Jul 1, 2026 at 11:28 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> It seems RISCV was added in capstone version 5. Unfortunately they are
> enum constants so cannot check with #ifdef but anyway we can define the
> symbols. Let's do it using the version number to avoid build errors.
> It'll fail at runtime though.
>
> util/capstone.c: In function 'e_machine_to_capstone':
> util/capstone.c:186:25: error: 'CS_ARCH_RISCV' undeclared (first use in this function);
> did you mean 'CS_ARCH_SYSZ'?
> 186 | *arch = CS_ARCH_RISCV;
> | ^~~~~~~~~~~~~
> | CS_ARCH_SYSZ
> util/capstone.c:186:25: note: each undeclared identifier is reported only once for each function it appears in
>
> util/capstone.c:187:34: error: 'CS_MODE_RISCV64' undeclared (first use in this function);
> did you mean 'CS_MODE_MIPS64'?
> 187 | *mode |= (is64 ? CS_MODE_RISCV64 : CS_MODE_RISCV32) | CS_MODE_RISCVC;
> | ^~~~~~~~~~~~~~~
> | CS_MODE_MIPS64
>
> Also note that capstone renamed CS_MODE_RISCVC to CS_MODE_RISCV_C which
> would cause a different build failure on latest versions. It's reported
> in https://github.com/capstone-engine/capstone/issues/2977 so I think
> they will add compatibility layer to prevent the error.
>
> Fixes: 12c4737f55f2 ("perf capstone: Determine architecture from e_machine")
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Perhaps update the feature test from:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/build/feature/test-libcapstone.c?h=perf-tools-next
```
cs_open(CS_ARCH_X86, CS_MODE_64, &handle);
```
to be CS_ARCH_RISCV? That way we won't detect old libcapstones and
avoid cluttering up the code.
Thanks,
Ian
> ---
> tools/perf/util/capstone.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c
> index 5ad537fea4360e31..dd7cd97d0a38056e 100644
> --- a/tools/perf/util/capstone.c
> +++ b/tools/perf/util/capstone.c
> @@ -24,6 +24,13 @@
> #include "symbol.h"
> #include "thread.h"
>
> +#if CS_VERSION_MAJOR < 5
> +#define CS_ARCH_RISCV CS_ARCH_MAX
> +#define CS_MODE_RISCV32 1
> +#define CS_MODE_RISCV64 2
> +#define CS_MODE_RISCVC 4
> +#endif
> +
> #ifdef LIBCAPSTONE_DLOPEN
> static void *perf_cs_dll_handle(void)
> {
> --
> 2.55.0.rc0.799.gd6f94ed593-goog
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf build: Fix compiler errors with old capstone
2026-07-01 18:49 ` Ian Rogers
@ 2026-07-01 19:30 ` Namhyung Kim
2026-07-01 23:39 ` Ian Rogers
0 siblings, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2026-07-01 19:30 UTC (permalink / raw)
To: Ian Rogers
Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
Hi Ian,
On Wed, Jul 01, 2026 at 11:49:03AM -0700, Ian Rogers wrote:
> On Wed, Jul 1, 2026 at 11:28 AM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > It seems RISCV was added in capstone version 5. Unfortunately they are
> > enum constants so cannot check with #ifdef but anyway we can define the
> > symbols. Let's do it using the version number to avoid build errors.
> > It'll fail at runtime though.
> >
> > util/capstone.c: In function 'e_machine_to_capstone':
> > util/capstone.c:186:25: error: 'CS_ARCH_RISCV' undeclared (first use in this function);
> > did you mean 'CS_ARCH_SYSZ'?
> > 186 | *arch = CS_ARCH_RISCV;
> > | ^~~~~~~~~~~~~
> > | CS_ARCH_SYSZ
> > util/capstone.c:186:25: note: each undeclared identifier is reported only once for each function it appears in
> >
> > util/capstone.c:187:34: error: 'CS_MODE_RISCV64' undeclared (first use in this function);
> > did you mean 'CS_MODE_MIPS64'?
> > 187 | *mode |= (is64 ? CS_MODE_RISCV64 : CS_MODE_RISCV32) | CS_MODE_RISCVC;
> > | ^~~~~~~~~~~~~~~
> > | CS_MODE_MIPS64
> >
> > Also note that capstone renamed CS_MODE_RISCVC to CS_MODE_RISCV_C which
> > would cause a different build failure on latest versions. It's reported
> > in https://github.com/capstone-engine/capstone/issues/2977 so I think
> > they will add compatibility layer to prevent the error.
> >
> > Fixes: 12c4737f55f2 ("perf capstone: Determine architecture from e_machine")
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
>
> Perhaps update the feature test from:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/build/feature/test-libcapstone.c?h=perf-tools-next
> ```
> cs_open(CS_ARCH_X86, CS_MODE_64, &handle);
> ```
> to be CS_ARCH_RISCV? That way we won't detect old libcapstones and
> avoid cluttering up the code.
Then it'll drop support for capstone version 4 which works fine on some
architectures. Maybe we can add another feature check for capstone
RISC-V support but I think it's better to define the RISCV symbols here.
What do you think?
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf build: Fix compiler errors with old capstone
2026-07-01 19:30 ` Namhyung Kim
@ 2026-07-01 23:39 ` Ian Rogers
0 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2026-07-01 23:39 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
On Wed, Jul 1, 2026 at 12:30 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Hi Ian,
>
> On Wed, Jul 01, 2026 at 11:49:03AM -0700, Ian Rogers wrote:
> > On Wed, Jul 1, 2026 at 11:28 AM Namhyung Kim <namhyung@kernel.org> wrote:
> > >
> > > It seems RISCV was added in capstone version 5. Unfortunately they are
> > > enum constants so cannot check with #ifdef but anyway we can define the
> > > symbols. Let's do it using the version number to avoid build errors.
> > > It'll fail at runtime though.
> > >
> > > util/capstone.c: In function 'e_machine_to_capstone':
> > > util/capstone.c:186:25: error: 'CS_ARCH_RISCV' undeclared (first use in this function);
> > > did you mean 'CS_ARCH_SYSZ'?
> > > 186 | *arch = CS_ARCH_RISCV;
> > > | ^~~~~~~~~~~~~
> > > | CS_ARCH_SYSZ
> > > util/capstone.c:186:25: note: each undeclared identifier is reported only once for each function it appears in
> > >
> > > util/capstone.c:187:34: error: 'CS_MODE_RISCV64' undeclared (first use in this function);
> > > did you mean 'CS_MODE_MIPS64'?
> > > 187 | *mode |= (is64 ? CS_MODE_RISCV64 : CS_MODE_RISCV32) | CS_MODE_RISCVC;
> > > | ^~~~~~~~~~~~~~~
> > > | CS_MODE_MIPS64
> > >
> > > Also note that capstone renamed CS_MODE_RISCVC to CS_MODE_RISCV_C which
> > > would cause a different build failure on latest versions. It's reported
> > > in https://github.com/capstone-engine/capstone/issues/2977 so I think
> > > they will add compatibility layer to prevent the error.
> > >
> > > Fixes: 12c4737f55f2 ("perf capstone: Determine architecture from e_machine")
> > > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> >
> > Perhaps update the feature test from:
> > https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/build/feature/test-libcapstone.c?h=perf-tools-next
> > ```
> > cs_open(CS_ARCH_X86, CS_MODE_64, &handle);
> > ```
> > to be CS_ARCH_RISCV? That way we won't detect old libcapstones and
> > avoid cluttering up the code.
>
> Then it'll drop support for capstone version 4 which works fine on some
> architectures. Maybe we can add another feature check for capstone
> RISC-V support but I think it's better to define the RISCV symbols here.
>
> What do you think?
Arnaldo and I also discussed this in a thread, but I can't find it
right now. I believe the RISC-V support in libcapstone is now 8 years
old:
https://github.com/capstone-engine/capstone/issues/966
so it seemed unfortunate to add shims to support older libcapstone versions.
Thanks,
Ian
> Thanks,
> Namhyung
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-01 23:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01 18:28 [PATCH] perf build: Fix compiler errors with old capstone Namhyung Kim
2026-07-01 18:49 ` Ian Rogers
2026-07-01 19:30 ` Namhyung Kim
2026-07-01 23:39 ` Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox