public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/44059]  New: Static initializers executed more than once when using unique global symbols
@ 2010-05-10 13:38 ivan dot stankovic at avl dot com
  2010-05-10 13:41 ` [Bug c++/44059] " ivan dot stankovic at avl dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: ivan dot stankovic at avl dot com @ 2010-05-10 13:38 UTC (permalink / raw)
  To: gcc-bugs

With g++ 4.5.0 static initializers can be executed more than once.
Here's how. Let a.cc contain the following code:

#include <stdio.h>

struct A {
  A() {
    static int x = printf("x initialized at @%p\n", &x);
  }
};

extern "C" void inita();

void inita()
{
  A x;
  A y;
}

And let b.cc be the copy of a.cc where 'inita' has been renamed
to 'initb'. Then make a shared library a.so from a.cc and b.so from
b.cc. Finally, make a program that dynamically loads a.so and b.so
and calls inita and initb functions.

Since 'x' ends up as a unique global symbol, there will be only one
object in the process, but the initialization code will be run twice
(the address printed will be the same).


-- 
           Summary: Static initializers executed more than once when using
                    unique global symbols
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ivan dot stankovic at avl dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44059


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2010-07-24 18:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-10 13:38 [Bug c++/44059] New: Static initializers executed more than once when using unique global symbols ivan dot stankovic at avl dot com
2010-05-10 13:41 ` [Bug c++/44059] " ivan dot stankovic at avl dot com
2010-05-10 13:54 ` rguenth at gcc dot gnu dot org
2010-05-10 13:58 ` rguenth at gcc dot gnu dot org
2010-05-10 14:09 ` jakub at gcc dot gnu dot org
2010-05-10 14:14 ` ivan dot stankovic at avl dot com
2010-05-10 14:39 ` jakub at gcc dot gnu dot org
2010-05-10 14:39 ` jakub at gcc dot gnu dot org
2010-05-11 18:15 ` jakub at gcc dot gnu dot org
2010-05-11 18:28 ` jakub at gcc dot gnu dot org
2010-06-30 15:17 ` jakub at gcc dot gnu dot org
2010-07-08 17:08 ` jakub at gcc dot gnu dot org
2010-07-24 18:40 ` [Bug c++/44059] [4.5 Regression] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).