This repository has been archived by the owner on Sep 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
afl-llvm-optimize.diff
67 lines (57 loc) · 2.03 KB
/
afl-llvm-optimize.diff
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--- llvm_mode/afl-llvm-pass.so.cc.orig 2019-01-03 19:37:23.641280087 +0100
+++ llvm_mode/afl-llvm-pass.so.cc 2019-01-04 10:31:02.999576722 +0100
@@ -31,12 +31,22 @@
#include <stdlib.h>
#include <unistd.h>
+#include "llvm/IR/BasicBlock.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/CFG.h"
+#include <algorithm>
using namespace llvm;
@@ -69,6 +79,7 @@
IntegerType *Int8Ty = IntegerType::getInt8Ty(C);
IntegerType *Int32Ty = IntegerType::getInt32Ty(C);
+ unsigned int cur_loc = 0;
/* Show a banner */
@@ -118,7 +129,32 @@
/* Make up cur_loc */
- unsigned int cur_loc = AFL_R(MAP_SIZE);
+ //cur_loc++;
+ cur_loc = AFL_R(MAP_SIZE);
+
+ // only instrument if this basic block is the destination of a previous
+ // basic block that has multiple successors
+ // this gets rid of ~5-10% of instrumentations that are unnecessary
+ // result: a little more speed and less map pollution
+ int more_than_one = -1;
+ //fprintf(stderr, "BB %u: ", cur_loc);
+ for (BasicBlock *Pred : predecessors(&BB)) {
+ int count = 0;
+ if (more_than_one == -1)
+ more_than_one = 0;
+ //fprintf(stderr, " %p=>", Pred);
+ for (BasicBlock *Succ : successors(Pred)) {
+ //if (count > 0)
+ // fprintf(stderr, "|");
+ if (Succ != NULL) count++;
+ //fprintf(stderr, "%p", Succ);
+ }
+ if (count > 1)
+ more_than_one = 1;
+ }
+ //fprintf(stderr, " == %d\n", more_than_one);
+ if (more_than_one != 1)
+ continue;
ConstantInt *CurLoc = ConstantInt::get(Int32Ty, cur_loc);