Skip to content

Commit 54b87cb

Browse files
authored
Fix missing stack frame alloc/free in AOT multi-module invoke (#3562)
Fix #3545 and update the build configuration for multi-module sample: - pass debug to AOT-compiled modules - support optional DUMP_CALL_STACK - support optional GC
1 parent d36160b commit 54b87cb

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

core/iwasm/aot/aot_runtime.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,10 +2883,24 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
28832883
"create singleton exec_env failed");
28842884
goto fail;
28852885
}
2886+
#if WASM_ENABLE_AOT_STACK_FRAME != 0
2887+
struct WASMInterpFrame *prev_frame = exec_env->cur_frame;
2888+
2889+
if (!aot_alloc_frame(exec_env, func_idx)) {
2890+
goto fail;
2891+
}
28862892
#endif
2893+
#endif /* WASM_ENABLE_MULTI_MODULE != 0 */
28872894
ret =
28882895
wasm_runtime_invoke_native(exec_env, func_ptr, func_type, signature,
28892896
attachment, argv, argc, argv);
2897+
#if WASM_ENABLE_MULTI_MODULE != 0 && WASM_ENABLE_AOT_STACK_FRAME != 0
2898+
/* Free all frames allocated, note that some frames
2899+
may be allocated in AOT code and haven't been
2900+
freed if exception occurred */
2901+
while (exec_env->cur_frame != prev_frame)
2902+
aot_free_frame(exec_env);
2903+
#endif
28902904
}
28912905
else {
28922906
signature = import_func->signature;

samples/multi-module/CMakeLists.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ endif ()
4949
if (NOT DEFINED WAMR_BUILD_JIT)
5050
set(WAMR_BUILD_JIT 0)
5151
endif ()
52+
if (NOT DEFINED WAMR_BUILD_DUMP_CALL_STACK)
53+
set(WAMR_BUILD_DUMP_CALL_STACK 0)
54+
endif ()
55+
if (NOT DEFINED WAMR_BUILD_GC)
56+
set(WAMR_BUILD_GC 0)
57+
endif ()
5258
set(WAMR_BUILD_SIMD 1)
5359
set(WAMR_BUILD_REF_TYPES 1)
5460
set(WAMR_BUILD_LIBC_BUILTIN 1)
@@ -141,6 +147,7 @@ ExternalProject_Add(WASM_MODULE
141147
-DWASI_SDK_PREFIX=${WASI_SDK_DIR}
142148
-DCMAKE_TOOLCHAIN_FILE=${WASI_TOOLCHAIN_FILE}
143149
-DCMAKE_SYSROOT=${WASI_SYS_ROOT}
150+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
144151
-S ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps
145152
BUILD_COMMAND ${CMAKE_COMMAND} --build .
146153
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy
@@ -172,17 +179,24 @@ if (WAMR_BUILD_AOT EQUAL 1)
172179
message(STATUS "WAMR_COMPILER is ${WAMR_COMPILER}")
173180
endif()
174181

182+
if (WAMR_BUILD_DUMP_CALL_STACK EQUAL 1)
183+
list(APPEND WAMR_AOT_COMPILE_OPTIONS "--enable-dump-call-stack")
184+
endif ()
185+
if (WAMR_BUILD_GC EQUAL 1)
186+
list(APPEND WAMR_AOT_COMPILE_OPTIONS "--enable-gc")
187+
endif ()
188+
175189
add_custom_target(
176190
wasm_to_aot
177191
ALL
178192
DEPENDS
179193
WASM_MODULE ${WAMR_COMPILER}
180194
COMMAND
181-
${WAMR_COMPILER} -o mA.aot ./mA.wasm
195+
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mA.aot ./mA.wasm
182196
COMMAND
183-
${WAMR_COMPILER} -o mB.aot ./mB.wasm
197+
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mB.aot ./mB.wasm
184198
COMMAND
185-
${WAMR_COMPILER} -o mC.aot ./mC.wasm
199+
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mC.aot ./mC.wasm
186200
WORKING_DIRECTORY
187201
${CMAKE_BINARY_DIR}
188202
)

samples/multi-module/wasm-apps/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function(COMPILE_WITH_CLANG SOURCE_FILE COMMAND)
5757

5858
add_executable(${MAIN_TARGET_NAME} ${SOURCE_FILE})
5959
set_target_properties(${MAIN_TARGET_NAME} PROPERTIES OUTPUT_NAME ${WASM_MODULE})
60+
target_compile_options (${MAIN_TARGET_NAME} PRIVATE -fno-exceptions)
6061

6162
if(${COMMAND})
6263
message(STATUS "Generating ${WASM_MODULE} as COMMAND...")

0 commit comments

Comments
 (0)