[PATCH] D55056: [CMake] Default options for faster executables on MSVC

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 22 17:33:05 PDT 2019


aganea updated this revision to Diff 200578.
aganea added a comment.

Reopening with fixes for LLDB.

This build break was caused by the liblldb.dll used along with /MT (static CRT) which is usually not advisable. `lldb.exe` was initializing a handle for the stdout stream (using `_pipe`) and consuming it in `liblldb.dll`. /MT evidently creates internal states that are different across module bounds (exe, dll), which causes the stdout handle (__pioinfo <https://docs.microsoft.com/en-us/cpp/c-runtime-library/internal-crt-globals-and-functions?view=vs-2019> in this case) to point to separate copies in memory.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55056/new/

https://reviews.llvm.org/D55056

Files:
  CMakeLists.txt
  cmake/modules/ChooseMSVCCRT.cmake
  cmake/modules/HandleLLVMOptions.cmake


Index: cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -418,6 +418,14 @@
   # "Enforce type conversion rules".
   append("/Zc:rvalueCast" CMAKE_CXX_FLAGS)
 
+  if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND NOT LLVM_ENABLE_INCREMENTAL_LINK)
+    foreach(CONFIG RELEASE RELWITHDEBINFO MINSIZEREL)
+      foreach(FLAG EXE MODULE SHARED STATIC)
+        string(REGEX REPLACE "[-/](INCREMENTAL:YES|INCREMENTAL:NO|INCREMENTAL)" "/INCREMENTAL:NO" CMAKE_${FLAG}_LINKER_FLAGS_${CONFIG} "${CMAKE_${FLAG}_LINKER_FLAGS_${CONFIG}}")
+      endforeach()
+    endforeach()
+  endif()
+
   if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT LLVM_ENABLE_LTO)
     # clang-cl and cl by default produce non-deterministic binaries because
     # link.exe /incremental requires a timestamp in the .obj file.  clang-cl
Index: cmake/modules/ChooseMSVCCRT.cmake
===================================================================
--- cmake/modules/ChooseMSVCCRT.cmake
+++ cmake/modules/ChooseMSVCCRT.cmake
@@ -66,6 +66,21 @@
       get_current_crt(LLVM_USE_CRT_${build}
         MSVC_CRT_REGEX
         CMAKE_CXX_FLAGS_${build})
+
+      if (LLVM_TOOL_LLDB_BUILD)
+        if ((NOT ${build} STREQUAL "DEBUG") AND (LLVM_TOOL_CLANG_BUILD OR LLVM_TOOL_LLD_BUILD))
+          message(WARNING "Disabling /MT required by LLDB. This will impact runtime performance for Clang or LLD. Preferably build them separately.")
+        endif()
+      else()
+        # Make /MT the default in Release builds to make them faster
+        # and avoid the DLL function thunking.
+        if ((${build} STREQUAL "MINSIZEREL") OR
+            (${build} STREQUAL "RELEASE") OR
+            (${build} STREQUAL "RELWITHDEBINFO"))
+            set(LLVM_USE_CRT_${build} "MT")
+        endif()
+      endif()
+
       set(LLVM_USE_CRT_${build}
         "${LLVM_USE_CRT_${build}}"
         CACHE STRING "Specify VC++ CRT to use for ${build_type} configurations."
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -428,6 +428,10 @@
 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
 
+if (MSVC)
+   option(LLVM_ENABLE_INCREMENTAL_LINK "Link incrementally. Enabling it might produce slower executables." OFF)
+endif()
+
 option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)
 
 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55056.200578.patch
Type: text/x-patch
Size: 2634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190523/fc81f650/attachment.bin>


More information about the llvm-commits mailing list