about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvanhauser-thc <vh@thc.org>2022-03-17 19:43:14 +0100
committervanhauser-thc <vh@thc.org>2022-03-17 19:43:14 +0100
commit90fd61d14a3a154ed58461a9e3eaf2c91d094a86 (patch)
treeba823561b230d6e4952c6bb43f837941e920f847
parent3d1be62c96f2f10963b8fa6f3946e44e40e6b8b3 (diff)
downloadafl++-90fd61d14a3a154ed58461a9e3eaf2c91d094a86.tar.gz
forgot one pass
-rw-r--r--docs/Changelog.md2
-rw-r--r--instrumentation/afl-llvm-lto-instrumentlist.so.cc49
-rw-r--r--instrumentation/afl-llvm-pass.so.cc3
3 files changed, 40 insertions, 14 deletions
diff --git a/docs/Changelog.md b/docs/Changelog.md
index 549d5e4a..18a4debf 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -23,6 +23,8 @@ sending a mail to <afl-users+subscribe@googlegroups.com>.
     - add AFL_EARY_FORKSERVER to install the forkserver as earliest as
       possible in the target (for afl-gcc-fast/afl-clang-fast/
       afl-clang-lto)
+  - afl-cc:
+    - converted all passed to use the new llvm pass manager for llvm 11+
   - frida_mode:
     - update to new frida release, handles now c++ throw/catch
 
diff --git a/instrumentation/afl-llvm-lto-instrumentlist.so.cc b/instrumentation/afl-llvm-lto-instrumentlist.so.cc
index 2ddbc725..70c6b10d 100644
--- a/instrumentation/afl-llvm-lto-instrumentlist.so.cc
+++ b/instrumentation/afl-llvm-lto-instrumentlist.so.cc
@@ -45,8 +45,14 @@
 #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"
 
@@ -54,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;
 
@@ -66,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;
@@ -80,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 */
 
@@ -131,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) {
 
@@ -149,4 +171,5 @@ static RegisterStandardPasses RegisterAFLcheckIfInstrumentpass(
 static RegisterStandardPasses RegisterAFLcheckIfInstrumentpass0(
     PassManagerBuilder::EP_EnabledOnOptLevel0,
     registerAFLcheckIfInstrumentpass);
+#endif
 
diff --git a/instrumentation/afl-llvm-pass.so.cc b/instrumentation/afl-llvm-pass.so.cc
index be8099bb..fde785bd 100644
--- a/instrumentation/afl-llvm-pass.so.cc
+++ b/instrumentation/afl-llvm-pass.so.cc
@@ -44,7 +44,6 @@
 typedef long double max_align_t;
 #endif
 
-#include "llvm/IR/IRBuilder.h"
 #include "llvm/Pass.h"
 #if LLVM_VERSION_MAJOR >= 11                        /* use new pass manager */
   #include "llvm/Passes/PassPlugin.h"
@@ -71,6 +70,8 @@ typedef long double max_align_t;
   #include "llvm/Support/CFG.h"
 #endif
 
+#include "llvm/IR/IRBuilder.h"
+
 #include "afl-llvm-common.h"
 #include "llvm-alternative-coverage.h"