[LLVMdev] Invalid or unaligned stack exception on Windows

Reid Kleckner rnk at google.com
Mon Apr 27 16:30:40 PDT 2015


I think Paweł identified the problem. The frames on the stack between the
setjmp and longjmp must have valid unwind information, which is described
here:
https://msdn.microsoft.com/en-us/library/ft9x1kdx.aspx?f=255&MSPPError=-2147217396

In particular, it has this line about JITed code:
  "For dynamically generated functions [JIT compilers], the runtime to
support these functions must either use RtlInstallFunctionTableCallback or
RtlAddFunctionTable to provide this information to the operating system.
Failure to do so will result in unreliable exception handling and debugging
of processes."

LLVM does not contain any references to these functions, so I must conclude
that unwinding through LLVM JITed frames on Win64 is not supported. Sorry.
:-(

You can try implementing your own setjmp / longjmp pair that bypasses the
libc versions. That might work.

On Mon, Apr 27, 2015 at 4:23 PM, Dibyendu Majumdar <mobile at majumdar.org.uk>
wrote:

> On 27 April 2015 at 19:04, Reid Kleckner <rnk at google.com> wrote:
> > Are you using split stacks of some kind? Are you sure these actually
> work as
> > intended on Win64? Based on the source code, it looks like you are
> > allocating stack manually, but I could be wrong.
>
> Hi,
> Lua uses its own stack (which is just an array of value objects), and
> Lua functions basically manipulate this data structure.
>
> >
> > What triple are you using with LLVM to generate code?
>
> x86_64-pc-windows-msvc-elf
>
> >
> > There isn't much else information here, but you can try to zero in on the
> > problem by checking the stack alignment manually with a helper like:
> > void CheckAlignment() {
> >   assert((((uintptr_t)_AddressOfReturnAddress() + 8) & 15) == 0);
> > }
> >
> > Run this near where LLVM calls back into C code. If it fails, disassemble
> > the calling LLVM function and look at that to see if there's something
> wrong
> > with the prologue. Sending that along with any followups would be
> helpful.
> >
>
> Thank you - I will try this, although Pawel's reply on this issue
> seems like a plausible explanation.
> I am trying to figure out how to dump the disassembly from the
> compiled code - it seems not so easy as dumping IR.
> I will also try compiling the using clang or gcc to see if that makes
> the problem go away.
>
> Thanks and Regards
> Dibyendu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150427/6249972b/attachment.html>


More information about the llvm-dev mailing list