Commit | Line | Data |
---|---|---|
252b5132 | 1 | # Expect script for LD Bootstrap Tests |
f96b4a7b | 2 | # Copyright 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2004, |
aa820537 | 3 | # 2005, 2006, 2007, 2009 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 | ||
ed948520 NC |
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 { | |
38 | set plugins "yes" | |
39 | } else { | |
40 | set plugins "no" | |
41 | } | |
42 | ||
5d3236ee DK |
43 | # LD can have plugin support even if BFD does not. |
44 | if [check_plugin_api_available] { | |
45 | set plugins "yes" | |
46 | } | |
47 | ||
252b5132 RH |
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 | ||
0085b5a8 RH |
53 | foreach flags {"" "strip" "--static" "--traditional-format" |
54 | "--no-keep-memory" "--relax"} { | |
e1753d2c L |
55 | set do_strip "no" |
56 | if {"$flags" == "strip"} { | |
57 | set testname "bootstrap with $flags" | |
58 | set flags "" | |
59 | set do_strip "yes" | |
60 | } else { if {"$flags" != ""} { | |
252b5132 RH |
61 | set testname "bootstrap with $flags" |
62 | } else { | |
63 | set testname "bootstrap" | |
e1753d2c | 64 | }} |
252b5132 | 65 | |
0085b5a8 RH |
66 | # --static is meaningless and --relax is incompatible with -r. |
67 | set partial_flags "$flags" | |
68 | if { "$flags" == "--static" || "$flags" == "--relax" } { | |
69 | set partial_flags "" | |
70 | } | |
71 | ||
252b5132 RH |
72 | # This test can only be run if we have the ld build directory, |
73 | # since we need the object files. | |
74 | if {$ld != "$objdir/ld-new"} { | |
75 | untested $testname | |
76 | continue | |
77 | } | |
78 | ||
ed948520 NC |
79 | # Plugin support requires linking with a dynamic library which |
80 | # means that these | |
81 | if { $flags == "--static" && $plugins == "yes" } then { | |
82 | untested $testname | |
83 | continue | |
84 | } | |
85 | ||
252b5132 | 86 | # If we only have a shared libbfd, we probably can't run the |
ed948520 | 87 | # --static test.will fail. |
252b5132 RH |
88 | if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then { |
89 | untested $testname | |
90 | continue | |
91 | } | |
92 | ||
0085b5a8 | 93 | if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] { |
252b5132 RH |
94 | fail $testname |
95 | continue | |
96 | } | |
97 | ||
98 | # On AIX, you need to specify an import list when using --static. | |
99 | # You only want the import list when creating the final | |
100 | # executable. | |
41c49998 TW |
101 | if { [istarget "*-*-aix*"] |
102 | && ![istarget "ia64-*-aix*"]} { | |
252b5132 RH |
103 | if {"$flags" == "--static"} { |
104 | set flags "--static -bI:/lib/syscalls.exp" | |
105 | } | |
106 | } | |
107 | ||
9b3ea03b DK |
108 | # On Cygwin, -lintl may require -liconv when linking statically. |
109 | set extralibs "" | |
110 | if { [istarget "*-*-cygwin*"]} { | |
111 | if {"$flags" == "--static"} { | |
112 | set extralibs "-liconv" | |
113 | } | |
114 | } | |
115 | ||
ed948520 NC |
116 | # Plugin support requires linking with libdl. |
117 | if { $plugins == "yes" } { | |
118 | set extralibs "$extralibs -ldl" | |
119 | } | |
120 | ||
252b5132 RH |
121 | # On Irix 5, linking with --static only works if all the files are |
122 | # compiled using -non_shared. | |
123 | if {"$flags" == "--static"} { | |
124 | setup_xfail "mips*-*-irix5*" | |
125 | } | |
126 | ||
9b3ea03b | 127 | if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY $extralibs"] { |
252b5132 RH |
128 | fail $testname |
129 | continue | |
130 | } | |
131 | ||
e1753d2c L |
132 | if {"$do_strip" == "yes"} { |
133 | verbose -log "$strip tmpdir/ld1" | |
134 | catch "exec $strip tmpdir/ld1" exec_output | |
135 | if ![string match "" $exec_output] then { | |
136 | verbose -log "$exec_output" | |
137 | fail $testname | |
138 | continue | |
139 | } | |
140 | } | |
141 | ||
9b3ea03b | 142 | if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] { |
252b5132 RH |
143 | fail $testname |
144 | continue | |
145 | } | |
146 | ||
9b3ea03b | 147 | if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] { |
252b5132 RH |
148 | fail $testname |
149 | continue | |
150 | } | |
151 | ||
ad995491 L |
152 | if {"$flags" == "--static"} { |
153 | if { [istarget ia64-*-elf*] | |
154 | || [istarget ia64-*-linux*] } { | |
155 | # On ia64, tmpdir/ld2 != tmpdir/ld3 is normal since they are | |
156 | # generated by different linkers, tmpdir/ld1 and tmpdir/ld2. | |
157 | # So we rebuild tmpdir/ld2 with tmpdir/ld3. | |
158 | if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] { | |
159 | fail $testname | |
160 | continue | |
161 | } | |
162 | } | |
66517a2f L |
163 | } else { |
164 | if { [istarget mips*-*-linux*] } { | |
165 | # On Linux/mips, tmpdir/ld2 != tmpdir/ld3 is normal since | |
166 | # they are generated by different linkers, tmpdir/ld1 and | |
167 | # tmpdir/ld2. So we rebuild tmpdir/ld2 with tmpdir/ld3. | |
168 | if ![ld_link tmpdir/ld3 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY"] { | |
169 | fail $testname | |
170 | continue | |
171 | } | |
172 | } | |
ad995491 L |
173 | } |
174 | ||
86017ce9 | 175 | if {[istarget "*-*-pe"] |
336d6a64 AM |
176 | || [istarget "*-*-wince"] |
177 | || [istarget "*-*-cygwin*"] | |
178 | || [istarget "*-*-winnt*"] | |
99ad8390 | 179 | || [istarget "*-*-mingw*"] |
336d6a64 AM |
180 | || [istarget "*-*-interix*"] |
181 | || [istarget "*-*-beospe*"] | |
182 | || [istarget "*-*-netbsdpe*"]} { | |
eccbf555 AM |
183 | # Trim off the date present in PE binaries by only looking |
184 | # at the ends of the files | |
185 | # Although this works, a way to set the date would be better. | |
186 | # Removing or zeroing the date stamp in the binary produced by | |
187 | # the linker is not possible as it is required by the target OS. | |
188 | set do_compare [string map {16 220 f1 tmpdir/ld2 f2 tmpdir/ld3 tmp-foo1 tmpdir/ld2tail tmp-foo2 tmpdir/ld3tail} $DO_COMPARE] | |
189 | send_log "$do_compare\n" | |
190 | verbose "$do_compare" | |
191 | catch "exec sh -c [list $do_compare]" exec_output | |
86017ce9 | 192 | } else { |
eccbf555 AM |
193 | send_log "cmp tmpdir/ld2 tmpdir/ld3\n" |
194 | verbose "cmp tmpdir/ld2 tmpdir/ld3" | |
195 | catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output | |
86017ce9 | 196 | } |
252b5132 RH |
197 | set exec_output [prune_warnings $exec_output] |
198 | ||
199 | if [string match "" $exec_output] then { | |
200 | pass $testname | |
201 | } else { | |
202 | send_log "$exec_output\n" | |
203 | verbose "$exec_output" 1 | |
204 | ||
205 | fail $testname | |
206 | } | |
207 | } | |
9ab80182 JB |
208 | |
209 | catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status | |
eccbf555 | 210 | catch "exec rm -f tmpdir/ld2tail tmpdir/ld3tail" status |