BPF List
 help / color / mirror / Atom feed
* [PATCH v2] kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping
@ 2026-07-16  2:53 Yafang Shao
  2026-07-16  3:01 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Yafang Shao @ 2026-07-16  2:53 UTC (permalink / raw)
  To: nathan, nsc; +Cc: linux-kbuild, bpf, Yafang Shao

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

Assisted-by: Comagic:DeepSeek-V4-Flash
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 scripts/package/kernel.spec | 2 +-
 scripts/package/mkspec      | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

v1->v2: check if find-debuginfo.sh supports --keep-section (sashiko-bot)

diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec
index c732415662ef..2e16de54ed74 100644
--- a/scripts/package/kernel.spec
+++ b/scripts/package/kernel.spec
@@ -67,7 +67,7 @@ This package provides debug information for the kernel image and modules from th
 %undefine _unique_debug_srcs
 %undefine _debugsource_packages
 %undefine _debuginfo_subpackages
-%global _find_debuginfo_opts -r
+%global _find_debuginfo_opts -r%{?with_keep_section: --keep-section .BTF}
 %global _missing_build_ids_terminate_build 1
 %global _no_recompute_build_ids 1
 %{debug_package}
diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index c604f8c174e2..00acef348ba8 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -65,6 +65,11 @@ fi
 echo "%define with_debuginfo_manual $with_debuginfo_manual"
 echo "%define with_debuginfo_rpm $with_debuginfo_rpm"
 
+# Detect if find-debuginfo.sh supports --keep-section (RHEL 9+)
+if find-debuginfo.sh --help 2>&1 | grep -q keep-section; then
+	echo "%global with_keep_section 1"
+fi
+
 cat<<EOF
 %define ARCH ${ARCH}
 %define KERNELRELEASE ${KERNELRELEASE}
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping
  2026-07-16  2:53 [PATCH v2] kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping Yafang Shao
@ 2026-07-16  3:01 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-07-16  3:01 UTC (permalink / raw)
  To: Yafang Shao; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The check for `find-debuginfo.sh` capabilities in `mkspec` hardcodes host properties into `kernel.spec`, breaking SRPM portability across distributions and failing silently when the tool is not in `$PATH`.
--

--- Patch [1]: [PATCH v2] kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping ---
commit 99202060a54c32638e01a2bfdc4d23b190f3f77c
Author: Yafang Shao <laoar.shao@gmail.com>

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

This commit updates the RPM packaging scripts to pass --keep-section .BTF
to find-debuginfo.sh. This ensures that BTF information is preserved when
debuginfo is stripped from kernel modules.

> diff --git a/scripts/package/mkspec b/scripts/package/mkspec
> index c604f8c174e2c..00acef348ba84 100755
> --- a/scripts/package/mkspec
> +++ b/scripts/package/mkspec
[ ... ]
> @@ -65,6 +65,11 @@ fi
>  echo "%define with_debuginfo_manual $with_debuginfo_manual"
>  echo "%define with_debuginfo_rpm $with_debuginfo_rpm"
>  
> +# Detect if find-debuginfo.sh supports --keep-section (RHEL 9+)
> +if find-debuginfo.sh --help 2>&1 | grep -q keep-section; then
> +	echo "%global with_keep_section 1"
> +fi

[Severity: Medium]
Is it safe to assume find-debuginfo.sh is in the standard user $PATH?

On many systems, this script resides in /usr/lib/rpm/, which isn't typically
in the $PATH. This could cause the check to silently fail and strip the .BTF
section during a local make rpm-pkg build.

Also, since mkspec runs during SRPM generation (make srcrpm-pkg), doesn't
this statically bake the generation host's capabilities into the resulting
kernel.spec file?

If the SRPM is rebuilt on an older distribution, rpmbuild might fail because
the older script rejects the --keep-section argument. If generated on an
older host and built on a newer one, BTF info would be silently stripped.
Could we dynamically query the target host's capabilities using something
like %(__find_debuginfo) inside the spec file itself?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716025342.42628-1-laoar.shao@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-16  3:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16  2:53 [PATCH v2] kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping Yafang Shao
2026-07-16  3:01 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox