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.
if { [istarget *-*-cygwin] || [istarget *-*-mingw*] } {
set test_prog "testprog.exe"
} else {
set test_prog "testprog"
}
set exe [exeext]
set test_prog "testprog${exe}"
proc copy_setup { } {
global srcdir
@ -1342,6 +1339,13 @@ proc objcopy_remove_relocations_from_executable { } {
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 [prune_warnings $exec_output1]
if ![string equal "" $exec_output1] {
fail $test
return
}
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] } {
fail $test
@ -1350,7 +1354,9 @@ proc objcopy_remove_relocations_from_executable { } {
pass $test
}
objcopy_remove_relocations_from_executable
if [is_elf_format] {
objcopy_remove_relocations_from_executable
}
run_dump_test "pr23633"

View File

@ -62,6 +62,7 @@ set obj o
if { [istarget "*-*-vms"] } then {
set obj obj
}
set exe [exeext]
# The remaining tests require a test file.
@ -519,6 +520,7 @@ proc test_build_id_debuglink {} {
global OBJCOPY
global OBJDUMP
global CFLAGS_FOR_TARGET
global exe
set test "build-id-debuglink"
@ -528,7 +530,7 @@ proc test_build_id_debuglink {} {
}
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)"
return
}
@ -539,12 +541,12 @@ proc test_build_id_debuglink {} {
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)"
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)"
return
}
@ -813,15 +815,16 @@ proc test_objdump_S { } {
global subdir
global OBJDUMP
global OBJDUMPFLAGS
global exe
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)"
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"
@ -833,7 +836,7 @@ proc test_objdump_S { } {
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"

View File

@ -183,6 +183,18 @@ proc is_rela { binary_file } {
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
# in square brackets or as machine triplet otherwise.
#