about summary refs log tree commit diff
path: root/instrumentation/afl-compiler-rt.o.c
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2020-09-08 15:21:55 +0200
committerGitHub <noreply@github.com>2020-09-08 15:21:55 +0200
commit3890225c35413ca33a28495ce2f97b0256ad9791 (patch)
treed8fe0fe7e79dd5458d393de4df1fd0bfa62b9888 /instrumentation/afl-compiler-rt.o.c
parent43cb626ad3d36024529ddc459032e664282f3cab (diff)
parent9544b3dbf22f1007f7d3f77593ec746a0345a587 (diff)
downloadafl++-3890225c35413ca33a28495ce2f97b0256ad9791.tar.gz
Merge pull request #551 from AdaCore/topic/plugin
rewrite gcc plugin
Diffstat (limited to 'instrumentation/afl-compiler-rt.o.c')
-rw-r--r--instrumentation/afl-compiler-rt.o.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c
index a3d75b15..05e2d50d 100644
--- a/instrumentation/afl-compiler-rt.o.c
+++ b/instrumentation/afl-compiler-rt.o.c
@@ -38,7 +38,9 @@
 #include <sys/wait.h>
 #include <sys/types.h>
 
+#if ! __GNUC__
 #include "llvm/Config/llvm-config.h"
+#endif
 
 #ifdef __linux__
   #include "snapshot-inl.h"
@@ -109,14 +111,22 @@ static u8 _is_sancov;
 
 void __afl_trace(const u32 x) {
 
+  PREV_LOC_T prev = __afl_prev_loc[0];
+  __afl_prev_loc[0] = (x >> 1);
+
+  u8 *p = &__afl_area_ptr[prev ^ x];
+
 #if 1                                      /* enable for neverZero feature. */
-  __afl_area_ptr[__afl_prev_loc[0] ^ x] +=
-      1 + ((u8)(1 + __afl_area_ptr[__afl_prev_loc[0] ^ x]) == 0);
+# if __GNUC__
+  u8 c = __builtin_add_overflow (*p, 1, p);
+  *p += c;
+# else
+  *p += 1 + ((u8)(1 + *p == 0);
+# endif
 #else
-  ++__afl_area_ptr[__afl_prev_loc[0] ^ x];
+  ++*p;
 #endif
 
-  __afl_prev_loc[0] = (x >> 1);
   return;
 
 }