public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Rainer Orth <ro@cebitec.uni-bielefeld.de>
Cc: Jason Merrill <jason@redhat.com>,
	gcc-patches@gcc.gnu.org, 	Richard Henderson <rth@redhat.com>,
	Jakub Jelinek <jakub@redhat.com>
Subject: Re: PATCH [8/n]: Prepare x32: PR other/48007: Unwind library doesn't work with UNITS_PER_WORD > sizeof (void *)
Date: Thu, 30 Jun 2011 20:14:00 -0000	[thread overview]
Message-ID: <BANLkTimRWq4S4bKQpvuYzO3Go6yMc2fcgg@mail.gmail.com> (raw)
In-Reply-To: <yddr56bxkb1.fsf@manam.CeBiTec.Uni-Bielefeld.DE>

[-- Attachment #1: Type: text/plain, Size: 1563 bytes --]

On Thu, Jun 30, 2011 at 11:09 AM, Rainer Orth
<ro@cebitec.uni-bielefeld.de> wrote:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>>> Why all those contortions with i386/value-unwind.h?  It seems far
>>> simpler to me to put this into libgcc/config/i386/linux-unwind.h and be
>>> done with it.
>>
>> I did it this way so that other non-Linux x32 targets can use it.
>
> Such as?  Currently, only Linux, Windows and Solaris have i386/*-unwind.h
> implementations.  I'm pretty sure the latter two are highly unlikely to
> develop an x32 port, so let's cross that bridge when we get there.
>

Here is the updated patch without config/i386/value-unwind.h.
OK for trunk?

Thanks.

-- 
H.J.
---
2011-06-30  H.J. Lu  <hongjiu.lu@intel.com>

	* system.h (REG_VALUE_IN_UNWIND_CONTEXT): Poisoned.

	* unwind-dw2.c (_Unwind_Context_Reg_Val): New.
	(_Unwind_Get_Unwind_Word): Likewise.
	(_Unwind_Get_Unwind_Context_Reg_Val): Likewise.
	(_Unwind_Context): Use _Unwind_Context_Reg_Val on the reg field.
	(SIGNAL_FRAME_BIT): Define if REG_VALUE_IN_UNWIND_CONTEXT is
	defined.
	(_Unwind_IsExtendedContext): Likewise.
	(EXTENDED_CONTEXT_BIT): Don't define if REG_VALUE_IN_UNWIND_CONTEXT
	is defined.
	(_Unwind_GetGR): Updated.
	(_Unwind_SetGR): Likewise.
	(_Unwind_GetGRPtr): Likewise.
	(_Unwind_SetGRPtr): Likewise.
	(_Unwind_SetGRValue): Likewise.
	(_Unwind_GRByValue): Likewise.
	(__frame_state_for): Likewise.
	(uw_install_context_1): Likewise.

	* doc/tm.texi.in: Document REG_VALUE_IN_UNWIND_CONTEXT.
	* doc/tm.texi: Regenerated.

[-- Attachment #2: gcc-x32-pr48007-5.patch --]
[-- Type: text/plain, Size: 8846 bytes --]

2011-06-30  H.J. Lu  <hongjiu.lu@intel.com>

	* system.h (REG_VALUE_IN_UNWIND_CONTEXT): Poisoned.

	* unwind-dw2.c (_Unwind_Context_Reg_Val): New.
	(_Unwind_Get_Unwind_Word): Likewise.
	(_Unwind_Get_Unwind_Context_Reg_Val): Likewise.
	(_Unwind_Context): Use _Unwind_Context_Reg_Val on the reg field.
	(SIGNAL_FRAME_BIT): Define if REG_VALUE_IN_UNWIND_CONTEXT is
	defined.
	(_Unwind_IsExtendedContext): Likewise.
	(EXTENDED_CONTEXT_BIT): Don't define if REG_VALUE_IN_UNWIND_CONTEXT
	is defined.
	(_Unwind_GetGR): Updated.
	(_Unwind_SetGR): Likewise.
	(_Unwind_GetGRPtr): Likewise.
	(_Unwind_SetGRPtr): Likewise.
	(_Unwind_SetGRValue): Likewise.
	(_Unwind_GRByValue): Likewise.
	(__frame_state_for): Likewise.
	(uw_install_context_1): Likewise.

	* doc/tm.texi.in: Document REG_VALUE_IN_UNWIND_CONTEXT.
	* doc/tm.texi: Regenerated.

diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 341628b..2666716 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -3701,6 +3701,14 @@ return @code{@var{regno}}.
 
 @end defmac
 
+@defmac REG_VALUE_IN_UNWIND_CONTEXT
+
+Define this macro if the target stores register values as
+@code{_Unwind_Word} type in unwind context.  The default is to
+store register values as @code{void *} type.
+
+@end defmac
+
 @node Elimination
 @subsection Eliminating Frame Pointer and Arg Pointer
 
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index f7c16e9..690fa52 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -3687,6 +3687,14 @@ return @code{@var{regno}}.
 
 @end defmac
 
+@defmac REG_VALUE_IN_UNWIND_CONTEXT
+
+Define this macro if the target stores register values as
+@code{_Unwind_Word} type in unwind context.  The default is to
+store register values as @code{void *} type.
+
+@end defmac
+
 @node Elimination
 @subsection Eliminating Frame Pointer and Arg Pointer
 
diff --git a/gcc/system.h b/gcc/system.h
index e02cbcd..ed39d93 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -764,7 +764,7 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
 /* Target macros only used for code built for the target, that have
    moved to libgcc-tm.h or have never been present elsewhere.  */
  #pragma GCC poison DECLARE_LIBRARY_RENAMES LIBGCC2_GNU_PREFIX		\
-	MD_UNWIND_SUPPORT ENABLE_EXECUTE_STACK
+	MD_UNWIND_SUPPORT ENABLE_EXECUTE_STACK REG_VALUE_IN_UNWIND_CONTEXT
 
 /* Other obsolete target macros, or macros that used to be in target
    headers and were not used, and may be obsolete or may never have
diff --git a/gcc/unwind-dw2.c b/gcc/unwind-dw2.c
index 19da299..c77265c 100644
--- a/gcc/unwind-dw2.c
+++ b/gcc/unwind-dw2.c
@@ -59,20 +59,56 @@
 #define DWARF_REG_TO_UNWIND_COLUMN(REGNO) (REGNO)
 #endif
 
+#ifdef REG_VALUE_IN_UNWIND_CONTEXT
+typedef _Unwind_Word _Unwind_Context_Reg_Val;
+/* Signal frame context.  */
+#define SIGNAL_FRAME_BIT ((_Unwind_Word) 1 >> 0)
+
+#define _Unwind_IsExtendedContext(c) 1
+
+static inline _Unwind_Word
+_Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
+{
+  return val;
+}
+
+static inline _Unwind_Context_Reg_Val
+_Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
+{
+  return val;
+}
+#else
+typedef void *_Unwind_Context_Reg_Val;
+/* Signal frame context.  */
+#define SIGNAL_FRAME_BIT ((~(_Unwind_Word) 0 >> 1) + 1)
+/* Context which has version/args_size/by_value fields.  */
+#define EXTENDED_CONTEXT_BIT ((~(_Unwind_Word) 0 >> 2) + 1)
+
+#define _Unwind_IsExtendedContext(c) ((c)->flags & EXTENDED_CONTEXT_BIT)
+
+static inline _Unwind_Word
+_Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
+{
+  return (_Unwind_Word) (_Unwind_Internal_Ptr) val;
+}
+
+static inline _Unwind_Context_Reg_Val
+_Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
+{
+  return (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) val;
+}
+#endif
+
 /* This is the register and unwind state for a particular frame.  This
    provides the information necessary to unwind up past a frame and return
    to its caller.  */
 struct _Unwind_Context
 {
-  void *reg[DWARF_FRAME_REGISTERS+1];
+  _Unwind_Context_Reg_Val reg[DWARF_FRAME_REGISTERS+1];
   void *cfa;
   void *ra;
   void *lsda;
   struct dwarf_eh_bases bases;
-  /* Signal frame context.  */
-#define SIGNAL_FRAME_BIT ((~(_Unwind_Word) 0 >> 1) + 1)
-  /* Context which has version/args_size/by_value fields.  */
-#define EXTENDED_CONTEXT_BIT ((~(_Unwind_Word) 0 >> 2) + 1)
   _Unwind_Word flags;
   /* 0 for now, can be increased when further fields are added to
      struct _Unwind_Context.  */
@@ -143,12 +179,6 @@ _Unwind_SetSignalFrame (struct _Unwind_Context *context, int val)
   else
     context->flags &= ~SIGNAL_FRAME_BIT;
 }
-
-static inline _Unwind_Word
-_Unwind_IsExtendedContext (struct _Unwind_Context *context)
-{
-  return context->flags & EXTENDED_CONTEXT_BIT;
-}
 \f
 /* Get the value of register INDEX as saved in CONTEXT.  */
 
@@ -156,7 +186,7 @@ inline _Unwind_Word
 _Unwind_GetGR (struct _Unwind_Context *context, int index)
 {
   int size;
-  void *ptr;
+  _Unwind_Context_Reg_Val val;
 
 #ifdef DWARF_ZERO_REG
   if (index == DWARF_ZERO_REG)
@@ -166,18 +196,18 @@ _Unwind_GetGR (struct _Unwind_Context *context, int index)
   index = DWARF_REG_TO_UNWIND_COLUMN (index);
   gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
   size = dwarf_reg_size_table[index];
-  ptr = context->reg[index];
+  val = context->reg[index];
 
   if (_Unwind_IsExtendedContext (context) && context->by_value[index])
-    return (_Unwind_Word) (_Unwind_Internal_Ptr) ptr;
+    return _Unwind_Get_Unwind_Word (val);
 
   /* This will segfault if the register hasn't been saved.  */
   if (size == sizeof(_Unwind_Ptr))
-    return * (_Unwind_Ptr *) ptr;
+    return * (_Unwind_Ptr *) (_Unwind_Internal_Ptr) val;
   else
     {
       gcc_assert (size == sizeof(_Unwind_Word));
-      return * (_Unwind_Word *) ptr;
+      return * (_Unwind_Word *) (_Unwind_Internal_Ptr) val;
     }
 }
 
@@ -209,11 +239,11 @@ _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
 
   if (_Unwind_IsExtendedContext (context) && context->by_value[index])
     {
-      context->reg[index] = (void *) (_Unwind_Internal_Ptr) val;
+      context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
       return;
     }
 
-  ptr = context->reg[index];
+  ptr = (void *) (_Unwind_Internal_Ptr) context->reg[index];
 
   if (size == sizeof(_Unwind_Ptr))
     * (_Unwind_Ptr *) ptr = val;
@@ -232,7 +262,7 @@ _Unwind_GetGRPtr (struct _Unwind_Context *context, int index)
   index = DWARF_REG_TO_UNWIND_COLUMN (index);
   if (_Unwind_IsExtendedContext (context) && context->by_value[index])
     return &context->reg[index];
-  return context->reg[index];
+  return (void *) (_Unwind_Internal_Ptr) context->reg[index];
 }
 
 /* Set the pointer to a register INDEX as saved in CONTEXT.  */
