Only scan tail of executable for PE targets.
[binutils.git] / ld / testsuite / ld-bootstrap / bootstrap.exp
blob69d30883e1d6c5f7ca135ba1130ee00a59b23760
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.
9 #
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.
26 if ![isnative] {
27 return
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"} {
36 set do_strip "no"
37 if {"$flags" == "strip"} {
38 set testname "bootstrap with $flags"
39 set flags ""
40 set do_strip "yes"
41 } else { if {"$flags" != ""} {
42 set testname "bootstrap with $flags"
43 } else {
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"} {
50 untested $testname
51 continue
54 # If we only have a shared libbfd, we probably can't run the
55 # --static test.
56 if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then {
57 untested $testname
58 continue
61 if ![ld_relocate $ld tmpdir/ld-partial.o "$flags $OFILES"] {
62 fail $testname
63 continue
66 # On AIX, you need to specify an import list when using --static.
67 # You only want the import list when creating the final
68 # executable.
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"] {
83 fail $testname
84 continue
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"
92 fail $testname
93 continue
97 if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
98 fail $testname
99 continue
102 if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY"] {
103 fail $testname
104 continue
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"] {
114 fail $testname
115 continue
118 } else {
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"] {
124 fail $testname
125 continue
130 send_log "compare (tail of) tmpdir/ld2 tmpdir/ld3\n"
131 verbose "compare (tail of) tmpdir/ld2 tmpdir/ld3"
132 if {[istarget "*-*-pe"]
133 || [istarget "*-*-wince"]} {
134 # Trim off the date present in PE binaries by only looking
135 # at the ends of the files
136 # Although this works, a way to set the date would be better.
137 # Removing or zeroing the date stamp in the binary produced by
138 # the linker is not possible as it is required by the target OS.
139 exec tail +140 tmpdir/ld2 >tmpdir/ld2tail
140 exec tail +140 tmpdir/ld3 >tmpdir/ld3tail
141 catch "exec cmp tmpdir/ld2tail tmpdir/ld3tail" exec_output
142 exec rm tmpdir/ld2tail tmpdir/ld3tail
143 } else {
144 send_log "cmp tmpdir/ld2 tmpdir/ld3\n"
145 verbose "cmp tmpdir/ld2 tmpdir/ld3"
146 catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output
148 set exec_output [prune_warnings $exec_output]
150 if [string match "" $exec_output] then {
151 pass $testname
152 } else {
153 send_log "$exec_output\n"
154 verbose "$exec_output" 1
156 fail $testname