Skip to content

RFC perf build: Improve header handling for BPF skeleton cross-builds

hupu linux-perf-users lkml llvm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2perf build: Allow passing extra Clang flags via EXTRA_BPF_FLAGStools/perf/Makefile.perf+4 -13 replies
2/2perf build: Prefer kernel source headers for BPF skeletonstools/perf/Makefile.perf+7 -11 reply

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchNamhyung Kim
1/2R-b
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [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(-)
Signature · 1 line
2.43.0