ld: Skip unsupported static executable tests
[deliverable/binutils-gdb.git] / ld / testsuite / ld-bootstrap / bootstrap.exp
1 # Expect script for LD Bootstrap Tests
2 # Copyright (C) 1993-2018 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 global STATIC_LDFLAGS
33
34 # Determine if plugin support is present.
35 remote_exec host "$nm --help" "" "/dev/null" "plugin-support"
36 set tmp [file_contents "plugin-support"]
37 regexp ".*\(--plugin\).*\n" $tmp foo plugins
38 if [info exists plugins] then {
39 set plugins "yes"
40 } else {
41 set plugins "no"
42 }
43
44 # LD can have plugin support even if BFD does not.
45 if [check_plugin_api_available] {
46 set plugins "yes"
47 }
48
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.
53 set test_flags {"" "strip" "--static" "-Wl,--traditional-format"
54 "-Wl,--no-keep-memory" "-Wl,--relax"}
55 if { [istarget "powerpc-*-*"] } {
56 lappend test_flags "-Wl,--ppc476-workaround"
57 }
58
59 set gcc_B_opt_save $gcc_B_opt
60
61 foreach 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 }
68 }
69
70 foreach flags $test_flags {
71 set gcc_B_opt $gcc_B_opt_save
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" != ""} {
78 set testname "bootstrap with $flags"
79 } else {
80 set testname "bootstrap"
81 }}
82
83 # --static is meaningless and --relax is incompatible with -r.
84 regsub -- "-Wl," $flags "" partial_flags
85 if { "$partial_flags" == "--static" || "$partial_flags" == "--relax" } {
86 set partial_flags ""
87 }
88
89 if { $partial_flags == "--ppc476-workaround" } {
90 append partial_flags " -T $srcdir/$subdir/ppc476.t"
91 }
92
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
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
106 # Plugin support requires linking with a dynamic library which
107 # means that these tests will fail.
108 if { $flags == "--static" && $plugins == "yes" } then {
109 untested $testname
110 continue
111 }
112
113 # If we only have a shared libbfd, we probably can't run the
114 # --static test.
115 if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then {
116 untested $testname
117 continue
118 }
119
120 if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] {
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.
128 if { [istarget "*-*-aix*"]
129 && ![istarget "ia64-*-aix*"]} {
130 if {"$flags" == "--static"} {
131 set flags "--static -bI:/lib/syscalls.exp"
132 }
133 }
134
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
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
150 # Plugin support requires linking with libdl.
151 if { $plugins == "yes" } {
152 if { ![istarget "*-*-freebsd*"]} {
153 set extralibs "$extralibs -ldl"
154 }
155 }
156
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
163 if ![ld_link $CC tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY $extralibs"] {
164 fail $testname
165 continue
166 }
167
168 if {"$do_strip" == "yes"} {
169 verbose -log "$strip tmpdir/ld1"
170 catch "exec $strip tmpdir/ld1" exec_output
171 if ![string match "" $exec_output] then {
172 verbose -log "$exec_output"
173 fail $testname
174 continue
175 }
176 }
177
178 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld1/ gcc_B_opt
179 if ![ld_link $CC tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
180 fail $testname
181 continue
182 }
183
184 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld2/ gcc_B_opt
185 if ![ld_link $CC tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
186 fail $testname
187 continue
188 }
189
190 if { "$flags" == "--static" && { [istarget ia64-*-elf*] || [istarget ia64-*-linux*] }
191 || [istarget mips*-*-linux*] } {
192 # On ia64 and mips, tmpdir/ld2 != tmpdir/ld3 is normal since they are
193 # generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
194 # So we rebuild tmpdir/ld2 with tmpdir/ld3.
195 regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld3/ gcc_B_opt
196 if ![ld_link $CC tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
197 fail $testname
198 continue
199 }
200 }
201
202 if {[istarget "*-*-pe"]
203 || [istarget "*-*-wince"]
204 || [istarget "*-*-cygwin*"]
205 || [istarget "*-*-winnt*"]
206 || [istarget "*-*-mingw*"]
207 || [istarget "*-*-interix*"]
208 || [istarget "*-*-beospe*"]
209 || [istarget "*-*-netbsdpe*"]} {
210 # Trim off the date present in PE binaries by only looking
211 # at the ends of the files
212 # Although this works, a way to set the date would be better.
213 # Removing or zeroing the date stamp in the binary produced by
214 # the linker is not possible as it is required by the target OS.
215 set do_compare [string map {16 220 f1 tmpdir/ld2 f2 tmpdir/ld3 tmp-foo1 tmpdir/ld2tail tmp-foo2 tmpdir/ld3tail} $DO_COMPARE]
216 send_log "$do_compare\n"
217 verbose "$do_compare"
218 catch "exec sh -c [list $do_compare]" exec_output
219 } else {
220 send_log "cmp tmpdir/ld2 tmpdir/ld3\n"
221 verbose "cmp tmpdir/ld2 tmpdir/ld3"
222 catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output
223 }
224 set exec_output [prune_warnings $exec_output]
225
226 if [string match "" $exec_output] then {
227 pass $testname
228 } else {
229 send_log "$exec_output\n"
230 verbose "$exec_output" 1
231
232 fail $testname
233 }
234 }
235
236 set gcc_B_opt $gcc_B_opt_save
237 catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status
238 catch "exec rm -f tmpdir/ld2tail tmpdir/ld3tail" status
This page took 0.042872 seconds and 5 git commands to generate.