From ed33140be61fd95ec7343ced561aaab122f804ba Mon Sep 17 00:00:00 2001 From: Alex Sepkowski Date: Tue, 18 Aug 2026 17:17:05 -0700 Subject: [PATCH] [Win] Enable function-level linking for Release Compile C and C++ Release functions into individual COMDATs so the existing /OPT:REF linker setting can discard unused functions from referenced object files. This resolves the long-standing MSVC dead-strip FIXME. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0f4d0e10-e926-4bce-b36b-0abebc08f6dc --- cmake/modules/HandleLLVMOptions.cmake | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index d5769abce7..03b9957ffd 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -362,8 +362,9 @@ if( MSVC ) append("/analyze" CMAKE_CXX_FLAGS) endif () - # Change release to always build debug information out-of-line, but - # also enable Reference optimization, ie dead function elimination. + # Change release to always build debug information out-of-line and enable + # function-level dead code elimination. + append("/Gy" CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE) if (NOT CMAKE_MSVC_DEBUG_INFORMATION_FORMAT) append("/Zi" CMAKE_CXX_FLAGS_RELEASE) append("/DEBUG /OPT:REF" CMAKE_SHARED_LINKER_FLAGS_RELEASE) @@ -609,9 +610,6 @@ endif() # HLSL Change Ends # Add flags for add_dead_strip(). -# FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF? -# But MinSizeRel seems to add that automatically, so maybe disable these -# flags instead if LLVM_NO_DEAD_STRIP is set. if(NOT CYGWIN AND NOT WIN32) if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")