Bug 22229 - Segfault due to unaligned movaps access
Summary: Segfault due to unaligned movaps access
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ssemmx
Depends on:
Blocks:
 
Reported: 2005-06-29 12:38 UTC by Uroš Bizjak
Modified: 2005-07-23 22:49 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Uroš Bizjak 2005-06-29 12:38:40 UTC
This testcase segfaults due to unaligned movaps access when compiled with 'gcc -
O2 -msse':

--cut here--
#include <xmmintrin.h>

__m128 bar (__m128 x1, __m128 y1, __m128 x2, __m128 y2)
{
  return x1;
}

__m128 foo (__m128 x)
{
  return bar (x, x, x, x);
}

int main()
{
  __m128 a = {1.0, 2.0, 3.0, 4.0};

  union {
    __m128 _xmm;
    float x[4];
  } temp;

  temp._xmm = foo (a);

  printf("%f\n", temp.x[2]);
  return 0;
}
--cut here--

The problem is, that 4th parameter to bar is now passed on stack (this is 
specified by x86 ABI). Unfortunatelly, stack is not aligned correctly and 
testcase segfaults in foo():

foo:
	subss	%xmm1, %xmm0
	pushl	%ebp
	movl	%esp, %ebp
	subl	$16, %esp
	movaps	%xmm0, (%esp)         <<<< here
	movaps	%xmm0, %xmm2
	movaps	%xmm0, %xmm1
	call	bar
	leave
	ret

Value of %esp is 0xbffff958 at the point of segfault.
Comment 1 Andrew Pinski 2005-07-09 16:45:06 UTC
Fixed by:
2005-07-07  Richard Henderson  <rth@redhat.com>
        
        * function.c (locate_and_pad_parm): Record parameter alignment in
        stack_alignment_needed.