NetBSD Problem Report #51139
From www@NetBSD.org Sun May 15 01:09:56 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id A03CE7A2AF
for <gnats-bugs@gnats.NetBSD.org>; Sun, 15 May 2016 01:09:56 +0000 (UTC)
Message-Id: <20160515010955.C351D7AAAE@mollari.NetBSD.org>
Date: Sun, 15 May 2016 01:09:55 +0000 (UTC)
From: n54@gmx.com
Reply-To: n54@gmx.com
To: gnats-bugs@NetBSD.org
Subject: C++11 std::call_once() broken on NetBSD
X-Send-Pr-Version: www-1.0
>Number: 51139
>Category: lib
>Synopsis: C++11 std::call_once() broken on NetBSD
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun May 15 01:10:00 +0000 2016
>Closed-Date: Sat Aug 05 13:47:52 +0000 2017
>Last-Modified: Sat Aug 05 13:47:52 +0000 2017
>Originator: Kamil Rytarowski
>Release: 7.99.28 and 7.0
>Organization:
>Environment:
NetBSD chieftec 7.99.28 NetBSD 7.99.28 (GENERIC) #0: Wed Apr 27 05:36:02 CEST 2016 root@chieftec:/tmp/netbsd-tmp/sys/arch/amd64/compile/GENERIC amd64
And
NetBSD nb7_amd64 7.0 NetBSD 7.0 (GENERIC.201509250726Z) amd64
>Description:
The LLVM+Clang+LLDB buildbot has caught quickly a bug on NetBSD with std::call_once() in C++11.
http://reviews.llvm.org/D19271
It happened that std::call_once() as defined in C++11 doesn't work in 7.0 neither in HEAD (7.99.28).
>How-To-Repeat:
Build the following example and try to run.
#include <iostream>
#include <thread>
#include <mutex>
std::once_flag flag;
void simple_do_once()
{
std::call_once(flag, [](){ std::cout << "Simple example: called once\n"; });
}
int main()
{
std::thread st1(simple_do_once);
st1.join();
}
<build>
g++ -std=c++11 -lpthread test.cpp
</build>
<run>
</run>
>Fix:
not investigated
>Release-Note:
>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: lib/51139: C++11 std::call_once() broken on NetBSD
Date: Sun, 15 May 2016 09:31:43 +0200
Program received signal SIGSEGV, Segmentation fault.
[Switching to LWP 2]
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x00007f7ff780692e in pthread_once (
once_control=once_control@entry=0x601d00 <flag>,
routine=0x400d50 <__once_proxy@plt>)
at /usr/src/lib/libpthread/pthread_once.c:63
#2 0x00000000004010cb in __gthread_once (__func=<optimized out>,
__once=0x601d00 <flag>) at /usr/include/g++/bits/gthr-default.h:699
#3 std::call_once<simple_do_once()::<lambda()> > (__once=...,
__f=<optimized out>) at /usr/include/g++/mutex:729
#4 simple_do_once () at test.cc:9
#5 0x00007f7ff74a6dab in std::(anonymous namespace)::execute_native_thread_routine (__p=<optimized out>)
at /usr/src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11/thread.cc:84
#6 0x00007f7ff780b1c1 in pthread__create_tramp (cookie=0x7f7ff7b19000)
at /usr/src/lib/libpthread/pthread.c:576
Name clash on weak symbols between libpthread and libstdc++ ?
Martin
From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@NetBSD.org
Cc: Martin Husemann <martin@duskware.de>
Subject: Re: lib/51139: C++11 std::call_once() broken on NetBSD
Date: Sun, 15 May 2016 13:54:53 +0300
On Sun, May 15, 2016 at 07:35:00 +0000, Martin Husemann wrote:
> Name clash on weak symbols between libpthread and libstdc++ ?
It works if -static, so more likely a bug ld.so vs. TLS.
-uwe
From: Joerg Sonnenberger <joerg@bec.de>
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org, n54@gmx.com
Subject: Re: lib/51139: C++11 std::call_once() broken on NetBSD
Date: Sun, 15 May 2016 17:40:35 +0200
On Sun, May 15, 2016 at 10:55:01AM +0000, Valery Ushakov wrote:
> The following reply was made to PR lib/51139; it has been noted by GNATS.
>
> From: Valery Ushakov <uwe@stderr.spb.ru>
> To: gnats-bugs@NetBSD.org
> Cc: Martin Husemann <martin@duskware.de>
> Subject: Re: lib/51139: C++11 std::call_once() broken on NetBSD
> Date: Sun, 15 May 2016 13:54:53 +0300
>
> On Sun, May 15, 2016 at 07:35:00 +0000, Martin Husemann wrote:
> > Name clash on weak symbols between libpthread and libstdc++ ?
>
> It works if -static, so more likely a bug ld.so vs. TLS.
That doesn't say much. With -static, the weak symbols are resolved
differently, most noticable all weak versions are completely ignored in
favor of the strong implementation.
Joerg
From: Joerg Sonnenberger <joerg@bec.de>
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: lib/51139: C++11 std::call_once() broken on NetBSD
Date: Sun, 15 May 2016 18:03:17 +0200
On Sun, May 15, 2016 at 01:10:00AM +0000, n54@gmx.com wrote:
> It happened that std::call_once() as defined in C++11 doesn't work in
> 7.0 neither in HEAD (7.99.28).
Note that this issue is specific to libstdc++. libc++ works correctly.
Joerg
From: Kamil Rytarowski <n54@gmx.com>
To: gnats-bugs@NetBSD.org
Cc: jwakely@redhat.com
Subject: Re: lib/51139: C++11 std::call_once() broken on NetBSD
Date: Wed, 21 Dec 2016 00:37:18 +0100
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--XIhW0cj4obWMxJ86tIQNMcewMATUxqHa1
Content-Type: multipart/mixed; boundary="uiUp6R2bHkXWMUp2cN1Vx5amJkPTRURCQ"
From: Kamil Rytarowski <n54@gmx.com>
To: gnats-bugs@NetBSD.org
Cc: jwakely@redhat.com
Message-ID: <69cb1ee3-f006-3f11-e56a-2fdbcaac6580@gmx.com>
Subject: Re: lib/51139: C++11 std::call_once() broken on NetBSD
References: <pr-lib-51139@gnats.netbsd.org>
<20160515010955.C351D7AAAE@mollari.NetBSD.org>
<20160515160501.511577AAAE@mollari.NetBSD.org>
In-Reply-To: <20160515160501.511577AAAE@mollari.NetBSD.org>
--uiUp6R2bHkXWMUp2cN1Vx5amJkPTRURCQ
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
On 15.05.2016 18:05, Joerg Sonnenberger wrote:
> The following reply was made to PR lib/51139; it has been noted by GNAT=
S.
>=20
> From: Joerg Sonnenberger <joerg@bec.de>
> To: gnats-bugs@NetBSD.org
> Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
> netbsd-bugs@netbsd.org
> Subject: Re: lib/51139: C++11 std::call_once() broken on NetBSD
> Date: Sun, 15 May 2016 18:03:17 +0200
>=20
> On Sun, May 15, 2016 at 01:10:00AM +0000, n54@gmx.com wrote:
> > It happened that std::call_once() as defined in C++11 doesn't work i=
n
> > 7.0 neither in HEAD (7.99.28).
> =20
> Note that this issue is specific to libstdc++. libc++ works correctly.=
> =20
> Joerg
> =20
>=20
libc++ doesn't use pthread_once(3)
The problem is with TLS used in combination with libstdc++ for
std::call_once.
Everything works (for single threaded setup safe) if we remove __thread
from the following fragment:
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
#ifdef _GLIBCXX_HAVE_TLS
__thread void* __once_callable;
__thread void (*__once_call)();
#else
// Explicit instantiation due to -fno-implicit-instantiation.
template class function<void()>;
function<void()> __once_functor;
mutex&
__get_once_mutex()
{
static mutex once_mutex;
return once_mutex;
}
// code linked against ABI 3.4.12 and later uses this
void
__set_once_functor_lock_ptr(unique_lock<mutex>* __ptr)
{
__get_once_functor_lock_ptr() =3D __ptr;
}
// unsafe - retained for compatibility with ABI 3.4.11
unique_lock<mutex>&
__get_once_functor_lock()
{
static unique_lock<mutex> once_functor_lock(__get_once_mutex(),
defer_lock);
return once_functor_lock;
}
#endif
extern "C"
{
void __once_proxy()
{
#ifndef _GLIBCXX_HAVE_TLS
function<void()> __once_call =3D std::move(__once_functor);
if (unique_lock<mutex>* __lock =3D __get_once_functor_lock_ptr())
{
// caller is using new ABI and provided lock ptr
__get_once_functor_lock_ptr() =3D 0;
__lock->unlock();
}
else
__get_once_functor_lock().unlock(); // global lock
#endif
__once_call();
}
}
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
-- src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11/mutex.cc
So far I have not reproduced this issue out of the libstdc++ context.
Upstream reports that it might be related to ld.so and resolving
__tls_get_addr, as it was causing trouble in the past.
Perhaps something related:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D52192
std::call_once is frequently used in LLDB.
I've not reproduced this issue out of the libstdc++ context so far.
--uiUp6R2bHkXWMUp2cN1Vx5amJkPTRURCQ--
--XIhW0cj4obWMxJ86tIQNMcewMATUxqHa1
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIbBAEBCAAGBQJYWcC2AAoJEEuzCOmwLnZsPp4P93wns07DHZiVUr5DCGY6TAS1
oMhUxlnq0is0Zz4CZ4W0Q6KkbUrHjxR4ifKb6aaWS7CUburlily3t6i8rBqgmanR
tNH9gm2m+MjeDojkytyjrXP3vOVsAM8Rvw7WBudZURMTakijUiJ3nx/k5z6OLmcO
KzOR0k/nzWYySZpNDJy37agR7otDUeogp9A4WXGJluHnXBFF2gbj1mq9Xd2+hMZx
ViGZr5UOCjgp5obnxJWAYJ57SWfroNTbZOg+c5HRXBRSN73H9W9YvGWT5RdmQzhP
Zgt+ekn4o3kKZ9O7cAoaxfYu2q+Eop5hD/G6hs+f7kiriXOiwIwUil1X8JQCymL/
NnG30LDtzdIeDz+54LymZIhW5um4bI3hUpNVWd62RXlac/VKlji/7VJ7YX6rwmKh
/Nlb3ASIc0guppUc2WcoXmOd2iGdPHT8dZzpjdMx+OPYsXzlfA0/BR8ivATtPkV3
Dj83O/djNKekLVSCnxQoSGVnflVE9znAi00mqX6NzZvBQTvVKgFeRaphx50n+GlI
7p16vy8NG5A93M+R0DrDFbRi9TYNjPDPEOaUG+9az0OB62DJWWkoNjTtrNDvs/QA
RGHUoK8fz/PehhBGyD4x6kKxokxVqiAnDc2A6Qc9ZAFwctL5ESsC756gH21IIj4N
78h4R5s0RW9JrWGUliA=
=LUXc
-----END PGP SIGNATURE-----
--XIhW0cj4obWMxJ86tIQNMcewMATUxqHa1--
From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51139 CVS commit: src/external/gpl3/gcc/dist/libstdc++-v3
Date: Wed, 21 Dec 2016 21:55:46 +0000
Module Name: src
Committed By: kamil
Date: Wed Dec 21 21:55:46 UTC 2016
Modified Files:
src/external/gpl3/gcc/dist/libstdc++-v3/include/std: mutex
src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11: mutex.cc
Log Message:
Add a walkaround for TLS bug in libstdc++ exposed with std::call_once
Currently std::call_once with libstdc++ works only with static linking.
Disable code path using __thread types and introduce FIXME_PR_51139.
Problem discussed in PR 51139
Functional std::call_once is required in LLVM and LLDB codebase.
Example code to test std::call_once:
#include <iostream>
#include <thread>
#include <mutex>
#include <cstdlib>
std::once_flag flag;
int main(int argc, char **argv)
{
std::call_once(flag, [](){ std::cout << "Simple example: called once\n"; });
return EXIT_SUCCESS;
}
Sponsored by <The NetBSD Foundation>
To generate a diff of this commit:
cvs rdiff -u -r1.1.1.4 -r1.2 \
src/external/gpl3/gcc/dist/libstdc++-v3/include/std/mutex
cvs rdiff -u -r1.1.1.2 -r1.2 \
src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11/mutex.cc
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51139 CVS commit: src/external/gpl3/gcc/dist/libstdc++-v3
Date: Sat, 24 Dec 2016 15:48:26 +0000
Module Name: src
Committed By: kamil
Date: Sat Dec 24 15:48:26 UTC 2016
Modified Files:
src/external/gpl3/gcc/dist/libstdc++-v3/include/std: mutex
src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11: mutex.cc
Log Message:
Revert introduction of FIXME_PR_51139
This change introduced ABI incompatible change with older versions shipped
on NetBSD. This back out code that is currently not working correctly due
to TLS-based std::call_once implementation in GNU libstdc++.
Error when starting gnuchash:
/usr/pkg/lib/libwebkitgtk-1.0.so.0: Undefined symbol "_ZSt15__once_callable" (symnum = 1705)
PR 51139
Reported by <wiz>
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/external/gpl3/gcc/dist/libstdc++-v3/include/std/mutex
cvs rdiff -u -r1.2 -r1.3 \
src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11/mutex.cc
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: kamil@NetBSD.org
State-Changed-When: Sat, 05 Aug 2017 15:47:52 +0200
State-Changed-Why:
Fixed by Joerg Sonnenberger
Fixed in NetBSD-current and pull-requested for NetBSD-8.
src/libexec/ld.elf_so: tls.c r. 1.11
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.