-
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
Add -fno-rtti
/fno-exceptions
based on LLVM's configuration
#1291
Changes from 9 commits
bdbae40
3959742
2c574c6
c24615f
8f01b0e
9ef3df0
6e83d12
ca5632c
58a4ffc
af15d88
3f51410
d0a1b83
1fd01be
6cc852b
6f1f351
d4e6d6b
97d624d
d8670ae
fabc7df
d85eacb
1f54a14
1063318
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,11 @@ cmake_minimum_required(VERSION 3.13.4) | |
|
||
project("SVF") | ||
|
||
message(STATUS "Using CMake with generator: ${CMAKE_GENERATOR}") | ||
|
||
configure_file(${PROJECT_SOURCE_DIR}/.config.in | ||
${PROJECT_BINARY_DIR}/include/Util/config.h) | ||
|
||
# We need to match the build environment for LLVM: In particular, we need C++14 | ||
# and the -fno-rtti flag | ||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
# add -std=gnu++14 | ||
set(CMAKE_CXX_EXTENSIONS ON) | ||
|
||
add_compile_options("-fno-rtti") | ||
add_compile_options("-fno-exceptions") | ||
Comment on lines
-15
to
-16
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. If we want to enable svfcore as 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. Sure, this was why I initially moved the LLVM finding into the top-level |
||
|
||
# Treat compiler warnings as errors | ||
add_compile_options("-Werror" "-Wall") | ||
|
||
|
@@ -80,11 +72,18 @@ endif() | |
add_subdirectory(svf) | ||
add_subdirectory(svf-llvm) | ||
|
||
include(GNUInstallDirs) | ||
install( | ||
TARGETS SvfCore SvfLLVM | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
) | ||
install( | ||
DIRECTORY ${PROJECT_SOURCE_DIR}/svf/include/ | ||
${PROJECT_SOURCE_DIR}/svf-llvm/include/ | ||
COMPONENT devel | ||
DESTINATION include/svf | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/include/svf | ||
FILES_MATCHING | ||
PATTERN "**/*.h") | ||
|
||
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. Could we also move the following to svf-llvm/CMakeList.txt? Compile extapi.c to extapi.bcfind_path(LLVM_CLANG_DIR 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. Done. 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. I also moved the installation commands to the subdirectory so the While doing that I also fixed the remaining installation predicates:
This should be unnecessary for the way SVF is currently designed to be used (i.e. through the |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,7 +205,10 @@ if [[ ! -d "$Z3_DIR" ]]; then | |
export Z3_DIR="$SVFHOME/$Z3Home" | ||
fi | ||
|
||
export PATH=$LLVM_DIR/bin:$PATH | ||
# Add LLVM & Z3 to $PATH and $LD_LIBRARY_PATH (prepend so that selected instances will be used first) | ||
export PATH=$LLVM_DIR/bin:$Z3_DIR/bin:$PATH | ||
export LD_LIBRARY_PATH=$LLVM_DIR/lib:$Z3_BIN/lib:$LD_LIBRARY_PATH | ||
|
||
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. There is no need to export since the end of 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. Alright, I'll remove those references. |
||
echo "LLVM_DIR=$LLVM_DIR" | ||
echo "Z3_DIR=$Z3_DIR" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,83 @@ | ||
# 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-llvm without exception handling") | ||
add_compile_options("-fno-exceptions") | ||
endif() | ||
|
||
if(LLVM_LINK_LLVM_DYLIB) | ||
set(llvm_libs LLVM) | ||
if(NOT LLVM_ENABLE_RTTI) | ||
message(STATUS "Building SVF-llvm without RTII") | ||
add_compile_options("-fno-rtti") | ||
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.
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. Fixed. Thanks. :) |
||
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) | ||
# Build SVF with C++ standard C++17 | ||
set_property(TARGET SvfLLVM PROPERTY CXX_STANDARD 17) | ||
set_property(TARGET SvfLLVM PROPERTY CXX_EXTENSIONS ON) | ||
set_property(TARGET SvfLLVM PROPERTY CXX_STANDARD_REQUIRED ON) | ||
|
||
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. Any better reason to set the C++ standard for SVFcore and SVF-LLVM separately? I think the original way is less repetitive. 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. I think CMake generally recommends applying options/properties to specific targets rather than using global options (e.g. the documentation for However, I think the |
||
# Add intrinsics_gen target if we're building as part of LLVM source build | ||
if(TARGET intrinsics_gen) | ||
add_dependencies(SvfLLVM intrinsics_gen) | ||
endif() | ||
|
||
|
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,14 @@ | ||
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 CXX_STANDARD 17 | ||
CXX_EXTENSIONS ON | ||
CXX_STANDARD_REQUIRED ON | ||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
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) |
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) |
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) |
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,2 @@ | ||
if(DEFINED IN_SOURCE_BUILD) | ||
add_llvm_tool(saber saber.cpp) | ||
else() | ||
add_executable(saber saber.cpp) | ||
|
||
target_link_libraries(saber SvfLLVM ${llvm_libs}) | ||
|
||
set_target_properties(saber PROPERTIES RUNTIME_OUTPUT_DIRECTORY | ||
${CMAKE_BINARY_DIR}/bin) | ||
endif() | ||
add_llvm_executable(saber saber.cpp) | ||
target_link_libraries(saber PUBLIC ${llvm_libs} SvfLLVM) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
set(THREADS_PREFER_PTHREAD_FLAG ON) | ||
find_package(Threads REQUIRED) | ||
|
||
if(DEFINED IN_SOURCE_BUILD) | ||
add_llvm_tool(wpa wpa.cpp) | ||
else() | ||
add_executable(wpa wpa.cpp) | ||
|
||
target_link_libraries(wpa SvfLLVM ${llvm_libs} Threads::Threads) | ||
|
||
set_target_properties(wpa PROPERTIES RUNTIME_OUTPUT_DIRECTORY | ||
${CMAKE_BINARY_DIR}/bin) | ||
endif() | ||
add_llvm_executable(wpa wpa.cpp) | ||
target_link_libraries(wpa PUBLIC ${llvm_libs} SvfLLVM Threads::Threads) |
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.
We can adjust the language standard here, like:
Those properties will be effective for all new targets by default.
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.
@Johanmyst could you add the options here and remove
set_property
in svf-llvm/CMakLiist.txt and svf/CMakeList.txtThere 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.
Done. 👍