From 1f2fa22dad4440bf053e24811b5ece89ca276afc Mon Sep 17 00:00:00 2001 From: hexcoder- Date: Sat, 16 Oct 2021 14:37:54 +0200 Subject: make new pass manager interface compiler version dependent (>=7) --- instrumentation/compare-transform-pass.so.cc | 38 +++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'instrumentation/compare-transform-pass.so.cc') diff --git a/instrumentation/compare-transform-pass.so.cc b/instrumentation/compare-transform-pass.so.cc index ce8efaa7..3c975fe8 100644 --- a/instrumentation/compare-transform-pass.so.cc +++ b/instrumentation/compare-transform-pass.so.cc @@ -26,14 +26,17 @@ #include "llvm/ADT/Statistic.h" #include "llvm/IR/IRBuilder.h" +#if LLVM_MAJOR >= 7 /* use new pass manager */ #include "llvm/Passes/PassPlugin.h" #include "llvm/Passes/PassBuilder.h" #include "llvm/IR/PassManager.h" -//#include "llvm/IR/LegacyPassManager.h" +#else +#include "llvm/IR/LegacyPassManager.h" +#include "llvm/Transforms/IPO/PassManagerBuilder.h" +#endif #include "llvm/IR/Module.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Pass.h" #include "llvm/Analysis/ValueTracking.h" @@ -55,16 +58,28 @@ using namespace llvm; namespace { +#if LLVM_MAJOR >= 7 /* use new pass manager */ class CompareTransform : public PassInfoMixin { public: CompareTransform() { +#else +class CompareTransform : public ModulePass { + + public: + static char ID; + CompareTransform() : ModulePass(ID) { +#endif initInstrumentList(); } +#if LLVM_MAJOR >= 7 /* use new pass manager */ PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); +#else + bool runOnModule(Module &M) override; +#endif private: bool transformCmps(Module &M, const bool processStrcmp, @@ -76,6 +91,7 @@ class CompareTransform : public PassInfoMixin { } // namespace +#if LLVM_MAJOR >= 7 /* use new pass manager */ extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo() { return { @@ -106,7 +122,9 @@ llvmGetPassPluginInfo() { } }; } - +#else +char CompareTransform::ID = 0; +#endif bool CompareTransform::transformCmps(Module &M, const bool processStrcmp, const bool processMemcmp, @@ -613,7 +631,11 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp, } +#if LLVM_MAJOR >= 7 /* use new pass manager */ PreservedAnalyses CompareTransform::run(Module &M, ModuleAnalysisManager &MAM) { +#else +bool CompareTransform::runOnModule(Module &M) { +#endif if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL) printf( @@ -622,22 +644,26 @@ PreservedAnalyses CompareTransform::run(Module &M, ModuleAnalysisManager &MAM) { else be_quiet = 1; +#if LLVM_MAJOR >= 7 /* use new pass manager */ auto PA = PreservedAnalyses::all(); +#endif transformCmps(M, true, true, true, true, true); verifyModule(M); +#if LLVM_MAJOR >= 7 /* use new pass manager */ /* if (modified) { PA.abandon(); }*/ return PA; - -// return true; +#else + return true; +#endif } -#if 0 +#if LLVM_MAJOR < 7 /* use old pass manager */ static void registerCompTransPass(const PassManagerBuilder &, legacy::PassManagerBase &PM) { -- cgit 1.4.1