From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/1312 Path: news.gmane.org!not-for-mail From: John Spencer Newsgroups: gmane.comp.lang.lua.luajit,gmane.linux.lib.musl.general Subject: Fwd: Re: [musl] thread local storage Date: Tue, 17 Jul 2012 01:53:32 +0200 Message-ID: <5004A97C.2000002@barfooze.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 1342482245 6760 80.91.229.3 (16 Jul 2012 23:44:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 16 Jul 2012 23:44:05 +0000 (UTC) Cc: luajit-uGLqWuYN4qMgsBAKwltoeQ@public.gmane.org, musl-ZwoEplunGu1jrUoiu81ncdBPR1lH4CV8@public.gmane.org, Rich Felker To: Mike Pall Original-X-From: luajit-bounce-uGLqWuYN4qMgsBAKwltoeQ@public.gmane.org Tue Jul 17 01:44:05 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 1SquxP-0004t7-AR for gclll-luajit@m.gmane.org; Tue, 17 Jul 2012 01:44:04 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id E6F7BEDB15B; Mon, 16 Jul 2012 19:43:58 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=freelists.org; s=turing; t=1342482238; bh=RGqEtTe7GlaCxI79nY4R54yZrnfg2hEJadgw0vsh 3IM=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject: Content-Type:Content-Transfer-Encoding:Sender:Reply-To:List-help: List-unsubscribe:List-Id; b=ZMSugN7RWZxmikIMKuSw4w0VB1RPNYbxe9lLKd iI5Wg2SFSL3Qx2zDlnaow5olNWS5yrqWq/PdpvuWWSe+iFWJCGGQqhetDYREOzmvm8T T0OJ/zOGswtmb7Gl2Bu++pXcGT2/dhykYv2Fa2cfmHvzg+s9e5pPnm7ckJ9iq5U8Bc= 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 9PGUsH64xfGw; Mon, 16 Jul 2012 19:43:58 -0400 (EDT) Original-Received: from turing.freelists.org (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 80EF3EDAC17; Mon, 16 Jul 2012 19:43:44 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=freelists.org; s=turing; t=1342482238; bh=RGqEtTe7GlaCxI79nY4R54yZrnfg2hEJadgw0vsh 3IM=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject: Content-Type:Content-Transfer-Encoding:Sender:Reply-To:List-help: List-unsubscribe:List-Id; b=ZMSugN7RWZxmikIMKuSw4w0VB1RPNYbxe9lLKd iI5Wg2SFSL3Qx2zDlnaow5olNWS5yrqWq/PdpvuWWSe+iFWJCGGQqhetDYREOzmvm8T T0OJ/zOGswtmb7Gl2Bu++pXcGT2/dhykYv2Fa2cfmHvzg+s9e5pPnm7ckJ9iq5U8Bc= Original-Received: with ECARTIS (v1.0.0; list luajit); Mon, 16 Jul 2012 19:43:44 -0400 (EDT) Original-Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 52B8AEDACA0 for ; Mon, 16 Jul 2012 19:43:44 -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 z58dk1xdRohH for ; Mon, 16 Jul 2012 19:43:44 -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 C3A4CEDAC17 for ; Mon, 16 Jul 2012 19:43:41 -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 1Squx0-00025h-EM; Tue, 17 Jul 2012 01:43:39 +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 X-archive-position: 848 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:547 gmane.linux.lib.musl.general:1312 Archived-At: Mike, 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