[Bug libstdc++/94936] New: pmr::synchronized_pool_resource crashes without -pthread

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun May 3 11:33:06 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94936

            Bug ID: 94936
           Summary: pmr::synchronized_pool_resource crashes without
                    -pthread
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

#include <memory_resource>

// g++ -std=c++17 segfault.cc -o segfault

int main()
{
    std::pmr::synchronized_pool_resource pool;
}

This dies in the constructor:

  synchronized_pool_resource::
  synchronized_pool_resource(const pool_options& opts,
                             memory_resource* upstream)
  : _M_impl(opts, upstream)
  {
    if (int err = __gthread_key_create(&_M_key, destroy_TPools))
      __throw_system_error(err);
    exclusive_lock l(_M_mx);
    _M_tpools = _M_alloc_shared_tpools(l);
  }


Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) up
#1  0x00007ffff7f5aeca in __gthread_key_create (__dtor=0x7ffff7f5aa90
<std::pmr::destroy_TPools(void*)>, __key=0x7fffffffd7c0) at
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/gthr-default.h:708
#2  std::pmr::synchronized_pool_resource::synchronized_pool_resource
(this=0x7fffffffd780, opts=..., upstream=<optimized out>) at
/home/jwakely/src/gcc/gcc/libstdc++-v3/src/c++17/memory_resource.cc:1136


__gthread_key_create doesn't check __ghtread_active_p before calling
pthread_key_create, so calls an undefined weak symbol if not linked to
libpthread.


More information about the Gcc-bugs mailing list