Blame SOURCES/gcc44-pr49146.patch

dc1507
2013-05-17  Richard Henderson  <rth@redhat.com>
dc1507
dc1507
	PR target/49146
dc1507
	* unwind-dw2.c (UNWIND_COLUMN_IN_RANGE): New macro.
dc1507
	(execute_cfa_program): Use it when storing to fs->regs.
dc1507
dc1507
--- gcc/unwind-dw2.c	(revision 199018)
dc1507
+++ gcc/unwind-dw2.c	(revision 199019)
dc1507
@@ -55,6 +55,35 @@
dc1507
 #define DWARF_REG_TO_UNWIND_COLUMN(REGNO) (REGNO)
dc1507
 #endif
dc1507
 
dc1507
+/* ??? For the public function interfaces, we tend to gcc_assert that the
dc1507
+   column numbers are in range.  For the dwarf2 unwind info this does happen,
dc1507
+   although so far in a case that doesn't actually matter.
dc1507
+
dc1507
+   See PR49146, in which a call from x86_64 ms abi to x86_64 unix abi stores
dc1507
+   the call-saved xmm registers and annotates them.  We havn't bothered
dc1507
+   providing support for the xmm registers for the x86_64 port primarily
dc1507
+   because the 64-bit windows targets don't use dwarf2 unwind, using sjlj or
dc1507
+   SEH instead.  Adding the support for unix targets would generally be a
dc1507
+   waste.  However, some runtime libraries supplied with ICC do contain such
dc1507
+   an unorthodox transition, as well as the unwind info to match.  This loss
dc1507
+   of register restoration doesn't matter in practice, because the exception
dc1507
+   is caught in the native unix abi, where all of the xmm registers are 
dc1507
+   call clobbered.
dc1507
+
dc1507
+   Ideally, we'd record some bit to notice when we're failing to restore some
dc1507
+   register recorded in the unwind info, but to do that we need annotation on
dc1507
+   the unix->ms abi edge, so that we know when the register data may be
dc1507
+   discarded.  And since this edge is also within the ICC library, we're
dc1507
+   unlikely to be able to get the new annotation.
dc1507
+
dc1507
+   Barring a magic solution to restore the ms abi defined 128-bit xmm registers
dc1507
+   (as distictly opposed to the full runtime width) without causing extra
dc1507
+   overhead for normal unix abis, the best solution seems to be to simply
dc1507
+   ignore unwind data for unknown columns.  */
dc1507
+
dc1507
+#define UNWIND_COLUMN_IN_RANGE(x) \
dc1507
+    __builtin_expect((x) <= DWARF_FRAME_REGISTERS, 1)
dc1507
+
dc1507
 /* This is the register and unwind state for a particular frame.  This
dc1507
    provides the information necessary to unwind up past a frame and return
dc1507
    to its caller.  */
dc1507
@@ -897,14 +926,19 @@ execute_cfa_program (const unsigned char
dc1507
 	  reg = insn & 0x3f;
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
dc1507
 	  offset = (_Unwind_Sword) utmp * fs->data_align;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
dc1507
-	    = REG_SAVED_OFFSET;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = offset;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    {
dc1507
+	      fs->regs.reg[reg].how = REG_SAVED_OFFSET;
dc1507
+	      fs->regs.reg[reg].loc.offset = offset;
dc1507
+	    }
dc1507
 	}
dc1507
       else if ((insn & 0xc0) == DW_CFA_restore)
dc1507
 	{
dc1507
 	  reg = insn & 0x3f;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how = REG_UNSAVED;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    fs->regs.reg[reg].how = REG_UNSAVED;
dc1507
 	}
dc1507
       else switch (insn)
dc1507
 	{
dc1507
@@ -935,26 +969,35 @@ execute_cfa_program (const unsigned char
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
dc1507
 	  offset = (_Unwind_Sword) utmp * fs->data_align;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
dc1507
-	    = REG_SAVED_OFFSET;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = offset;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    {
dc1507
+	      fs->regs.reg[reg].how = REG_SAVED_OFFSET;
dc1507
+	      fs->regs.reg[reg].loc.offset = offset;
dc1507
+	    }
dc1507
 	  break;
dc1507
 
dc1507
 	case DW_CFA_restore_extended:
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
 	  /* FIXME, this is wrong; the CIE might have said that the
dc1507
 	     register was saved somewhere.  */
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN(reg)].how = REG_UNSAVED;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    fs->regs.reg[reg].how = REG_UNSAVED;
dc1507
 	  break;
dc1507
 
dc1507
 	case DW_CFA_same_value:
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN(reg)].how = REG_UNSAVED;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    fs->regs.reg[reg].how = REG_UNSAVED;
dc1507
 	  break;
