Skip to content

Fix ByteBuffer CompressedInt32 representation - #504

Merged
sbomer merged 1 commit into
dotnet:mainfrom
jonpryor:dev/jonpryor/jonp-fix-CompressedInt32
Aug 12, 2026
Merged

sbomer merged 1 commit into
dotnet:mainfrom
jonpryor:dev/jonpryor/jonp-fix-CompressedInt32

Conversation

@jonpryor

Copy link
Copy Markdown

Context: dotnet/maui#37782
Context: unoplatform/uno#24036
Context: jbevain@608fac6
Context: jbevain#982

I've been trying to get a project building for iOS+Native AOT, which
invariably would error out in ilc:

Error: Sequence point value is out of range.
System.BadImageFormatException: Sequence point value is out of range.
   at System.Reflection.Throw.SequencePointValueOutOfRange() in /_/src/runtime/src/libraries/System.Reflection.Metadata/src/System/Reflection/Throw.cs:line 239
   at System.Reflection.Metadata.SequencePointCollection.Enumerator.MoveNext() in /_/src/runtime/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/PortablePdb/SequencePointCollection.cs:line 86
   at Internal.TypeSystem.Ecma.PortablePdbSymbolReader.<GetSequencePointsForMethod>d__10.MoveNext() in /_/src/runtime/src/coreclr/tools/Common/TypeSystem/Ecma/SymbolReader/PortablePdbSymbolReader.cs:line 147
   at ILCompiler.Logging.MessageOrigin..ctor(MethodIL, Int32) in /_/src/runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/MessageOrigin.cs:line 65

After quite a bit of investigation, determined that Cecil was apparent
cause of the crash, because multiple "involved parties" did not have
the fix present in commit jbevain/cecil@608fac6f, resulting in a "failure cascade":

  1. <Csc/> task produces .pdb file

  2. Uno <EmbeddedResourceInjectorTask_v0/> task uses Cecil to update
    (1), introduces "Invalid compressed integer".

  3. illink -- which has its own copy of Cecil, from the dotnet/cecil
    fork -- consumes (2), turning "Invalid compressed integer" values
    into different values.

  4. ilc processes pdb produced from (3), fails with
    BadImageFormatException: Sequence point value is out of range.

A "full stack" fix involves updating Uno to use Mono.Cecil 0.11.6,
which contains jbevain/cecil@608fac6f, and also updating illink
to also contain the fix from jbevain/cecil@608fac6f.

Which brings us to this PR: before updating illink, dotnet/cecil also
needs the fix from jbevain/cecil@608fac6f, so that (eventually) illink
doesn't produce invalid .pdb files.

"Cherry-pick" (kinda) the following PRs from jbevain/cecil:

@akoeplinger

Copy link
Copy Markdown
Member

@sbomer would you mind taking a look? thanks

@sbomer

sbomer commented Aug 11, 2026

Copy link
Copy Markdown
Member

Thanks for finding @jonpryor! I think we should pick up the fix via a merge from upstream: #505, then add the extra tests.

@agocke

agocke commented Aug 11, 2026

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

Context: https://github.com/dotnet/roslyn/issues/80952
Context: unoplatform/uno#24036
Context: jbevain@608fac6
Context: jbevain#982

I've been trying to get a project building for iOS+Native AOT, which
invariably would error out in `ilc`:

	Error: Sequence point value is out of range.
	System.BadImageFormatException: Sequence point value is out of range.
	   at System.Reflection.Throw.SequencePointValueOutOfRange() in /_/src/runtime/src/libraries/System.Reflection.Metadata/src/System/Reflection/Throw.cs:line 239
	   at System.Reflection.Metadata.SequencePointCollection.Enumerator.MoveNext() in /_/src/runtime/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/PortablePdb/SequencePointCollection.cs:line 86
	   at Internal.TypeSystem.Ecma.PortablePdbSymbolReader.<GetSequencePointsForMethod>d__10.MoveNext() in /_/src/runtime/src/coreclr/tools/Common/TypeSystem/Ecma/SymbolReader/PortablePdbSymbolReader.cs:line 147
	   at ILCompiler.Logging.MessageOrigin..ctor(MethodIL, Int32) in /_/src/runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/MessageOrigin.cs:line 65

After quite a bit of investigation, determined that Cecil was apparent
cause of the crash, because multiple "involved parties" did *not* have
the fix present in commit jbevain/cecil@608fac6f, resulting in a
"failure cascade":

 1. `<Csc/>` task produces `.pdb` file

 2. Uno `<EmbeddedResourceInjectorTask_v0/>` task uses Cecil to update
    (1), introduces "Invalid compressed integer".

 3. `illink` -- which has its own copy of Cecil, from the dotnet/cecil
    fork -- consumes (2), turning "Invalid compressed integer" values
    into *different* values.

 4. `ilc` processes `pdb` produced from (3), fails with
    `BadImageFormatException: Sequence point value is out of range`.

A "full stack" fix involves updating Uno to use Mono.Cecil 0.11.6,
which contains jbevain/cecil@608fac6f, *and also* updating `illink`
to also contain the fix from jbevain/cecil@608fac6f.

However, as part of this investigation, Claude cooked up a patch
to dotnet/cecil along with unit test updates to ByteBufferTests.
Of interest is that the suggested Claude fix for dotnet/cecil also
causes the original ByteBufferTests test from jbevain/cecil@608fac6f
to pass (yay), but not all of the new tests.  Meanwhile, jbevain/cecil
*does* pass all of the suggested new tests.

Record the new tests for posterity, and to reduce future drift between
jbevain/cecil and dotnet/cecil.
@jonpryor
jonpryor force-pushed the dev/jonpryor/jonp-fix-CompressedInt32 branch from fa9f916 to 53c7f0c Compare August 12, 2026 10:48
@jonpryor

Copy link
Copy Markdown
Author

I fixed the merge conflicts (by basically deleting the branch and recreating from main atop dotnet/runtime#505 and cherry-picking jbevain#982).

@agocke

agocke commented Aug 12, 2026

Copy link
Copy Markdown
Member

Thanks!

@jonpryor

Copy link
Copy Markdown
Author

@agocke: I am unable to merge. As you approved the changes, would you be able to merge as well? Thanks!

@sbomer
sbomer merged commit 5ae012f into dotnet:main Aug 12, 2026
6 checks passed
jonpryor added a commit to unoplatform/uno that referenced this pull request Aug 13, 2026
Fixes: #24036

Context: #23966
Context: dotnet/macios#26428
Context: dotnet/cecil#504
Context: jbevain/cecil#982
Context: jbevain/cecil@0.11.4...0.11.6
Context: jbevain/cecil@0.10.1...0.11.6

In The Beginning™ was a simple idea: why don't we have an
iOS+Native AOT test stage?  Thus began #23966, which promptly fell
over, caught on fire, and sank into the swamp.

There are two issues with #23966:

 1. CI was unhappy; it errors out with

        …/Xamarin.Shared.targets(2073,3): error : No valid iOS code signing keys found in keychain. You need to request a codesigning certificate from https://developer.apple.com.

    Not sure what's happening there.  It doesn't happen locally…

 2. It couldn't build locally either!

The initial attempt to build locally would fail in `ilc`:

	# note: using changes from #23966
	% TFM=net11.0-ios \
	  NAOT=1 \
	  BUILD_SOURCESDIRECTORY=`pwd` \
	  BUILD_ARTIFACTSTAGINGDIRECTORY=`pwd`/artifacts \
	  sh build/test-scripts/skia-ios-uitest-build.sh
	…
	    …/unoplatform/uno/src/SourceGenerators/Uno.UI.Tasks/Content/Uno.UI.Tasks.targets(487,3): warning Failed to resolve assembly `JetBrains.Annotations, Version=4242.42.42.42, Culture=neutral, PublicKeyToken=1010a0d8d6380325`: Failed to resolve assembly: 'JetBrains.Annotations, Version=4242.42.42.42, Culture=neutral, PublicKeyToken=1010a0d8d6380325'
	    EXEC : error Sequence point value is out of range.
	    $HOME/.nuget/packages/microsoft.dotnet.ilcompiler/11.0.0-preview.6.26359.118/build/Microsoft.NETCore.Native.targets(359,5): error MSB3073: The command ""$HOME/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/11.0.0-preview.6.26359.118/tools/ilc" @"obj/Release/net11.0-ios/ios-arm64/native/SamplesApp.ilc.rsp"" exited with code 1.

Thus began a fair bit of investigation, some of which is mentioned
in #24036 and dotnet/cecil#504.

What happened was a "failure cascade":

 1. The `<Csc/>` task produced a `.pdb` file.

 2. Uno's `<EmbeddedResourceInjectorTask_v0/>` task would use Cecil
    to process the assembly and `.pdb` file from (1).
    Uno was using, at most, Mono.Cecil 0.11.4, which had a bug around
    the encoding of "compressed" integers within `.pdb` files.

    (This is later fixed in jbevain/cecil#982, and released as part
    of Mono.Cecil 0.11.6.)

    The updated `.pdb` file would contain "Invalid compressed integer"
    values.

 3. Later, `illink` would run, which has it's own separate copy of
    Mono.Cecil -- from dotnet/cecil -- which would *also* update the
    `.pdb` files from (2).  When `illink` ran, any "Invalid compressed
    integer" values would be further corrupted.

 4. Later still, when `ilc` runs, it would process the `.pdb` files
    produced by (3), and at this point instead of "silently corrupting"
    data, it would error out entirely:

        Error: Sequence point value is out of range.
        System.BadImageFormatException: Sequence point value is out of range.
           at System.Reflection.Throw.SequencePointValueOutOfRange() in /_/src/runtime/src/libraries/System.Reflection.Metadata/src/System/Reflection/Throw.cs:line 239
           at System.Reflection.Metadata.SequencePointCollection.Enumerator.MoveNext() in /_/src/runtime/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/PortablePdb/SequencePointCollection.cs:line 86
           at Internal.TypeSystem.Ecma.PortablePdbSymbolReader.<GetSequencePointsForMethod>d__10.MoveNext() in /_/src/runtime/src/coreclr/tools/Common/TypeSystem/Ecma/SymbolReader/PortablePdbSymbolReader.cs:line 147
           at ILCompiler.Logging.MessageOrigin..ctor(MethodIL, Int32) in /_/src/runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/MessageOrigin.cs:line 65

(Failure cascades are fun!)

*Part* of the fix here is to update Uno to use Mono.Cecil 0.11.6,
which contains the fix for reading and writing "compressed" integers
in `.pdb` files.  That is done here.

Updating Cecil will *not* fix #23966, but is a partial prerequisite.
A full fix will require dotnet/cecil#504 to be merged and released,
(currently merged), `illink` updated to use dotnet/cecil#504, and
*then* there's dotnet/macios#26428, in which `clang++` crashes when
trying to link everything even if we get past the whole `.pdb` mess
(which reportedly is fixed in the not-yet-released .NET 11 RC1).

(Aside: the `.pdb` mess can be avoided by NOT USING `.pdb` FILES,
e.g. buil with `-p:DebugType=none`.  However, who wants to do that?)

…which still leaves the original "how do we get this building on CI"
question…

Baby steps!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants