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 Fri, Nov 30, 2012 at 11:22:41AM +1300, Maxim Kuvyrkov wrote:
> 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.
> 

I tried adding -lpthread while creating the shared library and
while linking the binary. I end up with the same error. If I add
the tls variable to the application code and not link it with the
shared library everything works fine without adding -lpthread. I
am not sure what I am doing wrong which is causing this specific
issue.

-- 
Bharath


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