-
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 5 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 |
---|---|---|
|
@@ -5,15 +5,86 @@ project("SVF") | |
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) | ||
# Match configuration used to build LLVM (match C++ standard; match | ||
# runtime typing information (RTTI); match exception handling; etc) | ||
if(COMMAND add_llvm_library) | ||
message(STATUS "Detected in-tree build configuration; skipping LLVM fetching") | ||
set(IN_SOURCE_BUILD 1) | ||
else() | ||
message(STATUS "Detected out-of-tree build configuration; fetching LLVM") | ||
|
||
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 |
||
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}" | ||
) | ||
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. After a second look, the current cmakelist in the root folder was not supposed to have anything related to LLVM and those LLVM options should be moved to svf-llvm/CMakelist.txt. I assume this change should be straight-forward? SVF itself is now designed language-independent, and we may have another module later (e.g., svf-xxx) which may not rely on llvm-based language, so a clean root cmakelist would be helpful. 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 moved this check to the top-level |
||
|
||
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() | ||
|
||
if(NOT LLVM_ENABLE_EH) | ||
message(STATUS "Building SVF without exception handling") | ||
add_compile_options("-fno-exceptions") | ||
endif() | ||
|
||
if(NOT LLVM_ENABLE_RTTI) | ||
message(STATUS "Building SVF without RTII") | ||
add_compile_options("-fno-rtti") | ||
endif() | ||
|
||
if(NOT ${LLVM_LINK_LLVM_DYLIB}) | ||
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) | ||
else() | ||
message(STATUS "Linking to LLVM dynamic shared library object") | ||
set(llvm_libs LLVM) | ||
endif() | ||
|
||
# Make the "add_llvm_library()" command available | ||
include(AddLLVM) | ||
|
||
# Set the default C++ standard used to build SVF; LLVM versions up to version 6 defaulted to C++98, | ||
# and up to (and including) version 15 the default was C++14. From versions 16 and onwards, the | ||
# default C++ standard has been C++17. Build SVF with C++14 unless the LLVM version is below 6. | ||
if (LLVM_VERSION_MAJOR VERSION_LESS 6) | ||
set(CMAKE_CXX_STANDARD 98) | ||
message(STATUS "Got LLVM version ${LLVM_VERSION}; using C++ standard: ${CMAKE_CXX_STANDARD}") | ||
elseif(LLVM_VERSION_MAJOR VERSION_LESS 16) | ||
set(CMAKE_CXX_STANDARD 14) | ||
message(STATUS "Got LLVM version ${LLVM_VERSION}; using C++ standard: ${CMAKE_CXX_STANDARD}") | ||
else() | ||
set(CMAKE_CXX_STANDARD 17) | ||
message(WARNING "Found unsupported LLVM version (got version ${LLVM_VERSION}; currently supported " | ||
"versions are up to 15); using C++ standard: ${CMAKE_CXX_STANDARD}") | ||
endif() | ||
|
||
# Always enable extensions and require a compiler that supports at least the set C++ standard | ||
set(CMAKE_CXX_EXTENSIONS ON) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
endif() | ||
|
||
# Treat compiler warnings as errors | ||
add_compile_options("-Werror" "-Wall") | ||
|
@@ -80,11 +151,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 |
---|---|---|
|
@@ -3,7 +3,13 @@ if(DEFINED IN_SOURCE_BUILD) | |
else() | ||
add_executable(cfl cfl.cpp) | ||
|
||
target_link_libraries(cfl SvfLLVM ${llvm_libs}) | ||
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS}) | ||
target_include_directories(cfl PUBLIC include) | ||
target_include_directories(cfl SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS}) | ||
target_link_directories(cfl PUBLIC ${LLVM_LIBRARY_DIRS}) | ||
target_compile_definitions(cfl PUBLIC ${LLVM_DEFINITIONS}) | ||
|
||
target_link_libraries(cfl SvfCore SvfLLVM) | ||
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. It looks to me like every tool has these repetitive lines. Could we move them to parent cmakelist? 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. Of course; I did this because I thought the linking was going wrong but on my system this is difficult to reproduce as my LLVM instance's library directory is also in Either way, it is not necessary to explicitly link against the LLVM library anyway since the library is defined using Note that I've also modified |
||
|
||
set_target_properties(cfl PROPERTIES RUNTIME_OUTPUT_DIRECTORY | ||
${CMAKE_BINARY_DIR}/bin) | ||
|
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. 👍