linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] kbuild: rpm-pkg: improve debuggability
@ 2025-02-11  1:11 Uday Shankar
  2025-02-11  1:11 ` [PATCH 1/2] scripts: make python shebangs specific about desired version Uday Shankar
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Uday Shankar @ 2025-02-11  1:11 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Masahiro Yamada, Nathan Chancellor, Nicolas Schier
  Cc: linux-trace-kernel, linux-kbuild, Uday Shankar

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/20240910014327.1726214-1-ushankar@purestorage.com/

Signed-off-by: Uday Shankar <ushankar@purestorage.com>
---
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,
-- 
Uday Shankar <ushankar@purestorage.com>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/2] scripts: make python shebangs specific about desired version
  2025-02-11  1:11 [PATCH 0/2] kbuild: rpm-pkg: improve debuggability Uday Shankar
@ 2025-02-11  1:11 ` Uday Shankar
  2025-02-18 14:34   ` Steven Rostedt
  2025-03-06 17:29   ` Masahiro Yamada
  2025-02-11  1:11 ` [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs Uday Shankar
  2025-02-18  2:27 ` [PATCH 0/2] kbuild: rpm-pkg: improve debuggability Uday Shankar
  2 siblings, 2 replies; 14+ messages in thread
From: Uday Shankar @ 2025-02-11  1:11 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Masahiro Yamada, Nathan Chancellor, Nicolas Schier
  Cc: linux-trace-kernel, linux-kbuild, 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 <ushankar@purestorage.com>
---
 scripts/show_delta                | 2 +-
 scripts/tracing/draw_functrace.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/show_delta b/scripts/show_delta
