https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104852
Bug ID: 104852 Summary: std::[j]thread::detach() still gives segmentation faults with glibc 2.34 Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: lightningdzeyenr at gmail dot com Target Milestone: --- I'm using g++ 11.2.0 on Ubuntu 21.10 (Pop!_OS 21.10) and trying to compile a project that uses the std::[j]thread::detach() function a lot. When I statically link it, I always get a segmentation fault for what seems to be something in the libpthread library. This happens with both std::thread and std::jthread. ldd --version shows a glibc version of 2.34 (specifically 2.34-0ubuntu3.2), and ld --version shows 2.37, both versions at which this bug should have been fixed. Here's the output of g++ -v: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu [I'm using AMD Zen 3] Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-7ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.2.0 (Ubuntu 11.2.0-7ubuntu2) I'm compiling with the CMake command > cmake source -DADD_FLAGS="-static -lpthread" which adds these flags to the end of CMAKE_CXX_FLAGS, and > cmake --build . -j 12 to build. I can't provide the .i files because even compressed as a .tar.gz, the archive is too big (4.5MB). However, this is reproducible by cloning the repo (https://github.com/Slackadays/Hajime), cd hajime, and issuing the two CMake commands above. Output of GDB: Thread 2 "hajime" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff7ff8640 (LWP 52019)] 0x0000000000000000 in ?? () (gdb) bt #0 0x0000000000000000 in ?? () #1 0x0000000000510745 in std::thread::detach() () #2 0x000000000044ca76 in Server::startProgram (this=0x7022b0, method=...) at /home/jackson/hajime/source/server.cpp:290 #3 0x000000000044ad15 in Server::startServer (this=0x7022b0, confFile=...) at /home/jackson/hajime/source/server.cpp:112 #4 0x0000000000449d8f in std::__invoke_impl<void, void (Server::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >), std::shared_ptr<Server>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (__f= @0x6ff0c8: (void (Server::*)(Server * const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)) 0x44a298 <Server::startServer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)>, __t=...) at /usr/include/c++/11/bits/invoke.h:74 #5 0x0000000000449c45 in std::__invoke<void (Server::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >), std::shared_ptr<Server>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (__fn= @0x6ff0c8: (void (Server::*)(Server * const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)) 0x44a298 <Server::startServer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)>) at /usr/include/c++/11/bits/invoke.h:96 #6 0x0000000000449b35 in std::thread::_Invoker<std::tuple<void (Server::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >), std::shared_ptr<Server>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_invoke<0ul, 1ul, 2ul> (this=0x6ff098) at /usr/include/c++/11/bits/std_thread.h:253 #7 0x000000000044958a in std::thread::_Invoker<std::tuple<void (Server::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >), std::shared_ptr<Server>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::operator() (this=0x6ff098) at /usr/include/c++/11/bits/std_thread.h:260 #8 0x0000000000449422 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (Server::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >), std::shared_ptr<Server>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_M_run ( this=0x6ff090) at /usr/include/c++/11/bits/std_thread.h:211 #9 0x00000000005104b4 in execute_native_thread_routine () #10 0x000000000058a877 in start_thread () #11 0x000000000060d814 in clone () (gdb)