-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Modified CMakeLists.txt to take whether or not to disable RTTI & exception handling from LLVM's configuration, rather than hardcoding * Fixed setting of C++ standard and removed requirement for LLVM to be built in debug-mode when SVF is being built in debug-mode * Fix matching parameters and return values for "OVERWRITE" functions and add some new functions sepcfications in extapi.c * Remove getPointerElementType() The getPointerElementType will be deprecated in future versions of LLVM. Considering compatibility, avoid using getPointerElementType()->isIntegerTy(8) to determine if the arguments and return values are of the void * type. * SVF code formatter * Take LLVMContext object from module used to build SVFModule rather than forcing unique_ptr to avoid erronous garbage collection clearing LLVM internal objects when SVF is used from within an LLVM pass * Replaced fatal error for LLVM versions greater than 15 with a warning to cater to future LLVM 16 support * Switched adding LLVM definitions, link directories, and include directories from only to `SvfLLVM` to global additions so that modules defined after `SvfLLVM` or in its subdirectories automatically inherit/can find LLVM as well * Switched to CMake-recommended way of linking libraries (through `target_link_libraries()`); linked SvfCore and SvfLLVM for tools; LLVM link directory should be added to rpath for tools * Add the tools through `add_llvm_executable`; modify build/setup scripts to also include the installed LLVM/Z3 instances in $LD_LIBRARY_PATH (same for compiled SVF libraries) * Apparently this is not the case for older CMake versions; explicitly link LLVM libraries to avoid undefined symbols * Tests require specific output directory for tools * Updated CMake build system to install correctly; moved more LLVM-only variables to the CMakeLists.txt script in svf-llm/; modified generated configuration variables in config.h (and updated ExtAPI.h/ExtAPI.cpp accordingly); removed unnecessary exports from build script; added additional configuration information to config.h * Removed repetitive setting of C++ standard to top-level CMakeLists.txt script; removed target-specific setting of C++ standard * FIX: Replaced setting `CXX_STANDARD` (and related) with `CMAKE_CXX_STANDARD` --------- Co-authored-by: shuangxiang kan <[email protected]> Co-authored-by: GitHub Actions Build <[email protected]>
- Loading branch information
1 parent
dfeb685
commit 52b7034
Showing
16 changed files
with
233 additions
and
186 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
#ifndef CONFIG_H_IN | ||
#define CONFIG_H_IN | ||
|
||
#define PROJECT_PATH "@CMAKE_CURRENT_SOURCE_DIR@" | ||
#define BUILD_TYPE "@CMAKE_BUILD_TYPE@-build" | ||
#define EXTAPI_DIR PROJECT_PATH "/@CMAKE_BUILD_TYPE@-build/svf-llvm" | ||
// Directory structure of SVF build | ||
#define SVF_ROOT "@CMAKE_CURRENT_SOURCE_DIR@" | ||
#define SVF_BUILD_DIR "@CMAKE_CURRENT_BINARY_DIR@" | ||
#define SVF_INSTALL_DIR "@CMAKE_INSTALL_PREFIX@" | ||
#define SVF_BIN_DIR SVF_INSTALL_DIR "/bin" | ||
#define SVF_LIB_DIR SVF_INSTALL_DIR "/lib" | ||
#define SVF_INCLUDE_DIR SVF_INSTALL_DIR "/include" | ||
#define SVF_EXTAPI_DIR SVF_INCLUDE_DIR "/SVF-LLVM" | ||
#define SVF_EXTAPI_BC SVF_EXTAPI_DIR "/extapi.bc" | ||
|
||
// Build properties of current SVF build | ||
#define SVF_BUILD_TYPE "@CMAKE_BUILD_TYPE@" | ||
#cmakedefine SVF_ASSERT_MODE | ||
#cmakedefine SVF_COVERAGE | ||
#cmakedefine SVF_SANITIZE "@SVF_SANITIZE@" | ||
|
||
|
||
#endif |
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 |
---|---|---|
@@ -1,61 +1,124 @@ | ||
# To support both in- and out-of-source builds, we check for the presence of the | ||
# add_llvm_loadable_module command. - if this command is not present, we are | ||
# building out-of-source | ||
if(NOT COMMAND add_llvm_library) | ||
find_package(LLVM REQUIRED CONFIG HINTS "${LLVM_DIR}") | ||
set(LLVM_DIR ${LLVM_BINARY_DIR} PARENT_SCOPE) | ||
|
||
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") | ||
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") | ||
|
||
if(NOT LLVM_ENABLE_RTTI) | ||
add_compile_options("-fno-rtti") | ||
message(STATUS "Disable RTTI") | ||
endif() | ||
# SVF-LLVM contains LLVM Libs | ||
file(GLOB SVFLLVM_SOURCES lib/*.cpp) | ||
|
||
if(NOT LLVM_ENABLE_EH) | ||
add_compile_options("-fno-exceptions") | ||
message(STATUS "Disable exceptions") | ||
endif() | ||
find_package(LLVM REQUIRED CONFIG HINTS ${LLVM_DIR} $ENV{LLVM_DIR}) | ||
message(STATUS "LLVM STATUS: | ||
Version ${LLVM_VERSION} | ||
Definitions ${LLVM_DEFINITIONS} | ||
Includes ${LLVM_INCLUDE_DIRS} | ||
Libraries ${LLVM_LIBRARY_DIRS} | ||
Targets ${LLVM_TARGETS_TO_BUILD} | ||
Build type ${LLVM_BUILD_TYPE} | ||
Exceptions ${LLVM_ENABLE_EH} | ||
RTTI ${LLVM_ENABLE_RTTI} | ||
Dynamic lib ${LLVM_LINK_LLVM_DYLIB}" | ||
) | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") | ||
include(AddLLVM) | ||
if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT ${LLVM_BUILD_TYPE} STREQUAL "Debug") | ||
message(NOTICE "Building SVF in debug-mode but LLVM was not built in debug-mode; " | ||
"debug information could be incomplete when using SVF from LLVM") | ||
endif() | ||
|
||
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS}) | ||
link_directories(${LLVM_LIBRARY_DIRS}) | ||
add_definitions(${LLVM_DEFINITIONS}) | ||
|
||
add_definitions(${LLVM_DEFINITIONS}) | ||
# include_directories(SYSTEM ${LLVM_INCLUDE_DIRS}) | ||
if(NOT LLVM_ENABLE_EH) | ||
message(STATUS "Building SVF without exception handling") | ||
set(SVF_NO_RTTI ON PARENT_SCOPE) # Set for parent scope because this needs to be set in top-level CMakeLists.txt | ||
endif() | ||
|
||
if(LLVM_LINK_LLVM_DYLIB) | ||
set(llvm_libs LLVM) | ||
if(NOT LLVM_ENABLE_RTTI) | ||
message(STATUS "Building SVF without RTTI") | ||
set(SVF_NO_EH ON PARENT_SCOPE) # Set for parent scope because this needs to be set in top-level CMakeLists.txt | ||
endif() | ||
|
||
if(LLVM_LINK_LLVM_DYLIB) | ||
message(STATUS "Linking to LLVM dynamic shared library object") | ||
set(llvm_libs LLVM) | ||
|
||
# Set which components to include in the dynamic library to include the new SvfLLVM | ||
if (LLVM_DYLIB_COMPONENTS) | ||
message(STATUS "Appending SvfLLVM to LLVM dynamic library components") | ||
list(APPEND LLVM_DYLIB_COMPONENTS SvfLLVM) | ||
else() | ||
llvm_map_components_to_libnames( | ||
llvm_libs | ||
analysis | ||
bitwriter | ||
core | ||
instcombine | ||
instrumentation | ||
ipo | ||
irreader | ||
linker | ||
scalaropts | ||
support | ||
target | ||
transformutils) | ||
message(STATUS "Adding all;SvfLLVM to LLVM dynamic library components (was unset)") | ||
set(LLVM_DYLIB_COMPONENTS all;SvfLLVM) | ||
endif() | ||
else() | ||
set(IN_SOURCE_BUILD 1) | ||
message(STATUS "Linking to separate LLVM static libraries") | ||
llvm_map_components_to_libnames( | ||
llvm_libs | ||
analysis | ||
bitwriter | ||
core | ||
instcombine | ||
instrumentation | ||
ipo | ||
irreader | ||
linker | ||
scalaropts | ||
support | ||
target | ||
transformutils | ||
) | ||
endif() | ||
|
||
# SVF-LLVM contains LLVM Libs | ||
file(GLOB SVFLLVM_SOURCES lib/*.cpp) | ||
# Make the "add_llvm_library()" command available and configure LLVM/CMake | ||
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") | ||
include(AddLLVM) | ||
|
||
add_llvm_library(SvfLLVM ${SVFLLVM_SOURCES}) | ||
target_include_directories(SvfLLVM SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS}) | ||
target_include_directories(SvfLLVM PUBLIC include) | ||
target_link_libraries(SvfLLVM PUBLIC ${llvm_libs} ${Z3_LIBRARIES} SvfCore) | ||
|
||
if(DEFINED IN_SOURCE_BUILD) | ||
# Add intrinsics_gen target if we're building as part of LLVM source build | ||
if(TARGET intrinsics_gen) | ||
add_dependencies(SvfLLVM intrinsics_gen) | ||
endif() | ||
|
||
add_subdirectory(tools) | ||
|
||
# Compile extapi.c to extapi.bc | ||
set(EXTAPI_TO_BC_FLAGS | ||
"-w" | ||
"-S" | ||
"-c" | ||
"-Xclang" | ||
"-disable-O0-optnone" | ||
"-fno-discard-value-names" | ||
"-emit-llvm" | ||
"${CMAKE_CURRENT_LIST_DIR}/lib/extapi.c" | ||
"-o" | ||
"${CMAKE_BINARY_DIR}/svf-llvm/extapi.bc" | ||
) | ||
find_program(LLVM_CLANG | ||
NAMES clang | ||
HINTS ${LLVM_BINARY_DIR} | ||
PATH_SUFFIXES bin | ||
REQUIRED | ||
) | ||
add_custom_target(extapi_ir ALL | ||
COMMAND ${LLVM_CLANG} ${EXTAPI_TO_BC_FLAGS} | ||
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/lib/extapi.c | ||
) | ||
|
||
# Install the headers (as a subdirectory of the main SVF include) and the compiled library binaries | ||
include(GNUInstallDirs) | ||
install( | ||
TARGETS SvfLLVM | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
) | ||
install( | ||
FILES ${CMAKE_BINARY_DIR}/svf-llvm/extapi.bc | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/svf/SVF-LLVM | ||
) | ||
install( | ||
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/ | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/svf | ||
FILES_MATCHING | ||
PATTERN "**/*.h" | ||
) | ||
|
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 |
---|---|---|
@@ -1,10 +1,2 @@ | ||
if(DEFINED IN_SOURCE_BUILD) | ||
add_llvm_tool(cfl cfl.cpp) | ||
else() | ||
add_executable(cfl cfl.cpp) | ||
|
||
target_link_libraries(cfl SvfLLVM ${llvm_libs}) | ||
|
||
set_target_properties(cfl PROPERTIES RUNTIME_OUTPUT_DIRECTORY | ||
${CMAKE_BINARY_DIR}/bin) | ||
endif() | ||
add_llvm_executable(cfl cfl.cpp) | ||
target_link_libraries(cfl PUBLIC ${llvm_libs} SvfLLVM) |
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 |
---|---|---|
@@ -1,23 +1,22 @@ | ||
if(DEFINED IN_SOURCE_BUILD) | ||
set(LLVM_LINK_COMPONENTS | ||
BitWriter | ||
Core | ||
IPO | ||
IrReader | ||
InstCombine | ||
Instrumentation | ||
Target | ||
Linker | ||
Analysis | ||
ScalarOpts | ||
Support | ||
SvfLLVM) | ||
endif() | ||
|
||
add_subdirectory(SABER) | ||
add_subdirectory(WPA) | ||
add_subdirectory(Example) | ||
add_subdirectory(DDA) | ||
add_subdirectory(MTA) | ||
add_subdirectory(CFL) | ||
add_subdirectory(LLVM2SVF) | ||
|
||
# Build SvfLLVM tools with C++ standard C++17 | ||
set_target_properties( | ||
cfl dvf svf-ex llvm2svf mta saber wpa | ||
PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin | ||
) | ||
|
||
include(GNUInstallDirs) | ||
install( | ||
TARGETS cfl dvf svf-ex llvm2svf mta saber wpa | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
) |
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 |
---|---|---|
@@ -1,10 +1,2 @@ | ||
if(DEFINED IN_SOURCE_BUILD) | ||
add_llvm_tool(dvf dda.cpp) | ||
else() | ||
add_executable(dvf dda.cpp) | ||
|
||
target_link_libraries(dvf SvfLLVM ${llvm_libs}) | ||
|
||
set_target_properties(dvf PROPERTIES RUNTIME_OUTPUT_DIRECTORY | ||
${CMAKE_BINARY_DIR}/bin) | ||
endif() | ||
add_llvm_executable(dvf dda.cpp) | ||
target_link_libraries(dvf PUBLIC ${llvm_libs} SvfLLVM) |
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 |
---|---|---|
@@ -1,10 +1,2 @@ | ||
if(DEFINED IN_SOURCE_BUILD) | ||
add_llvm_tool(svf-ex svf-ex.cpp) | ||
else() | ||
add_executable(svf-ex svf-ex.cpp) | ||
|
||
target_link_libraries(svf-ex SvfLLVM ${llvm_libs}) | ||
|
||
set_target_properties(svf-ex PROPERTIES RUNTIME_OUTPUT_DIRECTORY | ||
${CMAKE_BINARY_DIR}/bin) | ||
endif() | ||
add_llvm_executable(svf-ex svf-ex.cpp) | ||
target_link_libraries(svf-ex PUBLIC ${llvm_libs} SvfLLVM) |
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 |
---|---|---|
@@ -1,10 +1,2 @@ | ||
if(DEFINED IN_SOURCE_BUILD) | ||
add_llvm_tool(llvm2svf llvm2svf.cpp) | ||
else() | ||
add_executable(llvm2svf llvm2svf.cpp) | ||
|
||
target_link_libraries(llvm2svf SvfLLVM ${llvm_libs}) | ||
|
||
set_target_properties(llvm2svf PROPERTIES RUNTIME_OUTPUT_DIRECTORY | ||
${CMAKE_BINARY_DIR}/bin) | ||
endif() | ||
add_llvm_executable(llvm2svf llvm2svf.cpp) | ||
target_link_libraries(llvm2svf PUBLIC ${llvm_libs} SvfLLVM) |
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 |
---|---|---|
@@ -1,12 +1,2 @@ | ||
if(DEFINED IN_SOURCE_BUILD) | ||
add_llvm_tool(mta mta.cpp LockResultValidator.cpp MTAResultValidator.cpp | ||
MTAAnnotator.cpp) | ||
else() | ||
add_executable(mta mta.cpp LockResultValidator.cpp MTAResultValidator.cpp | ||
MTAAnnotator.cpp) | ||
|
||
target_link_libraries(mta SvfLLVM ${llvm_libs}) | ||
|
||
set_target_properties(mta PROPERTIES RUNTIME_OUTPUT_DIRECTORY | ||
${CMAKE_BINARY_DIR}/bin) | ||
endif() | ||
add_llvm_executable(mta mta.cpp LockResultValidator.cpp MTAResultValidator.cpp MTAAnnotator.cpp) | ||
target_link_libraries(mta PUBLIC ${llvm_libs} SvfLLVM) |
Oops, something went wrong.