Browse Source

Merge topic 'Linux-deduplication-static-libs' into release-3.31

0445190d2f LLD linker: avoid regression on archive libraries deduplication

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !10010
Brad King 1 year ago
parent
commit
6b9aee9f38
37 changed files with 70 additions and 1 deletions
  1. 1 0
      Modules/Platform/Linker/AIX-AIX.cmake
  2. 1 0
      Modules/Platform/Linker/Apple-AppleClang.cmake
  3. 2 0
      Modules/Platform/Linker/Apple-LLD-C.cmake
  4. 2 0
      Modules/Platform/Linker/Apple-LLD-CXX.cmake
  5. 2 0
      Modules/Platform/Linker/Apple-LLD-OBJC.cmake
  6. 2 0
      Modules/Platform/Linker/Apple-LLD-OBJCXX.cmake
  7. 2 0
      Modules/Platform/Linker/Apple-MOLD-C.cmake
  8. 2 0
      Modules/Platform/Linker/Apple-MOLD-CXX.cmake
  9. 2 0
      Modules/Platform/Linker/Apple-MOLD-OBJC.cmake
  10. 2 0
      Modules/Platform/Linker/Apple-MOLD-OBJCXX.cmake
  11. 1 0
      Modules/Platform/Linker/CYGWIN-GNU.cmake
  12. 1 0
      Modules/Platform/Linker/CYGWIN-LLD.cmake
  13. 1 0
      Modules/Platform/Linker/FreeBSD-GNU.cmake
  14. 1 0
      Modules/Platform/Linker/FreeBSD-LLD.cmake
  15. 1 0
      Modules/Platform/Linker/GNU-GNU.cmake
  16. 1 0
      Modules/Platform/Linker/Linux-GNU.cmake
  17. 2 0
      Modules/Platform/Linker/Linux-GNUgold-ASM.cmake
  18. 2 0
      Modules/Platform/Linker/Linux-GNUgold-C.cmake
  19. 2 0
      Modules/Platform/Linker/Linux-GNUgold-CUDA.cmake
  20. 2 0
      Modules/Platform/Linker/Linux-GNUgold-CXX.cmake
  21. 2 0
      Modules/Platform/Linker/Linux-GNUgold-Fortran.cmake
  22. 2 0
      Modules/Platform/Linker/Linux-GNUgold-HIP.cmake
  23. 1 0
      Modules/Platform/Linker/Linux-LLD.cmake
  24. 2 0
      Modules/Platform/Linker/Linux-MOLD.cmake
  25. 1 0
      Modules/Platform/Linker/NetBSD-GNU.cmake
  26. 1 0
      Modules/Platform/Linker/OpenBSD-GNU.cmake
  27. 1 0
      Modules/Platform/Linker/OpenBSD-LLD.cmake
  28. 1 0
      Modules/Platform/Linker/SerenityOS-GNU.cmake
  29. 1 0
      Modules/Platform/Linker/SerenityOS-LLD.cmake
  30. 1 0
      Modules/Platform/Linker/SunOS-GNU.cmake
  31. 1 0
      Modules/Platform/Linker/SunOS-Solaris.cmake
  32. 1 0
      Modules/Platform/Linker/Windows-GNU.cmake
  33. 1 0
      Modules/Platform/Linker/Windows-LLD.cmake
  34. 1 0
      Modules/Platform/Linker/Windows-MSVC.cmake
  35. 9 0
      Source/cmComputeLinkDepends.cxx
  36. 2 0
      Tests/RunCMake/LinkLibrariesStrategy/Inspect.cmake
  37. 10 1
      Tests/RunCMake/LinkLibrariesStrategy/RunCMakeTest.cmake

+ 1 - 0
Modules/Platform/Linker/AIX-AIX.cmake

@@ -6,5 +6,6 @@
 include_guard()
 
 macro(__aix_linker_aix lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID AIX)
   set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=REVERSE DEDUPLICATION=ALL)
 endmacro()

+ 1 - 0
Modules/Platform/Linker/Apple-AppleClang.cmake

@@ -6,6 +6,7 @@
 include_guard()
 
 macro(__apple_linker_appleclang lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID AppleClang)
   set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=REVERSE DEDUPLICATION=ALL)
 
   # Features for LINK_LIBRARY generator expression

+ 2 - 0
Modules/Platform/Linker/Apple-LLD-C.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Apple-AppleClang-C)
+
+set(CMAKE_C_PLATFORM_LINKER_ID LLD)

