mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: Re: gthread_once
Date: Sat, 18 Oct 2014 20:14:30 +0200	[thread overview]
Message-ID: <20141018181430.GC16659@port70.net> (raw)
In-Reply-To: <20141018154518.GE32028@brightrain.aerifal.cx>

* Rich Felker <dalias@libc.org> [2014-10-18 11:45:18 -0400]:
> 
> If I understand the explanation of what's going on correctly, it's a
> huge bug in libstdc++, and exactly the same as the one that's known
> (and that we've discussed on IRC, etc.) many times in libxml2:
> 
> https://bugzilla.gnome.org/show_bug.cgi?id=704904
> 
> It looks to me like gcc is expecting dynamic-linking-like and/or
> bloatware-libpthread-like behavior, where if any one of the pthread
> symbols has a definition, they all do. This is definitely NOT the case
> with static linking, especially with musl. It's also not the case with
> glibc, though they have more indirect dependencies that cause a large
> portion (but not all) of libpthread to be pulled in when you use any
> one part, and some distros (at least Redhat ones, IIRC) link their
> libpthread.a with a hack to merge all the modules into one giant .o
> file inside the .a precisely to work around bugs like this.
> 
> If I'm correct, just removing all the weak attributes from the
> gthr-posix.h stuff should fix the bug.

yes this is the bug

it turns out gthr-posix.h decides if there are threads
if pthread_cancel is present (weak ref is non-null)
(on glibc it checks pthread_key_create and on bionic it
checks pthread_create)

if there is no pthread_cancel then libstdc++ will assume
no threads and __gthread calls fail (eg iostream locks
are skipped, in call_once a system_error is thrown)

if there is pthread_cancel then a __gthread_something call
will call pthread_something and if that is otherwise
unreferenced it will crash (in case of static linking)

example that crases here whit -static:

#include <iostream>
#include <pthread.h>
int (*f)(pthread_t) = pthread_cancel;
int main()
{
	std::cout << "";
}

possible workaround: create a .o that references all
pthread_* functions and link it into your app
(this is the bloatware-libpthread solution until libstdc++ is fixed)


  reply	other threads:[~2014-10-18 18:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-18  2:16 gthread_once Michael
2014-10-18 10:18 ` gthread_once Szabolcs Nagy
2014-10-18 15:45   ` Rich Felker
2014-10-18 18:14     ` Szabolcs Nagy [this message]
2014-10-18 19:02       ` Rich Felker
2014-10-18 19:25         ` Jens Gustedt
2014-10-19  0:08           ` Michael
  -- strict thread matches above, loose matches on Subject: below --
2014-10-17 10:36 gthread_once Michael
2014-10-17 11:42 ` gthread_once Jens Gustedt
2014-10-17 12:10   ` Rich Felker

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=20141018181430.GC16659@port70.net \
    --to=nsz@port70.net \
    --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).