seg fault with tls arrays gcc-4.4.1 -mcmodel=large (x86_64)
shankha
shankhabanerjee@gmail.com
Sat May 22 13:48:00 GMT 2010
Hi,
I have following sample code. It segfaults on the assignment "x1[1]
=60", the assignment in the loop "x[i] = x[i] + i +250" goes through
fine. I have looked at the assembly generated, it is different in both
cases, though looks equivalent to my non-expert eyes. Is this a bug
or am I missing something.
gcc version is 4.4.1, kernel-version 2.6.31-21-generic
compiled with "gcc -mcmodel=large test.c -o test"
#include <stdio.h>
#include <pthread.h>
#define SIZE 2
__thread int x1[SIZE] = {300, 400};
int main()
{
int i = 0;
for ( i = 0 ; i < SIZE ; i++ )
{
x1[i] = x1[i] + i + 250; /*This access works fine*/
}
x1[0] = 50;
printf ("%d x1[0] = %d\n", __LINE__, x1[0]);
x1[1] = 60; /* This line segfaults */
printf ("%d x1[1] = %d\n", __LINE__, x1[1]);
return 0;
}
On further digging this might be a linker/loader issue x1@TPOFF+4
seems to generating a garbage value.
-Shankha
PS: Reposting of google groups query, since it didn't appear here.
Andrew Haley responded there saying it is a bug
More information about the Gcc-help
mailing list