kbuild: rpm-pkg: improve debuggability
cover kbuild: rpm-pkg: improve debuggability
This patch set aims to improve debuggability of kernels packaged using the rpm-pkg target by producing debuginfo and debugsource RPMs that contain a full set of debugging information for the kernel. The preexisting kernel-%{KERNELRELEASE} RPM is also shrunk by moving all debuginfo out of it into the new debuginfo RPM.
The first patch is just a bit of cleanup to keep rpmbuild happy, and the second patch contains the main work.
This is technically a v2 for the following patch, but since it's been a while I didn't mark it as such
https://lore.kernel.org/linux-kbuild/[email protected]/
---
Uday Shankar (2):
scripts: make python shebangs specific about desired version
kbuild: rpm-pkg: build debuginfo and debugsource RPMs
scripts/package/kernel.spec | 31 +++++++++++++++++++++++++++++-- scripts/package/mkspec | 3 +++ scripts/show_delta | 2 +- scripts/tracing/draw_functrace.py | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-)
---
base-commit: a64dcfb451e254085a7daee5fe51bf22959d52d3
change-id: 20250209-debuginfo-cd3d9417af21
Best regards,
Signature · 1 line
Uday Shankar <[email protected]>
PATCH 1/2 scripts: make python shebangs specific about desired version
The RPM packaging tools like to make sure that all packaged python scripts have version-unambiguous shebangs. Be more specific about the desired python version in a couple of places to avoid having to disable these checks in make rpm-pkg.
--- scripts/show_delta | 2 +- scripts/tracing/draw_functrace.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
scripts/show_delta +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only # # show_deltas: Read list of printk messages instrumented with
scripts/tracing/draw_functrace.py +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only """
Signature · 1 line
2.34.1
Steven Rostedt
maintainerRe: [PATCH 1/2] scripts: make python shebangs specific about desired version
scripts/tracing/draw_functrace.py line 2
Quoted 8 lines · On Mon, 10 Feb 2025 18:11:54 -0700 Uday Shankar <[email protected]>…
scripts/tracing/draw_functrace.py +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only
Does anyone actually use this script?
If not, I wonder if we should just remove it.
Frederic?
-- Steve
Re: [PATCH 1/2] scripts: make python shebangs specific about desired version
In reply to Uday ShankarQuoted 7 lines · Uday Shankar
The RPM packaging tools like to make sure that all packaged python scripts have version-unambiguous shebangs. Be more specific about the desired python version in a couple of places to avoid having to disable these checks in make rpm-pkg.
Signed-off-by Uday Shankar <[email protected]>
Applied to linux-kbuild.
Thanks.
Quoted 27 lines
--- scripts/show_delta | 2 +- scripts/tracing/draw_functrace.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)scripts/show_delta +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only # # show_deltas: Read list of printk messages instrumented withscripts/tracing/draw_functrace.py +1
-2@@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only """ --
Quoted 3 lines
2.34.1
--
Best Regards
Masahiro Yamada
PATCH 2/2 kbuild: rpm-pkg: build debuginfo and debugsource RPMs
In reply to Uday ShankarThe rpm-pkg make target currently suffers from a few issues related to debuginfo:
1. debuginfo for things built into the kernel (vmlinux) is not available in any RPM produced by make rpm-pkg. This makes using tools like systemtap against a make rpm-pkg kernel impossible.
2. debug source for the kernel is not available. This means that commands like 'disas /s' in gdb, which display source intermixed with assembly, can only print file names/line numbers which then must be painstakingly resolved to actual source in a separate editor.
3. debuginfo for modules is available, but it remains bundled with the .ko files that contain module code, in the kernel-%{KERNELRELEASE} RPM. This is a waste of space for users who do not need to debug the kernel (i.e. most users).
Address all of these issues by additionally building debuginfo and debugsource RPMs when CONFIG_DEBUG_INFO=y is set, in line with standard patterns followed by most distribution packages. With these changes:
1. systemtap now works (when these changes are backported to 6.11, since systemtap lags a bit behind in compatibility), as verified by the following simple test script:
# stap -e 'probe kernel.function("do_sys_open").call { printf("%s\n", $$parms); }'
dfd=0xffffffffffffff9c filename=0x7fe18800b160 flags=0x88800 mode=0x0
...2. disas /s works correctly in gdb, with source and disassembly interspersed:
# gdb vmlinux --batch -ex 'disas /s blk_op_str'
Dump of assembler code for function blk_op_str:
block/blk-core.c:
125 {
0xffffffff814c8740 <+0>: endbr64 127
128 if (op < ARRAY_SIZE(blk_op_name) && blk_op_name[op])
0xffffffff814c8744 <+4>: mov $0xffffffff824a7378,%rax
0xffffffff814c874b <+11>: cmp $0x23,%edi
0xffffffff814c874e <+14>: ja 0xffffffff814c8768 <blk_op_str+40>
0xffffffff814c8750 <+16>: mov %edi,%edi
126 const char *op_str = "UNKNOWN";
0xffffffff814c8752 <+18>: mov $0xffffffff824a7378,%rdx
127
128 if (op < ARRAY_SIZE(blk_op_name) && blk_op_name[op])
0xffffffff814c8759 <+25>: mov -0x7dfa0160(,%rdi,8),%rax
126 const char *op_str = "UNKNOWN";
0xffffffff814c8761 <+33>: test %rax,%rax
0xffffffff814c8764 <+36>: cmove %rdx,%rax 129 op_str = blk_op_name[op];
130
131 return op_str;
132 }
0xffffffff814c8768 <+40>: jmp 0xffffffff81d01360 <__x86_return_thunk>
End of assembler dump.
3. The size of the kernel-%{KERNELRELEASE} package goes down substantially. Here is a comparison of installed size of the kernel-%{KERNELRELEASE} package (configured with allmodconfig, dwarf4 debuginfo, and module compression turned off) before and after this patch:
# rpm -qi kernel-6.13* | grep -E '^(Version|Size)' Version : 6.13.0postpatch+ Size : 1382874089 Version : 6.13.0prepatch+ Size : 17870795887
This is a ~92% size reduction.
Note that this feature is incompatible with CONFIG_MODULE_COMPRESS - if it is turned on, the module .ko files are compressed before find-debuginfo.sh sees them, and it will not be able to extract debuginfo from them. There are two potential paths forward here:
- teach find-debuginfo.sh to extract debuginfo from compressed kernel modules
- teach the kernel build process to produce split debuginfo and then package that directly, bypassing find-debuginfo.sh
But leaving CONFIG_MODULE_COMPRESS off seems common, so taking this patch as is still feels useful.
--- scripts/package/kernel.spec | 31 +++++++++++++++++++++++++++++-- scripts/package/mkspec | 3 +++ 2 files changed, 32 insertions(+), 2 deletions(-)
scripts/package/kernel.spec +29 -2
@@ -2,8 +2,6 @@ %{!?_arch: %define _arch dummy} %{!?make: %define make make} %define makeflags %{?_smp_mflags} ARCH=%{ARCH} -%define __spec_install_post /usr/lib/rpm/brp-compress || : -%define debug_package %{nil} Name: kernel Summary: The Linux Kernel
@@ -46,6 +44,24 @@ This package provides kernel headers and makefiles sufficient to build modules against the %{version} kernel package. %endif +%if %{with_debuginfo} +# list of debuginfo-related options taken from distribution spec files +%undefine _include_minidebuginfo +%undefine _find_debuginfo_dwz_opts +%undefine _unique_build_ids +%undefine _unique_debug_names +%undefine _unique_debug_srcs +%undefine _debuginfo_subpackages +%global _find_debuginfo_opts -r +%global _missing_build_ids_terminate_build 1 +%global _no_recompute_build_ids 1 +%{debug_package} +%endif +# some (but not all) versions of rpmbuild emit %%debug_package with +# %%install. since we've already emitted it manually, that would cause +# a package redefinition error. ensure that doesn't happen +%define debug_package %{nil} + %prep %setup -q -n linux cp %{SOURCE1} .config
@@ -89,8 +105,19 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA echo "%exclude /lib/modules/%{KERNELRELEASE}/build" } > %{buildroot}/kernel.list +# make modules executable so that find-debuginfo.sh strips them +find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \ + | xargs --no-run-if-empty chmod u+x + +%if %{with_debuginfo} +mkdir -p %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE} +cp vmlinux %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE} +%endif + %clean rm -rf %{buildroot} +rm -f debugfiles.list debuglinks.list debugsourcefiles.list debugsources.list \ + elfbins.list %post if [ -x /usr/bin/kernel-install ]; then
scripts/package/mkspec +3 -0
@@ -23,6 +23,9 @@ else echo '%define with_devel 0' fi +WITH_DEBUGINFO=$(grep -c CONFIG_DEBUG_INFO=y include/config/auto.conf) +echo "%define with_debuginfo ${WITH_DEBUGINFO}" + cat<<EOF %define ARCH ${ARCH} %define KERNELRELEASE ${KERNELRELEASE}
Signature · 1 line
2.34.1
Re: [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs
Sorry for the long delay.
Quoted 8 lines · Uday Shankar
Note that this feature is incompatible with
CONFIG_MODULE_COMPRESS- if it is turned on, the module .ko files are compressed beforefind-debuginfo.shsees them, and it will not be able to extract debuginfo from them. There are two potential paths forward here:
- teachfind-debuginfo.shto extract debuginfo from compressed kernel modules
- teach the kernel build process to produce split debuginfo and then package that directly, bypassingfind-debuginfo.sh
'make bindeb-pkg' (Debian package) is able to build the debug package with CONFIG_MODULE_COMPRESS enabled.
(see scripts/package/builddeb if you are interested)
I have not checked if this works for 'make binrpm-pkg' or not. If this is a tricky case, I am OK with giving up CONFIG_MODULE_COMPRESS.
Quoted 48 lines
But leaving
CONFIG_MODULE_COMPRESSoff seems common, so taking this patch as is still feels useful.Signed-off-by Uday Shankar <[email protected]>--- scripts/package/kernel.spec | 31 +++++++++++++++++++++++++++++-- scripts/package/mkspec | 3 +++ 2 files changed, 32 insertions(+), 2 deletions(-)scripts/package/kernel.spec +18
-2@@ -2,8 +2,6 @@ %{!?_arch: %define _arch dummy} %{!?make: %define make make} %define makeflags %{?_smp_mflags} ARCH=%{ARCH} -%define __spec_install_post /usr/lib/rpm/brp-compress || : -%define debug_package %{nil} Name: kernel Summary: The Linux Kernel@@ -46,6 +44,24 @@ This package provides kernel headers and makefiles sufficient to build modules against the %{version} kernel package. %endif +%if %{with_debuginfo} +# list of debuginfo-related options taken from distribution spec files +%undefine _include_minidebuginfo +%undefine _find_debuginfo_dwz_opts +%undefine _unique_build_ids +%undefine _unique_debug_names +%undefine _unique_debug_srcs +%undefine _debuginfo_subpackages +%global _find_debuginfo_opts -r +%global _missing_build_ids_terminate_build 1 +%global _no_recompute_build_ids 1 +%{debug_package} +%endif +# some (but not all) versions of rpmbuild emit %%debug_package with +# %%install. since we've already emitted it manually, that would cause +# a package redefinition error. ensure that doesn't happen +%define debug_package %{nil} + %prep %setup -q -n linux cp %{SOURCE1} .config
scripts/package/kernel.spec ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA · line 110
Quoted 6 lines
scripts/package/kernel.spec +3
-0@@ -89,8 +105,19 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA echo "%exclude /lib/modules/%{KERNELRELEASE}/build" } > %{buildroot}/kernel.list +# make modules executable so that find-debuginfo.sh strips them +find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \ + | xargs --no-run-if-empty chmod u+x
This seems necessary and correct.
One side-effect I noticed is that *.ko under /lib/modules/$(uname -r)/ now have +x permissions. (Previously, they were non-executables).
I checked Fedora. Modules under /lib/modules/$(uname -r)/ do not have +x permissions.
Do you know how Fedora's kernel.spec handles this?
Quoted 18 lines
scripts/package/kernel.spec +8
-0+ +%if %{with_debuginfo} +mkdir -p %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE} +cp vmlinux %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE} +%endif + %clean rm -rf %{buildroot} +rm -f debugfiles.list debuglinks.list debugsourcefiles.list debugsources.list \ + elfbins.list %post if [ -x /usr/bin/kernel-install ]; thenscripts/package/mkspec +0
-0
scripts/package/mkspec else · line 28
Quoted 6 lines
scripts/package/mkspec +3
-0@@ -23,6 +23,9 @@ else echo '%define with_devel 0' fi +WITH_DEBUGINFO=$(grep -c CONFIG_DEBUG_INFO=y include/config/auto.conf) +echo "%define with_debuginfo ${WITH_DEBUGINFO}" +
How about this code?
if grep -q CONFIG_DEBUG_INFO=y include/config/auto.conf; then echo '%define with_debuginfo %{?_without_debuginfo: 0} %{?!_without_debuginfo: 1}'
else
echo '%define with_debuginfo 0'
fi
This allows users to skip the debuginfo package and aligns with the existing code a few lines above.
Also, it is compatible with Fedora's kernel.spec.
https://src.fedoraproject.org/rpms/kernel/blob/rawhide/f/kernel.spec#_236
If you do not support CONFIG_MODULE_COMPRESS,
you can check it here.
Quoted 8 lines
scripts/package/mkspec +0
-1cat<<EOF %define ARCH ${ARCH} %define KERNELRELEASE ${KERNELRELEASE} --2.34.1
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs
Quoted 1 line · Masahiro Yamada
Sorry for the long delay.
No worries and thanks for the review!
Quoted 11 lines · Uday Shankar
Quoted 8 lines
Note that this feature is incompatible with
CONFIG_MODULE_COMPRESS- if it is turned on, the module .ko files are compressed beforefind-debuginfo.shsees them, and it will not be able to extract debuginfo from them. There are two potential paths forward here:
- teachfind-debuginfo.shto extract debuginfo from compressed kernel modules
- teach the kernel build process to produce split debuginfo and then package that directly, bypassingfind-debuginfo.sh
Quoted 5 lines
'make bindeb-pkg' (Debian package) is able to build the debug package with
CONFIG_MODULE_COMPRESSenabled.
(seescripts/package/builddebif you are interested)
I have not checked if this works for 'make binrpm-pkg' or not. If this is a tricky case, I am OK with giving upCONFIG_MODULE_COMPRESS.
scripts/package/builddeb is able to do this because it is more hands-on with the debuginfo generation - it invokes objcopy --only-keep-debug directly. Meanwhile for rpm-pkg we are relying on find-debuginfo.sh for the debuginfo generation - we just set things up appropriately (meaning that we mark everything to be stripped as executable), and find-debuginfo.sh does the rest. This means we can get debuginfo without working as hard, but our flexibility is limited - without nasty hacks, we cannot really handle compressed modules unless/until find-debuginfo.sh is patched to handle them.
I could try revising this to remove the dependency on find-debuginfo.sh and strip the debuginfo ourselves. Then we could handle compressed modules the same way that deb-pkg does.
Quoted 6 lines
scripts/package/kernel.spec ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA · line 110
Quoted 3 lines
scripts/package/kernel.spec +3
-0+# make modules executable so that find-debuginfo.sh strips them +find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \ + | xargs --no-run-if-empty chmod u+xThis seems necessary and correct.
Quoted 7 lines
One side-effect I noticed is that *.ko under /lib/modules/$(uname -r)/ now have +x permissions. (Previously, they were non-executables).
I checked Fedora. Modules under /lib/modules/$(uname -r)/ do not have +x permissions.
Do you know how Fedora's kernel.spec handles this?
I'm looking at
https://koji.fedoraproject.org/koji/buildinfo?buildID=2661097
The spec file for that package actually does something similar to what we're doing above; it has this excerpt
# mark modules executable so that strip-to-file can strip them xargs --no-run-if-empty chmod u+x < modnames
But later on it compresses the modules, using some RPM macro magic to ensure that happens _after_ find-debuginfo.sh has seen and stripped the executable modules. The compression eats the executable bit.
Quoted 37 lines
Quoted 18 lines
scripts/package/kernel.spec +8
-0+ +%if %{with_debuginfo} +mkdir -p %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE} +cp vmlinux %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE} +%endif + %clean rm -rf %{buildroot} +rm -f debugfiles.list debuglinks.list debugsourcefiles.list debugsources.list \ + elfbins.list %post if [ -x /usr/bin/kernel-install ]; thenscripts/package/mkspec +0
-0scripts/package/mkspec else · line 28
Quoted 6 lines
scripts/package/mkspec +3
-0@@ -23,6 +23,9 @@ else echo '%define with_devel 0' fi +WITH_DEBUGINFO=$(grep -c CONFIG_DEBUG_INFO=y include/config/auto.conf) +echo "%define with_debuginfo ${WITH_DEBUGINFO}" +How about this code?
if grep -q
CONFIG_DEBUG_INFO=yinclude/config/auto.conf; then echo '%definewith_debuginfo%{?_without_debuginfo: 0} %{?!_without_debuginfo: 1}'
else
echo '%definewith_debuginfo0'
fiThis allows users to skip the debuginfo package and aligns with the existing code a few lines above.
Quoted 6 lines
Also, it is compatible with Fedora's kernel.spec.
https://src.fedoraproject.org/rpms/kernel/blob/rawhide/f/kernel.spec#_236If you do not support
CONFIG_MODULE_COMPRESS,
you can check it here.
Yes, both suggestions make sense, thanks. Will implement these in v2.
ping
Quoted 1 line · Uday Shankar
ping
ping again
Steven Rostedt
maintainerQuoted 4 lines · On Mon, 24 Feb 2025 12:35:00 -0700 Uday Shankar <[email protected]>…
Quoted 1 line · Uday Shankar
ping
ping again
Do you just package it, or do you actually use it?
-- Steve
Quoted 9 lines · Steven Rostedt
Quoted 4 lines · On Mon, 24 Feb 2025 12:35:00 -0700 Uday Shankar <[email protected]>…
Quoted 1 line · Uday Shankar
ping
ping again
Do you just package it, or do you actually use it?
Are you talking about the two scripts whose shebangs I modified in patch 1? Those scripts aren't used by the build process, they're just packaged in kernel-devel by the following command
%{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
Presumably those scripts are important to users of kernel-devel, which is supposed to "provide kernel headers and makefiles sufficient to build modules against the ... kernel." Though looking closer at these scripts, they look like they're probably extraneous for that purpose.
Steven Rostedt
maintainerQuoted 15 lines · On Mon, 24 Feb 2025 15:17:49 -0700 Uday Shankar <[email protected]>…
Quoted 9 lines · Steven Rostedt
Quoted 4 lines · On Mon, 24 Feb 2025 12:35:00 -0700 Uday Shankar <[email protected]>…
Quoted 1 line · Uday Shankar
ping
ping again
Do you just package it, or do you actually use it?
Are you talking about the two scripts whose shebangs I modified in patch 1? Those scripts aren't used by the build process, they're just packaged in kernel-devel by the following command
Quoted 6 lines
%{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
Presumably those scripts are important to users of kernel-devel, which is supposed to "provide kernel headers and makefiles sufficient to build modules against the ... kernel." Though looking closer at these scripts, they look like they're probably extraneous for that purpose.
Sorry, I missed your reply here.
I'm asking if anyone uses draw_functrace.py or if it can simply be deleted.
The rest of the changes are for the build maintainer not me.
-- Steve
Quoted 4 lines · Uday Shankar
Quoted 1 line · Uday Shankar
ping
ping again
ping again again. Can someone please take a look at this and/or let me know if I'm missing any recipients or if I'm expecting feedback too soon?
Nathan Chancellor
maintainerHi Uday,
Quoted 9 lines · Uday Shankar
Quoted 4 lines · Uday Shankar
Quoted 1 line · Uday Shankar
ping
ping again
ping again again. Can someone please take a look at this and/or let me know if I'm missing any recipients or if I'm expecting feedback too soon?
Your recipients list looks correct to me but I am not super knowledgeable about the RPM format so I am not sure I can give this a proper review but I will try to take a look at it when I can find some time to do some research. Masahiro will be the one to pick this up but some maintainers are busier than others.
Cheers,
Nathan