From owner-svn-src-head@FreeBSD.ORG Mon Apr 9 04:16:17 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 016B71065673; Mon, 9 Apr 2012 04:16:17 +0000 (UTC) (envelope-from andrew@fubar.geek.nz) Received: from mailfilter44.ihug.co.nz (mailfilter44.ihug.co.nz [203.109.136.44]) by mx1.freebsd.org (Postfix) with ESMTP id B70E88FC08; Mon, 9 Apr 2012 04:16:15 +0000 (UTC) X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.0 c=1 a=DE6nE7g822sA:10 a=f/SxzVRvWQdBqo0nlH1VRA==:17 a=6I5d2MoRAAAA:8 a=Gjt9h_guEhBIAy_4Co8A:9 a=QEXdDO2ut3YA:10 a=SV7veod9ZcQA:10 a=VAGSD8EX3UrfVcmK:21 a=uMMGHQrZwPfZDydR:21 a=Z1xzJwc4NuAIBxNH110A:9 a=-xCp-FiVW73MmOn47wkA:7 a=KTr_PvXjTkxT82MG:21 a=olYByBxJUJGmHZ1l:21 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8EAA1hgk/Ldqol/2dsb2JhbABEhWazRIEIggkBAQQBIzMjBQsIAQIOBgQqAgI5HgYTiAkEDKcmkgeLMYQRgRgEjmyGfwGQNoJ8gT8BFg X-IronPort-AV: E=Sophos;i="4.75,392,1330858800"; d="scan'208";a="133786825" Received: from 203-118-170-37.adsl.ihug.co.nz (HELO localhost) ([203.118.170.37]) by cust.filter6.content.vf.net.nz with SMTP; 09 Apr 2012 16:15:06 +1200 Date: Mon, 9 Apr 2012 16:14:53 +1200 From: Andrew Turner To: Juli Mallett Message-ID: <20120409161453.29d1f3de@fubar.geek.nz> In-Reply-To: References: <201204080436.q384aRXS093116@svn.freebsd.org> <20120408164521.55aecdd1@fubar.geek.nz> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.6; i386-portbld-freebsd8.0) X-Pirate: Arrrr Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/MUAtSxdUM4O2DLeLY2lu62S" Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r234014 - head/lib/libc/arm/gen X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Apr 2012 04:16:17 -0000 --MP_/MUAtSxdUM4O2DLeLY2lu62S Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Sun, 8 Apr 2012 18:36:45 -0700 Juli Mallett wrote: > On Sat, Apr 7, 2012 at 21:45, Andrew Turner > wrote: > > On Sun, 8 Apr 2012 04:36:27 +0000 (UTC) > > Andrew Turner wrote: > > > >> Author: andrew > >> Date: Sun Apr =C2=A08 04:36:27 2012 > >> New Revision: 234014 > >> URL: http://svn.freebsd.org/changeset/base/234014 > >> > >> Log: > >> =C2=A0 Unlike other functions __aeabi_read_tp function must preserve > >> r1-r3. The currently generated code clobbers r3. Fix this by > >> loading ARM_TP_ADDRESS using inline assembly. > >> > >> =C2=A0 Approved by: =C2=A0 =C2=A0 =C2=A0 =C2=A0imp (mentor) > > > > This fixes thread local storage on ARM in cases when the compiler > > loads the offset of the variable in r3 before calling > > __aeabi_read_tp as has been observed when the variable is in a > > shared library. >=20 > I don't believe this is safe unless you specify __attribute__ > ((__naked__)) in the declaration =E2=80=94 currently the compiler is free= to > clobber registers that the calling convention/ABI allows it to > clobber. I don't see the benefit of implementing this in C over using > an assembly file, that said, although GCC does have this attribute > precisely to allow one to write assembly in a C source file without > having to worry about unexpected behavior. We can implement it as a naked function but we will need to store all registers other than r0 and pc which seems a waste. The problem implementing it in an assembly file is we are unable to use ARM_TP_ADDRESS is defined as: #define ARM_TP_ADDRESS (ARM_VECTORS_HIGH + 0x1000) Where ARM_VECTORS_HIGH is defined as: #define ARM_VECTORS_HIGH 0xffff0000U Binutils fails because of the U in ARM_VECTORS_HIGH eith the following: Error: missing ')' Error: junk at end of line, first unrecognized character is `U' I could remove the U from ARM_VECTORS_HIGH however I'm not sure on the implications of that change. > How do you know GCC won't allocate r2 to be used as a temporary in > between the assembly and the return? The compiler is free to use r2 with the current code. I have attached a patch that fools the compiler into thinking we are using r1-r3 by placing them in the clobber list. Andrew --MP_/MUAtSxdUM4O2DLeLY2lu62S Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=arm_tls.patch Index: lib/libc/arm/gen/__aeabi_read_tp.c =================================================================== --- lib/libc/arm/gen/__aeabi_read_tp.c (revision 234031) +++ lib/libc/arm/gen/__aeabi_read_tp.c (working copy) @@ -39,7 +39,8 @@ { void *_tp; - asm("ldr %0, [%1]\n" : "=r"(_tp) : "r"(ARM_TP_ADDRESS)); + asm("ldr %0, [%1]\n" : "=r"(_tp) : "r"(ARM_TP_ADDRESS) + : "r1", "r2", "r3"); return _tp; } --MP_/MUAtSxdUM4O2DLeLY2lu62S--