mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-12 10:08:07 +00:00
Merge branch 'newpm2' into dev
This commit is contained in:
10
TODO_LLVM
Normal file
10
TODO_LLVM
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
with LLVM 14: only new pass manager
|
||||||
|
up to LLVM 13: only old pass manager
|
||||||
|
|
||||||
|
These do not work yet with the new pass manager:
|
||||||
|
cmplog-instructions-pass.so
|
||||||
|
compare-transform-pass.so
|
||||||
|
afl-llvm-dict2file.so
|
||||||
|
afl-llvm-lto-instrumentlist.so
|
||||||
|
SanitizerCoverageLTO.so
|
||||||
|
SanitizerCoveragePCGUARD.so
|
@ -589,7 +589,6 @@ bool AFLdict2filePass::runOnModule(Module &M) {
|
|||||||
|
|
||||||
if (optLen < 2) { continue; }
|
if (optLen < 2) { continue; }
|
||||||
if (literalLength + 1 == optLen) { // add null byte
|
if (literalLength + 1 == optLen) { // add null byte
|
||||||
|
|
||||||
thestring.append("\0", 1);
|
thestring.append("\0", 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -612,11 +611,17 @@ bool AFLdict2filePass::runOnModule(Module &M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
if (!isStdString && thestring.find('\0', 0) != std::string::npos) {
|
|
||||||
|
if (!isStdString) {
|
||||||
|
|
||||||
// ensure we do not have garbage
|
// ensure we do not have garbage
|
||||||
size_t offset = thestring.find('\0', 0);
|
size_t offset = thestring.find('\0', 0);
|
||||||
if (offset + 1 < optLen) optLen = offset + 1;
|
if (offset && offset < optLen && offset + 1 < optLen) {
|
||||||
|
|
||||||
|
optLen = offset + 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
thestring = thestring.substr(0, optLen);
|
thestring = thestring.substr(0, optLen);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,12 +46,21 @@ typedef long double max_align_t;
|
|||||||
|
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
#if LLVM_VERSION_MAJOR >= 11 /* 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/BasicBlock.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
#if LLVM_VERSION_MAJOR >= 14 /* how about stable interfaces? */
|
||||||
|
#include "llvm/Passes/OptimizationLevel.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 4 || \
|
#if LLVM_VERSION_MAJOR >= 4 || \
|
||||||
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
|
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
|
||||||
@ -69,17 +78,30 @@ using namespace llvm;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
class AFLCoverage : public PassInfoMixin<AFLCoverage> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
AFLCoverage() {
|
||||||
|
|
||||||
|
#else
|
||||||
class AFLCoverage : public ModulePass {
|
class AFLCoverage : public ModulePass {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
AFLCoverage() : ModulePass(ID) {
|
AFLCoverage() : ModulePass(ID) {
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
initInstrumentList();
|
initInstrumentList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
|
||||||
|
#else
|
||||||
bool runOnModule(Module &M) override;
|
bool runOnModule(Module &M) override;
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t ngram_size = 0;
|
uint32_t ngram_size = 0;
|
||||||
@ -93,7 +115,55 @@ class AFLCoverage : public ModulePass {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* 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
|
||||||
|
#if LLVM_VERSION_MAJOR <= 13
|
||||||
|
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
||||||
|
#endif
|
||||||
|
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;
|
char AFLCoverage::ID = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* needed up to 3.9.0 */
|
/* needed up to 3.9.0 */
|
||||||
#if LLVM_VERSION_MAJOR == 3 && \
|
#if LLVM_VERSION_MAJOR == 3 && \
|
||||||
@ -119,8 +189,15 @@ uint64_t PowerOf2Ceil(unsigned in) {
|
|||||||
(LLVM_VERSION_MAJOR == 4 && LLVM_VERSION_PATCH >= 1)
|
(LLVM_VERSION_MAJOR == 4 && LLVM_VERSION_PATCH >= 1)
|
||||||
#define AFL_HAVE_VECTOR_INTRINSICS 1
|
#define AFL_HAVE_VECTOR_INTRINSICS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
PreservedAnalyses AFLCoverage::run(Module &M, ModuleAnalysisManager &MAM) {
|
||||||
|
|
||||||
|
#else
|
||||||
bool AFLCoverage::runOnModule(Module &M) {
|
bool AFLCoverage::runOnModule(Module &M) {
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
LLVMContext &C = M.getContext();
|
LLVMContext &C = M.getContext();
|
||||||
|
|
||||||
IntegerType *Int8Ty = IntegerType::getInt8Ty(C);
|
IntegerType *Int8Ty = IntegerType::getInt8Ty(C);
|
||||||
@ -134,6 +211,10 @@ bool AFLCoverage::runOnModule(Module &M) {
|
|||||||
u32 rand_seed;
|
u32 rand_seed;
|
||||||
unsigned int cur_loc = 0;
|
unsigned int cur_loc = 0;
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
auto PA = PreservedAnalyses::all();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Setup random() so we get Actually Random(TM) outputs from AFL_R() */
|
/* Setup random() so we get Actually Random(TM) outputs from AFL_R() */
|
||||||
gettimeofday(&tv, &tz);
|
gettimeofday(&tv, &tz);
|
||||||
rand_seed = tv.tv_sec ^ tv.tv_usec ^ getpid();
|
rand_seed = tv.tv_sec ^ tv.tv_usec ^ getpid();
|
||||||
@ -998,10 +1079,15 @@ bool AFLCoverage::runOnModule(Module &M) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
return PA;
|
||||||
|
#else
|
||||||
return true;
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR < 11 /* use old pass manager */
|
||||||
static void registerAFLPass(const PassManagerBuilder &,
|
static void registerAFLPass(const PassManagerBuilder &,
|
||||||
legacy::PassManagerBase &PM) {
|
legacy::PassManagerBase &PM) {
|
||||||
|
|
||||||
@ -1014,4 +1100,5 @@ static RegisterStandardPasses RegisterAFLPass(
|
|||||||
|
|
||||||
static RegisterStandardPasses RegisterAFLPass0(
|
static RegisterStandardPasses RegisterAFLPass0(
|
||||||
PassManagerBuilder::EP_EnabledOnOptLevel0, registerAFLPass);
|
PassManagerBuilder::EP_EnabledOnOptLevel0, registerAFLPass);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -28,11 +28,16 @@
|
|||||||
#include "llvm/Config/llvm-config.h"
|
#include "llvm/Config/llvm-config.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
#if LLVM_MAJOR >= 11
|
||||||
|
// #include "llvm/Passes/PassPlugin.h"
|
||||||
|
// #include "llvm/Passes/PassBuilder.h"
|
||||||
|
#include "llvm/IR/PassManager.h"
|
||||||
|
#else
|
||||||
|
#include "llvm/IR/LegacyPassManager.h"
|
||||||
|
#endif
|
||||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Analysis/ValueTracking.h"
|
#include "llvm/Analysis/ValueTracking.h"
|
||||||
@ -55,6 +60,15 @@ using namespace llvm;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* use new pass manager */
|
||||||
|
class CmpLogInstructions : public PassInfoMixin<CmpLogInstructions> {
|
||||||
|
public:
|
||||||
|
CmpLogInstructions() {
|
||||||
|
|
||||||
|
initInstrumentList();
|
||||||
|
|
||||||
|
}
|
||||||
|
#else
|
||||||
class CmpLogInstructions : public ModulePass {
|
class CmpLogInstructions : public ModulePass {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -64,7 +78,11 @@ class CmpLogInstructions : public ModulePass {
|
|||||||
initInstrumentList();
|
initInstrumentList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* use new pass manager */
|
||||||
|
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
|
||||||
|
#else
|
||||||
bool runOnModule(Module &M) override;
|
bool runOnModule(Module &M) override;
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 4
|
#if LLVM_VERSION_MAJOR >= 4
|
||||||
@ -77,6 +95,7 @@ class CmpLogInstructions : public ModulePass {
|
|||||||
return "cmplog instructions";
|
return "cmplog instructions";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool hookInstrs(Module &M);
|
bool hookInstrs(Module &M);
|
||||||
@ -85,7 +104,9 @@ class CmpLogInstructions : public ModulePass {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
#if LLVM_MAJOR <= 10 /* use old pass manager */
|
||||||
char CmpLogInstructions::ID = 0;
|
char CmpLogInstructions::ID = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
template <class Iterator>
|
template <class Iterator>
|
||||||
Iterator Unique(Iterator first, Iterator last) {
|
Iterator Unique(Iterator first, Iterator last) {
|
||||||
@ -613,7 +634,12 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* use new pass manager */
|
||||||
|
PreservedAnalyses CmpLogInstructions::run(Module & M,
|
||||||
|
ModuleAnalysisManager &MAM) {
|
||||||
|
#else
|
||||||
bool CmpLogInstructions::runOnModule(Module &M) {
|
bool CmpLogInstructions::runOnModule(Module &M) {
|
||||||
|
#endif
|
||||||
|
|
||||||
if (getenv("AFL_QUIET") == NULL)
|
if (getenv("AFL_QUIET") == NULL)
|
||||||
printf("Running cmplog-instructions-pass by andreafioraldi@gmail.com\n");
|
printf("Running cmplog-instructions-pass by andreafioraldi@gmail.com\n");
|
||||||
@ -622,10 +648,15 @@ bool CmpLogInstructions::runOnModule(Module &M) {
|
|||||||
hookInstrs(M);
|
hookInstrs(M);
|
||||||
verifyModule(M);
|
verifyModule(M);
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* use new pass manager */
|
||||||
|
return PreservedAnalyses::all();
|
||||||
|
#else
|
||||||
return true;
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_MAJOR < 11 /* use old pass manager */
|
||||||
static void registerCmpLogInstructionsPass(const PassManagerBuilder &,
|
static void registerCmpLogInstructionsPass(const PassManagerBuilder &,
|
||||||
legacy::PassManagerBase &PM) {
|
legacy::PassManagerBase &PM) {
|
||||||
|
|
||||||
@ -645,4 +676,4 @@ static RegisterStandardPasses RegisterCmpLogInstructionsPassLTO(
|
|||||||
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
|
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
|
||||||
registerCmpLogInstructionsPass);
|
registerCmpLogInstructionsPass);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
@ -26,14 +26,23 @@
|
|||||||
|
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
#if LLVM_MAJOR >= 11 /* 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/IR/Module.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
|
||||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Analysis/ValueTracking.h"
|
#include "llvm/Analysis/ValueTracking.h"
|
||||||
|
#if LLVM_VERSION_MAJOR >= 14 /* how about stable interfaces? */
|
||||||
|
#include "llvm/Passes/OptimizationLevel.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 4 || \
|
#if LLVM_VERSION_MAJOR >= 4 || \
|
||||||
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
|
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
|
||||||
@ -52,28 +61,37 @@ using namespace llvm;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* use new pass manager */
|
||||||
|
class CompareTransform : public PassInfoMixin<CompareTransform> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
CompareTransform() {
|
||||||
|
|
||||||
|
#else
|
||||||
class CompareTransform : public ModulePass {
|
class CompareTransform : public ModulePass {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
CompareTransform() : ModulePass(ID) {
|
CompareTransform() : ModulePass(ID) {
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
initInstrumentList();
|
initInstrumentList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runOnModule(Module &M) override;
|
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 4
|
#if LLVM_VERSION_MAJOR >= 4
|
||||||
StringRef getPassName() const override {
|
StringRef getPassName() const override {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
const char *getPassName() const override {
|
const char *getPassName() const override {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return "transforms compare functions";
|
|
||||||
|
|
||||||
}
|
#if LLVM_MAJOR >= 11 /* use new pass manager */
|
||||||
|
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
|
||||||
|
#else
|
||||||
|
bool runOnModule(Module &M) override;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool transformCmps(Module &M, const bool processStrcmp,
|
bool transformCmps(Module &M, const bool processStrcmp,
|
||||||
@ -85,7 +103,54 @@ class CompareTransform : public ModulePass {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* 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
|
||||||
|
#if LLVM_VERSION_MAJOR <= 13
|
||||||
|
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
||||||
|
#endif
|
||||||
|
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;
|
char CompareTransform::ID = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
||||||
const bool processMemcmp,
|
const bool processMemcmp,
|
||||||
@ -385,6 +450,7 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
|||||||
bool isCaseInsensitive = false;
|
bool isCaseInsensitive = false;
|
||||||
bool needs_null = false;
|
bool needs_null = false;
|
||||||
Function * Callee = callInst->getCalledFunction();
|
Function * Callee = callInst->getCalledFunction();
|
||||||
|
|
||||||
if (Callee) {
|
if (Callee) {
|
||||||
|
|
||||||
if (!Callee->getName().compare("memcmp") ||
|
if (!Callee->getName().compare("memcmp") ||
|
||||||
@ -642,8 +708,14 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* use new pass manager */
|
||||||
|
PreservedAnalyses CompareTransform::run(Module &M, ModuleAnalysisManager &MAM) {
|
||||||
|
|
||||||
|
#else
|
||||||
bool CompareTransform::runOnModule(Module &M) {
|
bool CompareTransform::runOnModule(Module &M) {
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL)
|
if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL)
|
||||||
printf(
|
printf(
|
||||||
"Running compare-transform-pass by laf.intel@gmail.com, extended by "
|
"Running compare-transform-pass by laf.intel@gmail.com, extended by "
|
||||||
@ -651,13 +723,28 @@ bool CompareTransform::runOnModule(Module &M) {
|
|||||||
else
|
else
|
||||||
be_quiet = 1;
|
be_quiet = 1;
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* use new pass manager */
|
||||||
|
auto PA = PreservedAnalyses::all();
|
||||||
|
#endif
|
||||||
|
|
||||||
transformCmps(M, true, true, true, true, true);
|
transformCmps(M, true, true, true, true, true);
|
||||||
verifyModule(M);
|
verifyModule(M);
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* use new pass manager */
|
||||||
|
/* if (modified) {
|
||||||
|
|
||||||
|
PA.abandon<XX_Manager>();
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
return PA;
|
||||||
|
#else
|
||||||
return true;
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_MAJOR < 11 /* use old pass manager */
|
||||||
static void registerCompTransPass(const PassManagerBuilder &,
|
static void registerCompTransPass(const PassManagerBuilder &,
|
||||||
legacy::PassManagerBase &PM) {
|
legacy::PassManagerBase &PM) {
|
||||||
|
|
||||||
@ -672,8 +759,9 @@ static RegisterStandardPasses RegisterCompTransPass(
|
|||||||
static RegisterStandardPasses RegisterCompTransPass0(
|
static RegisterStandardPasses RegisterCompTransPass0(
|
||||||
PassManagerBuilder::EP_EnabledOnOptLevel0, registerCompTransPass);
|
PassManagerBuilder::EP_EnabledOnOptLevel0, registerCompTransPass);
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 11
|
#if LLVM_VERSION_MAJOR >= 11
|
||||||
static RegisterStandardPasses RegisterCompTransPassLTO(
|
static RegisterStandardPasses RegisterCompTransPassLTO(
|
||||||
PassManagerBuilder::EP_FullLinkTimeOptimizationLast, registerCompTransPass);
|
PassManagerBuilder::EP_FullLinkTimeOptimizationLast, registerCompTransPass);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016 laf-intel
|
* Copyright 2016 laf-intel
|
||||||
* extended for floating point by Heiko Eißfeldt
|
* 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -28,10 +29,20 @@
|
|||||||
|
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
#if LLVM_MAJOR >= 11
|
||||||
|
#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/Transforms/Utils/BasicBlockUtils.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
|
#if LLVM_VERSION_MAJOR >= 14 /* how about stable interfaces? */
|
||||||
|
#include "llvm/Passes/OptimizationLevel.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#if LLVM_VERSION_MAJOR >= 4 || \
|
#if LLVM_VERSION_MAJOR >= 4 || \
|
||||||
@ -53,27 +64,31 @@ using namespace llvm;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11
|
||||||
|
class SplitComparesTransform : public PassInfoMixin<SplitComparesTransform> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
// static char ID;
|
||||||
|
SplitComparesTransform() : enableFPSplit(0) {
|
||||||
|
|
||||||
|
#else
|
||||||
class SplitComparesTransform : public ModulePass {
|
class SplitComparesTransform : public ModulePass {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
SplitComparesTransform() : ModulePass(ID), enableFPSplit(0) {
|
SplitComparesTransform() : ModulePass(ID), enableFPSplit(0) {
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
initInstrumentList();
|
initInstrumentList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runOnModule(Module &M) override;
|
#if LLVM_MAJOR >= 11
|
||||||
#if LLVM_VERSION_MAJOR >= 4
|
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
|
||||||
StringRef getPassName() const override {
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
const char *getPassName() const override {
|
bool runOnModule(Module &M) override;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return "AFL_SplitComparesTransform";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int enableFPSplit;
|
int enableFPSplit;
|
||||||
@ -162,7 +177,54 @@ class SplitComparesTransform : public ModulePass {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11
|
||||||
|
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
|
||||||
|
#if LLVM_VERSION_MAJOR <= 13
|
||||||
|
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
||||||
|
#endif
|
||||||
|
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;
|
char SplitComparesTransform::ID = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/// This function splits FCMP instructions with xGE or xLE predicates into two
|
/// This function splits FCMP instructions with xGE or xLE predicates into two
|
||||||
/// FCMP instructions with predicate xGT or xLT and EQ
|
/// FCMP instructions with predicate xGT or xLT and EQ
|
||||||
@ -1421,8 +1483,15 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11
|
||||||
|
PreservedAnalyses SplitComparesTransform::run(Module & M,
|
||||||
|
ModuleAnalysisManager &MAM) {
|
||||||
|
|
||||||
|
#else
|
||||||
bool SplitComparesTransform::runOnModule(Module &M) {
|
bool SplitComparesTransform::runOnModule(Module &M) {
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
char *bitw_env = getenv("AFL_LLVM_LAF_SPLIT_COMPARES_BITW");
|
char *bitw_env = getenv("AFL_LLVM_LAF_SPLIT_COMPARES_BITW");
|
||||||
if (!bitw_env) bitw_env = getenv("LAF_SPLIT_COMPARES_BITW");
|
if (!bitw_env) bitw_env = getenv("LAF_SPLIT_COMPARES_BITW");
|
||||||
if (bitw_env) { target_bitwidth = atoi(bitw_env); }
|
if (bitw_env) { target_bitwidth = atoi(bitw_env); }
|
||||||
@ -1432,7 +1501,7 @@ bool SplitComparesTransform::runOnModule(Module &M) {
|
|||||||
if ((isatty(2) && getenv("AFL_QUIET") == NULL) ||
|
if ((isatty(2) && getenv("AFL_QUIET") == NULL) ||
|
||||||
getenv("AFL_DEBUG") != 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 "
|
"heiko@hexco.de (splitting icmp to "
|
||||||
<< target_bitwidth << " bit)\n";
|
<< target_bitwidth << " bit)\n";
|
||||||
|
|
||||||
@ -1444,6 +1513,10 @@ bool SplitComparesTransform::runOnModule(Module &M) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11
|
||||||
|
auto PA = PreservedAnalyses::all();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (enableFPSplit) {
|
if (enableFPSplit) {
|
||||||
|
|
||||||
simplifyFPCompares(M);
|
simplifyFPCompares(M);
|
||||||
@ -1473,7 +1546,16 @@ bool SplitComparesTransform::runOnModule(Module &M) {
|
|||||||
|
|
||||||
auto op0 = CI->getOperand(0);
|
auto op0 = CI->getOperand(0);
|
||||||
auto op1 = CI->getOperand(1);
|
auto op1 = CI->getOperand(1);
|
||||||
if (!op0 || !op1) { return false; }
|
if (!op0 || !op1) {
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11
|
||||||
|
return PA;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
auto iTy1 = dyn_cast<IntegerType>(op0->getType());
|
auto iTy1 = dyn_cast<IntegerType>(op0->getType());
|
||||||
if (iTy1 && isa<IntegerType>(op1->getType())) {
|
if (iTy1 && isa<IntegerType>(op1->getType())) {
|
||||||
|
|
||||||
@ -1522,10 +1604,29 @@ bool SplitComparesTransform::runOnModule(Module &M) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((isatty(2) && getenv("AFL_QUIET") == NULL) ||
|
||||||
|
getenv("AFL_DEBUG") != NULL) {
|
||||||
|
|
||||||
|
errs() << count << " comparisons found\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11
|
||||||
|
/* if (modified) {
|
||||||
|
|
||||||
|
PA.abandon<XX_Manager>();
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
return PA;
|
||||||
|
#else
|
||||||
return true;
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_MAJOR < 11 /* use old pass manager */
|
||||||
|
|
||||||
static void registerSplitComparesPass(const PassManagerBuilder &,
|
static void registerSplitComparesPass(const PassManagerBuilder &,
|
||||||
legacy::PassManagerBase &PM) {
|
legacy::PassManagerBase &PM) {
|
||||||
|
|
||||||
@ -1539,14 +1640,15 @@ static RegisterStandardPasses RegisterSplitComparesPass(
|
|||||||
static RegisterStandardPasses RegisterSplitComparesTransPass0(
|
static RegisterStandardPasses RegisterSplitComparesTransPass0(
|
||||||
PassManagerBuilder::EP_EnabledOnOptLevel0, registerSplitComparesPass);
|
PassManagerBuilder::EP_EnabledOnOptLevel0, registerSplitComparesPass);
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 11
|
#if LLVM_VERSION_MAJOR >= 11
|
||||||
static RegisterStandardPasses RegisterSplitComparesTransPassLTO(
|
static RegisterStandardPasses RegisterSplitComparesTransPassLTO(
|
||||||
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
|
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
|
||||||
registerSplitComparesPass);
|
registerSplitComparesPass);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static RegisterPass<SplitComparesTransform> X("splitcompares",
|
static RegisterPass<SplitComparesTransform> X("splitcompares",
|
||||||
"AFL++ split compares",
|
"AFL++ split compares",
|
||||||
true /* Only looks at CFG */,
|
true /* Only looks at CFG */,
|
||||||
true /* Analysis Pass */);
|
true /* Analysis Pass */);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -27,14 +27,23 @@
|
|||||||
|
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
#if LLVM_VERSION_MAJOR >= 11 /* 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/IR/Module.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
|
||||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Analysis/ValueTracking.h"
|
#include "llvm/Analysis/ValueTracking.h"
|
||||||
|
#if LLVM_VERSION_MAJOR >= 14 /* how about stable interfaces? */
|
||||||
|
#include "llvm/Passes/OptimizationLevel.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#if LLVM_VERSION_MAJOR >= 4 || \
|
#if LLVM_VERSION_MAJOR >= 4 || \
|
||||||
@ -54,29 +63,42 @@ using namespace llvm;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
class SplitSwitchesTransform : public PassInfoMixin<SplitSwitchesTransform> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
SplitSwitchesTransform() {
|
||||||
|
|
||||||
|
#else
|
||||||
class SplitSwitchesTransform : public ModulePass {
|
class SplitSwitchesTransform : public ModulePass {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
SplitSwitchesTransform() : ModulePass(ID) {
|
SplitSwitchesTransform() : ModulePass(ID) {
|
||||||
|
|
||||||
|
#endif
|
||||||
initInstrumentList();
|
initInstrumentList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runOnModule(Module &M) override;
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
|
||||||
|
#else
|
||||||
|
bool runOnModule(Module &M) override;
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 4
|
#if LLVM_VERSION_MAJOR >= 4
|
||||||
StringRef getPassName() const override {
|
StringRef getPassName() const override {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
const char *getPassName() const override {
|
const char *getPassName() const override {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return "splits switch constructs";
|
return "splits switch constructs";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
struct CaseExpr {
|
struct CaseExpr {
|
||||||
|
|
||||||
ConstantInt *Val;
|
ConstantInt *Val;
|
||||||
@ -103,7 +125,54 @@ class SplitSwitchesTransform : public ModulePass {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* 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
|
||||||
|
#if LLVM_VERSION_MAJOR <= 13
|
||||||
|
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
||||||
|
#endif
|
||||||
|
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;
|
char SplitSwitchesTransform::ID = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* switchConvert - Transform simple list of Cases into list of CaseRange's */
|
/* switchConvert - Transform simple list of Cases into list of CaseRange's */
|
||||||
BasicBlock *SplitSwitchesTransform::switchConvert(
|
BasicBlock *SplitSwitchesTransform::switchConvert(
|
||||||
@ -413,19 +482,42 @@ bool SplitSwitchesTransform::splitSwitches(Module &M) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
PreservedAnalyses SplitSwitchesTransform::run(Module & M,
|
||||||
|
ModuleAnalysisManager &MAM) {
|
||||||
|
|
||||||
|
#else
|
||||||
bool SplitSwitchesTransform::runOnModule(Module &M) {
|
bool SplitSwitchesTransform::runOnModule(Module &M) {
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL)
|
if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL)
|
||||||
printf("Running split-switches-pass by laf.intel@gmail.com\n");
|
printf("Running split-switches-pass by laf.intel@gmail.com\n");
|
||||||
else
|
else
|
||||||
be_quiet = 1;
|
be_quiet = 1;
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
auto PA = PreservedAnalyses::all();
|
||||||
|
#endif
|
||||||
|
|
||||||
splitSwitches(M);
|
splitSwitches(M);
|
||||||
verifyModule(M);
|
verifyModule(M);
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
/* if (modified) {
|
||||||
|
|
||||||
|
PA.abandon<XX_Manager>();
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
return PA;
|
||||||
|
#else
|
||||||
return true;
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR < 11 /* use old pass manager */
|
||||||
static void registerSplitSwitchesTransPass(const PassManagerBuilder &,
|
static void registerSplitSwitchesTransPass(const PassManagerBuilder &,
|
||||||
legacy::PassManagerBase &PM) {
|
legacy::PassManagerBase &PM) {
|
||||||
|
|
||||||
@ -440,9 +532,10 @@ static RegisterStandardPasses RegisterSplitSwitchesTransPass(
|
|||||||
static RegisterStandardPasses RegisterSplitSwitchesTransPass0(
|
static RegisterStandardPasses RegisterSplitSwitchesTransPass0(
|
||||||
PassManagerBuilder::EP_EnabledOnOptLevel0, registerSplitSwitchesTransPass);
|
PassManagerBuilder::EP_EnabledOnOptLevel0, registerSplitSwitchesTransPass);
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 11
|
#if LLVM_VERSION_MAJOR >= 11
|
||||||
static RegisterStandardPasses RegisterSplitSwitchesTransPassLTO(
|
static RegisterStandardPasses RegisterSplitSwitchesTransPassLTO(
|
||||||
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
|
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
|
||||||
registerSplitSwitchesTransPass);
|
registerSplitSwitchesTransPass);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
39
src/afl-cc.c
39
src/afl-cc.c
@ -462,11 +462,17 @@ static void edit_params(u32 argc, char **argv, char **envp) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* 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++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] = "-load";
|
cc_params[cc_par_cnt++] = "-load";
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
cc_params[cc_par_cnt++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] =
|
cc_params[cc_par_cnt++] =
|
||||||
alloc_printf("%s/split-switches-pass.so", obj_path);
|
alloc_printf("%s/split-switches-pass.so", obj_path);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,11 +488,17 @@ static void edit_params(u32 argc, char **argv, char **envp) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11 /* 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++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] = "-load";
|
cc_params[cc_par_cnt++] = "-load";
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
cc_params[cc_par_cnt++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] =
|
cc_params[cc_par_cnt++] =
|
||||||
alloc_printf("%s/compare-transform-pass.so", obj_path);
|
alloc_printf("%s/compare-transform-pass.so", obj_path);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,11 +514,16 @@ static void edit_params(u32 argc, char **argv, char **envp) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11
|
||||||
|
cc_params[cc_par_cnt++] =
|
||||||
|
alloc_printf("-fpass-plugin=%s/split-compares-pass.so", obj_path);
|
||||||
|
#else
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
cc_params[cc_par_cnt++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] = "-load";
|
cc_params[cc_par_cnt++] = "-load";
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
cc_params[cc_par_cnt++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] =
|
cc_params[cc_par_cnt++] =
|
||||||
alloc_printf("%s/split-compares-pass.so", obj_path);
|
alloc_printf("%s/split-compares-pass.so", obj_path);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,11 +553,17 @@ static void edit_params(u32 argc, char **argv, char **envp) {
|
|||||||
alloc_printf("%s/cmplog-switches-pass.so", obj_path);
|
alloc_printf("%s/cmplog-switches-pass.so", obj_path);
|
||||||
|
|
||||||
// reuse split switches from laf
|
// reuse split switches from laf
|
||||||
|
#if LLVM_MAJOR >= 11
|
||||||
|
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++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] = "-load";
|
cc_params[cc_par_cnt++] = "-load";
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
cc_params[cc_par_cnt++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] =
|
cc_params[cc_par_cnt++] =
|
||||||
alloc_printf("%s/split-switches-pass.so", obj_path);
|
alloc_printf("%s/split-switches-pass.so", obj_path);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,8 +571,8 @@ static void edit_params(u32 argc, char **argv, char **envp) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LLVM_MAJOR >= 13
|
#if LLVM_MAJOR == 13 // TODO: set to 14 when done FIXME
|
||||||
// Use the old pass manager in LLVM 14 which the afl++ passes still use.
|
// Use the old pass manager in LLVM 13 which the afl++ passes still use.
|
||||||
cc_params[cc_par_cnt++] = "-flegacy-pass-manager";
|
cc_params[cc_par_cnt++] = "-flegacy-pass-manager";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -633,10 +656,16 @@ static void edit_params(u32 argc, char **argv, char **envp) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11
|
||||||
|
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++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] = "-load";
|
cc_params[cc_par_cnt++] = "-load";
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
cc_params[cc_par_cnt++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] = alloc_printf("%s/afl-llvm-pass.so", obj_path);
|
cc_params[cc_par_cnt++] = alloc_printf("%s/afl-llvm-pass.so", obj_path);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -653,11 +682,17 @@ static void edit_params(u32 argc, char **argv, char **envp) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
#if LLVM_MAJOR >= 11
|
||||||
|
cc_params[cc_par_cnt++] = "-fexperimental-new-pass-manager";
|
||||||
|
cc_params[cc_par_cnt++] =
|
||||||
|
alloc_printf("-fpass-plugin=%s/cmplog-instructions-pass.so", obj_path);
|
||||||
|
#else
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
cc_params[cc_par_cnt++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] = "-load";
|
cc_params[cc_par_cnt++] = "-load";
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
cc_params[cc_par_cnt++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] =
|
cc_params[cc_par_cnt++] =
|
||||||
alloc_printf("%s/cmplog-instructions-pass.so", obj_path);
|
alloc_printf("%s/cmplog-instructions-pass.so", obj_path);
|
||||||
|
#endif
|
||||||
|
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
cc_params[cc_par_cnt++] = "-Xclang";
|
||||||
cc_params[cc_par_cnt++] = "-load";
|
cc_params[cc_par_cnt++] = "-load";
|
||||||
|
Reference in New Issue
Block a user