* NEWS: Mention OpenBSD/arm as a new native configuration.
[deliverable/binutils-gdb.git] / ld / testsuite / ld-selective / selective.exp
CommitLineData
252b5132 1# Expect script for LD selective linking tests
6db74b6f
DJ
2# Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
3# Free Software Foundation, Inc.
252b5132
RH
4#
5# This file is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
4f70f93f 9#
252b5132
RH
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
4f70f93f 14#
252b5132
RH
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
75be928b 17# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
252b5132
RH
18#
19# Written by Catherine Moore (clm@cygnus.com)
20# Make sure that constructors are handled correctly.
21
031d7588
AM
22# Only ELF based ports support selective linking
23if ![is_elf_format] {
4648dfcf
MS
24 return
25}
26
0fb33ef4
L
27# IA64 does not support selective linking
28if {[istarget "ia64-*-*"]} {
29 return
30}
31
d63083ef
HPN
32# List contains test-items with three items followed by four lists:
33# 1:name 2:test-type (CC or C++; add as needed) 3:filename 4:ld-flags
34# 5:must-have-symbols 6:must-not-have-symbols 7:xfail-targets.
35#
36# If a must(-not)-have symbol is a list, then that list must have two
37# items; the symbol name and a value the symbol must (not) have.
38#
39# Note: ld_nm trims leading `_' from _start
40#
41# FIXME: Instead of table, read settings from each source-file.
42set seltests {
031d7588
AM
43 {selective1 C 1.c {} {} {dropme1 dropme2} {}}
44 {selective2 C 2.c {} {} {foo} {mips*-*}}
453abe31 45 {selective3 C 2.c {-u foo} {foo} {{foo 0}} {mips*-*}}
031d7588
AM
46 {selective4 C++ 3.cc {} {start a A::foo() B::foo()} {A::bar()} {mips*-*}}
47 {selective5 C++ 4.cc {} {start a A::bar()} {A::foo() B::foo()} {mips*-*}}
453abe31 48 {selective6 C++ 5.cc {} {start a A::bar()}
067f2074 49 {A::foo() B::foo() dropme1() dropme2()} {*-*-*}}
d63083ef 50}
252b5132 51
44df2f94 52set cflags "-w -O -ffunction-sections -fdata-sections"
252b5132
RH
53set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti"
54set ldflags "--gc-sections -Bstatic"
55
1b19eb81
AO
56if [istarget sh64*-*-elf] {
57 # This is what gcc passes to ld by default, plus switch to the
58 # "usual" ELF _start (shelf32 normally uses just `start' for COFF
59 # compatibility)
60 set ldflags "-e _start -mshelf32 $ldflags"
61}
62
d63083ef 63# If we don't have g++ for the target, mark all tests as untested.
252b5132 64if { [which $CXX] == 0 } {
d63083ef 65 foreach testitem $seltests {
4291c3fa 66 untested "[lindex $testitem 0]"
252b5132 67 }
252b5132
RH
68 return
69}
70
d63083ef
HPN
71foreach testitem $seltests {
72 set testname [lindex $testitem 0]
73 set testtype [lindex $testitem 1]
74 set testfile [lindex $testitem 2]
75 set objfile "tmpdir/[file rootname $testfile].o"
76 set ldfile "tmpdir/[file rootname $testfile].x"
77 set failed 0
78
79 set ldargs [lindex $testitem 3]
80 set mustsyms [lindex $testitem 4]
81 set mustnotsyms [lindex $testitem 5]
82 set xfails [lindex $testitem 6]
83
84 foreach xfail_target $xfails {
85 setup_xfail $xfail_target
3017ff0e 86 }
031d7588 87 setup_xfail "alpha*-*" "arc*-*" "d30v*-*" "dlx*-*" "i370*-*" "i860*-*"
40937810 88 setup_xfail "i960*-*" "mn10200-*" "or32-*" "pj-*"
252b5132 89
d63083ef
HPN
90 # It's either C or C++ at the moment.
91 if { $testtype == "C++" } {
92 set testflags "$cflags $cxxflags"
23a75657
NC
93 if [string match "*gcc*" [lindex $CC 0]] {
94 # Starting with 3.4.0, -fvtable-gc is no longer supported and thus
95 # the functionality we try to test for cannot be expected to work.
96 catch "exec -- $CC -dumpversion" version
97 if [regexp "^(\[1-9\]\[0-9\]+|\[4-9\]|3.(\[1-9\]\[0-9\]+|\[4-9\]))\\." $version] {
98 setup_xfail {*-*-*}
99 }
100 }
d63083ef
HPN
101 } {
102 set testflags "$cflags"
103 }
252b5132 104
d63083ef
HPN
105 # Note that we do not actually *use* CXX; we just add cxxflags for C++
106 # tests. It might have been a buglet originally; now I think better
107 # leave as is.
108 if { ![ld_compile "$CC $testflags" $srcdir/$subdir/$testfile $objfile] } {
109 unresolved $testname
453abe31 110 continue
3017ff0e 111 }
252b5132 112
f6673641
NC
113 # V850 targets need libgcc.a
114 if [istarget v850*-*-elf] {
6db74b6f
DJ
115 catch "exec $CC -print-libgcc-file-name" libgcc
116 set objfile "$objfile $libgcc"
f6673641 117 }
4f70f93f 118
8f2a6955
NC
119 # ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided
120 if {[istarget arm-*-*] || [istarget xscale-*-*]} {
6db74b6f
DJ
121 catch "exec $CC -print-libgcc-file-name" libgcc
122 set objfile "$objfile $libgcc"
8f2a6955 123 }
4f70f93f
AM
124
125 # HPPA linux targets need libgcc.a for millicode routines ($$dyncall).
126 if [istarget hppa*-*-linux*] {
127 catch "exec $CC -print-libgcc-file-name" libgcc
128 set objfile "$objfile $libgcc"
129 }
130
fef67c28
SC
131 # m6811/m6812 code has references to soft registers.
132 if {[istarget m6811-*-*] || [istarget m6812-*-*]} {
133 set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0"
134 set objfile "$objfile --defsym _.d2=0"
135 }
136
d63083ef
HPN
137 if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
138 fail $testname
139 continue
140 }
252b5132 141
067f2074 142 if ![ld_nm $nm --demangle $ldfile] {
d63083ef
HPN
143 unresolved $testname
144 continue
145 }
252b5132 146
067f2074
AM
147 # Must make V2 demangled names look like V3
148 foreach nm_output_key [array names nm_output] {
149 if [regsub \\(void\\) $nm_output_key () new_nm_output_key] {
150 set nm_output($new_nm_output_key) nm_output($nm_output_key)
151 }
152 }
153
4f70f93f 154 # Check each mandated symbol and optionally mandated values.
d63083ef
HPN
155 foreach mustsym $mustsyms {
156 if { [llength [concat $mustsym]] == 1 } {
157 if { ![info exists nm_output($mustsym)] } {
158 verbose -log "$testname: missing $mustsym"
159 fail $testname
160 set failed 1
161 break
162 }
163 } {
164 set mustsymname [lindex $mustsym 0]
165 set mustsymvalue [lindex $mustsym 1]
166 if { ![info exists nm_output($mustsymname)] } {
167 verbose -log "$testname: missing $mustsymname"
168 fail $testname
169 set failed 1
170 break
171 } {
172 if { $nm_output($mustsymname) != $mustsymvalue } {
173 verbose -log "$testname: $mustsymname != $mustsymvalue"
174 verbose -log "is instead $nm_output($mustsymname)"
175 fail $testname
176 set failed 1
177 break
e76e4c91
AM
178 }
179 }
3017ff0e
AM
180 }
181 }
252b5132 182
d63083ef
HPN
183 if { $failed != 0 } {
184 continue
185 }
252b5132 186
d63083ef
HPN
187 # Check each unwanted symbol, or that symbols do not have specific
188 # values.
189 foreach mustnotsym $mustnotsyms {
190 if { [llength [concat $mustnotsym]] == 1 } {
191 if { [info exists nm_output($mustnotsym)] } {
192 verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)"
193 fail $testname
194 set failed 1
195 break
196 }
197 } {
198 set mustnotsymname [lindex $mustnotsym 0]
199 set mustnotsymvalue [lindex $mustnotsym 1]
200 if { [info exists nm_output($mustnotsymname)] \
201 && $nm_output($mustnotsymname) == $mustnotsymvalue} {
202 verbose -log "$testname: $mustnotsymname == $mustnotsymvalue"
203 fail $testname
204 set failed 1
205 break
3017ff0e 206 }
252b5132
RH
207 }
208 }
bd0110a3 209
d63083ef
HPN
210 if { $failed == 0 } {
211 pass $testname
bd0110a3
HPN
212 }
213}
This page took 0.265487 seconds and 4 git commands to generate.