I discovered that the stack-smashing protection options (-fstack-protector and friends) were rejected on nios2 because this backend wasn't defining FRAME_GROWS_DOWNWARD. There doesn't seem to be any particular reason not to enable that, so here I've switched it on.

Committed after regression testing on nios2-linux-gnu. I've also got this working for nios2-elf on a local branch in conjunction with BSP library support and this patch

https://gcc.gnu.org/ml/gcc-patches/2017-10/msg00537.html

which is still awaiting review.

-Sandra

2017-10-28  Sandra Loosemore  <san...@codesourcery.com>

	gcc/
	* config/nios2/nios2.h (FRAME_GROWS_DOWNWARD): Define to 1.
	* config/nios2/nios2.c (nios2_initial_elimination_offset):  Make
	FRAME_POINTER_REGNUM point at high end of local var area.
diff --git a/gcc/config/nios2/nios2.h b/gcc/config/nios2/nios2.h
index 420543e..9fdff02 100644
--- a/gcc/config/nios2/nios2.h
+++ b/gcc/config/nios2/nios2.h
@@ -252,6 +252,7 @@ enum reg_class
 
 /* Stack layout.  */
 #define STACK_GROWS_DOWNWARD 1
+#define FRAME_GROWS_DOWNWARD 1
 #define FIRST_PARM_OFFSET(FUNDECL) 0
 
 /* Before the prologue, RA lives in r31.  */
diff --git a/gcc/config/nios2/nios2.c b/gcc/config/nios2/nios2.c
index cdd5e9a..5c70de7 100644
--- a/gcc/config/nios2/nios2.c
+++ b/gcc/config/nios2/nios2.c
@@ -1114,7 +1114,9 @@ nios2_initial_elimination_offset (int from, int to)
   switch (from)
     {
     case FRAME_POINTER_REGNUM:
-      offset = cfun->machine->args_size;
+      /* This is the high end of the local variable storage, not the
+	 hard frame pointer.  */
+      offset = cfun->machine->args_size + cfun->machine->var_size;
       break;
 
     case ARG_POINTER_REGNUM:

Reply via email to