1 # Copyright
(C
) 2001-2013 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
3 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; see the file COPYING3.
If not see
15 #
<http
://www.gnu.org
/licenses
/>.
17 #
Define libmudflap callbacks
for dg.exp.
18 # This file is a copy of libstdc
++-v3
's dejagnu driver, with minor changes.
20 # Useful hook: if ${hostname}_init exists, it will be called, almost
21 # the last thing before testing begins. This can be defined in, e.g.,
22 # ~/.dejagnurc or $DEJAGNU.
24 proc load_gcc_lib { filename } {
26 load_file $srcdir/../../gcc/testsuite/lib/$filename
31 load_gcc_lib target-libpath.exp
32 load_gcc_lib target-supports.exp
33 load_gcc_lib timeout.exp
34 load_gcc_lib timeout-dg.exp
36 proc libmudflap-init { language } {
38 global srcdir outdir blddir objdir tool_root_dir
42 global gluefile wrap_flags
43 global ld_library_path
49 if [info exists CC_UNDER_TEST] then {
50 set cxx $CC_UNDER_TEST
55 if [info exists CXX_UNDER_TEST] then {
56 set cxx $CXX_UNDER_TEST
61 default { error "bad language code $language"; return }
64 verbose -log "libmudflap-init $cxx"
66 set blddir [lookfor_file [get_multilibs] libmudflap]
67 set cxxblddir [lookfor_file [get_multilibs] libstdc++-v3]
68 set cxxflags_file "${cxxblddir}/scripts/testsuite_flags"
70 # By default, we assume we want to run program images.
71 global dg-do-what-default
72 set dg-do-what-default run
74 # set LD_LIBRARY_PATH so that libgcc_s, libstdc++ binaries can be found.
75 # locate libgcc.a so we don't need to account
for different
values of
76 # SHLIB_EXT
on different platforms
77 set gccdir
[lookfor_file $tool_root_dir gcc
/libgcc.a
]
79 set gccdir
[file dirname $gccdir
]
82 set ld_library_path
"."
83 append ld_library_path
":${gccdir}"
84 append ld_library_path
":${cxxblddir}/src/.libs"
85 if {[is_remote host
] == 0} {
86 foreach i
"[exec ${gccdir}/xgcc --print-multi-lib]" {
88 regexp
-- "\[a-z0-9=_/\.-\]*;" $i mldir
89 set mldir
[string trimright $mldir
"\;@"]
90 if { "$mldir" == "." } {
93 if { [llength
[glob
-nocomplain $
{gccdir
}/$
{mldir
}/libgcc_s
*.so.
*]] >= 1 } {
94 append ld_library_path
":${gccdir}/${mldir}"
98 append ld_library_path
":${blddir}/.libs"
100 set libs
"-L${blddir}/.libs"
101 set cxxflags
"-ggdb3 -DDEBUG_ASSERT -fdiagnostics-color=never"
102 set includes
"-I${srcdir} -I${srcdir}/.. -I.."
104 if {$language
== "c++"} {
105 if {[file
exists $cxxflags_file
]} then {
106 set includes
"${includes} [exec sh $cxxflags_file --build-includes]"
107 set cxxflags
"${cxxflags} [exec sh $cxxflags_file --cxxflags]"
108 # c
++ libs are included by
--build
-cxx below
109 set cxx
"[exec sh $cxxflags_file --build-cxx]"
111 lappend libs
"-L${cxxblddir}src/.libs"
112 lappend includes
"-I../../libstdc++-v3/include"
118 append add_flags
" $mfconfig_libs"
120 set_ld_library_path_env_vars
121 if [info exists env
(LD_LIBRARY_PATH
)] {
122 verbose
-log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
125 if { [target_info needs_status_wrapper
]!=""} {
126 file
delete $
{objdir
}/testglue.o
;
127 set gluefile $
{objdir
}/testglue.o
;
128 set result
[build_wrapper $gluefile
];
129 if { $result
!= "" } {
130 set gluefile
[lindex $result
0];
131 set wrap_flags
[lindex $result
1];
137 #
If there is no static library
then don
't run tests with -static.
140 set opts "additional_flags=-static"
141 lappend opts "additional_flags=-fmudflap"
142 lappend opts "additional_flags=-lmudflap"
143 lappend opts "libs=$mfconfig_libs"
147 set f [open $src "w"]
148 puts $f "int main () { }"
150 set lines [${tool}_target_compile $src $exe executable "$opts"]
152 remote_file build delete $exe
154 if { ![string match "" $lines] } {
155 # Compilation failed; assume static library is not available.
157 set i [lsearch $MUDFLAP_FLAGS "*static*"]
158 set MUDFLAP_FLAGS [lreplace $MUDFLAP_FLAGS $i $i]
162 proc libmudflap-dg-test { prog do_what extra_tool_flags } {
163 # Set up the compiler flags, based on what we're going to
do.
167 set compile_type
"preprocess"
168 set output_file
"[file rootname [file tail $prog]].i"
171 set compile_type
"assembly"
172 set output_file
"[file rootname [file tail $prog]].s"
175 set compile_type
"object"
176 set output_file
"[file rootname [file tail $prog]].o"
179 set compile_type
"executable"
180 set output_file
"./[file rootname [file tail $prog]].exe"
183 set compile_type
"executable"
184 # FIXME
: "./" is to cope with "." not being in $PATH.
185 # Should this be handled elsewhere?
187 set output_file
"./[file rootname [file tail $prog]].exe"
188 # This is the only place where we care
if an executable was
189 # created or not.
If it was
, dg.exp will try to run it.
190 remote_file build
delete $output_file
;
193 perror
"$do_what: not a valid dg-do keyword"
198 if { $extra_tool_flags
!= "" } {
199 lappend options
"additional_flags=$extra_tool_flags"
203 lappend options
"libs=$mfconfig_libs"
205 set comp_output
[libmudflap_target_compile
"$prog" "$output_file" "$compile_type" $options];
207 return [list $comp_output $output_file
]
211 proc libmudflap_target_compile
{ source dest type options
} {
220 if { [target_info needs_status_wrapper
] != "" && [info exists gluefile] } {
221 lappend options
"libs=${gluefile}"
222 lappend options
"ldflags=${wrap_flags}"
226 set cxxlibglossflags
[libgloss_link_flags
]
227 set cxx_final
[concat $cxx_final $cxxlibglossflags
]
228 set cxx_final
[concat $cxx_final $cxxflags
]
229 set cxx_final
[concat $cxx_final $includes
]
230 set cxx_final
[concat $cxx_final $libs
]
232 lappend options
"compiler=$cxx_final"
233 lappend options
"timeout=[timeout_value]"
235 # Picks up the freshly
-built testsuite library corresponding to the
236 # multilib under test.
237 lappend options
"ldflags=-L${blddir}/testsuite"
239 return [target_compile $source $dest $type $options
]
243 # A bit sloppy... Returns a list of source files
(full pathnames
) to
244 #
compile. We mimic the mkcheck script in that the first time this is run
,
245 # all existing files are listed in
"testsuite_files" in the output
246 # directory. Subsequent runs pull the list from that file
, allowing users
247 # to trim the list down to problematic tests.
248 ### This is supposed to be done via RUNTESTFLAGS
, but that doesn
't work.
249 proc libmudflap-list-sourcefiles { } {
253 set files_file "${outdir}/testsuite_files"
255 if { [file exists $files_file] } {
256 set f [open $files_file]
257 while { ! [eof $f] } {
259 if { [string length "$t"] != 0 } {
260 lappend sfiles ${srcdir}/${t}
264 set f [open $files_file "w"]
265 set where_we_were [pwd]
267 foreach s [lsort [glob -nocomplain "*/*.cc" "*/*/*.cc" "{,*/}*/*/*/*.cc" ]] {
268 lappend sfiles ${srcdir}/${s}
275 # Disable wchar_t tests if library not configured to support
277 set wchar_file "${outdir}/testsuite_wchar_t"
278 if { [file exists $wchar_file] } {
281 # Remove wchar_t tests files from list.
284 if [regexp "wchar_t" $w] {
285 verbose -log "element out list is $w"
287 verbose -log "element in list is $w"
296 proc libmudflap-dg-prune { system text } {
297 global additional_prunes
299 set text [prune_gcc_output $text]
301 foreach p $additional_prunes {
302 if { [string length $p] > 0 } {
303 # Following regexp matches a complete line containing $p.
304 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
312 proc prune_gcc_output { text } {
313 # Ignore caret diagnostics. Unfortunately dejaGNU trims leading
314 # spaces, so one cannot rely on them being present.
315 regsub -all "(^|\n)\[^\n\]+\n *\\^\n" $text "\n" text
316 regsub -all {(^|\n)[^\n]*ld: warning: libgcc_s[^\n]*not found[^\n]*try using[^\n]*} $text "" text
317 regsub -all {(^|\n)[^\n]*In function.*pthread_create[^\n]*} $text "" text
318 regsub -all {(^|\n)[^\n]*the use of .pthread.*is deprecated[^\n]*} $text "" text
319 regsub -all {(^|\n)[^\n]*Dwarf Error:.*FORM value: 14[^\n]*} $text "" text
320 regsub -all {(^|\n)[^\n]*In function[^\n]*} $text "" text
321 regsub -all {(^|\n)[^\n]*Using.*in statically linked applications requires[^\n]*} $text "" text