On Fri, Oct 14, 2005 at 01:43:03PM -0700, Kean Johnston wrote:

> Also, when you say "stack going into main is 16 byte aligned",
> what specifically do you mean? that its 16-byte aligned before
> the call to main() itself? That at the first insn in main, most
> likely a push %ebp, its 16-byte aligned (i.e does the call
> to main from crt1.o have to take the push of the return address
> into account)?


The stack alignment is computed before the saved-EIP is pushed on
the stack by a CALL instruction.  So on function entry, the ESP has
already been decremented by 4 off of its 16-byte alignment.
Conventioanlly the EBP is pushed, making the ESP 8 bytes off its
16-byte alignment.

If your ABI does not require 16-byte stack frame alignment, aligning
it correctly in main() will not fix all the problems unless you can
recompile all of the code (and fix all the hand-written assembly)
on the entire system.  If you're 16-byte aligned and you call into
a library that only requires 4-byte alignment (the traditional SysV
x86 ABI--Pinski says it's been updated to require 16-byte alignment
but I don't know when that happened) and that library function calls
into a newly-gcc-recompiled function, you can crash over there
because of a misaligned operation.

J

Reply via email to