Skip to content

[NativeAOT] Add managed type sub-descriptor for cDAC#127025

Closed
max-charlamb wants to merge 1 commit intodev/max-charlamb/nativeaot-datadescriptorfrom
dev/max-charlamb/managed-type-descriptors
Closed

[NativeAOT] Add managed type sub-descriptor for cDAC#127025
max-charlamb wants to merge 1 commit intodev/max-charlamb/nativeaot-datadescriptorfrom
dev/max-charlamb/managed-type-descriptors

Conversation

@max-charlamb
Copy link
Copy Markdown
Member

Note

This PR was created with assistance from GitHub Copilot.

Summary

Adds ILC infrastructure to emit managed type field offsets as a cDAC sub-descriptor, enabling diagnostic tools to inspect managed type instances without runtime metadata (critical for NativeAOT where metadata may be stripped).

Stacked on #127024 — review that PR first.

Changes

Attribute-based type discovery

Instead of hardcoding BCL implementation details in the compiler (as flagged in #126972 review), types opt-in via internal attributes in NativeAOT CoreLib:

  • [CdacType(""ManagedThread"")] on the type — specifies the cDAC descriptor type name
  • [CdacField(""ManagedThreadId"")] on fields — specifies the cDAC field name (defaults to field name if omitted)

ILC discovers annotated types by scanning the system module metadata, following the same pattern as EagerStaticClassConstructionAttribute.

Validation

The provider fails fast on misconfiguration:

  • Empty/null descriptor names
  • Generic types (not supported — layout depends on instantiation)
  • Duplicate descriptor type or field names

Files

  • CdacTypeAttribute.cs / CdacFieldAttribute.cs — internal attributes
  • Thread.NativeAot.cs — annotated with ManagedThread descriptor
  • ManagedDataDescriptorNode.cs — emits ContractDescriptor with JSON layout
  • ManagedDataDescriptorProvider.cs — attribute scanning and registration
  • datadescriptor.h/.inc — managed sub-descriptor reference

Validation

  • Build: build.cmd clr.aot+libs -rc release — 0 errors, 0 warnings
  • cDAC reader tests: all passed
  • tools.cdac tests: all passed

Add ILC infrastructure to emit managed type field offsets as a cDAC
sub-descriptor, enabling diagnostic tools to inspect managed type
instances without runtime metadata.

Types opt-in via [CdacType] and [CdacField] attributes in CoreLib.
ILC discovers annotated types at compile time, computes field offsets,
and emits a ContractDescriptor (DotNetManagedContractDescriptor) that
the native runtime references as a sub-descriptor.

Includes:
- CdacTypeAttribute / CdacFieldAttribute in NativeAOT CoreLib
- ManagedDataDescriptorNode: emits ContractDescriptor with JSON layout
- ManagedDataDescriptorProvider: attribute-based type discovery with
  validation (rejects generics, duplicates, empty names)
- Thread.NativeAot.cs annotated with ManagedThread descriptor fields

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@max-charlamb max-charlamb deleted the dev/max-charlamb/managed-type-descriptors branch April 16, 2026 20:53
@max-charlamb max-charlamb restored the dev/max-charlamb/managed-type-descriptors branch April 16, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant