* [PATCH 0/3] perf build: Fix cross-arch build failures and GCC 14 warnings
@ 2026-05-13 15:48 Li Guan
2026-05-13 15:48 ` [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects Li Guan
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Li Guan @ 2026-05-13 15:48 UTC (permalink / raw)
To: acme, namhyung
Cc: irogers, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel, Li Guan
This patch series addresses a set of build and linking failures encountered
when cross-compiling the perf tool for non-x86 architectures (specifically
RISC-V and ARM64), while also ensuring compatibility with stricter GCC 14
compiler checks.
The series resolves three distinct issues:
1. GCC 14 Compatibility: Fixes a -Werror=discarded-qualifiers build failure
in the RISC-V specific code by explicitly casting strrchr() return
values to (char *).
2. Hardware Tracing Isolation: Decouples arch-specific auxtrace objects
(e.g., intel-pt, arm-spe) from the generic build process, preventing
"No such file or directory" and undefined reference linker errors on
architectures that lack these features.
3. Instruction Decoding Stubs: Provides global __weak stubs for dump_insn()
and arch_is_uncond_branch() in builtin-script.c, resolving undefined
reference linker errors on architectures (like RISC-V and ARM64) that do
not yet implement hardware-specific instruction decoding.
These changes have been successfully verified via full builds across
x86_64, s390x, aarch64, and riscv64 architectures.
Li Guan (3):
perf build: Fix cross-arch build failures by isolating auxtrace
objects
perf riscv: Fix discarded const qualifier error in _get_field()
perf script: Provide weak stubs for instruction decoding
tools/perf/Makefile.config | 21 +++++++++
tools/perf/arch/riscv/util/header.c | 4 +-
tools/perf/builtin-script.c | 22 +++++++++
tools/perf/util/Build | 20 ++++-----
tools/perf/util/auxtrace.c | 70 +++++++++++++++++++++++++++++
tools/perf/util/auxtrace.h | 6 +++
6 files changed, 131 insertions(+), 12 deletions(-)
--
2.54.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects
2026-05-13 15:48 [PATCH 0/3] perf build: Fix cross-arch build failures and GCC 14 warnings Li Guan
@ 2026-05-13 15:48 ` Li Guan
2026-05-13 16:14 ` Ian Rogers
2026-05-13 15:48 ` [PATCH 2/3] perf riscv: Fix discarded const qualifier error in _get_field() Li Guan
2026-05-13 15:48 ` [PATCH 3/3] perf script: Provide weak stubs for instruction decoding Li Guan
2 siblings, 1 reply; 13+ messages in thread
From: Li Guan @ 2026-05-13 15:48 UTC (permalink / raw)
To: acme, namhyung
Cc: irogers, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel, Li Guan
Currently, tools/perf/util/Build hardcodes architecture-specific hardware
tracing objects (e.g., intel-pt.o, arm-spe.o, cs-etm-base.o) into the
generic perf-util-y list. When compiling on architectures that lack
these features (such as RISC-V), the compiler skips generating these
objects, causing the linker to fail with "No such file or directory"
or undefined references.
Fix this by decoupling the architecture-specific hardware tracing drivers
from the generic build process:
1. In Makefile.config, explicitly export CONFIG_PERF_XYZ feature flags
only for their corresponding target architectures.
2. In util/Build, conditionally link these hardware tracing objects
based on the newly exported feature flags.
3. In util/auxtrace.c, provide __weak stub functions returning -ENOSYS
for the arch-specific processing routines. This ensures successful
linking and graceful degradation when specific drivers are omitted.
Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
---
tools/perf/Makefile.config | 21 ++++++++++++
tools/perf/util/Build | 20 +++++------
tools/perf/util/auxtrace.c | 70 ++++++++++++++++++++++++++++++++++++++
tools/perf/util/auxtrace.h | 6 ++++
4 files changed, 107 insertions(+), 10 deletions(-)
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 06d7a3f999..13f4b98b2e 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -107,6 +107,27 @@ ifeq ($(SRCARCH),loongarch)
endif
endif
+ifndef NO_AUXTRACE
+ ifeq ($(SRCARCH),x86)
+ $(call detected,CONFIG_PERF_INTEL_PT)
+ $(call detected,CONFIG_PERF_AMD_PT)
+ endif
+
+ ifeq ($(SRCARCH),arm64)
+ $(call detected,CONFIG_PERF_ARM_SPE)
+ $(call detected,CONFIG_PERF_HISI_PTT)
+ $(call detected,CONFIG_PERF_CS_ETM)
+ endif
+
+ ifeq ($(SRCARCH),s390)
+ $(call detected,CONFIG_PERF_S390_CPUMSF)
+ endif
+endif
+
+ifeq ($(SRCARCH),arm64)
+ $(call detected,CONFIG_PERF_ARM64_UNWIND_SUPPORT)
+endif
+
ifeq ($(ARCH),s390)
CFLAGS += -fPIC
endif
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 70cc91d008..79ade6066d 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -132,21 +132,21 @@ perf-util-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
perf-util-y += kvm-stat-arch/
perf-util-y += lock-contention.o
perf-util-y += auxtrace.o
-perf-util-y += intel-pt-decoder/
-perf-util-y += intel-pt.o
-perf-util-y += intel-bts.o
-perf-util-y += arm-spe.o
-perf-util-y += arm-spe-decoder/
-perf-util-y += hisi-ptt.o
-perf-util-y += hisi-ptt-decoder/
-perf-util-y += s390-cpumsf.o
+perf-util-$(CONFIG_PERF_INTEL_PT) += intel-pt-decoder/
+perf-util-$(CONFIG_PERF_INTEL_PT) += intel-pt.o
+perf-util-$(CONFIG_PERF_INTEL_PT) += intel-bts.o
+perf-util-$(CONFIG_PERF_ARM_SPE) += arm-spe.o
+perf-util-$(CONFIG_PERF_ARM_SPE) += arm-spe-decoder/
+perf-util-$(CONFIG_PERF_HISI_PTT) += hisi-ptt.o
+perf-util-$(CONFIG_PERF_HISI_PTT) += hisi-ptt-decoder/
+perf-util-$(CONFIG_PERF_S390_CPUMSF) += s390-cpumsf.o
perf-util-y += powerpc-vpadtl.o
ifdef CONFIG_LIBOPENCSD
perf-util-y += cs-etm.o
perf-util-y += cs-etm-decoder/
endif
-perf-util-y += cs-etm-base.o
+perf-util-$(CONFIG_PERF_CS_ETM) += cs-etm-base.o
perf-util-y += parse-branch-options.o
perf-util-y += parse-regs-options.o
@@ -168,7 +168,7 @@ perf-util-y += clockid.o
perf-util-y += list_sort.o
perf-util-y += mutex.o
perf-util-y += sharded_mutex.o
-perf-util-y += intel-tpebs.o
+perf-util-$(CONFIG_PERF_INTEL_PT) += intel-tpebs.o
perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter.o
perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter_cgroup.o
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index a224687ffb..f6e426c3c5 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -51,6 +51,7 @@
#include "cs-etm.h"
#include "intel-pt.h"
#include "intel-bts.h"
+#include "intel-tpebs.h"
#include "arm-spe.h"
#include "hisi-ptt.h"
#include "s390-cpumsf.h"
@@ -2960,3 +2961,72 @@ bool auxtrace__evsel_is_auxtrace(struct perf_session *session,
return session->auxtrace->evsel_is_auxtrace(session, evsel);
}
+
+/*
+ * Stub functions for architecture-specific features to support cross-platform building.
+ * These weak symbols are overridden by strong symbols when the corresponding
+ * architecture-specific code is compiled in.
+ */
+#ifndef HAVE_ARCH_X86_64_SUPPORT
+int __weak intel_pt_process_auxtrace_info(union perf_event *event __maybe_unused,
+ struct perf_session *session __maybe_unused)
+{
+ return -EOPNOTSUPP;
+}
+
+int __weak intel_bts_process_auxtrace_info(union perf_event *event __maybe_unused,
+ struct perf_session *session __maybe_unused)
+{
+ return -EOPNOTSUPP;
+}
+
+int __weak evsel__tpebs_open(struct evsel *evsel __maybe_unused)
+{
+ return -EOPNOTSUPP;
+}
+
+void __weak evsel__tpebs_close(struct evsel *evsel __maybe_unused)
+{
+}
+
+int __weak evsel__tpebs_read(struct evsel *evsel __maybe_unused,
+ int cpu_map_idx __maybe_unused,
+ int thread __maybe_unused)
+{
+ return -EOPNOTSUPP;
+}
+
+int __weak insn_decode(void *insn __maybe_unused, const void *kaddr __maybe_unused,
+ int len __maybe_unused, int mode __maybe_unused)
+{
+ return -EOPNOTSUPP;
+}
+#endif
+
+#ifndef HAVE_ARCH_ARM64_SUPPORT
+int __weak arm_spe_process_auxtrace_info(union perf_event *event __maybe_unused,
+ struct perf_session *session __maybe_unused)
+{
+ return -EOPNOTSUPP;
+}
+
+int __weak hisi_ptt_process_auxtrace_info(union perf_event *event __maybe_unused,
+ struct perf_session *session __maybe_unused)
+{
+ return -EOPNOTSUPP;
+}
+
+int __weak cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused,
+ struct perf_session *session __maybe_unused)
+{
+ return -EOPNOTSUPP;
+}
+#endif
+
+#ifndef HAVE_ARCH_S390_SUPPORT
+int __weak s390_cpumsf_process_auxtrace_info(union perf_event *event __maybe_unused,
+ struct perf_session *session __maybe_unused)
+{
+ return -EOPNOTSUPP;
+}
+#endif
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 6947f3f284..474e9445b4 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -699,4 +699,10 @@ void itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts)
opts->range_num = 0;
}
+/*
+ * Prototypes for architecture-specific functions that require weak stubs
+ * to support cross-platform builds on non-x86 architectures.
+ */
+int insn_decode(void *insn, const void *kaddr, int len, int mode);
+
#endif
--
2.54.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/3] perf riscv: Fix discarded const qualifier error in _get_field()
2026-05-13 15:48 [PATCH 0/3] perf build: Fix cross-arch build failures and GCC 14 warnings Li Guan
2026-05-13 15:48 ` [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects Li Guan
@ 2026-05-13 15:48 ` Li Guan
2026-05-13 16:18 ` Ian Rogers
2026-05-13 18:07 ` [PATCH v2] perf riscv: Fix discarded const qualifier " Li Guan
2026-05-13 15:48 ` [PATCH 3/3] perf script: Provide weak stubs for instruction decoding Li Guan
2 siblings, 2 replies; 13+ messages in thread
From: Li Guan @ 2026-05-13 15:48 UTC (permalink / raw)
To: acme, namhyung
Cc: irogers, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel, Li Guan
When building perf for the RISC-V architecture (e.g., with GCC 14), the
build fails due to strict type checking on pointer assignments. The
compiler flags the return value of strrchr() being assigned to a
non-const pointer while processing a const string, triggering
-Werror=discarded-qualifiers:
arch/riscv/util/header.c:24:15: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
24 | line2 = strrchr(line, ' ');
| ^
arch/riscv/util/header.c:29:12: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
29 | nl = strrchr(line, '\n');
| ^
Resolve this by adding an explicit (char *) cast to the strrchr()
return values, which satisfies the compiler's qualifier checks
without altering the runtime behavior.
Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
---
| 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
index 4b839203d4..d01ba64aec 100644
--- a/tools/perf/arch/riscv/util/header.c
+++ b/tools/perf/arch/riscv/util/header.c
@@ -21,12 +21,12 @@ static char *_get_field(const char *line)
{
char *line2, *nl;
- line2 = strrchr(line, ' ');
+ line2 = (char *)strrchr(line, ' ');
if (!line2)
return NULL;
line2++;
- nl = strrchr(line, '\n');
+ nl = (char *)strrchr(line, '\n');
if (!nl)
return NULL;
--
2.54.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/3] perf script: Provide weak stubs for instruction decoding
2026-05-13 15:48 [PATCH 0/3] perf build: Fix cross-arch build failures and GCC 14 warnings Li Guan
2026-05-13 15:48 ` [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects Li Guan
2026-05-13 15:48 ` [PATCH 2/3] perf riscv: Fix discarded const qualifier error in _get_field() Li Guan
@ 2026-05-13 15:48 ` Li Guan
2026-05-13 16:20 ` Ian Rogers
2 siblings, 1 reply; 13+ messages in thread
From: Li Guan @ 2026-05-13 15:48 UTC (permalink / raw)
To: acme, namhyung
Cc: irogers, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel, Li Guan
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.
Signed-off-by: Li Guan <guanli.oerv@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
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects
2026-05-13 15:48 ` [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects Li Guan
@ 2026-05-13 16:14 ` Ian Rogers
2026-05-13 16:31 ` guanli
0 siblings, 1 reply; 13+ messages in thread
From: Ian Rogers @ 2026-05-13 16:14 UTC (permalink / raw)
To: Li Guan
Cc: acme, namhyung, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel
On Wed, May 13, 2026 at 8:50 AM Li Guan <guanli.oerv@isrc.iscas.ac.cn> wrote:
>
> Currently, tools/perf/util/Build hardcodes architecture-specific hardware
> tracing objects (e.g., intel-pt.o, arm-spe.o, cs-etm-base.o) into the
> generic perf-util-y list. When compiling on architectures that lack
> these features (such as RISC-V), the compiler skips generating these
> objects, causing the linker to fail with "No such file or directory"
> or undefined references.
So it is intentional to build these into the perf binary so that you
may generate a perf.data file on an x86 or ARM machine and then
analyze it on an RISC-V machine. I'm not sure how you've managed to
break the build, you didn't provide a message, but the build expects
these decoders for cross-platform support.
> Fix this by decoupling the architecture-specific hardware tracing drivers
> from the generic build process:
> 1. In Makefile.config, explicitly export CONFIG_PERF_XYZ feature flags
> only for their corresponding target architectures.
> 2. In util/Build, conditionally link these hardware tracing objects
> based on the newly exported feature flags.
> 3. In util/auxtrace.c, provide __weak stub functions returning -ENOSYS
> for the arch-specific processing routines. This ensures successful
> linking and graceful degradation when specific drivers are omitted.
This is a complete misunderstanding of the code, please don't
implement this. If anything, more code should move out of the
tools/perf/arch directory and into tools/perf/util guarded by
perf_env's arch or e_machine values for cross platform support.
Thanks,
Ian
> Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
> ---
> tools/perf/Makefile.config | 21 ++++++++++++
> tools/perf/util/Build | 20 +++++------
> tools/perf/util/auxtrace.c | 70 ++++++++++++++++++++++++++++++++++++++
> tools/perf/util/auxtrace.h | 6 ++++
> 4 files changed, 107 insertions(+), 10 deletions(-)
>
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 06d7a3f999..13f4b98b2e 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -107,6 +107,27 @@ ifeq ($(SRCARCH),loongarch)
> endif
> endif
>
> +ifndef NO_AUXTRACE
> + ifeq ($(SRCARCH),x86)
> + $(call detected,CONFIG_PERF_INTEL_PT)
> + $(call detected,CONFIG_PERF_AMD_PT)
> + endif
> +
> + ifeq ($(SRCARCH),arm64)
> + $(call detected,CONFIG_PERF_ARM_SPE)
> + $(call detected,CONFIG_PERF_HISI_PTT)
> + $(call detected,CONFIG_PERF_CS_ETM)
> + endif
> +
> + ifeq ($(SRCARCH),s390)
> + $(call detected,CONFIG_PERF_S390_CPUMSF)
> + endif
> +endif
> +
> +ifeq ($(SRCARCH),arm64)
> + $(call detected,CONFIG_PERF_ARM64_UNWIND_SUPPORT)
> +endif
> +
> ifeq ($(ARCH),s390)
> CFLAGS += -fPIC
> endif
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index 70cc91d008..79ade6066d 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -132,21 +132,21 @@ perf-util-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
> perf-util-y += kvm-stat-arch/
> perf-util-y += lock-contention.o
> perf-util-y += auxtrace.o
> -perf-util-y += intel-pt-decoder/
> -perf-util-y += intel-pt.o
> -perf-util-y += intel-bts.o
> -perf-util-y += arm-spe.o
> -perf-util-y += arm-spe-decoder/
> -perf-util-y += hisi-ptt.o
> -perf-util-y += hisi-ptt-decoder/
> -perf-util-y += s390-cpumsf.o
> +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-pt-decoder/
> +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-pt.o
> +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-bts.o
> +perf-util-$(CONFIG_PERF_ARM_SPE) += arm-spe.o
> +perf-util-$(CONFIG_PERF_ARM_SPE) += arm-spe-decoder/
> +perf-util-$(CONFIG_PERF_HISI_PTT) += hisi-ptt.o
> +perf-util-$(CONFIG_PERF_HISI_PTT) += hisi-ptt-decoder/
> +perf-util-$(CONFIG_PERF_S390_CPUMSF) += s390-cpumsf.o
> perf-util-y += powerpc-vpadtl.o
>
> ifdef CONFIG_LIBOPENCSD
> perf-util-y += cs-etm.o
> perf-util-y += cs-etm-decoder/
> endif
> -perf-util-y += cs-etm-base.o
> +perf-util-$(CONFIG_PERF_CS_ETM) += cs-etm-base.o
>
> perf-util-y += parse-branch-options.o
> perf-util-y += parse-regs-options.o
> @@ -168,7 +168,7 @@ perf-util-y += clockid.o
> perf-util-y += list_sort.o
> perf-util-y += mutex.o
> perf-util-y += sharded_mutex.o
> -perf-util-y += intel-tpebs.o
> +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-tpebs.o
>
> perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter.o
> perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter_cgroup.o
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index a224687ffb..f6e426c3c5 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -51,6 +51,7 @@
> #include "cs-etm.h"
> #include "intel-pt.h"
> #include "intel-bts.h"
> +#include "intel-tpebs.h"
> #include "arm-spe.h"
> #include "hisi-ptt.h"
> #include "s390-cpumsf.h"
> @@ -2960,3 +2961,72 @@ bool auxtrace__evsel_is_auxtrace(struct perf_session *session,
>
> return session->auxtrace->evsel_is_auxtrace(session, evsel);
> }
> +
> +/*
> + * Stub functions for architecture-specific features to support cross-platform building.
> + * These weak symbols are overridden by strong symbols when the corresponding
> + * architecture-specific code is compiled in.
> + */
> +#ifndef HAVE_ARCH_X86_64_SUPPORT
> +int __weak intel_pt_process_auxtrace_info(union perf_event *event __maybe_unused,
> + struct perf_session *session __maybe_unused)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> +int __weak intel_bts_process_auxtrace_info(union perf_event *event __maybe_unused,
> + struct perf_session *session __maybe_unused)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> +int __weak evsel__tpebs_open(struct evsel *evsel __maybe_unused)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> +void __weak evsel__tpebs_close(struct evsel *evsel __maybe_unused)
> +{
> +}
> +
> +int __weak evsel__tpebs_read(struct evsel *evsel __maybe_unused,
> + int cpu_map_idx __maybe_unused,
> + int thread __maybe_unused)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> +int __weak insn_decode(void *insn __maybe_unused, const void *kaddr __maybe_unused,
> + int len __maybe_unused, int mode __maybe_unused)
> +{
> + return -EOPNOTSUPP;
> +}
> +#endif
> +
> +#ifndef HAVE_ARCH_ARM64_SUPPORT
> +int __weak arm_spe_process_auxtrace_info(union perf_event *event __maybe_unused,
> + struct perf_session *session __maybe_unused)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> +int __weak hisi_ptt_process_auxtrace_info(union perf_event *event __maybe_unused,
> + struct perf_session *session __maybe_unused)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> +int __weak cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused,
> + struct perf_session *session __maybe_unused)
> +{
> + return -EOPNOTSUPP;
> +}
> +#endif
> +
> +#ifndef HAVE_ARCH_S390_SUPPORT
> +int __weak s390_cpumsf_process_auxtrace_info(union perf_event *event __maybe_unused,
> + struct perf_session *session __maybe_unused)
> +{
> + return -EOPNOTSUPP;
> +}
> +#endif
> diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
> index 6947f3f284..474e9445b4 100644
> --- a/tools/perf/util/auxtrace.h
> +++ b/tools/perf/util/auxtrace.h
> @@ -699,4 +699,10 @@ void itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts)
> opts->range_num = 0;
> }
>
> +/*
> + * Prototypes for architecture-specific functions that require weak stubs
> + * to support cross-platform builds on non-x86 architectures.
> + */
> +int insn_decode(void *insn, const void *kaddr, int len, int mode);
> +
> #endif
> --
> 2.54.0
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/3] perf riscv: Fix discarded const qualifier error in _get_field()
2026-05-13 15:48 ` [PATCH 2/3] perf riscv: Fix discarded const qualifier error in _get_field() Li Guan
@ 2026-05-13 16:18 ` Ian Rogers
2026-05-13 18:07 ` [PATCH v2] perf riscv: Fix discarded const qualifier " Li Guan
1 sibling, 0 replies; 13+ messages in thread
From: Ian Rogers @ 2026-05-13 16:18 UTC (permalink / raw)
To: Li Guan
Cc: acme, namhyung, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel
On Wed, May 13, 2026 at 8:50 AM Li Guan <guanli.oerv@isrc.iscas.ac.cn> wrote:
>
> When building perf for the RISC-V architecture (e.g., with GCC 14), the
> build fails due to strict type checking on pointer assignments. The
> compiler flags the return value of strrchr() being assigned to a
> non-const pointer while processing a const string, triggering
> -Werror=discarded-qualifiers:
>
> arch/riscv/util/header.c:24:15: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
> 24 | line2 = strrchr(line, ' ');
> | ^
> arch/riscv/util/header.c:29:12: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
> 29 | nl = strrchr(line, '\n');
> | ^
>
> Resolve this by adding an explicit (char *) cast to the strrchr()
> return values, which satisfies the compiler's qualifier checks
> without altering the runtime behavior.
Why not add the const? There have been a few rounds of this clean up, like:
https://lore.kernel.org/linux-perf-users/20251211221756.96294-3-acme@kernel.org/
Did you check it wasn't already fixed in perf-tools-next?
Thanks,
Ian
> Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
> ---
> tools/perf/arch/riscv/util/header.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
> index 4b839203d4..d01ba64aec 100644
> --- a/tools/perf/arch/riscv/util/header.c
> +++ b/tools/perf/arch/riscv/util/header.c
> @@ -21,12 +21,12 @@ static char *_get_field(const char *line)
> {
> char *line2, *nl;
>
> - line2 = strrchr(line, ' ');
> + line2 = (char *)strrchr(line, ' ');
> if (!line2)
> return NULL;
>
> line2++;
> - nl = strrchr(line, '\n');
> + nl = (char *)strrchr(line, '\n');
> if (!nl)
> return NULL;
>
> --
> 2.54.0
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/3] perf script: Provide weak stubs for instruction decoding
2026-05-13 15:48 ` [PATCH 3/3] perf script: Provide weak stubs for instruction decoding Li Guan
@ 2026-05-13 16:20 ` Ian Rogers
0 siblings, 0 replies; 13+ messages in thread
From: Ian Rogers @ 2026-05-13 16:20 UTC (permalink / raw)
To: Li Guan
Cc: acme, namhyung, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel
On Wed, May 13, 2026 at 8:50 AM Li Guan <guanli.oerv@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@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
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Re: [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects
2026-05-13 16:14 ` Ian Rogers
@ 2026-05-13 16:31 ` guanli
2026-05-13 16:37 ` Ian Rogers
0 siblings, 1 reply; 13+ messages in thread
From: guanli @ 2026-05-13 16:31 UTC (permalink / raw)
To: Ian Rogers
Cc: acme, namhyung, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel
Hi Ian,
Thanks a lot for the quick and detailed review!
Regarding Patch 1/3 and 3/3 (the auxtrace decoupling):
I completely misunderstood the design goal of perf for cross-platform trace analysis. My apologies for that. I encountered build errors on RISC-V with GCC 14 when it tried to compile files like intel-pt.c, and I incorrectly assumed they shouldn't be built for RISC-V at all.
I will drop this approach entirely. I'll go back to the original build logs to find the exact GCC 14 compilation errors in those decoders on RISC-V, and I will try to fix those specific issues instead. I'll make sure to include the exact compiler error messages in the next patch.
Regarding Patch 2/3 (the const qualifier):
You are right, casting it to (char *) is not the proper way to handle it. I will check the perf-tools-next branch as you suggested. If it hasn't been fixed there, I will submit a v2 that properly preserves the const semantics.
Thanks again for pointing me in the right direction!
Best regards,
Li Guan
> -----原始邮件-----
> 发件人: "Ian Rogers" <irogers@google.com>
> 发送时间: 2026-05-14 00:14:59 (星期四)
> 收件人: "Li Guan" <guanli.oerv@isrc.iscas.ac.cn>
> 抄送: acme@kernel.org, namhyung@kernel.org, adrian.hunter@intel.com, palmer@dabbelt.com, pjw@kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
> 主题: Re: [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects
>
> On Wed, May 13, 2026 at 8:50 AM Li Guan <guanli.oerv@isrc.iscas.ac.cn> wrote:
> >
> > Currently, tools/perf/util/Build hardcodes architecture-specific hardware
> > tracing objects (e.g., intel-pt.o, arm-spe.o, cs-etm-base.o) into the
> > generic perf-util-y list. When compiling on architectures that lack
> > these features (such as RISC-V), the compiler skips generating these
> > objects, causing the linker to fail with "No such file or directory"
> > or undefined references.
>
> So it is intentional to build these into the perf binary so that you
> may generate a perf.data file on an x86 or ARM machine and then
> analyze it on an RISC-V machine. I'm not sure how you've managed to
> break the build, you didn't provide a message, but the build expects
> these decoders for cross-platform support.
>
> > Fix this by decoupling the architecture-specific hardware tracing drivers
> > from the generic build process:
> > 1. In Makefile.config, explicitly export CONFIG_PERF_XYZ feature flags
> > only for their corresponding target architectures.
> > 2. In util/Build, conditionally link these hardware tracing objects
> > based on the newly exported feature flags.
> > 3. In util/auxtrace.c, provide __weak stub functions returning -ENOSYS
> > for the arch-specific processing routines. This ensures successful
> > linking and graceful degradation when specific drivers are omitted.
>
> This is a complete misunderstanding of the code, please don't
> implement this. If anything, more code should move out of the
> tools/perf/arch directory and into tools/perf/util guarded by
> perf_env's arch or e_machine values for cross platform support.
>
> Thanks,
> Ian
>
> > Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
> > ---
> > tools/perf/Makefile.config | 21 ++++++++++++
> > tools/perf/util/Build | 20 +++++------
> > tools/perf/util/auxtrace.c | 70 ++++++++++++++++++++++++++++++++++++++
> > tools/perf/util/auxtrace.h | 6 ++++
> > 4 files changed, 107 insertions(+), 10 deletions(-)
> >
> > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> > index 06d7a3f999..13f4b98b2e 100644
> > --- a/tools/perf/Makefile.config
> > +++ b/tools/perf/Makefile.config
> > @@ -107,6 +107,27 @@ ifeq ($(SRCARCH),loongarch)
> > endif
> > endif
> >
> > +ifndef NO_AUXTRACE
> > + ifeq ($(SRCARCH),x86)
> > + $(call detected,CONFIG_PERF_INTEL_PT)
> > + $(call detected,CONFIG_PERF_AMD_PT)
> > + endif
> > +
> > + ifeq ($(SRCARCH),arm64)
> > + $(call detected,CONFIG_PERF_ARM_SPE)
> > + $(call detected,CONFIG_PERF_HISI_PTT)
> > + $(call detected,CONFIG_PERF_CS_ETM)
> > + endif
> > +
> > + ifeq ($(SRCARCH),s390)
> > + $(call detected,CONFIG_PERF_S390_CPUMSF)
> > + endif
> > +endif
> > +
> > +ifeq ($(SRCARCH),arm64)
> > + $(call detected,CONFIG_PERF_ARM64_UNWIND_SUPPORT)
> > +endif
> > +
> > ifeq ($(ARCH),s390)
> > CFLAGS += -fPIC
> > endif
> > diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> > index 70cc91d008..79ade6066d 100644
> > --- a/tools/perf/util/Build
> > +++ b/tools/perf/util/Build
> > @@ -132,21 +132,21 @@ perf-util-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
> > perf-util-y += kvm-stat-arch/
> > perf-util-y += lock-contention.o
> > perf-util-y += auxtrace.o
> > -perf-util-y += intel-pt-decoder/
> > -perf-util-y += intel-pt.o
> > -perf-util-y += intel-bts.o
> > -perf-util-y += arm-spe.o
> > -perf-util-y += arm-spe-decoder/
> > -perf-util-y += hisi-ptt.o
> > -perf-util-y += hisi-ptt-decoder/
> > -perf-util-y += s390-cpumsf.o
> > +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-pt-decoder/
> > +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-pt.o
> > +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-bts.o
> > +perf-util-$(CONFIG_PERF_ARM_SPE) += arm-spe.o
> > +perf-util-$(CONFIG_PERF_ARM_SPE) += arm-spe-decoder/
> > +perf-util-$(CONFIG_PERF_HISI_PTT) += hisi-ptt.o
> > +perf-util-$(CONFIG_PERF_HISI_PTT) += hisi-ptt-decoder/
> > +perf-util-$(CONFIG_PERF_S390_CPUMSF) += s390-cpumsf.o
> > perf-util-y += powerpc-vpadtl.o
> >
> > ifdef CONFIG_LIBOPENCSD
> > perf-util-y += cs-etm.o
> > perf-util-y += cs-etm-decoder/
> > endif
> > -perf-util-y += cs-etm-base.o
> > +perf-util-$(CONFIG_PERF_CS_ETM) += cs-etm-base.o
> >
> > perf-util-y += parse-branch-options.o
> > perf-util-y += parse-regs-options.o
> > @@ -168,7 +168,7 @@ perf-util-y += clockid.o
> > perf-util-y += list_sort.o
> > perf-util-y += mutex.o
> > perf-util-y += sharded_mutex.o
> > -perf-util-y += intel-tpebs.o
> > +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-tpebs.o
> >
> > perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter.o
> > perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter_cgroup.o
> > diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> > index a224687ffb..f6e426c3c5 100644
> > --- a/tools/perf/util/auxtrace.c
> > +++ b/tools/perf/util/auxtrace.c
> > @@ -51,6 +51,7 @@
> > #include "cs-etm.h"
> > #include "intel-pt.h"
> > #include "intel-bts.h"
> > +#include "intel-tpebs.h"
> > #include "arm-spe.h"
> > #include "hisi-ptt.h"
> > #include "s390-cpumsf.h"
> > @@ -2960,3 +2961,72 @@ bool auxtrace__evsel_is_auxtrace(struct perf_session *session,
> >
> > return session->auxtrace->evsel_is_auxtrace(session, evsel);
> > }
> > +
> > +/*
> > + * Stub functions for architecture-specific features to support cross-platform building.
> > + * These weak symbols are overridden by strong symbols when the corresponding
> > + * architecture-specific code is compiled in.
> > + */
> > +#ifndef HAVE_ARCH_X86_64_SUPPORT
> > +int __weak intel_pt_process_auxtrace_info(union perf_event *event __maybe_unused,
> > + struct perf_session *session __maybe_unused)
> > +{
> > + return -EOPNOTSUPP;
> > +}
> > +
> > +int __weak intel_bts_process_auxtrace_info(union perf_event *event __maybe_unused,
> > + struct perf_session *session __maybe_unused)
> > +{
> > + return -EOPNOTSUPP;
> > +}
> > +
> > +int __weak evsel__tpebs_open(struct evsel *evsel __maybe_unused)
> > +{
> > + return -EOPNOTSUPP;
> > +}
> > +
> > +void __weak evsel__tpebs_close(struct evsel *evsel __maybe_unused)
> > +{
> > +}
> > +
> > +int __weak evsel__tpebs_read(struct evsel *evsel __maybe_unused,
> > + int cpu_map_idx __maybe_unused,
> > + int thread __maybe_unused)
> > +{
> > + return -EOPNOTSUPP;
> > +}
> > +
> > +int __weak insn_decode(void *insn __maybe_unused, const void *kaddr __maybe_unused,
> > + int len __maybe_unused, int mode __maybe_unused)
> > +{
> > + return -EOPNOTSUPP;
> > +}
> > +#endif
> > +
> > +#ifndef HAVE_ARCH_ARM64_SUPPORT
> > +int __weak arm_spe_process_auxtrace_info(union perf_event *event __maybe_unused,
> > + struct perf_session *session __maybe_unused)
> > +{
> > + return -EOPNOTSUPP;
> > +}
> > +
> > +int __weak hisi_ptt_process_auxtrace_info(union perf_event *event __maybe_unused,
> > + struct perf_session *session __maybe_unused)
> > +{
> > + return -EOPNOTSUPP;
> > +}
> > +
> > +int __weak cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused,
> > + struct perf_session *session __maybe_unused)
> > +{
> > + return -EOPNOTSUPP;
> > +}
> > +#endif
> > +
> > +#ifndef HAVE_ARCH_S390_SUPPORT
> > +int __weak s390_cpumsf_process_auxtrace_info(union perf_event *event __maybe_unused,
> > + struct perf_session *session __maybe_unused)
> > +{
> > + return -EOPNOTSUPP;
> > +}
> > +#endif
> > diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
> > index 6947f3f284..474e9445b4 100644
> > --- a/tools/perf/util/auxtrace.h
> > +++ b/tools/perf/util/auxtrace.h
> > @@ -699,4 +699,10 @@ void itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts)
> > opts->range_num = 0;
> > }
> >
> > +/*
> > + * Prototypes for architecture-specific functions that require weak stubs
> > + * to support cross-platform builds on non-x86 architectures.
> > + */
> > +int insn_decode(void *insn, const void *kaddr, int len, int mode);
> > +
> > #endif
> > --
> > 2.54.0
> >
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Re: [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects
2026-05-13 16:31 ` guanli
@ 2026-05-13 16:37 ` Ian Rogers
0 siblings, 0 replies; 13+ messages in thread
From: Ian Rogers @ 2026-05-13 16:37 UTC (permalink / raw)
To: guanli
Cc: acme, namhyung, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel
On Wed, May 13, 2026 at 9:32 AM guanli <guanli.oerv@isrc.iscas.ac.cn> wrote:
>
> Hi Ian,
>
> Thanks a lot for the quick and detailed review!
>
> Regarding Patch 1/3 and 3/3 (the auxtrace decoupling):
> I completely misunderstood the design goal of perf for cross-platform trace analysis. My apologies for that. I encountered build errors on RISC-V with GCC 14 when it tried to compile files like intel-pt.c, and I incorrectly assumed they shouldn't be built for RISC-V at all.
> I will drop this approach entirely. I'll go back to the original build logs to find the exact GCC 14 compilation errors in those decoders on RISC-V, and I will try to fix those specific issues instead. I'll make sure to include the exact compiler error messages in the next patch.
>
> Regarding Patch 2/3 (the const qualifier):
> You are right, casting it to (char *) is not the proper way to handle it. I will check the perf-tools-next branch as you suggested. If it hasn't been fixed there, I will submit a v2 that properly preserves the const semantics.
>
> Thanks again for pointing me in the right direction!
No worries, thanks for sending fixes and glad to clean up the intent
in the tool. I'm actually trying to push more with this cross-platform
direction, and increase RISC-V support in this series that I'm
currently rebasing:
https://lore.kernel.org/linux-perf-users/20260413024805.1316480-1-irogers@google.com/
I'll be cheeky and add you to the cc list as maybe you can help with
building/testing :-)
Thanks,
Ian
> Best regards,
> Li Guan
>
>
> > -----原始邮件-----
> > 发件人: "Ian Rogers" <irogers@google.com>
> > 发送时间: 2026-05-14 00:14:59 (星期四)
> > 收件人: "Li Guan" <guanli.oerv@isrc.iscas.ac.cn>
> > 抄送: acme@kernel.org, namhyung@kernel.org, adrian.hunter@intel.com, palmer@dabbelt.com, pjw@kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
> > 主题: Re: [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects
> >
> > On Wed, May 13, 2026 at 8:50 AM Li Guan <guanli.oerv@isrc.iscas.ac.cn> wrote:
> > >
> > > Currently, tools/perf/util/Build hardcodes architecture-specific hardware
> > > tracing objects (e.g., intel-pt.o, arm-spe.o, cs-etm-base.o) into the
> > > generic perf-util-y list. When compiling on architectures that lack
> > > these features (such as RISC-V), the compiler skips generating these
> > > objects, causing the linker to fail with "No such file or directory"
> > > or undefined references.
> >
> > So it is intentional to build these into the perf binary so that you
> > may generate a perf.data file on an x86 or ARM machine and then
> > analyze it on an RISC-V machine. I'm not sure how you've managed to
> > break the build, you didn't provide a message, but the build expects
> > these decoders for cross-platform support.
> >
> > > Fix this by decoupling the architecture-specific hardware tracing drivers
> > > from the generic build process:
> > > 1. In Makefile.config, explicitly export CONFIG_PERF_XYZ feature flags
> > > only for their corresponding target architectures.
> > > 2. In util/Build, conditionally link these hardware tracing objects
> > > based on the newly exported feature flags.
> > > 3. In util/auxtrace.c, provide __weak stub functions returning -ENOSYS
> > > for the arch-specific processing routines. This ensures successful
> > > linking and graceful degradation when specific drivers are omitted.
> >
> > This is a complete misunderstanding of the code, please don't
> > implement this. If anything, more code should move out of the
> > tools/perf/arch directory and into tools/perf/util guarded by
> > perf_env's arch or e_machine values for cross platform support.
> >
> > Thanks,
> > Ian
> >
> > > Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
> > > ---
> > > tools/perf/Makefile.config | 21 ++++++++++++
> > > tools/perf/util/Build | 20 +++++------
> > > tools/perf/util/auxtrace.c | 70 ++++++++++++++++++++++++++++++++++++++
> > > tools/perf/util/auxtrace.h | 6 ++++
> > > 4 files changed, 107 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> > > index 06d7a3f999..13f4b98b2e 100644
> > > --- a/tools/perf/Makefile.config
> > > +++ b/tools/perf/Makefile.config
> > > @@ -107,6 +107,27 @@ ifeq ($(SRCARCH),loongarch)
> > > endif
> > > endif
> > >
> > > +ifndef NO_AUXTRACE
> > > + ifeq ($(SRCARCH),x86)
> > > + $(call detected,CONFIG_PERF_INTEL_PT)
> > > + $(call detected,CONFIG_PERF_AMD_PT)
> > > + endif
> > > +
> > > + ifeq ($(SRCARCH),arm64)
> > > + $(call detected,CONFIG_PERF_ARM_SPE)
> > > + $(call detected,CONFIG_PERF_HISI_PTT)
> > > + $(call detected,CONFIG_PERF_CS_ETM)
> > > + endif
> > > +
> > > + ifeq ($(SRCARCH),s390)
> > > + $(call detected,CONFIG_PERF_S390_CPUMSF)
> > > + endif
> > > +endif
> > > +
> > > +ifeq ($(SRCARCH),arm64)
> > > + $(call detected,CONFIG_PERF_ARM64_UNWIND_SUPPORT)
> > > +endif
> > > +
> > > ifeq ($(ARCH),s390)
> > > CFLAGS += -fPIC
> > > endif
> > > diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> > > index 70cc91d008..79ade6066d 100644
> > > --- a/tools/perf/util/Build
> > > +++ b/tools/perf/util/Build
> > > @@ -132,21 +132,21 @@ perf-util-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
> > > perf-util-y += kvm-stat-arch/
> > > perf-util-y += lock-contention.o
> > > perf-util-y += auxtrace.o
> > > -perf-util-y += intel-pt-decoder/
> > > -perf-util-y += intel-pt.o
> > > -perf-util-y += intel-bts.o
> > > -perf-util-y += arm-spe.o
> > > -perf-util-y += arm-spe-decoder/
> > > -perf-util-y += hisi-ptt.o
> > > -perf-util-y += hisi-ptt-decoder/
> > > -perf-util-y += s390-cpumsf.o
> > > +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-pt-decoder/
> > > +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-pt.o
> > > +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-bts.o
> > > +perf-util-$(CONFIG_PERF_ARM_SPE) += arm-spe.o
> > > +perf-util-$(CONFIG_PERF_ARM_SPE) += arm-spe-decoder/
> > > +perf-util-$(CONFIG_PERF_HISI_PTT) += hisi-ptt.o
> > > +perf-util-$(CONFIG_PERF_HISI_PTT) += hisi-ptt-decoder/
> > > +perf-util-$(CONFIG_PERF_S390_CPUMSF) += s390-cpumsf.o
> > > perf-util-y += powerpc-vpadtl.o
> > >
> > > ifdef CONFIG_LIBOPENCSD
> > > perf-util-y += cs-etm.o
> > > perf-util-y += cs-etm-decoder/
> > > endif
> > > -perf-util-y += cs-etm-base.o
> > > +perf-util-$(CONFIG_PERF_CS_ETM) += cs-etm-base.o
> > >
> > > perf-util-y += parse-branch-options.o
> > > perf-util-y += parse-regs-options.o
> > > @@ -168,7 +168,7 @@ perf-util-y += clockid.o
> > > perf-util-y += list_sort.o
> > > perf-util-y += mutex.o
> > > perf-util-y += sharded_mutex.o
> > > -perf-util-y += intel-tpebs.o
> > > +perf-util-$(CONFIG_PERF_INTEL_PT) += intel-tpebs.o
> > >
> > > perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter.o
> > > perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter_cgroup.o
> > > diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> > > index a224687ffb..f6e426c3c5 100644
> > > --- a/tools/perf/util/auxtrace.c
> > > +++ b/tools/perf/util/auxtrace.c
> > > @@ -51,6 +51,7 @@
> > > #include "cs-etm.h"
> > > #include "intel-pt.h"
> > > #include "intel-bts.h"
> > > +#include "intel-tpebs.h"
> > > #include "arm-spe.h"
> > > #include "hisi-ptt.h"
> > > #include "s390-cpumsf.h"
> > > @@ -2960,3 +2961,72 @@ bool auxtrace__evsel_is_auxtrace(struct perf_session *session,
> > >
> > > return session->auxtrace->evsel_is_auxtrace(session, evsel);
> > > }
> > > +
> > > +/*
> > > + * Stub functions for architecture-specific features to support cross-platform building.
> > > + * These weak symbols are overridden by strong symbols when the corresponding
> > > + * architecture-specific code is compiled in.
> > > + */
> > > +#ifndef HAVE_ARCH_X86_64_SUPPORT
> > > +int __weak intel_pt_process_auxtrace_info(union perf_event *event __maybe_unused,
> > > + struct perf_session *session __maybe_unused)
> > > +{
> > > + return -EOPNOTSUPP;
> > > +}
> > > +
> > > +int __weak intel_bts_process_auxtrace_info(union perf_event *event __maybe_unused,
> > > + struct perf_session *session __maybe_unused)
> > > +{
> > > + return -EOPNOTSUPP;
> > > +}
> > > +
> > > +int __weak evsel__tpebs_open(struct evsel *evsel __maybe_unused)
> > > +{
> > > + return -EOPNOTSUPP;
> > > +}
> > > +
> > > +void __weak evsel__tpebs_close(struct evsel *evsel __maybe_unused)
> > > +{
> > > +}
> > > +
> > > +int __weak evsel__tpebs_read(struct evsel *evsel __maybe_unused,
> > > + int cpu_map_idx __maybe_unused,
> > > + int thread __maybe_unused)
> > > +{
> > > + return -EOPNOTSUPP;
> > > +}
> > > +
> > > +int __weak insn_decode(void *insn __maybe_unused, const void *kaddr __maybe_unused,
> > > + int len __maybe_unused, int mode __maybe_unused)
> > > +{
> > > + return -EOPNOTSUPP;
> > > +}
> > > +#endif
> > > +
> > > +#ifndef HAVE_ARCH_ARM64_SUPPORT
> > > +int __weak arm_spe_process_auxtrace_info(union perf_event *event __maybe_unused,
> > > + struct perf_session *session __maybe_unused)
> > > +{
> > > + return -EOPNOTSUPP;
> > > +}
> > > +
> > > +int __weak hisi_ptt_process_auxtrace_info(union perf_event *event __maybe_unused,
> > > + struct perf_session *session __maybe_unused)
> > > +{
> > > + return -EOPNOTSUPP;
> > > +}
> > > +
> > > +int __weak cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused,
> > > + struct perf_session *session __maybe_unused)
> > > +{
> > > + return -EOPNOTSUPP;
> > > +}
> > > +#endif
> > > +
> > > +#ifndef HAVE_ARCH_S390_SUPPORT
> > > +int __weak s390_cpumsf_process_auxtrace_info(union perf_event *event __maybe_unused,
> > > + struct perf_session *session __maybe_unused)
> > > +{
> > > + return -EOPNOTSUPP;
> > > +}
> > > +#endif
> > > diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
> > > index 6947f3f284..474e9445b4 100644
> > > --- a/tools/perf/util/auxtrace.h
> > > +++ b/tools/perf/util/auxtrace.h
> > > @@ -699,4 +699,10 @@ void itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts)
> > > opts->range_num = 0;
> > > }
> > >
> > > +/*
> > > + * Prototypes for architecture-specific functions that require weak stubs
> > > + * to support cross-platform builds on non-x86 architectures.
> > > + */
> > > +int insn_decode(void *insn, const void *kaddr, int len, int mode);
> > > +
> > > #endif
> > > --
> > > 2.54.0
> > >
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2] perf riscv: Fix discarded const qualifier in _get_field()
2026-05-13 15:48 ` [PATCH 2/3] perf riscv: Fix discarded const qualifier error in _get_field() Li Guan
2026-05-13 16:18 ` Ian Rogers
@ 2026-05-13 18:07 ` Li Guan
2026-05-13 23:11 ` Ian Rogers
2026-05-23 18:41 ` Li Guan
1 sibling, 2 replies; 13+ messages in thread
From: Li Guan @ 2026-05-13 18:07 UTC (permalink / raw)
To: acme, namhyung
Cc: irogers, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel, Li Guan
The assignment of strrchr() return values to non-const char * variables
triggers a -Werror=discarded-qualifiers warning when building with GCC 14.
This happens because in newer glibc versions, strrchr() returns a
const char * if the input string is const.
Properly declare 'line2' and 'nl' as const char * to match the glibc
function signature and ensure type safety. This avoids the need for
explicit type casting and aligns with the design pattern of not
modifying read-only memory in the perf tool.
Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
---
v2:
- Drop the auxtrace decoupling and weak stub approach as they interfered
with the cross-platform analysis intent, per Ian's feedback.
- Focus on a clean fix for the const qualifier issue in RISC-V header.c
by properly declaring local variables as const.
- Use Li Guan as the preferred name format for consistency.
- Verified that this fix is not yet present in acme/perf-tools-next.
| 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
index 4b839203d4..891984e909 100644
--- a/tools/perf/arch/riscv/util/header.c
+++ b/tools/perf/arch/riscv/util/header.c
@@ -19,7 +19,7 @@
static char *_get_field(const char *line)
{
- char *line2, *nl;
+ const char *line2, *nl;
line2 = strrchr(line, ' ');
if (!line2)
--
2.54.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2] perf riscv: Fix discarded const qualifier in _get_field()
2026-05-13 18:07 ` [PATCH v2] perf riscv: Fix discarded const qualifier " Li Guan
@ 2026-05-13 23:11 ` Ian Rogers
2026-05-23 18:41 ` Li Guan
1 sibling, 0 replies; 13+ messages in thread
From: Ian Rogers @ 2026-05-13 23:11 UTC (permalink / raw)
To: Li Guan
Cc: acme, namhyung, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel
On Wed, May 13, 2026 at 11:12 AM Li Guan <guanli.oerv@isrc.iscas.ac.cn> wrote:
>
> The assignment of strrchr() return values to non-const char * variables
> triggers a -Werror=discarded-qualifiers warning when building with GCC 14.
> This happens because in newer glibc versions, strrchr() returns a
> const char * if the input string is const.
>
> Properly declare 'line2' and 'nl' as const char * to match the glibc
> function signature and ensure type safety. This avoids the need for
> explicit type casting and aligns with the design pattern of not
> modifying read-only memory in the perf tool.
>
> Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
> v2:
> - Drop the auxtrace decoupling and weak stub approach as they interfered
> with the cross-platform analysis intent, per Ian's feedback.
> - Focus on a clean fix for the const qualifier issue in RISC-V header.c
> by properly declaring local variables as const.
> - Use Li Guan as the preferred name format for consistency.
> - Verified that this fix is not yet present in acme/perf-tools-next.
>
> tools/perf/arch/riscv/util/header.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
> index 4b839203d4..891984e909 100644
> --- a/tools/perf/arch/riscv/util/header.c
> +++ b/tools/perf/arch/riscv/util/header.c
> @@ -19,7 +19,7 @@
>
> static char *_get_field(const char *line)
> {
> - char *line2, *nl;
> + const char *line2, *nl;
>
> line2 = strrchr(line, ' ');
> if (!line2)
> --
> 2.54.0
>
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] perf riscv: Fix discarded const qualifier in _get_field()
2026-05-13 18:07 ` [PATCH v2] perf riscv: Fix discarded const qualifier " Li Guan
2026-05-13 23:11 ` Ian Rogers
@ 2026-05-23 18:41 ` Li Guan
2026-05-23 22:44 ` Arnaldo Carvalho de Melo
1 sibling, 1 reply; 13+ messages in thread
From: Li Guan @ 2026-05-23 18:41 UTC (permalink / raw)
To: acme, namhyung
Cc: irogers, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel
Hi Arnaldo, Namhyung,
Just a gentle ping on this patch. It has received a Reviewed-by from Ian.
Could you please consider picking it up for perf-tools-next?
Thanks,
Li Guan
On 5/14/2026 2:07 AM, Li Guan wrote:
> The assignment of strrchr() return values to non-const char * variables
> triggers a -Werror=discarded-qualifiers warning when building with GCC 14.
> This happens because in newer glibc versions, strrchr() returns a
> const char * if the input string is const.
>
> Properly declare 'line2' and 'nl' as const char * to match the glibc
> function signature and ensure type safety. This avoids the need for
> explicit type casting and aligns with the design pattern of not
> modifying read-only memory in the perf tool.
>
> Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
> ---
> v2:
> - Drop the auxtrace decoupling and weak stub approach as they interfered
> with the cross-platform analysis intent, per Ian's feedback.
> - Focus on a clean fix for the const qualifier issue in RISC-V header.c
> by properly declaring local variables as const.
> - Use Li Guan as the preferred name format for consistency.
> - Verified that this fix is not yet present in acme/perf-tools-next.
>
> tools/perf/arch/riscv/util/header.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
> index 4b839203d4..891984e909 100644
> --- a/tools/perf/arch/riscv/util/header.c
> +++ b/tools/perf/arch/riscv/util/header.c
> @@ -19,7 +19,7 @@
>
> static char *_get_field(const char *line)
> {
> - char *line2, *nl;
> + const char *line2, *nl;
>
> line2 = strrchr(line, ' ');
> if (!line2)
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2] perf riscv: Fix discarded const qualifier in _get_field()
2026-05-23 18:41 ` Li Guan
@ 2026-05-23 22:44 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-05-23 22:44 UTC (permalink / raw)
To: Li Guan
Cc: namhyung, irogers, adrian.hunter, palmer, pjw, linux-perf-users,
linux-riscv, linux-kernel
On Sun, May 24, 2026 at 02:41:26AM +0800, Li Guan wrote:
> Hi Arnaldo, Namhyung,
>
> Just a gentle ping on this patch. It has received a Reviewed-by from Ian.
> Could you please consider picking it up for perf-tools-next?
Thanks, applying.
- Arnaldo
> Thanks,
> Li Guan
>
> On 5/14/2026 2:07 AM, Li Guan wrote:
> > The assignment of strrchr() return values to non-const char * variables
> > triggers a -Werror=discarded-qualifiers warning when building with GCC 14.
> > This happens because in newer glibc versions, strrchr() returns a
> > const char * if the input string is const.
> >
> > Properly declare 'line2' and 'nl' as const char * to match the glibc
> > function signature and ensure type safety. This avoids the need for
> > explicit type casting and aligns with the design pattern of not
> > modifying read-only memory in the perf tool.
> >
> > Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
> > ---
> > v2:
> > - Drop the auxtrace decoupling and weak stub approach as they interfered
> > with the cross-platform analysis intent, per Ian's feedback.
> > - Focus on a clean fix for the const qualifier issue in RISC-V header.c
> > by properly declaring local variables as const.
> > - Use Li Guan as the preferred name format for consistency.
> > - Verified that this fix is not yet present in acme/perf-tools-next.
> >
> > tools/perf/arch/riscv/util/header.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
> > index 4b839203d4..891984e909 100644
> > --- a/tools/perf/arch/riscv/util/header.c
> > +++ b/tools/perf/arch/riscv/util/header.c
> > @@ -19,7 +19,7 @@
> > static char *_get_field(const char *line)
> > {
> > - char *line2, *nl;
> > + const char *line2, *nl;
> > line2 = strrchr(line, ' ');
> > if (!line2)
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-05-23 22:45 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-13 15:48 [PATCH 0/3] perf build: Fix cross-arch build failures and GCC 14 warnings Li Guan
2026-05-13 15:48 ` [PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects Li Guan
2026-05-13 16:14 ` Ian Rogers
2026-05-13 16:31 ` guanli
2026-05-13 16:37 ` Ian Rogers
2026-05-13 15:48 ` [PATCH 2/3] perf riscv: Fix discarded const qualifier error in _get_field() Li Guan
2026-05-13 16:18 ` Ian Rogers
2026-05-13 18:07 ` [PATCH v2] perf riscv: Fix discarded const qualifier " Li Guan
2026-05-13 23:11 ` Ian Rogers
2026-05-23 18:41 ` Li Guan
2026-05-23 22:44 ` Arnaldo Carvalho de Melo
2026-05-13 15:48 ` [PATCH 3/3] perf script: Provide weak stubs for instruction decoding Li Guan
2026-05-13 16:20 ` Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox