Skip to content

Commit a7c699d

Browse files
ps-ushankarmasahir0y
authored andcommitted
kbuild: rpm-pkg: build a debuginfo RPM
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 main kernel 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 a debuginfo RPM when the kernel configuration allows for it, in line with standard patterns followed by RPM distributors. 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 main kernel package goes down substantially, especially if many modules are built (quite typical). Here is a comparison of installed size of the kernel 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 a debuginfo package can only be produced if the following configs are set: - CONFIG_DEBUG_INFO=y - CONFIG_MODULE_COMPRESS=n - CONFIG_DEBUG_INFO_SPLIT=n The first of these is obvious - we can't produce debuginfo if the build does not generate it. The second two requirements can in principle be removed, but doing so is difficult with the current approach, which uses a generic rpmbuild script find-debuginfo.sh that processes all packaged executables. If we want to remove those requirements the best path forward is likely to add some debuginfo extraction/installation logic to the modules_install target (controllable by flags). That way, it's easier to operate on modules before they're compressed, and the logic can be reused by all packaging targets. Signed-off-by: Uday Shankar <ushankar@purestorage.com> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent a26fe28 commit a7c699d

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

scripts/package/kernel.spec

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
%{!?_arch: %define _arch dummy}
33
%{!?make: %define make make}
44
%define makeflags %{?_smp_mflags} ARCH=%{ARCH}
5-
%define __spec_install_post /usr/lib/rpm/brp-compress || :
6-
%define debug_package %{nil}
75

86
Name: kernel
97
Summary: The Linux Kernel
@@ -46,6 +44,36 @@ This package provides kernel headers and makefiles sufficient to build modules
4644
against the %{version} kernel package.
4745
%endif
4846

47+
%if %{with_debuginfo}
48+
# list of debuginfo-related options taken from distribution kernel.spec
49+
# files
50+
%undefine _include_minidebuginfo
51+
%undefine _find_debuginfo_dwz_opts
52+
%undefine _unique_build_ids
53+
%undefine _unique_debug_names
54+
%undefine _unique_debug_srcs
55+
%undefine _debugsource_packages
56+
%undefine _debuginfo_subpackages
57+
%global _find_debuginfo_opts -r
58+
%global _missing_build_ids_terminate_build 1
59+
%global _no_recompute_build_ids 1
60+
%{debug_package}
61+
%endif
62+
# some (but not all) versions of rpmbuild emit %%debug_package with
63+
# %%install. since we've already emitted it manually, that would cause
64+
# a package redefinition error. ensure that doesn't happen
65+
%define debug_package %{nil}
66+
67+
# later, we make all modules executable so that find-debuginfo.sh strips
68+
# them up. but they don't actually need to be executable, so remove the
69+
# executable bit, taking care to do it _after_ find-debuginfo.sh has run
70+
%define __spec_install_post \
71+
%{?__debug_package:%{__debug_install_post}} \
72+
%{__arch_install_post} \
73+
%{__os_install_post} \
74+
find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \\\
75+
| xargs --no-run-if-empty chmod u-x
76+
4977
%prep
5078
%setup -q -n linux
5179
cp %{SOURCE1} .config
@@ -89,8 +117,22 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA
89117
echo "%exclude /lib/modules/%{KERNELRELEASE}/build"
90118
} > %{buildroot}/kernel.list
91119

120+
# make modules executable so that find-debuginfo.sh strips them. this
121+
# will be undone later in %%__spec_install_post
122+
find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \
123+
| xargs --no-run-if-empty chmod u+x
124+
125+
%if %{with_debuginfo}
126+
# copying vmlinux directly to the debug directory means it will not get
127+
# stripped (but its source paths will still be collected + fixed up)
128+
mkdir -p %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE}
129+
cp vmlinux %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE}
130+
%endif
131+
92132
%clean
93133
rm -rf %{buildroot}
134+
rm -f debugfiles.list debuglinks.list debugsourcefiles.list debugsources.list \
135+
elfbins.list
94136

95137
%post
96138
if [ -x /usr/bin/kernel-install ]; then

scripts/package/mkspec

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ else
2323
echo '%define with_devel 0'
2424
fi
2525

26+
# debuginfo package generation uses find-debuginfo.sh under the hood,
27+
# which only works on uncompressed modules that contain debuginfo
28+
if grep -q CONFIG_DEBUG_INFO=y include/config/auto.conf &&
29+
(! grep -q CONFIG_MODULE_COMPRESS=y include/config/auto.conf) &&
30+
(! grep -q CONFIG_DEBUG_INFO_SPLIT=y include/config/auto.conf); then
31+
echo '%define with_debuginfo %{?_without_debuginfo: 0} %{?!_without_debuginfo: 1}'
32+
else
33+
echo '%define with_debuginfo 0'
34+
fi
35+
2636
cat<<EOF
2737
%define ARCH ${ARCH}
2838
%define KERNELRELEASE ${KERNELRELEASE}

0 commit comments

Comments
 (0)