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