From d04bdf2e841fa6706c16bbba1cb6f6c73d647767 Mon Sep 17 00:00:00 2001 From: Huanyao Rong Date: Fri, 21 Jun 2024 21:03:37 -0700 Subject: Implement AFLRun References: https://github.com/Mem2019/AFLRun/commit/f5bb87f78ef1 References: https://github.com/Mem2019/AFLRun/commit/3af5f11b5644 --- src/aflrun-cc.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/aflrun-cc.c (limited to 'src/aflrun-cc.c') diff --git a/src/aflrun-cc.c b/src/aflrun-cc.c new file mode 100644 index 00000000..2b12c413 --- /dev/null +++ b/src/aflrun-cc.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include "debug.h" +#include "alloc-inl.h" + +/* This compiler is used to handle cases where we cannot designate compiler +via $CC and $CXX, but instead we can only replace their compiler with the AFL one. +For example, when compiling chroimium/v8. */ + +int main(int argc, char const *argv[]) +{ + char const** new_argv = (char const**)malloc((argc + 1) * sizeof(char*)); + + char* afl_path = getenv("AFL_PATH"); + if (afl_path == NULL) + FATAL("Please specify AFL_PATH"); + + new_argv[0] = alloc_printf("%s/%s", afl_path, + strstr(argv[0], "++") == NULL ? "afl-clang-lto" : "afl-clang-lto++"); + for (int i = 1; i < argc; ++i) + new_argv[i] = argv[i]; + new_argv[argc] = NULL; + + execvp(new_argv[0], (char**)new_argv); + + return 0; +} -- cgit 1.4.1