gas:
[binutils/dougsmingw.git] / ld / testsuite / ld-selective / selective.exp
blobb563d355b2fcc0075eca5877671672f6cb963590
1 # Expect script for LD selective linking tests
2 # Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
3 # Free Software Foundation, Inc.
5 # This file is part of the GNU Binutils.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
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.
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
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 # MA 02110-1301, USA.
22 # Written by Catherine Moore (clm@cygnus.com)
23 # Make sure that constructors are handled correctly.
25 # Only ELF based ports support selective linking
26 if ![is_elf_format] {
27 return
30 # These targets do not support selective linking
31 if {[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*-*-*"]} {
39 return
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.
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.
49 # Note: ld_nm trims leading `_' from _start
51 # FIXME: Instead of table, read settings from each source-file.
52 set seltests {
53 {selective1 C 1.c {} {} {dropme1 dropme2} {}}
54 {selective2 C 2.c {} {} {foo} {}}
55 {selective3 C 2.c {-u foo} {foo} {{foo 0}} {}}
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*-*}}
58 {selective6 C++ 5.cc {} {start a A::bar()}
59 {A::foo() B::foo() dropme1() dropme2()} {*-*-*}}
62 set cflags "-w -O -ffunction-sections -fdata-sections"
63 set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti"
64 set ldflags "--gc-sections -Bstatic"
66 if [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"
73 if [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"
80 # If we don't have g++ for the target, mark all tests as untested.
81 if { ![is_remote host] && [which $CXX] == 0 } {
82 foreach testitem $seltests {
83 untested "[lindex $testitem 0]"
85 return
88 foreach 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
96 set ldargs [lindex $testitem 3]
97 set mustsyms [lindex $testitem 4]
98 set mustnotsyms [lindex $testitem 5]
99 set xfails [lindex $testitem 6]
101 foreach xfail_target $xfails {
102 setup_xfail $xfail_target
104 setup_xfail "arc*-*" "d30v*-*" "dlx*-*" "i370*-*" "i860*-*"
105 setup_xfail "i960*-*" "mn10200-*" "or32-*" "pj-*"
107 # It's either C or C++ at the moment.
108 if { $testtype == "C++" } {
109 set testflags "$cflags $cxxflags"
110 set compiler "$CXX"
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.
113 set version [remote_exec host "$CXX -dumpversion"]
114 set version [lindex $version 1]
115 if [regexp "^(\[1-9\]\[0-9\]+|\[4-9\]|3.(\[1-9\]\[0-9\]+|\[4-9\]))\\." $version] {
116 setup_xfail {*-*-*}
118 } else {
119 set testflags "$cflags"
120 set compiler "$CC"
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 "$compiler $testflags" $srcdir/$subdir/$testfile $objfile] } {
127 unresolved $testname
128 continue
131 # V850 targets need libgcc.a
132 if [istarget v850*-*-elf] {
133 set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
134 set libgcc [lindex $libgcc 1]
135 regsub -all "\[\r\n\]" $libgcc "" libgcc
136 set objfile "$objfile $libgcc"
139 # ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided
140 if {[istarget arm-*-*] || [istarget xscale-*-*]} {
141 set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
142 set libgcc [lindex $libgcc 1]
143 regsub -all "\[\r\n\]" $libgcc "" libgcc
144 set objfile "$objfile $libgcc"
147 # HPPA linux targets need libgcc.a for millicode routines ($$dyncall).
148 if [istarget hppa*-*-linux*] {
149 set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
150 set libgcc [lindex $libgcc 1]
151 regsub -all "\[\r\n\]" $libgcc "" libgcc
152 set objfile "$objfile $libgcc"
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"
161 if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
162 fail $testname
163 continue
166 if ![ld_nm $nm --demangle $ldfile] {
167 unresolved $testname
168 continue
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)
178 # Check each mandated symbol and optionally mandated values.
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
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
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
207 if { $failed != 0 } {
208 continue
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
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
234 if { $failed == 0 } {
235 pass $testname