svf-lib 1.0.726 → 1.0.730
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/Graphs/PAGNode.h +1 -1
- package/SVF-linux/include/MemoryModel/LocationSet.h +0 -1
- package/SVF-linux/include/MemoryModel/SVFIR.h +380 -0
- package/SVF-linux/include/MemoryModel/SymbolTableInfo.h +428 -0
- package/SVF-linux/include/SVF-FE/MemModelBuilder.h +102 -0
- package/SVF-linux/include/SVF-FE/SymbolTableBuilder.h +90 -0
- package/SVF-linux/include/SVF-FE/SymbolTableInfo.h +7 -32
- package/SVF-linux/include/Util/BasicTypes.h +0 -10
- package/SVF-linux/include/Util/NodeIDAllocator.h +1 -1
- 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/Graphs/PAGNode.h +1 -1
- package/SVF-osx/include/MemoryModel/LocationSet.h +0 -1
- package/SVF-osx/include/MemoryModel/SVFIR.h +380 -0
- package/SVF-osx/include/MemoryModel/SymbolTableInfo.h +428 -0
- package/SVF-osx/include/SVF-FE/MemModelBuilder.h +102 -0
- package/SVF-osx/include/SVF-FE/SymbolTableBuilder.h +90 -0
- package/SVF-osx/include/SVF-FE/SymbolTableInfo.h +7 -32
- package/SVF-osx/include/Util/BasicTypes.h +0 -10
- package/SVF-osx/include/Util/NodeIDAllocator.h +1 -1
- 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,428 @@
|
|
|
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/MemModel.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,MemObj*> IDToMemMapTy;
|
|
54
|
+
/// function to sym id map
|
|
55
|
+
typedef OrderedMap<const Function *, SymID> FunToIDMapTy;
|
|
56
|
+
/// sym id to sym type map
|
|
57
|
+
typedef OrderedMap<SymID,SYMTYPE> IDToSymTyMapTy;
|
|
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
|
+
IDToMemMapTy objMap; ///< map a memory sym id to its obj
|
|
73
|
+
IDToSymTyMapTy symTyMap; /// < map a sym id to its type
|
|
74
|
+
FunToIDMapTy returnSymMap; ///< return map
|
|
75
|
+
FunToIDMapTy varargSymMap; ///< vararg map
|
|
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 void createBlkOrConstantObj(SymID symId)
|
|
196
|
+
{
|
|
197
|
+
assert(isBlkObjOrConstantObj(symId));
|
|
198
|
+
assert(objMap.find(symId)==objMap.end());
|
|
199
|
+
objMap[symId] = new MemObj(symId, createObjTypeInfo());;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
inline MemObj* getBlkObj() const
|
|
203
|
+
{
|
|
204
|
+
return getObj(blackholeSymID());
|
|
205
|
+
}
|
|
206
|
+
inline MemObj* getConstantObj() const
|
|
207
|
+
{
|
|
208
|
+
return getObj(constantSymID());
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
inline SymID blkPtrSymID() const
|
|
212
|
+
{
|
|
213
|
+
return BlkPtr;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
inline SymID nullPtrSymID() const
|
|
217
|
+
{
|
|
218
|
+
return NullPtr;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
inline SymID constantSymID() const
|
|
222
|
+
{
|
|
223
|
+
return ConstantObj;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
inline SymID blackholeSymID() const
|
|
227
|
+
{
|
|
228
|
+
return BlackHole;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/// Can only be invoked by PAG::addDummyNode() when creaing PAG from file.
|
|
232
|
+
inline const MemObj* createDummyObj(SymID symId, const Type* type)
|
|
233
|
+
{
|
|
234
|
+
assert(objMap.find(symId)==objMap.end() && "this dummy obj has been created before");
|
|
235
|
+
MemObj* memObj = new MemObj(symId, createObjTypeInfo(type));
|
|
236
|
+
objMap[symId] = memObj;
|
|
237
|
+
return memObj;
|
|
238
|
+
}
|
|
239
|
+
// @}
|
|
240
|
+
|
|
241
|
+
/// Get different kinds of syms
|
|
242
|
+
//@{
|
|
243
|
+
SymID getValSym(const Value *val)
|
|
244
|
+
{
|
|
245
|
+
|
|
246
|
+
if(isNullPtrSym(val))
|
|
247
|
+
return nullPtrSymID();
|
|
248
|
+
else if(isBlackholeSym(val))
|
|
249
|
+
return blkPtrSymID();
|
|
250
|
+
else
|
|
251
|
+
{
|
|
252
|
+
ValueToIDMapTy::const_iterator iter = valSymMap.find(val);
|
|
253
|
+
assert(iter!=valSymMap.end() &&"value sym not found");
|
|
254
|
+
return iter->second;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
inline bool hasValSym(const Value* val)
|
|
259
|
+
{
|
|
260
|
+
if (isNullPtrSym(val) || isBlackholeSym(val))
|
|
261
|
+
return true;
|
|
262
|
+
else
|
|
263
|
+
return (valSymMap.find(val) != valSymMap.end());
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
inline SymID getObjSym(const Value *val) const
|
|
267
|
+
{
|
|
268
|
+
ValueToIDMapTy::const_iterator iter = objSymMap.find(SVFUtil::getGlobalRep(val));
|
|
269
|
+
assert(iter!=objSymMap.end() && "obj sym not found");
|
|
270
|
+
return iter->second;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
inline MemObj* getObj(SymID id) const
|
|
274
|
+
{
|
|
275
|
+
IDToMemMapTy::const_iterator iter = objMap.find(id);
|
|
276
|
+
assert(iter!=objMap.end() && "obj not found");
|
|
277
|
+
return iter->second;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
inline SymID getRetSym(const Function *val) const
|
|
281
|
+
{
|
|
282
|
+
FunToIDMapTy::const_iterator iter = returnSymMap.find(val);
|
|
283
|
+
assert(iter!=returnSymMap.end() && "ret sym not found");
|
|
284
|
+
return iter->second;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
inline SymID getVarargSym(const Function *val) const
|
|
288
|
+
{
|
|
289
|
+
FunToIDMapTy::const_iterator iter = varargSymMap.find(val);
|
|
290
|
+
assert(iter!=varargSymMap.end() && "vararg sym not found");
|
|
291
|
+
return iter->second;
|
|
292
|
+
}
|
|
293
|
+
//@}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
/// Statistics
|
|
297
|
+
//@{
|
|
298
|
+
inline Size_t getTotalSymNum() const
|
|
299
|
+
{
|
|
300
|
+
return totalSymNum;
|
|
301
|
+
}
|
|
302
|
+
inline u32_t getMaxStructSize() const
|
|
303
|
+
{
|
|
304
|
+
return maxStSize;
|
|
305
|
+
}
|
|
306
|
+
//@}
|
|
307
|
+
|
|
308
|
+
/// Get different kinds of syms maps
|
|
309
|
+
//@{
|
|
310
|
+
inline ValueToIDMapTy& valSyms()
|
|
311
|
+
{
|
|
312
|
+
return valSymMap;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
inline ValueToIDMapTy& objSyms()
|
|
316
|
+
{
|
|
317
|
+
return objSymMap;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
inline IDToMemMapTy& idToObjMap()
|
|
321
|
+
{
|
|
322
|
+
return objMap;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
inline FunToIDMapTy& retSyms()
|
|
326
|
+
{
|
|
327
|
+
return returnSymMap;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
inline FunToIDMapTy& varargSyms()
|
|
331
|
+
{
|
|
332
|
+
return varargSymMap;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
//@}
|
|
336
|
+
|
|
337
|
+
/// Get struct info
|
|
338
|
+
//@{
|
|
339
|
+
///Get an iterator for StructInfo, designed as internal methods
|
|
340
|
+
TypeToFieldInfoMap::iterator getStructInfoIter(const Type *T)
|
|
341
|
+
{
|
|
342
|
+
assert(T);
|
|
343
|
+
TypeToFieldInfoMap::iterator it = typeToFieldInfo.find(T);
|
|
344
|
+
if (it != typeToFieldInfo.end())
|
|
345
|
+
return it;
|
|
346
|
+
else
|
|
347
|
+
{
|
|
348
|
+
collectTypeInfo(T);
|
|
349
|
+
return typeToFieldInfo.find(T);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
///Get a reference to StructInfo.
|
|
354
|
+
inline StInfo* getStructInfo(const Type *T)
|
|
355
|
+
{
|
|
356
|
+
return getStructInfoIter(T)->second;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
///Get a reference to the components of struct_info.
|
|
360
|
+
const inline std::vector<u32_t>& getFattenFieldIdxVec(const Type *T)
|
|
361
|
+
{
|
|
362
|
+
return getStructInfoIter(T)->second->getFieldIdxVec();
|
|
363
|
+
}
|
|
364
|
+
const inline std::vector<u32_t>& getFattenFieldOffsetVec(const Type *T)
|
|
365
|
+
{
|
|
366
|
+
return getStructInfoIter(T)->second->getFieldOffsetVec();
|
|
367
|
+
}
|
|
368
|
+
const inline std::vector<FieldInfo>& getFlattenFieldInfoVec(const Type *T)
|
|
369
|
+
{
|
|
370
|
+
return getStructInfoIter(T)->second->getFlattenFieldInfoVec();
|
|
371
|
+
}
|
|
372
|
+
const inline Type* getOrigSubTypeWithFldInx(const Type* baseType, u32_t field_idx)
|
|
373
|
+
{
|
|
374
|
+
return getStructInfoIter(baseType)->second->getFieldTypeWithFldIdx(field_idx);
|
|
375
|
+
}
|
|
376
|
+
const inline Type* getOrigSubTypeWithByteOffset(const Type* baseType, u32_t byteOffset)
|
|
377
|
+
{
|
|
378
|
+
return getStructInfoIter(baseType)->second->getFieldTypeWithByteOffset(byteOffset);
|
|
379
|
+
}
|
|
380
|
+
//@}
|
|
381
|
+
|
|
382
|
+
/// Compute gep offset
|
|
383
|
+
virtual bool computeGepOffset(const User *V, LocationSet& ls);
|
|
384
|
+
/// Get the base type and max offset
|
|
385
|
+
const Type *getBaseTypeAndFlattenedFields(const Value *V, std::vector<LocationSet> &fields);
|
|
386
|
+
/// Replace fields with flatten fields of T if the number of its fields is larger than msz.
|
|
387
|
+
u32_t getFields(std::vector<LocationSet>& fields, const Type* T, u32_t msz);
|
|
388
|
+
/// Collect type info
|
|
389
|
+
void collectTypeInfo(const Type* T);
|
|
390
|
+
/// Given an offset from a Gep Instruction, return it modulus offset by considering memory layout
|
|
391
|
+
virtual LocationSet getModulusOffset(const MemObj* obj, const LocationSet& ls);
|
|
392
|
+
|
|
393
|
+
/// Debug method
|
|
394
|
+
void printFlattenFields(const Type* type);
|
|
395
|
+
|
|
396
|
+
static std::string toString(SYMTYPE symtype);
|
|
397
|
+
|
|
398
|
+
/// Another debug method
|
|
399
|
+
virtual void dump();
|
|
400
|
+
|
|
401
|
+
protected:
|
|
402
|
+
/// Collect the struct info
|
|
403
|
+
virtual void collectStructInfo(const StructType *T);
|
|
404
|
+
/// Collect the array info
|
|
405
|
+
virtual void collectArrayInfo(const ArrayType* T);
|
|
406
|
+
/// Collect simple type (non-aggregate) info
|
|
407
|
+
virtual void collectSimpleTypeInfo(const Type* T);
|
|
408
|
+
|
|
409
|
+
/// Create an objectInfo based on LLVM type (value is null, and type could be null, representing a dummy object)
|
|
410
|
+
ObjTypeInfo* createObjTypeInfo(const Type *type = nullptr);
|
|
411
|
+
|
|
412
|
+
/// Every type T is mapped to StInfo
|
|
413
|
+
/// which contains size (fsize) , offset(foffset)
|
|
414
|
+
/// fsize[i] is the number of fields in the largest such struct, else fsize[i] = 1.
|
|
415
|
+
/// fsize[0] is always the size of the expanded struct.
|
|
416
|
+
TypeToFieldInfoMap typeToFieldInfo;
|
|
417
|
+
|
|
418
|
+
///The struct type with the most fields
|
|
419
|
+
const Type* maxStruct;
|
|
420
|
+
|
|
421
|
+
///The number of fields in max_struct
|
|
422
|
+
u32_t maxStSize;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
} // End namespace SVF
|
|
427
|
+
|
|
428
|
+
#endif /* INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_ */
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//===- LocMemModel.h -- Memory model builder-----------------------//
|
|
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 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
|
+
* MemModelBuilder.h
|
|
25
|
+
*
|
|
26
|
+
* Created on: Apr 28, 2014
|
|
27
|
+
* Author: Yulei
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#ifndef MEMMODELBUILDER_H_
|
|
31
|
+
#define MEMMODELBUILDER_H_
|
|
32
|
+
|
|
33
|
+
#include "MemoryModel/MemModel.h"
|
|
34
|
+
#include "SVF-FE/LLVMModule.h"
|
|
35
|
+
#include "SVF-FE/SymbolTableInfo.h"
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* This class is to build SymbolTableInfo, MemObjs and ObjTypeInfo
|
|
39
|
+
*/
|
|
40
|
+
namespace SVF
|
|
41
|
+
{
|
|
42
|
+
|
|
43
|
+
class MemModelBuilder
|
|
44
|
+
{
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
SymbolTableInfo* symInfo;
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
/// Constructor
|
|
51
|
+
MemModelBuilder(SymbolTableInfo* si): symInfo(si){
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Start building memory model
|
|
56
|
+
void buildMemModel(SVFModule* svfModule);
|
|
57
|
+
|
|
58
|
+
/// collect the syms
|
|
59
|
+
//@{
|
|
60
|
+
void collectSym(const Value *val);
|
|
61
|
+
|
|
62
|
+
void collectVal(const Value *val);
|
|
63
|
+
|
|
64
|
+
void collectObj(const Value *val);
|
|
65
|
+
|
|
66
|
+
void collectRet(const Function *val);
|
|
67
|
+
|
|
68
|
+
void collectVararg(const Function *val);
|
|
69
|
+
//@}
|
|
70
|
+
|
|
71
|
+
/// Handle constant expression
|
|
72
|
+
// @{
|
|
73
|
+
void handleGlobalCE(const GlobalVariable *G);
|
|
74
|
+
void handleGlobalInitializerCE(const Constant *C, u32_t offset);
|
|
75
|
+
void handleCE(const Value *val);
|
|
76
|
+
// @}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// /// Collect the struct info
|
|
80
|
+
// virtual void collectStructInfo(const StructType *T);
|
|
81
|
+
// /// Collect the array info
|
|
82
|
+
// virtual void collectArrayInfo(const ArrayType* T);
|
|
83
|
+
// /// Collect simple type (non-aggregate) info
|
|
84
|
+
// virtual void collectSimpleTypeInfo(const Type* T);
|
|
85
|
+
|
|
86
|
+
/// Create an objectInfo based on LLVM value
|
|
87
|
+
ObjTypeInfo* createObjTypeInfo(const Value *val);
|
|
88
|
+
/// Create an objectInfo based on LLVM type (value is null, and type could be null, representing a dummy object)
|
|
89
|
+
// ObjTypeInfo* createObjTypeInfo(const Type *type = nullptr);
|
|
90
|
+
|
|
91
|
+
/// Initialize TypeInfo based on LLVM Value
|
|
92
|
+
void initTypeInfo(ObjTypeInfo* typeinfo, const Value* value);
|
|
93
|
+
/// Analyse types of all flattened fields of this object
|
|
94
|
+
void analyzeGlobalStackObjType(ObjTypeInfo* typeinfo, const Value* val);
|
|
95
|
+
/// Return size of this object based on LLVM value
|
|
96
|
+
u32_t getObjSize(const Value* val);
|
|
97
|
+
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#endif /* MEMMODELBUILDER_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/MemModel.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_ */
|
|
@@ -42,6 +42,8 @@ namespace SVF
|
|
|
42
42
|
class SymbolTableInfo
|
|
43
43
|
{
|
|
44
44
|
|
|
45
|
+
friend class MemModelBuilder;
|
|
46
|
+
|
|
45
47
|
public:
|
|
46
48
|
/// various maps defined
|
|
47
49
|
//{@
|
|
@@ -142,6 +144,11 @@ public:
|
|
|
142
144
|
{
|
|
143
145
|
return mod;
|
|
144
146
|
}
|
|
147
|
+
/// Module
|
|
148
|
+
inline void setModule(SVFModule* m)
|
|
149
|
+
{
|
|
150
|
+
mod = m;
|
|
151
|
+
}
|
|
145
152
|
|
|
146
153
|
/// Get target machine data layout
|
|
147
154
|
inline static DataLayout* getDataLayout(Module* mod)
|
|
@@ -157,22 +164,6 @@ public:
|
|
|
157
164
|
u32_t getTypeSizeInBytes(const StructType *sty, u32_t field_index);
|
|
158
165
|
//@}
|
|
159
166
|
|
|
160
|
-
/// Start building memory model
|
|
161
|
-
void buildMemModel(SVFModule* svfModule);
|
|
162
|
-
|
|
163
|
-
/// collect the syms
|
|
164
|
-
//@{
|
|
165
|
-
void collectSym(const Value *val);
|
|
166
|
-
|
|
167
|
-
void collectVal(const Value *val);
|
|
168
|
-
|
|
169
|
-
void collectObj(const Value *val);
|
|
170
|
-
|
|
171
|
-
void collectRet(const Function *val);
|
|
172
|
-
|
|
173
|
-
void collectVararg(const Function *val);
|
|
174
|
-
//@}
|
|
175
|
-
|
|
176
167
|
/// special value
|
|
177
168
|
// @{
|
|
178
169
|
static bool isNullPtrSym(const Value *val);
|
|
@@ -248,13 +239,6 @@ public:
|
|
|
248
239
|
}
|
|
249
240
|
// @}
|
|
250
241
|
|
|
251
|
-
/// Handle constant expression
|
|
252
|
-
// @{
|
|
253
|
-
void handleGlobalCE(const GlobalVariable *G);
|
|
254
|
-
void handleGlobalInitializerCE(const Constant *C, u32_t offset);
|
|
255
|
-
void handleCE(const Value *val);
|
|
256
|
-
// @}
|
|
257
|
-
|
|
258
242
|
/// Get different kinds of syms
|
|
259
243
|
//@{
|
|
260
244
|
SymID getValSym(const Value *val)
|
|
@@ -433,18 +417,9 @@ protected:
|
|
|
433
417
|
/// Collect simple type (non-aggregate) info
|
|
434
418
|
virtual void collectSimpleTypeInfo(const Type* T);
|
|
435
419
|
|
|
436
|
-
/// Create an objectInfo based on LLVM value
|
|
437
|
-
ObjTypeInfo* createObjTypeInfo(const Value *val);
|
|
438
420
|
/// Create an objectInfo based on LLVM type (value is null, and type could be null, representing a dummy object)
|
|
439
421
|
ObjTypeInfo* createObjTypeInfo(const Type *type = nullptr);
|
|
440
422
|
|
|
441
|
-
/// Initialize TypeInfo based on LLVM Value
|
|
442
|
-
void initTypeInfo(ObjTypeInfo* typeinfo, const Value* value);
|
|
443
|
-
/// Analyse types of all flattened fields of this object
|
|
444
|
-
void analyzeGlobalStackObjType(ObjTypeInfo* typeinfo, const Value* val);
|
|
445
|
-
/// Return size of this object based on LLVM value
|
|
446
|
-
u32_t getObjSize(const Value* val);
|
|
447
|
-
|
|
448
423
|
/// Every type T is mapped to StInfo
|
|
449
424
|
/// which contains size (fsize) , offset(foffset)
|
|
450
425
|
/// fsize[i] is the number of fields in the largest such struct, else fsize[i] = 1.
|
|
@@ -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;
|