1414
1515#include " FuzzerExtFunctions.h"
1616#include " FuzzerIO.h"
17+ #include < stdlib.h>
1718
1819using namespace fuzzer ;
1920
@@ -22,6 +23,11 @@ using namespace fuzzer;
2223#define STRINGIFY (A ) STRINGIFY_(A)
2324
2425#if LIBFUZZER_MSVC
26+ #define GET_FUNCTION_ADDRESS (fn ) &fn
27+ #else
28+ #define GET_FUNCTION_ADDRESS (fn ) __builtin_function_start(fn)
29+ #endif // LIBFUZER_MSVC
30+
2531// Copied from compiler-rt/lib/sanitizer_common/sanitizer_win_defs.h
2632#if defined(_M_IX86) || defined(__i386__)
2733#define WIN_SYM_PREFIX " _"
@@ -31,17 +37,9 @@ using namespace fuzzer;
3137
3238// Declare external functions as having alternativenames, so that we can
3339// determine if they are not defined.
34- #define EXTERNAL_FUNC (Name, Default ) \
35- __pragma (comment(linker, " /alternatename:" WIN_SYM_PREFIX STRINGIFY ( \
40+ #define EXTERNAL_FUNC (Name, Default ) \
41+ __pragma (comment(linker, " /alternatename:" WIN_SYM_PREFIX STRINGIFY ( \
3642 Name) "=" WIN_SYM_PREFIX STRINGIFY(Default)))
37- #else
38- // Declare external functions as weak to allow them to default to a specified
39- // function if not defined explicitly. We must use weak symbols because clang's
40- // support for alternatename is not 100%, see
41- // https://bugs.llvm.org/show_bug.cgi?id=40218 for more details.
42- #define EXTERNAL_FUNC (Name, Default ) \
43- __attribute__ ((weak, alias(STRINGIFY(Default))))
44- #endif // LIBFUZZER_MSVC
4543
4644extern "C" {
4745#define EXT_FUNC (NAME, RETURN_TYPE, FUNC_SIG, WARN ) \
@@ -57,20 +55,23 @@ extern "C" {
5755}
5856
5957template <typename T>
60- static T *GetFnPtr (T *Fun, T *FunDef, const char *FnName, bool WarnIfMissing) {
58+ static T *GetFnPtr (void *Fun, void *FunDef, const char *FnName,
59+ bool WarnIfMissing) {
6160 if (Fun == FunDef) {
6261 if (WarnIfMissing)
6362 Printf (" WARNING: Failed to find function \" %s\" .\n " , FnName);
6463 return nullptr ;
6564 }
66- return Fun;
65+ return (T *) Fun;
6766}
6867
6968namespace fuzzer {
7069
7170ExternalFunctions::ExternalFunctions () {
72- #define EXT_FUNC (NAME, RETURN_TYPE, FUNC_SIG, WARN ) \
73- this ->NAME = GetFnPtr<decltype (::NAME)>(::NAME, ::NAME##Def, #NAME, WARN);
71+ #define EXT_FUNC (NAME, RETURN_TYPE, FUNC_SIG, WARN ) \
72+ this ->NAME = GetFnPtr<decltype (::NAME)>(GET_FUNCTION_ADDRESS (::NAME), \
73+ GET_FUNCTION_ADDRESS (::NAME##Def), \
74+ #NAME, WARN);
7475
7576#include " FuzzerExtFunctions.def"
7677
0 commit comments