Skip to content

Mach-O: Fix chained fixups in universal binaries - #620

Open
Ketlark wants to merge 1 commit into
SamboyCoding:developmentfrom
Ketlark:macho-universal-writable
Open

Ketlark wants to merge 1 commit into
SamboyCoding:developmentfrom
Ketlark:macho-universal-writable

Conversation

@Ketlark

@Ketlark Ketlark commented Oct 5, 2026

Copy link
Copy Markdown

MachOUniversalFile wraps the selected slice in a read-only MemoryStream. MachOFile applies chained fixups in place through WriteWord, so any universal binary that uses chained fixups fails to load with NotSupportedException: Stream does not support writing. Chained fixups are the default for macOS 12+ deployment targets, so this hits the universal GameAssembly.dylib of Unity 6 macOS builds.

The fix makes the slice stream writable (new MemoryStream(buffer, 0, size, writable: true, publiclyVisible: true)).

Test: adds TestFiles/MachO/ChainedFixupsUniversal.dylib, a 49,792-byte x86_64+arm64 universal binary, with its C source and build command. It also adds MachOUniversalFileTests, which checks that the x86_64 slice's two-pointer rebase chain resolves to 0x1000/0x1008. Before the fix, the test throws "Stream does not support writing". After the fix, dotnet test -c Release passes 82 of 82 tests.

Real-world check: Dofus 3.6.10.11 (Unity 6000.3.16f1) produced 143 assemblies in 35 s with a self-contained osx-x64 build at 2022.1.0-pre-release.21 with this fix.

MachOUniversalFile wrapped the selected slice in a read-only MemoryStream,
but MachOFile applies chained fixups in place through WriteWord, so any
universal binary using chained fixups failed to load with "Stream does not
support writing". This is the default for macOS 12+ deployment targets, e.g.
the GameAssembly.dylib of Unity 6 macOS builds.

Adds a small universal fixture built from the included C source and a test
checking that the selected slice's rebases are applied.
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.

1 participant