From: Nick Clifton <nickc@redhat.com>
To: Tom Tromey <tom@tromey.com>, binutils@sourceware.org
Subject: Re: [PATCH 1/3] Make several more BFD globals thread-local
Date: Mon, 12 Feb 2024 15:28:20 +0000 [thread overview]
Message-ID: <a862a884-db47-46b8-81c1-931d7f1bf01e@redhat.com> (raw)
In-Reply-To: <20240130010540.1754740-2-tom@tromey.com>
Hi Tom,
> 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.
Actually, I think that I would prefer this alternative solution.
I am particularly worried about making the error handler thread local
when this might not match the expectations of a client using the BFD
library. Since the error handler is currently global, a client can
expect to set it once and have it affect all threads.
Looking at the code in bfd_check_format_matches() it seems clear that
the error handler manipulation is really a hack, based upon the single
threaded nature of the BFD library. This become problematical when the
BFD library is used in a multi-threaded environment.
It seems to me that the proper thing to do would be to [throw away the
BFD library and use something designed from the ground up to thread-safe],
ahem, I mean provide a thread safe way for bfd_check_format_matches to
override the error handler within its local context, without it affecting
the global error handler for other threads *and* still allowing the client
to call bfd_set_error_handler to change the error handler for all threads
at once.
This sounds like a lot of work however, and probably something that
ought to be done as part of a larger project to turn the BFD library
into a thread-safe and multi-threaded library.
What are you thoughts ?
Cheers
Nick
next prev parent reply other threads:[~2024-02-12 15:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-30 1:03 [PATCH 0/3] Fix some error-printing issues Tom Tromey
2024-01-30 1:03 ` [PATCH 1/3] Make several more BFD globals thread-local Tom Tromey
2024-02-12 15:28 ` Nick Clifton [this message]
2024-02-12 23:52 ` Tom Tromey
2024-02-13 0:35 ` Tom Tromey
2024-02-13 1:20 ` Tom Tromey
2024-03-09 1:12 ` Tom Tromey
2024-03-09 4:11 ` Alan Modra
2024-03-09 10:31 ` Alan Modra
2024-03-15 0:12 ` Tom Tromey
2024-03-19 20:17 ` Tom Tromey
2024-03-15 1:15 ` Tom Tromey
2024-01-30 1:03 ` [PATCH 2/3] Do not call fputc from _bfd_doprnt Tom Tromey
2024-02-12 15:04 ` Nick Clifton
2024-01-30 1:03 ` [PATCH 3/3] Introduce bfd_print_error function Tom Tromey
2024-02-12 15:04 ` Nick Clifton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a862a884-db47-46b8-81c1-931d7f1bf01e@redhat.com \
--to=nickc@redhat.com \
--cc=binutils@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).