From: "H.J. Lu" <hjl.tools@gmail.com>
To: Ian Lance Taylor <iant@google.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: PATCH: PR other/48007: Unwind library doesn't work with UNITS_PER_WORD > sizeof (void *)
Date: Tue, 22 Mar 2011 04:19:00 -0000 [thread overview]
Message-ID: <AANLkTi=hA05XuTsEUAeimD1M2a_W8z=v=OPQSvM1mfSq@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimb64b4tA81DfQp_mG8JMr-n_kpEZ5VxZm6VdFO@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2620 bytes --]
On Mon, Mar 21, 2011 at 2:55 PM, Ian Lance Taylor <iant@google.com> wrote:
> On Sun, Mar 6, 2011 at 9:18 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>
>> We shouldn't save call frame hard registers as "void *". This patch
>> changes the unwind library to save call frame hard registers as
>> _Unwind_Word. OK for 4.7?
>
>> + PR other/48007
>> + * unwind-dw2.c (_Unwind_Context): Save call frame hard registers
>> + as _Unwind_Word.
>> + (_Unwind_GetGR): Get GR value as _Unwind_Word.
>> + (_Unwind_SetGR): Set GR value as _Unwind_Word.
>> + (_Unwind_SetGRValue): Likewise.
>> + (_Unwind_GetGRPtr): Cast return to "void *".
>> + (_Unwind_SetGRPtr): Cast pointer to _Unwind_Word.
>> + (uw_install_context_1): Cast pointer to "void *".
>
> The approach you are using here looks wrong to me. When looking at
> the DWARF2 _Unwind_Context, you have to look at the by_value field for
> the register. If by_value is true, then the reg field for that
> register holds an _Unwind_Word which is the value of the register. If
> by_value is false, then the reg field holds a pointer to the place
> where the actual value is stored. The size of the actual value is
> determined by dwarf_reg_size_table. In other words, the reg field is
> a really a union of _Unwind_Word and void*.
>
> You have correctly observed that the current code fails for the case
> where sizeof(_Unwind_Word) > sizeof(void*). However, the answer is
> not to change the type from void* to _Unwind_Word. That will fail
> when sizeof(void*) > sizeof(_Unwind_Word).
>
> I think you have to make the reg field a union.
>
> By the way, don't use intptr_t in the unwind code. Use
> _Unwind_Internal_Ptr. But I think if you make the field a union, you
> won't need to use either type.
>
> Ian
>
Here is the updated patch. It has
@@ -243,7 +250,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].ref = p;
}
Is that OK to take the address of a union member?
--
H.J.
--
2011-03-22 H.J. Lu <hongjiu.lu@intel.com>
PR other/48007
* unwind-dw2.c (_Unwind_Register): New.
(_Unwind_Context): Save call frame hard registers as
_Unwind_Register.
(_Unwind_GetGR): Updated.
(_Unwind_SetGR): Likewise.
(_Unwind_SetGRValue): Likewise.
(_Unwind_GetGRPtr): Likewise.
(_Unwind_SetGRPtr): Likewise.
(uw_install_context_1): Likewise.
[-- Attachment #2: gcc-pr48007-1.patch --]
[-- Type: text/plain, Size: 4140 bytes --]
2011-03-22 H.J. Lu <hongjiu.lu@intel.com>
PR other/48007
* unwind-dw2.c (_Unwind_Register): New.
(_Unwind_Context): Save call frame hard registers as
_Unwind_Register.
(_Unwind_GetGR): Updated.
(_Unwind_SetGR): Likewise.
(_Unwind_SetGRValue): Likewise.
(_Unwind_GetGRPtr): Likewise.
(_Unwind_SetGRPtr): Likewise.
(uw_install_context_1): Likewise.
diff --git a/gcc/unwind-dw2.c b/gcc/unwind-dw2.c
index 25990b4..1cb4b47 100644
--- a/gcc/unwind-dw2.c
+++ b/gcc/unwind-dw2.c
@@ -59,12 +59,19 @@
#define DWARF_REG_TO_UNWIND_COLUMN(REGNO) (REGNO)
#endif
+/* A reister is stored either by reference or by value. */
+union _Unwind_Register
+{
+ void *ref;
+ _Unwind_Word val;
+};
+
/* 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];
+ union _Unwind_Register reg[DWARF_FRAME_REGISTERS+1];
void *cfa;
void *ra;
void *lsda;
@@ -156,7 +163,7 @@ inline _Unwind_Word
_Unwind_GetGR (struct _Unwind_Context *context, int index)
{
int size;
- void *ptr;
+ union _Unwind_Register reg;
#ifdef DWARF_ZERO_REG
if (index == DWARF_ZERO_REG)
@@ -166,18 +173,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];
+ reg = context->reg[index];
if (_Unwind_IsExtendedContext (context) && context->by_value[index])
- return (_Unwind_Word) (_Unwind_Internal_Ptr) ptr;
+ return reg.val;
/* This will segfault if the register hasn't been saved. */
if (size == sizeof(_Unwind_Ptr))
- return * (_Unwind_Ptr *) ptr;
+ return * (_Unwind_Ptr *) reg.ref;
else
{
gcc_assert (size == sizeof(_Unwind_Word));
- return * (_Unwind_Word *) ptr;
+ return * (_Unwind_Word *) reg.ref;
}
}
@@ -209,11 +216,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].val = val;
return;
}
- ptr = context->reg[index];
+ ptr = context->reg[index].ref;
if (size == sizeof(_Unwind_Ptr))
* (_Unwind_Ptr *) ptr = val;
@@ -231,8 +238,8 @@ _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 *) &context->reg[index].val;
+ return context->reg[index].ref;
}
/* Set the pointer to a register INDEX as saved in CONTEXT. */
@@ -243,7 +250,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].ref = p;
}
/* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
@@ -254,10 +261,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_Word));
context->by_value[index] = 1;
- context->reg[index] = (void *) (_Unwind_Internal_Ptr) val;
+ context->reg[index].val = val;
}
/* Return nonzero if register INDEX is stored by value rather than
@@ -1534,8 +1541,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 = current->reg[i].ref;
+ void *t = target->reg[i].ref;
gcc_assert (current->by_value[i] == 0);
if (target->by_value[i] && c)
next prev parent reply other threads:[~2011-03-22 4:19 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-06 17:18 H.J. Lu
2011-03-06 21:15 ` Andrew Pinski
2011-03-06 21:28 ` H.J. Lu
2011-03-06 23:23 ` Richard Guenther
2011-03-06 23:40 ` H.J. Lu
2011-03-07 0:15 ` H.J. Lu
2011-03-14 17:49 ` H.J. Lu
2011-03-21 21:56 ` Ian Lance Taylor
2011-03-22 4:19 ` H.J. Lu [this message]
2011-03-22 6:32 ` Ian Lance Taylor
2011-03-22 15:19 ` Ulrich Weigand
2011-03-22 15:41 ` Jakub Jelinek
2011-03-22 16:42 ` Ian Lance Taylor
2011-03-22 16:52 ` Andrew Pinski
2011-03-22 18:58 ` Ian Lance Taylor
2011-03-22 19:30 ` Ulrich Weigand
2011-03-22 22:18 ` Ian Lance Taylor
2011-03-23 3:25 ` H.J. Lu
2011-03-23 4:53 ` Ian Lance Taylor
2011-03-23 5:01 ` H.J. Lu
2011-03-23 13:58 ` Ian Lance Taylor
2011-03-23 17:50 ` Richard Henderson
2011-03-23 18:04 ` Jakub Jelinek
2011-03-23 18:20 ` Richard Henderson
2011-03-23 18:24 ` H.J. Lu
2011-03-23 18:27 ` Richard Henderson
2011-03-23 18:37 ` Jakub Jelinek
2011-03-23 19:01 ` Richard Henderson
2011-03-23 19:17 ` Jakub Jelinek
2011-03-23 19:22 ` Ulrich Weigand
2011-03-24 7:15 ` H.J. Lu
2011-04-10 1:52 ` 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='AANLkTi=hA05XuTsEUAeimD1M2a_W8z=v=OPQSvM1mfSq@mail.gmail.com' \
--to=hjl.tools@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=iant@google.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).