RISC-V: Fix 32-bit stack pointer alignment problem.

Message ID 20180417214829.15259-1-jimw@sifive.com
State New
Headers show
Series
  • RISC-V: Fix 32-bit stack pointer alignment problem.
Related show

Commit Message

Jim Wilson April 17, 2018, 9:48 p.m.
This fixes the problem that Kito Cheng just reported, where the stack doesn't
have ABI required alignment for 32-bit targets.  This was an unintended side
effect of my previous change to fix a gcc bootstrap build failure.

This was tested with riscv{32,64}-{elf,linux} cross compilers and testsuite
runs.  There were no regressions.

Jim

	gcc/
	PR 84856
	* config/riscv/riscv.c (riscv_compute_frame_info): Add calls to
	RISCV_STACK_ALIGN when using outgoing_args_size and pretend_args_size.
	Set arg_pointer_offset after using pretend_args_size.
---
 gcc/config/riscv/riscv.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

-- 
2.14.1

Patch

diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index 9e1005e8f10..2870177fa97 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -3307,7 +3307,7 @@  riscv_compute_frame_info (void)
     }
 
   /* At the bottom of the frame are any outgoing stack arguments. */
-  offset = crtl->outgoing_args_size;
+  offset = RISCV_STACK_ALIGN (crtl->outgoing_args_size);
   /* Next are local stack variables. */
   offset += RISCV_STACK_ALIGN (get_frame_size ());
   /* The virtual frame pointer points above the local variables. */
@@ -3333,9 +3333,11 @@  riscv_compute_frame_info (void)
   frame->hard_frame_pointer_offset = offset;
   /* Above the hard frame pointer is the callee-allocated varags save area. */
   offset += RISCV_STACK_ALIGN (cfun->machine->varargs_size);
-  frame->arg_pointer_offset = offset;
   /* Next is the callee-allocated area for pretend stack arguments.  */
-  offset += crtl->args.pretend_args_size;
+  offset += RISCV_STACK_ALIGN (crtl->args.pretend_args_size);
+  /* Arg pointer must be below pretend args, but must be above alignment
+     padding.  */
+  frame->arg_pointer_offset = offset - crtl->args.pretend_args_size;
   frame->total_size = offset;
   /* Next points the incoming stack pointer and any incoming arguments. */