bytecodealliance / wasm-micro-runtime

WebAssembly Micro Runtime (WAMR)
Apache License 2.0
4.79k stars 606 forks source link

AOT module load failed: resolve symbol __atomic_compare_exchange_4 failed #3731

Open Kvencc opened 3 weeks ago

Kvencc commented 3 weeks ago

The following are the details when wamrc is compiled: wamrc --target=riscv32 --target-abi=ilp32d --size-level=1 --enable-multi-thread --format=aot -o foo.aot foo.asm Create AoT compiler with: target: riscv32 target cpu: target triple: riscv32-pc-linux-ilp32d cpu features: +d opt level: 3 size level: 1 output format: AoT file Compile success, file foo.aot was generated.

Then when I tried to load and run this aot module, this error occurred:

AOT module load failed: resolve symbol __atomic_compare_exchange_4 failed.

I tried to use the same compilation option on other platforms, but only modified the -target option, which seems to work normally.

Do I need to provide implementation for functions like __atomic_compare_exchange_4 and __atomic_store_4 in riscv?

Thank you very much for your reply.

TianlongLiang commented 3 weeks ago

So what if you don't specific the target? Will it run successfully?

Kvencc commented 3 weeks ago

If I don't specify the target, won't wamrc be compiled into the host architecture by default? I have x86_64 here. But I need to run this aot module on the riscv platform.

When I run on the riscv platform if dont specify the target, an error like this will be returned: AOT module load failed: invalid target bit width, expected 32-bit but got 64-bit

TianlongLiang commented 3 weeks ago

So you want to do cross-compiling.

AOT file generated on the x86_64 platform iwasm ran on the riscv32 platform(is it also compiled on the riscv32 platform or use cross-compile toolchain generated on the x86_64 platform?)

Am I right?

And the error message:

AOT module load failed: resolve symbol __atomic_compare_exchange_4 failed.

refer to the lack of support for atomic intrinsic on the riscv32 platform, I am not very familiar with the risc32 platform, I suspect that it might be some extra compile flag needed to be added when compiling iwasm on the risv32 platform to support atomic operations

Kvencc commented 3 weeks ago

Yes, I ported iwasm to my application and used cross-compilation tools to build it on the x86_64 platform. And the aot file is also generated on the x86 platform.

Can I choose not to use these platform-related features in iwasm? If possible, which options should I specify in the process of compiling iwasm and aot?

Kvencc commented 3 weeks ago

I broke the debugging point in the resolve_target_sym function of aot_loader.c, and the following functions returned null:

So I wonder if some configurations were not done well when I compiled iwasm.

TianlongLiang commented 3 weeks ago

If you are not using threads in your wasm app, you can try to remove the option --enable-multi-thread. For the other missing symbols, you may try the approach in this PR to see whether it helps.