perf: build: Fix cross compilation
v3 cover perf: build: Fix cross compilation
This patch series fixes cross compilation issues.
The first patch sets the package path if the package configuration path is not specified. This helps the compiler to find the architecture's package in a Multiarch system.
The patch 02 sets the Python configuration path and renames the .so to
The patches 03, 04 and 05 fix the static build failures.
The patch 06 adds document for how to cross compile. The patch 07 is to remove obsolete info for building perf with Android NDK.
This patch series is tested for building perf on x86_64 host for Arm64 target, with verified on Debian two distros (buster and bookworm).
Changes from v2:
- Reordered lib paths for PKG_CONFIG_LIBDIR. (Namhyung)
- Verified the Android NDK and based on the testing result to remove the file android.txt. (Ian)
Changes from v1:
- Kept the cross-compile-pkg-config if it is available. (Namhyung)
- Removed the patch 02 for fixing pkg-config path for libtraceevent, as this will be resolved in Guilherme Amadio's patch "perf build: Use pkg-config for feature check for libtrace{event,fs}".
- Added patch 06 for document.
Leo Yan (7):
perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
perf: build: Set Python configuration for cross compilation
perf: build: Only link libebl.a for old libdw
perf: build: Link lib 'lzma' for static build
perf: build: Link lib 'zstd' for static build perf docs: Document cross compilation
perf docs: Remove the Android cross building document
tools/build/feature/Makefile | 54 +++++++++++++++---- tools/perf/Documentation/Build.txt | 37 +++++++++++++ tools/perf/Documentation/android.txt | 78 ---------------------------- tools/perf/Makefile.config | 20 ++++++- tools/perf/Makefile.perf | 26 +++++++++- 5 files changed, 125 insertions(+), 90 deletions(-) delete mode 100644 tools/perf/Documentation/android.txt
Signature · 1 line
2.34.1
PATCH v3 1/7 perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
On recent Linux distros like Ubuntu Noble and Debian Bookworm, the 'pkg-config-aarch64-linux-gnu' package is missing. As a result, the aarch64-linux-gnu-pkg-config command is not available, which causes build failures.
When a build passes the environment variables PKG_CONFIG_LIBDIR or PKG_CONFIG_PATH, like a user uses make command or a build system (like Yocto, Buildroot, etc) prepares the variables and passes to the Perf's Makefile, the commit keeps these variables for package configuration. Otherwise, this commit sets the PKG_CONFIG_LIBDIR variable to use the Multiarch libs for the cross compilation.
--- tools/build/feature/Makefile | 26 +++++++++++++++++++++++++- tools/perf/Makefile.perf | 26 +++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-)
tools/build/feature/Makefile +25 -1
@@ -82,7 +82,31 @@ FILES= \ FILES := $(addprefix $(OUTPUT),$(FILES)) -PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config +# Some distros provide the command $(CROSS_COMPILE)pkg-config for +# searching packges installed with Multiarch. Use it for cross +# compilation if it is existed. +ifneq (, $(shell which $(CROSS_COMPILE)pkg-config)) + PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config +else + PKG_CONFIG ?= pkg-config + + # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR is required for the cross + # compilation. If both is not set, try to set the lib paths installed + # by multiarch. + ifdef CROSS_COMPILE + ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),) + CROSS_ARCH = $(shell $(CC) -dumpmachine) + PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/ + export PKG_CONFIG_LIBDIR + $(warning Missing PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH for cross compilation,) + $(warning set PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR) for building with Multiarch libs.) + endif + endif +endif all: $(FILES)
tools/perf/Makefile.perf +25 -1
@@ -193,7 +193,31 @@ HOSTLD ?= ld HOSTAR ?= ar CLANG ?= clang -PKG_CONFIG = $(CROSS_COMPILE)pkg-config +# Some distros provide the command $(CROSS_COMPILE)pkg-config for +# searching packges installed with Multiarch. Use it for cross +# compilation if it is existed. +ifneq (, $(shell which $(CROSS_COMPILE)pkg-config)) + PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config +else + PKG_CONFIG ?= pkg-config + + # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR is required for the cross + # compilation. If both is not set, try to set the lib paths installed + # by multiarch. + ifdef CROSS_COMPILE + ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),) + CROSS_ARCH = $(shell $(CC) -dumpmachine) + PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/ + export PKG_CONFIG_LIBDIR + $(warning Missing PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH for cross compilation,) + $(warning set PKG_CONFIG_LIBDIR to $(PKG_CONFIG_LIBDIR) for using libs with Multiarch.) + endif + endif +endif RM = rm -f LN = ln -f
Signature · 1 line
2.34.1
Namhyung Kim
maintainerRe: [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
Hi Leo,
Quoted 26 lines · Leo Yan
On recent Linux distros like Ubuntu Noble and Debian Bookworm, the 'pkg-config-aarch64-linux-gnu' package is missing. As a result, the aarch64-linux-gnu-pkg-config command is not available, which causes build failures.
When a build passes the environment variables
PKG_CONFIG_LIBDIRorPKG_CONFIG_PATH, like a user uses make command or a build system (like Yocto, Buildroot, etc) prepares the variables and passes to the Perf'sMakefile, the commit keeps these variables for package configuration. Otherwise, this commit sets thePKG_CONFIG_LIBDIRvariable to use the Multiarch libs for the cross compilation.Signed-off-by Leo Yan <[email protected]>--- tools/build/feature/Makefile | 26 +++++++++++++++++++++++++- tools/perf/Makefile.perf | 26 +++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-)tools/build/feature/Makefile +0
-0@@ -82,7 +82,31 @@ FILES= \ FILES := $(addprefix $(OUTPUT),$(FILES))
tools/build/feature/Makefile FILES= \ · line 93
Quoted 10 lines
tools/build/feature/Makefile +9
-1-PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config +# Some distros provide the command $(CROSS_COMPILE)pkg-config for +# searching packges installed with Multiarch. Use it for cross +# compilation if it is existed. +ifneq (, $(shell which $(CROSS_COMPILE)pkg-config)) + PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config +else + PKG_CONFIG ?= pkg-config + + # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR is required for the cross
And PKG_CONFIG_SYSROOT_DIR too.
tools/build/feature/Makefile FILES= \ · line 105
Quoted 12 lines
tools/build/feature/Makefile +12
-0+ # compilation. If both is not set, try to set the lib paths installed + # by multiarch. + ifdef CROSS_COMPILE + ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),) + CROSS_ARCH = $(shell $(CC) -dumpmachine) + PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/ + export PKG_CONFIG_LIBDIR + $(warning Missing PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH for cross compilation,)
Probably you need to add it here too.
tools/build/feature/Makefile FILES= \ · line 106
Quoted 1 line
tools/build/feature/Makefile +1
-0+ $(warning set PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR) for building with Multiarch libs.)
I guess the message would get too long. Maybe it's ok to hide the actual value..
In addition, I think this message will be displayed multiple times - once here and later in Makefile.perf. Maybe we can show it once in the latter only?
Thanks,
Namhyung
Quoted 46 lines
tools/build/feature/Makefile +3
-0+ endif + endif +endif all: $(FILES)tools/perf/Makefile.perf +25
-1@@ -193,7 +193,31 @@ HOSTLD ?= ld HOSTAR ?= ar CLANG ?= clang -PKG_CONFIG = $(CROSS_COMPILE)pkg-config +# Some distros provide the command $(CROSS_COMPILE)pkg-config for +# searching packges installed with Multiarch. Use it for cross +# compilation if it is existed. +ifneq (, $(shell which $(CROSS_COMPILE)pkg-config)) + PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config +else + PKG_CONFIG ?= pkg-config + + # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR is required for the cross + # compilation. If both is not set, try to set the lib paths installed + # by multiarch. + ifdef CROSS_COMPILE + ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),) + CROSS_ARCH = $(shell $(CC) -dumpmachine) + PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/ + export PKG_CONFIG_LIBDIR + $(warning Missing PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH for cross compilation,) + $(warning set PKG_CONFIG_LIBDIR to $(PKG_CONFIG_LIBDIR) for using libs with Multiarch.) + endif + endif +endif RM = rm -f LN = ln -fSignature · 1 line
2.34.1
Re: [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
Hi Namhyung,
On 7/12/24 05:52, Namhyung Kim wrote:
[...]
Quoted 8 lines
Quoted 8 lines
tools/build/feature/Makefile +0
-0@@ -82,7 +82,31 @@ FILES= \ FILES := $(addprefix $(OUTPUT),$(FILES))
Quoted 12 lines
tools/build/feature/Makefile FILES= \ · line 93
Quoted 10 lines
tools/build/feature/Makefile +9
-1-PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config +# Some distros provide the command $(CROSS_COMPILE)pkg-config for +# searching packges installed with Multiarch. Use it for cross +# compilation if it is existed. +ifneq (, $(shell which $(CROSS_COMPILE)pkg-config)) + PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config +else + PKG_CONFIG ?= pkg-config + + # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR is required for the crossAnd
PKG_CONFIG_SYSROOT_DIRtoo.
I will refine the comment as:
# PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR, alongside PKG_CONFIG_SYSROOT_DIR
# for modified system root, is required for the cross compilation. # If these PKG_CONFIG environment variables are not set, Multiarch library # paths are used instead.
Quoted 13 lines
tools/build/feature/Makefile FILES= \ · line 105
Quoted 12 lines
tools/build/feature/Makefile +12
-0+ # compilation. If both is not set, try to set the lib paths installed + # by multiarch. + ifdef CROSS_COMPILE + ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),) + CROSS_ARCH = $(shell $(CC) -dumpmachine) + PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/ + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/ + export PKG_CONFIG_LIBDIR + $(warning Missing PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH for cross compilation,)
Quoted 1 line
Probably you need to add it here too.
Will do.
Quoted 4 lines
tools/build/feature/Makefile FILES= \ · line 106
Quoted 1 line
tools/build/feature/Makefile +1
-0+ $(warning set PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR) for building with Multiarch libs.)I guess the message would get too long. Maybe it's ok to hide the actual value..
Will do.
Quoted 3 lines
In addition, I think this message will be displayed multiple times - once here and later in Makefile.perf. Maybe we can show it once in the latter only?
Will polish for this.
Thanks,
Leo
PATCH v3 2/7 perf: build: Set Python configuration for cross compilation
In reply to Leo YanPython configuration has dedicated folders for different architectures. For example, Python 3.11 has two folders as shown below, one for Arm64 and another for x86_64:
/usr/lib/python3.11/config-3.11-aarch64-linux-gnu/ /usr/lib/python3.11/config-3.11-x86_64-linux-gnu/
This commit updates the Python configuration path based on the compiler's machine type, guiding the compiler to find the correct path for Python libraries. It also renames the generated .so file name to match the machine name.
--- tools/perf/Makefile.config | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/Makefile.config +8 -0
@@ -303,6 +303,11 @@ endif ifdef PYTHON_CONFIG PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null) + # Update the python flags for cross compilation + ifdef CROSS_COMPILE + PYTHON_NATIVE := $(shell echo $(PYTHON_EMBED_LDOPTS) | sed 's/\(-L.*\/\)\(.*-linux-gnu\).*/\2/') + PYTHON_EMBED_LDOPTS := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EMBED_LDOPTS)) + endif PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS)) PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
@@ -904,6 +909,9 @@ else PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no") ifeq ($(PYTHON_SETUPTOOLS_INSTALLED), yes) PYTHON_EXTENSION_SUFFIX := $(shell $(PYTHON) -c 'from importlib import machinery; print(machinery.EXTENSION_SUFFIXES[0])') + ifdef CROSS_COMPILE + PYTHON_EXTENSION_SUFFIX := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EXTENSION_SUFFIX)) + endif LANG_BINDINGS += $(obj-perf)python/perf$(PYTHON_EXTENSION_SUFFIX) else $(warning Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent)
Signature · 1 line
2.34.1
PATCH v3 3/7 perf: build: Only link libebl.a for old libdw
In reply to Leo YanSince libdw version 0.177, elfutils has merged libebl.a into libdw (see the commit "libebl: Don't install libebl.a, libebl.h and remove backends from spec." in the elfutils repository).
As a result, libebl.a does not exist on Debian Bullseye and newer releases, causing static perf builds to fail on these distributions.
This commit checks the libdw version and only links libebl.a if it detects that the libdw version is older than 0.177.
--- tools/build/feature/Makefile | 12 +++++++++++- tools/perf/Makefile.config | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-)
tools/build/feature/Makefile +11 -1
@@ -171,7 +171,17 @@ $(OUTPUT)test-libopencsd.bin: DWARFLIBS := -ldw ifeq ($(findstring -static,${LDFLAGS}),-static) -DWARFLIBS += -lelf -lebl -lz -llzma -lbz2 + DWARFLIBS += -lelf -lz -llzma -lbz2 + + LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw) + LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION))) + LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION))) + + # Elfutils merged libebl.a into libdw.a starting from version 0.177, + # Link libebl.a only if libdw is older than this version. + ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0) + DWARFLIBS += -lebl + endif endif $(OUTPUT)test-dwarf.bin:
tools/perf/Makefile.config +11 -1
@@ -152,7 +152,17 @@ ifdef LIBDW_DIR endif DWARFLIBS := -ldw ifeq ($(findstring -static,${LDFLAGS}),-static) - DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2 + DWARFLIBS += -lelf -ldl -lz -llzma -lbz2 + + LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw) + LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION))) + LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION))) + + # Elfutils merged libebl.a into libdw.a starting from version 0.177, + # Link libebl.a only if libdw is older than this version. + ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0) + DWARFLIBS += -lebl + endif endif FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS) FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
Signature · 1 line
2.34.1
PATCH v3 4/7 perf: build: Link lib 'lzma' for static build
In reply to Leo YanThe libunwind feature test failed with the static linkage. This is due to the 'lzma' lib is missed, so link it to dismiss building failure.
--- tools/build/feature/Makefile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
tools/build/feature/Makefile +8 -8
@@ -212,27 +212,27 @@ $(OUTPUT)test-numa_num_possible_cpus.bin: $(BUILD) -lnuma $(OUTPUT)test-libunwind.bin: - $(BUILD) -lelf + $(BUILD) -lelf -llzma $(OUTPUT)test-libunwind-debug-frame.bin: - $(BUILD) -lelf + $(BUILD) -lelf -llzma $(OUTPUT)test-libunwind-x86.bin: - $(BUILD) -lelf -lunwind-x86 + $(BUILD) -lelf -llzma -lunwind-x86 $(OUTPUT)test-libunwind-x86_64.bin: - $(BUILD) -lelf -lunwind-x86_64 + $(BUILD) -lelf -llzma -lunwind-x86_64 $(OUTPUT)test-libunwind-arm.bin: - $(BUILD) -lelf -lunwind-arm + $(BUILD) -lelf -llzma -lunwind-arm $(OUTPUT)test-libunwind-aarch64.bin: - $(BUILD) -lelf -lunwind-aarch64 + $(BUILD) -lelf -llzma -lunwind-aarch64 $(OUTPUT)test-libunwind-debug-frame-arm.bin: - $(BUILD) -lelf -lunwind-arm + $(BUILD) -lelf -llzma -lunwind-arm $(OUTPUT)test-libunwind-debug-frame-aarch64.bin: - $(BUILD) -lelf -lunwind-aarch64 + $(BUILD) -lelf -llzma -lunwind-aarch64 $(OUTPUT)test-libaudit.bin: $(BUILD) -laudit
Signature · 1 line
2.34.1
PATCH v3 5/7 perf: build: Link lib 'zstd' for static build
In reply to Leo YanWhen build static perf, Makefile reports the error:
Makefile.config:480: No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR
The libdw has been installed on the system, but the build system fails to build the feature detecting binary 'test-libdw-dwarf-unwind'. The failure is caused by missing to link the lib 'zstd'.
Link lib 'zstd' for the static build, in the end, the dwarf feature can be enabled in the static perf.
--- tools/build/feature/Makefile | 2 +- tools/perf/Makefile.config | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/build/feature/Makefile +1 -1
@@ -171,7 +171,7 @@ $(OUTPUT)test-libopencsd.bin: DWARFLIBS := -ldw ifeq ($(findstring -static,${LDFLAGS}),-static) - DWARFLIBS += -lelf -lz -llzma -lbz2 + DWARFLIBS += -lelf -lz -llzma -lbz2 -lzstd LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw) LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
tools/perf/Makefile.config +1 -1
@@ -152,7 +152,7 @@ ifdef LIBDW_DIR endif DWARFLIBS := -ldw ifeq ($(findstring -static,${LDFLAGS}),-static) - DWARFLIBS += -lelf -ldl -lz -llzma -lbz2 + DWARFLIBS += -lelf -ldl -lz -llzma -lbz2 -lzstd LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw) LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
Signature · 1 line
2.34.1
PATCH v3 6/7 perf docs: Document cross compilation
In reply to Leo YanRecords 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).
--- tools/perf/Documentation/Build.txt | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
tools/perf/Documentation/Build.txt +37 -0
@@ -71,3 +71,40 @@ supported by GCC. UBSan detects undefined behaviors of programs at runtime. $ UBSAN_OPTIONS=print_stacktrace=1 ./perf record -a If UBSan detects any problem at runtime, it outputs a “runtime error:” message. + +4) Cross compilation +==================== +The perf tool can be cross compiled in below methods. + +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 perf with dynamic linking: +As Multiarch is commonly supported in Linux distros, therefore, we can +install multiple architectures libs in the same system and then cross compile +the Linux perf. For example, the Aarch64 libraries and toolchain can be +installed on the x86_64 machine, based on it we can compile the perf for +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.
Signature · 1 line
2.34.1
PATCH v3 7/7 perf docs: Remove the Android cross building document
In reply to Leo YanThe Android NDK (as time being the latest LTS version is r26d) changes toolchain to LLVM / Clang, so GCC compilers is not included in the NDK anymore. Therefore, the Android document contains obsolete info for building perf binary with NDK.
Furthermore, the Clang included in the Android NDK is problematic for cross compilation Aarch64 target. The building reports multiple errors with the compiler aarch64-linux-android34-clang.
Thus, delete Documentation/android.txt to avoid confusion.
--- tools/perf/Documentation/android.txt | 78 ---------------------------- 1 file changed, 78 deletions(-) delete mode 100644 tools/perf/Documentation/android.txt
tools/perf/Documentation/android.txt deleted +0 -78
@@ -1,78 +0,0 @@ -How to compile perf for Android -========================================= - -I. Set the Android NDK environment ------------------------------------------------- - -(a). Use the Android NDK ------------------------------------------------- -1. You need to download and install the Android Native Development Kit (NDK). -Set the NDK variable to point to the path where you installed the NDK: - export NDK=/path/to/android-ndk - -2. Set cross-compiling environment variables for NDK toolchain and sysroot. -For arm: - export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi- - export NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm -For x86: - export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android- - export NDK_SYSROOT=${NDK}/platforms/android-24/arch-x86 - -This method is only tested for Android NDK versions Revision 11b and later. -perf uses some bionic enhancements that are not included in prior NDK versions. -You can use method (b) described below instead. - -(b). Use the Android source tree ------------------------------------------------ -1. Download the master branch of the Android source tree. -Set the environment for the target you want using: - source build/envsetup.sh - lunch - -2. Build your own NDK sysroot to contain latest bionic changes and set the -NDK sysroot environment variable. - cd ${ANDROID_BUILD_TOP}/ndk -For arm: - ./build/tools/build-ndk-sysroot.sh --abi=arm - export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm -For x86: - ./build/tools/build-ndk-sysroot.sh --abi=x86 - export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86 - -3. Set the NDK toolchain environment variable. -For arm: - export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi- -For x86: - export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android- - -II. Compile perf for Android ------------------------------------------------- -You need to run make with the NDK toolchain and sysroot defined above: -For arm: - make WERROR=0 ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" -For x86: - make WERROR=0 ARCH=x86 CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" - -III. Install perf ------------------------------------------------ -You need to connect to your Android device/emulator using adb. -Install perf using: - adb push perf /data/perf - -If you also want to use perf-archive you need busybox tools for Android. -For installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh: - sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive - chmod +x /tmp/perf-archive - adb push /tmp/perf-archive /data/perf-archive - -IV. Environment settings for running perf ------------------------------------------------- -Some perf features need environment variables to run properly. -You need to set these before running perf on the target: - adb shell - # PERF_PAGER=cat - -IV. Run perf ------------------------------------------------- -Run perf on your device/emulator to which you previously connected using adb: - # ./data/perf
Signature · 1 line
2.34.1
Namhyung Kim
maintainerRe: [PATCH v3 7/7] perf docs: Remove the Android cross building document
Quoted 4 lines · Leo Yan
The Android NDK (as time being the latest LTS version is r26d) changes toolchain to LLVM / Clang, so GCC compilers is not included in the NDK anymore. Therefore, the Android document contains obsolete info for building perf binary with NDK.
Do you know if the version prior to the change is still used?
Quoted 6 lines
Furthermore, the Clang included in the Android NDK is problematic for cross compilation Aarch64 target. The building reports multiple errors with the compiler aarch64-linux-android34-clang.
Thus, delete
Documentation/android.txtto avoid confusion.
If so, maybe we can keep the document little more and add a note that this works only for some old versions.
I'm also curious if it's still broken after your fixes.
Thanks,
Namhyung
Quoted 94 lines
Signed-off-by Leo Yan <[email protected]>--- tools/perf/Documentation/android.txt | 78 ---------------------------- 1 file changed, 78 deletions(-) delete mode 100644 tools/perf/Documentation/android.txttools/perf/Documentation/android.txt deleted +0
-78@@ -1,78 +0,0 @@ -How to compile perf for Android -========================================= - -I. Set the Android NDK environment ------------------------------------------------- - -(a). Use the Android NDK ------------------------------------------------- -1. You need to download and install the Android Native Development Kit (NDK). -Set the NDK variable to point to the path where you installed the NDK: - export NDK=/path/to/android-ndk - -2. Set cross-compiling environment variables for NDK toolchain and sysroot. -For arm: - export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi- - export NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm -For x86: - export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android- - export NDK_SYSROOT=${NDK}/platforms/android-24/arch-x86 - -This method is only tested for Android NDK versions Revision 11b and later. -perf uses some bionic enhancements that are not included in prior NDK versions. -You can use method (b) described below instead. - -(b). Use the Android source tree ------------------------------------------------ -1. Download the master branch of the Android source tree. -Set the environment for the target you want using: - source build/envsetup.sh - lunch - -2. Build your own NDK sysroot to contain latest bionic changes and set the -NDK sysroot environment variable. - cd ${ANDROID_BUILD_TOP}/ndk -For arm: - ./build/tools/build-ndk-sysroot.sh --abi=arm - export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm -For x86: - ./build/tools/build-ndk-sysroot.sh --abi=x86 - export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86 - -3. Set the NDK toolchain environment variable. -For arm: - export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi- -For x86: - export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android- - -II. Compile perf for Android ------------------------------------------------- -You need to run make with the NDK toolchain and sysroot defined above: -For arm: - make WERROR=0 ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" -For x86: - make WERROR=0 ARCH=x86 CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" - -III. Install perf ------------------------------------------------ -You need to connect to your Android device/emulator using adb. -Install perf using: - adb push perf /data/perf - -If you also want to use perf-archive you need busybox tools for Android. -For installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh: - sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive - chmod +x /tmp/perf-archive - adb push /tmp/perf-archive /data/perf-archive - -IV. Environment settings for running perf ------------------------------------------------- -Some perf features need environment variables to run properly. -You need to set these before running perf on the target: - adb shell - # PERF_PAGER=cat - -IV. Run perf ------------------------------------------------- -Run perf on your device/emulator to which you previously connected using adb: - # ./data/perfSignature · 1 line
2.34.1
Ian Rogers
reviewerRe: [PATCH v3 7/7] perf docs: Remove the Android cross building document
Quoted 8 lines · Namhyung Kim
Quoted 4 lines · Leo Yan
The Android NDK (as time being the latest LTS version is r26d) changes toolchain to LLVM / Clang, so GCC compilers is not included in the NDK anymore. Therefore, the Android document contains obsolete info for building perf binary with NDK.
Do you know if the version prior to the change is still used?
The git log last mentions NDK 12 from 2016 working. I suspect these instructions haven't worked for a good long while.
Thanks,
Ian
Quoted 109 lines
Quoted 6 lines
Furthermore, the Clang included in the Android NDK is problematic for cross compilation Aarch64 target. The building reports multiple errors with the compiler aarch64-linux-android34-clang.
Thus, delete
Documentation/android.txtto avoid confusion.If so, maybe we can keep the document little more and add a note that this works only for some old versions.
I'm also curious if it's still broken after your fixes.
Thanks,
NamhyungQuoted 94 lines
Signed-off-by Leo Yan <[email protected]>--- tools/perf/Documentation/android.txt | 78 ---------------------------- 1 file changed, 78 deletions(-) delete mode 100644 tools/perf/Documentation/android.txttools/perf/Documentation/android.txt deleted +0
-79@@ -1,78 +0,0 @@ -How to compile perf for Android -========================================= - -I. Set the Android NDK environment ------------------------------------------------- - -(a). Use the Android NDK ------------------------------------------------- -1. You need to download and install the Android Native Development Kit (NDK). -Set the NDK variable to point to the path where you installed the NDK: - export NDK=/path/to/android-ndk - -2. Set cross-compiling environment variables for NDK toolchain and sysroot. -For arm: - export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi- - export NDK_SYSROOT=${NDK}/platforms/android-24/arch-arm -For x86: - export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android- - export NDK_SYSROOT=${NDK}/platforms/android-24/arch-x86 - -This method is only tested for Android NDK versions Revision 11b and later. -perf uses some bionic enhancements that are not included in prior NDK versions. -You can use method (b) described below instead. - -(b). Use the Android source tree ------------------------------------------------ -1. Download the master branch of the Android source tree. -Set the environment for the target you want using: - source build/envsetup.sh - lunch - -2. Build your own NDK sysroot to contain latest bionic changes and set the -NDK sysroot environment variable. - cd ${ANDROID_BUILD_TOP}/ndk -For arm: - ./build/tools/build-ndk-sysroot.sh --abi=arm - export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm -For x86: - ./build/tools/build-ndk-sysroot.sh --abi=x86 - export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86 - -3. Set the NDK toolchain environment variable. -For arm: - export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/arm-linux-androideabi- -For x86: - export NDK_TOOLCHAIN=${ANDROID_TOOLCHAIN}/i686-linux-android- - -II. Compile perf for Android ------------------------------------------------- -You need to run make with the NDK toolchain and sysroot defined above: -For arm: - make WERROR=0 ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" -For x86: - make WERROR=0 ARCH=x86 CROSS_COMPILE=${NDK_TOOLCHAIN} EXTRA_CFLAGS="-pie --sysroot=${NDK_SYSROOT}" - -III. Install perf ------------------------------------------------ -You need to connect to your Android device/emulator using adb. -Install perf using: - adb push perf /data/perf - -If you also want to use perf-archive you need busybox tools for Android. -For installing perf-archive, you first need to replace #!/bin/bash with #!/system/bin/sh: - sed 's/#!\/bin\/bash/#!\/system\/bin\/sh/g' perf-archive >> /tmp/perf-archive - chmod +x /tmp/perf-archive - adb push /tmp/perf-archive /data/perf-archive - -IV. Environment settings for running perf ------------------------------------------------- -Some perf features need environment variables to run properly. -You need to set these before running perf on the target: - adb shell - # PERF_PAGER=cat - -IV. Run perf ------------------------------------------------- -Run perf on your device/emulator to which you previously connected using adb: - # ./data/perf --2.34.1
Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
In reply to Namhyung KimHi Namhyung,
Quoted 1 line · Namhyung Kim
On Sat, Jul 06, 2024 at 07:29:12PM +0100, Leo Yan wrote:
[...]
Quoted 6 lines
Quoted 4 lines
The Android NDK (as time being the latest LTS version is r26d) changes toolchain to LLVM / Clang, so GCC compilers is not included in the NDK anymore. Therefore, the Android document contains obsolete info for building perf binary with NDK.
Do you know if the version prior to the change is still used?
Based on the Android NDK wiki claims [1], since NDK r15 (backed to 26th July, 2017) "GCC is no longer supported. It will not be removed from the NDK just yet, but is no longer receiving backports".
Quoted 10 lines
Quoted 5 lines
Furthermore, the Clang included in the Android NDK is problematic for cross compilation Aarch64 target. The building reports multiple errors with the compiler aarch64-linux-android34-clang.
Thus, delete
Documentation/android.txtto avoid confusion.If so, maybe we can keep the document little more and add a note that this works only for some old versions.
I'm also curious if it's still broken after your fixes.
When I tried Android NDK for cross building perf, it is still broken after applied this series.
From my testing, now using LLVM for native building works well:
make LLVM=-15 VF=1 DEBUG=1 -C tools/perf
But it failed for cross compilation. Since Android NDK system root does not contain some dependency libs, we must use extra options to disable some features (e.g. NO_LIBELF=1 NO_LIBTRACEEVENT=1). The commands I tried for cross building but failed:
make ARCH=arm64 CC=$NDK_TOOLCHAIN/aarch64-linux-android-clang \
LD=$NDK_TOOLCHAIN/ld.lld AR=$NDK_TOOLCHAIN/llvm-ar \
NM=$NDK_TOOLCHAIN/llvm-nm STRIP=$NDK_TOOLCHAIN/llvm-strip \
OBJCOPY=$NDK_TOOLCHAIN/llvm-objcopy \
OBJDUMP=$NDK_TOOLCHAIN/llvm-objdump \
READELF=$NDK_TOOLCHAIN/llvm-readelf \
HOSTCC=$NDK_TOOLCHAIN/clang \
HOSTCXX=$NDK_TOOLCHAIN/clang++ HOSTAR=$NDK_TOOLCHAIN/llvm-ar \
HOSTLD=$NDK_TOOLCHAIN/ld.lld VF=1 DEBUG=1 NO_LIBELF=1 \
NO_LIBTRACEEVENT=1 EXTRA_CFLAGS=-fgnuc-version=0 \
-C tools/perfGiven the test result, my conclusion is the doc for Android cross building is not useful for a long while. If we really want to support it, I would like to suggest to take a separate task for fixing LLVM / Clang cross compilation.
Thanks,
Leo
James Clark
reviewerRe: [PATCH v3 7/7] perf docs: Remove the Android cross building document
Quoted 53 lines · Leo Yan
Hi Namhyung,
Quoted 1 line · Namhyung Kim
On Sat, Jul 06, 2024 at 07:29:12PM +0100, Leo Yan wrote:
[...]
Quoted 6 lines
Quoted 4 lines
The Android NDK (as time being the latest LTS version is r26d) changes toolchain to LLVM / Clang, so GCC compilers is not included in the NDK anymore. Therefore, the Android document contains obsolete info for building perf binary with NDK.
Do you know if the version prior to the change is still used?
Based on the Android NDK wiki claims [1], since NDK r15 (backed to 26th July, 2017) "GCC is no longer supported. It will not be removed from the NDK just yet, but is no longer receiving backports".
Quoted 10 lines
Quoted 5 lines
Furthermore, the Clang included in the Android NDK is problematic for cross compilation Aarch64 target. The building reports multiple errors with the compiler aarch64-linux-android34-clang.
Thus, delete
Documentation/android.txtto avoid confusion.If so, maybe we can keep the document little more and add a note that this works only for some old versions.
I'm also curious if it's still broken after your fixes.
When I tried Android NDK for cross building perf, it is still broken after applied this series.
From my testing, now using LLVM for native building works well:
make LLVM=-15 VF=1 DEBUG=1 -C
tools/perfBut it failed for cross compilation. Since Android NDK system root does not contain some dependency libs, we must use extra options to disable some features (e.g. NO_LIBELF=1 NO_LIBTRACEEVENT=1). The commands I tried for cross building but failed:
make ARCH=arm64 CC=$NDK_TOOLCHAIN/aarch64-linux-android-clang \
LD=$NDK_TOOLCHAIN/ld.lld AR=$NDK_TOOLCHAIN/llvm-ar \
NM=$NDK_TOOLCHAIN/llvm-nm STRIP=$NDK_TOOLCHAIN/llvm-strip \
OBJCOPY=$NDK_TOOLCHAIN/llvm-objcopy \
OBJDUMP=$NDK_TOOLCHAIN/llvm-objdump \
READELF=$NDK_TOOLCHAIN/llvm-readelf \
HOSTCC=$NDK_TOOLCHAIN/clang \
HOSTCXX=$NDK_TOOLCHAIN/clang++ HOSTAR=$NDK_TOOLCHAIN/llvm-ar \
HOSTLD=$NDK_TOOLCHAIN/ld.lld VF=1 DEBUG=1 NO_LIBELF=1 \
NO_LIBTRACEEVENT=1 EXTRA_CFLAGS=-fgnuc-version=0 \
-Ctools/perf
Quoted 4 lines
Given the test result, my conclusion is the doc for Android cross building is not useful for a long while. If we really want to support it, I would like to suggest to take a separate task for fixing LLVM / Clang cross compilation.
We could replace the entire contents of the file with something like "Android NDK compilation deprecated -- no longer supported". It might help someone in being able to recover the history of the file by leaving in some keywords. If you delete it it becomes very unlikely that the history will be found by someone trying to get it working again.
Quoted 5 lines
Thanks,
Leo
Re: [PATCH v3 7/7] perf docs: Remove the Android cross building document
On 7/12/24 14:38, James Clark wrote:
[...]
Quoted 10 lines
Quoted 4 lines
Given the test result, my conclusion is the doc for Android cross building is not useful for a long while. If we really want to support it, I would like to suggest to take a separate task for fixing LLVM / Clang cross compilation.
We could replace the entire contents of the file with something like "Android NDK compilation deprecated -- no longer supported". It might help someone in being able to recover the history of the file by leaving in some keywords. If you delete it it becomes very unlikely that the history will be found by someone trying to get it working again.
A specific Android version has corresponding Linux kernels. It is likely developers can find what they want, as they should work on an relative old kernel source tree.
Given Namhyung and you both are concerned for removing the doc, I have followed the suggestion, respined this patch and sent sepearately [1], as this patch is not really related to cross building fix.
Thanks,
Leo
[1] https://lore.kernel.org/linux-perf-users/[email protected]/T/#u