svf-lib 1.0.728 → 1.0.732
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/lib/libSvf.a +0 -0
- package/SVF-linux/include/DDA/DDAVFSolver.h +1 -1
- package/SVF-linux/include/Graphs/PAG.h +4 -4
- package/SVF-linux/include/Graphs/PAGNode.h +4 -4
- package/SVF-linux/include/MemoryModel/LocationSet.h +0 -1
- package/SVF-linux/include/MemoryModel/SVFIR.h +380 -0
- package/SVF-linux/include/MemoryModel/SVFSymbols.h +648 -0
- package/SVF-linux/include/MemoryModel/SymbolTableInfo.h +440 -0
- package/SVF-linux/include/SVF-FE/SymbolTableBuilder.h +90 -0
- package/SVF-linux/include/Util/BasicTypes.h +0 -10
- package/SVF-linux/include/Util/SVFUtil.h +11 -0
- package/SVF-linux/include/WPA/Andersen.h +0 -89
- package/SVF-osx/Release-build/lib/CUDD/libCudd.a +0 -0
- package/SVF-osx/Release-build/lib/libSvf.a +0 -0
- package/SVF-osx/include/DDA/DDAVFSolver.h +1 -1
- package/SVF-osx/include/Graphs/PAG.h +4 -4
- package/SVF-osx/include/Graphs/PAGNode.h +4 -4
- package/SVF-osx/include/MemoryModel/LocationSet.h +0 -1
- package/SVF-osx/include/MemoryModel/SVFIR.h +380 -0
- package/SVF-osx/include/MemoryModel/SVFSymbols.h +648 -0
- package/SVF-osx/include/MemoryModel/SymbolTableInfo.h +440 -0
- package/SVF-osx/include/SVF-FE/SymbolTableBuilder.h +90 -0
- package/SVF-osx/include/Util/BasicTypes.h +0 -10
- package/SVF-osx/include/Util/SVFUtil.h +11 -0
- package/SVF-osx/include/WPA/Andersen.h +0 -89
- package/package.json +1 -1
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
//===- SymbolTableInfo.h -- Symbol information from IR------------------------//
|
|
2
|
+
//
|
|
3
|
+
// SVF: Static Value-Flow Analysis
|
|
4
|
+
//
|
|
5
|
+
// Copyright (C) <2013-> <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 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 General Public License for more details.
|
|
17
|
+
|
|
18
|
+
// You should have received a copy of the GNU General Public License
|
|
19
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
//
|
|
21
|
+
//===----------------------------------------------------------------------===//
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* SymbolTableInfo.h
|
|
25
|
+
*
|
|
26
|
+
* Created on: Nov 11, 2013
|
|
27
|
+
* Author: Yulei Sui
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#ifndef INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_
|
|
31
|
+
#define INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_
|
|
32
|
+
|
|
33
|
+
#include "MemoryModel/SVFSymbols.h"
|
|
34
|
+
#include "Util/SVFUtil.h"
|
|
35
|
+
|
|
36
|
+
namespace SVF
|
|
37
|
+
{
|
|
38
|
+
|
|
39
|
+
/*!
|
|
40
|
+
* Symbol table of the memory model for analysis
|
|
41
|
+
*/
|
|
42
|
+
class SymbolTableInfo
|
|
43
|
+
{
|
|
44
|
+
friend class SymbolTableBuilder;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
/// various maps defined
|
|
48
|
+
//{@
|
|
49
|
+
/// llvm value to sym id map
|
|
50
|
+
/// local (%) and global (@) identifiers are pointer types which have a value node id.
|
|
51
|
+
typedef OrderedMap<const Value *, SymID> ValueToIDMapTy;
|
|
52
|
+
/// sym id to memory object map
|
|
53
|
+
typedef OrderedMap<SymID,ObjSym*> IDToMemMapTy;
|
|
54
|
+
/// function to sym id map
|
|
55
|
+
typedef OrderedMap<const Function *, SymID> FunToIDMapTy;
|
|
56
|
+
/// sym id to sym type map
|
|
57
|
+
typedef OrderedSet<const SVFVar*> SymSet;
|
|
58
|
+
/// struct type to struct info map
|
|
59
|
+
typedef OrderedMap<const Type*, StInfo*> TypeToFieldInfoMap;
|
|
60
|
+
typedef Set<CallSite> CallSiteSet;
|
|
61
|
+
typedef OrderedMap<const Instruction*,CallSiteID> CallSiteToIDMapTy;
|
|
62
|
+
typedef OrderedMap<CallSiteID,const Instruction*> IDToCallSiteMapTy;
|
|
63
|
+
|
|
64
|
+
//@}
|
|
65
|
+
|
|
66
|
+
private:
|
|
67
|
+
/// Data layout on a target machine
|
|
68
|
+
static DataLayout *dl;
|
|
69
|
+
|
|
70
|
+
ValueToIDMapTy valSymMap; ///< map a value to its sym id
|
|
71
|
+
ValueToIDMapTy objSymMap; ///< map a obj reference to its sym id
|
|
72
|
+
FunToIDMapTy returnSymMap; ///< return map
|
|
73
|
+
FunToIDMapTy varargSymMap; ///< vararg map
|
|
74
|
+
SymSet symSet; /// < a set of all symbols
|
|
75
|
+
IDToMemMapTy objMap; ///< map a memory sym id to its obj
|
|
76
|
+
|
|
77
|
+
CallSiteSet callSiteSet;
|
|
78
|
+
|
|
79
|
+
// Singleton pattern here to enable instance of SymbolTableInfo can only be created once.
|
|
80
|
+
static SymbolTableInfo* symInfo;
|
|
81
|
+
|
|
82
|
+
/// Module
|
|
83
|
+
SVFModule* mod;
|
|
84
|
+
|
|
85
|
+
/// Max field limit
|
|
86
|
+
static u32_t maxFieldLimit;
|
|
87
|
+
|
|
88
|
+
/// Clean up memory
|
|
89
|
+
void destroy();
|
|
90
|
+
|
|
91
|
+
/// Whether to model constants
|
|
92
|
+
bool modelConstants;
|
|
93
|
+
|
|
94
|
+
/// total number of symbols
|
|
95
|
+
SymID totalSymNum;
|
|
96
|
+
|
|
97
|
+
protected:
|
|
98
|
+
/// Constructor
|
|
99
|
+
SymbolTableInfo(void) :
|
|
100
|
+
mod(nullptr), modelConstants(false), totalSymNum(0), maxStruct(nullptr), maxStSize(0)
|
|
101
|
+
{
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public:
|
|
105
|
+
|
|
106
|
+
/// Singleton design here to make sure we only have one instance during any analysis
|
|
107
|
+
//@{
|
|
108
|
+
static SymbolTableInfo* SymbolInfo();
|
|
109
|
+
|
|
110
|
+
static void releaseSymbolInfo()
|
|
111
|
+
{
|
|
112
|
+
delete symInfo;
|
|
113
|
+
symInfo = nullptr;
|
|
114
|
+
}
|
|
115
|
+
virtual ~SymbolTableInfo()
|
|
116
|
+
{
|
|
117
|
+
destroy();
|
|
118
|
+
}
|
|
119
|
+
//@}
|
|
120
|
+
|
|
121
|
+
/// Set / Get modelConstants
|
|
122
|
+
//@{
|
|
123
|
+
void setModelConstants(bool _modelConstants)
|
|
124
|
+
{
|
|
125
|
+
modelConstants = _modelConstants;
|
|
126
|
+
}
|
|
127
|
+
bool getModelConstants() const
|
|
128
|
+
{
|
|
129
|
+
return modelConstants;
|
|
130
|
+
}
|
|
131
|
+
//@}
|
|
132
|
+
|
|
133
|
+
/// Get callsite set
|
|
134
|
+
//@{
|
|
135
|
+
inline const CallSiteSet& getCallSiteSet() const
|
|
136
|
+
{
|
|
137
|
+
return callSiteSet;
|
|
138
|
+
}
|
|
139
|
+
//@}
|
|
140
|
+
|
|
141
|
+
/// Module
|
|
142
|
+
inline SVFModule* getModule()
|
|
143
|
+
{
|
|
144
|
+
return mod;
|
|
145
|
+
}
|
|
146
|
+
/// Module
|
|
147
|
+
inline void setModule(SVFModule* m)
|
|
148
|
+
{
|
|
149
|
+
mod = m;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// Get target machine data layout
|
|
153
|
+
inline static DataLayout* getDataLayout(Module* mod)
|
|
154
|
+
{
|
|
155
|
+
if(dl==nullptr)
|
|
156
|
+
return dl = new DataLayout(mod);
|
|
157
|
+
return dl;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/// Helper method to get the size of the type from target data layout
|
|
161
|
+
//@{
|
|
162
|
+
u32_t getTypeSizeInBytes(const Type* type);
|
|
163
|
+
u32_t getTypeSizeInBytes(const StructType *sty, u32_t field_index);
|
|
164
|
+
//@}
|
|
165
|
+
|
|
166
|
+
/// special value
|
|
167
|
+
// @{
|
|
168
|
+
static bool isNullPtrSym(const Value *val);
|
|
169
|
+
|
|
170
|
+
static bool isBlackholeSym(const Value *val);
|
|
171
|
+
|
|
172
|
+
bool isConstantObjSym(const Value *val);
|
|
173
|
+
|
|
174
|
+
static inline bool isBlkPtr(NodeID id)
|
|
175
|
+
{
|
|
176
|
+
return (id == BlkPtr);
|
|
177
|
+
}
|
|
178
|
+
static inline bool isNullPtr(NodeID id)
|
|
179
|
+
{
|
|
180
|
+
return (id == NullPtr);
|
|
181
|
+
}
|
|
182
|
+
static inline bool isBlkObj(NodeID id)
|
|
183
|
+
{
|
|
184
|
+
return (id == BlackHole);
|
|
185
|
+
}
|
|
186
|
+
static inline bool isConstantObj(NodeID id)
|
|
187
|
+
{
|
|
188
|
+
return (id == ConstantObj);
|
|
189
|
+
}
|
|
190
|
+
static inline bool isBlkObjOrConstantObj(NodeID id)
|
|
191
|
+
{
|
|
192
|
+
return (isBlkObj(id) || isConstantObj(id));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
inline ObjSym* createBlkObj(SymID symId)
|
|
196
|
+
{
|
|
197
|
+
assert(isBlkObj(symId));
|
|
198
|
+
assert(objMap.find(symId)==objMap.end());
|
|
199
|
+
ObjSym* obj = new BlackHoleSym(symId, createObjTypeInfo());
|
|
200
|
+
objMap[symId] = obj;
|
|
201
|
+
return obj;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
inline ObjSym* createConstantObj(SymID symId)
|
|
205
|
+
{
|
|
206
|
+
assert(isConstantObj(symId));
|
|
207
|
+
assert(objMap.find(symId)==objMap.end());
|
|
208
|
+
ObjSym* obj = new ConstantObjSym(symId, createObjTypeInfo());
|
|
209
|
+
objMap[symId] = obj;
|
|
210
|
+
return obj;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
inline ObjSym* getBlkObj() const
|
|
214
|
+
{
|
|
215
|
+
return getObj(blackholeSymID());
|
|
216
|
+
}
|
|
217
|
+
inline ObjSym* getConstantObj() const
|
|
218
|
+
{
|
|
219
|
+
return getObj(constantSymID());
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
inline SymID blkPtrSymID() const
|
|
223
|
+
{
|
|
224
|
+
return BlkPtr;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
inline SymID nullPtrSymID() const
|
|
228
|
+
{
|
|
229
|
+
return NullPtr;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
inline SymID constantSymID() const
|
|
233
|
+
{
|
|
234
|
+
return ConstantObj;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
inline SymID blackholeSymID() const
|
|
238
|
+
{
|
|
239
|
+
return BlackHole;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/// Can only be invoked by PAG::addDummyNode() when creaing PAG from file.
|
|
243
|
+
inline const ObjSym* createDummyObj(SymID symId, const Type* type)
|
|
244
|
+
{
|
|
245
|
+
assert(objMap.find(symId)==objMap.end() && "this dummy obj has been created before");
|
|
246
|
+
ObjSym* memObj = new ObjSym(symId, createObjTypeInfo(type));
|
|
247
|
+
objMap[symId] = memObj;
|
|
248
|
+
symSet.insert(memObj);
|
|
249
|
+
return memObj;
|
|
250
|
+
}
|
|
251
|
+
// @}
|
|
252
|
+
|
|
253
|
+
/// Get different kinds of syms
|
|
254
|
+
//@{
|
|
255
|
+
SymID getValSym(const Value *val)
|
|
256
|
+
{
|
|
257
|
+
|
|
258
|
+
if(isNullPtrSym(val))
|
|
259
|
+
return nullPtrSymID();
|
|
260
|
+
else if(isBlackholeSym(val))
|
|
261
|
+
return blkPtrSymID();
|
|
262
|
+
else
|
|
263
|
+
{
|
|
264
|
+
ValueToIDMapTy::const_iterator iter = valSymMap.find(val);
|
|
265
|
+
assert(iter!=valSymMap.end() &&"value sym not found");
|
|
266
|
+
return iter->second;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
inline bool hasValSym(const Value* val)
|
|
271
|
+
{
|
|
272
|
+
if (isNullPtrSym(val) || isBlackholeSym(val))
|
|
273
|
+
return true;
|
|
274
|
+
else
|
|
275
|
+
return (valSymMap.find(val) != valSymMap.end());
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
inline SymID getObjSym(const Value *val) const
|
|
279
|
+
{
|
|
280
|
+
ValueToIDMapTy::const_iterator iter = objSymMap.find(SVFUtil::getGlobalRep(val));
|
|
281
|
+
assert(iter!=objSymMap.end() && "obj sym not found");
|
|
282
|
+
return iter->second;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
inline ObjSym* getObj(SymID id) const
|
|
286
|
+
{
|
|
287
|
+
IDToMemMapTy::const_iterator iter = objMap.find(id);
|
|
288
|
+
assert(iter!=objMap.end() && "obj not found");
|
|
289
|
+
return iter->second;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
inline SymID getRetSym(const Function *val) const
|
|
293
|
+
{
|
|
294
|
+
FunToIDMapTy::const_iterator iter = returnSymMap.find(val);
|
|
295
|
+
assert(iter!=returnSymMap.end() && "ret sym not found");
|
|
296
|
+
return iter->second;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
inline SymID getVarargSym(const Function *val) const
|
|
300
|
+
{
|
|
301
|
+
FunToIDMapTy::const_iterator iter = varargSymMap.find(val);
|
|
302
|
+
assert(iter!=varargSymMap.end() && "vararg sym not found");
|
|
303
|
+
return iter->second;
|
|
304
|
+
}
|
|
305
|
+
//@}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
/// Statistics
|
|
309
|
+
//@{
|
|
310
|
+
inline Size_t getTotalSymNum() const
|
|
311
|
+
{
|
|
312
|
+
return totalSymNum;
|
|
313
|
+
}
|
|
314
|
+
inline u32_t getMaxStructSize() const
|
|
315
|
+
{
|
|
316
|
+
return maxStSize;
|
|
317
|
+
}
|
|
318
|
+
//@}
|
|
319
|
+
|
|
320
|
+
/// Get different kinds of syms maps
|
|
321
|
+
//@{
|
|
322
|
+
inline ValueToIDMapTy& valSyms()
|
|
323
|
+
{
|
|
324
|
+
return valSymMap;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
inline ValueToIDMapTy& objSyms()
|
|
328
|
+
{
|
|
329
|
+
return objSymMap;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
inline IDToMemMapTy& idToObjMap()
|
|
333
|
+
{
|
|
334
|
+
return objMap;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
inline FunToIDMapTy& retSyms()
|
|
338
|
+
{
|
|
339
|
+
return returnSymMap;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
inline FunToIDMapTy& varargSyms()
|
|
343
|
+
{
|
|
344
|
+
return varargSymMap;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
//@}
|
|
348
|
+
|
|
349
|
+
/// Get struct info
|
|
350
|
+
//@{
|
|
351
|
+
///Get an iterator for StructInfo, designed as internal methods
|
|
352
|
+
TypeToFieldInfoMap::iterator getStructInfoIter(const Type *T)
|
|
353
|
+
{
|
|
354
|
+
assert(T);
|
|
355
|
+
TypeToFieldInfoMap::iterator it = typeToFieldInfo.find(T);
|
|
356
|
+
if (it != typeToFieldInfo.end())
|
|
357
|
+
return it;
|
|
358
|
+
else
|
|
359
|
+
{
|
|
360
|
+
collectTypeInfo(T);
|
|
361
|
+
return typeToFieldInfo.find(T);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
///Get a reference to StructInfo.
|
|
366
|
+
inline StInfo* getStructInfo(const Type *T)
|
|
367
|
+
{
|
|
368
|
+
return getStructInfoIter(T)->second;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
///Get a reference to the components of struct_info.
|
|
372
|
+
const inline std::vector<u32_t>& getFattenFieldIdxVec(const Type *T)
|
|
373
|
+
{
|
|
374
|
+
return getStructInfoIter(T)->second->getFieldIdxVec();
|
|
375
|
+
}
|
|
376
|
+
const inline std::vector<u32_t>& getFattenFieldOffsetVec(const Type *T)
|
|
377
|
+
{
|
|
378
|
+
return getStructInfoIter(T)->second->getFieldOffsetVec();
|
|
379
|
+
}
|
|
380
|
+
const inline std::vector<FieldInfo>& getFlattenFieldInfoVec(const Type *T)
|
|
381
|
+
{
|
|
382
|
+
return getStructInfoIter(T)->second->getFlattenFieldInfoVec();
|
|
383
|
+
}
|
|
384
|
+
const inline Type* getOrigSubTypeWithFldInx(const Type* baseType, u32_t field_idx)
|
|
385
|
+
{
|
|
386
|
+
return getStructInfoIter(baseType)->second->getFieldTypeWithFldIdx(field_idx);
|
|
387
|
+
}
|
|
388
|
+
const inline Type* getOrigSubTypeWithByteOffset(const Type* baseType, u32_t byteOffset)
|
|
389
|
+
{
|
|
390
|
+
return getStructInfoIter(baseType)->second->getFieldTypeWithByteOffset(byteOffset);
|
|
391
|
+
}
|
|
392
|
+
//@}
|
|
393
|
+
|
|
394
|
+
/// Compute gep offset
|
|
395
|
+
virtual bool computeGepOffset(const User *V, LocationSet& ls);
|
|
396
|
+
/// Get the base type and max offset
|
|
397
|
+
const Type *getBaseTypeAndFlattenedFields(const Value *V, std::vector<LocationSet> &fields);
|
|
398
|
+
/// Replace fields with flatten fields of T if the number of its fields is larger than msz.
|
|
399
|
+
u32_t getFields(std::vector<LocationSet>& fields, const Type* T, u32_t msz);
|
|
400
|
+
/// Collect type info
|
|
401
|
+
void collectTypeInfo(const Type* T);
|
|
402
|
+
/// Given an offset from a Gep Instruction, return it modulus offset by considering memory layout
|
|
403
|
+
virtual LocationSet getModulusOffset(const ObjSym* obj, const LocationSet& ls);
|
|
404
|
+
|
|
405
|
+
/// Debug method
|
|
406
|
+
void printFlattenFields(const Type* type);
|
|
407
|
+
|
|
408
|
+
static std::string toString(SYMTYPE symtype);
|
|
409
|
+
|
|
410
|
+
/// Another debug method
|
|
411
|
+
virtual void dump();
|
|
412
|
+
|
|
413
|
+
protected:
|
|
414
|
+
/// Collect the struct info
|
|
415
|
+
virtual void collectStructInfo(const StructType *T);
|
|
416
|
+
/// Collect the array info
|
|
417
|
+
virtual void collectArrayInfo(const ArrayType* T);
|
|
418
|
+
/// Collect simple type (non-aggregate) info
|
|
419
|
+
virtual void collectSimpleTypeInfo(const Type* T);
|
|
420
|
+
|
|
421
|
+
/// Create an objectInfo based on LLVM type (value is null, and type could be null, representing a dummy object)
|
|
422
|
+
ObjTypeInfo* createObjTypeInfo(const Type *type = nullptr);
|
|
423
|
+
|
|
424
|
+
/// Every type T is mapped to StInfo
|
|
425
|
+
/// which contains size (fsize) , offset(foffset)
|
|
426
|
+
/// fsize[i] is the number of fields in the largest such struct, else fsize[i] = 1.
|
|
427
|
+
/// fsize[0] is always the size of the expanded struct.
|
|
428
|
+
TypeToFieldInfoMap typeToFieldInfo;
|
|
429
|
+
|
|
430
|
+
///The struct type with the most fields
|
|
431
|
+
const Type* maxStruct;
|
|
432
|
+
|
|
433
|
+
///The number of fields in max_struct
|
|
434
|
+
u32_t maxStSize;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
} // End namespace SVF
|
|
439
|
+
|
|
440
|
+
#endif /* INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_ */
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//===- SymbolTableBuilder.h -- Symbol Table builder-----------------------//
|
|
2
|
+
//
|
|
3
|
+
// SVF: Static Value-Flow Analysis
|
|
4
|
+
//
|
|
5
|
+
// Copyright (C) <2013-> <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 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 General Public License for more details.
|
|
17
|
+
|
|
18
|
+
// You should have received a copy of the GNU General Public License
|
|
19
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
//
|
|
21
|
+
//===----------------------------------------------------------------------===//
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* SymbolTableBuilder.h
|
|
25
|
+
*
|
|
26
|
+
* Created on: Apr 28, 2014
|
|
27
|
+
* Author: Yulei
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#ifndef SymbolTableBuilder_H_
|
|
31
|
+
#define SymbolTableBuilder_H_
|
|
32
|
+
|
|
33
|
+
#include "MemoryModel/SVFSymbols.h"
|
|
34
|
+
#include "SVF-FE/LLVMModule.h"
|
|
35
|
+
#include "MemoryModel/SymbolTableInfo.h"
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* This class is to build SymbolTableInfo, MemObjs and ObjTypeInfo
|
|
39
|
+
*/
|
|
40
|
+
namespace SVF
|
|
41
|
+
{
|
|
42
|
+
|
|
43
|
+
class SymbolTableBuilder
|
|
44
|
+
{
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
SymbolTableInfo* symInfo;
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
/// Constructor
|
|
51
|
+
SymbolTableBuilder(SymbolTableInfo* si): symInfo(si){
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/// Start building memory model
|
|
55
|
+
void buildMemModel(SVFModule* svfModule);
|
|
56
|
+
|
|
57
|
+
/// collect the syms
|
|
58
|
+
//@{
|
|
59
|
+
void collectSym(const Value *val);
|
|
60
|
+
|
|
61
|
+
void collectVal(const Value *val);
|
|
62
|
+
|
|
63
|
+
void collectObj(const Value *val);
|
|
64
|
+
|
|
65
|
+
void collectRet(const Function *val);
|
|
66
|
+
|
|
67
|
+
void collectVararg(const Function *val);
|
|
68
|
+
//@}
|
|
69
|
+
|
|
70
|
+
/// Handle constant expression
|
|
71
|
+
// @{
|
|
72
|
+
void handleGlobalCE(const GlobalVariable *G);
|
|
73
|
+
void handleGlobalInitializerCE(const Constant *C, u32_t offset);
|
|
74
|
+
void handleCE(const Value *val);
|
|
75
|
+
// @}
|
|
76
|
+
|
|
77
|
+
/// Create an objectInfo based on LLVM value
|
|
78
|
+
ObjTypeInfo* createObjTypeInfo(const Value *val);
|
|
79
|
+
|
|
80
|
+
/// Initialize TypeInfo based on LLVM Value
|
|
81
|
+
void initTypeInfo(ObjTypeInfo* typeinfo, const Value* value);
|
|
82
|
+
/// Analyse types of all flattened fields of this object
|
|
83
|
+
void analyzeGlobalStackObjType(ObjTypeInfo* typeinfo, const Value* val);
|
|
84
|
+
/// Return size of this object based on LLVM value
|
|
85
|
+
u32_t getObjSize(const Value* val);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#endif /* SymbolTableBuilder_H_ */
|
|
@@ -300,16 +300,6 @@ public:
|
|
|
300
300
|
|
|
301
301
|
};
|
|
302
302
|
|
|
303
|
-
class SVFInstruction : public SVFValue
|
|
304
|
-
{
|
|
305
|
-
|
|
306
|
-
public:
|
|
307
|
-
SVFInstruction(const std::string& val): SVFValue(val,SVFValue::SVFInst)
|
|
308
|
-
{
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
};
|
|
312
|
-
|
|
313
303
|
class CallSite {
|
|
314
304
|
private:
|
|
315
305
|
CallBase *CB;
|
|
@@ -241,6 +241,17 @@ inline const SVFFunction* getFunction(StringRef name)
|
|
|
241
241
|
return nullptr;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
/// find the unique defined global across multiple modules
|
|
245
|
+
inline const Value* getGlobalRep(const Value* val)
|
|
246
|
+
{
|
|
247
|
+
if(const GlobalVariable* gvar = SVFUtil::dyn_cast<GlobalVariable>(val))
|
|
248
|
+
{
|
|
249
|
+
if (LLVMModuleSet::getLLVMModuleSet()->hasGlobalRep(gvar))
|
|
250
|
+
val = LLVMModuleSet::getLLVMModuleSet()->getGlobalRep(gvar);
|
|
251
|
+
}
|
|
252
|
+
return val;
|
|
253
|
+
}
|
|
254
|
+
|
|
244
255
|
/// Get the definition of a function across multiple modules
|
|
245
256
|
inline const SVFFunction* getDefFunForMultipleModule(const Function* fun)
|
|
246
257
|
{
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
namespace SVF
|
|
41
41
|
{
|
|
42
42
|
|
|
43
|
-
class PTAType;
|
|
44
43
|
class SVFModule;
|
|
45
44
|
|
|
46
45
|
/*!
|
|
@@ -464,94 +463,6 @@ protected:
|
|
|
464
463
|
};
|
|
465
464
|
|
|
466
465
|
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* Wave propagation with diff points-to set with type filter.
|
|
470
|
-
*/
|
|
471
|
-
class AndersenWaveDiffWithType : public AndersenWaveDiff
|
|
472
|
-
{
|
|
473
|
-
|
|
474
|
-
private:
|
|
475
|
-
|
|
476
|
-
typedef Map<NodeID, Set<const GepCGEdge*>> TypeMismatchedObjToEdgeTy;
|
|
477
|
-
|
|
478
|
-
TypeMismatchedObjToEdgeTy typeMismatchedObjToEdges;
|
|
479
|
-
|
|
480
|
-
void recordTypeMismatchedGep(NodeID obj, const GepCGEdge* gepEdge)
|
|
481
|
-
{
|
|
482
|
-
TypeMismatchedObjToEdgeTy::iterator it = typeMismatchedObjToEdges.find(obj);
|
|
483
|
-
if (it != typeMismatchedObjToEdges.end())
|
|
484
|
-
{
|
|
485
|
-
Set<const GepCGEdge*> &edges = it->second;
|
|
486
|
-
edges.insert(gepEdge);
|
|
487
|
-
}
|
|
488
|
-
else
|
|
489
|
-
{
|
|
490
|
-
Set<const GepCGEdge*> edges;
|
|
491
|
-
edges.insert(gepEdge);
|
|
492
|
-
typeMismatchedObjToEdges[obj] = edges;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
static AndersenWaveDiffWithType* diffWaveWithType; // static instance
|
|
497
|
-
|
|
498
|
-
/// Handle diff points-to set.
|
|
499
|
-
//@{
|
|
500
|
-
virtual inline void computeDiffPts(NodeID id)
|
|
501
|
-
{
|
|
502
|
-
NodeID rep = sccRepNode(id);
|
|
503
|
-
getDiffPTDataTy()->computeDiffPts(rep, getDiffPTDataTy()->getPts(rep));
|
|
504
|
-
}
|
|
505
|
-
virtual inline const PointsTo& getDiffPts(NodeID id)
|
|
506
|
-
{
|
|
507
|
-
NodeID rep = sccRepNode(id);
|
|
508
|
-
return getDiffPTDataTy()->getDiffPts(rep);
|
|
509
|
-
}
|
|
510
|
-
//@}
|
|
511
|
-
|
|
512
|
-
public:
|
|
513
|
-
AndersenWaveDiffWithType(PAG* _pag, PTATY type = AndersenWaveDiffWithType_WPA): AndersenWaveDiff(_pag,type)
|
|
514
|
-
{
|
|
515
|
-
assert(getTypeSystem()!=nullptr && "a type system is required for this pointer analysis");
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
/// Create an singleton instance directly instead of invoking llvm pass manager
|
|
519
|
-
static AndersenWaveDiffWithType* createAndersenWaveDiffWithType(PAG* p)
|
|
520
|
-
{
|
|
521
|
-
if(diffWaveWithType==nullptr)
|
|
522
|
-
{
|
|
523
|
-
diffWaveWithType = new AndersenWaveDiffWithType(p);
|
|
524
|
-
diffWaveWithType->analyze();
|
|
525
|
-
return diffWaveWithType;
|
|
526
|
-
}
|
|
527
|
-
return diffWaveWithType;
|
|
528
|
-
}
|
|
529
|
-
static void releaseAndersenWaveDiffWithType()
|
|
530
|
-
{
|
|
531
|
-
if (diffWaveWithType)
|
|
532
|
-
delete diffWaveWithType;
|
|
533
|
-
diffWaveWithType = nullptr;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
protected:
|
|
537
|
-
/// SCC detection
|
|
538
|
-
virtual NodeStack& SCCDetect();
|
|
539
|
-
/// merge types of nodes in a cycle
|
|
540
|
-
void mergeTypeOfNodes(const NodeBS &nodes);
|
|
541
|
-
/// process "bitcast" CopyCGEdge
|
|
542
|
-
virtual void processCast(const ConstraintEdge *edge);
|
|
543
|
-
/// update type of objects when process "bitcast" CopyCGEdge
|
|
544
|
-
void updateObjType(const Type *type, const PointsTo &objs);
|
|
545
|
-
/// process mismatched gep edges
|
|
546
|
-
void processTypeMismatchedGep(NodeID obj, const Type *type);
|
|
547
|
-
/// match types for Gep Edges
|
|
548
|
-
virtual bool matchType(NodeID ptrid, NodeID objid, const NormalGepCGEdge *normalGepEdge);
|
|
549
|
-
/// add type for newly created GepObjNode
|
|
550
|
-
virtual void addTypeForGepObjNode(NodeID id, const NormalGepCGEdge* normalGepEdge);
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
466
|
/*
|
|
556
467
|
* Lazy Cycle Detection Based Andersen Analysis
|
|
557
468
|
*/
|
|
Binary file
|
|
Binary file
|
|
@@ -448,7 +448,7 @@ protected:
|
|
|
448
448
|
assert(obj && "object not found!!");
|
|
449
449
|
if(obj->isStack())
|
|
450
450
|
{
|
|
451
|
-
if(const AllocaInst* local = SVFUtil::dyn_cast<AllocaInst>(obj->
|
|
451
|
+
if(const AllocaInst* local = SVFUtil::dyn_cast<AllocaInst>(obj->getValue()))
|
|
452
452
|
{
|
|
453
453
|
const SVFFunction* fun = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(local->getFunction());
|
|
454
454
|
return _callGraphSCC->isInCycle(_callGraph->getCallGraphNode(fun)->getId());
|