Index: lib/Fuzzer/CMakeLists.txt =================================================================== --- lib/Fuzzer/CMakeLists.txt +++ lib/Fuzzer/CMakeLists.txt @@ -11,8 +11,9 @@ add_library(LLVMFuzzerNoMainObjects OBJECT FuzzerCrossOver.cpp FuzzerDriver.cpp - FuzzerExtFunctionsDlsym.cpp - FuzzerExtFunctionsWeak.cpp + FuzzerExtFunctionsApple.cpp + FuzzerExtFunctionsLinux.cpp + FuzzerExtFunctionsWindows.cpp FuzzerIO.cpp FuzzerIOPosix.cpp FuzzerIOWindows.cpp Index: lib/Fuzzer/FuzzerCorpus.h =================================================================== --- lib/Fuzzer/FuzzerCorpus.h +++ lib/Fuzzer/FuzzerCorpus.h @@ -14,6 +14,7 @@ #include #include +#include #include "FuzzerDefs.h" #include "FuzzerIO.h" Index: lib/Fuzzer/FuzzerExtFunctionsApple.cpp =================================================================== --- lib/Fuzzer/FuzzerExtFunctionsApple.cpp +++ lib/Fuzzer/FuzzerExtFunctionsApple.cpp @@ -1,4 +1,4 @@ -//===- FuzzerExtFunctionsDlsym.cpp - Interface to external functions ------===// +//===- FuzzerExtFunctionsApple.cpp - Interface to external functions ------===// // // The LLVM Compiler Infrastructure // @@ -13,8 +13,8 @@ //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" #if LIBFUZZER_APPLE - #include "FuzzerExtFunctions.h" +#include "FuzzerIO.h" #include using namespace fuzzer; Index: lib/Fuzzer/FuzzerExtFunctionsLinux.cpp =================================================================== --- lib/Fuzzer/FuzzerExtFunctionsLinux.cpp +++ lib/Fuzzer/FuzzerExtFunctionsLinux.cpp @@ -1,4 +1,4 @@ -//===- FuzzerExtFunctionsWeak.cpp - Interface to external functions -------===// +//===- FuzzerExtFunctionsLinux.cpp - Interface to external functions ------===// // // The LLVM Compiler Infrastructure // @@ -14,9 +14,8 @@ //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" #if LIBFUZZER_LINUX - -#include "FuzzerIO.h" #include "FuzzerExtFunctions.h" +#include "FuzzerIO.h" extern "C" { // Declare these symbols as weak to allow them to be optionally defined. Index: lib/Fuzzer/FuzzerExtFunctionsWindows.cpp =================================================================== --- /dev/null +++ lib/Fuzzer/FuzzerExtFunctionsWindows.cpp @@ -0,0 +1,53 @@ +//===- FuzzerExtFunctionsWindows.cpp - Interface to external functions ----===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Implementation for Windows. +//===----------------------------------------------------------------------===// +#include "FuzzerDefs.h" +#if LIBFUZZER_WINDOWS +#include "FuzzerExtFunctions.h" +#include "FuzzerIO.h" + +using namespace fuzzer; + +extern "C" { +// Declare these symbols as weak to allow them to be optionally defined. +#define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \ + RETURN_TYPE NAME ## Def FUNC_SIG { \ + Printf("ERROR: Function \"%s\" not defined.\n", #NAME); \ + exit(1); \ + } \ + RETURN_TYPE NAME FUNC_SIG __attribute__ ((weak, alias (#NAME "Def"))); + +#include "FuzzerExtFunctions.def" + +#undef EXT_FUNC +} + +template +static T* GetFnPtr(T *Fun, T *FunDef, const char *FnName, bool WarnIfMissing) { + if (Fun == FunDef) { + if (WarnIfMissing) + Printf("WARNING: Failed to find function \"%s\".\n", FnName); + return nullptr; + } + return Fun; +} + +namespace fuzzer { + +ExternalFunctions::ExternalFunctions() { +#define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \ + this->NAME = GetFnPtr(::NAME, ::NAME ## Def, #NAME, WARN); + +#include "FuzzerExtFunctions.def" + +#undef EXT_FUNC +} +} // namespace fuzzer +#endif // LIBFUZZER_WINDOWS