libpqxx: thread_local storage in strconv.cxx crashes under MSys.
Use of dumb_stringstream in conjunction with have_thread_local=true in a multi-threaded program compiled using MinGW/GCC under MSys causes a segfault on exit:
(gdb) bt
#0 0x6f4e39ee in ?? () from C:\msys64\mingw32\bin\libstdc++-6.dll
#1 0x6f4f3b16 in ?? () from C:\msys64\mingw32\bin\libstdc++-6.dll
#2 0x00e81775 in (anonymous namespace)::dumb_stringstream<double>::~dumb_stringstream (this=0x31b17ac, __in_chrg=<optimized out>,
__vtt_parm=<optimized out>)
at C:/Work/BUILDS/apollo/PostgreSQL_XX/PostgreSQL_XX-src/src/strconv.cxx:480
#3 0x00e8abe5 in run_dtor_list (ptr=<synthetic pointer>)
at C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:59
#4 tls_callback (hDllHandle=0xe60000, dwReason=3, lpReserved=0x0)
at C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:155
#5 0x77072976 in ntdll!RtlIpv6AddressToStringA ()
from C:\Windows\SysWOW64\ntdll.dll
#6 0x7704dd22 in ntdll!RtlActivateActivationContextUnsafeFast ()
from C:\Windows\SysWOW64\ntdll.dll
#7 0x7704f141 in ntdll!RtlRbInsertNodeEx ()
from C:\Windows\SysWOW64\ntdll.dll
#8 0x7704f7be in ntdll!LdrShutdownThread ()
from C:\Windows\SysWOW64\ntdll.dll
#9 0x28600952 in ?? ()
#10 0x00000000 in ?? ()
Overriding “have_thread_local” to false prevents the crash.
The program I reproduce this with is a test program where the code under test is writing a double to a database in one thread, and the test is reading the database in another thread.
Sorry to just dump this on you but I don’t really have time for further investigation. I suspect thread_local is just broken with MinGW/GCC/MSys and that the fix is to detect this build environment in the CMake/configure scripts. E.g. something like:
if (not MSYS)
try_compile(
PQXX_HAVE_THREAD_LOCAL
${PROJECT_BINARY_DIR}
SOURCES ${PROJECT_SOURCE_DIR}/config-tests/thread_local.cxx)
endif()
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (11 by maintainers)
Commits related to this issue
- Avoid `thread_local` on current or older MinGW. This is for #453. Turns out MinGW gcc's current `thread_local` implementation breaks _at runtime._ So a simple compilation check won't detect the pro... — committed to jtv/libpqxx by jtv 3 years ago
- For #453: MinGW's gcc 11.0 is also broken. — committed to jtv/libpqxx by jtv 3 years ago
On windows you can already install gcc-11. Why do you mention linux distributions if you have windows issue?