* lib/ld-lib.exp (run_dump_test): When checking linker message and
[deliverable/binutils-gdb.git] / ld / testsuite / lib / ld-lib.exp
index d4e996e331e4b1f098789dc0f549a840d82bfdc5..5b2e62b35c5c9e86afc584d3f5bfd839c0413f14 100644 (file)
@@ -1,6 +1,6 @@
 # Support routines for LD testsuite.
 #   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-#    2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+#    2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
@@ -352,6 +352,47 @@ proc default_ld_nm { nm nmflags object } {
     }
 }
 
+# Define various symbols needed when not linking against all
+# target libs.
+proc ld_simple_link_defsyms {} {
+
+    set flags "--defsym __stack_chk_fail=0"
+
+    # ARM targets call __gccmain
+    if {[istarget arm*-*-*]       || \
+        [istarget strongarm*-*-*] || \
+        [istarget xscale*-*-*]    || \
+        [istarget thumb-*-*] } {
+        append flags " --defsym __gccmain=0"
+    }
+
+    # PowerPC EABI code calls __eabi.
+    if {[istarget powerpc*-*-eabi*] || [istarget powerpc*-*-rtems*]} {
+       append flags " --defsym __eabi=0"
+    }
+
+    # mn10200 code calls __truncsipsi2_d0_d2.
+    if {[istarget mn10200*-*-*]} then {
+       append flags " --defsym __truncsipsi2_d0_d2=0"
+    }
+
+    # m6811/m6812 code has references to soft registers.
+    if {[istarget m6811-*-*] || [istarget m6812-*-*]} {
+       append flags " --defsym _.frame=0 --defsym _.d1=0 --defsym _.d2=0"
+       append flags " --defsym _.d3=0 --defsym _.d4=0"
+       append flags " --defsym _.tmp=0 --defsym _.xy=0 --defsym _.z=0"
+    }
+
+    # Some OpenBSD targets have ProPolice and reference __guard and
+    # __stack_smash_handler.
+    if [istarget *-*-openbsd*] {
+       append flags " --defsym __guard=0"
+       append flags " --defsym __stack_smash_handler=0"
+    }
+
+    return $flags
+}
+
 # True if the object format is known to be ELF.
 #
 proc is_elf_format {} {
@@ -362,6 +403,7 @@ proc is_elf_format {} {
         && ![istarget hppa*64*-*-hpux*] \
         && ![istarget *-*-linux*] \
         && ![istarget frv-*-uclinux*] \
+        && ![istarget bfin-*-uclinux] \
         && ![istarget *-*-irix5*] \
         && ![istarget *-*-irix6*] \
         && ![istarget *-*-netbsd*] \
@@ -447,6 +489,7 @@ proc is_aout_format {} {
 proc is_pecoff_format {} {
     if { ![istarget *-*-mingw*] \
         && ![istarget *-*-cygwin*] \
+        && ![istarget *-*-cegcc*] \
         && ![istarget *-*-pe*] } {
        return 0
     }
@@ -564,6 +607,9 @@ proc simple_diff { file_1 file_2 } {
 #       Link assembled files using FLAGS, in the order of the "source"
 #       directives, when using multiple files.
 #
+#   ld_after_inputfiles: FLAGS
+#       Similar to "ld", but put after all input files.
+#
 #   objcopy_linked_file: FLAGS
 #      Run objcopy on the linked file with the specified flags.
 #      This lets you transform the linked file using objcopy, before the
@@ -608,11 +654,13 @@ proc simple_diff { file_1 file_2 } {
 #   error: REGEX
 #      An error with message matching REGEX must be emitted for the test
 #      to pass.  The PROG, objdump, nm and objcopy options have no
-#      meaning and need not supplied if this is present.
+#      meaning and need not supplied if this is present.  Multiple "error"
+#      directives append to the expected linker error message.
 #
 #   warning: REGEX
 #      Expect a linker warning matching REGEX.  It is an error to issue
-#      both "error" and "warning".
+#      both "error" and "warning".  Multiple "warning" directives
+#      append to the expected linker warning message.
 #
 # Each option may occur at most once unless otherwise mentioned.
 #
@@ -626,7 +674,7 @@ proc run_dump_test { name } {
     global OBJDUMP NM AS OBJCOPY READELF LD
     global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS LDFLAGS
     global host_triplet runtests
-    global env
+    global env verbose
 
     if [string match "*/*" $name] {
        set file $name
@@ -650,6 +698,7 @@ proc run_dump_test { name } {
     set run_objcopy 0
     set opts(as) {}
     set opts(ld) {}
+    set opts(ld_after_inputfiles) {}
     set opts(xfail) {}
     set opts(target) {}
     set opts(notarget) {}
@@ -678,6 +727,8 @@ proc run_dump_test { name } {
            xfail {}
            target {}
            notarget {}
+           warning {}
+           error {}
            source {
                # Move any source-specific as-flags to a separate array to
                # simplify processing.
@@ -842,7 +893,7 @@ proc run_dump_test { name } {
        # Add -L$srcdir/$subdir so that the linker command can use
        # linker scripts in the source directory.
        set cmd "$LD $LDFLAGS -L$srcdir/$subdir \
-                  $opts(ld) -o $objfile $objfiles"
+                  $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
 
        send_log "$cmd\n"
        set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
@@ -878,8 +929,9 @@ proc run_dump_test { name } {
            send_log "$comp_output\n"
            verbose "$comp_output" 3
 
-           if { [regexp $expmsg $comp_output] \
-                   && (($cmdret == 0) == ($opts(warning) != "")) } {
+           if { ($expmsg == "") == ($comp_output == "") \
+                   && [regexp $expmsg $comp_output] \
+                   && (($cmdret == 0) == ($opts(error) == "")) } {
                # We have the expected output from ld.
                if { $opts(error) != "" || $program == "" } {
                    pass $testname
@@ -927,6 +979,7 @@ proc run_dump_test { name } {
     set env(LC_ALL) "C"
     send_log "$cmd\n"
     set cmdret [remote_exec host [concat sh -c [list "$cmd 2>ld.tmp"]] "" "/dev/null"]
+    set cmdret [lindex $cmdret 0]
     remote_upload host "ld.tmp"
     set comp_output [prune_warnings [file_contents "ld.tmp"]]
     remote_file host delete "ld.tmp"
@@ -936,16 +989,16 @@ proc run_dump_test { name } {
     } else {
        unset env(LC_ALL)
     }
-    if ![string match "" $comp_output] then {
-       send_log "$comp_output\n"
+    if { $cmdret != 0 || $comp_output != "" } {
+       send_log "exited abnormally with $cmdret, output:$comp_output\n"
        fail $testname
        return
     }
 
-    verbose_eval {[file_contents $dumpfile]} 3
+    if { $verbose > 2 } then { verbose "output is [file_contents $dumpfile]" 3 }
     if { [regexp_diff $dumpfile "${file}.d"] } then {
        fail $testname
-       verbose "output is [file_contents $dumpfile]" 2
+       if { $verbose == 2 } then { verbose "output is [file_contents $dumpfile]" 2 }
        return
     }
 
@@ -992,6 +1045,7 @@ proc regexp_diff { file_1 file_2 } {
     set end_2 0
     set differences 0
     set diff_pass 0
+    set fail_if_match 0
 
     if [file exists $file_1] then {
        set file_a [open $file_1 r]
@@ -1024,6 +1078,10 @@ proc regexp_diff { file_1 file_2 } {
                set end_2 1
                set diff_pass 1
                break
+           } elseif [ string match "#failif" $line_b ] {
+               send_log "fail if no difference\n"
+               verbose "fail if no difference" 3
+               set fail_if_match 1
            } elseif [ string match "#..." $line_b ] {
                if { [gets $file_b line_b] == $eof } {
                    set end_2 1
@@ -1076,6 +1134,14 @@ proc regexp_diff { file_1 file_2 } {
        set differences 1
     }
 
+    if { $fail_if_match } {
+       if { $differences == 0 } {
+           set differences 1
+       } else {
+           set differences 0
+       }
+    }
+
     close $file_a
     close $file_b
 
@@ -1089,9 +1155,25 @@ proc file_contents { filename } {
     return $contents
 }
 
+# Create an archive using ar
+#
+proc ar_simple_create { ar aropts target objects } {
+    remote_file host delete $target
+
+    set exec_output [run_host_cmd "$ar" "$aropts rc $target $objects"]
+    set exec_output [prune_warnings $exec_output]
+
+    if [string match "" $exec_output] then {
+       send_log "$exec_output\n"
+       return 1
+    } else {
+       return 0
+    }
+}
+
 # List contains test-items with 3 items followed by 2 lists, one item and
 # one optional item:
-# 0:name 1:ld options 2:assembler options
+# 0:name 1:ld/ar options 2:assembler options
 # 3:filenames of assembler files 4: action and options. 5: name of output file
 # 6:compiler flags (optional)
 #
@@ -1104,6 +1186,7 @@ proc run_ld_link_tests { ldtests } {
     global ld
     global as
     global nm
+    global ar
     global objdump
     global READELF
     global srcdir
@@ -1111,9 +1194,15 @@ proc run_ld_link_tests { ldtests } {
     global env
     global CC
     global CFLAGS
+    global runtests
 
     foreach testitem $ldtests {
        set testname [lindex $testitem 0]
+
+       if ![runtest_file_p $runtests $testname] then {
+           continue
+       }
+
        set ld_options [lindex $testitem 1]
        set as_options [lindex $testitem 2]
        set src_files  [lindex $testitem 3]
@@ -1157,10 +1246,21 @@ proc run_ld_link_tests { ldtests } {
            continue
        }
 
-       if ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] {
+       if { [regexp ".*\\.a$" $binfile] } {
+           if { ![ar_simple_create $ar $ld_options $binfile "$objfiles"] } {
+               fail $testname
+               set failed 1
+           } else {
+               set failed 0
+           }
+       } elseif { ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] } {
            fail $testname
+           set failed 1
        } else {
            set failed 0
+       }
+
+       if { $failed == 0 } {
            foreach actionlist $actions {
                set action [lindex $actionlist 0]
                set progopts [lindex $actionlist 1]
@@ -1242,12 +1342,6 @@ proc run_ld_link_tests { ldtests } {
     }
 }
 
-
-proc verbose_eval { expr { level 1 } } {
-    global verbose
-    if $verbose>$level then { eval verbose "$expr" $level }
-}
-
 # This definition is taken from an unreleased version of DejaGnu.  Once
 # that version gets released, and has been out in the world for a few
 # months at least, it may be safe to delete this copy.
@@ -1402,7 +1496,7 @@ proc run_ld_link_exec_tests { targets_to_xfail ldtests } {
 # List contains test-items with 3 items followed by 2 lists, one item and
 # one optional item:
 #  0:name
-#  1:link options
+#  1:ld or ar options
 #  2:compile options
 #  3:filenames of source files
 #  4:action and options.
@@ -1425,6 +1519,7 @@ proc run_cc_link_tests { ldtests } {
     global CXX
     global CFLAGS
     global CXXFLAGS
+    global ar
 
     foreach testitem $ldtests {
        set testname [lindex $testitem 0]
@@ -1462,10 +1557,21 @@ proc run_cc_link_tests { ldtests } {
            set cc_cmd $CC
        }
 
-       if ![ld_simple_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles"] {
+       if { [regexp ".*\\.a$" $binfile] } {
+           if { ![ar_simple_create $ar $ldflags $binfile "$objfiles"] } {
+               fail $testname
+               set failed 1
+           } else {
+               set failed 0
+           }
+       } elseif { ![ld_simple_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles"] } {
            fail $testname
+           set failed 1
        } else {
            set failed 0
+       }
+
+       if { $failed == 0 } {
            foreach actionlist $actions {
                set action [lindex $actionlist 0]
                set progopts [lindex $actionlist 1]
@@ -1547,7 +1653,10 @@ proc check_gc_sections_available { } {
        # Some targets don't support gc-sections despite whatever's
        # advertised by ld's options.
        if { [istarget alpha*-*-*]
-            || [istarget ia64-*-*] } {
+            || [istarget mep-*-*]
+            || [istarget ia64-*-*]
+            || [istarget *-*-cygwin]
+            || [istarget *-*-mingw*] } {
            set gc_sections_available_saved 0
            return 0
        }
This page took 0.027774 seconds and 4 git commands to generate.