Skip to content

Commit

Permalink
Refine wasm loader and interpreter, enhance wamrc to support SGX (#167)
Browse files Browse the repository at this point in the history
Former-commit-id: 76f4a12 [formerly b1ab479]
Former-commit-id: 8e5c6e8
  • Loading branch information
wenyongh authored Feb 18, 2020
1 parent 20cf199 commit e62bbeb
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 342 deletions.
9 changes: 6 additions & 3 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,8 @@ apply_relocation(AOTModule *module,
if ((int32)target_addr != target_addr) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"relocation truncated to fit R_X86_64_PC32 failed");
"relocation truncated to fit R_X86_64_PC32 failed. "
"Try using wamrc with --size-level=1 option.");
return false;
}

Expand All @@ -1305,7 +1306,8 @@ apply_relocation(AOTModule *module,
&& (int32)target_addr != (int64)target_addr)) {
snprintf(buf, sizeof(buf),
"AOT module load failed: "
"relocation truncated to fit %s failed",
"relocation truncated to fit %s failed. "
"Try using wamrc with --size-level=1 option.",
reloc_type == R_X86_64_32
? "R_X86_64_32" : "R_X86_64_32S");
set_error_buf(error_buf, error_buf_size, buf);
Expand Down Expand Up @@ -1335,7 +1337,8 @@ apply_relocation(AOTModule *module,
if ((int32)target_addr != target_addr) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"relocation truncated to fit R_X86_64_PC32 failed");
"relocation truncated to fit R_X86_64_PC32 failed. "
"Try using wamrc with --size-level=1 option.");
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/compilation/aot_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index)
return false;
break;

case WASM_OP_DROP_32:
case WASM_OP_DROP:
if (!aot_compile_op_drop(comp_ctx, func_ctx, true))
return false;
break;
Expand All @@ -196,7 +196,7 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index)
return false;
break;

case WASM_OP_SELECT_32:
case WASM_OP_SELECT:
if (!aot_compile_op_select(comp_ctx, func_ctx, true))
return false;
break;
Expand Down
17 changes: 15 additions & 2 deletions core/iwasm/compilation/aot_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,8 @@ aot_create_comp_context(AOTCompData *comp_data,
char *triple_norm_new = NULL, *cpu_new = NULL;
char *err = NULL, *fp_round= "round.tonearest", *fp_exce = "fpexcept.strict";
char triple_buf[32] = {0};
uint32 opt_level;
uint32 opt_level, size_level;
LLVMCodeModel code_model;

/* Initialize LLVM environment */
LLVMInitializeAllTargetInfos();
Expand Down Expand Up @@ -896,6 +897,7 @@ aot_create_comp_context(AOTCompData *comp_data,
cpu = option->target_cpu;
features = option->cpu_features;
opt_level = option->opt_level;
size_level = option->size_level;

if (arch) {
/* Add default sub-arch if not specified */
Expand Down Expand Up @@ -1001,6 +1003,7 @@ aot_create_comp_context(AOTCompData *comp_data,
bh_printf(" target cpu: %s\n", cpu);
bh_printf(" cpu features: %s\n", features);
bh_printf(" opt level: %d\n", opt_level);
bh_printf(" size level: %d\n", size_level);
switch (option->output_format) {
case AOT_LLVMIR_UNOPT_FILE:
bh_printf(" output format: unoptimized LLVM IR\n");
Expand Down Expand Up @@ -1030,11 +1033,21 @@ aot_create_comp_context(AOTCompData *comp_data,
goto fail;
}

/* Set code model */
if (size_level == 0)
code_model = LLVMCodeModelLarge;
else if (size_level == 1)
code_model = LLVMCodeModelMedium;
else if (size_level == 2)
code_model = LLVMCodeModelKernel;
else
code_model = LLVMCodeModelSmall;

/* Create the target machine */
if (!(comp_ctx->target_machine =
LLVMCreateTargetMachine(target, triple_norm, cpu, features,
opt_level, LLVMRelocStatic,
LLVMCodeModelSmall))) {
code_model))) {
aot_set_last_error("create LLVM target machine failed.");
goto fail;
}
Expand Down
1 change: 1 addition & 0 deletions core/iwasm/compilation/aot_llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ typedef struct AOTCompOption{
char *target_cpu;
char *cpu_features;
uint32 opt_level;
uint32 size_level;
uint32 output_format;
} AOTCompOption, *aot_comp_option_t;

Expand Down
1 change: 1 addition & 0 deletions core/iwasm/include/aot_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef struct AOTCompOption{
char *target_cpu;
char *cpu_features;
uint32_t opt_level;
uint32_t size_level;
uint32_t output_format;
} AOTCompOption, *aot_comp_option_t;

Expand Down
22 changes: 19 additions & 3 deletions core/iwasm/interpreter/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ typedef struct WASMFunction {
WASMType *func_type;
uint32 local_count;
uint8 *local_types;

/* cell num of parameters */
uint16 param_cell_num;
/* cell num of return type */
uint16 ret_cell_num;
/* cell num of local variables */
uint16 local_cell_num;
/* offset of each local, including function paramameters
and local variables */
uint16 *local_offsets;

uint32 max_stack_cell_num;
uint32 max_block_num;
/* Whether function has opcode memory.grow */
Expand Down Expand Up @@ -226,6 +237,11 @@ typedef struct WASIArguments {
} WASIArguments;
#endif

typedef struct StringNode {
struct StringNode *next;
char *str;
} StringNode, *StringList;

typedef struct WASMModule {
/* Module type, for module loaded from WASM bytecode binary,
this field is Wasm_Module_Bytecode;
Expand Down Expand Up @@ -279,7 +295,8 @@ typedef struct WASMModule {
memory.grow opcode or call enlargeMemory */
bool possible_memory_grow;

HashMap *const_str_set;
StringList const_str_list;

BlockAddr block_addr_cache[BLOCK_ADDR_CACHE_SIZE][BLOCK_ADDR_CONFLICT_SIZE];

#if WASM_ENABLE_LIBC_WASI != 0
Expand All @@ -291,8 +308,7 @@ typedef struct WASMModule {
typedef struct WASMBranchBlock {
uint8 block_type;
uint8 return_type;
uint8 *start_addr;
uint8 *end_addr;
uint8 *target_addr;
uint32 *frame_sp;
} WASMBranchBlock;

Expand Down
Loading

0 comments on commit e62bbeb

Please sign in to comment.