@@ -243,7 +273,7 @@ _Unwind_SetGRPtr (struct _Unwind_Context *context, int index, void *p)
   index = DWARF_REG_TO_UNWIND_COLUMN (index);
   if (_Unwind_IsExtendedContext (context))
     context->by_value[index] = 0;
-  context->reg[index] = p;
+  context->reg[index] = (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) p;
 }
 
 /* Overwrite the saved value for register INDEX in CONTEXT with VAL.  */
@@ -254,10 +284,10 @@ _Unwind_SetGRValue (struct _Unwind_Context *context, int index,
 {
   index = DWARF_REG_TO_UNWIND_COLUMN (index);
   gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
-  gcc_assert (dwarf_reg_size_table[index] == sizeof (_Unwind_Ptr));
+  gcc_assert (dwarf_reg_size_table[index] == sizeof (_Unwind_Context_Reg_Val));
 
   context->by_value[index] = 1;
-  context->reg[index] = (void *) (_Unwind_Internal_Ptr) val;
+  context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
 }
 
 /* Return nonzero if register INDEX is stored by value rather than
@@ -1215,7 +1245,9 @@ __frame_state_for (void *pc_target, struct frame_state *state_in)
   int reg;
 
   memset (&context, 0, sizeof (struct _Unwind_Context));
+#ifndef REG_VALUE_IN_UNWIND_CONTEXT
   context.flags = EXTENDED_CONTEXT_BIT;
+#endif
   context.ra = pc_target + 1;
 
   if (uw_frame_state_for (&context, &fs) != _URC_NO_REASON)
@@ -1453,7 +1485,9 @@ uw_init_context_1 (struct _Unwind_Context *context,
 
   memset (context, 0, sizeof (struct _Unwind_Context));
   context->ra = ra;
+#ifndef REG_VALUE_IN_UNWIND_CONTEXT
   context->flags = EXTENDED_CONTEXT_BIT;
+#endif
 
   code = uw_frame_state_for (context, &fs);
   gcc_assert (code == _URC_NO_REASON);
@@ -1532,8 +1566,8 @@ uw_install_context_1 (struct _Unwind_Context *current,
 
   for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
     {
-      void *c = current->reg[i];
-      void *t = target->reg[i];
+      void *c = (void *) (_Unwind_Internal_Ptr) current->reg[i];
+      void *t = (void *) (_Unwind_Internal_Ptr)target->reg[i];
 
       gcc_assert (current->by_value[i] == 0);
       if (target->by_value[i] && c)

  reply	other threads:[~2011-06-30 18:24 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-25 17:02 H.J. Lu
2011-06-25 23:34 ` Joseph S. Myers
2011-06-25 23:36   ` H.J. Lu
2011-06-26 20:06 ` Jason Merrill
2011-06-26 20:22   ` Jason Merrill
2011-06-26 21:45   ` H.J. Lu
2011-06-27  2:12     ` Jason Merrill
2011-06-27  3:17       ` H.J. Lu
2011-06-27 15:16         ` Jason Merrill
2011-06-28 19:25           ` H.J. Lu
2011-06-30 14:46             ` Jason Merrill
2011-06-30 14:53               ` H.J. Lu
2011-06-30 15:26                 ` Jason Merrill
2011-06-30 16:36                   ` H.J. Lu
2011-06-30 17:57                     ` H.J. Lu
2011-06-30 18:01                       ` H.J. Lu
2011-06-30 18:10                         ` Rainer Orth
2011-06-30 18:19                           ` H.J. Lu
2011-06-30 18:42                             ` Rainer Orth
2011-06-30 20:14                               ` H.J. Lu [this message]
2011-06-30 20:24                                 ` Richard Henderson
2011-06-30 21:51                                   ` H.J. Lu
2011-07-01  9:03                                     ` Rainer Orth
2011-07-01 12:51                                       ` H.J. Lu
2011-07-01 13:37                                         ` Rainer Orth
2011-07-01 13:42                                           ` H.J. Lu
2011-07-01 14:03                                             ` Rainer Orth
2011-07-01 14:06                                               ` H.J. Lu
2011-07-01 14:25                                                 ` Rainer Orth
2011-07-01 14:55                                                   ` H.J. Lu
2011-08-02 21:02                                     ` Jason Merrill
2011-08-02 22:27                                       ` H.J. Lu
2011-08-03 21:47                                         ` Jason Merrill
2011-06-30 20:59                               ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTimRWq4S4bKQpvuYzO3Go6yMc2fcgg@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    --cc=ro@cebitec.uni-bielefeld.de \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).