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, ®); fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN(reg)].how = REG_UNSAVED; break; + case DW_CFA_undefined: + insn_ptr = read_uleb128 (insn_ptr, ®); + 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