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.

Modified files:

Index: src/external/gpl3/gcc/dist/libstdc++-v3/include/std/mutex
diff -u src/external/gpl3/gcc/dist/libstdc++-v3/include/std/mutex:1.1.1.4 src/external/gpl3/gcc/dist/libstdc++-v3/include/std/mutex:1.2
--- src/external/gpl3/gcc/dist/libstdc++-v3/include/std/mutex:1.1.1.4	Tue Jun  7 05:57:53 2016
+++ src/external/gpl3/gcc/dist/libstdc++-v3/include/std/mutex	Wed Dec 21 21:55:46 2016
@@ -695,7 +695,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       call_once(once_flag& __once, _Callable&& __f, _Args&&... __args);
   };
 
-#ifdef _GLIBCXX_HAVE_TLS
+#if defined(_GLIBCXX_HAVE_TLS) && defined(FIXME_PR_51139)
   extern __thread void* __once_callable;
   extern __thread void (*__once_call)();
 
@@ -722,7 +722,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     void
     call_once(once_flag& __once, _Callable&& __f, _Args&&... __args)
     {
-#ifdef _GLIBCXX_HAVE_TLS
+#if defined(_GLIBCXX_HAVE_TLS) && defined(FIXME_PR_51139)
       auto __bound_functor = std::__bind_simple(std::forward<_Callable>(__f),
           std::forward<_Args>(__args)...);
       __once_callable = std::__addressof(__bound_functor);
@@ -737,7 +737,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       int __e = __gthread_once(&__once._M_once, &__once_proxy);
 
-#ifndef _GLIBCXX_HAVE_TLS
+#if !defined(_GLIBCXX_HAVE_TLS) || !defined(FIXME_PR_51139)
       if (__functor_lock)
         __set_once_functor_lock_ptr(0);
 #endif

Index: src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11/mutex.cc
diff -u src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11/mutex.cc:1.1.1.2 src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11/mutex.cc:1.2
--- src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11/mutex.cc:1.1.1.2	Sun Jan 24 06:05:43 2016
+++ src/external/gpl3/gcc/dist/libstdc++-v3/src/c++11/mutex.cc	Wed Dec 21 21:55:46 2016
@@ -25,7 +25,7 @@
 #include <mutex>
 
 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
-#ifndef _GLIBCXX_HAVE_TLS
+#if !defined(_GLIBCXX_HAVE_TLS) || !defined(FIXME_PR_51139)
 namespace
 {
   inline std::unique_lock<std::mutex>*&
@@ -41,7 +41,7 @@ namespace std _GLIBCXX_VISIBILITY(defaul
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-#ifdef _GLIBCXX_HAVE_TLS
+#if defined(_GLIBCXX_HAVE_TLS) && defined(FIXME_PR_51139)
   __thread void* __once_callable;
   __thread void (*__once_call)();
 #else
@@ -76,7 +76,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   {
     void __once_proxy()
     {
-#ifndef _GLIBCXX_HAVE_TLS
+#if !defined(_GLIBCXX_HAVE_TLS) || !defined(FIXME_PR_51139)
       function<void()> __once_call = std::move(__once_functor);
       if (unique_lock<mutex>* __lock = __get_once_functor_lock_ptr())
       {

Reply via email to