Discussion:
Issues with accessing TLS of shared object
Bill Fischofer
2016-05-17 20:58:32 UTC
Permalink
This may be a better question for the linaro tools group. +cc their list
for the general question of conventions surrounding how shared library
objects identify and access thread-local storage that they need as part of
calling threads.
Hi All,
I am trying to write a shared library object over ODP. Our ODP library has
some per thread variables. When my application invokes an API of shared
object which accesses per thread variable it gives segmentation fault.
My concern is that when a shared object is loaded dynamically, how memory
is assigned to thread specific variables defined inside shared objects.
AFAIK we need to compile it with -ftls-model=global-dynamic, which is
enabled by default when compiled with -fPIC flag, and library loader
takes care for these issues.
I am not an expert in this area, please help me in getting to some
suitable reference pointers or some steps I might have missed.
Thanks in advance
Nikhil
Kugan Vivekanandarajah
2016-05-17 23:30:06 UTC
Permalink
Hi,
I am trying to write a shared library object over ODP. Our ODP library has
some per thread variables. When my application invokes an API of shared
object which accesses per thread variable it gives segmentation fault.
If you think that there is a bug in the toolchain, please file a bug
in bugs.linaro.org with minimal set of sample code and
compiler/toolchain option to reproduce this.
My concern is that when a shared object is loaded dynamically, how memory
is assigned to thread specific variables defined inside shared objects.
AFAIK we need to compile it with -ftls-model=global-dynamic, which is
enabled by default when compiled with -fPIC flag, and library loader takes
care for these issues.
I am not an expert in this area, please help me in getting to some
suitable reference pointers or some steps I might have missed.
Ian has written a nice blog post about this at:
http://www.airs.com/blog/archives/44

Thanks,
Kugan
Peter Smith
2016-05-18 08:58:12 UTC
Permalink
Hello Nikhil,

Just to add some more references you might like to check out, although
be warned they are not easy to digest. They do go into how the memory
for thread local storage is allocated so you may be able to skip
through the details.

There shouldn't be anything special that you need to do to make this
work on the command line. The global-dynamic model is the most general
and can cope with libraries that are dynamically loaded via dlopen.
The static linker is able to perform relaxations when it can detect
that the full generality of global-dynamic is not needed.

It is difficult to know whether your program has segfaulted due to the
program loader not allocating memory for the thread local storage
block, or for the toolchain to have miscompiled code to access the
memory. As Kugan suggests you'll need to provide some kind of
reproducer before we'll be able to help.

Hope this is of some help

Peter

References:
For 32-bit ARM the Addenda to the ABI for the ARM Architecture has a
good introduction to how the traditional model of TLS model works.
This is available at:
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0045e/IHI0045E_ABI_addenda.pdf

Since that document was published an alternative descriptor model of
TLS has been adopted. This is less formally documented, the best
reference I have found are:
http://sourcery.mentor.com/public/publications/RFC-TLSDESC-ARM.txt for
ARM details and
http://www.fsfla.org/~lxoliva/writeups/TLS/paper-lk2006.pdf for a
general overview.

There is very little public information about the details of the
AARCH64 TLS although it differs from ARM only in the low-level details
such as the instructions used.
Post by Bill Fischofer
This may be a better question for the linaro tools group. +cc their list
for the general question of conventions surrounding how shared library
objects identify and access thread-local storage that they need as part of
calling threads.
Hi All,
I am trying to write a shared library object over ODP. Our ODP library has
some per thread variables. When my application invokes an API of shared
object which accesses per thread variable it gives segmentation fault.
My concern is that when a shared object is loaded dynamically, how memory
is assigned to thread specific variables defined inside shared objects.
AFAIK we need to compile it with -ftls-model=global-dynamic, which is
enabled by default when compiled with -fPIC flag, and library loader takes
care for these issues.
I am not an expert in this area, please help me in getting to some
suitable reference pointers or some steps I might have missed.
Thanks in advance
Nikhil
_______________________________________________
linaro-toolchain mailing list
https://lists.linaro.org/mailman/listinfo/linaro-toolchain
Loading...