[cfe-dev] C++11 ABI Compatibility and Static Initialization
Kevin Locke
kevin at kevinlocke.name
Mon Apr 14 08:46:56 PDT 2014
On Sun, 2014-04-13 at 17:36 -0700, Richard Smith wrote:
> On Mon, Apr 7, 2014 at 3:11 PM, Kevin Locke <kevin at kevinlocke.name> wrote:
>> I've been trying to track down an EXC_BAD_ACCESS error (Bus error: 10)
>> which occurs during static initialization when linking a program using
>> boost to a library using boost. The problem occurred, for me, with
>> QuantLib, but it has been reported to occur with mlpack[1] and likely
>> affects other boost-using libraries as well. I have determined that
>> the issue occurs when a library is compiled with -std=c++11 and the
>> program is not (or vice versa).
>
> This is a known issue that we've discussed in the past (though I can't find
> a record of the discussion right now). The issue, in the general case, is
> that it's possible for a common variable (local static or static data
> member of a class template specialization or variable template
> specialization) to have static initialization in one translation unit and
> dynamic initialization in another.
>
> The approach we came up with was:
>
> * put the variable and its guard variable in a COMDAT together, as the
> ABI document suggests (LLVM doesn't yet have the machinery for this)
> * if we constant-initialize a common variable, but we can't prove that
> every other translation unit that sees it will also constant-initialize it,
> emit a guard variable statically initialized to the 'already initialized'
> value
>
> ... but we've not implemented anything like this yet.
That explains it very well. Thanks!
Do you know if there is a bug filed for tracking progress on the
issue? I didn't see anything in Bugzilla but may not have been
searching with the right keywords.
Cheers,
Kevin
More information about the cfe-dev
mailing list