diff options
author | Nick Clifton <nickc@redhat.com> | 2015-08-05 16:16:39 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2015-08-05 16:16:39 +0100 |
commit | 63b9bbb7d7bcdcb6e0f59dd8da9615d80c537b8d (patch) | |
tree | 63a87d567a4c30e48ed3ae9784fe5b03e3621a31 /binutils | |
parent | 260439cb8ec21ffd75b240aadc55fd341c8c8dd4 (diff) | |
download | gdb-63b9bbb7d7bcdcb6e0f59dd8da9615d80c537b8d.zip gdb-63b9bbb7d7bcdcb6e0f59dd8da9615d80c537b8d.tar.gz gdb-63b9bbb7d7bcdcb6e0f59dd8da9615d80c537b8d.tar.bz2 |
Change the behaviour of the --only-keep-debug option to objcopy and strip so that the sh_link and sh_info fields in stripped section headers are preserved.
bfd * elf.c (_bfd_elf_copy_private_bfd_data): Copy the sh_link and
sh_info fields of sections whose type has been changed to
SHT_NOBITS.
bin * doc/binutils.texi: Document that the --only-keep-debug option
to strip and objcopy preserves the section headers of stripped
sections.
tests * binutils-all/objcopy.exp (keep_debug_symbols_and_check_links):
New proc. Checks that debug-info-only binaries retain the
sh_link field in stripped sections.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/ChangeLog | 6 | ||||
-rw-r--r-- | binutils/doc/binutils.texi | 17 | ||||
-rw-r--r-- | binutils/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/objcopy.exp | 67 |
4 files changed, 94 insertions, 2 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 33c5e7d..0b5ff7f 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,9 @@ +2015-08-05 Nick Clifton <nickc@redhat.com> + + * doc/binutils.texi: Document that the --only-keep-debug option + to strip and objcopy preserves the section headers of stripped + sections. + 2015-08-04 Yuriy M. Kaminskiy" <yumkam@gmail.com> Tyler Hicks <tyhicks@canonical.com> diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index 466f125..fef5f3e 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -1731,6 +1731,12 @@ Strip a file, removing contents of any sections that would not be stripped by @option{--strip-debug} and leaving the debugging sections intact. In ELF files, this preserves all note sections in the output. +Note - the section headers of the stripped sections are preserved, +including their sizes, but the contents of the section are discarded. +The section headers are preserved so that other tools can match up the +debuginfo file with the real executable, even if that executable has +been relocated to a different address space. + The intention is that this option will be used in conjunction with @option{--add-gnu-debuglink} to create a two part executable. One a stripped binary which will occupy less space in RAM and in a @@ -3074,9 +3080,16 @@ When stripping a file, perhaps with @option{--strip-debug} or which would otherwise get stripped. @item --only-keep-debug -Strip a file, removing contents of any sections that would not be +Strip a file, emptying the contents of any sections that would not be stripped by @option{--strip-debug} and leaving the debugging sections -intact. In ELF files, this preserves all note sections in the output. +intact. In ELF files, this preserves all the note sections in the +output as well. + +Note - the section headers of the stripped sections are preserved, +including their sizes, but the contents of the section are discarded. +The section headers are preserved so that other tools can match up the +debuginfo file with the real executable, even if that executable has +been relocated to a different address space. The intention is that this option will be used in conjunction with @option{--add-gnu-debuglink} to create a two part executable. One a diff --git a/binutils/testsuite/ChangeLog b/binutils/testsuite/ChangeLog index 1076ca7..9255fb9 100644 --- a/binutils/testsuite/ChangeLog +++ b/binutils/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-08-05 Nick Clifton <nickc@redhat.com> + + * binutils-all/objcopy.exp (keep_debug_symbols_and_check_links): + New proc. Checks that debug-info-only binaries retain the + sh_link field in stripped sections. + 2015-08-04 Nick Clifton <nickc@redhat.com> * lib/utils-lib.exp (run_dump_test): Document DUMPPROG, readelf diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp index ae21b22..01d2e17 100644 --- a/binutils/testsuite/binutils-all/objcopy.exp +++ b/binutils/testsuite/binutils-all/objcopy.exp @@ -829,12 +829,70 @@ proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } pass $test2 } +# Tests that in a debug only copy of a file the sections +# headers whoes types have been changed to NOBITS still +# retain their sh_link fields. + +proc keep_debug_symbols_and_check_links { prog flags test } { + global READELF + + remote_file build delete tmpdir/striprog + remote_download build tmpdir/copyprog tmpdir/striprog + if [is_remote host] { + set copyfile [remote_download host tmpdir/striprog] + } else { + set copyfile tmpdir/striprog + } + + set exec_output [binutils_run $prog "$flags ${copyfile}"] + if ![string match "" $exec_output] { + fail $test + return + } + + set got [binutils_run $READELF "-S --wide ${copyfile}"] + + set fails 0 + # Regexp to match a section with NOBITS type and extract its name and sh_link fields + while {[regexp \ + {[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ ]+NOBITS[ ]+[0-9a-fA-F]+ [0-9a-fA-F]+ [0-9a-fA-F]+ [0-9]+[ A]+([0-9]+)(.*)} \ + $got all name link rest]} { + set sh_link 0x$link + if {$sh_link == 0} { + # Only some NOBITS sections should have a non-zero sh_link field. + # Look for them by name. + verbose "NOBITS section .$name has a 0 sh_link field\n" + switch $name { + "rela.*" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } + "rel.*" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } + "hash" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } + "gnu_version" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } + "dynsym" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } + "gnu.version_r" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } + "dynamic" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } + "symtab" { set fails 1 ; send_log "Expected non-zero sh_link for .$name\n" } + } + } + set got $rest + } + + if {$fails == 0} { + pass $test + } else { + fail $test + } +} + + set test1 "simple objcopy of executable" set test2 "run objcopy of executable" set test3 "run stripped executable" set test4 "run stripped executable with saving a symbol" set test5 "keep only debug data" set test6 "simple objcopy of debug data" +if [is_elf_format] { + set test7 "NOBITS sections retain sh_link field" +} switch [copy_setup] { "1" { @@ -847,6 +905,9 @@ switch [copy_setup] { untested $test4 untested $test5 untested $test6 + if [is_elf_format] { + untested $test7 + } } "3" { copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "" @@ -855,6 +916,9 @@ switch [copy_setup] { unsupported $test4 unsupported $test5 unsupported $test6 + if [is_elf_format] { + unsupported $test7 + } } "0" { copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2" @@ -862,6 +926,9 @@ switch [copy_setup] { strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test4" keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test5" \ "$OBJCOPY" "$OBJCOPYFLAGS" "$test6" + if [is_elf_format] { + keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test7" + } } } |