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 @@ -482,7 +482,13 @@ # trump. With MSVC we can't do that because CMake is set up to run link.exe # when linking, not the compiler. Here, we hack it to use the compiler # because we want to use -fsanitize flags. - if(NOT MSVC) + + # Only add CMAKE_EXE_LINKER_FLAGS when in a standalone bulid. + # Or else CMAKE_EXE_LINKER_FLAGS contains flags for build compiler of Clang/llvm. + # This might not be the same as what the COMPILER_RT_TEST_COMPILER supports. + # eg: the build compiler use lld linker and we build clang with default ld linker + # then to be tested clang will complain about lld options like --color-diagnostics. + if(NOT MSVC AND COMPILER_RT_STANDALONE_BUILD) set(TEST_LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_LINK_FLAGS}") separate_arguments(TEST_LINK_FLAGS) endif()