From 16b96a6d1ae4abfb6b9e0e769c136703d9dd213d Mon Sep 17 00:00:00 2001 From: shuangxiang kan <18550887212@163.com> Date: Mon, 2 Oct 2023 11:45:03 +1100 Subject: [PATCH 1/2] Fix some issues about ExtAPI --- .config.in | 2 +- svf-llvm/include/SVF-LLVM/LLVMModule.h | 2 +- svf-llvm/lib/LLVMModule.cpp | 8 ++++---- svf-llvm/lib/LLVMUtil.cpp | 2 +- svf/include/Util/ExtAPI.h | 2 +- svf/include/Util/Options.h | 1 - svf/lib/Util/ExtAPI.cpp | 4 ++-- svf/lib/Util/Options.cpp | 6 ------ 8 files changed, 10 insertions(+), 17 deletions(-) diff --git a/.config.in b/.config.in index 904cb382e..f9ecec3fe 100644 --- a/.config.in +++ b/.config.in @@ -2,6 +2,6 @@ #define CONFIG_H_IN #define PROJECT_PATH "@CMAKE_CURRENT_SOURCE_DIR@" -#define EXTAPI_PATH PROJECT_PATH "/@CMAKE_BUILD_TYPE@-build/svf-llvm" +#define EXTAPI_DIR PROJECT_PATH "/@CMAKE_BUILD_TYPE@-build/svf-llvm" #endif diff --git a/svf-llvm/include/SVF-LLVM/LLVMModule.h b/svf-llvm/include/SVF-LLVM/LLVMModule.h index 8498b1102..b34d45340 100644 --- a/svf-llvm/include/SVF-LLVM/LLVMModule.h +++ b/svf-llvm/include/SVF-LLVM/LLVMModule.h @@ -240,7 +240,7 @@ class LLVMModuleSet bool isCalledExtFunction(Function* func) { /// if this function func defined in extapi.bc but never used in application code (without any corresponding declared functions). - if (func->getParent()->getName().str() == Options::ExtAPIInput() + if (func->getParent()->getName().str() == ExtAPI::getExtAPI()->getExtBcPath() && FunDefToDeclsMap.find(func) == FunDefToDeclsMap.end() && std::find(ExtFuncsVec.begin(), ExtFuncsVec.end(), func) == ExtFuncsVec.end()) { diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index 4d4e13aee..bc5b383bd 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -530,10 +530,10 @@ void LLVMModuleSet::loadModules(const std::vector &moduleNameVec) void LLVMModuleSet::loadExtAPIModules() { - // has external bc - if (Options::ExtAPIInput().size() > 0) + // Load external API module (extapi.bc) + if (!ExtAPI::getExtAPI()->getExtBcPath().empty()) { - std::string extModuleName = Options::ExtAPIInput(); + std::string extModuleName = ExtAPI::getExtAPI()->getExtBcPath(); if (!LLVMUtil::isIRFile(extModuleName)) { SVFUtil::errs() << "not an external IR file: " << extModuleName << std::endl; @@ -809,7 +809,7 @@ void LLVMModuleSet::buildFunToFunMap() for (Module& mod : modules) { // extapi.bc functions - if (mod.getName().str() == Options::ExtAPIInput()) + if (mod.getName().str() == ExtAPI::getExtAPI()->getExtBcPath()) { for (const Function& fun : mod.functions()) { diff --git a/svf-llvm/lib/LLVMUtil.cpp b/svf-llvm/lib/LLVMUtil.cpp index 593746185..83c88c22e 100644 --- a/svf-llvm/lib/LLVMUtil.cpp +++ b/svf-llvm/lib/LLVMUtil.cpp @@ -599,7 +599,7 @@ void LLVMUtil::removeUnusedFuncsAndAnnotationsAndGlobalVariables(std::vectorgetParent(); - if (mod->getName().str() != Options::ExtAPIInput()) + if (mod->getName().str() != ExtAPI::getExtAPI()->getExtBcPath()) return; /// Delete unused function annotations diff --git a/svf/include/Util/ExtAPI.h b/svf/include/Util/ExtAPI.h index db2f57145..2692dab1f 100644 --- a/svf/include/Util/ExtAPI.h +++ b/svf/include/Util/ExtAPI.h @@ -53,7 +53,7 @@ class ExtAPI public: - static ExtAPI *getExtAPI(const std::string& = ""); + static ExtAPI *getExtAPI(); static void destory(); diff --git a/svf/include/Util/Options.h b/svf/include/Util/Options.h index b34d6016e..d911bb0b4 100644 --- a/svf/include/Util/Options.h +++ b/svf/include/Util/Options.h @@ -248,7 +248,6 @@ class Options static const Option VtableInSVFIR; // WPAPass.cpp - static const Option ExtAPIInput; static const Option AnderSVFG; static const Option SABERFULLSVFG; static const Option PrintAliases; diff --git a/svf/lib/Util/ExtAPI.cpp b/svf/lib/Util/ExtAPI.cpp index 7ce1d2e62..967cffed4 100644 --- a/svf/lib/Util/ExtAPI.cpp +++ b/svf/lib/Util/ExtAPI.cpp @@ -35,7 +35,7 @@ using namespace SVF; ExtAPI* ExtAPI::extOp = nullptr; -ExtAPI* ExtAPI::getExtAPI(const std::string& path) +ExtAPI* ExtAPI::getExtAPI() { if (extOp == nullptr) { @@ -108,7 +108,7 @@ static std::string getFilePath(const std::string& path) std::string ExtAPI::getExtBcPath() { struct stat statbuf; - std::string bcFilePath = std::string(EXTAPI_PATH) + "/extapi.bc"; + std::string bcFilePath = std::string(EXTAPI_DIR) + "/extapi.bc"; if (!stat(bcFilePath.c_str(), &statbuf)) return bcFilePath; diff --git a/svf/lib/Util/Options.cpp b/svf/lib/Util/Options.cpp index 10fcbcfec..685ea8744 100644 --- a/svf/lib/Util/Options.cpp +++ b/svf/lib/Util/Options.cpp @@ -770,12 +770,6 @@ const Option Options::VtableInSVFIR( false ); - -//WPAPass.cpp -const Option Options::ExtAPIInput( - "extapi", "External API extapi.bc", ExtAPI::getExtAPI()->getExtBcPath() -); - const Option Options::AnderSVFG( "svfg", "Generate SVFG after Andersen's Analysis", From 41a3a06daaa49c9a4a0ef3ebe73457f991d206a5 Mon Sep 17 00:00:00 2001 From: shuangxiang kan <18550887212@163.com> Date: Mon, 2 Oct 2023 11:55:28 +1100 Subject: [PATCH 2/2] Fix typo in ExtAPI.cpp --- svf/lib/Util/ExtAPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svf/lib/Util/ExtAPI.cpp b/svf/lib/Util/ExtAPI.cpp index 967cffed4..f919fd94d 100644 --- a/svf/lib/Util/ExtAPI.cpp +++ b/svf/lib/Util/ExtAPI.cpp @@ -120,7 +120,7 @@ std::string ExtAPI::getExtBcPath() if (!stat(bcFilePath.c_str(), &statbuf)) return bcFilePath; - SVFUtil::errs() << "No extpai.bc found at " << bcFilePath << " for getExtAPI(); set $SVF_DIR first!\n"; + SVFUtil::errs() << "No extapi.bc found at " << bcFilePath << " for getExtAPI(); The default path for extapi.bc is: SVF_IR_PATH/CMAKE_BUILD_TYPE-build/svf-llvm/extapi.bc !\n"; abort(); }