Implementing TLS: step 1
Alexander Kabaev
kabaev at mail.ru
Thu Jun 19 17:58:52 PDT 2003
On Thu, 19 Jun 2003 16:30:42 -0700
Marcel Moolenaar <marcel at xcllnt.net> wrote:
> On Thu, Jun 19, 2003 at 04:03:30PM -0700, Julian Elischer wrote:
> >
> > > The compiler generates access sequences according to the runtime
> > > specification which in general means that all offsets to the TLS
> > > are based on some TLS base address. On ia64 the thread pointer
> > > points to the TLS and serves as the TLS base address. On other
> > > architectures there may be an indirection. This means that on ia64
> > > the lack of TLS still requires us to allocate something for the
> > > thread pointer to point to. On other architectures this may not be
> > > the case.
> > >
> > > A typical access sequence on i386 is:
> > >
> > > 00000000 <x>:
> > > 0: 55 push %ebp
> > > 1: 89 e5 mov %esp,%ebp
> > > 3: 65 a1 00 00 00 00 mov %gs:0x0,%eax
> > > 9: 8b 80 00 00 00 00 mov 0x0(%eax),%eax
> > > f: c9 leave
> > > 10: c3 ret
> >
> > The example you show doesn't have any offset into the TLS,
> > just returning the base address of the dtv, correct?
>
> This is an access sequence for static TLS. There's no DTV in that
> case.
>
Actually, the code looks like this:
mov 0x0(%eax),%eax ;; return DTV address (or null if static)
mov -4(%eax), %eax ;; return first int variable in TLS.
i.e. i386 is using TLS Type II, where variables are addressed using
_negative_ offsets relative to thread pointer (%gs:0).
More information about the freebsd-threads
mailing list