diff mbox

[OpenWrt-Devel] include/kernel: Do not strip kernel's Elf

Message ID 1463409763-11832-1-git-send-email-abrodkin@synopsys.com
State Changes Requested
Delegated to: John Crispin
Headers show

Commit Message

Alexey Brodkin May 16, 2016, 2:42 p.m. UTC
If an image gets built as an Elf there's a chance
it will be used by developers for debugging purposes.
In that case it's very helpful to keep debugging info
in that image.

I would think that most OWRT-powered devices in production
will use some form of binary image for booting so Elf
flavours could be left a bit bulkier with more debug info
inside.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
---
 include/kernel-defaults.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Daniel Golle May 16, 2016, 3:20 p.m. UTC | #1
On Mon, May 16, 2016 at 05:42:43PM +0300, Alexey Brodkin wrote:
> If an image gets built as an Elf there's a chance
> it will be used by developers for debugging purposes.
> In that case it's very helpful to keep debugging info
> in that image.
> 
> I would think that most OWRT-powered devices in production
> will use some form of binary image for booting so Elf
> flavours could be left a bit bulkier with more debug info
> inside.

Well, some of the tiniest AR7 boxes out there come with a bootloader
expecting ELF binaries... I didn't have a close look, just assuming
that they might be affected. May Florian knows more...?

Cheers

Daniel

