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