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

WAMR behaves differently compared to other runtimes for a particular test case.

Open teyahb8 opened this issue 10 months ago • 2 comments

Subject of the issue

I have generated a test case and tested multiple runtimes with it. WAMR (AOT) mode behaves differently compared to other runtimes for this particular test case. Other runtimes including WAMR (Interpreter) produce import error whereas WAMR (AOT) produces a segfault.

Test case

(module
  (import "" "" (func))
  (export "main" (func 0))
)

Your environment

  • WAMR version (2.2.0), platform (Linux), cpu architecture (X86_64), running mode (AOT).

Steps to reproduce

Run wat2wasm file.wat to generate file.wasm Run wamrc --bounds-checks=1 -o file.aot file.wasm to generate file.aot Run iwasm -f main file.aot to manifest the crash

Expected behavior

Other runtimes like wasmtime, wasmer, wamr (interpreter), and wasmedge all produce import error with this test case.

Actual behavior

Outputs from wamrc and iwasm are as follows:

wamrc output:

Create AoT compiler with:
  target:        x86_64
  target cpu:    znver3
  target triple: x86_64-unknown-linux-gnu
  cpu features:  
  opt level:     3
  size level:    3
  output format: AoT file
Compile success, file file.aot was generated.

iwasm output:

warning: failed to link import function (, )
unhandled SIGSEGV, si_addr: (nil)

Can you confirm if this is a bug? Thanks in advance.

teyahb8 avatar Feb 14 '25 02:02 teyahb8

The difference in output between iwasm and wamrc is a deliberate design decision. Rather than failing during instantiation, WAMR opts to attempt executing Wasm functions until it encounters an unlinked import function. This is why, when the import requirements are not fully met:

  • There is no error reported during initialization.
  • AOT files are still generated.

BTW, The SIGSEGV is suspicious. Could you please tell me which version of iwasm you are using?

lum1n0us avatar Feb 18 '25 04:02 lum1n0us

I see. Thanks for explaining the design decision. But, this test case might be a corner case to cause a segfault instead of gracefully exiting. I am building iwasm from the latest commit. I am sharing the commit and version information in the attached screenshot.

Image

teyahb8 avatar Feb 18 '25 15:02 teyahb8

I will appreciate any update on this crash. Many thanks.

teyahb8 avatar Jul 11 '25 06:07 teyahb8

For some additional context, the execution of this test case now shows an assertion failure along with the crash.

[04:48:15:894 - 7FFFF7F347C0]: warning: failed to link import function (, )
[04:48:15:894 - 7FFFF7F347C0]: 
ASSERTION FAILED: func_ptr != NULL, at file wasm-micro-runtime/core/iwasm/aot/aot_runtime.c

Aborted

The assertion failure occurs at this line inside aot_runtime.c file:

/* func pointer was looked up previously */
    bh_assert(func_ptr != NULL);

teyahb8 avatar Jul 25 '25 21:07 teyahb8