* ld-elfvsb/elfvsb.exp: Mirror ia64 non-pic xfails for alpha.
[external/binutils.git] / ld / testsuite / ld-selective / selective.exp
1 # Expect script for LD selective linking tests
2 #   Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
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 # AOUT based ports do not support selective linking
23 if {[istarget "vax-*-ultrix*"]} {
24     return
25 }
26
27 # COFF based ports do not support selective linking
28 if {[istarget "*-*-coff"]} {
29     return
30 }
31 if {[istarget "*-*-pe"]} {
32     return
33 }
34
35 # Alpha does not support selective linking
36 if {[istarget "alpha*-*-*"]} {
37     return
38 }
39
40 # List contains test-items with three items followed by four lists:
41 # 1:name 2:test-type (CC or C++; add as needed) 3:filename 4:ld-flags
42 # 5:must-have-symbols 6:must-not-have-symbols 7:xfail-targets.
43 #
44 # If a must(-not)-have symbol is a list, then that list must have two
45 # items; the symbol name and a value the symbol must (not) have.
46 #
47 # Note: ld_nm trims leading `_' from _start
48 #
49 # FIXME: Instead of table, read settings from each source-file.
50 set seltests {
51   {selective1 C   1.c  {}       {}    {dropme1 dropme2} {alpha*-*}}
52   {selective2 C   2.c  {}       {}    {foo} {alpha*-* mips*-*}}
53   {selective3 C   2.c  {-u foo} {foo} {{foo 0}} {mips*-*}}
54   {selective4 C++ 3.cc {}       {start a A::foo() B::foo()} {A::bar()} {alpha*-*  mips*-*}}
55   {selective5 C++ 4.cc {}       {start a A::bar()} {A::foo() B::foo()} {alpha*-*  mips*-*}}
56   {selective6 C++ 5.cc {}       {start a A::bar()}
57     {A::foo() B::foo() dropme1() dropme2()} {*-*-*}}
58 }
59
60 set cflags "-w -O -ffunction-sections -fdata-sections"
61 set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti"
62 set ldflags "--gc-sections -Bstatic"
63
64 if [istarget sh64*-*-elf] {
65     # This is what gcc passes to ld by default, plus switch to the
66     # "usual" ELF _start (shelf32 normally uses just `start' for COFF
67     # compatibility)
68     set ldflags "-e _start -mshelf32 $ldflags"
69 }
70
71 # If we don't have g++ for the target, mark all tests as untested.
72 if { [which $CXX] == 0 } {
73     foreach testitem $seltests {
74         untested "[lindex $testitem 0]"
75     }
76     return
77 }
78
79 foreach testitem $seltests {
80     set testname [lindex $testitem 0]
81     set testtype [lindex $testitem 1]
82     set testfile [lindex $testitem 2]
83     set objfile "tmpdir/[file rootname $testfile].o"
84     set ldfile "tmpdir/[file rootname $testfile].x"
85     set failed 0
86
87     set ldargs [lindex $testitem 3]
88     set mustsyms [lindex $testitem 4]
89     set mustnotsyms [lindex $testitem 5]
90     set xfails [lindex $testitem 6]
91
92     foreach xfail_target $xfails {
93         setup_xfail $xfail_target
94     }
95
96     # It's either C or C++ at the moment.
97     if { $testtype == "C++" } {
98         set testflags "$cflags $cxxflags"
99     } {
100         set testflags "$cflags"
101     }
102
103     # Note that we do not actually *use* CXX; we just add cxxflags for C++
104     # tests.  It might have been a buglet originally; now I think better
105     # leave as is.
106     if { ![ld_compile "$CC $testflags" $srcdir/$subdir/$testfile $objfile] } {
107         unresolved $testname
108         continue
109     }
110
111     # V850 targets need libgcc.a
112     # FIXME: This does not work with installed toolchains!
113     if [istarget v850*-*-elf] {
114         set objfile "$objfile -L ../gcc -lgcc"
115     }
116
117     # ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided
118     # FIXME: This does not work with installed toolchains!
119     if {[istarget arm-*-*] || [istarget xscale-*-*]} {
120         set objfile "$objfile -L ../gcc -lgcc"
121     }
122
123     # HPPA linux targets need libgcc.a for millicode routines ($$dyncall).
124     if [istarget hppa*-*-linux*] {
125         catch "exec $CC -print-libgcc-file-name" libgcc
126         set objfile "$objfile $libgcc"
127     }
128
129     # m6811/m6812 code has references to soft registers.
130     if {[istarget m6811-*-*] || [istarget m6812-*-*]} {
131         set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0"
132         set objfile "$objfile --defsym _.d2=0"
133     }
134
135     if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
136         fail $testname
137         continue
138     }
139
140     if ![ld_nm $nm --demangle $ldfile] {
141         unresolved $testname
142         continue
143     }
144
145     # Must make V2 demangled names look like V3
146     foreach nm_output_key [array names nm_output] {
147         if [regsub \\(void\\) $nm_output_key () new_nm_output_key] {
148             set nm_output($new_nm_output_key) nm_output($nm_output_key)
149         }
150     }
151
152     # Check each mandated symbol and optionally mandated values.
153     foreach mustsym $mustsyms {
154         if { [llength [concat $mustsym]] == 1 } {
155             if { ![info exists nm_output($mustsym)] } {
156                 verbose -log "$testname: missing $mustsym"
157                 fail $testname
158                 set failed 1
159                 break
160             }
161         } {
162             set mustsymname [lindex $mustsym 0]
163             set mustsymvalue [lindex $mustsym 1]
164             if { ![info exists nm_output($mustsymname)] } {
165                 verbose -log "$testname: missing $mustsymname"
166                 fail $testname
167                 set failed 1
168                 break
169             } {
170                 if { $nm_output($mustsymname) != $mustsymvalue } {
171                     verbose -log "$testname: $mustsymname != $mustsymvalue"
172                     verbose -log "is instead $nm_output($mustsymname)"
173                     fail $testname
174                     set failed 1
175                     break
176                 }
177             }
178         }
179     }
180
181     if { $failed != 0 } {
182         continue
183     }
184
185     # Check each unwanted symbol, or that symbols do not have specific
186     # values.
187     foreach mustnotsym $mustnotsyms {
188         if { [llength [concat $mustnotsym]] == 1 } {
189             if { [info exists nm_output($mustnotsym)] } {
190                 verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)"
191                 fail $testname
192                 set failed 1
193                 break
194             }
195         } {
196             set mustnotsymname [lindex $mustnotsym 0]
197             set mustnotsymvalue [lindex $mustnotsym 1]
198             if { [info exists nm_output($mustnotsymname)] \
199                     && $nm_output($mustnotsymname) == $mustnotsymvalue} {
200                 verbose -log "$testname: $mustnotsymname == $mustnotsymvalue"
201                 fail $testname
202                 set failed 1
203                 break
204             }
205         }
206     }
207
208     if { $failed == 0 } {
209         pass $testname
210     }
211 }