Skip to content

Conversation

wenyongh
Copy link
Contributor

@wenyongh wenyongh commented Apr 30, 2024

The current length type of aot_memmove/aot_memset is size_t, and on
a 64 bit host it is uint64, while what the aot code passes to it is uint32,
this might lead to unexpected behavior.

ps. #3375.

@wenyongh wenyongh changed the title aot compiler: Fix the length type passed to aot_memmove/aot_memset in aot compiler: Fix the length type passed to aot_memmove/aot_memset Apr 30, 2024
call_aot_memmove = comp_ctx->is_indirect_mode || comp_ctx->is_jit_mode;
if (call_aot_memmove) {
LLVMTypeRef param_types[3], ret_type, func_type, func_ptr_type;
LLVMValueRef func, params[3];

param_types[0] = INT8_PTR_TYPE;
param_types[1] = INT8_PTR_TYPE;
param_types[2] = I32_TYPE;
param_types[2] = INTPTR_T_TYPE; /* int32 for 32-bit, int64 for 64-bit */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we perhaps define SIZE_T_TYPE (or MEM_OFFSET_T_TYPE) instead? Even though it will (almost) always have the same value as INTPTR_T_TYPE, semantically pointer and size are different so the code would probably be slightly easier to read and maintain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, updated to use SIZE_T_TYPE instead. I didn't add MEM_OFFSET_T_TYPE since it cannot be decided by the target bit width, e.g. in 64-bit target, the memory may be 32-bit or 64-bit. Or it seems we had to define MEM_OFFSET_T_TYPE(memory) like macro to set its type according to the memory's type.

@yamt
Copy link
Collaborator

yamt commented Apr 30, 2024

ps. #3376.

wrong link?

@wenyongh
Copy link
Contributor Author

ps. #3376.

wrong link?

Yeah, should be #3375, thanks, updated.

/* zero extend to uint64 if the target is 64-bit */
len = LLVMBuildZExt(comp_ctx->builder, len, I64_TYPE, "len64");
if (!len) {
aot_set_last_error("llvm build bitcast failed.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a bitcast.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

/* zero extend to uint64 if the target is 64-bit */
len = LLVMBuildZExt(comp_ctx->builder, len, I64_TYPE, "len64");
if (!len) {
aot_set_last_error("llvm build bitcast failed.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Collaborator

@yamt yamt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@wenyongh wenyongh merged commit 835188c into bytecodealliance:main May 1, 2024
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 1, 2024
…ytecodealliance#3378)

The current length type of aot_memmove/aot_memset is size_t, and on
a 64 bit host it is uint64, while what the aot code passes to it is uint32,
this might lead to unexpected behavior.

ps. bytecodealliance#3376.
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 2, 2024
…ytecodealliance#3378)

The current length type of aot_memmove/aot_memset is size_t, and on
a 64 bit host it is uint64, while what the aot code passes to it is uint32,
this might lead to unexpected behavior.

ps. bytecodealliance#3376.

Signed-off-by: victoryang00 <[email protected]>
@wenyongh wenyongh deleted the fix_aot_compiler branch May 9, 2024 14:08
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…ytecodealliance#3378)

The current length type of aot_memmove/aot_memset is size_t, and on
a 64 bit host it is uint64, while what the aot code passes to it is uint32,
this might lead to unexpected behavior.

ps. bytecodealliance#3376.

Signed-off-by: victoryang00 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants