blob: 81934bb2961c861e67713a93478e6cc229147141 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# Copyright (C) 2013-2015 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
# Return 1 if compilation with -fsanitize=undefined is error-free for trivial
# code, 0 otherwise.
proc check_effective_target_fsanitize_undefined {} {
return [check_runtime fsanitize_undefined {
int main (void) { return 0; }
} "-fsanitize=undefined"]
}
#
# ubsan_link_flags -- compute library path and flags to find libubsan.
# (originally from g++.exp)
#
proc ubsan_link_flags { paths } {
global srcdir
global ld_library_path
global shlib_ext
global ubsan_saved_library_path
set gccpath ${paths}
set flags ""
set shlib_ext [get_shlib_extension]
set ubsan_saved_library_path $ld_library_path
if { $gccpath != "" } {
if { [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.a"]
|| [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.${shlib_ext}"] } {
append flags " -B${gccpath}/libsanitizer/ "
append flags " -B${gccpath}/libsanitizer/ubsan/ "
append flags " -L${gccpath}/libsanitizer/ubsan/.libs"
append ld_library_path ":${gccpath}/libsanitizer/ubsan/.libs"
append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
}
} else {
global tool_root_dir
set libubsan [lookfor_file ${tool_root_dir} libubsan]
if { $libubsan != "" } {
append flags "-L${libubsan} "
append ld_library_path ":${libubsan}"
}
}
set_ld_library_path_env_vars
return "$flags"
}
#
# ubsan_init -- called at the start of each subdir of tests
#
proc ubsan_init { args } {
global TEST_ALWAYS_FLAGS
global ALWAYS_CXXFLAGS
global TOOL_OPTIONS
global ubsan_saved_TEST_ALWAYS_FLAGS
global ubsan_saved_ALWAYS_CXXFLAGS
set link_flags ""
if ![is_remote host] {
if [info exists TOOL_OPTIONS] {
set link_flags "[ubsan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
} else {
set link_flags "[ubsan_link_flags [get_multilibs]]"
}
}
if [info exists TEST_ALWAYS_FLAGS] {
set ubsan_saved_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
}
if [info exists ALWAYS_CXXFLAGS] {
set ubsan_saved_ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS
set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
} else {
if [info exists TEST_ALWAYS_FLAGS] {
set TEST_ALWAYS_FLAGS "$link_flags $TEST_ALWAYS_FLAGS"
} else {
set TEST_ALWAYS_FLAGS "$link_flags"
}
}
}
#
# ubsan_finish -- called at the end of each subdir of tests
#
proc ubsan_finish { args } {
global TEST_ALWAYS_FLAGS
global ubsan_saved_TEST_ALWAYS_FLAGS
global ubsan_saved_ALWAYS_CXXFLAGS
global ubsan_saved_library_path
global ld_library_path
if [info exists ubsan_saved_ALWAYS_CXXFLAGS ] {
set ALWAYS_CXXFLAGS $ubsan_saved_ALWAYS_CXXFLAGS
} else {
if [info exists ubsan_saved_TEST_ALWAYS_FLAGS] {
set TEST_ALWAYS_FLAGS $ubsan_saved_TEST_ALWAYS_FLAGS
} else {
unset TEST_ALWAYS_FLAGS
}
}
set ld_library_path $ubsan_saved_library_path
set_ld_library_path_env_vars
}
|