1 |
38 |
julius |
# Expect script for LD selective linking tests
|
2 |
|
|
# Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007
|
3 |
|
|
# Free Software Foundation, Inc.
|
4 |
|
|
#
|
5 |
|
|
# This file is part of the GNU Binutils.
|
6 |
|
|
#
|
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.
|
11 |
|
|
#
|
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.
|
16 |
|
|
#
|
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.
|
21 |
|
|
#
|
22 |
|
|
# Written by Catherine Moore (clm@cygnus.com)
|
23 |
|
|
# Make sure that constructors are handled correctly.
|
24 |
|
|
|
25 |
|
|
# Only ELF based ports support selective linking
|
26 |
|
|
if ![is_elf_format] {
|
27 |
|
|
return
|
28 |
|
|
}
|
29 |
|
|
|
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
|
40 |
|
|
}
|
41 |
|
|
|
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.
|
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()} {*-*-*}}
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
set cflags "-w -O -ffunction-sections -fdata-sections"
|
63 |
|
|
set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti"
|
64 |
|
|
set ldflags "--gc-sections -Bstatic"
|
65 |
|
|
|
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"
|
71 |
|
|
}
|
72 |
|
|
|
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"
|
78 |
|
|
}
|
79 |
|
|
|
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]"
|
84 |
|
|
}
|
85 |
|
|
return
|
86 |
|
|
}
|
87 |
|
|
|
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
|
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
|
103 |
|
|
}
|
104 |
|
|
setup_xfail "arc*-*" "d30v*-*" "dlx*-*" "i370*-*" "i860*-*"
|
105 |
|
|
setup_xfail "i960*-*" "mn10200-*" "or32-*" "pj-*"
|
106 |
|
|
|
107 |
|
|
# It's either C or C++ at the moment.
|
108 |
|
|
if { $testtype == "C++" } {
|
109 |
|
|
set testflags "$cflags $cxxflags"
|
110 |
|
|
set compiler "$CXX"
|
111 |
|
|
if [string match "*gcc*" [lindex $CC 0]] {
|
112 |
|
|
# Starting with 3.4.0, -fvtable-gc is no longer supported and thus
|
113 |
|
|
# the functionality we try to test for cannot be expected to work.
|
114 |
|
|
set version [remote_exec host "$CC -dumpversion"]
|
115 |
|
|
set version [lindex $version 1]
|
116 |
|
|
if [regexp "^(\[1-9\]\[0-9\]+|\[4-9\]|3.(\[1-9\]\[0-9\]+|\[4-9\]))\\." $version] {
|
117 |
|
|
setup_xfail {*-*-*}
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
} {
|
121 |
|
|
set testflags "$cflags"
|
122 |
|
|
set compiler "$CC"
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
# Note that we do not actually *use* CXX; we just add cxxflags for C++
|
126 |
|
|
# tests. It might have been a buglet originally; now I think better
|
127 |
|
|
# leave as is.
|
128 |
|
|
if { ![ld_compile "$compiler $testflags" $srcdir/$subdir/$testfile $objfile] } {
|
129 |
|
|
unresolved $testname
|
130 |
|
|
continue
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
# V850 targets need libgcc.a
|
134 |
|
|
if [istarget v850*-*-elf] {
|
135 |
|
|
set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
|
136 |
|
|
set libgcc [lindex $libgcc 1]
|
137 |
|
|
regsub -all "\[\r\n\]" $libgcc "" libgcc
|
138 |
|
|
set objfile "$objfile $libgcc"
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
# ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided
|
142 |
|
|
if {[istarget arm-*-*] || [istarget xscale-*-*]} {
|
143 |
|
|
set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
|
144 |
|
|
set libgcc [lindex $libgcc 1]
|
145 |
|
|
regsub -all "\[\r\n\]" $libgcc "" libgcc
|
146 |
|
|
set objfile "$objfile $libgcc"
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
# HPPA linux targets need libgcc.a for millicode routines ($$dyncall).
|
150 |
|
|
if [istarget hppa*-*-linux*] {
|
151 |
|
|
set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
|
152 |
|
|
set libgcc [lindex $libgcc 1]
|
153 |
|
|
regsub -all "\[\r\n\]" $libgcc "" libgcc
|
154 |
|
|
set objfile "$objfile $libgcc"
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
# m6811/m6812 code has references to soft registers.
|
158 |
|
|
if {[istarget m6811-*-*] || [istarget m6812-*-*]} {
|
159 |
|
|
set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0"
|
160 |
|
|
set objfile "$objfile --defsym _.d2=0"
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
|
164 |
|
|
fail $testname
|
165 |
|
|
continue
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
if ![ld_nm $nm --demangle $ldfile] {
|
169 |
|
|
unresolved $testname
|
170 |
|
|
continue
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
# Must make V2 demangled names look like V3
|
174 |
|
|
foreach nm_output_key [array names nm_output] {
|
175 |
|
|
if [regsub \\(void\\) $nm_output_key () new_nm_output_key] {
|
176 |
|
|
set nm_output($new_nm_output_key) nm_output($nm_output_key)
|
177 |
|
|
}
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
# Check each mandated symbol and optionally mandated values.
|
181 |
|
|
foreach mustsym $mustsyms {
|
182 |
|
|
if { [llength [concat $mustsym]] == 1 } {
|
183 |
|
|
if { ![info exists nm_output($mustsym)] } {
|
184 |
|
|
verbose -log "$testname: missing $mustsym"
|
185 |
|
|
fail $testname
|
186 |
|
|
set failed 1
|
187 |
|
|
break
|
188 |
|
|
}
|
189 |
|
|
} {
|
190 |
|
|
set mustsymname [lindex $mustsym 0]
|
191 |
|
|
set mustsymvalue [lindex $mustsym 1]
|
192 |
|
|
if { ![info exists nm_output($mustsymname)] } {
|
193 |
|
|
verbose -log "$testname: missing $mustsymname"
|
194 |
|
|
fail $testname
|
195 |
|
|
set failed 1
|
196 |
|
|
break
|
197 |
|
|
} {
|
198 |
|
|
if { $nm_output($mustsymname) != $mustsymvalue } {
|
199 |
|
|
verbose -log "$testname: $mustsymname != $mustsymvalue"
|
200 |
|
|
verbose -log "is instead $nm_output($mustsymname)"
|
201 |
|
|
fail $testname
|
202 |
|
|
set failed 1
|
203 |
|
|
break
|
204 |
|
|
}
|
205 |
|
|
}
|
206 |
|
|
}
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
if { $failed != 0 } {
|
210 |
|
|
continue
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
# Check each unwanted symbol, or that symbols do not have specific
|
214 |
|
|
# values.
|
215 |
|
|
foreach mustnotsym $mustnotsyms {
|
216 |
|
|
if { [llength [concat $mustnotsym]] == 1 } {
|
217 |
|
|
if { [info exists nm_output($mustnotsym)] } {
|
218 |
|
|
verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)"
|
219 |
|
|
fail $testname
|
220 |
|
|
set failed 1
|
221 |
|
|
break
|
222 |
|
|
}
|
223 |
|
|
} {
|
224 |
|
|
set mustnotsymname [lindex $mustnotsym 0]
|
225 |
|
|
set mustnotsymvalue [lindex $mustnotsym 1]
|
226 |
|
|
if { [info exists nm_output($mustnotsymname)] \
|
227 |
|
|
&& $nm_output($mustnotsymname) == $mustnotsymvalue} {
|
228 |
|
|
verbose -log "$testname: $mustnotsymname == $mustnotsymvalue"
|
229 |
|
|
fail $testname
|
230 |
|
|
set failed 1
|
231 |
|
|
break
|
232 |
|
|
}
|
233 |
|
|
}
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
if { $failed == 0 } {
|
237 |
|
|
pass $testname
|
238 |
|
|
}
|
239 |
|
|
}
|