Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf docs: Document cross compilation

Records the commands for cross compilation with two methods.

The first method relies on Multiarch. The second approach is to explicitly
specify the PKG_CONFIG variables, which is widely used in build system
(like Buildroot, Yocto, etc).

Co-developed-by: James Clark <james.clark@arm.com>
Signed-off-by: James Clark <james.clark@arm.com>
Signed-off-by: Leo Yan <leo.yan@arm.com>
Tested-by: Ian Rogers <irogers@google.com>
Cc: amadio@gentoo.org
Cc: Thomas Richter <tmricht@linux.ibm.com>
Link: https://lore.kernel.org/r/20240717082211.524826-7-leo.yan@arm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Leo Yan and committed by
Namhyung Kim
d27087c7 f42596c7

+28
+28
tools/perf/Documentation/Build.txt
··· 71 71 $ UBSAN_OPTIONS=print_stacktrace=1 ./perf record -a 72 72 73 73 If UBSan detects any problem at runtime, it outputs a “runtime error:” message. 74 + 75 + 4) Cross compilation 76 + ==================== 77 + As Multiarch is commonly supported in Linux distributions, we can install 78 + libraries for multiple architectures on the same system and then cross-compile 79 + Linux perf. For example, Aarch64 libraries and toolchains can be installed on 80 + an x86_64 machine, allowing us to compile perf for an Aarch64 target. 81 + 82 + Below is the command for building the perf with dynamic linking. 83 + 84 + $ cd /path/to/Linux 85 + $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf 86 + 87 + For static linking, the option `LDFLAGS="-static"` is required. 88 + 89 + $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \ 90 + LDFLAGS="-static" -C tools/perf 91 + 92 + In the embedded system world, a use case is to explicitly specify the package 93 + configuration paths for cross building: 94 + 95 + $ PKG_CONFIG_SYSROOT_DIR="/path/to/cross/build/sysroot" \ 96 + PKG_CONFIG_LIBDIR="/usr/lib/:/usr/local/lib" \ 97 + make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf 98 + 99 + In this case, the variable PKG_CONFIG_SYSROOT_DIR can be used alongside the 100 + variable PKG_CONFIG_LIBDIR or PKG_CONFIG_PATH to prepend the sysroot path to 101 + the library paths for cross compilation.