[llvm] r247321 - [libFuzzer] refactor the code to allow building libFuzzer on platforms that don't have dfsan and don't support weak functions

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 11:48:38 PDT 2015


Author: kcc
Date: Thu Sep 10 13:48:38 2015
New Revision: 247321

URL: http://llvm.org/viewvc/llvm-project?rev=247321&view=rev
Log:
[libFuzzer] refactor the code to allow building libFuzzer on platforms that don't have dfsan and don't support weak functions

Added:
    llvm/trunk/lib/Fuzzer/FuzzerDFSan.h
Modified:
    llvm/trunk/lib/Fuzzer/FuzzerTraceState.cpp

Added: llvm/trunk/lib/Fuzzer/FuzzerDFSan.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerDFSan.h?rev=247321&view=auto
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerDFSan.h (added)
+++ llvm/trunk/lib/Fuzzer/FuzzerDFSan.h Thu Sep 10 13:48:38 2015
@@ -0,0 +1,51 @@
+//===- FuzzerDFSan.h - Internal header for the Fuzzer -----------*- C++ -* ===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// DFSan interface.
+//===----------------------------------------------------------------------===//
+
+#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
+
+#include <sanitizer/dfsan_interface.h>
+#if LLVM_FUZZER_SUPPORTS_DFSAN
+
+extern "C" {
+__attribute__((weak))
+dfsan_label dfsan_create_label(const char *desc, void *userdata);
+__attribute__((weak))
+void dfsan_set_label(dfsan_label label, void *addr, size_t size);
+__attribute__((weak))
+void dfsan_add_label(dfsan_label label, void *addr, size_t size);
+__attribute__((weak))
+const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label);
+__attribute__((weak))
+dfsan_label dfsan_read_label(const void *addr, size_t size);
+}  // extern "C"
+
+namespace fuzzer {
+static bool ReallyHaveDFSan() {
+  return &dfsan_create_label != nullptr;
+}
+}  // namespace fuzzer
+#else
+namespace fuzzer {
+static bool ReallyHaveDFSan() { return false; }
+}  // namespace fuzzer
+
+#endif
+
+#endif // LLVM_FUZZER_DFSAN_H

Modified: llvm/trunk/lib/Fuzzer/FuzzerTraceState.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTraceState.cpp?rev=247321&r1=247320&r2=247321&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTraceState.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTraceState.cpp Thu Sep 10 13:48:38 2015
@@ -67,37 +67,34 @@
   clang  -fPIC -c -g -O2 -std=c++11 Fuzzer*.cpp
   clang++ -O0 -std=c++11 -fsanitize-coverage=edge,trace-cmp \
     -fsanitize=dataflow \
-    test/dfsan/DFSanSimpleCmpTest.cpp Fuzzer*.o
-  ./a.out
+    test/SimpleCmpTest.cpp Fuzzer*.o
+  ./a.out -use_traces=1
 )
 */
 
+#include "FuzzerDFSan.h"
 #include "FuzzerInternal.h"
-#include <sanitizer/dfsan_interface.h>
 
 #include <algorithm>
 #include <cstring>
 #include <unordered_map>
 
+#if !LLVM_FUZZER_SUPPORTS_DFSAN
+// Stubs for dfsan for platforms where dfsan does not exist and weak
+// functions don't work.
 extern "C" {
-__attribute__((weak))
-dfsan_label dfsan_create_label(const char *desc, void *userdata);
-__attribute__((weak))
-void dfsan_set_label(dfsan_label label, void *addr, size_t size);
-__attribute__((weak))
-void dfsan_add_label(dfsan_label label, void *addr, size_t size);
-__attribute__((weak))
-const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label);
-__attribute__((weak))
-dfsan_label dfsan_read_label(const void *addr, size_t size);
+dfsan_label dfsan_create_label(const char *desc, void *userdata) { return 0; }
+void dfsan_set_label(dfsan_label label, void *addr, size_t size) {}
+void dfsan_add_label(dfsan_label label, void *addr, size_t size) {}
+const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label) {
+  return nullptr;
+}
+dfsan_label dfsan_read_label(const void *addr, size_t size) { return 0; }
 }  // extern "C"
+#endif  // !LLVM_FUZZER_SUPPORTS_DFSAN
 
 namespace fuzzer {
 
-static bool ReallyHaveDFSan() {
-  return &dfsan_create_label != nullptr;
-}
-
 // These values are copied from include/llvm/IR/InstrTypes.h.
 // We do not include the LLVM headers here to remain independent.
 // If these values ever change, an assertion in ComputeCmp will fail.




More information about the llvm-commits mailing list