]> git.ipfire.org Git - thirdparty/gcc.git/blob - libffi/testsuite/lib/libffi-dg.exp
re PR other/18138 (libgcc_s.so.1 not found by 64-bit testsuite)
[thirdparty/gcc.git] / libffi / testsuite / lib / libffi-dg.exp
1 # Copyright (C) 2003 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 2 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; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 load_lib dg.exp
18 load_lib libgloss.exp
19
20
21
22 # Define libffi callbacks for dg.exp.
23
24 proc libffi-dg-test-1 { target_compile prog do_what extra_tool_flags } {
25 # Set up the compiler flags, based on what we're going to do.
26
27 set options [list]
28 switch $do_what {
29 "compile" {
30 set compile_type "assembly"
31 set output_file "[file rootname [file tail $prog]].s"
32 }
33 "link" {
34 set compile_type "executable"
35 set output_file "[file rootname [file tail $prog]].exe"
36 # The following line is needed for targets like the i960 where
37 # the default output file is b.out. Sigh.
38 }
39 "run" {
40 set compile_type "executable"
41 # FIXME: "./" is to cope with "." not being in $PATH.
42 # Should this be handled elsewhere?
43 # YES.
44 set output_file "./[file rootname [file tail $prog]].exe"
45 # This is the only place where we care if an executable was
46 # created or not. If it was, dg.exp will try to run it.
47 remote_file build delete $output_file;
48 }
49 default {
50 perror "$do_what: not a valid dg-do keyword"
51 return ""
52 }
53 }
54
55 if { $extra_tool_flags != "" } {
56 lappend options "additional_flags=$extra_tool_flags"
57 }
58
59 set comp_output [libffi_target_compile "$prog" "$output_file" "$compile_type" $options];
60
61
62 return [list $comp_output $output_file]
63 }
64
65
66 proc libffi-dg-test { prog do_what extra_tool_flags } {
67 return [libffi-dg-test-1 target_compile $prog $do_what $extra_tool_flags]
68 }
69
70 proc libffi-init { args } {
71 global gluefile wrap_flags;
72 global srcdir
73 global blddirffi
74 global blddircxx
75 global TOOL_OPTIONS
76 global tool
77 global libffi_include
78 global libffi_link_flags
79 global tool_root_dir
80
81 set blddirffi [lookfor_file [get_multilibs] libffi]
82 verbose "libffi $blddirffi"
83 set blddircxx [lookfor_file [get_multilibs] libstdc++-v3]
84 verbose "libstdc++ $blddircxx"
85
86 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
87 if {$gccdir != ""} {
88 set gccdir [file dirname $gccdir]
89 }
90 verbose "gccdir $gccdir"
91
92 set ld_library_path "."
93 append ld_library_path ":${gccdir}"
94
95 set compiler "${gccdir}/xgcc"
96 if { [is_remote host] == 0 && [which $compiler] != 0 } {
97 foreach i "[exec $compiler --print-multi-lib]" {
98 set mldir ""
99 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
100 set mldir [string trimright $mldir "\;@"]
101 if { "$mldir" == "." } {
102 continue
103 }
104 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
105 append ld_library_path ":${gccdir}/${mldir}"
106 }
107 }
108 }
109 # add the library path for libffi.
110 append ld_library_path ":${blddirffi}/.libs"
111 # add the library path for libstdc++ as well.
112 append ld_library_path ":${blddircxx}/src/.libs"
113
114 verbose "ld_library_path: $ld_library_path"
115
116 # Point to the Libffi headers in libffi.
117 set libffi_include "${blddirffi}/include"
118 verbose "libffi_include $libffi_include"
119
120 set libffi_dir "${blddirffi}/.libs"
121 verbose "libffi_dir $libffi_dir"
122 if { $libffi_dir != "" } {
123 set libffi_dir [file dirname ${libffi_dir}]
124 set libffi_link_flags "-L${libffi_dir}/.libs"
125 lappend libffi_link_flags "-L${blddircxx}/src/.libs"
126 }
127
128 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
129 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
130 # (for the 64-bit ABI). The right way to do this would be to modify
131 # unix.exp -- but that's not an option since it's part of DejaGNU
132 # proper, so we do it here.
133 # The same applies to darwin (DYLD_LIBRARY_PATH), solaris 32 bit
134 # (LD_LIBRARY_PATH_32), solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
135 # (SHLIB_PATH).
136 if {![is_remote target]} {
137 set ld_path "LD_LIBRARY_PATH SHLIB_PATH LD_LIBRARYN32_PATH LD_LIBRARY64_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 DYLD_LIBRARY_PATH"
138 foreach path $ld_path {
139 if [info exists env($path)] {
140 # If we've already added these directories once, keep
141 # the existing path.
142 if {$ld_library_path != $env($path)
143 && [string first $ld_library_path: $env($path)] != 0} {
144 setenv $path "$ld_library_path:$env($path)"
145 }
146 } else {
147 setenv $path "$ld_library_path"
148 }
149 }
150 }
151 }
152
153 proc libffi_target_compile { source dest type options } {
154 global gluefile wrap_flags;
155 global srcdir
156 global blddirffi
157 global TOOL_OPTIONS
158 global libffi_link_flags
159 global libffi_include
160 global target_triplet
161
162
163 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
164 lappend options "libs=${gluefile}"
165 lappend options "ldflags=$wrap_flags"
166 }
167
168 # TOOL_OPTIONS must come first, so that it doesn't override testcase
169 # specific options.
170 if [info exists TOOL_OPTIONS] {
171 lappend options [concat "additional_flags=$TOOL_OPTIONS" $options];
172 }
173
174 # search for ffi_mips.h in srcdir, too
175 lappend options "additional_flags=-I${libffi_include} -I${srcdir}/../include -I${libffi_include}/.."
176 lappend options "additional_flags=${libffi_link_flags}"
177
178 if { [string match "powerpc-*-darwin*" $target_triplet] } {
179 lappend options "libs= -lgcc_s"
180 }
181
182 lappend options "libs= -lffi"
183
184 verbose "options: $options"
185 return [target_compile $source $dest $type $options]
186 }
187
188 # Utility routines.
189
190 #
191 # search_for -- looks for a string match in a file
192 #
193 proc search_for { file pattern } {
194 set fd [open $file r]
195 while { [gets $fd cur_line]>=0 } {
196 if [string match "*$pattern*" $cur_line] then {
197 close $fd
198 return 1
199 }
200 }
201 close $fd
202 return 0
203 }
204
205 # Modified dg-runtest that can cycle through a list of optimization options
206 # as c-torture does.
207 proc libffi-dg-runtest { testcases default-extra-flags } {
208 global runtests
209
210 foreach test $testcases {
211 # If we're only testing specific files and this isn't one of
212 # them, skip it.
213 if ![runtest_file_p $runtests $test] {
214 continue
215 }
216
217 # Look for a loop within the source code - if we don't find one,
218 # don't pass -funroll[-all]-loops.
219 global torture_with_loops torture_without_loops
220 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
221 set option_list $torture_with_loops
222 } else {
223 set option_list $torture_without_loops
224 }
225
226 set nshort [file tail [file dirname $test]]/[file tail $test]
227
228 foreach flags $option_list {
229 verbose "Testing $nshort, $flags" 1
230 dg-test $test $flags ${default-extra-flags}
231 }
232 }
233 }
234
235
236 # Like check_conditional_xfail, but callable from a dg test.
237
238 proc dg-xfail-if { args } {
239 set args [lreplace $args 0 0]
240 set selector "target [join [lindex $args 1]]"
241 if { [dg-process-target $selector] == "S" } {
242 global compiler_conditional_xfail_data
243 set compiler_conditional_xfail_data $args
244 }
245 }
246
247
248 # We need to make sure that additional_files and additional_sources
249 # are both cleared out after every test. It is not enough to clear
250 # them out *before* the next test run because gcc-target-compile gets
251 # run directly from some .exp files (outside of any test). (Those
252 # uses should eventually be eliminated.)
253
254 # Because the DG framework doesn't provide a hook that is run at the
255 # end of a test, we must replace dg-test with a wrapper.
256
257 if { [info procs saved-dg-test] == [list] } {
258 rename dg-test saved-dg-test
259
260 proc dg-test { args } {
261 global additional_files
262 global additional_sources
263 global errorInfo
264
265 if { [ catch { eval saved-dg-test $args } errmsg ] } {
266 set saved_info $errorInfo
267 set additional_files ""
268 set additional_sources ""
269 error $errmsg $saved_info
270 }
271 set additional_files ""
272 set additional_sources ""
273 }
274 }
275
276 # Local Variables:
277 # tcl-indent-level:4
278 # End: