This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Shared library and TLS variables
- From: Maxim Kuvyrkov <maxim at codesourcery dot com>
- To: Bharath Ramesh <bramesh at vt dot edu>
- Cc: <libc-help at sourceware dot org>
- Date: Fri, 30 Nov 2012 11:22:41 +1300
- Subject: Re: Shared library and TLS variables
- References: <20121129221139.GF3115@vt.edu>
On 30/11/2012, at 11:11 AM, Bharath Ramesh wrote:
> I am wondering if there is any minimal size that is required for
> TLS when variables are declared in a shared library. I am having
> an issue when I declare a single TLS variable of type char. I
> access this variable from my application. When I run a simple
> test case I am able to reproduce this behavior. There is an issue
> during the allocation of the static TLS block when the shared
> library is being loaded. If I change the type of the variable
> from char to int it works as expected. I am attaching the
> associated test code along with this email.
>
> libfoo is compiled as follows:
>
> gcc -Wall -Wextra -fPIC -shared -o libfoo.so foo.c
I have a vague memory that adding -lpthread to the library link line may fix this problem. There is something in libpthread that TLS depends on, but the dependency is silently ignored if none of the library or the application actually uses threads.
>
> test is compiled as follows:
>
> gcc -Wall -Wextra -Wl,-rpath . -o test test.c -L . -lfoo
>
> When I execute it I get the following error:
>
> $ ./test
> ./test: error while loading shared libraries: ./libfoo.so: cannot allocate memory in static TLS block
--
Maxim Kuvyrkov
CodeSourcery / Mentor Graphics