[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251223084337.3789-1-hupu.gm@gmail.com>
Date: Tue, 23 Dec 2025 16:43:33 +0800
From: hupu <hupu.gm@...il.com>
To: peterz@...radead.org,
mingo@...hat.com,
acme@...nel.org,
namhyung@...nel.org,
mark.rutland@....com,
alexander.shishkin@...ux.intel.com,
jolsa@...nel.org,
irogers@...gle.com,
adrian.hunter@...el.com,
james.clark@...aro.org,
nathan@...nel.org,
nick.desaulniers+lkml@...il.com,
morbo@...gle.com,
justinstitt@...gle.com,
linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org,
llvm@...ts.linux.dev,
hupu.gm@...il.com
Subject: [RFC 0/2] perf build: Improve header handling for BPF skeleton cross-builds
I am currently cross-compiling perf for ARM64. During the build of the
eBPF skeleton (compiled by Clang), the build fails due to missing header
files. The error message is as follows:
/usr/include/linux/ioctl.h:5:10: fatal error: 'asm/ioctl.h' file not
found
5 | #include <asm/ioctl.h>
| ^~~~~~~~~~~~~
Leo suggested resolving this issue by installing the following packages
on the host:
$ sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
$ sudo apt-get install libc6-dev-aarch64-cross linux-libc-dev-aarch64-cross
$ sudo apt-get install libc6-dev-arm64-cross linux-libc-dev-arm64-cross
With these packages installed, the required header files can be found in
the following host paths (defined by the CLANG_SYS_INCLUDES variable),
and perf can indeed be built successfully:
*** Makefile.perf:1203: ***
CLANG_SYS_INCLUDES=-idirafter /usr/lib/llvm-18/lib/clang/18/include
-idirafter /usr/local/include
-idirafter /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/14/../../../../aarch64-linux-gnu/include
-idirafter /usr/include/aarch64-linux-gnu
-idirafter /usr/include
However, I do not believe that relying on the host build environment is
the best approach, for several reasons:
a) These commands install UAPI header files on the host, especially
`linux-libc-dev-aarch64-cross` and `linux-libc-dev-arm64-cross`. These
headers originate from the kernel source tree’s `include/uapi/` and
`arch/arm64/include/uapi/` directories, and their versions are tied to
the *HOST* kernel version. If the target kernel version is different,
mismatches may cause compilation errors or even runtime failures.
b) Even if `perf` can be compiled and run successfully now, there is
no guarantee that the kernel source headers will always match the
host-installed UAPI headers as the upstream kernel evolves.
c) In scenarios where the host acts as a general build server and
needs to build multiple target kernel versions, it is not possible to
ensure that the host UAPI headers are compatible with all target
versions.
d) On the other hand, `CLANG_SYS_INCLUDES` does include host headers,
but it uses `-idirafter` instead of `-I`. This means the host headers
have lower priority. This change was introduced in commit a2af0f6b8ef7
("perf build: Add system include paths to BPF builds"); as noted in
the commit message, the preferred approach is to use kernel source
headers rather than potentially older ones from the system.
Therefore, although installing the corresponding packages on the host
can resolve the immediate build issue, I do not think this should be
considered the only solution, nor should it have the highest priority.
Instead, I think the header search order should be as follows.
- Prefer kernel source headers
[RFC 2/2] perf build: Prefer kernel source headers for BPF skeletons
With this approach, even as the kernel version evolves, the headers
used during the build will always match the target kernel version.
- Allow users to specify header search paths matching the target kernel
version (eg. via `EXTRA_BPF_FLAGS`)
[RFC 1/2] perf build: Allow passing extra Clang flags via EXTRA_BPF_FLAGS
With this approach, users can explicitly specify the appropriate
header search paths via EXTRA_BPF_FLAGS.
- Fall back to the host build environment only if necessary
Reliance on the host build environment should be the last resort.
In summary, while relying on the host build environment can address the
current build issue, I believe it is not the optimal solution.
hupu (2):
perf build: Allow passing extra Clang flags via EXTRA_BPF_FLAGS
perf build: Prefer kernel source headers for BPF skeletons
tools/perf/Makefile.perf | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
--
2.43.0
Powered by blists - more mailing lists