diff options
author | Tamar Christina <tamar.christina@arm.com> | 2024-01-31 14:50:33 +0000 |
---|---|---|
committer | Tamar Christina <tamar.christina@arm.com> | 2024-01-31 14:50:33 +0000 |
commit | 0debaceb11dee9781f9a8b320cb5893836324878 (patch) | |
tree | 473946a50f47d8599e20f909c5482d5129d627a6 /gcc/asan.h | |
parent | a73421bcf301911f2cbdb1c58316ddf3473ea6d5 (diff) | |
download | gcc-0debaceb11dee9781f9a8b320cb5893836324878.zip gcc-0debaceb11dee9781f9a8b320cb5893836324878.tar.gz gcc-0debaceb11dee9781f9a8b320cb5893836324878.tar.bz2 |
hwasan: instrument new memory and string functions [PR112644]
Recent libhwasan updates[1] intercept various string and memory functions.
These functions have checking in them, which means there's no need to
inline the checking.
This patch marks said functions as intercepted, and adjusts a testcase
to handle the difference. It also looks for HWASAN in a check in
expand_builtin. This check originally is there to avoid using expand to
inline the behaviour of builtins like memset which are intercepted by
ASAN and hence which we rely on the function call staying as a function
call. With the new reliance on function calls in HWASAN we need to do
the same thing for HWASAN too.
HWASAN and ASAN don't seem to however instrument the same functions.
Looking into libsanitizer/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
it looks like the common ones are memset, memmove and memcpy.
The rest of the routines for asan seem to be defined in
compiler-rt/lib/asan/asan_interceptors.h however compiler-rt/lib/hwasan/
does not have such a file but it does have
compiler-rt/lib/hwasan/hwasan_platform_interceptors.h which it looks like is
forcing off everything but memset, memmove, memcpy, memcmp and bcmp.
As such I've taken those as the final list that hwasan currently supports.
This also means that on future updates this list should be cross checked.
[1] https://discourse.llvm.org/t/hwasan-question-about-the-recent-interceptors-being-added/75351
gcc/ChangeLog:
PR sanitizer/112644
* asan.h (asan_intercepted_p): Incercept memset, memmove, memcpy and
memcmp.
* builtins.cc (expand_builtin): Include HWASAN when checking for
builtin inlining.
gcc/testsuite/ChangeLog:
PR sanitizer/112644
* c-c++-common/hwasan/builtin-special-handling.c: Update testcase.
Co-Authored-By: Matthew Malcomson <matthew.malcomson@arm.com>
Diffstat (limited to 'gcc/asan.h')
-rw-r--r-- | gcc/asan.h | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -185,8 +185,13 @@ extern hash_set<tree> *asan_handled_variables; inline bool asan_intercepted_p (enum built_in_function fcode) { + /* This list should be kept up-to-date with upstream's version at + compiler-rt/lib/hwasan/hwasan_platform_interceptors.h. */ if (hwasan_sanitize_p ()) - return false; + return fcode == BUILT_IN_MEMCMP + || fcode == BUILT_IN_MEMCPY + || fcode == BUILT_IN_MEMMOVE + || fcode == BUILT_IN_MEMSET; return fcode == BUILT_IN_INDEX || fcode == BUILT_IN_MEMCHR |