Skip to content

Commit 3c126e6

Browse files
authored
Change CoreCLR diagnostic resource production to remove cross-component build dependency (#67018)
1 parent 96d1df6 commit 3c126e6

23 files changed

+246
-484
lines changed

src/coreclr/build-runtime.cmd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,9 @@ if %__BuildNative% EQU 1 (
528528
if /i "%__BuildArch%" == "x86" ( set __VCBuildArch=x86 )
529529
if /i "%__BuildArch%" == "arm" (
530530
set __VCBuildArch=x86_arm
531-
set ___CrossBuildDefine="-DCLR_CMAKE_CROSS_ARCH=1" "-DCLR_CMAKE_CROSS_HOST_ARCH=%__CrossArch%"
532531
)
533532
if /i "%__BuildArch%" == "arm64" (
534533
set __VCBuildArch=x86_arm64
535-
if defined __CrossArch (
536-
set ___CrossBuildDefine="-DCLR_CMAKE_CROSS_ARCH=1" "-DCLR_CMAKE_CROSS_HOST_ARCH=%__CrossArch%"
537-
)
538534
)
539535

540536
echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch!
@@ -549,7 +545,7 @@ if %__BuildNative% EQU 1 (
549545
set __ExtraCmakeArgs="-DCMAKE_BUILD_TYPE=!__BuildType!"
550546
)
551547

552-
set __ExtraCmakeArgs=!__ExtraCmakeArgs! !___CrossBuildDefine! "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_PATH=%__PgoOptDataPath%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" %__CMakeArgs%
548+
set __ExtraCmakeArgs=!__ExtraCmakeArgs! "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_PATH=%__PgoOptDataPath%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" %__CMakeArgs%
553549
call "%__RepoRootDir%\eng\native\gen-buildsys.cmd" "%__ProjectDir%" "%__IntermediatesDir%" %__VSVersion% %__BuildArch% !__ExtraCmakeArgs!
554550
if not !errorlevel! == 0 (
555551
echo %__ErrMsgPrefix%%__MsgPrefix%Error: failed to generate native component build project!

src/coreclr/crosscomponents.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,3 @@ if(NOT CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_OSX AND NOT FEATURE_CROSSBITN
4242
COMPONENT crosscomponents
4343
)
4444
endif()
45-
46-
if (CLR_CMAKE_TARGET_WIN32 AND NOT CLR_CMAKE_CROSS_ARCH)
47-
add_dependencies(crosscomponents InjectResource GenClrDebugResource)
48-
endif()

src/coreclr/debug/runtimeinfo/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function(generate_module_index Target ModuleIndexFile)
2929
target_sources(runtimeinfo PRIVATE ${ModuleIndexFile})
3030
endfunction(generate_module_index)
3131

32-
generate_module_index(coreclr ${CMAKE_CURRENT_BINARY_DIR}/runtimemoduleindex.h)
3332
if(NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
33+
generate_module_index(coreclr ${CMAKE_CURRENT_BINARY_DIR}/runtimemoduleindex.h)
3434
add_dependencies(runtimeinfo inject_debug_resources_coreclr)
3535
generate_module_index(mscordaccore ${CMAKE_CURRENT_BINARY_DIR}/dacmoduleindex.h)
3636
generate_module_index(mscordbi ${CMAKE_CURRENT_BINARY_DIR}/dbimoduleindex.h)

src/coreclr/dlls/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ if(CLR_CMAKE_TARGET_WIN32)
22
add_subdirectory(clretwrc)
33
endif(CLR_CMAKE_TARGET_WIN32)
44
add_subdirectory(dbgshim)
5-
if (NOT (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_I386 OR CLR_CMAKE_TARGET_ARCH_ARM) AND CLR_CMAKE_HOST_ARCH_AMD64))
5+
if (NOT (CLR_CMAKE_TARGET_WIN32 AND FEATURE_CROSSBITNESS))
66
add_subdirectory(mscordbi)
77
add_subdirectory(mscordac)
8+
add_subdirectory(mscoree)
89
endif()
9-
add_subdirectory(mscoree)
1010
add_subdirectory(mscorpe)
1111
add_subdirectory(mscorrc)

src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,26 @@ target_link_libraries(coreclr_static PUBLIC ${CORECLR_LIBRARIES} clrjit_static c
173173
target_compile_definitions(coreclr_static PUBLIC CORECLR_EMBEDDED)
174174

175175
if(CLR_CMAKE_TARGET_WIN32)
176+
set(CLRDEBUGINFO_RESOURCE_PATH ${CMAKE_CURRENT_BINARY_DIR}/clr_debug_resource.bin)
177+
178+
add_custom_target(
179+
clr_debug_resources
180+
DEPENDS mscordaccore mscordbi
181+
# make CLRDEBUGINFO resource
182+
COMMAND powershell -NoProfile -ExecutionPolicy ByPass -File "${CMAKE_CURRENT_SOURCE_DIR}/GenClrDebugResource.ps1" -dac $<TARGET_FILE:mscordaccore> -dbi $<TARGET_FILE:mscordbi> -out ${CLRDEBUGINFO_RESOURCE_PATH}
183+
)
184+
185+
configure_file(dump_helper_resource.rc.in ${CMAKE_CURRENT_BINARY_DIR}/dump_helper_resource.rc)
186+
187+
set(EMBEDDED_MINIDUMP_AUXILIARY_PROVIDER ON)
188+
configure_file(dump_helper_resource.rc.in ${CMAKE_CURRENT_BINARY_DIR}/dump_helper_resource_embedded_minidump_provider.rc)
189+
190+
target_sources(coreclr PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/dump_helper_resource.rc)
191+
target_sources(coreclr_static PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/dump_helper_resource_embedded_minidump_provider.rc)
192+
193+
add_dependencies(coreclr clr_debug_resources)
194+
add_dependencies(coreclr_static clr_debug_resources)
195+
176196
# Add dac table & debug resource to coreclr
177197
get_include_directories(INC_DIR)
178198
get_compile_definitions(PREPROCESS_DEFINITIONS)
@@ -191,10 +211,9 @@ if(CLR_CMAKE_TARGET_WIN32)
191211
clr_unknown_arch()
192212
endif()
193213

194-
195-
if (CLR_CMAKE_CROSS_ARCH)
196-
include(${CMAKE_INSTALL_PREFIX}/${CLR_CMAKE_CROSS_HOST_ARCH}/dactabletools/dactabletools.cmake)
197-
endif()
214+
# dacess.h defines this constant
215+
# The value is a constract between the DAC and the runtime
216+
set (DACCESS_TABLE_RESOURCE COREXTERNALDATAACCESSRESOURCE)
198217

199218
add_custom_command(
200219
DEPENDS coreclr mscordaccore mscordbi ${CLR_DIR}/debug/daccess/daccess.cpp
@@ -203,17 +222,10 @@ if(CLR_CMAKE_TARGET_WIN32)
203222

204223
# make and inject dactable for coreclr
205224
COMMAND cmd /c ${CLR_REPO_ROOT_DIR}/dotnet.cmd exec ${CMAKE_INSTALL_PREFIX}/DacTableGen/DacTableGen.dll /dac:${CMAKE_CURRENT_BINARY_DIR}/daccess.i /pdb:$<TARGET_PDB_FILE:coreclr> /dll:$<TARGET_FILE:coreclr> /bin:${CMAKE_CURRENT_BINARY_DIR}/wks.bin
206-
COMMAND InjectResource /bin:${CMAKE_CURRENT_BINARY_DIR}/wks.bin /dll:$<TARGET_FILE:coreclr>
207-
208-
# make CLRDEBUGINFO resource and inject into coreclr
209-
COMMAND GenClrDebugResource /dac:$<TARGET_FILE:mscordaccore> /dbi:$<TARGET_FILE:mscordbi> /sku:onecoreclr /out:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin
210-
COMMAND InjectResource /bin:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin /dll:$<TARGET_FILE:coreclr> /name:CLRDEBUGINFO
211-
212-
# inject MINIDUMP_AUXILIARY_PROVIDER into coreclr
213-
COMMAND InjectResource /bin:${CMAKE_CURRENT_SOURCE_DIR}/dump_helper_resource.bin /dll:$<TARGET_FILE:coreclr> /name:MINIDUMP_AUXILIARY_PROVIDER
225+
COMMAND cmd /c ${CLR_REPO_ROOT_DIR}/dotnet.cmd exec ${CMAKE_INSTALL_PREFIX}/InjectResource/InjectResource.dll --bin ${CMAKE_CURRENT_BINARY_DIR}/wks.bin --image $<TARGET_FILE:coreclr> --name ${DACCESS_TABLE_RESOURCE}
214226

215227
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/inject_debug_resources_coreclr.timestamp
216-
COMMENT Add dactable, debug resources, and dump helper resources to coreclr
228+
COMMENT Add dactable to coreclr
217229
)
218230

219231
if(NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
@@ -228,14 +240,10 @@ if(CLR_CMAKE_TARGET_WIN32)
228240

229241
# make and inject dactable for singlefilehost
230242
COMMAND cmd /c ${CLR_REPO_ROOT_DIR}/dotnet.cmd exec ${CMAKE_INSTALL_PREFIX}/DacTableGen/DacTableGen.dll /dac:${CMAKE_CURRENT_BINARY_DIR}/daccess.i /pdb:$<TARGET_PDB_FILE:singlefilehost> /dll:$<TARGET_FILE:singlefilehost> /bin:${CMAKE_CURRENT_BINARY_DIR}/sfh.bin
231-
COMMAND InjectResource /bin:${CMAKE_CURRENT_BINARY_DIR}/sfh.bin /dll:$<TARGET_FILE:singlefilehost>
232-
233-
# make CLRDEBUGINFO resource and inject into singlefilehost
234-
COMMAND GenClrDebugResource /dac:$<TARGET_FILE:mscordaccore> /dbi:$<TARGET_FILE:mscordbi> /sku:onecoreclr /out:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin
235-
COMMAND InjectResource /bin:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin /dll:$<TARGET_FILE:singlefilehost> /name:CLRDEBUGINFO
243+
COMMAND cmd /c ${CLR_REPO_ROOT_DIR}/dotnet.cmd exec ${CMAKE_INSTALL_PREFIX}/InjectResource/InjectResource.dll --bin ${CMAKE_CURRENT_BINARY_DIR}/sfh.bin --image $<TARGET_FILE:singlefilehost> --name ${DACCESS_TABLE_RESOURCE}
236244

237245
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/inject_debug_resources_singlefilehost.timestamp
238-
COMMENT Add dactable, debug resources, and dump helper resources to singlefilehost
246+
COMMENT Add dactable to singlefilehost
239247
)
240248

241249
if(NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
param (
2+
[string]
3+
$dac,
4+
[string]
5+
$dbi,
6+
[string]
7+
$out
8+
)
9+
10+
function Parse-Int {
11+
param (
12+
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
13+
[string]$hexValue
14+
)
15+
return [System.Int32]::Parse($hexValue, [System.Globalization.NumberStyles]::HexNumber)
16+
}
17+
18+
$clrDebugResource = [System.IO.BinaryWriter]::new([System.IO.File]::OpenWrite($out))
19+
20+
try {
21+
# We're creating the resource with the following layout (represented as a C struct)
22+
# struct CLR_DEBUG_RESOURCE
23+
# {
24+
# int version;
25+
# GUID clrSkuGuid;
26+
# int dacTimeStamp;
27+
# int dacImageSize;
28+
# int dbiTimeStamp;
29+
# int dacImageSize;
30+
# };
31+
32+
# Write the debug resource version
33+
$clrDebugResource.Write(0);
34+
# Write the GUID for CoreCLR (should match the CLR_ID_ONECORE_CLR GUID in clrinternal.idl)
35+
$clrDebugResource.Write([System.Guid]::Parse("{0xb1ee760d,0x6c4a,0x4533,{0xba,0x41,0x6f,0x4f,0x66,0x1f,0xab,0xaf}}").ToByteArray())
36+
[int]$dacTimeStamp = dumpbin $dac /HEADERS | Select-String "([0-9A-Fa-f]+) time date stamp" | %{ $_.Matches.Groups[1].Value } | Parse-Int
37+
[int]$dacImageSize = dumpbin $dac /HEADERS | Select-String "([0-9A-Fa-f]+) size of image" | %{ $_.Matches.Groups[1].Value } | Parse-Int
38+
[int]$dbiTimeStamp = dumpbin $dbi /HEADERS | Select-String "([0-9A-Fa-f]+) time date stamp" | %{ $_.Matches.Groups[1].Value } | Parse-Int
39+
[int]$dbiImageSize = dumpbin $dbi /HEADERS | Select-String "([0-9A-Fa-f]+) size of image" | %{ $_.Matches.Groups[1].Value } | Parse-Int
40+
$clrDebugResource.Write($dacTimeStamp)
41+
$clrDebugResource.Write($dacImageSize)
42+
$clrDebugResource.Write($dbiTimeStamp)
43+
$clrDebugResource.Write($dbiImageSize)
44+
}
45+
finally {
46+
$clrDebugResource.Dispose()
47+
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
dump\_helper\_resource.bin in this folder is a text file with a single 0 byte appended on the end using a hex-editor. It is unlikely it will need to be modified frequently if at all,
2-
but if that changes we can always create a little nicer tooling for it.
3-
4-
dump\_helper\_resource.bin is used to populate the DUMP\_HELPER resource inside coreclr.dll on Windows. When an application crashes, Windows MinidumpWriteDump is planning to scan
1+
dump\_helper\_resource.rc is used to populate the MINIDUMP\_AUXILIARY\_PROVIDER resource inside coreclr.dll on Windows. When an application crashes, Windows MinidumpWriteDump is planning to scan
52
modules looking for this resource. The content of the resource is expected to be the name of a dll in the same folder, encoded in UTF8, null terminated, that implements the
63
CLRDataCreateInterface function. For OS security purposes MinidumpWriteDump will do an authenticode signing check before loading the indicated binary, however if your build isn't
74
signed you can get around this limitation by registering it at HKLM\Software\Microsoft\WindowsNT\CurrentVersion\MiniDumpAuxilliaryDlls.
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <windows.h>
2+
3+
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
4+
5+
#cmakedefine EMBEDDED_MINIDUMP_AUXILIARY_PROVIDER
6+
7+
#ifndef EMBEDDED_MINIDUMP_AUXILIARY_PROVIDER
8+
9+
MINIDUMP_AUXILIARY_PROVIDER RCDATA { "mscordaccore.dll\0" }
10+
11+
#endif
12+
13+
CLRDEBUGINFO RCDATA @CLRDEBUGINFO_RESOURCE_PATH@

src/coreclr/runtime-prereqs.proj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<AssemblyName>.NET Runtime</AssemblyName>
88
</PropertyGroup>
99

10-
<ItemGroup>
11-
<ProjectReference Condition="'$(TargetOS)' == 'Windows'" Include="tools/SOS/DacTableGen/DacTableGen.csproj" />
10+
<ItemGroup Condition="'$(TargetOS)' == 'Windows'">
11+
<ProjectReference Include="tools/SOS/DacTableGen/DacTableGen.csproj" />
12+
<ProjectReference Include="tools/InjectResource/InjectResource.csproj" />
1213
</ItemGroup>
1314

1415
<Import Project="$(RepositoryEngineeringDir)versioning.targets" />

src/coreclr/tools/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
add_subdirectory(SOS)
22
add_subdirectory(superpmi)
33

4-
if (CLR_CMAKE_TARGET_WIN32 AND NOT CLR_CMAKE_CROSS_ARCH)
5-
add_subdirectory(GenClrDebugResource)
6-
add_subdirectory(InjectResource)
7-
8-
install(EXPORT dactabletools DESTINATION dactabletools COMPONENT crosscomponents)
9-
endif()
104
if (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64)
115
add_subdirectory(StressLogAnalyzer)
126
endif()

src/coreclr/tools/GenClrDebugResource/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)