linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/purgatory: strip debug info
@ 2020-07-30  8:26 Pingfan Liu
  2020-07-30 23:11 ` Nick Desaulniers
  0 siblings, 1 reply; 5+ messages in thread
From: Pingfan Liu @ 2020-07-30  8:26 UTC (permalink / raw)
  To: x86
  Cc: Pingfan Liu, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, Hans de Goede, Nick Desaulniers, Arvind Sankar,
	Steve Wahl, linux-kernel

It is useless to keep debug info in purgatory. And discarding them saves
about 200K space.

Original:
  259080  kexec-purgatory.o
Stripped:
   29152  kexec-purgatory.o

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Steve Wahl <steve.wahl@hpe.com>
Cc: linux-kernel@vger.kernel.org
To: x86@kernel.org
---
 arch/x86/purgatory/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
index 088bd76..4340ae6 100644
--- a/arch/x86/purgatory/Makefile
+++ b/arch/x86/purgatory/Makefile
@@ -16,7 +16,7 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS
 
 # When linking purgatory.ro with -r unresolved symbols are not checked,
 # also link a purgatory.chk binary without -r to check for unresolved symbols.
-PURGATORY_LDFLAGS := -e purgatory_start -nostdlib -z nodefaultlib
+PURGATORY_LDFLAGS := -e purgatory_start -nostdlib -z nodefaultlib -S
 LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
 LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
 targets += purgatory.ro purgatory.chk
-- 
2.7.5


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

* Re: [PATCH] x86/purgatory: strip debug info
  2020-07-30  8:26 [PATCH] x86/purgatory: strip debug info Pingfan Liu
@ 2020-07-30 23:11 ` Nick Desaulniers
  2020-07-31  9:36   ` Pingfan Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Desaulniers @ 2020-07-30 23:11 UTC (permalink / raw)
  To: Pingfan Liu
  Cc: maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	Hans de Goede, Arvind Sankar, Steve Wahl, LKML

On Thu, Jul 30, 2020 at 1:27 AM Pingfan Liu <kernelfans@gmail.com> wrote:
>
> It is useless to keep debug info in purgatory. And discarding them saves
> about 200K space.
>
> Original:
>   259080  kexec-purgatory.o
> Stripped:
>    29152  kexec-purgatory.o
>
> Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Hans de Goede <hdegoede@redhat.com>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: Arvind Sankar <nivedita@alum.mit.edu>
> Cc: Steve Wahl <steve.wahl@hpe.com>
> Cc: linux-kernel@vger.kernel.org
> To: x86@kernel.org

I don't see any code in
arch/x86/purgatory/
arch/x86/include/asm/purgatory.h
include/linux/purgatory.h
include/uapi/linux/kexec.h
kernel/kexec*
include/linux/kexec.h
include/linux/crash_dump.h
kernel/crash_dump.c
arch/x86/kernel/crash*
https://github.com/horms/kexec-tools/tree/master/kexec/arch/x86_64
that mentions any kind of debug info section.  I'm not sure what you'd
do with the debug info anyway for this binary.  So I suspect this
information should ok to discard.

This works, but it might be faster to build to not generate the
compile info in the first place via compile flag `-g0`, which could be
added `ifdef CONFIG_DEBUG_INFO` or even just unconditionally.  That
way we're not doing additional work to generate debug info, then
additional work to throw it away.

> ---
>  arch/x86/purgatory/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
> index 088bd76..4340ae6 100644
> --- a/arch/x86/purgatory/Makefile
> +++ b/arch/x86/purgatory/Makefile
> @@ -16,7 +16,7 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS
>
>  # When linking purgatory.ro with -r unresolved symbols are not checked,
>  # also link a purgatory.chk binary without -r to check for unresolved symbols.
> -PURGATORY_LDFLAGS := -e purgatory_start -nostdlib -z nodefaultlib
> +PURGATORY_LDFLAGS := -e purgatory_start -nostdlib -z nodefaultlib -S
>  LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
>  LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
>  targets += purgatory.ro purgatory.chk
> --
> 2.7.5
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] x86/purgatory: strip debug info
  2020-07-30 23:11 ` Nick Desaulniers
@ 2020-07-31  9:36   ` Pingfan Liu
  2020-07-31 18:18     ` Nick Desaulniers
  0 siblings, 1 reply; 5+ messages in thread
From: Pingfan Liu @ 2020-07-31  9:36 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	Hans de Goede, Arvind Sankar, Steve Wahl, LKML

