[compiler-rt] r293741 - [sanitizer] Support SANITIZER_INTERCEPTOR_HOOKS on Darwin

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 31 19:31:10 PST 2017


Author: bogner
Date: Tue Jan 31 21:31:09 2017
New Revision: 293741

URL: http://llvm.org/viewvc/llvm-project?rev=293741&view=rev
Log:
[sanitizer] Support SANITIZER_INTERCEPTOR_HOOKS on Darwin

This basically already worked other than weak symbols needing
definitions on darwin.

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc
      - copied, changed from r293734, compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/weak_hook_test.cc
Removed:
    compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/weak_hook_test.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=293741&r1=293740&r2=293741&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Tue Jan 31 21:31:09 2017
@@ -44,15 +44,9 @@
 #include <stdarg.h>
 
 #if SANITIZER_INTERCEPTOR_HOOKS
-#define CALL_WEAK_INTERCEPTOR_HOOK(f, ...)                                     \
-  do {                                                                         \
-    if (f)                                                                     \
-      f(__VA_ARGS__);                                                          \
-  } while (false);
-#define DECLARE_WEAK_INTERCEPTOR_HOOK(f, ...)                                  \
-  extern "C" {                                                                 \
-  SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void f(__VA_ARGS__);  \
-  } // extern "C"
+#define CALL_WEAK_INTERCEPTOR_HOOK(f, ...) f(__VA_ARGS__);
+#define DECLARE_WEAK_INTERCEPTOR_HOOK(f, ...) \
+  SANITIZER_INTERFACE_WEAK_DEF(void, f, __VA_ARGS__) {}
 #else
 #define DECLARE_WEAK_INTERCEPTOR_HOOK(f, ...)
 #define CALL_WEAK_INTERCEPTOR_HOOK(f, ...)

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=293741&r1=293740&r2=293741&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Tue Jan 31 21:31:09 2017
@@ -302,7 +302,7 @@
 #define SANITIZER_INTERCEPT_CTERMID SI_LINUX || SI_MAC || SI_FREEBSD
 #define SANITIZER_INTERCEPT_CTERMID_R SI_MAC || SI_FREEBSD
 
-#define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX
+#define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX || SI_MAC
 #define SANITIZER_INTERCEPT_RECV_RECVFROM SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_SEND_SENDTO SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE SI_LINUX

Removed: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/weak_hook_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/weak_hook_test.cc?rev=293740&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/weak_hook_test.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/weak_hook_test.cc (removed)
@@ -1,82 +0,0 @@
-// Test the weak hooks.
-// RUN: %clangxx %s -o %t
-// RUN: %run %t
-
-// Hooks are not implemented for lsan.
-// XFAIL: lsan
-
-#include <string.h>
-#include <assert.h>
-
-bool seen_memcmp, seen_strncmp, seen_strncasecmp, seen_strcmp, seen_strcasecmp,
-    seen_strstr, seen_strcasestr, seen_memmem;
-
-extern "C" {
-void __sanitizer_weak_hook_memcmp(void *called_pc, const void *s1,
-                                  const void *s2, size_t n, int result) {
-  seen_memcmp = true;
-}
-void __sanitizer_weak_hook_strncmp(void *called_pc, const char *s1,
-                                   const char *s2, size_t n, int result) {
-  seen_strncmp = true;
-}
-void __sanitizer_weak_hook_strncasecmp(void *called_pc, const char *s1,
-                                       const char *s2, size_t n, int result){
-  seen_strncasecmp = true;
-}
-void __sanitizer_weak_hook_strcmp(void *called_pc, const char *s1,
-                                  const char *s2, int result){
-  seen_strcmp = true;
-}
-void __sanitizer_weak_hook_strcasecmp(void *called_pc, const char *s1,
-                                      const char *s2, int result){
-  seen_strcasecmp = true;
-}
-void __sanitizer_weak_hook_strstr(void *called_pc, const char *s1,
-                                  const char *s2, char *result){
-  seen_strstr = true;
-}
-void __sanitizer_weak_hook_strcasestr(void *called_pc, const char *s1,
-                                      const char *s2, char *result){
-  seen_strcasestr = true;
-}
-void __sanitizer_weak_hook_memmem(void *called_pc, const void *s1, size_t len1,
-                                  const void *s2, size_t len2, void *result){
-  seen_memmem = true;
-}
-} // extern "C"
-
-char s1[] = "ABCDEF";
-char s2[] = "CDE";
-
-static volatile int int_sink;
-static volatile void *ptr_sink;
-
-int main() {
-  assert(sizeof(s2) < sizeof(s1));
-
-  int_sink = memcmp(s1, s2, sizeof(s2));
-  assert(seen_memcmp);
-
-  int_sink = strncmp(s1, s2, sizeof(s2));
-  assert(seen_strncmp);
-
-  int_sink = strncasecmp(s1, s2, sizeof(s2));
-  assert(seen_strncasecmp);
-
-  int_sink = strcmp(s1, s2);
-  assert(seen_strcmp);
-
-  int_sink = strcasecmp(s1, s2);
-  assert(seen_strcasecmp);
-
-  ptr_sink = strstr(s1, s2);
-  assert(seen_strstr);
-
-  ptr_sink = strcasestr(s1, s2);
-  assert(seen_strcasestr);
-
-  ptr_sink = memmem(s1, sizeof(s1), s2, sizeof(s2));
-  assert(seen_memmem);
-  return 0;
-}

Copied: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc (from r293734, compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/weak_hook_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc?p2=compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc&p1=compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/weak_hook_test.cc&r1=293734&r2=293741&rev=293741&view=diff
==============================================================================
    (empty)




More information about the llvm-commits mailing list