2001-07-12 H.J. Lu <hjl@gnu.org>
[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 foo__1A foo__1B} {bar__1A} {alpha*-* mips*-*}}
45   {selective5 C++ 4.cc {} {} {foo__1B foo__1A} {alpha*-* mips*-*}}
46   {selective6 C++ 5.cc {} {} {foo__1B foo__1A dropme1__Fv dropme2__Fv} {*-*-*}}
47 }
48
49 set cflags "-w -O -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     # m6811/m6812 code has references to soft registers.
99     if {[istarget m6811-*-*] || [istarget m6812-*-*]} {
100         set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0"
101         set objfile "$objfile --defsym _.d2=0"
102     }
103
104     if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
105         fail $testname
106         continue
107     }
108
109     if ![ld_nm $nm $ldfile] {
110         unresolved $testname
111         continue
112     }
113
114     # Check each mandated symbol and optionally mandated values. 
115     foreach mustsym $mustsyms {
116         if { [llength [concat $mustsym]] == 1 } {
117             if { ![info exists nm_output($mustsym)] } {
118                 verbose -log "$testname: missing $mustsym"
119                 fail $testname
120                 set failed 1
121                 break
122             }
123         } {
124             set mustsymname [lindex $mustsym 0]
125             set mustsymvalue [lindex $mustsym 1]
126             if { ![info exists nm_output($mustsymname)] } {
127                 verbose -log "$testname: missing $mustsymname"
128                 fail $testname
129                 set failed 1
130                 break
131             } {
132                 if { $nm_output($mustsymname) != $mustsymvalue } {
133                     verbose -log "$testname: $mustsymname != $mustsymvalue"
134                     verbose -log "is instead $nm_output($mustsymname)"
135                     fail $testname
136                     set failed 1
137                     break
138                 }
139             }
140         }
141     }
142
143     if { $failed != 0 } {
144         continue
145     }
146
147     # Check each unwanted symbol, or that symbols do not have specific
148     # values.
149     foreach mustnotsym $mustnotsyms {
150         if { [llength [concat $mustnotsym]] == 1 } {
151             if { [info exists nm_output($mustnotsym)] } {
152                 verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)"
153                 fail $testname
154                 set failed 1
155                 break
156             }
157         } {
158             set mustnotsymname [lindex $mustnotsym 0]
159             set mustnotsymvalue [lindex $mustnotsym 1]
160             if { [info exists nm_output($mustnotsymname)] \
161                     && $nm_output($mustnotsymname) == $mustnotsymvalue} {
162                 verbose -log "$testname: $mustnotsymname == $mustnotsymvalue"
163                 fail $testname
164                 set failed 1
165                 break
166             }
167         }
168     }
169
170     if { $failed == 0 } {
171         pass $testname
172     }
173 }
174