shithub: puzzles

Download patch

ref: 015bd1447472f82a5607ecb5fabaf25bf37cd4e2
parent: 80de73a6aa4c4e726860c492d2264d4958a56b0d
author: Ben Harris <bjh21@bjh21.me.uk>
date: Tue Feb 21 16:04:58 EST 2023

Don't give the libFuzzer version of fuzzpuzz a special name

I've changed my mind already.  The other versions of fuzzpuzz all have
different command-line interfaces anyway, so I think the best approach
is to just accept that and decide that precisely how fuzzpuzz works
isn't a defined API.  Fuzzing is inherently not an end-user activity, so
I think it's acceptable to make it a bit inconsistent.

This means that in Clang builds you get the non-libFuzzer version of
fuzzpuzz by default (so you can use it with other fuzzers), but if you
turn on WITH_LIBFUZZER then you'll get the libFuzzer version instead.

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -279,18 +279,15 @@
   write_generated_games_header()
   include(CheckFunctionExists)
   check_function_exists(HF_ITER HAVE_HF_ITER)
+  set(WITH_LIBFUZZER OFF
+    CACHE BOOL "Build fuzzpuzz using Clang's libFuzzer")
   cliprogram(fuzzpuzz fuzzpuzz.c list.c ${puzzle_sources}
-    COMPILE_DEFINITIONS COMBINED $<$<BOOL:${HAVE_HF_ITER}>:HAVE_HF_ITER>)
+    COMPILE_DEFINITIONS COMBINED $<$<BOOL:${WITH_LIBFUZZER}>:OMIT_MAIN>
+    $<$<BOOL:${HAVE_HF_ITER}>:HAVE_HF_ITER>)
   target_include_directories(fuzzpuzz PRIVATE ${generated_include_dir})
-
-  if(CMAKE_C_COMPILER_ID MATCHES "Clang")
-    cliprogram(fuzzpuzz-libfuzzer fuzzpuzz.c list.c ${puzzle_sources}
-      COMPILE_DEFINITIONS COMBINED OMIT_MAIN)
-    target_include_directories(fuzzpuzz-libfuzzer
-      PRIVATE ${generated_include_dir})
-    target_compile_options(fuzzpuzz-libfuzzer PRIVATE -fsanitize=fuzzer)
-    set_target_properties(fuzzpuzz-libfuzzer
-      PROPERTIES LINK_FLAGS -fsanitize=fuzzer)
+  if(WITH_LIBFUZZER)
+    target_compile_options(fuzzpuzz PRIVATE -fsanitize=fuzzer)
+    set_target_properties(fuzzpuzz PROPERTIES LINK_FLAGS -fsanitize=fuzzer)
   endif()
 endif()
 
--- a/fuzzpuzz.c
+++ b/fuzzpuzz.c
@@ -27,11 +27,11 @@
  * You can also use libFuzzer, though it's not really a good fit for
  * Puzzles.  The experimental forking mode seems to work OK:
  *
- * CC=clang cmake -B build-clang
- * cmake --build build-clang --target fuzzpuzz-libfuzzer
+ * CC=clang cmake -B build-clang -DWITH_LIBFUZZER=Y
+ * cmake --build build-clang --target fuzzpuzz
  * mkdir fuzz-corpus && ln icons/''*.sav fuzz-corpus
- * build-clang/fuzzpuzz-libfuzzer -fork=1 -ignore_crashes=1 \
- *   -dict=fuzzpuzz.dict fuzz-corpus
+ * build-clang/fuzzpuzz -fork=1 -ignore_crashes=1 -dict=fuzzpuzz.dict \
+ *   fuzz-corpus
  */
 
 #include <stdbool.h>