Some more on TLS

Marcel Moolenaar marcel at xcllnt.net
Sat Jul 19 09:24:09 PDT 2003


On Sat, Jul 19, 2003 at 09:54:06AM -0400, Alexander Kabaev wrote:
> 
> > o  There's no assembler support for TLS on i386 and amd64.
> 
> amd64 is new and TLS is probably not activated enabled in binutils yet.
> 
> i386 assebmly thing: what do you mean?
> 
> % cat test.c 
>        .section ".tdata","awT", at progbits
> foo:    .long   25
>         .text
>         movl    %gs:0, %eax
>         leal    foo at TLSGD(,%ebx,1), %eax
>         leal    foo at TLSLDM(%ebx), %eax
>         leal    foo at DTPOFF(%eax), %edx
>         movl    foo at GOTTPOFF(%ebx), %eax
>         subl    foo at GOTTPOFF(%ebx), %eax
>         addl    foo at GOTNTPOFF(%ebx), %eax
>         movl    foo at INDNTPOFF, %eax
>         movl    $foo at TPOFF, %eax
>         subl    $foo at TPOFF, %eax
>         leal    foo at NTPOFF(%ecx), %eax

Our in-tree compiler emits assembly that our assembler doesn't like.
Given the following C program:

\begin{c}
int __thread i = 3;
int x()
{
        return i;
}
\end{c}

Our compiler emits:

\begin{as}
        .file   "t.c"
.globl %li
        .section        .tdata,"awT", at progbits
        .p2align 2
        .type   %li, @object
        .size   %li, 4
%li:
        .long   3
        .text
        .p2align 2,,3
.globl x
        .type   x, @function
x:
        pushl   %ebp
        movl    %esp, %ebp
        movl    %gs:0, %eax
        movl    %li at NTPOFF(%eax), %eax
        leave
        ret
        .size   x, .-x
        .ident  "GCC: (GNU) 3.3.1 [FreeBSD] 20030711 (prerelease)"
\end{as}

And the assembler does not like that:
/var/tmp//ccVMU4H6.s: Assembler messages:
/var/tmp//ccVMU4H6.s:2: Warning: rest of line ignored; first ignored character is `%'
/var/tmp//ccVMU4H6.s:5: Error: unrecognized symbol type "li"
/var/tmp//ccVMU4H6.s:5: Warning: rest of line ignored; first ignored character is `,'
/var/tmp//ccVMU4H6.s:6: Error: expected comma after name `' in .size directive
/var/tmp//ccVMU4H6.s:6: Warning: rest of line ignored; first ignored character is `%'
/var/tmp//ccVMU4H6.s:7: Warning: rest of line ignored; first ignored character is `%'
/var/tmp//ccVMU4H6.s:17: Error: bad register name `%li at NTPOFF(%eax)'

It's probably just the %l and %G prefix, but it makes the use of the
__thread keyword rather pointless at this time.

-- 
 Marcel Moolenaar	  USPA: A-39004		 marcel at xcllnt.net


More information about the freebsd-threads mailing list