Skip to content

Commit

Permalink
move libSvfCore and libSvfLLVM files to lib folder (#1366)
Browse files Browse the repository at this point in the history
* move libSvfCore and libSvfLLVM files to lib folder

* fix CMakelist

* resume

* fix npm publish

* fix npm publish

* fix npm publish

* fix install

* fix Extapi path

* fix npm, add bin folder

* copy in compile time

* copy in compile time

* copy in compile time

* add comments

---------

Co-authored-by: bjjwwang <[email protected]>
  • Loading branch information
bjjwwang and bjjwwang authored Feb 13, 2024
1 parent a5731d3 commit 748f2be
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 34 deletions.
22 changes: 6 additions & 16 deletions .github/workflows/svf-lib_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,12 @@ 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
cp -rf $GITHUB_WORKSPACE/Release-build/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
17 changes: 9 additions & 8 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,16 +163,16 @@ 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
)

Expand All @@ -183,4 +184,4 @@ install(
)

# Export targets added to SVFTargets (set by install() command)
export(EXPORT SVFTargets FILE "${CMAKE_CURRENT_BINARY_DIR}/SVFTargets.cmake")
export(EXPORT SVFTargets FILE "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/SVF/SVFTargets.cmake")
19 changes: 16 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,13 +88,20 @@ 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)
add_custom_target(CopySVFLLVMIncludeFiles ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_BINARY_DIR}/include)

target_sources(SvfLLVM
PUBLIC
FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
FILES ${SVF_LLVM_HEADERS}
)

add_dependencies(SvfCore CopySVFLLVMIncludeFiles CopySVFIncludeFiles)

# Add intrinsics_gen target if we're building as part of LLVM source build
if(TARGET intrinsics_gen)
add_dependencies(SvfLLVM intrinsics_gen)
Expand Down Expand Up @@ -118,15 +131,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 +151,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}
)
3 changes: 1 addition & 2 deletions svf-llvm/tools/AE/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
add_llvm_executable(ae ae.cpp)
target_link_libraries(ae PUBLIC ${llvm_libs} SvfLLVM)

target_link_libraries(ae PUBLIC ${llvm_libs} SvfLLVM)
2 changes: 1 addition & 1 deletion svf-llvm/tools/CFL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(cfl cfl.cpp)
target_link_libraries(cfl PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(cfl PUBLIC ${llvm_libs} SvfLLVM)
2 changes: 1 addition & 1 deletion svf-llvm/tools/DDA/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(dvf dda.cpp)
target_link_libraries(dvf PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(dvf PUBLIC ${llvm_libs} SvfLLVM)
2 changes: 1 addition & 1 deletion svf-llvm/tools/Example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(svf-ex svf-ex.cpp)
target_link_libraries(svf-ex PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(svf-ex PUBLIC ${llvm_libs} SvfLLVM)
2 changes: 1 addition & 1 deletion svf-llvm/tools/SABER/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_llvm_executable(saber saber.cpp)
target_link_libraries(saber PUBLIC ${llvm_libs} SvfLLVM)
target_link_libraries(saber PUBLIC ${llvm_libs} SvfLLVM)
14 changes: 14 additions & 0 deletions svf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,33 @@ target_include_directories(SvfCore
$<INSTALL_INTERFACE:${SVF_INSTALL_INCLUDE_DIR}>
)

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

# Get the source files (i.e. all *.c/*.cpp files) for SVF's subprojects and add them to SvfCore
file(GLOB_RECURSE SVF_CORE_SOURCES lib/*.cpp)
target_sources(SvfCore PRIVATE ${SVF_CORE_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_CORE_HEADERS include/*.h include/*.hpp)

add_custom_target(CopySVFIncludeFiles ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_BINARY_DIR}/include)

target_sources(SvfCore
PUBLIC
FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
FILES ${SVF_CORE_HEADERS}
)

add_dependencies(SvfCore CopySVFIncludeFiles)

# Install the headers and compiled libraries (associate SvfCore with the SVF package's targets)
install(
TARGETS SvfCore
Expand Down
3 changes: 3 additions & 0 deletions svf/include/AE/Svfexe/AbstractExecution.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// The implementation is based on
// Xiao Cheng, Jiawei Wang and Yulei Sui. Precise Sparse Abstract Execution via Cross-Domain Interaction.
// 46th International Conference on Software Engineering. (ICSE24)
//===----------------------------------------------------------------------===//


Expand Down
3 changes: 3 additions & 0 deletions svf/include/AE/Svfexe/BufOverflowChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// The implementation is based on
// Xiao Cheng, Jiawei Wang and Yulei Sui. Precise Sparse Abstract Execution via Cross-Domain Interaction.
// 46th International Conference on Software Engineering. (ICSE24)
//===----------------------------------------------------------------------===//


Expand Down
3 changes: 3 additions & 0 deletions svf/include/AE/Svfexe/SVFIR2ItvExeState.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// The implementation is based on
// Xiao Cheng, Jiawei Wang and Yulei Sui. Precise Sparse Abstract Execution via Cross-Domain Interaction.
// 46th International Conference on Software Engineering. (ICSE24)
//===----------------------------------------------------------------------===//
/*
* SVFIR2ItvExeState.h
Expand Down
2 changes: 1 addition & 1 deletion svf/lib/Util/ExtAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ std::string ExtAPI::getExtBcPath()
return extBcPath;

// 4. Get location in build tree based from `config.h` header file (if SVF was only built)
if (setExtBcPath(SVF_BUILD_DIR "/svf-llvm/extapi.bc"))
if (setExtBcPath(SVF_BUILD_DIR "/lib/extapi.bc"))
return extBcPath;

// 5. Get location based on environment variable $ENV{SVF_DIR}
Expand Down

0 comments on commit 748f2be

Please sign in to comment.