https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114968
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to LIU Hao from comment #6) > I suspect this isn't correct. I am getting strange errors like 'ld exited > with code 5' not sure what could cause it (possibly also recent MSYS2 > updates): > > ``` > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index 2af026d255d..f5dce6a93bc 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -9669,6 +9669,16 @@ get_atexit_fn_ptr_type (void) > > fn_type = build_function_type_list (void_type_node, > arg_type, NULL_TREE); > +#ifdef IX86_CALLCVT_THISCALL > + if (flag_use_cxa_atexit > + && !targetm.cxx.use_atexit_for_cxa_atexit ()) > + { > + fn_type = copy_node (fn_type); > + TYPE_ATTRIBUTES (fn_type) = tree_cons ( > + get_identifier ("thiscall"), NULL_TREE, > + TYPE_ATTRIBUTES (fn_type)); > + } > +#endif > atexit_fn_ptr_type_node = build_pointer_type (fn_type); > } > > diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc > index f1ffda22fd3..00a8843fa2e 100644 > --- a/gcc/cp/except.cc > +++ b/gcc/cp/except.cc > @@ -648,6 +648,12 @@ build_throw (location_t loc, tree exp, tsubst_flags_t > complain) > { > tree tmp = build_function_type_list (void_type_node, > ptr_type_node, NULL_TREE); > +#ifdef IX86_CALLCVT_THISCALL > + tmp = copy_node (tmp); > + TYPE_ATTRIBUTES (tmp) = tree_cons ( > + get_identifier ("thiscall"), NULL_TREE, > + TYPE_ATTRIBUTES (tmp)); > +#endif > cleanup_type = build_pointer_type (tmp); > } > > > ``` Besides wrong formatting and the case that you need to build_variant_type (or build_distinct_type?, one needs to look at what will be normally done if you do: void (__attribute__((thiscall)) *fn) (void); ), you really can't do it like that. IX86_CALLCVT_THISCALL is defined on all x86_64/i?86 targets, so not limited to mingw 32-bit.