Skip to content

Commit

Permalink
tests: Provide main(...) function in fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift committed Jun 25, 2020
1 parent 80fd474 commit 1087807
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/test/fuzz/fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@

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

#if defined(__AFL_COMPILER)
// Decide if main(...) should be provided:
// * AFL needs main(...) regardless of platform.
// * macOS handles __attribute__((weak)) main(...) poorly when linking
// against libFuzzer. See https://github.com/bitcoin/bitcoin/pull/18008
// for details.
#if defined(__AFL_COMPILER) || !defined(MAC_OSX)
#define PROVIDE_MAIN_FUNCTION
#endif

#if defined(PROVIDE_MAIN_FUNCTION)
static bool read_stdin(std::vector<uint8_t>& data)
{
uint8_t buffer[1024];
Expand Down Expand Up @@ -44,9 +53,8 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
return 0;
}

// Generally, the fuzzer will provide main(), except for AFL
#if defined(__AFL_COMPILER)
int main(int argc, char** argv)
#if defined(PROVIDE_MAIN_FUNCTION)
__attribute__((weak)) int main(int argc, char** argv)
{
initialize();
#ifdef __AFL_INIT
Expand Down

0 comments on commit 1087807

Please sign in to comment.