User account creation filtered due to spam.

Bug 11438

Summary: optmization bug with -fPIC
Product: gcc Reporter: Stanislav S. Anokhin <stas>
Component: rtl-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: critical CC: gcc-bugs
Priority: P1    
Version: 3.3   
Target Milestone: 3.4.0   
Host: i686-pc-linux-gnu Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed:

Description Stanislav S. Anokhin 2003-07-04 22:58:21 UTC
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--]
Comment 1 Andrew Pinski 2003-07-04 23:11:47 UTC
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 ***