Skip to contentSkip to conversation

kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping

PATCH Superseded Yafang Shao 2 participants 3 messages Jul 26

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping

After switching to the kernel's default package scripts for our local kernel RPM builds, we noticed that module BTF entries were missing:

  $ ls /sys/kernel/btf/
  vmlinux    <<<< only vmlinux, no module BTF

Root cause: find-debuginfo.sh (from the debugedit package) prefers eu-strip over strip when elfutils is installed, which is the common case on RHEL 9. eu-strip removes non-allocated ELF sections, including the .BTF section that contains BPF Type Format information for kernel modules. Without .BTF, BPF tools (bpftool, bcc, bpftrace) cannot resolve kernel types at runtime, and /sys/kernel/btf/<module> entries are not created when modules are loaded.

Fix by passing --keep-section .BTF via _find_debuginfo_opts, which adds -K .BTF to the eu-strip/strip command, preserving the .BTF section while allowing normal debuginfo extraction to proceed.

After this change, all module BTF files are properly generated:

  $ ls /sys/kernel/btf/
  aesni_intel         drm                 i2c_i801            mfd_core
  ahci                drm_client_lib      i2c_mux             net_failover
  backlight           drm_kms_helper      i2c_smbus           pcspkr
  ccp                 drm_shmem_helper    input_leds          qemu_fw_cfg
  dm_log              failover            intel_rapl_common   sch_fq_codel
  dm_mirror           fat                 intel_rapl_msr      serio_raw
  dm_mod              fuse                irqbypass           sunrpc
  dm_region_hash      gf128mul            iTCO_wdt            vfat
  virtio_balloon      virtio_console      virtio_dma_buf      virtio_gpu
  virtio_net          virtio_rng          virtio_blk          vmlinux
  xfs
---
 scripts/package/kernel.spec | 10 ++++++++++
 1 file changed, 10 insertions(+)

v2->v3: use %{__find_debuginfo} (Nathan)
v1->v2: check if find-debuginfo.sh supports --keep-section (sashiko-bot)

scripts/package/kernel.spec +10 -0
index c732415662ef..1032f337a71c 100644
@@ -67,7 +67,17 @@ This package provides debug information for the kernel image and modules from th
 %undefine _unique_debug_srcs
 %undefine _debugsource_packages
 %undefine _debuginfo_subpackages
+
+# Preserve .BTF section in kernel modules during debuginfo stripping
+# find-debuginfo.sh (from debugedit) uses eu-strip which removes
+# non-allocated ELF sections like .BTF by default.
+%global with_keep_section %(%{__find_debuginfo} --help 2>&1 | grep -c keep-section)
+%if %{with_keep_section}
+%global _find_debuginfo_opts -r --keep-section .BTF
+%else
 %global _find_debuginfo_opts -r
+%endif
+
 %global _missing_build_ids_terminate_build 1
 %global _no_recompute_build_ids 1
 %{debug_package}
Signature · 1 line
2.52.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The patch preserves the `.BTF` section during debuginfo stripping but fails to also preserve the…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch preserves the .BTF section during debuginfo stripping but fails to also preserve the .BTF.base section, causing module BTF validation to fail. --

--- Patch [1]: [PATCH v3] kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping --- commit cd09ed46074d0224c00066939452278fca769e51
Author: Yafang Shao <[email protected]>
kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping

This commit updates the RPM build scripts to pass --keep-section .BTF to find-debuginfo.sh. This prevents eu-strip from dropping the .BTF section from kernel modules during debuginfo extraction.

Quoted 4 lines
scripts/package/kernel.spec +0 -0
index c732415662ef2..1032f337a71cd 100644

[ ... ]

scripts/package/kernel.spec This package provides debug information for the kernel image and modules from th · line 76

Quoted 11 lines
scripts/package/kernel.spec +7 -0
@@ -67,7 +67,17 @@ This package provides debug information for the kernel image and modules from th
 %undefine _unique_debug_srcs
 %undefine _debugsource_packages
 %undefine _debuginfo_subpackages
+
+# Preserve .BTF section in kernel modules during debuginfo stripping
+# find-debuginfo.sh (from debugedit) uses eu-strip which removes
+# non-allocated ELF sections like .BTF by default.
+%global with_keep_section %(%{__find_debuginfo} --help 2>&1 | grep -c keep-section)
+%if %{with_keep_section}
+%global _find_debuginfo_opts -r --keep-section .BTF

[Severity: High]
Does this also need to preserve the .BTF.base section?

When modules are built with BTF distillation (which is standard on recent kernels), both .BTF and .BTF.base sections are generated. If .BTF.base is stripped, btf_parse_module() in kernel/bpf/btf.c falls back to using the vmlinux_btf.

This fallback causes type ID mismatches during btf_check_all_metas() because the module's .BTF was built with distilled IDs, ultimately resulting in the module's BTF being rejected entirely.

Could we add --keep-section .BTF.base here as well to ensure distilled BTF validation succeeds?

Quoted 7 lines
scripts/package/kernel.spec +3 -0
+%else
 %global _find_debuginfo_opts -r
+%endif
+
 %global _missing_build_ids_terminate_build 1
 %global _no_recompute_build_ids 1
 %{debug_package}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 41 lines · On Sun, Jul 26, 2026 at 11:03 AM <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch preserves the .BTF section during debuginfo stripping but fails to also preserve the .BTF.base section, causing module BTF validation to fail. --

--- Patch [1]: [PATCH v3] kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping --- commit cd09ed46074d0224c00066939452278fca769e51
Author: Yafang Shao <[email protected]>
kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping

This commit updates the RPM build scripts to pass --keep-section .BTF to find-debuginfo.sh. This prevents eu-strip from dropping the .BTF section from kernel modules during debuginfo extraction.

Quoted 4 lines
scripts/package/kernel.spec +0 -0
index c732415662ef2..1032f337a71cd 100644

[ ... ]

scripts/package/kernel.spec This package provides debug information for the kernel image and modules from th · line 76

Quoted 11 lines
scripts/package/kernel.spec +7 -0
@@ -67,7 +67,17 @@ This package provides debug information for the kernel image and modules from th
 %undefine _unique_debug_srcs
 %undefine _debugsource_packages
 %undefine _debuginfo_subpackages
+
+# Preserve .BTF section in kernel modules during debuginfo stripping
+# find-debuginfo.sh (from debugedit) uses eu-strip which removes
+# non-allocated ELF sections like .BTF by default.
+%global with_keep_section %(%{__find_debuginfo} --help 2>&1 | grep -c keep-section)
+%if %{with_keep_section}
+%global _find_debuginfo_opts -r --keep-section .BTF

[Severity: High]
Does this also need to preserve the .BTF.base section?

When modules are built with BTF distillation (which is standard on recent kernels), both .BTF and .BTF.base sections are generated. If .BTF.base is stripped, btf_parse_module() in kernel/bpf/btf.c falls back to using the vmlinux_btf.

Quoted 6 lines

This fallback causes type ID mismatches during btf_check_all_metas() because the module's .BTF was built with distilled IDs, ultimately resulting in the module's BTF being rejected entirely.

Could we add --keep-section .BTF.base here as well to ensure distilled BTF validation succeeds?

You're right. .BTF.base should also be preserved. I'll update it.

Signature · 2 lines
Regards
Yafang