Fix v850 test failures
[external/binutils.git] / ld / testsuite / ld-selective / selective.exp
1 # Expect script for LD selective linking tests
2 #   Copyright (C) 1998, 1999, 2000 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 # 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} {}}
42   {selective2 C 2.c {} {} {foo} {}}
43   {selective3 C 2.c {-u foo} {foo} {{foo 0}} {}}
44   {selective4 C++ 3.cc {} {start foo__1A foo__1B} {bar__1A} {}}
45   {selective5 C++ 4.cc {} {} {foo__1B foo__1A} {}}
46   {selective6 C++ 5.cc {} {} {foo__1B foo__1A dropme1__Fv dropme2__Fv} {*-*-*}}
47 }
48
49 set cflags "-w -O2 -ffunction-sections -fdata-sections"
50 set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti"
51 set ldflags "--gc-sections -Bstatic"
52
53 # If we don't have g++ for the target, mark all tests as untested.
54 if { [which $CXX] == 0 } {
55     foreach testitem $seltests {
56         untested "[lindex $testitem 0]"
57     }
58     return
59 }
60
61 foreach testitem $seltests {
62     set testname [lindex $testitem 0]
63     set testtype [lindex $testitem 1]
64     set testfile [lindex $testitem 2]
65     set objfile "tmpdir/[file rootname $testfile].o"
66     set ldfile "tmpdir/[file rootname $testfile].x"
67     set failed 0
68
69     set ldargs [lindex $testitem 3]
70     set mustsyms [lindex $testitem 4]
71     set mustnotsyms [lindex $testitem 5]
72     set xfails [lindex $testitem 6]
73
74     foreach xfail_target $xfails {
75         setup_xfail $xfail_target
76     }
77
78     # It's either C or C++ at the moment.
79     if { $testtype == "C++" } {
80         set testflags "$cflags $cxxflags"
81     } {
82         set testflags "$cflags"
83     }
84
85     # Note that we do not actually *use* CXX; we just add cxxflags for C++
86     # tests.  It might have been a buglet originally; now I think better
87     # leave as is.
88     if { ![ld_compile "$CC $testflags" $srcdir/$subdir/$testfile $objfile] } {
89         unresolved $testname
90         return
91     }
92
93     # V850 targets need libgcc.a
94     if [istarget v850*-*-elf] {
95         set objfile "$objfile -L ../gcc -lgcc"
96     }
97     
98     if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
99         fail $testname
100         continue
101     }
102
103     if ![ld_nm $nm $ldfile] {
104         unresolved $testname
105         continue
106     }
107
108     # Check each mandated symbol and optionally mandated values. 
109     foreach mustsym $mustsyms {
110         if { [llength [concat $mustsym]] == 1 } {
111             if { ![info exists nm_output($mustsym)] } {
112                 verbose -log "$testname: missing $mustsym"
113                 fail $testname
114                 set failed 1
115                 break
116             }
117         } {
118             set mustsymname [lindex $mustsym 0]
119             set mustsymvalue [lindex $mustsym 1]
120             if { ![info exists nm_output($mustsymname)] } {
121                 verbose -log "$testname: missing $mustsymname"
122                 fail $testname
123                 set failed 1
124                 break
125             } {
126                 if { $nm_output($mustsymname) != $mustsymvalue } {
127                     verbose -log "$testname: $mustsymname != $mustsymvalue"
128                     verbose -log "is instead $nm_output($mustsymname)"
129                     fail $testname
130                     set failed 1
131                     break
132                 }
133             }
134         }
135     }
136
137     if { $failed != 0 } {
138         continue
139     }
140
141     # Check each unwanted symbol, or that symbols do not have specific
142     # values.
143     foreach mustnotsym $mustnotsyms {
144         if { [llength [concat $mustnotsym]] == 1 } {
145             if { [info exists nm_output($mustnotsym)] } {
146                 verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)"
147                 fail $testname
148                 set failed 1
149                 break
150             }
151         } {
152             set mustnotsymname [lindex $mustnotsym 0]
153             set mustnotsymvalue [lindex $mustnotsym 1]
154             if { [info exists nm_output($mustnotsymname)] \
155                     && $nm_output($mustnotsymname) == $mustnotsymvalue} {
156                 verbose -log "$testname: $mustnotsymname == $mustnotsymvalue"
157                 fail $testname
158                 set failed 1
159                 break
160             }
161         }
162     }
163
164     if { $failed == 0 } {
165         pass $testname
166     }
167 }
168