aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Fuzzer/FuzzerLoop.cpp
diff options
context:
space:
mode:
authorDan Liew <dan@su-root.co.uk>2016-05-19 22:00:33 +0000
committerDan Liew <dan@su-root.co.uk>2016-05-19 22:00:33 +0000
commit3868e468fea62a245b12f9debec242f6d2a62e23 (patch)
treed0ba0c034ed1e7497e638d3b576c7738a730121c /llvm/lib/Fuzzer/FuzzerLoop.cpp
parent97d7a66299278911c3ca5b828d29d34f0cd942f0 (diff)
downloadllvm-3868e468fea62a245b12f9debec242f6d2a62e23.zip
llvm-3868e468fea62a245b12f9debec242f6d2a62e23.tar.gz
llvm-3868e468fea62a245b12f9debec242f6d2a62e23.tar.bz2
[LibFuzzer]
Work around crashes in ``__sanitizer_malloc_hook()`` under Mac OSX. Under Mac OSX we intercept calls to malloc before thread local storage is initialised leading to a crash when accessing ``AllocTracer``. To workaround this ``AllocTracer`` is only accessed in the hook under Linux. For symmetry ``__sanitizer_free_hook()`` is also modified in the same way. To support this change a set of new macros LIBFUZZER_LINUX and LIBFUZZER_APPLE has been defined which can be used to check the target being compiled for. Differential Revision: http://reviews.llvm.org/D20402 llvm-svn: 270145
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerLoop.cpp')
-rw-r--r--llvm/lib/Fuzzer/FuzzerLoop.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp
index 6b19a15..0adbc89 100644
--- a/llvm/lib/Fuzzer/FuzzerLoop.cpp
+++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp
@@ -437,9 +437,19 @@ struct MallocFreeTracer {
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_APPLE)
+ AllocTracer.Mallocs++;
+}
+void __sanitizer_free_hook(void *ptr) {
+ if (!LIBFUZZER_APPLE)
+ AllocTracer.Frees++;
+}
} // extern "C"
void Fuzzer::ExecuteCallback(const uint8_t *Data, size_t Size) {