Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Facon opened this issue Oct 1, 2020 · 24 comments
Closed

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

Facon opened this issue Oct 1, 2020 · 24 comments

Comments

@Facon
Copy link

Facon commented Oct 1, 2020

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
Copy link
Member

Biswa96 commented Oct 1, 2020

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

@Facon
Copy link
Author

Facon commented Oct 1, 2020

@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
Copy link
Member

lazka commented Oct 1, 2020

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

@revelator
Copy link
Contributor

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
Copy link
Member

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

@revelator
Copy link
Contributor

That may very well be the case aye.

@lazka lazka changed the title [boost] How to link boost::fibers in MINGW32 environment [boost] libboost_fiber-mt.dll missing in mingw32 package Oct 2, 2020
@revelator
Copy link
Contributor

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
Copy link
Member

lazka commented Oct 2, 2020

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. boostorg/stacktrace@cd420b3
  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
Copy link
Contributor

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
Copy link
Member

lazka commented Oct 2, 2020

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

@revelator
Copy link
Contributor

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

@Alexpux
Copy link
Member

Alexpux commented Oct 7, 2020

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
Copy link
Member

Alexpux commented Oct 7, 2020

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
Copy link
Contributor

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
Copy link
Member

Alexpux commented Oct 7, 2020

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

@jeremyd2019
Copy link
Member

jeremyd2019 commented Oct 7, 2020

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
Copy link
Contributor

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
Copy link
Member

I think @Alexpux is one step ahead of you there 😁
c910889#diff-78b35e86b9af9094b73ccbd0561f0910

@lhmouse
Copy link
Contributor

lhmouse commented Oct 8, 2020

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
Copy link
Member

jeremyd2019 commented Oct 8, 2020

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
Copy link
Contributor

lhmouse commented Oct 8, 2020

@revelator
Copy link
Contributor

Neat 👍

kraj pushed a commit to kraj/gcc that referenced this issue Nov 7, 2020
…se the `__thiscall` calling convention for i686-w64-mingw32

The mingw-w64 implementations of `__cxa_thread_atexit()` and `__cxa_atexit()` have been
using `__thiscall` since two years ago. Using the default calling convention (which is
`__cdecl`) causes crashes as explained in PR83562.

Calling conventions have no effect on x86_64-w64-mingw32.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83562
Reference: https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/crt/cxa_thread_atexit.c
Reference: https://sourceforge.net/p/mingw-w64/mingw-w64/ci/f3e0fbb40cbc9f8821db8bd8a0c4dae8ff671e9f/
Reference: msys2/MINGW-packages#7071
Signed-off-by: Liu Hao <lh_mouse@126.com>

    2020-10-08  Liu Hao  <lh_mouse@126.com>

	libstdc++-v3:
	* libsupc++/cxxabi.h: (__cxa_atexit): mark with _GLIBCXX_CDTOR_CALLABI
	(__cxa_thread_atexit): ditto
	* libsupc++/atexit_thread.cc: (__cxa_atexit): mark with
	_GLIBCXX_CDTOR_CALLABI
	(__cxa_thread_atexit): ditto
	(elt): ditto
@Seidko
Copy link

Seidko commented Dec 30, 2021

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

@Biswa96
Copy link
Member

Biswa96 commented Sep 27, 2022

Workaround available #7071 (comment)

@Biswa96 Biswa96 closed this as completed Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants