1 # Expect script for LD Bootstrap Tests
2 # Copyright (C) 1993-2014 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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,
21 # Written by Jeffrey Wheat (cassidy@cygnus.com)
22 # Rewritten by Ian Lance Taylor (ian@cygnus.com)
25 # Make sure that ld can bootstrap itself.
27 # This test can only be run if ld generates native executables.
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 {
42 # LD can have plugin support even if BFD does not.
43 if [check_plugin_api_available] {
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" "--traditional-format"
52 "--no-keep-memory" "--relax"}
53 if { [istarget "powerpc-*-*"] } {
54 lappend test_flags "--ppc476-workaround"
57 foreach flags $test_flags {
59 if {"$flags" == "strip"} {
60 set testname "bootstrap with $flags"
63 } else { if {"$flags" != ""} {
64 set testname "bootstrap with $flags"
66 set testname "bootstrap"
69 # --static is meaningless and --relax is incompatible with -r.
70 set partial_flags "$flags"
71 if { "$flags" == "--static" || "$flags" == "--relax" } {
75 if { $partial_flags == "--ppc476-workaround" } {
76 append partial_flags " -T $srcdir/$subdir/ppc476.t"
79 # This test can only be run if we have the ld build directory,
80 # since we need the object files.
82 set ldparm [string first " " $ld]
83 if { $ldparm > 0 } then {
84 set ldexe [string range $ld 0 $ldparm]
86 if {$ldexe != "$objdir/ld-new"} {
91 # Plugin support requires linking with a dynamic library which
92 # means that these tests will fail.
93 if { $flags == "--static" && $plugins == "yes" } then {
98 # If we only have a shared libbfd, we probably can't run the
100 if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then {
105 if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] {
110 # On AIX, you need to specify an import list when using --static.
111 # You only want the import list when creating the final
113 if { [istarget "*-*-aix*"]
114 && ![istarget "ia64-*-aix*"]} {
115 if {"$flags" == "--static"} {
116 set flags "--static -bI:/lib/syscalls.exp"
120 # On Cygwin, -lintl may require -liconv when linking statically.
122 if { [istarget "*-*-cygwin*"]} {
123 if {"$flags" == "--static"} {
124 set extralibs "-liconv"
128 # Plugin support requires linking with libdl.
129 if { $plugins == "yes" } {
130 if { ![istarget "*-*-freebsd*"]} {
131 set extralibs "$extralibs -ldl"
135 # On Irix 5, linking with --static only works if all the files are
136 # compiled using -non_shared.
137 if {"$flags" == "--static"} {
138 setup_xfail "mips*-*-irix5*"
141 if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY $extralibs"] {
146 if {"$do_strip" == "yes"} {
147 verbose -log "$strip tmpdir/ld1"
148 catch "exec $strip tmpdir/ld1" exec_output
149 if ![string match "" $exec_output] then {
150 verbose -log "$exec_output"
156 if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
161 if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
166 if {"$flags" == "--static"} {
167 if { [istarget ia64-*-elf*]
168 || [istarget ia64-*-linux*] } {
169 # On ia64, tmpdir/ld2 != tmpdir/ld3 is normal since they are
170 # generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
171 # So we rebuild tmpdir/ld2 with tmpdir/ld3.
172 if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
178 if { [istarget mips*-*-linux*] } {
179 # On Linux/mips, tmpdir/ld2 != tmpdir/ld3 is normal since
180 # they are generated by different linkers, tmpdir/ld1 and
181 # tmpdir/ld2. So we rebuild tmpdir/ld2 with tmpdir/ld3.
182 if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
189 if {[istarget "*-*-pe"]
190 || [istarget "*-*-wince"]
191 || [istarget "*-*-cygwin*"]
192 || [istarget "*-*-winnt*"]
193 || [istarget "*-*-mingw*"]
194 || [istarget "*-*-interix*"]
195 || [istarget "*-*-beospe*"]
196 || [istarget "*-*-netbsdpe*"]} {
197 # Trim off the date present in PE binaries by only looking
198 # at the ends of the files
199 # Although this works, a way to set the date would be better.
200 # Removing or zeroing the date stamp in the binary produced by
201 # the linker is not possible as it is required by the target OS.
202 set do_compare [string map {16 220 f1 tmpdir/ld2 f2 tmpdir/ld3 tmp-foo1 tmpdir/ld2tail tmp-foo2 tmpdir/ld3tail} $DO_COMPARE]
203 send_log "$do_compare\n"
204 verbose "$do_compare"
205 catch "exec sh -c [list $do_compare]" exec_output
207 send_log "cmp tmpdir/ld2 tmpdir/ld3\n"
208 verbose "cmp tmpdir/ld2 tmpdir/ld3"
209 catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output
211 set exec_output [prune_warnings $exec_output]
213 if [string match "" $exec_output] then {
216 send_log "$exec_output\n"
217 verbose "$exec_output" 1
223 catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status
224 catch "exec rm -f tmpdir/ld2tail tmpdir/ld3tail" status