VTABLE Thunks broken on linux egcs 1.1.1 and earlier versions

William A. Hoffman hoffman@albirio.crd.ge.com
Fri Feb 5 06:51:00 GMT 1999


I have a rather complex program using Fresco that segfaults when compiled with
egcs on linux.   I think the problem is due to an incorrect vtable thunk
function.   Is there a flag to turn off thunks for egcs?

I have found a small example that shows a problem very close to what I have
seen in the larger program.



#include <iostream.h>
 
class super
{
public:
  int s[4];
  virtual void doit(const char* message) =0;
};
 
class top : virtual public super
{
public:
  top() { s[0] = s[1] = s[2] = 1; }
  int s[3];
  void doit(const char* message);
};
 
class mid : public top
{
public:
  int s[2];
  mid();
};
 
class leaf : public mid
{
public:
  leaf();
  int i;
};
 
 
 
void top::doit(const char* message)
{
  cout << s[0] << s[1] << s[2] << endl;
  cout << "top::doit " << this << " " << message << endl;
}
 
mid::mid ()
{
  cout << "mid " << this << endl;
  top::doit("top::doit called from mid::mid ");
  top* hackptr = this;
  cout << "hackptr = " << hackptr << endl;
  hackptr->doit("called like this top* hackptr = this; hackptr->doit()");
// <<<<<******** incorrectly adjusts "this" by size of leaf
  this->doit("called from mid::mid   this->doit");
}
 
leaf::leaf()
{
  cout << "leaf " << this << endl;
}
 
int main ()
{
  leaf* l = new leaf();
  return 0;
}

Here is the output from the program:

mid 0x8057878
111
top::doit 0x8057878 top::doit called from mid::mid
hackptr = 0x8057878
110
top::doit 0x805787c called like this top* hackptr = this; hackptr->doit()
111
top::doit 0x8057878 called from mid::mid   this->doit
leaf 0x8057878


As you can see doit should never print 110, and you can see that
the hackptr is getting changed by a thunk when it should not be.

If anyone has a patch for this it would be a big help.
It seems only to be a problem on linux.


Here is the version information:

$ c++ --version
egcs-2.91.60
$ c++ -c -v /tmp/e.cc 
Reading specs from /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.60/specs
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
 /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.60/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -D__EXCEPTIONS -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ /tmp/e.cc /tmp/ccM3MPvh.ii
GNU CPP version egcs-2.91.60 19981201 (egcs-1.1.1 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/gnu/include/g++
 /usr/local/include
 /usr/gnu/i686-pc-linux-gnu/include
 /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.60/include
 /usr/include
End of search list.
 /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.60/cc1plus /tmp/ccM3MPvh.ii -quiet -dumpbase e.cc -version -o /tmp/ccoVaIZz.s
GNU C++ version egcs-2.91.60 19981201 (egcs-1.1.1 release) (i686-pc-linux-gnu) compiled by GNU C version egcs-2.91.60 19981201 (egcs-1.1.1 release).
 as -V -Qy -o e.o /tmp/ccoVaIZz.s
GNU assembler version 2.9.1 (i686-pc-linux-gnu), using BFD version 2.9.1.0.4




-Bill Hoffman (hoffman@crd.ge.com)


More information about the Gcc-bugs mailing list