* configure.in: Always pass --target to target configures as
[deliverable/binutils-gdb.git] / ld / testsuite / lib / ld-lib.exp
index b4e3f33ce51411673f386c79e73a6d16c7be53e6..48e9957e66400163b2ce6341b352d4bef3e049e7 100644 (file)
@@ -1,6 +1,6 @@
 # Support routines for LD testsuite.
-#   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
-#   Free Software Foundation, Inc.
+#   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
+#    2004, 2005 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -416,6 +416,36 @@ proc is_elf64 { binary_file } {
     return 0
 }
 
+#
+# is_aout_format
+#      true if the object format is known to be aout
+proc is_aout_format {} {
+    if { [istarget *-*-*\[ab\]out*] \
+            || [istarget *-*-linux*oldld*] \
+            || [istarget *-*-msdos*] \
+            || [istarget arm-*-netbsd] \
+            || [istarget i?86-*-netbsd] \
+            || [istarget i?86-*-mach*] \
+            || [istarget i?86-*-vsta] \
+            || [istarget pdp11-*-*] \
+            || [istarget m68*-ericsson-ose] \
+            || [istarget m68k-hp-bsd*] \
+            || [istarget m68*-*-hpux*] \
+            || [istarget m68*-*-netbsd] \
+            || [istarget m68*-*-netbsd*4k*] \
+            || [istarget m68k-sony-*] \
+            || [istarget m68*-sun-sunos\[34\]*] \
+            || [istarget m68*-wrs-vxworks*] \
+            || [istarget ns32k-*-*] \
+            || [istarget sparc*-*-netbsd] \
+            || [istarget sparc-sun-sunos4*] \
+            || [istarget vax-dec-ultrix*] \
+            || [istarget vax-*-netbsd] } {
+       return 1
+    }
+    return 0
+}
+
 #
 # is_pecoff_format
 #      true if the object format is known to be PECOFF
