aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/AddCompilerRT.cmake214
-rw-r--r--cmake/Modules/CompilerRTCompile.cmake6
-rw-r--r--cmake/Modules/CompilerRTDarwinUtils.cmake453
-rw-r--r--cmake/Modules/CompilerRTUtils.cmake10
-rw-r--r--cmake/Modules/SanitizerUtils.cmake82
-rw-r--r--cmake/config-ix.cmake346
6 files changed, 945 insertions, 166 deletions
diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
index 5ea313ba7162..6f401b1fa0c4 100644
--- a/cmake/Modules/AddCompilerRT.cmake
+++ b/cmake/Modules/AddCompilerRT.cmake
@@ -19,6 +19,7 @@ function(add_compiler_rt_object_libraries name)
set(libname "${name}.${os}")
set(libnames ${libnames} ${libname})
set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS})
+ list_union(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS)
endforeach()
else()
foreach(arch ${LIB_ARCHS})
@@ -26,7 +27,7 @@ function(add_compiler_rt_object_libraries name)
set(libnames ${libnames} ${libname})
set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS})
if(NOT CAN_TARGET_${arch})
- message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
+ message(FATAL_ERROR "Architecture ${arch} can't be targeted")
return()
endif()
endforeach()
@@ -39,91 +40,130 @@ function(add_compiler_rt_object_libraries name)
set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
if(APPLE)
- set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCHS}")
+ set_target_properties(${libname} PROPERTIES
+ OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}")
endif()
endforeach()
endfunction()
-# 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}
+# Takes a list of object library targets, and a suffix and appends the proper
+# TARGET_OBJECTS string to the output variable.
+# format_object_libs(<output> <suffix> ...)
+macro(format_object_libs output suffix)
+ foreach(lib ${ARGN})
+ list(APPEND ${output} $<TARGET_OBJECTS:${lib}.${suffix}>)
+ endforeach()
+endmacro()
+
+# Adds static or shared runtime for a list of architectures and operating
+# systems and puts it in the proper directory in the build and install trees.
+# add_compiler_rt_runtime(<name>
+# {STATIC|SHARED}
+# ARCHS <architectures>
+# OS <os list>
# SOURCES <source files>
# CFLAGS <compile flags>
+# LINKFLAGS <linker flags>
# DEFS <compile definitions>
-# OUTPUT_NAME <output library name>)
-macro(add_compiler_rt_runtime name arch type)
- if(CAN_TARGET_${arch})
- cmake_parse_arguments(LIB "" "OUTPUT_NAME" "SOURCES;CFLAGS;LINKFLAGS;DEFS" ${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} ${LIB_LINKFLAGS})
- 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}
- 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}
- LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
- RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+# LINK_LIBS <linked libraries> (only for shared library)
+# OBJECT_LIBS <object libraries to use as sources>
+# PARENT_TARGET <convenience parent target>)
+function(add_compiler_rt_runtime name type)
+ if(NOT type MATCHES "^(STATIC|SHARED)$")
+ message(FATAL_ERROR "type argument must be STATIC or SHARED")
+ return()
+ endif()
+ cmake_parse_arguments(LIB
+ ""
+ "PARENT_TARGET"
+ "OS;ARCHS;SOURCES;CFLAGS;LINKFLAGS;DEFS;LINK_LIBS;OBJECT_LIBS"
+ ${ARGN})
+ set(libnames)
+ if(APPLE)
+ foreach(os ${LIB_OS})
+ if(type STREQUAL "STATIC")
+ set(libname "${name}_${os}")
+ else()
+ set(libname "${name}_${os}_dynamic")
+ set(extra_linkflags_${libname} ${DARWIN_${os}_LINKFLAGS} ${LIB_LINKFLAGS})
+ endif()
+ list_union(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS)
+ if(LIB_ARCHS_${libname})
+ list(APPEND libnames ${libname})
+ set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS} ${LIB_CFLAGS})
+ set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX})
+ set(sources_${libname} ${LIB_SOURCES})
+ format_object_libs(sources_${libname} ${os} ${LIB_OBJECT_LIBS})
+ endif()
+ endforeach()
else()
- message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
+ foreach(arch ${LIB_ARCHS})
+ if(NOT CAN_TARGET_${arch})
+ message(FATAL_ERROR "Architecture ${arch} can't be targeted")
+ return()
+ endif()
+ if(type STREQUAL "STATIC")
+ set(libname "${name}-${arch}")
+ set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX})
+ else()
+ set(libname "${name}-dynamic-${arch}")
+ set(extra_linkflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS} ${LIB_LINKFLAGS})
+ if(WIN32)
+ set(output_name_${libname} ${name}_dynamic-${arch}${COMPILER_RT_OS_SUFFIX})
+ else()
+ set(output_name_${libname} ${name}-${arch}${COMPILER_RT_OS_SUFFIX})
+ endif()
+ endif()
+ set(sources_${libname} ${LIB_SOURCES})
+ format_object_libs(sources_${libname} ${arch} ${LIB_OBJECT_LIBS})
+ set(libnames ${libnames} ${libname})
+ set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
+ endforeach()
endif()
-endmacro()
-# Same as add_compiler_rt_runtime(... STATIC), but creates a universal library
-# for several architectures.
-# add_compiler_rt_osx_static_runtime(<name> ARCHS <architectures>
-# SOURCES <source files>
-# CFLAGS <compile flags>
-# DEFS <compile definitions>)
-macro(add_compiler_rt_osx_static_runtime name)
- cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS" ${ARGN})
- add_library(${name} STATIC ${LIB_SOURCES})
- set_target_compile_flags(${name} ${LIB_CFLAGS})
- set_property(TARGET ${name} APPEND PROPERTY
- COMPILE_DEFINITIONS ${LIB_DEFS})
- set_target_properties(${name} PROPERTIES
- OSX_ARCHITECTURES "${LIB_ARCHS}"
- ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
- install(TARGETS ${name}
- ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
-endmacro()
+ if(NOT libnames)
+ return()
+ endif()
-# Adds dynamic runtime library on osx/iossim, which supports multiple
-# architectures.
-# add_compiler_rt_darwin_dynamic_runtime(<name> <os>
-# ARCHS <architectures>
-# SOURCES <source files>
-# CFLAGS <compile flags>
-# DEFS <compile definitions>
-# LINKFLAGS <link flags>)
-macro(add_compiler_rt_darwin_dynamic_runtime name os)
- cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS;LINKFLAGS" ${ARGN})
- add_library(${name} SHARED ${LIB_SOURCES})
- set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
- set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS})
- set_property(TARGET ${name} APPEND PROPERTY
- COMPILE_DEFINITIONS ${LIB_DEFS})
- set_target_properties(${name} PROPERTIES
- OSX_ARCHITECTURES "${LIB_ARCHS}"
- LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
- install(TARGETS ${name}
- LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
-endmacro()
+ if(LIB_PARENT_TARGET)
+ set(COMPONENT_OPTION COMPONENT ${LIB_PARENT_TARGET})
+ endif()
+
+ foreach(libname ${libnames})
+ add_library(${libname} ${type} ${sources_${libname}})
+ set_target_compile_flags(${libname} ${extra_cflags_${libname}})
+ set_target_link_flags(${libname} ${extra_linkflags_${libname}})
+ set_property(TARGET ${libname} APPEND PROPERTY
+ COMPILE_DEFINITIONS ${LIB_DEFS})
+ set_target_properties(${libname} PROPERTIES
+ ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+ LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+ RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+ set_target_properties(${libname} PROPERTIES
+ OUTPUT_NAME ${output_name_${libname}})
+ if(LIB_LINK_LIBS AND ${type} STREQUAL "SHARED")
+ target_link_libraries(${libname} ${LIB_LINK_LIBS})
+ endif()
+ install(TARGETS ${libname}
+ ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
+ ${COMPONENT_OPTION}
+ LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
+ ${COMPONENT_OPTION}
+ RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
+ ${COMPONENT_OPTION})
+ if(APPLE)
+ set_target_properties(${libname} PROPERTIES
+ OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}")
+ endif()
+
+ if(type STREQUAL "SHARED")
+ rt_externalize_debuginfo(${libname})
+ endif()
+ endforeach()
+ if(LIB_PARENT_TARGET)
+ add_dependencies(${LIB_PARENT_TARGET} ${libnames})
+ endif()
+endfunction()
set(COMPILER_RT_TEST_CFLAGS)
@@ -248,7 +288,8 @@ macro(add_custom_libcxx name prefix)
ExternalProject_Add(${name}
PREFIX ${prefix}
SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH}
- CMAKE_ARGS -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER}
+ CMAKE_ARGS -DCMAKE_MAKE_PROGRAM:STRING=${CMAKE_MAKE_PROGRAM}
+ -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER}
-DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_COMPILER}
-DCMAKE_C_FLAGS=${LIBCXX_CFLAGS}
-DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS}
@@ -273,3 +314,24 @@ macro(add_custom_libcxx name prefix)
DEPENDS ${LIBCXX_DEPS}
)
endmacro()
+
+function(rt_externalize_debuginfo name)
+ if(NOT COMPILER_RT_EXTERNALIZE_DEBUGINFO)
+ return()
+ endif()
+
+ if(APPLE)
+ if(CMAKE_CXX_FLAGS MATCHES "-flto"
+ OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto")
+
+ set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o)
+ set_property(TARGET ${name} APPEND_STRING PROPERTY
+ LINK_FLAGS " -Wl,-object_path_lto -Wl,${lto_object}")
+ endif()
+ add_custom_command(TARGET ${name} POST_BUILD
+ COMMAND xcrun dsymutil $<TARGET_FILE:${name}>
+ COMMAND xcrun strip -Sl $<TARGET_FILE:${name}>)
+ else()
+ message(FATAL_ERROR "COMPILER_RT_EXTERNALIZE_DEBUGINFO isn't implemented for non-darwin platforms!")
+ endif()
+endfunction()
diff --git a/cmake/Modules/CompilerRTCompile.cmake b/cmake/Modules/CompilerRTCompile.cmake
index b2e62dd0bac6..48f40bf4f753 100644
--- a/cmake/Modules/CompilerRTCompile.cmake
+++ b/cmake/Modules/CompilerRTCompile.cmake
@@ -49,6 +49,10 @@ macro(clang_compile object_file source)
translate_msvc_cflags(global_flags "${global_flags}")
endif()
+ if (APPLE)
+ set(global_flags ${OSX_SYSROOT_FLAG} ${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)
@@ -72,7 +76,7 @@ endmacro()
macro(clang_compiler_add_cxx_check)
if (APPLE)
set(CMD
- "echo '#include <iostream>' | ${COMPILER_RT_TEST_COMPILER} -E -x c++ - > /dev/null"
+ "echo '#include <iostream>' | ${COMPILER_RT_TEST_COMPILER} ${OSX_SYSROOT_FLAG} -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.'"
diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake
new file mode 100644
index 000000000000..511361b49a7a
--- /dev/null
+++ b/cmake/Modules/CompilerRTDarwinUtils.cmake
@@ -0,0 +1,453 @@
+# On OS X SDKs can be installed anywhere on the base system and xcode-select can
+# set the default Xcode to use. This function finds the SDKs that are present in
+# the current Xcode.
+function(find_darwin_sdk_dir var sdk_name)
+ # Let's first try the internal SDK, otherwise use the public SDK.
+ execute_process(
+ COMMAND xcodebuild -version -sdk ${sdk_name}.internal Path
+ OUTPUT_VARIABLE var_internal
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_FILE /dev/null
+ )
+ if("" STREQUAL "${var_internal}")
+ execute_process(
+ COMMAND xcodebuild -version -sdk ${sdk_name} Path
+ OUTPUT_VARIABLE var_internal
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_FILE /dev/null
+ )
+ endif()
+ set(${var} ${var_internal} PARENT_SCOPE)
+endfunction()
+
+# There isn't a clear mapping of what architectures are supported with a given
+# target platform, but ld's version output does list the architectures it can
+# link for.
+function(darwin_get_toolchain_supported_archs output_var)
+ execute_process(
+ COMMAND ld -v
+ ERROR_VARIABLE LINKER_VERSION)
+
+ string(REGEX MATCH "configured to support archs: ([^\n]+)"
+ ARCHES_MATCHED "${LINKER_VERSION}")
+ if(ARCHES_MATCHED)
+ set(ARCHES "${CMAKE_MATCH_1}")
+ message(STATUS "Got ld supported ARCHES: ${ARCHES}")
+ string(REPLACE " " ";" ARCHES ${ARCHES})
+ else()
+ # If auto-detecting fails, fall back to a default set
+ message(WARNING "Detecting supported architectures from 'ld -v' failed. Returning default set.")
+ set(ARCHES "i386;x86_64;armv7;armv7s;arm64")
+ endif()
+
+ set(${output_var} ${ARCHES} PARENT_SCOPE)
+endfunction()
+
+# This function takes an OS and a list of architectures and identifies the
+# subset of the architectures list that the installed toolchain can target.
+function(darwin_test_archs os valid_archs)
+ if(${valid_archs})
+ message(STATUS "Using cached valid architectures for ${os}.")
+ return()
+ endif()
+
+ set(archs ${ARGN})
+ message(STATUS "Finding valid architectures for ${os}...")
+ set(SIMPLE_CPP ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.cpp)
+ file(WRITE ${SIMPLE_CPP} "#include <iostream>\nint main() { std::cout << std::endl; return 0; }\n")
+
+ set(os_linker_flags)
+ foreach(flag ${DARWIN_${os}_LINKFLAGS})
+ set(os_linker_flags "${os_linker_flags} ${flag}")
+ endforeach()
+
+ # The simple program will build for x86_64h on the simulator because it is
+ # compatible with x86_64 libraries (mostly), but since x86_64h isn't actually
+ # a valid or useful architecture for the iOS simulator we should drop it.
+ if(${os} STREQUAL "iossim")
+ list(REMOVE_ITEM archs "x86_64h")
+ endif()
+
+ set(working_archs)
+ foreach(arch ${archs})
+
+ set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")
+ try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_CPP}
+ COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS}
+ CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${arch_linker_flags}"
+ OUTPUT_VARIABLE TEST_OUTPUT)
+ if(${CAN_TARGET_${os}_${arch}})
+ list(APPEND working_archs ${arch})
+ else()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Testing compiler for supporting ${os}-${arch}:\n"
+ "${TEST_OUTPUT}\n")
+ endif()
+ endforeach()
+ set(${valid_archs} ${working_archs}
+ CACHE STRING "List of valid architectures for platform ${os}.")
+endfunction()
+
+# This function checks the host cpusubtype to see if it is post-haswell. Haswell
+# and later machines can run x86_64h binaries. Haswell is cpusubtype 8.
+function(darwin_filter_host_archs input output)
+ list_union(tmp_var DARWIN_osx_ARCHS ${input})
+ execute_process(
+ COMMAND sysctl hw.cpusubtype
+ OUTPUT_VARIABLE SUBTYPE)
+
+ string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"
+ SUBTYPE_MATCHED "${SUBTYPE}")
+ set(HASWELL_SUPPORTED Off)
+ if(SUBTYPE_MATCHED)
+ if(${CMAKE_MATCH_1} GREATER 7)
+ set(HASWELL_SUPPORTED On)
+ endif()
+ endif()
+ if(NOT HASWELL_SUPPORTED)
+ list(REMOVE_ITEM tmp_var x86_64h)
+ endif()
+ set(${output} ${tmp_var} PARENT_SCOPE)
+endfunction()
+
+# Read and process the exclude file into a list of symbols
+function(darwin_read_list_from_file output_var file)
+ if(EXISTS ${file})
+ file(READ ${file} EXCLUDES)
+ string(REPLACE "\n" ";" EXCLUDES ${EXCLUDES})
+ set(${output_var} ${EXCLUDES} PARENT_SCOPE)
+ endif()
+endfunction()
+
+# this function takes an OS, architecture and minimum version and provides a
+# list of builtin functions to exclude
+function(darwin_find_excluded_builtins_list output_var)
+ cmake_parse_arguments(LIB
+ ""
+ "OS;ARCH;MIN_VERSION"
+ ""
+ ${ARGN})
+
+ if(NOT LIB_OS OR NOT LIB_ARCH)
+ message(FATAL_ERROR "Must specify OS and ARCH to darwin_find_excluded_builtins_list!")
+ endif()
+
+ darwin_read_list_from_file(${LIB_OS}_BUILTINS
+ ${DARWIN_EXCLUDE_DIR}/${LIB_OS}.txt)
+ darwin_read_list_from_file(${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS
+ ${DARWIN_EXCLUDE_DIR}/${LIB_OS}-${LIB_ARCH}.txt)
+
+ if(LIB_MIN_VERSION)
+ file(GLOB builtin_lists ${DARWIN_EXCLUDE_DIR}/${LIB_OS}*-${LIB_ARCH}.txt)
+ foreach(builtin_list ${builtin_lists})
+ string(REGEX MATCH "${LIB_OS}([0-9\\.]*)-${LIB_ARCH}.txt" VERSION_MATCHED "${builtin_list}")
+ if (VERSION_MATCHED AND NOT CMAKE_MATCH_1 VERSION_LESS LIB_MIN_VERSION)
+ if(NOT smallest_version)
+ set(smallest_version ${CMAKE_MATCH_1})
+ elseif(CMAKE_MATCH_1 VERSION_LESS smallest_version)
+ set(smallest_version ${CMAKE_MATCH_1})
+ endif()
+ endif()
+ endforeach()
+
+ if(smallest_version)
+ darwin_read_list_from_file(${LIB_ARCH}_${LIB_OS}_BUILTINS
+ ${DARWIN_EXCLUDE_DIR}/${LIB_OS}${smallest_version}-${LIB_ARCH}.txt)
+ endif()
+ endif()
+
+ set(${output_var}
+ ${${LIB_ARCH}_${LIB_OS}_BUILTINS}
+ ${${LIB_OS}_${LIB_ARCH}_BASE_BUILTINS}
+ ${${LIB_OS}_BUILTINS} PARENT_SCOPE)
+endfunction()
+
+# adds a single builtin library for a single OS & ARCH
+macro(darwin_add_builtin_library name suffix)
+ cmake_parse_arguments(LIB
+ ""
+ "PARENT_TARGET;OS;ARCH"
+ "SOURCES;CFLAGS;DEFS"
+ ${ARGN})
+ set(libname "${name}.${suffix}_${LIB_ARCH}_${LIB_OS}")
+ add_library(${libname} STATIC ${LIB_SOURCES})
+ if(DARWIN_${LIB_OS}_SYSROOT)
+ set(sysroot_flag -isysroot ${DARWIN_${LIB_OS}_SYSROOT})
+ endif()
+ set_target_compile_flags(${libname}
+ ${sysroot_flag}
+ ${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG}
+ ${LIB_CFLAGS})
+ set_property(TARGET ${libname} APPEND PROPERTY
+ COMPILE_DEFINITIONS ${LIB_DEFS})
+ set_target_properties(${libname} PROPERTIES
+ OUTPUT_NAME ${libname}${COMPILER_RT_OS_SUFFIX})
+ set_target_properties(${libname} PROPERTIES
+ OSX_ARCHITECTURES ${LIB_ARCH})
+
+ if(LIB_PARENT_TARGET)
+ add_dependencies(${LIB_PARENT_TARGET} ${libname})
+ endif()
+
+ list(APPEND ${LIB_OS}_${suffix}_libs ${libname})
+ list(APPEND ${LIB_OS}_${suffix}_lipo_flags -arch ${arch} $<TARGET_FILE:${libname}>)
+endmacro()
+
+function(darwin_lipo_libs name)
+ cmake_parse_arguments(LIB
+ ""
+ "PARENT_TARGET;OUTPUT_DIR;INSTALL_DIR"
+ "LIPO_FLAGS;DEPENDS"
+ ${ARGN})
+ if(LIB_DEPENDS AND LIB_LIPO_FLAGS)
+ add_custom_command(OUTPUT ${LIB_OUTPUT_DIR}/lib${name}.a
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${LIB_OUTPUT_DIR}
+ COMMAND lipo -output
+ ${LIB_OUTPUT_DIR}/lib${name}.a
+ -create ${LIB_LIPO_FLAGS}
+ DEPENDS ${LIB_DEPENDS}
+ )
+ add_custom_target(${name}
+ DEPENDS ${LIB_OUTPUT_DIR}/lib${name}.a)
+ add_dependencies(${LIB_PARENT_TARGET} ${name})
+ install(FILES ${LIB_OUTPUT_DIR}/lib${name}.a
+ DESTINATION ${LIB_INSTALL_DIR})
+ else()
+ message(WARNING "Not generating lipo target for ${name} because no input libraries exist.")
+ endif()
+endfunction()
+
+# Filter out generic versions of routines that are re-implemented in
+# architecture specific manner. This prevents multiple definitions of the
+# same symbols, making the symbol selection non-deterministic.
+function(darwin_filter_builtin_sources output_var exclude_or_include excluded_list)
+ if(exclude_or_include STREQUAL "EXCLUDE")
+ set(filter_action GREATER)
+ set(filter_value -1)
+ elseif(exclude_or_include STREQUAL "INCLUDE")
+ set(filter_action LESS)
+ set(filter_value 0)
+ else()
+ message(FATAL_ERROR "darwin_filter_builtin_sources called without EXCLUDE|INCLUDE")
+ endif()
+
+ set(intermediate ${ARGN})
+ foreach (_file ${intermediate})
+ get_filename_component(_name_we ${_file} NAME_WE)
+ list(FIND ${excluded_list} ${_name_we} _found)
+ if(_found ${filter_action} ${filter_value})
+ list(REMOVE_ITEM intermediate ${_file})
+ elseif(${_file} MATCHES ".*/.*\\.S" OR ${_file} MATCHES ".*/.*\\.c")
+ get_filename_component(_name ${_file} NAME)
+ string(REPLACE ".S" ".c" _cname "${_name}")
+ list(REMOVE_ITEM intermediate ${_cname})
+ endif ()
+ endforeach ()
+ set(${output_var} ${intermediate} PARENT_SCOPE)
+endfunction()
+
+function(darwin_add_eprintf_library)
+ cmake_parse_arguments(LIB
+ ""
+ ""
+ "CFLAGS"
+ ${ARGN})
+
+ add_library(clang_rt.eprintf STATIC eprintf.c)
+ set_target_compile_flags(clang_rt.eprintf
+ -isysroot ${DARWIN_osx_SYSROOT}
+ ${DARWIN_osx_BUILTIN_MIN_VER_FLAG}
+ -arch i386
+ ${LIB_CFLAGS})
+ set_target_properties(clang_rt.eprintf PROPERTIES
+ OUTPUT_NAME clang_rt.eprintf${COMPILER_RT_OS_SUFFIX})
+ set_target_properties(clang_rt.eprintf PROPERTIES
+ OSX_ARCHITECTURES i386)
+ add_dependencies(builtins clang_rt.eprintf)
+ set_target_properties(clang_rt.eprintf PROPERTIES
+ ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+ install(TARGETS clang_rt.eprintf
+ ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+endfunction()
+
+# Generates builtin libraries for all operating systems specified in ARGN. Each
+# OS library is constructed by lipo-ing together single-architecture libraries.
+macro(darwin_add_builtin_libraries)
+ set(DARWIN_EXCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Darwin-excludes)
+
+ set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer")
+ set(CMAKE_C_FLAGS "")
+ set(CMAKE_CXX_FLAGS "")
+ set(CMAKE_ASM_FLAGS "")
+
+ set(PROFILE_SOURCES ../profile/InstrProfiling
+ ../profile/InstrProfilingBuffer
+ ../profile/InstrProfilingPlatformDarwin)
+ foreach (os ${ARGN})
+ list_union(DARWIN_BUILTIN_ARCHS DARWIN_${os}_ARCHS BUILTIN_SUPPORTED_ARCH)
+ foreach (arch ${DARWIN_BUILTIN_ARCHS})
+ darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS
+ OS ${os}
+ ARCH ${arch}
+ MIN_VERSION ${DARWIN_${os}_BUILTIN_MIN_VER})
+
+ darwin_filter_builtin_sources(filtered_sources
+ EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS
+ ${${arch}_SOURCES})
+
+ darwin_add_builtin_library(clang_rt builtins
+ OS ${os}
+ ARCH ${arch}
+ SOURCES ${filtered_sources}
+ CFLAGS ${CFLAGS} -arch ${arch}
+ PARENT_TARGET builtins)
+ endforeach()
+
+ # Don't build cc_kext libraries for simulator platforms
+ if(NOT DARWIN_${os}_SKIP_CC_KEXT)
+ foreach (arch ${DARWIN_BUILTIN_ARCHS})
+ # By not specifying MIN_VERSION this only reads the OS and OS-arch lists.
+ # We don't want to filter out the builtins that are present in libSystem
+ # because kexts can't link libSystem.
+ darwin_find_excluded_builtins_list(${arch}_${os}_EXCLUDED_BUILTINS
+ OS ${os}
+ ARCH ${arch})
+
+ darwin_filter_builtin_sources(filtered_sources
+ EXCLUDE ${arch}_${os}_EXCLUDED_BUILTINS
+ ${${arch}_SOURCES})
+
+ # In addition to the builtins cc_kext includes some profile sources
+ darwin_add_builtin_library(clang_rt cc_kext
+ OS ${os}
+ ARCH ${arch}
+ SOURCES ${filtered_sources} ${PROFILE_SOURCES}
+ CFLAGS ${CFLAGS} -arch ${arch} -mkernel
+ DEFS KERNEL_USE
+ PARENT_TARGET builtins)
+ endforeach()
+ set(archive_name clang_rt.cc_kext_${os})
+ if(${os} STREQUAL "osx")
+ set(archive_name clang_rt.cc_kext)
+ endif()
+ darwin_lipo_libs(${archive_name}
+ PARENT_TARGET builtins
+ LIPO_FLAGS ${${os}_cc_kext_lipo_flags}
+ DEPENDS ${${os}_cc_kext_libs}
+ OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+ INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+ endif()
+ endforeach()
+
+ darwin_add_eprintf_library(CFLAGS ${CFLAGS})
+
+ # We put the x86 sim slices into the archives for their base OS
+ foreach (os ${ARGN})
+ if(NOT ${os} MATCHES ".*sim$")
+ darwin_lipo_libs(clang_rt.${os}
+ PARENT_TARGET builtins
+ LIPO_FLAGS ${${os}_builtins_lipo_flags} ${${os}sim_builtins_lipo_flags}
+ DEPENDS ${${os}_builtins_libs} ${${os}sim_builtins_libs}
+ OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+ INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+ endif()
+ endforeach()
+ darwin_add_embedded_builtin_libraries()
+endmacro()
+
+macro(darwin_add_embedded_builtin_libraries)
+ # this is a hacky opt-out. If you can't target both intel and arm
+ # architectures we bail here.
+ set(DARWIN_SOFT_FLOAT_ARCHS armv6m armv7m armv7em armv7)
+ set(DARWIN_HARD_FLOAT_ARCHS armv7em armv7)
+ if(COMPILER_RT_SUPPORTED_ARCH MATCHES ".*armv.*")
+ list(FIND COMPILER_RT_SUPPORTED_ARCH i386 i386_idx)
+ if(i386_idx GREATER -1)
+ list(APPEND DARWIN_HARD_FLOAT_ARCHS i386)
+ endif()
+
+ list(FIND COMPILER_RT_SUPPORTED_ARCH x86_64 x86_64_idx)
+ if(x86_64_idx GREATER -1)
+ list(APPEND DARWIN_HARD_FLOAT_ARCHS x86_64)
+ endif()
+
+ set(MACHO_SYM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/macho_embedded)
+
+ set(CFLAGS "-Oz -Wall -fomit-frame-pointer -ffreestanding")
+ set(CMAKE_C_FLAGS "")
+ set(CMAKE_CXX_FLAGS "")
+ set(CMAKE_ASM_FLAGS "")
+
+ set(SOFT_FLOAT_FLAG -mfloat-abi=soft)
+ set(HARD_FLOAT_FLAG -mfloat-abi=hard)
+
+ set(ENABLE_PIC Off)
+ set(PIC_FLAG -fPIC)
+ set(STATIC_FLAG -static)
+
+ set(DARWIN_macho_embedded_ARCHS armv6m armv7m armv7em armv7 i386 x86_64)
+
+ set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR
+ ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded)
+ set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR
+ ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded)
+
+ set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi")
+ set(CFLAGS_i386 "-march=pentium")
+
+ darwin_read_list_from_file(common_FUNCTIONS ${MACHO_SYM_DIR}/common.txt)
+ darwin_read_list_from_file(thumb2_FUNCTIONS ${MACHO_SYM_DIR}/thumb2.txt)
+ darwin_read_list_from_file(thumb2_64_FUNCTIONS ${MACHO_SYM_DIR}/thumb2-64.txt)
+ darwin_read_list_from_file(arm_FUNCTIONS ${MACHO_SYM_DIR}/arm.txt)
+ darwin_read_list_from_file(i386_FUNCTIONS ${MACHO_SYM_DIR}/i386.txt)
+
+
+ set(armv6m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS})
+ set(armv7m_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS})
+ set(armv7em_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS})
+ set(armv7_FUNCTIONS ${common_FUNCTIONS} ${arm_FUNCTIONS} ${thumb2_FUNCTIONS} ${thumb2_64_FUNCTIONS})
+ set(i386_FUNCTIONS ${common_FUNCTIONS} ${i386_FUNCTIONS})
+ set(x86_64_FUNCTIONS ${common_FUNCTIONS})
+
+ foreach(arch ${DARWIN_macho_embedded_ARCHS})
+ darwin_filter_builtin_sources(${arch}_filtered_sources
+ INCLUDE ${arch}_FUNCTIONS
+ ${${arch}_SOURCES})
+ if(NOT ${arch}_filtered_sources)
+ message("${arch}_SOURCES: ${${arch}_SOURCES}")
+ message("${arch}_FUNCTIONS: ${${arch}_FUNCTIONS}")
+ message(FATAL_ERROR "Empty filtered sources!")
+ endif()
+ endforeach()
+
+ foreach(float_type SOFT HARD)
+ foreach(type PIC STATIC)
+ string(TOLOWER "${float_type}_${type}" lib_suffix)
+ foreach(arch ${DARWIN_${float_type}_FLOAT_ARCHS})
+ set(DARWIN_macho_embedded_SYSROOT ${DARWIN_osx_SYSROOT})
+ set(float_flag)
+ if(${arch} MATCHES "^arm")
+ # x86 targets are hard float by default, but the complain about the
+ # float ABI flag, so don't pass it unless we're targeting arm.
+ set(float_flag ${${float_type}_FLOAT_FLAG})
+ endif()
+ darwin_add_builtin_library(clang_rt ${lib_suffix}
+ OS macho_embedded
+ ARCH ${arch}
+ SOURCES ${${arch}_filtered_sources}
+ CFLAGS ${CFLAGS} -arch ${arch} ${${type}_FLAG} ${float_flag} ${CFLAGS_${arch}}
+ PARENT_TARGET builtins)
+ endforeach()
+ foreach(lib ${macho_embedded_${lib_suffix}_libs})
+ set_target_properties(${lib} PROPERTIES LINKER_LANGUAGE C)
+ endforeach()
+ darwin_lipo_libs(clang_rt.${lib_suffix}
+ PARENT_TARGET builtins
+ LIPO_FLAGS ${macho_embedded_${lib_suffix}_lipo_flags}
+ DEPENDS ${macho_embedded_${lib_suffix}_libs}
+ OUTPUT_DIR ${DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR}
+ INSTALL_DIR ${DARWIN_macho_embedded_LIBRARY_INSTALL_DIR})
+ endforeach()
+ endforeach()
+ endif()
+endmacro()
diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake
index f7f60a4ac6f4..cf690f4a33c5 100644
--- a/cmake/Modules/CompilerRTUtils.cmake
+++ b/cmake/Modules/CompilerRTUtils.cmake
@@ -57,3 +57,13 @@ macro(append_have_file_definition filename varname list)
endif()
list(APPEND ${list} "${varname}=${${varname}}")
endmacro()
+
+macro(list_union output input1 input2)
+ set(${output})
+ foreach(it ${${input1}})
+ list(FIND ${input2} ${it} index)
+ if( NOT (index EQUAL -1))
+ list(APPEND ${output} ${it})
+ endif()
+ endforeach()
+endmacro()
diff --git a/cmake/Modules/SanitizerUtils.cmake b/cmake/Modules/SanitizerUtils.cmake
index c040b42122ce..3eb49c83f51c 100644
--- a/cmake/Modules/SanitizerUtils.cmake
+++ b/cmake/Modules/SanitizerUtils.cmake
@@ -4,46 +4,60 @@ set(SANITIZER_GEN_DYNAMIC_LIST
set(SANITIZER_LINT_SCRIPT
${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/scripts/check_lint.sh)
-# Create a target "<name>-symbols" that would generate the list of symbols
-# that need to be exported from sanitizer runtime "<name>". Function
+# Create a target "<name>-<arch>-symbols" that would generate the list of
+# symbols that need to be exported from sanitizer runtime "<name>". Function
# interceptors are exported automatically, user can also provide files with
# symbol names that should be exported as well.
-# add_sanitizer_rt_symbols(<name> <files with extra symbols to export>)
+# add_sanitizer_rt_symbols(<name>
+# ARCHS <architectures>
+# PARENT_TARGET <convenience parent target>
+# EXTRA <files with extra symbols to export>)
macro(add_sanitizer_rt_symbols name)
- set(stamp ${CMAKE_CURRENT_BINARY_DIR}/${name}.syms-stamp)
- set(extra_args)
- foreach(arg ${ARGN})
- list(APPEND extra_args "--extra" ${arg})
- endforeach()
- add_custom_command(OUTPUT ${stamp}
- COMMAND ${PYTHON_EXECUTABLE}
- ${SANITIZER_GEN_DYNAMIC_LIST} ${extra_args} $<TARGET_FILE:${name}>
- > $<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 ${stamp}
- SOURCES ${SANITIZER_GEN_DYNAMIC_LIST} ${ARGN})
+ cmake_parse_arguments(ARG
+ ""
+ "PARENT_TARGET"
+ "ARCHS;EXTRA"
+ ${ARGN})
+ foreach(arch ${ARG_ARCHS})
+ set(target_name ${name}-${arch})
+ set(stamp ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.syms-stamp)
+ set(extra_args)
+ foreach(arg ${ARG_EXTRA})
+ list(APPEND extra_args "--extra" ${arg})
+ endforeach()
+ add_custom_command(OUTPUT ${stamp}
+ COMMAND ${PYTHON_EXECUTABLE}
+ ${SANITIZER_GEN_DYNAMIC_LIST} ${extra_args} $<TARGET_FILE:${target_name}>
+ > $<TARGET_FILE:${target_name}>.syms
+ COMMAND ${CMAKE_COMMAND} -E touch ${stamp}
+ DEPENDS ${target_name} ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMENT "Generating exported symbols for ${target_name}"
+ VERBATIM)
+ add_custom_target(${target_name}-symbols ALL
+ DEPENDS ${stamp}
+ SOURCES ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA})
- 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()
+ if(NOT CMAKE_VERSION VERSION_LESS 3.0)
+ install(FILES $<TARGET_FILE:${target_name}>.syms
+ DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
else()
- get_target_property(libfile ${name} LOCATION_${CMAKE_BUILD_TYPE})
- install(FILES ${libfile}.syms DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+ # Per-config install location.
+ if(CMAKE_CONFIGURATION_TYPES)
+ foreach(c ${CMAKE_CONFIGURATION_TYPES})
+ get_target_property(libfile ${target_name} LOCATION_${c})
+ install(FILES ${libfile}.syms CONFIGURATIONS ${c}
+ DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+ endforeach()
+ else()
+ get_target_property(libfile ${target_name} LOCATION_${CMAKE_BUILD_TYPE})
+ install(FILES ${libfile}.syms DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+ endif()
endif()
- endif()
+ if(ARG_PARENT_TARGET)
+ add_dependencies(${ARG_PARENT_TARGET} ${target_name}-symbols)
+ endif()
+ endforeach()
endmacro()
macro(add_sanitizer_rt_version_list name)
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index c645be4d88d6..f91530bb4403 100644
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -27,7 +27,14 @@ check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUN
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(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG)
-check_cxx_compiler_flag(-msse3 COMPILER_RT_HAS_MSSE3_FLAG)
+check_cxx_compiler_flag("-Werror -msse3" COMPILER_RT_HAS_MSSE3_FLAG)
+check_cxx_compiler_flag(-std=c99 COMPILER_RT_HAS_STD_C99_FLAG)
+check_cxx_compiler_flag(--sysroot=. COMPILER_RT_HAS_SYSROOT_FLAG)
+
+if(NOT WIN32 AND NOT CYGWIN)
+ # MinGW warns if -fvisibility-inlines-hidden is used.
+ check_cxx_compiler_flag("-fvisibility-inlines-hidden" COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG)
+endif()
check_cxx_compiler_flag(/GR COMPILER_RT_HAS_GR_FLAG)
check_cxx_compiler_flag(/GS COMPILER_RT_HAS_GS_FLAG)
@@ -61,7 +68,7 @@ check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG)
check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL)
# Libraries.
-check_library_exists(c printf "" COMPILER_RT_HAS_LIBC)
+check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC)
check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL)
check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT)
check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
@@ -71,6 +78,7 @@ check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX)
# Linker flags.
if(ANDROID)
check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL)
+ check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG)
endif()
# Architectures.
@@ -120,8 +128,8 @@ macro(test_target_arch arch def)
endif()
if(${CAN_TARGET_${arch}})
list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
- elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}" AND
- COMPILER_RT_HAS_EXPLICIT_TEST_TARGET_TRIPLE)
+ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "${arch}" AND
+ COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE)
# Bail out if we cannot target the architecture we plan to test.
message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
endif()
@@ -168,12 +176,11 @@ endif()
# Generate the COMPILER_RT_SUPPORTED_ARCH list.
if(ANDROID)
- # Can't rely on LLVM_NATIVE_ARCH in cross-compilation.
- # Examine compiler output instead.
+ # Examine compiler output to determine target architecture.
detect_target_arch()
set(COMPILER_RT_OS_SUFFIX "-android")
-else()
- if("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
+elseif(NOT APPLE) # Supported archs for Apple platforms are generated later
+ if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "i[2-6]86|x86|amd64")
if(NOT MSVC)
test_target_arch(x86_64 "" "-m64")
# FIXME: We build runtimes for both i686 and i386, as "clang -m32" may
@@ -188,42 +195,38 @@ else()
test_target_arch(x86_64 "" "")
endif()
endif()
- elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC")
+ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc")
TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN)
if(HOST_IS_BIG_ENDIAN)
test_target_arch(powerpc64 "" "-m64")
else()
test_target_arch(powerpc64le "" "-m64")
endif()
- elseif("${LLVM_NATIVE_ARCH}" STREQUAL "Mips")
+ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
# Gcc doesn't accept -m32/-m64 so we do the next best thing and use
# -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match
# clang's default CPU's. In the 64-bit case, we must also specify the ABI
# since the default ABI differs between gcc and clang.
# FIXME: Ideally, we would build the N32 library too.
- if("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "mipsel|mips64el")
- # regex for mipsel, mips64el
- test_target_arch(mipsel "" "-mips32r2" "--target=mipsel-linux-gnu")
- test_target_arch(mips64el "" "-mips64r2" "-mabi=n64")
- else()
- test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu")
- test_target_arch(mips64 "" "-mips64r2" "-mabi=n64")
- 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(mipsel "" "-mips32r2" "--target=mipsel-linux-gnu")
+ test_target_arch(mips64el "" "-mips64r2" "--target=mips64el-linux-gnu" "-mabi=n64")
+ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips")
+ test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu")
+ test_target_arch(mips64 "" "-mips64r2" "--target=mips64-linux-gnu" "-mabi=n64")
+ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm")
+ test_target_arch(arm "" "-march=armv7-a" "-mfloat-abi=soft")
+ test_target_arch(armhf "" "-march=armv7-a" "-mfloat-abi=hard")
+ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch32")
test_target_arch(aarch32 "" "-march=armv8-a")
- elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch64")
+ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch64")
test_target_arch(aarch64 "" "-march=armv8-a")
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)
+ set(archs ${${out_var}})
foreach(arch ${ARGN})
list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch})
@@ -239,30 +242,264 @@ function(get_target_flags_for_arch arch out_var)
if(ARCH_INDEX EQUAL -1)
message(FATAL_ERROR "Unsupported architecture: ${arch}")
else()
- set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE)
+ if (NOT APPLE)
+ set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE)
+ else()
+ # This is only called in constructing cflags for tests executing on the
+ # host. This will need to all be cleaned up to support building tests
+ # for cross-targeted hardware (i.e. iOS).
+ set(${out_var} -arch ${arch} PARENT_SCOPE)
+ endif()
endif()
endfunction()
-# Architectures supported by compiler-rt libraries.
-filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
- x86_64 i386 i686 powerpc64 powerpc64le arm aarch64 mips mips64 mipsel mips64el)
-# LSan and UBSan 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(UBSAN_COMMON_SUPPORTED_ARCH
- ${SANITIZER_COMMON_SUPPORTED_ARCH})
-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 mips64 mips64el)
-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 mips64 mips64el)
-filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 i686 arm aarch64 mips
- mipsel mips64 mips64el powerpc64 powerpc64le)
-filter_available_targets(SAFESTACK_SUPPORTED_ARCH x86_64 i386 i686)
+set(ARM64 aarch64)
+set(ARM32 arm armhf)
+set(X86 i386 i686)
+set(X86_64 x86_64)
+set(MIPS32 mips mipsel)
+set(MIPS64 mips64 mips64el)
+set(PPC64 powerpc64 powerpc64le)
+
+if(APPLE)
+ set(ARM64 arm64)
+ set(ARM32 armv7 armv7s)
+ set(X86_64 x86_64 x86_64h)
+endif()
+
+set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
+ ${MIPS32} ${MIPS64})
+set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64}
+ ${ARM32} ${ARM64} ${MIPS32} ${MIPS64})
+set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
+ ${MIPS32} ${MIPS64} ${PPC64})
+set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
+set(ALL_LSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
+set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
+set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64}
+ ${MIPS32} ${MIPS64})
+set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64})
+set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
+ ${MIPS32} ${MIPS64} ${PPC64})
+set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
+set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64})
+
+if(APPLE)
+ include(CompilerRTDarwinUtils)
+
+ # On Darwin if /usr/include doesn't exist, the user probably has Xcode but not
+ # the command line tools. If this is the case, we need to find the OS X
+ # sysroot to pass to clang.
+ if(NOT EXISTS /usr/include)
+ execute_process(COMMAND xcodebuild -version -sdk macosx Path
+ OUTPUT_VARIABLE OSX_SYSROOT
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ set(OSX_SYSROOT_FLAG "-isysroot${OSX_SYSROOT}")
+ endif()
+
+ option(COMPILER_RT_ENABLE_IOS "Enable building for iOS - Experimental" Off)
+
+ find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx)
+ find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator)
+ find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos)
+
+ # Note: In order to target x86_64h on OS X the minimum deployment target must
+ # be 10.8 or higher.
+ set(SANITIZER_COMMON_SUPPORTED_OS osx)
+ set(BUILTIN_SUPPORTED_OS osx)
+ set(PROFILE_SUPPORTED_OS osx)
+ set(TSAN_SUPPORTED_OS osx)
+ if(NOT SANITIZER_MIN_OSX_VERSION)
+ string(REGEX MATCH "-mmacosx-version-min=([.0-9]+)"
+ MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}")
+ if(MACOSX_VERSION_MIN_FLAG)
+ set(SANITIZER_MIN_OSX_VERSION "${CMAKE_MATCH_1}")
+ elseif(CMAKE_OSX_DEPLOYMENT_TARGET)
+ set(SANITIZER_MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
+ else()
+ set(SANITIZER_MIN_OSX_VERSION 10.9)
+ endif()
+ if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7")
+ message(FATAL_ERROR "Too old OS X version: ${SANITIZER_MIN_OSX_VERSION}")
+ endif()
+ endif()
+
+ # We're setting the flag manually for each target OS
+ set(CMAKE_OSX_DEPLOYMENT_TARGET "")
+
+ set(DARWIN_COMMON_CFLAGS -stdlib=libc++)
+ set(DARWIN_COMMON_LINKFLAGS
+ -stdlib=libc++
+ -lc++
+ -lc++abi)
+
+ set(DARWIN_osx_CFLAGS
+ ${DARWIN_COMMON_CFLAGS}
+ -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
+ set(DARWIN_osx_LINKFLAGS
+ ${DARWIN_COMMON_LINKFLAGS}
+ -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
+ set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
+ set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
+ -mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
+
+ if(DARWIN_osx_SYSROOT)
+ list(APPEND DARWIN_osx_CFLAGS -isysroot ${DARWIN_osx_SYSROOT})
+ list(APPEND DARWIN_osx_LINKFLAGS -isysroot ${DARWIN_osx_SYSROOT})
+ endif()
+
+ # Figure out which arches to use for each OS
+ darwin_get_toolchain_supported_archs(toolchain_arches)
+ message(STATUS "Toolchain supported arches: ${toolchain_arches}")
+
+ if(NOT MACOSX_VERSION_MIN_FLAG)
+ darwin_test_archs(osx
+ DARWIN_osx_ARCHS
+ ${toolchain_arches})
+ message(STATUS "OSX supported arches: ${DARWIN_osx_ARCHS}")
+ foreach(arch ${DARWIN_osx_ARCHS})
+ list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
+ set(CAN_TARGET_${arch} 1)
+ endforeach()
+
+ # Need to build a 10.4 compatible libclang_rt
+ set(DARWIN_10.4_SYSROOT ${DARWIN_osx_SYSROOT})
+ set(DARWIN_10.4_BUILTIN_MIN_VER 10.4)
+ set(DARWIN_10.4_BUILTIN_MIN_VER_FLAG
+ -mmacosx-version-min=${DARWIN_10.4_BUILTIN_MIN_VER})
+ set(DARWIN_10.4_SKIP_CC_KEXT On)
+ darwin_test_archs(10.4
+ DARWIN_10.4_ARCHS
+ ${toolchain_arches})
+ message(STATUS "OSX 10.4 supported arches: ${DARWIN_10.4_ARCHS}")
+ if(DARWIN_10.4_ARCHS)
+ # don't include the Haswell slice in the 10.4 compatibility library
+ list(REMOVE_ITEM DARWIN_10.4_ARCHS x86_64h)
+ list(APPEND BUILTIN_SUPPORTED_OS 10.4)
+ endif()
+
+ if(DARWIN_iossim_SYSROOT)
+ set(DARWIN_iossim_CFLAGS
+ ${DARWIN_COMMON_CFLAGS}
+ -mios-simulator-version-min=7.0
+ -isysroot ${DARWIN_iossim_SYSROOT})
+ set(DARWIN_iossim_LINKFLAGS
+ ${DARWIN_COMMON_LINKFLAGS}
+ -mios-simulator-version-min=7.0
+ -isysroot ${DARWIN_iossim_SYSROOT})
+ set(DARWIN_iossim_BUILTIN_MIN_VER 6.0)
+ set(DARWIN_iossim_BUILTIN_MIN_VER_FLAG
+ -mios-simulator-version-min=${DARWIN_iossim_BUILTIN_MIN_VER})
+
+ set(DARWIN_iossim_SKIP_CC_KEXT On)
+ darwin_test_archs(iossim
+ DARWIN_iossim_ARCHS
+ ${toolchain_arches})
+ message(STATUS "iOS Simulator supported arches: ${DARWIN_iossim_ARCHS}")
+ if(DARWIN_iossim_ARCHS)
+ list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim)
+ list(APPEND BUILTIN_SUPPORTED_OS iossim)
+ list(APPEND PROFILE_SUPPORTED_OS iossim)
+ endif()
+ foreach(arch ${DARWIN_iossim_ARCHS})
+ list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
+ set(CAN_TARGET_${arch} 1)
+ endforeach()
+ endif()
+
+ if(DARWIN_ios_SYSROOT AND COMPILER_RT_ENABLE_IOS)
+ set(DARWIN_ios_CFLAGS
+ ${DARWIN_COMMON_CFLAGS}
+ -miphoneos-version-min=7.0
+ -isysroot ${DARWIN_ios_SYSROOT})
+ set(DARWIN_ios_LINKFLAGS
+ ${DARWIN_COMMON_LINKFLAGS}
+ -miphoneos-version-min=7.0
+ -isysroot ${DARWIN_ios_SYSROOT})
+ set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
+ set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
+ -miphoneos-version-min=${DARWIN_ios_BUILTIN_MIN_VER})
+
+ darwin_test_archs(ios
+ DARWIN_ios_ARCHS
+ ${toolchain_arches})
+ message(STATUS "iOS supported arches: ${DARWIN_ios_ARCHS}")
+ if(DARWIN_ios_ARCHS)
+ list(APPEND SANITIZER_COMMON_SUPPORTED_OS ios)
+ list(APPEND BUILTIN_SUPPORTED_OS ios)
+ list(APPEND PROFILE_SUPPORTED_OS ios)
+ endif()
+ foreach(arch ${DARWIN_ios_ARCHS})
+ list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
+ set(CAN_TARGET_${arch} 1)
+ endforeach()
+ endif()
+ endif()
+
+ # for list_union
+ include(CompilerRTUtils)
+
+ list_union(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH toolchain_arches)
+
+ list_union(SANITIZER_COMMON_SUPPORTED_ARCH
+ ALL_SANITIZER_COMMON_SUPPORTED_ARCH
+ COMPILER_RT_SUPPORTED_ARCH
+ )
+ set(LSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH})
+ set(UBSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH})
+ list_union(ASAN_SUPPORTED_ARCH
+ ALL_ASAN_SUPPORTED_ARCH
+ SANITIZER_COMMON_SUPPORTED_ARCH)
+ list_union(DFSAN_SUPPORTED_ARCH
+ ALL_DFSAN_SUPPORTED_ARCH
+ SANITIZER_COMMON_SUPPORTED_ARCH)
+ list_union(LSAN_SUPPORTED_ARCH
+ ALL_LSAN_SUPPORTED_ARCH
+ SANITIZER_COMMON_SUPPORTED_ARCH)
+ list_union(MSAN_SUPPORTED_ARCH
+ ALL_MSAN_SUPPORTED_ARCH
+ SANITIZER_COMMON_SUPPORTED_ARCH)
+ list_union(PROFILE_SUPPORTED_ARCH
+ ALL_PROFILE_SUPPORTED_ARCH
+ SANITIZER_COMMON_SUPPORTED_ARCH)
+ list_union(TSAN_SUPPORTED_ARCH
+ ALL_TSAN_SUPPORTED_ARCH
+ SANITIZER_COMMON_SUPPORTED_ARCH)
+ list_union(UBSAN_SUPPORTED_ARCH
+ ALL_UBSAN_SUPPORTED_ARCH
+ SANITIZER_COMMON_SUPPORTED_ARCH)
+ list_union(SAFESTACK_SUPPORTED_ARCH
+ ALL_SAFESTACK_SUPPORTED_ARCH
+ SANITIZER_COMMON_SUPPORTED_ARCH)
+ list_union(CFI_SUPPORTED_ARCH
+ ALL_CFI_SUPPORTED_ARCH
+ SANITIZER_COMMON_SUPPORTED_ARCH)
+else()
+ # Architectures supported by compiler-rt libraries.
+ filter_available_targets(BUILTIN_SUPPORTED_ARCH
+ ${ALL_BUILTIN_SUPPORTED_ARCH})
+ filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
+ ${ALL_SANITIZER_COMMON_SUPPORTED_ARCH})
+ # LSan and UBSan 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(UBSAN_COMMON_SUPPORTED_ARCH
+ ${SANITIZER_COMMON_SUPPORTED_ARCH})
+ filter_available_targets(ASAN_SUPPORTED_ARCH ${ALL_ASAN_SUPPORTED_ARCH})
+ filter_available_targets(DFSAN_SUPPORTED_ARCH ${ALL_DFSAN_SUPPORTED_ARCH})
+ filter_available_targets(LSAN_SUPPORTED_ARCH ${ALL_LSAN_SUPPORTED_ARCH})
+ filter_available_targets(MSAN_SUPPORTED_ARCH ${ALL_MSAN_SUPPORTED_ARCH})
+ filter_available_targets(PROFILE_SUPPORTED_ARCH ${ALL_PROFILE_SUPPORTED_ARCH})
+ filter_available_targets(TSAN_SUPPORTED_ARCH ${ALL_TSAN_SUPPORTED_ARCH})
+ filter_available_targets(UBSAN_SUPPORTED_ARCH ${ALL_UBSAN_SUPPORTED_ARCH})
+ filter_available_targets(SAFESTACK_SUPPORTED_ARCH
+ ${ALL_SAFESTACK_SUPPORTED_ARCH})
+ filter_available_targets(CFI_SUPPORTED_ARCH ${ALL_CFI_SUPPORTED_ARCH})
+endif()
+
+message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}")
if(ANDROID)
set(OS_NAME "Android")
@@ -329,7 +566,7 @@ else()
endif()
if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND
- OS_NAME MATCHES "Linux|FreeBSD")
+ OS_NAME MATCHES "Darwin|Linux|FreeBSD")
set(COMPILER_RT_HAS_TSAN TRUE)
else()
set(COMPILER_RT_HAS_TSAN FALSE)
@@ -342,17 +579,16 @@ else()
set(COMPILER_RT_HAS_UBSAN FALSE)
endif()
-# -msse3 flag is not valid for Mips therefore clang gives a warning
-# message with -msse3. But check_c_compiler_flags() checks only for
-# compiler error messages. Therefore COMPILER_RT_HAS_MSSE3_FLAG turns out to be
-# true on Mips, so we make it false here.
-if("${LLVM_NATIVE_ARCH}" STREQUAL "Mips")
- set(COMPILER_RT_HAS_MSSE3_FLAG FALSE)
-endif()
-
if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND
OS_NAME MATCHES "Darwin|Linux|FreeBSD")
set(COMPILER_RT_HAS_SAFESTACK TRUE)
else()
set(COMPILER_RT_HAS_SAFESTACK FALSE)
endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND CFI_SUPPORTED_ARCH AND
+ OS_NAME MATCHES "Linux")
+ set(COMPILER_RT_HAS_CFI TRUE)
+else()
+ set(COMPILER_RT_HAS_CFI FALSE)
+endif()