This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Shared library and TLS variables
- From: Bharath Ramesh <bramesh at vt dot edu>
- To: libc-help at sourceware dot org
- Date: Thu, 29 Nov 2012 17:11:39 -0500
- Subject: Shared library and TLS variables
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
#include <stdint.h>
#include <stdio.h>
__thread char foo = 1;
void bar(void)
{
printf("address of foo: %p\n", &foo);
return;
}
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
extern void bar(void);
extern __thread char foo;
int main(int argc, char *argv[])
{
printf("foo: %d\n", foo);
bar();
return EXIT_SUCCESS;
}