# 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
     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
     pass $test
 }
 
-objcopy_remove_relocations_from_executable
+if [is_elf_format] {
+    objcopy_remove_relocations_from_executable
+}
 
 run_dump_test "pr23633"
 
 
 if { [istarget "*-*-vms"] } then {
     set obj obj
 }
+set exe [exeext]
 
 # The remaining tests require a test file.
 
     global OBJCOPY
     global OBJDUMP
     global CFLAGS_FOR_TARGET
+    global exe
     
     set 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
     }
        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
     }
     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"
 
 
     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"
 
 
     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.
 #