[PATCH] D27235: [libFuzzer] Diff 5 - Split FuzzerExtFunction implementation for Linux, Apple and Windows.

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 2 11:51:37 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL288530: [LibFuzzer] Introduce a portable WeakAlias implementation. (authored by zturner).

Changed prior to commit:
  https://reviews.llvm.org/D27235?vs=80076&id=80114#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27235

Files:
  llvm/trunk/lib/Fuzzer/CMakeLists.txt
  llvm/trunk/lib/Fuzzer/FuzzerExtFunctionsWeakAlias.cpp


Index: llvm/trunk/lib/Fuzzer/FuzzerExtFunctionsWeakAlias.cpp
===================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerExtFunctionsWeakAlias.cpp
+++ llvm/trunk/lib/Fuzzer/FuzzerExtFunctionsWeakAlias.cpp
@@ -0,0 +1,54 @@
+//===- FuzzerExtFunctionsWeakAlias.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 using weak aliases. Works 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 <typename T>
+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<decltype(::NAME)>(::NAME, ::NAME##Def, #NAME, WARN);
+
+#include "FuzzerExtFunctions.def"
+
+#undef EXT_FUNC
+}
+} // namespace fuzzer
+#endif // LIBFUZZER_WINDOWS
Index: llvm/trunk/lib/Fuzzer/CMakeLists.txt
===================================================================
--- llvm/trunk/lib/Fuzzer/CMakeLists.txt
+++ llvm/trunk/lib/Fuzzer/CMakeLists.txt
@@ -13,6 +13,7 @@
     FuzzerDriver.cpp
     FuzzerExtFunctionsDlsym.cpp
     FuzzerExtFunctionsWeak.cpp
+    FuzzerExtFunctionsWeakAlias.cpp
     FuzzerIO.cpp
     FuzzerIOPosix.cpp
     FuzzerIOWindows.cpp


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27235.80114.patch
Type: text/x-patch
Size: 2521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161202/8d810e2d/attachment.bin>


More information about the llvm-commits mailing list