Skip to content

Use sequential blobs for NativeAOT attribute and constant metadata - #136357

Merged
MichalStrehovsky merged 9 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-metadata-blobs
Nov 2, 2026
Merged

MichalStrehovsky merged 9 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-metadata-blobs

Conversation

@MichalStrehovsky

@MichalStrehovsky MichalStrehovsky commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Encode custom attributes and default values as ECMA-shaped NativeFormat blobs while retaining compressed string/type handles. Simplify NativeAOT parsing and update enum, GUID, and stack-trace consumers.

Encode custom attributes and default values as ECMA-shaped NativeFormat blobs while retaining compressed string/type handles. Simplify NativeAOT parsing and update enum, GUID, and stack-trace consumers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0f7ac0ae-31cc-43ab-925d-b7bf74bff1ad
@azure-pipelines

azure-pipelines Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Prune unused primitive collections and serializers, remove the unused NotPersisted schema flag, and collapse the sequence comparison helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 1dd7eab4-f8ce-4856-bc24-5f85b04ea804
Encode string values as inline UTF-8 SerStrings instead of metadata handles. Store constant blobs as byte arrays and parse GUID attributes directly without resolving constructor signatures.

This change is mostly for size measurement.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f2846059-49b6-42a1-8411-ac728be88865
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@MichalStrehovsky
MichalStrehovsky marked this pull request as ready for review October 31, 2026 11:19
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

This is now ready for review. RuntimeCustomAttributeData.NativeAot.cs can now share a lot more with CoreCLR but that will be a separate PR. Looks like we also got an extra bit saving in handle type so we can do bit shifts in a more space saving way. Also a separate PR.

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The metadata wire-format rewrite spans compiler emission and NativeAOT consumers, and source-only review lacked the end-to-end runtime validation needed to establish compatibility.

No open issues 🎉

What changed in this PR

This PR changes NativeAOT custom attributes and default values to sequential, ECMA-shaped blobs while retaining compressed string and type handles. It updates metadata generation and reflection consumers together.

Changes:

  • Replace specialized constant and named-argument records with blob-backed metadata.
  • Add sequential blob reading and writing, including relocatable handles.
  • Adapt custom-attribute parsing, default values, enum values, GUID lookup, and stack-trace formatting.
File Description
src/​coreclr/​tools/​Common/​Internal/​NativeFormat/​NativeFormatReader.String.cs Generalizes length-prefixed byte reading.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​NativeMetadataReader.cs Exposes byte collections as spans.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​NativeFormatReaderCommonGen.cs Updates constant codes and handle kinds.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​MdBinaryReaderGen.cs Updates generated readers for the new schema.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​MdBinaryReader.cs Removes obsolete primitive readers.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​Generator/​WriterGen.cs Generates blob visitation, comparison, and serialization.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​Generator/​SchemaDef.cs Defines blob-backed constants and attributes.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​Generator/​ReaderGen.cs Generates blob collection access.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​BlobReader.cs Adds sequential primitive and handle decoding.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​Internal/​Metadata/​NativeFormat/​Writer/​NativeMetadataWriter.cs Updates diagnostics and removes obsolete comparers.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​Internal/​Metadata/​NativeFormat/​Writer/​NativeFormatWriterGen.cs Updates generated metadata records.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​Internal/​Metadata/​NativeFormat/​Writer/​MetadataBlob.cs Adds blob storage and relocatable references.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​Internal/​Metadata/​NativeFormat/​Writer/​MdBinaryWriterGen.cs Updates generated serialization overloads.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​Internal/​Metadata/​NativeFormat/​Writer/​MdBinaryWriter.cs Removes obsolete primitive writers.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​Internal/​Metadata/​NativeFormat/​Writer/​ConstantValues.cs Removes superseded constant formatting helpers.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​ILCompiler/​Metadata/​Transform.CustomAttribute.cs Transcodes attribute arguments into sequential blobs.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​ILCompiler/​Metadata/​Transform.Constant.cs Transcodes default constants into typed blobs.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​ILCompiler.MetadataTransform.csproj Includes blob support files.
src/​coreclr/​nativeaot/​System.Private.StackTraceMetadata/​src/​Internal/​StackTraceMetadata/​MethodNameFormatter.cs Uses typed string-handle collections.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​RuntimeParameterInfo.NativeAot.cs Uses the new constant handle.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​RuntimeCustomAttributeData.NativeAot.cs Parses and instantiates attributes from sequential blobs.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​TypeInfos/​NativeFormat/​NativeFormatRuntimeNamedTypeInfo.cs Reads GUID arguments and enum constants from blobs.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​General/​NativeFormat/​DefaultValueParser.cs Accepts typed constant handles.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​General/​MetadataReaderExtensions.NativeFormat.cs Decodes constants by type code.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System.Private.CoreLib.csproj Includes the shared blob reader.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​CompatibilitySuppressions.xml Aligns suppressions with the revised metadata types.

Review effort: Balanced

MichalStrehovsky and others added 2 commits November 1, 2026 08:11
Resolve NativeFormat schema conflicts and regenerate sources with UpdateNativeFormatSources.cmd.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 35982d34-c05d-4e6c-894e-d2fc2bbf62a0
Preserve BadImageFormatException for invalid reader metadata and document the mirrored System.Reflection.Metadata definitions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 35982d34-c05d-4e6c-894e-d2fc2bbf62a0
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bbe5596f-be51-49e6-86ed-e84e6a4008df
@MichalStrehovsky
MichalStrehovsky merged commit 0ca487c into dotnet:main Nov 2, 2026
100 of 102 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the nativeaot-metadata-blobs branch November 2, 2026 06:23
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.

3 participants