]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/lib/tsan-dg.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / tsan-dg.exp
CommitLineData
99dee823 1# Copyright (C) 2013-2021 Free Software Foundation, Inc.
85826504
MO
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# Return 1 if compilation with -fsanitize=thread is error-free for trivial
ccc71ab8
UB
18# code, 0 otherwise. Also set what to do by default here, depending on the
19# result of a runtime test.
85826504 20
9fbbb20d 21proc check_effective_target_fsanitize_thread {} {
ccc71ab8
UB
22 global individual_timeout
23 global dg-do-what-default
24
25 if ![check_no_compiler_messages fsanitize_thread executable {
9fbbb20d 26 int main (void) { return 0; }
ccc71ab8
UB
27 }] {
28 return 0
29 }
30
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; }
35 }] {
36 set dg-do-what-default run
37 } else {
38 set dg-do-what-default link
39 }
40 unset individual_timeout
41
42 return 1
85826504
MO
43}
44
45#
46# tsan_link_flags -- compute library path and flags to find libtsan.
47# (originally from g++.exp)
48#
49
50proc tsan_link_flags { paths } {
51 global srcdir
52 global ld_library_path
53 global shlib_ext
06a04ce7 54 global tsan_saved_library_path
85826504
MO
55
56 set gccpath ${paths}
57 set flags ""
58
59 set shlib_ext [get_shlib_extension]
06a04ce7 60 set tsan_saved_library_path $ld_library_path
85826504
MO
61
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"
68 }
69 } else {
70 global tool_root_dir
71
72 set libtsan [lookfor_file ${tool_root_dir} libtsan]
73 if { $libtsan != "" } {
74 append flags "-L${libtsan} "
75 append ld_library_path ":${libtsan}"
76 }
77 }
78
79 set_ld_library_path_env_vars
80
81 return "$flags"
82}
83
84#
85# tsan_init -- called at the start of each subdir of tests
86#
87
88proc tsan_init { args } {
89 global TEST_ALWAYS_FLAGS
90 global ALWAYS_CXXFLAGS
91 global TOOL_OPTIONS
92 global tsan_saved_TEST_ALWAYS_FLAGS
9fbbb20d 93 global tsan_saved_ALWAYS_CXXFLAGS
eecd8b7c
JJ
94 global dg-do-what-default
95 global tsan_saved_dg-do-what-default
85826504
MO
96
97 set link_flags ""
98 if ![is_remote host] {
99 if [info exists TOOL_OPTIONS] {
100 set link_flags "[tsan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
101 } else {
102 set link_flags "[tsan_link_flags [get_multilibs]]"
103 }
104 }
105
eecd8b7c
JJ
106 if [info exists dg-do-what-default] {
107 set tsan_saved_dg-do-what-default ${dg-do-what-default}
108 }
85826504
MO
109 if [info exists TEST_ALWAYS_FLAGS] {
110 set tsan_saved_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
111 }
112 if [info exists ALWAYS_CXXFLAGS] {
9fbbb20d 113 set tsan_saved_ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS
85826504 114 set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
4bb0ca2d 115 set ALWAYS_CXXFLAGS [concat "{additional_flags=-fsanitize=thread -g}" $ALWAYS_CXXFLAGS]
85826504
MO
116 } else {
117 if [info exists TEST_ALWAYS_FLAGS] {
4bb0ca2d 118 set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=thread -g $TEST_ALWAYS_FLAGS"
85826504 119 } else {
4bb0ca2d 120 set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=thread -g"
85826504
MO
121 }
122 }
85826504
MO
123}
124
125#
f8e162b7 126# tsan_finish -- called at the end of each subdir of tests
85826504
MO
127#
128
129proc tsan_finish { args } {
130 global TEST_ALWAYS_FLAGS
131 global tsan_saved_TEST_ALWAYS_FLAGS
9fbbb20d 132 global tsan_saved_ALWAYS_CXXFLAGS
eecd8b7c
JJ
133 global dg-do-what-default
134 global tsan_saved_dg-do-what-default
06a04ce7
MO
135 global tsan_saved_library_path
136 global ld_library_path
85826504 137
9fbbb20d
AP
138 if [info exists tsan_saved_ALWAYS_CXXFLAGS ] {
139 set ALWAYS_CXXFLAGS $tsan_saved_ALWAYS_CXXFLAGS
85826504 140 } else {
9fbbb20d
AP
141 if [info exists tsan_saved_TEST_ALWAYS_FLAGS] {
142 set TEST_ALWAYS_FLAGS $tsan_saved_TEST_ALWAYS_FLAGS
143 } else {
144 unset TEST_ALWAYS_FLAGS
145 }
85826504 146 }
9fbbb20d 147
eecd8b7c
JJ
148 if [info exists tsan_saved_dg-do-what-default] {
149 set dg-do-what-default ${tsan_saved_dg-do-what-default}
150 } else {
151 unset dg-do-what-default
152 }
24d762d1
TB
153 if [info exists tsan_saved_library_path ] {
154 set ld_library_path $tsan_saved_library_path
155 set_ld_library_path_env_vars
156 }
dfda198c 157 clear_effective_target_cache
85826504 158}