# 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.
#
}
}
+# 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 {} {
&& ![istarget hppa*64*-*-hpux*] \
&& ![istarget *-*-linux*] \
&& ![istarget frv-*-uclinux*] \
+ && ![istarget bfin-*-uclinux] \
&& ![istarget *-*-irix5*] \
&& ![istarget *-*-irix6*] \
&& ![istarget *-*-netbsd*] \
proc is_pecoff_format {} {
if { ![istarget *-*-mingw*] \
&& ![istarget *-*-cygwin*] \
+ && ![istarget *-*-cegcc*] \
&& ![istarget *-*-pe*] } {
return 0
}
# 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
# 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.
#
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
set run_objcopy 0
set opts(as) {}
set opts(ld) {}
+ set opts(ld_after_inputfiles) {}
set opts(xfail) {}
set opts(target) {}
set opts(notarget) {}
xfail {}
target {}
notarget {}
+ warning {}
+ error {}
source {
# Move any source-specific as-flags to a separate array to
# simplify processing.
# 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"]
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
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"
} 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
}
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]
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
set differences 1
}
+ if { $fail_if_match } {
+ if { $differences == 0 } {
+ set differences 1
+ } else {
+ set differences 0
+ }
+ }
+
close $file_a
close $file_b
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)
#
global ld
global as
global nm
+ global ar
global objdump
global READELF
global srcdir
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]
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]
}
}
-
-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.
# 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.
global CXX
global CFLAGS
global CXXFLAGS
+ global ar
foreach testitem $ldtests {
set testname [lindex $testitem 0]
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]
# 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
}