SVF
|
#include <PAGBuilder.h>
Public Member Functions | |
PAGBuilder () | |
Constructor. More... | |
virtual | ~PAGBuilder () |
Destructor. More... | |
virtual PAG * | build (SVFModule *svfModule) |
Start building PAG here. More... | |
PAG * | getPAG () const |
Return PAG. More... | |
void | sanityCheck () |
Sanity check for PAG. More... | |
void | processCE (const Value *val) |
Process constant expression. More... | |
bool | computeGepOffset (const User *V, LocationSet &ls) |
Compute offset of a gep instruction or gep constant expression. More... | |
void | handleDirectCall (CallSite cs, const SVFFunction *F) |
Handle direct call. More... | |
void | handleIndCall (CallSite cs) |
Handle indirect call. More... | |
void | initialiseNodes () |
Initialize nodes and edges. More... | |
void | addEdge (NodeID src, NodeID dst, PAGEdge::PEDGEK kind, Size_t offset=0, Instruction *cs=nullptr) |
NodeID | getValueNode (const Value *V) |
Get different kinds of node. More... | |
NodeID | getObjectNode (const Value *V) |
GetObject - Return the object node (stack/global/heap/function) according to a LLVM Value. More... | |
NodeID | getReturnNode (const SVFFunction *func) |
getReturnNode - Return the node representing the unique return value of a function. More... | |
NodeID | getVarargNode (const SVFFunction *func) |
getVarargNode - Return the node representing the unique variadic argument of a function. More... | |
void | visitGlobal (SVFModule *svfModule) |
Handle globals including (global variable and functions) More... | |
void | InitialGlobal (const GlobalVariable *gvar, Constant *C, u32_t offset) |
NodeID | getGlobalVarField (const GlobalVariable *gvar, u32_t offset) |
virtual void | handleExtCall (CallSite cs, const SVFFunction *F) |
Handle external call. More... | |
const Type * | getBaseTypeAndFlattenedFields (Value *v, std::vector< LocationSet > &fields) |
void | addComplexConsForExt (Value *D, Value *S, u32_t sz=0) |
virtual void | visitAllocaInst (AllocaInst &AI) |
Our visit overrides. More... | |
void | visitPHINode (PHINode &I) |
void | visitStoreInst (StoreInst &I) |
void | visitLoadInst (LoadInst &I) |
void | visitGetElementPtrInst (GetElementPtrInst &I) |
void | visitCallInst (CallInst &I) |
void | visitInvokeInst (InvokeInst &II) |
void | visitCallBrInst (CallBrInst &I) |
void | visitCallSite (CallSite cs) |
void | visitReturnInst (ReturnInst &I) |
void | visitCastInst (CastInst &I) |
void | visitSelectInst (SelectInst &I) |
void | visitExtractValueInst (ExtractValueInst &EVI) |
void | visitBranchInst (BranchInst &I) |
void | visitSwitchInst (SwitchInst &I) |
void | visitInsertValueInst (InsertValueInst &I) |
void | visitBinaryOperator (BinaryOperator &I) |
void | visitUnaryOperator (UnaryOperator &I) |
void | visitCmpInst (CmpInst &I) |
void | visitVAArgInst (VAArgInst &) |
void | visitVACopyInst (VACopyInst &I) |
void | visitVAEndInst (VAEndInst &I) |
void | visitVAStartInst (VAStartInst &I) |
void | visitFreezeInst (FreezeInst &I) |
void | visitExtractElementInst (ExtractElementInst &I) |
void | visitInsertElementInst (InsertElementInst &I) |
void | visitShuffleVectorInst (ShuffleVectorInst &I) |
void | visitLandingPadInst (LandingPadInst &I) |
void | visitResumeInst (ResumeInst &) |
Instruction not that often. More... | |
void | visitUnreachableInst (UnreachableInst &) |
void | visitFenceInst (FenceInst &I) |
void | visitAtomicCmpXchgInst (AtomicCmpXchgInst &I) |
void | visitAtomicRMWInst (AtomicRMWInst &I) |
void | visitInstruction (Instruction &) |
Provide base case for our instruction visit. More... | |
void | setCurrentLocation (const Value *val, const BasicBlock *bb) |
Set current basic block in order to keep track of control flow information. More... | |
const Value * | getCurrentValue () const |
const BasicBlock * | getCurrentBB () const |
void | addGlobalBlackHoleAddrEdge (NodeID node, const ConstantExpr *int2Ptrce) |
Add global black hole Address edge. More... | |
NodeID | addNullPtrNode () |
Add NullPtr PAGNode. More... | |
NodeID | getGepValNode (const Value *val, const LocationSet &ls, const Type *baseType, u32_t fieldidx) |
void | setCurrentBBAndValueForPAGEdge (PAGEdge *edge) |
PAGEdge * | addBlackHoleAddrEdge (NodeID node) |
AddrPE * | addAddrEdge (NodeID src, NodeID dst) |
Add Address edge. More... | |
CopyPE * | addCopyEdge (NodeID src, NodeID dst) |
Add Copy edge. More... | |
CmpPE * | addCmpEdge (NodeID src, NodeID dst) |
Add Copy edge. More... | |
BinaryOPPE * | addBinaryOPEdge (NodeID src, NodeID dst) |
Add Copy edge. More... | |
UnaryOPPE * | addUnaryOPEdge (NodeID src, NodeID dst) |
Add Unary edge. More... | |
LoadPE * | addLoadEdge (NodeID src, NodeID dst) |
Add Load edge. More... | |
StorePE * | addStoreEdge (NodeID src, NodeID dst) |
Add Store edge. More... | |
CallPE * | addCallEdge (NodeID src, NodeID dst, const CallBlockNode *cs) |
Add Call edge. More... | |
RetPE * | addRetEdge (NodeID src, NodeID dst, const CallBlockNode *cs) |
Add Return edge. More... | |
GepPE * | addGepEdge (NodeID src, NodeID dst, const LocationSet &ls, bool constGep) |
Add Gep edge. More... | |
NormalGepPE * | addNormalGepEdge (NodeID src, NodeID dst, const LocationSet &ls) |
Add Offset(Gep) edge. More... | |
VariantGepPE * | addVariantGepEdge (NodeID src, NodeID dst) |
Add Variant(Gep) edge. More... | |
TDForkPE * | addThreadForkEdge (NodeID src, NodeID dst, const CallBlockNode *cs) |
Add Thread fork edge for parameter passing. More... | |
TDJoinPE * | addThreadJoinEdge (NodeID src, NodeID dst, const CallBlockNode *cs) |
Add Thread join edge for parameter passing. More... | |
Private Attributes | |
PAG * | pag |
SVFModule * | svfMod |
const BasicBlock * | curBB |
Current basic block during PAG construction when visiting the module. More... | |
const Value * | curVal |
Current Value during PAG construction when visiting the module. More... | |
PAG Builder
Definition at line 44 of file PAGBuilder.h.
|
inline |
Constructor.
Definition at line 55 of file PAGBuilder.h.
|
inlinevirtual |
Add Address edge.
Definition at line 282 of file PAGBuilder.h.
|
inline |
Add Copy edge.
Definition at line 303 of file PAGBuilder.h.
Definition at line 274 of file PAGBuilder.h.
|
inline |
Add Call edge.
Definition at line 336 of file PAGBuilder.h.
Add Copy edge.
Definition at line 296 of file PAGBuilder.h.
Add the load/store constraints and temp. nodes for the complex constraint *D = *S (where D/S may point to structs).
If sz is 0, we will add edges for all fields.
Definition at line 912 of file PAGBuilder.cpp.
Add Copy edge.
Definition at line 289 of file PAGBuilder.h.
void SVF::PAGBuilder::addEdge | ( | NodeID | src, |
NodeID | dst, | ||
PAGEdge::PEDGEK | kind, | ||
Size_t | offset = 0 , |
||
Instruction * | cs = nullptr |
||
) |
|
inline |
Add Gep edge.
Definition at line 350 of file PAGBuilder.h.
|
inline |
Add global black hole Address edge.
Definition at line 249 of file PAGBuilder.h.
Add Load edge.
Definition at line 317 of file PAGBuilder.h.
|
inline |
Add Offset(Gep) edge.
Definition at line 357 of file PAGBuilder.h.
|
inline |
Add NullPtr PAGNode.
let all undef value or non-determined pointers points-to black hole
Definition at line 259 of file PAGBuilder.h.
|
inline |
Add Return edge.
Definition at line 343 of file PAGBuilder.h.
Add Store edge.
Definition at line 324 of file PAGBuilder.h.
|
inline |
Add Thread fork edge for parameter passing.
Definition at line 371 of file PAGBuilder.h.
|
inline |
Add Thread join edge for parameter passing.
Definition at line 378 of file PAGBuilder.h.
Add Unary edge.
Definition at line 310 of file PAGBuilder.h.
|
inline |
Add Variant(Gep) edge.
Definition at line 364 of file PAGBuilder.h.
Start building PAG here.
Start building PAG here
initial external library information initial PAG nodes
initial PAG edges:
// handle globals
handle functions
collect return node of function fun
Return PAG node will not be created for function which can not reach the return instruction due to call to abort(), exit(), etc. In 176.gcc of SPEC 2000, function build_objc_string() from c-lang.c shows an example when fun.doesNotReturn() evaluates to TRUE because of abort().
To be noted, we do not record arguments which are in declared function without body TODO: what about external functions with PAG imported by commandline?
Definition at line 47 of file PAGBuilder.cpp.
bool PAGBuilder::computeGepOffset | ( | const User * | V, |
LocationSet & | ls | ||
) |
Compute offset of a gep instruction or gep constant expression.
Return the object node offset according to GEP insn (V). Given a gep edge p = q + i, if "i" is a constant then we return its offset size otherwise if "i" is a variable determined by runtime, then it is a variant offset Return TRUE if the offset of this GEP insn is a constant.
Definition at line 208 of file PAGBuilder.cpp.
const Type * PAGBuilder::getBaseTypeAndFlattenedFields | ( | Value * | V, |
std::vector< LocationSet > & | fields | ||
) |
Find the base type and the max possible offset of an object pointed to by (V).
Definition at line 903 of file PAGBuilder.cpp.
|
inline |
Definition at line 243 of file PAGBuilder.h.
|
inline |
Definition at line 239 of file PAGBuilder.h.
NodeID PAGBuilder::getGepValNode | ( | const Value * | val, |
const LocationSet & | ls, | ||
const Type * | baseType, | ||
u32_t | fieldidx | ||
) |
Add a temp field value node according to base value and offset this node is after the initial node method, it is out of scope of symInfo table
Definition at line 1385 of file PAGBuilder.cpp.
NodeID PAGBuilder::getGlobalVarField | ( | const GlobalVariable * | gvar, |
u32_t | offset | ||
) |
Get the field of the global variable node FIXME:Here we only get the field that actually used in the program We ignore the initialization of global variable field that not used in the program
if we did not find the constant expression in the program, then we need to create a gep node for this field
Definition at line 344 of file PAGBuilder.cpp.
GetObject - Return the object node (stack/global/heap/function) according to a LLVM Value.
Definition at line 95 of file PAGBuilder.h.
|
inline |
Return PAG.
Definition at line 67 of file PAGBuilder.h.
|
inline |
getReturnNode - Return the node representing the unique return value of a function.
Definition at line 101 of file PAGBuilder.h.
Get different kinds of node.
Definition at line 85 of file PAGBuilder.h.
|
inline |
getVarargNode - Return the node representing the unique variadic argument of a function.
Definition at line 107 of file PAGBuilder.h.
void PAGBuilder::handleDirectCall | ( | CallSite | cs, |
const SVFFunction * | F | ||
) |
Handle direct call.
Add the constraints for a direct, non-external call.
FIXME: this assertion should be placed for correct checking except bug program like 188.ammp, 300.twolf
Definition at line 837 of file PAGBuilder.cpp.
|
virtual |
Handle external call.
Handle external calls
this case is for strcpy(dst,src); to maintain its semantics we will store src to the base of dst instead of dst. dst = load base store src base
create inter-procedural PAG edges for thread forks
pthread_create has 1 arg. apr_thread_create has 2 arg.
Connect actual parameter to formal parameter of the start routine
handle indirect calls at pthread create APIs e.g., pthread_create(&t1, nullptr, fp, ...); const Value* fun = ThreadAPI::getThreadAPI()->getForkedFun(inst); if(!SVFUtil::isa<Function>(fun)) pag->addIndirectCallsites(cs,pag->getValueNode(fun));
If forkedFun does not pass to spawnee as function type but as void pointer remember to update inter-procedural callgraph/PAG/SVFG etc. when indirect call targets are resolved We don't connect the callgraph here, further investigation is need to hanle mod-ref during SVFG construction.
create inter-procedural PAG edges for hare_parallel_for calls
The task function of hare_parallel_for has 3 args.
Connect actual parameter to formal parameter of the start routine
handle indirect calls at hare_parallel_for (e.g., hare_parallel_for(..., fp, ...); const Value* fun = ThreadAPI::getThreadAPI()->getForkedFun(inst); if(!SVFUtil::isa<Function>(fun)) pag->addIndirectCallsites(cs,pag->getValueNode(fun));
TODO: inter-procedural PAG edges for thread joins
Definition at line 952 of file PAGBuilder.cpp.
void PAGBuilder::handleIndCall | ( | CallSite | cs | ) |
Handle indirect call.
Indirect call is resolved on-the-fly during pointer analysis
Definition at line 1350 of file PAGBuilder.cpp.
void PAGBuilder::InitialGlobal | ( | const GlobalVariable * | gvar, |
Constant * | C, | ||
u32_t | offset | ||
) |
src should not point to anything yet
Definition at line 374 of file PAGBuilder.cpp.
void PAGBuilder::initialiseNodes | ( | ) |
Initialize nodes and edges.
add address edges for constant nodes.
Definition at line 131 of file PAGBuilder.cpp.
void PAGBuilder::processCE | ( | const Value * | val | ) |
Process constant expression.
Handle constant expression, and connect the gep edge
Definition at line 216 of file PAGBuilder.cpp.
void PAGBuilder::sanityCheck | ( | ) |
Sanity check for PAG.
Definition at line 1359 of file PAGBuilder.cpp.
void PAGBuilder::setCurrentBBAndValueForPAGEdge | ( | PAGEdge * | edge | ) |
We assume every GepValPN and its GepPE are unique across whole program
Definition at line 1432 of file PAGBuilder.cpp.
|
inline |
Set current basic block in order to keep track of control flow information.
Definition at line 234 of file PAGBuilder.h.
|
virtual |
Our visit overrides.
Visit alloca instructions Add edge V (dst) <– O (src), V here is a value node on PAG, O is object node on PAG
Definition at line 495 of file PAGBuilder.cpp.
|
inline |
Definition at line 216 of file PAGBuilder.h.
|
inline |
Definition at line 220 of file PAGBuilder.h.
void PAGBuilder::visitBinaryOperator | ( | BinaryOperator & | inst | ) |
Visit Binary Operator
Definition at line 617 of file PAGBuilder.cpp.
void PAGBuilder::visitBranchInst | ( | BranchInst & | inst | ) |
Branch and switch instructions are treated as UnaryOP br cmp label if.then, label if.else
Definition at line 788 of file PAGBuilder.cpp.
|
inline |
Definition at line 156 of file PAGBuilder.h.
|
inline |
Definition at line 148 of file PAGBuilder.h.
void PAGBuilder::visitCallSite | ( | CallSite | cs | ) |
Collect callsite arguments and returns
Definition at line 682 of file PAGBuilder.cpp.
void PAGBuilder::visitCastInst | ( | CastInst & | I | ) |
Definition at line 593 of file PAGBuilder.cpp.
void PAGBuilder::visitCmpInst | ( | CmpInst & | inst | ) |
Visit compare instruction
Definition at line 647 of file PAGBuilder.cpp.
void PAGBuilder::visitExtractElementInst | ( | ExtractElementInst & | inst | ) |
The �extractelement� instruction extracts a single scalar element from a vector at a specified index. TODO: for now we just assume the pointer after extraction points to blackhole The first operand of an �extractelement� instruction is a value of vector type. The second operand is an index indicating the position from which to extract the element.
<result> = extractelement <4 x i32> vec, i32 0 ; yields i32
Definition at line 778 of file PAGBuilder.cpp.
void PAGBuilder::visitExtractValueInst | ( | ExtractValueInst & | inst | ) |
visit extract value instructions for structures in registers TODO: for now we just assume the pointer after extraction points to blackhole for example %24 = extractvalue { i32, struct.s_hash* } call34, 0 %24 is a pointer points to first field of a register value call34 however we can not create call34 as an memory object, as it is register value. Is that necessary treat extract value as getelementptr instruction later to get more precise results?
Definition at line 764 of file PAGBuilder.cpp.
|
inline |
Definition at line 212 of file PAGBuilder.h.
void PAGBuilder::visitFreezeInst | ( | FreezeInst & | inst | ) |
<result> = freeze ty <val> If <val> is undef or poison, ‘freeze’ returns an arbitrary, but fixed value of type ty
Otherwise, this instruction is a no-op and returns the input <val>
<result> = freeze ty <val> If <val> is undef or poison, ‘freeze’ returns an arbitrary, but fixed value of type ty
Otherwise, this instruction is a no-op and returns the input <val> For now, we assume <val> is never a posion or undef.
Definition at line 823 of file PAGBuilder.cpp.
void PAGBuilder::visitGetElementPtrInst | ( | GetElementPtrInst & | inst | ) |
Visit getelementptr instructions
Definition at line 567 of file PAGBuilder.cpp.
void PAGBuilder::visitGlobal | ( | SVFModule * | svfModule | ) |
Handle globals including (global variable and functions)
Visit global variables for building PAG
initialize global variable
initialize global functions
Definition at line 445 of file PAGBuilder.cpp.
|
inline |
Definition at line 192 of file PAGBuilder.h.
|
inline |
Definition at line 166 of file PAGBuilder.h.
|
inline |
Provide base case for our instruction visit.
Definition at line 226 of file PAGBuilder.h.
|
inline |
Definition at line 152 of file PAGBuilder.h.
|
inline |
Definition at line 200 of file PAGBuilder.h.
void PAGBuilder::visitLoadInst | ( | LoadInst & | I | ) |
Definition at line 535 of file PAGBuilder.cpp.
void PAGBuilder::visitPHINode | ( | PHINode & | inst | ) |
Visit phi instructions
Definition at line 513 of file PAGBuilder.cpp.
|
inline |
void PAGBuilder::visitReturnInst | ( | ReturnInst & | inst | ) |
Visit return instructions of a function
Definition at line 735 of file PAGBuilder.cpp.
void PAGBuilder::visitSelectInst | ( | SelectInst & | inst | ) |
Visit select instructions
Two operands have same incoming basic block, both are the current BB
Definition at line 663 of file PAGBuilder.cpp.
|
inline |
Definition at line 196 of file PAGBuilder.h.
void PAGBuilder::visitStoreInst | ( | StoreInst & | inst | ) |
Visit store instructions
Definition at line 549 of file PAGBuilder.cpp.
void PAGBuilder::visitSwitchInst | ( | SwitchInst & | I | ) |
Definition at line 799 of file PAGBuilder.cpp.
void PAGBuilder::visitUnaryOperator | ( | UnaryOperator & | inst | ) |
Visit Unary Operator
Definition at line 632 of file PAGBuilder.cpp.
|
inline |
Definition at line 209 of file PAGBuilder.h.
void PAGBuilder::visitVAArgInst | ( | VAArgInst & | inst | ) |
TODO: var arguments need to be handled. https://llvm.org/docs/LangRef.html#id1911
ap = alloca struct.va_list ap2 = bitcast struct.va_list* ap to i8* ; Read a single integer argument from ap2 tmp = va_arg i8* ap2, i32 (VAArgInst) TODO: for now, create a copy edge from ap2 to tmp, we assume here tmp should point to the n-th argument of the var_args
Definition at line 812 of file PAGBuilder.cpp.
|
inline |
Definition at line 181 of file PAGBuilder.h.
|
inline |
Definition at line 182 of file PAGBuilder.h.
|
inline |
Definition at line 183 of file PAGBuilder.h.
|
private |
Current basic block during PAG construction when visiting the module.
Definition at line 50 of file PAGBuilder.h.
|
private |
Current Value during PAG construction when visiting the module.
Definition at line 51 of file PAGBuilder.h.
|
private |
Definition at line 48 of file PAGBuilder.h.
|
private |
Definition at line 49 of file PAGBuilder.h.