From 49de0046e87540bf77e05e8bcbcd6fb12fbbaab6 Mon Sep 17 00:00:00 2001 From: Dongjia Zhang Date: Fri, 24 Jun 2022 00:55:06 +0900 Subject: [PATCH] Fix AFLCoverage Pass & small fixes (#678) * fix * more * declare LIBAFL_CC_LLVM_VERSION at least when no llvm-config found * More llvm14 fixes --- libafl_cc/build.rs | 2 ++ libafl_cc/src/afl-coverage-pass.cc | 21 ++++++++++++++++++--- libafl_cc/src/coverage-accounting-pass.cc | 5 +++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libafl_cc/build.rs b/libafl_cc/build.rs index 5c6b306f53..2870c34c67 100644 --- a/libafl_cc/build.rs +++ b/libafl_cc/build.rs @@ -248,6 +248,8 @@ fn main() { pub const CLANG_PATH: &str = \"clang\"; /// The path to the `clang++` executable pub const CLANGXX_PATH: &str = \"clang++\"; +/// The llvm version used to build llvm passes +pub const LIBAFL_CC_LLVM_VERSION: Option = None; " ) .expect("Could not write file"); diff --git a/libafl_cc/src/afl-coverage-pass.cc b/libafl_cc/src/afl-coverage-pass.cc index 92bc44cacc..ad531b2280 100644 --- a/libafl_cc/src/afl-coverage-pass.cc +++ b/libafl_cc/src/afl-coverage-pass.cc @@ -51,6 +51,11 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/Support/FormatVariadic.h" +// Without this, Can't build with llvm-14 & old PM +#if LLVM_VERSION_MAJOR >= 14 && !defined(USE_NEW_PM) + #include "llvm/Pass.h" +#endif + #if LLVM_VERSION_MAJOR > 3 || \ (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4) #include "llvm/IR/DebugInfo.h" @@ -593,11 +598,21 @@ bool AFLCoverage::runOnModule(Module &M) { /* Load prev_loc */ - LoadInst *PrevLoc = IRB.CreateLoad( + LoadInst *PrevLoc; + + if (Ngram) { + PrevLoc = IRB.CreateLoad( #if LLVM_VERSION_MAJOR >= 14 - PrevLocTy, + PrevLocTy, #endif - AFLPrevLoc); + AFLPrevLoc); + } else { + PrevLoc = IRB.CreateLoad( +#if LLVM_VERSION_MAJOR >= 14 + IRB.getInt32Ty(), +#endif + AFLPrevLoc); + } PrevLoc->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None)); Value *PrevLocTrans; diff --git a/libafl_cc/src/coverage-accounting-pass.cc b/libafl_cc/src/coverage-accounting-pass.cc index 3ba16e0997..cb2c9bbc64 100644 --- a/libafl_cc/src/coverage-accounting-pass.cc +++ b/libafl_cc/src/coverage-accounting-pass.cc @@ -41,6 +41,11 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/MathExtras.h" +// Without this, Can't build with llvm-14 & old PM +#if LLVM_VERSION_MAJOR >= 14 && !defined(USE_NEW_PM) + #include "llvm/Pass.h" +#endif + #if LLVM_VERSION_MAJOR > 3 || \ (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4) #include "llvm/IR/DebugInfo.h"