-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the extapi.bc path not found issue #1212
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,13 @@ | |
|
||
#include "Util/ExtAPI.h" | ||
#include "Util/SVFUtil.h" | ||
#include "Util/Options.h" | ||
#include <sys/stat.h> | ||
|
||
using namespace SVF; | ||
|
||
ExtAPI* ExtAPI::extOp = nullptr; | ||
std::string ExtAPI::extBcPath = ""; | ||
|
||
ExtAPI* ExtAPI::getExtAPI() | ||
{ | ||
|
@@ -53,6 +55,12 @@ void ExtAPI::destory() | |
} | ||
} | ||
|
||
// Set extapi.bc file path | ||
void ExtAPI::setExtBcPath(const std::string& path) | ||
{ | ||
extBcPath = path; | ||
} | ||
|
||
// Get environment variables $SVF_DIR and "npm root" through popen() method | ||
static std::string GetStdoutFromCommand(const std::string& command) | ||
{ | ||
|
@@ -80,55 +88,77 @@ static std::string GetStdoutFromCommand(const std::string& command) | |
// Get extapi.bc file path in npm | ||
static std::string getFilePath(const std::string& path) | ||
{ | ||
std::string bcFilePath = GetStdoutFromCommand(path); | ||
if (path.compare("npm root") == 0) | ||
std::string bcFilePath = ""; | ||
if (path.compare("SVF_DIR") == 0) | ||
{ | ||
int os_flag = 1; | ||
bcFilePath = getenv("SVF_DIR"); | ||
} | ||
else if (path.compare("npm root") == 0) | ||
{ | ||
bcFilePath = GetStdoutFromCommand(path); | ||
// SVF installed via npm needs to determine the type of operating | ||
// system, otherwise the extapi.bc path may not be found. | ||
#ifdef linux | ||
// Linux os | ||
os_flag = 0; | ||
bcFilePath.append("/svf-lib/SVF-linux"); | ||
#endif | ||
#else | ||
// Mac os | ||
if (os_flag == 1) | ||
{ | ||
bcFilePath.append("/svf-lib/SVF-osx"); | ||
} | ||
bcFilePath.append("/svf-lib/SVF-osx"); | ||
#endif | ||
} | ||
|
||
if (bcFilePath.back() != '/') | ||
if (!bcFilePath.empty() && bcFilePath.back() != '/') | ||
bcFilePath.push_back('/'); | ||
bcFilePath.append(EXTAPI_BC_PATH); | ||
bcFilePath.append(BUILD_TYPE).append(DEFUALT_EXTAPI_BC_PATH); | ||
return bcFilePath; | ||
} | ||
|
||
// Get extapi.bc path | ||
std::string ExtAPI::getExtBcPath() | ||
{ | ||
struct stat statbuf; | ||
std::string bcFilePath = std::string(EXTAPI_DIR) + "/extapi.bc"; | ||
if (!stat(bcFilePath.c_str(), &statbuf)) | ||
return bcFilePath; | ||
|
||
bcFilePath = getFilePath("echo $SVF_DIR"); | ||
if (!stat(bcFilePath.c_str(), &statbuf)) | ||
return bcFilePath; | ||
// Five default ways to get extapi.bc path | ||
// 1. Set extapi.bc path through setExtBcPath() method | ||
// 2. Set extapi.bc path through the "-extapi = PATH_TO_EXTAPIFILE" option | ||
// 3. Default path: "SVF_IR_PATH/CMAKE_BUILD_TYPE-build/svf-llvm/extapi.bc" | ||
// 4. From $SVF_DIR | ||
// 5. From "npm root"(If SVF is installed via npm) | ||
|
||
bcFilePath = getFilePath("npm root"); | ||
if (!stat(bcFilePath.c_str(), &statbuf)) | ||
return bcFilePath; | ||
|
||
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"; | ||
struct stat statbuf; | ||
// 1. Set extapi.bc path through setExtBcPath() method | ||
if (!extBcPath.empty() && !stat(extBcPath.c_str(), &statbuf)) | ||
return extBcPath; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could simplify that function and make it much faster:
if (!extBcPath.empty())
return extBcPath;
This should also remove the code duplication. |
||
// 2. Set extapi.bc path through the "-extapi = PATH_TO_EXTAPIFILE" option | ||
extBcPath = Options::ExtAPIPath(); | ||
if (!extBcPath.empty() && !stat(extBcPath.c_str(), &statbuf)) | ||
return extBcPath; | ||
|
||
// 3. Default path: "SVF_IR_PATH/CMAKE_BUILD_TYPE-build/svf-llvm/extapi.bc" | ||
extBcPath = std::string(EXTAPI_DIR) + "/extapi.bc"; | ||
if (!stat(extBcPath.c_str(), &statbuf)) | ||
return extBcPath; | ||
|
||
// 4. From $SVF_DIR | ||
extBcPath = getFilePath("SVF_DIR"); | ||
if (!stat(extBcPath.c_str(), &statbuf)) | ||
return extBcPath; | ||
|
||
// 5. From "npm root"(If SVF is installed via npm) | ||
extBcPath = getFilePath("npm root"); | ||
if (!stat(extBcPath.c_str(), &statbuf)) | ||
return extBcPath; | ||
|
||
SVFUtil::errs() << "No extapi.bc found at " << extBcPath << " in getExtBcPath() !!!" << "\n" | ||
<< "You can specify extapi.bc path in two ways:" << "\n" | ||
<< "1. Set it via the command line using -extapi=/path_to_extapi;" << "\n" | ||
<< "2. Use the API setExtBcPath(). Please note that setExtBcPath() should be used before buildSVFModule().\n"; | ||
abort(); | ||
} | ||
|
||
std::string ExtAPI::getExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation) | ||
{ | ||
assert(fun && "Null SVFFunction* pointer"); | ||
const std::vector<std::string>& annotations = fun->getAnnotations(); | ||
for (const std::string& annotation : annotations) | ||
for (const std::string& annotation : fun->getAnnotations()) | ||
if (annotation.find(funcAnnotation) != std::string::npos) | ||
return annotation; | ||
return ""; | ||
|
@@ -137,8 +167,7 @@ std::string ExtAPI::getExtFuncAnnotation(const SVFFunction* fun, const std::stri | |
bool ExtAPI::hasExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation) | ||
{ | ||
assert(fun && "Null SVFFunction* pointer"); | ||
const std::vector<std::string>& annotations = fun->getAnnotations(); | ||
for (const std::string& annotation : annotations) | ||
for (const std::string& annotation : fun->getAnnotations()) | ||
if (annotation.find(funcAnnotation) != std::string::npos) | ||
return true; | ||
return false; | ||
|
@@ -168,8 +197,7 @@ bool ExtAPI::is_arg_alloc(const SVFFunction* F) | |
// Get the position of argument which holds the new object | ||
s32_t ExtAPI::get_alloc_arg_pos(const SVFFunction* F) | ||
{ | ||
std::string s = "ALLOC_ARG"; | ||
std::string allocArg = getExtFuncAnnotation(F, s); | ||
std::string allocArg = getExtFuncAnnotation(F, "ALLOC_ARG"); | ||
assert(!allocArg.empty() && "Not an alloc call via argument or incorrect extern function annotation!"); | ||
|
||
std::string number; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "DEFUALT"