mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
test: only declare a main() when fuzzing with AFL
libFuzzer will provide a main(). This also fixes a weak linking issue when fuzzing with libFuzzer on macOS.
This commit is contained in:
parent
fe48ac8580
commit
b35567fe0b
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
||||||
|
|
||||||
|
#if defined(__AFL_COMPILER)
|
||||||
static bool read_stdin(std::vector<uint8_t>& data)
|
static bool read_stdin(std::vector<uint8_t>& data)
|
||||||
{
|
{
|
||||||
uint8_t buffer[1024];
|
uint8_t buffer[1024];
|
||||||
@ -23,6 +24,7 @@ static bool read_stdin(std::vector<uint8_t>& data)
|
|||||||
}
|
}
|
||||||
return length == 0;
|
return length == 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Default initialization: Override using a non-weak initialize().
|
// Default initialization: Override using a non-weak initialize().
|
||||||
__attribute__((weak)) void initialize()
|
__attribute__((weak)) void initialize()
|
||||||
@ -44,9 +46,9 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Declare main(...) "weak" to allow for libFuzzer linking. libFuzzer provides
|
// Generally, the fuzzer will provide main(), except for AFL
|
||||||
// the main(...) function.
|
#if defined(__AFL_COMPILER)
|
||||||
__attribute__((weak)) int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
initialize();
|
initialize();
|
||||||
#ifdef __AFL_INIT
|
#ifdef __AFL_INIT
|
||||||
@ -74,3 +76,4 @@ __attribute__((weak)) int main(int argc, char** argv)
|
|||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user