[llvm] ef4cfd8 - Pass -gcodeview-ghash when using clang-cl and lld-link

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Thu May 27 21:02:38 PDT 2021


Author: Reid Kleckner
Date: 2021-05-27T20:49:17-07:00
New Revision: ef4cfd83223890fdbd69fbc9899089365f4588b4

URL: https://github.com/llvm/llvm-project/commit/ef4cfd83223890fdbd69fbc9899089365f4588b4
DIFF: https://github.com/llvm/llvm-project/commit/ef4cfd83223890fdbd69fbc9899089365f4588b4.diff

LOG: Pass -gcodeview-ghash when using clang-cl and lld-link

This precomputes some hashes that LLD uses for type merging to speed up
linking when PDBs are enabled. Only do this if any kind of /DEBUG flag
is passed to the linker. -gcodeview-ghash is orthogonal to /Z7, -g, -g1,
or -gmlt, so it is safe to set it independently from those flags. It
will not increase debug info emission.

Differential Revision: https://reviews.llvm.org/D103287

Added: 
    

Modified: 
    llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index e7a1e9ea38e79..c433117f89264 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -474,6 +474,23 @@ if( MSVC )
           CMAKE_SHARED_LINKER_FLAGS)
   endif()
 
+  # Get all linker flags in upper case form so we can search them.
+  set(all_linker_flags_uppercase
+    "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
+  string(TOUPPER "${all_linker_flags_uppercase}" all_linker_flags_uppercase)
+
+  if (CLANG_CL AND LINKER_IS_LLD)
+    # If we are using clang-cl with lld-link and /debug is present in any of the
+    # linker flag variables, pass -gcodeview-ghash to the compiler to speed up
+    # linking. This flag is orthogonal from /Zi, /Z7, and other flags that
+    # enable debug info emission, and only has an effect if those are also in
+    # use.
+    string(FIND "${all_linker_flags_uppercase}" "/DEBUG" linker_flag_idx)
+    if (${linker_flag_idx} GREATER -1)
+      add_flag_if_supported("-gcodeview-ghash" GCODEVIEW_GHASH)
+    endif()
+  endif()
+
   # Disable string literal const->non-const type conversion.
   # "When specified, the compiler requires strict const-qualification
   # conformance for pointers initialized by using string literals."
@@ -499,13 +516,7 @@ if( MSVC )
     if (SUPPORTS_BREPRO)
       # Check if /INCREMENTAL is passed to the linker and complain that it
       # won't work with /Brepro.
-      string(TOUPPER "${CMAKE_EXE_LINKER_FLAGS}" upper_exe_flags)
-      string(TOUPPER "${CMAKE_MODULE_LINKER_FLAGS}" upper_module_flags)
-      string(TOUPPER "${CMAKE_SHARED_LINKER_FLAGS}" upper_shared_flags)
-
-      string(FIND "${upper_exe_flags} ${upper_module_flags} ${upper_shared_flags}"
-        "/INCREMENTAL" linker_flag_idx)
-
+      string(FIND "${all_linker_flags_uppercase}" "/INCREMENTAL" linker_flag_idx)
       if (${linker_flag_idx} GREATER -1)
         message(WARNING "/Brepro not compatible with /INCREMENTAL linking - builds will be non-deterministic")
       else()


        


More information about the llvm-commits mailing list