Skip to content

Commit

Permalink
Merge remote-tracking branch 'root/master' into ae-icfg
Browse files Browse the repository at this point in the history
  • Loading branch information
bjjwwang committed Feb 20, 2024
2 parents a866f63 + 2b0b87f commit 3d9a8c8
Show file tree
Hide file tree
Showing 24 changed files with 186 additions and 164 deletions.
14 changes: 12 additions & 2 deletions .config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
set_and_check(SVF_INSTALL_ROOT "@PACKAGE_SVF_INSTALL_ROOT@")
set_and_check(SVF_INSTALL_BIN_DIR "@PACKAGE_SVF_INSTALL_BIN_DIR@")
set_and_check(SVF_INSTALL_LIB_DIR "@PACKAGE_SVF_INSTALL_LIB_DIR@")
set_and_check(SVF_INSTALL_INCLUDE_DIR "@PACKAGE_SVF_INSTALL_INCLUDE_DIR@")

set(SVF_INCLUDE_PATH "@PACKAGE_SVF_INSTALL_ROOT@/../svf/include")
set(SVF_LLVM_INCLUDE_PATH "@PACKAGE_SVF_INSTALL_ROOT@/../svf-llvm/include")

if(EXISTS ${SVF_INCLUDE_PATH} AND EXISTS ${SVF_LLVM_INCLUDE_PATH})
set(SVF_INSTALL_INCLUDE_DIR "${SVF_INCLUDE_PATH};${SVF_LLVM_INCLUDE_PATH};@PACKAGE_SVF_INSTALL_INCLUDE_DIR@")
else()
set_and_check(SVF_INSTALL_INCLUDE_DIR "@PACKAGE_SVF_INSTALL_INCLUDE_DIR@")
endif()

message(STATUS "SVF_INSTALL_INCLUDE_DIR is set to: ${SVF_INSTALL_INCLUDE_DIR}")

set_and_check(SVF_INSTALL_EXTAPI_DIR "@PACKAGE_SVF_INSTALL_EXTAPI_DIR@")
set_and_check(SVF_INSTALL_EXTAPI_FILE "@PACKAGE_SVF_INSTALL_EXTAPI_FILE@")
Expand All @@ -21,4 +31,4 @@ set(SVF_CXX_STANDARD "@CMAKE_CXX_STANDARD@")
set(SVF_ENABLE_RTTI "@SVF_ENABLE_RTTI@")
set(SVF_ENABLE_EXCEPTIONS "@SVF_ENABLE_EXCEPTIONS@")

include("${CMAKE_CURRENT_LIST_DIR}/SVFTargets.cmake")

