-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
112 changed files
with
256,770 additions
and
702 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVER_H | ||
#define FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVER_H | ||
|
||
#include "ftg/indcallsolver/GlobalInitializerSolverHandler.h" | ||
#include "ftg/indcallsolver/IndCallSolver.h" | ||
#include <llvm/IR/InstrTypes.h> | ||
#include <llvm/IR/Module.h> | ||
#include <set> | ||
|
||
namespace ftg { | ||
|
||
class GlobalInitializerSolver : public IndCallSolver { | ||
public: | ||
GlobalInitializerSolver(GlobalInitializerSolverHandler &&Handler); | ||
std::set<const llvm::Function *> | ||
solve(const llvm::CallBase &CB) const override; | ||
|
||
private: | ||
GlobalInitializerSolverHandler Handler; | ||
}; | ||
|
||
} // namespace ftg | ||
|
||
#endif // FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVER_H |
30 changes: 30 additions & 0 deletions
30
include/ftg/indcallsolver/GlobalInitializerSolverHandler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVERHANDLER_H | ||
#define FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVERHANDLER_H | ||
|
||
#include "ftg/indcallsolver/LLVMWalkHandler.h" | ||
#include <set> | ||
|
||
namespace ftg { | ||
|
||
class GlobalInitializerSolverHandler | ||
: public LLVMWalkHandler<llvm::GlobalVariable> { | ||
public: | ||
GlobalInitializerSolverHandler() = default; | ||
GlobalInitializerSolverHandler(GlobalInitializerSolverHandler &&Handler); | ||
void handle(const llvm::GlobalVariable &GV) override; | ||
std::set<const llvm::Function *> get(const llvm::Type *Ty, | ||
unsigned Idx) const; | ||
|
||
private: | ||
struct MapKey { | ||
const llvm::Type *Ty; | ||
unsigned Idx; | ||
MapKey(const llvm::Type *Ty, unsigned Idx); | ||
bool operator<(const MapKey &Key) const; | ||
}; | ||
std::map<MapKey, std::set<const llvm::Function *>> Map; | ||
}; | ||
|
||
} // namespace ftg | ||
|
||
#endif // FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVERHANDLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef FTG_INDCALLSOLVER_INDCALLSOLVERMGR_H | ||
#define FTG_INDCALLSOLVER_INDCALLSOLVERMGR_H | ||
|
||
#include "ftg/indcallsolver/IndCallSolver.h" | ||
#include "llvm/IR/Function.h" | ||
#include "llvm/IR/InstrTypes.h" | ||
#include <set> | ||
|
||
namespace ftg { | ||
|
||
class IndCallSolverMgr { | ||
|
||
public: | ||
void solve(llvm::Module &M); | ||
const llvm::Function *getCalledFunction(const llvm::CallBase &CB) const; | ||
virtual std::set<const llvm::Function *> | ||
getCalledFunctions(const llvm::CallBase &CB) const; | ||
|
||
private: | ||
std::vector<std::unique_ptr<IndCallSolver>> Solvers; | ||
}; | ||
|
||
} // namespace ftg | ||
|
||
#endif // FTG_INDCALLSOLVER_INDCALLSOLVERMGR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef FTG_INDCALLSOLVER_INDCALLSOLVERUTIL_HPP | ||
#define FTG_INDCALLSOLVER_INDCALLSOLVERUTIL_HPP | ||
|
||
#include <llvm/IR/Instructions.h> | ||
|
||
namespace ftg { | ||
|
||
static inline const llvm::MDNode *getTBAA(const llvm::Instruction *I) { | ||
const auto *ExprI = I; | ||
while (ExprI && (llvm::isa<llvm::LoadInst>(ExprI) || | ||
llvm::isa<llvm::GetElementPtrInst>(ExprI))) { | ||
const auto *TBAA = ExprI->getMetadata(llvm::LLVMContext::MD_tbaa); | ||
if (TBAA) | ||
return TBAA; | ||
|
||
const auto *Op = ExprI->getOperand(0); | ||
if (!Op) | ||
break; | ||
|
||
ExprI = llvm::dyn_cast_or_null<llvm::Instruction>(Op->stripPointerCasts()); | ||
} | ||
return nullptr; | ||
} | ||
|
||
} // namespace ftg | ||
|
||
#endif // FTG_INDCALLSOLVER_INDCALLSOLVERUTIL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef FTG_INDCALLSOLVER_LLVMWALKHANDLER_H | ||
#define FTG_INDCALLSOLVER_LLVMWALKHANDLER_H | ||
|
||
#include <llvm/IR/GlobalVariable.h> | ||
|
||
namespace ftg { | ||
|
||
template <typename T> class LLVMWalkHandler { | ||
public: | ||
virtual void handle(const T &IR) = 0; | ||
}; | ||
|
||
} // namespace ftg | ||
|
||
#endif // FTG_INDCALLSOLVER_LLVMWALKHANDLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef FTG_INDCALLSOLVER_LLVMWALKER_H | ||
#define FTG_INDCALLSOLVER_LLVMWALKER_H | ||
|
||
#include "ftg/indcallsolver/LLVMWalkHandler.h" | ||
#include <llvm/IR/Module.h> | ||
|
||
namespace ftg { | ||
|
||
class LLVMWalker { | ||
public: | ||
void addHandler(LLVMWalkHandler<llvm::GlobalVariable> *Handler); | ||
void addHandler(LLVMWalkHandler<llvm::Instruction> *Handler); | ||
void walk(const llvm::Module &M); | ||
|
||
private: | ||
std::vector<LLVMWalkHandler<llvm::GlobalVariable> *> GVHandlers; | ||
std::vector<LLVMWalkHandler<llvm::Instruction> *> InstHandlers; | ||
}; | ||
|
||
} // namespace ftg | ||
|
||
#endif // FTG_INDCALLSOLVER_LLVMWALKER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef FTG_INDCALLSOLVER_TBAASIMPLESOLVER_H | ||
#define FTG_INDCALLSOLVER_TBAASIMPLESOLVER_H | ||
|
||
#include "ftg/indcallsolver/IndCallSolver.h" | ||
#include "ftg/indcallsolver/TBAASimpleSolverHandler.h" | ||
#include <llvm/IR/InstrTypes.h> | ||
#include <llvm/IR/Module.h> | ||
#include <set> | ||
|
||
namespace ftg { | ||
|
||
class TBAASimpleSolver : public IndCallSolver { | ||
public: | ||
TBAASimpleSolver() = default; | ||
TBAASimpleSolver(TBAASimpleSolverHandler &&Handler); | ||
std::set<const llvm::Function *> | ||
solve(const llvm::CallBase &CB) const override; | ||
|
||
private: | ||
TBAASimpleSolverHandler Handler; | ||
}; | ||
|
||
} // namespace ftg | ||
|
||
#endif // FTG_INDCALLSOLVER_TBAASIMPLESOLVER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef FTG_INDCALLSOLVER_TBAASIMPLESOLVERHANDLER_H | ||
#define FTG_INDCALLSOLVER_TBAASIMPLESOLVERHANDLER_H | ||
|
||
#include "ftg/indcallsolver/LLVMWalkHandler.h" | ||
#include <llvm/IR/Instruction.h> | ||
#include <map> | ||
#include <set> | ||
|
||
namespace ftg { | ||
|
||
class TBAASimpleSolverHandler : public LLVMWalkHandler<llvm::Instruction> { | ||
public: | ||
TBAASimpleSolverHandler() = default; | ||
TBAASimpleSolverHandler(TBAASimpleSolverHandler &&Handler); | ||
std::set<const llvm::Function *> get(const llvm::MDNode *Node, | ||
const llvm::Type *Ty) const; | ||
void handle(const llvm::Instruction &I) override; | ||
|
||
private: | ||
struct MapKey { | ||
const llvm::MDNode *Node; | ||
const llvm::Type *Ty; | ||
MapKey(const llvm::MDNode *Node, const llvm::Type *Ty); | ||
bool operator<(const MapKey &Key) const; | ||
}; | ||
std::map<MapKey, std::set<const llvm::Function *>> Map; | ||
}; | ||
|
||
} // namespace ftg | ||
|
||
#endif // FTG_INDCALLSOLVER_TBAASIMPLESOLVERHANDLER_H |
Oops, something went wrong.