Skip to content

Commit fae2e54

Browse files
committed
Fix errors on the "i386-windows-msvc" platform
1 parent 4e50d21 commit fae2e54

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

core/iwasm/aot/aot_runtime.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,8 +3327,25 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
33273327
return true;
33283328
}
33293329
else {
3330+
#if WASM_ENABLE_AOT_STACK_FRAME != 0
3331+
void *prev_frame = get_top_frame(exec_env);
3332+
/* Only allocate frame for frame-per-call mode; in the
3333+
frame-per-function mode the frame is allocated at the
3334+
beginning of the function. */
3335+
if (!is_frame_per_function(exec_env)
3336+
&& !aot_alloc_frame(exec_env, table_elem_idx)) {
3337+
return false;
3338+
}
3339+
#endif
33303340
ret = invoke_native_internal(exec_env, func_ptr, func_type, signature,
33313341
attachment, argv, argc, argv);
3342+
#if WASM_ENABLE_AOT_STACK_FRAME != 0
3343+
/* Free all frames allocated, note that some frames
3344+
may be allocated in AOT code and haven't been
3345+
freed if exception occurred */
3346+
while (get_top_frame(exec_env) != prev_frame)
3347+
aot_free_frame(exec_env);
3348+
#endif
33323349
if (!ret)
33333350
goto fail;
33343351

core/iwasm/aot/arch/aot_reloc_x86_32.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,47 @@ void __umoddi3();
3030
#pragma function(floor)
3131
#pragma function(ceil)
3232

33-
static int64
33+
static int64 __stdcall
3434
__divdi3(int64 a, int64 b)
3535
{
3636
return a / b;
3737
}
3838

39-
static uint64
39+
static uint64 __stdcall
4040
__udivdi3(uint64 a, uint64 b)
4141
{
4242
return a / b;
4343
}
4444

45-
static int64
45+
static int64 __stdcall
4646
__moddi3(int64 a, int64 b)
4747
{
4848
return a % b;
4949
}
5050

51-
static uint64
51+
static uint64 __stdcall
5252
__umoddi3(uint64 a, uint64 b)
5353
{
5454
return a % b;
5555
}
5656
#endif
5757

58-
static uint64
58+
static uint64 __stdcall
5959
__aulldiv(uint64 a, uint64 b)
6060
{
6161
return a / b;
6262
}
63+
static int64 __stdcall
64+
__alldiv(int64 a, int64 b)
65+
{
66+
return a / b;
67+
}
68+
static int64 __stdcall
69+
__allrem(int64 a, int64 b)
70+
{
71+
return a % b;
72+
}
73+
6374

6475
/* clang-format off */
6576
static SymbolMap target_sym_map[] = {
@@ -69,7 +80,9 @@ static SymbolMap target_sym_map[] = {
6980
REG_SYM(__udivdi3),
7081
REG_SYM(__moddi3),
7182
REG_SYM(__umoddi3),
72-
REG_SYM(__aulldiv)
83+
REG_SYM(__aulldiv),
84+
REG_SYM(__alldiv),
85+
REG_SYM(__allrem)
7386
};
7487
/* clang-format on */
7588

core/iwasm/compilation/aot_emit_aot_file.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,14 @@ get_relocations_size(AOTObjectData *obj_data,
920920
/* ignore the relocations to aot_func_internal#n in text section
921921
for windows platform since they will be applied in
922922
aot_emit_text_section */
923+
924+
const char* name = relocation->symbol_name;
925+
if (name && obj_data->target_info.bin_type == AOT_COFF32_BIN_TYPE && *name == '_') {
926+
name++;
927+
}
923928
if ((!strcmp(relocation_group->section_name, ".text")
924929
|| !strcmp(relocation_group->section_name, ".ltext"))
925-
&& !strncmp(relocation->symbol_name, AOT_FUNC_INTERNAL_PREFIX,
930+
&& !strncmp(name, AOT_FUNC_INTERNAL_PREFIX,
926931
strlen(AOT_FUNC_INTERNAL_PREFIX))
927932
&& ((!strncmp(obj_data->comp_ctx->target_arch, "x86_64", 6)
928933
/* Windows AOT_COFF64_BIN_TYPE */
@@ -2489,7 +2494,11 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
24892494
relocation_count = relocation_group->relocation_count;
24902495
for (j = 0; j < relocation_count; j++) {
24912496
/* relocation to aot_func_internal#n */
2492-
if (str_starts_with(relocation->symbol_name,
2497+
const char* name = relocation->symbol_name;
2498+
if (name && obj_data->target_info.bin_type == AOT_COFF32_BIN_TYPE && *name == '_') {
2499+
name++;
2500+
}
2501+
if (str_starts_with(name,
24932502
AOT_FUNC_INTERNAL_PREFIX)
24942503
&& ((obj_data->target_info.bin_type
24952504
== 6 /* AOT_COFF64_BIN_TYPE */
@@ -2500,7 +2509,7 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
25002509
&& relocation->relocation_type
25012510
== 20 /* IMAGE_REL_I386_REL32 */))) {
25022511
uint32 func_idx =
2503-
atoi(relocation->symbol_name
2512+
atoi(name
25042513
+ strlen(AOT_FUNC_INTERNAL_PREFIX));
25052514
uint64 text_offset, reloc_offset, reloc_addend;
25062515

@@ -3695,8 +3704,11 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
36953704
}
36963705

36973706
while (!LLVMObjectFileIsSymbolIteratorAtEnd(obj_data->binary, sym_itr)) {
3698-
if ((name = (char *)LLVMGetSymbolName(sym_itr))
3699-
&& str_starts_with(name, prefix)) {
3707+
name = (char *)LLVMGetSymbolName(sym_itr);
3708+
if (name && obj_data->target_info.bin_type == AOT_COFF32_BIN_TYPE && *name == '_') {
3709+
name++;
3710+
}
3711+
if (name && str_starts_with(name, prefix)) {
37003712
/* symbol aot_func#n */
37013713
func_index = (uint32)atoi(name + strlen(prefix));
37023714
if (func_index < obj_data->func_count) {
@@ -3734,8 +3746,7 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
37343746
}
37353747
}
37363748
}
3737-
else if ((name = (char *)LLVMGetSymbolName(sym_itr))
3738-
&& str_starts_with(name, AOT_FUNC_INTERNAL_PREFIX)) {
3749+
else if (name && str_starts_with(name, AOT_FUNC_INTERNAL_PREFIX)) {
37393750
/* symbol aot_func_internal#n */
37403751
func_index = (uint32)atoi(name + strlen(AOT_FUNC_INTERNAL_PREFIX));
37413752
if (func_index < obj_data->func_count) {

0 commit comments

Comments
 (0)