On Wed, Jun 24, 2026 at 3:33 AM Eldar Osmanovic
<[email protected]> wrote:
>
> From: Matthew Fortune <[email protected]>
>
> Ensure the frame barrier prevents reordering of stack pointer changes.
>
> It is possible for a load/store accessing the stack via a copy of the
> stack pointer to be moved across the epilogue meaning that it accesses
> stack that is no longer allocated. This leads to a situation where the
> code is unsafe in the event of an interrupt where the same stack is
> used for interrupt handling.
>
> gcc/
>         * config/mips/mips.cc (mips_frame_barrier): Upgrade to a full
>         blockage.

Ok.

>
> gcc/testsuite/
>         * gcc.target/mips/frame-barrier-1.c: New test.
>
> Cherry-picked 0c240da6f6032bd19348b97148d25c05ba2e8356
> from https://github.com/MIPS/gcc
>
> Signed-off-by: Matthew Fortune <[email protected]>
> Signed-off-by: Faraz Shahbazker <[email protected]>
> Signed-off-by: Aleksandar Rakic <[email protected]>
> Signed-off-by: Eldar Osmanovic <[email protected]>
> ---
>  gcc/config/mips/mips.cc                         |  2 +-
>  gcc/testsuite/gcc.target/mips/frame-barrier-1.c | 15 +++++++++++++++
>  2 files changed, 16 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/mips/frame-barrier-1.c
>
> diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
> index 3f123523849..fdbb0a764bd 100644
> --- a/gcc/config/mips/mips.cc
> +++ b/gcc/config/mips/mips.cc
> @@ -12391,7 +12391,7 @@ mips_output_function_epilogue (FILE *)
>  static void
>  mips_frame_barrier (void)
>  {
> -  emit_clobber (gen_frame_mem (BLKmode, stack_pointer_rtx));
> +  emit_insn (gen_blockage ());
>  }
>
>
> diff --git a/gcc/testsuite/gcc.target/mips/frame-barrier-1.c 
> b/gcc/testsuite/gcc.target/mips/frame-barrier-1.c
> new file mode 100644
> index 00000000000..b49dab505df
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/mips/frame-barrier-1.c
> @@ -0,0 +1,15 @@
> +/* { dg-do compile } */
> +/* { dg-options "-mabi=32 -march=mips32r2 -mno-abicalls -fno-pic 
> -fdump-rtl-final" } */
> +
> +extern void use (char *);
> +
> +int
> +f (int n)
> +{
> +  char * p = (char *) __builtin_alloca (n);
> +
> +  use (p);
> +  return p[0];
> +}
> +
> +/* { dg-final { scan-rtl-dump-times "UNSPEC_BLOCKAGE" 3 "final" } } */
> --
> 2.43.0

Reply via email to