index 291ad65e30894645205101e3f31f2e38e90e172e..3755b6c6e55704ef08c2483ab44793adab78f76c 100755
--- a/scripts/show_delta
+++ b/scripts/show_delta
@@ -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
diff --git a/scripts/tracing/draw_functrace.py b/scripts/tracing/draw_functrace.py
index 42fa8730094166b5883aaa92b0e2c32e0268b120..97594b65f8ce9b1ade7f08b6b95eee6a1383fec7 100755
--- a/scripts/tracing/draw_functrace.py
+++ b/scripts/tracing/draw_functrace.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0-only
 
 """

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs
  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-11  1:11 ` Uday Shankar
  2025-03-14 19:56   ` Masahiro Yamada
  2025-02-18  2:27 ` [PATCH 0/2] kbuild: rpm-pkg: improve debuggability Uday Shankar
  2 siblings, 1 reply; 14+ messages in thread
From: Uday Shankar @ 2025-02-11  1:11 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Masahiro Yamada, Nathan Chancellor, Nicolas Schier
  Cc: linux-trace-kernel, linux-kbuild, Uday Shankar

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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/2] kbuild: rpm-pkg: improve debuggability
  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-11  1:11 ` [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs Uday Shankar
@ 2025-02-18  2:27 ` Uday Shankar
  2025-02-24 19:35   ` Uday Shankar
  2 siblings, 1 reply; 14+ messages in thread
From: Uday Shankar @ 2025-02-18  2:27 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Masahiro Yamada, Nathan Chancellor, Nicolas Schier
  Cc: linux-trace-kernel, linux-kbuild

ping

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] scripts: make python shebangs specific about desired version
  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
  1 sibling, 0 replies; 14+ messages in thread
From: Steven Rostedt @ 2025-02-18 14:34 UTC (permalink / raw)
  To: Uday Shankar, Frederic Weisbecker
  Cc: Masami Hiramatsu, Mathieu Desnoyers, Masahiro Yamada,
	Nathan Chancellor, Nicolas Schier, linux-trace-kernel,
	linux-kbuild

On Mon, 10 Feb 2025 18:11:54 -0700
Uday Shankar <ushankar@purestorage.com> wrote:

> diff --git a/scripts/tracing/draw_functrace.py b/scripts/tracing/draw_functrace.py
> index 42fa8730094166b5883aaa92b0e2c32e0268b120..97594b65f8ce9b1ade7f08b6b95eee6a1383fec7 100755
> --- a/scripts/tracing/draw_functrace.py
> +++ b/scripts/tracing/draw_functrace.py
> @@ -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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/2] kbuild: rpm-pkg: improve debuggability
  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-03-04  3:09     ` Uday Shankar
  0 siblings, 2 replies; 14+ messages in thread
From: Uday Shankar @ 2025-02-24 19:35 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Masahiro Yamada, Nathan Chancellor, Nicolas Schier
  Cc: linux-trace-kernel, linux-kbuild

On Mon, Feb 17, 2025 at 07:27:06PM -0700, Uday Shankar wrote:
> ping

ping again


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/2] kbuild: rpm-pkg: improve debuggability
  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:09     ` Uday Shankar
  1 sibling, 1 reply; 14+ messages in thread
From: Steven Rostedt @ 2025-02-24 22:07 UTC (permalink / raw)
  To: Uday Shankar
  Cc: Masami Hiramatsu, Mathieu Desnoyers, Masahiro Yamada,
	Nathan Chancellor, Nicolas Schier, linux-trace-kernel,
	linux-kbuild

On Mon, 24 Feb 2025 12:35:00 -0700
Uday Shankar <ushankar@purestorage.com> wrote:

> On Mon, Feb 17, 2025 at 07:27:06PM -0700, Uday Shankar wrote:
> > ping  
> 
> ping again

Do you just package it, or do you actually use it?

-- Steve

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/2] kbuild: rpm-pkg: improve debuggability
  2025-02-24 22:07     ` Steven Rostedt
@ 2025-02-24 22:17       ` Uday Shankar
  2025-03-04  3:46         ` Steven Rostedt
  0 siblings, 1 reply; 14+ messages in thread
From: Uday Shankar @ 2025-02-24 22:17 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Masami Hiramatsu, Mathieu Desnoyers, Masahiro Yamada,
	Nathan Chancellor, Nicolas Schier, linux-trace-kernel,
	linux-kbuild

On Mon, Feb 24, 2025 at 05:07:09PM -0500, Steven Rostedt wrote:
> On Mon, 24 Feb 2025 12:35:00 -0700
> Uday Shankar <ushankar@purestorage.com> wrote:
> 
> > On Mon, Feb 17, 2025 at 07:27:06PM -0700, Uday Shankar wrote:
> > > 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.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/2] kbuild: rpm-pkg: improve debuggability
  2025-02-24 19:35   ` Uday Shankar
  2025-02-24 22:07     ` Steven Rostedt
@ 2025-03-04  3:09     ` Uday Shankar
  2025-03-04 13:06       ` Nathan Chancellor
  1 sibling, 1 reply; 14+ messages in thread
From: Uday Shankar @ 2025-03-04  3:09 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Masahiro Yamada, Nathan Chancellor, Nicolas Schier
  Cc: linux-trace-kernel, linux-kbuild

On Mon, Feb 24, 2025 at 12:35:00PM -0700, Uday Shankar wrote:
> On Mon, Feb 17, 2025 at 07:27:06PM -0700, Uday Shankar wrote:
> > 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?


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/2] kbuild: rpm-pkg: improve debuggability
  2025-02-24 22:17       ` Uday Shankar
@ 2025-03-04  3:46         ` Steven Rostedt
  0 siblings, 0 replies; 14+ messages in thread
From: Steven Rostedt @ 2025-03-04  3:46 UTC (permalink / raw)
  To: Uday Shankar
  Cc: Masami Hiramatsu, Mathieu Desnoyers, Masahiro Yamada,
	Nathan Chancellor, Nicolas Schier, linux-trace-kernel,
	linux-kbuild

On Mon, 24 Feb 2025 15:17:49 -0700
Uday Shankar <ushankar@purestorage.com> wrote:

> On Mon, Feb 24, 2025 at 05:07:09PM -0500, Steven Rostedt wrote:
> > On Mon, 24 Feb 2025 12:35:00 -0700
> > Uday Shankar <ushankar@purestorage.com> wrote:
> >   
> > > On Mon, Feb 17, 2025 at 07:27:06PM -0700, Uday Shankar wrote:  
> > > > 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.

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/2] kbuild: rpm-pkg: improve debuggability
  2025-03-04  3:09     ` Uday Shankar
@ 2025-03-04 13:06       ` Nathan Chancellor
  0 siblings, 0 replies; 14+ messages in thread
From: Nathan Chancellor @ 2025-03-04 13:06 UTC (permalink / raw)
  To: Uday Shankar
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Masahiro Yamada, Nicolas Schier, linux-trace-kernel, linux-kbuild

Hi Uday,

On Mon, Mar 03, 2025 at 08:09:06PM -0700, Uday Shankar wrote:
> On Mon, Feb 24, 2025 at 12:35:00PM -0700, Uday Shankar wrote:
> > On Mon, Feb 17, 2025 at 07:27:06PM -0700, Uday Shankar wrote:
> > > 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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] scripts: make python shebangs specific about desired version
  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
  1 sibling, 0 replies; 14+ messages in thread
From: Masahiro Yamada @ 2025-03-06 17:29 UTC (permalink / raw)
  To: Uday Shankar
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Nathan Chancellor, Nicolas Schier, linux-trace-kernel,
	linux-kbuild

On Tue, Feb 11, 2025 at 10:12 AM Uday Shankar <ushankar@purestorage.com> wrote:
>
> 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 <ushankar@purestorage.com>


Applied to linux-kbuild.
Thanks.


> ---
>  scripts/show_delta                | 2 +-
>  scripts/tracing/draw_functrace.py | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/show_delta b/scripts/show_delta
> index 291ad65e30894645205101e3f31f2e38e90e172e..3755b6c6e55704ef08c2483ab44793adab78f76c 100755
> --- a/scripts/show_delta
> +++ b/scripts/show_delta
> @@ -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
> diff --git a/scripts/tracing/draw_functrace.py b/scripts/tracing/draw_functrace.py
> index 42fa8730094166b5883aaa92b0e2c32e0268b120..97594b65f8ce9b1ade7f08b6b95eee6a1383fec7 100755
> --- a/scripts/tracing/draw_functrace.py
> +++ b/scripts/tracing/draw_functrace.py
> @@ -1,4 +1,4 @@
> -#!/usr/bin/env python
> +#!/usr/bin/env python3
>  # SPDX-License-Identifier: GPL-2.0-only
>
>  """
>
> --
> 2.34.1
>
>


