From 02370acdc9967255cd06a928499fd1981356595e Mon Sep 17 00:00:00 2001 From: Zhang Boyang Date: Sat, 9 Sep 2017 21:01:42 +0800 Subject: [PATCH] Fix AL/AX is not extended to EAX when calling indirectly AL/AX should be extended to EAX when calling functions. However, the previous code did this only for direct calls, indirect calls were ignored. New code also avoid redundant code when generating JMP instruction. (i.e. expanding code should be generated with CALL instruction only) --- i386-gen.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/i386-gen.c b/i386-gen.c index f1d95cd..ef893b3 100644 --- a/i386-gen.c +++ b/i386-gen.c @@ -346,7 +346,6 @@ static void gcall_or_jmp(int is_jmp) { int r; if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { - int rt; /* constant case */ if (vtop->r & VT_SYM) { /* relocation case */ @@ -358,6 +357,14 @@ static void gcall_or_jmp(int is_jmp) ind + 1, R_386_PC32, 0); } oad(0xe8 + is_jmp, vtop->c.i - 4); /* call/jmp im */ + } else { + /* otherwise, indirect call */ + r = gv(RC_INT); + o(0xff); /* call/jmp *r */ + o(0xd0 + r + (is_jmp << 4)); + } + if (!is_jmp) { + int rt; /* extend the return value to the whole register if necessary visual studio and gcc do not always set the whole eax register when assigning the return value of a function */ @@ -382,11 +389,6 @@ static void gcall_or_jmp(int is_jmp) default: break; } - } else { - /* otherwise, indirect call */ - r = gv(RC_INT); - o(0xff); /* call/jmp *r */ - o(0xd0 + r + (is_jmp << 4)); } }