> 
> Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
> ---
>  include/kernel-defaults.mk | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk
> index 406fd46..0166dc5 100644
> --- a/include/kernel-defaults.mk
> +++ b/include/kernel-defaults.mk
> @@ -142,7 +142,7 @@ endif
>  define Kernel/CopyImage
>  	cmp -s $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug || { \
>  		$(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1); \
> -		$(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf; \
> +		$(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf; \
>  		$(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug; \
>  		$(foreach k, \
>  			$(if $(KERNEL_IMAGES),$(KERNEL_IMAGES),$(filter-out dtbs,$(KERNELNAME))), \
> -- 
> 2.5.5
> 
> 
> _______________________________________________
> Lede-dev mailing list
> Lede-dev@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/lede-dev
Felix Fietkau May 18, 2016, 12:57 p.m. UTC | #2
On 2016-05-16 16:42, Alexey Brodkin wrote:
> If an image gets built as an Elf there's a chance
> it will be used by developers for debugging purposes.
> In that case it's very helpful to keep debugging info
> in that image.
> 
> I would think that most OWRT-powered devices in production
> will use some form of binary image for booting so Elf
> flavours could be left a bit bulkier with more debug info
> inside.
> 
> Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
You can get the bulky one directly from the kernel source directory, and
there is definitely some value in having stripped ELF binaries as well
for devices that can load them.

- Felix
Alexey Brodkin May 18, 2016, 1:06 p.m. UTC | #3
Hi Felix,

On Wed, 2016-05-18 at 14:57 +0200, Felix Fietkau wrote:
> On 2016-05-16 16:42, Alexey Brodkin wrote:
> > 
> > If an image gets built as an Elf there's a chance
> > it will be used by developers for debugging purposes.
> > In that case it's very helpful to keep debugging info
> > in that image.
> > 
> > I would think that most OWRT-powered devices in production
> > will use some form of binary image for booting so Elf
> > flavours could be left a bit bulkier with more debug info
> > inside.
> > 
> > Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
> You can get the bulky one directly from the kernel source directory, and
> there is definitely some value in having stripped ELF binaries as well
> for devices that can load them.

Well indeed in kernel's source directory we have an unstripped elf.
But what happens at least in case of ARC we build only one kernel's elf
and then as a post-built step we patch in .dtb for all boards we build OWRT.

In other words in "bin/arc770-uClibc" folder I have:
 1) openwrt-arc770-generic-axs101-initramfs.elf
 2) openwrt-arc770-generic-nsim_700-initramfs.elf

Both are stripped but work as they are on the corresponding boards.

In "build_dir/target-arc_arc700_uClibc-1.0.9/linux-arc770_generic/linux-4.4.7/"
I have perfectly unstripped vmlinux but it won't work on either board because of
missing device tree blob.

That means if one wants to get image for a board X with debug symbols he or she
will need to do manual patching in of .dtb. Which is not the most convenient thing ever.

-Alexey
Felix Fietkau May 18, 2016, 1:49 p.m. UTC | #4
On 2016-05-18 15:06, Alexey Brodkin wrote:
> Hi Felix,
> 
> On Wed, 2016-05-18 at 14:57 +0200, Felix Fietkau wrote:
>> On 2016-05-16 16:42, Alexey Brodkin wrote:
>> > 
>> > If an image gets built as an Elf there's a chance
>> > it will be used by developers for debugging purposes.
>> > In that case it's very helpful to keep debugging info
>> > in that image.
>> > 
>> > I would think that most OWRT-powered devices in production
>> > will use some form of binary image for booting so Elf
>> > flavours could be left a bit bulkier with more debug info
>> > inside.
>> > 
>> > Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
>> You can get the bulky one directly from the kernel source directory, and
>> there is definitely some value in having stripped ELF binaries as well
>> for devices that can load them.
> 
> Well indeed in kernel's source directory we have an unstripped elf.
> But what happens at least in case of ARC we build only one kernel's elf
> and then as a post-built step we patch in .dtb for all boards we build OWRT.
> 
> In other words in "bin/arc770-uClibc" folder I have:
>  1) openwrt-arc770-generic-axs101-initramfs.elf
>  2) openwrt-arc770-generic-nsim_700-initramfs.elf
> 
> Both are stripped but work as they are on the corresponding boards.
> 
> In "build_dir/target-arc_arc700_uClibc-1.0.9/linux-arc770_generic/linux-4.4.7/"
> I have perfectly unstripped vmlinux but it won't work on either board because of
> missing device tree blob.
> 
> That means if one wants to get image for a board X with debug symbols he or she
> will need to do manual patching in of .dtb. Which is not the most convenient thing ever.
It's a lot simpler than that: You can boot the stripped and patched elf
image from bin/ and use the vmlinux from the kernel source for the
debugger afterwards. They are fully compatible.

- Felix
Alexey Brodkin May 18, 2016, 1:59 p.m. UTC | #5
Hi Felix,

On Wed, 2016-05-18 at 15:49 +0200, Felix Fietkau wrote:
> On 2016-05-18 15:06, Alexey Brodkin wrote:
> > 
> > Hi Felix,
> > 
> > On Wed, 2016-05-18 at 14:57 +0200, Felix Fietkau wrote:
> > > 
> > > On 2016-05-16 16:42, Alexey Brodkin wrote:
> > > > 
> > > > 
> > > > If an image gets built as an Elf there's a chance
> > > > it will be used by developers for debugging purposes.
> > > > In that case it's very helpful to keep debugging info
> > > > in that image.
> > > > 
> > > > I would think that most OWRT-powered devices in production
> > > > will use some form of binary image for booting so Elf
> > > > flavours could be left a bit bulkier with more debug info
> > > > inside.
> > > > 
> > > > Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
> > > You can get the bulky one directly from the kernel source directory, and
> > > there is definitely some value in having stripped ELF binaries as well
> > > for devices that can load them.
> > Well indeed in kernel's source directory we have an unstripped elf.
> > But what happens at least in case of ARC we build only one kernel's elf
> > and then as a post-built step we patch in .dtb for all boards we build OWRT.
> > 
> > In other words in "bin/arc770-uClibc" folder I have:
> >  1) openwrt-arc770-generic-axs101-initramfs.elf
> >  2) openwrt-arc770-generic-nsim_700-initramfs.elf
> > 
> > Both are stripped but work as they are on the corresponding boards.
> > 
> > In "build_dir/target-arc_arc700_uClibc-1.0.9/linux-arc770_generic/linux-4.4.7/"
> > I have perfectly unstripped vmlinux but it won't work on either board because of
> > missing device tree blob.
> > 
> > That means if one wants to get image for a board X with debug symbols he or she
> > will need to do manual patching in of .dtb. Which is not the most convenient thing ever.
> It's a lot simpler than that: You can boot the stripped and patched elf
> image from bin/ and use the vmlinux from the kernel source for the
> debugger afterwards. They are fully compatible.

