From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Anthonin Bonnefoy Newsgroups: gmane.lisp.guile.bugs Subject: bug#19523: Segfault when creating thread with scm_with_guile Date: Tue, 6 Jan 2015 15:27:31 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d043c061e7e9f4d050bfc9b31 X-Trace: ger.gmane.org 1420563354 27548 80.91.229.3 (6 Jan 2015 16:55:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 6 Jan 2015 16:55:54 +0000 (UTC) To: 19523@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Tue Jan 06 17:55:46 2015 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y8XNe-0002cg-Im for guile-bugs@m.gmane.org; Tue, 06 Jan 2015 17:53:18 +0100 Original-Received: from localhost ([::1]:37218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8XNe-0007AY-43 for guile-bugs@m.gmane.org; Tue, 06 Jan 2015 11:53:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8XNY-00077v-3O for bug-guile@gnu.org; Tue, 06 Jan 2015 11:53:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y8XNP-0000oo-Ln for bug-guile@gnu.org; Tue, 06 Jan 2015 11:53:12 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:57699) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8XNP-0000ok-I2 for bug-guile@gnu.org; Tue, 06 Jan 2015 11:53:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Y8XNP-0007ue-Aw for bug-guile@gnu.org; Tue, 06 Jan 2015 11:53:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Anthonin Bonnefoy Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 06 Jan 2015 16:53:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 19523 X-GNU-PR-Package: guile X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.142056312430310 (code B ref -1); Tue, 06 Jan 2015 16:53:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Jan 2015 16:52:04 +0000 Original-Received: from localhost ([127.0.0.1]:38830 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y8XMR-0007sf-IQ for submit@debbugs.gnu.org; Tue, 06 Jan 2015 11:52:04 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:59455) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y8V6j-0004Dy-6t for submit@debbugs.gnu.org; Tue, 06 Jan 2015 09:27:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y8V6h-0001KP-7s for submit@debbugs.gnu.org; Tue, 06 Jan 2015 09:27:40 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:34353) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8V6h-0001KJ-3j for submit@debbugs.gnu.org; Tue, 06 Jan 2015 09:27:39 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8V6f-0003ZK-C5 for bug-guile@gnu.org; Tue, 06 Jan 2015 09:27:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y8V6c-0001Ht-1l for bug-guile@gnu.org; Tue, 06 Jan 2015 09:27:37 -0500 Original-Received: from mail-wi0-f178.google.com ([209.85.212.178]:58136) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8V6b-0001HM-Nh for bug-guile@gnu.org; Tue, 06 Jan 2015 09:27:33 -0500 Original-Received: by mail-wi0-f178.google.com with SMTP id em10so5432315wid.11 for ; Tue, 06 Jan 2015 06:27:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=UFi5YG2njPk1HIx82pG39F1uEqBX8DEoC78TmwNdfFg=; b=JmnRa1T6rVBoXkvsLkpqsUJQcC7ptrZmJckG8ccYKGcEHC6ZInQ8YGZLdS9IoZG+ij w2PMQ4Fjtzjw23s0A8XgeBbyAKqADLuN5bnuNW0hzkCg+AmPpAgzmRiGuwyb9Y5dj/y/ NsP2Whdw3VLVxKK6hcauUGap3mZhPaDcSGesGsImPWF2om78gl7CUPWXo17ijAm9kiR/ oobLmK/eVZRk6SHOaQR/QYiZfRqF1MW5FSKq9BnfKjL0dG1OxAKx1vr3yYtafcLM2Q0S YJj4cHuKvueWJ10QBHI3wbAAkgGc+/dmKuvp2vw21k5xuRfXCTODZyels9pWRXo0NIxi 7iVw== X-Gm-Message-State: ALoCoQm2vTpsggIRctG/wPqbp6RVEyZCwGSum9JzTgsB5KIX984jFy1FFD6fSIPOXwgF2SHkLibB X-Received: by 10.180.104.9 with SMTP id ga9mr38157162wib.9.1420554451977; Tue, 06 Jan 2015 06:27:31 -0800 (PST) Original-Received: by 10.194.51.161 with HTTP; Tue, 6 Jan 2015 06:27:31 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Mailman-Approved-At: Tue, 06 Jan 2015 11:52:00 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7698 Archived-At: --f46d043c061e7e9f4d050bfc9b31 Content-Type: text/plain; charset=UTF-8 Hi all, I have segfaults occurring sometimes when threads are starting with scm_with_guile while main thread is using malloc. Example program: ``` #include #include #include static void *a_libguile_thread(void *unused) { } static void *a_libguile_thread_(void *unused) { scm_with_guile(a_libguile_thread, NULL); } static void do_mallocs(void) { void *a[1000]; for (int i = 0; i < 1000; ++i) { a[i] = malloc(356); } for (int i = 0; i < 1000; ++i) { free(a[i]); } } int main(int argc, char *argv[]) { scm_init_guile(); pthread_t pth[10]; for (int i = 0; i < 10; ++i) { GC_pthread_create(pth + i, NULL, a_libguile_thread_, NULL); } do_mallocs(); for (int i = 0; i < 10; ++i) { GC_pthread_join(pth[i], NULL); } return 0; } ``` To compile: gcc corruption_guile.c -g -std=c99 `pkg-config --cflags --libs guile-2.0` ``` Some iterations are needed before having the segfaults: while ./a.out; do echo -n "."; done; ``` Versions: gcc (Debian 4.9.1-19) 4.9.1 guile (GNU Guile) 2.0.11.20-4338f (also tried from v2.0.11 tag) libgc gc7_2d ``` Backtrace: #0 GC_generic_malloc (lb=524288, k=) at malloc.c:185 #1 0x00007fcc535541ff in make_vm () at vm.c:704 #2 0x00007fcc535542d5 in scm_the_vm () at vm.c:781 #3 0x00007fcc534da600 in scm_call_4 (proc=0x1198c30, arg1=arg1@entry=0x404, arg2=, arg3=, arg4=) at eval.c:507 #4 0x00007fcc53550d89 in scm_catch_with_pre_unwind_handler (key=key@entry=0x404, thunk=, handler=, pre_unwind_handler=) at throw.c:73 #5 0x00007fcc53550e8f in scm_c_catch (tag=tag@entry=0x404, body=body@entry=0x7fcc534d0c00 , body_data=body_data@entry=0x7fcc4d14cd50, handler=handler@entry=0x7fcc534d0fe0 , handler_data=handler_data@entry=0x7fcc4d14cd50 , pre_unwind_handler=pre_unwind_handler@entry=0x7fcc534d0d90 , pre_unwind_handler_data=0x127cff0) at throw.c:207 #6 0x00007fcc534d1381 in scm_i_with_continuation_barrier (body=body@entry=0x7fcc534d0c00 , body_data=body_data@entry=0x7fcc4d14cd50, handler=handler@entry=0x7fcc534d0fe0 , handler_data=handler_data@entry=0x7fcc4d14cd50, pre_unwind_handler=pre_unwind_handler@entry=0x7fcc534d0d90 , pre_unwind_handler_data=0x127cff0) at continuations.c:455 #7 0x00007fcc534d1415 in scm_c_with_continuation_barrier (func=, data=) at continuations.c:551 #8 0x00007fcc5354e6dc in with_guile_and_parent (base=base@entry=0x7fcc4d14cdb0, data=data@entry=0x7fcc4d14cde0) at threads.c:906 #9 0x00007fcc53222302 in GC_call_with_stack_base (fn=fn@entry=0x7fcc5354e690 , arg=arg@entry=0x7fcc4d14cde0) at misc.c:1553 #10 0x00007fcc5354eac8 in scm_i_with_guile_and_parent (parent=, data=, func=) at threads.c:949 #11 scm_with_guile (func=, data=) at threads.c:955 #12 0x00000000004008bb in a_libguile_thread_ (unused=0x0) at corruption_guile.c:11 #13 0x00007fcc53226f6e in GC_inner_start_routine (sb=, arg=) at pthread_start.c:56 #14 0x00007fcc53222302 in GC_call_with_stack_base (fn=, arg=) at misc.c:1553 #15 0x00007fcc52ff40a4 in start_thread (arg=0x7fcc4d14d700) at pthread_create.c:309 #16 0x00007fcc52d28ccd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111 ``` I thought at first it was a problem with libgc but the given program run without problems. ``` #include #include #define GC_THREADS 1 #define GC_NO_THREAD_REDIRECTS 1 #include #include static void *a_lib_gc_thread(void *unused) { void *a; for (int i = 0; i < 100; ++i) { a = GC_generic_malloc(524288, 6); } GC_free(a); } static void do_mallocs(void) { void *a[100]; for (int i = 0; i < 100; ++i) { a[i] = malloc(356); } for (int i = 0; i < 100; ++i) { free(a[i]); } } int main(int argc, char *argv[]) { pthread_t pth[10]; for (int i = 0; i < 10; ++i) { GC_pthread_create(pth + i, NULL, a_lib_gc_thread, NULL); } do_mallocs(); for (int i = 0; i < 10; ++i) { GC_pthread_join(pth[i], NULL); } return 0; } ``` I also tried to replace malloc by scm_malloc with no luck. Regards, Anthonin --f46d043c061e7e9f4d050bfc9b31 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi all,

