[PATCH] D84561: Replace fuzzer::FuzzerDriver's INTERFACE marking with new LLVMRunFuzzerDriver.

Ian Eldred Pudney via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 16:13:05 PDT 2020


IanPudney updated this revision to Diff 280613.
IanPudney edited the summary of this revision.
IanPudney added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Removed changes that were already made in a previous change, and adds docs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84561/new/

https://reviews.llvm.org/D84561

Files:
  compiler-rt/lib/fuzzer/FuzzerDriver.cpp
  llvm/docs/LibFuzzer.rst


Index: llvm/docs/LibFuzzer.rst
===================================================================
--- llvm/docs/LibFuzzer.rst
+++ llvm/docs/LibFuzzer.rst
@@ -617,6 +617,35 @@
     return 0;
    }
 
+Using libFuzzer as a library
+----------------------------
+If the code being fuzzed must provide its own `main`, it's possible to
+invoke libFuzzer as a library. Be sure to pass ``-fsanitize=fuzzer-no-link``
+during compilation, and link your binary against the no-main version of
+libFuzzer. On Linux installations, this is typically located at:
+
+.. code-block:: bash
+
+  /usr/lib/<llvm-version>/lib/clang/<clang-version>/lib/linux/libclang_rt.fuzzer_no_main-<architecture>.a
+
+If building libFuzzer from source, this is located at the following path
+in the build output directory:
+
+.. code-block:: bash
+
+  lib/linux/libclang_rt.fuzzer_no_main-<architecture>.a
+
+From here, the code can do whatever setup it requires, and when it's ready
+to start fuzzing, it can call `LLVMFuzzerRunDriver`, passing in the program
+arguments and a callback. This callback is invoked just like
+`LLVMFuzzerTestOneInput`, and has the same signature.
+
+.. code-block:: c++
+
+  extern "C" int LLVMFuzzerRunDriver(int *argc, char ***argv,
+                    int (*UserCb)(const uint8_t *Data, size_t Size));
+
+
 
 Leaks
 -----
Index: compiler-rt/lib/fuzzer/FuzzerDriver.cpp
===================================================================
--- compiler-rt/lib/fuzzer/FuzzerDriver.cpp
+++ compiler-rt/lib/fuzzer/FuzzerDriver.cpp
@@ -858,6 +858,12 @@
   exit(0);  // Don't let F destroy itself.
 }
 
+extern "C" ATTRIBUTE_INTERFACE int
+LLVMFuzzerRunDriver(int *argc, char ***argv,
+                    int (*UserCb)(const uint8_t *Data, size_t Size)) {
+  return FuzzerDriver(argc, argv, UserCb);
+}
+
 // Storage for global ExternalFunctions object.
 ExternalFunctions *EF = nullptr;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84561.280613.patch
Type: text/x-patch
Size: 1884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200724/5defbf6a/attachment.bin>


More information about the llvm-commits mailing list