diff options
Diffstat (limited to 'binutils/testsuite/binutils-all/objcopy.exp')
-rw-r--r-- | binutils/testsuite/binutils-all/objcopy.exp | 67 |
1 files changed, 67 insertions, 0 deletions
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" + } } } |