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