c++/934: new-abi bug: collisions between flag variables for local statics
snyder@fnal.gov
snyder@fnal.gov
Wed Nov 29 21:26:00 GMT 2000
>Number: 934
>Category: c++
>Synopsis: new-abi bug: collisions between flag variables for local statics
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Wed Nov 29 21:26:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: scott snyder
>Release: 2.97 20001127 (experimental)
>Organization:
>Environment:
System: Linux karma 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../egcs/configure --prefix=/usr/local/egcs --enable-libstdcxx-v3 --enable-threads=posix --enable-cshadow-headers
>Description:
See below.
>How-To-Repeat:
hi -
I've run into a problem with the new ABI. The flag variable
used to control initialization of local static variables is not
distinguished by source file, and is global (even if the function
in which it occurs is static). 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.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list