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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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 ` ivan dot stankovic at avl dot com
  2010-05-10 13:54 ` rguenth at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ivan dot stankovic at avl dot com @ 2010-05-10 13:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ivan dot stankovic at avl dot com  2010-05-10 13:40 -------
Created an attachment (id=20619)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20619&action=view)
The test case

Just unpack and run 'make; make run'. The output
should be something like:

x initialized at @0x40021a28
x initialized at @0x40021a28

(note that the addresses are identical).


-- 


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


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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-10 13:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2010-05-10 13:54 -------
It works for me.  You need to build shared libraries with -fPIC.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-10 13:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2010-05-10 13:57 -------
Or rather as you use dlopen you need to use RTLD_GLOBAL.


-- 


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


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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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
                   ` (2 preceding siblings ...)
  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
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-10 14:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jakub at gcc dot gnu dot org  2010-05-10 14:09 -------
Re: #c2, that's just because you are using too old binutils I guess.

The bug seems to be in:
        .type _ZGVZN1AC1EvE1x, @object
        .type _ZZN1AC1EvE1x, @gnu_unique_object
I believe the guard needs to be @gnu_unique_object as well.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu dot org
   Last reconfirmed|0000-00-00 00:00:00         |2010-05-10 14:09:22
               date|                            |


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


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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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
                   ` (3 preceding siblings ...)
  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
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ivan dot stankovic at avl dot com @ 2010-05-10 14:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from ivan dot stankovic at avl dot com  2010-05-10 14:14 -------
Indeed, using RTLD_GLOBAL works around the problem. However, I don't think
one should just resort to using this flag with dlopen everywhere. The problem
was originally found with Python modules written in C, and while one can
change the dlopen flags used for Python imports, I'm not sure that that won't
break something else.

As Jakub has pointed out, the guard needs to be unique as well.


-- 


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


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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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
                   ` (5 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-10 14:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2010-05-10 14:39 -------
I guess the problem is in the !DECL_ARTIFICIAL (DECL) test in
ASM_DECLARE_OBJECT_NAME macro - the guard is artificial.
Not sure why that has been added.
      /* For template static data member instantiations or              \
         inline fn local statics, use gnu_unique_object so that         \
         they will be combined even under RTLD_LOCAL.  */               \
      if (USE_GNU_UNIQUE_OBJECT                                         \
          && !DECL_ARTIFICIAL (DECL) && DECL_ONE_ONLY (DECL))           \
        ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "gnu_unique_object");    \
      else                                                              \
        ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");               \


-- 


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


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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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
                   ` (4 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-10 14:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jakub at gcc dot gnu dot org  2010-05-10 14:39 -------
Reopening.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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
                   ` (6 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-11 18:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jakub at gcc dot gnu dot org  2010-05-11 18:14 -------
Subject: Bug 44059

Author: jakub
Date: Tue May 11 18:14:19 2010
New Revision: 159287

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159287
Log:
        PR c++/44059
        * config/elfos.h (ASM_DECLARE_OBJECT_NAME): Use qnu_unique_object
        even for DECL_ONE_ONLY DECL_ARTIFICIAL !TREE_READONLY decls.
        * config/alpha/elf.h (ASM_DECLARE_OBJECT_NAME): Likewise.
        * dwarf2asm.c (dw2_output_indirect_constant_1): Set TREE_READONLY
        on DW.ref.* decls.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/alpha/elf.h
    trunk/gcc/config/elfos.h
    trunk/gcc/dwarf2asm.c


-- 


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


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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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
                   ` (7 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-11 18:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jakub at gcc dot gnu dot org  2010-05-11 18:28 -------
Fixed on the trunk so far, will backport to 4.5 after a while if there aren't
any issues with it on the trunk.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jakub at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|2010-05-10 14:09:22         |2010-05-11 18:28:30
               date|                            |


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


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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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
                   ` (8 preceding siblings ...)
  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
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-06-30 15:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from jakub at gcc dot gnu dot org  2010-06-30 15:17 -------
Subject: Bug 44059

Author: jakub
Date: Wed Jun 30 15:16:54 2010
New Revision: 161607

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161607
Log:
        Backport from mainline
        2010-05-11  Jakub Jelinek  <jakub@redhat.com>

        PR c++/44059
        * config/elfos.h (ASM_DECLARE_OBJECT_NAME): Use qnu_unique_object
        even for DECL_ONE_ONLY DECL_ARTIFICIAL !TREE_READONLY decls.
        * config/alpha/elf.h (ASM_DECLARE_OBJECT_NAME): Likewise.
        * dwarf2asm.c (dw2_output_indirect_constant_1): Set TREE_READONLY
        on DW.ref.* decls.

Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/config/alpha/elf.h
    branches/gcc-4_5-branch/gcc/config/elfos.h
    branches/gcc-4_5-branch/gcc/dwarf2asm.c
    branches/gcc-4_5-branch/gcc/testsuite/g++.dg/warn/Wconversion-null-2.C  
(props changed)

Propchange:
branches/gcc-4_5-branch/gcc/testsuite/g++.dg/warn/Wconversion-null-2.C
            ('svn:mergeinfo' removed)


-- 


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


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

* [Bug c++/44059] Static initializers executed more than once when using unique global symbols
  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
                   ` (9 preceding siblings ...)
  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
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-07-08 17:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from jakub at gcc dot gnu dot org  2010-07-08 17:08 -------
Fixed.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.1


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


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

* [Bug c++/44059] [4.5 Regression] Static initializers executed more than once when using unique global symbols
  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
                   ` (10 preceding siblings ...)
  2010-07-08 17:08 ` jakub at gcc dot gnu dot org
@ 2010-07-24 18:40 ` pinskia at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-07-24 18:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from pinskia at gcc dot gnu dot org  2010-07-24 18:39 -------
*** Bug 44815 has been marked as a duplicate of this bug. ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ubizjak at gmail dot com


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).