[RFC] perf build: Use self-contained headers from kernel source when compiling

From: hupu
Date: Mon Nov 24 2025 - 02:23:30 EST


When building perf, switch to using the self-contained headers provided
in the kernel source tree to avoid build failures caused by missing
architecture-specific headers. For example, the build may fail with
errors like:

/usr/include/linux/ioctl.h:5:10: fatal error: 'asm/ioctl.h' file not
found
5 | #include <asm/ioctl.h>
| ^~~~~~~~~~~~~

This issue may occur because system-installed headers are incomplete,
incompatible with the kernel version being built, or the corresponding
architecture-specific headers are not installed at all. Using the
self-contained headers from the kernel source ensures a consistent and
compatible build environment.

Signed-off-by: hupu <hupu.gm@xxxxxxxxx>
---
tools/perf/Makefile.perf | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 47c906b807ef..eaccaae87e3c 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -1202,7 +1202,9 @@ endif

CLANG_OPTIONS = -Wall
CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
-BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES)
+KHDR_INCLUDES := $(abspath $(OUTPUT)/../../usr/include)
+BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) \
+ -I$(KHDR_INCLUDES) $(CLANG_SYS_INCLUDES)
TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi

ifneq ($(WERROR),0)
--
2.43.0