about summary refs log tree commit diff
path: root/instrumentation/afl-llvm-lto-instrumentlist.so.cc
diff options
context:
space:
mode:
Diffstat (limited to 'instrumentation/afl-llvm-lto-instrumentlist.so.cc')
-rw-r--r--instrumentation/afl-llvm-lto-instrumentlist.so.cc50
1 files changed, 37 insertions, 13 deletions
diff --git a/instrumentation/afl-llvm-lto-instrumentlist.so.cc b/instrumentation/afl-llvm-lto-instrumentlist.so.cc
index 35ba9c5a..70c6b10d 100644
--- a/instrumentation/afl-llvm-lto-instrumentlist.so.cc
+++ b/instrumentation/afl-llvm-lto-instrumentlist.so.cc
@@ -43,9 +43,16 @@
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
+//#include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Passes/PassPlugin.h"
+#include "llvm/Passes/PassBuilder.h"
+#include "llvm/IR/PassManager.h"
 #include "llvm/IR/CFG.h"
+#if LLVM_VERSION_MAJOR >= 14                /* how about stable interfaces? */
+  #include "llvm/Passes/OptimizationLevel.h"
+#endif
 
 #include "afl-llvm-common.h"
 
@@ -53,11 +60,10 @@ using namespace llvm;
 
 namespace {
 
-class AFLcheckIfInstrument : public ModulePass {
+class AFLcheckIfInstrument : public PassInfoMixin<AFLcheckIfInstrument> {
 
  public:
-  static char ID;
-  AFLcheckIfInstrument() : ModulePass(ID) {
+  AFLcheckIfInstrument() {
 
     if (getenv("AFL_DEBUG")) debug = 1;
 
@@ -65,12 +71,7 @@ class AFLcheckIfInstrument : public ModulePass {
 
   }
 
-  bool runOnModule(Module &M) override;
-
-  // StringRef getPassName() const override {
-
-  //  return "American Fuzzy Lop Instrumentation";
-  // }
+  PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
 
  protected:
   std::list<std::string> myInstrumentList;
@@ -79,9 +80,29 @@ class AFLcheckIfInstrument : public ModulePass {
 
 }  // namespace
 
-char AFLcheckIfInstrument::ID = 0;
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
+llvmGetPassPluginInfo() {
+
+  return {LLVM_PLUGIN_API_VERSION, "AFLcheckIfInstrument", "v0.1",
+          /* lambda to insert our pass into the pass pipeline. */
+          [](PassBuilder &PB) {
+
+#if LLVM_VERSION_MAJOR <= 13
+            using OptimizationLevel = typename PassBuilder::OptimizationLevel;
+#endif
+            PB.registerOptimizerLastEPCallback(
+                [](ModulePassManager &MPM, OptimizationLevel OL) {
+
+                  MPM.addPass(AFLcheckIfInstrument());
+
+                });
+
+          }};
 
-bool AFLcheckIfInstrument::runOnModule(Module &M) {
+}
+
+PreservedAnalyses AFLcheckIfInstrument::run(Module &               M,
+                                            ModuleAnalysisManager &MAM) {
 
   /* Show a banner */
 
@@ -130,10 +151,12 @@ bool AFLcheckIfInstrument::runOnModule(Module &M) {
 
   }
 
-  return true;
+  auto PA = PreservedAnalyses::all();
+  return PA;
 
 }
 
+#if 0
 static void registerAFLcheckIfInstrumentpass(const PassManagerBuilder &,
                                              legacy::PassManagerBase &PM) {
 
@@ -148,4 +171,5 @@ static RegisterStandardPasses RegisterAFLcheckIfInstrumentpass(
 static RegisterStandardPasses RegisterAFLcheckIfInstrumentpass0(
     PassManagerBuilder::EP_EnabledOnOptLevel0,
     registerAFLcheckIfInstrumentpass);
+#endif