[libFuzzer] make libFuzzer build even with a compiler that does not have sanitizer...
authorKostya Serebryany <kcc@google.com>
Fri, 13 Nov 2015 01:54:40 +0000 (01:54 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 13 Nov 2015 01:54:40 +0000 (01:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253003 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerDFSan.h
lib/Fuzzer/FuzzerIO.cpp
lib/Fuzzer/FuzzerLoop.cpp

index 6398575e6955454f0f97ae5de891f95272c81c60..eb206ec61ce860fa67b9cc9cea36773377a5971f 100644 (file)
 #ifndef LLVM_FUZZER_DFSAN_H
 #define LLVM_FUZZER_DFSAN_H
 
 #ifndef LLVM_FUZZER_DFSAN_H
 #define LLVM_FUZZER_DFSAN_H
 
-#ifndef LLVM_FUZZER_SUPPORTS_DFSAN
-# if defined(__linux__)
-#  define LLVM_FUZZER_SUPPORTS_DFSAN 1
-# else
-#  define LLVM_FUZZER_SUPPORTS_DFSAN 0
-# endif  // __linux__
-#endif  // LLVM_FUZZER_SUPPORTS_DFSAN
+#define LLVM_FUZZER_SUPPORTS_DFSAN 0
+#if defined(__has_include)
+# if __has_include(<sanitizer/dfsan_interface.h>)
+#  if defined (__linux__)
+#   undef LLVM_FUZZER_SUPPORTS_DFSAN
+#   define LLVM_FUZZER_SUPPORTS_DFSAN 1
+#   include <sanitizer/dfsan_interface.h>
+#  endif  // __linux__
+# endif
+#endif  // defined(__has_include)
 
 
-#include <sanitizer/dfsan_interface.h>
 #if LLVM_FUZZER_SUPPORTS_DFSAN
 
 extern "C" {
 #if LLVM_FUZZER_SUPPORTS_DFSAN
 
 extern "C" {
@@ -42,6 +44,14 @@ static bool ReallyHaveDFSan() {
 }
 }  // namespace fuzzer
 #else
 }
 }  // namespace fuzzer
 #else
+// When compiling with a compiler which does not support dfsan,
+// this code is still expected to build (but not necessary work).
+typedef unsigned short dfsan_label;
+struct dfsan_label_info {
+  dfsan_label l1, l2;
+  const char *desc;
+  void *userdata;
+};
 namespace fuzzer {
 static bool ReallyHaveDFSan() { return false; }
 }  // namespace fuzzer
 namespace fuzzer {
 static bool ReallyHaveDFSan() { return false; }
 }  // namespace fuzzer
index 4bb2df5d71ae6f9f25eb693beac53b62287ed89e..abc444a3d4713e6abe0acdeff4475a1e7871ec6f 100644 (file)
@@ -15,6 +15,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <cstdarg>
 #include <cstdio>
 
 namespace fuzzer {
 #include <cstdio>
 
 namespace fuzzer {
index 455aa625337f847271fbd86e9fe6720810ced009..48c1b35dccbaa95c086c3e7f068e309182c46205 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "FuzzerInternal.h"
 //===----------------------------------------------------------------------===//
 
 #include "FuzzerInternal.h"
-#include <sanitizer/coverage_interface.h>
 #include <algorithm>
 
 #include <algorithm>
 
+#if defined(__has_include)
+# if __has_include(<sanitizer/coverage_interface.h>)
+#  include <sanitizer/coverage_interface.h>
+# endif
+#endif
+
 extern "C" {
 // Re-declare some of the sanitizer functions as "weak" so that
 extern "C" {
 // Re-declare some of the sanitizer functions as "weak" so that
-// libFuzzer can be linked w/o the sanitizers and sanitizer-coveragte
+// libFuzzer can be linked w/o the sanitizers and sanitizer-coverage
 // (in which case it will complain at start-up time).
 __attribute__((weak)) void __sanitizer_print_stack_trace();
 __attribute__((weak)) void __sanitizer_reset_coverage();
 // (in which case it will complain at start-up time).
 __attribute__((weak)) void __sanitizer_print_stack_trace();
 __attribute__((weak)) void __sanitizer_reset_coverage();