Hello,
On Wed, 4 Nov 2026, Jason Merrill wrote:
> >>>>>> 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.
I have difficulties to comprehend the difference of emittance
behaviour between C1/2 and C4. Above you're saying that the C4 copy is
emitted when C1/2 are (in the same way, e.g. weak/one-only). That makes
sense, but ...
> Except in this case the extern template tells us not to emit it, so we
> don't.
... here you're saying (or I think you are) that specifically the C4 one
is exempted because of the 'extern template'. Why is that then either not
also affecting C1/2, or alternatively why is it not also ignoring the
"extern template" behaviour for C4, like it does for C1/2?
What I'm trying to get at: there seems to be no reason to have different
emittance behaviour between C1/2 and C4. Making it different rather
causes only problems. So, why the eye-poking?
> > 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.
And why are C1/2 emitted then? What I'm saying ("C1/2 and C4 should be
emitted under same conditions") is so obvious to me that I must be missing
some detail. Which one?
> >>> 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.
Well, that's a user error then, isn't it? - that option has ABI
implications (namely agreeing on and using a name for the "commonized
body" and depending on its existence).
> 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.
So, in that model C1/2 would be a single unsplittable entity, all is fine.
C4, if it needs to exist, should also be part of that single unsplittable
entity. If this entity is implemented as a single multiple entry point
function, or as two or three hunks towards a single separate function
shouldn't matter. They all need to go together. Of course it needs a
agreeable name for the separate function, that's the implementation choice
we have to live with in that model.
The problem I have with the inliner change is twofold: (a) it shouldn't be
concerned if something is or isn't a constructor, it knows about functions
and thunks, which are just small functions themself, and their names and
if they are or are not defined in the current TU, and their linkage and
visibility, and we all know that already now, so it seems strange to need
new flags, and (b) the situation at hand seems to be similar to the
following code:
C1() { C4(1); } // thunk
C2() { C4(2); } // thunk
C4(int i) { C4real(i); } // thunk?
C4real(int i) { whatever-based-on(i); }
(or C4 being the real body, not a thunk and C4real not existing)
and you want to make it so that inlining C1/2 is avoided when C4 cannot be
inlined. But in the abstract that makes no sense for an inliner. To the
contrary: one of the compiler IPA transformations splits a function
containing an early-out into a small "thunk" (doing the early return) that
calls the meat of the former body. In that scenario you _want_ the thunk
to be inlined and the real body not:
void realbody() { large things; }
void foo(int i) { if (!i) return; realbody(); } // inline this!
The situation doesn't change depending on the availability of 'realbody'.
We want to inline the thunk and we don't want to inline realbody either
way, in particular we want to inline 'foo' even when realbody isn't
inlinable (i.e. your situation). As-is the situation with realbody not
being available currently cannot occur from IPA transformations, because
"realbody" will only be created by outlining and hence be available, but
the inliner itself shouldn't be concerned about that.
Ciao,
Michael.