[Q][PATCH 1/1] UBUNTU: [Packaging] Use host bpftool if doing cross-compiling

Zixing Liu zixing.liu at canonical.com
Tue Aug 12 01:49:05 UTC 2025


The bpftool binary compiled in the tree when cross-compiling will be for the
target architecture. To correctly generate the BTF data, host bpftool will be
used for running the generation process.

Signed-off-by: Zixing Liu <zixing.liu at canonical.com>
---
 debian.master/control.stub.in   | 1 +
 debian/rules.d/2-binary-arch.mk | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/debian.master/control.stub.in b/debian.master/control.stub.in
index 5559498f50e5..623eb50f03f7 100644
--- a/debian.master/control.stub.in
+++ b/debian.master/control.stub.in
@@ -52,6 +52,7 @@ Build-Depends:
  rustfmt:native [amd64 arm64 armhf ppc64el riscv64 s390x],
  uuid-dev <!stage1>,
  zstd <!stage1>,
+ bpftool:native <!stage1> <cross>,
 Build-Depends-Indep:
  asciidoc <!stage1>,
  bzip2 <!stage1>,
diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
index 7cde1abbc7c3..fc575f8d3cc9 100644
--- a/debian/rules.d/2-binary-arch.mk
+++ b/debian/rules.d/2-binary-arch.mk
@@ -20,6 +20,12 @@ BPFTOOL_VERSION_PATCH = $(shell sed -ne \
 	tools/bpf/bpftool/main.c)
 BPFTOOL_VERSION = $(shell expr $(BPFTOOL_VERSION_MAJOR) + 6).$(BPFTOOL_VERSION_MINOR).$(BPFTOOL_VERSION_PATCH)
 BPFTOOL_GENCONTROL_ARGS = -v$(BPFTOOL_VERSION)+$(DEB_VERSION)
+ifneq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
+# Use system bpftool when cross-building
+BPFTOOL_PATH = /usr/sbin/bpftool
+else
+BPFTOOL_PATH = $(builddirpa)/tools/bpf/bpftool/bpftool
+endif
 
 debian/scripts/fix-filenames: debian/scripts/fix-filenames.c
 	$(HOSTCC) $^ -o $@
@@ -64,7 +70,7 @@ ifeq ($(do_linux_tools),true)
   ifeq ($(do_tools_bpftool_stub),true)
 	echo '#error "Kernel does not support CONFIG_DEBUG_INFO_BTF"' > $(build_dir)/vmlinux.h
   else
-	$(builddirpa)/tools/bpf/bpftool/bpftool btf dump file $(build_dir)/vmlinux format c > $(build_dir)/vmlinux.h
+	$(BPFTOOL_PATH) btf dump file $(build_dir)/vmlinux format c > $(build_dir)/vmlinux.h
   endif
  endif
 endif
-- 
2.50.0




More information about the kernel-team mailing list