fix static and profiling compilation and add profiling calculation
MODIFY
GNUmakefile
GNUmakefile
@@ -52,12 +52,28 @@ endif
ifneq "$(shell uname)" "Darwin"
ifeq "$(shell echo 'int main() {return 0; }' | $(CC) $(CFLAGS) -Werror -x c - -march=native -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
- CFLAGS_OPT = -march=native
+ CFLAGS_OPT += -march=native
endif
# OS X does not like _FORTIFY_SOURCE=2
CFLAGS_OPT += -D_FORTIFY_SOURCE=2
endif
+ifdef STATIC
+ $(info Compiling static version of binaries)
+ # Disable python for static compilation to simplify things
+ PYTHON_OK=0
+ PYFLAGS=
+
+ CFLAGS_OPT += -static
+ LDFLAGS += -lm -lpthread -lz -lutil
+endif
+
+ifdef PROFILING
+ $(info Compiling with profiling information, for analysis: gprof ./afl-fuzz gmon.out > prof.txt)
+ CFLAGS_OPT += -pg -DPROFILING=1
+ LDFLAGS += -pg
+endif
+
ifneq "$(shell uname -m)" "x86_64"
ifneq "$(patsubst i%86,i386,$(shell uname -m))" "i386"
ifneq "$(shell uname -m)" "amd64"
@@ -184,18 +200,8 @@ ifeq "$(shell svn proplist . 2>/dev/null && echo 1 || echo 0)" "1"
IN_REPO=1
endif
-ifdef STATIC
- $(info Compiling static version of binaries)
- # Disable python for static compilation to simplify things
- PYTHON_OK=0
- PYFLAGS=
-
- CFLAGS += -static
- LDFLAGS += -lm -lpthread -lz -lutil
-endif
-
ASAN_CFLAGS=-fsanitize=address -fstack-protector-all -fno-omit-frame-pointer
-ASAN_LDFLAGS+=-fsanitize=address -fstack-protector-all -fno-omit-frame-pointer
+ASAN_LDFLAGS=-fsanitize=address -fstack-protector-all -fno-omit-frame-pointer
ifdef ASAN_BUILD
$(info Compiling ASAN version of binaries)
@@ -203,12 +209,6 @@ ifdef ASAN_BUILD
LDFLAGS+=$(ASAN_LDFLAGS)
endif
-ifdef PROFILING
- $(info Compiling with profiling information, for analysis: gprof ./afl-fuzz gmon.out > prof.txt)
- CFLAGS+=-pg
- LDFLAGS+=-pg
-endif
-
ifeq "$(shell echo '$(HASH)include <sys/ipc.h>@$(HASH)include <sys/shm.h>@int main() { int _id = shmget(IPC_PRIVATE, 65536, IPC_CREAT | IPC_EXCL | 0600); shmctl(_id, IPC_RMID, 0); return 0;}' | tr @ '\n' | $(CC) $(CFLAGS) -x c - -o .test2 2>/dev/null && echo 1 || echo 0 ; rm -f .test2 )" "1"
SHMAT_OK=1
else

MODIFY
src/afl-fuzz-run.c
src/afl-fuzz-run.c
#include "cmplog.h"
+#ifdef PROFILING
+u64 time_spent_working = 0;
+#endif
+
/* Execute target application, monitoring for timeouts. Return status
information. The called program will update afl->fsrv->trace_bits. */
fsrv_run_result_t fuzz_run_target(afl_state_t *afl, afl_forkserver_t *fsrv,
u32 timeout) {
+#ifdef PROFILING
+ static u64 time_spent_start = 0;
+ struct timespec spec;
+ if (time_spent_start) {
+
+ u64 current;
+ clock_gettime(CLOCK_REALTIME, &spec);
+ current = (spec.tv_sec * 1000000000) + spec.tv_nsec;
+ time_spent_working += (current - time_spent_start);
+
+ }
+
+#endif
+
fsrv_run_result_t res = afl_fsrv_run_target(fsrv, timeout, &afl->stop_soon);
+
+#ifdef PROFILING
+ clock_gettime(CLOCK_REALTIME, &spec);
+ time_spent_start = (spec.tv_sec * 1000000000) + spec.tv_nsec;
+#endif
+
// TODO: Don't classify for faults?
classify_counts(fsrv);
return res;

MODIFY
src/afl-fuzz.c
src/afl-fuzz.c
#include "cmplog.h"
#include <limits.h>
+#ifdef PROFILING
+extern u64 time_spent_working;
+#endif
+
static u8 *get_libradamsa_path(u8 *own_loc) {
u8 *tmp, *cp, *rsl, *own_copy;
@@ -1351,6 +1355,13 @@ stop_fuzzing:
}
+#ifdef PROFILING
+ SAYF(cYEL "[!] " cRST
+ "Profiling information: %llu ms total work, %llu ns/run\n",
+ time_spent_working / 1000000,
+ time_spent_working / afl->fsrv.total_execs);
+#endif
+
fclose(afl->fsrv.plot_file);
destroy_queue(afl);
destroy_extras(afl);

fix static and profiling compilation and add profiling calculation