OSDN Git Service

* bootstrap.exp: Detect if plugins are enabled. Skip the static
[pf3gnuchains/pf3gnuchains3x.git] / ld / testsuite / ld-bootstrap / bootstrap.exp
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.
4 #
5 # This file is part of the GNU Binutils.
6 #
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.
11 #
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.
16 #
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,
20 # MA 02110-1301, USA.
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 # 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
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.
47
48 foreach flags {"" "strip" "--static" "--traditional-format"
49                "--no-keep-memory" "--relax"} {
50     set do_strip "no"
51     if {"$flags" == "strip"} { 
52         set testname "bootstrap with $flags"
53         set flags ""
54         set do_strip "yes"
55     } else { if {"$flags" != ""} { 
56         set testname "bootstrap with $flags"
57     } else {
58         set testname "bootstrap"
59     }}
60
61     # --static is meaningless and --relax is incompatible with -r.
62     set partial_flags "$flags"
63     if { "$flags" == "--static" || "$flags" == "--relax" } {
64         set partial_flags ""
65     }
66
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"} {
70         untested $testname
71         continue
72     }
73
74     # Plugin support requires linking with a dynamic library which
75     # means that these
76     if { $flags == "--static" && $plugins == "yes" } then {
77         untested $testname
78         continue
79     }
80
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 {
84         untested $testname
85         continue
86     }
87
88     if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] {
89         fail $testname
90         continue
91     }
92
93     # On AIX, you need to specify an import list when using --static.
94     # You only want the import list when creating the final
95     # executable.
96     if { [istarget "*-*-aix*"] 
97          && ![istarget "ia64-*-aix*"]} {
98         if {"$flags" == "--static"} {
99             set flags "--static -bI:/lib/syscalls.exp"
100         }
101     }
102
103     # On Cygwin, -lintl may require -liconv when linking statically.
104     set extralibs ""
105     if { [istarget "*-*-cygwin*"]} {
106         if {"$flags" == "--static"} {
107             set extralibs "-liconv"
108         }
109     }
110
111     # Plugin support requires linking with libdl.
112     if { $plugins == "yes" } {
113         set extralibs "$extralibs -ldl"
114     }
115
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*"
120     }
121
122     if ![ld_link $ld tmpdir/ld1 "$flags tmpdir/ld-partial.o $BFDLIB $LIBIBERTY $extralibs"] {
123         fail $testname
124         continue
125     }
126
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"
132             fail $testname
133             continue
134         }
135     }
136
137     if ![ld_link tmpdir/ld1 tmpdir/ld2 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
138         fail $testname
139         continue
140     }
141
142     if ![ld_link tmpdir/ld2 tmpdir/ld3 "$flags $OFILES $BFDLIB $LIBIBERTY $extralibs"] {
143         fail $testname
144         continue
145     }
146
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"] {
154                 fail $testname
155                 continue
156             }
157         }
158     } else {
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"] {
164                 fail $testname
165                 continue
166             }
167         }
168     }
169
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
187     } else {
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
191     }
192     set exec_output [prune_warnings $exec_output]
193
194     if [string match "" $exec_output] then {
195         pass $testname
196     } else {
197         send_log "$exec_output\n"
198         verbose "$exec_output" 1
199
200         fail $testname
201     }
202 }
203
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