[P/U][PATCH] UBUNTU: [Packaging] bpftool: move to separate unversioned and unflavored binary package (LP: #2007308)

Frode Nordahl fnordahl at ubuntu.com
Thu Feb 27 06:38:31 UTC 2025


The bpftool binary is used as build time dependency for multiple
Debian packages.

Before this patch, bpftool was provided by the linux-tools-common
package, which in reality shipped a shell script that attempted to
locate the real binary in /usr/lib/linux-tools/$(uname -r)/,
falling back to printing a human friendly message with
instructions for what package to install.

This does not work well for multiple reasons:
* Automated build pipelines are more often than not run in
  containers.
* Said containers usually host a user space filesystem that do
  not contain nor have any way to install linux-tools-$(uname -r)
  package.
* Automated build pipelines declaring bpftool as a build time
  dependency expect the functionality of bpftool when executing
  bpftool, and have no way of interpreting the human friendly
  message.
* This deviation from Debian creates perpetual per release manual
  work for Ubuntu for any Debian package depending on bpftool.

The BPF Compile Once - Run Everywhere (BPF CO-RE) concept revolves
around using bpftool to dump BPF Type Format (BTF) information from
the running kernel.

With this in mind, it comes across as counter intuitive that the
bpftool binary needs to be distributed in a versioned and
flavoured package.

Move bpftool into a separate unversioned and unflavoured binary
package.

Prefix bpftool package version with the bpftool projects own
versioning scheme.  This is aligned with the Debian packaging [0]
and expectations created by upstream stand-alone distribution of
bpftool [1].

0: https://salsa.debian.org/kernel-team/linux/-/commit/b20f5b55eb30c2ba0e1fa8f5d241370225063321
1: https://lore.kernel.org/bpf/267a35a6-a045-c025-c2d9-78afbf6fc325@isovalent.com/
Signed-off-by: Frode Nordahl <fnordahl at ubuntu.com>
---
 debian/control.d/bpftool.stub            | 10 +++++++++
 debian/control.d/linux-tools-common.stub |  3 ++-
 debian/rules                             |  3 ++-
 debian/rules.d/0-common-vars.mk          |  1 +
 debian/rules.d/2-binary-arch.mk          | 28 +++++++++++++++++++++++-
 debian/rules.d/3-binary-indep.mk         | 24 ++++++++++++++------
 debian/scripts/control-create            |  6 +++++
 7 files changed, 65 insertions(+), 10 deletions(-)
 create mode 100644 debian/control.d/bpftool.stub

Build tested at:
https://launchpad.net/~fnordahl/+archive/ubuntu/bpftool-as-build-dep-fix

diff --git a/debian/control.d/bpftool.stub b/debian/control.d/bpftool.stub
new file mode 100644
index 000000000000..fd6a61d6f72c
--- /dev/null
+++ b/debian/control.d/bpftool.stub
@@ -0,0 +1,10 @@
+Package: bpftool
+Architecture: amd64 armhf arm64 ppc64el s390x
+Depends: ${misc:Depends}, ${shlibs:Depends}
+Breaks:
+  linux-tools-common (<< 6.14.0-6~),
+Replaces:
+  linux-tools-common (<< 6.14.0-6~),
+Description: Inspection and simple manipulation of BPF programs and maps
+ The bpftool command allows for inspection and simple modification of
+ Berkeley Packet Filter (BPF) objects on the system.
diff --git a/debian/control.d/linux-tools-common.stub b/debian/control.d/linux-tools-common.stub
index 37d5bd17bd76..4e09b79e8ba1 100644
--- a/debian/control.d/linux-tools-common.stub
+++ b/debian/control.d/linux-tools-common.stub
@@ -5,8 +5,9 @@ Multi-Arch: foreign
 Section: kernel
 Priority: optional
 Provides: 
- bpftool, 
  linux-cpupower,
+Recommends:
+ bpftool (>= 7.6.0+6.14.0-6~),
 Depends: ${misc:Depends}, lsb-release, hwdata
 Description: Linux kernel version specific tools for version PKGVER
  This package provides the architecture independent parts for kernel
diff --git a/debian/rules b/debian/rules
index b1a133265836..d54ca276ec51 100755
--- a/debian/rules
+++ b/debian/rules
@@ -167,7 +167,8 @@ UBUNTU_COMPATIBLE_SIGNING=$(shell grep -qx ' *Subject: C = GB, ST = Isle of Man,
 # Misc stuff
 .PHONY: $(DEBIAN)/control.stub
 $(DEBIAN)/control.stub: debian/canonical-revoked-certs.pem $(DEBIAN)/changelog
-	debian/scripts/control-create $(DEB_SOURCE) > $(DEBIAN)/control.stub
+	debian/scripts/control-create $(DEB_SOURCE) $(do_tools_bpftool)         \
+		> $(DEBIAN)/control.stub
 	sed -i -e 's/PKGVER/$(DEB_VERSION_UPSTREAM)/g'                          \
 	        -e 's/ABINUM/$(abinum)/g'                                       \
 		-e 's/SRCPKGNAME/$(DEB_SOURCE)/g'                               \
diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
index 4f8b430978b8..76871445b622 100644
--- a/debian/rules.d/0-common-vars.mk
+++ b/debian/rules.d/0-common-vars.mk
@@ -135,6 +135,7 @@ ifneq ($(wildcard $(CURDIR)/tools),)
 else
 	do_tools?=false
 endif
+bpftool_pkg_name=bpftool
 tools_pkg_name=$(DEB_SOURCE)-tools-$(abi_release)
 tools_common_pkg_name=linux-tools-common
 tools_flavour_pkg_name=linux-tools-$(abi_release)
diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
index 1dc6bdc574c0..f6ef0890152c 100644
--- a/debian/rules.d/2-binary-arch.mk
+++ b/debian/rules.d/2-binary-arch.mk
@@ -111,6 +111,7 @@ $(stampdir)/stamp-install-%: signingv = $(CURDIR)/debian/$(bin_pkg_name)-signing
 $(stampdir)/stamp-install-%: toolspkgdir = $(CURDIR)/debian/$(tools_flavour_pkg_name)-$*
 $(stampdir)/stamp-install-%: cloudpkgdir = $(CURDIR)/debian/$(cloud_flavour_pkg_name)-$*
 $(stampdir)/stamp-install-%: bpfdevpkgdir = $(CURDIR)/debian/linux-bpf-dev
+$(stampdir)/stamp-install-%: bpftoolpkgdir = $(CURDIR)/debian/$(bpftool_pkg_name)
 $(stampdir)/stamp-install-%: basepkg = $(hdrs_pkg_name)
 $(stampdir)/stamp-install-%: baserustpkg = $(rust_pkg_name)
 $(stampdir)/stamp-install-%: indeppkg = $(indep_hdrs_pkg_name)
@@ -364,6 +365,11 @@ ifeq ($(do_linux_tools),true)
 			 $(bpfdevpkgdir)/usr/include/$(DEB_HOST_MULTIARCH)/linux/ ; \
 	fi
   endif
+  ifneq ($(filter $(bpftool_pkg_name),$(packages_enabled)),)
+	if [ $* = $(firstword $(flavours)) ] ; then \
+		install -d -m755 $(bpftoolpkgdir)/usr/sbin/ ; \
+	fi
+  endif
  endif
 endif
 
@@ -552,6 +558,11 @@ binary-%: dbgpkg = $(bin_pkg_name)-$*-dbgsym
 binary-%: dbgpkgdir = $(CURDIR)/debian/$(bin_pkg_name)-$*-dbgsym
 binary-%: pkgtools = $(tools_flavour_pkg_name)-$*
 binary-%: pkgcloud = $(cloud_flavour_pkg_name)-$*
+binary-%: BPFTOOL_VERSION_MAJOR = $(shell sed -ne 's,^#define LIBBPF_MAJOR_VERSION \(.*\)$$,\1,p' tools/lib/bpf/libbpf_version.h)
+binary-%: BPFTOOL_VERSION_MINOR = $(shell sed -ne 's,^#define LIBBPF_MINOR_VERSION \(.*\)$$,\1,p' tools/lib/bpf/libbpf_version.h)
+binary-%: BPFTOOL_VERSION_PATCH = $(shell sed -ne 's,^#define BPFTOOL_PATCH_VERSION \(.*\)$$,\1,p' tools/bpf/bpftool/main.c)
+binary-%: BPFTOOL_VERSION = $(shell expr $(BPFTOOL_VERSION_MAJOR) + 6).$(BPFTOOL_VERSION_MINOR).$(BPFTOOL_VERSION_PATCH)
+binary-%: BPFTOOL_GENCONTROL_ARGS = -v$(BPFTOOL_VERSION)+$(DEB_VERSION)
 $(foreach _m,$(all_dkms_modules), \
   $(eval binary-%: enable_$(_m) = $$(filter true,$$(call custom_override,do_$(_m),$$*))) \
 )
@@ -614,6 +625,11 @@ ifeq ($(do_linux_tools),true)
 		$(call dh_all_inline,linux-bpf-dev) ; \
 	fi
   endif
+  ifneq ($(filter $(bpftool_pkg_name),$(packages_enabled)),)
+	if [ $* = $(firstword $(flavours)) ] ; then \
+		$(call dh_all_inline,$(bpftool_pkg_name),$(BPFTOOL_GENCONTROL_ARGS)) ; \
+	fi
+  endif
  endif
 endif
 
@@ -679,6 +695,7 @@ endif
 .PHONY: install-perarch
 install-perarch: toolspkgdir = $(CURDIR)/debian/$(tools_pkg_name)
 install-perarch: cloudpkgdir = $(CURDIR)/debian/$(cloud_pkg_name)
+install-perarch: bpftoolpkgdir = $(CURDIR)/debian/$(bpftool_pkg_name)
 install-perarch: $(stampdir)/stamp-build-perarch
 	@echo Debug: $@
 	# Add the tools.
@@ -714,8 +731,9 @@ ifeq ($(do_tools_perf_python),true)
 endif
 endif # do_tools_perf
 ifeq ($(do_tools_bpftool),true)
+	install -d $(bpftoolpkgdir)/usr/sbin
 	install -m755 $(builddirpa)/tools/bpf/bpftool/bpftool \
-		$(toolspkgdir)/usr/lib/$(DEB_SOURCE)-tools-$(abi_release)
+		$(bpftoolpkgdir)/usr/sbin/bpftool
 endif
 ifeq ($(do_tools_x86),true)
 	install -m755 $(addprefix $(builddirpa)/tools/power/x86/, x86_energy_perf_policy/x86_energy_perf_policy turbostat/turbostat) \
@@ -737,6 +755,7 @@ endif # do_cloud_tools
 .PHONY: binary-perarch
 binary-perarch: toolspkg = $(tools_pkg_name)
 binary-perarch: cloudpkg = $(cloud_pkg_name)
+binary-perarch: bpftoolpkg = $(bpftool_pkg_name)
 binary-perarch: install-perarch
 	@echo Debug: $@
 ifeq ($(do_linux_tools),true)
@@ -745,6 +764,13 @@ endif
 ifeq ($(do_cloud_tools),true)
 	$(call dh_all,$(cloudpkg))
 endif
+ifeq ($(do_tools_bpftool),true)
+  ifneq ($(filter $(bpftoolpkg),$(packages_enabled)),)
+	if [ $* = $(firstword $(flavours)) ] ; then \
+		$(call dh_all_inline,$(bpftoolpkg)) ; \
+	fi
+  endif
+endif
 
 .PHONY: binary-debs
 binary-debs: binary-perarch $(addprefix binary-,$(flavours))
diff --git a/debian/rules.d/3-binary-indep.mk b/debian/rules.d/3-binary-indep.mk
index 72bcd37b53e8..d0f45e0db5af 100644
--- a/debian/rules.d/3-binary-indep.mk
+++ b/debian/rules.d/3-binary-indep.mk
@@ -53,6 +53,10 @@ endif
 endif
 
 .PHONY: install-tools
+install-tools: bpftoolpkg = $(bpftool_pkg_name)
+install-tools: bpftoolsbin = $(CURDIR)/debian/$(bpftoolpkg)/usr/sbin
+install-tools: bpftoolman = $(CURDIR)/debian/$(bpftoolpkg)/usr/share/man
+install-tools: bpftoolbashcomp = $(CURDIR)/debian/$(bpftoolpkg)/usr/share/bash-completion/completions
 install-tools: toolspkg = $(tools_common_pkg_name)
 install-tools: toolsbin = $(CURDIR)/debian/$(toolspkg)/usr/bin
 install-tools: toolssbin = $(CURDIR)/debian/$(toolspkg)/usr/sbin
@@ -97,13 +101,6 @@ ifeq ($(do_tools_common),true)
 
 	install -m755 debian/tools/generic $(toolsbin)/perf
 
-	install -m755 debian/tools/generic $(toolssbin)/bpftool
-	make -C $(builddir)/tools/tools/bpf/bpftool doc
-	install -m644 $(builddir)/tools/tools/bpf/bpftool/Documentation/*.8 \
-		$(toolsman)/man8
-	install -m644 $(builddir)/tools/tools/bpf/bpftool/bash-completion/bpftool \
-		$(toolsbashcomp)
-
 	install -m755 debian/tools/generic $(toolsbin)/x86_energy_perf_policy
 	install -m755 debian/tools/generic $(toolsbin)/turbostat
 
@@ -139,6 +136,19 @@ endif
 endif
 endif
 
+ifeq ($(do_tools_bpftool),true)
+	dh_prep -p$(bpftoolpkg)
+
+	install -d $(bpftoolsbin)
+	install -d $(bpftoolman)/man8
+	install -d $(bpftoolbashcomp)
+	make -C $(builddir)/tools/tools/bpf/bpftool doc
+	install -m644 $(builddir)/tools/tools/bpf/bpftool/Documentation/*.8 \
+		$(bpftoolman)/man8
+	install -m644 $(builddir)/tools/tools/bpf/bpftool/bash-completion/bpftool \
+		$(bpftoolbashcomp)
+endif
+
 ifeq ($(do_tools_acpidbg),true)
 	install -m755 debian/tools/generic $(toolsbin)/acpidbg
 endif
diff --git a/debian/scripts/control-create b/debian/scripts/control-create
index 87e5d248be27..c3ccd19ee65e 100755
--- a/debian/scripts/control-create
+++ b/debian/scripts/control-create
@@ -4,6 +4,7 @@ set -e
 shopt -s nullglob
 
 DEB_SOURCE=$1
+DO_TOOLS_BPFTOOL=false && (( $# > 1 )) && DO_TOOLS_BPFTOOL=$2
 
 . debian/debian.env
 
@@ -25,6 +26,11 @@ gen_common () {
 			debian/control.d/linux-doc.stub
 			debian/control.d/linux-bpf-dev.stub
 		)
+		if [ "${DO_TOOLS_BPFTOOL}" = true ]; then
+			stubs+=(
+				debian/control.d/bpftool.stub
+			)
+		fi
 	fi
 
 	for f in "${stubs[@]}"
-- 
2.43.0




More information about the kernel-team mailing list