From owner-freebsd-ports-bugs@FreeBSD.ORG Mon Aug 5 13:50:00 2013 Return-Path: Delivered-To: freebsd-ports-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B8C9E883 for ; Mon, 5 Aug 2013 13:50:00 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9828F2E49 for ; Mon, 5 Aug 2013 13:50:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r75Do0S1070269 for ; Mon, 5 Aug 2013 13:50:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r75Do0CV070268; Mon, 5 Aug 2013 13:50:00 GMT (envelope-from gnats) Resent-Date: Mon, 5 Aug 2013 13:50:00 GMT Resent-Message-Id: <201308051350.r75Do0CV070268@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Vitaly Magerya Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D3E4F6A7 for ; Mon, 5 Aug 2013 13:40:07 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C178A2DE4 for ; Mon, 5 Aug 2013 13:40:07 +0000 (UTC) Received: from oldred.freebsd.org ([127.0.1.6]) by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r75De7DM091461 for ; Mon, 5 Aug 2013 13:40:07 GMT (envelope-from nobody@oldred.freebsd.org) Received: (from nobody@localhost) by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r75De6TL091341; Mon, 5 Aug 2013 13:40:06 GMT (envelope-from nobody) Message-Id: <201308051340.r75De6TL091341@oldred.freebsd.org> Date: Mon, 5 Aug 2013 13:40:06 GMT From: Vitaly Magerya To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: ports/181052: [patch] make lang/lua not hang on thread creation X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Aug 2013 13:50:00 -0000 >Number: 181052 >Category: ports >Synopsis: [patch] make lang/lua not hang on thread creation >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Aug 05 13:50:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Vitaly Magerya >Release: FreeBSD 9.1 amd64 >Organization: >Environment: >Description: Currently lang/lua links the 'lua' binary without -pthread flag; this results in any call to 'pthread_create' to completely hang the program. Normally this wouldn't be an issue, since Lua doesn't use any threading functions, but the problem propagates to all the C extensions as well. For example, if you'll install devel/lgi (the GObject/Gtk bindings), and try this simple program: $ lua-5.1 Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio > lgi = require 'lgi' > gtk = lgi.Gtk > gtk.FileChooserDialog {} .. it will hang at this point. The reason being that Gtk uses threads internally and tries to spawn a few when you create a FileChooser object. That is to say, this problem makes lang/lgi basically unusable, and prevents any kind of Lua Gtk programs working on FreeBSD. More directly, you can create an extension that calls 'pthread_create': $ cat >test.c <<'EOF' #include #include #include #include static void * thread_func(void *arg) { pthread_exit(0); } static int test(lua_State *L) { pthread_t thread; printf("PTHREAD CREATE\n"); pthread_create(&thread, NULL, thread_func, NULL); printf("PTHREAD JOIN\n"); pthread_join(thread, NULL); printf("DONE\n"); } static const struct luaL_Reg lib[] = { {"test", test}, {NULL, NULL} }; LUALIB_API int luaopen_test(lua_State *L) { #if LUA_VERSION_NUM < 502 luaL_register(L, "test", lib); #else luaL_newlib(L, lib); #endif return 1; } EOF $ cc -I/usr/local/include/lua51 -shared -pthread -fPIC -o test.so test.c $ lua-5.1 Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio > test = require "test" > test.test() PTHREAD CREATE .. and again, it hangs. >How-To-Repeat: >Fix: See the attached patch. With it both 'lua' and 'lua.so' link with -pthread. Note that lang/lua52 and lang/luajit are affected too, but this PR only deals with lang/lua. Patch attached with submission follows: diff -ruN lua.orig/Makefile lua/Makefile --- lua.orig/Makefile 2013-04-23 17:20:25.000000000 +0300 +++ lua/Makefile 2013-08-05 16:02:33.000000000 +0300 @@ -33,7 +33,7 @@ MAKE_ARGS= __MAKE_CONF=${NONEXISTENT} # liblua.so requires libm, so make sure it has an explicit dependency # so that applications need not second-guess lua's dependencies. -LDFLAGS+= -lm +LDFLAGS+= -lm -pthread MAN1= lua-${LUA_VER}.1 luac-${LUA_VER}.1 DOCSDIR= ${PREFIX}/share/doc/${LUA_SUBDIR} diff -ruN lua.orig/files/patch-src-Makefile lua/files/patch-src-Makefile --- lua.orig/files/patch-src-Makefile 2012-07-14 16:54:48.000000000 +0300 +++ lua/files/patch-src-Makefile 2013-08-05 15:57:29.000000000 +0300 @@ -1,6 +1,6 @@ ---- Makefile.orig 2008-01-19 17:37:58.000000000 -0200 -+++ Makefile 2008-08-10 16:00:41.000000000 -0300 -@@ -9,7 +9,8 @@ +--- Makefile.orig 2012-02-13 22:41:22.000000000 +0200 ++++ Makefile 2013-08-05 15:56:32.000000000 +0300 +@@ -9,10 +9,11 @@ CC= gcc CFLAGS= -O2 -Wall $(MYCFLAGS) @@ -9,7 +9,11 @@ +AR= ar RANLIB= ranlib RM= rm -f - LIBS= -lm $(MYLIBS) +-LIBS= -lm $(MYLIBS) ++LIBS= -lm -pthread $(MYLIBS) + + MYCFLAGS= + MYLDFLAGS= @@ -31,12 +32,13 @@ LUA_T= lua >Release-Note: >Audit-Trail: >Unformatted: