svf-tools 1.0.987 → 1.0.988

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-tools",
3
- "version": "1.0.987",
3
+ "version": "1.0.988",
4
4
  "description": "* <b>[TypeClone](https://github.com/SVF-tools/SVF/wiki/TypeClone) published in our [ECOOP paper](https://yuleisui.github.io/publications/ecoop20.pdf) is now available in SVF </b> * <b>SVF now uses a single script for its build. Just type [`source ./build.sh`](https://github.com/SVF-tools/SVF/blob/master/build.sh) in your terminal, that's it!</b> * <b>SVF now supports LLVM-10.0.0! </b> * <b>We thank [bsauce](https://github.com/bsauce) for writing a user manual of SVF ([link1](https://www.jianshu.com/p/068a08ec749c) and [link2](https://www.jianshu.com/p/777c30d4240e)) in Chinese </b> * <b>SVF now supports LLVM-9.0.0 (Thank [Byoungyoung Lee](https://github.com/SVF-tools/SVF/issues/142) for his help!). </b> * <b>SVF now supports a set of [field-sensitive pointer analyses](https://yuleisui.github.io/publications/sas2019a.pdf). </b> * <b>[Use SVF as an external lib](https://github.com/SVF-tools/SVF/wiki/Using-SVF-as-a-lib-in-your-own-tool) for your own project (Contributed by [Hongxu Chen](https://github.com/HongxuChen)). </b> * <b>SVF now supports LLVM-7.0.0. </b> * <b>SVF now supports Docker. [Try SVF in Docker](https://github.com/SVF-tools/SVF/wiki/Try-SVF-in-Docker)! </b> * <b>SVF now supports [LLVM-6.0.0](https://github.com/svf-tools/SVF/pull/38) (Contributed by [Jack Anthony](https://github.com/jackanth)). </b> * <b>SVF now supports [LLVM-4.0.0](https://github.com/svf-tools/SVF/pull/23) (Contributed by Jared Carlson. Thank [Jared](https://github.com/jcarlson23) and [Will](https://github.com/dtzWill) for their in-depth [discussions](https://github.com/svf-tools/SVF/pull/18) about updating SVF!) </b> * <b>SVF now supports analysis for C++ programs.</b> <br />",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -319,7 +319,6 @@ private:
319
319
  const SVFFunction* realDefFun; /// the definition of a function across multiple modules
320
320
  std::vector<const SVFBasicBlock*> allBBs; /// all BasicBlocks of this function
321
321
  std::vector<const SVFArgument*> allArgs; /// all formal arguments of this function
322
- std::vector<std::string> annotations; /// annotations of this function
323
322
  SVFBasicBlock *exitBlock; /// a 'single' basic block having no successors and containing return instruction in a function
324
323
 
325
324
  protected:
@@ -463,16 +462,6 @@ public:
463
462
  return !isNotRet;
464
463
  }
465
464
 
466
- inline const std::vector<std::string>& getAnnotations() const
467
- {
468
- return annotations;
469
- }
470
-
471
- inline void setAnnotations(std::vector<std::string>& annotations)
472
- {
473
- this->annotations = annotations;
474
- }
475
-
476
465
  inline void getExitBlocksOfLoop(const SVFBasicBlock* bb, BBList& exitbbs) const
477
466
  {
478
467
  return loopAndDom->getExitBlocksOfLoop(bb,exitbbs);
@@ -43,10 +43,14 @@ namespace SVF
43
43
 
44
44
  class ExtAPI
45
45
  {
46
+ friend class LLVMModuleSet;
46
47
  private:
47
48
 
48
49
  static ExtAPI *extOp;
49
50
 
51
+ // Map SVFFunction to its annotations
52
+ Map<const SVFFunction*, std::vector<std::string>> func2Annotations;
53
+
50
54
  // extapi.bc file path
51
55
  static std::string extBcPath;
52
56
 
@@ -67,6 +71,8 @@ public:
67
71
  // Get the annotation of (F)
68
72
  std::string getExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation);
69
73
 
74
+ const std::vector<std::string>& getExtFuncAnnotations(const SVFFunction* fun);
75
+
70
76
  // Does (F) have some annotation?
71
77
  bool hasExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation);
72
78
 
