aboutsummaryrefslogtreecommitdiff
path: root/gcc_plugin
diff options
context:
space:
mode:
authorhexcoder- <heiko@hexco.de>2019-10-18 19:53:10 +0200
committerhexcoder- <heiko@hexco.de>2019-10-18 19:53:10 +0200
commite7ab8be0cd97f9a18e6ca2f855afa69768322dfb (patch)
treed8248acacb9135473f35da77c832eddf4ae3d949 /gcc_plugin
parentb1822f26022c323e4b47198abbb7d5f5ea6a57e5 (diff)
downloadafl++-e7ab8be0cd97f9a18e6ca2f855afa69768322dfb.tar.gz
sync afl-fast-gcc with afl-clang-fast, add tests for gcc_plugin
Diffstat (limited to 'gcc_plugin')
-rw-r--r--gcc_plugin/afl-gcc-fast.c50
-rw-r--r--gcc_plugin/afl-gcc-pass.so.cc4
2 files changed, 36 insertions, 18 deletions
diff --git a/gcc_plugin/afl-gcc-fast.c b/gcc_plugin/afl-gcc-fast.c
index 8be05bb5..25ecf310 100644
--- a/gcc_plugin/afl-gcc-fast.c
+++ b/gcc_plugin/afl-gcc-fast.c
@@ -104,7 +104,7 @@ static void edit_params(u32 argc, char** argv) {
cc_params = ck_alloc((argc + 64) * sizeof(u8*));
name = strrchr(argv[0], '/');
- if (!name) name = argv[0]; else name++;
+ if (!name) name = argv[0]; else ++name;
if (!strcmp(name, "afl-g++-fast")) {
u8* alt_cxx = getenv("AFL_CXX");
@@ -114,9 +114,15 @@ static void edit_params(u32 argc, char** argv) {
cc_params[0] = alt_cc ? alt_cc : (u8*)"gcc";
}
+
+
char* fplugin_arg = alloc_printf("-fplugin=%s/afl-gcc-pass.so", obj_path);
cc_params[cc_par_cnt++] = fplugin_arg;
+ /* Detect stray -v calls from ./configure scripts. */
+
+ if (argc == 1 && !strcmp(argv[1], "-v")) maybe_linking = 0;
+
while (--argc) {
u8* cur = *(++argv);
@@ -134,6 +140,8 @@ static void edit_params(u32 argc, char** argv) {
if (strstr(cur, "FORTIFY_SOURCE")) fortify_set = 1;
+ if (!strcmp(cur, "-shared")) maybe_linking = 0;
+
cc_params[cc_par_cnt++] = cur;
}
@@ -151,17 +159,23 @@ static void edit_params(u32 argc, char** argv) {
if (getenv("AFL_USE_ASAN")) {
- cc_params[cc_par_cnt++] = "-fsanitize=address";
+ if (getenv("AFL_USE_MSAN")) FATAL("ASAN and MSAN are mutually exclusive");
+
+ if (getenv("AFL_HARDEN"))
+ FATAL("ASAN and AFL_HARDEN are mutually exclusive");
- if (getenv("AFL_USE_MSAN"))
- FATAL("ASAN and MSAN are mutually exclusive");
+ cc_params[cc_par_cnt++] = "-U_FORTIFY_SOURCE";
+ cc_params[cc_par_cnt++] = "-fsanitize=address";
} else if (getenv("AFL_USE_MSAN")) {
- cc_params[cc_par_cnt++] = "-fsanitize=memory";
+ if (getenv("AFL_USE_ASAN")) FATAL("ASAN and MSAN are mutually exclusive");
+
+ if (getenv("AFL_HARDEN"))
+ FATAL("MSAN and AFL_HARDEN are mutually exclusive");
- if (getenv("AFL_USE_ASAN"))
- FATAL("ASAN and MSAN are mutually exclusive");
+ cc_params[cc_par_cnt++] = "-U_FORTIFY_SOURCE";
+ cc_params[cc_par_cnt++] = "-fsanitize=memory";
}
@@ -175,7 +189,13 @@ static void edit_params(u32 argc, char** argv) {
}
+#ifdef USEMMAP
+ cc_params[cc_par_cnt++] = "-lrt";
+#endif
+
cc_params[cc_par_cnt++] = "-D__AFL_HAVE_MANUAL_CONTROL=1";
+ cc_params[cc_par_cnt++] = "-D__AFL_COMPILER=1";
+ cc_params[cc_par_cnt++] = "-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1";
/* When the user tries to use persistent or deferred forkserver modes by
appending a single line to the program, we want to reliably inject a
@@ -237,15 +257,10 @@ static void edit_params(u32 argc, char** argv) {
int main(int argc, char** argv) {
- if (isatty(2) && !getenv("AFL_QUIET")) {
-
- SAYF(cCYA "afl-gcc-fast " cBRI VERSION cRST " initially by <aseipp@pobox.com>, maintainer: hexcoder-\n");
-
- }
-
- if (argc < 2) {
+ if (argc < 2 || strcmp(argv[1], "-h") == 0) {
- SAYF("\n"
+ printf(cCYA "afl-gcc-fast" VERSION cRST " initially by <aseipp@pobox.com>, maintainer: hexcoder-\n"
+ "\n"
"This is a helper application for afl-fuzz. It serves as a drop-in replacement\n"
"for gcc, letting you recompile third-party code with the required runtime\n"
"instrumentation. A common use pattern would be one of the following:\n\n"
@@ -263,8 +278,11 @@ int main(int argc, char** argv) {
exit(1);
- }
+ } else if (isatty(2) && !getenv("AFL_QUIET")) {
+ SAYF(cCYA "afl-gcc-fast" VERSION cRST " initially by <aseipp@pobox.com>, maintainer: hexcoder-\n");
+
+ }
find_obj(argv[0]);
diff --git a/gcc_plugin/afl-gcc-pass.so.cc b/gcc_plugin/afl-gcc-pass.so.cc
index f0f5b30b..a44f5a74 100644
--- a/gcc_plugin/afl-gcc-pass.so.cc
+++ b/gcc_plugin/afl-gcc-pass.so.cc
@@ -416,7 +416,7 @@ public:
/* Either we couldn't figure out our location or the location is
* not whitelisted, so we skip instrumentation. */
- if (!instrumentBlock) return 0;;
+ if (!instrumentBlock) return 0;
}
return do_ext_call ? ext_call_instrument(fun) : inline_instrument(fun);
@@ -464,7 +464,7 @@ int plugin_init(struct plugin_name_args *plugin_info,
/* Show a banner */
if (isatty(2) && !getenv("AFL_QUIET")) {
- SAYF(G_(cCYA "afl-gcc-pass " cBRI VERSION cRST " initially by <aseipp@pobox.com>, maintainer: hexcoder-\n"));
+ SAYF(G_(cCYA "afl-gcc-pass" VERSION cRST " initially by <aseipp@pobox.com>, maintainer: hexcoder-\n"));
} else
be_quiet = 1;