Skip to contentSkip to conversation

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

PATCH Superseded Yafang Shao 3 participants 6 messages Jul 16 – Jul 24

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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
Assisted-by Comagic:DeepSeek-V4-Flash
---
 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)

scripts/package/kernel.spec +1 -1
index c732415662ef..2e16de54ed74 100644
@@ -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}
scripts/package/mkspec +5 -0
index c604f8c174e2..00acef348ba8 100755
@@ -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}
Signature · 1 line
2.52.0
#1 lore raw
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…

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 <[email protected]>

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.

Quoted 4 lines
scripts/package/mkspec +0 -0
index c604f8c174e2c..00acef348ba84 100755

[ ... ]

scripts/package/mkspec fi · line 71

Quoted 8 lines
scripts/package/mkspec +4 -0
@@ -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?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 40 lines · On Thu, Jul 16, 2026 at 11:01 AM <[email protected]> wrote:

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 <[email protected]>

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.

Quoted 4 lines
scripts/package/mkspec +0 -0
index c604f8c174e2c..00acef348ba84 100755

[ ... ]

scripts/package/mkspec fi · line 71

Quoted 8 lines
scripts/package/mkspec +4 -0
@@ -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?

Quoted 8 lines

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/[email protected]?part=1

I believe we could use the builtin _rpmconfigdir to locate find-debuginfo.sh reliably. This avoids relying on $PATH. What do you think about the following change?

scripts/package/kernel.spec +0 -0
index c732415662ef..4335e99f2aca 100644
@@ -67,7 +67,21 @@ 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.
+# --keep-section .BTF preserves BPF Type Format information.
+#
+# Uses _rpmconfigdir for reliable script location instead of relying on $PATH. +%{!?with_keep_section:%global __fd %{_rpmconfigdir}/find-debuginfo.sh} +%{!?with_keep_section:%global with_keep_section %(%{__fd} --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}

Please let me know if this approach works or if there are any concerns.

Signature · 2 lines
Regards
Yafang
#3 lore raw
Quoted 47 lines · Yafang Shao
Quoted 46 lines · On Thu, Jul 16, 2026 at 11:01 AM <[email protected]> wrote:

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 <[email protected]>

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.

Quoted 4 lines
scripts/package/mkspec +0 -0
index c604f8c174e2c..00acef348ba84 100755

[ ... ]

scripts/package/mkspec fi · line 71

Quoted 8 lines
scripts/package/mkspec +4 -0
@@ -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?

Quoted 6 lines
Quoted 2 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

I believe we could use the builtin _rpmconfigdir to locate find-debuginfo.sh reliably. This avoids relying on $PATH. What do you think about the following change?

Just an FYI, this was not sent to anyone with authority to comment on said change, as the Kbuild folks were not included in the AI review thread. I just happened to find this when browsing the archives.

Quoted 29 lines
scripts/package/kernel.spec +0 -0
index c732415662ef..4335e99f2aca 100644
@@ -67,7 +67,21 @@ This package provides debug information for the

kernel image and modules from th
%undefine _unique_debug_srcs
%undefine _debugsource_packages
%undefine _debuginfo_subpackages

