mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Rich Felker <dalias@libc.org>
Cc: Арсений <a@saur0n.science>,
	musl@lists.openwall.com, "Florian Weimer" <fw@deneb.enyo.de>
Subject: Re: [musl] Mutexes are not unlocking
Date: Mon, 23 Nov 2020 16:58:33 +0000	[thread overview]
Message-ID: <20201123165833.GU1312820@redhat.com> (raw)
In-Reply-To: <20201123145628.GV534@brightrain.aerifal.cx>

On 23/11/20 09:56 -0500, Rich Felker wrote:
>On Mon, Nov 23, 2020 at 12:24:28PM +0000, Jonathan Wakely wrote:
>> On 22/11/20 23:05 +0300, Арсений wrote:
>> >
>> >Hello,
>> > 
>> >I fixed the problem by making a workaround. Specifying -D_GLIBCXX_GTHREAD_USE_WEAK=0 forces libstdc++ headers do not use weak symbols. Mutexes are correctly locked and unlocked now.
>>
>> That might "work" but is unsupported, because that macro is for
>> libstdc++'s internal use, not for users to define/undefine.
>>
>> But then libstdc++ doesn't support being compiled/linked against a
>> glibc libstdc++ and then running against musl at runtime (I didn't
>> even know that was an option until today) so one more unsupported
>> thing probably won't hurt :-)
>>
>> Maybe we should just bless the use of that macro as supported, which
>> would solve https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89714
>
>As you noted in comment 2, that won't fix the uses internal to
>libstdc++.{so,a}, only the inlined ones. I think this could give the
>wrong behavior in the opposite direction -- calling unlock without
>lock, thereby causing an error (for error-checking mutexes) or trap
>(if UB catching traps are in place for other types).

I've just had a quick look, and (for linux targets) the only case I
found where there's a lock outside the library (in user code) and a
corresponding unlock inside the library, or vice versa, is in
std::notify_all_at_thread_exit. (I only looked very quickly, so there
might be other cases I missed).

It does look like it would be possible for user code to lock the mutex
(via a direct all to the non-weak pthread_mutex_lock) and then call
std::notify_all_at_thread_exit() which unlock the mutex, which would
test __gthread_active_p, which would incorrectly think the program is
single-threaded, and not call pthread_mutex_unlock.

So recommending -D_GLIBCXX_GTHREAD_USE_WEAK=0 is a bad idea. We would
need a better way for users to override the checks.



  reply	other threads:[~2020-11-23 17:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20  5:25 a
2020-11-20  5:58 ` Rich Felker
2020-11-21  6:46   ` Re[2]: " a
2020-11-21 15:51     ` Rich Felker
2020-11-22 18:43       ` Re[2]: " Арсений
2020-11-22 19:11         ` Rich Felker
2020-11-22 19:23           ` Florian Weimer
2020-11-22 19:28             ` Rich Felker
2020-11-22 19:45               ` Re[2]: " Арсений
2020-11-22 20:05               ` Арсений
2020-11-23 12:24                 ` Jonathan Wakely
2020-11-23 14:56                   ` Rich Felker
2020-11-23 16:58                     ` Jonathan Wakely [this message]
2020-11-23 11:41               ` Jonathan Wakely
2020-11-23 14:53                 ` Rich Felker
2020-11-23 16:19                   ` Jonathan Wakely
2020-11-23 16:51                     ` Rich Felker
2020-11-23 17:10                       ` Jonathan Wakely
2020-11-23 17:18                         ` Florian Weimer
2020-11-23 16:59                     ` Florian Weimer

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=20201123165833.GU1312820@redhat.com \
    --to=jwakely@redhat.com \
    --cc=a@saur0n.science \
    --cc=dalias@libc.org \
    --cc=fw@deneb.enyo.de \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).