First, install the latest LLVM from the official APT repository.
Then, clone AFLplusplus and run the following commands.
Fighting compiler optimization
A simple trick to avoid entire for loops and function calls be optimized away, store the result in an iteration or of the function in a volatile variable is the simplest without side-effects like printf.
Build Flags
Without -O flags, afl-cc will add -O3. Besides, -g is always added.
Last line of output should be [+] Instrumented ... (non-hardened mode) or (non-hardened, ASAN, UBSAN mode) with sanitizers.
Prepare Input
IMPORTANT: if you use afl-cmin or afl-cmin.bash, then either pass - or @@ as command line parameters.
Run
libFuzzer
Build Flags
Note: during configure phase, if AddressSanitizer discovers a crash, it will silently disable the feature.
FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION is proposed by libFuzzer authors as a common build macro for fuzzing-friendly build.