[LLVMdev] Issue with X86FrameLowering __chkstk on Windows 8 64-bit / Visual Studio 2012

Anton Korobeynikov anton at korobeynikov.info
Sun Sep 1 13:10:59 PDT 2013


> It's not a solution to the actual bug (which is, as the thread you linked
> discusses, a problem with the assumption on LLVM's part that the __chkstk
> function lies within 2GB of the emitted code's address space) but there is a
> simple workaround: hoist all allocas to the first basic block of your
> function. This allows the JIT to perform all stack allocations in a single
> adjustment of the SP instead of needing to use dynamic stack allocation, and
> thereby avoids the call to __chkstk entirely.
__chkstk is not connected with dynamic stack allocation at all, in
general. On Windows when one allocates more than 1 page (4kb) of
stack, it is necessary to touch all all the allocated space in order
to ensure the proper order of guard page allocation. Surely, it's
always required for dynamic stack allocation, because the amount of
allocation is not known in advance, however, it can be triggered for
static code as well. Consider e.g.

void bar(int*);
void baz() {
  int foo[2000];
  bar(foo);
}

-- 
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University



More information about the llvm-dev mailing list