aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2020-04-08 17:57:11 +0200
committervan Hauser <vh@thc.org>2020-04-09 10:23:37 +0200
commit698caed9c0b8c06d2576dcc866f654d6ada74235 (patch)
treed83bc1f7875496b293e1cc2dff1b1ba3d4557c16
parentae05f5c4b0611fe05a38a0c293c2d251085f510f (diff)
downloadafl++-698caed9c0b8c06d2576dcc866f654d6ada74235.tar.gz
llvm_mode ctx: move function terminator instrumentation before skipping blocks
-rw-r--r--llvm_mode/afl-llvm-pass.so.cc35
-rw-r--r--llvm_mode/afl-llvm-rt.o.c2
2 files changed, 19 insertions, 18 deletions
diff --git a/llvm_mode/afl-llvm-pass.so.cc b/llvm_mode/afl-llvm-pass.so.cc
index 058ab71f..b4249802 100644
--- a/llvm_mode/afl-llvm-pass.so.cc
+++ b/llvm_mode/afl-llvm-pass.so.cc
@@ -317,6 +317,7 @@ bool AFLCoverage::runOnModule(Module &M) {
for (auto &F : M) {
+ int has_calls = 0;
if (debug)
fprintf(stderr, "FUNCTION: %s (%zu)\n", F.getName().str().c_str(),
F.size());
@@ -336,7 +337,7 @@ bool AFLCoverage::runOnModule(Module &M) {
// does the function have calls? and is any of the calls larger than one
// basic block?
- int has_calls = 0;
+ has_calls = 0;
for (auto &BB : F) {
if (has_calls) break;
@@ -487,6 +488,22 @@ bool AFLCoverage::runOnModule(Module &M) {
}
+ // in CTX mode we have to restore the original context for the caller -
+ // she might be calling other functions which need the correct CTX
+ if (ctx_str && has_calls) {
+
+ Instruction *Inst = BB.getTerminator();
+ if (isa<ReturnInst>(Inst) || isa<ResumeInst>(Inst)) {
+
+ IRBuilder<> Post_IRB(Inst);
+ StoreInst * RestoreCtx = Post_IRB.CreateStore(PrevCtx, AFLContext);
+ RestoreCtx->setMetadata(M.getMDKindID("nosanitize"),
+ MDNode::get(C, None));
+
+ }
+
+ }
+
if (AFL_R(100) >= inst_ratio) continue;
/* Make up cur_loc */
@@ -682,22 +699,6 @@ bool AFLCoverage::runOnModule(Module &M) {
}
- // in CTX mode we have to restore the original context for the caller -
- // she might be calling other functions which need the correct CTX
- if (ctx_str) {
-
- Instruction *Inst = BB.getTerminator();
- if (isa<ReturnInst>(Inst) || isa<ResumeInst>(Inst)) {
-
- IRBuilder<> Post_IRB(Inst);
- StoreInst * RestoreCtx = Post_IRB.CreateStore(PrevCtx, AFLContext);
- RestoreCtx->setMetadata(M.getMDKindID("nosanitize"),
- MDNode::get(C, None));
-
- }
-
- }
-
inst_blocks++;
}
diff --git a/llvm_mode/afl-llvm-rt.o.c b/llvm_mode/afl-llvm-rt.o.c
index 4b140e14..3651fd97 100644
--- a/llvm_mode/afl-llvm-rt.o.c
+++ b/llvm_mode/afl-llvm-rt.o.c
@@ -78,7 +78,7 @@ __thread u32 __afl_prev_ctx;
__thread u32 __afl_cmp_counter;
#endif
- struct cmp_map *__afl_cmp_map;
+struct cmp_map *__afl_cmp_map;
/* Running in persistent mode? */