14
14
15
15
#include " FuzzerExtFunctions.h"
16
16
#include " FuzzerIO.h"
17
+ #include < stdlib.h>
17
18
18
19
using namespace fuzzer ;
19
20
@@ -22,6 +23,11 @@ using namespace fuzzer;
22
23
#define STRINGIFY (A ) STRINGIFY_(A)
23
24
24
25
#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
+
25
31
// Copied from compiler-rt/lib/sanitizer_common/sanitizer_win_defs.h
26
32
#if defined(_M_IX86) || defined(__i386__)
27
33
#define WIN_SYM_PREFIX " _"
@@ -31,17 +37,9 @@ using namespace fuzzer;
31
37
32
38
// Declare external functions as having alternativenames, so that we can
33
39
// 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 ( \
36
42
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
45
43
46
44
extern "C" {
47
45
#define EXT_FUNC (NAME, RETURN_TYPE, FUNC_SIG, WARN ) \
@@ -57,20 +55,23 @@ extern "C" {
57
55
}
58
56
59
57
template <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) {
61
60
if (Fun == FunDef) {
62
61
if (WarnIfMissing)
63
62
Printf (" WARNING: Failed to find function \" %s\" .\n " , FnName);
64
63
return nullptr ;
65
64
}
66
- return Fun;
65
+ return (T *) Fun;
67
66
}
68
67
69
68
namespace fuzzer {
70
69
71
70
ExternalFunctions::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);
74
75
75
76
#include " FuzzerExtFunctions.def"
76
77
0 commit comments