@@ -587,6 +617,10 @@ proc simple_diff { file_1 file_2 } {
 #      to pass.  The PROG, objdump, nm and objcopy options have no
 #      meaning and need not supplied if this is present.
 #
+#   warning: REGEX
+#      Expect a linker warning matching REGEX.  It is an error to issue
+#      both "error" and "warning".
+#
 # Each option may occur at most once unless otherwise mentioned.
 #
 # After the option lines come regexp lines.  `run_dump_test' calls
@@ -634,6 +668,7 @@ proc run_dump_test { name } {
     set opts(PROG) {}
     set opts(source) {}
     set opts(error) {}
+    set opts(warning) {}
     set opts(objcopy_linked_file) {}
     set asflags(${file}.s) {}
 
@@ -699,49 +734,42 @@ proc run_dump_test { name } {
        }
     }
 
-    if {$opts(PROG) != ""} {
-       switch -- $opts(PROG) {
-           objdump
-               { set program objdump }
-           nm
-               { set program nm }
-           objcopy
-               { set program objcopy }
-           readelf
-               { set program readelf }
-           default
+    set program ""
+    # It's meaningless to require an output-testing method when we
+    # expect an error.
+    if { $opts(error) == "" } {
+       if {$opts(PROG) != ""} {
+           switch -- $opts(PROG) {
+               objdump { set program objdump }
+               nm      { set program nm }
+               objcopy { set program objcopy }
+               readelf { set program readelf }
+               default
                { perror "unrecognized program option $opts(PROG) in $file.d"
                  unresolved $subdir/$name
                  return }
-       }
-    } elseif { $opts(error) != "" } {
-       # It's meaningless to require an output-testing method when we
-       # expect an error.  For simplicity, we fake an arbitrary method.
-       set program "nm"
-    } else {
+           }
+       } else {
        # Guess which program to run, by seeing which option was specified.
-       set program ""
-       foreach p {objdump objcopy nm readelf} {
-           if {$opts($p) != ""} {
-               if {$program != ""} {
-                   perror "ambiguous dump program in $file.d"
-                   unresolved $subdir/$name
-                   return
-               } else {
-                   set program $p
+           foreach p {objdump objcopy nm readelf} {
+               if {$opts($p) != ""} {
+                   if {$program != ""} {
+                       perror "ambiguous dump program in $file.d"
+                       unresolved $subdir/$name
+                       return
+                   } else {
+                       set program $p
+                   }
                }
            }
        }
-       if {$program == ""} {
+       if { $program == "" && $opts(warning) == "" } {
            perror "dump program unspecified in $file.d"
            unresolved $subdir/$name
            return
        }
     }
 
-    set progopts1 $opts($program)
-    eval set progopts \$[string toupper $program]FLAGS
-    eval set binary \$[string toupper $program]
     if { $opts(name) == "" } {
        set testname "$subdir/$name"
     } else {
@@ -755,7 +783,7 @@ proc run_dump_test { name } {
        foreach sf $opts(source) {
            if { [string match "/*" $sf] } {
                lappend sourcefiles "$sf"
-           } {
+           } else {
                lappend sourcefiles "$srcdir/$subdir/$sf"
            }
            # Must have asflags indexed on source name.
@@ -781,22 +809,27 @@ proc run_dump_test { name } {
        set cmdret [catch "exec $cmd" comp_output]
        set comp_output [prune_warnings $comp_output]
 
-       # We accept errors at assembly stage too, unless we're supposed to
-       # link something.
        if { $cmdret != 0 || ![string match "" $comp_output] } then {
            send_log "$comp_output\n"
            verbose "$comp_output" 3
-           if { $opts(error) != "" && $run_ld == 0 } {
-               if [regexp $opts(error) $comp_output] {
-                   pass $testname
-                   return
-               }
-           }
+
+           set exitstat "succeeded"
+           if { $cmdret != 0 } { set exitstat "failed" }
+           verbose -log "$exitstat with: <$comp_output>"
            fail $testname
            return
        }
     }
 
+    set expmsg $opts(error)
+    if { $opts(warning) != "" } {
+       if { $expmsg != "" } {
+           perror "$testname: mixing error and warning test-directives"
+           return
+       }
+       set expmsg $opts(warning)
+    }
+
     # Perhaps link the file(s).
     if { $run_ld } {
        set objfile "tmpdir/dump"
@@ -810,21 +843,20 @@ proc run_dump_test { name } {
        set cmdret [catch "exec $cmd" comp_output]
        set comp_output [prune_warnings $comp_output]
 
-       if { $cmdret != 0 || ![string match "" $comp_output] } then {
-           verbose -log "failed with: <$comp_output>, expected: <$opts(error)>"
-           send_log "$comp_output\n"
-           verbose "$comp_output" 3
-           if { $opts(error) != "" && $run_objcopy == 0 } {
-               if [regexp $opts(error) $comp_output] {
-                   pass $testname
-                   return
-               }
+       if { $cmdret != 0 } then {
+           # If the executed program writes to stderr and stderr is not
+           # redirected, exec *always* returns failure, regardless of the
+           # program exit code.  Thankfully, we can retrieve the true
+           # return status from a special variable.  Redirection would
+           # cause a tcl-specific message to be appended, and we'd rather
+           # not deal with that if we can help it.
+           global errorCode
+           if { [lindex $errorCode 0] == "NONE" } {
+               set cmdret 0
            }
-           fail $testname
-           return
        }
 
-       if { $run_objcopy } {
+       if { $cmdret == 0 && $run_objcopy } {
            set infile $objfile
            set objfile "tmpdir/dump1"
 
@@ -834,18 +866,32 @@ proc run_dump_test { name } {
 
            send_log "$cmd\n"
            set cmdret [catch "exec $cmd" comp_output]
-           set comp_output [prune_warnings $comp_output]
-
-           if { $cmdret != 0 || ![string match "" $comp_output] } then {
-               verbose -log "failed with: <$comp_output>, expected: <$opts(error)>"
-               send_log "$comp_output\n"
-               verbose "$comp_output" 3
-               if { $opts(error) != "" } {
-                   if [regexp $opts(error) $comp_output] {
-                       pass $testname
-                       return
-                   }
+           append comp_output [prune_warnings $comp_output]
+
+           if { $cmdret != 0 } then {
+               global errorCode
+               if { [lindex $errorCode 0] == "NONE" } {
+                   set cmdret 0
                }
+           }
+       }
+
+       if { $cmdret != 0 || $comp_output != "" || $expmsg != "" } then {
+           set exitstat "succeeded"
+           if { $cmdret != 0 } { set exitstat "failed" }
+           verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>"
+           send_log "$comp_output\n"
+           verbose "$comp_output" 3
+
+           if { [regexp $expmsg $comp_output] \
+                   && (($cmdret == 0) == ($opts(warning) != "")) } {
+               # We have the expected output from ld.
+               if { $opts(error) != "" || $program == "" } {
+                   pass $testname
+                   return
+               }
+           } else {
+               verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>"
                fail $testname
                return
            }
@@ -860,6 +906,10 @@ proc run_dump_test { name } {
        return
     }
 
+    set progopts1 $opts($program)
+    eval set progopts \$[string toupper $program]FLAGS
+    eval set binary \$[string toupper $program]
+
     if { [which $binary] == 0 } {
        untested $testname
        return
This page took 0.026339 seconds and 4 git commands to generate.