]>
Commit | Line | Data |
---|---|---|
a945c346 | 1 | # Copyright (C) 2013-2024 Free Software Foundation, Inc. |
de5a5fa1 MP |
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 | ||
9fbbb20d AP |
17 | # Return 1 if compilation with -fsanitize=undefined is error-free for trivial |
18 | # code, 0 otherwise. | |
19 | ||
2b11374c KC |
20 | set orig_ubsan_options_saved 0 |
21 | set orig_ubsan_options 0 | |
22 | ||
9fbbb20d | 23 | proc check_effective_target_fsanitize_undefined {} { |
2e4aa0a5 | 24 | return [check_runtime fsanitize_undefined { |
9fbbb20d AP |
25 | int main (void) { return 0; } |
26 | } "-fsanitize=undefined"] | |
27 | } | |
28 | ||
de5a5fa1 MP |
29 | # |
30 | # ubsan_link_flags -- compute library path and flags to find libubsan. | |
31 | # (originally from g++.exp) | |
32 | # | |
33 | ||
34 | proc ubsan_link_flags { paths } { | |
35 | global srcdir | |
36 | global ld_library_path | |
37 | global shlib_ext | |
06a04ce7 | 38 | global ubsan_saved_library_path |
de5a5fa1 MP |
39 | |
40 | set gccpath ${paths} | |
41 | set flags "" | |
42 | ||
43 | set shlib_ext [get_shlib_extension] | |
06a04ce7 | 44 | set ubsan_saved_library_path $ld_library_path |
de5a5fa1 MP |
45 | |
46 | if { $gccpath != "" } { | |
47 | if { [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.a"] | |
48 | || [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.${shlib_ext}"] } { | |
cc41e336 YG |
49 | append flags " -B${gccpath}/libsanitizer/ " |
50 | append flags " -B${gccpath}/libsanitizer/ubsan/ " | |
de5a5fa1 MP |
51 | append flags " -L${gccpath}/libsanitizer/ubsan/.libs" |
52 | append ld_library_path ":${gccpath}/libsanitizer/ubsan/.libs" | |
5341599a | 53 | append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs" |
de5a5fa1 MP |
54 | } |
55 | } else { | |
56 | global tool_root_dir | |
57 | ||
58 | set libubsan [lookfor_file ${tool_root_dir} libubsan] | |
59 | if { $libubsan != "" } { | |
60 | append flags "-L${libubsan} " | |
61 | append ld_library_path ":${libubsan}" | |
62 | } | |
63 | } | |
64 | ||
65 | set_ld_library_path_env_vars | |
66 | ||
67 | return "$flags" | |
68 | } | |
69 | ||
70 | # | |
71 | # ubsan_init -- called at the start of each subdir of tests | |
72 | # | |
73 | ||
74 | proc ubsan_init { args } { | |
75 | global TEST_ALWAYS_FLAGS | |
76 | global ALWAYS_CXXFLAGS | |
77 | global TOOL_OPTIONS | |
78 | global ubsan_saved_TEST_ALWAYS_FLAGS | |
9fbbb20d | 79 | global ubsan_saved_ALWAYS_CXXFLAGS |
2b11374c KC |
80 | global orig_ubsan_options_saved |
81 | global orig_ubsan_options | |
82 | ||
83 | if { $orig_ubsan_options_saved == 0 } { | |
84 | # Save the original environment. | |
85 | if [info exists env(UBSAN_OPTIONS)] { | |
86 | set orig_ubsan_options "$env(UBSAN_OPTIONS)" | |
87 | set orig_ubsan_options_saved 1 | |
88 | } | |
89 | } | |
90 | setenv UBSAN_OPTIONS color=never | |
de5a5fa1 MP |
91 | |
92 | set link_flags "" | |
93 | if ![is_remote host] { | |
94 | if [info exists TOOL_OPTIONS] { | |
95 | set link_flags "[ubsan_link_flags [get_multilibs ${TOOL_OPTIONS}]]" | |
96 | } else { | |
97 | set link_flags "[ubsan_link_flags [get_multilibs]]" | |
98 | } | |
99 | } | |
100 | ||
101 | if [info exists TEST_ALWAYS_FLAGS] { | |
102 | set ubsan_saved_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS | |
103 | } | |
104 | if [info exists ALWAYS_CXXFLAGS] { | |
9fbbb20d | 105 | set ubsan_saved_ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS |
de5a5fa1 MP |
106 | set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS] |
107 | } else { | |
108 | if [info exists TEST_ALWAYS_FLAGS] { | |
109 | set TEST_ALWAYS_FLAGS "$link_flags $TEST_ALWAYS_FLAGS" | |
110 | } else { | |
111 | set TEST_ALWAYS_FLAGS "$link_flags" | |
112 | } | |
113 | } | |
de5a5fa1 MP |
114 | } |
115 | ||
116 | # | |
117 | # ubsan_finish -- called at the end of each subdir of tests | |
118 | # | |
119 | ||
120 | proc ubsan_finish { args } { | |
121 | global TEST_ALWAYS_FLAGS | |
122 | global ubsan_saved_TEST_ALWAYS_FLAGS | |
9fbbb20d | 123 | global ubsan_saved_ALWAYS_CXXFLAGS |
06a04ce7 MO |
124 | global ubsan_saved_library_path |
125 | global ld_library_path | |
2b11374c KC |
126 | global orig_ubsan_options_saved |
127 | global orig_ubsan_options | |
128 | ||
129 | if { $orig_ubsan_options_saved } { | |
130 | setenv UBSAN_OPTIONS "$orig_ubsan_options" | |
131 | } elseif [info exists env(UBSAN_OPTIONS)] { | |
132 | unsetenv UBSAN_OPTIONS | |
133 | } | |
de5a5fa1 | 134 | |
9fbbb20d AP |
135 | if [info exists ubsan_saved_ALWAYS_CXXFLAGS ] { |
136 | set ALWAYS_CXXFLAGS $ubsan_saved_ALWAYS_CXXFLAGS | |
de5a5fa1 | 137 | } else { |
9fbbb20d AP |
138 | if [info exists ubsan_saved_TEST_ALWAYS_FLAGS] { |
139 | set TEST_ALWAYS_FLAGS $ubsan_saved_TEST_ALWAYS_FLAGS | |
140 | } else { | |
141 | unset TEST_ALWAYS_FLAGS | |
142 | } | |
de5a5fa1 | 143 | } |
24d762d1 TB |
144 | if [info exists ubsan_saved_library_path ] { |
145 | set ld_library_path $ubsan_saved_library_path | |
146 | set_ld_library_path_env_vars | |
147 | } | |
dfda198c | 148 | clear_effective_target_cache |
de5a5fa1 | 149 | } |