* ld-selective/selective.exp: Fix selective testcases for MIPS.
[external/binutils.git] / ld / testsuite / ld-selective / selective.exp
1 # Expect script for LD selective linking tests
2 #   Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 #   Free Software Foundation, Inc.
4 #
5 # This file is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19 # Written by Catherine Moore (clm@cygnus.com)
20 # Make sure that constructors are handled correctly.
21
22 # Only ELF based ports support selective linking
23 if ![is_elf_format] {
24     return
25 }
26
27 # Alpha and IA64 do not support selective linking
28 if {[istarget "alpha*-*-*"] || [istarget "ia64-*-*"]} {
29     return
30 }
31
32 # List contains test-items with three items followed by four lists:
33 # 1:name 2:test-type (CC or C++; add as needed) 3:filename 4:ld-flags
34 # 5:must-have-symbols 6:must-not-have-symbols 7:xfail-targets.
35 #
36 # If a must(-not)-have symbol is a list, then that list must have two
37 # items; the symbol name and a value the symbol must (not) have.
38 #
39 # Note: ld_nm trims leading `_' from _start
40 #
41 # FIXME: Instead of table, read settings from each source-file.
42 set seltests {
43   {selective1 C   1.c  {}       {}    {dropme1 dropme2} {}}
44   {selective2 C   2.c  {}       {}    {foo} {}}
45   {selective3 C   2.c  {-u foo} {foo} {{foo 0}} {}}
46   {selective4 C++ 3.cc {}       {start a A::foo() B::foo()} {A::bar()} {mips*-*}}
47   {selective5 C++ 4.cc {}       {start a A::bar()} {A::foo() B::foo()} {mips*-*}}
48   {selective6 C++ 5.cc {}       {start a A::bar()}
49     {A::foo() B::foo() dropme1() dropme2()} {*-*-*}}
50 }
51
52 set cflags "-w -O -ffunction-sections -fdata-sections"
53 set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti"
54 set ldflags "--gc-sections -Bstatic"
55
56 if [istarget mips*-*] {
57     # MIPS16 doesn't support PIC code.
58     set cflags "-mno-abicalls $cflags"
59     # MIPS ELF uses __start by default, we override it.
60     set ldflags "-e _start $ldflags"
61 }
62
63 if [istarget sh64*-*-elf] {
64     # This is what gcc passes to ld by default, plus switch to the
65     # "usual" ELF _start (shelf32 normally uses just `start' for COFF
66     # compatibility)
67     set ldflags "-e _start -mshelf32 $ldflags"
68 }
69
70 # If we don't have g++ for the target, mark all tests as untested.
71 if { [which $CXX] == 0 } {
72     foreach testitem $seltests {
73         untested "[lindex $testitem 0]"
74     }
75     return
76 }
77
78 foreach testitem $seltests {
79     set testname [lindex $testitem 0]
80     set testtype [lindex $testitem 1]
81     set testfile [lindex $testitem 2]
82     set objfile "tmpdir/[file rootname $testfile].o"
83     set ldfile "tmpdir/[file rootname $testfile].x"
84     set failed 0
85
86     set ldargs [lindex $testitem 3]
87     set mustsyms [lindex $testitem 4]
88     set mustnotsyms [lindex $testitem 5]
89     set xfails [lindex $testitem 6]
90
91     foreach xfail_target $xfails {
92         setup_xfail $xfail_target
93     }
94     setup_xfail "arc*-*" "d30v*-*" "dlx*-*" "i370*-*" "i860*-*"
95     setup_xfail "i960*-*" "mn10200-*" "or32-*" "pj-*"
96
97     # It's either C or C++ at the moment.
98     if { $testtype == "C++" } {
99         set testflags "$cflags $cxxflags"
100         if [string match "*gcc*" [lindex $CC 0]] {
101             # Starting with 3.4.0, -fvtable-gc is no longer supported and thus
102             # the functionality we try to test for cannot be expected to work.
103             catch "exec -- $CC -dumpversion" version
104             if [regexp "^(\[1-9\]\[0-9\]+|\[4-9\]|3.(\[1-9\]\[0-9\]+|\[4-9\]))\\." $version] {
105                 setup_xfail {*-*-*}
106             }
107         }
108     } {
109         set testflags "$cflags"
110     }
111
112     # Note that we do not actually *use* CXX; we just add cxxflags for C++
113     # tests.  It might have been a buglet originally; now I think better
114     # leave as is.
115     if { ![ld_compile "$CC $testflags" $srcdir/$subdir/$testfile $objfile] } {
116         unresolved $testname
117         continue
118     }
119
120     # V850 targets need libgcc.a
121     if [istarget v850*-*-elf] {
122         catch "exec $CC -print-libgcc-file-name" libgcc
123         set objfile "$objfile $libgcc"
124     }
125
126     # ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided
127     if {[istarget arm-*-*] || [istarget xscale-*-*]} {
128         catch "exec $CC -print-libgcc-file-name" libgcc
129         set objfile "$objfile $libgcc"
130     }
131
132     # HPPA linux targets need libgcc.a for millicode routines ($$dyncall).
133     if [istarget hppa*-*-linux*] {
134         catch "exec $CC -print-libgcc-file-name" libgcc
135         set objfile "$objfile $libgcc"
136     }
137
138     # m6811/m6812 code has references to soft registers.
139     if {[istarget m6811-*-*] || [istarget m6812-*-*]} {
140         set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0"
141         set objfile "$objfile --defsym _.d2=0"
142     }
143
144     if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
145         fail $testname
146         continue
147     }
148
149     if ![ld_nm $nm --demangle $ldfile] {
150         unresolved $testname
151         continue
152     }
153
154     # Must make V2 demangled names look like V3
155     foreach nm_output_key [array names nm_output] {
156         if [regsub \\(void\\) $nm_output_key () new_nm_output_key] {
157             set nm_output($new_nm_output_key) nm_output($nm_output_key)
158         }
159     }
160
161     # Check each mandated symbol and optionally mandated values.
162     foreach mustsym $mustsyms {
163         if { [llength [concat $mustsym]] == 1 } {
164             if { ![info exists nm_output($mustsym)] } {
165                 verbose -log "$testname: missing $mustsym"
166                 fail $testname
167                 set failed 1
168                 break
169             }
170         } {
171             set mustsymname [lindex $mustsym 0]
172             set mustsymvalue [lindex $mustsym 1]
173             if { ![info exists nm_output($mustsymname)] } {
174                 verbose -log "$testname: missing $mustsymname"
175                 fail $testname
176                 set failed 1
177                 break
178             } {
179                 if { $nm_output($mustsymname) != $mustsymvalue } {
180                     verbose -log "$testname: $mustsymname != $mustsymvalue"
181                     verbose -log "is instead $nm_output($mustsymname)"
182                     fail $testname
183                     set failed 1
184                     break
185                 }
186             }
187         }
188     }
189
190     if { $failed != 0 } {
191         continue
192     }
193
194     # Check each unwanted symbol, or that symbols do not have specific
195     # values.
196     foreach mustnotsym $mustnotsyms {
197         if { [llength [concat $mustnotsym]] == 1 } {
198             if { [info exists nm_output($mustnotsym)] } {
199                 verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)"
200                 fail $testname
201                 set failed 1
202                 break
203             }
204         } {
205             set mustnotsymname [lindex $mustnotsym 0]
206             set mustnotsymvalue [lindex $mustnotsym 1]
207             if { [info exists nm_output($mustnotsymname)] \
208                     && $nm_output($mustnotsymname) == $mustnotsymvalue} {
209                 verbose -log "$testname: $mustnotsymname == $mustnotsymvalue"
210                 fail $testname
211                 set failed 1
212                 break
213             }
214         }
215     }
216
217     if { $failed == 0 } {
218         pass $testname
219     }
220 }