[CMake] Simplify setting compile flag disabling RTTI

llvm-svn: 201547
This commit is contained in:
Alexey Samsonov 2014-02-18 07:52:40 +00:00
parent 16a03613fa
commit b73db72a17
10 changed files with 36 additions and 50 deletions

View File

@ -144,12 +144,6 @@ pythonize_bool(COMPILER_RT_DEBUG)
#================================ #================================
include(config-ix) include(config-ix)
macro(append_if list condition var)
if (${condition})
list(APPEND ${list} ${var})
endif()
endmacro()
# Provide some common commmandline flags for Sanitizer runtimes. # Provide some common commmandline flags for Sanitizer runtimes.
append_if(SANITIZER_COMMON_CFLAGS COMPILER_RT_HAS_FPIC_FLAG -fPIC) append_if(SANITIZER_COMMON_CFLAGS COMPILER_RT_HAS_FPIC_FLAG -fPIC)
append_if(SANITIZER_COMMON_CFLAGS COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin) append_if(SANITIZER_COMMON_CFLAGS COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin)
@ -229,17 +223,6 @@ filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386)
add_subdirectory(include) add_subdirectory(include)
# When ANDROID, we build tests with the host compiler (i.e. CMAKE_C_COMPILER),
# and run tests with tools from the host toolchain.
if (NOT ANDROID)
set(SANITIZER_COMMON_LIT_TEST_DEPS
clang clang-headers FileCheck count not llvm-nm llvm-symbolizer
compiler-rt-headers)
if(UNIX)
list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS SanitizerLintCheck)
endif()
endif()
set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx) set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx)
if(EXISTS ${COMPILER_RT_LIBCXX_PATH}/) if(EXISTS ${COMPILER_RT_LIBCXX_PATH}/)
set(COMPILER_RT_HAS_LIBCXX_SOURCES TRUE) set(COMPILER_RT_HAS_LIBCXX_SOURCES TRUE)

View File

@ -36,3 +36,14 @@ macro(pythonize_bool var)
set(${var}_PYBOOL False) set(${var}_PYBOOL False)
endif() endif()
endmacro() endmacro()
macro(append_if list condition var)
if (${condition})
list(APPEND ${list} ${var})
endif()
endmacro()
macro(append_no_rtti_flag list)
append_if(${list} COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti)
append_if(${list} COMPILER_RT_HAS_GR_FLAG /GR-)
endmacro()

View File

@ -8,8 +8,10 @@ check_cxx_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_FOMIT_FRAME_POINTER
check_cxx_compiler_flag(-funwind-tables COMPILER_RT_HAS_FUNWIND_TABLES_FLAG) check_cxx_compiler_flag(-funwind-tables COMPILER_RT_HAS_FUNWIND_TABLES_FLAG)
check_cxx_compiler_flag(-fno-stack-protector COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG) check_cxx_compiler_flag(-fno-stack-protector COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG)
check_cxx_compiler_flag(-fvisibility=hidden COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG) check_cxx_compiler_flag(-fvisibility=hidden COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
check_cxx_compiler_flag(-fno-rtti COMPILER_RT_HAS_FNO_RTTI_FLAG)
check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG) check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG)
check_cxx_compiler_flag(/GR COMPILER_RT_HAS_GR_FLAG)
check_cxx_compiler_flag(/GS COMPILER_RT_HAS_GS_FLAG) check_cxx_compiler_flag(/GS COMPILER_RT_HAS_GS_FLAG)
check_cxx_compiler_flag(/MT COMPILER_RT_HAS_MT_FLAG) check_cxx_compiler_flag(/MT COMPILER_RT_HAS_MT_FLAG)
check_cxx_compiler_flag(/Oy COMPILER_RT_HAS_Oy_FLAG) check_cxx_compiler_flag(/Oy COMPILER_RT_HAS_Oy_FLAG)

View File

@ -28,15 +28,8 @@ if(ANDROID)
include_directories(${COMPILER_RT_EXTRA_ANDROID_HEADERS}) include_directories(${COMPILER_RT_EXTRA_ANDROID_HEADERS})
endif() endif()
if (NOT MSVC) set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
set(ASAN_CFLAGS append_no_rtti_flag(ASAN_CFLAGS)
${SANITIZER_COMMON_CFLAGS}
-fno-rtti)
else()
set(ASAN_CFLAGS
${SANITIZER_COMMON_CFLAGS}
/GR-)
endif()
set(ASAN_COMMON_DEFINITIONS set(ASAN_COMMON_DEFINITIONS
ASAN_HAS_EXCEPTIONS=1) ASAN_HAS_EXCEPTIONS=1)

