Patch to correct 64-bit DWARF info

Joseph S. Myers joseph@codesourcery.com
Sat Mar 18 01:07:00 GMT 2006


When using the standard 64-bit DWARF3 format (used only on
mips64*-*-linux*, only for N64 ABI), GCC fails to include the
four-byte 0xffffffff header required at the start of CIEs and FDEs to
distinguish 64-bit DWARF from 32-bit DWARF, and wrongly uses the
32-but CIE identifier instead of the 64-bit one.  In addition, there
is confusion about whether dw_val_class_loc_list should be represented
as DW_FORM_data4 or DW_FORM_data8.

This patch fixes these problems.  Tested that the patched compiler
generates debuggable binaries for all ABIs on mips64el-linux; there
should be no effects on any other target.  OK to commit?

As a separate issue, it's not clear that mips64*-*-linux* should be
defaulting to the 64-bit DWARF format; it's bigger than 32-bit DWARF,
less well tested, and only needed where a linked object has more than
4GB of debug info.  Is anyone actually using GCC (targetting MIPS64
GNU/Linux) in circumstances involving objects with that much debug
info?

2006-03-18  Joseph S. Myers  <joseph@codesourcery.com>

	* dwarf2.h (DW64_CIE_ID): Define.
	* dwarf2out.c (DWARF_CIE_ID): Define.
	(output_call_frame_info): Output 0xffffffff before standard 8-byte
	length header.  Use DWARF_CIE_ID.
	(value_format): Use DW_FORM_data4 or DW_FORM_data8 for
	dw_val_class_loc_list depending on DWARF_OFFSET_SIZE.

diff -rupN GCC.orig/gcc/dwarf2.h GCC/gcc/dwarf2.h
--- GCC.orig/gcc/dwarf2.h	2006-03-02 22:56:46.000000000 +0000
+++ GCC/gcc/dwarf2.h	2006-03-17 17:20:26.000000000 +0000
@@ -757,6 +757,7 @@ enum dwarf_call_frame_info
   };
 
 #define DW_CIE_ID	  0xffffffff
+#define DW64_CIE_ID	  0xffffffffffffffffULL
 #define DW_CIE_VERSION	  1
 
 #define DW_CFA_extended   0
diff -rupN GCC.orig/gcc/dwarf2out.c GCC/gcc/dwarf2out.c
--- GCC.orig/gcc/dwarf2out.c	2006-03-17 14:33:22.000000000 +0000
+++ GCC/gcc/dwarf2out.c	2006-03-17 23:25:16.000000000 +0000
@@ -288,6 +288,14 @@ dw_fde_node;
 #endif
 #endif
 
+/* CIE identifier.  */
+#if HOST_BITS_PER_WIDE_INT >= 64
+#define DWARF_CIE_ID \
+  (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
+#else
+#define DWARF_CIE_ID DW_CIE_ID
+#endif
+
 /* A pointer to the base of a table that contains frame description
    information for each routine.  */
 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
@@ -2218,6 +2226,9 @@ output_call_frame_info (int for_eh)
   /* Output the CIE.  */
   ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
   ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
+  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
+    dw2_asm_output_data (4, 0xffffffff,
+      "Initial length escape value indicating 64-bit DWARF extension");
   dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
 			"Length of Common Information Entry");
   ASM_OUTPUT_LABEL (asm_out_file, l1);
@@ -2225,7 +2236,7 @@ output_call_frame_info (int for_eh)
   /* Now that the CIE pointer is PC-relative for EH,
      use 0 to identify the CIE.  */
   dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
-		       (for_eh ? 0 : DW_CIE_ID),
+		       (for_eh ? 0 : DWARF_CIE_ID),
 		       "CIE Identifier Tag");
 
   dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
@@ -2350,6 +2361,9 @@ output_call_frame_info (int for_eh)
       targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
       ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
       ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
+      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
+	dw2_asm_output_data (4, 0xffffffff,
+			     "Initial length escape value indicating 64-bit DWARF extension");
       dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
 			    "FDE Length");
       ASM_OUTPUT_LABEL (asm_out_file, l1);
@@ -6773,6 +6787,7 @@ value_format (dw_attr_ref a)
       return DW_FORM_addr;
     case dw_val_class_range_list:
     case dw_val_class_offset:
+    case dw_val_class_loc_list:
       switch (DWARF_OFFSET_SIZE)
 	{
 	case 4:
@@ -6782,10 +6797,6 @@ value_format (dw_attr_ref a)
 	default:
 	  gcc_unreachable ();
 	}
-    case dw_val_class_loc_list:
-      /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
-	 .debug_loc section */
-      return DW_FORM_data4;
     case dw_val_class_loc:
       switch (constant_size (size_of_locs (AT_loc (a))))
 	{


-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)



More information about the Gcc-patches mailing list