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

Reply via email to