26 changes: 10 additions & 16 deletions .github/workflows/svf-lib_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,16 @@ jobs:
cd ./SVF-npm
git fetch origin
git rebase origin/master
if [ ! -d "SVF-${osVersion}/svf" ]; then mkdir -p "SVF-${osVersion}/svf"; fi
if [ ! -d "SVF-${osVersion}/svf-llvm" ]; then mkdir -p "SVF-${osVersion}/svf-llvm"; fi
if [ ! -d "SVF-${osVersion}/Release-build/svf-llvm" ]; then mkdir -p "SVF-${osVersion}/Release-build/svf-llvm"; fi
if [ ! -d "SVF-${osVersion}/Release-build/svf" ]; then mkdir -p "SVF-${osVersion}/Release-build/svf"; fi
rm -rf SVF-${osVersion}/svf/*
rm -rf SVF-${osVersion}/svf-llvm/*
rm -rf SVF-${osVersion}/Release-build/include/*
git rm --cached -rf SVF-${osVersion}/svf/*
git rm --cached -rf SVF-${osVersion}/svf-llvm/*
git rm --cached -rf SVF-${osVersion}/Release-build/include/*
cp -rf $GITHUB_WORKSPACE/svf/include SVF-${osVersion}/svf
cp -rf $GITHUB_WORKSPACE/svf-llvm/include SVF-${osVersion}/svf-llvm
cp -f $GITHUB_WORKSPACE/Release-build/svf-llvm/libSvfLLVM.a SVF-${osVersion}/Release-build/svf-llvm/libSvfLLVM.a
cp -f $GITHUB_WORKSPACE/Release-build/svf-llvm/extapi.bc SVF-${osVersion}/Release-build/svf-llvm/extapi.bc
cp -f $GITHUB_WORKSPACE/Release-build/svf/libSvfCore.a SVF-${osVersion}/Release-build/svf/libSvfCore.a
cp -rf $GITHUB_WORKSPACE/Release-build/include SVF-${osVersion}/Release-build
rm -rf SVF-${osVersion}/*
git rm --cached -rf SVF-${osVersion}/*
if [ ! -d "SVF-${osVersion}/Release-build/" ]; then mkdir -p "SVF-${osVersion}/Release-build"; fi
rm -rf $GITHUB_WORKSPACE/Release-build/bin/*.dot
rm -rf $GITHUB_WORKSPACE/Release-build/bin/*.json
cp -rf $GITHUB_WORKSPACE/Release-build/include SVF-${osVersion}/Release-build/
cp -rf $GITHUB_WORKSPACE/svf/include SVF-${osVersion}/Release-build/
cp -rf $GITHUB_WORKSPACE/svf-llvm/include SVF-${osVersion}/Release-build/
cp -rf $GITHUB_WORKSPACE/Release-build/lib SVF-${osVersion}/Release-build/
cp -rf $GITHUB_WORKSPACE/Release-build/bin SVF-${osVersion}/Release-build/
git add .
if [ -n "$(git status -s)" ]; then git commit -m'Update svflib' ; fi
npm version patch
Expand Down
25 changes: 8 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ option(SVF_ENABLE_ASSERTIONS "Always enable assertions")
set(SVF_INSTALL_ROOT ${CMAKE_INSTALL_PREFIX})
set(SVF_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
set(SVF_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
set(SVF_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/svf)
set(SVF_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})

# Set where extapi.bc is exported to in the installed CMake package
set(SVF_INSTALL_EXTAPI_DIR ${SVF_INSTALL_INCLUDE_DIR}/SVF-LLVM)
set(SVF_INSTALL_EXTAPI_DIR ${SVF_INSTALL_LIB_DIR})
set(SVF_INSTALL_EXTAPI_FILE ${SVF_INSTALL_EXTAPI_DIR}/extapi.bc)

message(STATUS "Building ${PROJECT_NAME} with configuration:
Expand All @@ -47,6 +47,7 @@ message(STATUS "Using CMake build configuration:
CMake current source directory: ${CMAKE_CURRENT_SOURCE_DIR}
CMake current binary directory: ${CMAKE_CURRENT_BINARY_DIR}")

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
# Create config.h based on config.in
configure_file(${SVF_SOURCE_DIR}/.config.in ${SVF_BINARY_DIR}/include/Util/config.h)

Expand All @@ -56,7 +57,7 @@ include_directories(${SVF_BINARY_DIR}/include)
# Install generated configuration header (see `configure_file()`) to top-level include dir of SVF
install(
FILES ${SVF_BINARY_DIR}/include/Util/config.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/svf/Util
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Util
)

# Build SVF with C++ standard C++17
Expand Down Expand Up @@ -149,7 +150,7 @@ include(CMakePackageConfigHelpers)
# Generate SVFConfig.cmake
configure_package_config_file(
.config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/SVFConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/SVF/SVFConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SVF
PATH_VARS
SVF_INSTALL_ROOT
Expand All @@ -162,25 +163,15 @@ configure_package_config_file(

# Generate SVFConfigVersion.cmake
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/SVFConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/SVF/SVFConfigVersion.cmake"
VERSION "${SVF_VERSION_MAJOR}.${SVF_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)

# Install above CMake files as part of installation
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/SVFConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/SVFConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/SVF/SVFConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/SVF/SVFConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SVF
)

# Install CMake targets from different SVF subprojects so they can be found by find_package(SVF)
install(
EXPORT SVFTargets
FILE SVFTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SVF
)

# Export targets added to SVFTargets (set by install() command)
export(EXPORT SVFTargets FILE "${CMAKE_CURRENT_BINARY_DIR}/SVFTargets.cmake")
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<img src="./docs/images/svf_logo_2.png" width="15%"><img src="./docs/images/svf_logo_3.png" width="85%">


## News
* <b>SVF now supports LLVM-16.0.0 with opaque pointers (Contributed by [Xiao Cheng](https://github.com/jumormt)). </b>
* <b>Modernize SVF's CMake (Contributed by [Johannes](https://github.com/Johanmyst)). </b>
* <b>SVF now supports LLVM-13.0.0 (Thank [Shengjie Xu](https://github.com/xushengj) for his help!). </b>
* <b>[Object clustering](https://github.com/SVF-tools/SVF/wiki/Object-Clustering) published in our [OOPSLA paper](https://yuleisui.github.io/publications/oopsla21.pdf) is now available in SVF </b>
* <b>[Hash-Consed Points-To Sets](https://github.com/SVF-tools/SVF/wiki/Hash-Consed-Points-To-Sets) published in our [SAS paper](https://yuleisui.github.io/publications/sas21.pdf) is now available in SVF </b>
Expand Down
Binary file added docs/images/svf_logo_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/svf_logo_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/svf_logo_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="docs/stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="docs/stylesheets/github-light.css" media="screen">
<link rel="icon" type="image/x-icon" href="./docs/images/svf_logo_1.png">
</head>
<body>
<section class="page-header">
Expand Down
13 changes: 10 additions & 3 deletions svf-llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ target_include_directories(SvfLLVM
$<INSTALL_INTERFACE:${SVF_INSTALL_INCLUDE_DIR}>
)

set_target_properties(SvfLLVM PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
)

# Link LLVM's libraries to SvfLLVM, as well as the SVF core library
target_link_libraries(SvfLLVM PUBLIC ${llvm_libs} SvfCore)

Expand All @@ -82,6 +88,7 @@ target_sources(SvfLLVM PRIVATE ${SVF_LLVM_SOURCES})

# Get all of the public header files (i.e. all *.h/*.hpp files) for SVF's subprojects and add them
file(GLOB_RECURSE SVF_LLVM_HEADERS include/*.h include/*.hpp)

target_sources(SvfLLVM
PUBLIC
FILE_SET HEADERS
Expand Down Expand Up @@ -118,15 +125,15 @@ add_custom_command(
-emit-llvm
-fno-discard-value-names
-Xclang -disable-O0-optnone
-o ${CMAKE_CURRENT_BINARY_DIR}/extapi.bc
-o ${CMAKE_BINARY_DIR}/lib/extapi.bc
${CMAKE_CURRENT_LIST_DIR}/lib/extapi.c
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/lib/extapi.c
)

# Add a custom target for generating the LLVM bytecode file (and add it to the default build targets)
add_custom_target(gen_extapi_ir ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/extapi.bc)

# Install the SvfLLVM shared library and public headers (public headers go in include/svf/SVF-LLVM)
# Install the SvfLLVM shared library and public headers (public headers go in include/SVF-LLVM)
install(
TARGETS SvfLLVM
EXPORT SVFTargets
Expand All @@ -138,6 +145,6 @@ install(

# Install the generated extapi.bc bytecode file
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/extapi.bc
FILES ${CMAKE_BINARY_DIR}/lib/extapi.bc
DESTINATION ${SVF_INSTALL_EXTAPI_DIR}
)
4 changes: 0 additions & 4 deletions svf-llvm/include/SVF-LLVM/CppUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,11 @@ bool isTemplateFunc(const Function *foo);
/// whether foo is a cpp dyncast function
bool isDynCast(const Function *foo);

/// whether foo is a cpp heap allocation (new)
bool isNewAlloc(const Function *foo);

/// extract class name from cpp dyncast function
std::string extractClsNameFromDynCast(const CallBase* callBase);

const Type *cppClsNameToType(const std::string &className);

std::string typeToClsName(const Type *ty);


/// Constants pertaining to CTir, for C and C++.
Expand Down
6 changes: 3 additions & 3 deletions svf-llvm/include/SVF-LLVM/ObjTypeInference.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ObjTypeInference
typedef Map<const Value *, const Type *> ValueToType;
typedef std::pair<const Value *, bool> ValueBoolPair;
typedef Map<const Value *, Set<std::string>> ValueToClassNames;
typedef Map<const CallBase *, Set<const Function *>> AllocToClsNameSources;
typedef Map<const Value *, Set<const CallBase *>> ObjToClsNameSources;


private:
Expand All @@ -57,7 +57,7 @@ class ObjTypeInference
ValueToSources _valueToAllocs; // value allocations (stack, static, heap) cache
ValueToClassNames _thisPtrClassNames; // thisptr class name cache
ValueToSources _valueToAllocOrClsNameSources; // value alloc/clsname sources cache
AllocToClsNameSources _allocToClsNameSources; // alloc clsname sources cache
ObjToClsNameSources _objToClsNameSources; // alloc clsname sources cache


public:
Expand Down Expand Up @@ -122,7 +122,7 @@ class ObjTypeInference
Set<const Value *> &bwFindAllocOrClsNameSources(const Value *startValue);

/// forward find class name sources starting from an allocation
Set<const Function *> &fwFindClsNameSources(const CallBase *alloc);
Set<const CallBase *> &fwFindClsNameSources(const Value *startValue);
};
}
#endif //SVF_OBJTYPEINFERENCE_H
47 changes: 17 additions & 30 deletions svf-llvm/lib/CppUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
*/

