[LLVMdev] Problem with code generated for call using stdcall convention

Baptiste Lepilleur baptiste.lepilleur at gmail.com
Wed Dec 9 00:28:37 PST 2009


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>


More information about the llvm-dev mailing list