Skip to content

Commit e62bbeb

Browse files
authored
Refine wasm loader and interpreter, enhance wamrc to support SGX (#167)
Former-commit-id: 76f4a12 [formerly b1ab479] Former-commit-id: 8e5c6e8
1 parent 20cf199 commit e62bbeb

File tree

16 files changed

+304
-342
lines changed

16 files changed

+304
-342
lines changed

core/iwasm/aot/aot_loader.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,8 @@ apply_relocation(AOTModule *module,
12831283
if ((int32)target_addr != target_addr) {
12841284
set_error_buf(error_buf, error_buf_size,
12851285
"AOT module load failed: "
1286-
"relocation truncated to fit R_X86_64_PC32 failed");
1286+
"relocation truncated to fit R_X86_64_PC32 failed. "
1287+
"Try using wamrc with --size-level=1 option.");
12871288
return false;
12881289
}
12891290

@@ -1305,7 +1306,8 @@ apply_relocation(AOTModule *module,
13051306
&& (int32)target_addr != (int64)target_addr)) {
13061307
snprintf(buf, sizeof(buf),
13071308
"AOT module load failed: "
1308-
"relocation truncated to fit %s failed",
1309+
"relocation truncated to fit %s failed. "
1310+
"Try using wamrc with --size-level=1 option.",
13091311
reloc_type == R_X86_64_32
13101312
? "R_X86_64_32" : "R_X86_64_32S");
13111313
set_error_buf(error_buf, error_buf_size, buf);
@@ -1335,7 +1337,8 @@ apply_relocation(AOTModule *module,
13351337
if ((int32)target_addr != target_addr) {
13361338
set_error_buf(error_buf, error_buf_size,
13371339
"AOT module load failed: "
1338-
"relocation truncated to fit R_X86_64_PC32 failed");
1340+
"relocation truncated to fit R_X86_64_PC32 failed. "
1341+
"Try using wamrc with --size-level=1 option.");
13391342
return false;
13401343
}
13411344

core/iwasm/compilation/aot_compiler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index)
186186
return false;
187187
break;
188188

189-
case WASM_OP_DROP_32:
189+
case WASM_OP_DROP:
190190
if (!aot_compile_op_drop(comp_ctx, func_ctx, true))
191191
return false;
192192
break;
@@ -196,7 +196,7 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index)
196196
return false;
197197
break;
198198

199-
case WASM_OP_SELECT_32:
199+
case WASM_OP_SELECT:
200200
if (!aot_compile_op_select(comp_ctx, func_ctx, true))
201201
return false;
202202
break;

core/iwasm/compilation/aot_llvm.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,8 @@ aot_create_comp_context(AOTCompData *comp_data,
837837
char *triple_norm_new = NULL, *cpu_new = NULL;
838838
char *err = NULL, *fp_round= "round.tonearest", *fp_exce = "fpexcept.strict";
839839
char triple_buf[32] = {0};
840-
uint32 opt_level;
840+
uint32 opt_level, size_level;
841+
LLVMCodeModel code_model;
841842

842843
/* Initialize LLVM environment */
843844
LLVMInitializeAllTargetInfos();
@@ -896,6 +897,7 @@ aot_create_comp_context(AOTCompData *comp_data,
896897
cpu = option->target_cpu;
897898
features = option->cpu_features;
898899
opt_level = option->opt_level;
900+
size_level = option->size_level;
899901

900902
if (arch) {
901903
/* Add default sub-arch if not specified */
@@ -1001,6 +1003,7 @@ aot_create_comp_context(AOTCompData *comp_data,
10011003
bh_printf(" target cpu: %s\n", cpu);
10021004
bh_printf(" cpu features: %s\n", features);
10031005
bh_printf(" opt level: %d\n", opt_level);
1006+
bh_printf(" size level: %d\n", size_level);
10041007
switch (option->output_format) {
10051008
case AOT_LLVMIR_UNOPT_FILE:
10061009
bh_printf(" output format: unoptimized LLVM IR\n");
@@ -1030,11 +1033,21 @@ aot_create_comp_context(AOTCompData *comp_data,
10301033
goto fail;
10311034
}
10321035

1036+
/* Set code model */
1037+
if (size_level == 0)
1038+
code_model = LLVMCodeModelLarge;
1039+
else if (size_level == 1)
1040+
code_model = LLVMCodeModelMedium;
1041+
else if (size_level == 2)
1042+
code_model = LLVMCodeModelKernel;
1043+
else
1044+
code_model = LLVMCodeModelSmall;
1045+
10331046
/* Create the target machine */
10341047
if (!(comp_ctx->target_machine =
10351048
LLVMCreateTargetMachine(target, triple_norm, cpu, features,
10361049
opt_level, LLVMRelocStatic,
1037-
LLVMCodeModelSmall))) {
1050+
code_model))) {
10381051
aot_set_last_error("create LLVM target machine failed.");
10391052
goto fail;
10401053
}

core/iwasm/compilation/aot_llvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ typedef struct AOTCompOption{
219219
char *target_cpu;
220220
char *cpu_features;
221221
uint32 opt_level;
222+
uint32 size_level;
222223
uint32 output_format;
223224
} AOTCompOption, *aot_comp_option_t;
224225

core/iwasm/include/aot_export.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef struct AOTCompOption{
4040
char *target_cpu;
4141
char *cpu_features;
4242
uint32_t opt_level;
43+
uint32_t size_level;
4344
uint32_t output_format;
4445
} AOTCompOption, *aot_comp_option_t;
4546

core/iwasm/interpreter/wasm.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ typedef struct WASMFunction {
167167
WASMType *func_type;
168168
uint32 local_count;
169169
uint8 *local_types;
170+
171+
/* cell num of parameters */
172+
uint16 param_cell_num;
173+
/* cell num of return type */
174+
uint16 ret_cell_num;
175+
/* cell num of local variables */
176+
uint16 local_cell_num;
177+
/* offset of each local, including function paramameters
178+
and local variables */
179+
uint16 *local_offsets;
180+
170181
uint32 max_stack_cell_num;
171182
uint32 max_block_num;
172183
/* Whether function has opcode memory.grow */
@@ -226,6 +237,11 @@ typedef struct WASIArguments {
226237
} WASIArguments;
227238
#endif
228239

240+
typedef struct StringNode {
241+
struct StringNode *next;
242+
char *str;
243+
} StringNode, *StringList;
244+
229245
typedef struct WASMModule {
230246
/* Module type, for module loaded from WASM bytecode binary,
231247
this field is Wasm_Module_Bytecode;
@@ -279,7 +295,8 @@ typedef struct WASMModule {
279295
memory.grow opcode or call enlargeMemory */
280296
bool possible_memory_grow;
281297

282-
HashMap *const_str_set;
298+
StringList const_str_list;
299+
283300
BlockAddr block_addr_cache[BLOCK_ADDR_CACHE_SIZE][BLOCK_ADDR_CONFLICT_SIZE];
284301

285302
#if WASM_ENABLE_LIBC_WASI != 0
@@ -291,8 +308,7 @@ typedef struct WASMModule {
291308
typedef struct WASMBranchBlock {
292309
uint8 block_type;
293310
uint8 return_type;
294-
uint8 *start_addr;
295-
uint8 *end_addr;
311+
uint8 *target_addr;
296312
uint32 *frame_sp;
297313
} WASMBranchBlock;
298314

0 commit comments

Comments
 (0)