aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-01-07 19:55:37 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-01-07 19:55:37 +0000
commitca9211ecdede9bdedb812b2243a4abdb8dacd1b9 (patch)
tree9b19e801150082c33e9152275829a6ce90614b55 /cmake
parent8ef50bf3d1c287b5013c3168de77a462dfce3495 (diff)
downloadsrc-ca9211ecdede9bdedb812b2243a4abdb8dacd1b9.tar.gz
src-ca9211ecdede9bdedb812b2243a4abdb8dacd1b9.zip
Import compiler-rt trunk r224034.vendor/compiler-rt/compiler-rt-r224034
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=276789 svn path=/vendor/compiler-rt/compiler-rt-r224034/; revision=276790; tag=vendor/compiler-rt/compiler-rt-r224034
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/AddCompilerRT.cmake164
-rw-r--r--cmake/Modules/CompilerRTCompile.cmake71
-rw-r--r--cmake/Modules/CompilerRTLink.cmake10
-rw-r--r--cmake/Modules/CompilerRTUtils.cmake37
-rw-r--r--cmake/Modules/SanitizerUtils.cmake32
-rw-r--r--cmake/config-ix.cmake258
6 files changed, 521 insertions, 51 deletions
diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
index fd117ac522ca..3edd854fdee7 100644
--- a/cmake/Modules/AddCompilerRT.cmake
+++ b/cmake/Modules/AddCompilerRT.cmake
@@ -1,4 +1,5 @@
include(AddLLVM)
+include(ExternalProject)
include(LLVMParseArguments)
include(CompilerRTUtils)
@@ -13,7 +14,7 @@ macro(add_compiler_rt_object_library name arch)
parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN})
add_library(${name}.${arch} OBJECT ${LIB_SOURCES})
set_target_compile_flags(${name}.${arch}
- ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
+ ${CMAKE_CXX_FLAGS} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
set_property(TARGET ${name}.${arch} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
else()
@@ -37,34 +38,47 @@ macro(add_compiler_rt_darwin_object_library name os)
COMPILE_DEFINITIONS ${LIB_DEFS})
endmacro()
-# Adds static runtime for a given architecture and puts it in the proper
-# directory in the build and install trees.
-# add_compiler_rt_static_runtime(<name> <arch>
-# SOURCES <source files>
-# CFLAGS <compile flags>
-# DEFS <compile definitions>)
-macro(add_compiler_rt_static_runtime name arch)
+# Adds static or shared runtime for a given architecture and puts it in the
+# proper directory in the build and install trees.
+# add_compiler_rt_runtime(<name> <arch> {STATIC,SHARED}
+# SOURCES <source files>
+# CFLAGS <compile flags>
+# DEFS <compile definitions>
+# OUTPUT_NAME <output library name>)
+macro(add_compiler_rt_runtime name arch type)
if(CAN_TARGET_${arch})
- parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN})
- add_library(${name} STATIC ${LIB_SOURCES})
+ parse_arguments(LIB "SOURCES;CFLAGS;DEFS;OUTPUT_NAME" "" ${ARGN})
+ add_library(${name} ${type} ${LIB_SOURCES})
# Setup compile flags and definitions.
set_target_compile_flags(${name}
${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
+ set_target_link_flags(${name}
+ ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
set_property(TARGET ${name} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
# Setup correct output directory in the build tree.
set_target_properties(${name} PROPERTIES
- ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+ ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+ LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+ RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+ if ("${LIB_OUTPUT_NAME}" STREQUAL "")
+ set_target_properties(${name} PROPERTIES
+ OUTPUT_NAME ${name}${COMPILER_RT_OS_SUFFIX})
+ else()
+ set_target_properties(${name} PROPERTIES
+ OUTPUT_NAME ${LIB_OUTPUT_NAME})
+ endif()
# Add installation command.
install(TARGETS ${name}
- ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
- add_dependencies(compiler-rt ${name})
+ ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
+ LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
+ RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
else()
message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
endif()
endmacro()
-# Same as add_compiler_rt_static_runtime, but creates a universal library
+# Same as add_compiler_rt_runtime(... STATIC), but creates a universal library
# for several architectures.
# add_compiler_rt_osx_static_runtime(<name> ARCH <architectures>
# SOURCES <source files>
@@ -81,7 +95,6 @@ macro(add_compiler_rt_osx_static_runtime name)
ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
install(TARGETS ${name}
ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
- add_dependencies(compiler-rt ${name})
endmacro()
# Adds dynamic runtime library on osx/iossim, which supports multiple
@@ -104,20 +117,43 @@ macro(add_compiler_rt_darwin_dynamic_runtime name os)
LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
install(TARGETS ${name}
LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
- add_dependencies(compiler-rt ${name})
endmacro()
+set(COMPILER_RT_TEST_CFLAGS)
+
# Unittests support.
set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc)
-set(COMPILER_RT_GTEST_INCLUDE_CFLAGS
+set(COMPILER_RT_GTEST_CFLAGS
-DGTEST_NO_LLVM_RAW_OSTREAM=1
+ -DGTEST_HAS_RTTI=0
-I${COMPILER_RT_GTEST_PATH}/include
-I${COMPILER_RT_GTEST_PATH}
)
-# Use Clang to link objects into a single executable with just-built
-# Clang, using specific link flags. Make executable a part of provided
+if(MSVC)
+ # clang doesn't support exceptions on Windows yet.
+ list(APPEND COMPILER_RT_TEST_CFLAGS
+ -D_HAS_EXCEPTIONS=0)
+
+ # We should teach clang to understand "#pragma intrinsic", see PR19898.
+ list(APPEND COMPILER_RT_TEST_CFLAGS -Wno-undefined-inline)
+
+ # Clang doesn't support SEH on Windows yet.
+ list(APPEND COMPILER_RT_GTEST_CFLAGS -DGTEST_HAS_SEH=0)
+
+ # gtest use a lot of stuff marked as deprecated on Windows.
+ list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations)
+
+ # Visual Studio 2012 only supports up to 8 template parameters in
+ # std::tr1::tuple by default, but gtest requires 10
+ if(MSVC_VERSION EQUAL 1700)
+ list(APPEND COMPILER_RT_GTEST_CFLAGS -D_VARIADIC_MAX=10)
+ endif()
+endif()
+
+# Link objects into a single executable with COMPILER_RT_TEST_COMPILER,
+# using specified link flags. Make executable a part of provided
# test_suite.
# add_compiler_rt_test(<test_suite> <test_name>
# OBJECTS <object files>
@@ -126,20 +162,98 @@ set(COMPILER_RT_GTEST_INCLUDE_CFLAGS
macro(add_compiler_rt_test test_suite test_name)
parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}")
+ # Use host compiler in a standalone build, and just-built Clang otherwise.
+ if(NOT COMPILER_RT_STANDALONE_BUILD)
+ list(APPEND TEST_DEPS clang)
+ endif()
+ # If we're not on MSVC, include the linker flags from CMAKE but override them
+ # with the provided link flags. This ensures that flags which are required to
+ # link programs at all are included, but the changes needed for the test
+ # trump. With MSVC we can't do that because CMake is set up to run link.exe
+ # when linking, not the compiler. Here, we hack it to use the compiler
+ # because we want to use -fsanitize flags.
+ if(NOT MSVC)
+ set(TEST_LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_LINK_FLAGS}")
+ separate_arguments(TEST_LINK_FLAGS)
+ endif()
add_custom_target(${test_name}
- COMMAND clang ${TEST_OBJECTS} -o "${output_bin}"
+ COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS}
+ -o "${output_bin}"
${TEST_LINK_FLAGS}
- DEPENDS clang ${TEST_DEPS})
+ DEPENDS ${TEST_DEPS})
# Make the test suite depend on the binary.
add_dependencies(${test_suite} ${test_name})
endmacro()
macro(add_compiler_rt_resource_file target_name file_name)
set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
- set(dst_file "${CLANG_RESOURCE_DIR}/${file_name}")
- add_custom_target(${target_name}
+ set(dst_file "${COMPILER_RT_OUTPUT_DIR}/${file_name}")
+ add_custom_command(OUTPUT ${dst_file}
+ DEPENDS ${src_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file}
- DEPENDS ${file_name})
+ COMMENT "Copying ${file_name}...")
+ add_custom_target(${target_name} DEPENDS ${dst_file})
# Install in Clang resource directory.
- install(FILES ${file_name} DESTINATION ${LIBCLANG_INSTALL_PATH})
+ install(FILES ${file_name} DESTINATION ${COMPILER_RT_INSTALL_PATH})
+endmacro()
+
+macro(add_compiler_rt_script name)
+ set(dst ${COMPILER_RT_EXEC_OUTPUT_DIR}/${name})
+ set(src ${CMAKE_CURRENT_SOURCE_DIR}/${name})
+ add_custom_command(OUTPUT ${dst}
+ DEPENDS ${src}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
+ COMMENT "Copying ${name}...")
+ add_custom_target(${name} DEPENDS ${dst})
+ install(FILES ${dst}
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
+ DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin)
+endmacro(add_compiler_rt_script src name)
+
+# Builds custom version of libc++ and installs it in <prefix>.
+# Can be used to build sanitized versions of libc++ for running unit tests.
+# add_custom_libcxx(<name> <prefix>
+# DEPS <list of build deps>
+# CFLAGS <list of compile flags>)
+macro(add_custom_libcxx name prefix)
+ if(NOT COMPILER_RT_HAS_LIBCXX_SOURCES)
+ message(FATAL_ERROR "libcxx not found!")
+ endif()
+
+ parse_arguments(LIBCXX "DEPS;CFLAGS" "" ${ARGN})
+ foreach(flag ${LIBCXX_CFLAGS})
+ set(flagstr "${flagstr} ${flag}")
+ endforeach()
+ set(LIBCXX_CFLAGS ${flagstr})
+
+ if(NOT COMPILER_RT_STANDALONE_BUILD)
+ list(APPEND LIBCXX_DEPS clang)
+ endif()
+
+ ExternalProject_Add(${name}
+ PREFIX ${prefix}
+ SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH}
+ CMAKE_ARGS -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER}
+ -DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_COMPILER}
+ -DCMAKE_C_FLAGS=${LIBCXX_CFLAGS}
+ -DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS}
+ -DCMAKE_BUILD_TYPE=Release
+ -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ LOG_BUILD 1
+ LOG_CONFIGURE 1
+ LOG_INSTALL 1
+ )
+
+ ExternalProject_Add_Step(${name} force-reconfigure
+ DEPENDERS configure
+ ALWAYS 1
+ )
+
+ ExternalProject_Add_Step(${name} clobber
+ COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR>
+ COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR>
+ COMMENT "Clobberring ${name} build directory..."
+ DEPENDERS configure
+ DEPENDS ${LIBCXX_DEPS}
+ )
endmacro()
diff --git a/cmake/Modules/CompilerRTCompile.cmake b/cmake/Modules/CompilerRTCompile.cmake
index 2794cabe59c5..af3df8ff4f44 100644
--- a/cmake/Modules/CompilerRTCompile.cmake
+++ b/cmake/Modules/CompilerRTCompile.cmake
@@ -1,6 +1,6 @@
include(LLVMParseArguments)
-# Compile a source into an object file with just-built Clang using
+# Compile a source into an object file with COMPILER_RT_TEST_COMPILER using
# a provided compile flags and dependenices.
# clang_compile(<object> <source>
# CFLAGS <list of compile flags>
@@ -8,9 +8,74 @@ include(LLVMParseArguments)
macro(clang_compile object_file source)
parse_arguments(SOURCE "CFLAGS;DEPS" "" ${ARGN})
get_filename_component(source_rpath ${source} REALPATH)
+ if(NOT COMPILER_RT_STANDALONE_BUILD)
+ list(APPEND SOURCE_DEPS clang)
+ endif()
+ if (TARGET CompilerRTUnitTestCheckCxx)
+ list(APPEND SOURCE_DEPS CompilerRTUnitTestCheckCxx)
+ endif()
+ string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
+ if(is_cxx)
+ string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}")
+ else()
+ string(REPLACE " " ";" global_flags "${CMAKE_C_FLAGS}")
+ endif()
+ # On Windows, CMAKE_*_FLAGS are built for MSVC but we use the GCC clang.exe
+ # which doesn't support flags starting with "/smth". Replace those with
+ # "-smth" equivalents.
+ if(MSVC)
+ string(REGEX REPLACE "^/" "-" global_flags "${global_flags}")
+ string(REPLACE ";/" ";-" global_flags "${global_flags}")
+ endif()
+ # Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options
+ # which are not supported by Clang.
+ list(APPEND global_flags -Wno-unknown-warning-option)
+ set(compile_flags ${global_flags} ${SOURCE_CFLAGS})
add_custom_command(
OUTPUT ${object_file}
- COMMAND clang ${SOURCE_CFLAGS} -c -o "${object_file}" ${source_rpath}
+ COMMAND ${COMPILER_RT_TEST_COMPILER} ${compile_flags} -c
+ -o "${object_file}"
+ ${source_rpath}
MAIN_DEPENDENCY ${source}
- DEPENDS clang ${SOURCE_DEPS})
+ DEPENDS ${SOURCE_DEPS})
+endmacro()
+
+# On Darwin, there are no system-wide C++ headers and the just-built clang is
+# therefore not able to compile C++ files unless they are copied/symlinked into
+# ${LLVM_BINARY_DIR}/include/c++
+# The just-built clang is used to build compiler-rt unit tests. Let's detect
+# this before we try to build the tests and print out a suggestion how to fix
+# it.
+# On other platforms, this is currently not an issue.
+macro(clang_compiler_add_cxx_check)
+ if (APPLE)
+ set(CMD
+ "echo '#include <iostream>' | ${COMPILER_RT_TEST_COMPILER} -E -x c++ - > /dev/null"
+ "if [ $? != 0 ] "
+ " then echo"
+ " echo 'Your just-built clang cannot find C++ headers, which are needed to build and run compiler-rt tests.'"
+ " echo 'You should copy or symlink your system C++ headers into ${LLVM_BINARY_DIR}/include/c++'"
+ " if [ -d $(dirname $(dirname $(xcrun -f clang)))/include/c++ ]"
+ " then echo 'e.g. with:'"
+ " echo ' cp -r' $(dirname $(dirname $(xcrun -f clang)))/include/c++ '${LLVM_BINARY_DIR}/include/'"
+ " elif [ -d $(dirname $(dirname $(xcrun -f clang)))/lib/c++ ]"
+ " then echo 'e.g. with:'"
+ " echo ' cp -r' $(dirname $(dirname $(xcrun -f clang)))/lib/c++ '${LLVM_BINARY_DIR}/include/'"
+ " fi"
+ " echo 'This can also be fixed by checking out the libcxx project from llvm.org and installing the headers'"
+ " echo 'into your build directory:'"
+ " echo ' cd ${LLVM_SOURCE_DIR}/projects && svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx'"
+ " echo ' cd ${LLVM_BINARY_DIR} && make -C ${LLVM_SOURCE_DIR}/projects/libcxx installheaders HEADER_DIR=${LLVM_BINARY_DIR}/include'"
+ " echo"
+ " false"
+ "fi"
+ )
+ add_custom_target(CompilerRTUnitTestCheckCxx
+ COMMAND bash -c "${CMD}"
+ COMMENT "Checking that just-built clang can find C++ headers..."
+ VERBATIM)
+ if (TARGET clang)
+ ADD_DEPENDENCIES(CompilerRTUnitTestCheckCxx clang)
+ endif()
+ endif()
endmacro()
diff --git a/cmake/Modules/CompilerRTLink.cmake b/cmake/Modules/CompilerRTLink.cmake
index 85030a725e19..0f0e53a3b2f4 100644
--- a/cmake/Modules/CompilerRTLink.cmake
+++ b/cmake/Modules/CompilerRTLink.cmake
@@ -1,14 +1,18 @@
include(LLVMParseArguments)
-# Link a shared library with just-built Clang.
+# Link a shared library with COMPILER_RT_TEST_COMPILER.
# clang_link_shared(<output.so>
# OBJECTS <list of input objects>
# LINKFLAGS <list of link flags>
# DEPS <list of dependencies>)
macro(clang_link_shared so_file)
parse_arguments(SOURCE "OBJECTS;LINKFLAGS;DEPS" "" ${ARGN})
+ if(NOT COMPILER_RT_STANDALONE_BUILD)
+ list(APPEND SOURCE_DEPS clang)
+ endif()
add_custom_command(
OUTPUT ${so_file}
- COMMAND clang -o "${so_file}" -shared ${SOURCE_LINKFLAGS} ${SOURCE_OBJECTS}
- DEPENDS clang ${SOURCE_DEPS})
+ COMMAND ${COMPILER_RT_TEST_COMPILER} -o "${so_file}" -shared
+ ${SOURCE_LINKFLAGS} ${SOURCE_OBJECTS}
+ DEPENDS ${SOURCE_DEPS})
endmacro()
diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake
index fce37e3eb49a..ae59732928a1 100644
--- a/cmake/Modules/CompilerRTUtils.cmake
+++ b/cmake/Modules/CompilerRTUtils.cmake
@@ -2,6 +2,7 @@
# define a handy helper function for it. The compile flags setting in CMake
# has serious issues that make its syntax challenging at best.
function(set_target_compile_flags target)
+ set(argstring "")
foreach(arg ${ARGN})
set(argstring "${argstring} ${arg}")
endforeach()
@@ -9,24 +10,13 @@ function(set_target_compile_flags target)
endfunction()
function(set_target_link_flags target)
+ set(argstring "")
foreach(arg ${ARGN})
set(argstring "${argstring} ${arg}")
endforeach()
set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}")
endfunction()
-# Check if a given flag is present in a space-separated flag_string.
-# Store the result in out_var.
-function(find_flag_in_string flag_string flag out_var)
- string(REPLACE " " ";" flag_list ${flag_string})
- list(FIND flag_list ${flag} flag_pos)
- if(NOT flag_pos EQUAL -1)
- set(${out_var} TRUE PARENT_SCOPE)
- else()
- set(${out_var} FALSE PARENT_SCOPE)
- endif()
-endfunction()
-
# Set the variable var_PYBOOL to True if var holds a true-ish string,
# otherwise set it to False.
macro(pythonize_bool var)
@@ -36,3 +26,26 @@ macro(pythonize_bool var)
set(${var}_PYBOOL False)
endif()
endmacro()
+
+# Appends value to all lists in ARGN, if the condition is true.
+macro(append_list_if condition value)
+ if(${condition})
+ foreach(list ${ARGN})
+ list(APPEND ${list} ${value})
+ endforeach()
+ endif()
+endmacro()
+
+# Appends value to all strings in ARGN, if the condition is true.
+macro(append_string_if condition value)
+ if(${condition})
+ foreach(str ${ARGN})
+ set(${str} "${${str}} ${value}")
+ endforeach()
+ endif()
+endmacro()
+
+macro(append_no_rtti_flag list)
+ append_list_if(COMPILER_RT_HAS_FNO_RTTI_FLAG -fno-rtti ${list})
+ append_list_if(COMPILER_RT_HAS_GR_FLAG /GR- ${list})
+endmacro()
diff --git a/cmake/Modules/SanitizerUtils.cmake b/cmake/Modules/SanitizerUtils.cmake
index 0836edee2644..1ebc7030a57b 100644
--- a/cmake/Modules/SanitizerUtils.cmake
+++ b/cmake/Modules/SanitizerUtils.cmake
@@ -12,21 +12,36 @@ set(SANITIZER_LINT_SCRIPT
# symbol names that should be exported as well.
# add_sanitizer_rt_symbols(<name> <files with extra symbols to export>)
macro(add_sanitizer_rt_symbols name)
- get_target_property(libfile ${name} LOCATION)
- set(symsfile "${libfile}.syms")
- add_custom_command(OUTPUT ${symsfile}
+ set(stamp ${CMAKE_CURRENT_BINARY_DIR}/${name}.syms-stamp)
+ add_custom_command(OUTPUT ${stamp}
COMMAND ${PYTHON_EXECUTABLE}
- ${SANITIZER_GEN_DYNAMIC_LIST} ${libfile} ${ARGN}
- > ${symsfile}
+ ${SANITIZER_GEN_DYNAMIC_LIST} $<TARGET_FILE:${name}> ${ARGN}
+ > $<TARGET_FILE:${name}>.syms
+ COMMAND ${CMAKE_COMMAND} -E touch ${stamp}
DEPENDS ${name} ${SANITIZER_GEN_DYNAMIC_LIST} ${ARGN}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating exported symbols for ${name}"
VERBATIM)
add_custom_target(${name}-symbols ALL
- DEPENDS ${symsfile}
+ DEPENDS ${stamp}
SOURCES ${SANITIZER_GEN_DYNAMIC_LIST} ${ARGN})
- install(FILES ${symsfile} DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
- add_dependencies(compiler-rt ${name}-symbols)
+
+ if(NOT CMAKE_VERSION VERSION_LESS 3.0)
+ install(FILES $<TARGET_FILE:${name}>.syms
+ DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+ else()
+ # Per-config install location.
+ if(CMAKE_CONFIGURATION_TYPES)
+ foreach(c ${CMAKE_CONFIGURATION_TYPES})
+ get_target_property(libfile ${name} LOCATION_${c})
+ install(FILES ${libfile}.syms CONFIGURATIONS ${c}
+ DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+ endforeach()
+ else()
+ get_target_property(libfile ${name} LOCATION_${CMAKE_BUILD_TYPE})
+ install(FILES ${libfile}.syms DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+ endif()
+ endif()
endmacro()
# Add target to check code style for sanitizer runtimes.
@@ -34,6 +49,7 @@ if(UNIX)
add_custom_target(SanitizerLintCheck
COMMAND LLVM_CHECKOUT=${LLVM_MAIN_SRC_DIR} SILENT=1 TMPDIR=
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
+ COMPILER_RT=${COMPILER_RT_SOURCE_DIR}
${SANITIZER_LINT_SCRIPT}
DEPENDS ${SANITIZER_LINT_SCRIPT}
COMMENT "Running lint check for sanitizer sources..."
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
new file mode 100644
index 000000000000..5f921bf97f5c
--- /dev/null
+++ b/cmake/config-ix.cmake
@@ -0,0 +1,258 @@
+include(CheckCXXCompilerFlag)
+include(CheckLibraryExists)
+include(CheckSymbolExists)
+
+# CodeGen options.
+check_cxx_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG)
+check_cxx_compiler_flag(-fPIE COMPILER_RT_HAS_FPIE_FLAG)
+check_cxx_compiler_flag(-fno-builtin COMPILER_RT_HAS_FNO_BUILTIN_FLAG)
+check_cxx_compiler_flag(-fno-exceptions COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG)
+check_cxx_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_FOMIT_FRAME_POINTER_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(-fvisibility=hidden COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
+check_cxx_compiler_flag(-fno-rtti COMPILER_RT_HAS_FNO_RTTI_FLAG)
+check_cxx_compiler_flag(-ffreestanding COMPILER_RT_HAS_FFREESTANDING_FLAG)
+check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG)
+check_cxx_compiler_flag(-std=c++11 COMPILER_RT_HAS_STD_CXX11_FLAG)
+check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC)
+
+check_cxx_compiler_flag(/GR COMPILER_RT_HAS_GR_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(/Oy COMPILER_RT_HAS_Oy_FLAG)
+
+# Debug info flags.
+check_cxx_compiler_flag(-gline-tables-only COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG)
+check_cxx_compiler_flag(-g COMPILER_RT_HAS_G_FLAG)
+check_cxx_compiler_flag(/Zi COMPILER_RT_HAS_Zi_FLAG)
+
+# Warnings.
+check_cxx_compiler_flag(-Wall COMPILER_RT_HAS_WALL_FLAG)
+check_cxx_compiler_flag(-Werror COMPILER_RT_HAS_WERROR_FLAG)
+check_cxx_compiler_flag("-Werror -Wframe-larger-than=512" COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG)
+check_cxx_compiler_flag("-Werror -Wglobal-constructors" COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG)
+check_cxx_compiler_flag("-Werror -Wc99-extensions" COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG)
+check_cxx_compiler_flag("-Werror -Wgnu" COMPILER_RT_HAS_WGNU_FLAG)
+check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor" COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG)
+check_cxx_compiler_flag("-Werror -Wvariadic-macros" COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG)
+
+check_cxx_compiler_flag(/W3 COMPILER_RT_HAS_W3_FLAG)
+check_cxx_compiler_flag(/WX COMPILER_RT_HAS_WX_FLAG)
+check_cxx_compiler_flag(/wd4146 COMPILER_RT_HAS_WD4146_FLAG)
+check_cxx_compiler_flag(/wd4291 COMPILER_RT_HAS_WD4291_FLAG)
+check_cxx_compiler_flag(/wd4391 COMPILER_RT_HAS_WD4391_FLAG)
+check_cxx_compiler_flag(/wd4722 COMPILER_RT_HAS_WD4722_FLAG)
+check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG)
+
+# Symbols.
+check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL)
+
+# Libraries.
+check_library_exists(c printf "" COMPILER_RT_HAS_LIBC)
+check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL)
+check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
+check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
+check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX)
+
+# Architectures.
+
+# List of all architectures we can target.
+set(COMPILER_RT_SUPPORTED_ARCH)
+
+# Try to compile a very simple source file to ensure we can target the given
+# platform. We use the results of these tests to build only the various target
+# runtime libraries supported by our current compilers cross-compiling
+# abilities.
+set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
+file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <limits>\nint main() {}\n")
+
+# test_target_arch(<arch> <target flags...>)
+# Sets the target flags for a given architecture and determines if this
+# architecture is supported by trying to build a simple file.
+macro(test_target_arch arch)
+ set(TARGET_${arch}_CFLAGS ${ARGN})
+ set(argstring "${CMAKE_EXE_LINKER_FLAGS}")
+ foreach(arg ${ARGN})
+ set(argstring "${argstring} ${arg}")
+ endforeach()
+ try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
+ COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}"
+ OUTPUT_VARIABLE TARGET_${arch}_OUTPUT
+ CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}")
+ if(${CAN_TARGET_${arch}})
+ list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
+ elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}")
+ # Bail out if we cannot target the architecture we plan to test.
+ message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
+ endif()
+endmacro()
+
+# Add $arch as supported with no additional flags.
+macro(add_default_target_arch arch)
+ set(TARGET_${arch}_CFLAGS "")
+ set(CAN_TARGET_${arch} 1)
+ list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
+endmacro()
+
+macro(detect_target_arch)
+ check_symbol_exists(__arm__ "" __ARM)
+ check_symbol_exists(__aarch64__ "" __AARCH64)
+ check_symbol_exists(__x86_64__ "" __X86_64)
+ check_symbol_exists(__i686__ "" __I686)
+ check_symbol_exists(__i386__ "" __I386)
+ check_symbol_exists(__mips__ "" __MIPS)
+ check_symbol_exists(__mips64__ "" __MIPS64)
+ if(__ARM)
+ add_default_target_arch(arm)
+ elseif(__AARCH64)
+ add_default_target_arch(aarch64)
+ elseif(__X86_64)
+ add_default_target_arch(x86_64)
+ elseif(__I686)
+ add_default_target_arch(i686)
+ elseif(__I386)
+ add_default_target_arch(i386)
+ elseif(__MIPS64) # must be checked before __MIPS
+ add_default_target_arch(mips64)
+ elseif(__MIPS)
+ add_default_target_arch(mips)
+ endif()
+endmacro()
+
+# Generate the COMPILER_RT_SUPPORTED_ARCH list.
+if(ANDROID)
+ # Can't rely on LLVM_NATIVE_ARCH in cross-compilation.
+ # Examine compiler output instead.
+ detect_target_arch()
+ set(COMPILER_RT_OS_SUFFIX "-android")
+else()
+ if("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
+ 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})
+ test_target_arch(powerpc64le ${TARGET_64_BIT_CFLAGS})
+ elseif("${LLVM_NATIVE_ARCH}" STREQUAL "Mips")
+ if("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "mipsel|mips64el")
+ # regex for mipsel, mips64el
+ test_target_arch(mipsel ${TARGET_32_BIT_CFLAGS})
+ test_target_arch(mips64el ${TARGET_64_BIT_CFLAGS})
+ else()
+ test_target_arch(mips ${TARGET_32_BIT_CFLAGS})
+ test_target_arch(mips64 ${TARGET_64_BIT_CFLAGS})
+ endif()
+ elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "arm")
+ test_target_arch(arm "-march=armv7-a")
+ elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch32")
+ test_target_arch(aarch32 "-march=armv8-a")
+ elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch64")
+ test_target_arch(aarch64 "-march=aarch64")
+ endif()
+ set(COMPILER_RT_OS_SUFFIX "")
+endif()
+
+message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}")
+
+# Takes ${ARGN} and puts only supported architectures in @out_var list.
+function(filter_available_targets out_var)
+ set(archs)
+ foreach(arch ${ARGN})
+ list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
+ if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch})
+ list(APPEND archs ${arch})
+ endif()
+ endforeach()
+ set(${out_var} ${archs} PARENT_SCOPE)
+endfunction()
+
+# Arhcitectures supported by compiler-rt libraries.
+filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
+ x86_64 i386 i686 powerpc64 powerpc64le arm aarch64 mips mips64 mipsel mips64el)
+filter_available_targets(ASAN_SUPPORTED_ARCH
+ x86_64 i386 i686 powerpc64 powerpc64le arm mips mipsel mips64 mips64el)
+filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64 mips64 mips64el)
+filter_available_targets(LSAN_SUPPORTED_ARCH x86_64)
+# LSan common files should be available on all architectures supported
+# by other sanitizers (even if they build into dummy object files).
+filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH
+ ${SANITIZER_COMMON_SUPPORTED_ARCH})
+filter_available_targets(MSAN_SUPPORTED_ARCH x86_64 mips64 mips64el)
+filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 i686 arm mips mips64
+ mipsel mips64el aarch64 powerpc64 powerpc64le)
+filter_available_targets(TSAN_SUPPORTED_ARCH x86_64)
+filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 i686 arm aarch64 mips mipsel)
+
+if(ANDROID)
+ set(OS_NAME "Android")
+else()
+ set(OS_NAME "${CMAKE_SYSTEM_NAME}")
+endif()
+
+if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
+ (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD" OR
+ (OS_NAME MATCHES "Windows" AND MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 4)))
+ set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
+else()
+ set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH)
+ set(COMPILER_RT_HAS_ASAN TRUE)
+else()
+ set(COMPILER_RT_HAS_ASAN FALSE)
+endif()
+
+# TODO: Add builtins support.
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND
+ OS_NAME MATCHES "Linux")
+ set(COMPILER_RT_HAS_DFSAN TRUE)
+else()
+ set(COMPILER_RT_HAS_DFSAN FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND
+ OS_NAME MATCHES "Darwin|Linux|FreeBSD")
+ set(COMPILER_RT_HAS_LSAN TRUE)
+else()
+ set(COMPILER_RT_HAS_LSAN FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_COMMON_SUPPORTED_ARCH AND
+ OS_NAME MATCHES "Darwin|Linux|FreeBSD|Android")
+ set(COMPILER_RT_HAS_LSAN_COMMON TRUE)
+else()
+ set(COMPILER_RT_HAS_LSAN_COMMON FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
+ OS_NAME MATCHES "Linux")
+ set(COMPILER_RT_HAS_MSAN TRUE)
+else()
+ set(COMPILER_RT_HAS_MSAN FALSE)
+endif()
+
+if (PROFILE_SUPPORTED_ARCH AND
+ OS_NAME MATCHES "Darwin|Linux|FreeBSD")
+ set(COMPILER_RT_HAS_PROFILE TRUE)
+else()
+ set(COMPILER_RT_HAS_PROFILE FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND
+ OS_NAME MATCHES "Linux|FreeBSD")
+ set(COMPILER_RT_HAS_TSAN TRUE)
+else()
+ set(COMPILER_RT_HAS_TSAN FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
+ OS_NAME MATCHES "Darwin|Linux|FreeBSD")
+ set(COMPILER_RT_HAS_UBSAN TRUE)
+else()
+ set(COMPILER_RT_HAS_UBSAN FALSE)
+endif()
+