On 11/4/26 11:49 AM, Iain Sandoe wrote:
On 4 Nov 2026, at 15:02, Richard Biener <[email protected]> wrote:
On Wed, Nov 4, 2026 at 4:00 PM Michael Matz <[email protected]> wrote:
Hello,
On Wed, 4 Nov 2026, Iain Sandoe wrote:
At -Os, -fdeclone-ctor-dtor is enabled, which splits a cdtor into a unified
body (C4) plus C1/C2 thunks.
A TU that inlines a thunk therefore materialises a call to a C4 whose
own offline body is DECL_EXTERNAL (but emitted by nobody), and the
link fails with an undefined reference.
And if the C1/2 thunks are not inlined: which entity emits their body?
And why is that entity then not also the responsible one for emitting the
C4 body? This all sounds rather like a problem in setting up the
properties of the C1/2/4 symbols and not in the inliner?
Or rather if the C4 body has no public symbol, why is it also covered by
this rule, thus why is it DECL_EXTERNAL as well and not simply static?
On HAVE_COMDAT_GROUPS targets it's static; on other targets we don't
want to bloat by emitting a static copy in every TU, so we emit a
weak/one-only copy to go with the C1/2 that uses it. Except in this
case the extern template tells us not to emit it, so we don't.
I don't know if DECL_EXTERNAL is the right test or if get_availability
would be better?
Or, why is a C4 body there in the first place for an extern template and
not only instantiated separately on demand?
I don’t think anyone is saying that the inliner is at fault here, what I am
saying is that it is missing a piece of information that should forbid an
inline in specific cases.
We have to materialise the body to make it available for inlining, so it
does not seem possible to do it on demand.
It is instantiated on demand, along with the C1/2 that call it. It just
isn't emitted.
====
An alternative is to make a FE-only patch that causes a weak-hidden C4 to
be emitted when needed. Those would coalesce within one DSO but
leave the ABI the same as today (I *think* that also would work for Windows
but I am no expert).
That would be disobeying the extern template instruction not to emit
anything for that function.
The penalty for that is that we specify -Os but the binary grows by the
size of how ever many C4s we use - where with the current patch it
just calls the C1 in libstdc++.
The `extern template` markup says: “this function is going to be
available externally so do not emit its body; however do materialise
it’s body for the purposes of inlining”
So the build must provide one TU that overrides the `extern template` to
provide the function impl. for cases that do not inline (in the case of
the std::string fns. that TU is part of libstc++).
This is fine for C1/2 where they are emitted according to the ABI, but
it does not work for C4 which is an internal implementation detail and
is not emitted (and we do not want to emit it).
And why not? It seems to me that when (a) C1/2 are emitted for other TUs
use, and (b) -fdeclone-ctor-dtor says "but please commonize their body
into a C4 helper" that then it follows that C4 should be emitted at the
place where C1/2 are.
If the other TU is also compiled with -fdeclone-ctor-dtor, yes. But in
this case it isn't.
The inlining adjustment seems like the right path to me: if we can't
inline the whole constructor, inline none of it.
That needs someone who was “there at the time” to answer why it was not
part of Itanium, I assume there’s a good reason.
The ABI committee was optimistic about the ability/inclination of
compilers to implement C1/C2 as two entry points to the same function
rather than two separate functions. Instead we got clones. And then
later there was demand for decloning.
Jason