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