From 5c680d3f29a0f7073b32e00bc5d4fda17c5e89f0 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 27 Sep 1994 22:23:51 +0000 Subject: [PATCH] * config/unix-ld.exp: Set ld using findfile. * lib/ld.exp (default_ld_relocate): Return a value. Change format of log messages. (default_ld_compile): Likewise. (default_ld_link): Likewise. Also, don't include $BFDLIB and $LIBIBERTY in link. * ld.bootstrap/bootstrap.exp: Rewrite. * ld.cdtest/cdtest.exp: Rewrite. * ld.cdtest/cdtest-foo.cc: Update from top level ld directory. * ld.cdtest/cdtest-foo.h: Likewise. * ld.cdtest/cdtest-main.cc: Likewise. --- ld/testsuite/ChangeLog | 19 ++++ ld/testsuite/config/unix-ld.exp | 4 +- ld/testsuite/ld.bootstrap/bootstrap.exp | 114 +++++++++-------------- ld/testsuite/ld.cdtest/cdtest-foo.cc | 8 +- ld/testsuite/ld.cdtest/cdtest-foo.h | 4 +- ld/testsuite/ld.cdtest/cdtest-main.cc | 27 +++--- ld/testsuite/ld.cdtest/cdtest.exp | 118 ++++++++++++------------ ld/testsuite/lib/ld.exp | 54 ++++++----- 8 files changed, 179 insertions(+), 169 deletions(-) diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 8317b2ac399..12c192082e2 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,22 @@ +Tue Sep 27 14:59:51 1994 Ian Lance Taylor (ian@sanguine.cygnus.com) + + * config/unix-ld.exp: Set ld using findfile. + * lib/ld.exp (default_ld_relocate): Return a value. Change format + of log messages. + (default_ld_compile): Likewise. + (default_ld_link): Likewise. Also, don't include $BFDLIB and + $LIBIBERTY in link. + * ld.bootstrap/bootstrap.exp: Rewrite. + * ld.cdtest/cdtest.exp: Rewrite. + * ld.cdtest/cdtest-foo.cc: Update from top level ld directory. + * ld.cdtest/cdtest-foo.h: Likewise. + * ld.cdtest/cdtest-main.cc: Likewise. + +Fri May 27 09:35:04 1994 Ken Raeburn (raeburn@cygnus.com) + + * ld.cdtest/cdtest.exp: Don't look for $result before it's + defined. + Tue May 17 15:06:49 1994 Bill Cox (bill@rtl.cygnus.com) * ld.bootstrap/bootstrap.exp, lib/ld.exp: Replace error proc diff --git a/ld/testsuite/config/unix-ld.exp b/ld/testsuite/config/unix-ld.exp index 3720d1a2ce2..99ffb539251 100644 --- a/ld/testsuite/config/unix-ld.exp +++ b/ld/testsuite/config/unix-ld.exp @@ -21,7 +21,9 @@ # Written by Jeffrey Wheat (cassidy@cygnus.com) # -set ld $objdir/ld.new +if ![info exists ld] then { + set ld [findfile $objdir/ld.new $objdir/ld.new [transform ld]] +} # load the utility procedures load_lib ld.exp diff --git a/ld/testsuite/ld.bootstrap/bootstrap.exp b/ld/testsuite/ld.bootstrap/bootstrap.exp index 66337bf48c1..76d95b5ead5 100644 --- a/ld/testsuite/ld.bootstrap/bootstrap.exp +++ b/ld/testsuite/ld.bootstrap/bootstrap.exp @@ -1,6 +1,5 @@ -# # Expect script for LD Bootstrap Tests -# Copyright (C) 1993 Free Software Foundation +# Copyright (C) 1993,1994 Free Software Foundation # # 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 @@ -16,84 +15,63 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ # -# $Id$ -# # Written by Jeffrey Wheat (cassidy@cygnus.com) +# Rewritten by Ian Lance Taylor (ian@cygnus.com) # -if $tracelevel then { - strace $tracelevel -} +# Make sure that ld can bootstrap itself. -set tmpdir /tmp +# This test can only be run if ld generates native executables. +if ![isnative] {return} -set stage 0 +# This test can only be run if we have the ld build directory, since +# we need the object files. +if {$ld != "$objdir/ld.new"} {return} -# -# link an object using relocation -# +if ![file isdirectory tmpdir] {catch "exec mkdir tmpdir" status} -ld_relocate $objdir/ld.new $tmpdir/ld-partial.o $OFILES - -ld_link $objdir/ld.new $tmpdir/ld.partial $tmpdir/ld-partial.o +# Bootstrap ld. First link the object files together using -r, in +# order to test -r. Then link the result into an executable, ld1, to +# really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a +# new ld, ld3. ld2 and ld3 should be identical. -ld_link $tmpdir/ld.partial $tmpdir/ld.full $OFILES +foreach flags {"" "--static" "--traditional-format" "--no-keep-memory"} { + if {"$flags" != ""} { + set testname "bootstrap with $flags" + } else { + set testname "bootstrap" + } -ld_link $tmpdir/ld.full $tmpdir/ld.$stage $OFILES + if ![ld_relocate $ld tmpdir/ld-partial.o "$flags $OFILES"] { + fail $testname + return + } -# -# main test loop -# -for { set stage 0 } { $stage < 9 } { incr stage } { - - global OFILES - global BFDLIB - global LIBIBERTY - global HOSTING_EMU - global HOSTING_CRT0 - global HOSTING_LIBS - - set status -1 - - set tmpstage $stage - set ld_old $tmpdir/ld.$stage - set ld_new $tmpdir/ld.[incr tmpstage] - - verbose "### Running test $target\n" 1 - verbose "### stage is now $stage\n" 1 - - # link the target with itself - ld_link $ld_old $ld_new $OFILES - - # load (compare) the target - if ![file exists $ld_old] then { - unresolved "$ld_old doesn't exist." + if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY"] { + fail $testname + return } - - if ![file exists $ld_new] then { - unresolved "$ld_new doesn't exist." + + if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] { + fail $testname + return } - - # compare the old and new targets - set status [ eval ld_load "$ld_old $ld_new" ] - case $status in { - "0" { - pass "$ld_old == $ld_new" - } - "1" { - fail "$tmptarget aborted" - } - "-1" { - perror "Couldn't load $tmptarget." - } + + if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY"] { + fail $testname + return } -# remove generated targets -verbose "### EXEC exec rm -f $ld_old" -catch "exec rm -f $ld_old" result -} + send_log "cmp tmpdir/ld2 tmpdir/ld3\n" + verbose "cmp tmpdir/ld2 tmpdir/ld3" + catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output -# remove last generated targets -verbose "### EXEC rm -f $ld_old $ld_new" -catch "exec rm -f $ld_old $ld_new" result -ld_exit + if [string match "" $exec_output] then { + pass $testname + } else { + send_log "$exec_output\n" + verbose "$exec_output" 1 + + fail $testname + } +} diff --git a/ld/testsuite/ld.cdtest/cdtest-foo.cc b/ld/testsuite/ld.cdtest/cdtest-foo.cc index 40be44bd9bd..615e33cea78 100644 --- a/ld/testsuite/ld.cdtest/cdtest-foo.cc +++ b/ld/testsuite/ld.cdtest/cdtest-foo.cc @@ -1,5 +1,5 @@ // Class Foo -//#pragma implementation +#pragma implementation // We don't use header files, since we only want to see, whether the @@ -18,8 +18,6 @@ extern "C" { #include "cdtest-foo.h" -const Foo::len = FOO_MSG_LEN; - int Foo::foos = 0; void Foo::init_foo () @@ -56,7 +54,7 @@ Foo::Foo (const Foo& foo) { i = ++foos; #ifdef WITH_ADDR - printf ("Initializing Foo(%d) \"%s\" at %08x with Foo(%d) %08x\n", + printf ("Initializing Foo(%d) \"%s\" at %08x with Foo(%d) %08x\n", i, foo.message, this, foo.i, &foo); #else printf ("Initializing Foo(%d) \"%s\" with Foo(%d)\n",i, foo.message, foo.i); @@ -68,7 +66,7 @@ Foo::Foo (const Foo& foo) Foo& Foo::operator= (const Foo& foo) { #ifdef WITH_ADDR - printf ("Copying Foo(%d) \"%s\" at %08x to Foo(%d) %08x\n", + printf ("Copying Foo(%d) \"%s\" at %08x to Foo(%d) %08x\n", foo.i, foo.message, &foo, i, this); #else printf ("Copying Foo(%d) \"%s\" to Foo(%d)\n", foo.i, foo.message, i); diff --git a/ld/testsuite/ld.cdtest/cdtest-foo.h b/ld/testsuite/ld.cdtest/cdtest-foo.h index 35b3a5c2478..0ba2d37b272 100644 --- a/ld/testsuite/ld.cdtest/cdtest-foo.h +++ b/ld/testsuite/ld.cdtest/cdtest-foo.h @@ -11,8 +11,8 @@ class Foo { static int foos; int i; - static const int len; - char message[FOO_MSG_LEN]; + const len = FOO_MSG_LEN; + char message[len]; public: static void init_foo (); static int nb_foos() { return foos; } diff --git a/ld/testsuite/ld.cdtest/cdtest-main.cc b/ld/testsuite/ld.cdtest/cdtest-main.cc index ac4b0387ea2..4b99b5c5f0f 100644 --- a/ld/testsuite/ld.cdtest/cdtest-main.cc +++ b/ld/testsuite/ld.cdtest/cdtest-main.cc @@ -1,12 +1,14 @@ // main program for Class Foo +extern "C" { +// Some implementations (e.g. SUNOS 4.1) are broken, +// in that they require . But, if gcc/g++ is installed +// correctly, you should get gcc's assert.h. +// If the compile fails, it means the wrong include files are in use! +#include +}; #include "cdtest-foo.h" -// If we're using "../gcc/xgcc -B../gcc/", we may not have fixed C++ -// header files to work with. So we can't use assert.h here. -extern "C" void exit (int); -#define assert(X) if (!(X)) exit(1) - extern "C" void __init_start(); extern Foo f(void); @@ -14,24 +16,25 @@ extern void g(void); /* This function should *not* be called by the environment. There is no way in C++ to ``run something after the initializers but before main()''. - The library that depends on this (NIHCL) is broken. -- John Gilmore + The library that depends on this (NIHCL) is broken. -- John Gilmore We leave this here to test that future changes to the compiler do not re-introduce this losing ``feature''. */ -void +void __init_start() { Foo::init_foo(); } -static Foo static_foo( "static_foo"); +static Foo static_foo( "static_foo"); -main() -{ +main() +{ assert (Foo::nb_foos() == 2); Foo automatic_foo( "automatic_foo"); Foo bla_foo = f(); assert (Foo::nb_foos() == 4); g(); assert (Foo::nb_foos() == 4); - // `automatic_foo' and `bla_foo' are destructed here -} + // `automatic_foo' and `bla_foo' are destructed here +} + diff --git a/ld/testsuite/ld.cdtest/cdtest.exp b/ld/testsuite/ld.cdtest/cdtest.exp index 43acad486aa..e605c6118ff 100644 --- a/ld/testsuite/ld.cdtest/cdtest.exp +++ b/ld/testsuite/ld.cdtest/cdtest.exp @@ -1,6 +1,5 @@ -# # Expect script for LD cdtest Tests -# Copyright (C) 1993 Free Software Foundation +# Copyright (C) 1993,1994 Free Software Foundation # # 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 @@ -17,71 +16,74 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ # # Written by Jeffrey Wheat (cassidy@cygnus.com) +# Rewritten by Ian Lance Taylor (ian@cygnus.com) # -# -# Bugs: -# + Assumes native toolchain, not cross. -# + Doesn't detect compilation failures (including lack of C++ compiler) -# cleanly. -# + Shouldn't use fixed names in /tmp for temp files -- either use names -# in current directory, or generate unique names. -# - -if $tracelevel then { - strace $tracelevel -} +# Make sure that constructors are handled correctly. -set tmpdir /tmp -set ld $objdir/ld.new +# This test requires running the executable generated by ld. +if ![isnative] {return} -set objects "$tmpdir/cdtest-main.o $tmpdir/cdtest-bar.o $tmpdir/cdtest-foo.o" +if ![file isdirectory tmpdir] {catch "exec mkdir tmpdir" status} -# compile the dependant objects - -verbose "### Compiling dependant objects\n" - -ld_compile "$CXX $CXXFLAGS" $srcdir/$subdir/cdtest-foo.cc $tmpdir/cdtest-foo.o -ld_compile "$CXX $CXXFLAGS" $srcdir/$subdir/cdtest-bar.cc $tmpdir/cdtest-bar.o -ld_compile "$CXX $CXXFLAGS" $srcdir/$subdir/cdtest-main.cc $tmpdir/cdtest-main.o +if ![ld_compile "$CXX $CXXFLAGS -fgnu-linker" $srcdir$subdir/cdtest-foo.cc tmpdir/cdtest-foo.o] { + return +} +if ![ld_compile "$CXX $CXXFLAGS -fgnu-linker" $srcdir$subdir/cdtest-bar.cc tmpdir/cdtest-bar.o] { + return +} +if ![ld_compile "$CXX $CXXFLAGS -fgnu-linker" $srcdir$subdir/cdtest-main.cc tmpdir/cdtest-main.o] { + return +} -# -# main test loop -# -foreach test [glob -nocomplain $srcdir/$subdir/*.dat] { - global target - global status - global result - - set target "$srcdir/$subdir/[file tail [file rootname $test]]" - set tmptarget "$tmpdir/[file tail [file rootname $test]]" - - verbose "### Running test $target\n" - - # link the target with objects and libraries - ld_link $ld $tmptarget $objects - - # load (execute) the target - if ![file exists $tmptarget] then { - unresolved "$tmptarget doesn't exist." +if ![ld_link $ld tmpdir/cdtest {tmpdir/cdtest-foo.o tmpdir/cdtest-bar.o tmpdir/cdtest-main.o}] { + fail cdtest +} else { + send_log "tmpdir/cdtest >tmpdir/cdtest.out\n" + verbose "tmpdir/cdtest >tmpdir/cdtest.out" + catch "exec tmpdir/cdtest >tmpdir/cdtest.out" exec_output + if ![string match "" $exec_output] then { + send_log "$exec_output\n" + verbose "$exec_output" 1 + fail cdtest } else { - catch "exec $tmptarget > $tmptarget.out" exec_output - - # diff the expected and actual outputs - if [file exists $tmptarget.out] then { - catch "simple_diff $target.dat $tmptarget.out" status + send_log "diff tmpdir/cdtest.out $srcdir$subdir/cdtest.dat\n" + verbose "diff tmpdir/cdtest.out $srcdir$subdir/cdtest.dat" + catch "exec diff tmpdir/cdtest.out $srcdir$subdir/cdtest.dat" exec_output + if [string match "" $exec_output] then { + pass cdtest } else { - fail "$tmptarget.out doesn't exist. error was $status" + send_log "$exec_output\n" + verbose "$exec_output" 1 + fail cdtest } } - # remove generated targets - verbose "Exec exec rm -f $tmptarget.o $tmptarget.out $tmptarget $tmptarget.grt" - catch "exec rm -f $tmptarget.o $tmptarget.out $tmptarget.grt $tmptarget" result } - -# remove dependant objects -verbose "Exec rm -f $objects" -catch "exec rm -f $objects" result -ld_exit - +if ![ld_relocate $ld tmpdir/cdtest.o {-Ur tmpdir/cdtest-foo.o tmpdir/cdtest-bar.o tmpdir/cdtest-main.o}] { + fail "cdtest with -Ur" +} else { + if ![ld_link $ld tmpdir/cdtest tmpdir/cdtest.o] { + fail "cdtest with -Ur" + } else { + send_log "tmpdir/cdtest >tmpdir/cdtest.out\n" + verbose "tmpdir/cdtest >tmpdir/cdtest.out" + catch "exec tmpdir/cdtest >tmpdir/cdtest.out" exec_output + if ![string match "" $exec_output] then { + send_log "$exec_output\n" + verbose "$exec_output" 1 + fail "cdtest with -Ur" + } else { + send_log "diff tmpdir/cdtest.out $srcdir$subdir/cdtest.dat\n" + verbose "diff tmpdir/cdtest.out $srcdir$subdir/cdtest.dat" + catch "exec diff tmpdir/cdtest.out $srcdir$subdir/cdtest.dat" exec_output + if [string match "" $exec_output] then { + pass "cdtest with -Ur" + } else { + send_log "$exec_output\n" + verbose "$exec_output" 1 + fail "cdtest with -Ur" + } + } + } +} diff --git a/ld/testsuite/lib/ld.exp b/ld/testsuite/lib/ld.exp index aeb8454943a..ee395c27b49 100644 --- a/ld/testsuite/lib/ld.exp +++ b/ld/testsuite/lib/ld.exp @@ -4,7 +4,7 @@ # proc default_ld_version { ld } { if { [file exists $ld] == 0 } then { - perror "$ld does not exist" + perror "$ld does not exist" exit 1 } @@ -25,17 +25,20 @@ proc default_ld_relocate { ld target objects } { global HOSTING_EMU if { [file exists $ld] == 0 } then { - perror "$ld does not exist" - exit 1 + perror "$ld does not exist" + return 0 } - send_log "### EXEC \"$ld $HOSTING_EMU -o $target -r $objects\"\n" - verbose "### EXEC \"$ld $HOSTING_EMU -o $target -r $objects\"" + send_log "$ld $HOSTING_EMU -o $target -r $objects\n" + verbose "$ld $HOSTING_EMU -o $target -r $objects" catch "exec $ld $HOSTING_EMU -o $target -r $objects" exec_output - if ![string match "" $exec_output] then { + if [string match "" $exec_output] then { + return 1 + } else { send_log "$exec_output\n" verbose "$exec_output" + return 0 } } @@ -46,27 +49,28 @@ proc default_ld_relocate { ld target objects } { # proc default_ld_link { ld target objects } { - global BFDLIB - global LIBIBERTY global HOSTING_EMU global HOSTING_CRT0 global HOSTING_LIBS set objs "$HOSTING_CRT0 $objects" - set libs "$BFDLIB $LIBIBERTY $HOSTING_LIBS" + set libs "$HOSTING_LIBS" if { [file exists $ld] == 0 } then { - perror "$ld does not exist" - exit 1 + perror "$ld does not exist" + return 0 } - send_log "### EXEC \"$ld $HOSTING_EMU -o $target $objs $libs\"\n" - verbose "### EXEC \"$ld $HOSTING_EMU -o $target $objs $libs\"" + send_log "$ld $HOSTING_EMU -o $target $objs $libs\n" + verbose "$ld $HOSTING_EMU -o $target $objs $libs" catch "exec $ld $HOSTING_EMU -o $target $objs $libs" exec_output - if ![string match "" $exec_output] then { + if [string match "" $exec_output] then { + return 1 + } else { send_log "$exec_output\n" verbose "$exec_output" + return 0 } } @@ -80,17 +84,21 @@ proc default_ld_compile { cc source object } { global subdir if {[which $cc] == 0} then { - perror "$cc does not exist" - exit 1 + perror "$cc does not exist" + return 0 } - - send_log "$cc $CFLAGS -I$srcdir/$subdir -c $source -o $object\n" - verbose "### EXEC \"$cc $CFLAGS -I$srcdir/$subdir -c $source -o $object\"" - - catch "exec $cc $CFLAGS -I$srcdir/$subdir -c $source -o $object" exec_output - if ![string match "" $exec_output] then { + + send_log "$cc -I$srcdir$subdir -c $CFLAGS $source -o $object\n" + verbose "$cc -I$srcdir$subdir -c $CFLAGS $source -o $object" + + catch "exec $cc -I$srcdir$subdir -c $CFLAGS $source -o $object" exec_output + if [string match "" $exec_output] then { + return 1 + } else { send_log "$exec_output\n" verbose "$exec_output" + perror "$source: compilation failed" + return 0 } } @@ -120,7 +128,7 @@ proc simple_diff { file_1 file_2 } { return } - verbose "### Diff'ing: $file_1 $file_2\n" 2 + verbose "# Diff'ing: $file_1 $file_2\n" 2 while { [gets $file_a line] != $eof } { if [regexp "^#.*$" $line] then { -- 2.30.2