[PATCH v2] Mark swapcontext returns_twice by default [BZ #23130]

Andreas Schwab schwab@suse.de
Mon Sep 21 12:33:37 GMT 2026


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)
      | ^~~~~~~~~~~~~~~~~~~

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


More information about the Libc-alpha mailing list