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