Position Independent Code bug in egcs 1.1.2 on m68k

Kars de Jong jongk@cs.utwente.nl
Tue Apr 27 14:53:00 GMT 1999


egcs version: gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
System: Linux/m68k, kernel 2.2.3-pre1, glibc 2.1

Doesn't happen with gcc 2.7.2.3!

Hi,

When compiling some c++ code in a shared library the resulting code crashed
because of a bug in the handling of the Global Offset Table:
When a global variable is referenced, the address of the GOT is loaded into
register a5. This register isn't marked as 'unavailable' to the register
allocator however. The function in question uses up a lot of registers and
it also uses a5 as a temporary. It isn't restored when a global variable
is referenced later on. Here's the relevant section of the generated
assembler code:

.text
        .align  2
.globl main
        .type    main,@function
main:
        link.w %a6,#0
        movm.l #0x303c,-(%sp)
        lea (%pc, _GLOBAL_OFFSET_TABLE_@GOTPC), %a5 <-- Here a5 = GOT
        bsr.l GetInt@PLTPC
        move.l %a0,%a5           <-- a5 is something else now
        bsr.l GetInt@PLTPC
        move.l %a0,%a4
        bsr.l GetInt@PLTPC
        move.l %a0,%a3
        bsr.l GetInt@PLTPC
        move.l %a0,%a2
        bsr.l GetFloat@PLTPC
        fintrz.x %fp0,%fp0
        fmove.l %fp0,%d0
        move.l .LC0@GOT(%a5),%a1 <-- Oops, a5 is used as if it still contains
                                     the GOT
        ...

The following piece of code was used to generate this:

------------------------------------------------------------------------------
extern double JRound(double);
extern void UseFloat(double);
extern void UseThem(double, double, int, int, int, int);
extern int *GetInt(void);

const double frogs = 0.01;

double GetFloat() {
  return 0.03;
}

int main() {
  double bing, fluff, hair;
  int i, j, *k, *l, *m, *n;

  k = GetInt();
  l = GetInt();
  m = GetInt();
  n = GetInt();
  i = GetFloat();
  bing = JRound(i * frogs);
  UseThem(bing, hair, *k, *l, *m, *n);
  return 0;
}
------------------------------------------------------------------------------

egcs was invoked as:

bash# egcs -S -fPIC -O2 frog.c

Kars.
-- 
------------------------------------------------------------------------------
Kars de Jong             Signaalkamp rules the waves!       Turrican@Discworld
--------======]**-----|      jongk@cs.utwente.nl      |-----**[======---------


More information about the Gcc-bugs mailing list