public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/36801]  New: config/cpu/generic/atomicity_mutex/atomicity.h incorrectly relies on global constructor ordering
@ 2008-07-11  1:01 jifl-bugzilla at jifvik dot org
  2008-07-11 13:04 ` [Bug libstdc++/36801] " jifl-bugzilla at jifvik dot org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: jifl-bugzilla at jifvik dot org @ 2008-07-11  1:01 UTC (permalink / raw)
  To: gcc-bugs

In 4.3.1 (and 4.2.x and the trunk), ARM targets and no doubt plenty others use
libstdc++/config/cpu/generic/atomicity_mutex/atomicity.h.

With some build magic in libstdc++/src/Makefile.am, this file is also
atomicity.cc when building the library. Thus this object gets instantiated:
{
  __gnu_cxx::__mutex atomic_mutex;
} // anonymous namespace

The constructor for __mutex in include/ext/concurrence.h has a private member
of the underlying __gthread_mutex_t, and its constructor uses
GTHREAD_MUTEX_INIT or calls GTHREAD_MUTEX_INIT_FUNCTION as appropriate, as of
course it should.

The problem is that this becomes a global constructor and there is no control
over where in the running of global constructors it gets run. A consequence of
this is that any other initialisation function from another constructor using
atomic operations can end up locking a mutex which has never been initialised,
with unsurprising results. An example of such a case is ios_base::Init::Init()
which calls __gnu_cxx::__exchange_and_add_dispatch() which eventually reaches
__gnu_cxx::__scoped_lock sentry(atomic_mutex); which attempts to lock
atomic_mutex.

Code prior to this implementation used __gthread_mutex_t in atomicity.h
directly  using a macro defined by concurrence.h:
  __glibcxx_mutex_define_initialized(atomic_mutex);
and as such this used to work, so this is a regression.

It seems this is an unintended consequence of this change:
http://gcc.gnu.org/ml/libstdc++/2006-09/msg00084.html

I think this needs returning to something similar to the way it was before, so
that the __gthread_mutex_t was created in the atomic_mutex's own constructor.


-- 
           Summary: config/cpu/generic/atomicity_mutex/atomicity.h
                    incorrectly relies on global constructor ordering
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jifl-bugzilla at jifvik dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: arm-eabi


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


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

end of thread, other threads:[~2009-01-12 21:36 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-11  1:01 [Bug libstdc++/36801] New: config/cpu/generic/atomicity_mutex/atomicity.h incorrectly relies on global constructor ordering jifl-bugzilla at jifvik dot org
2008-07-11 13:04 ` [Bug libstdc++/36801] " jifl-bugzilla at jifvik dot org
2008-07-11 13:36 ` paolo dot carlini at oracle dot com
2008-07-11 20:54 ` bkoz at gcc dot gnu dot org
2008-07-12  1:53 ` jifl-bugzilla at jifvik dot org
2008-07-15  1:20 ` jifl-bugzilla at jifvik dot org
2008-10-03 22:44 ` paolo dot carlini at oracle dot com
2008-10-04  2:55 ` jifl-bugzilla at jifvik dot org
2008-10-30 13:12 ` jifl-bugzilla at jifvik dot org
2008-12-17 17:22 ` paolo dot carlini at oracle dot com
2009-01-07  3:40 ` bkoz at gcc dot gnu dot org
2009-01-07  3:56 ` bkoz at gcc dot gnu dot org
2009-01-07  9:19 ` bkoz at gcc dot gnu dot org
2009-01-07 18:03 ` jifl-bugzilla at jifvik dot org
2009-01-07 18:17 ` paolo dot carlini at oracle dot com
2009-01-08  3:15 ` bkoz at gcc dot gnu dot org
2009-01-12 20:57 ` bkoz at gcc dot gnu dot org
2009-01-12 21:32 ` bkoz at gcc dot gnu dot org
2009-01-12 21:36 ` bkoz 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).