bfd/
[deliverable/binutils-gdb.git] / ld / testsuite / ld-bootstrap / bootstrap.exp
CommitLineData
252b5132 1# Expect script for LD Bootstrap Tests
f96b4a7b
NC
2# Copyright 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2004,
3# 2006, 2007 Free Software Foundation, Inc.
252b5132 4#
f96b4a7b
NC
5# This file is part of the GNU Binutils.
6#
7# This program is free software; you can redistribute it and/or modify
252b5132 8# it under the terms of the GNU General Public License as published by
f96b4a7b 9# the Free Software Foundation; either version 3 of the License, or
252b5132 10# (at your option) any later version.
f96b4a7b 11#
252b5132
RH
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.
f96b4a7b 16#
252b5132
RH
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
f96b4a7b
NC
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
252b5132
RH
21#
22# Written by Jeffrey Wheat (cassidy@cygnus.com)
23# Rewritten by Ian Lance Taylor (ian@cygnus.com)
24#
25
26# Make sure that ld can bootstrap itself.
27
28# This test can only be run if ld generates native executables.
29if ![isnative] {
30 return
31}
32
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.
37
0085b5a8
RH
38foreach flags {"" "strip" "--static" "--traditional-format"
39 "--no-keep-memory" "--relax"} {
e1753d2c
L
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" != ""} {
252b5132
RH
46 set testname "bootstrap with $flags"
47 } else {
48 set testname "bootstrap"
e1753d2c 49 }}
252b5132 50
0085b5a8
RH
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 ""
55 }
56
252b5132
RH
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
62 }
63
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
69 }
70
0085b5a8 71 if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] {
252b5132
RH
72 fail $testname
73 continue
74 }
75
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.
41c49998
TW
79 if { [istarget "*-*-aix*"]
80 && ![istarget "ia64-*-aix*"]} {
252b5132
RH
81 if {"$flags" == "--static"} {
82 set flags "--static -bI:/lib/syscalls.exp"
83 }
84 }
85
9b3ea03b
DK
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"
91 }
92 }
93
252b5132
RH
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*"
98 }
99
9b3ea03b 100 if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
101 fail $testname
102 continue
103 }
104
e1753d2c
L
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
112 }
113 }
114
9b3ea03b 115 if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
116 fail $testname
117 continue
118 }
119
9b3ea03b 120 if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
121 fail $testname
122 continue
123 }
124
ad995491
L
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
134 }
135 }
66517a2f
L
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
144 }
145 }
ad995491
L
146 }
147
86017ce9 148 if {[istarget "*-*-pe"]
336d6a64
AM
149 || [istarget "*-*-wince"]
150 || [istarget "*-*-cygwin*"]
151 || [istarget "*-*-winnt*"]
99ad8390 152 || [istarget "*-*-mingw*"]
336d6a64
AM
153 || [istarget "*-*-interix*"]
154 || [istarget "*-*-beospe*"]
155 || [istarget "*-*-netbsdpe*"]} {
eccbf555
AM
156 # Trim off the date present in PE binaries by only looking
157 # at the ends of the files
158 # Although this works, a way to set the date would be better.
159 # Removing or zeroing the date stamp in the binary produced by
160 # the linker is not possible as it is required by the target OS.
161 set do_compare [string map {16 220 f1 tmpdir/ld2 f2 tmpdir/ld3 tmp-foo1 tmpdir/ld2tail tmp-foo2 tmpdir/ld3tail} $DO_COMPARE]
162 send_log "$do_compare\n"
163 verbose "$do_compare"
164 catch "exec sh -c [list $do_compare]" exec_output
86017ce9 165 } else {
eccbf555
AM
166 send_log "cmp tmpdir/ld2 tmpdir/ld3\n"
167 verbose "cmp tmpdir/ld2 tmpdir/ld3"
168 catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output
86017ce9 169 }
252b5132
RH
170 set exec_output [prune_warnings $exec_output]
171
172 if [string match "" $exec_output] then {
173 pass $testname
174 } else {
175 send_log "$exec_output\n"
176 verbose "$exec_output" 1
177
178 fail $testname
179 }
180}
9ab80182
JB
181
182catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status
eccbf555 183catch "exec rm -f tmpdir/ld2tail tmpdir/ld3tail" status
This page took 0.581632 seconds and 4 git commands to generate.