+ 2 - 0
Modules/Platform/Linker/Apple-LLD-CXX.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Apple-AppleClang-CXX)
+
+set(CMAKE_CXX_PLATFORM_LINKER_ID LLD)

+ 2 - 0
Modules/Platform/Linker/Apple-LLD-OBJC.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Apple-AppleClang-OBJC)
+
+set(CMAKE_OBJC_PLATFORM_LINKER_ID LLD)

+ 2 - 0
Modules/Platform/Linker/Apple-LLD-OBJCXX.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Apple-AppleClang-OBJCXX)
+
+set(CMAKE_OBJCXX_PLATFORM_LINKER_ID LLD)

+ 2 - 0
Modules/Platform/Linker/Apple-MOLD-C.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Apple-AppleClang-C)
+
+set(CMAKE_C_PLATFORM_LINKER_ID MOLD)

+ 2 - 0
Modules/Platform/Linker/Apple-MOLD-CXX.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Apple-AppleClang-CXX)
+
+set(CMAKE_CXX_PLATFORM_LINKER_ID MOLD)

+ 2 - 0
Modules/Platform/Linker/Apple-MOLD-OBJC.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Apple-AppleClang-OBJC)
+
+set(CMAKE_OBJC_PLATFORM_LINKER_ID MOLD)

+ 2 - 0
Modules/Platform/Linker/Apple-MOLD-OBJCXX.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Apple-AppleClang-OBJCXX)
+
+set(CMAKE_OBJCXX_PLATFORM_LINKER_ID MOLD)

+ 1 - 0
Modules/Platform/Linker/CYGWIN-GNU.cmake

@@ -8,6 +8,7 @@ include_guard()
 include(Platform/Linker/GNU)
 
 macro(__cygwin_linker_gnu lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID GNU)
   if(CMAKE_${lang}_COMPILER_LINKER)
     __cmake_set_whole_archive_feature("${CMAKE_${lang}_COMPILER_LINKER}" "${lang}")
   endif()

+ 1 - 0
Modules/Platform/Linker/CYGWIN-LLD.cmake

@@ -12,5 +12,6 @@ include(Platform/Linker/CYGWIN-GNU)
 macro(__cygwin_linker_lld lang)
   __cygwin_linker_gnu(${lang})
 
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID LLD)
   set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=REVERSE DEDUPLICATION=ALL)
 endmacro()

+ 1 - 0
Modules/Platform/Linker/FreeBSD-GNU.cmake

@@ -8,6 +8,7 @@ include_guard()
 include(Platform/Linker/GNU)
 
 macro(__freebsd_linker_gnu lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID GNU)
   if(CMAKE_${lang}_COMPILER_LINKER)
     __cmake_set_whole_archive_feature("${CMAKE_${lang}_COMPILER_LINKER}" "${lang}")
   endif()

+ 1 - 0
Modules/Platform/Linker/FreeBSD-LLD.cmake

@@ -12,5 +12,6 @@ include(Platform/Linker/FreeBSD-GNU)
 macro(__freebsd_linker_lld lang)
   __freebsd_linker_gnu(${lang})
 
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID LLD)
   set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=REVERSE DEDUPLICATION=ALL)
 endmacro()

+ 1 - 0
Modules/Platform/Linker/GNU-GNU.cmake

@@ -8,6 +8,7 @@ include_guard()
 include(Platform/Linker/GNU)
 
 macro(__gnu_linker_gnu lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID GNU)
   if(CMAKE_${lang}_COMPILER_LINKER)
     __cmake_set_whole_archive_feature("${CMAKE_${lang}_COMPILER_LINKER}" "${lang}")
   endif()

+ 1 - 0
Modules/Platform/Linker/Linux-GNU.cmake

@@ -8,6 +8,7 @@ include_guard()
 include(Platform/Linker/GNU)
 
 macro(__linux_linker_gnu lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID GNU)
   if(CMAKE_${lang}_COMPILER_LINKER)
     __cmake_set_whole_archive_feature("${CMAKE_${lang}_COMPILER_LINKER}" "${lang}")
   endif()

+ 2 - 0
Modules/Platform/Linker/Linux-GNUgold-ASM.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Linux-GNU-ASM)
+
+set(CMAKE_ASM_PLATFORM_LINKER_ID GNUgold)

+ 2 - 0
Modules/Platform/Linker/Linux-GNUgold-C.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Linux-GNU-C)
+
+set(CMAKE_C_PLATFORM_LINKER_ID GNUgold)

