From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 6803938485A7; Thu, 30 Jun 2022 11:31:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6803938485A7 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb] Block SIGTERM in worker threads X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 68514a919ec9a4b04b3b56730e9b070580a0e221 X-Git-Newrev: 6418644b0d09af7d1334cc034a7bf8674c061d6e Message-Id: <20220630113109.6803938485A7@sourceware.org> Date: Thu, 30 Jun 2022 11:31:09 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jun 2022 11:31:09 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6418644b0d09= af7d1334cc034a7bf8674c061d6e commit 6418644b0d09af7d1334cc034a7bf8674c061d6e Author: Tom de Vries Date: Thu Jun 30 13:31:06 2022 +0200 [gdb] Block SIGTERM in worker threads =20 With gdb build with gcc-12 and -fsanitize=3Dthread, and test-case gdb.base/gdb-sigterm.exp, I run into: ... WARNING: ThreadSanitizer: data race (pid=3D9722)^M Write of size 4 at 0x00000325bc68 by thread T1:^M #0 handle_sigterm(int) src/gdb/event-top.c:1211 (gdb+0x8ec01f)^M ... Previous read of size 4 at 0x00000325bc68 by main thread:^M [failed to restore the stack]^M ^M Location is global 'sync_quit_force_run' of size 4 at \ 0x00000325bc68 (gdb+0x325bc68)^M ... SUMMARY: ThreadSanitizer: data race gdb/event-top.c:1211 in \ handle_sigterm(int)^M ... and 3 more data races involving handle_sigterm and locations: - active_ext_lang - quit_flag - heap block of size 40 (XNEW (async_signal_handler) in create_async_signal_handler) =20 This was reported in PR29297. =20 The testcase executes a "kill -TERM $gdb_pid", which generates a process-directed signal. =20 A process-directed signal can be delivered to any thread, and what we s= ee here is the fallout of the signal being delivered to a worker thread ra= ther than the main thread. =20 Fix this by blocking SIGTERM in the worker threads. =20 [ I have not been able to reproduce this after it occurred for the firs= t time, so unfortunately I cannot confirm that the patch fixes the problem. ] =20 Tested on x86_64-linux, with and without -fsanitize=3Dthread. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29297 Diff: --- gdbsupport/block-signals.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gdbsupport/block-signals.h b/gdbsupport/block-signals.h index cf97208c750..4703690a4ec 100644 --- a/gdbsupport/block-signals.h +++ b/gdbsupport/block-signals.h @@ -42,6 +42,7 @@ public: sigaddset (&mask, SIGCHLD); sigaddset (&mask, SIGALRM); sigaddset (&mask, SIGWINCH); + sigaddset (&mask, SIGTERM); gdb_sigmask (SIG_BLOCK, &mask, &m_old_mask); #endif }