1 //===- FuzzerExtFunctionsDlsym.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 for operating systems that support dlsym(). We only use it on
10 // Apple platforms for now. We don't use this approach on Linux because it
11 // requires that clients of LibFuzzer pass ``--export-dynamic`` to the linker.
12 // That is a complication we don't wish to expose to clients right now.
13 //===----------------------------------------------------------------------===//
14 #include "FuzzerDefs.h"
17 #include "FuzzerExtFunctions.h"
21 using namespace fuzzer;
24 static T GetFnPtr(const char *FnName, bool WarnIfMissing) {
25 dlerror(); // Clear any previous errors.
26 void *Fn = dlsym(RTLD_DEFAULT, FnName);
29 const char *ErrorMsg = dlerror();
30 Printf("WARNING: Failed to find function \"%s\".", FnName);
32 Printf(" Reason %s.", ErrorMsg);
36 return reinterpret_cast<T>(Fn);
41 ExternalFunctions::ExternalFunctions() {
42 #define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \
43 this->NAME = GetFnPtr<decltype(ExternalFunctions::NAME)>(#NAME, WARN)
45 #include "FuzzerExtFunctions.def"
52 #endif // LIBFUZZER_APPLE