Hi,
I digged into the code and debug the asm code generated by mingw(x64), I think
it's a bug of mingw, I found mingw generated wrong asm code if pass more than 4
parameters in x64,
see code below:
JSValue JS_Eval(JSContext *ctx, const char *input, size_t input_len,
const char *filename, int eval_flags)
{
000000006C6D7740 push rbp
000000006C6D7741 mov rbp,rsp
000000006C6D7744 sub rsp,70h
000000006C6D7748 mov qword ptr [rbp+10h],rcx ; I don't know why
rcx(it's ctx) moved to [rbp+10h]
000000006C6D774C mov qword ptr [ctx],rdx ; ctx is wrong, it's "input"
000000006C6D7750 mov qword ptr [input],r8 ; input is wrong, it's
input_len
000000006C6D7754 mov dword ptr [input_len],r9d ; only process 4
arguments, missing eval_flags
vc passed parameters like:
JSValue ret = JS_Eval(ctx, src, strlen(src), "eval", 0);
00007FF6F44A2B8B mov rcx,qword ptr [src]
00007FF6F44A2B8F call strlen (07FF6F44A1032h)
00007FF6F44A2B94 cdqe
00007FF6F44A2B96 mov dword ptr [rsp+20h],0
00007FF6F44A2B9E lea r9,[string "eval" (07FF6F44AAC28h)]
00007FF6F44A2BA5 mov r8,rax
00007FF6F44A2BA8 mov rdx,qword ptr [src]
00007FF6F44A2BAC mov rcx,qword ptr [ctx]
00007FF6F44A2BB0 call JS_Eval (07FF6F44A1758h)
VC pass 5 arguments from right to left to rcx,rdx,r8,r9 and stack, but
mingw(x64) only read 4 misplaced, I read many articles for this problem, but
can't find any helps.
At 2020-01-08 15:46:54, "sineysan" <sineysan@xxxxxxx> wrote:
Hi,
I found same code if I using x86_64-w64-mingw32-g++.exe to compile and test, it
works, not crash, but using vc 2017 (x64) instead of
x86_64-w64-mingw32-g++.exe, it will crash like below.
Using vc2017 (x86) to link a dll generated by i686-w64-mingw32-gcc.exe, it
works. I'm confused. Is it a problem of calling convention ?
在 2020-01-08 15:30:55,"sineysan" <sineysan@xxxxxxx> 写道:
I use mingw-64 cross compile for window10, if I you i686 arch of mingw to
compile quickjs to genereate dll named libquickjs.dll, it works.
But if I use x86-64 arch , same test code will crash, see blow image,
it will crash on JS_Eval function , but first 2 functions call is ok, does
quickjs support x64 arch or not?