From: Uday Shankar <ushankar@purestorage.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Masahiro Yamada <masahiroy@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nicolas@fjasle.eu>
Cc: linux-trace-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org,
Uday Shankar <ushankar@purestorage.com>
Subject: [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs
Date: Mon, 10 Feb 2025 18:11:55 -0700 [thread overview]
Message-ID: <20250210-debuginfo-v1-2-368feb58292a@purestorage.com> (raw)
In-Reply-To: <20250210-debuginfo-v1-0-368feb58292a@purestorage.com>
The 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.
Signed-off-by: Uday Shankar <ushankar@purestorage.com>
---
scripts/package/kernel.spec | 31 +++++++++++++++++++++++++++++--
scripts/package/mkspec | 3 +++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec
index ac3e5ac01d8a4daa031bc9e70b792a68f74c388b..efd7b1f43c64c8324bb0a6e540f2ba5f77f9de1e 100644
--- a/scripts/package/kernel.spec
+++ b/scripts/package/kernel.spec
@@ -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
diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 4dc1466dfc815c110eb7206f83dd874b17f5170f..4c96bdca381a2fb4cc57415ca914d14e37e16caa 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -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}
--
2.34.1
next prev parent reply other threads:[~2025-02-11 1:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-11 1:11 [PATCH 0/2] kbuild: rpm-pkg: improve debuggability Uday Shankar
2025-02-11 1:11 ` [PATCH 1/2] scripts: make python shebangs specific about desired version Uday Shankar
2025-02-18 14:34 ` Steven Rostedt
2025-03-06 17:29 ` Masahiro Yamada
2025-02-11 1:11 ` Uday Shankar [this message]
2025-03-14 19:56 ` [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs Masahiro Yamada
2025-03-15 1:00 ` Uday Shankar
2025-02-18 2:27 ` [PATCH 0/2] kbuild: rpm-pkg: improve debuggability Uday Shankar
2025-02-24 19:35 ` Uday Shankar
2025-02-24 22:07 ` Steven Rostedt
2025-02-24 22:17 ` Uday Shankar
2025-03-04 3:46 ` Steven Rostedt
2025-03-04 3:09 ` Uday Shankar
2025-03-04 13:06 ` Nathan Chancellor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250210-debuginfo-v1-2-368feb58292a@purestorage.com \
--to=ushankar@purestorage.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=nathan@kernel.org \
--cc=nicolas@fjasle.eu \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).