From: Stian Halseth <stian@itx.no>
To: Andreas Schwab <schwab@suse.de>
Cc: libc-alpha@sourceware.org, adhemerval.zanella@linaro.org, sam@gentoo.org
Subject: Re: [PATCH v2] Mark swapcontext returns_twice by default [BZ #23130]
Date: Mon, 21 Sep 2026 15:05:51 +0200 [thread overview]
Message-ID: <4882cced3cc63a9b1a788bd2e8bbd791d7143bd4.camel@itx.no> (raw)
In-Reply-To: <mvmwlsebx7i.fsf@suse.de>
[-- Attachment #1: Type: text/plain, Size: 5095 bytes --]
Hi Andreas,
On Mon, 2026-09-21 at 14:33 +0200, Andreas Schwab wrote:
> On Sep 04 2026, Stian Halseth wrote:
>
> > diff --git a/bits/indirect-return.h b/bits/indirect-return.h
> > index 819bd25b..ba2efb06 100644
> > --- a/bits/indirect-return.h
> > +++ b/bits/indirect-return.h
> > @@ -21,5 +21,10 @@
> > #endif
> >
> > /* __INDIRECT_RETURN is used on swapcontext to indicate if it
> > requires
> > - special compiler treatment. */
> > -#define __INDIRECT_RETURN
> > + special compiler treatment. swapcontext does not restore every
> > + callee-saved register on all targets. */
> > +#if __glibc_has_attribute (__returns_twice__)
> > +# define __INDIRECT_RETURN __attribute__ ((__returns_twice__))
> > +#else
> > +# define __INDIRECT_RETURN
> > +#endif
> > diff --git a/string/tst-xbzero-opt.c b/string/tst-xbzero-opt.c
> > index 3aa13d03..26e2ec1c 100644
> > --- a/string/tst-xbzero-opt.c
> > +++ b/string/tst-xbzero-opt.c
> > @@ -111,10 +111,9 @@ use_test_buffer (unsigned char *buf)
> > /* Always check the test buffer immediately after filling it; this
> > makes externally visible side effects depend on the buffer
> > existing
> > and having been filled in. */
> > -#if defined __CET__ && !__glibc_has_attribute
> > (__indirect_return__)
> > -/* Note: swapcontext returns via indirect branch when SHSTK is
> > enabled.
> > - Without indirect_return attribute, swapcontext is marked with
> > - returns_twice attribute, which prevents always_inline to work.
> > */
> > +#if !__glibc_has_attribute (__indirect_return__)
> > +/* Without indirect_return, swapcontext is marked returns_twice,
> > which
> > + prevents always_inline from working. */
>
> Why does that use a different condition? The comment does not make
> sense, and it breaks RISC-V.
>
> tst-xbzero-opt.c: In function ‘prepare_test_buffer’:
> tst-xbzero-opt.c:122:1: error: function ‘prepare_test_buffer’ can
> never be inlined because it uses setjmp
> 122 | prepare_test_buffer (unsigned char *buf)
> | ^~~~~~~~~~~~~~~~~~~
>
Sorry for introducing that regression on RISC-V.
My testing on x86_64/sparc64 missed it, but I _think_ I understand the
problem.
Will try to do better, still learning :)
...and the comment in tst-xbzero-opt.c ("Without indirect_return,
swapcontext is marked returns_twice") refers to x86 header fallback as
if it were general, which it isn't.
Could we instead define __INDIRECT_RETURN_RETURNS_TWICE, and do
something like this?
diff --git a/bits/indirect-return.h b/bits/indirect-return.h
index ba2efb067..c6e967c9c 100644
--- a/bits/indirect-return.h
+++ b/bits/indirect-return.h
@@ -25,6 +25,7 @@
callee-saved register on all targets. */
#if __glibc_has_attribute (__returns_twice__)
# define __INDIRECT_RETURN __attribute__ ((__returns_twice__))
+# define __INDIRECT_RETURN_RETURNS_TWICE 1
#else
# define __INDIRECT_RETURN
#endif
diff --git a/string/tst-xbzero-opt.c b/string/tst-xbzero-opt.c
index 26e2ec1c1..625413cd8 100644
--- a/string/tst-xbzero-opt.c
+++ b/string/tst-xbzero-opt.c
@@ -111,9 +111,9 @@ use_test_buffer (unsigned char *buf)
/* Always check the test buffer immediately after filling it; this
makes externally visible side effects depend on the buffer existing
and having been filled in. */
-#if !__glibc_has_attribute (__indirect_return__)
-/* Without indirect_return, swapcontext is marked returns_twice, which
- prevents always_inline from working. */
+#ifdef __INDIRECT_RETURN_RETURNS_TWICE
+/* swapcontext is marked returns_twice, which prevents always_inline
+ from working. */
# define ALWAYS_INLINE
#else
# define ALWAYS_INLINE __attribute__ ((always_inline))
diff --git a/sysdeps/aarch64/bits/indirect-return.h
b/sysdeps/aarch64/bits/indirect-return.h
index 919fbdad6..75116cbb9 100644
--- a/sysdeps/aarch64/bits/indirect-return.h
+++ b/sysdeps/aarch64/bits/indirect-return.h
@@ -31,6 +31,7 @@
#elif __glibc_has_attribute (__returns_twice__) \
&& defined __ARM_FEATURE_GCS_DEFAULT
# define __INDIRECT_RETURN __attribute__ ((__returns_twice__))
+# define __INDIRECT_RETURN_RETURNS_TWICE 1
#else
# define __INDIRECT_RETURN
#endif
diff --git a/sysdeps/x86/bits/indirect-return.h
b/sysdeps/x86/bits/indirect-return.h
index f33d8ccf0..ee3834e52 100644
--- a/sysdeps/x86/bits/indirect-return.h
+++ b/sysdeps/x86/bits/indirect-return.h
@@ -31,6 +31,7 @@
it we can use returns_twice to affect the optimizer in the same
way and avoid unsafe optimizations. */
# define __INDIRECT_RETURN __attribute__ ((__returns_twice__))
+# define __INDIRECT_RETURN_RETURNS_TWICE 1
# endif
#else
# define __INDIRECT_RETURN
If this approach makes sense, I would write up, and send a new patch
along those lines later today.
I did a quick test with this, but again, not tested on RISC-V, so that,
and the idea should probably be validated by someone with a bit more
experience.
--
Best regards
Stian Halseth
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-09-21 13:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 12:43 [PATCH] Mark swapcontext returns_twice without indirect_return " Stian Halseth
2026-09-04 14:20 ` Adhemerval Zanella Netto
2026-09-04 15:29 ` [PATCH v2] Mark swapcontext returns_twice by default " Stian Halseth
2026-09-04 18:32 ` Adhemerval Zanella Netto
2026-09-15 21:00 ` Stian Halseth
2026-09-16 12:02 ` Adhemerval Zanella Netto
2026-09-16 12:33 ` Stian Halseth
2026-09-21 12:33 ` Andreas Schwab
2026-09-21 13:05 ` Stian Halseth [this message]
2026-09-21 13:14 ` Andreas Schwab
2026-09-21 20:36 ` Stian Halseth
2026-09-21 20:39 ` [PATCH] string: Drop always_inline from tst-xbzero-opt " Stian Halseth
2026-09-25 10:43 ` Stian Halseth
2026-09-25 13:03 ` Adhemerval Zanella Netto
2026-09-25 11:11 ` Adhemerval Zanella Netto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4882cced3cc63a9b1a788bd2e8bbd791d7143bd4.camel@itx.no \
--to=stian@itx.no \
--cc=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
--cc=sam@gentoo.org \
--cc=schwab@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).