Skip to content

Commit b337bd7

Browse files
author
MarcoFalke
committed
Merge #20065: fuzz: Configure check for main function
fae7a1c fuzz: Configure check for main function (MarcoFalke) Pull request description: Instead of the PP jungle, use a proper configure check Fixes google/honggfuzz#336 (comment) ACKs for top commit: practicalswift: ACK fae7a1c Tree-SHA512: 2e55457d01f9ac598bb1e119d8b49dca55a28f88ec164cee6b5f071c29e9791f5a46cc8ee2b801b3a3faf906348da964ce32e7254da981c1104b9210a3508100
2 parents 9dd4de2 + fae7a1c commit b337bd7

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)