https://gcc.gnu.org/g:61db64a590e577866579a830c056f257b607a4f1
commit r17-1977-g61db64a590e577866579a830c056f257b607a4f1 Author: Matthew Fortune <[email protected]> Date: Mon Jun 29 09:12:23 2026 -0600 MIPS: Frame barrier fix 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. Cherry-picked 0c240da6f6032bd19348b97148d25c05ba2e8356 from https://github.com/MIPS/gcc gcc/ * config/mips/mips.cc (mips_frame_barrier): Upgrade to a full blockage. gcc/testsuite/ * gcc.target/mips/frame-barrier-1.c: New test. 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]> Diff: --- gcc/config/mips/mips.cc | 2 +- gcc/testsuite/gcc.target/mips/frame-barrier-1.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index 277ec4198260..80828ed20afc 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -12388,7 +12388,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 000000000000..b49dab505df3 --- /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" } } */
