Merge topic 'GNU-linker-pushpop_state-detection'

d5be7c7f31 Linker: Detect GNU push-state/pop-state flags more robustly
7b552b9a64 Linker: Save GNU push-/pop-state detection with compiler inspection results
a9b126b0da Linker: Save linker inspection results with compiler inspection results
3f5f2b2d49 Linker: Honor CMAKE_<LANG>_LINK_LIBRARY_USING_FEATURE_SUPPORTED when FALSE

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10468
This commit is contained in:
Brad King 2025-03-21 12:06:29 +00:00 committed by Kitware Robot
commit c8f4ae9ccf
25 changed files with 169 additions and 20 deletions

View File

@ -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,8 @@ 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@)
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@

View File

@ -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@")

View File

@ -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@")

View File

@ -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@")

View File

@ -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()

View File

@ -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@")

View File

@ -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)

View File

@ -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@")

View File

@ -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)

View File

@ -0,0 +1,27 @@
# 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
LINKER_PUSHPOP_STATE_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()

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -14,21 +14,23 @@ 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)
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")
if(NOT DEFINED CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED)
# 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 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"
"<LINK_ITEM>"
"LINKER:--pop-state" PARENT_SCOPE)

View File

@ -42,7 +42,7 @@ macro(__linux_compiler_intel lang)
# FIXME(#26157): compute CMAKE_<LANG>_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)

View File

@ -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 =

View File

@ -941,9 +941,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)) {
@ -960,6 +960,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));
}
}
}
}
// Translate compiler ids for compatibility.