* [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; 14+ 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
^ permalink raw reply [flat|nested] 14+ 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-14 6:59 ` sashiko-bot
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, 2 replies; 14+ 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
^ permalink raw reply related [flat|nested] 14+ 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
` (2 more replies)
2026-05-13 15:48 ` [PATCH 3/3] perf script: Provide weak stubs for instruction decoding Li Guan
2 siblings, 3 replies; 14+ 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
^ permalink raw reply related [flat|nested] 14+ 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
2026-05-14 8:06 ` sashiko-bot
2 siblings, 2 replies; 14+ 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
^ permalink raw reply related [flat|nested] 14+ 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
2026-05-14 6:59 ` sashiko-bot
1 sibling, 1 reply; 14+ 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
>
^ permalink raw reply [flat|nested] 14+ 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
2026-05-14 7:38 ` [PATCH 2/3] perf riscv: Fix discarded const qualifier error " sashiko-bot
2 siblings, 0 replies; 14+ 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
>
^ permalink raw reply [flat|nested] 14+ 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
2026-05-14 8:06 ` sashiko-bot
1 sibling, 0 replies; 14+ 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
>
^ permalink raw reply [flat|nested] 14+ 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; 14+ 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
> >
^ permalink raw reply [flat|nested] 14+ 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; 14+ 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
> > >
^ permalink raw reply [flat|nested] 14+ 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-14 7:38 ` [PATCH 2/3] perf riscv: Fix discarded const qualifier error " sashiko-bot
2 siblings, 1 reply; 14+ 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
^ permalink raw reply related [flat|nested] 14+ 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
0 siblings, 0 replies; 14+ 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
>
>
^ permalink raw reply [flat|nested] 14+ 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-14 6:59 ` sashiko-bot
1 sibling, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-05-14 6:59 UTC (permalink / raw)
To: Li Guan; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [Critical] Linker errors on non-x86 architectures due to missing `tpebs` variables.
- [High] Loss of cross-architecture hardware trace decoding.
- [High] Linker errors on x86_64 when building with `NO_AUXTRACE=1`.
- [High] CoreSight (CS_ETM) trace decoding broken on 32-bit `arm`.
- [Low] Use of undefined macros for preprocessor guards.
- [Low] Signature mismatch and undefined behavior for `insn_decode` weak stub.
--
commit beae63268ca91077cb9cb1a3341f8277e45cb290
Author: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
perf build: Fix cross-arch build failures by isolating auxtrace objects
This commit isolates architecture-specific hardware tracing drivers from the
generic perf build process. It conditionally links objects based on exported
feature flags and introduces weak stub functions for gracefully handling
omitted drivers.
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 333ddd0e4bd81..c4c0d79242d5d 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
Does this omit CoreSight support on 32-bit arm builds? CoreSight trace
decoding is natively supported on 32-bit arm via tools/perf/arch/arm/, but
this explicitly restricts the feature flag solely to arm64.
[ ... ]
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index 70cc91d00804d..79ade6066df9d 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
Will this break the ability to decode hardware traces across different
architectures?
A core feature of perf is analyzing traces like ARM SPE on non-native
hosts like x86. Omitting these objects entirely on non-native
architectures would cause cross-architecture decoding to silently fall back
to the weak stubs and fail.
[ ... ]
> @@ -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
Could this cause linker errors on non-x86 architectures?
The builtin-stat.c file unconditionally references the tpebs_recording and
tpebs_mode global variables defined in intel-tpebs.o. If this file is
conditionally compiled only for x86, non-x86 builds will likely fail with
undefined references during the final linking stage.
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index a224687ffbc1b..f6e426c3c56e1 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
[ ... ]
> @@ -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,
Will this lead to unresolved symbols on 64-bit x86 if NO_AUXTRACE=1 is set?
The HAVE_ARCH_X86_64_SUPPORT macro is defined unconditionally for x86_64
builds. If NO_AUXTRACE=1 skips compiling the strong definitions, this
preprocessor guard will also skip the weak stubs, leaving unconditional
callers with missing symbols.
[ ... ]
> +int __weak insn_decode(void *insn __maybe_unused, const void *kaddr __maybe_unused,
> + int len __maybe_unused, int mode __maybe_unused)
> +{
> + return -EOPNOTSUPP;
> +}
Is the signature for insn_decode correct here?
The callers in tools/perf/util/sample.c expect the first parameter to be
struct insn *insn rather than void *insn. Calling a function via a
declaration with mismatched pointer types is undefined behavior in C. A
forward declaration for struct insn might be needed instead.
> +#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)
Are the HAVE_ARCH_ARM64_SUPPORT and HAVE_ARCH_S390_SUPPORT macros defined
anywhere in the tree?
These preprocessor guards do not appear to exist, which would mean these
weak stubs are compiled unconditionally on all architectures.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260513154851.1085334-1-guanli.oerv@isrc.iscas.ac.cn?part=1
^ permalink raw reply [flat|nested] 14+ 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
@ 2026-05-14 7:38 ` sashiko-bot
2 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-05-14 7:38 UTC (permalink / raw)
To: Li Guan; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Deterministic NULL pointer dereference in `get_cpuid()` when `/proc/cpuinfo` parsing fails.
- [Low] The patch resolves a const-qualifier warning by forcefully casting to `(char *)` instead of using const-correct variable types.
--
commit 5d7d955a53ac900eccabdb8ae292dcf199883310
Author: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
perf riscv: Fix discarded const qualifier error in _get_field()
This commit addresses a build failure on GCC 14 caused by strict type checking
on pointer assignments. It resolves the discarded-qualifiers warning by
explicitly casting the return values of strrchr() to a (char *).
> diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
> index 4b839203d4a54..d01ba64aecfd5 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, ' ');
Would it be better to declare line2 and nl as const char * rather than
forcefully casting away the const qualifier?
Since these variables are only used for pointer arithmetic and passed to
strndup() (which accepts a const char *), propagating the const qualifier
would prevent bypassing the compiler safety checks.
> if (!line2)
> return NULL;
>
> line2++;
> - nl = strrchr(line, '\n');
> + nl = (char *)strrchr(line, '\n');
> if (!nl)
> return NULL;
While reviewing this file, I also noticed a pre-existing issue in the
get_cpuid() function:
tools/perf/arch/riscv/util/header.c:get_cpuid() {
char *cpuid = _get_cpuid();
int ret = 0;
if (sz < strlen(cpuid)) {
ret = -EINVAL;
goto free;
}
...
}
Can this unconditional call to strlen() cause a segmentation fault if
_get_cpuid() returns NULL?
If _get_cpuid() fails to open /proc/cpuinfo or cannot find the expected
fields (mvendorid, marchid, mimpid), it will return NULL. Passing that NULL
pointer to strlen() would cause the tool to crash in environments without
/proc mounted or on older RISC-V kernels.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260513154851.1085334-1-guanli.oerv@isrc.iscas.ac.cn?part=2
^ permalink raw reply [flat|nested] 14+ 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
@ 2026-05-14 8:06 ` sashiko-bot
1 sibling, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-05-14 8:06 UTC (permalink / raw)
To: Li Guan; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The weak stub for `dump_insn` returns `NULL`, causing undefined behavior and a potential segmentation fault when passed to `fprintf`.
- [Low] Architectural layering violation by placing utility function stubs in a specific subcommand module.
--
commit c0a4d858da63f7e967ef9c465327ead66a0bd83b
Author: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
perf script: Provide weak stubs for instruction decoding
This commit provides global weak stubs for dump_insn and
arch_is_uncond_branch to resolve undefined reference linker errors
when cross-compiling perf for non-x86 architectures like ARM64 and
RISC-V.
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index c8ac9f01a36bc..80a8f0e80b42d 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.
> + */
Since dump_insn and arch_is_uncond_branch are general utility functions
declared in tools/perf/util/dump-insn.h, is it appropriate to place their
weak fallback implementations in a specific subcommand file?
This creates a structural inversion where a general utility header relies
on a subcommand's compilation to satisfy linker requirements. Would it be
better to place these stubs in a dedicated utility file like
tools/perf/util/dump-insn.c to preserve module boundaries and allow future
reuse across other perf tools?
> +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;
Does returning a null pointer here cause a segmentation fault?
Looking at any_dump_insn(), if Capstone disassembly is not used or fails,
the result is unconditionally formatted using fprintf:
fprintf(fp, "%s", dump_insn(...));
Passing a null pointer to the %s format specifier is undefined behavior.
While some standard C libraries like glibc defensively print "(null)", other
implementations commonly used on ARM or embedded systems (such as musl or
bionic) will directly dereference the null pointer, crashing perf script.
Should this return a valid static string literal like "<bad>" instead,
which matches the failure behavior of the x86 implementation?
> +}
> +
> +int __weak arch_is_uncond_branch(const unsigned char *buf __maybe_unused,
> + size_t len __maybe_unused,
> + int x86_64 __maybe_unused)
> +{
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260513154851.1085334-1-guanli.oerv@isrc.iscas.ac.cn?part=3
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-05-14 8:06 UTC | newest]
Thread overview: 14+ 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-14 6:59 ` sashiko-bot
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-14 7:38 ` [PATCH 2/3] perf riscv: Fix discarded const qualifier error " sashiko-bot
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
2026-05-14 8:06 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox