svf-lib 1.0.1823 → 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.
@@ -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,6 +32,7 @@
32
32
 
33
33
  #include "Graphs/ICFG.h"
34
34
  #include "Util/WorkList.h"
35
+ #include "BasicTypes.h"
35
36
 
36
37
  namespace SVF
37
38
  {
@@ -31,7 +31,6 @@
31
31
  #define INCLUDE_SVF_FE_LLVMMODULE_H_
32
32
 
33
33
  #include "SVF-LLVM/BasicTypes.h"
34
- #include "Util/CppUtil.h"
35
34
  #include "SVFIR/SVFValue.h"
36
35
  #include "SVFIR/SVFModule.h"
37
36
  #include "Util/Options.h"
@@ -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
- inline const Function* getDefFunForMultipleModule(const Function* fun)
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
- inline const Function* getProgFunction(const std::string& funName)
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
- inline const SVFFunction* getFunction(const std::string& name)
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
- inline const Value* getGlobalRep(const Value* val)
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1823",
3
+ "version": "1.0.1824",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {