diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -372,13 +372,33 @@ set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") endif() - if(APPLE) - # Ad-hoc sign the dylibs - add_custom_command(TARGET ${libname} - POST_BUILD - COMMAND codesign --sign - $ - WORKING_DIRECTORY ${COMPILER_RT_OUTPUT_LIBRARY_DIR} + if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*") + # Ad-hoc sign the dylibs when using Xcode versions older than 12. + # Xcode 12 shipped with ld64-609. + # FIXME: Remove whole conditional block once everything uses Xcode 12+. + set(LD_V_OUTPUT) + execute_process( + COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1" + RESULT_VARIABLE HAD_ERROR + OUTPUT_VARIABLE LD_V_OUTPUT ) + if (HAD_ERROR) + message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}") + endif() + set(NEED_EXPLICIT_ADHOC_CODESIGN 1) + if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*") + string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT}) + if (HOST_LINK_VERSION VERSION_GREATER_EQUAL 609) + set(NEED_EXPLICIT_ADHOC_CODESIGN 0) + endif() + endif() + if (NEED_EXPLICIT_ADHOC_CODESIGN) + add_custom_command(TARGET ${libname} + POST_BUILD + COMMAND codesign --sign - $ + WORKING_DIRECTORY ${COMPILER_RT_OUTPUT_LIBRARY_DIR} + ) + endif() endif() endif()