msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.25k stars 1.21k forks source link

[boost] libboost_fiber-mt.dll missing in mingw32 package #7071

Closed Facon closed 2 years ago

Facon commented 4 years ago

Hello everyone,

I would like to know how can I link a very simple application with boost fibers.

I am getting linking errors that says that fiber references are missing. I confirm that doing objectdump on all *.a doesn't show any reference to fiber's classes.

I show below files that I'm using.

CMakeLists.txt

cmake_minimum_required (VERSION 3.13)

set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)

project(Fibers VERSION 0.1.0.0)

find_package(Boost 1.73.0 REQUIRED)
#include(${PROJECT_BINARY_DIR}/conanbuildinfo.cmake)
#conan_basic_setup(TARGETS)

add_executable(${PROJECT_NAME})

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU")
    target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wunreachable-code -Wpedantic)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    target_compile_options(${PROJECT_NAME} PRIVATE -Wweak-vtables -Wexit-time-destructors -Wglobal-constructors -Wmissing-noreturn)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
    foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG
            CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL
            CMAKE_CXX_FLAGS_RELWITHDEBINFO)
        if(${flag_var} MATCHES "/MD")
            string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
        endif(${flag_var} MATCHES "/MD")
    endforeach(flag_var)
    target_compile_options(${PROJECT_NAME} PRIVATE /w44265 /w44061 /w44062)
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES
    EXPORT_NAME ${PROJECT_NAME}
    CXX_STANDARD 14
    CXX_STANDARD_REQUIRED YES
    CXX_EXTENSIONS NO
    DEBUG_POSTFIX "d"
    INTERPROCEDURAL_OPTIMIZATION True
    )