dc1507
 
dc1507
 	case DW_CFA_undefined:
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN(reg)].how = REG_UNDEFINED;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    fs->regs.reg[reg].how = REG_UNDEFINED;
dc1507
 	  break;
dc1507
 
dc1507
 	case DW_CFA_nop:
dc1507
@@ -965,9 +1008,12 @@ execute_cfa_program (const unsigned char
dc1507
 	    _uleb128_t reg2;
dc1507
 	    insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
 	    insn_ptr = read_uleb128 (insn_ptr, ®2;;
dc1507
-	    fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how = REG_SAVED_REG;
dc1507
-	    fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.reg =
dc1507
-	      (_Unwind_Word)reg2;
dc1507
+	    reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	    if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	      {
dc1507
+	        fs->regs.reg[reg].how = REG_SAVED_REG;
dc1507
+	        fs->regs.reg[reg].loc.reg = (_Unwind_Word)reg2;
dc1507
+	      }
dc1507
 	  }
dc1507
 	  break;
dc1507
 
dc1507
@@ -1025,8 +1071,12 @@ execute_cfa_program (const unsigned char
dc1507
 
dc1507
 	case DW_CFA_expression:
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how = REG_SAVED_EXP;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.exp = insn_ptr;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    {
dc1507
+	      fs->regs.reg[reg].how = REG_SAVED_EXP;
dc1507
+	      fs->regs.reg[reg].loc.exp = insn_ptr;
dc1507
+	    }
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
dc1507
 	  insn_ptr += utmp;
dc1507
 	  break;
dc1507
@@ -1036,9 +1086,12 @@ execute_cfa_program (const unsigned char
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
 	  insn_ptr = read_sleb128 (insn_ptr, &stmp);
dc1507
 	  offset = stmp * fs->data_align;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
dc1507
-	    = REG_SAVED_OFFSET;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = offset;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    {
dc1507
+	      fs->regs.reg[reg].how = REG_SAVED_OFFSET;
dc1507
+	      fs->regs.reg[reg].loc.offset = offset;
dc1507
+	    }
dc1507
 	  break;
dc1507
 
dc1507
 	case DW_CFA_def_cfa_sf:
dc1507
@@ -1061,25 +1114,34 @@ execute_cfa_program (const unsigned char
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
dc1507
 	  offset = (_Unwind_Sword) utmp * fs->data_align;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
dc1507
-	    = REG_SAVED_VAL_OFFSET;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = offset;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    {
dc1507
+	      fs->regs.reg[reg].how = REG_SAVED_VAL_OFFSET;
dc1507
+	      fs->regs.reg[reg].loc.offset = offset;
dc1507
+	    }
dc1507
 	  break;
dc1507
 
dc1507
 	case DW_CFA_val_offset_sf:
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
 	  insn_ptr = read_sleb128 (insn_ptr, &stmp);
dc1507
 	  offset = stmp * fs->data_align;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
dc1507
-	    = REG_SAVED_VAL_OFFSET;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = offset;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    {
dc1507
+	      fs->regs.reg[reg].how = REG_SAVED_VAL_OFFSET;
dc1507
+	      fs->regs.reg[reg].loc.offset = offset;
dc1507
+	    }
dc1507
 	  break;
dc1507
 
dc1507
 	case DW_CFA_val_expression:
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
dc1507
-	    = REG_SAVED_VAL_EXP;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.exp = insn_ptr;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    {
dc1507
+	      fs->regs.reg[reg].how = REG_SAVED_VAL_EXP;
dc1507
+	      fs->regs.reg[reg].loc.exp = insn_ptr;
dc1507
+	    }
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
dc1507
 	  insn_ptr += utmp;
dc1507
 	  break;
dc1507
@@ -1104,9 +1166,12 @@ execute_cfa_program (const unsigned char
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, ®);
dc1507
 	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
dc1507
 	  offset = (_Unwind_Word) utmp * fs->data_align;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].how
dc1507
-	    = REG_SAVED_OFFSET;
dc1507
-	  fs->regs.reg[DWARF_REG_TO_UNWIND_COLUMN (reg)].loc.offset = -offset;
dc1507
+	  reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
dc1507
+	  if (UNWIND_COLUMN_IN_RANGE (reg))
dc1507
+	    {
dc1507
+	      fs->regs.reg[reg].how = REG_SAVED_OFFSET;
dc1507
+	      fs->regs.reg[reg].loc.offset = -offset;
dc1507
+	    }
dc1507
 	  break;
dc1507
 
dc1507
 	default: