This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Simple struct member offset doesn't need a full dwarf location expression


Hi,

As explained in PR40659 a simple struct member offset doesn't need a
full dwarf location expression, but can just encode the
DW_AT_data_member_location as a constant offset according to the Dwarf
standard. This saves a little space (one byte per struct field member)
and is slightly simpler to handle for debuginfo consumers. It is also
the recommended way to encode this according to the examples in the
Dwarf standard appendix.

This was easy to implement, instead of always creating a full location
expression in add_data_member_location_attribute, just output a constant
for DW_AT_data_member_location when all we have is a simple offset.

I didn't change the way this is generated when MIPS_DEBUGGING_INFO is
defined, since the comment says that the current approach in that case
is a specific workaround for SGI dwarf reader and I have no way to test
against that.

2009-07-07  Mark Wielaard  <mjw@redhat.com>

    PR debug/40659
    * dwarf2out.c (add_data_member_location_attribute): When we have
    only a constant offset don't emit a new location description using
    DW_OP_plus_uconst, but just add the constant with add_AT_int.

Bootstrapped and regtested on x86_64-unknown-linux-gnu. GDB and binutils
readelf already handle this more compact form and I have a patch for
systemtap and elfutils to do the same.

OK to commit?

Mark
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c	(revision 149279)
+++ gcc/dwarf2out.c	(working copy)
@@ -11475,8 +11475,6 @@
 
   if (! loc_descr)
     {
-      enum dwarf_location_atom op;
-
       /* The DWARF2 standard says that we should assume that the structure
 	 address is already on the stack, so we can specify a structure field
 	 address by using DW_OP_plus_uconst.  */
@@ -11485,12 +11483,16 @@
       /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
 	 operator correctly.  It works only if we leave the offset on the
 	 stack.  */
+      enum dwarf_location_atom op;
+
       op = DW_OP_constu;
+      loc_descr = new_loc_descr (op, offset, 0);
 #else
-      op = DW_OP_plus_uconst;
+      /* Don't need an whole location expression, just a constant offset. */
+      add_AT_int (die, DW_AT_data_member_location, offset);
+      return;
 #endif
 
-      loc_descr = new_loc_descr (op, offset, 0);
     }
 
   add_AT_loc (die, DW_AT_data_member_location, loc_descr);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]