[2/2] strip debug information from kernel modules

Message ID 20240913151642.374093-2-felix.moessbauer@siemens.com
State Under Review
Headers show
Series [1/2] make kernel module build reproducible | expand

Commit Message

MOESSBAUER, Felix Sept. 13, 2024, 3:16 p.m. UTC
If not requested otherwise (e.g. via DEB_BUILD_OPTIONS=nostrip), strip
the debug information from the kernel module. This significantly reduces
the size of the .ko file. As the stripping needs to happen prior to
compression and signing, we need to do it during the build step.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/recipes-kernel/linux-module/files/debian/rules.tmpl | 3 +++
 meta/recipes-kernel/linux-module/module.inc              | 2 ++
 2 files changed, 5 insertions(+)

Patch

diff --git a/meta/recipes-kernel/linux-module/files/debian/rules.tmpl b/meta/recipes-kernel/linux-module/files/debian/rules.tmpl
index 7511a17d..ad743437 100755
--- a/meta/recipes-kernel/linux-module/files/debian/rules.tmpl
+++ b/meta/recipes-kernel/linux-module/files/debian/rules.tmpl
@@ -50,6 +50,9 @@  override_dh_auto_clean:
 
 override_dh_auto_build:
 	$(MAKE) -C $(KDIR) M=${MODULE_DIR} $(PARALLEL_MAKE) KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" modules
+ifeq ($(filter nostrip,$(DEB_BUILD_OPTIONS)),)
+	find . -name "*.ko" -print -exec strip --strip-debug --remove-section=.note.gnu.build-id {} \;
+endif
 ifneq ($(filter pkg.sign,$(DEB_BUILD_PROFILES)),)
 	find . -name "*.ko" -print -exec $(KDIR)/scripts/sign-file ${SIGNATURE_HASHFN} ${SIGNATURE_KEYFILE} ${SIGNATURE_CERTFILE} {} \;
 endif
diff --git a/meta/recipes-kernel/linux-module/module.inc b/meta/recipes-kernel/linux-module/module.inc
index 344dc50f..1734816b 100644
--- a/meta/recipes-kernel/linux-module/module.inc
+++ b/meta/recipes-kernel/linux-module/module.inc
@@ -19,6 +19,8 @@  KERNEL_IMAGE_PKG ??= "linux-image-${KERNEL_NAME}"
 KERNEL_HEADERS_PKG ??= "linux-headers-${KERNEL_NAME}"
 DEPENDS += "${KERNEL_HEADERS_PKG}-native"
 DEBIAN_BUILD_DEPENDS = "${KERNEL_HEADERS_PKG}"
+# Do not generate debug symbols packages, as not supported for modules
+DEB_BUILD_OPTIONS += "noautodbgsym"
 
 SIGNATURE_KEYFILE ??= ""
 SIGNATURE_CERTFILE ??= ""