Stream: wamr

Topic: Question about AOT compilation in WAMR and native symbols


view this post on Zulip Ethin Probst (Feb 05 2024 at 16:59):

Hi all,
I was looking at the AOT compilation process and just have a couple questions about it when embedding WAMR in an application.

First, if I enable AOT during the build process, I can use this in my host to AOT-compile Wasm modules via including (in C++ for example) aot_export.h? I assume this is correct based on how wamrc works, but I thought I'd ask to make sure.

Second, how does linking with external libraries work? If my host links with an external library (even one provided by the operating system), and I AOT-compile that module after registering all the natives, how do I tell the AOT compiler that these libraries are required (either linked statically or dynamically) with the final AOT binary?

WAMR looks like a really cool project and I can't wait to give it a spin, but thought I'd ask these questions anyhow.

view this post on Zulip Wenyong Huang (Feb 22 2024 at 08:53):

Ethin Probst said:

First, if I enable AOT during the build process, I can use this in my host to AOT-compile Wasm modules via including (in C++ for example) aot_export.h? I assume this is correct based on how wamrc works, but I thought I'd ask to make sure.

Hi, the aot_export.h is mainly used for the aot compiler and llvm jit, see <wamr_root>/wamr-compiler/main.c, not sure whether you need to call the API like aot_create_comp_data, aot_compiler_init, aot_create_comp_context and so on? If not, normally you can just include wasm_export.h instead.

Second, how does linking with external libraries work? If my host links with an external library (even one provided by the operating system), and I AOT-compile that module after registering all the natives, how do I tell the AOT compiler that these libraries are required (either linked statically or dynamically) with the final AOT binary?

Firstly, for iwasm or wamr library, please use wasm_runtime_register_natives to register the native APIs, refer to:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md
https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/samples/native-lib
Secondly, for the aot compiler, developer can also pre-tell it the info of the native APIs that will be registered by iwasm or wasm library, by wamrc --native-lib=<so file>, so as to generate the optimized code to speedup the calling process from AOT code to native API, please refer to:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/perf_tune.md#81-refine-callings-to-native-apis-registered-by-wasm_runtime_register_natives-from-aot-code


Last updated: Dec 23 2024 at 13:07 UTC