Draft: AArch64 iOS fixes
It is great that GHC natively supports arm64 Apple Silicon CPUs. So now GHC actually generates code for iOS devices already and fortunately there are only few fixes needed in RTS and NGC to build Haskell programs for iOS:
- Return NULL in my_mmap in a case of darwin_HOST_OS. It allows more attempts for osTryReserveHeapMemory. On macos my_mmap succeeds on the first try but ios doesn't give 256GB (0x4000000000) to allocate.
- Sometimes iOS doesn't allocate memory below the 8 GB (so the program goes into inifite loop in osReserveHeapMemory). I think we can relax this requirement by adding
--arbitrary-heap-start
RTS flag. It allows to allocate the memory block anywhere, not only above the 8 GB. - ARM CPUs before v8.3-a doesn't support
ldapr
instruction which is generated from__atomic_load_n(ptr, __ATOMIC_ACQUIRE)
. So we can add clang flag-march=armv8-a+norcpc
which disables this feature (https://developer.arm.com/documentation/ddi0596/2021-03/Base-Instructions/LDAPR--Load-Acquire-RCpc-Register-). - We shouldn't use x18 register in NCG for aarch64. Otherwise random crashes occur on some iphones. Apple doc says: "The platforms reserve register x18. Don’t use this register." https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms Another ios related doc says: x18 platform register (reserved, periodically zeroed by XNU) https://github.com/Siguza/ios-resources/blob/master/bits/arm64.md
Edited by Andreas Klebinger