Bug 11438 - optmization bug with -fPIC
Summary: optmization bug with -fPIC
Status: RESOLVED DUPLICATE of bug 10877
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3
: P1 critical
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2003-07-04 22:58 UTC by Stanislav S. Anokhin
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
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.

#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;

   printf("p1:%d\n", p2());
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 ***