On Sun, 8 Apr 2012 18:36:45 -0700 Juli Mallett <jmall...@freebsd.org> wrote:
> On Sat, Apr 7, 2012 at 21:45, Andrew Turner <and...@fubar.geek.nz> > wrote: > > On Sun, 8 Apr 2012 04:36:27 +0000 (UTC) > > Andrew Turner <and...@freebsd.org> wrote: > > > >> Author: andrew > >> Date: Sun Apr 8 04:36:27 2012 > >> New Revision: 234014 > >> URL: http://svn.freebsd.org/changeset/base/234014 > >> > >> Log: > >> 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. > >> > >> Approved by: imp (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. > > I don't believe this is safe unless you specify __attribute__ > ((__naked__)) in the declaration — 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
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; }
_______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"