-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[compiler-rt][sanitizer-common] adding C23 memset_explicit interception. #154428
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
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer Author: David CARLIER (devnexen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/154428.diff 3 Files Affected:
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
index 0b6731c89950b..5334b0ded17e8 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
@@ -233,6 +233,16 @@ INTERCEPTOR(void *, bzero, void *block, usize size) {
#define INIT_BZERO
#endif // SANITIZER_INTERCEPT_BZERO
+#if SANITIZER_INTERCEPT_MEMSET_EXPLICIT
+INTERCEPTOR(void *, memset_explicit, void *block, int c, usize size) {
+ void *ctx;
+ COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size);
+}
+#define INIT_MEMSET_EXPLICIT COMMON_INTERCEPT_FUNCTION(memset_explicit)
+#else
+#define INIT_MEMSET_EXPLICIT
+#endif
+
namespace __sanitizer {
// This does not need to be called if InitializeCommonInterceptors() is called.
void InitializeMemintrinsicInterceptors() {
@@ -242,5 +252,6 @@ void InitializeMemintrinsicInterceptors() {
INIT_AEABI_MEM;
INIT___BZERO;
INIT_BZERO;
+ INIT_MEMSET_EXPLICIT;
}
} // namespace __sanitizer
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 29987decdff45..eee7af2069694 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -663,15 +663,17 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
#define SANITIZER_INTERCEPT_GETSERVBYNAME_R SI_GLIBC
#define SANITIZER_INTERCEPT_GETSERVBYPORT_R SI_GLIBC
-// Until free_sized and free_aligned_sized are more generally available,
+// Until free_sized, free_aligned_sized and memset_explicit are more generally available,
// we can only unconditionally intercept on ELF-based platforms where it
// is okay to have undefined weak symbols.
#ifdef __ELF__
# define SANITIZER_INTERCEPT_FREE_SIZED 1
# define SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED 1
+# define SANITIZER_INTERCEPT_MEMSET_EXPLICIT 1
#else
# define SANITIZER_INTERCEPT_FREE_SIZED 0
# define SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED 0
+# define SANITIZER_INTERCEPT_MEMSET_EXPLICIT 0
#endif
// This macro gives a way for downstream users to override the above
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/memset_explicit.c b/compiler-rt/test/sanitizer_common/TestCases/Linux/memset_explicit.c
new file mode 100644
index 0000000000000..08b8bdeb5e817
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/memset_explicit.c
@@ -0,0 +1,14 @@
+// RUN: %clang -std=c23 -O0 %s -o %t && %run %t
+// UNSUPPORTED: asan, hwasan, ubsan
+
+#include <stddef.h>
+#include <stdlib.h>
+
+extern void *memset_explicit(void *p, int value, size_t size);
+
+int main() {
+ char secbuffer[64];
+ (void)memset_explicit(secbuffer, 0, sizeof(secbuffer));
+ return 0;
+}
+
|
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions h,inc,c -- compiler-rt/test/sanitizer_common/TestCases/Linux/memset_explicit.c compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
View the diff from clang-format here.diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
index 5334b0ded..52fb5207e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
@@ -234,13 +234,13 @@ INTERCEPTOR(void *, bzero, void *block, usize size) {
#endif // SANITIZER_INTERCEPT_BZERO
#if SANITIZER_INTERCEPT_MEMSET_EXPLICIT
-INTERCEPTOR(void *, memset_explicit, void *block, int c, usize size) {
- void *ctx;
+INTERCEPTOR(void*, memset_explicit, void* block, int c, usize size) {
+ void* ctx;
COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size);
}
-#define INIT_MEMSET_EXPLICIT COMMON_INTERCEPT_FUNCTION(memset_explicit)
+# define INIT_MEMSET_EXPLICIT COMMON_INTERCEPT_FUNCTION(memset_explicit)
#else
-#define INIT_MEMSET_EXPLICIT
+# define INIT_MEMSET_EXPLICIT
#endif
namespace __sanitizer {
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index eee7af206..5d9cd9c11 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -663,9 +663,9 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
#define SANITIZER_INTERCEPT_GETSERVBYNAME_R SI_GLIBC
#define SANITIZER_INTERCEPT_GETSERVBYPORT_R SI_GLIBC
-// Until free_sized, free_aligned_sized and memset_explicit are more generally available,
-// we can only unconditionally intercept on ELF-based platforms where it
-// is okay to have undefined weak symbols.
+// Until free_sized, free_aligned_sized and memset_explicit are more generally
+// available, we can only unconditionally intercept on ELF-based platforms where
+// it is okay to have undefined weak symbols.
#ifdef __ELF__
# define SANITIZER_INTERCEPT_FREE_SIZED 1
# define SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED 1
|
62cc294
to
262bb32
Compare
7ecce4d
to
24a0540
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These usually for stuff we use internally in sanitizers, e,g, bzero is not here
24a0540
to
8b27cc7
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/24068 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/95/builds/17988 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/51/builds/22984 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/198/builds/7630 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/72/builds/14881 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/76/builds/12716 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/143/builds/10665 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/17/builds/10783 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/199/builds/5691 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/18924 Here is the relevant piece of the build log for the reference
|
…terception." (#157317) Reverts #154428 due to buildbot breakages (e.g., https://lab.llvm.org/buildbot/#/builders/51/builds/22984)
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/4/builds/8977 Here is the relevant piece of the build log for the reference
|
Premerge notably caught all the errors that showed up postcommit .https://github.com/llvm/llvm-project/actions/runs/17507911007 |
…explicit interception." (#157317) Reverts llvm/llvm-project#154428 due to buildbot breakages (e.g., https://lab.llvm.org/buildbot/#/builders/51/builds/22984)
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/41/builds/8770 Here is the relevant piece of the build log for the reference
|
I thought it was unrelated sorry |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/145/builds/9608 Here is the relevant piece of the build log for the reference
|
No description provided.