forked from OSchip/llvm-project
cmake: fix the compiler-rt build with MSVC
This sets flags and excludes things that aren't working with MSVC yet, allowing us to build the ASan runtime as part of the cmake build. Differential Revision: http://llvm-reviews.chandlerc.com/D1525 llvm-svn: 189304
This commit is contained in:
parent
eb0133c112
commit
67c6e5041b
|
@ -47,8 +47,13 @@ if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND
|
|||
NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
message(FATAL_ERROR "Please use architecture with 4 or 8 byte pointers.")
|
||||
endif()
|
||||
set(TARGET_64_BIT_CFLAGS "-m64")
|
||||
set(TARGET_32_BIT_CFLAGS "-m32")
|
||||
if (NOT MSVC)
|
||||
set(TARGET_64_BIT_CFLAGS "-m64")
|
||||
set(TARGET_32_BIT_CFLAGS "-m32")
|
||||
else()
|
||||
set(TARGET_64_BIT_CFLAGS "")
|
||||
set(TARGET_32_BIT_CFLAGS "")
|
||||
endif()
|
||||
|
||||
# List of architectures we can target.
|
||||
set(COMPILER_RT_SUPPORTED_ARCH)
|
||||
|
@ -83,7 +88,9 @@ macro(test_target_arch arch)
|
|||
endmacro()
|
||||
|
||||
if("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
|
||||
test_target_arch(x86_64 ${TARGET_64_BIT_CFLAGS})
|
||||
if (NOT MSVC)
|
||||
test_target_arch(x86_64 ${TARGET_64_BIT_CFLAGS})
|
||||
endif()
|
||||
test_target_arch(i386 ${TARGET_32_BIT_CFLAGS})
|
||||
elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC")
|
||||
test_target_arch(powerpc64 ${TARGET_64_BIT_CFLAGS})
|
||||
|
@ -114,25 +121,34 @@ function(filter_available_targets out_var)
|
|||
endfunction()
|
||||
|
||||
# Provide some common commmandline flags for Sanitizer runtimes.
|
||||
set(SANITIZER_COMMON_CFLAGS
|
||||
-fPIC
|
||||
-fno-builtin
|
||||
-fno-exceptions
|
||||
-fomit-frame-pointer
|
||||
-funwind-tables
|
||||
-fno-stack-protector
|
||||
-Wno-gnu # Variadic macros with 0 arguments for ...
|
||||
-O3
|
||||
)
|
||||
if(NOT WIN32)
|
||||
list(APPEND SANITIZER_COMMON_CFLAGS -fvisibility=hidden)
|
||||
endif()
|
||||
# Build sanitizer runtimes with debug info.
|
||||
check_cxx_compiler_flag(-gline-tables-only SUPPORTS_GLINE_TABLES_ONLY_FLAG)
|
||||
if(SUPPORTS_GLINE_TABLES_ONLY_FLAG)
|
||||
list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
|
||||
if (NOT MSVC)
|
||||
set(SANITIZER_COMMON_CFLAGS
|
||||
-fPIC
|
||||
-fno-builtin
|
||||
-fno-exceptions
|
||||
-fomit-frame-pointer
|
||||
-funwind-tables
|
||||
-fno-stack-protector
|
||||
-Wno-gnu # Variadic macros with 0 arguments for ...
|
||||
-O3
|
||||
-fvisibility=hidden
|
||||
)
|
||||
else()
|
||||
list(APPEND SANITIZER_COMMON_CFLAGS -g)
|
||||
set(SANITIZER_COMMON_CFLAGS
|
||||
/MT
|
||||
/Zi
|
||||
/GS-
|
||||
/wd4722
|
||||
)
|
||||
endif()
|
||||
# Build sanitizer runtimes with debug info. (MSVC gets /Zi above)
|
||||
if (NOT MSVC)
|
||||
check_cxx_compiler_flag(-gline-tables-only SUPPORTS_GLINE_TABLES_ONLY_FLAG)
|
||||
if(SUPPORTS_GLINE_TABLES_ONLY_FLAG)
|
||||
list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
|
||||
else()
|
||||
list(APPEND SANITIZER_COMMON_CFLAGS -g)
|
||||
endif()
|
||||
endif()
|
||||
# Warnings suppressions.
|
||||
check_cxx_compiler_flag(-Wno-variadic-macros SUPPORTS_NO_VARIADIC_MACROS_FLAG)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# First, add the subdirectories which contain feature-based runtime libraries
|
||||
# and several convenience helper libraries.
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux")
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux|Windows")
|
||||
# AddressSanitizer is supported on Linux and Mac OS X.
|
||||
# Windows support is work in progress.
|
||||
# Windows support is experimental.
|
||||
add_subdirectory(asan)
|
||||
add_subdirectory(interception)
|
||||
add_subdirectory(sanitizer_common)
|
||||
if(NOT ANDROID)
|
||||
if(NOT ANDROID AND NOT MSVC)
|
||||
add_subdirectory(lsan)
|
||||
add_subdirectory(profile)
|
||||
add_subdirectory(ubsan)
|
||||
|
@ -182,13 +182,15 @@ set(i386_SOURCES
|
|||
i386/umoddi3.S
|
||||
${GENERIC_SOURCES})
|
||||
|
||||
foreach(arch x86_64 i386)
|
||||
if(CAN_TARGET_${arch})
|
||||
add_compiler_rt_static_runtime(clang_rt.${arch} ${arch}
|
||||
SOURCES ${${arch}_SOURCES}
|
||||
CFLAGS "-std=c99")
|
||||
endif()
|
||||
endforeach()
|
||||
if (NOT MSVC)
|
||||
foreach(arch x86_64 i386)
|
||||
if(CAN_TARGET_${arch})
|
||||
add_compiler_rt_static_runtime(clang_rt.${arch} ${arch}
|
||||
SOURCES ${${arch}_SOURCES}
|
||||
CFLAGS "-std=c99")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# Generate configs for running lit and unit tests.
|
||||
configure_lit_site_cfg(
|
||||
|
|
|
@ -26,9 +26,15 @@ set(ASAN_DYLIB_SOURCES
|
|||
|
||||
include_directories(..)
|
||||
|
||||
set(ASAN_CFLAGS
|
||||
${SANITIZER_COMMON_CFLAGS}
|
||||
-fno-rtti)
|
||||
if (NOT MSVC)
|
||||
set(ASAN_CFLAGS
|
||||
${SANITIZER_COMMON_CFLAGS}
|
||||
-fno-rtti)
|
||||
else()
|
||||
set(ASAN_CFLAGS
|
||||
${SANITIZER_COMMON_CFLAGS}
|
||||
/GR-)
|
||||
endif()
|
||||
|
||||
set(ASAN_COMMON_DEFINITIONS
|
||||
ASAN_HAS_EXCEPTIONS=1)
|
||||
|
@ -38,6 +44,10 @@ if(ANDROID)
|
|||
ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0
|
||||
ASAN_NEEDS_SEGV=0
|
||||
ASAN_LOW_MEMORY=1)
|
||||
elseif(MSVC)
|
||||
list(APPEND ASAN_COMMON_DEFINITIONS
|
||||
ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0
|
||||
ASAN_NEEDS_SEGV=0)
|
||||
else()
|
||||
list(APPEND ASAN_COMMON_DEFINITIONS
|
||||
ASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
|
||||
|
@ -78,17 +88,32 @@ elseif(ANDROID)
|
|||
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android)
|
||||
else()
|
||||
# Otherwise, build separate libraries for each target.
|
||||
|
||||
foreach(arch ${ASAN_SUPPORTED_ARCH})
|
||||
set(ASAN_SOURCE_LIBS
|
||||
$<TARGET_OBJECTS:RTInterception.${arch}>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
|
||||
if (NOT MSVC)
|
||||
# We can't build Leak Sanitizer on Windows yet.
|
||||
list(APPEND ASAN_SOURCE_LIBS $<TARGET_OBJECTS:RTLSanCommon.${arch}>)
|
||||
endif()
|
||||
|
||||
add_compiler_rt_static_runtime(clang_rt.asan-${arch} ${arch}
|
||||
SOURCES ${ASAN_SOURCES}
|
||||
$<TARGET_OBJECTS:RTInterception.${arch}>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
|
||||
$<TARGET_OBJECTS:RTLSanCommon.${arch}>
|
||||
SOURCES ${ASAN_SOURCES} ${ASAN_SOURCE_LIBS}
|
||||
CFLAGS ${ASAN_CFLAGS}
|
||||
DEFS ${ASAN_COMMON_DEFINITIONS}
|
||||
SYMS asan.syms)
|
||||
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch})
|
||||
|
||||
if (WIN32)
|
||||
add_compiler_rt_static_runtime(clang_rt.asan_dll_thunk-${arch} ${arch}
|
||||
SOURCES asan_dll_thunk.cc
|
||||
CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK
|
||||
DEFS ${ASAN_COMMON_DEFINITIONS}
|
||||
SYMS asan.syms)
|
||||
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_dll_thunk-${arch})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
|
|
|
@ -61,9 +61,15 @@ set(SANITIZER_HEADERS
|
|||
sanitizer_symbolizer.h
|
||||
sanitizer_thread_registry.h)
|
||||
|
||||
set(SANITIZER_CFLAGS
|
||||
${SANITIZER_COMMON_CFLAGS}
|
||||
-fno-rtti)
|
||||
if (NOT MSVC)
|
||||
set(SANITIZER_CFLAGS
|
||||
${SANITIZER_COMMON_CFLAGS}
|
||||
-fno-rtti)
|
||||
else()
|
||||
set(SANITIZER_CFLAGS
|
||||
${SANITIZER_COMMON_CFLAGS}
|
||||
/GR-)
|
||||
endif()
|
||||
|
||||
set(SANITIZER_RUNTIME_LIBRARIES)
|
||||
if(APPLE)
|
||||
|
|
Loading…
Reference in New Issue