Seeking guidance on how to implement -fdeclone-ctor-dtor for targets with HAVE_COMDAT_GROUPS=0

Peter0x44 peter0x44@disroot.org
Sat Nov 8 14:42:33 GMT 2025


Hi all,

I’m chasing down a fix for PR108383 that is related to 
-fdeclone-ctor-dtor. For reference, here is how the ICE looks:

   lto1: error: Two symbols with same comdat_group are not linked by the 
same_comdat_group list.
   lto1: internal compiler error: symtab_node::verify failed

I think the bug occurs across two locations in gcc/cp/optimize.cc:

1. In maybe_clone_body() around line 568:
    if (DECL_ONE_ONLY (fn))
      cgraph_node::get_create (clone)->set_comdat_group (cxx_comdat_group 
(clone));

    This sets comdat_group on clones REGARDLESS of HAVE_COMDAT_GROUP.

2. In maybe_thunk_body() around line 311-356:
    if (!DECL_WEAK (fn))
      { /* Handle non-weak: make local */ }
    else if (HAVE_COMDAT_GROUP)
      { /* Link symbols via same_comdat_group list */ }

When DECL_WEAK && !HAVE_COMDAT_GROUP, maybe_thunk_body() falls through
without calling add_to_same_comdat_group(). The clones already have
comdat_group identifiers (from maybe_clone_body), but they're never
linked via same_comdat_group. I think this is why the symtab verifier
is giving an ICE.

There are a few other locations that call set_comdat_group without 
checking HAVE_COMDAT_GROUP.
I tried patching them all, but instead I ended up with multiple 
definition errors when linking:

/home/peter/wintoolchain/lib/gcc/x86_64-w64-mingw32/16.0.0/../../../../x86_64-w64-mingw32/bin/ld: 
externals/simplecpp/simplecpp.o (symbol from plugin):(.text+0x0): 
multiple definition of `typeinfo name for std::runtime_error'; 
cli/threadexecutor.o (symbol from plugin):(.text+0x0): first defined 
here

Does anyone have ideas on how I can implement -fdeclone-ctor-dtor 
without using comdat groups?
Or if I'm going wrong anywhere with my approach?

Regards,
Peter Damianov.


More information about the Gcc mailing list