From d922bf573a6c0cf0c98748b813ab7f05e3f991ae Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 17 Jul 2026 09:55:13 -0700 Subject: [PATCH] Use MSVC_DEBUG_INFORMATION_FORMAT for CoreCLR object libraries Convert the remaining hand-rolled /Z7 compile options on the CoreCLR data descriptor and NativeAOT GC OBJECT libraries to the MSVC_DEBUG_INFORMATION_FORMAT Embedded target property, matching the approach used for the host object libraries. The property (introduced in CMake 3.25) is usable now that the repo minimum is 3.26, and keeps debug-info handling consistent across the object libraries that ship into static libraries. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c575f5c4-c35f-4fcb-9311-d65a626b8191 --- src/coreclr/clrdatadescriptors.cmake | 21 ++++++------------- .../nativeaot/Runtime/Full/CMakeLists.txt | 4 ++-- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/coreclr/clrdatadescriptors.cmake b/src/coreclr/clrdatadescriptors.cmake index 3a40c12dcc0840..70b9c274dad871 100644 --- a/src/coreclr/clrdatadescriptors.cmake +++ b/src/coreclr/clrdatadescriptors.cmake @@ -90,20 +90,11 @@ function(generate_data_descriptors) target_include_directories(${LIBRARY} PRIVATE ${GENERATED_CDAC_DESCRIPTOR_DIR}) if(MSVC) - # Give this OBJECT library a deterministic, per-target compile PDB. Without this, - # MSVC writes debug info to the default `vc140.pdb`, which does not travel with - # the .obj files when they are archived into a static library (e.g. - # Runtime.ServerGC.lib). Downstream linkers - notably the NativeAOT publish - # of ILCompiler/crossgen2/ilasm/mscordaccore_universal - then emit LNK4099 - # ("PDB ... was not found"), which is fatal under /WX in the VMR build. - set_target_properties(${LIBRARY} PROPERTIES - COMPILE_PDB_NAME "${LIBRARY}" - COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$") - # Even with a per-target PDB name, the external PDB stays in the producer's - # binary dir and is not visible to downstream linkers consuming the static lib. - # Embed CodeView debug info directly into each .obj (/Z7) so the debug data - # travels with the object when it is archived into the static library, removing - # the need for the linker to find a separate PDB and silencing LNK4099. - target_compile_options(${LIBRARY} PRIVATE /Z7) + # Embed debug info in the object files (/Z7). CMake does not assign a compile + # PDB to OBJECT libraries, so the objects archived into a static library (e.g. + # Runtime.ServerGC.lib) would otherwise reference an absent vc140.pdb, producing + # LNK4099 for the NativeAOT publish of ILCompiler/crossgen2/ilasm/mscordaccore_universal, + # which is fatal under /WX in the VMR build. + set_target_properties(${LIBRARY} PROPERTIES MSVC_DEBUG_INFORMATION_FORMAT Embedded) endif() endfunction(generate_data_descriptors) diff --git a/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt index 9701ad1713381e..0bc8879470db75 100644 --- a/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt @@ -105,8 +105,8 @@ if (CLR_CMAKE_TARGET_WIN32) # objects archived into Runtime.WorkstationGC/Runtime.ServerGC would otherwise # reference a vc140.pdb that is absent when these static libs are statically # linked by the AOT compiler publish projects, producing LNK4099. - target_compile_options(Runtime.GC.Workstation PRIVATE /Z7) - target_compile_options(Runtime.GC.Server PRIVATE /Z7) + set_target_properties(Runtime.GC.Workstation PROPERTIES MSVC_DEBUG_INFORMATION_FORMAT Embedded) + set_target_properties(Runtime.GC.Server PROPERTIES MSVC_DEBUG_INFORMATION_FORMAT Embedded) endif (CLR_CMAKE_TARGET_WIN32) add_library(Runtime.WorkstationGC STATIC