1 |
732 |
jeremybenn |
# Copyright (C) 2003, 2005, 2008, 2009, 2010 Free Software Foundation, Inc.
|
2 |
|
|
|
3 |
|
|
# This program is free software; you can redistribute it and/or modify
|
4 |
|
|
# it under the terms of the GNU General Public License as published by
|
5 |
|
|
# the Free Software Foundation; either version 3 of the License, or
|
6 |
|
|
# (at your option) any later version.
|
7 |
|
|
#
|
8 |
|
|
# This program is distributed in the hope that it will be useful,
|
9 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11 |
|
|
# GNU General Public License for more details.
|
12 |
|
|
#
|
13 |
|
|
# You should have received a copy of the GNU General Public License
|
14 |
|
|
# along with this program; see the file COPYING3. If not see
|
15 |
|
|
# .
|
16 |
|
|
|
17 |
|
|
proc load_gcc_lib { filename } {
|
18 |
|
|
global srcdir
|
19 |
|
|
load_file $srcdir/../../gcc/testsuite/lib/$filename
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
load_lib dg.exp
|
23 |
|
|
load_lib libgloss.exp
|
24 |
|
|
load_gcc_lib target-libpath.exp
|
25 |
|
|
load_gcc_lib wrapper.exp
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
# Define libffi callbacks for dg.exp.
|
29 |
|
|
|
30 |
|
|
proc libffi-dg-test-1 { target_compile prog do_what extra_tool_flags } {
|
31 |
|
|
|
32 |
|
|
# To get all \n in dg-output test strings to match printf output
|
33 |
|
|
# in a system that outputs it as \015\012 (i.e. not just \012), we
|
34 |
|
|
# need to change all \n into \r?\n. As there is no dejagnu flag
|
35 |
|
|
# or hook to do that, we simply change the text being tested.
|
36 |
|
|
# Unfortunately, we have to know that the variable is called
|
37 |
|
|
# dg-output-text and lives in the caller of libffi-dg-test, which
|
38 |
|
|
# is two calls up. Overriding proc dg-output would be longer and
|
39 |
|
|
# would necessarily have the same assumption.
|
40 |
|
|
upvar 2 dg-output-text output_match
|
41 |
|
|
|
42 |
|
|
if { [llength $output_match] > 1 } {
|
43 |
|
|
regsub -all "\n" [lindex $output_match 1] "\r?\n" x
|
44 |
|
|
set output_match [lreplace $output_match 1 1 $x]
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
# Set up the compiler flags, based on what we're going to do.
|
48 |
|
|
|
49 |
|
|
set options [list]
|
50 |
|
|
switch $do_what {
|
51 |
|
|
"compile" {
|
52 |
|
|
set compile_type "assembly"
|
53 |
|
|
set output_file "[file rootname [file tail $prog]].s"
|
54 |
|
|
}
|
55 |
|
|
"link" {
|
56 |
|
|
set compile_type "executable"
|
57 |
|
|
set output_file "[file rootname [file tail $prog]].exe"
|
58 |
|
|
# The following line is needed for targets like the i960 where
|
59 |
|
|
# the default output file is b.out. Sigh.
|
60 |
|
|
}
|
61 |
|
|
"run" {
|
62 |
|
|
set compile_type "executable"
|
63 |
|
|
# FIXME: "./" is to cope with "." not being in $PATH.
|
64 |
|
|
# Should this be handled elsewhere?
|
65 |
|
|
# YES.
|
66 |
|
|
set output_file "./[file rootname [file tail $prog]].exe"
|
67 |
|
|
# This is the only place where we care if an executable was
|
68 |
|
|
# created or not. If it was, dg.exp will try to run it.
|
69 |
|
|
remote_file build delete $output_file;
|
70 |
|
|
}
|
71 |
|
|
default {
|
72 |
|
|
perror "$do_what: not a valid dg-do keyword"
|
73 |
|
|
return ""
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
if { $extra_tool_flags != "" } {
|
78 |
|
|
lappend options "additional_flags=$extra_tool_flags"
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
set comp_output [libffi_target_compile "$prog" "$output_file" "$compile_type" $options];
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
return [list $comp_output $output_file]
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
proc libffi-dg-test { prog do_what extra_tool_flags } {
|
89 |
|
|
return [libffi-dg-test-1 target_compile $prog $do_what $extra_tool_flags]
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
proc libffi-init { args } {
|
93 |
|
|
global gluefile wrap_flags;
|
94 |
|
|
global srcdir
|
95 |
|
|
global blddirffi
|
96 |
|
|
global objdir
|
97 |
|
|
global blddircxx
|
98 |
|
|
global TOOL_OPTIONS
|
99 |
|
|
global tool
|
100 |
|
|
global libffi_include
|
101 |
|
|
global libffi_link_flags
|
102 |
|
|
global tool_root_dir
|
103 |
|
|
global ld_library_path
|
104 |
|
|
|
105 |
|
|
set blddirffi [lookfor_file [get_multilibs] libffi]
|
106 |
|
|
verbose "libffi $blddirffi"
|
107 |
|
|
set blddircxx [lookfor_file [get_multilibs] libstdc++-v3]
|
108 |
|
|
verbose "libstdc++ $blddircxx"
|
109 |
|
|
|
110 |
|
|
set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
|
111 |
|
|
if {$gccdir != ""} {
|
112 |
|
|
set gccdir [file dirname $gccdir]
|
113 |
|
|
}
|
114 |
|
|
verbose "gccdir $gccdir"
|
115 |
|
|
|
116 |
|
|
set ld_library_path "."
|
117 |
|
|
append ld_library_path ":${gccdir}"
|
118 |
|
|
|
119 |
|
|
set compiler "${gccdir}/xgcc"
|
120 |
|
|
if { [is_remote host] == 0 && [which $compiler] != 0 } {
|
121 |
|
|
foreach i "[exec $compiler --print-multi-lib]" {
|
122 |
|
|
set mldir ""
|
123 |
|
|
regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
|
124 |
|
|
set mldir [string trimright $mldir "\;@"]
|
125 |
|
|
if { "$mldir" == "." } {
|
126 |
|
|
continue
|
127 |
|
|
}
|
128 |
|
|
if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
|
129 |
|
|
append ld_library_path ":${gccdir}/${mldir}"
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
|
|
# add the library path for libffi.
|
134 |
|
|
append ld_library_path ":${blddirffi}/.libs"
|
135 |
|
|
# add the library path for libstdc++ as well.
|
136 |
|
|
append ld_library_path ":${blddircxx}/src/.libs"
|
137 |
|
|
|
138 |
|
|
verbose "ld_library_path: $ld_library_path"
|
139 |
|
|
|
140 |
|
|
# Point to the Libffi headers in libffi.
|
141 |
|
|
set libffi_include "${blddirffi}/include"
|
142 |
|
|
verbose "libffi_include $libffi_include"
|
143 |
|
|
|
144 |
|
|
set libffi_dir "${blddirffi}/.libs"
|
145 |
|
|
verbose "libffi_dir $libffi_dir"
|
146 |
|
|
if { $libffi_dir != "" } {
|
147 |
|
|
set libffi_dir [file dirname ${libffi_dir}]
|
148 |
|
|
set libffi_link_flags "-L${libffi_dir}/.libs"
|
149 |
|
|
lappend libffi_link_flags "-L${blddircxx}/src/.libs"
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
set_ld_library_path_env_vars
|
153 |
|
|
libffi_maybe_build_wrapper "${objdir}/testglue.o"
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
proc libffi_exit { } {
|
157 |
|
|
global gluefile;
|
158 |
|
|
|
159 |
|
|
if [info exists gluefile] {
|
160 |
|
|
file_on_build delete $gluefile;
|
161 |
|
|
unset gluefile;
|
162 |
|
|
}
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
proc libffi_target_compile { source dest type options } {
|
166 |
|
|
global gluefile wrap_flags;
|
167 |
|
|
global srcdir
|
168 |
|
|
global blddirffi
|
169 |
|
|
global TOOL_OPTIONS
|
170 |
|
|
global libffi_link_flags
|
171 |
|
|
global libffi_include
|
172 |
|
|
global target_triplet
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
|
176 |
|
|
lappend options "libs=${gluefile}"
|
177 |
|
|
lappend options "ldflags=$wrap_flags"
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
# TOOL_OPTIONS must come first, so that it doesn't override testcase
|
181 |
|
|
# specific options.
|
182 |
|
|
if [info exists TOOL_OPTIONS] {
|
183 |
|
|
lappend options [concat "additional_flags=$TOOL_OPTIONS" $options];
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
# search for ffi_mips.h in srcdir, too
|
187 |
|
|
lappend options "additional_flags=-I${libffi_include} -I${srcdir}/../include -I${libffi_include}/.."
|
188 |
|
|
lappend options "additional_flags=${libffi_link_flags}"
|
189 |
|
|
|
190 |
|
|
# Darwin needs a stack execution allowed flag.
|
191 |
|
|
|
192 |
|
|
if { [istarget "*-*-darwin9*"] || [istarget "*-*-darwin1*"]
|
193 |
|
|
|| [istarget "*-*-darwin2*"] } {
|
194 |
|
|
lappend options "additional_flags=-Wl,-allow_stack_execute"
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
# If you're building the compiler with --prefix set to a place
|
198 |
|
|
# where it's not yet installed, then the linker won't be able to
|
199 |
|
|
# find the libgcc used by libffi.dylib. We could pass the
|
200 |
|
|
# -dylib_file option, but that's complicated, and it's much easier
|
201 |
|
|
# to just make the linker find libgcc using -L options.
|
202 |
|
|
if { [string match "*-*-darwin*" $target_triplet] } {
|
203 |
|
|
lappend options "libs= -shared-libgcc"
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
if { [string match "*-*-openbsd*" $target_triplet] } {
|
207 |
|
|
lappend options "libs= -lpthread"
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
lappend options "libs= -lffi"
|
211 |
|
|
|
212 |
|
|
verbose "options: $options"
|
213 |
|
|
return [target_compile $source $dest $type $options]
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
# Utility routines.
|
217 |
|
|
|
218 |
|
|
#
|
219 |
|
|
# search_for -- looks for a string match in a file
|
220 |
|
|
#
|
221 |
|
|
proc search_for { file pattern } {
|
222 |
|
|
set fd [open $file r]
|
223 |
|
|
while { [gets $fd cur_line]>=0 } {
|
224 |
|
|
if [string match "*$pattern*" $cur_line] then {
|
225 |
|
|
close $fd
|
226 |
|
|
return 1
|
227 |
|
|
}
|
228 |
|
|
}
|
229 |
|
|
close $fd
|
230 |
|
|
return 0
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
# Modified dg-runtest that can cycle through a list of optimization options
|
234 |
|
|
# as c-torture does.
|
235 |
|
|
proc libffi-dg-runtest { testcases default-extra-flags } {
|
236 |
|
|
global runtests
|
237 |
|
|
|
238 |
|
|
foreach test $testcases {
|
239 |
|
|
# If we're only testing specific files and this isn't one of
|
240 |
|
|
# them, skip it.
|
241 |
|
|
if ![runtest_file_p $runtests $test] {
|
242 |
|
|
continue
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
# Look for a loop within the source code - if we don't find one,
|
246 |
|
|
# don't pass -funroll[-all]-loops.
|
247 |
|
|
global torture_with_loops torture_without_loops
|
248 |
|
|
if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
|
249 |
|
|
set option_list $torture_with_loops
|
250 |
|
|
} else {
|
251 |
|
|
set option_list $torture_without_loops
|
252 |
|
|
}
|
253 |
|
|
|
254 |
|
|
set nshort [file tail [file dirname $test]]/[file tail $test]
|
255 |
|
|
|
256 |
|
|
foreach flags $option_list {
|
257 |
|
|
verbose "Testing $nshort, $flags" 1
|
258 |
|
|
dg-test $test $flags ${default-extra-flags}
|
259 |
|
|
}
|
260 |
|
|
}
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
# Like check_conditional_xfail, but callable from a dg test.
|
265 |
|
|
|
266 |
|
|
proc dg-xfail-if { args } {
|
267 |
|
|
set args [lreplace $args 0 0]
|
268 |
|
|
set selector "target [join [lindex $args 1]]"
|
269 |
|
|
if { [dg-process-target $selector] == "S" } {
|
270 |
|
|
global compiler_conditional_xfail_data
|
271 |
|
|
set compiler_conditional_xfail_data $args
|
272 |
|
|
}
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
proc check-flags { args } {
|
276 |
|
|
|
277 |
|
|
# The args are within another list; pull them out.
|
278 |
|
|
set args [lindex $args 0]
|
279 |
|
|
|
280 |
|
|
# The next two arguments are optional. If they were not specified,
|
281 |
|
|
# use the defaults.
|
282 |
|
|
if { [llength $args] == 2 } {
|
283 |
|
|
lappend $args [list "*"]
|
284 |
|
|
}
|
285 |
|
|
if { [llength $args] == 3 } {
|
286 |
|
|
lappend $args [list ""]
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
# If the option strings are the defaults, or the same as the
|
290 |
|
|
# defaults, there is no need to call check_conditional_xfail to
|
291 |
|
|
# compare them to the actual options.
|
292 |
|
|
if { [string compare [lindex $args 2] "*"] == 0
|
293 |
|
|
&& [string compare [lindex $args 3] "" ] == 0 } {
|
294 |
|
|
set result 1
|
295 |
|
|
} else {
|
296 |
|
|
# The target list might be an effective-target keyword, so replace
|
297 |
|
|
# the original list with "*-*-*", since we already know it matches.
|
298 |
|
|
set result [check_conditional_xfail [lreplace $args 1 1 "*-*-*"]]
|
299 |
|
|
}
|
300 |
|
|
|
301 |
|
|
return $result
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
proc dg-skip-if { args } {
|
305 |
|
|
# Verify the number of arguments. The last two are optional.
|
306 |
|
|
set args [lreplace $args 0 0]
|
307 |
|
|
if { [llength $args] < 2 || [llength $args] > 4 } {
|
308 |
|
|
error "dg-skip-if 2: need 2, 3, or 4 arguments"
|
309 |
|
|
}
|
310 |
|
|
|
311 |
|
|
# Don't bother if we're already skipping the test.
|
312 |
|
|
upvar dg-do-what dg-do-what
|
313 |
|
|
if { [lindex ${dg-do-what} 1] == "N" } {
|
314 |
|
|
return
|
315 |
|
|
}
|
316 |
|
|
|
317 |
|
|
set selector [list target [lindex $args 1]]
|
318 |
|
|
if { [dg-process-target $selector] == "S" } {
|
319 |
|
|
if [check-flags $args] {
|
320 |
|
|
upvar dg-do-what dg-do-what
|
321 |
|
|
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
|
322 |
|
|
}
|
323 |
|
|
}
|
324 |
|
|
}
|
325 |
|
|
|
326 |
|
|
# We need to make sure that additional_files and additional_sources
|
327 |
|
|
# are both cleared out after every test. It is not enough to clear
|
328 |
|
|
# them out *before* the next test run because gcc-target-compile gets
|
329 |
|
|
# run directly from some .exp files (outside of any test). (Those
|
330 |
|
|
# uses should eventually be eliminated.)
|
331 |
|
|
|
332 |
|
|
# Because the DG framework doesn't provide a hook that is run at the
|
333 |
|
|
# end of a test, we must replace dg-test with a wrapper.
|
334 |
|
|
|
335 |
|
|
if { [info procs saved-dg-test] == [list] } {
|
336 |
|
|
rename dg-test saved-dg-test
|
337 |
|
|
|
338 |
|
|
proc dg-test { args } {
|
339 |
|
|
global additional_files
|
340 |
|
|
global additional_sources
|
341 |
|
|
global errorInfo
|
342 |
|
|
|
343 |
|
|
if { [ catch { eval saved-dg-test $args } errmsg ] } {
|
344 |
|
|
set saved_info $errorInfo
|
345 |
|
|
set additional_files ""
|
346 |
|
|
set additional_sources ""
|
347 |
|
|
error $errmsg $saved_info
|
348 |
|
|
}
|
349 |
|
|
set additional_files ""
|
350 |
|
|
set additional_sources ""
|
351 |
|
|
}
|
352 |
|
|
}
|
353 |
|
|
|
354 |
|
|
# Local Variables:
|
355 |
|
|
# tcl-indent-level:4
|
356 |
|
|
# End:
|