aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorllzmb <46303940+llzmb@users.noreply.github.com>2021-11-29 19:48:18 +0100
committerllzmb <46303940+llzmb@users.noreply.github.com>2021-11-29 19:48:18 +0100
commit11b3961e687f188aee806afee93bc95807081ff9 (patch)
treeb537761044d62010ac2da8f940846574d5fc2de6
parent70236b854ff99b6c26d7a11ed34dcbaea586226c (diff)
parent0e9b2089498c2acf307bbc90ade420b33aede150 (diff)
downloadafl++-11b3961e687f188aee806afee93bc95807081ff9.tar.gz
Merge branch 'dev' into docs_cleanup_folder_2
-rw-r--r--.gitmodules2
-rw-r--r--coresight_mode/README.md8
-rw-r--r--instrumentation/afl-compiler-rt.o.c17
-rw-r--r--instrumentation/afl-llvm-pass.so.cc70
-rw-r--r--instrumentation/compare-transform-pass.so.cc79
-rw-r--r--instrumentation/split-compares-pass.so.cc99
-rw-r--r--instrumentation/split-switches-pass.so.cc73
-rw-r--r--src/afl-cc.c32
8 files changed, 337 insertions, 43 deletions
diff --git a/.gitmodules b/.gitmodules
index cd9d73e9..6569c0b1 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -18,4 +18,4 @@
url = https://github.com/NixOS/patchelf.git
[submodule "coresight_mode/coresight-trace"]
path = coresight_mode/coresight-trace
- url = git@github.com:RICSecLab/coresight-trace.git
+ url = https://github.com/RICSecLab/coresight-trace.git
diff --git a/coresight_mode/README.md b/coresight_mode/README.md
index dac44076..cd1bccab 100644
--- a/coresight_mode/README.md
+++ b/coresight_mode/README.md
@@ -1,12 +1,16 @@
# AFL++ CoreSight mode
-CoreSight mode enables binary-only fuzzing on ARM64 Linux using CoreSight.
+CoreSight mode enables binary-only fuzzing on ARM64 Linux using CoreSight (ARM's hardware tracing technology).
NOTE: CoreSight mode is in the early development stage. Not applicable for production use.
+Currently the following hardware boards are supported:
+* NVIDIA Jetson TX2 (NVIDIA Parker)
+* NVIDIA Jetson Nano (NVIDIA Tegra X1)
+* GIGABYTE R181-T90 (Marvell ThunderX2 CN99XX)
## Getting started
-Please read the [RICSec/coresight-trace README](https://github.com/RICSecLab/coresight-trace/blob/master/README.md) and check the prerequisites before getting started.
+Please read the [RICSec/coresight-trace README](https://github.com/RICSecLab/coresight-trace/blob/master/README.md) and check the prerequisites (capstone) before getting started.
CoreSight mode supports the AFL fork server mode to reduce `exec` system call overhead. To support it for binary-only fuzzing, it needs to modify the target ELF binary to re-link to the patched glibc. We employ this design from [PTrix](https://github.com/junxzm1990/afl-pt).
diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c
index 7c628fcd..5d198ada 100644
--- a/instrumentation/afl-compiler-rt.o.c
+++ b/instrumentation/afl-compiler-rt.o.c
@@ -1892,9 +1892,13 @@ void __cmplog_rtn_hook_strn(u8 *ptr1, u8 *ptr2, u64 len) {
// fprintf(stderr, "RTN1 %p %p %u\n", ptr1, ptr2, len);
if (likely(!__afl_cmp_map)) return;
if (unlikely(!len)) return;
- int len1 = MIN(31, strlen(ptr1) + 1);
- int len2 = MIN(31, strlen(ptr2) + 1);
- int l = MIN(MAX(len1, len2), 31);
+ int len0 = MIN(len, 31);
+ int len1 = strnlen(ptr1, len0);
+ if (len1 < 31) len1 = area_is_valid(ptr1, len1 + 1);
+ int len2 = strnlen(ptr2, len0);
+ if (len2 < 31) len2 = area_is_valid(ptr1, len2 + 1);
+ int l = MAX(len1, len2);
+ if (l < 2) return;
uintptr_t k = (uintptr_t)__builtin_return_address(0);
k = (uintptr_t)(default_hash((u8 *)&k, sizeof(uintptr_t)) & (CMP_MAP_W - 1));
@@ -1937,9 +1941,10 @@ void __cmplog_rtn_hook_str(u8 *ptr1, u8 *ptr2) {
// fprintf(stderr, "RTN1 %p %p\n", ptr1, ptr2);
if (likely(!__afl_cmp_map)) return;
if (unlikely(!ptr1 || !ptr2)) return;
- int len1 = MIN(31, strlen(ptr1) + 1);
- int len2 = MIN(31, strlen(ptr2) + 1);
- int l = MIN(MAX(len1, len2), 31);
+ int len1 = strnlen(ptr1, 30) + 1;
+ int len2 = strnlen(ptr2, 30) + 1;
+ int l = MAX(len1, len2);
+ if (l < 3) return;
uintptr_t k = (uintptr_t)__builtin_return_address(0);
k = (uintptr_t)(default_hash((u8 *)&k, sizeof(uintptr_t)) & (CMP_MAP_W - 1));
diff --git a/instrumentation/afl-llvm-pass.so.cc b/instrumentation/afl-llvm-pass.so.cc
index 21ce0cf9..41a3e178 100644
--- a/instrumentation/afl-llvm-pass.so.cc
+++ b/instrumentation/afl-llvm-pass.so.cc
@@ -45,12 +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"
+#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)
@@ -68,17 +74,26 @@ using namespace llvm;
namespace {
+#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+class AFLCoverage : public PassInfoMixin<AFLCoverage> {
+ public:
+ AFLCoverage() {
+#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;
@@ -92,7 +107,41 @@ class AFLCoverage : public ModulePass {
} // namespace
+#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
+llvmGetPassPluginInfo() {
+ return {
+ LLVM_PLUGIN_API_VERSION, "AFLCoverage", "v0.1",
+ /* lambda to insert our pass into the pass pipeline. */
+ [](PassBuilder &PB) {
+#if 1
+ using OptimizationLevel = typename PassBuilder::OptimizationLevel;
+ PB.registerOptimizerLastEPCallback(
+ [](ModulePassManager &MPM, OptimizationLevel OL) {
+ MPM.addPass(AFLCoverage());
+ }
+ );
+/* TODO LTO registration */
+#else
+ using PipelineElement = typename PassBuilder::PipelineElement;
+ PB.registerPipelineParsingCallback(
+ [](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) {
+ if ( Name == "AFLCoverage" ) {
+ MPM.addPass(AFLCoverage());
+ return true;
+ } else {
+ return false;
+ }
+ }
+ );
+#endif
+ }
+ };
+}
+#else
+
char AFLCoverage::ID = 0;
+#endif
/* needed up to 3.9.0 */
#if LLVM_VERSION_MAJOR == 3 && \
@@ -118,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();
@@ -133,6 +188,10 @@ bool AFLCoverage::runOnModule(Module &M) {
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);
rand_seed = tv.tv_sec ^ tv.tv_usec ^ getpid();
@@ -970,10 +1029,15 @@ bool AFLCoverage::runOnModule(Module &M) {
}
+#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+ return PA;
+#else
return true;
+#endif
}
+#if LLVM_VERSION_MAJOR < 7 /* use old pass manager */
static void registerAFLPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
@@ -986,4 +1050,4 @@ static RegisterStandardPasses RegisterAFLPass(
static RegisterStandardPasses RegisterAFLPass0(
PassManagerBuilder::EP_EnabledOnOptLevel0, registerAFLPass);
-
+#endif
diff --git a/instrumentation/compare-transform-pass.so.cc b/instrumentation/compare-transform-pass.so.cc
index a1239040..5fd8efb1 100644
--- a/instrumentation/compare-transform-pass.so.cc
+++ b/instrumentation/compare-transform-pass.so.cc
@@ -26,11 +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"
+#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"
@@ -52,28 +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();
}
- bool runOnModule(Module &M) override;
-
-#if LLVM_VERSION_MAJOR < 4
- const char *getPassName() const override {
-
+#if LLVM_MAJOR >= 7 /* use new pass manager */
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
#else
- StringRef getPassName() const override {
-
+ bool runOnModule(Module &M) override;
#endif
- return "transforms compare functions";
-
- }
private:
bool transformCmps(Module &M, const bool processStrcmp,
@@ -85,7 +91,40 @@ class CompareTransform : public ModulePass {
} // namespace
+#if LLVM_MAJOR >= 7 /* use new pass manager */
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
+llvmGetPassPluginInfo() {
+ return {
+ LLVM_PLUGIN_API_VERSION, "comparetransform", "v0.1",
+ /* lambda to insert our pass into the pass pipeline. */
+ [](PassBuilder &PB) {
+#if 1
+ using OptimizationLevel = typename PassBuilder::OptimizationLevel;
+ PB.registerOptimizerLastEPCallback(
+ [](ModulePassManager &MPM, OptimizationLevel OL) {
+ MPM.addPass(CompareTransform());
+ }
+ );
+/* TODO LTO registration */
+#else
+ using PipelineElement = typename PassBuilder::PipelineElement;
+ PB.registerPipelineParsingCallback(
+ [](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) {
+ if ( Name == "comparetransform" ) {
+ MPM.addPass(CompareTransform());
+ return true;
+ } else {
+ return false;
+ }
+ }
+ );
+#endif
+ }
+ };
+}
+#else
char CompareTransform::ID = 0;
+#endif
bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
const bool processMemcmp,
@@ -592,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(
@@ -601,13 +644,26 @@ bool CompareTransform::runOnModule(Module &M) {
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;
+#else
return true;
+#endif
}
+#if LLVM_MAJOR < 7 /* use old pass manager */
static void registerCompTransPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
@@ -626,4 +682,5 @@ static RegisterStandardPasses RegisterCompTransPass0(
static RegisterStandardPasses RegisterCompTransPassLTO(
PassManagerBuilder::EP_FullLinkTimeOptimizationLast, registerCompTransPass);
#endif
+#endif
diff --git a/instrumentation/split-compares-pass.so.cc b/instrumentation/split-compares-pass.so.cc
index 7c652ca2..8ea67a21 100644
--- a/instrumentation/split-compares-pass.so.cc
+++ b/instrumentation/split-compares-pass.so.cc
@@ -1,6 +1,7 @@
/*
* Copyright 2016 laf-intel
* extended for floating point by Heiko Eißfeldt
+ * adapted to new pass manager by Heiko Eißfeldt
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,8 +29,15 @@
#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"
+#else
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#endif
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/IR/Module.h"
@@ -53,27 +61,26 @@ using namespace llvm;
namespace {
+#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();
-
}
- bool runOnModule(Module &M) override;
-#if LLVM_VERSION_MAJOR >= 4
- StringRef getPassName() const override {
-
+#if LLVM_MAJOR >= 7
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
#else
- const char *getPassName() const override {
-
+ bool runOnModule(Module &M) override;
#endif
- return "AFL_SplitComparesTransform";
-
- }
private:
int enableFPSplit;
@@ -162,7 +169,40 @@ class SplitComparesTransform : public ModulePass {
} // namespace
+#if LLVM_MAJOR >= 7
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
+llvmGetPassPluginInfo() {
+ return {
+ LLVM_PLUGIN_API_VERSION, "splitcompares", "v0.1",
+ /* lambda to insert our pass into the pass pipeline. */
+ [](PassBuilder &PB) {
+#if 1
+ using OptimizationLevel = typename PassBuilder::OptimizationLevel;
+ PB.registerOptimizerLastEPCallback(
+ [](ModulePassManager &MPM, OptimizationLevel OL) {
+ MPM.addPass(SplitComparesTransform());
+ }
+ );
+/* TODO LTO registration */
+#else
+ using PipelineElement = typename PassBuilder::PipelineElement;
+ PB.registerPipelineParsingCallback(
+ [](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) {
+ if ( Name == "splitcompares" ) {
+ MPM.addPass(SplitComparesTransform());
+ return true;
+ } else {
+ return false;
+ }
+ }
+ );
+#endif
+ }
+ };
+}
+#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
@@ -675,7 +715,7 @@ bool SplitComparesTransform::splitCompare(CmpInst *cmp_inst, Module &M,
ReplaceInstWithInst(cmp_inst->getParent()->getInstList(), ii, PN);
// We split the comparison into low and high. If this isn't our target
- // bitwidth we recursivly split the low and high parts again until we have
+ // bitwidth we recursively split the low and high parts again until we have
// target bitwidth.
if ((bitw / 2) > target_bitwidth) {
@@ -1316,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");
@@ -1327,7 +1371,7 @@ bool SplitComparesTransform::runOnModule(Module &M) {
if ((isatty(2) && getenv("AFL_QUIET") == NULL) ||
getenv("AFL_DEBUG") != NULL) {
- errs() << "Split-compare-pass by laf.intel@gmail.com, extended by "
+ errs() << "Split-compare-newpass by laf.intel@gmail.com, extended by "
"heiko@hexco.de (splitting icmp to "
<< target_bitwidth << " bit)\n";
@@ -1339,6 +1383,10 @@ bool SplitComparesTransform::runOnModule(Module &M) {
}
+#if LLVM_MAJOR >= 7
+ auto PA = PreservedAnalyses::all();
+#endif
+
if (enableFPSplit) {
count = splitFPCompares(M);
@@ -1371,7 +1419,13 @@ bool SplitComparesTransform::runOnModule(Module &M) {
auto op0 = CI->getOperand(0);
auto op1 = CI->getOperand(1);
- if (!op0 || !op1) { return false; }
+ 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())) {
@@ -1420,10 +1474,25 @@ bool SplitComparesTransform::runOnModule(Module &M) {
}
+ if ((isatty(2) && getenv("AFL_QUIET") == NULL) ||
+ getenv("AFL_DEBUG") != NULL) {
+ errs() << count << " comparisons found\n";
+ }
+
+#if LLVM_MAJOR >= 7
+/* if (modified) {
+ PA.abandon<XX_Manager>();
+ }*/
+
+ return PA;
+#else
return true;
+#endif
}
+#if LLVM_MAJOR < 7 /* use old pass manager */
+
static void registerSplitComparesPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
@@ -1447,4 +1516,4 @@ static RegisterPass<SplitComparesTransform> X("splitcompares",
"AFL++ split compares",
true /* Only looks at CFG */,
true /* Analysis Pass */);
-
+#endif
diff --git a/instrumentation/split-switches-pass.so.cc b/instrumentation/split-switches-pass.so.cc
index 1e32a31d..ca8cdc9b 100644
--- a/instrumentation/split-switches-pass.so.cc
+++ b/instrumentation/split-switches-pass.so.cc
@@ -27,11 +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"
+#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"
@@ -54,16 +60,25 @@ 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
@@ -76,6 +91,7 @@ class SplitSwitchesTransform : public ModulePass {
return "splits switch constructs";
}
+#endif
struct CaseExpr {
@@ -103,7 +119,40 @@ class SplitSwitchesTransform : public ModulePass {
} // namespace
+#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
+llvmGetPassPluginInfo() {
+ return {
+ LLVM_PLUGIN_API_VERSION, "splitswitches", "v0.1",
+ /* lambda to insert our pass into the pass pipeline. */
+ [](PassBuilder &PB) {
+#if 1
+ using OptimizationLevel = typename PassBuilder::OptimizationLevel;
+ PB.registerOptimizerLastEPCallback(
+ [](ModulePassManager &MPM, OptimizationLevel OL) {
+ MPM.addPass(SplitSwitchesTransform());
+ }
+ );
+/* TODO LTO registration */
+#else
+ using PipelineElement = typename PassBuilder::PipelineElement;
+ PB.registerPipelineParsingCallback(
+ [](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) {
+ if ( Name == "splitswitches" ) {
+ MPM.addPass(SplitSwitchesTransform());
+ return true;
+ } else {
+ return false;
+ }
+ }
+ );
+#endif
+ }
+ };
+}
+#else
char SplitSwitchesTransform::ID = 0;
+#endif
/* switchConvert - Transform simple list of Cases into list of CaseRange's */
BasicBlock *SplitSwitchesTransform::switchConvert(
@@ -415,19 +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 LLVM_VERSION_MAJOR < 7 /* use old pass manager */
static void registerSplitSwitchesTransPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
@@ -447,4 +514,4 @@ static RegisterStandardPasses RegisterSplitSwitchesTransPassLTO(
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
registerSplitSwitchesTransPass);
#endif
-
+#endif
diff --git a/src/afl-cc.c b/src/afl-cc.c
index 8ff241ba..58d978ea 100644
--- a/src/afl-cc.c
+++ b/src/afl-cc.c
@@ -462,12 +462,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
}
}
@@ -482,11 +487,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
}
@@ -502,11 +513,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
}
@@ -536,11 +554,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
}
@@ -630,11 +654,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
}
}