Skip to content

Commit fae7a1c

Browse files
author
MarcoFalke
committed
fuzz: Configure check for main function
1 parent 54fc96f commit fae7a1c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

configure.ac

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,20 @@ if test "x$enable_fuzz" = "xyes"; then
11651165
use_bench=no
11661166
use_upnp=no
11671167
use_zmq=no
1168+
1169+
AC_MSG_CHECKING([whether main function is needed])
1170+
AX_CHECK_LINK_FLAG(
1171+
[[-fsanitize=$use_sanitizers]],
1172+
[AC_MSG_RESULT([no])],
1173+
[AC_MSG_RESULT([yes])
1174+
CPPFLAGS="$CPPFLAGS -DPROVIDE_MAIN_FUNCTION"],
1175+
[],
1176+
[AC_LANG_PROGRAM([[
1177+
#include <cstdint>
1178+
#include <cstddef>
1179+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { return 0; }
1180+
/* unterminated comment to remove the main function ...
1181+
]],[[]])])
11681182
else
11691183
BITCOIN_QT_INIT
11701184

src/test/fuzz/fuzz.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@
1212

1313
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
1414

15-
// Decide if main(...) should be provided:
16-
// * AFL needs main(...) regardless of platform.
17-
// * macOS handles __attribute__((weak)) main(...) poorly when linking
18-
// against libFuzzer. See https://github.com/bitcoin/bitcoin/pull/18008
19-
// for details.
20-
#if defined(__AFL_COMPILER) || !defined(MAC_OSX)
21-
#define PROVIDE_MAIN_FUNCTION
22-
#endif
23-
2415
#if defined(PROVIDE_MAIN_FUNCTION)
2516
static bool read_stdin(std::vector<uint8_t>& data)
2617
{

0 commit comments

Comments
 (0)