--
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs
  2025-02-11  1:11 ` [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs Uday Shankar
@ 2025-03-14 19:56   ` Masahiro Yamada
  2025-03-15  1:00     ` Uday Shankar
  0 siblings, 1 reply; 14+ messages in thread
From: Masahiro Yamada @ 2025-03-14 19:56 UTC (permalink / raw)
  To: Uday Shankar
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Nathan Chancellor, Nicolas Schier, linux-trace-kernel,
	linux-kbuild

Sorry for the long delay.


On Tue, Feb 11, 2025 at 10:12 AM Uday Shankar <ushankar@purestorage.com> wrote:
> 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


'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.



> 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

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?



> +
> +%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}"
> +

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.


>  cat<<EOF
>  %define ARCH ${ARCH}
>  %define KERNELRELEASE ${KERNELRELEASE}
>
> --
> 2.34.1
>
>


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs
  2025-03-14 19:56   ` Masahiro Yamada
@ 2025-03-15  1:00     ` Uday Shankar
  0 siblings, 0 replies; 14+ messages in thread
From: Uday Shankar @ 2025-03-15  1:00 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Nathan Chancellor, Nicolas Schier, linux-trace-kernel,
	linux-kbuild

On Sat, Mar 15, 2025 at 04:56:35AM +0900, Masahiro Yamada wrote:
> Sorry for the long delay.

No worries and thanks for the review!

> On Tue, Feb 11, 2025 at 10:12 AM Uday Shankar <ushankar@purestorage.com> wrote:
> > 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
> 
> 
> '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.

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.

> > +# 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?

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.

> > +
> > +%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}"
> > +
> 
> 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.

Yes, both suggestions make sense, thanks. Will implement these in v2.


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-03-15  1:00 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/2] kbuild: rpm-pkg: build debuginfo and debugsource RPMs Uday Shankar
2025-03-14 19:56   ` 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

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).