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