| 1 |
# Expect script for LD Bootstrap Tests |
| 2 |
# Copyright 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2004 |
| 3 |
# Free Software Foundation, Inc. |
| 4 |
# |
| 5 |
# This file is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 2 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; if not, write to the Free Software |
| 17 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 |
# |
| 19 |
# Written by Jeffrey Wheat ([email protected]) |
| 20 |
# Rewritten by Ian Lance Taylor ([email protected]) |
| 21 |
# |
| 22 |
|
| 23 |
# Make sure that ld can bootstrap itself. |
| 24 |
|
| 25 |
# This test can only be run if ld generates native executables. |
| 26 |
if ![isnative] { |
| 27 |
return |
| 28 |
} |
| 29 |
|
| 30 |
# Bootstrap ld. First link the object files together using -r, in |
| 31 |
# order to test -r. Then link the result into an executable, ld1, to |
| 32 |
# really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a |
| 33 |
# new ld, ld3. ld2 and ld3 should be identical. |
| 34 |
|
| 35 |
foreach flags {"" "strip" "--static" "--traditional-format" |
| 36 |
"--no-keep-memory" "--relax"} { |
| 37 |
set do_strip "no" |
| 38 |
if {"$flags" == "strip"} { |
| 39 |
set testname "bootstrap with $flags" |
| 40 |
set flags "" |
| 41 |
set do_strip "yes" |
| 42 |
} else { if {"$flags" != ""} { |
| 43 |
set testname "bootstrap with $flags" |
| 44 |
} else { |
| 45 |
set testname "bootstrap" |
| 46 |
}} |
| 47 |
|
| 48 |
# --static is meaningless and --relax is incompatible with -r. |
| 49 |
set partial_flags "$flags" |
| 50 |
if { "$flags" == "--static" || "$flags" == "--relax" } { |
| 51 |
set partial_flags "" |
| 52 |
} |
| 53 |
|
| 54 |
# This test can only be run if we have the ld build directory, |
| 55 |
# since we need the object files. |
| 56 |
if {$ld != "$objdir/ld-new"} { |
| 57 |
untested $testname |
| 58 |
continue |
| 59 |
} |
| 60 |
|
| 61 |
# If we only have a shared libbfd, we probably can't run the |
| 62 |
# --static test. |
| 63 |
if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then { |
| 64 |
untested $testname |
| 65 |
continue |
| 66 |
} |
| 67 |
|
| 68 |
if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] { |
| 69 |
fail $testname |
| 70 |
continue |
| 71 |
} |
| 72 |
|
| 73 |
# On AIX, you need to specify an import list when using --static. |
| 74 |
# You only want the import list when creating the final |
| 75 |
# executable. |
| 76 |
if { [istarget "*-*-aix*"] |
| 77 |
&& ![istarget "ia64-*-aix*"]} { |
| 78 |
if {"$flags" == "--static"} { |
| 79 |
set flags "--static -bI:/lib/syscalls.exp" |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
# On Irix 5, linking with --static only works if all the files are |
| 84 |
# compiled using -non_shared. |
| 85 |
if {"$flags" == "--static"} { |
| 86 |
setup_xfail "mips*-*-irix5*" |
| 87 |
} |
| 88 |
|
| 89 |
if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY"] { |
| 90 |
fail $testname |
| 91 |
continue |
| 92 |
} |
| 93 |
|
| 94 |
if {"$do_strip" == "yes"} { |
| 95 |
verbose -log "$strip tmpdir/ld1" |
| 96 |
catch "exec $strip tmpdir/ld1" exec_output |
| 97 |
if ![string match "" $exec_output] then { |
| 98 |
verbose -log "$exec_output" |
| 99 |
fail $testname |
| 100 |
continue |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] { |
| 105 |
fail $testname |
| 106 |
continue |
| 107 |
} |
| 108 |
|
| 109 |
if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY"] { |
| 110 |
fail $testname |
| 111 |
continue |
| 112 |
} |
| 113 |
|
| 114 |
if {"$flags" == "--static"} { |
| 115 |
if { [istarget ia64-*-elf*] |
| 116 |
|| [istarget ia64-*-linux*] } { |
| 117 |
# On ia64, tmpdir/ld2 != tmpdir/ld3 is normal since they are |
| 118 |
# generated by different linkers, tmpdir/ld1 and tmpdir/ld2. |
| 119 |
# So we rebuild tmpdir/ld2 with tmpdir/ld3. |
| 120 |
if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] { |
| 121 |
fail $testname |
| 122 |
continue |
| 123 |
} |
| 124 |
} |
| 125 |
} else { |
| 126 |
if { [istarget mips*-*-linux*] } { |
| 127 |
# On Linux/mips, tmpdir/ld2 != tmpdir/ld3 is normal since |
| 128 |
# they are generated by different linkers, tmpdir/ld1 and |
| 129 |
# tmpdir/ld2. So we rebuild tmpdir/ld2 with tmpdir/ld3. |
| 130 |
if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] { |
| 131 |
fail $testname |
| 132 |
continue |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
send_log "compare (tail of) tmpdir/ld2 tmpdir/ld3\n" |
| 138 |
verbose "compare (tail of) tmpdir/ld2 tmpdir/ld3" |
| 139 |
if {[istarget "*-*-pe"] |
| 140 |
|| [istarget "*-*-wince"] |
| 141 |
|| [istarget "*-*-cygwin*"] |
| 142 |
|| [istarget "*-*-winnt*"] |
| 143 |
|| [istarget "*-*-mingw32*"] |
| 144 |
|| [istarget "*-*-interix*"] |
| 145 |
|| [istarget "*-*-beospe*"] |
| 146 |
|| [istarget "*-*-netbsdpe*"]} { |
| 147 |
# Trim off the date present in PE binaries by only looking |
| 148 |
# at the ends of the files |
| 149 |
# Although this works, a way to set the date would be better. |
| 150 |
# Removing or zeroing the date stamp in the binary produced by |
| 151 |
# the linker is not possible as it is required by the target OS. |
| 152 |
exec tail +140 tmpdir/ld2 >tmpdir/ld2tail |
| 153 |
exec tail +140 tmpdir/ld3 >tmpdir/ld3tail |
| 154 |
catch "exec cmp tmpdir/ld2tail tmpdir/ld3tail" exec_output |
| 155 |
exec rm tmpdir/ld2tail tmpdir/ld3tail |
| 156 |
} else { |
| 157 |
send_log "cmp tmpdir/ld2 tmpdir/ld3\n" |
| 158 |
verbose "cmp tmpdir/ld2 tmpdir/ld3" |
| 159 |
catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output |
| 160 |
} |
| 161 |
set exec_output [prune_warnings $exec_output] |
| 162 |
|
| 163 |
if [string match "" $exec_output] then { |
| 164 |
pass $testname |
| 165 |
} else { |
| 166 |
send_log "$exec_output\n" |
| 167 |
verbose "$exec_output" 1 |
| 168 |
|
| 169 |
fail $testname |
| 170 |
} |
| 171 |
} |