perf build: Support building with Clang
Subsystems (2)
v2 cover perf build: Support building with Clang
This series adds support for building perf with Clang, following the discussion in [1]. Because the Android NDK uses Clang by default, enabling Clang builds naturally covers Android as well.
The series is organized as follows:
- Patches 1–2: Fix two bugs found with Clang.
- Patches 3–6: Correct CROSS_ARCH and dismiss Clang build warnings.
- Patches 7–8: Enable Clang in the Makefile and update the documentation.
Testing:
- Clang 15.0.7 on Ubuntu 22.04.5: native and cross-compiling (aarch64)
- Clang 18.1.3 on Ubuntu 24.04.2: native and cross-compiling (aarch64)
- Android NDK r27d (latest LTS): cross-compiling (aarch64)
[1] https://lore.kernel.org/linux-perf-users/[email protected]/
---
Changes in v2:
- Dropped the patch for dismissing warning in bpftool.
- Refined the document. (Ian)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Leo Yan (8):
tools build: Align warning options with perf
perf python: split Clang options when invoking Popen
perf: build: Correct CROSS_ARCH for clang
perf test coresight: Dismiss clang warning for memcpy thread perf test coresight: Dismiss clang warning for thread loop perf test coresight: Dismiss clang warning for unroll loop thread perf build: Support build with clang
perf docs: Document building with Clang
tools/build/feature/Makefile | 6 +- tools/perf/Documentation/Build.txt | 15 ++++ tools/perf/Documentation/android.txt | 80 ++-------------------- tools/perf/Makefile.config | 32 ++++++++- tools/perf/Makefile.perf | 2 +- .../shell/coresight/memcpy_thread/memcpy_thread.c | 2 + .../shell/coresight/thread_loop/thread_loop.c | 4 +- .../unroll_loop_thread/unroll_loop_thread.c | 4 +- tools/perf/util/setup.py | 5 +- 9 files changed, 67 insertions(+), 83 deletions(-)
---
base-commit: c17dda8013495d8132c976cbf349be9949d0fbd1
change-id: 20250915-perf_build_android_ndk-500b53bea895
Best regards,
Signature · 1 line
Leo Yan <[email protected]>
PATCH v2 1/8 tools build: Align warning options with perf
The feature test programs are built without enabling '-Wall -Werror' options. As a result, a feature may appear to be available, but later building in perf can fail with stricter checks.
Make the feature test program use the same warning options as perf.
--- tools/build/feature/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/build/feature/Makefile +2 -2
@@ -316,10 +316,10 @@ $(OUTPUT)test-libcapstone.bin: $(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone) $(OUTPUT)test-compile-32.bin: - $(CC) -m32 -o $@ test-compile.c + $(CC) -m32 -Wall -Werror -o $@ test-compile.c $(OUTPUT)test-compile-x32.bin: - $(CC) -mx32 -o $@ test-compile.c + $(CC) -mx32 -Wall -Werror -o $@ test-compile.c $(OUTPUT)test-zlib.bin: $(BUILD) -lz
Signature · 1 line
2.34.1
PATCH v2 2/8 perf python: split Clang options when invoking Popen
In reply to Leo YanWhen passing a list to subprocess.Popen, each element maps to one argv token. Current code bundles multiple Clang flags into a single element, something like:
cmd = ['clang',
'--target=x86_64-linux-gnu -fintegrated-as -Wno-cast-function-type-mismatch', 'test-hello.c']
So Clang only sees one long, invalid option instead of separate flags, as a result, the script cannot capture any log via PIPE.
Fix this by using shlex.split() to separate the string so each option becomes its own argv element. The fixed list will be:
cmd = ['clang',
'--target=x86_64-linux-gnu', '-fintegrated-as', '-Wno-cast-function-type-mismatch', 'test-hello.c']
--- tools/perf/util/setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/setup.py +4 -1
@@ -1,6 +1,7 @@ from os import getenv, path from subprocess import Popen, PIPE from re import sub +import shlex cc = getenv("CC") assert cc, "Environment variable CC not set"
@@ -22,7 +23,9 @@ assert srctree, "Environment variable srctree, for the Linux sources, not set" src_feature_tests = f'{srctree}/tools/build/feature' def clang_has_option(option): - cc_output = Popen([cc, cc_options + option, path.join(src_feature_tests, "test-hello.c") ], stderr=PIPE).stderr.readlines() + cmd = shlex.split(f"{cc} {cc_options} {option}") + cmd.append(path.join(src_feature_tests, "test-hello.c")) + cc_output = Popen(cmd, stderr=PIPE).stderr.readlines() return [o for o in cc_output if ((b"unknown argument" in o) or (b"is not supported" in o) or (b"unknown warning option" in o))] == [ ] if cc_is_clang:
Signature · 1 line
2.34.1
PATCH v2 3/8 perf: build: Correct CROSS_ARCH for clang
In reply to Leo YanClang's -dumpmachine outputs "aarch64-unknown-linux-gnu", which does not match the MultiArch convention. This prevents the build system from detecting installed packages.
Fix by stripping the trailing '-' from CROSS_COMPILE when setting CROSS_ARCH.
--- tools/build/feature/Makefile | 2 +- tools/perf/Makefile.perf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/build/feature/Makefile +1 -1
@@ -94,7 +94,7 @@ else # paths are used instead. ifdef CROSS_COMPILE ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),) - CROSS_ARCH = $(shell $(CC) -dumpmachine) + CROSS_ARCH = $(notdir $(CROSS_COMPILE:%-=%)) 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/
tools/perf/Makefile.perf +1 -1
@@ -194,7 +194,7 @@ else # paths are used instead. ifdef CROSS_COMPILE ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),) - CROSS_ARCH = $(shell $(CC) -dumpmachine) + CROSS_ARCH = $(notdir $(CROSS_COMPILE:%-=%)) 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/
Signature · 1 line
2.34.1
PATCH v2 4/8 perf test coresight: Dismiss clang warning for memcpy thread
In reply to Leo Yanclang-18.1.3 on Ubuntu 24.04.2 reports warning:
memcpy_thread.c:30:1: warning: non-void function does not return a value in all control paths [-Wreturn-type]
30 | }
| ^Dismiss the warning with returning NULL from the thread function.
--- tools/perf/tests/shell/coresight/memcpy_thread/memcpy_thread.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/tests/shell/coresight/memcpy_thread/memcpy_thread.c +2 -0
@@ -27,6 +27,8 @@ static void *thrfn(void *arg) }for (i =0 ; i < len; i++)memcpy (dst, src, a->size *1024 ); + +return NULL ; }static pthread_t new_thr (void *(*fn) (void *arg),void *arg)
Signature · 1 line
2.34.1
PATCH v2 5/8 perf test coresight: Dismiss clang warning for thread loop
In reply to Leo Yanclang-18.1.3 on Ubuntu 24.04.2 reports warning:
thread_loop.c:41:23: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
41 | : /* in */ [i] "r" (i), [len] "r" (len)
| ^
thread_loop.c:37:8: note: use constraint modifier "w"
37 | "add %[i], %[i], #1\n"
| ^~~~
| %w[i]
thread_loop.c:41:23: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
41 | : /* in */ [i] "r" (i), [len] "r" (len)
| ^
thread_loop.c:37:14: note: use constraint modifier "w"
37 | "add %[i], %[i], #1\n"
| ^~~~
| %w[i]
thread_loop.c:41:23: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
41 | : /* in */ [i] "r" (i), [len] "r" (len)
| ^
thread_loop.c:38:8: note: use constraint modifier "w"
38 | "cmp %[i], %[len]\n"
| ^~~~
| %w[i]
thread_loop.c:41:38: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
41 | : /* in */ [i] "r" (i), [len] "r" (len)
| ^
thread_loop.c:38:14: note: use constraint modifier "w"
38 | "cmp %[i], %[len]\n"
| ^~~~~~
| %w[len]Use the modifier "w" for 32-bit register access.
--- tools/perf/tests/shell/coresight/thread_loop/thread_loop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/tests/shell/coresight/thread_loop/thread_loop.c +2 -2
@@ -34,8 +34,8 @@ static void *thrfn(void *arg) } asmvolatile ("loop:\n" -"add %[i], %[i], #1\n" -"cmp %[i], %[len]\n" +"add %w[i], %w[i], #1\n" +"cmp %w[i], %w[len]\n" "blt loop\n" :/* out */ : /* in */ [i] "r" (i), [len] "r" (len)
Signature · 1 line
2.34.1
PATCH v2 6/8 perf test coresight: Dismiss clang warning for unroll loop thread
In reply to Leo Yanclang-18.1.3 on Ubuntu 24.04.2 reports warning:
unroll_loop_thread.c:35:25: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
35 | : /* in */ [in] "r" (in)
| ^
unroll_loop_thread.c:39:1: warning: non-void function does not return a value [-Wreturn-type]
39 | }
| ^Use the modifier "w" for 32-bit register access and return NULL at the end of thread function.
--- .../tests/shell/coresight/unroll_loop_thread/unroll_loop_thread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/tests/shell/coresight/unroll_loop_thread/unroll_loop_thread.c +3 -1
@@ -20,7 +20,7 @@ static void *thrfn(void *arg)for (i =0 ; i <10000 ; i++) { asmvolatile (// force an unroll of thia add instruction so we can test long runs of code -#define SNIP1 "add %[in], %[in], #1\n" +#define SNIP1 "add %w[in], %w[in], #1\n"// 10 #define SNIP2 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 // 100
@@ -36,6 +36,8 @@ static void *thrfn(void *arg) : /* clobber */ ); } + +return NULL ; }static pthread_t new_thr (void *(*fn) (void *arg),void *arg)
Signature · 1 line
2.34.1
PATCH v2 7/8 perf build: Support build with clang
In reply to Leo YanAdd support for building perf with clang. For cross compilation, the Makefile dynamically selects target flag for corresponding arch.
This patch has been verified on x86_64 machine with Ubuntu distro, it can build successfully for native target, and for cross building Arm64 and s390.
Example: native build on x86_64 / Ubuntu machine:
$ HOSTCC=clang CC=clang CXX=clang++ make -C tools/perf
Example: cross building s390 target on x86_64 / Ubuntu machine:
# Install x390x cross toolchain and headers
$ sudo apt-get install gcc-s390x-linux-gnu g++-s390x-linux-gnu \
libc6-dev-s390x-cross linux-libc-dev-s390x-cross
# Build with clang
$ HOSTCC=clang CC=clang CXX=clang++ \
ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- \
make -C tools/perf NO_LIBELF=1 NO_LIBTRACEEVENT=1 NO_LIBPYTHON=1--- tools/perf/Makefile.config | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
tools/perf/Makefile.config +31 -1
@@ -23,8 +23,38 @@ HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) # borrowed from kernel headers depends on it, e.g. put_unaligned_*(). CFLAGS += -fno-strict-aliasing -# Enabled Wthread-safety analysis for clang builds. +# Set target flag and options when using clang as compiler. ifeq ($(CC_NO_CLANG), 0) + CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi + CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu + CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu + CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu + CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu + CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu + CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu + CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu + + # Default to host architecture if ARCH is not explicitly given. + ifeq ($(ARCH),) + CLANG_TARGET_FLAGS := $(shell $(CLANG) -print-target-triple) + else + CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH)) + endif + + ifeq ($(CROSS_COMPILE),) + ifeq ($(CLANG_TARGET_FLAGS),) + $(error Specify CROSS_COMPILE or add CLANG_TARGET_FLAGS for $(ARCH)) + else + CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS) + endif # CLANG_TARGET_FLAGS + else + CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) + endif # CROSS_COMPILE + + CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as + CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as + + # Enabled Wthread-safety analysis for clang builds. CFLAGS += -Wthread-safety endif
Signature · 1 line
2.34.1
PATCH v2 8/8 perf docs: Document building with Clang
In reply to Leo YanAdd 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.
--- tools/perf/Documentation/Build.txt | 15 +++++++ tools/perf/Documentation/android.txt | 80 +++--------------------------------- 2 files changed, 21 insertions(+), 74 deletions(-)
tools/perf/Documentation/Build.txt +15 -0
@@ -99,3 +99,18 @@ configuration paths for cross building: 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. + +5) Build with Clang +=================== +By default, the makefile uses GCC as compiler. With specifying environment +variables HOSTCC, CC and CXX, it allows to build perf with Clang. + +Using Clang for a native build: + + $ HOSTCC=clang CC=clang CXX=clang++ make -C tools/perf + +Specifying ARCH and CROSS_COMPILE for cross compilation: + + $ HOSTCC=clang CC=clang CXX=clang++ \ + ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \ + make -C tools/perf
tools/perf/Documentation/android.txt +6 -74
84 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 18 lines · Leo Yan
This series adds support for building perf with Clang, following the discussion in [1]. Because the Android NDK uses Clang by default, enabling Clang builds naturally covers Android as well.
The series is organized as follows:
- Patches 1–2: Fix two bugs found with Clang.
- Patches 3–6: CorrectCROSS_ARCHand dismiss Clang build warnings.
- Patches 7–8: Enable Clang in theMakefileand update the documentation.Testing:
- Clang 15.0.7 on Ubuntu 22.04.5: native and cross-compiling (aarch64)
- Clang 18.1.3 on Ubuntu 24.04.2: native and cross-compiling (aarch64)
- Android NDK r27d (latest LTS): cross-compiling (aarch64)
Quoted 7 lines
[1] https://lore.kernel.org/linux-perf-users/[email protected]/
---
Changes in v2:
- Dropped the patch for dismissing warning in bpftool.
- Refined the document. (Ian)
- Link to v1: https://lore.kernel.org/r/[email protected]
Thanks,
Ian
Quoted 29 lines
---
Leo Yan (8):
tools build: Align warning options with perf
perf python: split Clang options when invoking Popen
perf: build: CorrectCROSS_ARCHfor clang
perf test coresight: Dismiss clang warning for memcpy thread perf test coresight: Dismiss clang warning for thread loop perf test coresight: Dismiss clang warning for unroll loop thread perf build: Support build with clang
perf docs: Document building with Clangtools/build/feature/Makefile | 6 +- tools/perf/Documentation/Build.txt | 15 ++++ tools/perf/Documentation/android.txt | 80 ++-------------------- tools/perf/Makefile.config | 32 ++++++++- tools/perf/Makefile.perf | 2 +- .../shell/coresight/memcpy_thread/memcpy_thread.c | 2 + .../shell/coresight/thread_loop/thread_loop.c | 4 +- .../unroll_loop_thread/unroll_loop_thread.c | 4 +- tools/perf/util/setup.py | 5 +- 9 files changed, 67 insertions(+), 83 deletions(-)---
base-commit:c17dda8013495d8132c976cbf349be9949d0fbd1
change-id: 20250915-perf_build_android_ndk-500b53bea895Best regards,
--
Leo Yan <[email protected]>
Quoted 21 lines · Ian Rogers
Quoted 20 lines · Leo Yan
This series adds support for building perf with Clang, following the discussion in [1]. Because the Android NDK uses Clang by default, enabling Clang builds naturally covers Android as well.
The series is organized as follows:
- Patches 1–2: Fix two bugs found with Clang.
- Patches 3–6: CorrectCROSS_ARCHand dismiss Clang build warnings.
- Patches 7–8: Enable Clang in theMakefileand update the documentation.Testing:
- Clang 15.0.7 on Ubuntu 22.04.5: native and cross-compiling (aarch64)
- Clang 18.1.3 on Ubuntu 24.04.2: native and cross-compiling (aarch64)
- Android NDK r27d (latest LTS): cross-compiling (aarch64)[1] https://lore.kernel.org/linux-perf-users/[email protected]/
Quoted 7 lines
Quoted 5 lines
---
Changes in v2:
- Dropped the patch for dismissing warning in bpftool.
- Refined the document. (Ian)
- Link to v1: https://lore.kernel.org/r/[email protected]Reviewed-by Ian Rogers <[email protected]>
Thanks, applied to perf-tools-next,
- Arnaldo
Arnaldo Carvalho de Melo
maintainerQuoted 11 lines · Leo Yan
This series adds support for building perf with Clang, following the discussion in [1]. Because the Android NDK uses Clang by default, enabling Clang builds naturally covers Android as well.
The series is organized as follows:
- Patches 1–2: Fix two bugs found with Clang.
- Patches 3–6: CorrectCROSS_ARCHand dismiss Clang build warnings.
- Patches 7–8: Enable Clang in theMakefileand update the documentation.
Quoted 5 lines
Testing:
- Clang 15.0.7 on Ubuntu 22.04.5: native and cross-compiling (aarch64)
- Clang 18.1.3 on Ubuntu 24.04.2: native and cross-compiling (aarch64)
- Android NDK r27d (latest LTS): cross-compiling (aarch64)
LD /tmp/build/perf/util/perf-util-in.o LD /tmp/build/perf/perf-util-in.o AR /tmp/build/perf/libperf-util.a CC /tmp/build/perf/pmu-events/pmu-events.o LD /tmp/build/perf/pmu-events/pmu-events-in.o AR /tmp/build/perf/libpmu-events.a LINK /tmp/build/perf/perf
make: Leaving directory '/git/perf-6.17.0-rc6/tools/perf'
+ rm -rf /tmp/build/perf
+ mkdir /tmp/build/perf
+ make 'ARCH=' 'CROSS_COMPILE=' 'EXTRA_CFLAGS=' -C tools/perf 'O=/tmp/build/perf' 'CC=clang'
make: Entering directory '/git/perf-6.17.0-rc6/tools/perf'
BUILD: Doing 'make -j28' parallel build
Makefile.config:494: *** No gnu/libc-version.h found, please install glibc-dev[el]. Stop. make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-6.17.0-rc6/tools/perf'
+ exit 1
toolsbuilder@five:~$ cat dm.log/alpine\:3.22
Quoted 36 lines · Arnaldo Carvalho de Melo
Quoted 11 lines · Leo Yan
This series adds support for building perf with Clang, following the discussion in [1]. Because the Android NDK uses Clang by default, enabling Clang builds naturally covers Android as well.
The series is organized as follows:
- Patches 1–2: Fix two bugs found with Clang.
- Patches 3–6: CorrectCROSS_ARCHand dismiss Clang build warnings.
- Patches 7–8: Enable Clang in theMakefileand update the documentation.Quoted 5 lines
Testing:
- Clang 15.0.7 on Ubuntu 22.04.5: native and cross-compiling (aarch64)
- Clang 18.1.3 on Ubuntu 24.04.2: native and cross-compiling (aarch64)
- Android NDK r27d (latest LTS): cross-compiling (aarch64)LD /tmp/build/perf/util/perf-util-in.o LD /tmp/build/perf/perf-util-in.o AR /tmp/build/perf/libperf-util.a CC /tmp/build/perf/pmu-events/pmu-events.o LD /tmp/build/perf/pmu-events/pmu-events-in.o AR /tmp/build/perf/libpmu-events.a LINK /tmp/build/perf/perfmake: Leaving directory '/git/perf-6.17.0-rc6/tools/perf'
+ rm -rf/tmp/build/perf
+ mkdir/tmp/build/perf
+ make 'ARCH=' 'CROSS_COMPILE=' 'EXTRA_CFLAGS=' -Ctools/perf'O=/tmp/build/perf' 'CC=clang'
make: Entering directory '/git/perf-6.17.0-rc6/tools/perf'
BUILD: Doing 'make -j28' parallel build
Makefile.config:494: *** Nognu/libc-version.hfound, please install glibc-dev[el]. Stop. make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-6.17.0-rc6/tools/perf'
+ exit 1
Quoted 1 line
toolsbuilder@five:~$ cat dm.log/alpine\:3.22
A quick look: the build cannot find both libelf (feature-libelf=0) and glibc (feature-glibc=0), thus lead to build failure. It is good to know what the reason for the feature building failures:
tools/perf/feature/test-libelf.make.output
tools/perf/feature/test-glibc.make.output
I am not surprised for the failure of libelf (this is common case that the package is not installed by default in a distro), but it is a bit confused for the glibc feature failure.
It seems the issue occurs on Alpine 3.22, but the highest version supported in container-build is 3.21 [1]. Could you confirm whether the issue reproduces on other distros or versions?
Thanks,
Leo
[1] https://github.com/acmel/linux-tools-container-builds/tree/main/alpine
Arnaldo Carvalho de Melo
maintainerQuoted 46 lines · Leo Yan
Quoted 36 lines · Arnaldo Carvalho de Melo
Quoted 11 lines · Leo Yan
This series adds support for building perf with Clang, following the discussion in [1]. Because the Android NDK uses Clang by default, enabling Clang builds naturally covers Android as well.
The series is organized as follows:
- Patches 1–2: Fix two bugs found with Clang.
- Patches 3–6: CorrectCROSS_ARCHand dismiss Clang build warnings.
- Patches 7–8: Enable Clang in theMakefileand update the documentation.Quoted 5 lines
Testing:
- Clang 15.0.7 on Ubuntu 22.04.5: native and cross-compiling (aarch64)
- Clang 18.1.3 on Ubuntu 24.04.2: native and cross-compiling (aarch64)
- Android NDK r27d (latest LTS): cross-compiling (aarch64)LD /tmp/build/perf/util/perf-util-in.o LD /tmp/build/perf/perf-util-in.o AR /tmp/build/perf/libperf-util.a CC /tmp/build/perf/pmu-events/pmu-events.o LD /tmp/build/perf/pmu-events/pmu-events-in.o AR /tmp/build/perf/libpmu-events.a LINK /tmp/build/perf/perfmake: Leaving directory '/git/perf-6.17.0-rc6/tools/perf'
+ rm -rf/tmp/build/perf
+ mkdir/tmp/build/perf
+ make 'ARCH=' 'CROSS_COMPILE=' 'EXTRA_CFLAGS=' -Ctools/perf'O=/tmp/build/perf' 'CC=clang'
make: Entering directory '/git/perf-6.17.0-rc6/tools/perf'
BUILD: Doing 'make -j28' parallel build
Makefile.config:494: *** Nognu/libc-version.hfound, please install glibc-dev[el]. Stop. make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-6.17.0-rc6/tools/perf'
+ exit 1Quoted 1 line
toolsbuilder@five:~$ cat dm.log/alpine\:3.22A quick look: the build cannot find both libelf (feature-libelf=0) and glibc (feature-glibc=0), thus lead to build failure. It is good to know what the reason for the feature building failures:
tools/perf/feature/test-libelf.make.output
tools/perf/feature/test-glibc.make.output
Quoted 7 lines
I am not surprised for the failure of libelf (this is common case that the package is not installed by default in a distro), but it is a bit confused for the glibc feature failure.
It seems the issue occurs on Alpine 3.22, but the highest version supported in container-build is 3.21 [1]. Could you confirm whether the issue reproduces on other distros or versions?
It was in all alpine versions I have containers to test on:
toolsbuilder@five:~$ grep FAIL dm.log.old/summary 3 71.85 almalinux:9-i386 : FAIL clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) 5 78.60 alpine:3.16 : FAIL gcc version 11.2.1 20220219 (Alpine 11.2.1_git20220219) 6 59.77 alpine:3.17 : FAIL gcc version 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4) 7 56.89 alpine:3.18 : FAIL gcc version 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10) 8 60.86 alpine:3.19 : FAIL gcc version 13.2.1 20231014 (Alpine 13.2.1_git20231014) 9 60.18 alpine:3.20 : FAIL gcc version 13.2.1 20240309 (Alpine 13.2.1_git20240309) 10 64.58 alpine:3.22 : FAIL gcc version 14.2.0 (Alpine 14.2.0) 11 63.36 alpine:edge : FAIL gcc version 14.2.0 (Alpine 14.2.0) toolsbuilder@five:~$
GEN /tmp/build/perf/python/perf.cpython-312-x86_64-linux-musl.so
make: Leaving directory '/git/perf-6.17.0-rc6/tools/perf'
+ rm -rf /tmp/build/perf
+ mkdir /tmp/build/perf
+ make 'ARCH=' 'CROSS_COMPILE=' 'EXTRA_CFLAGS=' -C tools/perf 'O=/tmp/build/perf' 'CC=clang'
make: Entering directory '/git/perf-6.17.0-rc6/tools/perf'
BUILD: Doing 'make -j28' parallel build
Makefile.config:494: *** No gnu/libc-version.h found, please install glibc-dev[el]. Stop. make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-6.17.0-rc6/tools/perf'
+ exit 1
toolsbuilder@five:~
$
lemme try to reapply those patches and get thetools/perf/feature/test-libelf.make.output andtools/perf/feature/test-glibc.make.output files.
- Arnaldo
On Wed, Oct 01, 2025 at 03:25:56PM -0300, Arnaldo Carvalho de Melo wrote:
[...]
Quoted 28 lines
It was in all alpine versions I have containers to test on:
toolsbuilder@five:~$ grep FAIL dm.log.old/summary 3 71.85 almalinux:9-i386 : FAIL clang version 17.0.6 (AlmaLinux OS Foundation 17.0.6-5.el9) 5 78.60 alpine:3.16 : FAIL gcc version 11.2.1 20220219 (Alpine 11.2.1_git20220219) 6 59.77 alpine:3.17 : FAIL gcc version 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4) 7 56.89 alpine:3.18 : FAIL gcc version 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10) 8 60.86 alpine:3.19 : FAIL gcc version 13.2.1 20231014 (Alpine 13.2.1_git20231014) 9 60.18 alpine:3.20 : FAIL gcc version 13.2.1 20240309 (Alpine 13.2.1_git20240309) 10 64.58 alpine:3.22 : FAIL gcc version 14.2.0 (Alpine 14.2.0) 11 63.36 alpine:edge : FAIL gcc version 14.2.0 (Alpine 14.2.0) toolsbuilder@five:~$GEN
/tmp/build/perf/python/perf.cpython-312-x86_64-linux-musl.so
make: Leaving directory '/git/perf-6.17.0-rc6/tools/perf'
+ rm -rf/tmp/build/perf
+ mkdir/tmp/build/perf
+ make 'ARCH=' 'CROSS_COMPILE=' 'EXTRA_CFLAGS=' -Ctools/perf'O=/tmp/build/perf' 'CC=clang'
make: Entering directory '/git/perf-6.17.0-rc6/tools/perf'
BUILD: Doing 'make -j28' parallel build
Makefile.config:494: *** Nognu/libc-version.hfound, please install glibc-dev[el]. Stop. make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
make: Leaving directory '/git/perf-6.17.0-rc6/tools/perf'
+ exit 1
toolsbuilder@five:~
$
Quoted 3 lines
lemme try to reapply those patches and get the
tools/perf/feature/test-libelf.make.outputandtools/perf/feature/test-glibc.make.outputfiles.
That is fine. I have reproduced at my side, will look into.
Thanks,
Leo
On Wed, Oct 01, 2025 at 07:32:56PM +0100, Leo Yan wrote:
[...]
Quoted 4 lines
Quoted 4 lines
+ make 'ARCH=' 'CROSS_COMPILE=' 'EXTRA_CFLAGS=' -C
tools/perf'O=/tmp/build/perf' 'CC=clang'
make: Entering directory '/git/perf-6.17.0-rc6/tools/perf'
BUILD: Doing 'make -j28' parallel build
Makefile.config:494: *** Nognu/libc-version.hfound, please install glibc-dev[el]. Stop.
It does not set correctly --target as x86_64-alpine-linux-musl if distros are using musl libc.
Now running the container build for updated code. Once pass test, I will send new series.
Thanks,
Leo
Arnaldo Carvalho de Melo
maintainerQuoted 9 lines · Leo Yan
On Wed, Oct 01, 2025 at 07:32:56PM +0100, Leo Yan wrote:
[...]
Quoted 4 lines
Quoted 4 lines
+ make 'ARCH=' 'CROSS_COMPILE=' 'EXTRA_CFLAGS=' -C
tools/perf'O=/tmp/build/perf' 'CC=clang'
make: Entering directory '/git/perf-6.17.0-rc6/tools/perf'
BUILD: Doing 'make -j28' parallel build
Makefile.config:494: *** Nognu/libc-version.hfound, please install glibc-dev[el]. Stop.
Quoted 5 lines
It does not set correctly --target as x86_64-alpine-linux-musl if distros are using musl libc.
Now running the container build for updated code. Once pass test, I will send new series.
Thanks for spotting the problem after taking the trouble of starting a container! Hopefully that will save time for other people trying to cross-build perf.
Cheers,
- Arnaldo