Open XinyuShe opened 7 months ago
Hi, this issue is a combination of issue #2678 and issue #2773: different nan values are used in wamr and other runtimes and cause different input offset for the v128.load32_zero opcode, for wamr, the input will cause OOB exception thrown when "--bounds-checks=1" is enabled for wamrc, for others, the input won't cause OOB exception. And for wamr, the OOB exception isn't thrown when "--bounds-checks=1" isn't added for wamrc, since the v128.load32_zero bytecode is eliminated as dead code, see #2773.
In function 14, in the below bytecodes:
end
i32.const 1
v128.load16x4_s offset=4187 align=1
local.get 0
i32x4.extract_lane 1
v128.load32_zero offset=2862 align=1
After the execution of some bytecodes, there is an nan in the input operand of the opcode i32x4.extract_lane 1
, some other runtimes normalize the nan to 0x7ff80000
and the operand for this opcode is 0x00000000 0x7ff80000 0x00000000 0x7ff80000
, and the result is: 2146959360, so the next v128.load32_zero doesn't throw exception. For WAMR, the result is -1 (=UINT32_MAX), after adding 2862, the boundary check fails and throws exception.
And this bytecode is eliminated when "--bounds-checks=1" isn't added for wamrc, we can disable the dead code elimination by setting Volatile for v128 load, and the exception will be thrown again:
diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c
index 8c35c3fe..d859a7e2 100644
--- a/core/iwasm/compilation/aot_emit_memory.c
+++ b/core/iwasm/compilation/aot_emit_memory.c
@@ -299,6 +299,7 @@ fail:
goto fail; \
} \
LLVMSetAlignment(value, 1); \
+ LLVMSetVolatile(value, true); \
} while (0)
#define BUILD_TRUNC(value, data_type) \
diff --git a/core/iwasm/compilation/simd/simd_load_store.c b/core/iwasm/compilation/simd/simd_load_store.c
index 0e869727..1be07f7f 100644
--- a/core/iwasm/compilation/simd/simd_load_store.c
+++ b/core/iwasm/compilation/simd/simd_load_store.c
@@ -36,6 +36,7 @@ simd_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align,
}
LLVMSetAlignment(data, 1);
+ LLVMSetVolatile(data, true);
I used the AOT mode of different runtimes to run randomly generated wasm binaries, and the output from WAMR was different from the others. filea262_9.zip
WAMR used a commit from November 24th and the
--bounds-checks=1
feature.