-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ASan] Update meminstrinsics to use library memmove rather than internal #160740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ASan] Update meminstrinsics to use library memmove rather than internal #160740
Conversation
Currently memcpy and memset intrinsics map through to the library implementations if ASan has been inited, whereas memmove always calls internal_memmove. This patch changes memmove to use the library implementation if ASan has been inited.
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Dan Blackwell (DanBlackwell) ChangesCurrently This patch changes Full diff: https://github.com/llvm/llvm-project/pull/160740.diff 2 Files Affected:
diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
index bdf328f892063..f52ae9ae8d17c 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
@@ -55,8 +55,10 @@ using namespace __asan;
if (LIKELY(replace_intrin_cached)) { \
ASAN_READ_RANGE(ctx, from, size); \
ASAN_WRITE_RANGE(ctx, to, size); \
+ } else if (UNLIKELY(!AsanInited())) { \
+ return internal_memmove(to, from, size); \
} \
- return internal_memmove(to, from, size); \
+ return REAL(memmove)(to, from, size); \
} while (0)
void *__asan_memcpy(void *to, const void *from, uptr size) {
diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h
index 14727a5d665ed..ec988cff51c59 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h
@@ -20,6 +20,7 @@
DECLARE_REAL(void *, memcpy, void *to, const void *from, SIZE_T size)
DECLARE_REAL(void *, memset, void *block, int c, SIZE_T size)
+DECLARE_REAL(void *, memmove, void *to, const void *from, SIZE_T size)
namespace __asan {
|
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions h,cpp -- compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp compiler-rt/lib/asan/asan_interceptors_memintrinsics.h
View the diff from clang-format here.diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h
index ec988cff5..11e77e5ce 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.h
@@ -20,7 +20,7 @@
DECLARE_REAL(void *, memcpy, void *to, const void *from, SIZE_T size)
DECLARE_REAL(void *, memset, void *block, int c, SIZE_T size)
-DECLARE_REAL(void *, memmove, void *to, const void *from, SIZE_T size)
+DECLARE_REAL(void*, memmove, void* to, const void* from, SIZE_T size)
namespace __asan {
|
LGTM - do we need tests for this so it doesn't regress? |
I can't see any tests for the memintrinsics stuff; do you think there's anything that we could be testing here @melver? |
I thought we should at least have tests they behave as expected when instrumented. But if they don't exist yet, perhaps nothing to do. |
Oh, looks like
@melver what's your opinion on changing this test name to
I came across this while looking at some profiling data (I was surprised to see a bunch of samples with |
That looks reasonable, although up to you - it's just a cosmetic change, but maybe will help to find its existence quicker in future.
Thanks for clarifying. |
Ok, I won't rename the test for now - will merge as is. Thanks for the review! |
…nal (llvm#160740) Currently `memcpy` and `memset` intrinsics map through to the library implementations if ASan has been inited, whereas `memmove` always calls `internal_memmove`. This patch changes `memmove` to use the library implementation if ASan has been inited.
Currently
memcpy
andmemset
intrinsics map through to the library implementations if ASan has been inited, whereasmemmove
always callsinternal_memmove
.This patch changes
memmove
to use the library implementation if ASan has been inited.