Index: cmake/Modules/AddCompilerRT.cmake =================================================================== --- cmake/Modules/AddCompilerRT.cmake +++ cmake/Modules/AddCompilerRT.cmake @@ -46,83 +46,110 @@ 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( {STATIC,SHARED} +# 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( +# {STATIC|SHARED} +# ARCHS +# OS # SOURCES # CFLAGS +# LINKFLAGS # DEFS -# OUTPUT_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}) +# LIBS +# OUTPUT_NAME +# PARENT_TARGET ) +function(add_compiler_rt_runtime name) + cmake_parse_arguments(LIB "SHARED;STATIC" "OUTPUT_NAME;PARENT_TARGET" "ARCHS;SOURCES;CFLAGS;LINKFLAGS;DEFS;OS;LIBS" ${ARGN}) + set(libnames) + if(APPLE) + foreach(os ${LIB_OS}) + if(LIB_STATIC) + set(libname "${name}_${os}") + 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(extra_linkflags_${libname} ${DARWIN_${os}_LINKFLAGS} ${LIB_LINKFLAGS}) + set(type_${libname} STATIC) + endif() + endif() + if(LIB_SHARED) + set(libname "${name}_${os}_dynamic") + 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(extra_linkflags_${libname} ${DARWIN_${os}_LINKFLAGS} ${LIB_LINKFLAGS}) + set(type_${libname} SHARED) + endif() + endif() + endforeach() + else() + foreach(arch ${LIB_ARCHS}) + if(LIB_STATIC) + set(libname "${name}-${arch}") + set(libnames ${libnames} ${libname}) + set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) + set(extra_linkflags_${libname} ${TARGET_${arch}_LINKFLAGS} ${LIB_LINKFLAGS}) + set(type_${libname} STATIC) + if(NOT CAN_TARGET_${arch}) + message(FATAL_ERROR "Architecture ${arch} can't be targeted") + return() + endif() + endif() + if(LIB_SHARED) + set(libname "${name}-dynamic-${arch}") + set(libnames ${libnames} ${libname}) + set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) + set(extra_linkflags_${libname} ${TARGET_${arch}_LINKFLAGS} ${LIB_LINKFLAGS}) + set(type_${libname} SHARED) + if(NOT CAN_TARGET_${arch}) + message(FATAL_ERROR "Architecture ${arch} can't be targeted") + return() + endif() + endif() + endforeach() + endif() + + if(${LIB_PARENT_TARGET}) + set(COMONENT_OPTION COMPONENT ${LIB_PARENT_TARGET}) + endif() + + foreach(libname ${libnames}) + add_library(${libname} ${type_${libname}} ${LIB_SOURCES}) + 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}) if ("${LIB_OUTPUT_NAME}" STREQUAL "") - set_target_properties(${name} PROPERTIES - OUTPUT_NAME ${name}${COMPILER_RT_OS_SUFFIX}) + set_target_properties(${libname} PROPERTIES + OUTPUT_NAME ${libname}${COMPILER_RT_OS_SUFFIX}) else() - set_target_properties(${name} PROPERTIES + set_target_properties(${libname} PROPERTIES OUTPUT_NAME ${LIB_OUTPUT_NAME}) endif() - # Add installation command. - install(TARGETS ${name} + if(LIB_LIBS) + target_link_libraries(${libname} ${LIB_LIBS}) + endif() + install(TARGETS ${libname} ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} + ${COMONENT_OPTION} LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} - RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) - else() - message(FATAL_ERROR "Architecture ${arch} can't be targeted") - endif() -endmacro() - -# Adds runtime library for darwin platforms, which supports multiple -# architectures. -# add_compiler_rt_darwin_runtime( -# STATIC|SHARED -# ARCHS -# SOURCES -# CFLAGS -# DEFS -# LINKFLAGS ) -function(add_compiler_rt_darwin_runtime name os) - cmake_parse_arguments(LIB "SHARED;STATIC" "" "ARCHS;SOURCES;CFLAGS;DEFS;LINKFLAGS" ${ARGN}) - list_union(filtered_arches DARWIN_${os}_ARCHS LIB_ARCHS) - # if there are no supported architectures, don't create the library - if(filtered_arches) - if(LIB_SHARED) - add_library(${name} SHARED ${LIB_SOURCES}) - set_target_properties(${name} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) - install(TARGETS ${name} - LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) - elseif(LIB_STATIC) - add_library(${name} STATIC ${LIB_SOURCES}) - set_target_properties(${name} PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) - install(TARGETS ${name} - ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) - else() - message(FATAL_ERROR "Must specified SHARED|STATIC to add_compiler_rt_darwin_runtime") + ${COMONENT_OPTION} + RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} + ${COMONENT_OPTION}) + if(APPLE) + set_target_properties(${libname} PROPERTIES + OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}") endif() - - 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 "${filtered_arches}") + endforeach() + if(${LIB_PARENT_TARGET}) + add_dependencies(${LIB_PARENT_TARGET} ${libnames}) endif() endfunction() Index: lib/asan/CMakeLists.txt =================================================================== --- lib/asan/CMakeLists.txt +++ lib/asan/CMakeLists.txt @@ -111,8 +111,9 @@ add_custom_target(asan) if(APPLE) foreach (os ${SANITIZER_COMMON_SUPPORTED_OS}) - add_compiler_rt_darwin_runtime(clang_rt.asan_${os}_dynamic ${os} + add_compiler_rt_runtime(clang_rt.asan SHARED + OS ${os} ARCHS ${ASAN_SUPPORTED_ARCH} SOURCES $ $ @@ -120,8 +121,8 @@ $ $ CFLAGS ${ASAN_DYNAMIC_CFLAGS} - DEFS ${ASAN_DYNAMIC_DEFINITIONS}) - add_dependencies(asan clang_rt.asan_${os}_dynamic) + DEFS ${ASAN_DYNAMIC_DEFINITIONS} + PARENT_TARGET asan) endforeach() else() # Build separate libraries for each target. @@ -133,26 +134,32 @@ $ $) - add_compiler_rt_runtime(clang_rt.asan-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.asan + STATIC + ARCHS ${arch} SOURCES $ $ ${ASAN_COMMON_RUNTIME_OBJECTS} CFLAGS ${ASAN_CFLAGS} - DEFS ${ASAN_COMMON_DEFINITIONS}) - add_dependencies(asan clang_rt.asan-${arch}) + DEFS ${ASAN_COMMON_DEFINITIONS} + PARENT_TARGET asan) - add_compiler_rt_runtime(clang_rt.asan_cxx-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.asan_cxx + STATIC + ARCHS ${arch} SOURCES $ $ CFLAGS ${ASAN_CFLAGS} - DEFS ${ASAN_COMMON_DEFINITIONS}) - add_dependencies(asan clang_rt.asan_cxx-${arch}) + DEFS ${ASAN_COMMON_DEFINITIONS} + PARENT_TARGET asan) - add_compiler_rt_runtime(clang_rt.asan-preinit-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.asan-preinit + STATIC + ARCHS ${arch} SOURCES $ CFLAGS ${ASAN_CFLAGS} - DEFS ${ASAN_COMMON_DEFINITIONS}) - add_dependencies(asan clang_rt.asan-preinit-${arch}) + DEFS ${ASAN_COMMON_DEFINITIONS} + PARENT_TARGET asan) if (UNIX AND NOT ${arch} MATCHES "i386|i686") add_sanitizer_rt_version_list(clang_rt.asan-dynamic-${arch} @@ -173,7 +180,9 @@ else() set(SHARED_ASAN_NAME clang_rt.asan-${arch}${COMPILER_RT_OS_SUFFIX}) endif() - add_compiler_rt_runtime(clang_rt.asan-dynamic-${arch} ${arch} SHARED + add_compiler_rt_runtime(clang_rt.asan + SHARED + ARCHS ${arch} OUTPUT_NAME ${SHARED_ASAN_NAME} SOURCES $ # The only purpose of RTAsan_dynamic_version_script_dummy is to carry @@ -186,9 +195,9 @@ CFLAGS ${ASAN_DYNAMIC_CFLAGS} LINKFLAGS ${ASAN_DYNAMIC_LINK_FLAGS} ${VERSION_SCRIPT_FLAG} - DEFS ${ASAN_DYNAMIC_DEFINITIONS}) + DEFS ${ASAN_DYNAMIC_DEFINITIONS} + PARENT_TARGET asan) target_link_libraries(clang_rt.asan-dynamic-${arch} ${ASAN_DYNAMIC_LIBS}) - add_dependencies(asan clang_rt.asan-dynamic-${arch}) if (UNIX AND NOT ${arch} MATCHES "i386|i686") add_sanitizer_rt_symbols(clang_rt.asan_cxx-${arch}) @@ -198,18 +207,21 @@ endif() if (WIN32) - add_compiler_rt_runtime(clang_rt.asan_dll_thunk-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.asan_dll_thunk + STATIC + ARCHS ${arch} SOURCES asan_win_dll_thunk.cc $ CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK - DEFS ${ASAN_COMMON_DEFINITIONS}) - add_dependencies(asan clang_rt.asan_dll_thunk-${arch}) - add_compiler_rt_runtime(clang_rt.asan_dynamic_runtime_thunk-${arch} ${arch} + DEFS ${ASAN_COMMON_DEFINITIONS} + PARENT_TARGET asan) + add_compiler_rt_runtime(clang_rt.asan_dynamic_runtime_thunk STATIC + ARCHS ${arch} SOURCES asan_win_dynamic_runtime_thunk.cc CFLAGS ${ASAN_CFLAGS} -DASAN_DYNAMIC_RUNTIME_THUNK -Zl - DEFS ${ASAN_COMMON_DEFINITIONS}) - add_dependencies(asan clang_rt.asan_dynamic_runtime_thunk-${arch}) + DEFS ${ASAN_COMMON_DEFINITIONS} + PARENT_TARGET asan) endif() endforeach() endif() Index: lib/builtins/CMakeLists.txt =================================================================== --- lib/builtins/CMakeLists.txt +++ lib/builtins/CMakeLists.txt @@ -297,6 +297,10 @@ add_custom_target(builtins) +if(APPLE) + set(OS_OPTION OS osx) +endif() + if (NOT WIN32 OR MINGW) foreach (arch x86_64 i386 i686 arm aarch64) if (CAN_TARGET_${arch}) @@ -311,10 +315,13 @@ endif () endforeach () - add_compiler_rt_runtime(clang_rt.builtins-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.builtins + STATIC + ARCH ${arch} + ${OS_OPTION} SOURCES ${${arch}_SOURCES} - CFLAGS "-std=c99") - add_dependencies(builtins clang_rt.builtins-${arch}) + CFLAGS "-std=c99" + PARENT_TARGET builtins) endif () endforeach () endif () Index: lib/dfsan/CMakeLists.txt =================================================================== --- lib/dfsan/CMakeLists.txt +++ lib/dfsan/CMakeLists.txt @@ -15,7 +15,9 @@ foreach(arch ${DFSAN_SUPPORTED_ARCH}) set(DFSAN_CFLAGS ${DFSAN_COMMON_CFLAGS}) append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE DFSAN_CFLAGS) - add_compiler_rt_runtime(clang_rt.dfsan-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.dfsan + STATIC + ARCHS ${arch} SOURCES ${DFSAN_RTL_SOURCES} $ $ Index: lib/lsan/CMakeLists.txt =================================================================== --- lib/lsan/CMakeLists.txt +++ lib/lsan/CMakeLists.txt @@ -26,7 +26,9 @@ if(COMPILER_RT_HAS_LSAN) foreach(arch ${LSAN_SUPPORTED_ARCH}) - add_compiler_rt_runtime(clang_rt.lsan-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.lsan + STATIC + ARCHS ${arch} SOURCES ${LSAN_SOURCES} $ $ Index: lib/msan/CMakeLists.txt =================================================================== --- lib/msan/CMakeLists.txt +++ lib/msan/CMakeLists.txt @@ -27,14 +27,18 @@ # Static runtime library. add_custom_target(msan) foreach(arch ${MSAN_SUPPORTED_ARCH}) - add_compiler_rt_runtime(clang_rt.msan-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.msan + STATIC + ARCHS ${arch} SOURCES ${MSAN_RTL_SOURCES} $ $ $ $ CFLAGS ${MSAN_RTL_CFLAGS}) - add_compiler_rt_runtime(clang_rt.msan_cxx-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.msan_cxx + STATIC + ARCHS ${arch} SOURCES ${MSAN_RTL_CXX_SOURCES} $ CFLAGS ${MSAN_RTL_CFLAGS}) Index: lib/profile/CMakeLists.txt =================================================================== --- lib/profile/CMakeLists.txt +++ lib/profile/CMakeLists.txt @@ -12,15 +12,18 @@ if(APPLE) foreach (os osx) - add_compiler_rt_darwin_runtime(clang_rt.profile_${os} ${os} + add_compiler_rt_runtime(clang_rt.profile STATIC + OS ${os} ARCHS ${PROFILE_SUPPORTED_ARCH} SOURCES ${PROFILE_SOURCES}) add_dependencies(profile clang_rt.profile_${os}) endforeach() else() foreach(arch ${PROFILE_SUPPORTED_ARCH}) - add_compiler_rt_runtime(clang_rt.profile-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.profile + STATIC + ARCHS ${arch} CFLAGS -fPIC SOURCES ${PROFILE_SOURCES}) add_dependencies(profile clang_rt.profile-${arch}) Index: lib/safestack/CMakeLists.txt =================================================================== --- lib/safestack/CMakeLists.txt +++ lib/safestack/CMakeLists.txt @@ -9,8 +9,9 @@ if(APPLE) # Build universal binary on APPLE. foreach (os osx) - add_compiler_rt_darwin_runtime(clang_rt.safestack_${os} ${os} + add_compiler_rt_runtime(clang_rt.safestack STATIC + OS ${os} ARCHS ${SAFESTACK_SUPPORTED_ARCH} SOURCES ${SAFESTACK_SOURCES} $ @@ -21,7 +22,9 @@ else() # Otherwise, build separate libraries for each target. foreach(arch ${SAFESTACK_SUPPORTED_ARCH}) - add_compiler_rt_runtime(clang_rt.safestack-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.safestack + STATIC + ARCHS ${arch} SOURCES ${SAFESTACK_SOURCES} $ $ Index: lib/tsan/CMakeLists.txt =================================================================== --- lib/tsan/CMakeLists.txt +++ lib/tsan/CMakeLists.txt @@ -101,14 +101,18 @@ else() set(TSAN_ASM_SOURCES) endif() - add_compiler_rt_runtime(clang_rt.tsan-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.tsan + STATIC + ARCHS ${arch} SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES} $ $ $ $ CFLAGS ${TSAN_RTL_CFLAGS}) - add_compiler_rt_runtime(clang_rt.tsan_cxx-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.tsan_cxx + STATIC + ARCHS ${arch} SOURCES ${TSAN_CXX_SOURCES} $ CFLAGS ${TSAN_RTL_CFLAGS}) Index: lib/tsan/dd/CMakeLists.txt =================================================================== --- lib/tsan/dd/CMakeLists.txt +++ lib/tsan/dd/CMakeLists.txt @@ -19,25 +19,29 @@ # Deadlock detector is currently supported on 64-bit Linux only. if(CAN_TARGET_x86_64 AND UNIX AND NOT APPLE AND NOT ANDROID) set(arch "x86_64") - add_compiler_rt_runtime(clang_rt.dd-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.dd + STATIC + ARCHS ${arch} SOURCES ${DD_SOURCES} $ $ $ - CFLAGS ${DD_CFLAGS}) - add_dependencies(dd clang_rt.dd-${arch}) + CFLAGS ${DD_CFLAGS} + PARENT_TARGET dd) add_compiler_rt_object_libraries(RTDD ARCHS ${arch} SOURCES ${DD_SOURCES} CFLAGS ${DD_CFLAGS}) - add_compiler_rt_runtime(clang_rt.dyndd-${arch} ${arch} SHARED + add_compiler_rt_runtime(clang_rt.dyndd + SHARED + ARCHS ${arch} SOURCES $ $ $ - $) - target_link_libraries(clang_rt.dyndd-${arch} ${DD_LINKLIBS}) - add_dependencies(dd clang_rt.dyndd-${arch}) + $ + LIBS ${DD_LINKLIBS} + PARENT_TARGET dd) endif() add_dependencies(compiler-rt dd) Index: lib/ubsan/CMakeLists.txt =================================================================== --- lib/ubsan/CMakeLists.txt +++ lib/ubsan/CMakeLists.txt @@ -50,14 +50,15 @@ SOURCES ${UBSAN_STANDALONE_SOURCES} CFLAGS ${UBSAN_STANDALONE_CFLAGS}) foreach(os ${SANITIZER_COMMON_SUPPORTED_OS}) - add_compiler_rt_darwin_runtime(clang_rt.ubsan_${os}_dynamic ${os} + add_compiler_rt_darwin_runtime(clang_rt.ubsan SHARED + OS ${os} ARCHS ${UBSAN_SUPPORTED_ARCH} SOURCES $ $ - $) - - add_dependencies(ubsan clang_rt.ubsan_${os}_dynamic) + $ + CREATED_LIBS UBSAN_LIBS + PARENT_TARGET ubsan) endforeach() endif() @@ -79,19 +80,22 @@ foreach(arch ${UBSAN_SUPPORTED_ARCH}) # Standalone UBSan runtimes. - add_compiler_rt_runtime(clang_rt.ubsan_standalone-${arch} ${arch} STATIC + add_compiler_rt_runtime(clang_rt.ubsan_standalone + STATIC + ARCHS ${arch} SOURCES $ $ $ $ - CFLAGS ${UBSAN_CFLAGS}) - add_compiler_rt_runtime(clang_rt.ubsan_standalone_cxx-${arch} ${arch} STATIC + CFLAGS ${UBSAN_CFLAGS} + PARENT_TARGET ubsan) + add_compiler_rt_runtime(clang_rt.ubsan_standalone_cxx + STATIC + ARCHS ${arch} SOURCES $ - CFLAGS ${UBSAN_CXXFLAGS}) + CFLAGS ${UBSAN_CXXFLAGS} + PARENT_TARGET ubsan) - add_dependencies(ubsan - clang_rt.ubsan_standalone-${arch} - clang_rt.ubsan_standalone_cxx-${arch}) if (UNIX AND NOT ${arch} MATCHES "i386|i686") add_sanitizer_rt_symbols(clang_rt.ubsan_standalone-${arch} ubsan.syms.extra) add_sanitizer_rt_symbols(clang_rt.ubsan_standalone_cxx-${arch} ubsan.syms.extra)