Skip to contentSkip to conversation

x86/purgatory: strip debug info

PATCH In review Pingfan Liu 2 participants 5 messages Jul 30, 2020 – Aug 3, 2020 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/purgatory: strip debug info

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

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Arvind Sankar <[email protected]>
Cc Steve Wahl <[email protected]>

To: [email protected]

---
 arch/x86/purgatory/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/purgatory/Makefile +1 -1
index 088bd76..4340ae6 100644
@@ -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
Signature · 1 line
2.7.5
#1 lore raw
Quoted 19 lines · Pingfan Liu

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
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Arvind Sankar <[email protected]>
Cc Steve Wahl <[email protected]>
Quoted 1 line

To: [email protected]

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.

Quoted 20 lines
---
 arch/x86/purgatory/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/purgatory/Makefile +1 -2
index 088bd76..4340ae6 100644
@@ -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

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
Quoted 38 lines · Nick Desaulniers
Quoted 19 lines · Pingfan Liu

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
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Arvind Sankar <[email protected]>
Cc Steve Wahl <[email protected]>
Quoted 1 line

To: [email protected]

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.

Quoted 5 lines

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:

arch/x86/purgatory/Makefile +1 -2
index 088bd76..7e1ad9e 100644
@@ -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

#3 lore raw
Quoted 52 lines · Pingfan Liu
Quoted 38 lines · Nick Desaulniers
Quoted 19 lines · Pingfan Liu

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
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Arvind Sankar <[email protected]>
Cc Steve Wahl <[email protected]>
Quoted 1 line

To: [email protected]

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.

Quoted 5 lines

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:

arch/x86/purgatory/Makefile +0 -0
index 088bd76..7e1ad9e 100644

arch/x86/purgatory/Makefile KCOV_INSTRUMENT := n · line 37

Quoted 8 lines
arch/x86/purgatory/Makefile +1 -2
@@ -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)
Signature · 2 lines
Thanks,
~Nick Desaulniers
#4 lore raw
Quoted 72 lines · Nick Desaulniers
Quoted 52 lines · Pingfan Liu
Quoted 38 lines · Nick Desaulniers
Quoted 19 lines · Pingfan Liu

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
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Arvind Sankar <[email protected]>
Cc Steve Wahl <[email protected]>
Quoted 1 line

To: [email protected]

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.

Quoted 5 lines

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:

arch/x86/purgatory/Makefile +0 -0
index 088bd76..7e1ad9e 100644

arch/x86/purgatory/Makefile KCOV_INSTRUMENT := n · line 37

Quoted 8 lines
arch/x86/purgatory/Makefile +1 -2
@@ -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:
```

Review CFLAGS_sha256.o += $(PURGATORY_CFLAGS) · line 69

Quoted 6 lines
(quoted diff) +3 -0
@@ -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.

Quoted 6 lines
(quoted diff) +0 -0
 $(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