[PATCH 1/3] perf build: Fix cross-arch build failures by isolating auxtrace objects
Ian Rogers
irogers at google.com
Wed May 13 09:14:59 PDT 2026
On Wed, May 13, 2026 at 8:50 AM Li Guan <guanli.oerv at 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 at 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
>
More information about the linux-riscv
mailing list