Просмотр исходного кода

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 лет назад
Родитель
Сommit
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 {
             /* Store extra return values to function parameters */
             if (i != 0) {
+                LLVMValueRef res;
                 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.");
                     goto fail;
                 }
+                LLVMSetAlignment(res, 1);
             }
         }
     }
@@ -1102,14 +1104,17 @@ aot_compile_op_return(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
     if (block_func->result_count) {
         /* Store extra result values to function parameters */
         for (i = 0; i < block_func->result_count - 1; i++) {
+            LLVMValueRef res;
             result_index = block_func->result_count - 1 - i;
             POP(value, block_func->result_types[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.");
                 goto fail;
             }
+            LLVMSetAlignment(res, 1);
         }
         /* Return the first result value */
         POP(value, block_func->result_types[0]);