new-abi bug: names for local static vbl flags

scott snyder snyder@fnal.gov
Sun Nov 26 17:37:00 GMT 2000


hi -

I've run into a name mangling problem with the new ABI.  The flag variable
used to control initialization of local static variables is not
distinguished by source file.  Thus, one can get collisions between these
names across different source files.

Here's an example demonstrating this.

-- a.cc -----------------------------------------------------------
extern "C" int puts (const char*);
struct A { A() { puts ("a ctor");}  };

static void a ()
{
  static A aa;
}


void b () { a (); }
-- b.cc -----------------------------------------------------------
extern "C" int puts (const char*);
struct B { B() { puts ("b ctor");} };

static void a ()
{
  static B aa;
}

extern void b ();
int main ()
{
  a ();
  b ();
  return 0;
}
-------------------------------------------------------------------

If i compile and run this with a current version of gcc
(20001126, on a i686-pc-linux-gnu system), i get:

$ g++ -o b a.cc b.cc
$ ./b
b ctor
$

I.e., only one of the constructors got called.

If i use the old ABI instead, i get the expected result:


$ g++ -fno-new-abi -o b a.cc b.cc
$ ./b
b ctor
a ctor
$ 


If i look at the assembly code, i see that in both a.cc and b.cc,
gcc is using a symbol `_ZGVZ1avE2aa' to control whether or not the
local variable aa gets initialized.

thanks,
sss


More information about the Gcc-bugs mailing list