Index: compiler-rt/trunk/CMakeLists.txt =================================================================== --- compiler-rt/trunk/CMakeLists.txt +++ compiler-rt/trunk/CMakeLists.txt @@ -293,9 +293,9 @@ string(REGEX MATCH "-mmacosx-version-min=" MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}") - set(SANITIZER_COMMON_SUPPORTED_DARWIN_OS osx) + set(SANITIZER_COMMON_SUPPORTED_OS osx) if (IOSSIM_SDK_DIR AND NOT MACOSX_VERSION_MIN_FLAG) - list(APPEND SANITIZER_COMMON_SUPPORTED_DARWIN_OS iossim) + list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim) endif() set(SANITIZER_MIN_OSX_VERSION 10.7) Index: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake =================================================================== --- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake +++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake @@ -3,40 +3,47 @@ include(LLVMParseArguments) include(CompilerRTUtils) -# Tries to add "object library" target for a given architecture -# with name "." if architecture can be targeted. -# add_compiler_rt_object_library( -# SOURCES -# CFLAGS -# DEFS ) -macro(add_compiler_rt_object_library name arch) - if(CAN_TARGET_${arch}) - parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN}) - add_library(${name}.${arch} OBJECT ${LIB_SOURCES}) - set_target_compile_flags(${name}.${arch} - ${CMAKE_CXX_FLAGS} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) - set_property(TARGET ${name}.${arch} APPEND PROPERTY - COMPILE_DEFINITIONS ${LIB_DEFS}) +# Tries to add an "object library" target for a given list of OSs and/or +# architectures with name "." for non-Darwin platforms if +# architecture can be targeted, and "." for Darwin platforms. +# add_compiler_rt_object_libraries( +# OS +# ARCH +# SOURCES +# CFLAGS +# DEFS ) +function(add_compiler_rt_object_libraries name) + parse_arguments(LIB "OS;ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN}) + set(libnames) + if(APPLE) + foreach(os ${LIB_OS}) + set(libname "${name}.${os}") + set(libnames ${libnames} ${libname}) + set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS}) + endforeach() else() - message(FATAL_ERROR "Archtecture ${arch} can't be targeted") + foreach(arch ${LIB_ARCH}) + set(libname "${name}.${arch}") + 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") + return() + endif() + endforeach() endif() -endmacro() - -# Same as above, but adds universal osx library for either OSX or iOS simulator -# with name "." targeting multiple architectures. -# add_compiler_rt_darwin_object_library( ARCH -# SOURCES -# CFLAGS -# DEFS ) -macro(add_compiler_rt_darwin_object_library name os) - parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN}) - set(libname "${name}.${os}") - add_library(${libname} OBJECT ${LIB_SOURCES}) - set_target_compile_flags(${libname} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS}) - set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}") - set_property(TARGET ${libname} APPEND PROPERTY - COMPILE_DEFINITIONS ${LIB_DEFS}) -endmacro() + + foreach(libname ${libnames}) + add_library(${libname} OBJECT ${LIB_SOURCES}) + set_target_compile_flags(${libname} + ${CMAKE_CXX_FLAGS} ${extra_cflags_${libname}} ${LIB_CFLAGS}) + set_property(TARGET ${libname} APPEND PROPERTY + COMPILE_DEFINITIONS ${LIB_DEFS}) + if(APPLE) + set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}") + 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. Index: compiler-rt/trunk/lib/asan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/asan/CMakeLists.txt +++ compiler-rt/trunk/lib/asan/CMakeLists.txt @@ -75,41 +75,43 @@ # Compile ASan sources into an object library. if(APPLE) - foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS}) - add_compiler_rt_darwin_object_library(RTAsan ${os} - ARCH ${ASAN_SUPPORTED_ARCH} - SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES} - CFLAGS ${ASAN_DYNAMIC_CFLAGS} - DEFS ${ASAN_DYNAMIC_DEFINITIONS}) - endforeach() + add_compiler_rt_object_libraries(RTAsan + OS ${SANITIZER_COMMON_SUPPORTED_OS} + ARCH ${ASAN_SUPPORTED_ARCH} + SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES} + CFLAGS ${ASAN_DYNAMIC_CFLAGS} + DEFS ${ASAN_DYNAMIC_DEFINITIONS}) else() - foreach(arch ${ASAN_SUPPORTED_ARCH}) - add_compiler_rt_object_library(RTAsan ${arch} - SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_CFLAGS} - DEFS ${ASAN_COMMON_DEFINITIONS}) - add_compiler_rt_object_library(RTAsan_cxx ${arch} - SOURCES ${ASAN_CXX_SOURCES} CFLAGS ${ASAN_CFLAGS} - DEFS ${ASAN_COMMON_DEFINITIONS}) - add_compiler_rt_object_library(RTAsan_preinit ${arch} - SOURCES ${ASAN_PREINIT_SOURCES} CFLAGS ${ASAN_CFLAGS} - DEFS ${ASAN_COMMON_DEFINITIONS}) - add_compiler_rt_object_library(RTAsan_dynamic ${arch} - SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES} - CFLAGS ${ASAN_DYNAMIC_CFLAGS} - DEFS ${ASAN_DYNAMIC_DEFINITIONS}) - - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cc "") - add_compiler_rt_object_library(RTAsan_dynamic_version_script_dummy ${arch} - SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cc - CFLAGS ${ASAN_DYNAMIC_CFLAGS} - DEFS ${ASAN_DYNAMIC_DEFINITIONS}) - endforeach() + add_compiler_rt_object_libraries(RTAsan + ARCH ${ASAN_SUPPORTED_ARCH} + SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_CFLAGS} + DEFS ${ASAN_COMMON_DEFINITIONS}) + add_compiler_rt_object_libraries(RTAsan_cxx + ARCH ${ASAN_SUPPORTED_ARCH} + SOURCES ${ASAN_CXX_SOURCES} CFLAGS ${ASAN_CFLAGS} + DEFS ${ASAN_COMMON_DEFINITIONS}) + add_compiler_rt_object_libraries(RTAsan_preinit + ARCH ${ASAN_SUPPORTED_ARCH} + SOURCES ${ASAN_PREINIT_SOURCES} CFLAGS ${ASAN_CFLAGS} + DEFS ${ASAN_COMMON_DEFINITIONS}) + add_compiler_rt_object_libraries(RTAsan_dynamic + ARCH ${ASAN_SUPPORTED_ARCH} + SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES} + CFLAGS ${ASAN_DYNAMIC_CFLAGS} + DEFS ${ASAN_DYNAMIC_DEFINITIONS}) + + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cc "") + add_compiler_rt_object_libraries(RTAsan_dynamic_version_script_dummy + ARCH ${ASAN_SUPPORTED_ARCH} + SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cc + CFLAGS ${ASAN_DYNAMIC_CFLAGS} + DEFS ${ASAN_DYNAMIC_DEFINITIONS}) endif() # Build ASan runtimes shipped with Clang. add_custom_target(asan) if(APPLE) - foreach (os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS}) + foreach (os ${SANITIZER_COMMON_SUPPORTED_OS}) add_compiler_rt_darwin_dynamic_runtime(clang_rt.asan_${os}_dynamic ${os} ARCH ${ASAN_SUPPORTED_ARCH} SOURCES $ Index: compiler-rt/trunk/lib/interception/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/interception/CMakeLists.txt +++ compiler-rt/trunk/lib/interception/CMakeLists.txt @@ -12,18 +12,8 @@ set(INTERCEPTION_CFLAGS ${SANITIZER_COMMON_CFLAGS}) append_no_rtti_flag(INTERCEPTION_CFLAGS) -if(APPLE) - # Build universal binary on APPLE. - foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS}) - add_compiler_rt_darwin_object_library(RTInterception ${os} - ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH} - SOURCES ${INTERCEPTION_SOURCES} - CFLAGS ${INTERCEPTION_CFLAGS}) - endforeach() -else() - # Otherwise, build separate libraries for each target. - foreach(arch ${SANITIZER_COMMON_SUPPORTED_ARCH}) - add_compiler_rt_object_library(RTInterception ${arch} - SOURCES ${INTERCEPTION_SOURCES} CFLAGS ${INTERCEPTION_CFLAGS}) - endforeach() -endif() +add_compiler_rt_object_libraries(RTInterception + OS ${SANITIZER_COMMON_SUPPORTED_OS} + ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH} + SOURCES ${INTERCEPTION_SOURCES} + CFLAGS ${INTERCEPTION_CFLAGS}) Index: compiler-rt/trunk/lib/lsan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/lsan/CMakeLists.txt +++ compiler-rt/trunk/lib/lsan/CMakeLists.txt @@ -18,20 +18,13 @@ add_custom_target(lsan) -if(APPLE) - foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS}) - add_compiler_rt_darwin_object_library(RTLSanCommon ${os} - ARCH ${LSAN_COMMON_SUPPORTED_ARCH} - SOURCES ${LSAN_COMMON_SOURCES} - CFLAGS ${LSAN_CFLAGS}) - endforeach() -else() - foreach(arch ${LSAN_COMMON_SUPPORTED_ARCH}) - add_compiler_rt_object_library(RTLSanCommon ${arch} - SOURCES ${LSAN_COMMON_SOURCES} - CFLAGS ${LSAN_CFLAGS}) - endforeach() +add_compiler_rt_object_libraries(RTLSanCommon + OS ${SANITIZER_COMMON_SUPPORTED_OS} + ARCH ${LSAN_COMMON_SUPPORTED_ARCH} + SOURCES ${LSAN_COMMON_SOURCES} + CFLAGS ${LSAN_CFLAGS}) +if(NOT APPLE) foreach(arch ${LSAN_SUPPORTED_ARCH}) add_compiler_rt_runtime(clang_rt.lsan-${arch} ${arch} STATIC SOURCES ${LSAN_SOURCES} Index: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt +++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt @@ -128,23 +128,28 @@ set(SANITIZER_RUNTIME_LIBRARIES) if(APPLE) # Build universal binary on APPLE. - foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS}) - add_compiler_rt_darwin_object_library(RTSanitizerCommon ${os} - ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH} - SOURCES ${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES} - CFLAGS ${SANITIZER_CFLAGS} - DEFS ${SANITIZER_COMMON_DEFINITIONS}) + + add_compiler_rt_object_libraries(RTSanitizerCommon + OS ${SANITIZER_COMMON_SUPPORTED_OS} + ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH} + SOURCES ${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES} + CFLAGS ${SANITIZER_CFLAGS} + DEFS ${SANITIZER_COMMON_DEFINITIONS}) + foreach(os ${SANITIZER_COMMON_SUPPORTED_OS}) list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.${os}) endforeach() else() # Otherwise, build separate libraries for each target. + + add_compiler_rt_object_libraries(RTSanitizerCommon + ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH} + SOURCES ${SANITIZER_SOURCES} CFLAGS ${SANITIZER_CFLAGS} + DEFS ${SANITIZER_COMMON_DEFINITIONS}) + add_compiler_rt_object_libraries(RTSanitizerCommonLibc + ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH} + SOURCES ${SANITIZER_LIBCDEP_SOURCES} CFLAGS ${SANITIZER_CFLAGS} + DEFS ${SANITIZER_COMMON_DEFINITIONS}) foreach(arch ${SANITIZER_COMMON_SUPPORTED_ARCH}) - add_compiler_rt_object_library(RTSanitizerCommon ${arch} - SOURCES ${SANITIZER_SOURCES} CFLAGS ${SANITIZER_CFLAGS} - DEFS ${SANITIZER_COMMON_DEFINITIONS}) - add_compiler_rt_object_library(RTSanitizerCommonLibc ${arch} - SOURCES ${SANITIZER_LIBCDEP_SOURCES} CFLAGS ${SANITIZER_CFLAGS} - DEFS ${SANITIZER_COMMON_DEFINITIONS}) list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.${arch} RTSanitizerCommonLibc.${arch}) endforeach() Index: compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt +++ compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt @@ -27,7 +27,8 @@ CFLAGS ${DD_CFLAGS}) add_dependencies(dd clang_rt.dd-${arch}) - add_compiler_rt_object_library(RTDD ${arch} + add_compiler_rt_object_libraries(RTDD + ARCH ${arch} SOURCES ${DD_SOURCES} CFLAGS ${DD_CFLAGS}) add_compiler_rt_runtime(clang_rt.dyndd-${arch} ${arch} SHARED Index: compiler-rt/trunk/lib/ubsan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/ubsan/CMakeLists.txt +++ compiler-rt/trunk/lib/ubsan/CMakeLists.txt @@ -28,20 +28,21 @@ add_custom_target(ubsan) if(APPLE) - foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS}) - # Common parts of UBSan runtime. - add_compiler_rt_darwin_object_library(RTUbsan ${os} - ARCH ${UBSAN_COMMON_SUPPORTED_ARCH} - SOURCES ${UBSAN_SOURCES} ${UBSAN_CXX_SOURCES} - CFLAGS ${UBSAN_CXXFLAGS}) - - if(COMPILER_RT_HAS_UBSAN) - # Initializer of standalone UBSan runtime. - add_compiler_rt_darwin_object_library(RTUbsan_standalone ${os} - ARCH ${UBSAN_SUPPORTED_ARCH} - SOURCES ${UBSAN_STANDALONE_SOURCES} - CFLAGS ${UBSAN_STANDALONE_CFLAGS}) + # Common parts of UBSan runtime. + add_compiler_rt_object_libraries(RTUbsan + OS ${SANITIZER_COMMON_SUPPORTED_OS} + ARCH ${UBSAN_COMMON_SUPPORTED_ARCH} + SOURCES ${UBSAN_SOURCES} ${UBSAN_CXX_SOURCES} + CFLAGS ${UBSAN_CXXFLAGS}) + if(COMPILER_RT_HAS_UBSAN) + # Initializer of standalone UBSan runtime. + add_compiler_rt_object_libraries(RTUbsan_standalone + OS ${SANITIZER_COMMON_SUPPORTED_OS} + ARCH ${UBSAN_SUPPORTED_ARCH} + SOURCES ${UBSAN_STANDALONE_SOURCES} + CFLAGS ${UBSAN_STANDALONE_CFLAGS}) + foreach(os ${SANITIZER_COMMON_SUPPORTED_OS}) add_compiler_rt_darwin_dynamic_runtime(clang_rt.ubsan_${os}_dynamic ${os} ARCH ${UBSAN_SUPPORTED_ARCH} SOURCES $ @@ -49,24 +50,26 @@ $) add_dependencies(ubsan clang_rt.ubsan_${os}_dynamic) - endif() - endforeach() + endforeach() + endif() + else() # Common parts of UBSan runtime. - foreach(arch ${UBSAN_COMMON_SUPPORTED_ARCH}) - add_compiler_rt_object_library(RTUbsan ${arch} - SOURCES ${UBSAN_SOURCES} CFLAGS ${UBSAN_CFLAGS}) - # C++-specific parts of UBSan runtime. Requires a C++ ABI library. - add_compiler_rt_object_library(RTUbsan_cxx ${arch} - SOURCES ${UBSAN_CXX_SOURCES} CFLAGS ${UBSAN_CXXFLAGS}) - endforeach() + add_compiler_rt_object_libraries(RTUbsan + ARCH ${UBSAN_COMMON_SUPPORTED_ARCH} + SOURCES ${UBSAN_SOURCES} CFLAGS ${UBSAN_CFLAGS}) + # C++-specific parts of UBSan runtime. Requires a C++ ABI library. + add_compiler_rt_object_libraries(RTUbsan_cxx + ARCH ${UBSAN_COMMON_SUPPORTED_ARCH} + SOURCES ${UBSAN_CXX_SOURCES} CFLAGS ${UBSAN_CXXFLAGS}) if(COMPILER_RT_HAS_UBSAN) + # Initializer of standalone UBSan runtime. + add_compiler_rt_object_libraries(RTUbsan_standalone + ARCH ${UBSAN_SUPPORTED_ARCH} + SOURCES ${UBSAN_STANDALONE_SOURCES} CFLAGS ${UBSAN_STANDALONE_CFLAGS}) + foreach(arch ${UBSAN_SUPPORTED_ARCH}) - # Initializer of standalone UBSan runtime. - add_compiler_rt_object_library(RTUbsan_standalone ${arch} - SOURCES ${UBSAN_STANDALONE_SOURCES} CFLAGS ${UBSAN_STANDALONE_CFLAGS}) - # Standalone UBSan runtimes. add_compiler_rt_runtime(clang_rt.ubsan_standalone-${arch} ${arch} STATIC SOURCES $