vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
MIT License
2.24k stars 147 forks source link

__GNU_LIBRARY__ isn't good in mirc_x86_64_stdarg.h #322

Closed Kray-G closed 1 year ago

Kray-G commented 1 year ago

I would like you to see details on #321, but let me report it again.

I found some errors in c2m.exe on Windows, and it caused by the file of mirc_x86_64_stdarg.h. At the beginning, I felt some mistakes with the macro of __WIN32 because MSVC doesn't have __WIN32 and it has _WIN32 instead. However, it has another error when I replaced it by _WIN32.

When I digged into the source file, this macro's branch has no #else clause and __WIN32 macro also doesn't work, so the frst problem has occurred. But even if I replaced it by _WIN32, the __va_start macro doesn't work by the error of not found on c2m.exe on Windows, that's why the second problem has occurred.

At least, this macro's branch has no #else clause, so it needs #else clause anyway, and now I am trying to find the correct fix but I didn't find anything so far. Therefore, this fix could be better as a workaround, so could you make it back to #else? My project is going well with this fix so far.

Thank you so much in advance.

vnmakarov commented 1 year ago

Thank you for reporting this and trying to make a fix.

Unfortunately windows port is currently not supported. What you see is the initial code for the windows port. Although I guess the most tests are still working.

What you are proposing with this change is basically to use SYSV ABI for varargs instead of Windows one. As all generated code using the same ABI, it is ok. But mixed code (e.g. calling standard library functions) might not work. So I'd rather avoid to commit the PR.

It is very hard to do native Windows port as the development documentation is not good and there is no source code to look at to resolve the issues. For example, I wasted so much time to make setjmp/longjmp working on Windows and failed. Windows requires specific function code generation and even after modifying code generation required by Windows documentation, I did not manage to make longjmp/setjmp working.

I'd like to try again to finish a native Windows port but I don't know when I really will have time for this. Even maintenance of MIR is difficult (although I am committed to this) as there are more higher priority projects I am involved in.

Kray-G commented 1 year ago

Thanks for your comment. I understand your opinion about what to do on your project. Actually, I am really in trouble with this error, so I am in the situation where I have to use a modified version on myself. That's why it would be really helpful if you could accept it even only if it would be a temporary workaround until you've got a real fix that have to be.

After you accept it, how about you having enough time to fix it with the best way that you think?

vnmakarov commented 1 year ago

After you accept it, how about you having enough time to fix it with the best way that you think?

I've merged your PR. I was afraid that it can affect musl based linux but it seems the change is ok for musl.

Kray-G commented 1 year ago

Thank you so much for accepting it. That's really helpful for me. I had an experience with the problem on the differences between MS ABI and SYSV ABI, so I know that's so tough work especially for mixed code as you said.

Anyway I am very appriciative of you and it works with my project. Thanks a lot.