I have segfaults occur= ring sometimes when threads are starting with scm_with_guile while main thr= ead is using malloc.

Example program:
```
#include <s= tdlib.h>
#include <pthread.h>
#include <libguile.h>
static void *a_libguile_thread(void *unused) {
}

static void= *a_libguile_thread_(void *unused) {
=C2=A0=C2=A0=C2=A0 scm_with_guile(a= _libguile_thread, NULL);
}

static void do_mallocs(void) {
=C2= =A0=C2=A0=C2=A0 void *a[1000];
=C2=A0=C2=A0=C2=A0 for (int i =3D 0; i &l= t; 1000; ++i) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 a[i] =3D mall= oc(356);
=C2=A0=C2=A0=C2=A0 }
=C2=A0=C2=A0=C2=A0 for (int i =3D 0; i = < 1000; ++i) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 free(a[i]);=
=C2=A0=C2=A0=C2=A0 }
}

int main(int argc, char *argv[]) {
= =C2=A0=C2=A0=C2=A0 scm_init_guile();

=C2=A0=C2=A0=C2=A0 pthread_t pt= h[10];
=C2=A0=C2=A0=C2=A0 for (int i =3D 0; i < 10; ++i) {
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 GC_pthread_create(pth + i, NULL, a_lib= guile_thread_, NULL);
=C2=A0=C2=A0=C2=A0 }

=C2=A0=C2=A0=C2=A0 do_= mallocs();

=C2=A0=C2=A0=C2=A0 for (int i =3D 0; i < 10; ++i) {=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 GC_pthread_join(pth[i], NULL);<= br>=C2=A0=C2=A0=C2=A0 }

=C2=A0=C2=A0=C2=A0 return 0;
}

```=
To compile:
gcc corruption_guile.c -g -std=3Dc99 `pkg-con= fig --cflags --libs guile-2.0`
```
Some iterati= ons are needed before having the segfaults:
while ./a.out; do= echo -n "."; done;
```
Versions:
=
gcc (Debian 4.9.1-19) 4.9.1
guile (GNU Guile) 2.0.11.20= -4338f (also tried from v2.0.11 tag)
libgc gc7_2d
```
<= div>Backtrace:

#0=C2=A0 GC_generic_malloc (lb=3D524288, = k=3D<optimized out>) at malloc.c:185
#1=C2=A0 0x00007fcc535541ff i= n make_vm () at vm.c:704
#2=C2=A0 0x00007fcc535542d5 in scm_the_vm () at= vm.c:781
#3=C2=A0 0x00007fcc534da600 in scm_call_4 (proc=3D0x1198c30, a= rg1=3Darg1@entry=3D0x404, arg2=3D<optimized out>, arg3=3D<optimize= d out>, arg4=3D<optimized out>) at eval.c:507
#4=C2=A0 0x00007f= cc53550d89 in scm_catch_with_pre_unwind_handler (key=3Dkey@entry=3D0x404, t= hunk=3D<optimized out>, handler=3D<optimized out>, pre_unwind_h= andler=3D<optimized out>) at throw.c:73
#5=C2=A0 0x00007fcc53550e8= f in scm_c_catch (tag=3Dtag@entry=3D0x404, body=3Dbody@entry=3D0x7fcc534d0c= 00 <c_body>, body_data=3Dbody_data@entry=3D0x7fcc4d14cd50, handler=3D= handler@entry=3D0x7fcc534d0fe0 <c_handler>, handler_data=3Dhandler_da= ta@entry=3D0x7fcc4d14cd50
, pre_unwind_handler=3Dpre_unwind_handler@entr= y=3D0x7fcc534d0d90 <pre_unwind_handler>, pre_unwind_handler_data=3D0x= 127cff0) at throw.c:207
#6=C2=A0 0x00007fcc534d1381 in scm_i_with_contin= uation_barrier (body=3Dbody@entry=3D0x7fcc534d0c00 <c_body>, body_dat= a=3Dbody_data@entry=3D0x7fcc4d14cd50, handler=3Dhandler@entry=3D0x7fcc534d0= fe0 <c_handler>, handler_data=3Dhandler_data@entry=3D0x7fcc4d14cd50,<= br>=C2=A0pre_unwind_handler=3Dpre_unwind_handler@entry=3D0x7fcc534d0d90 <= ;pre_unwind_handler>, pre_unwind_handler_data=3D0x127cff0) at continuati= ons.c:455
#7=C2=A0 0x00007fcc534d1415 in scm_c_with_continuation_barrier= (func=3D<optimized out>, data=3D<optimized out>) at continuati= ons.c:551
#8=C2=A0 0x00007fcc5354e6dc in with_guile_and_parent (base=3Db= ase@entry=3D0x7fcc4d14cdb0, data=3Ddata@entry=3D0x7fcc4d14cde0) at threads.= c:906
#9=C2=A0 0x00007fcc53222302 in GC_call_with_stack_base (fn=3Dfn@en= try=3D0x7fcc5354e690 <with_guile_and_parent>, arg=3Darg@entry=3D0x7fc= c4d14cde0) at misc.c:1553
#10 0x00007fcc5354eac8 in scm_i_with_guile_and= _parent (parent=3D<optimized out>, data=3D<optimized out>, func= =3D<optimized out>) at threads.c:949
#11 scm_with_guile (func=3D&l= t;optimized out>, data=3D<optimized out>) at threads.c:955
#12 = 0x00000000004008bb in a_libguile_thread_ (unused=3D0x0) at corruption_guile= .c:11
#13 0x00007fcc53226f6e in GC_inner_start_routine (sb=3D<error r= eading variable: value has been optimized out>, arg=3D<error reading = variable: value has been optimized out>) at pthread_start.c:56
#14 0x= 00007fcc53222302 in GC_call_with_stack_base (fn=3D<optimized out>, ar= g=3D<optimized out>) at misc.c:1553
#15 0x00007fcc52ff40a4 in star= t_thread (arg=3D0x7fcc4d14d700) at pthread_create.c:309
#16 0x00007fcc52= d28ccd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
```<= br>
I thought at first it was a problem with libgc but the given program= run without problems.
```
#include <stdlib.h>
#include <= pthread.h>
#define GC_THREADS 1
#define GC_NO_THREAD_REDIRECTS 1#include <gc/gc_mark.h>
#include <gc.h>

static void= *a_lib_gc_thread(void *unused) {
=C2=A0=C2=A0=C2=A0 void *a;
=C2=A0= =C2=A0=C2=A0 for (int i =3D 0; i < 100; ++i) {
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 a =3D GC_generic_malloc(524288, 6);
=C2=A0=C2=A0= =C2=A0 }
=C2=A0=C2=A0=C2=A0 GC_free(a);
}

static void do_mallo= cs(void) {
=C2=A0=C2=A0=C2=A0 void *a[100];
=C2=A0=C2=A0=C2=A0 for (i= nt i =3D 0; i < 100; ++i) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 a[i] =3D malloc(356);
=C2=A0=C2=A0=C2=A0 }
=C2=A0=C2=A0=C2=A0 for= (int i =3D 0; i < 100; ++i) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 free(a[i]);
=C2=A0=C2=A0=C2=A0 }
}

int main(int argc, c= har *argv[]) {
=C2=A0=C2=A0=C2=A0 pthread_t pth[10];
=C2=A0=C2=A0=C2= =A0 for (int i =3D 0; i < 10; ++i) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 GC_pthread_create(pth + i, NULL, a_lib_gc_thread, NULL);
= =C2=A0=C2=A0=C2=A0 }
=C2=A0=C2=A0=C2=A0 do_mallocs();
=C2=A0=C2=A0=C2= =A0 for (int i =3D 0; i < 10; ++i) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 GC_pthread_join(pth[i], NULL);
=C2=A0=C2=A0=C2=A0 }
=C2= =A0=C2=A0=C2=A0 return 0;
}
```
I also tried to replace mal= loc by scm_malloc with no luck.

Regards, Antho= nin
--f46d043c061e7e9f4d050bfc9b31--