From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id 95E033858D20 for ; Tue, 13 Feb 2024 01:20:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95E033858D20 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 95E033858D20 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=1707787211; cv=none; b=j2dF6llSyKPmDoiFVHKo6q3Kc/9h12FIIDqS4P25N83zcAeRzTb7GSllSAMbbHuleJHiS8iG3+PuaBPMQV38kR3v8rmkiPDVlQaAgHQJhK3HHeV8L5houTlKlhgCVEOORV3icD7WcIox+g/+59pvqLdXfztcRYCWkxYI2csDd3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707787211; c=relaxed/simple; bh=Bc4jfXvz6+nLzr+56gN4nmOmcSYcDIUww9VVaiE2LS8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=T3qd0/5Za0eCacJLREsfPsByWL5Zkg3HSpUh3sIf+mbjtcHMt8TWha47xVA4eN+44vTD7pLU70RapVvhZKT8YCHYjxqSw/mpaoycnw8kUiDuYn1o0D5JYPgd6NSs7SMduk5QaJJewSvjxE7yigBHxYtRtPJFOz8GJ/kXrgn+PvU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5008a.ext.cloudfilter.net ([10.0.29.246]) by cmsmtp with ESMTPS id Zac2rfrykTHHuZhSvrvkbY; Tue, 13 Feb 2024 01:20:05 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id ZhSurdx4Ib248ZhSvrn8rD; Tue, 13 Feb 2024 01:20:05 +0000 X-Authority-Analysis: v=2.4 cv=CK+JXgrD c=1 sm=1 tr=0 ts=65cac3c5 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=k7vzHIieQBIA:10 a=Qbun_eYptAEA:10 a=4dFnyDhqQ3D9fg3u0BUA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: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=ZexcX5uPFwPUnVCGaJYBsggvBESjS9k9ClMcsb0Ure4=; b=bpRKefK7a7i5DLAGmdLYQSf6NM Re6PXnvi2a4R9ic+Apynr7XChjMQptKnBFLZWmjqmqulFFb+jM33UwBmqXG2bvQucWShQN8hewfS+ PkqbxrHbp1noYvqXubI8p3jNq; Received: from [161.98.8.3] (port=58844 helo=prentzel) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rZhSu-003beR-1J; Mon, 12 Feb 2024 18:20:04 -0700 From: Tom Tromey To: Tom Tromey Cc: Nick Clifton , binutils@sourceware.org Subject: Re: [PATCH 1/3] Make several more BFD globals thread-local References: <20240130010540.1754740-1-tom@tromey.com> <20240130010540.1754740-2-tom@tromey.com> <87sf1xjj62.fsf@tromey.com> X-Attribution: Tom Date: Mon, 12 Feb 2024 18:20:02 -0700 In-Reply-To: <87sf1xjj62.fsf@tromey.com> (Tom Tromey's message of "Mon, 12 Feb 2024 17:35:01 -0700") Message-ID: <87bk8ljh31.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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: 1rZhSu-003beR-1J X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (prentzel) [161.98.8.3]:58844 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfL4OfS/OqK45BcMtH5gUh1DOcGt37qn23/f/KFeOLBLtEnCTJMu4TI4uWYRLWWlHhjqkS1KPQCiiWE5TCDQ9GVj4wbrN3cI5ExOcVrrRle/Eq41MYCdl 6i3gdeMx5BpOE3pxOvyJPDVFm2xwaZedCX4dtTFCO3KrRzUqTGusgY6NFbdjo6ls6p1Ze7db8iMWS5rCILKykoLShxEmOkH6UK8= X-Spam-Status: No, score=-3022.1 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 List-Id: Tom> What I meant when I wrote the above is that basically there are two sets Tom> of globals to consider in this patch: the ones related to error emission Tom> (_bfd_error_internal and error_handler_bfd), and then the other ones Tom> related to the caching error message code (per_xvec_warn, Tom> in_check_format). Tom> I thought that making the latter ones thread-local felt hackish, because Tom> they could somewhat easily be attributes of a BFD and not globals at Tom> all. I took a stab at some of this tonight and discovered that since in_check_format is only used by the error-reporting code, it can be combined with the other flag. I've appended a rough draft of this. I haven't tackled the xvec stuff yet. Also I think it'd be good if print_warnmsg re-emitted the errors using _bfd_error_handler. This would let gdb print them the way it likes. However... that's a change to semantics so I don't know if that's OK or whether another error emitter is required. I guess I don't really know how to provoke one of these messages and when they would matter. Like, I see that ldmain.c installs an error handler -- is it intentional that this be bypassed by errors occurring in bfd_check_format_matches? thanks, Tom diff --git a/bfd/bfd.c b/bfd/bfd.c index 6c822656cc8..238aa71b4c5 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -1528,9 +1528,15 @@ err_sprintf (void *stream, const char *fmt, ...) } /* Communicate the bfd processed by bfd_check_format_matches to the - error handling function error_handler_sprintf. */ + error handling function error_handler_sprintf. When non-NULL, + _bfd_error_handler will call error_handler_sprintf; when NULL, + _bfd_error_internal will be used instead. */ -static bfd *error_handler_bfd; +static TLS bfd *error_handler_bfd; + +/* A special value for error_handler_bfd that indicates that the error + should simply be ignored. */ +#define IGNORE_ERROR_BFD ((bfd *) -1) /* An error handler that prints to a string, then dups that string to a per-xvec cache. */ @@ -1590,7 +1596,14 @@ _bfd_error_handler (const char *fmt, ...) va_list ap; va_start (ap, fmt); - _bfd_error_internal (fmt, ap); + if (error_handler_bfd == IGNORE_ERROR_BFD) + { + /* Nothing. */ + } + else if (error_handler_bfd != NULL) + error_handler_sprintf (fmt, ap); + else + _bfd_error_internal (fmt, ap); va_end (ap); } @@ -1621,18 +1634,42 @@ INTERNAL_FUNCTION _bfd_set_error_handler_caching SYNOPSIS - bfd_error_handler_type _bfd_set_error_handler_caching (bfd *); + bfd *_bfd_set_error_handler_caching (bfd *); DESCRIPTION Set the BFD error handler function to one that stores messages - to the per_xvec_warn array. Returns the previous function. + to the per_xvec_warn array. Returns the previous BFD to which + messages are stored. Note that two sequential calls to this + with a non-NULL BFD will cause output to be dropped, rather + than gathered. */ -bfd_error_handler_type +bfd * _bfd_set_error_handler_caching (bfd *abfd) +{ + bfd *old = error_handler_bfd; + if (old == NULL) + error_handler_bfd = abfd; + else + error_handler_bfd = IGNORE_ERROR_BFD; + return old; +} + +/* +INTERNAL_FUNCTION + _bfd_restore_error_handler_caching + +SYNOPSIS + void _bfd_restore_error_handler_caching (bfd *); + +DESCRIPTION + Reset the BFD error handler function an earlier value. +*/ + +void +_bfd_restore_error_handler_caching (bfd *abfd) { error_handler_bfd = abfd; - return bfd_set_error_handler (error_handler_sprintf); } /* diff --git a/bfd/format.c b/bfd/format.c index 47c3e9ba35a..42b50421288 100644 --- a/bfd/format.c +++ b/bfd/format.c @@ -279,12 +279,6 @@ clear_warnmsg (struct per_xvec_message **list) *list = NULL; } -static void -null_error_handler (const char *fmt ATTRIBUTE_UNUSED, - va_list ap ATTRIBUTE_UNUSED) -{ -} - /* FUNCTION bfd_check_format_matches @@ -320,8 +314,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching) unsigned int initial_section_id = _bfd_section_id; struct bfd_preserve preserve, preserve_match; bfd_cleanup cleanup = NULL; - bfd_error_handler_type orig_error_handler; - static int in_check_format; + bfd *orig_error_bfd; if (matching != NULL) *matching = NULL; @@ -350,13 +343,10 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching) abfd->format = format; save_targ = abfd->xvec; - /* Don't report errors on recursive calls checking the first element - of an archive. */ - if (in_check_format) - orig_error_handler = bfd_set_error_handler (null_error_handler); - else - orig_error_handler = _bfd_set_error_handler_caching (abfd); - ++in_check_format; + /* We don't want to report errors on recursive calls checking the + first element of an archive. This is handled by the + error-handler code, which see. */ + orig_error_bfd = _bfd_set_error_handler_caching (abfd); preserve_match.marker = NULL; if (!bfd_preserve_save (abfd, &preserve, NULL)) @@ -598,7 +588,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching) if (preserve_match.marker != NULL) bfd_preserve_finish (abfd, &preserve_match); bfd_preserve_finish (abfd, &preserve); - bfd_set_error_handler (orig_error_handler); + _bfd_restore_error_handler_caching (orig_error_bfd); struct per_xvec_message **list = _bfd_per_xvec_warn (abfd->xvec, 0); if (*list) @@ -606,7 +596,6 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching) list = _bfd_per_xvec_warn (NULL, 0); for (size_t i = 0; i < _bfd_target_vector_entries + 1; i++) clear_warnmsg (list++); - --in_check_format; /* File position has moved, BTW. */ return true; @@ -650,7 +639,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching) if (preserve_match.marker != NULL) bfd_preserve_finish (abfd, &preserve_match); bfd_preserve_restore (abfd, &preserve); - bfd_set_error_handler (orig_error_handler); + _bfd_restore_error_handler_caching (orig_error_bfd); struct per_xvec_message **list = _bfd_per_xvec_warn (NULL, 0); struct per_xvec_message **one = NULL; for (size_t i = 0; i < _bfd_target_vector_entries + 1; i++) @@ -670,7 +659,6 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching) print_warnmsg (one); for (size_t i = 0; i < _bfd_target_vector_entries + 1; i++) clear_warnmsg (list++); - --in_check_format; return false; } diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 40bbe6a3886..40e9c88e711 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -933,7 +933,9 @@ void _bfd_clear_error_data (void) ATTRIBUTE_HIDDEN; char *bfd_asprintf (const char *fmt, ...) ATTRIBUTE_HIDDEN; -bfd_error_handler_type _bfd_set_error_handler_caching (bfd *) ATTRIBUTE_HIDDEN; +bfd *_bfd_set_error_handler_caching (bfd *) ATTRIBUTE_HIDDEN; + +void _bfd_restore_error_handler_caching (bfd *) ATTRIBUTE_HIDDEN; const char *_bfd_get_error_program_name (void) ATTRIBUTE_HIDDEN;