write(2) called from within signal handler is flagged as unsafe?

334 views
Skip to first unread message

r...@newrelic.com

unread,
Oct 13, 2014, 5:31:09 PM10/13/14
to thread-s...@googlegroups.com
On linux, in a simple test program, I send myself a signal; which is caught by a signal handler. The signal handler calls write(2).

The tsan runtime (both clang and gcc 4.9.1 build binaries) complains:

WARNING: ThreadSanitizer: signal-unsafe call inside of a signal (pid=26847)
    #0 write <null>:0 (backtrace+0x00000002af4b)
    #1 sigusr1_handler(int) /home/rrh/play.d/tsan/backtrace.cpp:13 (backtrace+0x00000006f04d)
    #2 rtl_sighandler(int) <null>:0 (backtrace+0x00000001c4aa)
    #3 main /home/rrh/play.d/tsan/backtrace.cpp:21 (backtrace+0x00000006f08b)

I'm confused, since the man page for signal
states that write() must be safely callable  from within a signal handler.

Dmitry Vyukov

unread,
Oct 13, 2014, 11:45:07 PM10/13/14
to thread-s...@googlegroups.com
Hi,

Can you show the reproducer?
> --
> You received this message because you are subscribed to the Google Groups
> "thread-sanitizer" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to thread-sanitiz...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

r...@newrelic.com

unread,
Oct 14, 2014, 12:09:07 PM10/14/14
to thread-s...@googlegroups.com
Attached is a small program "backtrace.cpp" that shows the issue.
backtrace.cpp

Dmitry Vyukov

unread,
Oct 15, 2014, 4:27:09 AM10/15/14
to thread-s...@googlegroups.com
Thanks!
I see the bug in tsan now.

Dmitry Vyukov

unread,
Oct 15, 2014, 5:08:39 AM10/15/14
to thread-s...@googlegroups.com
Fixed by http://llvm.org/viewvc/llvm-project?view=revision&revision=219784
I've added the test so that it doesn't break in future.
Thanks again!

r...@newrelic.com

unread,
Oct 15, 2014, 10:28:20 AM10/15/14
to thread-s...@googlegroups.com
I'm happy to help.

How/when does this change percolate out to gcc?

There's a whole bunch of syscalls that are legal from the context of a signal handler.  I'm wondering if any of the others will also have similar problems.

Dmitry Vyukov

unread,
Oct 15, 2014, 10:32:48 AM10/15/14
to thread-s...@googlegroups.com
On Wed, Oct 15, 2014 at 6:28 PM, <r...@newrelic.com> wrote:
> I'm happy to help.
>
> How/when does this change percolate out to gcc?

Do you mean gcc tip or release?
If release, then I guess it will be the next release.


> There's a whole bunch of syscalls that are legal from the context of a
> signal handler. I'm wondering if any of the others will also have similar
> problems.


I"ve fixed a common source of such false positives. All operations on
file descriptors were affected.
I've greped sources for similar issues and did not found any.
Reply all
Reply to author
Forward
0 new messages