Question about __gnu_cxx::__exchange_and_add_dispatch
unlvsur unlvsur
unlvsur@live.com
Fri Apr 21 08:53:40 GMT 2023
Looks like truly a linker bug that fails to initialize static variable if it is dynamic linked with it
30375 – C++ std::cout's rdbuf gives ridiculous address on windows with dynamic linking with ld (sourceware.org)<https://sourceware.org/bugzilla/show_bug.cgi?id=30375>
30254 – iostream crashes with ld linker for windows targets (sourceware.org)<https://sourceware.org/bugzilla/show_bug.cgi?id=30254>
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
From: Jonathan Wakely<mailto:jwakely@redhat.com>
Sent: Friday, April 21, 2023 04:49
To: unlvsur unlvsur<mailto:unlvsur@live.com>
Cc: unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
Subject: Re: Question about __gnu_cxx::__exchange_and_add_dispatch
On Fri, 21 Apr 2023 at 08:06, unlvsur unlvsur via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Take this as an example
> gcc/ios_init.cc at master · gcc-mirror/gcc (github.com)<https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/src/c++98/ios_init.cc#L80>
>
>
> what happens when
> if (__gnu_cxx::__exchange_and_add_dispatch(&_S_refcount, 1) != 0??
>
> Does that mean global objects of iostream are not initialized?)
If _S_refcount != 0 that means the global iostreams have already been
initialized.
> Probably this is why I get crashing on windows since never (__gnu_cxx::__exchange_and_add_dispatch(&_S_refcount, 1) == 0
> With win32 thread model any more
That _S_refcount object has static storage duration, so it should be
initialized to zero before the program starts executing.
If static data isn't being zeroed that yes, that will cause big problems.
> However, if I use lld or statically link with ld, the program would still work. It does not when it dynamic link with ld.
More information about the Libstdc++
mailing list