Fix fast-interp "pre-compiled label offset out of range" issue (#2659)
When labels-as-values is enabled in a target which doesn't support unaligned address access, 16-bit offset is used to store the relative offset between two opcode labels. But it is a little small and the loader may report "pre-compiled label offset out of range" error. Emitting 32-bit data instead to resolve the issue: emit label address in 32-bit target and emit 32-bit relative offset in 64-bit target. See also: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2635
This commit is contained in:
@ -1128,12 +1128,27 @@ wasm_interp_dump_op_count()
|
||||
goto *p_label_addr; \
|
||||
} while (0)
|
||||
#else
|
||||
#define FETCH_OPCODE_AND_DISPATCH() \
|
||||
do { \
|
||||
const void *p_label_addr = label_base + *(int16 *)frame_ip; \
|
||||
frame_ip += sizeof(int16); \
|
||||
goto *p_label_addr; \
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
#define FETCH_OPCODE_AND_DISPATCH() \
|
||||
do { \
|
||||
const void *p_label_addr; \
|
||||
bh_assert(((uintptr_t)frame_ip & 1) == 0); \
|
||||
/* int32 relative offset was emitted in 64-bit target */ \
|
||||
p_label_addr = label_base + (int32)LOAD_U32_WITH_2U16S(frame_ip); \
|
||||
frame_ip += sizeof(int32); \
|
||||
goto *p_label_addr; \
|
||||
} while (0)
|
||||
#else
|
||||
#define FETCH_OPCODE_AND_DISPATCH() \
|
||||
do { \
|
||||
const void *p_label_addr; \
|
||||
bh_assert(((uintptr_t)frame_ip & 1) == 0); \
|
||||
/* uint32 label address was emitted in 32-bit target */ \
|
||||
p_label_addr = (void *)(uintptr_t)LOAD_U32_WITH_2U16S(frame_ip); \
|
||||
frame_ip += sizeof(int32); \
|
||||
goto *p_label_addr; \
|
||||
} while (0)
|
||||
#endif
|
||||
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
||||
#define HANDLE_OP_END() FETCH_OPCODE_AND_DISPATCH()
|
||||
|
||||
@ -1183,7 +1198,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
register uint8 *frame_ip = &opcode_IMPDEP; /* cache of frame->ip */
|
||||
register uint32 *frame_lp = NULL; /* cache of frame->lp */
|
||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
|
||||
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 && UINTPTR_MAX == UINT64_MAX
|
||||
/* cache of label base addr */
|
||||
register uint8 *label_base = &&HANDLE_WASM_OP_UNREACHABLE;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user