libgcc patch committed: Fix split-stack stack alignment

Ian Lance Taylor iant@google.com
Tue Nov 6 23:04:00 GMT 2012


This patch fixes two stack alignment bugs in the split-stack support.

The first is that I managed to miscalculate the stack alignment in the
assembly code.  I was treating that code as though it were a normal
function.  That is wrong, because __morestack is actually called without
any stack adjustment in the caller, which means that when __morestack is
entered the stack % 16 will == 8 in 32-bit mode and 0 in 64-bit mode,
unlike the usual case of 12 and 8, respectively.  This patch corrects
the code to align the stack correctly when calling the C split-stack
functions.  Previously the stack was misaligned when calling those
functions.  Since those functions don't happen to use any vector
registers, this did not matter except for performance.  In any case,
this patch fixes it.

The second bug is that the C functions were not aligning the returned
stack.  The result was coming back to an alignment determined by the
parameter size.  This is simply wrong.  Since the C code doesn't know
the required stack alignment, I simply made it always align to a 32-byte
boundary.  If split stack support is added for more processors, this may
need to become processor dependent.

Along the way I noticed that the 32-bit __morestack_non_split support
was mishandling the return address when called by a varargs function,
and I fixed that too.

Bootstrapped and ran split-stack and Go tests on
x86_64-unknown-linux-gnu, both 64-bit and 32-bit mode.  Committed to
mainline.

Ian


2012-11-06  Ian Lance Taylor  <iant@google.com>

	* generic-morestack.c (__generic_morestack): Align the returned
	stack pointer to a 32 byte boundary.
	* config/i386/morestack.S (__morestack_non_split) [32-bit]: Don't
	increment the return address until we have decided that we don't
	have a varargs function.
	(__morestack) [32-bit]: Align stack correctly when calling C
	functions.
	(__morestack) [64-bit]: Likewise.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-diff
Size: 4136 bytes
Desc: patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20121106/a93d7aa5/attachment.bin>


More information about the Gcc-patches mailing list