1 # Expect script for LD Bootstrap Tests
2 # Copyright 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2004,
3 # 2005, 2006, 2007, 2009 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 # Bootstrap ld. First link the object files together using -r, in
44 # order to test -r. Then link the result into an executable, ld1, to
45 # really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a
46 # new ld, ld3. ld2 and ld3 should be identical.
48 foreach flags {"" "strip" "--static" "--traditional-format"
49 "--no-keep-memory" "--relax"} {
51 if {"$flags" == "strip"} {
52 set testname "bootstrap with $flags"
55 } else { if {"$flags" != ""} {
56 set testname "bootstrap with $flags"
58 set testname "bootstrap"
61 # --static is meaningless and --relax is incompatible with -r.
62 set partial_flags "$flags"
63 if { "$flags" == "--static" || "$flags" == "--relax" } {
67 # This test can only be run if we have the ld build directory,
68 # since we need the object files.
69 if {$ld != "$objdir/ld-new"} {
74 # Plugin support requires linking with a dynamic library which
76 if { $flags == "--static" && $plugins == "yes" } then {
81 # If we only have a shared libbfd, we probably can't run the
82 # --static test.will fail.
83 if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then {
88 if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] {
93 # On AIX, you need to specify an import list when using --static.
94 # You only want the import list when creating the final
96 if { [istarget "*-*-aix*"]
97 && ![istarget "ia64-*-aix*"]} {
98 if {"$flags" == "--static"} {
99 set flags "--static -bI:/lib/syscalls.exp"
103 # On Cygwin, -lintl may require -liconv when linking statically.
105 if { [istarget "*-*-cygwin*"]} {
106 if {"$flags" == "--static"} {
107 set extralibs "-liconv"
111 # Plugin support requires linking with libdl.
112 if { $plugins == "yes" } {
113 set extralibs "$extralibs -ldl"
116 # On Irix 5, linking with --static only works if all the files are
117 # compiled using -non_shared.
118 if {"$flags" == "--static"} {
119 setup_xfail "mips*-*-irix5*"
122 if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY $extralibs"] {
127 if {"$do_strip" == "yes"} {
128 verbose -log "$strip tmpdir/ld1"
129 catch "exec $strip tmpdir/ld1" exec_output
130 if ![string match "" $exec_output] then {
131 verbose -log "$exec_output"
137 if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
142 if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
147 if {"$flags" == "--static"} {
148 if { [istarget ia64-*-elf*]
149 || [istarget ia64-*-linux*] } {
150 # On ia64, tmpdir/ld2 != tmpdir/ld3 is normal since they are
151 # generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
152 # So we rebuild tmpdir/ld2 with tmpdir/ld3.
153 if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
159 if { [istarget mips*-*-linux*] } {
160 # On Linux/mips, tmpdir/ld2 != tmpdir/ld3 is normal since
161 # they are generated by different linkers, tmpdir/ld1 and
162 # tmpdir/ld2. So we rebuild tmpdir/ld2 with tmpdir/ld3.
163 if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
170 if {[istarget "*-*-pe"]
171 || [istarget "*-*-wince"]
172 || [istarget "*-*-cygwin*"]
173 || [istarget "*-*-winnt*"]
174 || [istarget "*-*-mingw*"]
175 || [istarget "*-*-interix*"]
176 || [istarget "*-*-beospe*"]
177 || [istarget "*-*-netbsdpe*"]} {
178 # Trim off the date present in PE binaries by only looking
179 # at the ends of the files
180 # Although this works, a way to set the date would be better.
181 # Removing or zeroing the date stamp in the binary produced by
182 # the linker is not possible as it is required by the target OS.
183 set do_compare [string map {16 220 f1 tmpdir/ld2 f2 tmpdir/ld3 tmp-foo1 tmpdir/ld2tail tmp-foo2 tmpdir/ld3tail} $DO_COMPARE]
184 send_log "$do_compare\n"
185 verbose "$do_compare"
186 catch "exec sh -c [list $do_compare]" exec_output
188 send_log "cmp tmpdir/ld2 tmpdir/ld3\n"
189 verbose "cmp tmpdir/ld2 tmpdir/ld3"
190 catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output
192 set exec_output [prune_warnings $exec_output]
194 if [string match "" $exec_output] then {
197 send_log "$exec_output\n"
198 verbose "$exec_output" 1
204 catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status
205 catch "exec rm -f tmpdir/ld2tail tmpdir/ld3tail" status