Skip to content

Commit 1087807

Browse files
tests: Provide main(...) function in fuzzer
1 parent 80fd474 commit 1087807

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/test/fuzz/fuzz.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212

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

15-
#if defined(__AFL_COMPILER)
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+
24+
#if defined(PROVIDE_MAIN_FUNCTION)
1625
static bool read_stdin(std::vector<uint8_t>& data)
1726
{
1827
uint8_t buffer[1024];
@@ -44,9 +53,8 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
4453
return 0;
4554
}
4655

47-
// Generally, the fuzzer will provide main(), except for AFL
48-
#if defined(__AFL_COMPILER)
49-
int main(int argc, char** argv)
56+
#if defined(PROVIDE_MAIN_FUNCTION)
57+
__attribute__((weak)) int main(int argc, char** argv)
5058
{
5159
initialize();
5260
#ifdef __AFL_INIT

0 commit comments

Comments
 (0)