public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: Szabolcs Nagy via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH v4] elf: Avoid deadlock between pthread_create and ctors [BZ #28357]
Date: Wed, 2 Feb 2022 14:41:33 +0000	[thread overview]
Message-ID: <20220202144133.GL1989194@arm.com> (raw)
In-Reply-To: <87wnidjq5k.fsf@igel.home>

The 02/02/2022 15:31, Andreas Schwab wrote:
> On Okt 01 2021, Szabolcs Nagy via Libc-alpha wrote:
> 
> > diff --git a/elf/dl-open.c b/elf/dl-open.c
> > index 5295e931b0..6ea5dd2457 100644
> > --- a/elf/dl-open.c
> > +++ b/elf/dl-open.c
> > @@ -66,6 +66,9 @@ struct dl_open_args
> >       libc_map value in the namespace in case of a dlopen failure.  */
> >    bool libc_already_loaded;
> >  
> > +  /* Set to true if the end of dl_open_worker_begin was reached.  */
> > +  bool worker_continue;
> > +
> >    /* Original parameters to the program and the current environment.  */
> >    int argc;
> >    char **argv;
> > @@ -482,7 +485,7 @@ call_dl_init (void *closure)
> >  }
> >  
> >  static void
> > -dl_open_worker (void *a)
> > +dl_open_worker_begin (void *a)
> >  {
> >    struct dl_open_args *args = a;
> >    const char *file = args->file;
> > @@ -774,6 +777,36 @@ dl_open_worker (void *a)
> >        _dl_call_libc_early_init (libc_map, false);
> >      }
> >  
> > +  args->worker_continue = true;
> > +}
> > +
> > +static void
> > +dl_open_worker (void *a)
> > +{
> > +  struct dl_open_args *args = a;
> > +
> > +  args->worker_continue = false;
> > +
> > +  {
> > +    /* Protects global and module specific TLS state.  */
> > +    __rtld_lock_lock_recursive (GL(dl_load_tls_lock));
> > +
> > +    struct dl_exception ex;
> > +    int err = _dl_catch_exception (&ex, dl_open_worker_begin, args);
> > +
> > +    __rtld_lock_unlock_recursive (GL(dl_load_tls_lock));
> > +
> > +    if (__glibc_unlikely (ex.errstring != NULL))
> > +      /* Reraise the error.  */
> > +      _dl_signal_exception (err, &ex, NULL);
> > +  }
> > +
> > +  if (!args->worker_continue)
> > +    return;
> 
> Why do you need worker_continue?  How can worker_continue not be set at
> this point?

because dl_open_worker_begin (old dl_open_worker) can simply return.
(without reaching the end of the function or raising an error)

  reply	other threads:[~2022-02-02 14:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01 16:33 Szabolcs Nagy
2021-10-01 16:43 ` Adhemerval Zanella
2021-10-04 13:00   ` Szabolcs Nagy
2022-02-02 14:31 ` Andreas Schwab
2022-02-02 14:41   ` Szabolcs Nagy [this message]
2022-02-02 15:13     ` Andreas Schwab
2022-02-02 15:17     ` Andreas Schwab

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=20220202144133.GL1989194@arm.com \
    --to=szabolcs.nagy@arm.com \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@linux-m68k.org \
    /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).