RFC: Fixing objcopy --only-keep-debug
Nick Clifton
nickc@redhat.com
Tue Jul 28 11:07:00 GMT 2015
Hi Guys,
It seems to me that "objcopy --only-keep-debug" is not doing what it
is supposed to do, ie strip all non-debug sections, leaving a valid,
but truncated binary file:
% cat foo.c
int main (void) { return 0; }
% gcc -g foo.c -o foo
% objcopy --only-keep-debug foo foo.debuginfo
% readelf -S foo.debuginfo
There are 35 section headers, starting at offset 0xbf8:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .interp NOBITS 0000000000400238 00000238
000000000000001c 0000000000000000 A 0 0 1
[ 2] .note.ABI-tag NOTE 0000000000400254 00000254
0000000000000020 0000000000000000 A 0 0 4
[ 3] .note.gnu.build-i NOTE 0000000000400274 00000274
0000000000000024 0000000000000000 A 0 0 4
[ 4] .gnu.hash NOBITS 0000000000400298 00000298
000000000000001c 0000000000000000 A 0 0 8
[ 5] .dynsym NOBITS 00000000004002b8 00000298
0000000000000048 0000000000000018 A 0 1 8
and so on, for 35 sections in total, including .text, .rodata and lots
of other sections that I would not expect to find in a .debuginfo file.
This strikes me as wrong, so I am proposing the attached patch. But
since I am paranoid I am checking here first to see if anyone has a
reason for keeping the current behaviour.
Oh, as an added bonus (?) the patch also extends objcopy's --verbose
option so that it lists sections and symbols that are stripped during
a copy. I found this to be quite helpful in debugging the patch, and
maybe others will like it too. The patch also adds a couple of tests
to the binutils testsuite to check the new behaviour.
I have regression tested the patch with no new failures on lots of
different targets, so I am fairly confident that it will not break
anything.
Any comments or objections ?
Cheers
Nick
binutils/ChangeLog
2015-07-28 Nick Clifton <nickc@redhat.com>
* objcopy (is_non_debug_strip_section): New function.
(filer_symbols): Use the new function. Report any stripped
symbols.
(setup_section): Likewise.
* doc/binutils.texi (objcopy): Document that the --verbose
option displays any stripped sections or symbols.
binutils/testsuite/ChangeLog
2015-07-28 Nick Clifton <nickc@redhat.com>
* binutils-all/strip-12.s: New source file. Contains debug
sections and non-debug sections.
* binutils-all/strip-12.d: New test driver. Checks that
--only-keep-debug leaves debug sections in the copied file.
* binutils-all/strip-13.d: New test driver. Checks that
--only-keep-debug strips out the text and data sections.
* binutils-all/objcopy.exp: Run the new tests.
bfd/ChangeLog
2015-07-28 Nick Clifton <nickc@redhat.com>
* elf.c (ignore_section_sym): Check that output_section exists
before testing its owner.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: objcopy.only-keep-debug.patch
Type: text/x-patch
Size: 5763 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20150728/130e0ac7/attachment.bin>
More information about the Binutils
mailing list