From patchwork Tue Jan 30 01:03:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 193763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp928000dyb; Mon, 29 Jan 2024 17:06:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGK2GJs0BtDxiqYsfNYSoGNHKN4JzvIpodZIRluT+bCIamsrdYdKRUe89V43p2BbVly6N9c X-Received: by 2002:a05:6102:4414:b0:46b:8824:bb88 with SMTP id df20-20020a056102441400b0046b8824bb88mr934726vsb.26.1706576769186; Mon, 29 Jan 2024 17:06:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706576769; cv=pass; d=google.com; s=arc-20160816; b=nUUzQK6e38zOL+T2nwCOomRzQ+yDqRHIpDUlpAxijHo8tt9C/oSB9LRzfa7NsAPgV4 hmfpfkjk25VbgtQKPdGb8tNRdtEU2mVxfId+FYfxO8BCGMCqDICbXLuSS6czMXWeWp+5 pzulyJ/85jeXbDzIkG8K1qX5EEXYtJFsesAcrmNBYhYXBmX1Fkg7+32WKOGtxvrmAmLN q0D7HncTpqOXOOtqjNnlW+zKnSAWev4SE9DKSHsJ7oqM6leAWnw5Cp3Q4G197ctw97Ov MMgeoX+7Mfyr2tNSbyC964TTU8bFLLBcCG19Y29nMaWyzCagepOOAHGEk/JgR20CeGZq nD1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=1ZC5TrxeLLJCKPfZuKlP4yJhSe8UvTZqQ8/Jw2kK8Ns=; fh=PTZv/fEnntkVjZjJeDKIkUWVkECXkQyaIllNGCyO/VM=; b=dUAEG359Pc8WR0xTi9QpyahRZb5eB0qH1KHknmjqpaFL+0Xhz8jzfztYqkq1kVUaz0 3J6vpRfwwKNWlnbT38zaHLhCwJb6MIddx/fUrKUXsSjXhwbT7RRp9oMIwSIzd6EGOTjj Y5vv1VpTIBqI0TTGbz3/Yitf0cxdYtKZPlydin5Bsh7UoXaxZPMGHo86gO8y2Cvtjjik KCV+irwd42/gGZyPOtvhei4fBHV7dV3x1qAo5ssOp6z0kSxhg1XD8X4ecX68YevJPOj2 JCazr1h+mJQG5mwgFzcQbPEmRHu/kNGHKdL2PwM9au6bg7w8xNjQeNzKVvOm6V/pd3Af ig9w== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@tromey.com header.s=default header.b="CRQtR/Xq"; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b18-20020a05620a04f200b0078403334a6fsi2186386qkh.733.2024.01.29.17.06.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 17:06:09 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@tromey.com header.s=default header.b="CRQtR/Xq"; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E0AC5385841E for ; Tue, 30 Jan 2024 01:06:08 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789475442613165119 X-GMAIL-MSGID: 1789475442613165119 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. */ From patchwork Tue Jan 30 01:03:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 193764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp928047dyb; Mon, 29 Jan 2024 17:06:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtobRRsh2ENjfEAwJxPezSHWWWINCTp6I9Srd8WMQYn9xY5E6uGAldjCyx89yGdG01fWip X-Received: by 2002:a05:6214:f6e:b0:686:949c:1dc1 with SMTP id iy14-20020a0562140f6e00b00686949c1dc1mr8879624qvb.10.1706576777501; Mon, 29 Jan 2024 17:06:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706576777; cv=pass; d=google.com; s=arc-20160816; b=MKAavxDiC+Lfg4rH4jbOEOZksW3I17HkCJl0jSvl2PitDXFqG6U2v+xPyXeRPy177z V+qUtTunnVAWH8mgAWHuj5S7MoAH39OYXb3Tgu10TaqZ7sjuypyQYFn6CMFLyk9wm17G kf6prlG5gC23rvVmlvoDu7TFqedn076BeFxJF2Q8LP0L/obKOeJGVSmGLpvOUC+6/hoo +GRW5W/ZEMLP5L0SwXKtt9jPSLgkZizxQOPKqL2s/VW0kf6ox5593Ts0GXwViqEZWKya O8rcgvuzG46pdfZPx+NsOX6nSVUyT7Q9rk8bG/Mt9ae9mG6k8vuD98l6Dar1hU3G6djW DD/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=qx6vopRJoDKNq6ezWFrWQyQn0sf0vz8stbVKgNDdT+M=; fh=PTZv/fEnntkVjZjJeDKIkUWVkECXkQyaIllNGCyO/VM=; b=w+6teqd1KWqdEnM7g/3YXWko3Q60fLnZxxpCcybaISISb9YRpDKh8Wkazd/2OM9x6c fgVS4LTtAmFDOUp8TioiP8F9AOqYeNFxgxEQzojlvgGHW5A2n4tB7Url4xRXHVP0544F mDQQiZKCtVYURipASW+PUrGo/GVEG2KkH0ixbsCoNzcRVDf31+u0DZHyoui0YQCM3Yj5 /ualYD9iLV0I/4gkejFxNRM/u+dLJUE8vj+XSsVuGMM6yy/9PuQDL+ur4kP69iupUehz xtgf/Vj1Q/bjnHyKItP5od8SpaVdNSz+RAL+r8YKYuJZ0vCvY6Gsl1dPYlG6Ex+2jqmC kenQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@tromey.com header.s=default header.b=p5ujkqp+; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c6-20020a05620a164600b00783e000b202si7407279qko.345.2024.01.29.17.06.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 17:06:17 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=fail header.i=@tromey.com header.s=default header.b=p5ujkqp+; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 261503858437 for ; Tue, 30 Jan 2024 01:06:17 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id 0458A3858413 for ; Tue, 30 Jan 2024 01:05:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0458A3858413 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 0458A3858413 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706576759; cv=none; b=JkFIvWFh9GH779lAzdvuhRooX5t1Ac3/Y4dkkweLHHj60C/MR4ar7QSpoLWncq9KP/hxIxIsQ9XbMVN9yuYqqR5ZRduQD/UyOLKPOJ/B68LnK/WBAZG8QifIQ6KsWOF1fQwuDzZWmmPB5XvBvCAkefNiddMp63onJoB6F725/10= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706576759; c=relaxed/simple; bh=k4jdhGEHiUz93z4ZBn0h73zUIBko/DfsTchrNF1vVrU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GFD2YILXcO5gIe3yRfTOII52fHm5Sey/vZqd2qL7VVDEJAsamWgw4ULpRPNF32otrcUCr42uGU0hGzqT0o9HwH+bh9vndqZrKFBMM5JmbIEcK3LtBeT67E/hhH+EEAtZ2UVwujYW3tRz+RaB0MPqTkXc/LCNvcoPdWaQN9N4G44= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6009a.ext.cloudfilter.net ([10.0.30.184]) by cmsmtp with ESMTPS id UcQNrMQ0BMVQiUcZYrqVxT; Tue, 30 Jan 2024 01:05:56 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id UcZXrZLBUjqQkUcZXrFQoE; Tue, 30 Jan 2024 01:05:55 +0000 X-Authority-Analysis: v=2.4 cv=A7F/goaG c=1 sm=1 tr=0 ts=65b84b73 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=zstS-IiYAAAA:8 a=4HCetuFXo1Zvk4fGk-gA:9 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=qx6vopRJoDKNq6ezWFrWQyQn0sf0vz8stbVKgNDdT+M=; b=p5ujkqp+3oGWUan17SskihwufO 3zPdeCxVJUpKsbJI19Hw5bh7PK4mCyoTRR5HcVJMYLPeiAI8uYm2H99vp8V7wr0urPjXfehckLK9D brd6ckcybPK1AQbTv1HlUDwEz; 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 1rUcZW-003BfD-0S; Mon, 29 Jan 2024 18:05:54 -0700 From: Tom Tromey To: binutils@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/3] Do not call fputc from _bfd_doprnt Date: Mon, 29 Jan 2024 18:03:32 -0700 Message-ID: <20240130010540.1754740-3-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 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: 1rUcZW-003BfD-0S 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: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfEhUxVQ2xZ89/SVaoVLHhhucUboiOTmi8v8dRSeGzn02ss1bqCJxurOQj8DFHMF2jUAnv3VyFI1pFA49ZIF92MI31Lxx8UKNIE6LCy6p1FIZ79ykcvYA HWl+Bb+mqRy2LgkIBtkc71+AaR4TXveP+0OvjLjnaTU6QJkbqSRAVTmZag3HQVAM0nnTKMIe9SeFMs2lsZgl1X42onCwHioydao= 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789475451187113001 X-GMAIL-MSGID: 1789475451187113001 I noticed that _bfd_doprnt can unconditionally call fputc. However, when called from error_handler_sprintf, this will likely result in a crash, as the stream argument does not actually point to a FILE. bfd/ChangeLog 2024-01-29 Tom Tromey * bfd.c (_bfd_doprnt): Do not call fputc. --- bfd/ChangeLog | 4 ++++ bfd/bfd.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bfd/bfd.c b/bfd/bfd.c index 5619799e403..0f1eaa1629f 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -1027,7 +1027,7 @@ _bfd_doprnt (print_func print, void *stream, const char *format, } else if (ptr[1] == '%') { - fputc ('%', stream); + print (stream, "%%"); result = 1; ptr += 2; } From patchwork Tue Jan 30 01:03:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 193765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp928723dyb; Mon, 29 Jan 2024 17:07:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IH13Xu+Ny8gYoHvvbGhE8hz4f49ham9JIsAsXVF8y5xq7MYiVXxCBJyfCY4e9p1SPGNP5w3 X-Received: by 2002:a05:622a:58d:b0:42a:5ef4:33d3 with SMTP id c13-20020a05622a058d00b0042a5ef433d3mr8842677qtb.60.1706576867472; Mon, 29 Jan 2024 17:07:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706576867; cv=pass; d=google.com; s=arc-20160816; b=WK0EY461dF5qNBH/ejklAfn9ERR3LSLukGSLrKbYeEIV0NQ+b8vmH/4PHy9TL+dxLx Ue6tdwN5n8K+PK2RmJ1PgEw647vGx34fo04klOdMfAEQD/ulKJnLbrnVFvL6KRU2nrxC P3f/xi0ul6cfbUCpPvG1/Vsjzk+IcRnUfcecK0hAnwCNqktazc/NnjXhyXGBMAXpHf8f vZWee1fvpZdpgI4IZbxcc2RhU/ORoYFux3iLvnGG4i9ESYRcAp33fWcZZowDWN9KgR3s CVWjWvRldKFdhuZxuUJ9LW2GoM5zwtOWp9FpyqhBnXKY2yTWatU+NwGQXi8r5p6MtFVj iliQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=Dxg+HTBHDbIWnOdODk9TjpmAWVxXIcIIsm8bC2WpLMk=; fh=PTZv/fEnntkVjZjJeDKIkUWVkECXkQyaIllNGCyO/VM=; b=ICN/Cyo6LBY+JsA+d3s4J3Vvd6VI48l0YiGJ6B+yxWa1Ay3ItTb7efpDgqtO5ydtZD jZhPvaLlEMsQOm/ODPvKPk7BtBKoADBzGct7/McHNFH7aaZd1c0IYZ85MgByJwXIqkBb 5/6yxITS0UE0AMA26WbC+Bm7AnevUSzI8gBJPesGO78YKClqNqmnrqkVx+in4vFB4zR0 i9jfaRKiKi5N31LUcKvs5brEtkwAq7wDsQYomjLbE2IvW3TbXIH62SrGLFkkpFYT7oah ThKqv805FxKoE6c7mBXnrcV8umz8jy190OWRNi5FtwoI6J8u6ww9kxQrm9Fic792CX/N n1Cg== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@tromey.com header.s=default header.b=wDob1uFt; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bp35-20020a05622a1ba300b00429a16bf24asi8801670qtb.743.2024.01.29.17.07.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 17:07:47 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@tromey.com header.s=default header.b=wDob1uFt; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B44A385842F for ; Tue, 30 Jan 2024 01:07:47 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id 11E05385828D for ; Tue, 30 Jan 2024 01:06:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11E05385828D 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 11E05385828D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706576767; cv=none; b=AmhOkV9kv1wggUrB3s8P9fGr7Oc9zhGEnMETvFn/QkXYfSMAoG3JA5xeF6l2uabE9PIascgm/MlN6qH5r5UgOnlHu5Gy1B2EvPzAjd91IJGSj9EVhi0wTCE9OTWX6BxC04KO5QAoqH4v0+tK0P9Kjn3XD1R+K79jBdX1jn53X9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706576767; c=relaxed/simple; bh=VV/B0IDmYnVhNBI5bRVt4D+4Muy7v+xRShIfrjLEUew=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OeSPi4l+/ySczmjY4Dp3QbJjRreSQYKr7gLVE+xj6gIV00DPe1ieBPFG4Pwbiw/fSvgRHb+HIV36GDFSa32VmNyG+EEPCNL0BfQLWGJ3SemslPZslphO/mKfF5HpyStqVcuKjs4Gub8egHWi97w0f/L3AhIE0DvaZwCRdpcYK0I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5004a.ext.cloudfilter.net ([10.0.29.221]) by cmsmtp with ESMTPS id UaoSrQvg8THHuUcZgrlRDr; Tue, 30 Jan 2024 01:06:04 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id UcZfrZyihKleDUcZgre8Vz; Tue, 30 Jan 2024 01:06:04 +0000 X-Authority-Analysis: v=2.4 cv=KcbBDCUD c=1 sm=1 tr=0 ts=65b84b7c a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=zstS-IiYAAAA:8 a=OXhtBIGw6S4pdDCVDrwA:9 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=Dxg+HTBHDbIWnOdODk9TjpmAWVxXIcIIsm8bC2WpLMk=; b=wDob1uFtYG8vsvufD/e16K3Zrp 9HcYbl1i0zTkwQ4h+vmjwGM8vYxdFOgxQjk3M8Zw/ISduWsKC9cssyiGI+oG3VBSUii9NRbK1sZfJ 7R3g7eZAzp+/05CTLT2hKL5ul; 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 1rUcZX-003BfD-2E; Mon, 29 Jan 2024 18:06:03 -0700 From: Tom Tromey To: binutils@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/3] Introduce bfd_print_error function Date: Mon, 29 Jan 2024 18:03:33 -0700 Message-ID: <20240130010540.1754740-4-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 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: 1rUcZX-003BfD-2E 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: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfGMs/98PeYvmpUDFY5Bp3T0i2zR2AZ9O8u8k5t1HfAF0+rGgA51e4yRQYK+5Ba5tER4vCqYghSNh8oIx3Dh+5+XMhUqdFTHkE8MopLPWAmuV8SRURhh6 EKaEhqFQ5XrA0HiJpfywNirIBOJZAzOTUgQkYcDEYFzMUKo1QPAfmLtNe6caobOde4gPzlQ6Noya7vX2IXrtX4ne3FbFtFbhrgU= 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_DNSWL_NONE, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789475545575073469 X-GMAIL-MSGID: 1789475545575073469 gdb likes to control its own output; for example, this is important for gdb's pager, and for logging. While BFD provides a way to intercept error output, via bfd_set_error_handler, it turns out to be difficult for this function to truly generate the desired output in a gdb-friendly way -- the error handler is expected to implement some BFD printf format extensions. This patch introduces a new function that an error handler can use to format the text. This way, gdb can set the error handler and arrange for the output to be displayed as it likes. bfd/ChangeLog 2024-01-29 Tom Tromey * bfd.c (bfd_print_callback): Rename from print_func. Move into comment. (_bfd_doprnt): Update. (bfd_print_error): New function. (error_handler_fprintf, error_handler_sprintf): Use bfd_print_error. * bfd-in2.h: Rebuild. --- bfd/ChangeLog | 10 ++++++++++ bfd/bfd-in2.h | 4 ++++ bfd/bfd.c | 48 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 581d8fe0b3e..e8b0e9f8699 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -2557,6 +2557,10 @@ void bfd_perror (const char *message); typedef void (*bfd_error_handler_type) (const char *, va_list); +typedef int (*bfd_print_callback) (void *, const char *, ...); +void bfd_print_error (bfd_print_callback print_func, + void *stream, const char *fmt, va_list ap); + void _bfd_error_handler (const char *fmt, ...) ATTRIBUTE_PRINTF_1; bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type); diff --git a/bfd/bfd.c b/bfd/bfd.c index 0f1eaa1629f..886a97ce078 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -1000,10 +1000,13 @@ union _bfd_doprnt_args result = print (stream, specifier, value); \ } while (0) -typedef int (*print_func) (void *, const char *, ...); +/* +CODE_FRAGMENT +.typedef int (*bfd_print_callback) (void *, const char *, ...); +*/ static int -_bfd_doprnt (print_func print, void *stream, const char *format, +_bfd_doprnt (bfd_print_callback print, void *stream, const char *format, union _bfd_doprnt_args *args) { const char *ptr = format; @@ -1446,21 +1449,44 @@ _bfd_doprnt_scan (const char *format, va_list ap, union _bfd_doprnt_args *args) return arg_count; } -/* The standard error handler that prints to stderr. */ +/* +FUNCTION + bfd_print_error -static void -error_handler_fprintf (const char *fmt, va_list ap) +SYNOPSIS + void bfd_print_error (bfd_print_callback print_func, + void *stream, const char *fmt, va_list ap); + +DESCRIPTION + + This formats FMT and AP according to BFD "printf" rules, + sending the output to STREAM by repeated calls to PRINT_FUNC. + PRINT_FUNC is a printf-like function; it does not need to + implement the BFD printf format extensions. This can be used + in a callback that is set via bfd_set_error_handler to turn + the error into ordinary output. +*/ + +void +bfd_print_error (bfd_print_callback print_func, void *stream, + const char *fmt, va_list ap) { union _bfd_doprnt_args args[MAX_ARGS]; + print_func (stream, "%s: ", _bfd_get_error_program_name ()); _bfd_doprnt_scan (fmt, ap, args); + _bfd_doprnt (print_func, stream, fmt, args); +} +/* The standard error handler that prints to stderr. */ + +static void +error_handler_fprintf (const char *fmt, va_list ap) +{ /* PR 4992: Don't interrupt output being sent to stdout. */ fflush (stdout); - fprintf (stderr, "%s: ", _bfd_get_error_program_name ()); - - _bfd_doprnt ((print_func) fprintf, stderr, fmt, args); + bfd_print_error ((bfd_print_callback) fprintf, stderr, fmt, ap); /* On AIX, putc is implemented as a macro that triggers a -Wunused-value warning, so use the fputc function to avoid it. */ @@ -1512,15 +1538,13 @@ static TLS bfd *error_handler_bfd; static void error_handler_sprintf (const char *fmt, va_list ap) { - union _bfd_doprnt_args args[MAX_ARGS]; char error_buf[1024]; struct buf_stream error_stream; - _bfd_doprnt_scan (fmt, ap, args); - error_stream.ptr = error_buf; error_stream.left = sizeof (error_buf); - _bfd_doprnt (err_sprintf, &error_stream, fmt, args); + + bfd_print_error (err_sprintf, &error_stream, fmt, ap); size_t len = error_stream.ptr - error_buf; struct per_xvec_message **warn