+ 2 - 0
Modules/Platform/Linker/Linux-GNUgold-CUDA.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Linux-GNU-CUDA)
+
+set(CMAKE_CUDA_PLATFORM_LINKER_ID GNUgold)

+ 2 - 0
Modules/Platform/Linker/Linux-GNUgold-CXX.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Linux-GNU-CXX)
+
+set(CMAKE_CXX_PLATFORM_LINKER_ID GNUgold)

+ 2 - 0
Modules/Platform/Linker/Linux-GNUgold-Fortran.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Linux-GNU-Fortran)
+
+set(CMAKE_Fortran_PLATFORM_LINKER_ID GNUgold)

+ 2 - 0
Modules/Platform/Linker/Linux-GNUgold-HIP.cmake

@@ -2,3 +2,5 @@
 # file Copyright.txt or https://cmake.org/licensing for details.
 
 include(Platform/Linker/Linux-GNU-HIP)
+
+set(CMAKE_HIP_PLATFORM_LINKER_ID GNUgold)

+ 1 - 0
Modules/Platform/Linker/Linux-LLD.cmake

@@ -12,5 +12,6 @@ include(Platform/Linker/Linux-GNU)
 macro(__linux_linker_lld lang)
   __linux_linker_gnu(${lang})
 
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID LLD)
   set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=REVERSE DEDUPLICATION=ALL)
 endmacro()

+ 2 - 0
Modules/Platform/Linker/Linux-MOLD.cmake

@@ -12,5 +12,7 @@ include(Platform/Linker/Linux-GNU)
 macro(__linux_linker_mold lang)
   __linux_linker_gnu(${lang})
 
+
+  set(CMAKE_C_PLATFORM_LINKER_ID MOLD)
   set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=REVERSE DEDUPLICATION=ALL)
 endmacro()

+ 1 - 0
Modules/Platform/Linker/NetBSD-GNU.cmake

@@ -8,6 +8,7 @@ include_guard()
 include(Platform/Linker/GNU)
 
 macro(__netbsd_linker_gnu lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID GNU)
   if(CMAKE_${lang}_COMPILER_LINKER)
     __cmake_set_whole_archive_feature("${CMAKE_${lang}_COMPILER_LINKER}" "${lang}")
   endif()

+ 1 - 0
Modules/Platform/Linker/OpenBSD-GNU.cmake

@@ -8,6 +8,7 @@ include_guard()
 include(Platform/Linker/GNU)
 
 macro(__openbsd_linker_gnu lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID GNU)
   if(CMAKE_${lang}_COMPILER_LINKER)
     __cmake_set_whole_archive_feature("${CMAKE_${lang}_COMPILER_LINKER}" "${lang}")
   endif()

+ 1 - 0
Modules/Platform/Linker/OpenBSD-LLD.cmake

@@ -12,5 +12,6 @@ include(Platform/Linker/OpenBSD-GNU)
 macro(__openbsd_linker_lld lang)
   __openbsd_linker_gnu(${lang})
 
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID LLD)
   set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=REVERSE DEDUPLICATION=ALL)
 endmacro()

+ 1 - 0
Modules/Platform/Linker/SerenityOS-GNU.cmake

@@ -8,6 +8,7 @@ include_guard()
 include(Platform/Linker/GNU)
 
 macro(__serenityos_linker_gnu lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID GNU)
   if(CMAKE_${lang}_COMPILER_LINKER)
     __cmake_set_whole_archive_feature("${CMAKE_${lang}_COMPILER_LINKER}" "${lang}")
   endif()

+ 1 - 0
Modules/Platform/Linker/SerenityOS-LLD.cmake

@@ -12,5 +12,6 @@ include(Platform/Linker/SerenityOS-GNU)
 macro(__serenityos_linker_lld lang)
   __serenityos_linker_gnu(${lang})
 
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID LLD)
   set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=REVERSE DEDUPLICATION=ALL)
 endmacro()

+ 1 - 0
Modules/Platform/Linker/SunOS-GNU.cmake

@@ -8,6 +8,7 @@ include_guard()
 include(Platform/Linker/GNU)
 
 macro(__sunos_linker_gnu lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID GNU)
   if(CMAKE_${lang}_COMPILER_LINKER)
     __cmake_set_whole_archive_feature("${CMAKE_${lang}_COMPILER_LINKER}" "${lang}")
   endif()

+ 1 - 0
Modules/Platform/Linker/SunOS-Solaris.cmake

