[PATCH] D20402: Work around crashes in `__sanitizer_malloc_hook()` under Mac OSX.
Dan Liew via llvm-commits
llvm-commits at lists.llvm.org
Thu May 19 12:15:28 PDT 2016
delcypher retitled this revision from "Try to fix libFuzzer running on Mac OSX" to "Work around crashes in `__sanitizer_malloc_hook()` under Mac OSX.".
delcypher updated the summary for this revision.
delcypher updated this revision to Diff 57835.
http://reviews.llvm.org/D20402
Files:
lib/Fuzzer/FuzzerInternal.h
lib/Fuzzer/FuzzerLoop.cpp
Index: lib/Fuzzer/FuzzerLoop.cpp
===================================================================
--- lib/Fuzzer/FuzzerLoop.cpp
+++ lib/Fuzzer/FuzzerLoop.cpp
@@ -437,9 +437,21 @@
static thread_local MallocFreeTracer AllocTracer;
+// FIXME: The hooks only count on Linux because
+// on Mac OSX calls to malloc are intercepted before
+// thread local storage is initialised leading to
+// crashes when accessing ``AllocTracer``.
extern "C" {
-void __sanitizer_malloc_hook(void *ptr, size_t size) { AllocTracer.Mallocs++; }
-void __sanitizer_free_hook(void *ptr) { AllocTracer.Frees++; }
+void __sanitizer_malloc_hook(void *ptr, size_t size) {
+ if (LIBFUZZER_LINUX) {
+ AllocTracer.Mallocs++;
+ }
+}
+void __sanitizer_free_hook(void *ptr) {
+ if (LIBFUZZER_LINUX) {
+ AllocTracer.Frees++;
+ }
+}
} // extern "C"
void Fuzzer::ExecuteCallback(const uint8_t *Data, size_t Size) {
Index: lib/Fuzzer/FuzzerInternal.h
===================================================================
--- lib/Fuzzer/FuzzerInternal.h
+++ lib/Fuzzer/FuzzerInternal.h
@@ -27,6 +27,17 @@
#include "FuzzerInterface.h"
#include "FuzzerTracePC.h"
+// Platform detection.
+#ifdef __linux__
+#define LIBFUZZER_LINUX 1
+#define LIBFUZZER_APPLE 0
+#elif __APPLE__
+#define LIBFUZZER_LINUX 0
+#define LIBFUZZER_APPLE 1
+#else
+#error "Support for your platform has not been implemented"
+#endif
+
namespace fuzzer {
typedef int (*UserCallback)(const uint8_t *Data, size_t Size);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20402.57835.patch
Type: text/x-patch
Size: 1476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160519/d1e37de2/attachment.bin>
More information about the llvm-commits
mailing list