mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
Merge #18008: test: only declare a main() when fuzzing with AFL
b35567fe0b
test: only declare a main() when fuzzing with AFL (fanquake) Pull request description: This fixes fuzzing using [libFuzzer](https://llvm.org/docs/LibFuzzer.html) on macOS, which caused a few issues during the recent review club. macOS users could only fuzz using afl, or inside a VM. It seems that the `__attribute__((weak))` marking is not quite enough to properly mark `main()` as weak on macOS. See Apples docs on [Frameworks and Weak Linking](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html#//apple_ref/doc/uid/20002378-107262-CJBJAEID). Have tested fuzzing using libFuzzer and AFL with this patch. ACKs for top commit: MarcoFalke: ACKb35567fe0b
fjahr: ACKb35567f
Tree-SHA512: b881fdd98c7e1587fcf44debd31f5e7a52df938059ab91c41d0785077b3329b793e051a2bf2eee64488b9f6029d9288c911052ec23ab3ab8c0561a2be1682dae
This commit is contained in:
commit
c434282d2c
@ -12,6 +12,7 @@
|
||||
|
||||
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
||||
|
||||
#if defined(__AFL_COMPILER)
|
||||
static bool read_stdin(std::vector<uint8_t>& data)
|
||||
{
|
||||
uint8_t buffer[1024];
|
||||
@ -23,6 +24,7 @@ static bool read_stdin(std::vector<uint8_t>& data)
|
||||
}
|
||||
return length == 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Default initialization: Override using a non-weak initialize().
|
||||
__attribute__((weak)) void initialize()
|
||||
@ -44,9 +46,9 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Declare main(...) "weak" to allow for libFuzzer linking. libFuzzer provides
|
||||
// the main(...) function.
|
||||
__attribute__((weak)) int main(int argc, char** argv)
|
||||
// Generally, the fuzzer will provide main(), except for AFL
|
||||
#if defined(__AFL_COMPILER)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
initialize();
|
||||
#ifdef __AFL_INIT
|
||||
@ -74,3 +76,4 @@ __attribute__((weak)) int main(int argc, char** argv)
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user