|
| 1 | +diff --git a/GNUmakefile.llvm b/GNUmakefile.llvm |
| 2 | +index 685964b7..9f309c08 100644 |
| 3 | +--- a/GNUmakefile.llvm |
| 4 | ++++ b/GNUmakefile.llvm |
| 5 | +@@ -308,7 +308,7 @@ ifeq "$(TEST_MMAP)" "1" |
| 6 | + endif |
| 7 | + |
| 8 | + PROGS_ALWAYS = ./afl-cc ./afl-compiler-rt.o ./afl-compiler-rt-32.o ./afl-compiler-rt-64.o |
| 9 | +-PROGS = $(PROGS_ALWAYS) ./afl-llvm-pass.so ./SanitizerCoveragePCGUARD.so ./split-compares-pass.so ./split-switches-pass.so ./cmplog-routines-pass.so ./cmplog-instructions-pass.so ./cmplog-switches-pass.so ./afl-llvm-dict2file.so ./compare-transform-pass.so ./afl-ld-lto ./afl-llvm-lto-instrumentlist.so ./SanitizerCoverageLTO.so |
| 10 | ++PROGS = $(PROGS_ALWAYS) ./afl-llvm-pass.so ./SanitizerCoveragePCGUARD.so ./split-compares-pass.so ./split-switches-pass.so ./cmplog-routines-pass.so ./cmplog-instructions-pass.so ./cmplog-switches-pass.so ./afl-llvm-dict2file.so ./compare-transform-pass.so ./afl-ld-lto ./afl-llvm-lto-instrumentlist.so ./SanitizerCoverageLTO.so ./afl-demo-pass.so ./afl-demo-rt.o |
| 11 | + |
| 12 | + # If prerequisites are not given, warn, do not build anything, and exit with code 0 |
| 13 | + ifeq "$(LLVMVER)" "" |
| 14 | +@@ -436,6 +436,9 @@ endif |
| 15 | + afl-llvm-dict2file.so: instrumentation/afl-llvm-dict2file.so.cc instrumentation/afl-llvm-common.o | test_deps |
| 16 | + $(CXX) $(CLANG_CPPFL) -shared $< -o $@ $(CLANG_LFL) instrumentation/afl-llvm-common.o |
| 17 | + |
| 18 | ++afl-demo-pass.so: instrumentation/afl-demo-pass.so.cc instrumentation/afl-llvm-common.o | test_deps |
| 19 | ++ $(CXX) $(CLANG_CPPFL) -shared $< -o $@ $(CLANG_LFL) |
| 20 | ++ |
| 21 | + .PHONY: document |
| 22 | + document: |
| 23 | + $(CLANG_BIN) -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS_SAFE) $(CPPFLAGS) $(CLANG_CFL) -O3 -Wno-unused-result -fPIC -c instrumentation/afl-compiler-rt.o.c -o ./afl-compiler-rt.o |
| 24 | +@@ -453,6 +456,9 @@ document: |
| 25 | + @printf "[*] Building 64-bit variant of the runtime (-m64)... " |
| 26 | + @$(CC) $(CLANG_CFL) $(CFLAGS_SAFE) $(CPPFLAGS) -O3 -Wno-unused-result -m64 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi |
| 27 | + |
| 28 | ++./afl-demo-rt.o: instrumentation/afl-demo-rt.o.c |
| 29 | ++ $(CC) $(CLANG_CFL) $(CFLAGS_SAFE) $(CPPFLAGS) -O3 -Wno-unused-result -fPIC -c $< -o $@ |
| 30 | ++ |
| 31 | + .PHONY: test_build |
| 32 | + test_build: $(PROGS) |
| 33 | + @echo "[*] Testing the CC wrapper and instrumentation output..." |
| 34 | +@@ -475,6 +481,7 @@ install: all |
| 35 | + @if [ -f ./afl-cc ]; then set -e; install -m 755 ./afl-cc $${DESTDIR}$(BIN_PATH); ln -sf afl-cc $${DESTDIR}$(BIN_PATH)/afl-c++; fi |
| 36 | + @rm -f $${DESTDIR}$(HELPER_PATH)/afl-llvm-rt*.o $${DESTDIR}$(HELPER_PATH)/afl-gcc-rt*.o |
| 37 | + @if [ -f ./afl-compiler-rt.o ]; then set -e; install -m 755 ./afl-compiler-rt.o $${DESTDIR}$(HELPER_PATH); fi |
| 38 | ++ @if [ -f ./afl-demo-rt.o ]; then set -e; install -m 755 ./afl-demo-rt.o $${DESTDIR}$(HELPER_PATH); fi |
| 39 | + @if [ -f ./afl-lto ]; then set -e; ln -sf afl-cc $${DESTDIR}$(BIN_PATH)/afl-lto; ln -sf afl-cc $${DESTDIR}$(BIN_PATH)/afl-lto++; ln -sf afl-cc $${DESTDIR}$(BIN_PATH)/afl-clang-lto; ln -sf afl-cc $${DESTDIR}$(BIN_PATH)/afl-clang-lto++; install -m 755 ./afl-llvm-rt-lto*.o ./afl-llvm-lto-instrumentlist.so $${DESTDIR}$(HELPER_PATH); fi |
| 40 | + @if [ -f ./afl-ld-lto ]; then set -e; install -m 755 ./afl-ld-lto $${DESTDIR}$(BIN_PATH); fi |
| 41 | + @if [ -f ./afl-compiler-rt-32.o ]; then set -e; install -m 755 ./afl-compiler-rt-32.o $${DESTDIR}$(HELPER_PATH); fi |
| 42 | +diff --git a/include/envs.h b/include/envs.h |
| 43 | +index 25b792fa..bbe9a99e 100644 |
| 44 | +--- a/include/envs.h |
| 45 | ++++ b/include/envs.h |
| 46 | +@@ -226,6 +226,7 @@ static char *afl_environment_variables[] = { |
| 47 | + "AFL_USE_QASAN", |
| 48 | + "AFL_PRINT_FILENAMES", |
| 49 | + "AFL_PIZZA_MODE", |
| 50 | ++ "AFL_DEMO", |
| 51 | + NULL |
| 52 | + |
| 53 | + }; |
| 54 | +diff --git a/src/afl-cc.c b/src/afl-cc.c |
| 55 | +index 2667ae28..7da0b89c 100644 |
| 56 | +--- a/src/afl-cc.c |
| 57 | ++++ b/src/afl-cc.c |
| 58 | +@@ -57,6 +57,7 @@ static u8 * lto_flag = AFL_CLANG_FLTO, *argvnull; |
| 59 | + static u8 debug; |
| 60 | + static u8 cwd[4096]; |
| 61 | + static u8 cmplog_mode; |
| 62 | ++static u8 demo_mode; |
| 63 | + u8 use_stdin; /* dummy */ |
| 64 | + static int passthrough; |
| 65 | + // static u8 *march_opt = CFLAGS_OPT; |
| 66 | +@@ -699,6 +700,23 @@ static void edit_params(u32 argc, char **argv, char **envp) { |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | ++ |
| 71 | ++ if (demo_mode) { |
| 72 | ++ |
| 73 | ++#if LLVM_MAJOR >= 11 |
| 74 | ++ cc_params[cc_par_cnt++] = "-fexperimental-new-pass-manager"; |
| 75 | ++ cc_params[cc_par_cnt++] = alloc_printf( |
| 76 | ++ "-fpass-plugin=%s/afl-demo-pass.so", obj_path); |
| 77 | ++#else |
| 78 | ++ cc_params[cc_par_cnt++] = "-Xclang"; |
| 79 | ++ cc_params[cc_par_cnt++] = "-load"; |
| 80 | ++ cc_params[cc_par_cnt++] = "-Xclang"; |
| 81 | ++ cc_params[cc_par_cnt++] = |
| 82 | ++ alloc_printf("%s/afl-demo-pass.so", obj_path); |
| 83 | ++#endif |
| 84 | ++ |
| 85 | ++ } |
| 86 | ++ |
| 87 | + // cc_params[cc_par_cnt++] = "-Qunused-arguments"; |
| 88 | + |
| 89 | + if (lto_mode && argc > 1) { |
| 90 | +@@ -1100,6 +1118,9 @@ static void edit_params(u32 argc, char **argv, char **envp) { |
| 91 | + if (lto_mode) |
| 92 | + cc_params[cc_par_cnt++] = |
| 93 | + alloc_printf("%s/afl-llvm-rt-lto.o", obj_path); |
| 94 | ++ if (demo_mode) |
| 95 | ++ cc_params[cc_par_cnt++] = |
| 96 | ++ alloc_printf("%s/afl-demo-rt.o", obj_path); |
| 97 | + break; |
| 98 | + |
| 99 | + case 32: |
| 100 | +@@ -2153,6 +2174,8 @@ int main(int argc, char **argv, char **envp) { |
| 101 | + if (!be_quiet && cmplog_mode) |
| 102 | + printf("CmpLog mode by <andreafioraldi@gmail.com>\n"); |
| 103 | + |
| 104 | ++ demo_mode = !!getenv("AFL_DEMO"); |
| 105 | ++ |
| 106 | + #if !defined(__ANDROID__) && !defined(ANDROID) |
| 107 | + ptr = find_object("afl-compiler-rt.o", argv[0]); |
| 108 | + |
0 commit comments