Pthread library error when calling from static constructor code

I have a C ++ shared library object that includes a GLib library .

When I create a minimal test program with the emptymain() function , and I link to the shared library, the program terminates immediately at runtime with the following GLib error message:

GLib (gthread-posix.c): Unexpected error from C library during 'pthread_cond_init': Invalid argument.  Aborting.

Since my main function is empty, the error should be executed somewhere in some pre-initialization function. So, using GDB, I found that GLib has a static initialization function (in glib-init.c) that it calls at runtime before main(). Inside this initialization function, it calls pthread_cond_init, which mysteriously fails.

Here is the complete backtrace:

(gdb) run
Starting program: ~/example
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x2aaaaaaab000
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
GLib (gthread-posix.c): Unexpected error from C library during 'pthread_cond_init': Invalid argument.  Aborting.

Program received signal SIGABRT, Aborted.
0x0000003891830265 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x0000003891830265 in raise () from /lib64/libc.so.6
#1  0x0000003891831d10 in abort () from /lib64/libc.so.6
#2  0x00002aaaab9aed32 in g_thread_abort (status=22,
    function=0x2aaaabcbdd2b "pthread_cond_init")
    at ~/libs/glib/gthread-posix.c:75
#3  0x00002aaaab9af349 in g_cond_impl_new ()
    at ~/libs/glib/gthread-posix.c:656
#4  0x00002aaaab9af39b in g_cond_get_impl (
    cond=0x2aaaac15f690 <g_once_cond>)
    at ~/libs/glib/gthread-posix.c:677
#5  0x00002aaaab9af4b2 in g_cond_broadcast (
    cond=0x2aaaac15f690 <g_once_cond>)
    at ~/libs/glib/gthread-posix.c:792
#6  0x00002aaaab9ab529 in g_once_init_leave (
    location=0x2aaaac160510 <g_define_type_id__volatile.11714>,
    result=6524000) at ~/libs/glib/gthread.c:682
#7  0x00002aaaaba34a2f in g_value_array_get_type ()
    at ~/libs/gobject/gboxed.c:132
#8  0x00002aaaaba41b28 in _g_param_spec_types_init ()
    at ~/libs/gobject/gparamspecs.c:1511
#9  0x00002aaaaba30c72 in gobject_init_ctor ()
    at ~/libs/gobject/gtype.c:4391
#10 0x00002aaaabb2bc36 in __do_global_ctors_aux ()
   from ./MYLIB.so
#11 0x00002aaaaad368eb in _init () from ./MYLIB.so
#12 0x00002aaab0180e60 in ?? ()
#13 0x000000389140d4ab in call_init ()
  from /lib64/ld-linux-x86-64.so.2
#14 0x000000389140d5b5 in _dl_init_internal ()
   from /lib64/ld-linux-x86-64.so.2
#15 0x0000003891400aaa in _dl_start_user ()
   from /lib64/ld-linux-x86-64.so.2
#16 0x0000000000000001 in ?? ()
#17 0x00007fffffffe6de in ?? ()
#18 0x0000000000000000 in ?? ()

, , , .so pthread. , ldd, , pthread:

$ ldd MYLIB.so
        linux-vdso.so.1 =>  (0x00007fff56ed1000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b8a747bf000)
        librt.so.1 => /lib64/librt.so.1 (0x00002b8a749db000)
        libpng12.so.0 => /usr/lib64/libpng12.so.0 (0x00002b8a74be5000)
        libfontconfig.so.1 => /usr/lib64/libfontconfig.so.1 (0x00002b8a74e09000)
        libz.so.1 => /lib64/libz.so.1 (0x00002b8a7503d000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00002b8a75252000)
        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002b8a75456000)
        libm.so.6 => /lib64/libm.so.6 (0x00002b8a75756000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002b8a759da000)
        libc.so.6 => /lib64/libc.so.6 (0x00002b8a75be8000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003891400000)
        libfreetype.so.6 => /usr/lib64/libfreetype.so.6 (0x00002b8a75f41000)
        libexpat.so.0 => /lib64/libexpat.so.0 (0x00002b8a761c6000)

, libpthread /usr/lib64/pthread.so.0

, GLib, pthread_cond_init. . #ifdef:

  pthread_condattr_t attr;
  pthread_cond_t *cond;
  gint status;
  pthread_condattr_init (&attr);

  cond = malloc (sizeof (pthread_cond_t));
  if G_UNLIKELY (cond == NULL)
    g_thread_abort (errno, "malloc");

  if G_UNLIKELY ((status = pthread_cond_init (cond, &attr)) != 0) <--- this fails
    g_thread_abort (status, "pthread_cond_init");

, , , GLib , , , Linux-.

, . / ? , , pthread lib , GLib ?

+4
1

glibc-2.5 pthread_cond_init. , , , , ,

, CLOCK_REALTIME

EINVAL .

642 gthread-posix.c

pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);

, , EINVAL pthread_cond_init.

glib, HAVE_PTHREAD_CONDATTR_SETCLOCK.

glibc, .

0

All Articles