From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/1313 Path: news.gmane.org!not-for-mail From: John Spencer Newsgroups: gmane.comp.lang.lua.luajit,gmane.linux.lib.musl.general Subject: Re: segfault on x86_64 using musl libc Date: Tue, 17 Jul 2012 02:46:23 +0200 Message-ID: <5004B5DF.7090403@barfooze.de> References: <5004117B.4080808@barfooze.de> <20120716140546.GA2002@mike.de> Reply-To: luajit-uGLqWuYN4qMgsBAKwltoeQ@public.gmane.org NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1342485429 26576 80.91.229.3 (17 Jul 2012 00:37:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 17 Jul 2012 00:37:09 +0000 (UTC) Cc: musl-ZwoEplunGu1jrUoiu81ncdBPR1lH4CV8@public.gmane.org, Rich Felker To: luajit-uGLqWuYN4qMgsBAKwltoeQ@public.gmane.org, Mike Pall Original-X-From: luajit-bounce-uGLqWuYN4qMgsBAKwltoeQ@public.gmane.org Tue Jul 17 02:37:08 2012 Return-path: Envelope-to: gclll-luajit@m.gmane.org Original-Received: from freelists-180.iquest.net ([206.53.239.180] helo=turing.freelists.org) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sqvmi-0006fb-1k for gclll-luajit@m.gmane.org; Tue, 17 Jul 2012 02:37:08 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id DDAC9EDA0FF; Mon, 16 Jul 2012 20:37:00 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=freelists.org; s=turing; t=1342485420; bh=peh6+qN3dNouo6mdpyzyXkiTyexHCM+hOoFxFTlp nOE=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding:Sender:Reply-To: List-help:List-unsubscribe:List-Id; b=S2wNU5SAakmMFRGHJmEgPQBMvBhx iOo5K4/JxeGTg3mHB363nmPLgk+uvTXkHvzwJxdsaBmorg8Cd+GmNLXPqq+v1oGorXH 8w9kuKb0ZGymQnP0d1aePsnx7X6Rr+OfRkAuIYlNqTbVSUg71K6VRfmWMdo42ONTU/q uuZB4vkk0= X-Virus-Scanned: Debian amavisd-new at localhost.localdomain Original-Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tdvmyW1bfS4Y; Mon, 16 Jul 2012 20:37:00 -0400 (EDT) Original-Received: from turing.freelists.org (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 9E351EDA0C5; Mon, 16 Jul 2012 20:36:46 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=freelists.org; s=turing; t=1342485420; bh=peh6+qN3dNouo6mdpyzyXkiTyexHCM+hOoFxFTlp nOE=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding:Sender:Reply-To: List-help:List-unsubscribe:List-Id; b=S2wNU5SAakmMFRGHJmEgPQBMvBhx iOo5K4/JxeGTg3mHB363nmPLgk+uvTXkHvzwJxdsaBmorg8Cd+GmNLXPqq+v1oGorXH 8w9kuKb0ZGymQnP0d1aePsnx7X6Rr+OfRkAuIYlNqTbVSUg71K6VRfmWMdo42ONTU/q uuZB4vkk0= Original-Received: with ECARTIS (v1.0.0; list luajit); Mon, 16 Jul 2012 20:36:46 -0400 (EDT) Original-Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 74EA9EDA0D3 for ; Mon, 16 Jul 2012 20:36:46 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at localhost.localdomain Original-Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xMHdHeC95YN8 for ; Mon, 16 Jul 2012 20:36:46 -0400 (EDT) Original-Received: from furnace.wzff.de (furnace.wzff.de [176.9.216.40]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id DFACBEDA0C5 for ; Mon, 16 Jul 2012 20:36:40 -0400 (EDT) Original-Received: from xdsl-188-155-204-150.adslplus.ch ([188.155.204.150] helo=[10.1.1.4]) by furnace.wzff.de with esmtpsa (TLSv1:CAMELLIA256-SHA:256) (Exim 4.77 (FreeBSD)) (envelope-from ) id 1Sqvm9-0003Gk-Cn; Tue, 17 Jul 2012 02:36:30 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Mail/1.0 In-Reply-To: <20120716140546.GA2002-kxVVdsWjIls@public.gmane.org> X-archive-position: 849 X-ecartis-version: Ecartis v1.0.0 Original-Sender: luajit-bounce-uGLqWuYN4qMgsBAKwltoeQ@public.gmane.org Errors-to: luajit-bounce-uGLqWuYN4qMgsBAKwltoeQ@public.gmane.org X-original-sender: maillist-luajit-Am5OCHYCrcUb1SvskN2V4Q@public.gmane.org Precedence: normal List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: luajit X-List-ID: luajit X-list: luajit Xref: news.gmane.org gmane.comp.lang.lua.luajit:548 gmane.linux.lib.musl.general:1313 Archived-At: On 07/16/2012 04:05 PM, Mike Pall wrote: > Apparently musl doesn't set up thread-local storage correctly. we had a discussion on the musl mailing list about the TLS issue, and it turned out that I mistakenly built gcc without --disable-tls. (musl currently doesn't support TLS for various reasons.) with gcc fixed, luajit seems to work fine (at least for singlethreaded usage). Rich came up with a clever portable (POSIX) way that could be used instead of the existing non-threadsafe fallback code for OSX/OpenBSD/non-TLS. please see forwarded Mail content below. From: Rich Felker Subject: Re: [musl] thread local storage On Mon, Jul 16, 2012 at 02:57:22PM -0400, Gregor Richards wrote: > On 07/16/2012 03:02 PM, John Spencer wrote: > >2 out of 14 sabotage followers wanted to use a musl-based system > >as a platform for luajit (and then were never seen again). > >so i looked into adding it... > > > >luajit builds without problems on musl, but then crashes due to a > >lack of TLS. > > > >is it planned to add this feature ? iirc it wasn't mentioned on > >the latest roadmap... > > > > > > > With a quick perusal of the LuaJIT source, this is the only instance > of TLS I see: > > #if LJ_UNWIND_EXT > #if LJ_TARGET_OSX || defined(__OpenBSD__) > /* Sorry, no thread safety for OSX. Complain to Apple, not me. */ > static _Unwind_Exception static_uex; > #else > static __thread _Unwind_Exception static_uex; > #endif > > Convince it to use the same exception as OS X and OpenBSD and you > should be in business. This is broken and non-thread-safe. Not a good idea. Instead try: #define static_uex (*(_Unwind_Exception *)pthread_getspecific(static_uex_key)) where static_uex_key is a pthread_key_t initialized earlier with: pthread_key_create(&static_uex_key, 0); And where the thread-specific value of the key is set in thread startup as: _Unwind_Exception static_uex_local; pthread_setspecific(static_uex_key, &static_uex_local); The simplicity and generality of this solution is why __thread was just a stupid idea to begin with... Rich