public inbox for ecos-devel@sourceware.org
 help / color / mirror / Atom feed
From: Bart Veer <bartv@ecoscentric.com>
To: cetoni GmbH - Uwe Kindler <uwe.kindler@cetoni.de>
Cc: ecos-devel@sourceware.org, sergei.gavrikov@gmail.com
Subject: Re: Strange __cxa_pure_virtual problem
Date: Fri, 21 Aug 2009 14:55:00 -0000	[thread overview]
Message-ID: <pntz01fc7p.fsf@delenn.bartv.net> (raw)
In-Reply-To: <4A8C0D9B.1010406@cetoni.de> (message from cetoni GmbH - Uwe 	Kindler on Wed, 19 Aug 2009 16:35:07 +0200)

>>>>> "Uwe" == cetoni GmbH <- Uwe Kindler <uwe.kindler@cetoni.de>> writes:

    Uwe> Hi Bart,
    Uwe> I compiled an eCos library from default template with
    Uwe> arm-eabi toolchain from eCos homepage. These are teh compiler
    Uwe> switches:

    <snip>

OK, after looking at a disassembly and doing some reading I now
understand what is going on.

static Class object;
int
fred(void)
{
    ...
}

has different semantics from

int
fred(void)
{
    static Class object;
    ...    
}

In the first case "object" will be constructed at system
initialization time. In the second case "object" will be constructed
during the first call to fred(), not during system initialization
time. This difference in behaviour is defined in my copy of Stroustrup
and presumably in the C++ language standard.

In the early days of C++ this would not have been a problem. In
today's multi-threaded environments things are very different. fred()
may get called from inside several threads at the same time, leading
to multiple concurrent attempts at constructing "object". Needless to
say that is going to lead to disaster.

So, g++ generates code to avoid the problem. In particular it will
surround the construction with calls to __cxa_guard_acquire() and
__cxa_guard_release(), plus __cxa_guard_abort() in case problems.
These functions are normally provided in libsupc++.

The default implementations need to be examined in more details, but I
suspect the ones in the anoncvs toolchains are up to the job. They
will be unaware of eCos threading so will not provide appropriate
locking. Hence construction of per-function static objects will not be
properly thread-safe. Also, libsupc++ has been built on the assumption
that code may throw C++ exceptions so the __cxa_guard_...() functions
end up pulling in all the exception handling support, even though eCos
is built with -fno-exceptions. At this stage my guess is that we will
need to provide eCos-specific replacements for these guard functions.
The compiler is doing exactly what it is supposed to.

Theoretically this is a problem for any eCos code involving C++.
Obviously it is much more likely to trigger for code that uses C++
libraries like STL.

Bart

-- 
Bart Veer                                   eCos Configuration Architect
eCosCentric Limited    The eCos experts      http://www.ecoscentric.com/
Barnwell House, Barnwell Drive, Cambridge, UK.      Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.

  parent reply	other threads:[~2009-08-21 14:55 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-19 14:35 cetoni GmbH - Uwe Kindler
2009-08-19 16:05 ` John Dallaway
2009-08-21 14:55 ` Bart Veer [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-08-12 17:49 Uwe Kindler
2009-08-12 19:07 ` Bart Veer
2009-08-13  8:00   ` Uwe Kindler
2009-08-19 10:37     ` Bart Veer
     [not found] <4A827EDC.3030004@cetoni.de>
2009-08-12 14:15 ` Jonathan Larmour
2009-08-12  9:10 cetoni GmbH - Uwe Kindler
2009-08-08  6:04 Uwe Kindler
2009-08-07 11:35 cetoni GmbH - Uwe Kindler
2009-08-07 12:04 ` John Dallaway
2009-08-07 13:40   ` Bart Veer
2009-08-07 15:08     ` John Dallaway
2009-08-07 15:42       ` Bart Veer
2009-08-11  9:05       ` Daniel Néri
2009-08-07 16:31     ` Sergei Gavrikov
2009-08-12  1:34     ` Jonathan Larmour
2009-08-05 18:55 Uwe Kindler
2009-08-07  9:35 ` John Dallaway

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pntz01fc7p.fsf@delenn.bartv.net \
    --to=bartv@ecoscentric.com \
    --cc=ecos-devel@sourceware.org \
    --cc=sergei.gavrikov@gmail.com \
    --cc=uwe.kindler@cetoni.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).