On Fri, Jul 31, 2020 at 7:11 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Thu, Jul 30, 2020 at 1:27 AM Pingfan Liu <kernelfans@gmail.com> wrote:
> >
> > It is useless to keep debug info in purgatory. And discarding them saves
> > about 200K space.
> >
> > Original:
> >   259080  kexec-purgatory.o
> > Stripped:
> >    29152  kexec-purgatory.o
> >
> > Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Borislav Petkov <bp@alien8.de>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: Hans de Goede <hdegoede@redhat.com>
> > Cc: Nick Desaulniers <ndesaulniers@google.com>
> > Cc: Arvind Sankar <nivedita@alum.mit.edu>
> > Cc: Steve Wahl <steve.wahl@hpe.com>
> > Cc: linux-kernel@vger.kernel.org
> > To: x86@kernel.org
>
> I don't see any code in
> arch/x86/purgatory/
> arch/x86/include/asm/purgatory.h
> include/linux/purgatory.h
> include/uapi/linux/kexec.h
> kernel/kexec*
> include/linux/kexec.h
> include/linux/crash_dump.h
> kernel/crash_dump.c
> arch/x86/kernel/crash*
> https://github.com/horms/kexec-tools/tree/master/kexec/arch/x86_64
> that mentions any kind of debug info section.  I'm not sure what you'd
> do with the debug info anyway for this binary.  So I suspect this
> information should ok to discard.
>
> This works, but it might be faster to build to not generate the
> compile info in the first place via compile flag `-g0`, which could be
> added `ifdef CONFIG_DEBUG_INFO` or even just unconditionally.  That
> way we're not doing additional work to generate debug info, then
> additional work to throw it away.
What about:
diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
index 088bd76..7e1ad9e 100644
--- a/arch/x86/purgatory/Makefile
+++ b/arch/x86/purgatory/Makefile
@@ -32,7 +32,7 @@ KCOV_INSTRUMENT := n
 # make up the standalone purgatory.ro

 PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
-PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss
+PURGATORY_CFLAGS := -mcmodel=large -ffreestanding
-fno-zero-initialized-in-bss -g0
 PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
 PURGATORY_CFLAGS += $(call cc-option,-fno-stack-protector)

Thanks,
Pingfan

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

* Re: [PATCH] x86/purgatory: strip debug info
  2020-07-31  9:36   ` Pingfan Liu
@ 2020-07-31 18:18     ` Nick Desaulniers
  2020-08-03  4:13       ` Pingfan Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Desaulniers @ 2020-07-31 18:18 UTC (permalink / raw)
  To: Pingfan Liu, Steve Wahl
  Cc: maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	Hans de Goede, Arvind Sankar, LKML

On Fri, Jul 31, 2020 at 2:36 AM Pingfan Liu <kernelfans@gmail.com> wrote:
>
> On Fri, Jul 31, 2020 at 7:11 AM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> >
> > On Thu, Jul 30, 2020 at 1:27 AM Pingfan Liu <kernelfans@gmail.com> wrote:
> > >
> > > It is useless to keep debug info in purgatory. And discarding them saves
> > > about 200K space.
> > >
> > > Original:
> > >   259080  kexec-purgatory.o
> > > Stripped:
> > >    29152  kexec-purgatory.o
> > >
> > > Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
> > > Cc: Thomas Gleixner <tglx@linutronix.de>
> > > Cc: Ingo Molnar <mingo@redhat.com>
> > > Cc: Borislav Petkov <bp@alien8.de>
> > > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > > Cc: Hans de Goede <hdegoede@redhat.com>
> > > Cc: Nick Desaulniers <ndesaulniers@google.com>
> > > Cc: Arvind Sankar <nivedita@alum.mit.edu>
> > > Cc: Steve Wahl <steve.wahl@hpe.com>
> > > Cc: linux-kernel@vger.kernel.org
> > > To: x86@kernel.org
> >
> > I don't see any code in
> > arch/x86/purgatory/
> > arch/x86/include/asm/purgatory.h
> > include/linux/purgatory.h
> > include/uapi/linux/kexec.h
> > kernel/kexec*
> > include/linux/kexec.h
> > include/linux/crash_dump.h
> > kernel/crash_dump.c
> > arch/x86/kernel/crash*
> > https://github.com/horms/kexec-tools/tree/master/kexec/arch/x86_64
> > that mentions any kind of debug info section.  I'm not sure what you'd
> > do with the debug info anyway for this binary.  So I suspect this
> > information should ok to discard.
> >
> > This works, but it might be faster to build to not generate the
> > compile info in the first place via compile flag `-g0`, which could be
> > added `ifdef CONFIG_DEBUG_INFO` or even just unconditionally.  That
> > way we're not doing additional work to generate debug info, then
> > additional work to throw it away.
> What about:
> diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
> index 088bd76..7e1ad9e 100644
> --- a/arch/x86/purgatory/Makefile
> +++ b/arch/x86/purgatory/Makefile
> @@ -32,7 +32,7 @@ KCOV_INSTRUMENT := n
>  # make up the standalone purgatory.ro
>
>  PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
> -PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss
> +PURGATORY_CFLAGS := -mcmodel=large -ffreestanding
> -fno-zero-initialized-in-bss -g0
>  PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
>  PURGATORY_CFLAGS += $(call cc-option,-fno-stack-protector)

I tested your patch but still see .debug_* sections in the .ro from a few .o.

At least on
* setup-x86_64.o
* entry64.o

If you add the following hunk to your diff:
```
@@ -64,6 +64,9 @@ CFLAGS_sha256.o                       += $(PURGATORY_CFLAGS)
 CFLAGS_REMOVE_string.o         += $(PURGATORY_CFLAGS_REMOVE)
 CFLAGS_string.o                        += $(PURGATORY_CFLAGS)

