This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Shared library and TLS variables


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]