The x86 psABI is very old and doesn't cover XMM registers. I'd like to
update x86 Linux calling convention for XMM register usage. I am not
sure if I should update stack alignment requirement.

The x86 psABI only requires 4 byte aligned stack. But the current gcc
assumes that the satck of a function which uses XMM register is 16
byte aligned. That means gcc may generate x86 codes which are psABI
compliant, but will crash at runtime:

[EMAIL PROTECTED] stack]$ cat m.c
#include <stdio.h>
extern char *e1 (void);
int
main ()
{
  printf ("%s\n", e1 ());
  return 0;
}
[EMAIL PROTECTED] stack]$ cat x.c
#include <emmintrin.h>
extern char *e1 (void);
char *e1 (void)
{
  volatile __m128 dummy = _mm_set_ps1(0.f);
  return "OK";
}
[EMAIL PROTECTED] stack]$ make
gcc -Os   -c -o m.o m.c
gcc -O -msse2   -c -o x.o x.c
gcc -o m m.o x.o
./m
make: *** [all] Segmentation fault
[EMAIL PROTECTED] stack]$

We have several choices for stack alignment requirement

1. Leave it unchanged. Gcc can do
        a. Nothing. Let the program crash.
        b. Align stack to 16byte if XMM registers are used locally and
           aren't passed down as function arguments.
2. Update stack alignment requirement to 16byte and gcc will align
stack at 16byte by default, including -Os.


H.J.

Reply via email to