[LLVMdev] Win64 bugs

Peter Shugalev peter at shugalev.com
Thu Jul 30 17:32:11 PDT 2009


I've just tried generating Win64 code and the result is not that good.

First of all, XMM registers are saved without reason to do so. Not only
this slows the performance but leads to random crashes too. XMMs are
stored to the stack with MOVAPS instruction which requires 16-byte
alignment which is not always the case. lli.exe (built in debug mode)
randomly crashes on some simple hello-world-alike tests due to misalignment.

Though the most problematic stuff is the lack of 'shadow zone' support
in Win64 ABI. Or maybe I haven't figured out how to turn this on. In
Win64 any function can treat 32 bytes of stack (RSP+08h..RSP+28h just
after the call instruction) as scratch data. VC++ compiler stores
arguments passed in registers there. In debug builds this doesn't get
optimized away.

Consider this C++ code:

#include <stdio.h>

int main () {
	for ( int i=0; i<5; i++ )
		printf ( "%d\n", 0 );
	return 0;

Compile it to llvm bytecode with -O0 flag. Then run debug build of
64-bit lli.exe (with -mtriple=x86_64-pc-windows argument). For me it
prints 0's forever.

The reason for this is printf function using shadow zone to store its
arguments. Second arguments goes to the stack at address RSP+10h and
overwrites 'i' variable always resetting it to zero.

Is anyone aware of the second bug? If I have some time I'll try to fix
it by myself but it'd be much better if someone hints me where to start

Best Regards
Peter Shugalev

More information about the llvm-dev mailing list