Skip to content

Fix Intel Mac crash: handle arch-specific DLLs in universal binary#144

Open
Redth wants to merge 3 commits intomainfrom
fix-intel-mac-universal-dlls
Open

Fix Intel Mac crash: handle arch-specific DLLs in universal binary#144
Redth wants to merge 3 commits intomainfrom
fix-intel-mac-universal-dlls

Conversation

@Redth
Copy link
Copy Markdown
Owner

@Redth Redth commented Apr 11, 2026

Fix Intel Mac crash in universal macOS binary

Fixes #142

Root Cause

coreclr_initialize returns 0x8007000b (ERROR_BAD_FORMAT) on Intel Macs because all managed DLLs in Contents/MonoBundle/ are architecture-specific.

When creating the universal binary, the CI copies the arm64 publish output as the base. While native dylibs are properly merged via lipo, the 93 managed assemblies (System.Private.CoreLib.dll, MauiSherpa.MacOS.dll, etc.) contain ReadyToRun native code compiled for arm64 only. The x64 CoreCLR runtime rejects these, aborting with "Failed to initialize the VM".

How it was diagnosed

  1. Downloaded the CI artifact and reproduced the crash on an Intel Mac
  2. Used lldb to break on coreclr_initialize and captured the return code: 0x8007000b = ERROR_BAD_FORMAT
  3. Analyzed PE headers of all DLLs — found 93 with architecture-specific machine types (0xaa64 for arm64, 0xec20 for arm64 composite R2R) instead of 0x14c (IL-only)
  4. Confirmed the macOS bootstrapper adds .xamarin/<RID>/ paths to the Trusted Platform Assemblies list
  5. Validated the fix by moving arm64 DLLs to .xamarin/osx-arm64/, copying x64 DLLs to .xamarin/osx-x64/, and confirming the app launches on Intel

Fix

After creating the universal binary (lipo for native code), the CI now:

  1. Scans all DLLs in MonoBundle and reads their PE header machine field
  2. Moves arch-specific DLLs (machine != 0x14c) from MonoBundle to .xamarin/osx-arm64/
  3. Copies the corresponding x64 DLLs from the x64 publish to .xamarin/osx-x64/

The macOS bootstrapper already resolves assemblies from .xamarin/<RID>/ per-architecture subdirectories, so each architecture now loads its own compatible DLLs while pure IL assemblies remain shared in MonoBundle.

redth and others added 2 commits April 11, 2026 12:45
When xcdevice was not found (e.g., xcode-select pointing to Command Line
Tools instead of Xcode.app), RunXcdeviceObserveAsync returned normally
causing AppleWatchLoopAsync to immediately retry in a tight loop. This
produced 165+ warnings in ~4 seconds and could exhaust resources.

Fix: throw FileNotFoundException when xcdevice is missing, and catch it
in the loop to break out entirely since retrying won't help until the
app is restarted.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dotnet publish produces managed assemblies with ReadyToRun native code
compiled for the target architecture. When creating the universal binary,
the CI was copying the arm64 app as the base, so all DLLs in MonoBundle
were arm64-specific. The x64 CoreCLR runtime rejected these with
ERROR_BAD_FORMAT (0x8007000b), causing the app to crash on Intel Macs
with 'Failed to initialize the VM'.

The fix detects architecture-specific DLLs by reading the PE header
machine field (0x14c = IL-only, anything else = arch-specific) and moves
them into .xamarin/<RID>/ subdirectories. The macOS bootstrapper already
adds both MonoBundle/ and .xamarin/<RID>/ to the Trusted Platform
Assemblies list, so each architecture now loads its own compatible
assemblies.

Fixes #142

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Redth Redth added the build-artifacts Triggers building app artifacts on PRs label Apr 11, 2026
- Add 'build-artifacts' label trigger for PR builds on all publish jobs
- Add pull_request types: [opened, synchronize, reopened, labeled]
- Track lipo failures with ::warning:: instead of silent || true
- Copy x64-only dylibs not present in arm64 build
- Merge deps.json from both architectures for complete runtime resolution

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Redth Redth added build-artifacts Triggers building app artifacts on PRs and removed build-artifacts Triggers building app artifacts on PRs labels Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build-artifacts Triggers building app artifacts on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Still crashes at startup on Intel Mac

1 participant