This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
gcc version 3.3 release. If compile following source with #gcc -o ptest -O3 -fPIC test.c get Segmentation fault. If remove static from PTEST declaration all is fine. Compiling with #gcc -o ptest -O2 -fPIC test.c produce normal result. [--cut--] #include <stdio.h> #include <stdlib.h> typedef struct _test { int p1; int p2; char *p3; } tests; static tests *PTEST = NULL; /* tests *PTEST = NULL; */ void init() { tests *ptest; ptest = PTEST; ptest = (tests*) malloc(sizeof(tests)); ptest->p1 = 1; PTEST = ptest; } int p2() { tests *ptest; ptest = PTEST; return(ptest->p1); } main() { init(); printf("p1:%d\n", p2()); } [--cut--]
This is a binutils bug (we will be documenting what version of `as' gcc requires, we already have a bug filed for that; bug 10877). Closing as dup of bug 10877. The binutils bug is fixed in binutils 2.13.1, please update binutils and this will fix your seg fault. *** This bug has been marked as a duplicate of 10877 ***