Skip to content

Native AOT fidelity follow-up: resolver lookup, culture independence, gate coverage - #4268

Merged
siegfriedpammer merged 3 commits into
masterfrom
aot-fidelity-followup
Oct 20, 2026
Merged

siegfriedpammer merged 3 commits into
masterfrom
aot-fidelity-followup

Conversation

@christophwille

Copy link
Copy Markdown
Member

Follow-up to #4259 (and #4241) from a review of the Native AOT fidelity of the ICSharpCode.Decompiler package: can a Native AOT consumer and a framework-dependent consumer of the netstandard2.0 assembly produce different output for the same input? Three commits, one per finding class; the assembly stays netstandard2.0-only.

How the gaps were found

  • Rooted gate (ICSharpCode.Decompiler.AotTest), an unrooted Native AOT consumer and an ILLink-trimmed consumer (plain dll reference to the Release assembly, EventSourceSupport=true), each compared with a framework-dependent build on the same inputs: Mono.Cecil (net45), the decompiler itself (netstandard2.0), ILSpyX (net10), System.Windows.Forms resources.
  • ilspycmd published with -p:IlspyCmdRidPackages=true -r win-x64 against the framework-dependent build: 49 switch combinations (whole project, IL, PDB generation and dumps, metadata tables, resources, BAML, nupkg entries, settings, language versions, error paths) over Mono.Cecil, FSharp.Core, NRefactory, Avalonia.Base, ILSpyX, PresentationFramework.Aero and System.Windows.Forms. All identical except the expected + 0x.. frame format in crash traces.
  • Linux host layouts in WSL (Ubuntu 24.04): framework-dependent, self-contained, single-file and Native AOT hosts, with and without dotnet on PATH, with DOTNET_ROOT only, with a symlinked dotnet, with two installed majors.

Findings and fixes

  1. Resolver lookup on single-file and Native AOT hosts (commit 1). The shared-framework lookup added in Native AOT fidelity for the ICSharpCode.Decompiler package #4259 took the newest shared framework of the dotnet on PATH. Measured divergences from a framework-dependent host: with dotnet installed but not on PATH (DOTNET_ROOT only) the native binary printed corlib -> NOT FOUND and its output changed; a self-contained host ignored the facades in its own directory as soon as any dotnet was on PATH; with 10.0 and 11.0 installed the native binary used the 11.0 facades while the net10 framework-dependent host used 10.0. The lookup now accepts a runtime directory that holds the facades, walks DOTNET_ROOT, the default install locations and then PATH (the host's order, with PATH as the fallback the host does not have), and prefers the host's own major version. Four new resolver tests.
  2. Culture-dependent output (commit 2). Native AOT apps normally run in invariant globalization mode; framework-dependent apps run on ICU with the user's culture. Local functions were ordered with the culture comparer (ICU: _gamma, alpha, Beta, Zed; invariant: Beta, Zed, _gamma, alpha), and variable names derived from type names used culture case mapping, so under tr-TR Instruction instruction became Instruction ınstruction (5680 changed lines when decompiling the decompiler itself, 158 for Mono.Cecil, in the native and the managed build alike). All measured sites plus the remaining culture-sensitive comparisons and case mappings are ordinal/invariant now, CA1309/CA1310/CA1311 are enabled for ICSharpCode.Decompiler/** so the sources stay that way, and a CultureIndependenceTests fixture (tr-TR) and a LocalFunctions pretty case (ordinal order) cover the two measured cases. After the change en-US (ICU), tr-TR and invariant mode give byte-identical output, natively and managed, for all inputs above.
  3. Gate blind spots (commit 3). The gate rooted the whole decompiler, so it never ran it trimmed, and both sides ran in invariant mode, so it could not see finding 2. CI now also publishes with RootDecompiler=false and builds the managed comparison with InvariantGlobalization=false; all three outputs must match.

Verification

  • ICSharpCode.Decompiler.Tests (Release): full suite green after the final change 4682 passed, 0 failed, 24 skipped (the usual ILSpy-tests-dependent ignores).
  • Linux gate after the fixes: rooted native, trimmed native and the managed build on the system 10.0 runtime (ICU, en-US and tr-TR) resolve the same facades and produce identical output for the net45, netstandard2.0 and net10 inputs; the DOTNET_ROOT-only and self-contained scenarios resolve.
  • The VS add-in, which links the resolver sources, still compiles.

Review of #4259 itself

Every change there holds up: the polyfilled UnconditionalSuppressMessage, the GetStackTrace fallback (frames are kept, verified in an unrooted consumer), the four EventSource suppressions (all ten events fire with identical payloads under ILC and ILLink), the markers, and the NotSupportedException removal. IsNil is a correct cleanup of an always-false comparison with no behaviour change. Nothing from #3946 was carried over that should not have been.

Assisted-by: Claude:claude-fable-5-1:Claude Code

… hosts

A framework-dependent app resolves .NET Framework and netstandard facades
from the shared framework it runs on. A Native AOT or single-file build
of the same app has to locate an installed shared framework instead, and
the lookup took the newest one of the dotnet on PATH, which differs from
the framework-dependent host in three measured cases: with dotnet
installed but not on PATH (the host finds it through DOTNET_ROOT and the
default install locations, the resolver found nothing and every corlib
type became unknown); for a self-contained host, whose own directory
holds the facades but is not named like a shared framework, so it was
passed over for whatever dotnet was on PATH; and when several majors are
installed, where the newest was taken rather than the host's own.

The lookup now accepts any runtime directory that holds the facades,
walks DOTNET_ROOT and the default install locations before PATH, and
prefers the shared framework of the host's own major version.

Assisted-by: Claude:claude-fable-5-1:Claude Code
Native AOT apps usually run in invariant globalization mode, framework-
dependent apps on ICU with the user's culture, and the decompiler gave
them different text for the same input: local functions were ordered
with the culture comparer (ICU puts "alpha" before "Beta", invariant
mode the other way round), and variable names derived from type names
went through culture case mapping, which under tr-TR turns "Instruction"
into a dotless "ınstruction" (5680 changed lines when decompiling
the decompiler itself). The remaining culture-sensitive comparisons and
case mappings are switched to ordinal and invariant as well, and the
globalization analyzers now keep the decompiler's sources that way.

Assisted-by: Claude:claude-fable-5-1:Claude Code
The gate rooted the whole decompiler, so the native binary never ran
with the decompiler trimmed as it is in a consumer's app, and both sides
of the comparison ran in invariant globalization mode, so output that
depends on the culture could not show up as a difference. A second
native publish leaves the decompiler unrooted, and the managed
comparison build now runs on ICU while the native binaries stay in
invariant mode.

Assisted-by: Claude:claude-fable-5-1:Claude Code
@siegfriedpammer
siegfriedpammer merged commit c3f9e7d into master Oct 20, 2026
20 checks passed
@siegfriedpammer
siegfriedpammer deleted the aot-fidelity-followup branch October 20, 2026 14:47
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.

2 participants