Skip to content

Fix WriteCompressedInt32 endianness on big-endian hosts - #984

Closed
medhatiwari wants to merge 391 commits into
jbevain:masterfrom
medhatiwari:fix-compressed-int32-be
Closed

medhatiwari wants to merge 391 commits into
jbevain:masterfrom
medhatiwari:fix-compressed-int32-be

Conversation

@medhatiwari

Copy link
Copy Markdown

Cecil’s WriteUInt16/WriteUInt32 are always little-endian. WriteCompressedInt32 copied SRM’s IsLittleEndian check, so on big-endian it writes swapped compressed ints into portable PDBs.

That landed in dotnet/cecil via #505 (608fac6, originally jbevain/cecil#958) and flowed into the VMR in [dotnet/dotnet#8250](dotnet/dotnet#8250. Native s390x VMR Mono then fails in ILLink while trimming System.Runtime (IL1012, ArgumentNullException / document).

Always ReverseEndianness before those writes. Round-trip tests do not catch this on little-endian, the new test asserts spec bytes (-100 → BF39, -9076 → DFFFB919).

cc: @tmds

dotnet-maestro Bot and others added 30 commits December 26, 2022 13:38
…223.1 (dotnet#56)

[main] Update dependencies from dotnet/arcade
This ensures that section starts are aligned by adjusting the
previous Range's length to ensure the computed start of a new
Range meets the alignment requirements. It was done this way
rather than just computing an aligned start for the new Range,
because the TextMap assumes that the Ranges are contiguous - see
for example GetNextRVA.
…230.1 (dotnet#57)

[main] Update dependencies from dotnet/arcade
This ensures that section starts are aligned by adjusting the
previous Range's length to ensure the computed start of a new
Range meets the alignment requirements. It was done this way
rather than just computing an aligned start for the new Range,
because the TextMap assumes that the Ranges are contiguous - see
for example GetNextRVA.

GetNextRVA was used to compute the Code RVA, before adding that
segment to the TextMap. This meant that the alignment (only added
later) wasn't taken into account when writing out the code, but
then later the TextMap was modified to include the alignment.

This is fixed by first inserting an aligned zero-length Code
segment before writing the code, then inserting it again once the
length is known. Removing the Code alignment altogether would
work too, but the alignment constants are kept in there, because
it looks like they were added intentionally, even though the
reason is unknown.

Note that before this change, the start of the Code segment (at
least on x64) was not 16-byte aligned in the first place, so this
change will actually move the beginning of the Code segment.
[main] Update dependencies from dotnet/arcade


 - Merge branch 'main' into darc-main-236f6763-3a8c-439a-bd54-2abd86c5577b

 - Update test target to net8
…117.5 (dotnet#63)

[main] Update dependencies from dotnet/arcade
…127.1 (dotnet#64)

[main] Update dependencies from dotnet/arcade
…203.1 (dotnet#65)

[main] Update dependencies from dotnet/arcade
Add Microsoft.DotNet.Cecil project to do the packaging of cecil just like Mono.Cecil is packaged
Removes old packaging logic
Adds logic to be able to generate a csproj that build no code just packs
Add Sign info
…210.3 (dotnet#68)

[main] Update dependencies from dotnet/arcade
…218.1 (dotnet#69)

[main] Update dependencies from dotnet/arcade
…223.2 (dotnet#70)

[main] Update dependencies from dotnet/arcade
…303.1 (dotnet#71)

[main] Update dependencies from dotnet/arcade
…309.1 (dotnet#72)

[main] Update dependencies from dotnet/arcade
…318.1 (dotnet#73)

[main] Update dependencies from dotnet/arcade
…324.1 (dotnet#74)

[main] Update dependencies from dotnet/arcade
…417.1 (dotnet#76)

[main] Update dependencies from dotnet/arcade
Enable source-build pre-built detection
…424.1 (dotnet#78)

[main] Update dependencies from dotnet/arcade
- Coherency Updates:
  - Microsoft.SourceLink.GitHub: from 8.0.0-beta.23211.2 to 8.0.0-beta.23218.3 (parent: Microsoft.DotNet.Arcade.Sdk)
dotnet#79)

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 8.0.0-alpha.1.23214.4 -> To Version 8.0.0-alpha.1.23221.1

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Marek Safar <marek.safar@gmail.com>
…426.4 (dotnet#80)

[main] Update dependencies from dotnet/arcade
dotnet#81)

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 8.0.0-alpha.1.23221.1 -> To Version 8.0.0-alpha.1.23228.2

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
…505.2 (dotnet#82)

[main] Update dependencies from dotnet/arcade
dotnet#83)

Microsoft.SourceBuild.Intermediate.source-build-reference-packages
 From Version 8.0.0-alpha.1.23228.2 -> To Version 8.0.0-alpha.1.23253.2

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
…512.5 (dotnet#84)

[main] Update dependencies from dotnet/arcade
mmitche and others added 27 commits November 14, 2025 18:14
* Add .azuredevops/dependabot.yml

* Add .azuredevops/dependabot.yml
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk (Version 11.0.0-beta.26281.102 -> 11.0.0-beta.26313.102)
[[ commit created by automation ]]
…f-914f-99ce1158c4dd

[main] Source code updates from dotnet/dotnet
* Backflow from https://github.com/dotnet/dotnet / a9679a8 build 320973

Diff: https://github.com/dotnet/dotnet/compare/06787fc66d5364230924d00f2c5c251aeb7a31cd..a9679a8de87742e170318ea39f7f0e2874bcd441

From: dotnet/dotnet@06787fc
To: dotnet/dotnet@a9679a8

[[ commit created by automation ]]

* Update dependencies from build 320973
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk (Version 11.0.0-beta.26313.102 -> 11.0.0-beta.26330.112)
[[ commit created by automation ]]

* Try if nodeReuse=false is breaking the Windows build

* Update dependencies from build 321508
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk (Version 11.0.0-beta.26330.112 -> 11.0.0-beta.26356.101)
[[ commit created by automation ]]

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk (Version 11.0.0-beta.26356.101 -> 11.0.0-beta.26363.117)
[[ commit created by automation ]]

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
* Preserve document custom debug information

Load custom debug information for every preserved portable PDB document so embedded sources survive a round trip.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 01ec6ff9-132e-45df-95c2-9cedbce405cb
Assisted-by: GitHub Copilot CLI:GPT-5.6-Sol [code-review]

* Hydrate document debug information when writing

Read missing document custom debug information only when producing a portable PDB, and verify embedded sources survive after their sequence points are trimmed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 01ec6ff9-132e-45df-95c2-9cedbce405cb
Assisted-by: GitHub Copilot CLI:GPT-5.6-Sol [code-review]

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 01ec6ff9-132e-45df-95c2-9cedbce405cb
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk (Version 11.0.0-beta.26363.117 -> 11.0.0-beta.26381.101)
[[ commit created by automation ]]

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
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.
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk (Version 11.0.0-beta.26381.101 -> 11.0.0-beta.26411.119)
[[ commit created by automation ]]

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
* Enable AOT compatibility analysis

Add a net8.0 analyzer target, make optional symbol provider lookup trim-safe, and annotate reflection import APIs that are incompatible with trimming.

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

Copilot-Session: 844b37b7-122c-40c2-a4c2-d499dd6e59bc

* Use net10.0 for AOT analysis

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

Copilot-Session: 844b37b7-122c-40c2-a4c2-d499dd6e59bc

* Use framework compatibility for AOT analysis

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

Copilot-Session: 844b37b7-122c-40c2-a4c2-d499dd6e59bc

* Resolve modern framework warnings

Use supported cryptography APIs, guard Windows-only CSP fallbacks, and exclude unsupported legacy reflection APIs from the net10 target.

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

Copilot-Session: 844b37b7-122c-40c2-a4c2-d499dd6e59bc

* Ship trimming annotations for netstandard

Polyfill RequiresUnreferencedCodeAttribute for older targets and emit reflection import annotations without target framework guards.

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

Copilot-Session: 844b37b7-122c-40c2-a4c2-d499dd6e59bc

* Ship dynamic member annotations for netstandard

Polyfill DynamicallyAccessedMembersAttribute and DynamicallyAccessedMemberTypes so symbol provider constructor requirements are emitted for older targets.

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

Copilot-Session: 844b37b7-122c-40c2-a4c2-d499dd6e59bc

* Add compoent to explain

* Update Mono.Cecil.csproj

Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>

---------

Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
Copilot-Session: 844b37b7-122c-40c2-a4c2-d499dd6e59bc
@medhatiwari
medhatiwari force-pushed the fix-compressed-int32-be branch from 5e08e58 to 49cd6f9 Compare September 1, 2026 06:29
@medhatiwari

Copy link
Copy Markdown
Author

This branch was reset to the dotnet/cecil-based commit so dotnet#517 could merge. The jbevain-based change is now in #985.

@medhatiwari medhatiwari closed this Sep 1, 2026
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.