@@ -94,6 +100,10 @@ public:
94
100
  // Should (F) be considered "external" (either not defined in the program
95
101
  // or a user-defined version of a known alloc or no-op)?
96
102
  bool is_ext(const SVFFunction *F);
103
+
104
+ private:
105
+ // Set the annotation of (F)
106
+ void setExtFuncAnnotations(const SVFFunction* fun, const std::vector<std::string>& funcAnnotations);
97
107
  };
98
108
  } // End namespace SVF
99
109
 
@@ -391,19 +391,13 @@ bool isExtCall(const ICFGNode* node);
391
391
 
392
392
  bool isHeapAllocExtCallViaArg(const CallICFGNode* cs);
393
393
 
394
- bool isHeapAllocExtCallViaArg(const SVFInstruction *inst);
395
-
396
- bool isHeapAllocExtCallViaRet(const SVFInstruction *inst);
397
394
 
398
395
  /// interfaces to be used externally
399
396
  bool isHeapAllocExtCallViaRet(const CallICFGNode* cs);
400
397
 
401
398
  bool isHeapAllocExtCall(const ICFGNode* cs);
402
399
 
403
- inline bool isHeapAllocExtCall(const SVFInstruction *inst)
404
- {
405
- return isHeapAllocExtCallViaRet(inst) || isHeapAllocExtCallViaArg(inst);
406
- }
400
+
407
401
 
408
402
  //@}
409
403
 
@@ -150,7 +150,7 @@ void BufOverflowDetector::detectExtAPI(AbstractState& as,
150
150
  AbstractInterpretation::ExtAPIType extType = AbstractInterpretation::UNCLASSIFIED;
151
151
 
152
152
  // Determine the type of external memory API
153
- for (const std::string &annotation : call->getCalledFunction()->getAnnotations())
153
+ for (const std::string &annotation : ExtAPI::getExtAPI()->getExtFuncAnnotations(call->getCalledFunction()))
154
154
  {
155
155
  if (annotation.find("MEMCPY") != std::string::npos)
156
156
  extType = AbstractInterpretation::MEMCPY;
@@ -1377,7 +1377,7 @@ void AbstractInterpretation::handleExtAPI(const CallICFGNode *call)
1377
1377
  assert(fun && "SVFFunction* is nullptr");
1378
1378
  ExtAPIType extType = UNCLASSIFIED;
1379
1379
  // get type of mem api
1380
- for (const std::string &annotation: fun->getAnnotations())
1380
+ for (const std::string &annotation: ExtAPI::getExtAPI()->getExtFuncAnnotations(fun))
1381
1381
  {
1382
1382
  if (annotation.find("MEMCPY") != std::string::npos)
1383
1383
  extType = MEMCPY;
@@ -549,7 +549,6 @@ cJSON* SVFIRWriter::contentToJson(const SVFFunction* value)
549
549
  F(realDefFun);
550
550
  F(allBBs);
551
551
  F(allArgs);
552
- F(annotations);
553
552
  #undef F
554
553
  return root;
555
554
  }
@@ -2357,7 +2356,6 @@ void SVFIRReader::fill(const cJSON*& fieldJson, SVFFunction* value)
2357
2356
  F(realDefFun);
2358
2357
  F(allBBs);
2359
2358
  F(allArgs);
2360
- F(annotations);
2361
2359
  #undef F
2362
2360
  }
2363
2361
 
@@ -161,24 +161,47 @@ std::string ExtAPI::getExtBcPath()
161
161
  abort();
162
162
  }
163
163
 
164
- std::string ExtAPI::getExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation)
164
+ void ExtAPI::setExtFuncAnnotations(const SVFFunction* fun, const std::vector<std::string>& funcAnnotations)
165
165
  {
166
166
  assert(fun && "Null SVFFunction* pointer");
167
- for (const std::string& annotation : fun->getAnnotations())
168
- if (annotation.find(funcAnnotation) != std::string::npos)
169
- return annotation;
170
- return "";
167
+ func2Annotations[fun] = funcAnnotations;
171
168
  }
172
169
 
173
170
  bool ExtAPI::hasExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation)
174
171
  {
175
172
  assert(fun && "Null SVFFunction* pointer");
176
- for (const std::string& annotation : fun->getAnnotations())
177
- if (annotation.find(funcAnnotation) != std::string::npos)
178
- return true;
173
+ auto it = func2Annotations.find(fun);
174
+ if (it != func2Annotations.end())
175
+ {
176
+ for (const std::string& annotation : it->second)
177
+ if (annotation.find(funcAnnotation) != std::string::npos)
178
+ return true;
179
+ }
179
180
  return false;
180
181
  }
181
182
 
183
+ std::string ExtAPI::getExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation)
184
+ {
185
+ assert(fun && "Null SVFFunction* pointer");
186
+ auto it = func2Annotations.find(fun);
187
+ if (it != func2Annotations.end())
188
+ {
189
+ for (const std::string& annotation : it->second)
190
+ if (annotation.find(funcAnnotation) != std::string::npos)
191
+ return annotation;
192
+ }
193
+ return "";
194
+ }
195
+
196
+ const std::vector<std::string>& ExtAPI::getExtFuncAnnotations(const SVFFunction* fun)
197
+ {
198
+ assert(fun && "Null SVFFunction* pointer");
199
+ auto it = func2Annotations.find(fun);
200
+ if (it != func2Annotations.end())
201
+ return it->second;
202
+ return func2Annotations[fun];
203
+ }
204
+
182
205
  bool ExtAPI::is_memcpy(const SVFFunction *F)
183
206
  {
184
207
  return F &&
@@ -232,8 +255,8 @@ bool ExtAPI::is_ext(const SVFFunction* F)
232
255
  assert(F && "Null SVFFunction* pointer");
233
256
  if (F->isDeclaration() || F->isIntrinsic())
234
257
  return true;
235
- else if (hasExtFuncAnnotation(F, "OVERWRITE") && F->getAnnotations().size() == 1)
258
+ else if (hasExtFuncAnnotation(F, "OVERWRITE") && getExtFuncAnnotations(F).size() == 1)
236
259
  return false;
237
260
  else
238
- return !F->getAnnotations().empty();
261
+ return !getExtFuncAnnotations(F).empty();
239
262
  }
@@ -353,13 +353,6 @@ bool SVFUtil::isHeapAllocExtCallViaArg(const CallICFGNode* cs)
353
353
  return isHeapAllocExtFunViaArg(cs->getCalledFunction());
354
354
  }
355
355
 
356
- bool SVFUtil::isHeapAllocExtCallViaArg(const SVFInstruction *inst)
357
- {
358
- if(const SVFCallInst* call = SVFUtil::dyn_cast<SVFCallInst>(inst))
359
- return isHeapAllocExtFunViaArg(call->getCalledFunction());
360
- else
361
- return false;
362
- }
363
356
 
364
357
  u32_t SVFUtil::getHeapAllocHoldingArgPosition(const CallICFGNode* cs)
365
358
  {
@@ -391,14 +384,6 @@ bool SVFUtil::isReallocExtCall(const CallICFGNode* cs)
391
384
  return isPtrTy && isReallocExtFun(cs->getCalledFunction());
392
385
  }
393
386
 
394
- bool SVFUtil::isHeapAllocExtCallViaRet(const SVFInstruction *inst)
395
- {
396
- bool isPtrTy = inst->getType()->isPointerTy();
397
- if(const SVFCallInst* call = SVFUtil::dyn_cast<SVFCallInst>(inst))
398
- return isPtrTy && isHeapAllocExtFunViaRet(call->getCalledFunction());
399
- else
400
- return false;
401
- }
402
387
 
403
388
  bool SVFUtil::isRetInstNode(const ICFGNode* node)
