Skip to content

std::call_once always segfaults on MinGW (regression 11->12) #49490

@HolyBlackCat

Description

@HolyBlackCat
Bugzilla Link 50146
Resolution FIXED
Resolved on Jun 10, 2021 00:45
Version unspecified
OS Windows NT
CC @mstorsjo,@zygoloid

Extended Description

Any use of std::call_once on MinGW causes a segfault. It used to work in Clang 11, but broke in 12.

Minimal example:
#include
#include

int main()
{
    std::once_flag flag;
    std::call_once(flag, []{std::cout << "Once!\n";});
}

The clang version is: Ubuntu clang version 12.0.1-++20210423082613+072c90a863aa-1exp120210423063319.76

The flags I use: clang++-12 --version --target=x86_64-w64-mingw32 --sysroot=/mingw64 -pthread -femulated-tls

The libstdc++ comes from MSYS2 GCC 10.2.0 (rev 10).

Here's what GDB says if I add -g:
Program received signal SIGSEGV, Segmentation fault.
0x00000001e014dc4a in ?? () from Z:\home\holyblackcat\Sandbox\2\libgcc_s_seh-1.dll
(gdb) bt
#​0 0x00000001e014dc4a in ?? () from Z:\home\holyblackcat\Sandbox\2\libgcc_s_seh-1.dll
#​1 0x00000000004015f3 in std::call_oncemain::$_0 (__once=..., __f=...) at /mingw64/include/c++/10.2.0/mutex:721
#​2 0x00000000004015b5 in main () at 1.cpp:8
(gdb) f 1
#​1 0x00000000004015f3 in std::call_oncemain::$_0 (__once=..., __f=...) at /mingw64/include/c++/10.2.0/mutex:721
721 __once_callable = std::__addressof(__callable);
(gdb) list
716 auto __callable = [&] {
717 std::__invoke(std::forward<_Callable>(__f),
718 std::forward<_Args>(__args)...);
719 };
720 #ifdef _GLIBCXX_HAVE_TLS
721 __once_callable = std::__addressof(__callable);
722 __once_call = []{ ((decltype(__callable))__once_callable)(); };
723 #else
724 unique_lock __functor_lock(__get_once_mutex());
725 __once_functor = __callable;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclangClang issues not falling into any other category

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions