From c4623e2cb53b459d646d359403c59345c5dc08e0 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Thu, 12 Jun 2025 08:44:45 +0800 Subject: [PATCH] Enable aot memory64 sw bounds checks by default (#4350) - enable aot memory64 sw bounds checks by default --- core/iwasm/compilation/aot_llvm.c | 15 +++++++++++++++ wamr-compiler/main.c | 9 ++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index c1708e3f9..7cbb4a57e 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -3204,6 +3204,21 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) #if WASM_ENABLE_WAMR_COMPILER != 0 WASMModule *wasm_module = (WASMModule *)comp_data->wasm_module; + bool is_memory64 = false; + + /* TODO: multi-memories for now assuming the memory64 flag of a memory is + * consistent across multi-memories */ + if (wasm_module->import_memory_count > 0) + is_memory64 = !!(wasm_module->import_memories[0].u.memory.mem_type.flags + & MEMORY64_FLAG); + else if (wasm_module->memory_count > 0) + is_memory64 = !!(wasm_module->memories[0].flags & MEMORY64_FLAG); + + if (!(option->bounds_checks == 1 || option->bounds_checks == 0) + && is_memory64) { + /* For memory64, the boundary check default value is true */ + comp_ctx->enable_bound_check = true; + } /* Return error if SIMD is disabled by command line but SIMD instructions * are used */ diff --git a/wamr-compiler/main.c b/wamr-compiler/main.c index f74b2fb15..c9c4ac5da 100644 --- a/wamr-compiler/main.c +++ b/wamr-compiler/main.c @@ -137,9 +137,12 @@ print_help() printf(" 3 - Small code model\n"); printf(" -sgx Generate code for SGX platform (Intel Software Guard Extensions)\n"); printf(" --bounds-checks=1/0 Enable or disable the bounds checks for memory access:\n"); - printf(" by default it is disabled in all 64-bit platforms except SGX and\n"); - printf(" in these platforms runtime does bounds checks with hardware trap,\n"); - printf(" and by default it is enabled in all 32-bit platforms\n"); + printf(" This flag controls bounds checking with a software check. \n"); + printf(" On 64-bit platforms, it is disabled by default, using a hardware \n"); + printf(" trap if supported, except when SGX or memory64 is enabled,\n"); + printf(" which defaults to a software check.\n"); + printf(" On 32-bit platforms, the flag is enabled by default, using a software check\n"); + printf(" due to the lack of hardware support.\n"); printf(" CAVEAT: --bounds-checks=0 enables some optimizations\n"); printf(" which make the compiled AOT module incompatible\n"); printf(" with a runtime without the hardware bounds checks.\n");