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