diff options
-rw-r--r-- | instrumentation/afl-llvm-pass.so.cc | 43 | ||||
-rw-r--r-- | instrumentation/compare-transform-pass.so.cc | 38 | ||||
-rw-r--r-- | instrumentation/split-compares-pass.so.cc | 48 | ||||
-rw-r--r-- | instrumentation/split-switches-pass.so.cc | 46 | ||||
-rw-r--r-- | src/afl-cc.c | 43 |
5 files changed, 190 insertions, 28 deletions
diff --git a/instrumentation/afl-llvm-pass.so.cc b/instrumentation/afl-llvm-pass.so.cc index 92999443..75f8621b 100644 --- a/instrumentation/afl-llvm-pass.so.cc +++ b/instrumentation/afl-llvm-pass.so.cc @@ -45,15 +45,18 @@ typedef long double max_align_t; #endif #include "llvm/IR/IRBuilder.h" +#if LLVM_VERSION_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/BasicBlock.h" #include "llvm/IR/Module.h" #include "llvm/Support/Debug.h" #include "llvm/Support/MathExtras.h" -//#include "llvm/Transforms/IPO/PassManagerBuilder.h" #if LLVM_VERSION_MAJOR > 3 || \ (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4) @@ -71,18 +74,26 @@ using namespace llvm; namespace { -//class AFLCoverage : public ModulePass { +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ class AFLCoverage : public PassInfoMixin<AFLCoverage> { - - public: -// static char ID; AFLCoverage() { + public: +#else +class AFLCoverage : public ModulePass { + public: + static char ID; + AFLCoverage() : ModulePass(ID) { +#endif initInstrumentList(); } +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); +#else + bool runOnModule(Module &M) override; +#endif protected: uint32_t ngram_size = 0; @@ -96,6 +107,7 @@ class AFLCoverage : public PassInfoMixin<AFLCoverage> { } // namespace +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo() { return { @@ -126,8 +138,10 @@ llvmGetPassPluginInfo() { } }; } +#else -//char AFLCoverage::ID = 0; +char AFLCoverage::ID = 0; +#endif /* needed up to 3.9.0 */ #if LLVM_VERSION_MAJOR == 3 && \ @@ -153,7 +167,13 @@ uint64_t PowerOf2Ceil(unsigned in) { (LLVM_VERSION_MAJOR == 4 && LLVM_VERSION_PATCH >= 1) #define AFL_HAVE_VECTOR_INTRINSICS 1 #endif + + +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ PreservedAnalyses AFLCoverage::run(Module &M, ModuleAnalysisManager &MAM) { +#else +bool AFLCoverage::runOnModule(Module &M) { +#endif LLVMContext &C = M.getContext(); @@ -168,7 +188,9 @@ PreservedAnalyses AFLCoverage::run(Module &M, ModuleAnalysisManager &MAM) { u32 rand_seed; unsigned int cur_loc = 0; +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ auto PA = PreservedAnalyses::all(); +#endif /* Setup random() so we get Actually Random(TM) outputs from AFL_R() */ gettimeofday(&tv, &tz); @@ -1006,10 +1028,15 @@ PreservedAnalyses AFLCoverage::run(Module &M, ModuleAnalysisManager &MAM) { } +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ return PA; +#else + return true; +#endif } -#if 0 + +#if LLVM_VERSION_MAJOR < 7 /* use old pass manager */ static void registerAFLPass(const PassManagerBuilder &, legacy::PassManagerBase &PM) { 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<CompareTransform> { 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<CompareTransform> { } // 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<XX_Manager>(); }*/ 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) { diff --git a/instrumentation/split-compares-pass.so.cc b/instrumentation/split-compares-pass.so.cc index 75a9c35c..ed7e111e 100644 --- a/instrumentation/split-compares-pass.so.cc +++ b/instrumentation/split-compares-pass.so.cc @@ -30,11 +30,14 @@ #include "llvm/Pass.h" #include "llvm/Support/raw_ostream.h" +#if LLVM_MAJOR >= 7 #include "llvm/Passes/PassPlugin.h" #include "llvm/Passes/PassBuilder.h" #include "llvm/IR/PassManager.h" -//#include "llvm/IR/LegacyPassManager.h" -//#include "llvm/Transforms/IPO/PassManagerBuilder.h" +#else +#include "llvm/IR/LegacyPassManager.h" +#include "llvm/Transforms/IPO/PassManagerBuilder.h" +#endif #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/IR/Module.h" @@ -58,17 +61,26 @@ using namespace llvm; namespace { -//class SplitComparesTransform : public ModulePass { +#if LLVM_MAJOR >= 7 class SplitComparesTransform : public PassInfoMixin<SplitComparesTransform> { - public: // static char ID; SplitComparesTransform() : enableFPSplit(0) { +#else +class SplitComparesTransform : public ModulePass { + public: + static char ID; + SplitComparesTransform() : ModulePass(ID), enableFPSplit(0) { +#endif initInstrumentList(); } +#if LLVM_MAJOR >= 7 PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); +#else + bool runOnModule(Module &M) override; +#endif private: int enableFPSplit; @@ -157,6 +169,7 @@ class SplitComparesTransform : public PassInfoMixin<SplitComparesTransform> { } // namespace +#if LLVM_MAJOR >= 7 extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo() { return { @@ -187,8 +200,9 @@ llvmGetPassPluginInfo() { } }; } - -//char SplitComparesTransform::ID = 0; +#else +char SplitComparesTransform::ID = 0; +#endif /// This function splits FCMP instructions with xGE or xLE predicates into two /// FCMP instructions with predicate xGT or xLT and EQ @@ -1342,7 +1356,11 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) { } +#if LLVM_MAJOR >= 7 PreservedAnalyses SplitComparesTransform::run(Module &M, ModuleAnalysisManager &MAM) { +#else +bool SplitComparesTransform::runOnModule(Module &M) { +#endif char *bitw_env = getenv("AFL_LLVM_LAF_SPLIT_COMPARES_BITW"); if (!bitw_env) bitw_env = getenv("LAF_SPLIT_COMPARES_BITW"); @@ -1365,7 +1383,9 @@ PreservedAnalyses SplitComparesTransform::run(Module &M, ModuleAnalysisManager & } +#if LLVM_MAJOR >= 7 auto PA = PreservedAnalyses::all(); +#endif if (enableFPSplit) { @@ -1399,7 +1419,13 @@ PreservedAnalyses SplitComparesTransform::run(Module &M, ModuleAnalysisManager & auto op0 = CI->getOperand(0); auto op1 = CI->getOperand(1); - if (!op0 || !op1) { return PA; } + if (!op0 || !op1) { +#if LLVM_MAJOR >= 7 + return PA; +#else + return false; +#endif + } auto iTy1 = dyn_cast<IntegerType>(op0->getType()); if (iTy1 && isa<IntegerType>(op1->getType())) { @@ -1453,14 +1479,20 @@ PreservedAnalyses SplitComparesTransform::run(Module &M, ModuleAnalysisManager & errs() << count << " comparisons found\n"; } +#if LLVM_MAJOR >= 7 /* if (modified) { PA.abandon<XX_Manager>(); }*/ return PA; +#else + return true; +#endif } -#if 0 + +#if LLVM_MAJOR < 7 /* use old pass manager */ + static void registerSplitComparesPass(const PassManagerBuilder &, legacy::PassManagerBase &PM) { diff --git a/instrumentation/split-switches-pass.so.cc b/instrumentation/split-switches-pass.so.cc index b8cd61c3..42441de1 100644 --- a/instrumentation/split-switches-pass.so.cc +++ b/instrumentation/split-switches-pass.so.cc @@ -27,14 +27,17 @@ #include "llvm/ADT/Statistic.h" #include "llvm/IR/IRBuilder.h" +#if LLVM_VERSION_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" @@ -57,16 +60,38 @@ using namespace llvm; namespace { +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ class SplitSwitchesTransform : public PassInfoMixin<SplitSwitchesTransform> { public: SplitSwitchesTransform() { +#else +class SplitSwitchesTransform : public ModulePass { + public: + static char ID; + SplitSwitchesTransform() : ModulePass(ID) { +#endif initInstrumentList(); } +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); +#else + bool runOnModule(Module &M) override; + +#if LLVM_VERSION_MAJOR >= 4 + StringRef getPassName() const override { + +#else + const char *getPassName() const override { + +#endif + return "splits switch constructs"; + + } +#endif struct CaseExpr { @@ -94,6 +119,7 @@ class SplitSwitchesTransform : public PassInfoMixin<SplitSwitchesTransform> { } // namespace +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo() { return { @@ -124,6 +150,9 @@ llvmGetPassPluginInfo() { } }; } +#else +char SplitSwitchesTransform::ID = 0; +#endif /* switchConvert - Transform simple list of Cases into list of CaseRange's */ BasicBlock *SplitSwitchesTransform::switchConvert( @@ -435,26 +464,37 @@ bool SplitSwitchesTransform::splitSwitches(Module &M) { } +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ PreservedAnalyses SplitSwitchesTransform::run(Module &M, ModuleAnalysisManager &MAM) { +#else +bool SplitSwitchesTransform::runOnModule(Module &M) { +#endif if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL) printf("Running split-switches-pass by laf.intel@gmail.com\n"); else be_quiet = 1; +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ auto PA = PreservedAnalyses::all(); +#endif splitSwitches(M); verifyModule(M); +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ /* if (modified) { PA.abandon<XX_Manager>(); }*/ return PA; +#else + return true; +#endif } -#if 0 + +#if LLVM_VERSION_MAJOR < 7 /* use old pass manager */ static void registerSplitSwitchesTransPass(const PassManagerBuilder &, legacy::PassManagerBase &PM) { diff --git a/src/afl-cc.c b/src/afl-cc.c index e8584d50..7549e17b 100644 --- a/src/afl-cc.c +++ b/src/afl-cc.c @@ -460,10 +460,17 @@ static void edit_params(u32 argc, char **argv, char **envp) { } else { +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ cc_params[cc_par_cnt++] = "-fexperimental-new-pass-manager"; cc_params[cc_par_cnt++] = alloc_printf("-fpass-plugin=%s/split-switches-pass.so", obj_path); - +#else + cc_params[cc_par_cnt++] = "-Xclang"; + cc_params[cc_par_cnt++] = "-load"; + cc_params[cc_par_cnt++] = "-Xclang"; + cc_params[cc_par_cnt++] = + alloc_printf("%s/split-switches-pass.so", obj_path); +#endif } } @@ -478,9 +485,17 @@ static void edit_params(u32 argc, char **argv, char **envp) { } else { +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ cc_params[cc_par_cnt++] = "-fexperimental-new-pass-manager"; cc_params[cc_par_cnt++] = alloc_printf("-fpass-plugin=%s/compare-transform-pass.so", obj_path); +#else + cc_params[cc_par_cnt++] = "-Xclang"; + cc_params[cc_par_cnt++] = "-load"; + cc_params[cc_par_cnt++] = "-Xclang"; + cc_params[cc_par_cnt++] = + alloc_printf("%s/compare-transform-pass.so", obj_path); +#endif } @@ -496,10 +511,18 @@ static void edit_params(u32 argc, char **argv, char **envp) { } else { +#if LLVM_MAJOR >= 7 cc_params[cc_par_cnt++] = "-fexperimental-new-pass-manager"; cc_params[cc_par_cnt++] = alloc_printf("-fpass-plugin=%s/split-compares-pass.so", obj_path); // cc_params[cc_par_cnt++] = "-fno-experimental-new-pass-manager"; +#else + cc_params[cc_par_cnt++] = "-Xclang"; + cc_params[cc_par_cnt++] = "-load"; + cc_params[cc_par_cnt++] = "-Xclang"; + cc_params[cc_par_cnt++] = + alloc_printf("%s/split-compares-pass.so", obj_path); +#endif } @@ -529,9 +552,17 @@ static void edit_params(u32 argc, char **argv, char **envp) { alloc_printf("%s/cmplog-switches-pass.so", obj_path); // reuse split switches from laf +#if LLVM_MAJOR >= 7 cc_params[cc_par_cnt++] = "-fexperimental-new-pass-manager"; cc_params[cc_par_cnt++] = alloc_printf("-fpass-plugin=%s/split-switches-pass.so", obj_path); +#else + cc_params[cc_par_cnt++] = "-Xclang"; + cc_params[cc_par_cnt++] = "-load"; + cc_params[cc_par_cnt++] = "-Xclang"; + cc_params[cc_par_cnt++] = + alloc_printf("%s/split-switches-pass.so", obj_path); +#endif } @@ -541,7 +572,7 @@ static void edit_params(u32 argc, char **argv, char **envp) { #if LLVM_MAJOR >= 13 // fuck you llvm 13 -// cc_params[cc_par_cnt++] = "-fno-experimental-new-pass-manager"; + cc_params[cc_par_cnt++] = "-fno-experimental-new-pass-manager"; #endif if (lto_mode && !have_c) { @@ -621,9 +652,15 @@ static void edit_params(u32 argc, char **argv, char **envp) { } else { +#if LLVM_MAJOR >= 7 cc_params[cc_par_cnt++] = "-fexperimental-new-pass-manager"; cc_params[cc_par_cnt++] = alloc_printf("-fpass-plugin=%s/afl-llvm-pass.so", obj_path); - +#else + cc_params[cc_par_cnt++] = "-Xclang"; + cc_params[cc_par_cnt++] = "-load"; + cc_params[cc_par_cnt++] = "-Xclang"; + cc_params[cc_par_cnt++] = alloc_printf("%s/afl-llvm-pass.so", obj_path); +#endif } } |