404
389
  {
@@ -61,7 +61,7 @@ public:
61
61
  typedef Map<const SVFValue*, const Value*> SVFValue2LLVMValueMap;
62
62
  typedef Map<const Type*, SVFType*> LLVMType2SVFTypeMap;
63
63
  typedef Map<const Type*, StInfo*> Type2TypeInfoMap;
64
- typedef Map<const Function*, std::vector<std::string>> Fun2AnnoMap;
64
+ typedef Map<std::string, std::vector<std::string>> Fun2AnnoMap;
65
65
 
66
66
  private:
67
67
  static LLVMModuleSet* llvmModuleSet;
@@ -72,10 +72,6 @@ private:
72
72
  std::vector<std::unique_ptr<Module>> owned_modules;
73
73
  std::vector<std::reference_wrapper<Module>> modules;
74
74
 
75
- /// Function declaration to function definition map
76
- FunDeclToDefMapTy FunDeclToDefMap;
77
- /// Function definition to function declaration map
78
- FunDefToDeclsMapTy FunDefToDeclsMap;
79
75
  /// Record some "sse_" function declarations used in other ext function definition, e.g., svf_ext_foo(), and svf_ext_foo() used in app functions
80
76
  FunctionSetType ExtFuncsVec;
81
77
  /// Record annotations of function in extapi.bc
@@ -253,19 +249,6 @@ public:
253
249
 
254
250
  SVFOtherValue* getSVFOtherValue(const Value* ov);
255
251
 
256
- /// Remove unused function in extapi.bc module
257
- bool isCalledExtFunction(Function* func)
258
- {
259
- /// if this function func defined in extapi.bc but never used in application code (without any corresponding declared functions).
260
- if (func->getParent()->getName().str() == ExtAPI::getExtAPI()->getExtBcPath()
261
- && FunDefToDeclsMap.find(func) == FunDefToDeclsMap.end()
262
- && std::find(ExtFuncsVec.begin(), ExtFuncsVec.end(), func) == ExtFuncsVec.end())
263
- {
264
- return true;
265
- }
266
- return false;
267
- }
268
-
269
252
  /// Get the corresponding Function based on its name
270
253
  inline const SVFFunction* getSVFFunction(const std::string& name)
271
254
  {
@@ -283,45 +266,6 @@ public:
283
266
  return nullptr;
284
267
  }
285
268
 
286
- bool hasDefinition(const Function* fun) const
287
- {
288
- assert(fun->isDeclaration() && "not a function declaration?");
289
- FunDeclToDefMapTy::const_iterator it = FunDeclToDefMap.find(fun);
290
- return it != FunDeclToDefMap.end();
291
- }
292
-
293
- const Function* getDefinition(const Function* fun) const
294
- {
295
- assert(fun->isDeclaration() && "not a function declaration?");
296
- FunDeclToDefMapTy::const_iterator it = FunDeclToDefMap.find(fun);
297
- assert(it != FunDeclToDefMap.end() && "has no definition?");
298
- return it->second;
299
- }
300
-
301
- bool hasDeclaration(const Function* fun) const
302
- {
303
- if(fun->isDeclaration() && !hasDefinition(fun))
304
- return false;
305
-
306
- const Function* funDef = fun;
307
- if(fun->isDeclaration() && hasDefinition(fun))
308
- funDef = getDefinition(fun);
309
-
310
- FunDefToDeclsMapTy::const_iterator it = FunDefToDeclsMap.find(funDef);
311
- return it != FunDefToDeclsMap.end();
312
- }
313
-
314
- const FunctionSetType& getDeclaration(const Function* fun) const
315
- {
316
- const Function* funDef = fun;
317
- if(fun->isDeclaration() && hasDefinition(fun))
318
- funDef = getDefinition(fun);
319
-
320
- FunDefToDeclsMapTy::const_iterator it = FunDefToDeclsMap.find(funDef);
321
- assert(it != FunDefToDeclsMap.end() && "does not have a function definition (body)?");
322
- return it->second;
323
- }
324
-
325
269
  /// Global to rep
326
270
  bool hasGlobalRep(const GlobalVariable* val) const
327
271
  {
@@ -400,7 +344,6 @@ private:
400
344
  void prePassSchedule();
401
345
  void buildSymbolTable() const;
402
346
  void collectExtFunAnnotations(const Module* mod);
403
- void removeUnusedExtAPIs();
404
347
  };
405
348
 
406
349
  } // End namespace SVF
@@ -52,8 +52,6 @@ inline bool isCallSite(const Value* val)
52
52
  return SVFUtil::isa<CallBase>(val);
53
53
  }
54
54
 
55
- /// Get the definition of a function across multiple modules
56
- const Function* getDefFunForMultipleModule(const Function* fun);
57
55
 
58
56
  /// Return LLVM callsite given a value
59
57
  inline const CallBase* getLLVMCallSite(const Value* value)
