1 # Expect script for LD Bootstrap Tests
2 # Copyright 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001
3 # Free Software Foundation, Inc.
5 # This file is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # Written by Jeffrey Wheat (cassidy@cygnus.com)
20 # Rewritten by Ian Lance Taylor (ian@cygnus.com)
23 # Make sure that ld can bootstrap itself.
25 # This test can only be run if ld generates native executables.
30 # Bootstrap ld. First link the object files together using -r, in
31 # order to test -r. Then link the result into an executable, ld1, to
32 # really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a
33 # new ld, ld3. ld2 and ld3 should be identical.
35 foreach flags {"" "strip" "--static" "--traditional-format" "--no-keep-memory"} {
37 if {"$flags" == "strip"} {
38 set testname "bootstrap with $flags"
41 } else { if {"$flags" != ""} {
42 set testname "bootstrap with $flags"
44 set testname "bootstrap"
47 # This test can only be run if we have the ld build directory,
48 # since we need the object files.
49 if {$ld != "$objdir/ld-new"} {
54 # If we only have a shared libbfd, we probably can't run the
56 if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then {
61 if ![ld_relocate $ld tmpdir/ld-partial.o "$flags $OFILES"] {
66 # On AIX, you need to specify an import list when using --static.
67 # You only want the import list when creating the final
69 if { [istarget "*-*-aix*"]
70 && ![istarget "ia64-*-aix*"]} {
71 if {"$flags" == "--static"} {
72 set flags "--static -bI:/lib/syscalls.exp"
76 # On Irix 5, linking with --static only works if all the files are
77 # compiled using -non_shared.
78 if {"$flags" == "--static"} {
79 setup_xfail "mips*-*-irix5*"
82 if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY"] {
87 if {"$do_strip" == "yes"} {
88 verbose -log "$strip tmpdir/ld1"
89 catch "exec $strip tmpdir/ld1" exec_output
90 if ![string match "" $exec_output] then {
91 verbose -log "$exec_output"
97 if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
102 if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
107 if {"$flags" == "--static"} {
108 if { [istarget ia64-*-elf*]
109 || [istarget ia64-*-linux*] } {
110 # On ia64, tmpdir/ld2 != tmpdir/ld3 is normal since they are
111 # generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
112 # So we rebuild tmpdir/ld2 with tmpdir/ld3.
113 if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
119 if { [istarget mips*-*-linux*] } {
120 # On Linux/mips, tmpdir/ld2 != tmpdir/ld3 is normal since
121 # they are generated by different linkers, tmpdir/ld1 and
122 # tmpdir/ld2. So we rebuild tmpdir/ld2 with tmpdir/ld3.
123 if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
130 send_log "compare (tail of) tmpdir/ld2 tmpdir/ld3\n"
131 verbose "compare (tail of) tmpdir/ld2 tmpdir/ld3"
132 # Trim off the date present in PE binaries by only looking
133 # at the ends of the files
134 # Although this works, a way to set the date would be better.
135 # Removing or zeroing the date stamp in the binary produced by
136 # the linker is not possible as it is required by the target OS.
137 exec tail +140 tmpdir/ld2 >tmpdir/ld2tail
138 exec tail +140 tmpdir/ld3 >tmpdir/ld3tail
139 catch "exec cmp tmpdir/ld2tail tmpdir/ld3tail" exec_output
140 exec rm tmpdir/ld2tail tmpdir/ld3tail
141 set exec_output [prune_warnings $exec_output]
143 if [string match "" $exec_output] then {
146 send_log "$exec_output\n"
147 verbose "$exec_output" 1