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