[PATCH] D80493: [CMake]: Properly handle the LTO cache arguments for MinGW

Tobias Hieta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 24 10:08:36 PDT 2020


thieta created this revision.
thieta added reviewers: mstorsjo, mati865.
Herald added subscribers: llvm-commits, dexonsmith, inglorion, mgorny.
Herald added a project: LLVM.

There where a few problems with the handling originally discussed in this issue here: https://reviews.llvm.org/D80425

We want to make sure that LINKER_IS_LLD_LINK is properly set - in this case it shouldn't be set when building for MinGW.

Then we want to make the test for it correct and finally include the option to build with thinlto cache since the MinGW driver now supports that.

Note that this will break when building with LTO and a older lld than what ships before the addition of that option in the tree. We could add logic for checking if the linker flags are correct - but I think when using LTO multi-stage builds are not uncommon.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80493

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -13,7 +13,7 @@
 include(CheckSymbolExists)
 include(CMakeDependentOption)
 
-if(CMAKE_LINKER MATCHES "lld-link" OR (WIN32 AND LLVM_USE_LINKER STREQUAL "lld") OR LLVM_ENABLE_LLD)
+if(CMAKE_LINKER MATCHES "lld-link" OR MSVC AND (LLVM_USE_LINKER STREQUAL "lld" OR LLVM_ENABLE_LLD))
   set(LINKER_IS_LLD_LINK TRUE)
 else()
   set(LINKER_IS_LLD_LINK FALSE)
@@ -941,7 +941,7 @@
   message(FATAL_ERROR "LLVM_BUILD_INSTRUMENTED and LLVM_BUILD_INSTRUMENTED_COVERAGE cannot both be specified")
 endif()
 
-if(LLVM_ENABLE_LTO AND LLVM_ON_WIN32 AND NOT LINKER_IS_LLD_LINK)
+if(LLVM_ENABLE_LTO AND LLVM_ON_WIN32 AND NOT LINKER_IS_LLD_LINK AND NOT MINGW)
   message(FATAL_ERROR "When compiling for Windows, LLVM_ENABLE_LTO requires using lld as the linker (point CMAKE_LINKER at lld-link.exe)")
 endif()
 if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
@@ -956,7 +956,7 @@
   if(APPLE)
     append("-Wl,-cache_path_lto,${PROJECT_BINARY_DIR}/lto.cache"
            CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
-  elseif(UNIX AND LLVM_USE_LINKER STREQUAL "lld")
+  elseif(UNIX OR MINGW AND LLVM_USE_LINKER STREQUAL "lld")
     append("-Wl,--thinlto-cache-dir=${PROJECT_BINARY_DIR}/lto.cache"
            CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
   elseif(LLVM_USE_LINKER STREQUAL "gold")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80493.265935.patch
Type: text/x-patch
Size: 1499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200524/c3830ada/attachment-0001.bin>


More information about the llvm-commits mailing list