1 # Copyright
(C
) 2020-2023 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
/>.
19 #
Return 1 if target can
compile a binary
for hardware address
20 # sanitization
, 0 otherwise.
22 # NOTE
: This should only be used between calls to hwasan_init and
23 # hwasan_finish. It is therefore defined here rather than in
24 # target
-supports.exp.
26 proc check_effective_target_fsanitize_hwaddress
{} {
27 if ![check_no_compiler_messages fsanitize_hwaddress executable
{
28 int main
(void
) { return 0; }
35 #
Return 1 if target can
compile and run a binary
for hardware address
36 # sanitization
, 0 otherwise.
38 # NOTE
: This should only be used between calls to hwasan_init and
39 # hwasan_finish. It is therefore defined here rather than in
40 # target
-supports.exp.
42 proc check_effective_target_hwaddress_exec
{} {
43 if ![check_runtime hwaddress_exec
{
47 extern
int prctl
(int, unsigned long
, unsigned long
, unsigned long
, unsigned long
);
52 #
define PR_SET_TAGGED_ADDR_CTRL
55
53 #
define PR_GET_TAGGED_ADDR_CTRL
56
54 #
define PR_TAGGED_ADDR_ENABLE
(1UL << 0)
55 if (prctl
(PR_GET_TAGGED_ADDR_CTRL
, 0, 0, 0, 0) == -1)
57 if (prctl
(PR_SET_TAGGED_ADDR_CTRL
, PR_TAGGED_ADDR_ENABLE
, 0, 0, 0) == -1
58 ||
!prctl
(PR_GET_TAGGED_ADDR_CTRL
, 0, 0, 0, 0))
68 proc hwasan_include_flags
{} {
70 global TESTING_IN_BUILD_TREE
74 if { [is_remote host
] ||
! [info exists TESTING_IN_BUILD_TREE
] } {
78 set flags
"-I$srcdir/../../libsanitizer/include"
84 # hwasan_link_flags
-- compute library path and flags to find libhwasan.
85 #
(implementation in asan
-dg.exp
)
88 proc hwasan_link_flags
{ paths
} {
89 return [asan_link_flags_1 $paths hwasan
]
93 # hwasan_init
-- called at the start of each subdir of tests
96 proc hwasan_init
{ args } {
97 global TEST_ALWAYS_FLAGS
98 global ALWAYS_CXXFLAGS
100 global hwasan_saved_TEST_ALWAYS_FLAGS
101 global hwasan_saved_ALWAYS_CXXFLAGS
103 setenv HWASAN_OPTIONS
"random_tags=0"
106 if ![is_remote host
] {
107 if [info exists TOOL_OPTIONS
] {
108 set link_flags
"[hwasan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
110 set link_flags
"[hwasan_link_flags [get_multilibs]]"
114 set include_flags
"[hwasan_include_flags]"
116 if [info exists TEST_ALWAYS_FLAGS
] {
117 set hwasan_saved_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
119 if [info exists ALWAYS_CXXFLAGS
] {
120 set hwasan_saved_ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS
121 set ALWAYS_CXXFLAGS
[concat
"{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
122 set ALWAYS_CXXFLAGS
[concat
"{additional_flags=-fsanitize=hwaddress --param hwasan-random-frame-tag=0 -g $include_flags}" $ALWAYS_CXXFLAGS]
124 if [info exists TEST_ALWAYS_FLAGS
] {
125 set TEST_ALWAYS_FLAGS
"$link_flags -fsanitize=hwaddress --param hwasan-random-frame-tag=0 -g $include_flags $TEST_ALWAYS_FLAGS"
127 set TEST_ALWAYS_FLAGS
"$link_flags -fsanitize=hwaddress --param hwasan-random-frame-tag=0 -g $include_flags"
133 # hwasan_finish
-- called at the start of each subdir of tests
136 proc hwasan_finish
{ args } {
137 global TEST_ALWAYS_FLAGS
138 global hwasan_saved_TEST_ALWAYS_FLAGS
139 global hwasan_saved_ALWAYS_CXXFLAGS
140 global hwasan_saved_library_path
141 global ld_library_path
143 unsetenv HWASAN_OPTIONS
145 if [info exists hwasan_saved_ALWAYS_CXXFLAGS
] {
146 set ALWAYS_CXXFLAGS $hwasan_saved_ALWAYS_CXXFLAGS
148 if [info exists hwasan_saved_TEST_ALWAYS_FLAGS
] {
149 set TEST_ALWAYS_FLAGS $hwasan_saved_TEST_ALWAYS_FLAGS
151 unset TEST_ALWAYS_FLAGS
154 if [info exists hwasan_saved_library_path
] {
155 set ld_library_path $hwasan_saved_library_path
156 set_ld_library_path_env_vars
158 clear_effective_target_cache
161 # Utility
for running gtest hwasan emulation under dejagnu
, invoked via dg
-final.
162 #
Call pass
if variable has the desired value
, otherwise fail.
164 #
Argument 0 handles expected failures and the like
165 proc hwasan
-gtest
{ args } {