From a6eb1bb59e753ad81e2d6798d996cdd7cc1488b2 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Thu, 27 Mar 2014 14:20:34 +0000 Subject: [PATCH] [sanitizer] Intercept __bzero on Mac. This should make memset_test pass on Mac. llvm-svn: 204929 --- .../sanitizer_common_interceptors.inc | 14 +++++++++++++- .../sanitizer_platform_interceptors.h | 1 + compiler-rt/test/asan/TestCases/memset_test.cc | 5 +++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 883286209200..8eaeb19dcc54 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -3470,6 +3470,17 @@ INTERCEPTOR(void *, __aeabi_memclr8, void *block, uptr size) { #define INIT_AEABI_MEM #endif // SANITIZER_INTERCEPT_AEABI_MEM +#if SANITIZER_INTERCEPT___BZERO +DECLARE_REAL_AND_INTERCEPTOR(void *, memset, void *, int, uptr); + +INTERCEPTOR(void *, __bzero, void *block, uptr size) { + return WRAP(memset)(block, 0, size); +} +#define INIT___BZERO COMMON_INTERCEPT_FUNCTION(__bzero); +#else +#define INIT___BZERO +#endif // SANITIZER_INTERCEPT___BZERO + #define SANITIZER_COMMON_INTERCEPTORS_INIT \ INIT_TEXTDOMAIN; \ INIT_STRCMP; \ @@ -3592,5 +3603,6 @@ INTERCEPTOR(void *, __aeabi_memclr8, void *block, uptr size) { INIT_GETIFADDRS; \ INIT_IF_INDEXTONAME; \ INIT_CAPGET; \ - INIT_AEABI_MEM; + INIT_AEABI_MEM; \ + INIT___BZERO; /**/ diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 3e9ec10450fb..e87feff0a49c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -188,5 +188,6 @@ #define SANITIZER_INTERCEPT_IF_INDEXTONAME SI_LINUX_NOT_ANDROID || SI_MAC #define SANITIZER_INTERCEPT_CAPGET SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_AEABI_MEM SI_LINUX && defined(__arm__) +#define SANITIZER_INTERCEPT___BZERO SI_MAC #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H diff --git a/compiler-rt/test/asan/TestCases/memset_test.cc b/compiler-rt/test/asan/TestCases/memset_test.cc index 37898e143066..ea7702566fcb 100644 --- a/compiler-rt/test/asan/TestCases/memset_test.cc +++ b/compiler-rt/test/asan/TestCases/memset_test.cc @@ -47,11 +47,12 @@ int main(int argc, char **argv) { #if defined(TEST_MEMCPY) memcpy(q, p, 3000); // CHECK-MEMCPY: AddressSanitizer: use-after-poison on address - // CHECK-MEMCPY: in {{.*}}memcpy + // On Mac, memmove and memcpy are the same. Accept either one. + // CHECK-MEMCPY: in {{.*(memmove|memcpy)}} #elif defined(TEST_MEMMOVE) memmove(q, p, 3000); // CHECK-MEMMOVE: AddressSanitizer: use-after-poison on address - // CHECK-MEMMOVE: in {{.*}}memmove + // CHECK-MEMMOVE: in {{.*(memmove|memcpy)}} #endif assert(q[1] == 0); free(q);