[NativeAOT] Add cDAC data descriptor infrastructure#126972
[NativeAOT] Add cDAC data descriptor infrastructure#126972max-charlamb merged 29 commits intomainfrom
Conversation
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
Pull request overview
Adds cDAC contract descriptor generation to the NativeAOT runtime, plus an ILC-emitted managed sub-descriptor so diagnostic tools can inspect NativeAOT runtime/managed state via the shared contract mechanism.
Changes:
- Integrates NativeAOT cDAC contract descriptor (and GC sub-descriptors) into the NativeAOT CMake build and runtime libraries.
- Introduces a managed type layout sub-descriptor emitted by ILC (
DotNetManagedContractDescriptor) and wires it into the NativeAOT descriptor as a sub-descriptor. - Exposes select private NativeAOT runtime offsets/constants to the descriptor via the
cdac_data<T>friend pattern and exports the main contract descriptor symbol for diagnostics.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler/Program.cs | Adds the managed descriptor root provider to ILC compilation roots. |
| src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj | Includes new managed descriptor provider/node sources in the build. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ManagedDataDescriptorProvider.cs | Registers managed types to be described and roots the descriptor + JSON blob. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ManagedDataDescriptorNode.cs | Emits a ContractDescriptor-shaped symbol containing JSON type layout data. |
| src/coreclr/nativeaot/Runtime/threadstore.h | Exposes ThreadStore private offsets for descriptor generation via cdac_data<>. |
| src/coreclr/nativeaot/Runtime/inc/MethodTable.h | Exposes MethodTable offsets and flag constants for descriptor consumption via cdac_data<>. |
| src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.inc | Defines the NativeAOT data descriptor types/globals/contracts and sub-descriptors. |
| src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.h | Provides includes and declares the managed sub-descriptor symbol address for inclusion. |
| src/coreclr/nativeaot/Runtime/datadescriptor/CMakeLists.txt | Adds descriptor generation targets for NativeAOT runtime + GC (wks/svr). |
| src/coreclr/nativeaot/Runtime/RuntimeInstance.h | Exposes RuntimeInstance private offsets via cdac_data<>. |
| src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt | Links the generated descriptor libraries into WorkstationGC/ServerGC runtime libs. |
| src/coreclr/nativeaot/Runtime/CMakeLists.txt | Adds the datadescriptor subdirectory to the NativeAOT runtime build (non-WASM). |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets | Exports DotNetRuntimeContractDescriptor symbol for diagnostics on all OSes. |
Comments suppressed due to low confidence (1)
src/coreclr/nativeaot/Runtime/datadescriptor/CMakeLists.txt:73
target_compile_definitionsentries should be raw preprocessor symbols (e.g.,SERVER_GC), not compiler flags. Passing-DSERVER_GChere will typically result in an invalid definition being forwarded to the compiler. UseSERVER_GC(orSERVER_GC=1) instead.
9462d5c to
f226bc3
Compare
This comment has been minimized.
This comment has been minimized.
Walk ContainingType chain to produce fully-qualified names with + separator (e.g., System.Foo.Outer+Inner). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jkotas
left a comment
There was a problem hiding this comment.
@MichalStrehovsky Could you please signoff as well?
This comment has been minimized.
This comment has been minimized.
…ed descriptor - Remove MethodTable flag constant globals from datadescriptor.inc and cdac_data<MethodTable> in MethodTable.h — these are already defined as part of the contract in MethodTableFlags_1.cs - Add baseline and contracts properties to managed sub-descriptor JSON for self-describing format consistency Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🤖 Copilot Code Review — PR #126972Note This review was generated by GitHub Copilot. Holistic AssessmentMotivation: This PR adds cDAC (data access component) data descriptor infrastructure to NativeAOT, enabling diagnostic tools (debuggers, crash dump analyzers) to inspect NativeAOT runtime state without symbols. This is well-motivated — it's a prerequisite for cDAC support in NativeAOT, analogous to what already exists for CoreCLR. Approach: The approach is sound — it reuses the existing Summary: Detailed Findings
|
MichalStrehovsky
left a comment
There was a problem hiding this comment.
Looks good otherwise! What is the testing strategy for this? The DotNetRuntimeDebugHeader was pretty much untested because the code to read it lived elsewhere. Do we have the ability to test this in the dotnet/runtime repo?
Some of these values are read by the existing cDAC contracts, some will be read by new contracts (in a different repo). We don't have tests automated yet, but it is one of the next items I am working on. |
- Simplify GetSection to always use ReadOnlyDataSection - Add Debug.Assert for header size before emitting JSON - Remove Phase override (default unordered is fine) - Gate ManagedDataDescriptorProvider on EnableDebugInfo Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Revert GetSection to use DataSection on non-Windows platforms. Nodes with pointer relocations require writable sections on ELF. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Note
This PR was created with assistance from GitHub Copilot.
Summary
Adds the cDAC data descriptor infrastructure for NativeAOT, enabling diagnostic tools (cDAC reader, SOS) to inspect NativeAOT runtime state through the same contract-based mechanism used by CoreCLR.
Changes
Native data descriptor (
datadescriptor.inc)cdac_data<>friend patternSTRESS_LOG)ILC managed type descriptor (
ManagedDataDescriptorNode)ContractDescriptor(DotNetManagedContractDescriptor) with JSON-encoded type layouts usingUtf8JsonWriter[DataContract]attribute on types inMetadataManager.GetTypesWithEETypes()System.Threading.Thread->System_Threading_ThreadCDAC_GLOBAL_SUB_DESCRIPTORSystem.Threading.Threadfields (ManagedThreadId,Name)GC sub-descriptor
GC_INTERFACE_*_VERSIONbeforeGC_InitializeGC_DESCRIPTORcompile definition (guarded on non-WASM)Runtime.ServerGC(ServerGC compiles both paths)#ifdef HEAP_ANALYZEguards in shared GC datadescriptor files (NativeAOT disablesHEAP_ANALYZE)Attribute-based type discovery
[DataContract]attribute inSystem.Diagnosticsnamespace (internal, targets Class/Struct/Field)System.Threading.Threadfields inThread.NativeAot.csGetTypesWithEETypes()ensuring only types with MethodTables are includedBuild integration
clrdatadescriptors.cmakeinfrastructurenativeaot_runtime_includesinterface library captures all Runtime include paths for cross-target compilationcdac-build-toolenabled for NativeAOT viaClrNativeAotSubsetinruntime.proj--export-dynamic-symbolinMicrosoft.NETCore.Native.targets(WASM excluded)cdacdata.htemplate inRuntime/inc/(matching GC pattern for self-contained builds)Key design decisions
n1for NativeAOT-specific contracts,c1/c2for contracts shared with CoreCLR (same version)SPTR_DECL/SPTR_IMPLfors_pThreadStorestatic member, matching CoreCLR patternManagedDataDescriptorNodedoes not overrideCompareToImpl— follows the ILC singleton pattern (base class throws on duplicates)slist.hshared between CoreCLR VM and NativeAOT RuntimeValidation
build.cmd clr.aot+libs -rc release— 0 errors, 0 warningsRuntime.WorkstationGC.libvia dumpbin