View File

@ -9,15 +9,8 @@ set(INTERCEPTION_SOURCES
include_directories(..) include_directories(..)
if (NOT MSVC) set(INTERCEPTION_CFLAGS ${SANITIZER_COMMON_CFLAGS})
set(INTERCEPTION_CFLAGS append_no_rtti_flag(INTERCEPTION_CFLAGS)
${SANITIZER_COMMON_CFLAGS}
-fno-rtti)
else()
set(INTERCEPTION_CFLAGS
${SANITIZER_COMMON_CFLAGS}
/GR-)
endif()
if(APPLE) if(APPLE)
# Build universal binary on APPLE. # Build universal binary on APPLE.

View File

@ -1,8 +1,7 @@
include_directories(..) include_directories(..)
set(LSAN_CFLAGS set(LSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
${SANITIZER_COMMON_CFLAGS} append_no_rtti_flag(LSAN_CFLAGS)
-fno-rtti)
set(LSAN_COMMON_SOURCES set(LSAN_COMMON_SOURCES
lsan_common.cc lsan_common.cc

View File

@ -9,12 +9,13 @@ set(MSAN_RTL_SOURCES
msan_new_delete.cc msan_new_delete.cc
msan_report.cc msan_report.cc
) )
set(MSAN_RTL_CFLAGS set(MSAN_RTL_CFLAGS
${SANITIZER_COMMON_CFLAGS} ${SANITIZER_COMMON_CFLAGS}
-fno-rtti
-fPIE -fPIE
# Prevent clang from generating libc calls. # Prevent clang from generating libc calls.
-ffreestanding) -ffreestanding)
append_no_rtti_flag(MSAN_RTL_CFLAGS)
# Static runtime library. # Static runtime library.
add_custom_target(msan) add_custom_target(msan)

View File

@ -88,15 +88,8 @@ else()
SANITIZER_NEEDS_SEGV=1) SANITIZER_NEEDS_SEGV=1)
endif() endif()
if (NOT MSVC) set(SANITIZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
set(SANITIZER_CFLAGS append_no_rtti_flag(SANITIZER_CFLAGS)
${SANITIZER_COMMON_CFLAGS}
-fno-rtti)
else()
set(SANITIZER_CFLAGS
${SANITIZER_COMMON_CFLAGS}
/GR-)
endif()
append_if(SANITIZER_CFLAGS COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG -Wframe-larger-than=512) append_if(SANITIZER_CFLAGS COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG -Wframe-larger-than=512)
append_if(SANITIZER_CFLAGS COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors) append_if(SANITIZER_CFLAGS COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors)

View File

@ -6,8 +6,8 @@ include_directories(..)
# TSan runtime to be built with -fPIE to reduce the number of register spills. # TSan runtime to be built with -fPIE to reduce the number of register spills.
set(TSAN_CFLAGS set(TSAN_CFLAGS
${SANITIZER_COMMON_CFLAGS} ${SANITIZER_COMMON_CFLAGS}
-fPIE -fPIE)
-fno-rtti) append_no_rtti_flag(TSAN_CFLAGS)
set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS}) set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS})
append_if(TSAN_RTL_CFLAGS COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG -Wframe-larger-than=512) append_if(TSAN_RTL_CFLAGS COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG -Wframe-larger-than=512)

View File

@ -6,6 +6,17 @@ configure_lit_site_cfg(
# add_subdirectory(BlocksRuntime) # add_subdirectory(BlocksRuntime)
# add_subdirectory(builtins) # add_subdirectory(builtins)
# When ANDROID, we build tests with the host compiler (i.e. CMAKE_C_COMPILER),
# and run tests with tools from the host toolchain.
if (NOT ANDROID)
set(SANITIZER_COMMON_LIT_TEST_DEPS
clang clang-headers FileCheck count not llvm-nm llvm-symbolizer
compiler-rt-headers)
if(UNIX)
list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS SanitizerLintCheck)
endif()
endif()
# Run sanitizer tests only if we're sure that clang would produce # Run sanitizer tests only if we're sure that clang would produce
# working binaries. # working binaries.
if(COMPILER_RT_CAN_EXECUTE_TESTS) if(COMPILER_RT_CAN_EXECUTE_TESTS)