wasm-micro-runtime: aarch64 AOT module fails to load on android
When trying to load an aarch64 AOT file on android, the module fails to load due to an overflow check failing, AOT module load failed: target address out of range..
Expected behaviour
aarch64 AOT module loads without error
Actual behaviour
aarch64 AOT module fails to load
Steps to reproduce
I’ve attached the example android studio project which reproduces the issue consistently on an arm64 emulator: WasmAOT.zip
C++ code to load the AOT module:
#include <android/asset_manager_jni.h>
#include <android/log.h>
#include <jni.h>
#include <cstring>
#include <string>
#include <vector>
#include "wasm_export.h"
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_wasmaot_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from wasm aot example";
return env->NewStringUTF(hello.c_str());
}
extern "C" JNIEXPORT jint JNICALL
Java_com_example_wasmaot_MainActivity_loadWasmAOTModule(
JNIEnv* env,
jobject /* this */,
jobject jasset_manager) {
auto asset_manager = AAssetManager_fromJava(env, jasset_manager);
auto aot_file_name = std::string("wamr_aot_test_") + AOT_FILE_SUFFIX + std::string(".aot");
__android_log_print(ANDROID_LOG_INFO,"example.wasmaot", "%s", ("Loading AOT file " + aot_file_name).c_str());
auto asset = AAssetManager_open(asset_manager, aot_file_name.c_str(), AASSET_MODE_BUFFER);
if (!asset) {
__android_log_print(ANDROID_LOG_ERROR,"example.wasmaot", "Failed to open AOT asset");
return 1;
}
auto size = AAsset_getLength(asset);
auto asset_buffer = AAsset_getBuffer(asset);
std::vector<uint8_t> buf;
buf.reserve(size);
buf.assign(static_cast<const uint8_t*>(asset_buffer), static_cast<const uint8_t*>(asset_buffer) + size);
AAsset_close(asset);
wasm_runtime_init();
char error_buf[128] = {};
auto module = wasm_runtime_load(buf.data(), size, error_buf, sizeof(error_buf));
if (module) {
wasm_runtime_unload(module);
} else {
__android_log_print(ANDROID_LOG_ERROR,"example.wasmaot" ,"%s", error_buf);
return 1;
}
wasm_runtime_destroy();
return 0;
}
This is the rust code for the AOT module:
use std::os::raw::c_char;
#[no_mangle]
pub extern "C" fn main(_argv: *const *const c_char, _argc: i32) -> i32 {
let mut a = 0;
for i in 0..10 {
a += i;
}
let mut buffer = Vec::new();
buffer.extend([1, 2, 3]);
println!("Hello world {:?}", buffer);
println!("Hello world {:?}", a);
0
}
which was compiled via cargo build --target=wasm32-wasi and
wamrc \
--disable-simd \
--target=aarch64 \
--size-level=3 \
-o "wamr_aot_test_aarch64.aot" \
"hello_world.wasm"
The same rust code, when compiled for armv7 loads without issue on an armv7 android build.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (17 by maintainers)
Commits related to this issue
- aarch64 AOT module fails to load on android (#2274) — committed to bianchui/wasm-micro-runtime by bianchui 2 years ago
- aarch64 AOT module fails to load on android Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2274 — committed to bianchui/wasm-micro-runtime by bianchui 2 years ago
- aarch64 AOT module fails to load on android Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2274 — committed to bianchui/wasm-micro-runtime by bianchui 2 years ago
- aarch64 AOT module fails to load on android Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2274 — committed to bianchui/wasm-micro-runtime by bianchui 2 years ago
- aarch64 AOT module fails to load on android Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2274 — committed to bianchui/wasm-micro-runtime by bianchui 2 years ago
- aarch64 AOT module fails to load on android Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2274 — committed to bianchui/wasm-micro-runtime by bianchui 2 years ago
- Enable merged os_mmap for aot data sections (#3681) And enable merged os_mmap for aot data and text sections except on platform nuttx and esp-idf. Fix issue that aarch64 AOT module fails to load ... — committed to bytecodealliance/wasm-micro-runtime by bianchui 2 years ago
- Enable merged os_mmap for aot data sections and aot text (#3743) Enable merged os_mmap for aot data sections first, and try enabling merged os_mmap for them and aot text except on platform nuttx and... — committed to bytecodealliance/wasm-micro-runtime by wenyongh 2 years ago
- Enable merged os_mmap for aot data sections (#3681) And enable merged os_mmap for aot data and text sections except on platform nuttx and esp-idf. Fix issue that aarch64 AOT module fails to load ... — committed to LazyBoy-KK/wasm-micro-runtime by bianchui 2 years ago
Glad to know that WAMR is tested in nearly 1million devices, it is cool!