Patchwork [4.7] Decrease size of DW_AT_bit_offset on little-endian targets (PR debug/47946)

login
register
mail settings
Submitter Jakub Jelinek
Date March 2, 2011, 5:44 p.m.
Message ID <20110302174418.GS30899@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/85117/
State New
Headers show

Comments

Jakub Jelinek - March 2, 2011, 5:44 p.m.
Hi!

DW_AT_bit_offset on little-endian targets often has negative values,
if we encode it as add_AT_unsigned, it needs DW_FORM_data8 for HWI 64
and DW_FORM_data4 for HWI 32.  But the numbers are usually small negative
values, so encoding them using DW_FORM_sdata is much more compact.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for 4.7?

DWARF4 obsoletes DW_AT_bit_offset with DW_AT_data_bit_offset, but
this patch doesn't try to change it for -gdwarf-4, that would be more work
(and most probably gdb doesn't handle it yet either).

2011-03-02  Jakub Jelinek  <jakub@redhat.com>

	PR debug/47946
	* dwarf2out.c (add_bit_offset_attribute): If bit_offset is negative,
	emit it as add_AT_int instead of add_AT_unsigned.


	Jakub
Tom Tromey - March 2, 2011, 6:27 p.m.
>>>>> "Jakub" == Jakub Jelinek <jakub@redhat.com> writes:

Jakub> DWARF4 obsoletes DW_AT_bit_offset with DW_AT_data_bit_offset, but
Jakub> this patch doesn't try to change it for -gdwarf-4, that would be
Jakub> more work (and most probably gdb doesn't handle it yet either).

Unfortunately you are right -- GDB doesn't handle DW_AT_data_bit_offset.
If you want to do that, let me know and I will write a GDB patch for it.

Tom
Richard Henderson - March 3, 2011, 4:53 a.m.
On 03/03/2011 03:44 AM, Jakub Jelinek wrote:
> 	PR debug/47946
> 	* dwarf2out.c (add_bit_offset_attribute): If bit_offset is negative,
> 	emit it as add_AT_int instead of add_AT_unsigned.

Ok for 4.7.


r~

Patch

--- gcc/dwarf2out.c.jj	2011-02-15 15:42:26.000000000 +0100
+++ gcc/dwarf2out.c	2011-03-01 19:31:54.735911828 +0100
@@ -17685,7 +17685,7 @@  add_bit_offset_attribute (dw_die_ref die
   HOST_WIDE_INT bitpos_int;
   HOST_WIDE_INT highest_order_object_bit_offset;
   HOST_WIDE_INT highest_order_field_bit_offset;
-  HOST_WIDE_INT unsigned bit_offset;
+  HOST_WIDE_INT bit_offset;
 
   /* Must be a field and a bit field.  */
   gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
@@ -17718,7 +17718,10 @@  add_bit_offset_attribute (dw_die_ref die
        ? highest_order_object_bit_offset - highest_order_field_bit_offset
        : highest_order_field_bit_offset - highest_order_object_bit_offset);
 
-  add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
+  if (bit_offset < 0)
+    add_AT_int (die, DW_AT_bit_offset, bit_offset);
+  else
+    add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
 }
 
 /* For a FIELD_DECL node which represents a bit field, output an attribute