[PATCH] D29562: [sanitizer] Add weak hooks for Windows,

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 5 03:55:59 PST 2017


mpividori created this revision.
Herald added subscribers: kubamracek, emaste.

I add weak hooks for Windows. As we use the macro: `SANITIZER_INTERFACE_WEAK_DEF()` I don't need to modify the header file: `sanitizer_common_interceptors.h`.
I think we could remove the flag: `SANITIZER_INTERCEPTOR_HOOKS` because the only missing case is FreeBSD, and I don't see any problem in adding weak hooks for FreeBSD too.

After this diff, many tests were fixed for libFuzzer.


https://reviews.llvm.org/D29562

Files:
  lib/sanitizer_common/sanitizer_common_interface.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h
  lib/sanitizer_common/sanitizer_win_weak_interception.cc
  test/asan/TestCases/Darwin/interface_symbols_darwin.c
  test/asan/TestCases/Linux/interface_symbols_linux.c


Index: test/asan/TestCases/Linux/interface_symbols_linux.c
===================================================================
--- test/asan/TestCases/Linux/interface_symbols_linux.c
+++ test/asan/TestCases/Linux/interface_symbols_linux.c
@@ -15,6 +15,7 @@
 // RUN:  %p/../../../../lib/sanitizer_common/sanitizer_common_interface.inc    \
 // RUN:  %p/../../../../lib/sanitizer_common/sanitizer_common_interface_posix.inc \
 // RUN:  %p/../../../../lib/sanitizer_common/sanitizer_coverage_interface.inc  \
+// RUN:  | grep -v "__sanitizer_weak_hook"                                     \
 // RUN:  | sed -e "s/.*(//" -e "s/).*//" > %t.imports
 //
 // RUN: cat %t.imports | sort | uniq > %t.imports-sorted
Index: test/asan/TestCases/Darwin/interface_symbols_darwin.c
===================================================================
--- test/asan/TestCases/Darwin/interface_symbols_darwin.c
+++ test/asan/TestCases/Darwin/interface_symbols_darwin.c
@@ -21,6 +21,7 @@
 // RUN:  %p/../../../../lib/sanitizer_common/sanitizer_common_interface.inc    \
 // RUN:  %p/../../../../lib/sanitizer_common/sanitizer_common_interface_posix.inc \
 // RUN:  %p/../../../../lib/sanitizer_common/sanitizer_coverage_interface.inc  \
+// RUN:  | grep -v "__sanitizer_weak_hook"                                     \
 // RUN:  | sed -e "s/.*(//" -e "s/).*//" > %t.imports
 //
 // RUN: cat %t.imports | sort | uniq > %t.imports-sorted
Index: lib/sanitizer_common/sanitizer_win_weak_interception.cc
===================================================================
--- lib/sanitizer_common/sanitizer_win_weak_interception.cc
+++ lib/sanitizer_common/sanitizer_win_weak_interception.cc
@@ -37,6 +37,18 @@
 }
 } // namespace __sanitizer
 
+// Declare weak hooks.
+extern "C" {
+void __sanitizer_weak_hook_memcmp(uptr called_pc, const void *s1,
+                                  const void *s2, uptr n, int result);
+void __sanitizer_weak_hook_strcmp(uptr called_pc, const char *s1,
+                                  const char *s2, int result);
+void __sanitizer_weak_hook_strncmp(uptr called_pc, const char *s1,
+                                   const char *s2, uptr n, int result);
+void __sanitizer_weak_hook_strstr(uptr called_pc, const char *s1,
+                                  const char *s2, char *result);
+}
+
 // Include Sanitizer Common interface.
 #define INTERFACE_FUNCTION(Name)
 #define INTERFACE_WEAK_FUNCTION(Name) INTERCEPT_SANITIZER_WEAK_FUNCTION(Name)
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -17,9 +17,11 @@
 #include "sanitizer_internal_defs.h"
 
 #if !SANITIZER_WINDOWS
+# define SI_WINDOWS 0
 # define SI_NOT_WINDOWS 1
 # include "sanitizer_platform_limits_posix.h"
 #else
+# define SI_WINDOWS 1
 # define SI_NOT_WINDOWS 0
 #endif
 
@@ -310,7 +312,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 || SI_MAC
+#define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX || SI_MAC || SI_WINDOWS
 #define SANITIZER_INTERCEPT_RECV_RECVFROM SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_SEND_SENDTO SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE SI_LINUX
Index: lib/sanitizer_common/sanitizer_common_interface.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interface.inc
+++ lib/sanitizer_common/sanitizer_common_interface.inc
@@ -16,6 +16,11 @@
 INTERFACE_FUNCTION(__sanitizer_verify_contiguous_container)
 INTERFACE_WEAK_FUNCTION(__sanitizer_report_error_summary)
 INTERFACE_WEAK_FUNCTION(__sanitizer_sandbox_on_notify)
+// Sanitizer weak hooks
+INTERFACE_WEAK_FUNCTION(__sanitizer_weak_hook_memcmp)
+INTERFACE_WEAK_FUNCTION(__sanitizer_weak_hook_strcmp)
+INTERFACE_WEAK_FUNCTION(__sanitizer_weak_hook_strncmp)
+INTERFACE_WEAK_FUNCTION(__sanitizer_weak_hook_strstr)
 // Stacktrace interface.
 INTERFACE_FUNCTION(__sanitizer_get_module_and_offset_for_pc)
 INTERFACE_FUNCTION(__sanitizer_symbolize_global)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29562.87138.patch
Type: text/x-patch
Size: 4221 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170205/275979d0/attachment.bin>


More information about the llvm-commits mailing list