I'm using WAMR-1.2.3 (the latest release as of now). When I run the sample code (wasm-micro-runtime-WAMR-1.2.3/product-mini/platforms/esp-idf), everything works fine. When I try exporting the wasm binary and run wasm2wat, I get:
(module
(type (;0;) (func (param i32) (result i32)))
(type (;1;) (func (param i32 i32) (result i32)))
(type (;2;) (func (param i32)))
(import "env" "puts" (func (;0;) (type 0)))
(import "env" "malloc" (func (;1;) (type 0)))
(import "env" "printf" (func (;2;) (type 1)))
(import "env" "free" (func (;3;) (type 2)))
(func (;4;) (type 1) (param i32 i32) (result i32)
(local i32 i32 i32)
global.get 0
i32.const 32
i32.sub
local.tee 2
global.set 0
i32.const 1051
call 0
drop
block ;; label = @1
block ;; label = @2
i32.const 1024
call 1
local.tee 3
br_if 0 (;@2;)
i32.const 1064
call 0
drop
i32.const -1
local.set 4
br 1 (;@1;)
end
local.get 2
local.get 3
i32.store offset=16
i32.const 1024
local.get 2
i32.const 16
i32.add
call 2
drop
i32.const 0
local.set 4
local.get 3
i32.const 4
i32.add
i32.const 0
i32.load16_u offset=1041 align=1
i32.store16 align=1
local.get 3
i32.const 0
i32.load offset=1037 align=1
i32.store align=1
local.get 2
local.get 3
i32.store
i32.const 1043
local.get 2
call 2
drop
local.get 3
call 3
end
local.get 2
i32.const 32
i32.add
global.set 0
local.get 4)
(table (;0;) 1 1 funcref)
(memory (;0;) 1)
(global (;0;) (mut i32) (i32.const 5184))
(global (;1;) i32 (i32.const 1082))
(global (;2;) i32 (i32.const 5184))
(export "memory" (memory 0))
(export "__data_end" (global 1))
(export "__heap_base" (global 2))
(export "main" (func 4))
(data (;0;) (i32.const 1024) "buf ptr: %p\0a\001234\0a\00buf: %s\00Hello world!\00malloc buf failed\00"))
I then run wamrc like this: wamrc "-o" "sample.aot" --target=riscv32 --target-abi=ilp32 sample.wasm --cpu-features=+i,+m,+c --bounds-checks=1
Then I transform the output (sample.aot) to a header file (xxd -i sample.aot >> test_wasm.h
) and use that.
After the program prints "Unload WASM module", it crashes complaining that assert failed: heap_caps_free heap_caps.c:392 (heap != NULL && "free() target pointer is outside heap areas")
.
Doing a bit of logging, the program tries freeing a pointer to "0xc".
freeing
real freeing 0x40394780
freeing
real freeing 0xc
assert failed: heap_caps_free heap_caps.c:392 (heap != NULL && "free() target pointer is outside heap areas")
Core 0 register dump:
MEPC : 0x403806f8 RA : 0x40383a64 SP : 0x3fc94180 GP : 0x3fc8c400
TP : 0x3fc89848 T0 : 0x37363534 T1 : 0x7271706f T2 : 0x33323130
S0/FP : 0x0000005a S1 : 0x00000001 A0 : 0x3fc941bc A1 : 0x3fc8db99
A2 : 0x00000001 A3 : 0x00000029 A4 : 0x00000001 A5 : 0x3fc8f000
A6 : 0x7a797877 A7 : 0x76757473 S2 : 0x00000009 S3 : 0x3fc942fd
S4 : 0x3fc8db98 S5 : 0x00000000 S6 : 0x00000000 S7 : 0x00000000
S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
T3 : 0x6e6d6c6b T4 : 0x6a696867 T5 : 0x66656463 T6 : 0x62613938
MSTATUS : 0x00001881 MTVEC : 0x40380001 MCAUSE : 0x00000007 MTVAL : 0x00000000
MHARTID : 0x00000000
I suspect that there's some kind of memory corruption. Can this be because I'm passing the wrong flags to wamrc, and what flags were passed to build the original source?
I tried not calling any functions (just go through the setup/tear-down procedure. It doesn't help.
Hi, the AOT file buffer should be at 4-byte aligned address, could you please try adding __aligned(4)
for the array generated by xxd tool? And could you dump more log if it doesn't work? e.g., add "-v=5" for iwasm or add some os_printf in wasm_runtime_full_init
?
Wenyong Huang said:
Hi, the AOT file buffer should be at 4-byte aligned address, could you please try adding
__aligned(4)
for the array generated by xxd tool? And could you dump more log if it doesn't work? e.g., add "-v=5" for iwasm or add some os_printf inwasm_runtime_full_init
?
__aligned(4) doesn't help. Where should I add printf to wasm_runtime_full_init?
Also, is there a doxygen documentation somewhere online?
__aligned(4) doesn't help. Where should I add printf to wasm_runtime_full_init?
I meant to add printf sentences in:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/common/wasm_runtime_common.c#L649-L702
Also, is there a doxygen documentation somewhere online?
No doxygen document, but you can refer to:
https://wamr.gitbook.io/document/
https://bytecodealliance.github.io/wamr.dev/
https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/doc
Last updated: Nov 22 2024 at 17:03 UTC