On Wed, Oct 28, 2026 at 4:57 PM Stefan Schulze Frielinghaus
<[email protected]> wrote:
>
> On Wed, Oct 28, 2026 at 01:46:24PM +0100, Richard Biener wrote:
> > On Wed, Oct 28, 2026 at 12:45 PM Stefan Schulze Frielinghaus
> > <[email protected]> wrote:
> > >
> > > From: Stefan Schulze Frielinghaus <[email protected]>
> >
> > Can you check whether any libstdc++.so provided symbol is affected
> > and add a note indicating the result?
>
> There is probably a pretty way to do this check but I took the dirty
> route and did a bootstrap asserting that nullptr_t type is not passed to
> s390_return_in_memory.  Therefore, symbols should be fine.  Of course
> there are non-symbol related incompatibilities like seen in a LLVM build
>
> include/c++/17.0.0/bits/invoke.h:116:42: note: the ABI for returning 
> 'std::nullptr_t' changed in GCC 17.1; it is now returned in a register 
> instead of in memory
>   116 |         return std::__invoke_impl<__type>(__tag{},
>       |                ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
>   117 |                                           
> std::forward<_Callable>(__fn),
>       |                                           
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   118 |                                           
> std::forward<_Args>(__args)...);
>       |                                           
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> >
> > Btw, what can one do with a nullptr_t result?  So what would be
> > a testcase with two TUs that would fail when both are compiled
> > with incompatible compilers?
>
> This is a question I have been trying to solve for myself for the last
> 24h.  Bear with me; I wouldn't describe myself as a C++ expert ;)
> It seems to me that there is some sort of a pattern in C++ where due to
> templates, instances with a nullptr_t could arise.  But not only through
> templates but also due to auto.  In combination with lambdas this seems
> to be somewhat of a thing.  For example, in LLVM DebugInfoMetadata.cpp
> we have
>
> template <typename ScopeT, typename NodeT>
> static ScopeT getRawRetainedNodeScopeInternal(NodeT *N) {
>   auto getScopeLambda = [](auto *N) { return getScope(N); };
>   return DISubprogram::visitRetainedNode<ScopeT>(
>       N, getScopeLambda, getScopeLambda, getScopeLambda, getScopeLambda,
>       getScopeLambda, [](auto *N) { return nullptr; });
> }
>
> For the lambda the auto deduced return type becomes nullptr_t.
>
> At first I had hoped to skip the note/diagnostics for functions without
> linkage and for which the address is not taken.  However, this seems to
> be not easily doable due to how TARGET_RETURN_IN_MEMORY is used.
>
> What makes this whole situation particularly nasty is that if a value is
> returned in memory, then we pass a hidden argument for the pointer and
> this hidden argument is assigned the first argument register.  This
> means, all other arguments are passed in a register N+1.  Therefore, a
> return value also affects how arguments are passed.  For example:
>
> Let TU-1 be compiled with GCC <17
>
> nullptr_t foo (int x)
> {
>   return nullptr;
> }
>
> and TU-2 be compiled with GCC 17/Clang
>
> extern nullptr_t foo (int);
> int main (void)
> {
>   foo (0);
> }
>
> then we will run into a segfault because foo() expects in r2 the hidden
> argument where to store the return value whereas main() passes the real
> first argument aka x in r2 which is zero leading to the segfault once
> dereferenced.

Oh.

> I could certainly document this more verbose, but it doesn't change the
> fact that this is a messy situation.

I was hoping we could have documented it as a non-observable issue,
but the point above makes that moot ...

Richard.

> Cheers,
> Stefan
>
> >
> > > ---
> > >  htdocs/gcc-17/changes.html | 12 ++++++++++++
> > >  1 file changed, 12 insertions(+)
> > >
> > > diff --git a/htdocs/gcc-17/changes.html b/htdocs/gcc-17/changes.html
> > > index 68717be56..ccbfa4957 100644
> > > --- a/htdocs/gcc-17/changes.html
> > > +++ b/htdocs/gcc-17/changes.html
> > > @@ -250,6 +250,18 @@ for general information.</p>
> > >    <li>Support for <code>-m31</code> was removed and as a consequence
> > >        <code>-mesa</code> support.
> > >    </li>
> > > +
> > > +  <li id="s390_return_nullptr_type">
> > > +    Starting with GCC 4.6 (which introduced initial C++11 and
> > > +    <code>std::nullptr_t</code> support), arguments of type
> > > +    <code>nullptr_t</code> / <code>std::nullptr_t</code> /
> > > +    <code>decltype(nullptr)</code> are passed in registers. However, 
> > > return
> > > +    values are erroneously returned in memory violating the psABI. This 
> > > is
> > > +    fixed in GCC 17 so that <code>nullptr_t</code> et al. are returned 
> > > in a
> > > +    register (<code>%r2</code>), matching argument passing and the psABI.
> > > +    Functions returning <code>nullptr_t</code> compiled with GCC 17 are
> > > +    ABI-incompatible with binaries compiled by older GCC versions.
> > > +  </li>
> > >  </ul>
> > >
> > >  <!-- <h3 id="riscv">RISC-V</h3> -->
> > > --
> > > 2.55.0
> > >

Reply via email to