[LLVMdev] misaligned_stack_error caused by LLVM code on MacOS: how to fix?

Nick Kledzik kledzik at apple.com
Sat Jan 1 17:52:58 PST 2011


That stack alignment check only happens when a lazy pointer is resolved, which happens the first time each external function is called.  For example, if your program calls malloc() the first time malloc is called from any site in your program, the stack alignment is checked.  After that, if your program calls malloc, no alignment checking is done.  

So, not seeing a misaligned_stack_error does not mean the program is correct.  It may be that in the code path you exercised the first time a function was called had the stack aligned.  But there may be another code path involving a function that misaligns the stack, which could trigger the misaligned_stack_error.

-Nick

On Jan 1, 2011, at 4:26 AM, Yuri wrote:
> llvm-generated code that runs fine on linux/i386 causes EXC_BAD_ACCESS 
> with misaligned_stack_error_ on MacOS/i386.
> 
> I read online that each function should have stack aligned by 16 on 
> MacOS/i386 and such code should be used:
> 
> Fn->addAttribute(~0U, llvm::Attribute::constructStackAlignmentFromInt(16));
> 
> But when I run clang on some C++ code I don't see alignstack 
> instructions generated at all.
> 
> What is the right way for fix this misaligned_stack_error?
> 
> Yuri
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev





More information about the llvm-dev mailing list