Avoid exponential behavior in rust_evaluate_subexp
[deliverable/binutils-gdb.git] / ld / testsuite / ld-bootstrap / bootstrap.exp
CommitLineData
252b5132 1# Expect script for LD Bootstrap Tests
2571583a 2# Copyright (C) 1993-2017 Free Software Foundation, Inc.
252b5132 3#
f96b4a7b
NC
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
252b5132 7# it under the terms of the GNU General Public License as published by
f96b4a7b 8# the Free Software Foundation; either version 3 of the License, or
252b5132 9# (at your option) any later version.
f96b4a7b 10#
252b5132
RH
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
f96b4a7b 15#
252b5132
RH
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
f96b4a7b
NC
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
252b5132
RH
20#
21# Written by Jeffrey Wheat (cassidy@cygnus.com)
22# Rewritten by Ian Lance Taylor (ian@cygnus.com)
23#
24
25# Make sure that ld can bootstrap itself.
26
27# This test can only be run if ld generates native executables.
28if ![isnative] {
29 return
30}
31
ed948520
NC
32# Determine if plugin support is present.
33remote_exec host "$nm --help" "" "/dev/null" "plugin-support"
34set tmp [file_contents "plugin-support"]
35regexp ".*\(--plugin\).*\n" $tmp foo plugins
36if [info exists plugins] then {
37 set plugins "yes"
38} else {
39 set plugins "no"
40}
41
5d3236ee
DK
42# LD can have plugin support even if BFD does not.
43if [check_plugin_api_available] {
44 set plugins "yes"
45}
46
252b5132
RH
47# Bootstrap ld. First link the object files together using -r, in
48# order to test -r. Then link the result into an executable, ld1, to
49# really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a
50# new ld, ld3. ld2 and ld3 should be identical.
d9816402
AM
51set test_flags {"" "strip" "--static" "-Wl,--traditional-format"
52 "-Wl,--no-keep-memory" "-Wl,--relax"}
a97726da 53if { [istarget "powerpc-*-*"] } {
d9816402
AM
54 lappend test_flags "-Wl,--ppc476-workaround"
55}
56
57set gcc_B_opt_save $gcc_B_opt
58
59foreach ldexe {ld1 ld2 ld3} {
60 if {![file isdirectory tmpdir/gcc$ldexe]} then {
61 catch "exec mkdir tmpdir/gcc$ldexe" status
62 catch "exec ln -s ../$ldexe tmpdir/gcc$ldexe/ld" status
63 catch "exec ln -s ld tmpdir/gcc$ldexe/collect-ld" status
64 catch "exec ln -s ../../../gas/as-new tmpdir/gcc$ldexe/as" status
65 }
a97726da 66}
252b5132 67
a97726da 68foreach flags $test_flags {
d9816402 69 set gcc_B_opt $gcc_B_opt_save
e1753d2c
L
70 set do_strip "no"
71 if {"$flags" == "strip"} {
72 set testname "bootstrap with $flags"
73 set flags ""
74 set do_strip "yes"
75 } else { if {"$flags" != ""} {
252b5132
RH
76 set testname "bootstrap with $flags"
77 } else {
78 set testname "bootstrap"
e1753d2c 79 }}
252b5132 80
0085b5a8 81 # --static is meaningless and --relax is incompatible with -r.
d9816402
AM
82 regsub -- "-Wl," $flags "" partial_flags
83 if { "$partial_flags" == "--static" || "$partial_flags" == "--relax" } {
0085b5a8
RH
84 set partial_flags ""
85 }
86
a97726da
AM
87 if { $partial_flags == "--ppc476-workaround" } {
88 append partial_flags " -T $srcdir/$subdir/ppc476.t"
89 }
90
252b5132
RH
91 # This test can only be run if we have the ld build directory,
92 # since we need the object files.
93 if {$ld != "$objdir/ld-new"} {
94 untested $testname
95 continue
96 }
97
ed948520 98 # Plugin support requires linking with a dynamic library which
66a3cb9c 99 # means that these tests will fail.
ed948520
NC
100 if { $flags == "--static" && $plugins == "yes" } then {
101 untested $testname
102 continue
103 }
104
252b5132 105 # If we only have a shared libbfd, we probably can't run the
66a3cb9c 106 # --static test.
252b5132
RH
107 if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then {
108 untested $testname
109 continue
110 }
111
0085b5a8 112 if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] {
252b5132
RH
113 fail $testname
114 continue
115 }
116
117 # On AIX, you need to specify an import list when using --static.
118 # You only want the import list when creating the final
119 # executable.
41c49998
TW
120 if { [istarget "*-*-aix*"]
121 && ![istarget "ia64-*-aix*"]} {
252b5132
RH
122 if {"$flags" == "--static"} {
123 set flags "--static -bI:/lib/syscalls.exp"
124 }
125 }
126
9b3ea03b
DK
127 # On Cygwin, -lintl may require -liconv when linking statically.
128 set extralibs ""
129 if { [istarget "*-*-cygwin*"]} {
130 if {"$flags" == "--static"} {
131 set extralibs "-liconv"
132 }
133 }
134
f24173eb
L
135 # Check if the system's zlib library is used.
136 if {[file exists ../zlib/Makefile ]} then {
137 set extralibs "$extralibs -L../zlib -lz"
138 } else {
139 set extralibs "$extralibs -lz"
140 }
141
ed948520
NC
142 # Plugin support requires linking with libdl.
143 if { $plugins == "yes" } {
fb2c6e43
AT
144 if { ![istarget "*-*-freebsd*"]} {
145 set extralibs "$extralibs -ldl"
146 }
ed948520
NC
147 }
148
252b5132
RH
149 # On Irix 5, linking with --static only works if all the files are
150 # compiled using -non_shared.
151 if {"$flags" == "--static"} {
152 setup_xfail "mips*-*-irix5*"
153 }
154
d9816402 155 if ![ld_link $CC tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
156 fail $testname
157 continue
158 }
159
e1753d2c
L
160 if {"$do_strip" == "yes"} {
161 verbose -log "$strip tmpdir/ld1"
162 catch "exec $strip tmpdir/ld1" exec_output
163 if ![string match "" $exec_output] then {
164 verbose -log "$exec_output"
165 fail $testname
166 continue
167 }
168 }
169
d9816402
AM
170 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld1/ gcc_B_opt
171 if ![ld_link $CC tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
172 fail $testname
173 continue
174 }
175
d9816402
AM
176 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld2/ gcc_B_opt
177 if ![ld_link $CC tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
178 fail $testname
179 continue
180 }
181
d9816402
AM
182 if { "$flags" == "--static" && { [istarget ia64-*-elf*] || [istarget ia64-*-linux*] }
183 || [istarget mips*-*-linux*] } {
184 # On ia64 and mips, tmpdir/ld2 != tmpdir/ld3 is normal since they are
185 # generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
186 # So we rebuild tmpdir/ld2 with tmpdir/ld3.
187 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld3/ gcc_B_opt
188 if ![ld_link $CC tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
189 fail $testname
190 continue
66517a2f 191 }
ad995491
L
192 }
193
86017ce9 194 if {[istarget "*-*-pe"]
336d6a64
AM
195 || [istarget "*-*-wince"]
196 || [istarget "*-*-cygwin*"]
197 || [istarget "*-*-winnt*"]
99ad8390 198 || [istarget "*-*-mingw*"]
336d6a64
AM
199 || [istarget "*-*-interix*"]
200 || [istarget "*-*-beospe*"]
201 || [istarget "*-*-netbsdpe*"]} {
eccbf555
AM
202 # Trim off the date present in PE binaries by only looking
203 # at the ends of the files
204 # Although this works, a way to set the date would be better.
205 # Removing or zeroing the date stamp in the binary produced by
206 # the linker is not possible as it is required by the target OS.
207 set do_compare [string map {16 220 f1 tmpdir/ld2 f2 tmpdir/ld3 tmp-foo1 tmpdir/ld2tail tmp-foo2 tmpdir/ld3tail} $DO_COMPARE]
208 send_log "$do_compare\n"
209 verbose "$do_compare"
210 catch "exec sh -c [list $do_compare]" exec_output
86017ce9 211 } else {
eccbf555
AM
212 send_log "cmp tmpdir/ld2 tmpdir/ld3\n"
213 verbose "cmp tmpdir/ld2 tmpdir/ld3"
214 catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output
86017ce9 215 }
252b5132
RH
216 set exec_output [prune_warnings $exec_output]
217
218 if [string match "" $exec_output] then {
219 pass $testname
220 } else {
221 send_log "$exec_output\n"
222 verbose "$exec_output" 1
223
224 fail $testname
225 }
226}
9ab80182 227
d9816402 228set gcc_B_opt $gcc_B_opt_save
9ab80182 229catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status
eccbf555 230catch "exec rm -f tmpdir/ld2tail tmpdir/ld3tail" status
This page took 0.796609 seconds and 4 git commands to generate.