Shared library and TLS variables

Bharath Ramesh bramesh@vt.edu
Thu Nov 29 22:11:00 GMT 2012


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

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

-- 
Bharath
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.c
Type: text/x-csrc
Size: 131 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-help/attachments/20121129/e31cb4e3/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 206 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-help/attachments/20121129/e31cb4e3/attachment-0001.bin>


More information about the Libc-help mailing list