Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Roland McGrath <roland@redhat.com>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>,
	gcc@gcc.gnu.org,         libc-alpha@sources.redhat.com,
	gdb@sourceware.org,         Richard Henderson <rth@redhat.com>
Subject: Re: Unwinding CFI gcc practice of assumed `same value' regs
Date: Tue, 12 Dec 2006 15:54:00 -0000	[thread overview]
Message-ID: <20061212155233.GH29911@devserv.devel.redhat.com> (raw)
In-Reply-To: <20061211224022.AD76E1800E7@magilla.sf.frob.com>

On Mon, Dec 11, 2006 at 02:40:22PM -0800, Roland McGrath wrote:
> My reading is that the "ABI authoring body" for GNU systems or the
> "compilation system authoring body" for GNU compilers already specifies
> that the default rule is same_value for callee-saves registers (as chosen
> by each particular ABI), even if this has not been formally documented
> anywhere heretofore.  (This is how I've written ABI support in another
> unwinder implementation I've worked on.)  As you've said, this is the only
> reading by which current CFI is correct and complete for getting the values
> of callee-saves registers.  I presume that GCC's omission of rules for
> those registers is in fact simply because EH unwinding doesn't care and
> people on the generation side just didn't think about it beyond that.
> Regardless of the true reasons for the history, the description above
> applies to the manifest practice that constitutes what we want the formal
> specification to mean.

Well, for satisfying the requirement that undefined retaddr_column
identifies outermost frame it matters whether retaddr_column's default rule
is same_value or undefined.  If it is by default same_value, then
unwind-dw2.c should just handle explicit DW_CFA_undefined retaddr_column
as outermost frame mark, otherwise it would need to handle any unspecified
or explicit DW_CFA_undefined retaddr_column (but not DW_CFA_same_value).
Here is something that would handle by default same_value retaddr_column:

--- gcc/unwind-dw2.h	2006-10-29 21:49:23.000000000 +0100
+++ gcc/unwind-dw2.h	2006-12-12 16:30:29.000000000 +0100
@@ -1,5 +1,5 @@
 /* DWARF2 frame unwind data structure.
-   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2006
    Free Software Foundation, Inc.
 
    This file is part of GCC.
@@ -55,7 +55,8 @@ typedef struct
 	REG_SAVED_REG,
 	REG_SAVED_EXP,
 	REG_SAVED_VAL_OFFSET,
-	REG_SAVED_VAL_EXP
+	REG_SAVED_VAL_EXP,
+	REG_UNDEFINED
       } how;
     } reg[DWARF_FRAME_REGISTERS+1];
 
--- gcc/unwind-dw2.c	2006-12-08 15:57:44.000000000 +0100
+++ gcc/unwind-dw2.c	2006-12-12 16:38:26.000000000 +0100
@@ -887,12 +887,16 @@ execute_cfa_program (const unsigned char
 	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN(reg)].how = REG_UNSAVED;
 	  break;
 
-	case DW_CFA_undefined:
 	case DW_CFA_same_value:
 	  insn_ptr = read_uleb128 (insn_ptr, &reg);
 	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN(reg)].how = REG_UNSAVED;
 	  break;
 
+	case DW_CFA_undefined:
+	  insn_ptr = read_uleb128 (insn_ptr, &reg);
+	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN(reg)].how = REG_UNDEFINED;
+	  break;
+
 	case DW_CFA_nop:
 	  break;
 
@@ -1255,6 +1259,7 @@ uw_update_context_1 (struct _Unwind_Cont
     switch (fs->regs.reg[i].how)
       {
       case REG_UNSAVED:
+      case REG_UNDEFINED:
 	break;
 
       case REG_SAVED_OFFSET:
@@ -1323,10 +1328,21 @@ uw_update_context (struct _Unwind_Contex
 {
   uw_update_context_1 (context, fs);
 
-  /* Compute the return address now, since the return address column
-     can change from frame to frame.  */
-  context->ra = __builtin_extract_return_addr
-    (_Unwind_GetPtr (context, fs->retaddr_column));
+  /* In general this unwinder doesn't make any distinction between
+     undefined and same_value rule.  Call-saved registers are assumed
+     to have same_value rule by default and explicit undefined
+     rule is handled like same_value.  The only exception is
+     DW_CFA_undefined on retaddr_column which is supposed to
+     mark outermost frame in DWARF 3.  */
+  if (fs->regs[fs->retaddr_column].how == REG_UNDEFINED)
+    /* uw_frame_state_for uses context->ra == 0 check to find outermost
+       stack frame.  */
+    context->ra = 0;
+  else
+    /* Compute the return address now, since the return address column
+       can change from frame to frame.  */
+    context->ra = __builtin_extract_return_addr
+      (_Unwind_GetPtr (context, fs->retaddr_column));
 }
 
 static void


	Jakub


  reply	other threads:[~2006-12-12 15:54 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-11 19:03 Jan Kratochvil
2006-12-11 22:40 ` Roland McGrath
2006-12-12 15:54   ` Jakub Jelinek [this message]
2006-12-12 13:55 ` Andrew Haley
2006-12-12 14:55   ` Mark Kettenis
2006-12-12 15:04     ` Andrew Haley
2006-12-12 15:21       ` Ulrich Drepper
2006-12-12 15:26         ` Andrew Haley
2006-12-12 15:39           ` Ulrich Drepper
2006-12-13 18:11             ` Michael Matz
2006-12-12 15:50           ` Jan Kratochvil
2006-12-12 16:19           ` Jakub Jelinek
2006-12-12 16:55       ` Ian Lance Taylor
2006-12-12 17:06         ` Andrew Haley
2006-12-12 17:34           ` Mark Kettenis
2006-12-13 18:02           ` Michael Matz
2006-12-13 18:10 ` Michael Matz

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=20061212155233.GH29911@devserv.devel.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=gdb@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=libc-alpha@sources.redhat.com \
    --cc=roland@redhat.com \
    --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