https://github.com/llvmbot updated https://github.com/llvm/llvm-project/pull/150764
>From 96e15ebab5ae593cd5c8d84ce9d787d81f4b756d Mon Sep 17 00:00:00 2001 From: David Truby <david.tr...@arm.com> Date: Sat, 26 Jul 2025 14:42:42 +0100 Subject: [PATCH] [flang-rt] Remove hard-coded dependency on compiler-rt path on Windows (#150244) This fixes an issue where if the build folder is no longer present flang cannot link anything on Windows because the path to compiler-rt in the binary is hard-coded. Flang already links compiler-rt on Windows so it isn't necessary for flang-rt to specify that it depends on compiler-rt at all, other than for the unit tests, so instead we can move that logic into the unit test compile lines. (cherry picked from commit c20a95a7ddd8219f3e587e335a0a8e3f4613fc47) --- flang-rt/cmake/modules/AddFlangRT.cmake | 21 --------------------- flang-rt/unittests/CMakeLists.txt | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake index e51590fdae3d3..58541609829c4 100644 --- a/flang-rt/cmake/modules/AddFlangRT.cmake +++ b/flang-rt/cmake/modules/AddFlangRT.cmake @@ -286,27 +286,6 @@ function (add_flangrt_library name) target_compile_options(${tgtname} PUBLIC -U_LIBCPP_ENABLE_ASSERTIONS) endif () - # Flang/Clang (including clang-cl) -compiled programs targeting the MSVC ABI - # should only depend on msvcrt/ucrt. LLVM still emits libgcc/compiler-rt - # functions in some cases like 128-bit integer math (__udivti3, __modti3, - # __fixsfti, __floattidf, ...) that msvc does not support. We are injecting a - # dependency to Compiler-RT's builtin library where these are implemented. - if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if (FLANG_RT_BUILTINS_LIBRARY) - target_compile_options(${tgtname} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:-Xclang>" "$<$<COMPILE_LANGUAGE:CXX,C>:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>") - endif () - endif () - if (MSVC AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang") - if (FLANG_RT_BUILTINS_LIBRARY) - target_compile_options(${tgtname} PRIVATE "$<$<COMPILE_LANGUAGE:Fortran>:-Xflang>" "$<$<COMPILE_LANGUAGE:Fortran>:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>") - else () - message(WARNING "Did not find libclang_rt.builtins.lib. - LLVM may emit builtins that are not implemented in msvcrt/ucrt and - instead falls back to builtins from Compiler-RT. Linking with ${tgtname} - may result in a linker error.") - endif () - endif () - # Non-GTest unittests depend on LLVMSupport if (ARG_LINK_TO_LLVM) if (LLVM_LINK_LLVM_DYLIB) diff --git a/flang-rt/unittests/CMakeLists.txt b/flang-rt/unittests/CMakeLists.txt index 5282196174134..831bc8a4c2906 100644 --- a/flang-rt/unittests/CMakeLists.txt +++ b/flang-rt/unittests/CMakeLists.txt @@ -60,6 +60,27 @@ function(add_flangrt_unittest_offload_properties target) endif() endfunction() +# flang-rt on Windows requires compiler-rt for some symbols. For binaries built +# with flang this dependency is added by the flang driver, but since the unit +# tests are built with clang we need to add the dependency manually. +function(add_flangrt_dependent_libs target) + if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if (FLANG_RT_BUILTINS_LIBRARY) + target_compile_options(${target} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:-Xclang>" "$<$<COMPILE_LANGUAGE:CXX,C>:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>") + endif () + endif () + if (MSVC AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang") + if (FLANG_RT_BUILTINS_LIBRARY) + target_compile_options(${target} PRIVATE "$<$<COMPILE_LANGUAGE:Fortran>:-Xflang>" "$<$<COMPILE_LANGUAGE:Fortran>:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>") + else () + message(WARNING "Did not find libclang_rt.builtins.lib. + LLVM may emit builtins that are not implemented in msvcrt/ucrt and + instead falls back to builtins from Compiler-RT. Linking with ${tgtname} + may result in a linker error.") + endif () + endif () +endfunction() + function(add_flangrt_unittest test_dirname) cmake_parse_arguments(ARG @@ -72,6 +93,7 @@ function(add_flangrt_unittest test_dirname) target_link_libraries(${test_dirname} PRIVATE ${ARG_LINK_LIBS}) add_flangrt_unittest_offload_properties(${test_dirname}) + add_flangrt_dependent_libs(${test_dirname}) # Required because LLVMSupport is compiled with this option. # FIXME: According to CMake documentation, this is the default. Why is it @@ -99,6 +121,7 @@ function(add_flangrt_nongtest_unittest test_name) set_target_properties(${test_name}${suffix} PROPERTIES FOLDER "Flang-RT/Tests/Unit") target_link_libraries(${test_name}${suffix} PRIVATE NonGTestTesting ${ARG_LINK_LIBS}) + add_flangrt_dependent_libs(${test_name}${suffix}) if(NOT ARG_SLOW_TEST) add_dependencies(FlangRTUnitTests ${test_name}${suffix}) _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits