linux: add DEBUG_INFO_BTF
I'd like to see BTF enabled in the kernel.
Rationales are:
- (not a great one, but) it's enabled on archlinux https://git.archlinux.org/svntogit/packages.git/tree/trunk/config?h=packages/linux#n9939 , debian https://salsa.debian.org/kernel-team/linux/-/blob/master/debian/config/amd64/config#L231 , rhel variants (fedora & centos 8)...
- It would allow using bpftrace and other bcc tools more easily without requiring to install a large debug kernel and all header files; in particular bcc's libbpf-tools can be compiled down to ~hundred of KBs and copied on other systems even if the kernel is not the same which is great for embedded systems.
- The final size increase is (probably) tiny enough to accept (100-600KB) -- it will become slightly bigger once modules BTF types also get stored but should remain reasonable (not tested with alpine config, but would expect a total increase of about 2MB for the lts kernel)
For x86_64 this can be done with the patch included at the end, which has the following problems:
- pahole is very new (I just submitted it a few weeks ago) and in testing/, so we can't use it for kernel in main/...
- the strip-debug has to be added because DEBUG_INFO_BTF requires DEBUG_INFO, which would otherwise bloat the modules (packages become as big as 1 to 4GB if not stripped...!)
- the final size increase after stripping is negligible, but the build directory before strip is much bigger and compilation time increases as well; here are the sizes/time on my laptop
### baseline with kernel 5.10.23 and current options
real 3h 2m 10s
user 4h 40m 38s
sys 1h 33m 29s
259.0M pkg/linux-lts
131.2M pkg/linux-lts-dev
76.1M pkg/linux-virt
125.8M pkg/linux-virt-dev
2.2G src/build-lts.x86_64
889.3M src/build-virt.x86_64
### just enabling btf, without stripping modules
### (should consider this size for build directories max size)
real 3h 51m 41s
user 5h 47m 34s
sys 1h 38m 06s
4.1G pkg/linux-lts
142.9M pkg/linux-lts-dev
1.1G pkg/linux-virt
137.4M pkg/linux-virt-dev
13.8G src/build-lts.x86_64
5.1G src/build-virt.x86_64
### btf enabled and modules stripped
real 3h 34m 08s
user 5h 26m 08s
sys 1h 48m 57s
259.6M linux-lts
142.9M linux-lts-dev
76.2M linux-virt
137.4M linux-virt-dev
10.0G src/build-lts.x86_64
4.1G src/build-virt.x86_64
- (the config diff is actually from a newer kernel, it works but DEBUG_INFO_BTF_MODULES won't be used before 5.11 -- and I need to check how that will work with strip at that point, haven't looked yet.)
- quite some bpf-related utilities require bpftool from linux sources, which will need to be added to linux-tools on alpine -- I've started looking at it but they use nftw with flags incompatible with musl; I've sent the musl list an implementation here: https://www.openwall.com/lists/musl/2021/03/26/1 - depending on their reply (or lack of thereof) I will then submit a patch upstream first so inclusion in alpine might take a while if it depends on me, but it should get there eventually.
- (bpftrace also requires !19903 (merged) to use BTF, but that shouldn't be a problem)
The main blocker is, in my opinion, pahole, which is why I'm just opening an issue for now, but assuming pahole is present the rest works.
From 9080b09cde9a815118ee33d75d71945be68bcf0f Mon Sep 17 00:00:00 2001
From: Dominique Martinet <dominique.martinet@atmark-techno.com>
Date: Tue, 30 Mar 2021 11:41:52 +0900
Subject: [PATCH] linux: enable BTF
diff --git a/main/linux-lts/APKBUILD b/main/linux-lts/APKBUILD
index 275d2c684dcc..c430d4cf3bd3 100644
--- a/main/linux-lts/APKBUILD
+++ b/main/linux-lts/APKBUILD
@@ -13,7 +13,7 @@ url="https://www.kernel.org"
depends="mkinitfs"
_depends_dev="perl gmp-dev elfutils-dev bash flex bison"
makedepends="$_depends_dev sed installkernel bc linux-headers linux-firmware-any openssl-dev
- diffutils findutils"
+ diffutils findutils pahole python3"
options="!strip"
_config=${config:-config-lts.${CARCH}}
install=
@@ -146,6 +146,8 @@ _package() {
*) _install=install;;
esac
+ find . -type f -name "*.ko" -exec strip --strip-debug {} +
+
make -j1 modules_install $_install \
ARCH="$_carch" \
INSTALL_MOD_PATH="$_outdir" \
diff --git a/main/linux-lts/config-lts.x86_64 b/main/linux-lts/config-lts.x86_64
index d6c220a1f120..4f42882527ae 100644
--- a/main/linux-lts/config-lts.x86_64
+++ b/main/linux-lts/config-lts.x86_64
@@ -8959,7 +8959,16 @@ CONFIG_DEBUG_BUGVERBOSE=y
#
# Compile-time checks and compiler options
#
-# CONFIG_DEBUG_INFO is not set
+CONFIG_DEBUG_INFO=y
+# CONFIG_DEBUG_INFO_REDUCED is not set
+# CONFIG_DEBUG_INFO_COMPRESSED is not set
+# CONFIG_DEBUG_INFO_SPLIT is not set
+CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
+# CONFIG_DEBUG_INFO_DWARF4 is not set
+CONFIG_DEBUG_INFO_BTF=y
+CONFIG_PAHOLE_HAS_SPLIT_BTF=y
+CONFIG_DEBUG_INFO_BTF_MODULES=y
+# CONFIG_GDB_SCRIPTS is not set
# CONFIG_ENABLE_MUST_CHECK is not set
CONFIG_FRAME_WARN=1280
# CONFIG_STRIP_ASM_SYMS is not set
diff --git a/main/linux-lts/config-virt.x86_64 b/main/linux-lts/config-virt.x86_64
index aa453b4a7cd4..f34c66922fdf 100644
--- a/main/linux-lts/config-virt.x86_64
+++ b/main/linux-lts/config-virt.x86_64
@@ -4628,7 +4628,16 @@ CONFIG_DEBUG_BUGVERBOSE=y
#
# Compile-time checks and compiler options
#
-# CONFIG_DEBUG_INFO is not set
+CONFIG_DEBUG_INFO=y
+# CONFIG_DEBUG_INFO_REDUCED is not set
+# CONFIG_DEBUG_INFO_COMPRESSED is not set
+# CONFIG_DEBUG_INFO_SPLIT is not set
+CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
+# CONFIG_DEBUG_INFO_DWARF4 is not set
+CONFIG_DEBUG_INFO_BTF=y
+CONFIG_PAHOLE_HAS_SPLIT_BTF=y
+CONFIG_DEBUG_INFO_BTF_MODULES=y
+# CONFIG_GDB_SCRIPTS is not set
# CONFIG_ENABLE_MUST_CHECK is not set
CONFIG_FRAME_WARN=1280
# CONFIG_STRIP_ASM_SYMS is not set