[x86] alignment problem for local mmx/sse/sse2 data inside threads
Hi,
I tried to switch from Intel's icc to gcc for an application that uses 
both threads and SSE/SSE2 data. The problem is that local mmx/sse/sse2 
variables are not correctly aligned for functions inside threads, thus 
segfaulting on access. I filed bug report with gcc-bugzilla (bug 10395 
), but it's not clear if it is gcc or glibc problem (or both) and when 
it'll be fixed. Does anyone know a work-around or fix for this problem? 
(BTW, the code below works correctly on RedHat9, I use unstable branch 
of Debian and tested with gcc-3.2.*, 3.3* and gcc-snapshot 3.4 20030706):
/* example */
#include <pthread.h>
#include <stdio.h>
#include <assert.h>
#include <xmmintrin.h>
#include <mmintrin.h>
#ifdef __ICC
#include <emmintrin.h>
#endif
void * f(void *p)
{
  int x = (p == NULL) ? 0 : * (int *) p;
  __m128i s; /* s must be aligned at 16 bytes */
  printf("&x = %p &s= %p\n", &x, &s);
  return NULL;
}
int main(int argc, char ** argv)
{
  pthread_t th;
  f(& argc);
  assert(pthread_create(& th, NULL, f, &argc)==0);
  assert(pthread_join(th, NULL)==0);
  return 0;
}
/* ***end *** /
$ gcc-3.3 -pthread -msse2 gcc_test.c -o gcc_test.LINUX
$ ./gcc_test.LINUX
&x = 0xbffffb6c &s= 0xbffffb50
&x = 0xbf7ffae8 &s= 0xbf7ffacc <---- error; &s doesn't end with 0
$ldd ./gcc_test.LINUX
       libpthread.so.0 => /lib/libpthread.so.0 (0x40030000)
       libc.so.6 => /lib/libc.so.6 (0x4007f000)
       /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
Thanks,
Vladimir
--
======================================================================
Vladimir Grebinskiy (grebinsk@cgen.com)   |   7, Centre Drive, Suite 9
Compugen, Inc 	Tel: 609-6555105 ext 24   |   Jamesburg, NJ 08831, USA
======================================================================
Reply to: