This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PR7297: Fix size of sjlj's jbuf for MIPS


This patch fixes a long-standing failure in sjlj for MIPS.  The problem
is that MIPS's __builtin_setjmp() saves an extra word (the global pointer)
and no space was reserved for it in SjLj_Function_Context.

The comments in builtins.c say that __builtin_setjmp() is supposed to
take a pointer to 5 words.  Going by that, the MIPS version should be
in the clear, since it only needs 4.  But the sjlj code tries to save
a few bytes by using the following type for the jbuf field:

      /* This is 2 for builtin_setjmp, plus whatever the target requires
	 via STACK_SAVEAREA_MODE (SAVE_NONLOCAL).  */
      tmp = build_int_2 ((GET_MODE_SIZE (STACK_SAVEAREA_MODE (SAVE_NONLOCAL))
			  / GET_MODE_SIZE (Pmode)) + 2 - 1, 0);
      ...
      tmp = build_index_type (tmp);
      tmp = build_array_type (ptr_type_node, tmp);

The patch fixes this by introducing a new target macro to control the
size of the buffer.  This is obviously an ABI change for MIPS, but since
the bug meant that sjlj hadn't worked properly for many releases, I don't
think it should be a problem.

Tested on mips-sgi-irix6.5 with native assembler, fixes 47 g++ failures
for -mabi=32.  OK to install?

Richard

	PR target/7297
	* defaults.h (BUILTIN_JBUF_SIZE): New macro.
	* except.c (init_eh): Use it.
	* doc/tm.tex: Document it.
	* config/mips/mips.h: Set it to 4.

Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.280
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.280 tm.texi
*** doc/tm.texi	15 Jan 2004 03:44:19 -0000	1.280
--- doc/tm.texi	18 Jan 2004 21:08:43 -0000
*************** for the abi and context in the @code{.un
*** 3072,3077 ****
--- 3072,3084 ----
  be updated in @var{fs}.
  @end defmac
  
+ @defmac BUILTIN_JBUF_SIZE
+ If defined, the number of pointers saved by @code{__builtin_setjmp}.
+ The default is correct for the standard implementation; you need only
+ define this macro when the target's @code{builtin_setjmp_setup} pattern
+ needs more fields than the norm.
+ @end defmac
+ 
  @node Stack Checking
  @subsection Specifying How Stack Checking is Done
  
Index: defaults.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/defaults.h,v
retrieving revision 1.122
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.122 defaults.h
*** defaults.h	31 Dec 2003 23:02:44 -0000	1.122
--- defaults.h	18 Jan 2004 21:08:43 -0000
*************** #define LOCAL_REGNO(REGNO)  0
*** 690,693 ****
--- 690,701 ----
  #define EXIT_IGNORE_STACK 0
  #endif
  
+ #ifndef BUILTIN_JBUF_SIZE
+ /* This is 2 for builtin_setjmp (the frame pointer and receiver label) plus
+    whatever the target requires via STACK_SAVEAREA_MODE (SAVE_NONLOCAL).  */
+ #define BUILTIN_JBUF_SIZE				\
+   (GET_MODE_SIZE (STACK_SAVEAREA_MODE (SAVE_NONLOCAL))	\
+    / GET_MODE_SIZE (Pmode) + 2)
+ #endif
+ 
  #endif  /* ! GCC_DEFAULTS_H */
Index: except.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/except.c,v
retrieving revision 1.256
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.256 except.c
*** except.c	14 Jan 2004 21:01:17 -0000	1.256
--- except.c	18 Jan 2004 21:08:44 -0000
*************** init_eh (void)
*** 412,421 ****
        tmp = build_int_2 (FIRST_PSEUDO_REGISTER + 2 - 1, 0);
  #endif
  #else
!       /* This is 2 for builtin_setjmp, plus whatever the target requires
! 	 via STACK_SAVEAREA_MODE (SAVE_NONLOCAL).  */
!       tmp = build_int_2 ((GET_MODE_SIZE (STACK_SAVEAREA_MODE (SAVE_NONLOCAL))
! 			  / GET_MODE_SIZE (Pmode)) + 2 - 1, 0);
  #endif
        tmp = build_index_type (tmp);
        tmp = build_array_type (ptr_type_node, tmp);
--- 412,418 ----
        tmp = build_int_2 (FIRST_PSEUDO_REGISTER + 2 - 1, 0);
  #endif
  #else
!       tmp = build_int_2 (BUILTIN_JBUF_SIZE - 1, 0);
  #endif
        tmp = build_index_type (tmp);
        tmp = build_array_type (ptr_type_node, tmp);
Index: config/mips/mips.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.h,v
retrieving revision 1.310
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.310 mips.h
*** config/mips/mips.h	7 Jan 2004 00:52:31 -0000	1.310
--- config/mips/mips.h	18 Jan 2004 21:08:45 -0000
*************** #define PROMOTE_FUNCTION_ARGS
*** 1464,1469 ****
--- 1464,1472 ----
  /* Likewise, if the function return value is promoted.  */
  #define PROMOTE_FUNCTION_RETURN
  
+ /* Besides the normal three fields (frame pointer, receiver label and
+    stack pointer), we need an extra one for the global pointer.  */
+ #define BUILTIN_JBUF_SIZE 4
  
  /* Standard register usage.  */
  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]