mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-12 01:58:17 +00:00
fix for compcov transform strings
This commit is contained in:
@ -26,13 +26,13 @@
|
|||||||
|
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
||||||
#include "llvm/Passes/PassPlugin.h"
|
#include "llvm/Passes/PassPlugin.h"
|
||||||
#include "llvm/Passes/PassBuilder.h"
|
#include "llvm/Passes/PassBuilder.h"
|
||||||
#include "llvm/IR/PassManager.h"
|
#include "llvm/IR/PassManager.h"
|
||||||
#else
|
#else
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
#include "llvm/IR/LegacyPassManager.h"
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
||||||
#endif
|
#endif
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
@ -58,24 +58,26 @@ using namespace llvm;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
||||||
class CompareTransform : public PassInfoMixin<CompareTransform> {
|
class CompareTransform : public PassInfoMixin<CompareTransform> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CompareTransform() {
|
CompareTransform() {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
class CompareTransform : public ModulePass {
|
class CompareTransform : public ModulePass {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
CompareTransform() : ModulePass(ID) {
|
CompareTransform() : ModulePass(ID) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
initInstrumentList();
|
initInstrumentList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
||||||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
|
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
|
||||||
#else
|
#else
|
||||||
bool runOnModule(Module &M) override;
|
bool runOnModule(Module &M) override;
|
||||||
@ -91,37 +93,49 @@ class CompareTransform : public ModulePass {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
||||||
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
|
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
|
||||||
llvmGetPassPluginInfo() {
|
llvmGetPassPluginInfo() {
|
||||||
return {
|
|
||||||
LLVM_PLUGIN_API_VERSION, "comparetransform", "v0.1",
|
return {LLVM_PLUGIN_API_VERSION, "comparetransform", "v0.1",
|
||||||
/* lambda to insert our pass into the pass pipeline. */
|
/* lambda to insert our pass into the pass pipeline. */
|
||||||
[](PassBuilder &PB) {
|
[](PassBuilder &PB) {
|
||||||
#if 1
|
|
||||||
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
#if 1
|
||||||
PB.registerOptimizerLastEPCallback(
|
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
||||||
[](ModulePassManager &MPM, OptimizationLevel OL) {
|
PB.registerOptimizerLastEPCallback(
|
||||||
MPM.addPass(CompareTransform());
|
[](ModulePassManager &MPM, OptimizationLevel OL) {
|
||||||
}
|
|
||||||
);
|
MPM.addPass(CompareTransform());
|
||||||
/* TODO LTO registration */
|
|
||||||
#else
|
});
|
||||||
using PipelineElement = typename PassBuilder::PipelineElement;
|
|
||||||
PB.registerPipelineParsingCallback(
|
/* TODO LTO registration */
|
||||||
[](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) {
|
#else
|
||||||
if ( Name == "comparetransform" ) {
|
using PipelineElement = typename PassBuilder::PipelineElement;
|
||||||
MPM.addPass(CompareTransform());
|
PB.registerPipelineParsingCallback([](StringRef Name,
|
||||||
return true;
|
ModulePassManager &MPM,
|
||||||
} else {
|
ArrayRef<PipelineElement>) {
|
||||||
return false;
|
|
||||||
}
|
if (Name == "comparetransform") {
|
||||||
}
|
|
||||||
);
|
MPM.addPass(CompareTransform());
|
||||||
#endif
|
return true;
|
||||||
}
|
|
||||||
};
|
} else {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
char CompareTransform::ID = 0;
|
char CompareTransform::ID = 0;
|
||||||
#endif
|
#endif
|
||||||
@ -484,12 +498,17 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add null termination character implicit in c strings
|
// the following is in general OK, but strncmp is sometimes used in binary
|
||||||
if (!isMemcmp && TmpConstStr[TmpConstStr.length() - 1]) {
|
// data structures and this can result in crashes :( so it is commented out
|
||||||
|
/*
|
||||||
|
// add null termination character implicit in c strings
|
||||||
|
if (!isMemcmp && TmpConstStr[TmpConstStr.length() - 1]) {
|
||||||
|
|
||||||
TmpConstStr.append("\0", 1);
|
TmpConstStr.append("\0", 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
// in the unusual case the const str has embedded null
|
// in the unusual case the const str has embedded null
|
||||||
// characters, the string comparison functions should terminate
|
// characters, the string comparison functions should terminate
|
||||||
@ -631,10 +650,12 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
||||||
PreservedAnalyses CompareTransform::run(Module &M, ModuleAnalysisManager &MAM) {
|
PreservedAnalyses CompareTransform::run(Module &M, ModuleAnalysisManager &MAM) {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
bool CompareTransform::runOnModule(Module &M) {
|
bool CompareTransform::runOnModule(Module &M) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL)
|
if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL)
|
||||||
@ -644,17 +665,19 @@ bool CompareTransform::runOnModule(Module &M) {
|
|||||||
else
|
else
|
||||||
be_quiet = 1;
|
be_quiet = 1;
|
||||||
|
|
||||||
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
||||||
auto PA = PreservedAnalyses::all();
|
auto PA = PreservedAnalyses::all();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
transformCmps(M, true, true, true, true, true);
|
transformCmps(M, true, true, true, true, true);
|
||||||
verifyModule(M);
|
verifyModule(M);
|
||||||
|
|
||||||
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
#if LLVM_MAJOR >= 7 /* use new pass manager */
|
||||||
/* if (modified) {
|
/* if (modified) {
|
||||||
PA.abandon<XX_Manager>();
|
|
||||||
}*/
|
PA.abandon<XX_Manager>();
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
return PA;
|
return PA;
|
||||||
#else
|
#else
|
||||||
@ -663,7 +686,7 @@ bool CompareTransform::runOnModule(Module &M) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LLVM_MAJOR < 7 /* use old pass manager */
|
#if LLVM_MAJOR < 7 /* use old pass manager */
|
||||||
static void registerCompTransPass(const PassManagerBuilder &,
|
static void registerCompTransPass(const PassManagerBuilder &,
|
||||||
legacy::PassManagerBase &PM) {
|
legacy::PassManagerBase &PM) {
|
||||||
|
|
||||||
@ -678,9 +701,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
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user