This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Choosing the right TLS access model
- From: ludo at gnu dot org (Ludovic Courtès)
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 02 Aug 2007 10:30:39 +0200
- Subject: Choosing the right TLS access model
Hi,
I read parts of Drepper's [0] and Oliva's [1] work on TLS access. From
my understanding, the `initial-exec' model can be used safely when
compiling an executable. However, it's still unclear to me whether/when
it can be used within a shared library.
Section 3 of [0] explains `initial-exec' like this:
A more restrictive optimization is usable if the variables accessed
are known to be in one of the modules available and program start and if
the programmer selects to use the static access model.
I believe it should read "available *at* program start".
Likewise, Section 2.1 of [1] reads:
Under certain circumstances, [the Initial Exec model] may be used in
dynamic libraries as well, but it may come at the cost of being unable
to dlopen such libraries.
This gives the impression that shared libraries that are not meant to be
dlopened can be compiled with `-ftls-model=initial-exec'. Is this true?
If so, would using `-ftls-model=initial-exec' cause problems with the
way the shared library accesses other library's TLS (e.g., libc's
`errno')? IOW, instead of using `-ftls-model', should one instead use
an explicit `tls_model' attribute for all the library's thread-local
variables?
Thanks,
Ludovic.
[0] http://people.redhat.com/drepper/tls.pdf
[1] http://www.lsd.ic.unicamp.br/~oliva/writeups/TLS/paper.pdf