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