+AFLAGS_REMOVE_setup-x86_$(BITS).o      += -Wa,-gdwarf-2
+AFLAGS_REMOVE_entry64.o                += -Wa,-gdwarf-2
+
 $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
                $(call if_changed,ld)
```
then that should do it.  Then you can verify the .ro file via:
$ llvm-readelf -S arch/x86/purgatory/purgatory.ro | not grep debug_
(no output, should return zero)
-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] x86/purgatory: strip debug info
  2020-07-31 18:18     ` Nick Desaulniers
@ 2020-08-03  4:13       ` Pingfan Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Pingfan Liu @ 2020-08-03  4:13 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Steve Wahl, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	Hans de Goede, Arvind Sankar, LKML

On Sat, Aug 1, 2020 at 2:18 AM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> On Fri, Jul 31, 2020 at 2:36 AM Pingfan Liu <kernelfans@gmail.com> wrote:
> >
> > On Fri, Jul 31, 2020 at 7:11 AM Nick Desaulniers
> > <ndesaulniers@google.com> wrote:
> > >
> > > On Thu, Jul 30, 2020 at 1:27 AM Pingfan Liu <kernelfans@gmail.com> wrote:
> > > >
> > > > It is useless to keep debug info in purgatory. And discarding them saves
> > > > about 200K space.
> > > >
> > > > Original:
> > > >   259080  kexec-purgatory.o
> > > > Stripped:
> > > >    29152  kexec-purgatory.o
> > > >
> > > > Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
> > > > Cc: Thomas Gleixner <tglx@linutronix.de>
> > > > Cc: Ingo Molnar <mingo@redhat.com>
> > > > Cc: Borislav Petkov <bp@alien8.de>
> > > > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > > > Cc: Hans de Goede <hdegoede@redhat.com>
> > > > Cc: Nick Desaulniers <ndesaulniers@google.com>
> > > > Cc: Arvind Sankar <nivedita@alum.mit.edu>
> > > > Cc: Steve Wahl <steve.wahl@hpe.com>
> > > > Cc: linux-kernel@vger.kernel.org
> > > > To: x86@kernel.org
> > >
> > > I don't see any code in
> > > arch/x86/purgatory/
> > > arch/x86/include/asm/purgatory.h
> > > include/linux/purgatory.h
> > > include/uapi/linux/kexec.h
> > > kernel/kexec*
> > > include/linux/kexec.h
> > > include/linux/crash_dump.h
> > > kernel/crash_dump.c
> > > arch/x86/kernel/crash*
> > > https://github.com/horms/kexec-tools/tree/master/kexec/arch/x86_64
> > > that mentions any kind of debug info section.  I'm not sure what you'd
> > > do with the debug info anyway for this binary.  So I suspect this
> > > information should ok to discard.
> > >
> > > This works, but it might be faster to build to not generate the
> > > compile info in the first place via compile flag `-g0`, which could be
> > > added `ifdef CONFIG_DEBUG_INFO` or even just unconditionally.  That
> > > way we're not doing additional work to generate debug info, then
> > > additional work to throw it away.
> > What about:
> > diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
> > index 088bd76..7e1ad9e 100644
> > --- a/arch/x86/purgatory/Makefile
> > +++ b/arch/x86/purgatory/Makefile
> > @@ -32,7 +32,7 @@ KCOV_INSTRUMENT := n
> >  # make up the standalone purgatory.ro
> >
> >  PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
> > -PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss
> > +PURGATORY_CFLAGS := -mcmodel=large -ffreestanding
> > -fno-zero-initialized-in-bss -g0
> >  PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
> >  PURGATORY_CFLAGS += $(call cc-option,-fno-stack-protector)
>
> I tested your patch but still see .debug_* sections in the .ro from a few .o.
>
> At least on
> * setup-x86_64.o
> * entry64.o
>
> If you add the following hunk to your diff:
> ```
> @@ -64,6 +64,9 @@ CFLAGS_sha256.o                       += $(PURGATORY_CFLAGS)
>  CFLAGS_REMOVE_string.o         += $(PURGATORY_CFLAGS_REMOVE)
>  CFLAGS_string.o                        += $(PURGATORY_CFLAGS)
>
> +AFLAGS_REMOVE_setup-x86_$(BITS).o      += -Wa,-gdwarf-2
> +AFLAGS_REMOVE_entry64.o                += -Wa,-gdwarf-2
> +
Go through man as and gcc, and can not find a simpler method than your
suggestion.
>  $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
>                 $(call if_changed,ld)
> ```
> then that should do it.  Then you can verify the .ro file via:
> $ llvm-readelf -S arch/x86/purgatory/purgatory.ro | not grep debug_
> (no output, should return zero)
Thank you for your good suggestion and I will update V2

Regards,
Pingfan

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

end of thread, other threads:[~2020-08-03  4:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-30  8:26 [PATCH] x86/purgatory: strip debug info Pingfan Liu
2020-07-30 23:11 ` Nick Desaulniers
2020-07-31  9:36   ` Pingfan Liu
2020-07-31 18:18     ` Nick Desaulniers
2020-08-03  4:13       ` Pingfan Liu

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