Subject: bug#15411: libguile initialization inside a pthread segfaults

From: Dale Mellor <[email-masked]>
Date: Wed, 18 Sep 2013 20:36:39 +0100

The following program fails; it produces the session shown below.  Any
help greatly appreciated.

Dale

=PROGRAM==============================================================
#include <libguile.h>

static void *do_guile (void *)
{
  for (;;) ;

  return nullptr;
}

static void *run_thread (void *)
{
  return scm_with_guile (&do_guile, nullptr);
}

int main (int, char **)
{
  pthread_t thread;
  pthread_create (&thread, nullptr, run_thread, nullptr);

  pthread_join (thread, nullptr);

  return 0;
}

=/PROGRAM=============================================================

=SESSION==============================================================
$ cat /etc/debian_version 
7.1

$ g++-4.6 --version
g++-4.6 (Debian 4.6.3-14) 4.6.3

$ guile --version
guile (GNU Guile) 2.0.5-deb+1-3

$ g++-4.6 --std=c++0x test.cc `pkg-config --libs --cflags guile-2.0` -g

$ gdb a.out
GNU gdb (GDB) 7.4.1-debian
This GDB was configured as "i486-linux-gnu".
Reading symbols from a.out...done.
(gdb) r
Starting program: a.out 
warning: Could not load shared library symbols for linux-gate.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library
"/lib/i386-linux-gnu/i686/cmov/libthread_db.so.1".
[New Thread 0xb7916b40 (LWP 4792)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7916b40 (LWP 4792)]
0xb7e2854f in GC_push_all_eager () from /usr/lib/libgc.so.1
(gdb) info stack
#0  0xb7e2854f in GC_push_all_eager () from /usr/lib/libgc.so.1
#1  0xb7e285a3 in GC_push_all_stack () from /usr/lib/libgc.so.1
#2  0xb7e30b9b in GC_push_all_stacks () from /usr/lib/libgc.so.1
#3  0xb7e2b6e4 in GC_default_push_other_roots ()
from /usr/lib/libgc.so.1
#4  0xb7e29c45 in GC_push_roots () from /usr/lib/libgc.so.1
#5  0xb7e290b6 in GC_mark_some () from /usr/lib/libgc.so.1
#6  0xb7e1ffb5 in GC_stopped_mark () from /usr/lib/libgc.so.1
#7  0xb7e206ba in GC_try_to_collect_inner () from /usr/lib/libgc.so.1
#8  0xb7e2ae50 in GC_init_inner () from /usr/lib/libgc.so.1
#9  0xb7e2afa4 in GC_init () from /usr/lib/libgc.so.1
#10 0xb7eba7d0 in ?? () from /usr/lib/libguile-2.0.so.22
#11 0xb7ecbebd in ?? () from /usr/lib/libguile-2.0.so.22
#12 0xb7f29750 in ?? () from /usr/lib/libguile-2.0.so.22
#13 0xb7f29790 in ?? () from /usr/lib/libguile-2.0.so.22
#14 0xb7e2aa2e in GC_call_with_stack_base () from /usr/lib/libgc.so.1
#15 0xb7f2998f in scm_with_guile () from /usr/lib/libguile-2.0.so.22
#16 0x08048663 in run_thread () at test.cc:16
#17 0xb7cb2cf1 in start_thread ()
   from /lib/i386-linux-gnu/i686/cmov/libpthread.so.0
#18 0xb7bebfee in clone () from /lib/i386-linux-gnu/i686/cmov/libc.so.6
(gdb) thr 1
[Switching to thread 1 (Thread 0xb7918700 (LWP 4789))]
#0  0xb7fde424 in __kernel_vsyscall ()
(gdb) info stack
#0  0xb7fde424 in __kernel_vsyscall ()
#1  0xb7cb3d8c in pthread_join ()
   from /lib/i386-linux-gnu/i686/cmov/libpthread.so.0
#2  0x080486a6 in main () at test.cc:26
(gdb) quit

=/SESSION=============================================================