| 1 |
# Copyright (C) 1992-2025 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 GCC; see the file COPYING3. If not see |
| 15 |
# <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
# This file was written by Rob Savoye ([email protected]) |
| 18 |
# Currently maintained by Doug Evans ([email protected]) |
| 19 |
|
| 20 |
# This file is loaded by the tool init file (eg: unix.exp). It provides |
| 21 |
# default definitions for gcc_start, etc. and other supporting cast members. |
| 22 |
|
| 23 |
# These globals are used by gcc_start if no compiler arguments are provided. |
| 24 |
# They are also used by the various testsuites to define the environment: |
| 25 |
# where to find stdio.h, libc.a, etc. |
| 26 |
|
| 27 |
# we want to use libgloss so we can get find_gcc. |
| 28 |
load_lib libgloss.exp |
| 29 |
load_lib prune.exp |
| 30 |
load_lib gcc-defs.exp |
| 31 |
load_lib timeout.exp |
| 32 |
|
| 33 |
# |
| 34 |
# GCC_UNDER_TEST is the compiler under test. |
| 35 |
# |
| 36 |
|
| 37 |
# |
| 38 |
# default_gcc_version -- extract and print the version number of the compiler |
| 39 |
# |
| 40 |
|
| 41 |
proc default_gcc_version { } { |
| 42 |
global GCC_UNDER_TEST |
| 43 |
|
| 44 |
gcc_init |
| 45 |
|
| 46 |
# ignore any arguments after the command |
| 47 |
set compiler [lindex $GCC_UNDER_TEST 0] |
| 48 |
|
| 49 |
if ![is_remote host] { |
| 50 |
set compiler_name [which $compiler] |
| 51 |
} else { |
| 52 |
set compiler_name $compiler |
| 53 |
} |
| 54 |
|
| 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 \[^\n\r\]*" $output version |
| 61 |
if { $status == 0 && [info exists version] } then { |
| 62 |
clone_output "$compiler_name $version\n" |
| 63 |
} else { |
| 64 |
clone_output "Couldn't determine version of $compiler_name: $output\n" |
| 65 |
} |
| 66 |
} else { |
| 67 |
# compiler does not exist (this should have already been detected) |
| 68 |
warning "$compiler does not exist" |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
# |
| 73 |
# gcc_version -- Call default_gcc_version, so we can override it if needed. |
| 74 |
# |
| 75 |
|
| 76 |
proc gcc_version { } { |
| 77 |
default_gcc_version |
| 78 |
} |
| 79 |
|
| 80 |
# |
| 81 |
# gcc_init -- called at the start of each .exp script. |
| 82 |
# |
| 83 |
# There currently isn't much to do, but always using it allows us to |
| 84 |
# make some enhancements without having to go back and rewrite the scripts. |
| 85 |
# |
| 86 |
|
| 87 |
set gcc_initialized 0 |
| 88 |
|
| 89 |
proc gcc_init { args } { |
| 90 |
global tmpdir |
| 91 |
global libdir |
| 92 |
global gluefile wrap_flags |
| 93 |
global gcc_initialized |
| 94 |
global GCC_UNDER_TEST |
| 95 |
global TOOL_EXECUTABLE |
| 96 |
global gcc_warning_prefix |
| 97 |
global gcc_error_prefix |
| 98 |
|
| 99 |
if { $gcc_initialized == 1 } { return; } |
| 100 |
|
| 101 |
if ![info exists GCC_UNDER_TEST] { |
| 102 |
if [info exists TOOL_EXECUTABLE] { |
| 103 |
set GCC_UNDER_TEST $TOOL_EXECUTABLE |
| 104 |
} else { |
| 105 |
set GCC_UNDER_TEST "[find_gcc]" |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
if ![info exists tmpdir] then { |
| 110 |
set tmpdir /tmp |
| 111 |
} |
| 112 |
|
| 113 |
set gcc_warning_prefix "warning:" |
| 114 |
set gcc_error_prefix "(fatal )?error:" |
| 115 |
|
| 116 |
gcc_maybe_build_wrapper "${tmpdir}/gcc-testglue.o" |
| 117 |
} |
| 118 |
|
| 119 |
# |
| 120 |
# gcc_target_compile -- compile a source file |
| 121 |
# |
| 122 |
|
| 123 |
proc gcc_target_compile { source dest type options } { |
| 124 |
global tmpdir |
| 125 |
global gluefile wrap_flags |
| 126 |
global GCC_UNDER_TEST |
| 127 |
global TOOL_OPTIONS |
| 128 |
global TEST_ALWAYS_FLAGS |
| 129 |
global flags_to_postpone |
| 130 |
global board_info |
| 131 |
|
| 132 |
global TEST_EXTRA_LIBS |
| 133 |
if [info exists TEST_EXTRA_LIBS] { |
| 134 |
lappend options "ldflags=$TEST_EXTRA_LIBS" |
| 135 |
} |
| 136 |
|
| 137 |
# TEST_ALWAYS_FLAGS are flags that should be passed to every |
| 138 |
# compilation. They are passed first to allow individual |
| 139 |
# tests to override them. |
| 140 |
if [info exists TEST_ALWAYS_FLAGS] { |
| 141 |
set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options] |
| 142 |
} |
| 143 |
|
| 144 |
# TOOL_OPTIONS must come first, so that it doesn't override testcase |
| 145 |
# specific options. |
| 146 |
if [info exists TOOL_OPTIONS] { |
| 147 |
set options [concat "{additional_flags=$TOOL_OPTIONS}" $options] |
| 148 |
} |
| 149 |
|
| 150 |
# bind_pic_locally adds -fpie/-fPIE flags to flags_to_postpone and it is |
| 151 |
# appended here to multilib_flags as it can be overridden by the latter |
| 152 |
# if it was added earlier. After the target_compile, multilib_flags is |
| 153 |
# restored to its orignal content. |
| 154 |
set tboard [target_info name] |
| 155 |
if {[board_info $tboard exists multilib_flags]} { |
| 156 |
set orig_multilib_flags "[board_info [target_info name] multilib_flags]" |
| 157 |
append board_info($tboard,multilib_flags) " $flags_to_postpone" |
| 158 |
} |
| 159 |
|
| 160 |
lappend options "timeout=[timeout_value]" |
| 161 |
lappend options "compiler=$GCC_UNDER_TEST" |
| 162 |
set options [dg-additional-files-options $options $source $dest $type] |
| 163 |
|
| 164 |
if {[target_info needs_status_wrapper] != "" && \ |
| 165 |
[target_info needs_status_wrapper] != "0" && \ |
| 166 |
[info exists gluefile] } { |
| 167 |
lappend options "libs=${gluefile}" |
| 168 |
lappend options "ldflags=$wrap_flags" |
| 169 |
if { $type == "executable" } { |
| 170 |
set options [concat "{additional_flags=-dumpbase \"\"}" $options] |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
set return_val [target_compile $source $dest $type $options] |
| 175 |
|
| 176 |
if {[board_info $tboard exists multilib_flags]} { |
| 177 |
set board_info($tboard,multilib_flags) $orig_multilib_flags |
| 178 |
set flags_to_postpone "" |
| 179 |
} |
| 180 |
|
| 181 |
return $return_val |
| 182 |
} |
| 183 |
|