Baptiste Lepilleur
2009-Dec-09 08:28 UTC
[LLVMdev] Problem with code generated for call using stdcall convention
Hi, I'm trying to run the following module in lli on LLVM 2.6, Windows/MSVS 2008, 32 bits memory model: --- declare x86_stdcallcc i8* @GetStdHandle(i32) define i32 @main() { %handle = call i8* @GetStdHandle(i32 -11) ret i32 0 } --- (This small modules that just retrieve the handle to stdout using WIN32 API). I'm converting it to bytecode using: llvm-as.exe -f helloworldwin32.ll and running it with lli using: lli.exe helloworldwin32.bc which results into a crash. When debbugging the lli crash, I found the following code being called by llvm::ExecutionEngine::runFunctionAsMain(): --- 01E80010 sub esp,4 01E80013 mov dword ptr [esp],0FFFFFFF5h 01E8001A call 7C812FD9 01E8001F xor eax,eax 01E80021 add esp,4 01E80024 ret --- It is my understanding that the final "add esp, 4" should not be present when using the stdcall convention as the callee is responsible for popping the arguments from the stack, but I'm not an expert on this. Is the x86_stdcallcc call convention actually supported? I found it by digging into LLVM sources (it is not listed on http://llvm.org/docs/LangRef.html#callingconv). Is my initial LLVM-IR correct for invoking WIN32 API function? Thanks, Baptiste. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091209/3bc5e1e7/attachment.html>
Anton Korobeynikov
2009-Dec-09 11:14 UTC
[LLVMdev] Problem with code generated for call using stdcall convention
Hello> Is the x86_stdcallcc call convention actually supported? I found it by > digging into LLVM sourcesYes. It's fully supported.> Is my initial LLVM-IR correct for invoking WIN32 API function?No. You forgot to put calling convention on the call itself. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Baptiste Lepilleur
2009-Dec-09 19:54 UTC
[LLVMdev] Problem with code generated for call using stdcall convention
2009/12/9 Anton Korobeynikov <anton at korobeynikov.info>> Hello > > Is my initial LLVM-IR correct for invoking WIN32 API function? > No. You forgot to put calling convention on the call itself. >Thanks, this work great! I naively though it would pick up the call convention from the declaration as there was no error like we have when the wrong number of parameters is used.> -- > With best regards, Anton Korobeynikov > Faculty of Mathematics and Mechanics, Saint Petersburg State University >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091209/b5d225e3/attachment.html>
Reasonably Related Threads
- [LLVMdev] Problem with code generated for call using stdcall convention
- [LLVMdev] Problem with code generated for call using stdcall convention
- [LLVMdev] Problem with code generated for call using stdcall convention
- [LLVMdev] Problem with code generated for call using stdcall convention
- [LLVMdev] Problem with code generated for call using stdcall convention