1 # Expect script for LD Bootstrap Tests
2 # Copyright 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2004,
3 # 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
5 # This file is part of the GNU Binutils.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 # Written by Jeffrey Wheat (cassidy@cygnus.com)
23 # Rewritten by Ian Lance Taylor (ian@cygnus.com)
26 # Make sure that ld can bootstrap itself.
28 # This test can only be run if ld generates native executables.
33 # Determine if plugin support is present.
34 remote_exec host "$nm --help" "" "/dev/null" "plugin-support"
35 set tmp [file_contents "plugin-support"]
36 regexp ".*\(--plugin\).*\n" $tmp foo plugins
37 if [info exists plugins] then {
43 # LD can have plugin support even if BFD does not.
44 if [check_plugin_api_available] {
48 # Bootstrap ld. First link the object files together using -r, in
49 # order to test -r. Then link the result into an executable, ld1, to
50 # really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a
51 # new ld, ld3. ld2 and ld3 should be identical.
52 set test_flags {"" "strip" "--static" "--traditional-format"
53 "--no-keep-memory" "--relax"}
54 if { [istarget "powerpc-*-*"] } {
55 lappend test_flags "--ppc476-workaround"
58 foreach flags $test_flags {
60 if {"$flags" == "strip"} {
61 set testname "bootstrap with $flags"
64 } else { if {"$flags" != ""} {
65 set testname "bootstrap with $flags"
67 set testname "bootstrap"
70 # --static is meaningless and --relax is incompatible with -r.
71 set partial_flags "$flags"
72 if { "$flags" == "--static" || "$flags" == "--relax" } {
76 if { $partial_flags == "--ppc476-workaround" } {
77 append partial_flags " -T $srcdir/$subdir/ppc476.t"
80 # This test can only be run if we have the ld build directory,
81 # since we need the object files.
82 if {$ld != "$objdir/ld-new"} {
87 # Plugin support requires linking with a dynamic library which
88 # means that these tests will fail.
89 if { $flags == "--static" && $plugins == "yes" } then {
94 # If we only have a shared libbfd, we probably can't run the
96 if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then {
101 if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] {
106 # On AIX, you need to specify an import list when using --static.
107 # You only want the import list when creating the final
109 if { [istarget "*-*-aix*"]
110 && ![istarget "ia64-*-aix*"]} {
111 if {"$flags" == "--static"} {
112 set flags "--static -bI:/lib/syscalls.exp"
116 # On Cygwin, -lintl may require -liconv when linking statically.
118 if { [istarget "*-*-cygwin*"]} {
119 if {"$flags" == "--static"} {
120 set extralibs "-liconv"
124 # Plugin support requires linking with libdl.
125 if { $plugins == "yes" } {
126 set extralibs "$extralibs -ldl"
129 # On Irix 5, linking with --static only works if all the files are
130 # compiled using -non_shared.
131 if {"$flags" == "--static"} {
132 setup_xfail "mips*-*-irix5*"
135 if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY $extralibs"] {
140 if {"$do_strip" == "yes"} {
141 verbose -log "$strip tmpdir/ld1"
142 catch "exec $strip tmpdir/ld1" exec_output
143 if ![string match "" $exec_output] then {
144 verbose -log "$exec_output"
150 if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
155 if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
160 if {"$flags" == "--static"} {
161 if { [istarget ia64-*-elf*]
162 || [istarget ia64-*-linux*] } {
163 # On ia64, tmpdir/ld2 != tmpdir/ld3 is normal since they are
164 # generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
165 # So we rebuild tmpdir/ld2 with tmpdir/ld3.
166 if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
172 if { [istarget mips*-*-linux*] } {
173 # On Linux/mips, tmpdir/ld2 != tmpdir/ld3 is normal since
174 # they are generated by different linkers, tmpdir/ld1 and
175 # tmpdir/ld2. So we rebuild tmpdir/ld2 with tmpdir/ld3.
176 if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
183 if {[istarget "*-*-pe"]
184 || [istarget "*-*-wince"]
185 || [istarget "*-*-cygwin*"]
186 || [istarget "*-*-winnt*"]
187 || [istarget "*-*-mingw*"]
188 || [istarget "*-*-interix*"]
189 || [istarget "*-*-beospe*"]
190 || [istarget "*-*-netbsdpe*"]} {
191 # Trim off the date present in PE binaries by only looking
192 # at the ends of the files
193 # Although this works, a way to set the date would be better.
194 # Removing or zeroing the date stamp in the binary produced by
195 # the linker is not possible as it is required by the target OS.
196 set do_compare [string map {16 220 f1 tmpdir/ld2 f2 tmpdir/ld3 tmp-foo1 tmpdir/ld2tail tmp-foo2 tmpdir/ld3tail} $DO_COMPARE]
197 send_log "$do_compare\n"
198 verbose "$do_compare"
199 catch "exec sh -c [list $do_compare]" exec_output
201 send_log "cmp tmpdir/ld2 tmpdir/ld3\n"
202 verbose "cmp tmpdir/ld2 tmpdir/ld3"
203 catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output
205 set exec_output [prune_warnings $exec_output]
207 if [string match "" $exec_output] then {
210 send_log "$exec_output\n"
211 verbose "$exec_output" 1
217 catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status
218 catch "exec rm -f tmpdir/ld2tail tmpdir/ld3tail" status