objdump -S test fail on mingw

FAIL: objdump -S
FAIL: objdump --source-comment
is seen on mingw for the simple reason that gcc adds a .exe suffix on
the output file if not already present.  Fix that, and tidy some objcopy
tests.

	* testsuite/lib/binutils-common.exp (exeext): New proc.
	* testsuite/binutils-all/objcopy.exp (exe, test_prog): Use it here.
	(objcopy_remove_relocations_from_executable): Catch objcopy errors.
	Only run on ELF targets.
	* testsuite/binutils-all/objdump.exp (exe): Set variable.
	(test_build_id_debuglink, test_objdump_S): Use exe file suffix.
This commit is contained in:
Alan Modra 2021-08-19 13:15:06 +09:30
parent ee077885e5
commit d4f5b5e214
3 changed files with 33 additions and 12 deletions

View file

@ -631,11 +631,8 @@ strip_test_with_saving_a_symbol
# Build a final executable. # Build a final executable.
if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } { set exe [exeext]
set test_prog "testprog.exe" set test_prog "testprog${exe}"
} else {
set test_prog "testprog"
}
proc copy_setup { } { proc copy_setup { } {
global srcdir global srcdir
@ -1342,6 +1339,13 @@ proc objcopy_remove_relocations_from_executable { } {
set out tmpdir/pr23611.out set out tmpdir/pr23611.out
set exec_output1 [binutils_run $OBJCOPY "-R .rela.plt -R .rela.dyn -R .rel.plt -R .rel.dyn $objfile $out"] set exec_output1 [binutils_run $OBJCOPY "-R .rela.plt -R .rela.dyn -R .rel.plt -R .rel.dyn $objfile $out"]
set exec_output1 [prune_warnings $exec_output1]
if ![string equal "" $exec_output1] {
fail $test
return
}
set exec_output2 [binutils_run $READELF "-S $out"] set exec_output2 [binutils_run $READELF "-S $out"]
if { [string match "*.rel.plt*" $exec_output2] || [string match "*.rela.plt*" $exec_output2] || [string match "*.rel.dyn*" $exec_output2] || [string match "*.rela.dyn*" $exec_output2] } { if { [string match "*.rel.plt*" $exec_output2] || [string match "*.rela.plt*" $exec_output2] || [string match "*.rel.dyn*" $exec_output2] || [string match "*.rela.dyn*" $exec_output2] } {
fail $test fail $test
@ -1350,7 +1354,9 @@ proc objcopy_remove_relocations_from_executable { } {
pass $test pass $test
} }
objcopy_remove_relocations_from_executable if [is_elf_format] {
objcopy_remove_relocations_from_executable
}
run_dump_test "pr23633" run_dump_test "pr23633"

View file

@ -62,6 +62,7 @@ set obj o
if { [istarget "*-*-vms"] } then { if { [istarget "*-*-vms"] } then {
set obj obj set obj obj
} }
set exe [exeext]
# The remaining tests require a test file. # The remaining tests require a test file.
@ -519,6 +520,7 @@ proc test_build_id_debuglink {} {
global OBJCOPY global OBJCOPY
global OBJDUMP global OBJDUMP
global CFLAGS_FOR_TARGET global CFLAGS_FOR_TARGET
global exe
set test "build-id-debuglink" set test "build-id-debuglink"
@ -528,7 +530,7 @@ proc test_build_id_debuglink {} {
} }
set CFLAGS_FOR_TARGET "-g -Wl,--build-id=0x12345678abcdef01" set CFLAGS_FOR_TARGET "-g -Wl,--build-id=0x12345678abcdef01"
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog executable debug] != "" } { if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog${exe} executable debug] != "" } {
unsupported "$test (build)" unsupported "$test (build)"
return return
} }
@ -539,12 +541,12 @@ proc test_build_id_debuglink {} {
unset CFLAGS_FOR_TARGET unset CFLAGS_FOR_TARGET
} }
if { [binutils_run $STRIP "--strip-debug --remove-section=.comment tmpdir/testprog -o tmpdir/testprog.strip"] != "" } { if { [binutils_run $STRIP "--strip-debug --remove-section=.comment tmpdir/testprog${exe} -o tmpdir/testprog.strip"] != "" } {
fail "$test (strip debug info)" fail "$test (strip debug info)"
return return
} }
if { [binutils_run $OBJCOPY "--only-keep-debug tmpdir/testprog tmpdir/testprog.debug"] != "" } { if { [binutils_run $OBJCOPY "--only-keep-debug tmpdir/testprog${exe} tmpdir/testprog.debug"] != "" } {
fail "$test (create separate debug info file)" fail "$test (create separate debug info file)"
return return
} }
@ -813,15 +815,16 @@ proc test_objdump_S { } {
global subdir global subdir
global OBJDUMP global OBJDUMP
global OBJDUMPFLAGS global OBJDUMPFLAGS
global exe
set test "objdump -S" set test "objdump -S"
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog executable debug] != "" } { if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog${exe} executable debug] != "" } {
unsupported "$test (build)" unsupported "$test (build)"
return return
} }
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -D -S tmpdir/testprog"] set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -D -S tmpdir/testprog${exe}"]
set want "static int local = 2" set want "static int local = 2"
@ -833,7 +836,7 @@ proc test_objdump_S { } {
set test "objdump --source-comment" set test "objdump --source-comment"
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble-all --source-comment=// tmpdir/testprog"] set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble-all --source-comment=// tmpdir/testprog${exe}"]
set want "//static int local = 2" set want "//static int local = 2"

View file

@ -183,6 +183,18 @@ proc is_rela { binary_file } {
return 1 return 1
} }
# Return the file name suffix required for executables, if any.
#
proc exeext {} {
if { [istarget *-*-cygwin*]
|| [istarget *-*-mingw*]
|| [istarget *-*-msdos*]
|| [istarget *-*-*vms*] } {
return ".exe"
}
return ""
}
# True if the target matches TARGET, specified as a TCL procedure if # True if the target matches TARGET, specified as a TCL procedure if
# in square brackets or as machine triplet otherwise. # in square brackets or as machine triplet otherwise.
# #