Cross-Compile perf for RISC-V

https://medium.com/@manas.marwah/building-perf-tool-fc838f084f71

https://perfwiki.github.io/main/development/

https://perfwiki.github.io/main/arm64-cross-compilation-dockerfile/

linux-6.16-rc3/tools/perf/Documentation/Build.txt

Option perf support

The standard Linux distribution package for the perf tool includes only basic support, lacking the full array of options.

$ perf --version --build-options
perf version 6.15-1
                   aio: [ on  ]  # HAVE_AIO_SUPPORT
                   bpf: [ on  ]  # HAVE_LIBBPF_SUPPORT
         bpf_skeletons: [ on  ]  # HAVE_BPF_SKEL
            debuginfod: [ on  ]  # HAVE_DEBUGINFOD_SUPPORT
                 dwarf: [ on  ]  # HAVE_LIBDW_SUPPORT
    dwarf_getlocations: [ on  ]  # HAVE_LIBDW_SUPPORT
          dwarf-unwind: [ on  ]  # HAVE_DWARF_UNWIND_SUPPORT
              auxtrace: [ on  ]  # HAVE_AUXTRACE_SUPPORT
                libbfd: [ OFF ]  # HAVE_LIBBFD_SUPPORT
           libcapstone: [ OFF ]  # HAVE_LIBCAPSTONE_SUPPORT
             libcrypto: [ on  ]  # HAVE_LIBCRYPTO_SUPPORT
    libdw-dwarf-unwind: [ on  ]  # HAVE_LIBDW_SUPPORT
                libelf: [ on  ]  # HAVE_LIBELF_SUPPORT
               libnuma: [ on  ]  # HAVE_LIBNUMA_SUPPORT
            libopencsd: [ OFF ]  # HAVE_CSTRACE_SUPPORT
               libperl: [ on  ]  # HAVE_LIBPERL_SUPPORT
               libpfm4: [ on  ]  # HAVE_LIBPFM
             libpython: [ on  ]  # HAVE_LIBPYTHON_SUPPORT
              libslang: [ on  ]  # HAVE_SLANG_SUPPORT
         libtraceevent: [ on  ]  # HAVE_LIBTRACEEVENT
             libunwind: [ OFF ]  # HAVE_LIBUNWIND_SUPPORT
                  lzma: [ on  ]  # HAVE_LZMA_SUPPORT
numa_num_possible_cpus: [ on  ]  # HAVE_LIBNUMA_SUPPORT
                  zlib: [ on  ]  # HAVE_ZLIB_SUPPORT
                  zstd: [ on  ]  # HAVE_ZSTD_SUPPORT

Cross-Compile

4) Cross compilation
====================
As Multiarch is commonly supported in Linux distributions, we can install
libraries for multiple architectures on the same system and then cross-compile
Linux perf. For example, Aarch64 libraries and toolchains can be installed on
an x86_64 machine, allowing us to compile perf for an Aarch64 target.

Below is the command for building the perf with dynamic linking.

  $ cd /path/to/Linux
  $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf

For static linking, the option `LDFLAGS="-static"` is required.

  $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
    LDFLAGS="-static" -C tools/perf

In the embedded system world, a use case is to explicitly specify the package
configuration paths for cross building:

  $ PKG_CONFIG_SYSROOT_DIR="/path/to/cross/build/sysroot" \
    PKG_CONFIG_LIBDIR="/usr/lib/:/usr/local/lib" \
    make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf

In this case, the variable PKG_CONFIG_SYSROOT_DIR can be used alongside the
variable PKG_CONFIG_LIBDIR or PKG_CONFIG_PATH to prepend the sysroot path to
the library paths for cross compilation.

source: tools/perf/Documentation/Build.txt