# Support routines for LD testsuite.
-# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
-# 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
proc big_or_little_endian {} {
if [board_info [target_info name] exists multilib_flags] {
- set tmp_flags " [board_info [target_info name] multilib_flags]";
+ set tmp_flags " [board_info [target_info name] multilib_flags]"
foreach x $tmp_flags {
case $x in {
- {*big*endian eb EB -eb -EB} {
+ {*big*endian eb EB -eb -EB -mb} {
set flags " -EB"
return $flags
}
- {*little*endian el EL -el -EL} {
+ {*little*endian el EL -el -EL -ml} {
set flags " -EL"
return $flags
}
proc default_ld_simple_link { ld target objects } {
global host_triplet
global link_output
+ global gcc_ld_flag
if { [which $ld] == 0 } then {
perror "$ld does not exist"
set flags ""
}
+ # If we are compiling with gcc, we want to add gcc_ld_flag to
+ # flags. Rather than determine this in some complex way, we guess
+ # based on the name of the compiler.
+ set ldexe $ld
+ set ldparm [string first " " $ld]
+ if { $ldparm > 0 } then {
+ set ldexe [string range $ld 0 $ldparm]
+ }
+ set ldexe [string replace $ldexe 0 [string last "/" $ldexe] ""]
+ if {[string match "*gcc*" $ldexe] || [string match "*++*" $ldexe]} then {
+ set flags "$gcc_ld_flag $flags"
+ }
+
verbose -log "$ld $flags -o $target $objects"
catch "exec $ld $flags -o $target $objects" link_output
# If we are compiling with gcc, we want to add gcc_gas_flag to
# flags. Rather than determine this in some complex way, we guess
# based on the name of the compiler.
- if {[string match "*gcc*" $cc] || [string match "*++*" $cc]} then {
+ set ccexe $cc
+ set ccparm [string first " " $cc]
+ if { $ccparm > 0 } then {
+ set ccexe [string range $cc 0 $ccparm]
+ }
+ set ccexe [string replace $ccexe 0 [string last "/" $ccexe] ""]
+ if {[string match "*gcc*" $ccexe] || [string match "*++*" $ccexe]} then {
set flags "$gcc_gas_flag $flags"
}
if [board_info [target_info name] exists multilib_flags] {
- append flags " [board_info [target_info name] multilib_flags]";
+ append flags " [board_info [target_info name] multilib_flags]"
}
verbose -log "$cc $flags -c $source -o $object"
&& ![istarget *-*-unixware*] \
&& ![istarget *-*-elf*] \
&& ![istarget *-*-eabi*] \
+ && ![istarget hppa*64*-*-hpux*] \
&& ![istarget *-*-linux*] \
+ && ![istarget frv-*-uclinux*] \
&& ![istarget *-*-irix5*] \
&& ![istarget *-*-irix6*] \
+ && ![istarget *-*-netbsd*] \
&& ![istarget *-*-solaris2*] } {
return 0
}
|| [istarget *-*-linux*oldld*] } {
return 0
}
+
+ if { ![istarget *-*-netbsdelf*] \
+ && ([istarget *-*-netbsd*aout*] \
+ || [istarget *-*-netbsdpe*] \
+ || [istarget arm*-*-netbsd*] \
+ || [istarget sparc-*-netbsd*] \
+ || [istarget i*86-*-netbsd*] \
+ || [istarget m68*-*-netbsd*] \
+ || [istarget vax-*-netbsd*] \
+ || [istarget ns32k-*-netbsd*]) } {
+ return 0
+ }
+ return 1
+}
+
+#
+# is_elf64
+# true if the object format is known to be 64bit ELF
+proc is_elf64 { binary_file } {
+ global READELF
+ global READELFFLAGS
+
+ set readelf_size ""
+ catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
+
+ if ![string match "" $got] then {
+ return 0
+ }
+
+ if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
+ [file_contents readelf.out] nil readelf_size] } {
+ return 0
+ }
+
+ if { $readelf_size == "64" } {
+ return 1
+ }
+
+ 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
+#
+proc is_pecoff_format {} {
+ if { ![istarget *-*-mingw32*] \
+ && ![istarget *-*-cygwin*] \
+ && ![istarget *-*-pe*] } {
+ return 0
+ }
+
return 1
}
# 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
set opts(PROG) {}
set opts(source) {}
set opts(error) {}
+ set opts(warning) {}
set opts(objcopy_linked_file) {}
set asflags(${file}.s) {}
}
}
- 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 {
} else {
set sourcefiles {}
foreach sf $opts(source) {
- lappend sourcefiles "$srcdir/$subdir/$sf"
+ if { [string match "/*" $sf] } {
+ lappend sourcefiles "$sf"
+ } else {
+ lappend sourcefiles "$srcdir/$subdir/$sf"
+ }
# Must have asflags indexed on source name.
set asflags($srcdir/$subdir/$sf) $asflags($sf)
}
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"
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"
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
}
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
return $contents
}
-# List contains test-items with 3 items followed by 2 lists:
+# 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
# 3:filenames of assembler files 4: action and options. 5: name of output file
+# 6:compiler flags (optional)
# Actions:
# objdump: Apply objdump options on result. Compare with regex (last arg).
global srcdir
global subdir
global env
+ global CC
+ global CFLAGS
foreach testitem $ldtests {
set testname [lindex $testitem 0]
set ld_options [lindex $testitem 1]
set as_options [lindex $testitem 2]
- set as_files [lindex $testitem 3]
+ set src_files [lindex $testitem 3]
set actions [lindex $testitem 4]
set binfile tmpdir/[lindex $testitem 5]
+ set cflags [lindex $testitem 6]
set objfiles {}
set is_unresolved 0
set failed 0
# verbose -log "Testname is $testname"
# verbose -log "ld_options is $ld_options"
# verbose -log "as_options is $as_options"
-# verbose -log "as_files is $as_files"
+# verbose -log "src_files is $src_files"
# verbose -log "actions is $actions"
# verbose -log "binfile is $binfile"
# Assemble each file in the test.
- foreach as_file $as_files {
- set objfile "tmpdir/[file rootname $as_file].o"
+ foreach src_file $src_files {
+ set objfile "tmpdir/[file rootname $src_file].o"
lappend objfiles $objfile
- if ![ld_assemble $as "$as_options $srcdir/$subdir/$as_file" $objfile] {
+ if { [file extension $src_file] == ".c" } {
+ set as_file "tmpdir/[file rootname $src_file].s"
+ if ![ld_compile "$CC -S $CFLAGS $cflags" $srcdir/$subdir/$src_file $as_file] {
+ set is_unresolved 1
+ break
+ }
+ } else {
+ set as_file "$srcdir/$subdir/$src_file"
+ }
+ if ![ld_assemble $as "$as_options $as_file" $objfile] {
set is_unresolved 1
break
}