1 # Copyright
(C
) 2013-2016 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 GCC
; see the file COPYING3.
If not see
15 #
<http
://www.gnu.org
/licenses
/>.
17 #
Return 1 if compilation with
-fsanitize
=thread is error
-free
for trivial
18 # code
, 0 otherwise. Also
set what to
do by default here
, depending
on the
19 # result of a runtime test.
21 proc check_effective_target_fsanitize_thread
{} {
22 global individual_timeout
23 global dg
-do-what
-default
25 if ![check_no_compiler_messages fsanitize_thread executable
{
26 int main
(void
) { return 0; }
31 # Lower timeout value in case test does not terminate properly.
32 set individual_timeout
20
33 if [check_runtime_nocache tsan_works
{
34 int main
() { return 0; }
36 set dg
-do-what
-default run
38 set dg
-do-what
-default link
40 unset individual_timeout
46 # tsan_link_flags
-- compute library path and flags to find libtsan.
47 #
(originally from g
++.exp
)
50 proc tsan_link_flags
{ paths
} {
52 global ld_library_path
54 global tsan_saved_library_path
59 set shlib_ext
[get_shlib_extension
]
60 set tsan_saved_library_path $ld_library_path
62 if { $gccpath
!= "" } {
63 if { [file
exists "${gccpath}/libsanitizer/tsan/.libs/libtsan.a"]
64 ||
[file
exists "${gccpath}/libsanitizer/tsan/.libs/libtsan.${shlib_ext}"] } {
65 append flags
" -B${gccpath}/libsanitizer/tsan/ "
66 append flags
" -L${gccpath}/libsanitizer/tsan/.libs "
67 append ld_library_path
":${gccpath}/libsanitizer/tsan/.libs"
72 set libtsan
[lookfor_file $
{tool_root_dir
} libtsan
]
73 if { $libtsan
!= "" } {
74 append flags
"-L${libtsan} "
75 append ld_library_path
":${libtsan}"
79 set_ld_library_path_env_vars
85 # tsan_init
-- called at the start of each subdir of tests
88 proc tsan_init
{ args } {
89 global TEST_ALWAYS_FLAGS
90 global ALWAYS_CXXFLAGS
92 global tsan_saved_TEST_ALWAYS_FLAGS
93 global tsan_saved_ALWAYS_CXXFLAGS
94 global dg
-do-what
-default
95 global tsan_saved_dg
-do-what
-default
98 if ![is_remote host
] {
99 if [info exists TOOL_OPTIONS
] {
100 set link_flags
"[tsan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
102 set link_flags
"[tsan_link_flags [get_multilibs]]"
106 if [info exists dg
-do-what
-default
] {
107 set tsan_saved_dg
-do-what
-default $
{dg
-do-what
-default
}
109 if [info exists TEST_ALWAYS_FLAGS
] {
110 set tsan_saved_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
112 if [info exists ALWAYS_CXXFLAGS
] {
113 set tsan_saved_ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS
114 set ALWAYS_CXXFLAGS
[concat
"{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
115 set ALWAYS_CXXFLAGS
[concat
"{additional_flags=-fsanitize=thread -g}" $ALWAYS_CXXFLAGS]
117 if [info exists TEST_ALWAYS_FLAGS
] {
118 set TEST_ALWAYS_FLAGS
"$link_flags -fsanitize=thread -g $TEST_ALWAYS_FLAGS"
120 set TEST_ALWAYS_FLAGS
"$link_flags -fsanitize=thread -g"
126 # tsan_finish
-- called at the end of each subdir of tests
129 proc tsan_finish
{ args } {
130 global TEST_ALWAYS_FLAGS
131 global tsan_saved_TEST_ALWAYS_FLAGS
132 global tsan_saved_ALWAYS_CXXFLAGS
133 global dg
-do-what
-default
134 global tsan_saved_dg
-do-what
-default
135 global tsan_saved_library_path
136 global ld_library_path
138 if [info exists tsan_saved_ALWAYS_CXXFLAGS
] {
139 set ALWAYS_CXXFLAGS $tsan_saved_ALWAYS_CXXFLAGS
141 if [info exists tsan_saved_TEST_ALWAYS_FLAGS
] {
142 set TEST_ALWAYS_FLAGS $tsan_saved_TEST_ALWAYS_FLAGS
144 unset TEST_ALWAYS_FLAGS
148 if [info exists tsan_saved_dg
-do-what
-default
] {
149 set dg
-do-what
-default $
{tsan_saved_dg
-do-what
-default
}
151 unset dg
-do-what
-default
153 set ld_library_path $tsan_saved_library_path
154 set_ld_library_path_env_vars
155 clear_effective_target_cache