尝试编译一个GHC到iOS,但是遇到了内存分配问题

需求: 不知道有没有大佬尝试过移植Glasgow Haskell Compiler到iOS,目前是编译了一个stage2编译器,但是真机运行时遇到了memory alloc fail的问题
操作步骤: 在Mac上编译时设置了target到iOS,并通过修改源码中对iOS的限制开启了terminfo等功能
一开始遇到了sandbox blocked mmap()的情况,通过ldid签入了如下entitlement

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>get-task-allow</key>
        <true/>
        <key>task_for_pid-allow</key>
        <true/>
        <key>platform-application</key>
        <true/>
        <key>com.apple.private.kernel.get-kext-info</key>
        <true/>
        <key>com.apple.private.security.no-container</key>
        <false/>
        <key>com.apple.private.security.container-required</key>
        <true/>
        <key>dynamic-codesigning</key>
        <true/>
        <key>com.apple.security.exception.files.absolute-path.read-write</key>
        <array>
            <string>/</string>
        </array>
</dict>
</plist>

随后尝试运行ghc,遇到内存分配错误

ghc-stage2: memory allocation failed (requested 274878955520 bytes)

之前编译QEMU的时候也有遇到这种情况,不知道有没有大佬知道怎么解决:pray:

你直接alloc了一个手机ROM大小的空间,肯定失败啊
image

我考虑到了ghc可能错误地计算了需要申请的内存大小,所以我在源码中硬写入了alloc的size,紧接着报错Illegal instruction: 4

Date: 9/6/21, 9:43 PM
Process: ghc-stage2
Bundle id: (null)
Device: iPhone 12 mini, iOS 14.2

Exception type: EXC_BAD_INSTRUCTION (SIGILL)
Exception subtype: (null)
Exception codes: 0x0000000000000000, 0x00000001c2482ca4
Culprit: Unknown

Triggered by thread: 0
Thread name: ghc_ticker
Call stack:
0   ???                           	0x00000001c2482ca4 0 + 7554477220