> 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?
> 
> 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.

====

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).

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.


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.


>> 
>> 
>> Ciao,
>> Michael.


Reply via email to