Skip to content

Fix iOS player crash due to mimalloc symbol conflict in Unity 6.5+#152

Merged
ruccho merged 2 commits into
mainfrom
feature/unity_6.5_mimalloc_conflict
Jul 10, 2026
Merged

Fix iOS player crash due to mimalloc symbol conflict in Unity 6.5+#152
ruccho merged 2 commits into
mainfrom
feature/unity_6.5_mimalloc_conflict

Conversation

@ruccho

@ruccho ruccho commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

After updating Unity to 6000.5.2f1, iOS builds crash on launch (EXC_BAD_ACCESS → watchdog SIGKILL).

Unity 6000.5 now bundles its own mimalloc in UnityFramework (_heap_main, _mi_page_empty, etc.). Our libunienc_c.a bundles its own mimalloc too, and on iOS it's statically linked (__Internal) into the same UnityFramework. The identically-named symbols coalesce at link time, so unienc's mimalloc ends up using Unity's _heap_main (different ABI layout) and dereferences a bogus pointer. -fvisibility=hidden doesn't help — on Mach-O it only makes symbols private-external, which still coalesce.

Fix

Localize every non-FFI symbol in the iOS .a as a CI post-build step, keeping only _unienc* global. No submodule/source changes.

  • apple-exports.txt — keeps _unienc* exported (all FFI entry points, incl. unienc_UnityPluginLoad/Unload).
  • localize-apple-staticlib.shar xld -r -exported_symbols_list (demotes non-_unienc* globals to local) → libtool -static. A nm -gU gate fails the build if any mimalloc symbol is still external.
  • build-unienc.yml — runs the script in build-ios (Unity variant), and sets CFLAGS_aarch64-apple-ios: -fno-common.

Linker notes (ld-prime, Xcode 16+)

  • Use loose objects, not -force_load (it localizes everything, wiping the exports).
  • -platform_version is required even for -r.
  • -fno-common is required: _mi_page_map is a common symbol otherwise and can't be localized. Injected via cc-rs CFLAGS, so no submodule change.

Verification

nm -gU shows only the 34 _unienc* symbols and 0 mimalloc symbols. Verified on device: launches on Unity 6000.6.0b1, Memory Profiler integration retained.

@ruccho ruccho requested a review from hkmt-mmy July 9, 2026 05:59
@ruccho ruccho merged commit e8e5e08 into main Jul 10, 2026
1 check passed
@ruccho ruccho deleted the feature/unity_6.5_mimalloc_conflict branch July 10, 2026 01:57
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.

2 participants