target_include_directories(${PROJECT_NAME}
    PUBLIC
    $<INSTALL_INTERFACE:include>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_sources(${PROJECT_NAME}
    PRIVATE
    include/sample.h
    src/sample.cpp
)

target_link_libraries (${PROJECT_NAME}
    PRIVATE
        ${Boost_LIBRARIES}
)

src/sample.cpp

#include <iostream>
#include <boost/fiber/all.hpp>

int main()
{
    boost::fibers::fiber f1(
    []
    {
        std::cout << "Hello world!\n";
    });

    f1.join();

    return 0;
}

Linking error

14:49:53: Running steps for project Fibers...
14:49:53: Starting: "C:\msys64\mingw32\bin\cmake.exe" --build . --target all
[ 50%] Linking CXX executable Fibersd.exe
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj):C:/Users/User/Documents/Sources/testing/fibers/src/sample.cpp:12: undefined reference to `boost::fibers::fiber::join()'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj):C:/msys64/mingw32/include/boost/fiber/fiber.hpp:67: undefined reference to `boost::context::stack_traits::default_size()'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj):C:/msys64/mingw32/include/boost/fiber/fiber.hpp:109: undefined reference to `boost::fibers::fiber::start_()'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj):C:/msys64/mingw32/include/boost/fiber/context.hpp:448: undefined reference to `boost::fibers::context::~context()'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj):C:/msys64/mingw32/include/boost/fiber/context.hpp:438: undefined reference to `boost::fibers::context::terminate()'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj):C:/msys64/mingw32/include/boost/context/fiber_fcontext.hpp:193: undefined reference to `make_fcontext'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj): in function `create_fiber2<boost::context::detail::fiber_record<boost::context::fiber, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, std::_Bind<boost::context::fiber (boost::fibers::worker_context<main()::<lambda()> >::*(boost::fibers::worker_context<main()::<lambda()> >*, std::_Placeholder<1>))(boost::context::fiber&&)> >, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, std::_Bind<boost::context::fiber (boost::fibers::worker_context<main()::<lambda()> >::*(boost::fibers::worker_context<main()::<lambda()> >*, std::_Placeholder<1>))(boost::context::fiber&&)> >':
C:/msys64/mingw32/include/boost/context/fiber_fcontext.hpp:196: undefined reference to `jump_fcontext'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj):C:/msys64/mingw32/include/boost/context/fiber_fcontext.hpp:78: undefined reference to `jump_fcontext'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj): in function `fiber_entry<boost::context::detail::fiber_record<boost::context::fiber, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, std::_Bind<boost::context::fiber (boost::fibers::worker_context<main()::<lambda()> >::*(boost::fibers::worker_context<main()::<lambda()> >*, std::_Placeholder<1>))(boost::context::fiber&&)> > >':
C:/msys64/mingw32/include/boost/context/fiber_fcontext.hpp:89: undefined reference to `ontop_fcontext'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj):C:/msys64/mingw32/include/boost/fiber/context.hpp:415: undefined reference to `boost::fibers::context::~context()'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj): in function `ZN5boost7context5fiberD1Ev':
C:/msys64/mingw32/include/boost/context/fiber_fcontext.hpp:261: undefined reference to `ontop_fcontext'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj): in function `ZNO5boost7context5fiber6resumeEv':
C:/msys64/mingw32/include/boost/context/fiber_fcontext.hpp:288: undefined reference to `jump_fcontext'
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\Fibers.dir/objects.a(sample.cpp.obj): in function `ZN5boost6fibers7contextC2EjNS0_4typeENS0_6launchE':
C:/msys64/mingw32/include/boost/fiber/context.hpp:200: undefined reference to `vtable for boost::fibers::context'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [CMakeFiles\Fibers.dir\build.make:106: Fibersd.exe] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:95: CMakeFiles/Fibers.dir/all] Error 2
mingw32-make: *** [Makefile:103: all] Error 2
14:49:54: The process "C:\msys64\mingw32\bin\cmake.exe" exited with code 2.
Error while building/deploying project Fibers (kit: MinGW 10 32-bit)
When executing step "CMake Build"
14:49:54: Elapsed time: 00:01.
Biswa96 commented 4 years ago

This command compiles your code: g++ test.cpp -lboost_fiber-mt -lboost_context-mt

Facon commented 4 years ago

@Biswa96

This command compiles your code: g++ test.cpp -lboost_fiber-mt -lboost_context-mt

I get the following error:

User@DESKTOP-LC9EG87 MINGW32 /c/Users/User/Documents/Sources/testing/fibers/src
$ pacman -Ql mingw-w64-i686-boost | grep libboost
mingw-w64-i686-boost /mingw32/bin/libboost_atomic-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_chrono-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_container-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_context-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_contract-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_coroutine-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_date_time-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_filesystem-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_graph-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_iostreams-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_locale-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_log-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_log_setup-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_math_c99-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_math_c99f-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_math_c99l-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_math_tr1-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_math_tr1f-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_math_tr1l-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_nowide-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_numpy38-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_prg_exec_monitor-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_program_options-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_python38-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_random-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_regex-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_serialization-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_stacktrace_noop-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_stacktrace_windbg-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_system-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_thread-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_timer-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_type_erasure-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_unit_test_framework-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_wave-mt.dll
mingw-w64-i686-boost /mingw32/bin/libboost_wserialization-mt.dll
mingw-w64-i686-boost /mingw32/lib/libboost_atomic-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_atomic-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_chrono-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_chrono-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_container-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_container-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_context-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_context-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_contract-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_contract-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_coroutine-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_coroutine-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_date_time-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_date_time-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_exception-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_filesystem-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_filesystem-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_graph-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_graph-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_iostreams-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_iostreams-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_locale-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_locale-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_log-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_log-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_log_setup-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_log_setup-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_c99-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_c99-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_c99f-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_c99f-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_c99l-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_c99l-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_tr1-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_tr1-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_tr1f-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_tr1f-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_tr1l-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_math_tr1l-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_nowide-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_nowide-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_numpy38-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_numpy38-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_prg_exec_monitor-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_prg_exec_monitor-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_program_options-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_program_options-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_python38-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_python38-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_random-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_random-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_regex-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_regex-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_serialization-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_serialization-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_stacktrace_noop-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_stacktrace_noop-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_stacktrace_windbg-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_stacktrace_windbg-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_system-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_system-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_test_exec_monitor-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_thread-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_thread-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_timer-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_timer-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_type_erasure-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_type_erasure-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_unit_test_framework-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_unit_test_framework-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_wave-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_wave-mt.dll.a
mingw-w64-i686-boost /mingw32/lib/libboost_wserialization-mt.a
mingw-w64-i686-boost /mingw32/lib/libboost_wserialization-mt.dll.a

User@DESKTOP-LC9EG87 MINGW32 /c/Users/User/Documents/Sources/testing/fibers/src
$ g++ sample.cpp -lboost_fiber-mt -lboost_context-mt
C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lboost_fiber-mt
collect2.exe: error: ld returned 1 exit status
lazka commented 4 years ago

Diffing both packages shows libboost_fiber-mt.dll and libboost_stacktrace_windbg_cached-mt.dll are missing. No idea

revelator commented 4 years ago

thread local storage seems to be misdetected for the fiber library, if you remove the requirement check for it in libs/fiber/build/jamfile.v2 it builds no problem.

jeremyd2019 commented 4 years ago

That sounds a bit like what happened with libstdc++ in #7043.

revelator commented 4 years ago

That may very well be the case aye.

revelator commented 4 years ago
In file included from libs\stacktrace\build\..\src\windbg_cached.cpp:10:
./boost/stacktrace/detail/frame_msvc.ipp:176:5: error: #error Your compiler does not support C++11 thread_local storage. It`s impossible to build with BOOST_STACKTRACE_USE_WINDBG_CACHED.
  176 | #   error Your compiler does not support C++11 thread_local storage. It`s impossible to build with BOOST_STACKTRACE_USE_WINDBG_CACHED.

