Commit | Line | Data |
---|---|---|
252b5132 | 1 | # Expect script for LD Bootstrap Tests |
f96b4a7b NC |
2 | # Copyright 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2004, |
3 | # 2006, 2007 Free Software Foundation, Inc. | |
252b5132 | 4 | # |
f96b4a7b NC |
5 | # This file is part of the GNU Binutils. |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
252b5132 | 8 | # it under the terms of the GNU General Public License as published by |
f96b4a7b | 9 | # the Free Software Foundation; either version 3 of the License, or |
252b5132 | 10 | # (at your option) any later version. |
f96b4a7b | 11 | # |
252b5132 RH |
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. | |
f96b4a7b | 16 | # |
252b5132 RH |
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 | |
f96b4a7b NC |
19 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | # MA 02110-1301, USA. | |
252b5132 RH |
21 | # |
22 | # Written by Jeffrey Wheat (cassidy@cygnus.com) | |
23 | # Rewritten by Ian Lance Taylor (ian@cygnus.com) | |
24 | # | |
25 | ||
26 | # Make sure that ld can bootstrap itself. | |
27 | ||
28 | # This test can only be run if ld generates native executables. | |
29 | if ![isnative] { | |
30 | return | |
31 | } | |
32 | ||
33 | # Bootstrap ld. First link the object files together using -r, in | |
34 | # order to test -r. Then link the result into an executable, ld1, to | |
35 | # really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a | |
36 | # new ld, ld3. ld2 and ld3 should be identical. | |
37 | ||
0085b5a8 RH |
38 | foreach flags {"" "strip" "--static" "--traditional-format" |
39 | "--no-keep-memory" "--relax"} { | |
e1753d2c L |
40 | set do_strip "no" |
41 | if {"$flags" == "strip"} { | |
42 | set testname "bootstrap with $flags" | |
43 | set flags "" | |
44 | set do_strip "yes" | |
45 | } else { if {"$flags" != ""} { | |
252b5132 RH |
46 | set testname "bootstrap with $flags" |
47 | } else { | |
48 | set testname "bootstrap" | |
e1753d2c | 49 | }} |
252b5132 | 50 | |
0085b5a8 RH |
51 | # --static is meaningless and --relax is incompatible with -r. |
52 | set partial_flags "$flags" | |
53 | if { "$flags" == "--static" || "$flags" == "--relax" } { | |
54 | set partial_flags "" | |
55 | } | |
56 | ||
252b5132 RH |
57 | # This test can only be run if we have the ld build directory, |
58 | # since we need the object files. | |
59 | if {$ld != "$objdir/ld-new"} { | |
60 | untested $testname | |
61 | continue | |
62 | } | |
63 | ||
64 | # If we only have a shared libbfd, we probably can't run the | |
65 | # --static test. | |
66 | if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then { | |
67 | untested $testname | |
68 | continue | |
69 | } | |
70 | ||
0085b5a8 | 71 | if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] { |
252b5132 RH |
72 | fail $testname |
73 | continue | |
74 | } | |
75 | ||
76 | # On AIX, you need to specify an import list when using --static. | |
77 | # You only want the import list when creating the final | |
78 | # executable. | |
41c49998 TW |
79 | if { [istarget "*-*-aix*"] |
80 | && ![istarget "ia64-*-aix*"]} { | |
252b5132 RH |
81 | if {"$flags" == "--static"} { |
82 | set flags "--static -bI:/lib/syscalls.exp" | |
83 | } | |
84 | } | |
85 | ||
86 | # On Irix 5, linking with --static only works if all the files are | |
87 | # compiled using -non_shared. | |
88 | if {"$flags" == "--static"} { | |
89 | setup_xfail "mips*-*-irix5*" | |
90 | } | |
91 | ||
92 | if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY"] { | |
93 | fail $testname | |
94 | continue | |
95 | } | |
96 | ||
e1753d2c L |
97 | if {"$do_strip" == "yes"} { |
98 | verbose -log "$strip tmpdir/ld1" | |
99 | catch "exec $strip tmpdir/ld1" exec_output | |
100 | if ![string match "" $exec_output] then { | |
101 | verbose -log "$exec_output" | |
102 | fail $testname | |
103 | continue | |
104 | } | |
105 | } | |
106 | ||
252b5132 RH |
107 | if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] { |
108 | fail $testname | |
109 | continue | |
110 | } | |
111 | ||
112 | if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY"] { | |
113 | fail $testname | |
114 | continue | |
115 | } | |
116 | ||
ad995491 L |
117 | if {"$flags" == "--static"} { |
118 | if { [istarget ia64-*-elf*] | |
119 | || [istarget ia64-*-linux*] } { | |
120 | # On ia64, tmpdir/ld2 != tmpdir/ld3 is normal since they are | |
121 | # generated by different linkers, tmpdir/ld1 and tmpdir/ld2. | |
122 | # 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 | |
126 | } | |
127 | } | |
66517a2f L |
128 | } else { |
129 | if { [istarget mips*-*-linux*] } { | |
130 | # On Linux/mips, tmpdir/ld2 != tmpdir/ld3 is normal since | |
131 | # they are generated by different linkers, tmpdir/ld1 and | |
132 | # tmpdir/ld2. So we rebuild tmpdir/ld2 with tmpdir/ld3. | |
133 | if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] { | |
134 | fail $testname | |
135 | continue | |
136 | } | |
137 | } | |
ad995491 L |
138 | } |
139 | ||
d7b78487 NC |
140 | send_log "compare (tail of) tmpdir/ld2 tmpdir/ld3\n" |
141 | verbose "compare (tail of) tmpdir/ld2 tmpdir/ld3" | |
86017ce9 | 142 | if {[istarget "*-*-pe"] |
336d6a64 AM |
143 | || [istarget "*-*-wince"] |
144 | || [istarget "*-*-cygwin*"] | |
145 | || [istarget "*-*-winnt*"] | |
99ad8390 | 146 | || [istarget "*-*-mingw*"] |
336d6a64 AM |
147 | || [istarget "*-*-interix*"] |
148 | || [istarget "*-*-beospe*"] | |
149 | || [istarget "*-*-netbsdpe*"]} { | |
86017ce9 NC |
150 | # Trim off the date present in PE binaries by only looking |
151 | # at the ends of the files | |
152 | # Although this works, a way to set the date would be better. | |
153 | # Removing or zeroing the date stamp in the binary produced by | |
154 | # the linker is not possible as it is required by the target OS. | |
155 | exec tail +140 tmpdir/ld2 >tmpdir/ld2tail | |
156 | exec tail +140 tmpdir/ld3 >tmpdir/ld3tail | |
157 | catch "exec cmp tmpdir/ld2tail tmpdir/ld3tail" exec_output | |
158 | exec rm tmpdir/ld2tail tmpdir/ld3tail | |
159 | } else { | |
160 | send_log "cmp tmpdir/ld2 tmpdir/ld3\n" | |
161 | verbose "cmp tmpdir/ld2 tmpdir/ld3" | |
162 | catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output | |
163 | } | |
252b5132 RH |
164 | set exec_output [prune_warnings $exec_output] |
165 | ||
166 | if [string match "" $exec_output] then { | |
167 | pass $testname | |
168 | } else { | |
169 | send_log "$exec_output\n" | |
170 | verbose "$exec_output" 1 | |
171 | ||
172 | fail $testname | |
173 | } | |
174 | } | |
9ab80182 JB |
175 | |
176 | catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status | |
177 | catch "exec rm -f tmpdir/ld1tail tmpdir/ld2tail tmpdir/ld3tail" status |