@@ -9,6 +9,7 @@ block(SCOPE_FOR POLICIES)
 cmake_policy(SET CMP0054 NEW)
 
 macro(__sunos_linker_solaris lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID Solaris)
   # Features for LINK_LIBRARY generator expression
   ## WHOLE_ARCHIVE: Force loading all members of an archive
   if (CMAKE_SYSTEM_VERSION VERSION_GREATER "5.10")

+ 1 - 0
Modules/Platform/Linker/Windows-GNU.cmake

@@ -8,6 +8,7 @@ include_guard()
 include(Platform/Linker/GNU)
 
 macro(__windows_linker_gnu lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID GNU)
   if(CMAKE_${lang}_COMPILER_LINKER)
     __cmake_set_whole_archive_feature("${CMAKE_${lang}_COMPILER_LINKER}" "${lang}")
   endif()

+ 1 - 0
Modules/Platform/Linker/Windows-LLD.cmake

@@ -9,6 +9,7 @@ block(SCOPE_FOR POLICIES)
 cmake_policy(SET CMP0054 NEW)
 
 macro(__windows_linker_lld lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID LLD)
   # Features for LINK_LIBRARY generator expression
   if(CMAKE_${lang}_COMPILER_LINKER_FRONTEND_VARIANT STREQUAL "GNU")
     include(Platform/Linker/Windows-GNU)

+ 1 - 0
Modules/Platform/Linker/Windows-MSVC.cmake

@@ -17,6 +17,7 @@ if(MSVC_VERSION GREATER "1900")
 endif()
 
 macro(__windows_linker_msvc lang)
+  set(CMAKE_${lang}_PLATFORM_LINKER_ID MSVC)
   set(CMAKE_${lang}_LINK_LIBRARIES_PROCESSING ORDER=FORWARD DEDUPLICATION=ALL)
 
   # Features for LINK_LIBRARY generator expression

+ 9 - 0
Source/cmComputeLinkDepends.cxx

@@ -449,6 +449,15 @@ public:
                        "_LINK_LIBRARIES_PROCESSING':\n", errorMessage),
               target->GetBacktrace());
           }
+          // For some environments, deduplication should be activated only if
+          // both policies CMP0156 and CMP0179 are NEW
+          if (makefile->GetDefinition(cmStrCat(
+                "CMAKE_", linkLanguage, "_PLATFORM_LINKER_ID")) == "LLD"_s &&
+              makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT") == "ELF"_s &&
+              target->GetPolicyStatusCMP0179() != cmPolicies::NEW &&
+              this->Deduplication == All) {
+            this->Deduplication = Shared;
+          }
         }
       }
     }

+ 2 - 0
Tests/RunCMake/LinkLibrariesStrategy/Inspect.cmake

@@ -3,6 +3,8 @@ enable_language(C)
 set(info "")
 foreach(var
     CMAKE_C_LINK_LIBRARIES_PROCESSING
+    CMAKE_C_PLATFORM_LINKER_ID
+    CMAKE_EXECUTABLE_FORMAT
     )
   if(DEFINED ${var})
     string(APPEND info "set(${var} \"${${var}}\")\n")

+ 10 - 1
Tests/RunCMake/LinkLibrariesStrategy/RunCMakeTest.cmake

@@ -10,13 +10,15 @@ endif()
 
 # Detect information from the toolchain:
 # - CMAKE_C_LINK_LIBRARIES_PROCESSING
+# - CMAKE_C_PLATFORM_LINKER_ID
+# - CMAKE_EXECUTABLE_FORMAT
 run_cmake(Inspect)
 include("${RunCMake_BINARY_DIR}/Inspect-build/info.cmake")
 
 run_cmake(Unknown)
 
 function(run_strategy case exe)
-  foreach(cmp0179 OLD NEW)
+  foreach(cmp0179 ${cmp0179_states})
     set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-CMP0179-${cmp0179}-build)
     set(RunCMake_TEST_VARIANT_DESCRIPTION "...CMP0179-${cmp0179}")
     if("DEDUPLICATION=ALL" IN_LIST CMAKE_C_LINK_LIBRARIES_PROCESSING)
@@ -44,6 +46,13 @@ function(run_strategy case exe)
   endforeach()
 endfunction()
 
+if(CMAKE_C_PLATFORM_LINKER_ID STREQUAL "LLD" AND CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
+  # deduplication done only if both CMP0156 and CMP0179 ARE NEW
+  set(cmp0179_states NEW)
+else()
+  set(cmp0179_states OLD NEW)
+endif()
+
 run_strategy(Basic-REORDER_MINIMALLY "main")
 run_strategy(Basic-REORDER_FREELY "main")