svf-lib 1.0.1822 → 1.0.1824
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SVF-linux/Release-build/svf/libSvfCore.a +0 -0
- package/SVF-linux/Release-build/svf-llvm/libSvfLLVM.a +0 -0
- package/SVF-linux/svf-llvm/include/SVF-LLVM/CppUtil.h +155 -0
- package/SVF-linux/svf-llvm/include/SVF-LLVM/DCHG.h +1 -9
- package/SVF-linux/svf-llvm/include/SVF-LLVM/ICFGBuilder.h +1 -0
- package/SVF-linux/svf-llvm/include/SVF-LLVM/LLVMModule.h +0 -1
- package/SVF-linux/svf-llvm/include/SVF-LLVM/LLVMUtil.h +4 -108
- package/SVF-osx/Release-build/svf/libSvfCore.a +0 -0
- package/SVF-osx/Release-build/svf-llvm/libSvfLLVM.a +0 -0
- package/SVF-osx/svf/include/SVFIR/SVFType.h +27 -7
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
//===- CPPUtil.h -- Base class of pointer analyses ---------------------------//
|
|
2
|
+
//
|
|
3
|
+
// SVF: Static Value-Flow Analysis
|
|
4
|
+
//
|
|
5
|
+
// Copyright (C) <2013-2017> <Yulei Sui>
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
// This program is free software: you can redistribute it and/or modify
|
|
9
|
+
// it under the terms of the GNU Affero General Public License as published by
|
|
10
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
// (at your option) any later version.
|
|
12
|
+
|
|
13
|
+
// This program is distributed in the hope that it will be useful,
|
|
14
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
// GNU Affero General Public License for more details.
|
|
17
|
+
|
|
18
|
+
// You should have received a copy of the GNU Affero General Public License
|
|
19
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
//
|
|
21
|
+
//===----------------------------------------------------------------------===//
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* CPPUtil.h
|
|
25
|
+
*
|
|
26
|
+
* Created on: Apr 13, 2016
|
|
27
|
+
* Author: Xiaokang Fan
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#ifndef CPPUtil_H_
|
|
31
|
+
#define CPPUtil_H_
|
|
32
|
+
|
|
33
|
+
#include "SVFIR/SVFValue.h"
|
|
34
|
+
#include "SVF-LLVM/BasicTypes.h"
|
|
35
|
+
|
|
36
|
+
namespace SVF
|
|
37
|
+
{
|
|
38
|
+
|
|
39
|
+
class CHGraph;
|
|
40
|
+
/*
|
|
41
|
+
* Util class to assist pointer analysis for cpp programs
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
namespace cppUtil
|
|
45
|
+
{
|
|
46
|
+
|
|
47
|
+
struct DemangledName
|
|
48
|
+
{
|
|
49
|
+
std::string className;
|
|
50
|
+
std::string funcName;
|
|
51
|
+
bool isThunkFunc;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
struct DemangledName demangle(const std::string& name);
|
|
55
|
+
|
|
56
|
+
std::string getBeforeBrackets(const std::string& name);
|
|
57
|
+
std::string getClassNameFromVtblObj(const std::string& vtblName);
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
* Get the vtable struct of a class.
|
|
61
|
+
*
|
|
62
|
+
* Given the class:
|
|
63
|
+
*
|
|
64
|
+
* class A {
|
|
65
|
+
* virtual ~A();
|
|
66
|
+
* };
|
|
67
|
+
* A::~A() = default;
|
|
68
|
+
*
|
|
69
|
+
* The corresponding vtable @_ZTV1A is of type:
|
|
70
|
+
*
|
|
71
|
+
* { [4 x i8*] }
|
|
72
|
+
*
|
|
73
|
+
* If the program has been compiled with AddressSanitizer,
|
|
74
|
+
* the vtable will have redzones and appear as:
|
|
75
|
+
*
|
|
76
|
+
* { { [4 x i8*] }, [32 x i8] }
|
|
77
|
+
*
|
|
78
|
+
* See https://github.com/SVF-tools/SVF/issues/1114 for more.
|
|
79
|
+
*/
|
|
80
|
+
const ConstantStruct *getVtblStruct(const GlobalValue *vtbl);
|
|
81
|
+
|
|
82
|
+
bool isValVtbl(const Value* val);
|
|
83
|
+
bool isVirtualCallSite(const CallBase* cs);
|
|
84
|
+
bool isConstructor(const Function* F);
|
|
85
|
+
bool isDestructor(const Function* F);
|
|
86
|
+
bool isCPPThunkFunction(const Function* F);
|
|
87
|
+
const Function* getThunkTarget(const Function* F);
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* VtableA = {&A::foo}
|
|
91
|
+
* A::A(this){
|
|
92
|
+
* *this = &VtableA;
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
*
|
|
96
|
+
* A* p = new A;
|
|
97
|
+
* cs: p->foo(...)
|
|
98
|
+
* ==>
|
|
99
|
+
* vtptr = *p;
|
|
100
|
+
* vfn = &vtptr[i]
|
|
101
|
+
* %funp = *vfn
|
|
102
|
+
* call %funp(p,...)
|
|
103
|
+
* getConstructorThisPtr(A) return "this" pointer
|
|
104
|
+
* getVCallThisPtr(cs) return p (this pointer)
|
|
105
|
+
* getVCallVtblPtr(cs) return vtptr
|
|
106
|
+
* getVCallIdx(cs) return i
|
|
107
|
+
* getClassNameFromVtblObj(VtableA) return
|
|
108
|
+
* getClassNameFromType(type of p) return type A
|
|
109
|
+
*/
|
|
110
|
+
const Argument* getConstructorThisPtr(const Function* fun);
|
|
111
|
+
const Value* getVCallThisPtr(const CallBase* cs);
|
|
112
|
+
const Value* getVCallVtblPtr(const CallBase* cs);
|
|
113
|
+
s32_t getVCallIdx(const CallBase* cs);
|
|
114
|
+
bool classTyHasVTable(const StructType* ty);
|
|
115
|
+
std::string getClassNameFromType(const StructType* ty);
|
|
116
|
+
std::string getClassNameOfThisPtr(const CallBase* cs);
|
|
117
|
+
std::string getFunNameOfVCallSite(const CallBase* cs);
|
|
118
|
+
bool VCallInCtorOrDtor(const CallBase* cs);
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
* A(A* this){
|
|
122
|
+
* store this this.addr;
|
|
123
|
+
* tmp = load this.addr;
|
|
124
|
+
* this1 = bitcast(tmp);
|
|
125
|
+
* B(this1);
|
|
126
|
+
* }
|
|
127
|
+
* this and this1 are the same thisPtr in the constructor
|
|
128
|
+
*/
|
|
129
|
+
bool isSameThisPtrInConstructor(const Argument* thisPtr1,
|
|
130
|
+
const Value* thisPtr2);
|
|
131
|
+
|
|
132
|
+
/// Constants pertaining to CTir, for C and C++.
|
|
133
|
+
/// TODO: move helper functions here too?
|
|
134
|
+
namespace ctir
|
|
135
|
+
{
|
|
136
|
+
/// On loads, stores, GEPs representing dereferences, and calls
|
|
137
|
+
/// representing virtual calls.
|
|
138
|
+
/// (The static type.)
|
|
139
|
+
const std::string derefMDName = "ctir";
|
|
140
|
+
/// On the (global) virtual table itself.
|
|
141
|
+
/// (The class it corresponds to.)
|
|
142
|
+
const std::string vtMDName = "ctir.vt";
|
|
143
|
+
/// On the bitcast of `this` to i8*.
|
|
144
|
+
/// (The class the constructor it corresponds to.)
|
|
145
|
+
const std::string vtInitMDName = "ctir.vt.init";
|
|
146
|
+
|
|
147
|
+
/// Value we expect a ctir-annotated module to have.
|
|
148
|
+
const uint32_t moduleFlagValue = 1;
|
|
149
|
+
} // namespace ctir
|
|
150
|
+
|
|
151
|
+
} // End namespace cppUtil
|
|
152
|
+
|
|
153
|
+
} // End namespace SVF
|
|
154
|
+
|
|
155
|
+
#endif /* CPPUtil_H_ */
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
|
|
17
17
|
#include "Graphs/GenericGraph.h"
|
|
18
18
|
#include "Graphs/CHG.h"
|
|
19
|
-
#include "Util/CppUtil.h"
|
|
20
19
|
#include "SVF-LLVM/BasicTypes.h"
|
|
21
20
|
#include "SVFIR/SVFModule.h"
|
|
22
21
|
#include "Util/SVFUtil.h"
|
|
@@ -413,14 +412,7 @@ private:
|
|
|
413
412
|
DCHNode* getOrCreateNode(const DIType* type);
|
|
414
413
|
|
|
415
414
|
/// Retrieves the metadata associated with a *virtual* callsite.
|
|
416
|
-
const DIType* getCSStaticType(CallBase* cs) const
|
|
417
|
-
{
|
|
418
|
-
MDNode *md = cs->getMetadata(cppUtil::ctir::derefMDName);
|
|
419
|
-
assert(md != nullptr && "Missing type metadata at virtual callsite");
|
|
420
|
-
DIType *diType = SVFUtil::dyn_cast<DIType>(md);
|
|
421
|
-
assert(diType != nullptr && "Incorrect metadata type at virtual callsite");
|
|
422
|
-
return diType;
|
|
423
|
-
}
|
|
415
|
+
const DIType* getCSStaticType(CallBase* cs) const;
|
|
424
416
|
|
|
425
417
|
const DIType *getCSStaticType(CallSite cs) const
|
|
426
418
|
{
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
|
|
33
33
|
#include "Util/SVFUtil.h"
|
|
34
34
|
#include "SVF-LLVM/BasicTypes.h"
|
|
35
|
-
#include "SVF-LLVM/LLVMModule.h"
|
|
36
35
|
#include "SVFIR/SVFValue.h"
|
|
37
36
|
#include "Util/ThreadAPI.h"
|
|
38
37
|
|
|
@@ -54,15 +53,7 @@ inline bool isCallSite(const Value* val)
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
/// Get the definition of a function across multiple modules
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
if (fun == nullptr)
|
|
60
|
-
return nullptr;
|
|
61
|
-
LLVMModuleSet* llvmModuleset = LLVMModuleSet::getLLVMModuleSet();
|
|
62
|
-
if (fun->isDeclaration() && llvmModuleset->hasDefinition(fun))
|
|
63
|
-
fun = LLVMModuleSet::getLLVMModuleSet()->getDefinition(fun);
|
|
64
|
-
return fun;
|
|
65
|
-
}
|
|
56
|
+
const Function* getDefFunForMultipleModule(const Function* fun);
|
|
66
57
|
|
|
67
58
|
/// Return LLVM callsite given a value
|
|
68
59
|
inline const CallBase* getLLVMCallSite(const Value* value)
|
|
@@ -85,18 +76,7 @@ inline const Function* getLLVMFunction(const Value* val)
|
|
|
85
76
|
}
|
|
86
77
|
|
|
87
78
|
/// Get program entry function from module.
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
for (const Module& M : LLVMModuleSet::getLLVMModuleSet()->getLLVMModules())
|
|
91
|
-
{
|
|
92
|
-
for (const Function& fun : M)
|
|
93
|
-
{
|
|
94
|
-
if (fun.getName() == funName)
|
|
95
|
-
return &fun;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return nullptr;
|
|
99
|
-
}
|
|
79
|
+
const Function* getProgFunction(const std::string& funName);
|
|
100
80
|
|
|
101
81
|
/// Check whether a function is an entry function (i.e., main)
|
|
102
82
|
inline bool isProgEntryFunction(const Function* fun)
|
|
@@ -354,10 +334,7 @@ void removeUnusedGlobalVariables(Module* module);
|
|
|
354
334
|
void removeUnusedFuncsAndAnnotationsAndGlobalVariables(std::vector<Function*> removedFuncList);
|
|
355
335
|
|
|
356
336
|
/// Get the corresponding Function based on its name
|
|
357
|
-
|
|
358
|
-
{
|
|
359
|
-
return LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(name);
|
|
360
|
-
}
|
|
337
|
+
const SVFFunction* getFunction(const std::string& name);
|
|
361
338
|
|
|
362
339
|
/// Return true if the value refers to constant data, e.g., i32 0
|
|
363
340
|
inline bool isConstDataOrAggData(const Value* val)
|
|
@@ -367,15 +344,7 @@ inline bool isConstDataOrAggData(const Value* val)
|
|
|
367
344
|
}
|
|
368
345
|
|
|
369
346
|
/// find the unique defined global across multiple modules
|
|
370
|
-
|
|
371
|
-
{
|
|
372
|
-
if (const GlobalVariable* gvar = SVFUtil::dyn_cast<GlobalVariable>(val))
|
|
373
|
-
{
|
|
374
|
-
if (LLVMModuleSet::getLLVMModuleSet()->hasGlobalRep(gvar))
|
|
375
|
-
val = LLVMModuleSet::getLLVMModuleSet()->getGlobalRep(gvar);
|
|
376
|
-
}
|
|
377
|
-
return val;
|
|
378
|
-
}
|
|
347
|
+
const Value* getGlobalRep(const Value* val);
|
|
379
348
|
|
|
380
349
|
/// Check whether this value points-to a constant object
|
|
381
350
|
bool isConstantObjSym(const SVFValue* val);
|
|
@@ -389,79 +358,6 @@ void viewCFG(const Function* fun);
|
|
|
389
358
|
// Dump Control Flow Graph of llvm function, without instructions
|
|
390
359
|
void viewCFGOnly(const Function* fun);
|
|
391
360
|
|
|
392
|
-
/*
|
|
393
|
-
* Get the vtable struct of a class.
|
|
394
|
-
*
|
|
395
|
-
* Given the class:
|
|
396
|
-
*
|
|
397
|
-
* class A {
|
|
398
|
-
* virtual ~A();
|
|
399
|
-
* };
|
|
400
|
-
* A::~A() = default;
|
|
401
|
-
*
|
|
402
|
-
* The corresponding vtable @_ZTV1A is of type:
|
|
403
|
-
*
|
|
404
|
-
* { [4 x i8*] }
|
|
405
|
-
*
|
|
406
|
-
* If the program has been compiled with AddressSanitizer,
|
|
407
|
-
* the vtable will have redzones and appear as:
|
|
408
|
-
*
|
|
409
|
-
* { { [4 x i8*] }, [32 x i8] }
|
|
410
|
-
*
|
|
411
|
-
* See https://github.com/SVF-tools/SVF/issues/1114 for more.
|
|
412
|
-
*/
|
|
413
|
-
const ConstantStruct *getVtblStruct(const GlobalValue *vtbl);
|
|
414
|
-
|
|
415
|
-
bool isValVtbl(const Value* val);
|
|
416
|
-
bool isVirtualCallSite(const CallBase* cs);
|
|
417
|
-
bool isConstructor(const Function* F);
|
|
418
|
-
bool isDestructor(const Function* F);
|
|
419
|
-
bool isCPPThunkFunction(const Function* F);
|
|
420
|
-
const Function* getThunkTarget(const Function* F);
|
|
421
|
-
|
|
422
|
-
/*
|
|
423
|
-
* VtableA = {&A::foo}
|
|
424
|
-
* A::A(this){
|
|
425
|
-
* *this = &VtableA;
|
|
426
|
-
* }
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
* A* p = new A;
|
|
430
|
-
* cs: p->foo(...)
|
|
431
|
-
* ==>
|
|
432
|
-
* vtptr = *p;
|
|
433
|
-
* vfn = &vtptr[i]
|
|
434
|
-
* %funp = *vfn
|
|
435
|
-
* call %funp(p,...)
|
|
436
|
-
* getConstructorThisPtr(A) return "this" pointer
|
|
437
|
-
* getVCallThisPtr(cs) return p (this pointer)
|
|
438
|
-
* getVCallVtblPtr(cs) return vtptr
|
|
439
|
-
* getVCallIdx(cs) return i
|
|
440
|
-
* getClassNameFromVtblObj(VtableA) return
|
|
441
|
-
* getClassNameFromType(type of p) return type A
|
|
442
|
-
*/
|
|
443
|
-
const Argument* getConstructorThisPtr(const Function* fun);
|
|
444
|
-
const Value* getVCallThisPtr(const CallBase* cs);
|
|
445
|
-
const Value* getVCallVtblPtr(const CallBase* cs);
|
|
446
|
-
s32_t getVCallIdx(const CallBase* cs);
|
|
447
|
-
bool classTyHasVTable(const StructType* ty);
|
|
448
|
-
std::string getClassNameFromType(const StructType* ty);
|
|
449
|
-
std::string getClassNameOfThisPtr(const CallBase* cs);
|
|
450
|
-
std::string getFunNameOfVCallSite(const CallBase* cs);
|
|
451
|
-
bool VCallInCtorOrDtor(const CallBase* cs);
|
|
452
|
-
|
|
453
|
-
/*
|
|
454
|
-
* A(A* this){
|
|
455
|
-
* store this this.addr;
|
|
456
|
-
* tmp = load this.addr;
|
|
457
|
-
* this1 = bitcast(tmp);
|
|
458
|
-
* B(this1);
|
|
459
|
-
* }
|
|
460
|
-
* this and this1 are the same thisPtr in the constructor
|
|
461
|
-
*/
|
|
462
|
-
bool isSameThisPtrInConstructor(const Argument* thisPtr1,
|
|
463
|
-
const Value* thisPtr2);
|
|
464
|
-
|
|
465
361
|
std::string dumpValue(const Value* val);
|
|
466
362
|
|
|
467
363
|
std::string dumpType(const Type* type);
|
|
Binary file
|
|
Binary file
|
|
@@ -243,6 +243,7 @@ class SVFType
|
|
|
243
243
|
{
|
|
244
244
|
friend class SVFIRWriter;
|
|
245
245
|
friend class SVFIRReader;
|
|
246
|
+
friend class LLVMModuleSet;
|
|
246
247
|
|
|
247
248
|
public:
|
|
248
249
|
typedef s64_t GNodeK;
|
|
@@ -258,6 +259,25 @@ public:
|
|
|
258
259
|
SVFOtherTy,
|
|
259
260
|
};
|
|
260
261
|
|
|
262
|
+
public:
|
|
263
|
+
|
|
264
|
+
inline static SVFType* getPtrTy()
|
|
265
|
+
{
|
|
266
|
+
assert(ptrTy && "ptr type not set?");
|
|
267
|
+
return ptrTy;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
inline static SVFType* getI8Ty()
|
|
271
|
+
{
|
|
272
|
+
assert(i8Ty && "int8 type not set?");
|
|
273
|
+
return i8Ty;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private:
|
|
277
|
+
|
|
278
|
+
static SVFType* ptrTy; ///< ptr type
|
|
279
|
+
static SVFType* i8Ty; ///< 8-bit int type
|
|
280
|
+
|
|
261
281
|
private:
|
|
262
282
|
GNodeK kind; ///< used for classof
|
|
263
283
|
const SVFPointerType*
|
|
@@ -268,7 +288,7 @@ private:
|
|
|
268
288
|
///< array
|
|
269
289
|
|
|
270
290
|
protected:
|
|
271
|
-
SVFType(bool svt, SVFTyKind k, u32_t Sz)
|
|
291
|
+
SVFType(bool svt, SVFTyKind k, u32_t Sz = 1)
|
|
272
292
|
: kind(k), getPointerToTy(nullptr), typeinfo(nullptr),
|
|
273
293
|
isSingleValTy(svt), byteSize(Sz)
|
|
274
294
|
{
|
|
@@ -357,7 +377,7 @@ private:
|
|
|
357
377
|
const SVFType* ptrElementType;
|
|
358
378
|
|
|
359
379
|
public:
|
|
360
|
-
SVFPointerType(u32_t byteSize)
|
|
380
|
+
SVFPointerType(u32_t byteSize = 1)
|
|
361
381
|
: SVFType(true, SVFPointerTy, byteSize), ptrElementType(nullptr)
|
|
362
382
|
{
|
|
363
383
|
}
|
|
@@ -389,7 +409,7 @@ private:
|
|
|
389
409
|
short signAndWidth; ///< For printing
|
|
390
410
|
|
|
391
411
|
public:
|
|
392
|
-
SVFIntegerType(u32_t byteSize) : SVFType(true, SVFIntegerTy, byteSize) {}
|
|
412
|
+
SVFIntegerType(u32_t byteSize = 1) : SVFType(true, SVFIntegerTy, byteSize) {}
|
|
393
413
|
static inline bool classof(const SVFType* node)
|
|
394
414
|
{
|
|
395
415
|
return node->getKind() == SVFIntegerTy;
|
|
@@ -418,7 +438,7 @@ private:
|
|
|
418
438
|
|
|
419
439
|
public:
|
|
420
440
|
SVFFunctionType(const SVFType* rt)
|
|
421
|
-
: SVFType(false, SVFFunctionTy,
|
|
441
|
+
: SVFType(false, SVFFunctionTy, 1), retTy(rt)
|
|
422
442
|
{
|
|
423
443
|
}
|
|
424
444
|
static inline bool classof(const SVFType* node)
|
|
@@ -443,7 +463,7 @@ private:
|
|
|
443
463
|
std::string name;
|
|
444
464
|
|
|
445
465
|
public:
|
|
446
|
-
SVFStructType(u32_t byteSize) : SVFType(false, SVFStructTy, byteSize) {}
|
|
466
|
+
SVFStructType(u32_t byteSize = 1) : SVFType(false, SVFStructTy, byteSize) {}
|
|
447
467
|
|
|
448
468
|
static inline bool classof(const SVFType* node)
|
|
449
469
|
{
|
|
@@ -476,7 +496,7 @@ private:
|
|
|
476
496
|
const SVFType* typeOfElement; /// For printing & debugging
|
|
477
497
|
|
|
478
498
|
public:
|
|
479
|
-
SVFArrayType(u32_t byteSize)
|
|
499
|
+
SVFArrayType(u32_t byteSize = 1)
|
|
480
500
|
: SVFType(false, SVFArrayTy, byteSize), numOfElement(0), typeOfElement(nullptr)
|
|
481
501
|
{
|
|
482
502
|
}
|
|
@@ -515,7 +535,7 @@ private:
|
|
|
515
535
|
std::string repr; /// Field representation for printing
|
|
516
536
|
|
|
517
537
|
public:
|
|
518
|
-
SVFOtherType(u32_t byteSize
|
|
538
|
+
SVFOtherType(bool isSingleValueTy, u32_t byteSize = 1) : SVFType(isSingleValueTy, SVFOtherTy, byteSize) {}
|
|
519
539
|
|
|
520
540
|
static inline bool classof(const SVFType* node)
|
|
521
541
|
{
|