scripts/package/kernel.spec +9 -0
+
+# 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.
+# --keep-section .BTF preserves BPF Type Format information.
+#
+# Uses _rpmconfigdir for reliable script location instead of relying on $PATH.
+%{!?with_keep_section:%global __fd %{_rpmconfigdir}/find-debuginfo.sh}
+%{!?with_keep_section:%global with_keep_section %(%{__fd} --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}

Quoted 1 line

Please let me know if this approach works or if there are any concerns.

/usr/lib/rpm/find-debuginfo.sh might not exist on certain distributions that can build .rpm packages like Arch Linux:

  $ ls -l /usr/lib/rpm/find-debuginfo.sh
  "/usr/lib/rpm/find-debuginfo.sh": No such file or directory (os error 2)

Even on modern Fedora, this is a symlink:

  $ ls -l /usr/lib/rpm/find-debuginfo.sh
  lrwxrwxrwx@ - root 19 Jul 17:00 /usr/lib/rpm/find-debuginfo.sh -> ../../bin/find-debuginfo

I think we would be better off just using the __find_debuginfo rpm macro:

  $ rg -m 1 find-debuginfo /usr/lib/rpm/macros
  69:%__find_debuginfo    /usr/bin/find-debuginfo

This appears to work for me, it would be good if you can confirm this works for you as well.

scripts/package/kernel.spec +10 -0
index c732415662ef..590b5b2e1b40 100644
@@ -67,7 +67,18 @@ 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 · 2 lines
Cheers,
Nathan
#4 lore raw
Quoted 52 lines · Nathan Chancellor
Quoted 50 lines · Yafang Shao
Quoted 48 lines · On Thu, Jul 16, 2026 at 11:01 AM <[email protected]> wrote:

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 <[email protected]>

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.

Quoted 4 lines
scripts/package/mkspec +0 -0
index c604f8c174e2c..00acef348ba84 100755

[ ... ]

scripts/package/mkspec fi · line 71

Quoted 8 lines
scripts/package/mkspec +4 -0
@@ -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/[email protected]?part=1

Quoted 7 lines
Quoted 3 lines

I believe we could use the builtin _rpmconfigdir to locate find-debuginfo.sh reliably. This avoids relying on $PATH. What do you think about the following change?

Just an FYI, this was not sent to anyone with authority to comment on said change, as the Kbuild folks were not included in the AI review thread. I just happened to find this when browsing the archives.

My apologies, I failed to notice that the linux-kbuild mailing list was excluded from Sashiko's reply.

Quoted 64 lines
Quoted 30 lines
scripts/package/kernel.spec +0 -0
index c732415662ef..4335e99f2aca 100644
@@ -67,7 +67,21 @@ This package provides debug information for the

kernel image and modules from th
%undefine _unique_debug_srcs
%undefine _debugsource_packages
%undefine _debuginfo_subpackages

scripts/package/kernel.spec +9 -0
+
+# 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.
+# --keep-section .BTF preserves BPF Type Format information.
+#
+# Uses _rpmconfigdir for reliable script location instead of relying on $PATH.
+%{!?with_keep_section:%global __fd %{_rpmconfigdir}/find-debuginfo.sh}
+%{!?with_keep_section:%global with_keep_section %(%{__fd} --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}

Quoted 1 line

Please let me know if this approach works or if there are any concerns.

/usr/lib/rpm/find-debuginfo.sh might not exist on certain distributions that can build .rpm packages like Arch Linux:

  $ ls -l /usr/lib/rpm/find-debuginfo.sh
  "/usr/lib/rpm/find-debuginfo.sh": No such file or directory (os error 2)

Even on modern Fedora, this is a symlink:

  $ ls -l /usr/lib/rpm/find-debuginfo.sh
  lrwxrwxrwx@ - root 19 Jul 17:00 /usr/lib/rpm/find-debuginfo.sh -> ../../bin/find-debuginfo

I think we would be better off just using the __find_debuginfo rpm macro:

  $ rg -m 1 find-debuginfo /usr/lib/rpm/macros
  69:%__find_debuginfo    /usr/bin/find-debuginfo

This appears to work for me, it would be good if you can confirm this works for you as well.

scripts/package/kernel.spec +4 -0
index c732415662ef..590b5b2e1b40 100644
@@ -67,7 +67,18 @@ 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.

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

Quoted 10 lines
scripts/package/kernel.spec +6 -0
+%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}

This works for me, thanks for the improvement.
Do you plan to send the official patch, or would you like me to send a new version?

Signature · 2 lines
Regards
Yafang
#5 lore raw
Quoted 57 lines · Yafang Shao
Quoted 56 lines · Nathan Chancellor
Quoted 53 lines · Yafang Shao
Quoted 40 lines · On Thu, Jul 16, 2026 at 11:01 AM <[email protected]> wrote:

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 <[email protected]>

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.

Quoted 4 lines
scripts/package/mkspec +0 -0
index c604f8c174e2c..00acef348ba84 100755

[ ... ]

scripts/package/mkspec fi · line 71

Quoted 8 lines
scripts/package/mkspec +4 -0
@@ -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?

Quoted 8 lines

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/[email protected]?part=1

I believe we could use the builtin _rpmconfigdir to locate find-debuginfo.sh reliably. This avoids relying on $PATH. What do you think about the following change?

Quoted 6 lines
Quoted 3 lines

Just an FYI, this was not sent to anyone with authority to comment on said change, as the Kbuild folks were not included in the AI review thread. I just happened to find this when browsing the archives.

My apologies, I failed to notice that the linux-kbuild mailing list was excluded from Sashiko's reply.

No problem at all, I just wanted to make it obvious why you may not have gotten a response to your suggestion and for this issue to get lost.

Quoted 69 lines
Quoted 69 lines
Quoted 29 lines
scripts/package/kernel.spec +0 -0
index c732415662ef..4335e99f2aca 100644
@@ -67,7 +67,21 @@ This package provides debug information for the

kernel image and modules from th
%undefine _unique_debug_srcs
%undefine _debugsource_packages
%undefine _debuginfo_subpackages

scripts/package/kernel.spec +9 -0
+
+# 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.
+# --keep-section .BTF preserves BPF Type Format information.
+#
+# Uses _rpmconfigdir for reliable script location instead of relying on $PATH.
+%{!?with_keep_section:%global __fd %{_rpmconfigdir}/find-debuginfo.sh}
+%{!?with_keep_section:%global with_keep_section %(%{__fd} --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}

Quoted 1 line

Please let me know if this approach works or if there are any concerns.

/usr/lib/rpm/find-debuginfo.sh might not exist on certain distributions that can build .rpm packages like Arch Linux:

  $ ls -l /usr/lib/rpm/find-debuginfo.sh
  "/usr/lib/rpm/find-debuginfo.sh": No such file or directory (os error 2)

Even on modern Fedora, this is a symlink:

  $ ls -l /usr/lib/rpm/find-debuginfo.sh
  lrwxrwxrwx@ - root 19 Jul 17:00 /usr/lib/rpm/find-debuginfo.sh -> ../../bin/find-debuginfo

I think we would be better off just using the __find_debuginfo rpm macro:

  $ rg -m 1 find-debuginfo /usr/lib/rpm/macros
  69:%__find_debuginfo    /usr/bin/find-debuginfo

This appears to work for me, it would be good if you can confirm this works for you as well.

scripts/package/kernel.spec +9 -0
index c732415662ef..590b5b2e1b40 100644
@@ -67,7 +67,18 @@ 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
Quoted 8 lines

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

Quoted 4 lines
scripts/package/kernel.spec +1 -0
+
 %global _missing_build_ids_terminate_build 1
 %global _no_recompute_build_ids 1
 %{debug_package}

This works for me, thanks for the improvement.
Do you plan to send the official patch, or would you like me to send a new version?

You can send a new version, as your message makes it clear what is going on here. If you feel so inclined, you can add a Suggested-by tag but I don't think this is substantially different from what you suggested.

Signature · 2 lines
Cheers,
Nathan