1 # libstdc++ "tool init file" for DejaGNU
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # Define callbacks and load other libraries. This file is loaded relatively
21 # early, and before any other file we write ourselves. "load_lib" will
22 # find anything in the DejaGNU installation tree, or in our lib directory.
23 # "load_gcc_lib" will search the core compiler's .exp collection instead.
25 # The naming rule is that dg.exp looks for "tool-" and runtest.exp looks
26 # for "tool_" when finding callbacks. Utility routines we define for
27 # our callbacks begin with "v3-".
29 # libstdc++_* callbacks we don't define, but could:
30 # ..._option_help prints additional --help output
31 # ..._option_proc (--foo) process our own options
32 # ..._init (normal.exp) called once per test file
33 # ..._finish bracketing function for libstdc++_init
34 # ...-dg-prune removing output text, see top of system dg.exp
36 # Useful hook: if ${hostname}_init exists, it will be called, almost
37 # the last thing before testing begins. This can be defined in, e.g.,
38 # ~/.dejagnurc or $DEJAGNU.
40 proc load_gcc_lib { filename } {
42 load_file $srcdir/../../gcc/testsuite/lib/$filename
48 # compiler routines, then ours
49 load_gcc_lib target-supports.exp
50 load_gcc_lib target-supports-dg.exp
52 load_lib dg-options.exp
53 load_gcc_lib target-libpath.exp
54 load_gcc_lib wrapper.exp
56 # Useful for debugging. Pass the name of a variable and the verbosity
57 # threshold (number of -v's on the command line).
58 proc v3track { var n } {
60 verbose "++ $var is $val" $n
63 # Called by v3-init below. "Static" to this file.
64 proc v3-copy-files {srcfiles} {
66 if { [catch { set symlink [file readlink $f] } x] } then {
67 remote_download target $f
69 if { [regexp "^/" "$symlink"] } then {
70 remote_download target $symlink
72 set dirname [file dirname $f]
73 remote_download target $dirname/$symlink
79 # Called once, during runtest.exp setup.
80 proc libstdc++_init { testfile } {
82 global srcdir blddir objdir tool_root_dir
85 global gluefile wrap_flags
86 global ld_library_path
89 # We set LC_ALL and LANG to C so that we get the same error
90 # messages as expected.
94 set blddir [lookfor_file [get_multilibs] libstdc++-v3]
95 set flags_file "${blddir}/scripts/testsuite_flags"
98 # If a test doesn't have special options, use DEFAULT_CXXFLAGS.
99 # Use this variable if the behavior
100 # 1) only applies to libstdc++ testing
101 # 2) might need to be negated
102 # In particular, some tests have to be run without precompiled
103 # headers, or without assertions.
104 global DEFAULT_CXXFLAGS
105 if ![info exists DEFAULT_CXXFLAGS] then {
106 set DEFAULT_CXXFLAGS ""
107 # Host specific goo here.
108 if { [string match "powerpc-*-darwin*" $target_triplet] } {
109 append DEFAULT_CXXFLAGS " -multiply_defined suppress"
112 v3track DEFAULT_CXXFLAGS 2
114 # By default, we assume we want to run program images.
115 global dg-do-what-default
116 set dg-do-what-default run
118 # Copy any required data files.
119 v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
120 v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
122 # Locate libgcc.a so we don't need to account for different values of
123 # SHLIB_EXT on different platforms
124 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
126 set gccdir [file dirname $gccdir]
130 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
132 set ld_library_path ""
133 append ld_library_path ":${gccdir}"
134 set compiler ${gccdir}/g++
135 append ld_library_path ":${blddir}/src/.libs"
137 if { [is_remote host] == 0 && [which $compiler] != 0 } {
138 foreach i "[exec $compiler --print-multi-lib]" {
140 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
141 set mldir [string trimright $mldir "\;@"]
142 if { "$mldir" == "." } {
145 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
146 append ld_library_path ":${gccdir}/${mldir}"
151 set_ld_library_path_env_vars
152 if [info exists env(LD_LIBRARY_PATH)] {
153 verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
156 set compiler [transform "g++"]
159 # Do a bunch of handstands and backflips for cross compiling and
160 # finding simulators...
161 if [is_remote host] {
162 set header [remote_download host ${blddir}/testsuite/testsuite_hooks.h]
163 if { $header == "" } {
164 verbose -log "Unable to download ${blddir}/testsuite/testsuite_hooks.h to host."
167 set cxx [transform "g++"]
168 set cxxflags "-ggdb3"
171 # If we find a testsuite_flags file, we're testing in the build dir.
172 if { [file exists $flags_file] } {
173 set cxx [exec sh $flags_file --build-cxx]
174 set cxxflags [exec sh $flags_file --cxxflags]
175 set includes [exec sh $flags_file --build-includes]
177 set cxx [transform "g++"]
178 set cxxflags "-g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0"
179 set includes "-I${srcdir}"
180 # Guess at the location of the installed locale files.
181 # (It would be nice if "gcc --print-file-name" could find
182 # message files, but it cannot.)
183 set absolute_cxx [which $cxx]
184 if { $absolute_cxx != "" } {
185 set localedir "[file dirname $absolute_cxx]/../share/locale"
187 set cxxflags "$cxxflags -DLOCALEDIR=\"$localedir\""
191 # If a PCH file is available, use it. We must delay performing
192 # this check until $cxx and such have been initialized because we
193 # perform a test compilation. (Ideally, gcc --print-file-name would
194 # list PCH files, but it does not.)
196 if ![info exists PCH_CXXFLAGS] then {
197 set src "config[pid].cc"
198 set f [open $src "w"]
199 puts $f "int main () {}"
202 set lines [v3_target_compile $src "config[pid].o" object \
203 "additional_flags=-include additional_flags=bits/stdc++.h"]
205 set PCH_CXXFLAGS "-include bits/stdc++.h"
210 v3track PCH_CXXFLAGS 2
213 libstdc++_maybe_build_wrapper "${objdir}/testglue.o"
216 # Callback for cleanup routines.
217 proc libstdc++_exit { } {
220 if [info exists gluefile] {
221 file_on_build delete $gluefile;
226 # Callback from system dg-test.
227 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
228 # Set up the compiler flags, based on what we're going to do.
231 set compile_type "preprocess"
232 set output_file "[file rootname [file tail $prog]].i"
235 set compile_type "assembly"
236 set output_file "[file rootname [file tail $prog]].s"
239 set compile_type "object"
240 set output_file "[file rootname [file tail $prog]].o"
243 set compile_type "executable"
244 set output_file "./[file rootname [file tail $prog]].exe"
247 set compile_type "executable"
248 # FIXME: "./" is to cope with "." not being in $PATH.
249 # Should this be handled elsewhere?
251 set output_file "./[file rootname [file tail $prog]].exe"
252 # This is the only place where we care if an executable was
253 # created or not. If it was, dg.exp will try to run it.
254 remote_file build delete $output_file;
257 perror "$do_what: not a valid dg-do keyword"
262 if { $extra_tool_flags != "" } {
263 lappend options "additional_flags=$extra_tool_flags"
266 # There is a libstdc++_compile made for us by default (via the tool-
267 # and-target file), but the defaults are lacking in goodness.
268 set comp_output [v3_target_compile "$prog" "$output_file" "$compile_type" $options];
269 set comp_output [ prune_g++_output $comp_output ];
271 return [list $comp_output $output_file]
274 # True if the library supports wchar_t.
277 # True if the library supports threads.
280 # True if the library supports symbol versioning.
283 # A string naming object files to be linked into all tests.
286 # Called from libstdc++-dg-test above. Calls back into system's
287 # target_compile to actually do the work.
288 proc v3_target_compile { source dest type options } {
297 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
298 lappend options "libs=${gluefile}"
299 lappend options "ldflags=${wrap_flags}"
303 set cxxlibglossflags [libgloss_link_flags]
304 set cxx_final [concat $cxx_final $cxxlibglossflags]
305 set cxx_final [concat $cxx_final $cxxflags]
306 set cxx_final [concat $cxx_final $includes]
307 # Link the support objects into executables.
308 if { $type == "executable" } {
309 set cxx_final [concat $cxx_final ${v3-test_objs}]
312 lappend options "compiler=$cxx_final"
314 return [target_compile $source $dest $type $options]
318 # Build the support objects linked in with the libstdc++ tests. In
319 # addition, set v3-wchar_t, v3-threads, v3-test_objs, and v3-symver
321 proc v3-build_support {} {
328 # Figure out whether or not the library supports certain features.
334 set config_src "config.cc"
335 set f [open $config_src "w"]
336 puts $f "#include <bits/c++config.h>"
337 puts $f "#include <bits/gthr.h>"
339 set preprocessed [v3_target_compile $config_src "" \
340 preprocess "additional_flags=-dN"]
341 if { [string first "_GLIBCXX_USE_WCHAR_T" $preprocessed] != -1 } {
342 verbose -log "wchar_t support detected"
345 if { [string first "_GLIBCXX_SYMVER" $preprocessed] != -1 } {
346 verbose -log "symbol versioning support detected"
349 if { [string first "__GTHREADS" $preprocessed] != -1 } {
350 verbose -log "thread support detected"
354 # Build the support objects.
356 [list testsuite_abi.cc testsuite_allocator.cc testsuite_character.cc testsuite_hooks.cc]
357 foreach f $source_files {
358 set object_file [file rootname $f].o
359 # Compile with "-w" so that warnings issued by the compiler
360 # do not prevent compilation.
361 if { [v3_target_compile $srcdir/$f $object_file "object" \
362 [list "incdir=$srcdir" "additional_flags=-w"]]
364 error "could not compile $f"
366 append v3-test_objs "$object_file "
370 proc check_v3_target_namedlocale { } {
371 global et_namedlocale_saved
372 global et_namedlocale_target_name
375 if { ![info exists et_namedlocale_target_name] } {
376 set et_namedlocale_target_name ""
379 # If the target has changed since we set the cached value, clear it.
380 set current_target [current_target_name]
381 if { $current_target != $et_namedlocale_target_name } {
382 verbose "check_v3_target_namedlocale: `$et_namedlocale_target_name'" 2
383 set et_namedlocale_target_name $current_target
384 if [info exists et_namedlocale_saved] {
385 verbose "check_v3_target_namedlocale: removing cached result" 2
386 unset et_namedlocale_saved
390 if [info exists et_namedlocale_saved] {
391 verbose "check_v3_target_namedlocale: using cached result" 2
393 set et_namedlocale_saved 0
395 # Set up, compile, and execute a C++ test program that tries to use
396 # all the required named locales.
397 set src nlocale[pid].cc
398 set exe nlocale[pid].x
400 set f [open $src "w"]
401 puts $f "#include <locale>"
402 puts $f "using namespace std;"
403 puts $f "int main ()"
407 puts $f " locale(\"\");"
408 puts $f " locale(\"de_DE\");"
409 puts $f " locale(\"de_DE.ISO-8859-15@euro\");"
410 puts $f " locale(\"de_DE@euro\");"
411 puts $f " locale(\"en_HK\");"
412 puts $f " locale(\"en_PH\");"
413 puts $f " locale(\"en_US\");"
414 puts $f " locale(\"en_US.ISO-8859-1\");"
415 puts $f " locale(\"en_US.ISO-8859-15\");"
416 puts $f " locale(\"en_US.UTF-8\");"
417 puts $f " locale(\"es_ES\");"
418 puts $f " locale(\"es_MX\");"
419 puts $f " locale(\"fr_FR\");"
420 puts $f " locale(\"fr_FR@euro\");"
421 puts $f " locale(\"is_IS\");"
422 puts $f " locale(\"is_IS.UTF-8\");"
423 puts $f " locale(\"it_IT\");"
424 puts $f " locale(\"ja_JP.eucjp\");"
425 puts $f " locale(\"se_NO.UTF-8\");"
426 puts $f " locale(\"ta_IN\");"
427 puts $f " locale(\"zh_TW\");"
430 puts $f " catch(...)"
437 set lines [v3_target_compile $src $exe executable ""]
440 if [string match "" $lines] {
441 # No error message, compilation succeeded.
442 set result [${tool}_load "./$exe" "" ""]
443 set status [lindex $result 0]
444 remote_file build delete $exe
446 verbose "check_v3_target_namedlocale: status is <$status>" 2
448 if { $status == "pass" } {
449 set et_namedlocale_saved 1
452 verbose "check_v3_target_namedlocale: compilation failed" 2
455 return $et_namedlocale_saved
458 proc check_v3_target_cxa_atexit { } {
460 global et_cxa_atexit_target_name
463 if { ![info exists et_cxa_atexit_target_name] } {
464 set et_cxa_atexit_target_name ""
467 # If the target has changed since we set the cached value, clear it.
468 set current_target [current_target_name]
469 if { $current_target != $et_cxa_atexit_target_name } {
470 verbose "check_v3_target_cxa_atexit: `$et_cxa_atexit_target_name'" 2
471 set et_cxa_atexit_target_name $current_target
472 if [info exists et_cxa_atexit] {
473 verbose "check_v3_target_cxa_atexit: removing cached result" 2
478 if [info exists et_cxa_atexit] {
479 verbose "check_v3_target_cxa_atexit: using cached result" 2
483 # Set up, compile, and execute a C++ test program that depends
484 # on correct ordering of static object destructors. This is
485 # indicative of the presence and use of __cxa_atexit.
486 set src cxaatexit[pid].cc
487 set exe cxaatexit[pid].x
489 set f [open $src "w"]
490 puts $f "#include <stdlib.h>"
491 puts $f "static unsigned int count;"
494 puts $f "X() { count = 1; }"
497 puts $f " if (count != 3)"
499 puts $f " count = 4;"
504 puts $f "static X x;"
508 puts $f "Y() { f(); count = 2; }"
511 puts $f "if (count != 2)"
518 puts $f "{ return 0; }"
521 set lines [v3_target_compile $src $exe executable ""]
524 if [string match "" $lines] {
525 # No error message, compilation succeeded.
526 set result [${tool}_load "./$exe" "" ""]
527 set status [lindex $result 0]
528 remote_file build delete $exe
530 verbose "check_v3_target_cxa_atexit: status is <$status>" 2
532 if { $status == "pass" } {
536 verbose "check_v3_target_cxa_atexit: compilation failed" 2
539 return $et_cxa_atexit