@@ -65,8 +63,7 @@ inline const CallBase* getLLVMCallSite(const Value* value)
65
63
  inline const Function* getCallee(const CallBase* cs)
66
64
  {
67
65
  // FIXME: do we need to strip-off the casts here to discover more library functions
68
- const Function* callee = SVFUtil::dyn_cast<Function>(cs->getCalledOperand()->stripPointerCasts());
69
- return callee ? getDefFunForMultipleModule(callee) : nullptr;
66
+ return SVFUtil::dyn_cast<Function>(cs->getCalledOperand()->stripPointerCasts());
70
67
  }
71
68
 
72
69
  /// Return LLVM function if this value is
@@ -291,9 +288,6 @@ inline static DataLayout* getDataLayout(Module* mod)
291
288
  void getNextInsts(const Instruction* curInst,
292
289
  std::vector<const Instruction*>& instList);
293
290
 
294
- /// Get the previous instructions following control flow
295
- void getPrevInsts(const Instruction* curInst,
296
- std::vector<const Instruction*>& instList);
297
291
 
298
292
  /// Basic block does not have predecessors
299
293
  /// map-1.cpp.bc
@@ -306,9 +300,6 @@ inline bool isNoPrecessorBasicBlock(const BasicBlock* bb)
306
300
  pred_empty(bb);
307
301
  }
308
302
 
309
- /// Get num of BB's predecessors
310
- u32_t getBBPredecessorNum(const BasicBlock* BB);
311
-
312
303
  /// Check whether a file is an LLVM IR file
313
304
  bool isIRFile(const std::string& filename);
314
305
 
@@ -316,10 +307,6 @@ bool isIRFile(const std::string& filename);
316
307
  void processArguments(int argc, char** argv, int& arg_num, char** arg_value,
317
308
  std::vector<std::string>& moduleNameVec);
318
309
 
319
- /// Helper method to get the size of the type from target data layout
320
- //@{
321
- u32_t getTypeSizeInBytes(const Type* type);
322
- u32_t getTypeSizeInBytes(const StructType* sty, u32_t field_index);
323
310
  //@}
324
311
 
325
312
  const std::string getSourceLoc(const Value* val);
@@ -330,11 +317,6 @@ bool isIntrinsicFun(const Function* func);
330
317
 
331
318
  /// Get all called funcions in a parent function
332
319
  std::vector<const Function *> getCalledFunctions(const Function *F);
333
- void removeFunAnnotations(Set<Function*>& removedFuncList);
334
- bool isUnusedGlobalVariable(const GlobalVariable& global);
335
- void removeUnusedGlobalVariables(Module* module);
336
- /// Delete unused functions, annotations and global variables in extapi.bc
337
- void removeUnusedFuncsAndAnnotationsAndGlobalVariables(Set<Function*> removedFuncList);
338
320
  // Converts a mangled name to C naming style to match functions in extapi.c.
339
321
  std::string restoreFuncName(std::string funcName);
340
322
 
@@ -369,6 +351,15 @@ std::string dumpType(const Type* type);
369
351
 
370
352
  std::string dumpValueAndDbgInfo(const Value* val);
371
353
 
354
+ bool isHeapAllocExtCallViaRet(const Instruction *inst);
355
+
356
+ bool isHeapAllocExtCallViaArg(const Instruction *inst);
357
+
358
+ inline bool isHeapAllocExtCall(const Instruction *inst)
359
+ {
360
+ return isHeapAllocExtCallViaRet(inst) || isHeapAllocExtCallViaArg(inst);
361
+ }
362
+
372
363
  } // End namespace LLVMUtil
373
364
 
374
365
  } // End namespace SVF
@@ -71,9 +71,9 @@ void CHGBuilder::buildCHG()
71
71
  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
72
72
  buildCHGNodes(&(*I));
73
73
  for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F)
74
- buildCHGNodes(LLVMUtil::getDefFunForMultipleModule(&(*F)));
74
+ buildCHGNodes(&(*F));
75
75
  for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F)
76
- buildCHGEdges(LLVMUtil::getDefFunForMultipleModule(&(*F)));
76
+ buildCHGEdges(&(*F));
77
77
 
78
78
  analyzeVTables(M);
79
79
  }