Skip to content

Commit 28456a5

Browse files
w4454962lum1n0us
authored andcommitted
Fix errors on the "i386-windows-msvc" platform
1 parent 751cdcf commit 28456a5

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
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: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,39 @@ void __umoddi3();
3030
#pragma function(floor)
3131
#pragma function(ceil)
3232

33-
static int64
34-
__divdi3(int64 a, int64 b)
33+
static int64 __stdcall __divdi3(int64 a, int64 b)
3534
{
3635
return a / b;
3736
}
3837

39-
static uint64
40-
__udivdi3(uint64 a, uint64 b)
38+
static uint64 __stdcall __udivdi3(uint64 a, uint64 b)
4139
{
4240
return a / b;
4341
}
4442

45-
static int64
46-
__moddi3(int64 a, int64 b)
43+
static int64 __stdcall __moddi3(int64 a, int64 b)
4744
{
4845
return a % b;
4946
}
5047

51-
static uint64
52-
__umoddi3(uint64 a, uint64 b)
48+
static uint64 __stdcall __umoddi3(uint64 a, uint64 b)
5349
{
5450
return a % b;
5551
}
5652
#endif
5753

58-
static uint64
59-
__aulldiv(uint64 a, uint64 b)
54+
static uint64 __stdcall __aulldiv(uint64 a, uint64 b)
6055
{
6156
return a / b;
6257
}
58+
static int64 __stdcall __alldiv(int64 a, int64 b)
59+
{
60+
return a / b;
61+
}
62+
static int64 __stdcall __allrem(int64 a, int64 b)
63+
{
64+
return a % b;
65+
}
6366

6467
/* clang-format off */
6568
static SymbolMap target_sym_map[] = {
@@ -69,7 +72,9 @@ static SymbolMap target_sym_map[] = {
6972
REG_SYM(__udivdi3),
7073
REG_SYM(__moddi3),
7174
REG_SYM(__umoddi3),
72-
REG_SYM(__aulldiv)
75+
REG_SYM(__aulldiv),
76+
REG_SYM(__alldiv),
77+
REG_SYM(__allrem)
7378
};
7479
/* clang-format on */
7580

core/iwasm/compilation/aot_emit_aot_file.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,15 @@ 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
926+
&& *name == '_') {
927+
name++;
928+
}
923929
if ((!strcmp(relocation_group->section_name, ".text")
924930
|| !strcmp(relocation_group->section_name, ".ltext"))
925-
&& !strncmp(relocation->symbol_name, AOT_FUNC_INTERNAL_PREFIX,
931+
&& !strncmp(name, AOT_FUNC_INTERNAL_PREFIX,
926932
strlen(AOT_FUNC_INTERNAL_PREFIX))
927933
&& ((!strncmp(obj_data->comp_ctx->target_arch, "x86_64", 6)
928934
/* Windows AOT_COFF64_BIN_TYPE */
@@ -2489,8 +2495,13 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
24892495
relocation_count = relocation_group->relocation_count;
24902496
for (j = 0; j < relocation_count; j++) {
24912497
/* relocation to aot_func_internal#n */
2492-
if (str_starts_with(relocation->symbol_name,
2493-
AOT_FUNC_INTERNAL_PREFIX)
2498+
const char *name = relocation->symbol_name;
2499+
if (name
2500+
&& obj_data->target_info.bin_type == AOT_COFF32_BIN_TYPE
2501+
&& *name == '_') {
2502+
name++;
2503+
}
2504+
if (str_starts_with(name, AOT_FUNC_INTERNAL_PREFIX)
24942505
&& ((obj_data->target_info.bin_type
24952506
== 6 /* AOT_COFF64_BIN_TYPE */
24962507
&& relocation->relocation_type
@@ -2500,8 +2511,7 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
25002511
&& relocation->relocation_type
25012512
== 20 /* IMAGE_REL_I386_REL32 */))) {
25022513
uint32 func_idx =
2503-
atoi(relocation->symbol_name
2504-
+ strlen(AOT_FUNC_INTERNAL_PREFIX));
2514+
atoi(name + strlen(AOT_FUNC_INTERNAL_PREFIX));
25052515
uint64 text_offset, reloc_offset, reloc_addend;
25062516

25072517
bh_assert(func_idx < obj_data->func_count);
@@ -3695,8 +3705,12 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
36953705
}
36963706

36973707
while (!LLVMObjectFileIsSymbolIteratorAtEnd(obj_data->binary, sym_itr)) {
3698-
if ((name = (char *)LLVMGetSymbolName(sym_itr))
3699-
&& str_starts_with(name, prefix)) {
3708+
name = (char *)LLVMGetSymbolName(sym_itr);
3709+
if (name && obj_data->target_info.bin_type == AOT_COFF32_BIN_TYPE
3710+
&& *name == '_') {
3711+
name++;
3712+
}
3713+
if (name && str_starts_with(name, prefix)) {
37003714
/* symbol aot_func#n */
37013715
func_index = (uint32)atoi(name + strlen(prefix));
37023716
if (func_index < obj_data->func_count) {
@@ -3734,8 +3748,7 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
37343748
}
37353749
}
37363750
}
3737-
else if ((name = (char *)LLVMGetSymbolName(sym_itr))
3738-
&& str_starts_with(name, AOT_FUNC_INTERNAL_PREFIX)) {
3751+
else if (name && str_starts_with(name, AOT_FUNC_INTERNAL_PREFIX)) {
37393752
/* symbol aot_func_internal#n */
37403753
func_index = (uint32)atoi(name + strlen(AOT_FUNC_INTERNAL_PREFIX));
37413754
if (func_index < obj_data->func_count) {

0 commit comments

Comments
 (0)