about summary refs log tree commit diff
path: root/src/aflrun-cc.c
blob: 2b12c41344b7e68bb4f802ba51894fadaa7c67c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

#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;
}