From 3f5f2b2d4903c3f0fdbcc31be6c65d2d094d67ff Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 14 Mar 2025 15:32:00 +0100 Subject: [PATCH 1/4] Linker: Honor CMAKE__LINK_LIBRARY_USING_FEATURE_SUPPORTED when FALSE It is documented to override `CMAKE_LINK_LIBRARY_USING_FEATURE_SUPPORTED`. --- Source/cmComputeLinkDepends.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index f3057b47b9..6b97280785 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -193,8 +193,8 @@ bool IsFeatureSupported(cmMakefile* makefile, std::string const& linkLanguage, { auto featureSupported = cmStrCat( "CMAKE_", linkLanguage, "_LINK_LIBRARY_USING_", feature, "_SUPPORTED"); - if (makefile->GetDefinition(featureSupported).IsOn()) { - return true; + if (cmValue perLangVar = makefile->GetDefinition(featureSupported)) { + return perLangVar.IsOn(); } featureSupported = From a9b126b0da595d4ad3f64a22485bdf7b4a70544d Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 14 Mar 2025 15:32:00 +0100 Subject: [PATCH 2/4] Linker: Save linker inspection results with compiler inspection results Reconfigure `CMakeCompiler.cmake` again after linker information is detected. --- Modules/CMakeASMCompiler.cmake.in | 10 +++---- .../Internal/CMakeInspectASM-ATTLinker.cmake | 7 +++++ Modules/Internal/CMakeInspectASMLinker.cmake | 26 +++++++++++++++++++ .../CMakeInspectASM_MARMASMLinker.cmake | 7 +++++ .../Internal/CMakeInspectASM_MASMLinker.cmake | 7 +++++ .../Internal/CMakeInspectASM_NASMLinker.cmake | 7 +++++ Modules/Internal/CMakeInspectCLinker.cmake | 8 ++++++ Modules/Internal/CMakeInspectCUDALinker.cmake | 8 ++++++ Modules/Internal/CMakeInspectCXXLinker.cmake | 8 ++++++ .../Internal/CMakeInspectFortranLinker.cmake | 8 ++++++ Modules/Internal/CMakeInspectHIPLinker.cmake | 8 ++++++ Modules/Internal/CMakeInspectOBJCLinker.cmake | 8 ++++++ .../Internal/CMakeInspectOBJCXXLinker.cmake | 8 ++++++ .../Internal/CMakeInspectSwiftLinker.cmake | 8 ++++++ Source/cmGlobalGenerator.cxx | 18 ++++++++++--- 15 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 Modules/Internal/CMakeInspectASM-ATTLinker.cmake create mode 100644 Modules/Internal/CMakeInspectASMLinker.cmake create mode 100644 Modules/Internal/CMakeInspectASM_MARMASMLinker.cmake create mode 100644 Modules/Internal/CMakeInspectASM_MASMLinker.cmake create mode 100644 Modules/Internal/CMakeInspectASM_NASMLinker.cmake create mode 100644 Modules/Internal/CMakeInspectCLinker.cmake create mode 100644 Modules/Internal/CMakeInspectCUDALinker.cmake create mode 100644 Modules/Internal/CMakeInspectCXXLinker.cmake create mode 100644 Modules/Internal/CMakeInspectFortranLinker.cmake create mode 100644 Modules/Internal/CMakeInspectHIPLinker.cmake create mode 100644 Modules/Internal/CMakeInspectOBJCLinker.cmake create mode 100644 Modules/Internal/CMakeInspectOBJCXXLinker.cmake create mode 100644 Modules/Internal/CMakeInspectSwiftLinker.cmake diff --git a/Modules/CMakeASMCompiler.cmake.in b/Modules/CMakeASMCompiler.cmake.in index c7dbfae970..a0434752e7 100644 --- a/Modules/CMakeASMCompiler.cmake.in +++ b/Modules/CMakeASMCompiler.cmake.in @@ -7,10 +7,10 @@ set(CMAKE_ASM@ASM_DIALECT@_COMPILER_RANLIB "@_CMAKE_ASM_COMPILER_RANLIB@") set(CMAKE_LINKER "@CMAKE_LINKER@") set(CMAKE_LINKER_LINK "@CMAKE_LINKER_LINK@") set(CMAKE_LINKER_LLD "@CMAKE_LINKER_LLD@") -set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LINKER "@CMAKE_ASM_COMPILER_LINKER@") -set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LINKER_ID "@CMAKE_ASM_COMPILER_LINKER_ID@") -set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LINKER_VERSION @CMAKE_ASM_COMPILER_LINKER_VERSION@) -set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LINKER_FRONTEND_VARIANT @CMAKE_ASM_COMPILER_LINKER_FRONTEND_VARIANT@) +set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LINKER "@_CMAKE_ASM_COMPILER_LINKER@") +set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LINKER_ID "@_CMAKE_ASM_COMPILER_LINKER_ID@") +set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LINKER_VERSION @_CMAKE_ASM_COMPILER_LINKER_VERSION@) +set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LINKER_FRONTEND_VARIANT @_CMAKE_ASM_COMPILER_LINKER_FRONTEND_VARIANT@) set(CMAKE_MT "@CMAKE_MT@") set(CMAKE_TAPI "@CMAKE_TAPI@") set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LOADED 1) @@ -23,6 +23,6 @@ set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ENV_VAR "@_CMAKE_ASM_COMPILER_ENV_VAR@") set(CMAKE_ASM@ASM_DIALECT@_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) set(CMAKE_ASM@ASM_DIALECT@_LINKER_PREFERENCE 0) -set(CMAKE_ASM@ASM_DIALECT@_LINKER_DEPFILE_SUPPORTED @CMAKE_ASM_LINKER_DEPFILE_SUPPORTED@) +set(CMAKE_ASM@ASM_DIALECT@_LINKER_DEPFILE_SUPPORTED @_CMAKE_ASM_LINKER_DEPFILE_SUPPORTED@) @CMAKE_ASM_COMPILER_CUSTOM_CODE@ diff --git a/Modules/Internal/CMakeInspectASM-ATTLinker.cmake b/Modules/Internal/CMakeInspectASM-ATTLinker.cmake new file mode 100644 index 0000000000..3c3a36d6e8 --- /dev/null +++ b/Modules/Internal/CMakeInspectASM-ATTLinker.cmake @@ -0,0 +1,7 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Load the generic ASM test file: +set(ASM_DIALECT "-ATT") +include(Internal/CMakeInspectASMLinker) +set(ASM_DIALECT) diff --git a/Modules/Internal/CMakeInspectASMLinker.cmake b/Modules/Internal/CMakeInspectASMLinker.cmake new file mode 100644 index 0000000000..b59763eb9e --- /dev/null +++ b/Modules/Internal/CMakeInspectASMLinker.cmake @@ -0,0 +1,26 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Re-configure to save learned information. +block() + foreach(_var IN ITEMS + COMPILER + COMPILER_ID + COMPILER_ARG1 + COMPILER_ENV_VAR + COMPILER_AR + COMPILER_RANLIB + COMPILER_VERSION + COMPILER_LINKER + COMPILER_LINKER_ID + COMPILER_LINKER_VERSION + COMPILER_LINKER_FRONTEND_VARIANT + LINKER_DEPFILE_SUPPORTED + ) + set(_CMAKE_ASM_${_var} "${CMAKE_ASM${ASM_DIALECT}_${_var}}") + endforeach() + configure_file( + ${CMAKE_ROOT}/Modules/CMakeASMCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeASM${ASM_DIALECT}Compiler.cmake + @ONLY) +endblock() diff --git a/Modules/Internal/CMakeInspectASM_MARMASMLinker.cmake b/Modules/Internal/CMakeInspectASM_MARMASMLinker.cmake new file mode 100644 index 0000000000..bea7af1c24 --- /dev/null +++ b/Modules/Internal/CMakeInspectASM_MARMASMLinker.cmake @@ -0,0 +1,7 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Load the generic ASM test file: +set(ASM_DIALECT "_MARMASM") +include(Internal/CMakeInspectASMLinker) +set(ASM_DIALECT) diff --git a/Modules/Internal/CMakeInspectASM_MASMLinker.cmake b/Modules/Internal/CMakeInspectASM_MASMLinker.cmake new file mode 100644 index 0000000000..b6c377f0e1 --- /dev/null +++ b/Modules/Internal/CMakeInspectASM_MASMLinker.cmake @@ -0,0 +1,7 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Load the generic ASM test file: +set(ASM_DIALECT "_MASM") +include(Internal/CMakeInspectASMLinker) +set(ASM_DIALECT) diff --git a/Modules/Internal/CMakeInspectASM_NASMLinker.cmake b/Modules/Internal/CMakeInspectASM_NASMLinker.cmake new file mode 100644 index 0000000000..53e9ad61e9 --- /dev/null +++ b/Modules/Internal/CMakeInspectASM_NASMLinker.cmake @@ -0,0 +1,7 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Load the generic ASM test file: +set(ASM_DIALECT "_NASM") +include(Internal/CMakeInspectASMLinker) +set(ASM_DIALECT) diff --git a/Modules/Internal/CMakeInspectCLinker.cmake b/Modules/Internal/CMakeInspectCLinker.cmake new file mode 100644 index 0000000000..fcec2e2019 --- /dev/null +++ b/Modules/Internal/CMakeInspectCLinker.cmake @@ -0,0 +1,8 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeCCompiler.cmake + @ONLY) diff --git a/Modules/Internal/CMakeInspectCUDALinker.cmake b/Modules/Internal/CMakeInspectCUDALinker.cmake new file mode 100644 index 0000000000..d1d5e7758a --- /dev/null +++ b/Modules/Internal/CMakeInspectCUDALinker.cmake @@ -0,0 +1,8 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeCUDACompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake + @ONLY) diff --git a/Modules/Internal/CMakeInspectCXXLinker.cmake b/Modules/Internal/CMakeInspectCXXLinker.cmake new file mode 100644 index 0000000000..6af7337861 --- /dev/null +++ b/Modules/Internal/CMakeInspectCXXLinker.cmake @@ -0,0 +1,8 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake + @ONLY) diff --git a/Modules/Internal/CMakeInspectFortranLinker.cmake b/Modules/Internal/CMakeInspectFortranLinker.cmake new file mode 100644 index 0000000000..0323d81522 --- /dev/null +++ b/Modules/Internal/CMakeInspectFortranLinker.cmake @@ -0,0 +1,8 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake + @ONLY) diff --git a/Modules/Internal/CMakeInspectHIPLinker.cmake b/Modules/Internal/CMakeInspectHIPLinker.cmake new file mode 100644 index 0000000000..2320abcb26 --- /dev/null +++ b/Modules/Internal/CMakeInspectHIPLinker.cmake @@ -0,0 +1,8 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeHIPCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeHIPCompiler.cmake + @ONLY) diff --git a/Modules/Internal/CMakeInspectOBJCLinker.cmake b/Modules/Internal/CMakeInspectOBJCLinker.cmake new file mode 100644 index 0000000000..e9e3e7caba --- /dev/null +++ b/Modules/Internal/CMakeInspectOBJCLinker.cmake @@ -0,0 +1,8 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeOBJCCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCCompiler.cmake + @ONLY) diff --git a/Modules/Internal/CMakeInspectOBJCXXLinker.cmake b/Modules/Internal/CMakeInspectOBJCXXLinker.cmake new file mode 100644 index 0000000000..2b3acf2022 --- /dev/null +++ b/Modules/Internal/CMakeInspectOBJCXXLinker.cmake @@ -0,0 +1,8 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake + @ONLY) diff --git a/Modules/Internal/CMakeInspectSwiftLinker.cmake b/Modules/Internal/CMakeInspectSwiftLinker.cmake new file mode 100644 index 0000000000..818d4e9aa8 --- /dev/null +++ b/Modules/Internal/CMakeInspectSwiftLinker.cmake @@ -0,0 +1,8 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +# Re-configure to save learned information. +configure_file( + ${CMAKE_ROOT}/Modules/CMakeSwiftCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake + @ONLY) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index e361ad26a5..eced1608ba 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -963,9 +963,9 @@ void cmGlobalGenerator::EnableLanguage( } // end if in try compile } // end need test language - // load linker configuration, if required - if (mf->GetDefinition(cmStrCat("CMAKE_", lang, "_USE_LINKER_INFORMATION")) - .IsOn()) { + // load linker configuration, if required + if (mf->IsOn(cmStrCat("CMAKE_", lang, "_COMPILER_WORKS")) && + mf->IsOn(cmStrCat("CMAKE_", lang, "_USE_LINKER_INFORMATION"))) { std::string langLinkerLoadedVar = cmStrCat("CMAKE_", lang, "_LINKER_INFORMATION_LOADED"); if (!mf->GetDefinition(langLinkerLoadedVar)) { @@ -982,6 +982,18 @@ void cmGlobalGenerator::EnableLanguage( "Could not process cmake module file: ", informationFile)); } } + + if (needTestLanguage[lang]) { + if (!this->CMakeInstance->GetIsInTryCompile()) { + std::string testLang = + cmStrCat("Internal/CMakeInspect", lang, "Linker.cmake"); + std::string ifpath = mf->GetModulesFile(testLang); + if (!mf->ReadListFile(ifpath)) { + cmSystemTools::Error( + cmStrCat("Could not find cmake module file: ", testLang)); + } + } + } } // Store the shared library flags so that we can satisfy CMP0018 From 7b552b9a6425446ca7f1789294caa704234bc241 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 14 Mar 2025 15:35:20 +0100 Subject: [PATCH 3/4] Linker: Save GNU push-/pop-state detection with compiler inspection results Previously we saved it in the cache, which: * Persists even if a new version of CMake changes how the check works. * Does not propagate to `try_compile` checks. --- Modules/CMakeASMCompiler.cmake.in | 2 ++ Modules/CMakeCCompiler.cmake.in | 2 ++ Modules/CMakeCUDACompiler.cmake.in | 2 ++ Modules/CMakeCXXCompiler.cmake.in | 2 ++ Modules/CMakeFortranCompiler.cmake.in | 2 ++ Modules/CMakeHIPCompiler.cmake.in | 2 ++ Modules/CMakeOBJCCompiler.cmake.in | 2 ++ Modules/CMakeOBJCXXCompiler.cmake.in | 2 ++ Modules/Internal/CMakeInspectASMLinker.cmake | 1 + Modules/Platform/Linker/GNU.cmake | 11 ++++++----- Modules/Platform/Linux-Intel.cmake | 2 +- 11 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Modules/CMakeASMCompiler.cmake.in b/Modules/CMakeASMCompiler.cmake.in index a0434752e7..ac92379150 100644 --- a/Modules/CMakeASMCompiler.cmake.in +++ b/Modules/CMakeASMCompiler.cmake.in @@ -24,5 +24,7 @@ set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ENV_VAR "@_CMAKE_ASM_COMPILER_ENV_VAR@") set(CMAKE_ASM@ASM_DIALECT@_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) set(CMAKE_ASM@ASM_DIALECT@_LINKER_PREFERENCE 0) set(CMAKE_ASM@ASM_DIALECT@_LINKER_DEPFILE_SUPPORTED @_CMAKE_ASM_LINKER_DEPFILE_SUPPORTED@) +set(CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED@) +set(CMAKE_ASM@ASM_DIALECT@_LINKER_PUSHPOP_STATE_SUPPORTED @_CMAKE_ASM_LINKER_PUSHPOP_STATE_SUPPORTED@) @CMAKE_ASM_COMPILER_CUSTOM_CODE@ diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in index 1726fe9b8f..5642f99140 100644 --- a/Modules/CMakeCCompiler.cmake.in +++ b/Modules/CMakeCCompiler.cmake.in @@ -47,6 +47,8 @@ set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m) set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) set(CMAKE_C_LINKER_PREFERENCE 10) set(CMAKE_C_LINKER_DEPFILE_SUPPORTED @CMAKE_C_LINKER_DEPFILE_SUPPORTED@) +set(CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED@) +set(CMAKE_C_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_C_LINKER_PUSHPOP_STATE_SUPPORTED@) # Save compiler ABI information. set(CMAKE_C_SIZEOF_DATA_PTR "@CMAKE_C_SIZEOF_DATA_PTR@") diff --git a/Modules/CMakeCUDACompiler.cmake.in b/Modules/CMakeCUDACompiler.cmake.in index c6a176ba53..6b8b43344e 100644 --- a/Modules/CMakeCUDACompiler.cmake.in +++ b/Modules/CMakeCUDACompiler.cmake.in @@ -35,6 +35,8 @@ set(CMAKE_CUDA_SOURCE_FILE_EXTENSIONS cu) set(CMAKE_CUDA_LINKER_PREFERENCE 15) set(CMAKE_CUDA_LINKER_PREFERENCE_PROPAGATES 1) set(CMAKE_CUDA_LINKER_DEPFILE_SUPPORTED @CMAKE_CUDA_LINKER_DEPFILE_SUPPORTED@) +set(CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED@) +set(CMAKE_CUDA_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_CUDA_LINKER_PUSHPOP_STATE_SUPPORTED@) set(CMAKE_CUDA_SIZEOF_DATA_PTR "@CMAKE_CUDA_SIZEOF_DATA_PTR@") set(CMAKE_CUDA_COMPILER_ABI "@CMAKE_CUDA_COMPILER_ABI@") diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index 2f7c3e4aaf..b1de7fb014 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -59,6 +59,8 @@ endforeach() set(CMAKE_CXX_LINKER_PREFERENCE 30) set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1) set(CMAKE_CXX_LINKER_DEPFILE_SUPPORTED @CMAKE_CXX_LINKER_DEPFILE_SUPPORTED@) +set(CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED@) +set(CMAKE_CXX_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_CXX_LINKER_PUSHPOP_STATE_SUPPORTED@) # Save compiler ABI information. set(CMAKE_CXX_SIZEOF_DATA_PTR "@CMAKE_CXX_SIZEOF_DATA_PTR@") diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in index 90c2ad014e..1a4acc4419 100644 --- a/Modules/CMakeFortranCompiler.cmake.in +++ b/Modules/CMakeFortranCompiler.cmake.in @@ -35,6 +35,8 @@ set(CMAKE_Fortran_SOURCE_FILE_EXTENSIONS f;F;fpp;FPP;f77;F77;f90;F90;for;For;FOR set(CMAKE_Fortran_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) set(CMAKE_Fortran_LINKER_PREFERENCE 20) set(CMAKE_Fortran_LINKER_DEPFILE_SUPPORTED @CMAKE_Fortran_LINKER_DEPFILE_SUPPORTED@) +set(CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED@) +set(CMAKE_Fortran_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_Fortran_LINKER_PUSHPOP_STATE_SUPPORTED@) if(UNIX) set(CMAKE_Fortran_OUTPUT_EXTENSION .o) else() diff --git a/Modules/CMakeHIPCompiler.cmake.in b/Modules/CMakeHIPCompiler.cmake.in index e6a472071e..0077c19593 100644 --- a/Modules/CMakeHIPCompiler.cmake.in +++ b/Modules/CMakeHIPCompiler.cmake.in @@ -34,6 +34,8 @@ set(CMAKE_HIP_SOURCE_FILE_EXTENSIONS hip) set(CMAKE_HIP_LINKER_PREFERENCE 90) set(CMAKE_HIP_LINKER_PREFERENCE_PROPAGATES 1) set(CMAKE_HIP_LINKER_DEPFILE_SUPPORTED @CMAKE_HIP_LINKER_DEPFILE_SUPPORTED@) +set(CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED@) +set(CMAKE_HIP_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_HIP_LINKER_PUSHPOP_STATE_SUPPORTED@) set(CMAKE_HIP_SIZEOF_DATA_PTR "@CMAKE_HIP_SIZEOF_DATA_PTR@") set(CMAKE_HIP_COMPILER_ABI "@CMAKE_HIP_COMPILER_ABI@") diff --git a/Modules/CMakeOBJCCompiler.cmake.in b/Modules/CMakeOBJCCompiler.cmake.in index fb699fca02..23175b23c6 100644 --- a/Modules/CMakeOBJCCompiler.cmake.in +++ b/Modules/CMakeOBJCCompiler.cmake.in @@ -45,6 +45,8 @@ set(CMAKE_OBJC_SOURCE_FILE_EXTENSIONS m) set(CMAKE_OBJC_IGNORE_EXTENSIONS h;H;o;O) set(CMAKE_OBJC_LINKER_PREFERENCE 5) set(CMAKE_OBJC_LINKER_DEPFILE_SUPPORTED @CMAKE_OBJC_LINKER_DEPFILE_SUPPORTED@) +set(CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED@) +set(CMAKE_OBJC_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_OBJC_LINKER_PUSHPOP_STATE_SUPPORTED@) foreach (lang C CXX OBJCXX) foreach(extension IN LISTS CMAKE_OBJC_SOURCE_FILE_EXTENSIONS) diff --git a/Modules/CMakeOBJCXXCompiler.cmake.in b/Modules/CMakeOBJCXXCompiler.cmake.in index 3bf12b1f84..a374acd174 100644 --- a/Modules/CMakeOBJCXXCompiler.cmake.in +++ b/Modules/CMakeOBJCXXCompiler.cmake.in @@ -62,6 +62,8 @@ endforeach() set(CMAKE_OBJCXX_LINKER_PREFERENCE 25) set(CMAKE_OBJCXX_LINKER_PREFERENCE_PROPAGATES 1) set(CMAKE_OBJCXX_LINKER_DEPFILE_SUPPORTED @CMAKE_OBJCXX_LINKER_DEPFILE_SUPPORTED@) +set(CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED@) +set(CMAKE_OBJCXX_LINKER_PUSHPOP_STATE_SUPPORTED @CMAKE_OBJCXX_LINKER_PUSHPOP_STATE_SUPPORTED@) # Save compiler ABI information. set(CMAKE_OBJCXX_SIZEOF_DATA_PTR "@CMAKE_OBJCXX_SIZEOF_DATA_PTR@") diff --git a/Modules/Internal/CMakeInspectASMLinker.cmake b/Modules/Internal/CMakeInspectASMLinker.cmake index b59763eb9e..3f256765ef 100644 --- a/Modules/Internal/CMakeInspectASMLinker.cmake +++ b/Modules/Internal/CMakeInspectASMLinker.cmake @@ -16,6 +16,7 @@ block() COMPILER_LINKER_VERSION COMPILER_LINKER_FRONTEND_VARIANT LINKER_DEPFILE_SUPPORTED + LINKER_PUSHPOP_STATE_SUPPORTED ) set(_CMAKE_ASM_${_var} "${CMAKE_ASM${ASM_DIALECT}_${_var}}") endforeach() diff --git a/Modules/Platform/Linker/GNU.cmake b/Modules/Platform/Linker/GNU.cmake index 5f1167418b..a1e8bd7c0e 100644 --- a/Modules/Platform/Linker/GNU.cmake +++ b/Modules/Platform/Linker/GNU.cmake @@ -17,21 +17,22 @@ function(__cmake_set_whole_archive_feature __linker) endif() if(NOT __linker) - set(_CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state") + set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED FALSE) endif() - if(NOT DEFINED _CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED) + if(NOT DEFINED CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED) execute_process(COMMAND "${__linker}" --help OUTPUT_VARIABLE __linker_help ERROR_VARIABLE __linker_help) if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state") - set(_CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED TRUE CACHE INTERNAL "linker supports push/pop state") + set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED FALSE) else() - set(_CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state") + set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED TRUE) endif() + set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED ${CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED} PARENT_SCOPE) endif() ## WHOLE_ARCHIVE: Force loading all members of an archive - if(_CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED) + if(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED) set(CMAKE_${__lang}LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--push-state,--whole-archive" "" "LINKER:--pop-state" PARENT_SCOPE) diff --git a/Modules/Platform/Linux-Intel.cmake b/Modules/Platform/Linux-Intel.cmake index 95debf96d9..b2ea00206b 100644 --- a/Modules/Platform/Linux-Intel.cmake +++ b/Modules/Platform/Linux-Intel.cmake @@ -42,7 +42,7 @@ macro(__linux_compiler_intel lang) # FIXME(#26157): compute CMAKE__COMPILER_LINKER* variables # in the meantime, enforce deactivation of push/pop state linker options # because xild front-end linker do not support these options even if the platform linker does... - set(_CMAKE_${lang}_LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state") + set(CMAKE_${lang}_LINKER_PUSHPOP_STATE_SUPPORTED FALSE) set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES) From d5be7c7f31dc406a37e1cfe34a76819f331d2131 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Thu, 13 Mar 2025 16:14:15 +0100 Subject: [PATCH 4/4] Linker: Detect GNU push-state/pop-state flags more robustly Try actually passing them to the linker to see whether it complains. Fixes: #26766 --- Modules/Platform/Linker/GNU.cmake | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Modules/Platform/Linker/GNU.cmake b/Modules/Platform/Linker/GNU.cmake index a1e8bd7c0e..3d6632976d 100644 --- a/Modules/Platform/Linker/GNU.cmake +++ b/Modules/Platform/Linker/GNU.cmake @@ -21,10 +21,11 @@ function(__cmake_set_whole_archive_feature __linker) endif() if(NOT DEFINED CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED) - execute_process(COMMAND "${__linker}" --help - OUTPUT_VARIABLE __linker_help - ERROR_VARIABLE __linker_help) - if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state") + # launch linker to check if push_state/pop_state options are supported + execute_process(COMMAND "${__linker}" --push-state --pop-state + OUTPUT_VARIABLE __linker_log + ERROR_VARIABLE __linker_log) + if(__linker_log MATCHES "--push-state" OR __linker_log MATCHES "--pop-state") set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED FALSE) else() set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED TRUE)