This is the mail archive of the libc-alpha@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: Async-signal-safe access to __thread variables from dlopen()ed libraries?


On Fri, Sep 20, 2013 at 2:28 PM, Ian Lance Taylor <iant@google.com> wrote:
>
> I don't think you characterized the problem precisely.  The issue is
> not receiving a signal while the thread is initializing TLS.  The
> general issue is that calling __tls_get_addr can call malloc, which is
> not async-signal-safe.  A specific example would be
>
> * There is an existing thread.
> * The program does a dlopen of a shared library that uses TLS.
> * The shared library installs a signal handler that refers to a TLS variable.
> * The signal handler is called on the existing thread.
> * Because shared library TLS variables are installed lazily, the
>   existing thread does not yet have a copy of the TLS variable.
> * Therefore the signal handlers TLS reference calls malloc.
> * If the signal occurred during a call to malloc, we have a deadlock.


I should add that in the most likely scenario the signal in question
is SIGPROF.  That is, there is a shared library that wants to do
profiling.  And so both the fact of catching the signal on an existing
thread and catching the signal during malloc are reasonably likely.

Ian


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