Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Jun 2003 17:05:37 -0400
From:      Alexander Kabaev <ak03@gte.com>
To:        Marcel Moolenaar <marcel@xcllnt.net>
Cc:        threads@freebsd.org
Subject:   Re: TLS: defining the problem space
Message-ID:  <20030620170537.0e03161b.ak03@gte.com>
In-Reply-To: <20030620204314.GA19111@dhcp01.pn.xcllnt.net>
References:  <20030620204314.GA19111@dhcp01.pn.xcllnt.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 20 Jun 2003 13:43:14 -0700
Marcel Moolenaar <marcel@xcllnt.net> wrote:
> 
> Y.  static vs dynamic. This of course refers to the TLS model in use.
>     A process can have both models in use at the same time!, but only
>     if the process belongs to a complete binary (ie: you cannot have
>     the static TLS model in shared executables,

Unless I am missing something, this is not true. One can have static
TLS in a dynamically linked binary as long all all modules using static
access are part of the process startup set of libraries. One cannot
dynamically load shared libraries compiled with static TLS model, but it
is OK to link with them.

>     but you can have the
>     dynamic TLS model in complete executables. The big difference
>     between static and dynamic is the use of __tls_get_addr() to get
>     the virtual address of a thread local variable (or not).

__tls_get_addr() use is a characteristic of the TLS model the module has
compiled in, and not whether or not application is static or dynamic.

> 
> Z.  with pthread vs without pthread. This means whether a threads
>     library (libc_r, libthr or libkse) is present and/or in use. The
>     existence of the __thread keyword does not imply or mean that
>     the process will be multi-threaded. This means that we have to
>     deal with TLS access outside the context of RTLD or pthread. The
>     big difference between pthread and without pthread is the ability
>     to actually have multiple threads.
> 
> Examples of problems we need to solve are:
> o  In a complete executable, without pthread and using dynamic TLS,
>    what defines __tls_get_addr() and how is it defined?

How about weak libc symbol which will be overridden by rtld definotion? 

> o  In a complete executable, without pthread and using static TLS,
>    where is the thread pointer initialized?

There has to be a hook defined in our crt startup files. I have
mentioned this initialization function before.

> Examples of answers we have, but may need to revise:
> o  In a complete executable, with pthread and using static TLS,
>    the thread pointer is defined by the pthread library.
> o  In a complete executable, with pthread and using dynamic TLS,
>    __tls_get_addr() is defined by the pthread library.
> 
> The intend of the posting is to come up with all questions and make
> sure we have them all answered before we do anything else. Note that
> answers may have tricky consequences, such as:
> 
> If pthread defines __tls_get_addr() in complete executables and RTLD
> defines __tls_get_addr() in shared executables, we have duplicate
> definitions for shared executables, with pthread (using dynamic TLS).
> Which takes precedence? [answer: RTLD]

Can __tls_get_addr be included only in a static library. All dynamic
libraries by necessity will have to depend on a declaration provided by
the rtld then. Otherwise a weak symbol trick can be used as described
above. This is no different from a case of libc providing dummy dlfcn.h
stubs today.


> It probably helps to have a authoritative list of questions and
> answers. I can probably create a trivial page somewhere where we list
> it...

Good idea.

-- 
Alexander Kabaev



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030620170537.0e03161b.ak03>