damn...

lazka commented 4 years ago

google gives me this:

  1. http://boost.2283326.n4.nabble.com/stacktrace-1-65-0-RC1-fails-to-build-for-MSYS2-mingw-w64-td4697777.html
  2. https://github.com/boostorg/stacktrace/commit/cd420b37ae7e84196cdb8202e489d5d276c55f0b
  3. https://sourceforge.net/p/mingw-w64/bugs/527/
  4. -> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83562 <-

I guess confirming that the gcc bug still exists and report it in the bugtracker would be a good next step.

revelator commented 4 years ago

That would probably be a good idea, though from what i can read at the gcc bug thread they allready had some idea how to fix it (trampolines) but it newer seems to have been applied.

lazka commented 4 years ago

@Facon so looks like there is no easy fix. I'd advise you to work with the 64bit toolchain instead if possible.

revelator commented 4 years ago

I reported the bug is still active to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83562

Alexpux commented 3 years ago

I see during boost 32 bit configure:

    - Boost.Config Feature Check: cxx11_template_aliases : yes
    - Boost.Config Feature Check: cxx11_thread_local : no
    - Boost.Config Feature Check: cxx11_variadic_templates : yes
Alexpux commented 3 years ago

In boost sources see:

#if (BOOST_GCC_VERSION < 40800) || !defined(BOOST_GCC_CXX11)
#  define BOOST_NO_CXX11_ALIGNAS
#  define BOOST_NO_CXX11_THREAD_LOCAL
#  define BOOST_NO_CXX11_SFINAE_EXPR
#endif
...
#if defined(__MINGW32__) && !defined(__MINGW64__)
// Currently (March 2019) thread_local is broken on mingw for all current 32bit compiler releases, see
// https://sourceforge.net/p/mingw-w64/bugs/527/
// Not setting this causes program termination on thread exit.
#define BOOST_NO_CXX11_THREAD_LOCAL
#endif

So it related to https://sourceforge.net/p/mingw-w64/bugs/527/

revelator commented 3 years ago

Been like this since forever and still not fixed, if it was as easy as the commenter in the gcc bug thread said it would have worked a long time ago, so i doubt we will ever see a fix to it unless someone comes up with a patch (it does not seem to be a main agenda for the gcc devs, as long as it works on linux). Might be better to get boost building with mingw clang instead.

Alexpux commented 3 years ago

@revelator at least example from mingw-w64 bugreport dont crash for me

jeremyd2019 commented 3 years ago

It appears that, despite commit messages to the contrary, the cxa_thread_atexit from mingw is being used rather than one from libstdc++, and this cxa_thread_atexit is defined to take a thiscall function pointer, not cdecl. https://sourceforge.net/p/mingw-w64/mingw-w64/ci/v8.0.0/tree/mingw-w64-crt/crt/cxa_thread_atexit.c#l7

revelator commented 3 years ago

So the boost workaround no longer appllies ?. In that case we could remove the BOOST_NO_CXX11_THREAD_LOCAL define and see how it goes from there.

jeremyd2019 commented 3 years ago

I think @Alexpux is one step ahead of you there 😁 https://github.com/msys2/MINGW-packages/commit/c910889ba9a31af6fa93ac3d25ca42b11c558506#diff-78b35e86b9af9094b73ccbd0561f0910

lhmouse commented 3 years ago

If the mingw-w64 __cxa_thread_atexit() uses __thiscall calling convention, then the libstdc++ one should align with it. I think I can send a patch to GCC.

jeremyd2019 commented 3 years ago

I haven't actually seen the destructor be called at thread exit, though. I stepped through the disassembly, and the tls value that mingw was storing its dtor list in was NULL at the time the tls_callback was called. I wonder if libgcc's was called first and cleaned up emutls before that.

EDIT: this appears to be the case (3 == DLL_THREAD_DETACH):

Thread 5 hit Breakpoint 2, 0x00406d70 in emutls_destroy ()
(gdb) c
Continuing.

Thread 5 hit Breakpoint 1, tls_callback (hDllHandle=0x400000, dwReason=3,
    lpReserved=0x0)
    at C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:89
89      in C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c
lhmouse commented 3 years ago

See https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555769.html.

revelator commented 3 years ago

Neat 👍

Seidko commented 2 years ago

If you use clion, you can try change your toolchain to msys2 mingw. Don't use clion bundled mingw.

Biswa96 commented 2 years ago

Workaround available https://github.com/msys2/MINGW-packages/issues/7071#issuecomment-702659710