瀏覽代碼

Fix potential unaligned store issue when extra return value is v128 (#2583)

Unaligned store v128 value to the AOT function argument of the pointer for
the extra return value may cause segmentation fault.

Fix the issue reported in #2556.
TianlongLiang 2 年之前
父節點
當前提交
71e07a7fa4
共有 1 個文件被更改,包括 10 次插入5 次删除
  1. 10 5
      core/iwasm/compilation/aot_emit_control.c

+ 10 - 5
core/iwasm/compilation/aot_emit_control.c

@@ -234,13 +234,15 @@ handle_next_reachable_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
         else {
         else {
             /* Store extra return values to function parameters */
             /* Store extra return values to function parameters */
             if (i != 0) {
             if (i != 0) {
+                LLVMValueRef res;
                 uint32 param_index = func_type->param_count + i;
                 uint32 param_index = func_type->param_count + i;
-                if (!LLVMBuildStore(
-                        comp_ctx->builder, block->result_phis[i],
-                        LLVMGetParam(func_ctx->func, param_index))) {
+                if (!(res = LLVMBuildStore(
+                          comp_ctx->builder, block->result_phis[i],
+                          LLVMGetParam(func_ctx->func, param_index)))) {
                     aot_set_last_error("llvm build store failed.");
                     aot_set_last_error("llvm build store failed.");
                     goto fail;
                     goto fail;
                 }
                 }
+                LLVMSetAlignment(res, 1);
             }
             }
         }
         }
     }
     }
@@ -1102,14 +1104,17 @@ aot_compile_op_return(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
     if (block_func->result_count) {
     if (block_func->result_count) {
         /* Store extra result values to function parameters */
         /* Store extra result values to function parameters */
         for (i = 0; i < block_func->result_count - 1; i++) {
         for (i = 0; i < block_func->result_count - 1; i++) {
+            LLVMValueRef res;
             result_index = block_func->result_count - 1 - i;
             result_index = block_func->result_count - 1 - i;
             POP(value, block_func->result_types[result_index]);
             POP(value, block_func->result_types[result_index]);
             param_index = func_type->param_count + result_index;
             param_index = func_type->param_count + result_index;
-            if (!LLVMBuildStore(comp_ctx->builder, value,
-                                LLVMGetParam(func_ctx->func, param_index))) {
+            if (!(res = LLVMBuildStore(
+                      comp_ctx->builder, value,
+                      LLVMGetParam(func_ctx->func, param_index)))) {
                 aot_set_last_error("llvm build store failed.");
                 aot_set_last_error("llvm build store failed.");
                 goto fail;
                 goto fail;
             }
             }
+            LLVMSetAlignment(res, 1);
         }
         }
         /* Return the first result value */
         /* Return the first result value */
         POP(value, block_func->result_types[0]);
         POP(value, block_func->result_types[0]);