stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <>
Subject Re: FW: RW libstd is sensitive to link order
Date Fri, 03 Aug 2007 01:08:57 GMT
Ravi Inampudi wrote:
> A customer discovered a problem with std::numeric_limits<double> in RW
> libstd. Placing RW libstd on linkline *before* libFoo results in the
> program printing "0" instead of "inf". The problem doesn't happen with
> native gcc STL.
> But the customer never links their shared libs(i.e libFoo in this
> example) with RW libstd.  They only link binaries with RW libstd! But it
> makes RW libstd sensitive to link order. And they think the problem is
> in limits.cpp file:
>> <snip>
>> static union {
>> char _C_bits [sizeof (double)];
>> double _C_inf;
>> } __rw_dbl_inf_bits = { _RWSTD_DBL_INF_BITS };
>> _RWSTD_EXPORT extern const double __rw_dbl_infinity =
>> __rw_dbl_inf_bits._C_inf; </snip>
>> __rw_dbl_infinity ends up in the uninitialized data section of
>> nm -C| grep __rw_dbl_infinity
>> 000937f8 B __rw::__rw_dbl_infinity
> If the symbol was initialized in data section, the link order wouldn't
> matter.

That's correct. Because the initializer of __rw_dbl_infinity is
not a constant expresssion [expr.const] the symbol is initialized
dynamically (at runtime) rather than statically (i.e., at load
time). It seems that the compiler should be able to initialize
it statically anyway, even if it's not required to. Regardless,
we should avoid making the assumption that it will and change
the initialization of the extern constants to use constant
expressions instead.

Can you please open an issue for this?


View raw message