Good point. So indeed if we do want stuff in "bin/" folder to be stripped
that seems to be the simplest approach.

But what if we with addition of another config option:
 a) toggle kernel's CONFIG_DEBUG_INFO
 b) use "--strip-unneeded" instead of currently used "-S" (which is an alias to "--strip-all").

-Alexey
Felix Fietkau May 18, 2016, 2:03 p.m. UTC | #6
On 2016-05-18 15:59, Alexey Brodkin wrote:
> Hi Felix,
> 
> On Wed, 2016-05-18 at 15:49 +0200, Felix Fietkau wrote:
>> On 2016-05-18 15:06, Alexey Brodkin wrote:
>> > 
>> > Hi Felix,
>> > 
>> > On Wed, 2016-05-18 at 14:57 +0200, Felix Fietkau wrote:
>> > > 
>> > > On 2016-05-16 16:42, Alexey Brodkin wrote:
>> > > > 
>> > > > 
>> > > > If an image gets built as an Elf there's a chance
>> > > > it will be used by developers for debugging purposes.
>> > > > In that case it's very helpful to keep debugging info
>> > > > in that image.
>> > > > 
>> > > > I would think that most OWRT-powered devices in production
>> > > > will use some form of binary image for booting so Elf
>> > > > flavours could be left a bit bulkier with more debug info
>> > > > inside.
>> > > > 
>> > > > Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
>> > > You can get the bulky one directly from the kernel source directory, and
>> > > there is definitely some value in having stripped ELF binaries as well
>> > > for devices that can load them.
>> > Well indeed in kernel's source directory we have an unstripped elf.
>> > But what happens at least in case of ARC we build only one kernel's elf
>> > and then as a post-built step we patch in .dtb for all boards we build OWRT.
>> > 
>> > In other words in "bin/arc770-uClibc" folder I have:
>> >  1) openwrt-arc770-generic-axs101-initramfs.elf
>> >  2) openwrt-arc770-generic-nsim_700-initramfs.elf
>> > 
>> > Both are stripped but work as they are on the corresponding boards.
>> > 
>> > In "build_dir/target-arc_arc700_uClibc-1.0.9/linux-arc770_generic/linux-4.4.7/"
>> > I have perfectly unstripped vmlinux but it won't work on either board because of
>> > missing device tree blob.
>> > 
>> > That means if one wants to get image for a board X with debug symbols he or she
>> > will need to do manual patching in of .dtb. Which is not the most convenient thing ever.
>> It's a lot simpler than that: You can boot the stripped and patched elf
>> image from bin/ and use the vmlinux from the kernel source for the
>> debugger afterwards. They are fully compatible.
> 
> Good point. So indeed if we do want stuff in "bin/" folder to be stripped
> that seems to be the simplest approach.
> 
> But what if we with addition of another config option:
>  a) toggle kernel's CONFIG_DEBUG_INFO
There's a config option for that already, and it's enabled by default.

>  b) use "--strip-unneeded" instead of currently used "-S" (which is an alias to "--strip-all").
Why?

- Felix
diff mbox

Patch

diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk
index 406fd46..0166dc5 100644
--- a/include/kernel-defaults.mk
+++ b/include/kernel-defaults.mk
@@ -142,7 +142,7 @@  endif
 define Kernel/CopyImage
 	cmp -s $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug || { \
 		$(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1); \
-		$(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf; \
+		$(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf; \
 		$(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug; \
 		$(foreach k, \
 			$(if $(KERNEL_IMAGES),$(KERNEL_IMAGES),$(filter-out dtbs,$(KERNELNAME))), \