Re: [PATCH v3] kbuild: rpm-pkg: Preserve .BTF section in kernel modules during debuginfo stripping

Yafang Shao <[email protected]> Sun, 26 Jul 2026 11:37:04 +0800
Newsgroups org.kernel.vger.linux-kbuild,dev.linux.lists.sashiko-reviews,org.kernel.vger.bpf
Message-ID <CALOAHbB0w+eK6Bxd+Lsb51Z5QVtnNv=4Srbb7KWcm6zAxgkTwA@mail.gmail.com>
On Sun, Jul 26, 2026 at 11:03=E2=80=AFAM <[email protected]> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential issu=
e(s) to consider:
> - [High] The patch preserves the `.BTF` section during debuginfo strippin=
g but fails to also preserve the `.BTF.base` section, causing module BTF va=
lidation to fail.
> --
>
> --- Patch [1]: [PATCH v3] kbuild: rpm-pkg: Preserve .BTF section in kerne=
l 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.
>
> > diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec
> > index c732415662ef2..1032f337a71cd 100644
> > --- a/scripts/package/kernel.spec
> > +++ b/scripts/package/kernel.spec
>
> [ ... ]
>
> > @@ -67,7 +67,17 @@ This package provides debug information for the kern=
el 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() beca=
use
> the module's .BTF was built with distilled IDs, ultimately resulting in t=
he
> module's BTF being rejected entirely.
>
> Could we add --keep-section .BTF.base here as well to ensure distilled BT=
F
> validation succeeds?

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

--=20
Regards
Yafang