diff options
| author | Dan Liew <dan@su-root.co.uk> | 2016-06-07 23:32:50 +0000 |
|---|---|---|
| committer | Dan Liew <dan@su-root.co.uk> | 2016-06-07 23:32:50 +0000 |
| commit | 1873a496e20a391633fc29665d6620c1ca3191f7 (patch) | |
| tree | abb6a28df749fed5b9e653269cdcd941af9d7bb1 /llvm/lib/Fuzzer/FuzzerDriver.cpp | |
| parent | 32c940de377ec87a072e3d7c3f3200beec6fe90e (diff) | |
| download | bcm5719-llvm-1873a496e20a391633fc29665d6620c1ca3191f7.tar.gz bcm5719-llvm-1873a496e20a391633fc29665d6620c1ca3191f7.zip | |
[LibFuzzer] Declare and use sanitizer functions in ``fuzzer::ExternalFunctions``
This fixes linking problems on OSX.
Unfortunately it turns out we need to use an instance of the
``fuzzer::ExternalFunctions`` object in several places so this
commit also replaces all instances with a single global instance.
It also turns out initializing a global ``fuzzer::ExternalFunctions``
before main is entered (i.e. letting the object be initialised by the
global initializers) is not safe (on OSX the call to ``Printf()`` in the
CTOR crashes if it is called from a global initializer) so we instead
have a global ``fuzzer::ExternalFunctions*`` and initialize it inside
``FuzzerDriver()``.
Multiple unit tests depend also depend on the
``fuzzer::ExternalFunctions*`` global so a ``main()`` function has been
added that initializes it before running any tests.
Differential Revision: http://reviews.llvm.org/D20943
llvm-svn: 272072
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerDriver.cpp')
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerDriver.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerDriver.cpp b/llvm/lib/Fuzzer/FuzzerDriver.cpp index 9807d605aeb..4e980bfd807 100644 --- a/llvm/lib/Fuzzer/FuzzerDriver.cpp +++ b/llvm/lib/Fuzzer/FuzzerDriver.cpp @@ -269,9 +269,9 @@ static bool AllInputsAreFiles() { int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) { using namespace fuzzer; assert(argc && argv && "Argument pointers cannot be nullptr"); - fuzzer::ExternalFunctions EF; - if (EF.LLVMFuzzerInitialize) - EF.LLVMFuzzerInitialize(argc, argv); + EF = new ExternalFunctions(); + if (EF->LLVMFuzzerInitialize) + EF->LLVMFuzzerInitialize(argc, argv); const std::vector<std::string> Args(*argv, *argv + *argc); assert(!Args.empty()); ProgName = new std::string(Args[0]); @@ -422,4 +422,8 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) { exit(0); // Don't let F destroy itself. } + +// Storage for global ExternalFunctions object. +ExternalFunctions *EF = nullptr; + } // namespace fuzzer |

