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

perf docs: Document building with Clang

Add example commands for building perf with Clang.

Since recent Android NDK releases use Clang as the default compiler, a
separate Android specific document is no longer needed; point to the
general build documentation instead.

Signed-off-by: Leo Yan <leo.yan@arm.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20251006-perf_build_android_ndk-v3-9-4305590795b2@arm.com
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Bill Wendling <morbo@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: linux-riscv@lists.infradead.org
Cc: llvm@lists.linux.dev
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Leo Yan and committed by
Arnaldo Carvalho de Melo
0a75ba3e 4772e66c

+21 -74
+15
tools/perf/Documentation/Build.txt
··· 99 99 In this case, the variable PKG_CONFIG_SYSROOT_DIR can be used alongside the 100 100 variable PKG_CONFIG_LIBDIR or PKG_CONFIG_PATH to prepend the sysroot path to 101 101 the library paths for cross compilation. 102 + 103 + 5) Build with Clang 104 + =================== 105 + By default, the makefile uses GCC as compiler. With specifying environment 106 + variables HOSTCC, CC and CXX, it allows to build perf with Clang. 107 + 108 + Using Clang for a native build: 109 + 110 + $ HOSTCC=clang CC=clang CXX=clang++ make -C tools/perf 111 + 112 + Specifying ARCH and CROSS_COMPILE for cross compilation: 113 + 114 + $ HOSTCC=clang CC=clang CXX=clang++ \ 115 + ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \ 116 + make -C tools/perf
+6 -74
tools/perf/Documentation/android.txt
··· 1 1 How to compile perf for Android 2 - ========================================= 2 + =============================== 3 3 4 - I. Set the Android NDK environment 5 - ------------------------------------------------ 4 + There are two ways to build perf and run it on Android: 6 5 7 - (a). Use the Android NDK 8 - ------------------------------------------------ 9 - 1. You need to download and install the Android Native Development Kit (NDK). 10 - Set the NDK variable to point to the path where you installed the NDK: 11 - export NDK=/path/to/android-ndk 6 + - Method 1: Build perf with static linking. See Build.txt, section 7 + "4) Cross compilation" for how to build a static perf binary. 12 8 13 - 2. Set cross-compiling environment variables for NDK toolchain and sysroot. 14 - For arm: 15 - export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi- 16 - export NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm 17 - For x86: 18 - export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android- 19 - export NDK_SYSROOT=${NDK}/platforms/android-24/arch-x86 20 - 21 - This method is only tested for Android NDK versions Revision 11b and later. 22 - perf uses some bionic enhancements that are not included in prior NDK versions. 23 - You can use method (b) described below instead. 24 - 25 - (b). Use the Android source tree 26 - ----------------------------------------------- 27 - 1. Download the master branch of the Android source tree. 28 - Set the environment for the target you want using: 29 - source build/envsetup.sh 30 - lunch 31 - 32 - 2. Build your own NDK sysroot to contain latest bionic changes and set the 33 - NDK sysroot environment variable. 34 - cd ${ANDROID_BUILD_TOP}/ndk 35 - For arm: 36 - ./build/tools/build-ndk-sysroot.sh --abi=arm 37 - export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm 38 - For x86: 39 - ./build/tools/build-ndk-sysroot.sh --abi=x86 40 - export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86 41 - 42 - 3. Set the NDK toolchain environment variable. 43 - For arm: 44 - export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi- 45 - For x86: 46 - export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android- 47 - 48 - II. Compile perf for Android 49 - ------------------------------------------------ 50 - You need to run make with the NDK toolchain and sysroot defined above: 51 - For arm: 52 - make WERROR=0 ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" 53 - For x86: 54 - make WERROR=0 ARCH=x86 CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" 55 - 56 - III. Install perf 57 - ----------------------------------------------- 58 - You need to connect to your Android device/emulator using adb. 59 - Install perf using: 60 - adb push perf /data/perf 61 - 62 - If you also want to use perf-archive you need busybox tools for Android. 63 - For installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh: 64 - sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive 65 - chmod +x /tmp/perf-archive 66 - adb push /tmp/perf-archive /data/perf-archive 67 - 68 - IV. Environment settings for running perf 69 - ------------------------------------------------ 70 - Some perf features need environment variables to run properly. 71 - You need to set these before running perf on the target: 72 - adb shell 73 - # PERF_PAGER=cat 74 - 75 - IV. Run perf 76 - ------------------------------------------------ 77 - Run perf on your device/emulator to which you previously connected using adb: 78 - # ./data/perf 9 + - Method 2: Download the Android NDK and use the bundled Clang to 10 + build perf. See Build.txt, section "5) Build with clang" for details.