I have been trying to use egcs 1.1.2 (cross compiling on intel for strong arm)
and have had lots of trouble when I use the -fpic flag
to generate position independent code (for shared libraries).  Has anyone on
this list tried this?  (I have had success without this
flag).

Here is an example of a simple program which shows some bad code generated with
the -fpic flag.

Who should I report this bug to?  Does anyone on this list have the know-how to
find the cause of the problem?

Thanks in advance for all of your help,
Hugh Morgenbesser

////////////////////////////////////////////////////////////////////////////
// This file is "bugreport.c" and is compiled using these commands
//   on an i86 RedHat 5.2 machine
//
//#with -fpic
//  /usr/local/arm112/bin/arm-linux-gcc -v -static -c -x c++ -fPIC -O -gstabs+
-o bugreport.s -S bugreport.cpp  >& log1.out
//  /usr/local/arm112/bin/arm-linux-gcc -v -static -c -x c++ -fPIC -O -gstabs+
-o bugreport.o    bugreport.cpp  >& log2.out
//  /usr/local/arm112/bin/arm-linux-gcc -v -static -o bugreport.exe bugreport.o
  >& log3.out
//
//#no -fpic
//  /usr/local/arm112/bin/arm-linux-gcc -v -static -c -x c++ -O -gstabs+ -o
bugreport2.s -S bugreport.cpp     >& log4.out
//  /usr/local/arm112/bin/arm-linux-gcc -v -static -c -x c++ -O -gstabs+ -o
bugreport2.o    bugreport.cpp     >& log5.out
//  /usr/local/arm112/bin/arm-linux-gcc -v -static -o bugreport2.exe
bugreport2.o  >& log6.out
//
// The programs are then run on a Netwinder:
// The bugreport.exe program that I generate produces the following (incorrect)
output
//   Before: foo.E=0.
//   After:  foo.E=6.
//   After:  foo.E=60.
//   After:  foo.E=600.
//
// The bugreport2.exe program that I generate produces the following (correct)
output
//   Before: foo.E=0.
//   After:  foo.E=4.
//   After:  foo.E=4.
//   After:  foo.E=4.
//
// /usr/local/arm112/bin/arm-linux-gcc -v shows that I am using the following
version of egcs:
//   Reading specs from
/usr/local/arm112/lib/gcc-lib/arm-linux/egcs-2.91.66/specs
//   gcc version egcs-2.91.66 19990325/philb (egcs-1.1.2 release)


#include <stdio.h>
#include <stdlib.h>

class TheClass
{
 public:
    TheClass();
    ~TheClass();
    void init();
    void initTheClass(int ret, int lft, int rht,
                      int assoc, int isLvalue, int precedence,
                      int index);
 public:
    int A;
    int B;
    int C;
    int D;
    int E;
    int F;
    int G;
};

TheClass::TheClass()
{
    init();
}

TheClass::~TheClass()
{
}

void TheClass::init()
{
    A=0;
    B=0;
    C=0;
    D=0;
    E=0;
    F=0;
    G=0;
}

void TheClass::initTheClass(int ret, int lft, int rht, int assoc,
                           int isLvalue, int precedence, int index)
{
    init();
    A=ret;
    B=index;
    C=lft;
    D=rht;
    E=assoc;
    F=isLvalue;
    G=precedence;
}



int main(void)
{
  TheClass foo;

  // we expect that foo.E will be 0 and then change to 4,then4,then4,
  // but the compiler produces code which sets it to 6,60, and then 600!
  // (the value of the 6th argument!)
  printf("Before: foo.E=%d.\n",foo.E);
  foo.initTheClass(1,2,3,4,5,6,7);
  printf("After:  foo.E=%d.\n",foo.E);
  foo.initTheClass(1,2,3,4,5,60,7);
  printf("After:  foo.E=%d.\n",foo.E);
  foo.initTheClass(1,2,3,4,5,600,7);
  printf("After:  foo.E=%d.\n",foo.E);
}


unsubscribe: body of `unsubscribe linux-arm' to [EMAIL PROTECTED]

Reply via email to