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]

[PATCH] Fix __builtin_frame_address on SPARC 64-bit


As demonstrated by the failures

FAIL: gcc.c-torture/execute/frame-address.c execution,  -O0 
FAIL: gcc.c-torture/execute/frame-address.c execution,  -O1 
FAIL: gcc.c-torture/execute/frame-address.c execution,  -O2 
FAIL: gcc.c-torture/execute/frame-address.c execution,  -O3 
-fomit-frame-pointer 
FAIL: gcc.c-torture/execute/frame-address.c execution,  -O3 -g 
FAIL: gcc.c-torture/execute/frame-address.c execution,  -Os 

__builtin_frame_address is not functional on SPARC 64-bit because it overlooks 
the famous stack bias (so the returned address is not even aligned).  Although 
expand_builtin_return_addr already uses 4 macros, this is not fixable using 
only this set unless DYNAMIC_CHAIN_ADDRESS is changed.

Hence the need for a 5th macro, namely FRAME_ADDR_RTX.  Tested on SPARC 32-bit 
and 64-bit.  OK for mainline?


2006-10-01  Eric Botcazou  <ebotcazou@libertysurf.fr>

	* builtins.c (expand_builtin_return_addr): Deal with FRAME_ADDR_RTX.
	* config/sparc/sparc.h (FRAME_ADDR_RTX): Define.
	* doc/tm.texi (Basic Stack Layout): Document FRAME_ADDR_RTX.


-- 
Eric Botcazou
Index: builtins.c
===================================================================
--- builtins.c	(revision 117300)
+++ builtins.c	(working copy)
@@ -558,14 +558,14 @@ expand_builtin_return_addr (enum built_i
 #endif
 
   /* Some machines need special handling before we can access
-     arbitrary frames.  For example, on the sparc, we must first flush
+     arbitrary frames.  For example, on the SPARC, we must first flush
      all register windows to the stack.  */
 #ifdef SETUP_FRAME_ADDRESSES
   if (count > 0)
     SETUP_FRAME_ADDRESSES ();
 #endif
 
-  /* On the sparc, the return address is not in the frame, it is in a
+  /* On the SPARC, the return address is not in the frame, it is in a
      register.  There is no way to access it off of the current frame
      pointer, but it can be accessed off the previous frame pointer by
      reading the value from the register window save area.  */
@@ -587,12 +587,16 @@ expand_builtin_return_addr (enum built_i
       tem = copy_to_reg (tem);
     }
 
-  /* For __builtin_frame_address, return what we've got.  */
+  /* For __builtin_frame_address, return what we've got.  But, on
+     the SPARC for example, we may have to add a bias.  */
   if (fndecl_code == BUILT_IN_FRAME_ADDRESS)
+#ifdef FRAME_ADDR_RTX
+    return FRAME_ADDR_RTX (tem);
+#else
     return tem;
+#endif
 
-  /* For __builtin_return_address, Get the return address from that
-     frame.  */
+  /* For __builtin_return_address, get the return address from that frame.  */
 #ifdef RETURN_ADDR_RTX
   tem = RETURN_ADDR_RTX (count, tem);
 #else
Index: config/sparc/sparc.h
===================================================================
--- config/sparc/sparc.h	(revision 117300)
+++ config/sparc/sparc.h	(working copy)
@@ -1701,6 +1701,10 @@ do {									\
 #define DYNAMIC_CHAIN_ADDRESS(frame)	\
   plus_constant (frame, 14 * UNITS_PER_WORD + SPARC_STACK_BIAS)
 
+/* Given an rtx for the frame pointer,
+   return an rtx for the address of the frame.  */
+#define FRAME_ADDR_RTX(frame) plus_constant (frame, SPARC_STACK_BIAS)
+
 /* The return address isn't on the stack, it is in a register, so we can't
    access it from the current frame pointer.  We can access it from the
    previous frame pointer though by reading a value from the register window
Index: doc/tm.texi
===================================================================
--- doc/tm.texi	(revision 117300)
+++ doc/tm.texi	(working copy)
@@ -2995,6 +2995,12 @@ machines.  One reason you may need to de
 @code{hard_frame_pointer_rtx} is the appropriate value on your machine.
 @end deftypefn
 
+@defmac FRAME_ADDR_RTX (@var{frameaddr})
+A C expression whose value is RTL representing the value of the frame
+address for the current frame.  @var{frameaddr} is the frame pointer
+of the current frame.
+@end defmac
+
 @defmac RETURN_ADDR_RTX (@var{count}, @var{frameaddr})
 A C expression whose value is RTL representing the value of the return
 address for the frame @var{count} steps up from the current frame, after

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