1 //===- FuzzerExtFunctionsWeakAlias.cpp - Interface to external functions --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // Implementation using weak aliases. Works for Windows.
10 //===----------------------------------------------------------------------===//
11 #include "FuzzerDefs.h"
14 #include "FuzzerExtFunctions.h"
17 using namespace fuzzer;
20 // Declare these symbols as weak to allow them to be optionally defined.
21 #define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \
22 RETURN_TYPE NAME##Def FUNC_SIG { \
23 Printf("ERROR: Function \"%s\" not defined.\n", #NAME); \
26 RETURN_TYPE NAME FUNC_SIG __attribute__((weak, alias(#NAME "Def")));
28 #include "FuzzerExtFunctions.def"
34 static T *GetFnPtr(T *Fun, T *FunDef, const char *FnName, bool WarnIfMissing) {
37 Printf("WARNING: Failed to find function \"%s\".\n", FnName);
45 ExternalFunctions::ExternalFunctions() {
46 #define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \
47 this->NAME = GetFnPtr<decltype(::NAME)>(::NAME, ::NAME##Def, #NAME, WARN);
49 #include "FuzzerExtFunctions.def"
56 #endif // LIBFUZZER_WINDOWS