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