]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/testsuite/ld-bootstrap/bootstrap.exp
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-bootstrap / bootstrap.exp
CommitLineData
252b5132 1# Expect script for LD Bootstrap Tests
b3adc24a 2# Copyright (C) 1993-2020 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
98d72909
L
32global STATIC_LDFLAGS
33
ed948520
NC
34# Determine if plugin support is present.
35remote_exec host "$nm --help" "" "/dev/null" "plugin-support"
36set tmp [file_contents "plugin-support"]
37regexp ".*\(--plugin\).*\n" $tmp foo plugins
38if [info exists plugins] then {
39 set plugins "yes"
40} else {
41 set plugins "no"
42}
43
5d3236ee
DK
44# LD can have plugin support even if BFD does not.
45if [check_plugin_api_available] {
46 set plugins "yes"
47}
48
252b5132
RH
49# Bootstrap ld. First link the object files together using -r, in
50# order to test -r. Then link the result into an executable, ld1, to
51# really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a
52# new ld, ld3. ld2 and ld3 should be identical.
d9816402
AM
53set test_flags {"" "strip" "--static" "-Wl,--traditional-format"
54 "-Wl,--no-keep-memory" "-Wl,--relax"}
a97726da 55if { [istarget "powerpc-*-*"] } {
d9816402
AM
56 lappend test_flags "-Wl,--ppc476-workaround"
57}
58
59set gcc_B_opt_save $gcc_B_opt
60
61foreach ldexe {ld1 ld2 ld3} {
62 if {![file isdirectory tmpdir/gcc$ldexe]} then {
63 catch "exec mkdir tmpdir/gcc$ldexe" status
64 catch "exec ln -s ../$ldexe tmpdir/gcc$ldexe/ld" status
65 catch "exec ln -s ld tmpdir/gcc$ldexe/collect-ld" status
66 catch "exec ln -s ../../../gas/as-new tmpdir/gcc$ldexe/as" status
67 }
a97726da 68}
252b5132 69
a97726da 70foreach flags $test_flags {
d9816402 71 set gcc_B_opt $gcc_B_opt_save
e1753d2c
L
72 set do_strip "no"
73 if {"$flags" == "strip"} {
74 set testname "bootstrap with $flags"
75 set flags ""
76 set do_strip "yes"
77 } else { if {"$flags" != ""} {
252b5132
RH
78 set testname "bootstrap with $flags"
79 } else {
80 set testname "bootstrap"
e1753d2c 81 }}
252b5132 82
0085b5a8 83 # --static is meaningless and --relax is incompatible with -r.
d9816402
AM
84 regsub -- "-Wl," $flags "" partial_flags
85 if { "$partial_flags" == "--static" || "$partial_flags" == "--relax" } {
0085b5a8
RH
86 set partial_flags ""
87 }
88
a97726da
AM
89 if { $partial_flags == "--ppc476-workaround" } {
90 append partial_flags " -T $srcdir/$subdir/ppc476.t"
91 }
92
252b5132
RH
93 # This test can only be run if we have the ld build directory,
94 # since we need the object files.
95 if {$ld != "$objdir/ld-new"} {
96 untested $testname
97 continue
98 }
99
98d72909
L
100 # If -static doesn't work, these tests will fail.
101 if { $flags == "--static" && [string match "" $STATIC_LDFLAGS] } then {
102 untested $testname
103 continue
104 }
105
ed948520 106 # Plugin support requires linking with a dynamic library which
66a3cb9c 107 # means that these tests will fail.
ed948520
NC
108 if { $flags == "--static" && $plugins == "yes" } then {
109 untested $testname
110 continue
111 }
112
252b5132 113 # If we only have a shared libbfd, we probably can't run the
66a3cb9c 114 # --static test.
252b5132
RH
115 if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then {
116 untested $testname
117 continue
118 }
119
0085b5a8 120 if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] {
252b5132
RH
121 fail $testname
122 continue
123 }
124
125 # On AIX, you need to specify an import list when using --static.
126 # You only want the import list when creating the final
127 # executable.
41c49998
TW
128 if { [istarget "*-*-aix*"]
129 && ![istarget "ia64-*-aix*"]} {
252b5132
RH
130 if {"$flags" == "--static"} {
131 set flags "--static -bI:/lib/syscalls.exp"
132 }
133 }
134
9b3ea03b
DK
135 # On Cygwin, -lintl may require -liconv when linking statically.
136 set extralibs ""
137 if { [istarget "*-*-cygwin*"]} {
138 if {"$flags" == "--static"} {
139 set extralibs "-liconv"
140 }
141 }
142
f24173eb
L
143 # Check if the system's zlib library is used.
144 if {[file exists ../zlib/Makefile ]} then {
145 set extralibs "$extralibs -L../zlib -lz"
146 } else {
147 set extralibs "$extralibs -lz"
148 }
149
ed948520
NC
150 # Plugin support requires linking with libdl.
151 if { $plugins == "yes" } {
fb2c6e43
AT
152 if { ![istarget "*-*-freebsd*"]} {
153 set extralibs "$extralibs -ldl"
154 }
ed948520
NC
155 }
156
252b5132
RH
157 # On Irix 5, linking with --static only works if all the files are
158 # compiled using -non_shared.
159 if {"$flags" == "--static"} {
160 setup_xfail "mips*-*-irix5*"
161 }
162
1ff6de03 163 if ![ld_link $CC tmpdir/ld1 "$flags tmpdir/ld-partial.o $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
164 fail $testname
165 continue
166 }
167
e1753d2c
L
168 if {"$do_strip" == "yes"} {
169 verbose -log "$strip tmpdir/ld1"
170 catch "exec $strip tmpdir/ld1" exec_output
7dd36a6f 171 set exec_output [prune_warnings $exec_output]
e1753d2c
L
172 if ![string match "" $exec_output] then {
173 verbose -log "$exec_output"
174 fail $testname
175 continue
176 }
177 }
178
d9816402 179 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld1/ gcc_B_opt
1ff6de03 180 if ![ld_link $CC tmpdir/ld2 "$flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
181 fail $testname
182 continue
183 }
184
d9816402 185 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld2/ gcc_B_opt
1ff6de03 186 if ![ld_link $CC tmpdir/ld3 "$flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
252b5132
RH
187 fail $testname
188 continue
189 }
190
2db70efa
AM
191 if { "$flags" == "--static"
192 && ([istarget ia64-*-elf*]
193 || [istarget ia64-*-linux*]
194 || [istarget mips*-*-linux*]) } {
d9816402
AM
195 # On ia64 and mips, tmpdir/ld2 != tmpdir/ld3 is normal since they are
196 # generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
197 # So we rebuild tmpdir/ld2 with tmpdir/ld3.
198 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld3/ gcc_B_opt
1ff6de03 199 if ![ld_link $CC tmpdir/ld2 "$flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
d9816402
AM
200 fail $testname
201 continue
66517a2f 202 }
ad995491
L
203 }
204
86017ce9 205 if {[istarget "*-*-pe"]
336d6a64
AM
206 || [istarget "*-*-wince"]
207 || [istarget "*-*-cygwin*"]
208 || [istarget "*-*-winnt*"]
99ad8390 209 || [istarget "*-*-mingw*"]
336d6a64
AM
210 || [istarget "*-*-interix*"]
211 || [istarget "*-*-beospe*"]
212 || [istarget "*-*-netbsdpe*"]} {
eccbf555
AM
213 # Trim off the date present in PE binaries by only looking
214 # at the ends of the files
215 # Although this works, a way to set the date would be better.
216 # Removing or zeroing the date stamp in the binary produced by
217 # the linker is not possible as it is required by the target OS.
218 set do_compare [string map {16 220 f1 tmpdir/ld2 f2 tmpdir/ld3 tmp-foo1 tmpdir/ld2tail tmp-foo2 tmpdir/ld3tail} $DO_COMPARE]
219 send_log "$do_compare\n"
220 verbose "$do_compare"
221 catch "exec sh -c [list $do_compare]" exec_output
86017ce9 222 } else {
eccbf555
AM
223 send_log "cmp tmpdir/ld2 tmpdir/ld3\n"
224 verbose "cmp tmpdir/ld2 tmpdir/ld3"
225 catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output
86017ce9 226 }
252b5132
RH
227 set exec_output [prune_warnings $exec_output]
228
229 if [string match "" $exec_output] then {
230 pass $testname
231 } else {
232 send_log "$exec_output\n"
233 verbose "$exec_output" 1
234
235 fail $testname
236 }
237}
9ab80182 238
d9816402 239set gcc_B_opt $gcc_B_opt_save
9ab80182 240catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status
eccbf555 241catch "exec rm -f tmpdir/ld2tail tmpdir/ld3tail" status