1 # Copyright (C) 1992, 1993, 1994, 1996, 1997, 1999 Free Software Foundation, Inc.
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.
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.
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gcc@prep.ai.mit.edu
20 # This file was written by Rob Savoye (rob@cygnus.com)
21 # Currently maintained by Doug Evans (dje@cygnus.com)
23 # This file is loaded by the tool init file (eg: unix.exp). It provides
24 # default definitions for gcc_start, etc. and other supporting cast members.
26 # These globals are used by gcc_start if no compiler arguments are provided.
27 # They are also used by the various testsuites to define the environment:
28 # where to find stdio.h, libc.a, etc.
30 # we want to use libgloss so we can get find_gcc.
34 # GCC_UNDER_TEST is the compiler under test.
38 # default_gcc_version -- extract and print the version number of the compiler
41 proc default_gcc_version { } {
46 # ignore any arguments after the command
47 set compiler [lindex $GCC_UNDER_TEST 0]
49 if ![is_remote host] {
50 set compiler_name [which $compiler];
52 set compiler_name $compiler;
55 # verify that the compiler exists
56 if { $compiler_name != 0 } then {
57 set tmp [remote_exec host "$compiler -v"]
58 set status [lindex $tmp 0];
59 set output [lindex $tmp 1];
60 regexp "version.*$" $output version
61 if { $status == 0 && [info exists version] } then {
62 clone_output "$compiler_name $version\n"
64 clone_output "Couldn't determine version of $compiler_name: $output\n"
67 # compiler does not exist (this should have already been detected)
68 warning "$compiler does not exist"
73 # Call gcc_version. We do it this way so we can override it if needed.
75 proc gcc_version { } {
80 # gcc_init -- called at the start of each .exp script.
82 # There currently isn't much to do, but always using it allows us to
83 # make some enhancements without having to go back and rewrite the scripts.
88 proc gcc_init { args } {
91 global gluefile wrap_flags
92 global gcc_initialized
94 global TOOL_EXECUTABLE
96 if { $gcc_initialized == 1 } { return; }
98 if ![info exists GCC_UNDER_TEST] {
99 if [info exists TOOL_EXECUTABLE] {
100 set GCC_UNDER_TEST $TOOL_EXECUTABLE;
102 set GCC_UNDER_TEST "[find_gcc]"
106 if ![info exists tmpdir] then {
109 if { [target_info needs_status_wrapper]!="" && ![info exists gluefile] } {
110 set gluefile ${tmpdir}/testglue.o;
111 set result [build_wrapper $gluefile];
112 if { $result != "" } {
113 set gluefile [lindex $result 0];
114 set wrap_flags [lindex $result 1];
121 proc gcc_target_compile { source dest type options } {
123 global gluefile wrap_flags;
124 global GCC_UNDER_TEST
127 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
128 lappend options "libs=${gluefile}"
129 lappend options "ldflags=$wrap_flags"
132 if [target_info exists gcc,stack_size] {
133 lappend options "additional_flags=-DSTACK_SIZE=[target_info gcc,stack_size]"
135 if [target_info exists gcc,no_trampolines] {
136 lappend options "additional_flags=-DNO_TRAMPOLINES"
138 if [target_info exists gcc,no_label_values] {
139 lappend options "additional_flags=-DNO_LABEL_VALUES"
141 if [info exists TOOL_OPTIONS] {
142 lappend options "additional_flags=$TOOL_OPTIONS"
144 if [target_info exists gcc,no_varargs] {
145 lappend options "additional_flags=-DNO_VARARGS"
147 lappend options "compiler=$GCC_UNDER_TEST"
148 return [target_compile $source $dest $type $options]
152 # Reports pass/fail for a gcc compilation and returns true/false.
153 proc gcc_check_compile {testcase option objname gcc_output} {
155 set fatal_signal "*cc: Internal compiler error: program*got fatal signal"
157 if [string match "$fatal_signal 6" $gcc_output] then {
158 gcc_fail $testcase "Got Signal 6, $option"
162 if [string match "$fatal_signal 11" $gcc_output] then {
163 gcc_fail $testcase "Got Signal 11, $option"
167 # We shouldn't get these because of -w, but just in case.
168 if [string match "*cc:*warning:*" $gcc_output] then {
169 warning "$testcase: (with warnings) $option"
170 send_log "$gcc_output\n"
171 unresolved "$testcase, $option"
175 set gcc_output [prune_warnings $gcc_output]
177 set unsupported_message [gcc_check_unsupported_p $gcc_output]
178 if { $unsupported_message != "" } {
179 unsupported "$testcase: $unsupported_message"
183 # remove any leftover LF/CR to make sure any output is legit
184 regsub -all -- "\[\r\n\]*" $gcc_output "" gcc_output
186 # If any message remains, we fail.
187 if ![string match "" $gcc_output] then {
188 gcc_fail $testcase $option
192 # fail if the desired object file doesn't exist.
193 # FIXME: there's no way of checking for existence on a remote host.
194 if {$objname != "" && ![is3way] && ![file exists $objname]} {
195 gcc_fail $testcase $option
199 gcc_pass $testcase $option
206 # gcc_pass -- utility to record a testcase passed
209 proc gcc_pass { testcase cflags } {
210 if { "$cflags" == "" } {
213 pass "$testcase, $cflags"
218 # gcc_fail -- utility to record a testcase failed
221 proc gcc_fail { testcase cflags } {
222 if { "$cflags" == "" } {
225 fail "$testcase, $cflags"
230 # gcc_finish -- called at the end of every .exp script that calls gcc_init
232 # The purpose of this proc is to hide all quirks of the testing environment
233 # from the testsuites. It also exists to undo anything that gcc_init did
234 # (that needs undoing).
237 proc gcc_finish { } {
238 # The testing harness apparently requires this.
241 if [info exists errorInfo] then {
245 # Might as well reset these (keeps our caller from wondering whether
246 # s/he has to or not).
247 global prms_id bug_id
255 if [info exists gluefile] {
256 file_on_build delete $gluefile;
261 # If this is an older version of dejagnu (without runtest_file_p),
262 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
263 # This can be deleted after next dejagnu release.
265 if { [info procs runtest_file_p] == "" } then {
266 proc runtest_file_p { runtests testcase } {
267 if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
268 if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
278 # Provide a definition of this if missing (delete after next dejagnu release).
280 if { [info procs prune_warnings] == "" } then {
281 proc prune_warnings { text } {
286 # Utility used by mike-gcc.exp and c-torture.exp.
287 # Check the compiler(/assembler/linker) output for text indicating that
288 # the testcase should be marked as "unsupported".
290 # When dealing with a large number of tests, it's difficult to weed out the
291 # ones that are too big for a particular cpu (eg: 16 bit with a small amount
292 # of memory). There are various ways to deal with this. Here's one.
293 # Fortunately, all of the cases where this is likely to happen will be using
294 # gld so we can tell what the error text will look like.
296 proc ${tool}_check_unsupported_p { output } {
297 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
303 # Prune messages from gcc that aren't useful.
305 proc prune_gcc_output { text } {
306 #send_user "Before:$text\n"
307 regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
308 regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
310 # It would be nice to avoid passing anything to gcc that would cause it to
311 # issue these messages (since ignoring them seems like a hack on our part),
312 # but that's too difficult in the general case. For example, sometimes
313 # you need to use -B to point gcc at crt0.o, but there are some targets
314 # that don't have crt0.o.
315 regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
316 regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
318 #send_user "After:$text\n"