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