summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/FuzzerIO.cpp
diff options
context:
space:
mode:
authorDan Liew <dan@su-root.co.uk>2016-06-07 23:32:50 +0000
committerDan Liew <dan@su-root.co.uk>2016-06-07 23:32:50 +0000
commit1873a496e20a391633fc29665d6620c1ca3191f7 (patch)
treeabb6a28df749fed5b9e653269cdcd941af9d7bb1 /llvm/lib/Fuzzer/FuzzerIO.cpp
parent32c940de377ec87a072e3d7c3f3200beec6fe90e (diff)
downloadbcm5719-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/FuzzerIO.cpp')
-rw-r--r--llvm/lib/Fuzzer/FuzzerIO.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerIO.cpp b/llvm/lib/Fuzzer/FuzzerIO.cpp
index 171b188eab5..0e0c4e989cc 100644
--- a/llvm/lib/Fuzzer/FuzzerIO.cpp
+++ b/llvm/lib/Fuzzer/FuzzerIO.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
// IO functions.
//===----------------------------------------------------------------------===//
+#include "FuzzerExtFunctions.h"
#include "FuzzerInternal.h"
#include <iterator>
#include <fstream>
@@ -18,10 +19,6 @@
#include <cstdarg>
#include <cstdio>
-extern "C" {
-__attribute__((weak)) void __sanitizer_set_report_fd(void *);
-}
-
namespace fuzzer {
static FILE *OutputFile = stderr;
@@ -126,8 +123,8 @@ void DupAndCloseStderr() {
FILE *NewOutputFile = fdopen(OutputFd, "w");
if (NewOutputFile) {
OutputFile = NewOutputFile;
- if (__sanitizer_set_report_fd)
- __sanitizer_set_report_fd(reinterpret_cast<void*>(OutputFd));
+ if (EF->__sanitizer_set_report_fd)
+ EF->__sanitizer_set_report_fd(reinterpret_cast<void *>(OutputFd));
close(2);
}
}
OpenPOWER on IntegriCloud