mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-13 10:38:07 +00:00
fix for compcov transform strings
This commit is contained in:
@ -27,12 +27,12 @@
|
|||||||
#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"
|
||||||
@ -63,12 +63,14 @@ 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();
|
||||||
@ -94,34 +96,46 @@ class CompareTransform : public ModulePass {
|
|||||||
#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
|
|
||||||
|
#if 1
|
||||||
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
||||||
PB.registerOptimizerLastEPCallback(
|
PB.registerOptimizerLastEPCallback(
|
||||||
[](ModulePassManager &MPM, OptimizationLevel OL) {
|
[](ModulePassManager &MPM, OptimizationLevel OL) {
|
||||||
|
|
||||||
MPM.addPass(CompareTransform());
|
MPM.addPass(CompareTransform());
|
||||||
}
|
|
||||||
);
|
});
|
||||||
/* TODO LTO registration */
|
|
||||||
#else
|
/* TODO LTO registration */
|
||||||
|
#else
|
||||||
using PipelineElement = typename PassBuilder::PipelineElement;
|
using PipelineElement = typename PassBuilder::PipelineElement;
|
||||||
PB.registerPipelineParsingCallback(
|
PB.registerPipelineParsingCallback([](StringRef Name,
|
||||||
[](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) {
|
ModulePassManager &MPM,
|
||||||
if ( Name == "comparetransform" ) {
|
ArrayRef<PipelineElement>) {
|
||||||
|
|
||||||
|
if (Name == "comparetransform") {
|
||||||
|
|
||||||
MPM.addPass(CompareTransform());
|
MPM.addPass(CompareTransform());
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
);
|
});
|
||||||
#endif
|
|
||||||
}
|
#endif
|
||||||
};
|
|
||||||
|
}};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
char CompareTransform::ID = 0;
|
char CompareTransform::ID = 0;
|
||||||
#endif
|
#endif
|
||||||
@ -484,6 +498,9 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the following is in general OK, but strncmp is sometimes used in binary
|
||||||
|
// data structures and this can result in crashes :( so it is commented out
|
||||||
|
/*
|
||||||
// add null termination character implicit in c strings
|
// add null termination character implicit in c strings
|
||||||
if (!isMemcmp && TmpConstStr[TmpConstStr.length() - 1]) {
|
if (!isMemcmp && TmpConstStr[TmpConstStr.length() - 1]) {
|
||||||
|
|
||||||
@ -491,6 +508,8 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
// 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
|
||||||
// at the first null
|
// at the first null
|
||||||
@ -633,8 +652,10 @@ 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)
|
||||||
@ -652,8 +673,10 @@ bool CompareTransform::runOnModule(Module &M) {
|
|||||||
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;
|
||||||
@ -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