summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2013-08-27 01:24:01 +0000
committerHans Wennborg <hans@hanshq.net>2013-08-27 01:24:01 +0000
commitc1f1af715b204a7be6e31754169c358edb392bb2 (patch)
tree45556ebc324e82566caca1667e5beccf0d2e0815
parent384a448fbe081352f7b3bb927093412ad1725cff (diff)
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@189304 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--CMakeLists.txt58
-rw-r--r--lib/CMakeLists.txt22
-rw-r--r--lib/asan/CMakeLists.txt41
-rw-r--r--lib/sanitizer_common/CMakeLists.txt12
4 files changed, 91 insertions, 42 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21fdf2951..67cc51ed9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index bc3a2574d..fbc6198d9 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -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(
diff --git a/lib/asan/CMakeLists.txt b/lib/asan/CMakeLists.txt
index 064ba1f58..fe14cc3df 100644
--- a/lib/asan/CMakeLists.txt
+++ b/lib/asan/CMakeLists.txt
@@ -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()
diff --git a/lib/sanitizer_common/CMakeLists.txt b/lib/sanitizer_common/CMakeLists.txt
index 8141ae684..3b4ce2217 100644
--- a/lib/sanitizer_common/CMakeLists.txt
+++ b/lib/sanitizer_common/CMakeLists.txt
@@ -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)