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