From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/1308 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: thread local storage Date: Mon, 16 Jul 2012 16:09:51 -0400 Message-ID: <20120716200951.GO544@brightrain.aerifal.cx> References: <50046559.3090204@barfooze.de> <50046412.4060609@purdue.edu> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1342469445 7832 80.91.229.3 (16 Jul 2012 20:10:45 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 16 Jul 2012 20:10:45 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-1309-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jul 16 22:10:44 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Sqrcv-000462-RE for gllmg-musl@plane.gmane.org; Mon, 16 Jul 2012 22:10:41 +0200 Original-Received: (qmail 5625 invoked by uid 550); 16 Jul 2012 20:10:40 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 5617 invoked from network); 16 Jul 2012 20:10:40 -0000 Content-Disposition: inline In-Reply-To: <50046412.4060609@purdue.edu> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:1308 Archived-At: 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