public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* Question about __gnu_cxx::__exchange_and_add_dispatch
@ 2023-04-21  7:06 unlvsur unlvsur
  2023-04-21  8:49 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: unlvsur unlvsur @ 2023-04-21  7:06 UTC (permalink / raw)
  To: unlvsur unlvsur via Libstdc++

[-- Attachment #1: Type: text/plain, Size: 689 bytes --]

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?)

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

However, if I use lld or statically link with ld, the program would still work. It does not when it dynamic link with ld.

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows


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

* Re: Question about __gnu_cxx::__exchange_and_add_dispatch
  2023-04-21  7:06 Question about __gnu_cxx::__exchange_and_add_dispatch unlvsur unlvsur
@ 2023-04-21  8:49 ` Jonathan Wakely
  2023-04-21  8:53   ` unlvsur unlvsur
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2023-04-21  8:49 UTC (permalink / raw)
  To: unlvsur unlvsur; +Cc: unlvsur unlvsur via Libstdc++

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.


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

* RE: Question about __gnu_cxx::__exchange_and_add_dispatch
  2023-04-21  8:49 ` Jonathan Wakely
@ 2023-04-21  8:53   ` unlvsur unlvsur
  0 siblings, 0 replies; 3+ messages in thread
From: unlvsur unlvsur @ 2023-04-21  8:53 UTC (permalink / raw)
  To: unlvsur unlvsur via Libstdc++

[-- Attachment #1: Type: text/plain, Size: 1778 bytes --]

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.


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

end of thread, other threads:[~2023-04-21  8:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-21  7:06 Question about __gnu_cxx::__exchange_and_add_dispatch unlvsur unlvsur
2023-04-21  8:49 ` Jonathan Wakely
2023-04-21  8:53   ` unlvsur unlvsur

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).