From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 73B693858C60 for ; Tue, 30 Jan 2024 01:05:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73B693858C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 73B693858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706576758; cv=none; b=rMV5OjJ8oCmWOdPVUMSwI/UcBu85PffPDc95r5bzguvnvJkg2JkDf7spYsXRVyjsv+AoWZtCByyreSdjerBE66frEm+y3/rpiw9geEJd9+k0srDJUdexj410pRAJdyJ2w3QwvZfOjq5gzLUCVjbrMD+L+NAudZFfraTCbQ0raAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706576758; c=relaxed/simple; bh=MHdIDRIEjVDZeGiA5+9Jt+Tu9+EkbQvUSB7+jdH0NMU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=v9a5FFSRQS8QBp0qr819gB1R2E0QhVMrEWSrGvn1jzmzNU8M5+GFiOk0eA4jG+RbM7ABv9tczrwHgTV+20uQ8+Smx1BF118EED8k41ZFkHTjR0GS15LIPQ4pTR5y5lObj4qwuejKEGRIO814AzAI3kwY8M4a8awXPgeMtrfkdHM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5006a.ext.cloudfilter.net ([10.0.29.179]) by cmsmtp with ESMTPS id UZfgrZ7Q980oiUcZXrcIXx; Tue, 30 Jan 2024 01:05:55 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id UcZWrHbs4im6EUcZWrhn3z; Tue, 30 Jan 2024 01:05:54 +0000 X-Authority-Analysis: v=2.4 cv=Qft1A+Xv c=1 sm=1 tr=0 ts=65b84b72 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=zstS-IiYAAAA:8 a=2K_a2Flm94jQqNAB1B0A:9 a=3ZKOabzyN94A:10 a=4G6NA9xxw8l3yy4pmD5M:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=1ZC5TrxeLLJCKPfZuKlP4yJhSe8UvTZqQ8/Jw2kK8Ns=; b=CRQtR/XqmAsiGjf4FClrCAgz4q Yw+8mx5DRdQrHU62g5ahSdzzQSZwSc1x0w62KIFKjylQukvbpq6i700SFssc25zlZq5bHP0jdJLuH yXFKDelsFuUf94fNAKlgYcd12; Received: from [161.98.8.3] (port=34570 helo=prentzel.ci.boulder.co.us) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rUcZU-003BfD-2z; Mon, 29 Jan 2024 18:05:53 -0700 From: Tom Tromey To: binutils@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] Make several more BFD globals thread-local Date: Mon, 29 Jan 2024 18:03:31 -0700 Message-ID: <20240130010540.1754740-2-tom@tromey.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240130010540.1754740-1-tom@tromey.com> References: <20240130010540.1754740-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 161.98.8.3 X-Source-L: No X-Exim-ID: 1rUcZU-003BfD-2z X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (prentzel.ci.boulder.co.us) [161.98.8.3]:34570 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfGq67COMaN7XWtXTLikeN+hV8ylmxHQHwytmNR32+VMSsTWOn5hcbeDmoqM9KlFr2h9tgqgmmGoyy7WtvyvZXRSpZ/ZH0O3P+evZwCwcbNq4Tb1IbBWq c/w8afIMDyFoNMPPwJDN3qCdCnUMePk/QcbLp/ZV8LF7ikBeH3ahL04m1uLLjKXoAF6jyBUOOHXrLpPQx+Y+OFbGIqHRMXJmzC4= X-Spam-Status: No, score=-3022.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Among other things, PR gdb/31264 points out a race in bfd_check_format -- it sets the error handler, which is a global. Looking into this a bit more, I found several other possible races: the "in_check_format" static local variable in bfd_check_format_matches, and the contents of per_xvec_warn. This patch makes all of these thread-local. I don't actually think this is the best way to approach this. "in_check_format" and the per-xvec warnings could be done by setting a flag on the BFD, avoiding globals entirely. I can do that if you want; I just wasn't sure if that is desirable or not. Note that this bug also points out a race between bfd_cache_close_all and bfd_check_format; I am not sure yet how this should be handled. bfd/ChangeLog 2024-01-29 Tom Tromey PR gdb/31264 * targets.c (per_xvec_warn): Now thread-local. * format.c (bfd_check_format_matches): Mark "in_check_format" as thread-local. * bfd.c (_bfd_error_internal, error_handler_bfd): Now thread-local. --- bfd/ChangeLog | 9 +++++++++ bfd/bfd.c | 4 ++-- bfd/format.c | 2 +- bfd/targets.c | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bfd/bfd.c b/bfd/bfd.c index 0776145af52..5619799e403 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -1504,7 +1504,7 @@ err_sprintf (void *stream, const char *fmt, ...) /* Communicate the bfd processed by bfd_check_format_matches to the error handling function error_handler_sprintf. */ -static bfd *error_handler_bfd; +static TLS bfd *error_handler_bfd; /* An error handler that prints to a string, then dups that string to a per-xvec cache. */ @@ -1538,7 +1538,7 @@ error_handler_sprintf (const char *fmt, va_list ap) function pointer permits a program linked against BFD to intercept the messages and deal with them itself. */ -static bfd_error_handler_type _bfd_error_internal = error_handler_fprintf; +static TLS bfd_error_handler_type _bfd_error_internal = error_handler_fprintf; /* FUNCTION diff --git a/bfd/format.c b/bfd/format.c index 47c3e9ba35a..ec37441904c 100644 --- a/bfd/format.c +++ b/bfd/format.c @@ -321,7 +321,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching) struct bfd_preserve preserve, preserve_match; bfd_cleanup cleanup = NULL; bfd_error_handler_type orig_error_handler; - static int in_check_format; + static TLS int in_check_format; if (matching != NULL) *matching = NULL; diff --git a/bfd/targets.c b/bfd/targets.c index 3addf2fe373..ca2a2039217 100644 --- a/bfd/targets.c +++ b/bfd/targets.c @@ -1458,8 +1458,8 @@ const bfd_target *const *const bfd_associated_vector = _bfd_associated_vector; const size_t _bfd_target_vector_entries = ARRAY_SIZE (_bfd_target_vector); /* A place to stash a warning from _bfd_check_format. */ -static struct per_xvec_message *per_xvec_warn[ARRAY_SIZE (_bfd_target_vector) - + 1]; +static TLS struct per_xvec_message *per_xvec_warn[ARRAY_SIZE (_bfd_target_vector) + + 1]; /* This array maps configuration triplets onto BFD vectors. */ -- 2.43.0