wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

Question: Is it possible to statically link AOT modules into the host program?

Open gechdcb opened this issue 10 months ago • 9 comments

Hi, I tested WAMR on iOS, and the interpreter mode worked fine. I know iOS does not support using mmap to allocate executable memory, so AOT mode is not supported on iOS. So my question is, is it possible to static link the AOT module into the host program, and then load the AOT module? After all, wamrc can output native object format.

gechdcb avatar Mar 28 '25 06:03 gechdcb

If I remember correctly, in iOS, the mmap can't mmap a region of memory that is both writable and executable at the same time, but it can use mprotect to change its state later. So maybe for AOT loading, it can load the code first and at the end of the loading phase make it executable

TianlongLiang avatar Mar 31 '25 03:03 TianlongLiang

I think iOS requires code signing or the device will refuse to run the app, so at least the AOT module's code needs to be signed along with the host app when it's built.

gechdcb avatar Mar 31 '25 03:03 gechdcb

You are right that the App Store policy wouldn't allow it. I was speaking from a purely technical standpoint, and it would only work for development.

TianlongLiang avatar Mar 31 '25 03:03 TianlongLiang

For your original question:

is it possible to static link the AOT module into the host program

It's possible, and in this case, I think you don't even have to use runtime. What you are trying to achieve is more like this project: https://github.com/web-devkits/wasm2native

TianlongLiang avatar Mar 31 '25 04:03 TianlongLiang

Yes, there are other wasm runtimes that can statically link AOT modules, but my use case is a bit different. What I'm trying to do is convert part of a wasm module to AOT, while leaving other parts for the interpreter to execute. Not many runtimes can support this.

gechdcb avatar Mar 31 '25 06:03 gechdcb

We implemented a similar solution in MOE 1.x: https://multi-os-engine.org . The AOT compiled native code (art / oat files) is packaged into a separate segment in the Mach-O binary, and then remapped as executable on startup. The whole Mach-O binary is codesigned. Such apps can be distributed in the App Store without problems.

kisg avatar Apr 05 '25 12:04 kisg

@TianlongLiang Can https://github.com/web-devkits/wasm2native be used on IOS App?

lengye7 avatar Apr 05 '25 13:04 lengye7

In theory it should work, but I didn't try it on iOS platform and it may need some extra configuration

TianlongLiang avatar Apr 10 '25 05:04 TianlongLiang

OK,thanks for your answer.

lengye7 avatar Apr 10 '25 18:04 lengye7