diff options
author | van Hauser <vh@thc.org> | 2020-04-08 17:57:11 +0200 |
---|---|---|
committer | van Hauser <vh@thc.org> | 2020-04-09 10:23:37 +0200 |
commit | 698caed9c0b8c06d2576dcc866f654d6ada74235 (patch) | |
tree | d83bc1f7875496b293e1cc2dff1b1ba3d4557c16 /llvm_mode/afl-llvm-pass.so.cc | |
parent | ae05f5c4b0611fe05a38a0c293c2d251085f510f (diff) | |
download | afl++-698caed9c0b8c06d2576dcc866f654d6ada74235.tar.gz |
llvm_mode ctx: move function terminator instrumentation before skipping blocks
Diffstat (limited to 'llvm_mode/afl-llvm-pass.so.cc')
-rw-r--r-- | llvm_mode/afl-llvm-pass.so.cc | 35 |
1 files changed, 18 insertions, 17 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++; } |