This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Async-signal-safe access to __thread variables from dlopen()ed libraries?
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: Paul Pluzhnikov <ppluzhnikov at google dot com>, Roland McGrath <roland at hack dot frob dot com>, Richard Henderson <rth at twiddle dot net>, GNU C Library <libc-alpha at sourceware dot org>, Andrew Hunter <ahh at google dot com>, Alexandre Oliva <aoliva at redhat dot com>
- Date: Fri, 20 Sep 2013 13:41:37 -0400
- Subject: Re: Async-signal-safe access to __thread variables from dlopen()ed libraries?
- Authentication-results: sourceware.org; auth=none
- References: <20120612193224 dot 8E43619060E at elbrus2 dot mtv dot corp dot google dot com> <4FD8D974 dot 7090903 at twiddle dot net> <20120613182826 dot 0CFAB2C0A3 at topped-with-meat dot com> <CALoOobMtXCw+oe7ZL0=my8YH5st8b1==CasS8i07z6G9DfaX-w at mail dot gmail dot com> <20120613210444 dot 659732C095 at topped-with-meat dot com> <mcr4nqebzok dot fsf at dhcp-172-18-216-180 dot mtv dot corp dot google dot com> <20120614002931 dot ABB762C08B at topped-with-meat dot com> <mcr1uliaeep dot fsf at dhcp-172-18-216-180 dot mtv dot corp dot google dot com> <CALoOobPJ7G7ciRfc2JwzHjsDTg4-_h-SXqeU1zR4WEzoyQhyNg at mail dot gmail dot com> <523BD470 dot 6090203 at redhat dot com> <CAKOQZ8y85QBkd97cEEmP-4OgE2KizCqknrVR_n44pwBGMs5uAw at mail dot gmail dot com>
On 09/20/2013 10:25 AM, Ian Lance Taylor wrote:
> Clearly it is technically infeasible to use some features from a
> signal handler. I'm not going to waste time suggesting that it be
> possible to call malloc from a signal handler. However, making it
> safe to use __thread variables in a signal handler is not technically
> infeasible. If we fail to support it, we're just being lazy.
Good programmers are both lazy *and* dumb.
Being lazy and dumb I don't want to maintain a complex TLS
implementation, and being dumb means I can't.
Therefore to overcome my lazy dumbness I suggest the following:
* Discuss some alternative solutions to the problem at hand
and why they were rejected.
* Discuss the ISO C11 implications.
ISO C11 wording in 7.14.1.1 p5:
~~~
If the signal occurs other than as the result of calling
the abort or raise function, the behavior is undefined if
the signal handler refers to any object with static or
thread storage duration that is not a lock-free atomic
object other than by assigning a value to an object
declared as volatile sig_atomic_t, or the signal handler
calls any function in the standard library other than
the abort function, the _Exit function, the quick_exit
function, or the signal function with the first argument
equal to the signal number corresponding to the signal
that caused the invocation of the handler. Furthermore,
if such a call to the signal function results in a
SIG_ERR return, the value of errno is indeterminate.252)
~~~
Will our TLS variables become lock-free atomic objects?
* Post the patches for an implementation and allow time
for upstream review and testing on various architectures.
* Provide detailed performance implications of the patches.
Preference is to have some data that shows that standard
uses of TLS are not negatively impacted.
* Provide changes to the manual to explain that accessing
thread local storage is now async-signal safe and
will be going forward.
* Consider providing some way to assure that old programs
using TLS in a signal handler fail safe. If it can't
be assured, explain why not.
* Similarly provide symbol versioning to prevent a new
program from being run on an old glibc that doesn't
provide AS-safe TLS vars.
* Provide proof that another arriving signal that interrupts
the dynamic TLS setup won't cause the setup to fail.
* Provide proof that another thread calling fork that
interrupts the dynamic TLS setup won't cause the setup to
fail (similar to re-entrancy requirement, but should be
considered separately).
* Provide proof that an asynchronous cancellation of
the thread in the singal handler doing the dynamic TLS
setup won't cause the setup to fail (again similar to
re-entrancy ...).
* Work with the community to ensure consensus around an
acceptable solution.
Please don't misinterpret my request as throwing up a road-block
to this work. I would like to see a high quality implementation
of TLS variables that supports use in signal handlers, but I do
not want to see it impact existing uses, or provide only half
of what is required.
And do not doubt that I am lazy and dumb :-)
Cheers,
Carlos.