Skip to content

Remove AOT unfriendly Marshal.SizeOf calls - #6098

Merged
max-charlamb merged 2 commits into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/nativeaot-register-sizing
Oct 21, 2026
Merged

max-charlamb merged 2 commits into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/nativeaot-register-sizing

Conversation

@max-charlamb

@max-charlamb max-charlamb commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Uses NativeAOT-friendly size calculations in SOS, based independently on origin/main.

  • Replace ThreadService's runtime Marshal.SizeOf(Type) with explicit sizeof values for paired ushort/short, uint/int, and ulong/long register fields.
  • Preserve register discovery, order, offsets, names, lookups, and special register indices; fail explicitly for unsupported field types.
  • Use Marshal.SizeOf<VS_FIXEDFILEINFO>() in SOSHost and DebuggerServices instead of the Type-based overload.
  • No new repository test file is included.

Validation

  • Both SOS target frameworks build with zero warnings/errors.
  • Expanded isolated net8.0/win-x64 NativeAOT publish completes with zero AOT/trimming warnings, without suppressions or broad metadata roots.
  • Actual NativeAOT execution constructs all six supported register contexts and validates the generic VS_FIXEDFILEINFO size as 52 bytes.
  • Register metadata matches the previously captured CoreCLR control across x64, x86, ARM64, ARM, LoongArch64, and RISC-V64 layouts.

The audit covers these sizing paths, not a claim that the entire SOS dependency closure is already NativeAOT-compatible. No framework retargeting, COM, JSON, command-factory, or packaging changes are included.

Replace Marshal.SizeOf(Type) with explicit primitive register widths, preserving register metadata and rejecting unsupported field types. Add coverage for all six ClrMD context layouts against the existing marshalling sizes.

Isolated NativeAOT publish has zero AOT/trimming warnings; native and CoreCLR register metadata match for every supported architecture.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: ab215431-2cf9-4421-8822-d411adca0f92
@max-charlamb max-charlamb changed the title Fix register sizing for NativeAOT Remove AOT unfriendly Marshal.SizeOf calls Oct 9, 2026
Handle signed and unsigned 16-, 32-, and 64-bit register fields in paired cases. Use generic Marshal.SizeOf for VS_FIXEDFILEINFO in SOSHost and DebuggerServices. Remove the register test file as requested.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: ab215431-2cf9-4421-8822-d411adca0f92
@max-charlamb
max-charlamb marked this pull request as ready for review October 9, 2026 02:43
@max-charlamb
max-charlamb requested a review from a team as a code owner October 9, 2026 02:43
@max-charlamb
max-charlamb requested review from hoyosjs and rcj1 October 9, 2026 02:43
@max-charlamb
max-charlamb merged commit c500770 into dotnet:main Oct 21, 2026
25 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants