* ld-selective/5.cc: New test.
[platform/upstream/binutils.git] / ld / testsuite / ld-selective / selective.exp
1 # Expect script for LD selective linking tests
2 #   Copyright (C) 1998, 1999 Free Software Foundation
3 #
4 # This file is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #
18 # Written by Catherine Moore (clm@cygnus.com)
19 # Make sure that constructors are handled correctly.
20
21
22 # COFF based ports do not support selective linking
23 if {[istarget "*-*-coff"]} {
24     return
25 }
26 if {[istarget "*-*-pe"]} {
27     return
28 }
29
30 set test1 "selective1"
31 set test2 "selective2"
32 set test3 "selective3"
33 set test4 "selective4"
34 set test5 "selective5"
35 set test6 "selective6"
36
37 set cflags "-w -O2 -ffunction-sections -fdata-sections"
38 set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti"
39 set ldflags "--gc-sections -Bstatic"
40
41 if { [which $CXX] == 0 } {
42     untested $test1
43     untested $test2
44     untested $test3
45     untested $test4
46     untested $test5
47     untested $test6
48     return
49 }
50
51 if { ![ld_compile "$CC $cflags" $srcdir/$subdir/1.c tmpdir/1.o]} {
52     unresolved $test1
53     return
54 }
55
56 if ![ld_simple_link $ld tmpdir/1.x "$ldflags tmpdir/1.o"] {
57     fail $test1
58 } else {
59     if ![ld_nm $nm tmpdir/1.x] {
60         unresolved $test1
61     } else {
62         if {[info exists nm_output(dropme1)]} {
63             send_log "dropme1 == $nm_output(dropme1)\n"
64             verbose "dropme1 == $nm_output(dropme1)"
65             fail $test1
66         } else {
67             if {[info exists nm_output(dropme2)]} {
68                 send_log "dropme2 == $nm_output(dropme2)\n"
69                 verbose "dropme2 == $nm_output(dropme2)"
70                 fail $test1
71             } else {
72                 pass $test1
73             }
74         }
75     }
76 }
77
78 if { ![ld_compile "$CC $cflags" $srcdir/$subdir/2.c tmpdir/2.o]} {
79     unresolved $test2
80     return
81 }
82
83 if ![ld_simple_link $ld tmpdir/2.x "$ldflags tmpdir/2.o"] {
84     fail $test2
85 } else {
86     if ![ld_nm $nm tmpdir/2.x] {
87         unresolved $test2
88     } else {
89         if {[info exists nm_output(foo)] } {
90             send_log "foo == $nm_output(foo)\n"
91             verbose "foo == $nm_output(foo)"
92             fail $test2
93         } else {
94             pass $test2
95         }
96     }
97 }
98
99 if { ![ld_compile "$CC $cflags" $srcdir/$subdir/2.c tmpdir/2.o]} {
100     unresolved $test3
101     return
102 }
103
104 if ![ld_simple_link $ld tmpdir/2.x "$ldflags -u foo tmpdir/2.o"] {
105     fail $test3
106 } else {
107     if ![ld_nm $nm tmpdir/2.x] {
108         unresolved $test3
109     } else {
110         if {![info exists nm_output(foo)] } {
111             send_log "bad output from nm\n"
112             verbose "bad output from nm"
113             fail $test3
114         } else {
115             if {$nm_output(foo) == 0} {
116                 send_log "foo == $nm_output(foo)\n"
117                 verbose "foo == $nm_output(foo)"
118                 fail $test3
119             } else {
120                 pass $test3
121             }
122         }
123     }
124 }
125
126 setup_xfail "v850*-*-elf"
127
128 if { ![ld_compile "$CC $cflags $cxxflags" $srcdir/$subdir/3.cc tmpdir/3.o]} {
129     unresolved $test4
130     return
131 }
132
133 setup_xfail "v850*-*-elf"
134
135 if ![ld_simple_link $ld tmpdir/3.x "$ldflags tmpdir/3.o"] {
136    fail $test4
137 } else {
138     if ![ld_nm $nm tmpdir/3.x] {
139        unresolved $test4
140     } else {
141         if [info exists nm_output(bar__1A)] {
142             send_log "bar__1A == $nm_output(bar__1A)\n"
143             verbose "bar__1A == $nm_output(bar__1A)"
144             fail $test4
145         } else {
146 #note ld_nm trims leading `_' from _start
147             if ![info exists nm_output(start)] {
148                 send_log "_start missing\n"
149                 verbose "_start missing"
150                 fail $test4
151             } else {
152                 if ![info exists nm_output(foo__1A)] {
153                     send_log "foo__1A missing\n"
154                     verbose "foo_1A missing"
155                     fail $test4
156                 } else {
157                     if ![info exists nm_output(foo__1B)] {
158                         send_log "foo__1B missing\n"
159                         verbose "foo_1B missing"
160                         fail $test4
161                     } else {
162                         pass $test4
163                     }
164                 }
165             }
166         }
167     }
168 }
169
170 if { ![ld_compile "$CC $cflags $cxxflags" $srcdir/$subdir/4.cc tmpdir/4.o]} {
171     unresolved $test5
172     return
173 }
174
175 if ![ld_simple_link $ld tmpdir/4.x "$ldflags tmpdir/4.o"] {
176     fail $test5
177 } else {
178     if ![ld_nm $nm tmpdir/4.x] {
179         unresolved $test5
180     } else {
181         if {[info exists nm_output(foo__1B)]} {
182             send_log "foo__1B == $nm_output(foo__1B)\n"
183             verbose "foo__1B == $nm_output(foo__1B)"
184             fail $test5
185         } else {
186             if {[info exists nm_output(foo__1A)]} {
187                 send_log "foo__1A == $nm_output(foo__1A)\n"
188                 verbose "foo__1A == $nm_output(foo__1A)"
189                 fail $test5
190             } else {
191                 pass $test5
192             }
193         }
194     }
195 }
196
197 if { ![ld_compile "$CC $cflags $cxxflags" $srcdir/$subdir/5.cc tmpdir/5.o]} {
198     unresolved $test6
199     return
200 }
201
202 # Exposes a bug, currently.  FIXME: Fix it.
203 # FIXME: Break out the nesting to a function that takes two lists, one
204 # with expected present symbols, one with expected absent symbols, and
205 # iterates over nm output.  Use that function in all tests here.
206
207 setup_xfail "*-*-*"
208
209 if ![ld_simple_link $ld tmpdir/5.x "$ldflags tmpdir/5.o"] {
210     fail $test6
211 } else {
212     if ![ld_nm $nm tmpdir/5.x] {
213         unresolved $test6
214     } else {
215         if {[info exists nm_output(foo__1B)]} {
216             send_log "foo__1B == $nm_output(foo__1B)\n"
217             verbose "foo__1B == $nm_output(foo__1B)"
218             fail $test6
219         } else {
220             if {[info exists nm_output(foo__1A)]} {
221                 send_log "foo__1A == $nm_output(foo__1A)\n"
222                 verbose "foo__1A == $nm_output(foo__1A)"
223                 fail $test6
224             } else {
225                 if {[info exists nm_output(dropme1__Fv)]} {
226                     send_log "dropme1__Fv == $nm_output(dropme1__Fv)\n"
227                     verbose "dropme1__Fv == $nm_output(dropme1__Fv)"
228                     fail $test6
229                 } else {
230                     if {[info exists nm_output(dropme2__Fv)]} {
231                         send_log "dropme2__Fv == $nm_output(dropme2__Fv)\n"
232                         verbose "dropme2__Fv == $nm_output(dropme2__Fv)"
233                         fail $test6
234                     } else {
235                         pass $test6
236                     }
237                 }
238             }
239         }
240     }
241 }
242