Make sure that the persistent signature is never optimized # missing include
+#include <string.h>
+
#include "honggfuzz.h"
#include "libhfuzz/persistent.h"
@@ -14,6 +16,14 @@ __attribute__((used)) const char* LIBHFUZZ_module_main = _HF_PERSISTENT_SIG;
#if !defined(__CYGWIN__)
__attribute__((weak))
#endif /* !defined(__CYGWIN__) */
-int main(int argc, char** argv) {
+main(int argc, char** argv) {
+ /*
+ * getpid() never returns -2, so it's only to reference the persistent
+ * signature, to prevent optimizing it out by clever compiler/link
+ * optimizers
+ */
+ if (getpid() == -2) {
+ return strlen(LIBHFUZZ_module_main);
+ }
return HonggfuzzMain(argc, argv);
}