#include "SVF-LLVM/CppUtil.h"
#include "SVF-LLVM/BasicTypes.h"
#include "SVF-LLVM/LLVMUtil.h"
#include "Util/Casting.h"
#include "Util/SVFUtil.h"
#include "SVF-LLVM/LLVMModule.h"
#include "SVF-LLVM/ObjTypeInference.h"
Expand Down Expand Up @@ -120,6 +122,8 @@ static std::string getBeforeParenthesis(const std::string& name)
return name.substr(0, pos);
}

/// get class name before brackets
/// e.g., for `namespace::A<...::...>::f', we get `namespace::A'
std::string cppUtil::getBeforeBrackets(const std::string& name)
{
if (name.empty() || name[name.size() - 1] != '>')
Expand Down Expand Up @@ -398,7 +402,9 @@ const Argument* cppUtil::getConstructorThisPtr(const Function* fun)
return thisPtr;
}

void updateClassNameBeforeBrackets(cppUtil::DemangledName& dname)
/// strip off brackets and namespace from classname
/// e.g., for `namespace::A<...::...>::f', we get `A' by stripping off namespace and <>
void stripBracketsAndNamespace(cppUtil::DemangledName& dname)
{
dname.funcName = cppUtil::getBeforeBrackets(dname.funcName);
dname.className = cppUtil::getBeforeBrackets(dname.className);
Expand All @@ -409,6 +415,7 @@ void updateClassNameBeforeBrackets(cppUtil::DemangledName& dname)
}
else
{
// strip off namespace
dname.className =
cppUtil::getBeforeBrackets(dname.className.substr(colon + 2));
}
Expand All @@ -428,7 +435,7 @@ bool cppUtil::isConstructor(const Function* F)
{
return false;
}
updateClassNameBeforeBrackets(dname);
stripBracketsAndNamespace(dname);
/// TODO: on mac os function name is an empty string after demangling
return dname.className.size() > 0 &&
dname.className.compare(dname.funcName) == 0;
Expand All @@ -448,7 +455,7 @@ bool cppUtil::isDestructor(const Function* F)
{
return false;
}
updateClassNameBeforeBrackets(dname);
stripBracketsAndNamespace(dname);
return (dname.className.size() > 0 && dname.funcName.size() > 0 &&
dname.className.size() + 1 == dname.funcName.size() &&
dname.funcName.compare(0, 1, "~") == 0 &&
Expand Down Expand Up @@ -635,11 +642,10 @@ Set<std::string> cppUtil::extractClsNamesFromFunc(const Function *foo)
{
assert(foo->hasName() && "foo does not have a name? possible indirect call");
const std::string &name = foo->getName().str();
if (isConstructor(foo))
if (isConstructor(foo) || isDestructor(foo))
{
// c++ constructor
// c++ constructor or destructor
DemangledName demangledName = cppUtil::demangle(name);
updateClassNameBeforeBrackets(demangledName);
return {demangledName.className};
}
else if (isTemplateFunc(foo))
Expand Down Expand Up @@ -705,7 +711,7 @@ std::vector<std::string> findInnermostBrackets(const std::string &input)
}

/*!
* strip the whitespaces in the beginning and ending of str
* strip off the whitespaces from the beginning and ending of str
* @param str
* @return
*/
Expand Down Expand Up @@ -793,6 +799,10 @@ bool cppUtil::isClsNameSource(const Value *val)
if(!foo) return false;
return isConstructor(foo) || isDestructor(foo) || isTemplateFunc(foo) || isDynCast(foo);
}
else if (const auto *func = SVFUtil::dyn_cast<Function>(val))
{
return isConstructor(func) || isDestructor(func) || isTemplateFunc(func);
}
return false;
}

Expand Down Expand Up @@ -835,17 +845,6 @@ bool cppUtil::isDynCast(const Function *foo)
return foo->getName().str() == dyncast;
}

/*!
* whether foo is a cpp heap allocation (new)
* @param foo
* @return
*/
bool cppUtil::isNewAlloc(const Function *foo)
{
assert(foo->hasName() && "foo does not have a name? possible indirect call");
return foo->getName().str() == znwm;
}

/*!
* extract class name from cpp dyncast function
* @param callBase
Expand All @@ -872,16 +871,4 @@ const Type *cppUtil::cppClsNameToType(const std::string &className)
StructType *classTy = StructType::getTypeByName(LLVMModuleSet::getLLVMModuleSet()->getContext(),
clsName + className);
return classTy ? classTy : LLVMModuleSet::getLLVMModuleSet()->getTypeInference()->ptrType();
}

std::string cppUtil::typeToClsName(const Type *ty)
{
if (const auto *stTy = SVFUtil::dyn_cast<StructType>(ty))
{
const std::string &typeName = stTy->getName().str();
const std::string &className = typeName.substr(
clsName.size(), typeName.size() - clsName.size());
return className;
}
return "";
}
Loading

0 comments on commit 3d9a8c8

Please sign in to comment.