[DominatorTree] Add support for mixed pre/post CFG views.
[llvm-project.git] / compiler-rt / lib / fuzzer / FuzzerExtFunctionsDlsym.cpp
blob95233d2a10d37161c55c5f7baa5edde345ae62d6
1 //===- FuzzerExtFunctionsDlsym.cpp - Interface to external functions ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // Implementation for operating systems that support dlsym(). We only use it on
9 // Apple platforms for now. We don't use this approach on Linux because it
10 // requires that clients of LibFuzzer pass ``--export-dynamic`` to the linker.
11 // That is a complication we don't wish to expose to clients right now.
12 //===----------------------------------------------------------------------===//
13 #include "FuzzerPlatform.h"
14 #if LIBFUZZER_APPLE
16 #include "FuzzerExtFunctions.h"
17 #include "FuzzerIO.h"
18 #include <dlfcn.h>
20 using namespace fuzzer;
22 template <typename T>
23 static T GetFnPtr(const char *FnName, bool WarnIfMissing) {
24 dlerror(); // Clear any previous errors.
25 void *Fn = dlsym(RTLD_DEFAULT, FnName);
26 if (Fn == nullptr) {
27 if (WarnIfMissing) {
28 const char *ErrorMsg = dlerror();
29 Printf("WARNING: Failed to find function \"%s\".", FnName);
30 if (ErrorMsg)
31 Printf(" Reason %s.", ErrorMsg);
32 Printf("\n");
35 return reinterpret_cast<T>(Fn);
38 namespace fuzzer {
40 ExternalFunctions::ExternalFunctions() {
41 #define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \
42 this->NAME = GetFnPtr<decltype(ExternalFunctions::NAME)>(#NAME, WARN)
44 #include "FuzzerExtFunctions.def"
46 #undef EXT_FUNC
49 } // namespace fuzzer
51 #endif // LIBFUZZER_APPLE