public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "slyfox at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/97485] std::call_once crashes at runtime on glibc if not linked to libpthread: terminate called after throwing an instance of 'std::system_error': what():  Unknown error -1
Date: Mon, 19 Oct 2020 07:23:50 +0000	[thread overview]
Message-ID: <bug-97485-4-4WdgPuFNH1@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97485-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97485

--- Comment #2 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
AFAIU '-1' comes from
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/gthr-posix.h;h=965247602acf11f81c5fa009c7ee48eb55cbacca;hb=HEAD#l696

 696 static inline int
 697 __gthread_once (__gthread_once_t *__once, void (*__func) (void))
 698 {
 699   if (__gthread_active_p ())
 700     return __gthrw_(pthread_once) (__once, __func);
 701   else
 702     return -1;
 703 }

where '__gthread_active_p ()' returns false:
  (gdb) call __gthread_active_p()
  $2 = 0

That is defined in
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/gthr-posix.h;h=965247602acf11f81c5fa009c7ee48eb55cbacca;hb=HEAD#l236

 236 #ifdef __GLIBC__
 237 __gthrw2(__gthrw_(__pthread_key_create),
 238          __pthread_key_create,
 239          pthread_key_create)
 240 # define GTHR_ACTIVE_PROXY      __gthrw_(__pthread_key_create)
 241 #elif defined (__BIONIC__)
 242 # define GTHR_ACTIVE_PROXY      __gthrw_(pthread_create)
 243 #else
 244 # define GTHR_ACTIVE_PROXY      __gthrw_(pthread_cancel)
 245 #endif
 246 
 247 static inline int
 248 __gthread_active_p (void)
 249 {
 250   static void *const __gthread_active_ptr
 251     = __extension__ (void *) &GTHR_ACTIVE_PROXY;
 252   return __gthread_active_ptr != 0;
 253 }

Both of symbols are weak, unbound to libpthread and unversioned (for
non-working case):

$ g++-11.0.0 a.cc -o a && x86_64-pc-linux-gnu-nm -D a | fgrep -i pthread
                 w __pthread_key_create
                 w pthread_once

$ g++-11.0.0 a.cc -o a -pthread && x86_64-pc-linux-gnu-nm -D a | fgrep -i
pthread
                 w __pthread_key_create@@GLIBC_2.2.5
                 w pthread_once@@GLIBC_2.2.5

  parent reply	other threads:[~2020-10-19  7:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-19  7:10 [Bug libstdc++/97485] New: std::call_once crashes at runtime on glibc if not linked to libpthread: slyfox at gcc dot gnu.org
2020-10-19  7:14 ` [Bug libstdc++/97485] std::call_once crashes at runtime on glibc if not linked to libpthread: terminate called after throwing an instance of 'std::system_error': what(): Unknown error -1 slyfox at gcc dot gnu.org
2020-10-19  7:23 ` slyfox at gcc dot gnu.org [this message]
2020-10-19 12:56 ` redi at gcc dot gnu.org
2020-10-19 22:07 ` slyfox at gcc dot gnu.org

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=bug-97485-4-4WdgPuFNH1@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).